Line data Source code
1 : import type { CapabilitiesSnapshot } from '@comfyorg/account-core/billing'
2 :
3 : import type { BillingCapabilitiesRead } from '@comfyorg/billing-core'
4 :
5 : /**
6 : * The SDK's cached capabilities snapshot in the shape the capabilities
7 : * composable already holds: the scope it was resolved for and the instant the
8 : * SDK stops serving it, which is the instant the composable would refetch.
9 : */
10 0 : export function projectBillingCapabilities(
11 : snapshot: CapabilitiesSnapshot
12 : ): BillingCapabilitiesRead {
13 0 : return {
14 : ...(snapshot.autoTopUpEnabled === undefined
15 : ? {}
16 : : { auto_top_up_enabled: snapshot.autoTopUpEnabled }),
17 : ...(snapshot.autoTopUpMemberView === undefined
18 : ? {}
19 : : { auto_top_up_member_view: snapshot.autoTopUpMemberView }),
20 : ...(snapshot.autoTopUpSetup === undefined
21 : ? {}
22 : : { auto_top_up_setup: snapshot.autoTopUpSetup }),
23 : ...(snapshot.billingNoticeAudience === undefined
24 : ? {}
25 : : { billing_notice_audience: snapshot.billingNoticeAudience }),
26 : capabilities: snapshot.capabilities,
27 : denied_reasons: snapshot.denials,
28 : ...(snapshot.endingNoticeStartsAt === undefined
29 : ? {}
30 : : { ending_notice_starts_at: snapshot.endingNoticeStartsAt }),
31 : expires_at: new Date(snapshot.freshUntil).toISOString(),
32 : resolved_for: {
33 : user_id: snapshot.scope.userId,
34 : workspace_id: snapshot.scope.workspaceId
35 : },
36 : revision: snapshot.revision,
37 : rollout_defaults_applied: snapshot.rolloutDefaultsApplied,
38 : ...(snapshot.planKind === undefined
39 : ? {}
40 : : { plan_kind: snapshot.planKind }),
41 : ...(snapshot.hasParkedBillingOperation === undefined
42 : ? {}
43 : : { has_parked_billing_operation: snapshot.hasParkedBillingOperation }),
44 : ...(snapshot.paymentRecoveryAvailable === undefined
45 : ? {}
46 : : { payment_recovery_available: snapshot.paymentRecoveryAvailable })
47 : }
48 : }
|