Line data Source code
1 : /**
2 : * The versioned URL contract every Comfy product uses to hand a customer to
3 : * the hosted billing app, and that the app reads back on arrival.
4 : *
5 : * The entry URL is routing input and nothing more. It never carries a token,
6 : * a JWT, a payment-provider secret, an authoritative price, or a caller-chosen
7 : * return URL: a product states which billing screen it wants, which product is
8 : * asking, and which registered destination the customer should land on
9 : * afterwards. Billing resolves everything else against its own environment and
10 : * the signed-in session, so a workspace id here is a requested scope and never
11 : * an authorization.
12 : *
13 : * Route and parameter names are provisional while the hosted app is behind a
14 : * flag. `BILLING_CONTRACT_VERSION` is what lets them change without stranding
15 : * a product that is already deployed against the older shape.
16 : *
17 : * Whether a payment renders embedded or hosted is not decided here — that is
18 : * the SDK core's `hostedDestination` port. This package stays dependency-free
19 : * and framework-free so a product, the billing app, and a future non-Vue host
20 : * can share exactly one definition of the route surface.
21 : */
22 : export const BILLING_CONTRACT_VERSION = 'v1'
23 :
24 : export const BILLING_INTENTS = [
25 : 'pricing',
26 : 'checkout',
27 : 'top-up',
28 : 'subscription',
29 : 'payment-methods',
30 : 'invoices',
31 : 'result'
32 : ] as const
33 :
34 : export type BillingIntent = (typeof BILLING_INTENTS)[number]
35 :
36 : export function isBillingIntent(
37 : value: string | null | undefined
38 : ): value is BillingIntent {
39 : return BILLING_INTENTS.some((intent) => intent === value)
40 : }
41 :
42 : /** The route an intent occupies, e.g. `/v1/checkout`. */
43 0 : export function billingIntentPath(intent: BillingIntent): string {
44 0 : return `/${BILLING_CONTRACT_VERSION}/${intent}`
45 : }
46 :
47 : /** The surfaces allowed to originate a billing trip. */
48 : export const BILLING_PRODUCTS = [
49 : 'comfyui',
50 : 'platform',
51 : 'workshop',
52 : 'models'
53 : ] as const
54 :
55 : export type BillingProduct = (typeof BILLING_PRODUCTS)[number]
56 :
57 : export function isBillingProduct(
58 : value: string | null | undefined
59 : ): value is BillingProduct {
60 : return BILLING_PRODUCTS.some((product) => product === value)
61 : }
62 :
63 : /**
64 : * Where in a product the customer asked for billing. A value outside this list
65 : * is read as no source.
66 : */
67 2356 : export const BILLING_SOURCES = [
68 : 'subscription_required',
69 : 'out_of_credits',
70 : 'top_up_blocked',
71 : 'deep_link',
72 : 'subscribe_to_run',
73 : 'subscribe_now_button',
74 : 'upgrade_to_add_credits',
75 : 'settings_billing_panel',
76 : 'avatar_menu_plans',
77 : 'team_members_panel',
78 : 'invite_member_upsell',
79 : 'upload_model_upgrade',
80 : 'team_upgrade_resume',
81 : 'free_tier_quota',
82 : 'agent_paywall'
83 : ] as const
84 :
85 : export type BillingSource = (typeof BILLING_SOURCES)[number]
86 :
87 0 : export function isBillingSource(
88 : value: string | null | undefined
89 : ): value is BillingSource {
90 0 : return BILLING_SOURCES.some((source) => source === value)
91 : }
92 :
93 : /**
94 : * Which deployment family a return destination belongs to. The backends run
95 : * three of them, not two, and pair each origin with exactly one family, so a
96 : * product resolves its return target in the same family its session was
97 : * minted against.
98 : *
99 : * A host picks its family by origin, never by the label on its own build: the
100 : * cloud app's "staging" distribution points at `testcloud.comfy.org`
101 : * (`STAGING_CLOUD_BASE_URL` in `src/config/comfyApi.ts`) and therefore maps to
102 : * `test` here, while `staging` means `stagingcloud.comfy.org`.
103 : */
104 : export type BillingEnvironment = 'production' | 'staging' | 'test'
|