@openrails/billing-ui 0.236.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +87 -9
  2. package/README.md +78 -83
  3. package/dist/account/account-billing.d.ts +1 -1
  4. package/dist/account/payment-methods-panel.d.ts +2 -2
  5. package/dist/authenticate.d.ts +5 -4
  6. package/dist/buy-button.d.ts +17 -10
  7. package/dist/client/client.d.ts +52 -23
  8. package/dist/client/generated/error-codes.d.ts +1 -1
  9. package/dist/client/generated/routes.d.ts +24 -218
  10. package/dist/client/generated/wire.d.ts +39 -200
  11. package/dist/client/index.d.ts +2 -1
  12. package/dist/client/token-source.d.ts +60 -0
  13. package/dist/client/types.d.ts +108 -199
  14. package/dist/client-Bi_lP_M0.js +932 -0
  15. package/dist/client-Bi_lP_M0.js.map +1 -0
  16. package/dist/client.js +2 -2
  17. package/dist/components/eyebrow.d.ts +5 -0
  18. package/dist/embedded-checkout.d.ts +22 -0
  19. package/dist/{hooks-2d-XjpuI.js → hooks-Bk80rNv8.js} +99 -90
  20. package/dist/hooks-Bk80rNv8.js.map +1 -0
  21. package/dist/index.d.ts +5 -8
  22. package/dist/index.js +1149 -2163
  23. package/dist/index.js.map +1 -1
  24. package/dist/modal.d.ts +3 -9
  25. package/dist/offers.d.ts +10 -9
  26. package/dist/psp.d.ts +0 -8
  27. package/dist/react/config.d.ts +17 -12
  28. package/dist/react/context.d.ts +3 -1
  29. package/dist/react/hooks.d.ts +5 -5
  30. package/dist/react/index.d.ts +1 -1
  31. package/dist/react.js +2 -2
  32. package/dist/styles.css +1 -1
  33. package/dist/tokenized-card-form.d.ts +5 -1
  34. package/dist/types.d.ts +12 -250
  35. package/docs/payment-form-contract.md +31 -74
  36. package/package.json +1 -2
  37. package/dist/checkout-frame.d.ts +0 -17
  38. package/dist/checkout-page.d.ts +0 -21
  39. package/dist/checkout.d.ts +0 -22
  40. package/dist/client/checkout.d.ts +0 -28
  41. package/dist/client-BuvolBPT.js +0 -1092
  42. package/dist/client-BuvolBPT.js.map +0 -1
  43. package/dist/components/ccbill-fields.d.ts +0 -8
  44. package/dist/components/methods.d.ts +0 -13
  45. package/dist/components/summary.d.ts +0 -12
  46. package/dist/fixtures.d.ts +0 -9
  47. package/dist/frame.d.ts +0 -47
  48. package/dist/hooks-2d-XjpuI.js.map +0 -1
  49. package/dist/lib/rail-meta.d.ts +0 -15
  50. package/dist/lib/redirect.d.ts +0 -2
  51. package/dist/source.d.ts +0 -5
package/dist/modal.d.ts CHANGED
@@ -1,12 +1,6 @@
1
- import { CheckoutProps } from './checkout';
2
- import * as React from "react";
3
- export interface CheckoutModalProps extends CheckoutProps {
1
+ import { OrderCheckoutProps } from './order-checkout';
2
+ export interface OrderModalProps extends OrderCheckoutProps {
4
3
  open: boolean;
5
4
  onOpenChange: (open: boolean) => void;
6
- /**
7
- * Rendered instead of the checkout while set, e.g. the host's sign-in.
8
- * Clear it to continue to payment in the same modal.
9
- */
10
- gate?: React.ReactNode;
11
5
  }
12
- export declare function CheckoutModal({ open, onOpenChange, onPhaseChange, gate, ...checkoutProps }: CheckoutModalProps): React.JSX.Element;
6
+ export declare function OrderModal({ open, onOpenChange, ...checkout }: OrderModalProps): import("react").JSX.Element;
package/dist/offers.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { CheckoutAppearance } from './appearance';
2
- import { Product } from './client/types';
3
- import { PayResult } from './types';
2
+ import { Order, Product } from './client/types';
4
3
  import * as React from "react";
5
4
  export interface OffersProps {
5
+ /** The id of the merchant whose catalog `keys` are looked up in. */
6
+ merchant?: string;
6
7
  /**
7
- * What to sell: these product keys, such as a course, its bundle and the
8
- * membership that also unlocks it, looked up in OpenRails' public catalog.
9
- * The host's server names them (the Go Client's ListOffers finds the
10
- * products granting an entitlement).
8
+ * What to sell: these product keys of `merchant`, such as a course, its
9
+ * bundle and the membership that also unlocks it, looked up in OpenRails'
10
+ * public catalog. The host's server names them (the Go Client's
11
+ * ListOffers finds the products granting an entitlement).
11
12
  */
12
13
  keys?: string[];
13
14
  /**
@@ -16,10 +17,10 @@ export interface OffersProps {
16
17
  */
17
18
  products?: Product[];
18
19
  /**
19
- * The checkout succeeded. A hint: the host's own gate decides access, so
20
- * send the buyer back to the content it guards.
20
+ * The order is paid. A hint: the host's own gate decides access, so send
21
+ * the buyer back to the content it guards.
21
22
  */
22
- onPaid: (result: PayResult) => void;
23
+ onPaid: (order: Order) => void;
23
24
  /**
24
25
  * Buying needs a signed-in customer: called instead of the checkout when
25
26
  * `signedIn` is false or OpenRails answers 401.
package/dist/psp.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import { z } from 'zod';
2
- import { PaymentMethod } from './client/types';
3
- import { PaymentOption, SavedPaymentMethod } from './types';
4
2
  export declare const pspConfigSchema: z.ZodObject<{
5
3
  psp_id: z.ZodString;
6
4
  key: z.ZodString;
@@ -14,8 +12,6 @@ export declare const pspConfigSchema: z.ZodObject<{
14
12
  retry_after: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
15
13
  }, z.core.$strip>;
16
14
  export type PspConfig = z.infer<typeof pspConfigSchema>;
17
- /** Whether a rail takes a card in the page (saved or new). */
18
- export declare const isCardRail: (rail: PaymentOption) => boolean;
19
15
  /** PSPs that take new purchases and new cards. */
20
16
  export declare const checkoutPsps: (psps: readonly PspConfig[]) => PspConfig[];
21
17
  /**
@@ -23,13 +19,9 @@ export declare const checkoutPsps: (psps: readonly PspConfig[]) => PspConfig[];
23
19
  * for again; null when none is.
24
20
  */
25
21
  export declare function cardRetryAfter(psps: readonly PspConfig[]): number | null;
26
- /** Saved cards the checkout can charge in place, for the given rails, newest first. */
27
- export declare function savedMethodsFor(methods: readonly PaymentMethod[], rails: readonly PaymentOption[]): SavedPaymentMethod[];
28
22
  export type CardSetupDriver = "collect_js" | "card" | "stripe_elements";
29
23
  /** How a card is saved with this PSP in the page, or null when it cannot be. */
30
24
  export declare function cardSetupDriver(psp: PspConfig): CardSetupDriver | null;
31
25
  export declare const canSavePaymentMethod: (psp: PspConfig) => boolean;
32
26
  /** Whether a pending payment on this PSP can be authenticated in the page. */
33
27
  export declare const canAuthenticatePayment: (psp: PspConfig) => boolean;
34
- /** The PSP config behind a checkout rail, for card setup and authentication. */
35
- export declare function railPsp(rail: PaymentOption): PspConfig;
@@ -1,31 +1,36 @@
1
- import { BillingClient } from '../client/client';
2
1
  import { BillingError } from '../client/errors';
3
- import { CurrencyScales, PublicConfig } from '../client/types';
4
- export interface ConfigState {
5
- config: PublicConfig | null;
2
+ import { CurrencyScales, CustomerConfig, PublicConfig } from '../client/types';
3
+ export interface ConfigState<T = PublicConfig> {
4
+ config: T | null;
6
5
  loading: boolean;
7
6
  error: BillingError | null;
8
7
  refetch: () => void;
9
8
  }
10
- interface Snapshot {
11
- config: PublicConfig | null;
9
+ interface Snapshot<T> {
10
+ config: T | null;
12
11
  loading: boolean;
13
12
  error: BillingError | null;
14
13
  }
15
- /** One shared copy of `GET /config` per client, fetched on first use. */
16
- export interface ConfigStore {
14
+ /** One shared copy of a configuration read per client, fetched on first use. */
15
+ export interface ConfigStore<T = PublicConfig> {
17
16
  subscribe(listener: () => void): () => void;
18
- snapshot(): Snapshot;
19
- /** Fetches the document unless it was already requested. */
17
+ snapshot(): Snapshot<T>;
18
+ /** Fetches the document unless it is loaded or loading. */
20
19
  ensure(): void;
21
20
  refetch(): void;
22
21
  }
23
- export declare function createConfigStore(client: BillingClient): ConfigStore;
22
+ export declare function createConfigStore<T>(read: () => Promise<T>): ConfigStore<T>;
24
23
  /**
25
- * The deployment's public configuration (`GET /config`), fetched once per
24
+ * The deployment's configuration (`GET /config`), fetched once per
26
25
  * `BillingProvider` and shared by every component that reads it.
27
26
  */
28
27
  export declare function useConfig(): ConfigState;
28
+ /**
29
+ * The customer's merchant (`GET /me/config`): its payment setup and how it
30
+ * presents itself, fetched once per `BillingProvider` for the signed-in
31
+ * customer and shared by every component that reads it.
32
+ */
33
+ export declare function useCustomerConfig(): ConfigState<CustomerConfig>;
29
34
  /**
30
35
  * Currency scales: the server's registry, under the client's pinned copy and
31
36
  * host overrides, which stand alone until the registry loads.
@@ -1,5 +1,5 @@
1
1
  import { BillingClient } from '../client/client';
2
- import { SubscriptionChange } from '../client/types';
2
+ import { CustomerConfig, SubscriptionChange } from '../client/types';
3
3
  import { ConfigStore } from './config';
4
4
  export type BillingChange = {
5
5
  type: "subscription.canceled" | "subscription.resumed";
@@ -27,6 +27,8 @@ export interface BillingContextValue {
27
27
  refresh(): void;
28
28
  /** The shared `GET /config`; read it with `useConfig()`. */
29
29
  config: ConfigStore;
30
+ /** The shared `GET /me/config`; read it with `useCustomerConfig()`. */
31
+ customerConfig: ConfigStore<CustomerConfig>;
30
32
  }
31
33
  export declare const BillingContext: import('react').Context<BillingContextValue | null>;
32
34
  export declare function useBillingContext(): BillingContextValue;
@@ -43,13 +43,13 @@ export interface ProductsState {
43
43
  error: BillingError | null;
44
44
  refetch: () => void;
45
45
  }
46
- /** The product keys to look up: `ProductListOptions`. */
47
- export type ProductsOptions = Pick<ProductListOptions, "keys">;
46
+ /** The merchant and its product keys to look up: `ProductListOptions`. */
47
+ export type ProductsOptions = Pick<ProductListOptions, "merchant" | "keys">;
48
48
  /**
49
- * The products on sale named by `keys`, each with its active prices: a
50
- * public catalog lookup.
49
+ * The products `merchant` has on sale named by `keys`, each with its active
50
+ * prices: a public catalog lookup.
51
51
  */
52
- export declare function useProducts({ keys }: ProductsOptions): ProductsState;
52
+ export declare function useProducts({ merchant, keys, }: ProductsOptions): ProductsState;
53
53
  export type PaymentMethodAction = "remove" | "default";
54
54
  export interface PaymentMethodsState {
55
55
  methods: PaymentMethod[] | null;
@@ -1,4 +1,4 @@
1
1
  export { BillingProvider, type BillingProviderProps } from './provider';
2
2
  export { useBillingClient, useBillingRefresh, useOptionalBillingContext, type BillingChange, type BillingContextValue, } from './context';
3
- export { useConfig, useCurrencyScales, type ConfigState, type ConfigStore, } from './config';
3
+ export { useConfig, useCurrencyScales, useCustomerConfig, type ConfigState, type ConfigStore, } from './config';
4
4
  export { usePaymentMethods, usePayments, useProducts, useSubscriptions, type ActionResult, type PaymentMethodAction, type PaymentMethodsState, type PaymentsOptions, type PaymentsState, type ProductsOptions, type ProductsState, type SubscriptionAction, type SubscriptionsOptions, type SubscriptionsState, } from './hooks';
package/dist/react.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, i as r, n as i, o as a, r as o, s, t as c, u as l } from "./hooks-2d-XjpuI.js";
2
- export { e as BillingProvider, t as useBillingClient, l as useBillingRefresh, a as useConfig, s as useCurrencyScales, n as useOptionalBillingContext, c as usePaymentMethods, i as usePayments, o as useProducts, r as useSubscriptions };
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u } from "./hooks-Bk80rNv8.js";
2
+ export { e as BillingProvider, a as useBillingClient, n as useBillingRefresh, s as useConfig, l as useCurrencyScales, t as useCustomerConfig, r as useOptionalBillingContext, u as usePaymentMethods, o as usePayments, c as useProducts, i as useSubscriptions };