@openrails/billing-ui 0.235.0 → 0.237.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/CHANGELOG.md +155 -0
  2. package/README.md +103 -103
  3. package/dist/account/account-billing.d.ts +2 -4
  4. package/dist/account/payment-methods-panel.d.ts +2 -4
  5. package/dist/buy-button.d.ts +40 -0
  6. package/dist/cart.d.ts +18 -0
  7. package/dist/client/client.d.ts +95 -59
  8. package/dist/client/errors.d.ts +4 -0
  9. package/dist/client/generated/error-codes.d.ts +1 -1
  10. package/dist/client/generated/routes.d.ts +103 -272
  11. package/dist/client/generated/wire.d.ts +117 -246
  12. package/dist/client/index.d.ts +2 -2
  13. package/dist/client/types.d.ts +286 -142
  14. package/dist/client-D9G1Tgox.js +888 -0
  15. package/dist/client-D9G1Tgox.js.map +1 -0
  16. package/dist/client.js +2 -2
  17. package/dist/components/eyebrow.d.ts +5 -0
  18. package/dist/components/stripe-card.d.ts +8 -2
  19. package/dist/components/stripe-wallets.d.ts +12 -0
  20. package/dist/components/ui/badge.d.ts +1 -1
  21. package/dist/components/ui/button.d.ts +1 -1
  22. package/dist/embedded-checkout.d.ts +22 -0
  23. package/dist/hooks-DYepYVMX.js +526 -0
  24. package/dist/hooks-DYepYVMX.js.map +1 -0
  25. package/dist/i18n/context.d.ts +1 -1
  26. package/dist/index.d.ts +9 -11
  27. package/dist/index.js +1470 -2178
  28. package/dist/index.js.map +1 -1
  29. package/dist/lib/money.d.ts +1 -0
  30. package/dist/lib/offer-label.d.ts +4 -0
  31. package/dist/locales/de.js +20 -0
  32. package/dist/locales/de.js.map +1 -1
  33. package/dist/locales/en.d.ts +20 -0
  34. package/dist/locales/en.js +20 -0
  35. package/dist/locales/en.js.map +1 -1
  36. package/dist/locales/es.js +20 -0
  37. package/dist/locales/es.js.map +1 -1
  38. package/dist/locales/ja.js +11 -0
  39. package/dist/locales/ja.js.map +1 -1
  40. package/dist/locales/ko.js +11 -0
  41. package/dist/locales/ko.js.map +1 -1
  42. package/dist/locales/zh.js +11 -0
  43. package/dist/locales/zh.js.map +1 -1
  44. package/dist/modal.d.ts +3 -9
  45. package/dist/offers.d.ts +32 -0
  46. package/dist/order-checkout.d.ts +30 -0
  47. package/dist/psp.d.ts +0 -8
  48. package/dist/react/hooks.d.ts +8 -7
  49. package/dist/react/index.d.ts +1 -1
  50. package/dist/react/provider.d.ts +24 -2
  51. package/dist/react.js +2 -33
  52. package/dist/save-payment-method.d.ts +0 -6
  53. package/dist/styles.css +1 -1
  54. package/dist/tokenized-card-form.d.ts +5 -1
  55. package/dist/types.d.ts +12 -250
  56. package/docs/payment-form-contract.md +31 -74
  57. package/package.json +1 -2
  58. package/dist/checkout-frame.d.ts +0 -17
  59. package/dist/checkout-page.d.ts +0 -21
  60. package/dist/checkout.d.ts +0 -24
  61. package/dist/client-BpzCZes3.js +0 -931
  62. package/dist/client-BpzCZes3.js.map +0 -1
  63. package/dist/components/ccbill-fields.d.ts +0 -8
  64. package/dist/components/methods.d.ts +0 -13
  65. package/dist/components/summary.d.ts +0 -12
  66. package/dist/config-qLcHvK0Q.js +0 -341
  67. package/dist/config-qLcHvK0Q.js.map +0 -1
  68. package/dist/fixtures.d.ts +0 -9
  69. package/dist/frame.d.ts +0 -47
  70. package/dist/lib/rail-meta.d.ts +0 -15
  71. package/dist/lib/redirect.d.ts +0 -2
  72. package/dist/provider.d.ts +0 -18
  73. package/dist/react.js.map +0 -1
  74. package/dist/source.d.ts +0 -5
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-qLcHvK0Q.js","names":[],"sources":["../src/react/context.ts","../src/react/remote.ts","../src/react/hooks.ts","../src/react/config.ts"],"sourcesContent":["import { createContext, useContext } from \"react\"\n\nimport type { BillingClient } from \"../client/client\"\nimport type { SubscriptionChange } from \"../client/types\"\nimport type { ConfigStore } from \"./config\"\n\nexport type BillingChange =\n | {\n type: \"subscription.canceled\" | \"subscription.resumed\"\n subscriptionId: string\n }\n | {\n type: \"subscription.payment_method_changed\"\n subscriptionId: string\n /** null: the subscription follows the default card. */\n paymentMethodId: string | null\n }\n | {\n type: \"subscription.changed\"\n subscriptionId: string\n /** `status` may still be `processing` or `requires_action`. */\n change: SubscriptionChange\n }\n | {\n type:\n | \"payment_method.added\"\n | \"payment_method.removed\"\n | \"payment_method.default_changed\"\n paymentMethodId: string\n }\n\nexport interface BillingContextValue {\n client: BillingClient\n /** Bumped after every mutation; hooks refetch on change. */\n version: number\n notify(change: BillingChange): void\n /** Refetch every hook after a host-side change such as a plan switch. */\n refresh(): void\n /** The shared `GET /config`; read it with `useConfig()`. */\n config: ConfigStore\n}\n\nexport const BillingContext = createContext<BillingContextValue | null>(null)\n\nexport function useBillingContext(): BillingContextValue {\n const ctx = useContext(BillingContext)\n if (!ctx) throw new Error(\"billing-ui: wrap the tree in <BillingProvider>\")\n return ctx\n}\n\nexport const useBillingClient = (): BillingClient => useBillingContext().client\n\nexport const useBillingRefresh = (): (() => void) => useBillingContext().refresh\n\n/** The billing context when a BillingProvider is present, else null. */\nexport const useOptionalBillingContext = (): BillingContextValue | null =>\n useContext(BillingContext)\n","import { useCallback, useEffect, useRef, useState } from \"react\"\n\nimport { toBillingError, type BillingError } from \"../client/errors\"\n\nexport interface RemoteState<T> {\n data: T | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n}\n\n// Keyed fetch that keeps the previous data while a newer key loads, so a\n// refetch after a mutation never flashes an empty list.\nexport function useRemote<T>(\n key: string,\n load: (signal: AbortSignal) => Promise<T>\n): RemoteState<T> & { replace: (update: (data: T) => T) => void } {\n const [nonce, setNonce] = useState(0)\n const request = `${key}|${nonce}`\n const [state, setState] = useState<{\n request: string | null\n data: T | null\n error: BillingError | null\n }>({ request: null, data: null, error: null })\n const loadRef = useRef(load)\n useEffect(() => {\n loadRef.current = load\n })\n\n useEffect(() => {\n const ctl = new AbortController()\n loadRef.current(ctl.signal).then(\n (data) => setState({ request, data, error: null }),\n (err: unknown) => {\n if (!ctl.signal.aborted)\n setState((s) => ({\n request,\n data: s.data,\n error: toBillingError(err),\n }))\n }\n )\n return () => ctl.abort()\n }, [request])\n\n const refetch = useCallback(() => setNonce((n) => n + 1), [])\n const replace = useCallback(\n (update: (data: T) => T) =>\n setState((s) => (s.data === null ? s : { ...s, data: update(s.data) })),\n []\n )\n return {\n data: state.data,\n loading: state.request !== request,\n error: state.request === request ? state.error : null,\n refetch,\n replace,\n }\n}\n","import { useCallback, useMemo, useState } from \"react\"\n\nimport {\n isWalletAction,\n signWalletAction,\n type SendSolanaTransaction,\n type SubscriptionChangeInput,\n} from \"../client/client\"\nimport { localError, toBillingError, type BillingError } from \"../client/errors\"\nimport type {\n NewCard,\n Payment,\n PaymentMethod,\n Product,\n Subscription,\n SubscriptionChange,\n} from \"../client/types\"\nimport { useBillingContext } from \"./context\"\nimport { useRemote } from \"./remote\"\n\n// Actions never throw: they resolve to null on success or the error.\nexport type ActionResult = Promise<BillingError | null>\n\n/** `signing` and `confirming` are a wallet step's stages. */\nexport type SubscriptionAction =\n | \"cancel\"\n | \"resume\"\n | \"payment_method\"\n | \"change\"\n | \"signing\"\n | \"confirming\"\n\nexport interface SubscriptionsOptions {\n /** Server filter; default `all`. */\n status?: string\n limit?: number\n}\n\nexport interface SubscriptionsState {\n subscriptions: Subscription[] | null\n /** The next page's cursor; null on the last page. */\n nextCursor: string | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n /** In-flight action per subscription id. */\n pending: Readonly<Record<string, SubscriptionAction>>\n /**\n * Cancels at period end. A Solana subscription is canceled by the wallet:\n * pass `sendTransaction`; without it the cancel resolves to a\n * `wallet_required` error.\n */\n cancel: (\n subscriptionId: string,\n reason: string,\n sendTransaction?: SendSolanaTransaction\n ) => ActionResult\n resume: (subscriptionId: string) => ActionResult\n /** `null` makes the subscription follow the default card. */\n setPaymentMethod: (\n subscriptionId: string,\n paymentMethodId: string | null\n ) => ActionResult\n /**\n * Resolves to the change, whose `status` may still be `processing` or\n * `requires_action`, or to the error. A Solana change is signed with\n * `sendTransaction` and resolves once the chain confirms it.\n */\n changeSubscription: (\n subscriptionId: string,\n input: SubscriptionChangeInput & { idempotencyKey: string },\n sendTransaction?: SendSolanaTransaction\n ) => Promise<SubscriptionChange | BillingError>\n}\n\nfunction usePending<A extends string>() {\n const [pending, setPending] = useState<Readonly<Record<string, A>>>({})\n const mark = useCallback((id: string, action: A | null) => {\n setPending((p) => {\n const next = { ...p }\n if (action) next[id] = action\n else delete next[id]\n return next\n })\n }, [])\n return [pending, mark] as const\n}\n\nconst walletRequired = () =>\n localError(\"wallet_required\", \"A wallet must sign this action.\")\n\nexport function useSubscriptions(\n options: SubscriptionsOptions = {}\n): SubscriptionsState {\n const { client, version, notify } = useBillingContext()\n const status = options.status ?? \"all\"\n const limit = options.limit ?? 100\n const remote = useRemote(`${status}|${limit}|${version}`, (signal) =>\n client.listSubscriptions({ status, limit, signal })\n )\n const [pending, mark] = usePending<SubscriptionAction>()\n const { replace } = remote\n\n const patchRow = useCallback(\n (next: Subscription) =>\n replace((page) => ({\n ...page,\n data: page.data.map((s) => (s.id === next.id ? next : s)),\n })),\n [replace]\n )\n\n const act = useCallback(\n async (\n id: string,\n action: SubscriptionAction,\n run: () => Promise<Subscription>,\n done: (subscription: Subscription) => void\n ): ActionResult => {\n mark(id, action)\n try {\n const next = await run()\n patchRow(next)\n done(next)\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [mark, patchRow]\n )\n\n // A declined wallet prompt resolves to a `wallet_rejected` error.\n const cancel = useCallback(\n (id: string, reason: string, sendTransaction?: SendSolanaTransaction) =>\n act(\n id,\n \"cancel\",\n async () => {\n const sub = await client.cancelSubscription(id, { reason })\n if (!sub.next_action) return sub\n if (!isWalletAction(sub.next_action) || !sendTransaction)\n throw walletRequired()\n mark(id, \"signing\")\n const signature = await signWalletAction(\n sub.next_action,\n sendTransaction\n )\n mark(id, \"confirming\")\n return client.cancelSubscription(id, { reason, signature })\n },\n () => notify({ type: \"subscription.canceled\", subscriptionId: id })\n ),\n [act, client, mark, notify]\n )\n\n const resume = useCallback(\n (id: string) =>\n act(\n id,\n \"resume\",\n () => client.resumeSubscription(id),\n () => notify({ type: \"subscription.resumed\", subscriptionId: id })\n ),\n [act, client, notify]\n )\n\n const setPaymentMethod = useCallback(\n (id: string, paymentMethodId: string | null) =>\n act(\n id,\n \"payment_method\",\n () => client.setSubscriptionPaymentMethod(id, paymentMethodId),\n () =>\n notify({\n type: \"subscription.payment_method_changed\",\n subscriptionId: id,\n paymentMethodId,\n })\n ),\n [act, client, notify]\n )\n\n // An upgrade may open a successor subscription: notify refetches the list.\n const changeSubscription = useCallback(\n async (\n id: string,\n input: SubscriptionChangeInput & { idempotencyKey: string },\n sendTransaction?: SendSolanaTransaction\n ) => {\n mark(id, \"change\")\n try {\n let change = await client.changeSubscription(id, input)\n if (\n change.status === \"requires_action\" &&\n isWalletAction(change.next_action) &&\n sendTransaction\n ) {\n mark(id, \"signing\")\n const signature = await signWalletAction(\n change.next_action!,\n sendTransaction\n )\n mark(id, \"confirming\")\n change = await client.changeSubscription(id, { ...input, signature })\n }\n notify({\n type: \"subscription.changed\",\n subscriptionId: id,\n change,\n })\n return change\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [client, mark, notify]\n )\n\n return {\n subscriptions: remote.data?.data ?? null,\n nextCursor: remote.data?.next_cursor ?? null,\n loading: remote.loading,\n error: remote.error,\n refetch: remote.refetch,\n pending,\n cancel,\n resume,\n setPaymentMethod,\n changeSubscription,\n }\n}\n\nexport interface ProductsState {\n products: Product[] | null\n /** The cursor of the next page; null on the last. */\n nextCursor: string | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n}\n\n/** The catalog: active products with their active prices. */\nexport function useProducts(options: { limit?: number } = {}): ProductsState {\n const { client } = useBillingContext()\n const limit = options.limit ?? 100\n const remote = useRemote(`${limit}`, (signal) =>\n client.listProducts({ limit, signal })\n )\n return {\n products: remote.data?.data ?? null,\n nextCursor: remote.data?.next_cursor ?? null,\n loading: remote.loading,\n error: remote.error,\n refetch: remote.refetch,\n }\n}\n\nexport type PaymentMethodAction = \"remove\" | \"default\"\n\nexport interface PaymentMethodsState {\n methods: PaymentMethod[] | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n pending: Readonly<Record<string, PaymentMethodAction>>\n adding: boolean\n add: (card: NewCard) => ActionResult\n remove: (paymentMethodId: string) => ActionResult\n /** Makes the card the default for the currency. */\n setDefault: (paymentMethodId: string, currency: string) => ActionResult\n}\n\nexport function usePaymentMethods(): PaymentMethodsState {\n const { client, version, notify } = useBillingContext()\n const remote = useRemote(`${version}`, (signal) =>\n client.listPaymentMethods({ signal })\n )\n const [pending, mark] = usePending<PaymentMethodAction>()\n const [adding, setAdding] = useState(false)\n const { replace } = remote\n\n const add = useCallback(\n async (card: NewCard): ActionResult => {\n setAdding(true)\n try {\n const method = await client.addPaymentMethod(card)\n replace((page) => ({ ...page, data: [...page.data, method] }))\n notify({ type: \"payment_method.added\", paymentMethodId: method.id })\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n setAdding(false)\n }\n },\n [client, notify, replace]\n )\n\n const remove = useCallback(\n async (id: string): ActionResult => {\n mark(id, \"remove\")\n try {\n await client.removePaymentMethod(id)\n replace((page) => ({\n ...page,\n data: page.data.filter((m) => m.id !== id),\n }))\n notify({ type: \"payment_method.removed\", paymentMethodId: id })\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [client, mark, notify, replace]\n )\n\n const setDefault = useCallback(\n async (id: string, currency: string): ActionResult => {\n mark(id, \"default\")\n try {\n await client.setDefaultPaymentMethod({\n currency,\n paymentMethodId: id,\n })\n const code = currency.toUpperCase()\n replace((page) => ({\n ...page,\n data: page.data.map((m) => {\n const others = (m.default_currencies ?? []).filter(\n (c) => c !== code\n )\n return {\n ...m,\n default_currencies: m.id === id ? [...others, code] : others,\n }\n }),\n }))\n notify({\n type: \"payment_method.default_changed\",\n paymentMethodId: id,\n })\n return null\n } catch (err) {\n return toBillingError(err)\n } finally {\n mark(id, null)\n }\n },\n [client, mark, notify, replace]\n )\n\n return {\n methods: remote.data?.data ?? null,\n loading: remote.loading,\n error: remote.error,\n refetch: remote.refetch,\n pending,\n adding,\n add,\n remove,\n setDefault,\n }\n}\n\nexport interface PaymentsOptions {\n pageSize?: number\n /** Filter by rail. */\n rail?: string\n}\n\nexport interface PaymentsState {\n payments: Payment[] | null\n /** Zero-based. */\n page: number\n hasMore: boolean\n loading: boolean\n error: BillingError | null\n next: () => void\n previous: () => void\n refetch: () => void\n}\n\nexport function usePayments(options: PaymentsOptions = {}): PaymentsState {\n const { client, version } = useBillingContext()\n const pageSize = options.pageSize ?? 20\n // cursors[i] reads page i of this filter; page 0 is the newest payments.\n const filter = `${pageSize}|${options.rail ?? \"\"}`\n const [state, setState] = useState({\n filter,\n cursors: [null] as (string | null)[],\n })\n const cursors = useMemo(\n () => (state.filter === filter ? state.cursors : [null]),\n [state, filter]\n )\n const page = cursors.length - 1\n const cursor = cursors[page]\n const remote = useRemote(`${filter}|${cursor ?? \"\"}|${version}`, (signal) =>\n client.listPayments({\n limit: pageSize,\n cursor,\n rail: options.rail,\n signal,\n })\n )\n const data = remote.data\n const nextCursor = data?.next_cursor ?? null\n return {\n payments: data?.data ?? null,\n page,\n hasMore: nextCursor !== null,\n loading: remote.loading,\n error: remote.error,\n next: useCallback(() => {\n if (nextCursor !== null)\n setState({ filter, cursors: [...cursors, nextCursor] })\n }, [filter, cursors, nextCursor]),\n previous: useCallback(() => {\n if (cursors.length > 1)\n setState({ filter, cursors: cursors.slice(0, -1) })\n }, [filter, cursors]),\n refetch: remote.refetch,\n }\n}\n","import { useEffect, useMemo, useSyncExternalStore } from \"react\"\n\nimport type { BillingClient } from \"../client/client\"\nimport { toBillingError, type BillingError } from \"../client/errors\"\nimport type { CurrencyScales, PublicConfig } from \"../client/types\"\nimport { useBillingContext } from \"./context\"\n\nexport interface ConfigState {\n config: PublicConfig | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n}\n\ninterface Snapshot {\n config: PublicConfig | null\n loading: boolean\n error: BillingError | null\n}\n\n/** One shared copy of `GET /config` per client, fetched on first use. */\nexport interface ConfigStore {\n subscribe(listener: () => void): () => void\n snapshot(): Snapshot\n /** Fetches the document unless it was already requested. */\n ensure(): void\n refetch(): void\n}\n\nexport function createConfigStore(client: BillingClient): ConfigStore {\n let snapshot: Snapshot = { config: null, loading: true, error: null }\n let started = false\n let latest = 0\n const listeners = new Set<() => void>()\n const set = (next: Snapshot) => {\n snapshot = next\n for (const listener of listeners) listener()\n }\n const load = () => {\n started = true\n const request = ++latest\n if (!snapshot.loading) set({ ...snapshot, loading: true })\n client.getConfig().then(\n (config) => {\n if (request === latest) set({ config, loading: false, error: null })\n },\n (err: unknown) => {\n if (request === latest)\n set({\n config: snapshot.config,\n loading: false,\n error: toBillingError(err),\n })\n }\n )\n }\n return {\n subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n snapshot: () => snapshot,\n ensure() {\n if (!started) load()\n },\n refetch: load,\n }\n}\n\n/**\n * The deployment's public configuration (`GET /config`), fetched once per\n * `BillingProvider` and shared by every component that reads it.\n */\nexport function useConfig(): ConfigState {\n const { config: store } = useBillingContext()\n const snapshot = useSyncExternalStore(\n store.subscribe,\n store.snapshot,\n store.snapshot\n )\n useEffect(() => store.ensure(), [store])\n return { ...snapshot, refetch: store.refetch }\n}\n\n/**\n * Currency scales: the server's registry, under the client's pinned copy and\n * host overrides, which stand alone until the registry loads.\n */\nexport function useCurrencyScales(): CurrencyScales {\n const { client } = useBillingContext()\n const { config } = useConfig()\n return useMemo(() => {\n const served = Object.fromEntries(\n (config?.currencies ?? []).map((c) => [c.code.toUpperCase(), c.decimals])\n )\n return { ...served, ...client.currencies }\n }, [config, client])\n}\n"],"mappings":";;;AA0CA,IAAa,IAAiB,EAA0C,IAAI;AAE5E,SAAgB,IAAy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AAkB,GACtC,IAAW,EACf,EAAM,WACN,EAAM,UACN,EAAM,QACR;CAEA,OADA,QAAgB,EAAM,OAAO,GAAG,CAAC,CAAK,CAAC,GAChC;EAAE,GAAG;EAAU,SAAS,EAAM;CAAQ;AAC/C;AAMA,SAAgB,IAAoC;CAClD,IAAM,EAAE,cAAW,EAAkB,GAC/B,EAAE,cAAW,EAAU;CAC7B,OAAO,SAIE;EAAE,GAHM,OAAO,aACnB,GAAQ,cAAc,CAAC,EAAA,CAAG,KAAK,MAAM,CAAC,EAAE,KAAK,YAAY,GAAG,EAAE,QAAQ,CAAC,CAE9D;EAAQ,GAAG,EAAO;CAAW,IACxC,CAAC,GAAQ,CAAM,CAAC;AACrB"}
@@ -1,9 +0,0 @@
1
- import { CheckoutSource } from './source';
2
- import { CheckoutSession, PayResult } from './types';
3
- export declare function fixtureSession(overrides?: Partial<CheckoutSession>): CheckoutSession;
4
- export declare function createFixtureSource(options?: {
5
- session?: Partial<CheckoutSession>;
6
- payResult?: PayResult;
7
- payDelayMs?: number;
8
- loadDelayMs?: number;
9
- }): CheckoutSource;
package/dist/frame.d.ts DELETED
@@ -1,47 +0,0 @@
1
- import { z } from 'zod';
2
- /** The page's color scheme, chosen by the framing app. */
3
- export type CheckoutFrameTheme = "light" | "dark" | "auto";
4
- declare const pageMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
- source: z.ZodLiteral<"openrails-checkout">;
6
- type: z.ZodLiteral<"ready">;
7
- }, z.core.$strip>, z.ZodObject<{
8
- source: z.ZodLiteral<"openrails-checkout">;
9
- type: z.ZodLiteral<"resize">;
10
- height: z.ZodNumber;
11
- }, z.core.$strip>, z.ZodObject<{
12
- source: z.ZodLiteral<"openrails-checkout">;
13
- type: z.ZodLiteral<"complete">;
14
- status: z.ZodEnum<{
15
- canceled: "canceled";
16
- succeeded: "succeeded";
17
- failed: "failed";
18
- expired: "expired";
19
- created: "created";
20
- requires_action: "requires_action";
21
- processing: "processing";
22
- blocked: "blocked";
23
- }>;
24
- }, z.core.$strip>, z.ZodObject<{
25
- source: z.ZodLiteral<"openrails-checkout">;
26
- type: z.ZodLiteral<"redirect">;
27
- url: z.ZodString;
28
- }, z.core.$strip>], "type">;
29
- export type PageMessage = z.infer<typeof pageMessageSchema>;
30
- declare const appMessageSchema: z.ZodObject<{
31
- source: z.ZodLiteral<"openrails-checkout">;
32
- type: z.ZodLiteral<"init">;
33
- theme: z.ZodEnum<{
34
- light: "light";
35
- dark: "dark";
36
- auto: "auto";
37
- }>;
38
- }, z.core.$strip>;
39
- export type AppMessage = z.infer<typeof appMessageSchema>;
40
- type Body<M> = M extends unknown ? Omit<M, "source"> : never;
41
- export declare const pageMessage: (body: Body<PageMessage>) => PageMessage;
42
- export declare const appMessage: (body: Body<AppMessage>) => AppMessage;
43
- export declare function parsePageMessage(data: unknown): PageMessage | null;
44
- export declare function parseAppMessage(data: unknown): AppMessage | null;
45
- /** The origin of a payment page URL, or null when it is not one. */
46
- export declare function pageOrigin(url: string): string | null;
47
- export {};
@@ -1,15 +0,0 @@
1
- import { PaymentOption } from '../types';
2
- export interface RailMeta {
3
- label: string;
4
- hint?: string;
5
- }
6
- export declare function railMeta(option: PaymentOption): RailMeta;
7
- export declare const RAIL_META: Record<string, RailMeta>;
8
- export interface SolanaToken {
9
- symbol: string;
10
- name?: string;
11
- network?: string;
12
- }
13
- export declare function solanaToken(option: PaymentOption): SolanaToken | undefined;
14
- export declare function solanaHint(token: SolanaToken): string;
15
- export declare function supportedOptions(options: PaymentOption[]): PaymentOption[];
@@ -1,2 +0,0 @@
1
- /** The https URL a redirect rail may navigate to, or null. */
2
- export declare function safeRedirectURL(raw: string): string | null;
@@ -1,18 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { CheckoutAppearance } from './appearance';
3
- import { BillingUiMessageBundle, BillingUiTranslate } from './i18n/messages';
4
- import { Navigate } from './scope-context';
5
- export interface BillingUiProviderProps {
6
- appearance?: CheckoutAppearance;
7
- /** Locale bundle(s) layered over English; later entries win. */
8
- messages?: BillingUiMessageBundle | readonly BillingUiMessageBundle[];
9
- /** Host translation hook, consulted before the bundles. */
10
- t?: BillingUiTranslate;
11
- /** BCP 47 tag for dates, money and plurals; defaults to the browser's. */
12
- locale?: string;
13
- /** Host router for in-app links (e.g. the plans page). */
14
- navigate?: Navigate;
15
- children?: ReactNode;
16
- }
17
- /** Renders no DOM; surfaces create their own styling roots. */
18
- export declare function BillingUiProvider({ appearance, messages, t, locale, navigate, children, }: BillingUiProviderProps): import("react").JSX.Element;
package/dist/react.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.js","names":[],"sources":["../src/react/provider.tsx"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from \"react\"\n\nimport type { BillingClient } from \"../client/client\"\nimport { createConfigStore } from \"./config\"\nimport { BillingContext, type BillingChange } from \"./context\"\n\nexport interface BillingProviderProps {\n client: BillingClient\n /** Fires after each successful mutation: the host's cache-invalidation hook. */\n onChange?: (change: BillingChange) => void\n children?: ReactNode\n}\n\nexport function BillingProvider({\n client,\n onChange,\n children,\n}: BillingProviderProps) {\n const [version, setVersion] = useState(0)\n const onChangeRef = useRef(onChange)\n useEffect(() => {\n onChangeRef.current = onChange\n })\n const notify = useCallback((change: BillingChange) => {\n setVersion((v) => v + 1)\n onChangeRef.current?.(change)\n }, [])\n const refresh = useCallback(() => setVersion((v) => v + 1), [])\n const config = useMemo(() => createConfigStore(client), [client])\n const value = useMemo(\n () => ({ client, version, notify, refresh, config }),\n [client, version, notify, refresh, config]\n )\n return (\n <BillingContext.Provider value={value}>{children}</BillingContext.Provider>\n )\n}\n"],"mappings":";;;;AAoBA,SAAgB,EAAgB,EAC9B,WACA,aACA,eACuB;CACvB,IAAM,CAAC,GAAS,KAAc,EAAS,CAAC,GAClC,IAAc,EAAO,CAAQ;CACnC,QAAgB;EACd,EAAY,UAAU;CACxB,CAAC;CACD,IAAM,IAAS,GAAa,MAA0B;EAEpD,AADA,GAAY,MAAM,IAAI,CAAC,GACvB,EAAY,UAAU,CAAM;CAC9B,GAAG,CAAC,CAAC,GACC,IAAU,QAAkB,GAAY,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,GACxD,IAAS,QAAc,EAAkB,CAAM,GAAG,CAAC,CAAM,CAAC,GAC1D,IAAQ,SACL;EAAE;EAAQ;EAAS;EAAQ;EAAS;CAAO,IAClD;EAAC;EAAQ;EAAS;EAAQ;EAAS;CAAM,CAC3C;CACA,OACE,kBAAC,EAAe,UAAhB;EAAgC;EAAQ;CAAkC,CAAA;AAE9E"}
package/dist/source.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { CheckoutSession, PayRequest, PayResult } from './types';
2
- export interface CheckoutSource {
3
- getSession(): Promise<CheckoutSession>;
4
- pay(request: PayRequest): Promise<PayResult>;
5
- }