@openrails/billing-ui 0.237.0 → 0.238.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.
- package/CHANGELOG.md +35 -9
- package/README.md +44 -19
- package/dist/account/payment-methods-panel.d.ts +1 -1
- package/dist/authenticate.d.ts +5 -4
- package/dist/buy-button.d.ts +4 -2
- package/dist/client/client.d.ts +30 -13
- package/dist/client/generated/routes.d.ts +34 -30
- package/dist/client/generated/wire.d.ts +5 -15
- package/dist/client/index.d.ts +2 -1
- package/dist/client/token-source.d.ts +60 -0
- package/dist/client/types.d.ts +43 -65
- package/dist/{client-D9G1Tgox.js → client-Bi_lP_M0.js} +251 -207
- package/dist/client-Bi_lP_M0.js.map +1 -0
- package/dist/client.js +2 -2
- package/dist/{hooks-DYepYVMX.js → hooks-Bk80rNv8.js} +99 -90
- package/dist/hooks-Bk80rNv8.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +989 -984
- package/dist/index.js.map +1 -1
- package/dist/offers.d.ts +6 -4
- package/dist/react/config.d.ts +17 -12
- package/dist/react/context.d.ts +3 -1
- package/dist/react/hooks.d.ts +5 -5
- package/dist/react/index.d.ts +1 -1
- package/dist/react.js +2 -2
- package/docs/payment-form-contract.md +1 -1
- package/package.json +1 -1
- package/dist/client-D9G1Tgox.js.map +0 -1
- package/dist/hooks-DYepYVMX.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-Bk80rNv8.js","names":[],"sources":["../src/i18n/messages.ts","../src/i18n/context.ts","../src/appearance.ts","../src/scope-context.ts","../src/react/context.ts","../src/react/config.ts","../src/react/provider.tsx","../src/react/remote.ts","../src/react/hooks.ts"],"sourcesContent":["import { en } from \"../locales/en.ts\"\n\n/**\n * A count-dependent message: CLDR plural categories for the locale, with\n * `other` required. An exact-count key (`\"1\"`) wins over the category, like\n * ICU's `=1`, for locales whose single form differs from `{count}` (毎日).\n */\nexport type PluralMessage = {\n [K in Intl.LDMLPluralRule | \"1\"]?: string\n} & { other: string }\n\ntype Widen<T> = {\n [K in keyof T]: T[K] extends string\n ? string\n : T[K] extends PluralMessage\n ? PluralMessage\n : Widen<T[K]>\n}\n\n/** The complete message tree; English is the reference shape. */\nexport type BillingUiMessages = Widen<typeof en>\n\ntype DeepPartial<T> = {\n [K in keyof T]?: T[K] extends string\n ? string\n : T[K] extends PluralMessage\n ? Partial<PluralMessage>\n : DeepPartial<T[K]>\n}\n\n/** A locale bundle or host override: any subset of the tree. */\nexport type BillingUiMessageBundle = DeepPartial<BillingUiMessages>\n\ntype Paths<T, P extends string = \"\"> = {\n [K in keyof T & string]: T[K] extends string\n ? `${P}${K}`\n : T[K] extends PluralMessage\n ? never\n : Paths<T[K], `${P}${K}.`>\n}[keyof T & string]\n\ntype PluralPaths<T, P extends string = \"\"> = {\n [K in keyof T & string]: T[K] extends string\n ? never\n : T[K] extends PluralMessage\n ? `${P}${K}`\n : PluralPaths<T[K], `${P}${K}.`>\n}[keyof T & string]\n\n/** Dotted key of any message, e.g. `subscriptions.title`. */\nexport type MessageKey = Paths<BillingUiMessages>\n\n/** Dotted key of a count-dependent message, e.g. `interval.every.day`. */\nexport type PluralKey = PluralPaths<BillingUiMessages>\n\nexport type MessageVars = Record<string, string | number>\n\n/**\n * Host translation hook. Receives the bare key (`subscriptions.title`,\n * `errors.not_found`); return nothing or the key itself to use ours.\n */\nexport type BillingUiTranslate = (\n key: string,\n vars?: MessageVars\n) => string | null | undefined\n\n/** Types a locale bundle or override against the message tree. */\nexport function defineMessages(\n bundle: BillingUiMessageBundle\n): BillingUiMessageBundle {\n return bundle\n}\n\nexport const defaultMessages: BillingUiMessages = en\n\ntype Tree = { [key: string]: string | Tree }\n\nfunction mergeInto(target: Tree, source: Tree): Tree {\n const out: Tree = { ...target }\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined || value === null) continue\n const current = out[key]\n if (typeof value === \"string\") {\n if (value !== \"\") out[key] = value\n } else if (typeof current === \"object\") {\n out[key] = mergeInto(current, value)\n } else {\n out[key] = mergeInto({}, value)\n }\n }\n return out\n}\n\n/** Layers bundles over English; later bundles win, missing keys fall back. */\nexport function resolveMessages(\n bundles?: BillingUiMessageBundle | readonly BillingUiMessageBundle[]\n): BillingUiMessages {\n const list = bundles ? (Array.isArray(bundles) ? bundles : [bundles]) : []\n let tree = en as unknown as Tree\n for (const bundle of list) tree = mergeInto(tree, bundle as Tree)\n return tree as unknown as BillingUiMessages\n}\n\nexport function interpolate(template: string, vars?: MessageVars): string {\n if (!vars) return template\n return template.replace(/\\{(\\w+)\\}/g, (match, name: string) =>\n name in vars ? String(vars[name]) : match\n )\n}\n\nfunction lookup(messages: BillingUiMessages, key: string): string | undefined {\n let node: unknown = messages\n for (const part of key.split(\".\")) {\n if (!node || typeof node !== \"object\") return undefined\n node = (node as Tree)[part]\n }\n return typeof node === \"string\" ? node : undefined\n}\n\nexport interface Translator {\n messages: BillingUiMessages\n /** BCP 47 tag used for plural rules and numbers; the runtime's when unset. */\n locale?: string\n t(key: MessageKey, vars?: MessageVars): string\n /**\n * Count-dependent message: tries `<key>.<count>`, then the locale's plural\n * category, then `<key>.other`. `{count}` is locale-formatted.\n */\n plural(key: PluralKey, count: number, vars?: MessageVars): string\n /** Message for a billing error, error code, or thrown value. */\n error(error: unknown, vars?: MessageVars): string\n}\n\nfunction errorCode(error: unknown): string | undefined {\n if (typeof error === \"string\") return error\n if (error && typeof error === \"object\" && \"code\" in error) {\n const code = (error as { code: unknown }).code\n if (typeof code === \"string\") return code\n }\n return undefined\n}\n\nfunction isNetworkError(error: unknown): boolean {\n return error instanceof TypeError && /fetch|network/i.test(error.message)\n}\n\nfunction pluralRules(locale?: string): Intl.PluralRules {\n try {\n return new Intl.PluralRules(locale)\n } catch {\n return new Intl.PluralRules(\"en\")\n }\n}\n\nfunction formatCount(count: number, locale?: string): string {\n try {\n return new Intl.NumberFormat(locale).format(count)\n } catch {\n return String(count)\n }\n}\n\nexport function createTranslator(\n messages: BillingUiMessages,\n hostT?: BillingUiTranslate,\n locale?: string\n): Translator {\n const rules = pluralRules(locale)\n const translate = (key: string, vars?: MessageVars): string | undefined => {\n const hosted = hostT?.(key, vars)\n if (hosted && hosted !== key) return hosted\n const own = lookup(messages, key)\n return own === undefined ? undefined : interpolate(own, vars)\n }\n return {\n messages,\n locale,\n t: (key, vars) => translate(key, vars) ?? key,\n plural(key, count, vars) {\n const all = { ...vars, count: formatCount(count, locale) }\n return (\n translate(`${key}.${count}`, all) ??\n translate(`${key}.${rules.select(count)}`, all) ??\n translate(`${key}.other`, all) ??\n key\n )\n },\n error(error, vars) {\n const code = errorCode(error)\n if (code && code !== \"generic\" && code !== \"network\") {\n const metadata =\n error && typeof error === \"object\" && \"metadata\" in error\n ? (error as { metadata?: MessageVars }).metadata\n : undefined\n const message = translate(`errors.${code}`, { ...metadata, ...vars })\n if (message) return message\n }\n const fallback = isNetworkError(error)\n ? \"errors.network\"\n : \"errors.generic\"\n return translate(fallback, vars) ?? messages.errors.generic\n },\n }\n}\n","import { createContext, useContext } from \"react\"\n\nimport {\n createTranslator,\n defaultMessages,\n type Translator,\n} from \"./messages.ts\"\n\nexport const MessagesContext = createContext<Translator>(\n createTranslator(defaultMessages)\n)\n\n/** English defaults when rendered outside a `BillingProvider`. */\nexport function useMessages(): Translator {\n return useContext(MessagesContext)\n}\n","// Integrator theming. The component scopes the standard shadcn token set\n// under its root, so `theme` flips the whole palette and `variables` override\n// individual tokens without the integrator touching our CSS.\nimport type { CSSProperties } from \"react\"\n\n// `inherit` uses the host page's shadcn tokens (`--background`, ...) and its\n// `.dark` class instead of the bundled zinc palette.\nexport type CheckoutTheme = \"light\" | \"dark\" | \"auto\" | \"inherit\"\n\n// The tokens integrators may override. Values are raw CSS color/length\n// strings; they land as custom properties on the checkout root.\nexport interface CheckoutVariables {\n background?: string\n foreground?: string\n card?: string\n mutedForeground?: string\n faintForeground?: string\n border?: string\n input?: string\n primary?: string\n primaryForeground?: string\n destructive?: string\n ring?: string\n radius?: string\n fontFamily?: string\n}\n\nexport interface CheckoutAppearance {\n theme?: CheckoutTheme\n variables?: CheckoutVariables\n}\n\nconst VARIABLE_TO_CSS: Record<keyof CheckoutVariables, string> = {\n background: \"--background\",\n foreground: \"--foreground\",\n card: \"--card\",\n mutedForeground: \"--muted-foreground\",\n faintForeground: \"--orck-faint\",\n border: \"--border\",\n input: \"--input\",\n primary: \"--primary\",\n primaryForeground: \"--primary-foreground\",\n destructive: \"--destructive\",\n ring: \"--ring\",\n radius: \"--radius\",\n fontFamily: \"--orck-font\",\n}\n\nexport function appearanceStyle(\n appearance: CheckoutAppearance | undefined\n): CSSProperties | undefined {\n const variables = appearance?.variables\n if (!variables) return undefined\n const style: Record<string, string> = {}\n for (const [key, value] of Object.entries(variables)) {\n if (!value) continue\n style[VARIABLE_TO_CSS[key as keyof CheckoutVariables]] = value\n }\n return style as CSSProperties\n}\n\nexport function appearanceTheme(\n appearance: CheckoutAppearance | undefined\n): CheckoutTheme {\n return appearance?.theme ?? \"auto\"\n}\n","import { createContext, useContext, type CSSProperties } from \"react\"\n\nimport {\n appearanceStyle,\n appearanceTheme,\n type CheckoutAppearance,\n type CheckoutTheme,\n} from \"./appearance\"\n\nexport type Navigate = (to: string) => void\n\nexport interface UiSettings {\n appearance?: CheckoutAppearance\n locale?: string\n navigate?: Navigate\n}\n\nexport const UiContext = createContext<UiSettings>({})\n\nexport const useUiSettings = (): UiSettings => useContext(UiContext)\n\nexport interface ScopeProps {\n className: string\n \"data-orck-theme\": CheckoutTheme\n style?: CSSProperties\n}\n\n/** Props that make an element a styling root; portals carry them too. */\nexport function useScopeProps(appearance?: CheckoutAppearance): ScopeProps {\n const settings = useUiSettings()\n const resolved = appearance ?? settings.appearance\n return {\n className: \"orck\",\n \"data-orck-theme\": appearanceTheme(resolved),\n style: appearanceStyle(resolved),\n }\n}\n","import { createContext, useContext } from \"react\"\n\nimport type { BillingClient } from \"../client/client\"\nimport type { CustomerConfig, 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 /** The shared `GET /me/config`; read it with `useCustomerConfig()`. */\n customerConfig: ConfigStore<CustomerConfig>\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 { useEffect, useMemo, useSyncExternalStore } from \"react\"\n\nimport { toBillingError, type BillingError } from \"../client/errors\"\nimport type {\n CurrencyScales,\n CustomerConfig,\n PublicConfig,\n} from \"../client/types\"\nimport { useBillingContext } from \"./context\"\n\nexport interface ConfigState<T = PublicConfig> {\n config: T | null\n loading: boolean\n error: BillingError | null\n refetch: () => void\n}\n\ninterface Snapshot<T> {\n config: T | null\n loading: boolean\n error: BillingError | null\n}\n\n/** One shared copy of a configuration read per client, fetched on first use. */\nexport interface ConfigStore<T = PublicConfig> {\n subscribe(listener: () => void): () => void\n snapshot(): Snapshot<T>\n /** Fetches the document unless it is loaded or loading. */\n ensure(): void\n refetch(): void\n}\n\nexport function createConfigStore<T>(read: () => Promise<T>): ConfigStore<T> {\n let snapshot: Snapshot<T> = { 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<T>) => {\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 read().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 // A read that failed with nothing loaded is tried again by the next\n // component: the customer may have signed in since.\n ensure() {\n if (!started || (snapshot.error && !snapshot.config && !snapshot.loading))\n load()\n },\n refetch: load,\n }\n}\n\nfunction useStore<T>(store: ConfigStore<T>): ConfigState<T> {\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 * The deployment's configuration (`GET /config`), fetched once per\n * `BillingProvider` and shared by every component that reads it.\n */\nexport function useConfig(): ConfigState {\n return useStore(useBillingContext().config)\n}\n\n/**\n * The customer's merchant (`GET /me/config`): its payment setup and how it\n * presents itself, fetched once per `BillingProvider` for the signed-in\n * customer and shared by every component that reads it.\n */\nexport function useCustomerConfig(): ConfigState<CustomerConfig> {\n return useStore(useBillingContext().customerConfig)\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","import {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ReactNode,\n} from \"react\"\n\nimport type { CheckoutAppearance } from \"../appearance\"\nimport type { BillingClient } from \"../client/client\"\nimport { MessagesContext } from \"../i18n/context\"\nimport {\n createTranslator,\n resolveMessages,\n type BillingUiMessageBundle,\n type BillingUiTranslate,\n} from \"../i18n/messages\"\nimport { UiContext, type Navigate } from \"../scope-context\"\nimport { createConfigStore } from \"./config\"\nimport { BillingContext, type BillingChange } from \"./context\"\n\nexport interface BillingProviderProps {\n /**\n * The customer's client: hooks and the account panels read it, and a\n * checkout saves a new card to the customer first. Leave it out where no\n * customer is signed in, such as the shared payment page.\n */\n client?: BillingClient\n /** Fires after each successful mutation: the host's cache-invalidation hook. */\n onChange?: (change: BillingChange) => void\n appearance?: CheckoutAppearance\n /** Locale bundle(s) layered over English; later entries win. */\n messages?: BillingUiMessageBundle | readonly BillingUiMessageBundle[]\n /** Host translation hook, consulted before the bundles. */\n t?: BillingUiTranslate\n /** BCP 47 tag for dates, money and plurals; defaults to the browser's. */\n locale?: string\n /** Host router for in-app links (e.g. the plans page). */\n navigate?: Navigate\n children?: ReactNode\n}\n\n/**\n * The one billing-ui provider: the client, and the appearance and words of\n * the styled components. Renders no DOM; surfaces create their own styling\n * roots, and no stylesheet loads until a styled component is imported.\n */\nexport function BillingProvider({\n client,\n onChange,\n appearance,\n messages,\n t,\n locale,\n navigate,\n children,\n}: BillingProviderProps) {\n const translator = useMemo(\n () => createTranslator(resolveMessages(messages), t, locale),\n [messages, t, locale]\n )\n const ui = useMemo(\n () => ({ appearance, locale, navigate }),\n [appearance, locale, navigate]\n )\n return (\n <UiContext.Provider value={ui}>\n <MessagesContext.Provider value={translator}>\n {client ? (\n <ClientProvider client={client} onChange={onChange}>\n {children}\n </ClientProvider>\n ) : (\n children\n )}\n </MessagesContext.Provider>\n </UiContext.Provider>\n )\n}\n\nfunction ClientProvider({\n client,\n onChange,\n children,\n}: {\n client: BillingClient\n onChange?: (change: BillingChange) => void\n children?: ReactNode\n}) {\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(\n () => createConfigStore(() => client.getConfig()),\n [client]\n )\n const customerConfig = useMemo(\n () => createConfigStore(() => client.getCustomerConfig()),\n [client]\n )\n const value = useMemo(\n () => ({ client, version, notify, refresh, config, customerConfig }),\n [client, version, notify, refresh, config, customerConfig]\n )\n return (\n <BillingContext.Provider value={value}>{children}</BillingContext.Provider>\n )\n}\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 ProductListOptions,\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 loading: boolean\n error: BillingError | null\n refetch: () => void\n}\n\n/** The merchant and its product keys to look up: `ProductListOptions`. */\nexport type ProductsOptions = Pick<ProductListOptions, \"merchant\" | \"keys\">\n\n/**\n * The products `merchant` has on sale named by `keys`, each with its active\n * prices: a public catalog lookup.\n */\nexport function useProducts({\n merchant,\n keys,\n}: ProductsOptions): ProductsState {\n const { client } = useBillingContext()\n const remote = useRemote(JSON.stringify([merchant, keys]), (signal) =>\n client.listProducts({ merchant, keys, signal })\n )\n return {\n products: remote.data?.data ?? 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"],"mappings":";;;;;AAmEA,SAAgB,EACd,GACwB;CACxB,OAAO;AACT;AAEA,IAAa,IAAqC;AAIlD,SAAS,EAAU,GAAc,GAAoB;CACnD,IAAM,IAAY,EAAE,GAAG,EAAO;CAC9B,KAAK,IAAM,CAAC,GAAK,MAAU,OAAO,QAAQ,CAAM,GAAG;EACjD,IAAI,KAAiC,MAAM;EAC3C,IAAM,IAAU,EAAI;EACpB,AAAI,OAAO,KAAU,WACf,MAAU,OAAI,EAAI,K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A;CACF;AACF;AAoBA,SAAgB,EAAY,IAA2B,CAAC,GAAkB;CACxE,IAAM,EAAE,WAAQ,eAAY,EAAkB,GACxC,IAAW,EAAQ,YAAY,IAE/B,IAAS,GAAG,EAAS,GAAG,EAAQ,QAAQ,MACxC,CAAC,GAAO,KAAY,EAAS;EACjC;EACA,SAAS,CAAC,IAAI;CAChB,CAAC,GACK,IAAU,QACP,EAAM,WAAW,IAAS,EAAM,UAAU,CAAC,IAAI,GACtD,CAAC,GAAO,CAAM,CAChB,GACM,IAAO,EAAQ,SAAS,GACxB,IAAS,EAAQ,IACjB,IAAS,EAAU,GAAG,EAAO,GAAG,KAAU,GAAG,GAAG,MAAY,MAChE,EAAO,aAAa;EAClB,OAAO;EACP;EACA,MAAM,EAAQ;EACd;CACF,CAAC,CACH,GACM,IAAO,EAAO,MACd,IAAa,GAAM,eAAe;CACxC,OAAO;EACL,UAAU,GAAM,QAAQ;EACxB;EACA,SAAS,MAAe;EACxB,SAAS,EAAO;EAChB,OAAO,EAAO;EACd,MAAM,QAAkB;GACtB,AAAI,MAAe,QACjB,EAAS;IAAE;IAAQ,SAAS,CAAC,GAAG,GAAS,CAAU;GAAE,CAAC;EAC1D,GAAG;GAAC;GAAQ;GAAS;EAAU,CAAC;EAChC,UAAU,QAAkB;GAC1B,AAAI,EAAQ,SAAS,KACnB,EAAS;IAAE;IAAQ,SAAS,EAAQ,MAAM,GAAG,EAAE;GAAE,CAAC;EACtD,GAAG,CAAC,GAAQ,CAAO,CAAC;EACpB,SAAS,EAAO;CAClB;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { createBillingClient, type BillingClient, type BillingClientOptions, type ProductListOptions, } from './client/client';
|
|
2
|
+
export { redeemAssertion, tokenSource, type RedeemAssertionOptions, type TokenResponse, type TokenSource, type TokenSourceOptions, } from './client/token-source';
|
|
2
3
|
export { BillingProvider, type BillingProviderProps } from './react/provider';
|
|
3
4
|
export { BillingUiRoot } from './scope';
|
|
4
5
|
export type { Navigate } from './scope-context';
|
|
@@ -10,7 +11,7 @@ export { SavePaymentMethod, type SavePaymentMethodProps, } from './save-payment-
|
|
|
10
11
|
export { OrderCheckout, type OrderCheckoutProps } from './order-checkout';
|
|
11
12
|
export { CHECKOUT_COMPLETE_MESSAGE, CHECKOUT_RESIZE_MESSAGE, EmbeddedCheckout, type EmbeddedCheckoutCompletion, type EmbeddedCheckoutProps, } from './embedded-checkout';
|
|
12
13
|
export { Cart, type CartProps } from './cart';
|
|
13
|
-
export {
|
|
14
|
+
export { authenticateChange } from './authenticate';
|
|
14
15
|
export { canAuthenticatePayment, canSavePaymentMethod, cardSetupDriver, checkoutPsps, pspConfigSchema, type CardSetupDriver, type PspConfig, } from './psp';
|
|
15
16
|
export { PaymentHistory, type PaymentHistoryProps, } from './account/payment-history';
|
|
16
17
|
export { BillingStatusBadge, type BillingStatusBadgeProps, } from './account/status-badge';
|