@usethrottle/cart 3.11.0 → 3.12.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/README.md CHANGED
@@ -66,8 +66,11 @@ All monetary values are integers in the smallest currency unit (cents for USD).
66
66
  `CartClient` carries a secret `sk_` key and must run on your server. For
67
67
  JAMstack / frontend-only storefronts that have no backend, use
68
68
  `CartSessionClient` instead — it creates and owns a Throttle cart directly from
69
- the browser, authorized by a publishable `pk_` quote token (the same token used
70
- by `StorefrontQuoteClient`) plus your application's origin allowlist.
69
+ the browser, authorized by a storefront quote token (`qt_…`, the same token used
70
+ by `StorefrontQuoteClient`) plus your application's origin allowlist. Quote
71
+ tokens minted before `qt_` start with `pk_` and keep working. A `pk_`
72
+ publishable API key is a different credential and is refused with
73
+ `401 invalid_quote_token`.
71
74
 
72
75
  Set your allowed origins first (`PUT /api/v1/embed-config`), then:
73
76
 
@@ -77,7 +80,7 @@ import { CartSessionClient } from '@usethrottle/cart';
77
80
  const cart = new CartSessionClient({
78
81
  applicationId: '7f9d4c8a-5b2e-4f16-9a73-2d1e5c8b6f40',
79
82
  environmentId: 'a1b2c3d4-...',
80
- quoteToken: 'pk_live_...',
83
+ quoteToken: 'qt_...',
81
84
  });
82
85
 
83
86
  // Create a new session (store cart.cartSessionId in localStorage),
@@ -171,8 +174,8 @@ const locked = await client.shippingTax.calculateCart(cart.id, {
171
174
  });
172
175
  ```
173
176
 
174
- External stores can also request read-only storefront quotes with a publishable
175
- `pk_` quote token. Create one from the dashboard Shipping & Tax page or with
177
+ External stores can also request read-only storefront quotes with a storefront
178
+ quote token (`qt_…`, or a legacy `pk_…` quote token). Create one from the dashboard Shipping & Tax page or with
176
179
  `POST /api/v1/shipping-tax/quote-tokens`.
177
180
 
178
181
  ```ts
@@ -180,7 +183,7 @@ import { StorefrontQuoteClient } from '@usethrottle/cart';
180
183
 
181
184
  const quotes = new StorefrontQuoteClient({
182
185
  applicationId: '7f9d4c8a-5b2e-4f16-9a73-2d1e5c8b6f40',
183
- quoteToken: 'pk_publishable_quote_token',
186
+ quoteToken: 'qt_storefront_quote_token',
184
187
  });
185
188
 
186
189
  const estimate = await quotes.quote({
package/dist/index.cjs CHANGED
@@ -287,7 +287,7 @@ var CartSessionClient = class _CartSessionClient {
287
287
  async create(input = {}) {
288
288
  if (this.isForSessionClient) {
289
289
  throw new Error(
290
- "CartSessionClient: this client was created with forSession() and cannot call create(). Construct a CartSessionClient with a real pk_ publishable token instead."
290
+ "CartSessionClient: this client was created with forSession() and cannot call create(). Construct a CartSessionClient with a real qt_ quote token instead."
291
291
  );
292
292
  }
293
293
  const data = await this.request("POST", "/api/v1/cart-sessions", {
@@ -352,7 +352,7 @@ var CartSessionClient = class _CartSessionClient {
352
352
  /**
353
353
  * Bind to an existing session without a publishable token.
354
354
  *
355
- * `create()` needs a `pk_` token; every other route is authorized by the
355
+ * `create()` needs a quote token; every other route is authorized by the
356
356
  * opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
357
357
  * hosted cart page, or a storefront restoring from localStorage — would
358
358
  * otherwise have to invent a token to satisfy the constructor.
package/dist/index.d.cts CHANGED
@@ -97,6 +97,19 @@ interface LineRecurringInput {
97
97
  intervalCount?: number;
98
98
  totalPayments?: number;
99
99
  trialDays?: number;
100
+ /**
101
+ * Custom installment schedule: 2-60 payments that differ in amount (per unit,
102
+ * minor units) and in the gap before each one. Row 0 has no gap. Replaces
103
+ * `interval`/`intervalUnit`/`intervalCount`/`totalPayments`/`trialDays`, which
104
+ * must be omitted or agree with it. The line's `unitPrice` must equal row 0.
105
+ */
106
+ schedule?: Array<{
107
+ amount: number;
108
+ intervalUnit?: SubscriptionIntervalUnit;
109
+ intervalCount?: number;
110
+ }>;
111
+ /** Read-only echo on responses: the sum of every row's per-unit amount. Ignored on input. */
112
+ scheduleUnitTotal?: number;
100
113
  }
101
114
  /** A merchant-declared subscription line's stored terms (it carries `plan`). */
102
115
  interface StoredLineRecurring {
@@ -111,6 +124,14 @@ interface StoredLineRecurring {
111
124
  amount: number | null;
112
125
  /** Display mirror of `totalPayments`. */
113
126
  count: number | null;
127
+ /** Present only on a custom installment schedule line. */
128
+ schedule?: Array<{
129
+ amount: number;
130
+ intervalUnit: string | null;
131
+ intervalCount: number | null;
132
+ }>;
133
+ /** Present only on a schedule line: the sum of every row's per-unit amount. */
134
+ scheduleUnitTotal?: number;
114
135
  }
115
136
  /** The plan line Throttle adds for a checkout session `recurring` intent. */
116
137
  interface LegacyLineRecurring {
@@ -506,8 +527,9 @@ declare class StorefrontQuoteClient {
506
527
  /**
507
528
  * Browser client for backend-less cart ownership. Unlike {@link CartClient}
508
529
  * (which needs a server-side `sk_` key), `CartSessionClient` runs in the browser:
509
- * it creates and mutates a Throttle cart authorized by a publishable quote token
510
- * (`pk_…`, the same token used by {@link StorefrontQuoteClient}) plus the
530
+ * it creates and mutates a Throttle cart authorized by a storefront quote token
531
+ * (`qt_…`, or a legacy `pk_…` quote token; the same token used by
532
+ * {@link StorefrontQuoteClient}, not a `pk_` publishable API key) plus the
511
533
  * application origin allowlist, and an opaque `cart_…` session id scoped to that
512
534
  * one cart.
513
535
  *
@@ -522,9 +544,14 @@ declare class StorefrontQuoteClient {
522
544
  interface CartSessionClientOptions {
523
545
  /** Application UUID. */
524
546
  applicationId: string;
525
- /** Workspace environment UUID the publishable token was minted for. */
547
+ /** Workspace environment UUID the quote token was minted for. */
526
548
  environmentId: string;
527
- /** Publishable storefront quote token (`pk_…`). */
549
+ /**
550
+ * Storefront quote token (`qt_…`), from the dashboard Shipping & Tax page or
551
+ * `POST /api/v1/shipping-tax/quote-tokens`. Tokens minted before `qt_` start
552
+ * with `pk_` and keep working. A `pk_` publishable API key is a different
553
+ * credential and is refused (`401 invalid_quote_token`).
554
+ */
528
555
  quoteToken: string;
529
556
  baseUrl?: string;
530
557
  fetch?: typeof globalThis.fetch;
@@ -644,7 +671,7 @@ declare class CartSessionClient {
644
671
  /**
645
672
  * Bind to an existing session without a publishable token.
646
673
  *
647
- * `create()` needs a `pk_` token; every other route is authorized by the
674
+ * `create()` needs a quote token; every other route is authorized by the
648
675
  * opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
649
676
  * hosted cart page, or a storefront restoring from localStorage — would
650
677
  * otherwise have to invent a token to satisfy the constructor.
package/dist/index.d.ts CHANGED
@@ -97,6 +97,19 @@ interface LineRecurringInput {
97
97
  intervalCount?: number;
98
98
  totalPayments?: number;
99
99
  trialDays?: number;
100
+ /**
101
+ * Custom installment schedule: 2-60 payments that differ in amount (per unit,
102
+ * minor units) and in the gap before each one. Row 0 has no gap. Replaces
103
+ * `interval`/`intervalUnit`/`intervalCount`/`totalPayments`/`trialDays`, which
104
+ * must be omitted or agree with it. The line's `unitPrice` must equal row 0.
105
+ */
106
+ schedule?: Array<{
107
+ amount: number;
108
+ intervalUnit?: SubscriptionIntervalUnit;
109
+ intervalCount?: number;
110
+ }>;
111
+ /** Read-only echo on responses: the sum of every row's per-unit amount. Ignored on input. */
112
+ scheduleUnitTotal?: number;
100
113
  }
101
114
  /** A merchant-declared subscription line's stored terms (it carries `plan`). */
102
115
  interface StoredLineRecurring {
@@ -111,6 +124,14 @@ interface StoredLineRecurring {
111
124
  amount: number | null;
112
125
  /** Display mirror of `totalPayments`. */
113
126
  count: number | null;
127
+ /** Present only on a custom installment schedule line. */
128
+ schedule?: Array<{
129
+ amount: number;
130
+ intervalUnit: string | null;
131
+ intervalCount: number | null;
132
+ }>;
133
+ /** Present only on a schedule line: the sum of every row's per-unit amount. */
134
+ scheduleUnitTotal?: number;
114
135
  }
115
136
  /** The plan line Throttle adds for a checkout session `recurring` intent. */
116
137
  interface LegacyLineRecurring {
@@ -506,8 +527,9 @@ declare class StorefrontQuoteClient {
506
527
  /**
507
528
  * Browser client for backend-less cart ownership. Unlike {@link CartClient}
508
529
  * (which needs a server-side `sk_` key), `CartSessionClient` runs in the browser:
509
- * it creates and mutates a Throttle cart authorized by a publishable quote token
510
- * (`pk_…`, the same token used by {@link StorefrontQuoteClient}) plus the
530
+ * it creates and mutates a Throttle cart authorized by a storefront quote token
531
+ * (`qt_…`, or a legacy `pk_…` quote token; the same token used by
532
+ * {@link StorefrontQuoteClient}, not a `pk_` publishable API key) plus the
511
533
  * application origin allowlist, and an opaque `cart_…` session id scoped to that
512
534
  * one cart.
513
535
  *
@@ -522,9 +544,14 @@ declare class StorefrontQuoteClient {
522
544
  interface CartSessionClientOptions {
523
545
  /** Application UUID. */
524
546
  applicationId: string;
525
- /** Workspace environment UUID the publishable token was minted for. */
547
+ /** Workspace environment UUID the quote token was minted for. */
526
548
  environmentId: string;
527
- /** Publishable storefront quote token (`pk_…`). */
549
+ /**
550
+ * Storefront quote token (`qt_…`), from the dashboard Shipping & Tax page or
551
+ * `POST /api/v1/shipping-tax/quote-tokens`. Tokens minted before `qt_` start
552
+ * with `pk_` and keep working. A `pk_` publishable API key is a different
553
+ * credential and is refused (`401 invalid_quote_token`).
554
+ */
528
555
  quoteToken: string;
529
556
  baseUrl?: string;
530
557
  fetch?: typeof globalThis.fetch;
@@ -644,7 +671,7 @@ declare class CartSessionClient {
644
671
  /**
645
672
  * Bind to an existing session without a publishable token.
646
673
  *
647
- * `create()` needs a `pk_` token; every other route is authorized by the
674
+ * `create()` needs a quote token; every other route is authorized by the
648
675
  * opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
649
676
  * hosted cart page, or a storefront restoring from localStorage — would
650
677
  * otherwise have to invent a token to satisfy the constructor.
package/dist/index.js CHANGED
@@ -252,7 +252,7 @@ var CartSessionClient = class _CartSessionClient {
252
252
  async create(input = {}) {
253
253
  if (this.isForSessionClient) {
254
254
  throw new Error(
255
- "CartSessionClient: this client was created with forSession() and cannot call create(). Construct a CartSessionClient with a real pk_ publishable token instead."
255
+ "CartSessionClient: this client was created with forSession() and cannot call create(). Construct a CartSessionClient with a real qt_ quote token instead."
256
256
  );
257
257
  }
258
258
  const data = await this.request("POST", "/api/v1/cart-sessions", {
@@ -317,7 +317,7 @@ var CartSessionClient = class _CartSessionClient {
317
317
  /**
318
318
  * Bind to an existing session without a publishable token.
319
319
  *
320
- * `create()` needs a `pk_` token; every other route is authorized by the
320
+ * `create()` needs a quote token; every other route is authorized by the
321
321
  * opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
322
322
  * hosted cart page, or a storefront restoring from localStorage — would
323
323
  * otherwise have to invent a token to satisfy the constructor.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usethrottle/cart",
3
- "version": "3.11.0",
3
+ "version": "3.12.0",
4
4
  "description": "Typed REST client for the Throttle Cart API.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",