Line data Source code
1 : import type {
2 : BillingEventsReadOptions,
3 : BillingResult,
4 : CapabilitiesReadOptions
5 : } from '@comfyorg/account-core/billing'
6 :
7 : import { useFeatureFlags } from '@/composables/useFeatureFlags'
8 : import type {
9 : BillingBalanceResponse,
10 : BillingCapabilitiesRead,
11 : BillingEventsResponse,
12 : BillingPlansResponse,
13 : BillingStatusResponse,
14 : SavedPaymentMethod
15 : } from '@comfyorg/billing-core'
16 :
17 : /** The reads a rail serves, in the shape the host's billing state holds. */
18 : export interface BillingReadRail {
19 : readStatus: () => Promise<BillingResult<BillingStatusResponse>>
20 : readBalance: () => Promise<BillingResult<BillingBalanceResponse>>
21 : readPlans: () => Promise<BillingResult<BillingPlansResponse>>
22 : readCapabilities: (
23 : options: CapabilitiesReadOptions
24 : ) => Promise<BillingResult<BillingCapabilitiesRead>>
25 : readPaymentMethods: () => Promise<BillingResult<SavedPaymentMethod[]>>
26 : /** The only read whose request varies per call: it asks for one page. */
27 : readEvents: (
28 : options?: BillingEventsReadOptions
29 : ) => Promise<BillingResult<BillingEventsResponse>>
30 : }
31 :
32 2356 : let useBillingSdkStore: () => BillingReadRail
33 :
34 : /** Called by `billingSdkStore` when it loads; the readers it imports reach it through here. */
35 2356 : export function provideBillingSdkStore(useStore: () => BillingReadRail): void {
36 2356 : useBillingSdkStore = useStore
37 : }
38 :
39 : /** The rail the billing reads are served on, read once per fetch. Null is the legacy client. */
40 89 : export function useBillingReadRail(): BillingReadRail | null {
41 89 : const { flags } = useFeatureFlags()
42 89 : return flags.billingSdkRailEnabled ? useBillingSdkStore() : null
43 : }
|