@usethrottle/cart 3.10.1 → 3.11.1
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 +42 -17
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +69 -24
- package/dist/index.d.ts +69 -24
- package/dist/index.js +2 -2
- package/package.json +2 -2
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
|
|
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: '
|
|
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
|
|
175
|
-
`pk_
|
|
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: '
|
|
186
|
+
quoteToken: 'qt_storefront_quote_token',
|
|
184
187
|
});
|
|
185
188
|
|
|
186
189
|
const estimate = await quotes.quote({
|
|
@@ -222,23 +225,45 @@ await client.shippingTax.pushExternalSnapshot({
|
|
|
222
225
|
|
|
223
226
|
## Subscriptions
|
|
224
227
|
|
|
225
|
-
|
|
228
|
+
Put `recurring` on a line to make it a subscription. A cart can hold any
|
|
229
|
+
number of one-time lines and up to 10 subscription lines, with the same plan
|
|
230
|
+
or different ones. The whole cart is paid in one capture, with one shipping
|
|
231
|
+
fee, and completes as one order linked to every subscription it created.
|
|
226
232
|
|
|
227
233
|
```ts
|
|
234
|
+
await client.items.add(cart.id, { name: 'Coffee kit', unitPrice: 4500, quantity: 1 });
|
|
228
235
|
await client.items.add(cart.id, {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
name: 'Barista Club',
|
|
237
|
+
unitPrice: 2000, // per period, per seat
|
|
238
|
+
quantity: 2, // seats
|
|
239
|
+
recurring: { plan: 'club_monthly', interval: 'monthly', trialDays: 14 },
|
|
233
240
|
});
|
|
234
241
|
```
|
|
235
242
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
243
|
+
- `interval` (`weekly`, `biweekly`, `monthly`, `quarterly`, `yearly`), or
|
|
244
|
+
`intervalUnit` (`hour`, `day`, `week`, `month`) + `intervalCount`: 1 hour
|
|
245
|
+
to 1 year.
|
|
246
|
+
- `totalPayments` (2–60) makes an installment plan; `trialDays` (0–365) a free
|
|
247
|
+
trial. They cannot be combined (`400 invalid_combination`).
|
|
248
|
+
- `type` is forced to `subscription`, and the line never ships:
|
|
249
|
+
`requiresShipping: true` is rejected with `400 validation_error`.
|
|
250
|
+
- A free-trial line is stored with `unitPrice: 0` and your price on
|
|
251
|
+
`recurring.amount`, and its name gets a "— 14-day free trial" suffix.
|
|
252
|
+
- `PATCH` may change `quantity` (seats) and `metadata` only. Changing
|
|
253
|
+
`unitPrice`, `taxAmount` or `discountAmount` is `422 recurring_line_immutable`.
|
|
254
|
+
Remove the line and add it again to change its terms.
|
|
255
|
+
- Each line's `subscriptionId` is set when the checkout completes.
|
|
256
|
+
|
|
257
|
+
| Status | Code | When |
|
|
258
|
+
|---|---|---|
|
|
259
|
+
| 422 | `too_many_subscriptions` | An 11th subscription line |
|
|
260
|
+
| 422 | `recurring_not_supported_for_cart` | The cart is managed by an external cart provider |
|
|
261
|
+
| 422 | `recurring_line_immutable` | A PATCH changes a subscription line's price, tax or discount |
|
|
262
|
+
| 400 | `invalid_line_item` | A free-trial line carries `taxAmount` or `discountAmount` |
|
|
263
|
+
| 400 | `invalid_interval` / `interval_conflict` / `invalid_total_payments` / `invalid_combination` / `invalid_plan` / `invalid_trial_days` | Terms out of range |
|
|
264
|
+
|
|
265
|
+
Do not also send a session `recurring` intent for the same cart. The two are
|
|
266
|
+
exclusive, and session creation answers `422 recurring_source_conflict`.
|
|
242
267
|
|
|
243
268
|
## Events
|
|
244
269
|
|
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
|
|
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
|
|
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
|
@@ -79,6 +79,47 @@ interface CartSessionCart extends Omit<Cart, 'workspaceId'> {
|
|
|
79
79
|
*/
|
|
80
80
|
unitCount: number;
|
|
81
81
|
}
|
|
82
|
+
type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';
|
|
83
|
+
type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';
|
|
84
|
+
/**
|
|
85
|
+
* Terms that make a cart line a subscription. One subscription is created per
|
|
86
|
+
* line when the checkout completes, with `quantity` as seats; at most 10 per
|
|
87
|
+
* cart. Send `interval`, or `intervalUnit` + `intervalCount` (1 hour to 1
|
|
88
|
+
* year). `totalPayments` (2-60) makes an installment plan; `trialDays`
|
|
89
|
+
* (0-365) a free trial, not combinable with `totalPayments`. The line's
|
|
90
|
+
* `unitPrice` is the per-period price per seat.
|
|
91
|
+
*/
|
|
92
|
+
interface LineRecurringInput {
|
|
93
|
+
plan: string;
|
|
94
|
+
planName?: string;
|
|
95
|
+
interval?: SubscriptionInterval;
|
|
96
|
+
intervalUnit?: SubscriptionIntervalUnit;
|
|
97
|
+
intervalCount?: number;
|
|
98
|
+
totalPayments?: number;
|
|
99
|
+
trialDays?: number;
|
|
100
|
+
}
|
|
101
|
+
/** A merchant-declared subscription line's stored terms (it carries `plan`). */
|
|
102
|
+
interface StoredLineRecurring {
|
|
103
|
+
plan: string;
|
|
104
|
+
planName: string | null;
|
|
105
|
+
interval: string;
|
|
106
|
+
intervalUnit: string;
|
|
107
|
+
intervalCount: number;
|
|
108
|
+
totalPayments: number | null;
|
|
109
|
+
trialDays: number;
|
|
110
|
+
/** Renewal price per seat. Set only on a free-trial line, whose `unitPrice` is 0. */
|
|
111
|
+
amount: number | null;
|
|
112
|
+
/** Display mirror of `totalPayments`. */
|
|
113
|
+
count: number | null;
|
|
114
|
+
}
|
|
115
|
+
/** The plan line Throttle adds for a checkout session `recurring` intent. */
|
|
116
|
+
interface LegacyLineRecurring {
|
|
117
|
+
interval: string;
|
|
118
|
+
intervalUnit?: string | null;
|
|
119
|
+
intervalCount?: number | null;
|
|
120
|
+
/** Display metadata: the number of payments to show. Not enforced. */
|
|
121
|
+
count: number | null;
|
|
122
|
+
}
|
|
82
123
|
interface LineItem {
|
|
83
124
|
id: string;
|
|
84
125
|
cartId: string;
|
|
@@ -93,16 +134,13 @@ interface LineItem {
|
|
|
93
134
|
discountAmount: number;
|
|
94
135
|
total: number;
|
|
95
136
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* `
|
|
137
|
+
* Subscription terms. `'plan' in recurring` tells a merchant-declared
|
|
138
|
+
* subscription line (`StoredLineRecurring`) from the plan line a checkout
|
|
139
|
+
* session adds (`LegacyLineRecurring`). Null on a one-time line.
|
|
99
140
|
*/
|
|
100
|
-
recurring:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
intervalUnit?: string | null;
|
|
104
|
-
intervalCount?: number | null;
|
|
105
|
-
} | null;
|
|
141
|
+
recurring: StoredLineRecurring | LegacyLineRecurring | null;
|
|
142
|
+
/** The subscription this line created. Null until the checkout completes. */
|
|
143
|
+
subscriptionId: string | null;
|
|
106
144
|
imageUrl: string | null;
|
|
107
145
|
position: number;
|
|
108
146
|
metadata: Record<string, unknown>;
|
|
@@ -181,16 +219,12 @@ interface AddLineItemInput {
|
|
|
181
219
|
taxAmount?: number;
|
|
182
220
|
discountAmount?: number;
|
|
183
221
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* `
|
|
222
|
+
* Makes this line a subscription: `type` is forced to `subscription`, and it
|
|
223
|
+
* never ships (`requiresShipping: true` is rejected with it). A free-trial
|
|
224
|
+
* line is stored with `unitPrice` 0 and your price on `recurring.amount`.
|
|
225
|
+
* Terms cannot change later: remove the line and add it again.
|
|
187
226
|
*/
|
|
188
|
-
recurring?:
|
|
189
|
-
interval: string;
|
|
190
|
-
count: number | null;
|
|
191
|
-
intervalUnit?: string | null;
|
|
192
|
-
intervalCount?: number | null;
|
|
193
|
-
} | null;
|
|
227
|
+
recurring?: LineRecurringInput;
|
|
194
228
|
imageUrl?: string;
|
|
195
229
|
/**
|
|
196
230
|
* Whether this item is physically shippable. For external/ad-hoc catalogs
|
|
@@ -201,6 +235,11 @@ interface AddLineItemInput {
|
|
|
201
235
|
requiresShipping?: boolean;
|
|
202
236
|
metadata?: Record<string, unknown>;
|
|
203
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* On a subscription line only `quantity` (seats) and `metadata` may change;
|
|
240
|
+
* a different `unitPrice`, `taxAmount` or `discountAmount` is
|
|
241
|
+
* 422 `recurring_line_immutable`.
|
|
242
|
+
*/
|
|
204
243
|
interface UpdateLineItemInput {
|
|
205
244
|
quantity?: number;
|
|
206
245
|
unitPrice?: number;
|
|
@@ -467,8 +506,9 @@ declare class StorefrontQuoteClient {
|
|
|
467
506
|
/**
|
|
468
507
|
* Browser client for backend-less cart ownership. Unlike {@link CartClient}
|
|
469
508
|
* (which needs a server-side `sk_` key), `CartSessionClient` runs in the browser:
|
|
470
|
-
* it creates and mutates a Throttle cart authorized by a
|
|
471
|
-
* (`
|
|
509
|
+
* it creates and mutates a Throttle cart authorized by a storefront quote token
|
|
510
|
+
* (`qt_…`, or a legacy `pk_…` quote token; the same token used by
|
|
511
|
+
* {@link StorefrontQuoteClient}, not a `pk_` publishable API key) plus the
|
|
472
512
|
* application origin allowlist, and an opaque `cart_…` session id scoped to that
|
|
473
513
|
* one cart.
|
|
474
514
|
*
|
|
@@ -483,9 +523,14 @@ declare class StorefrontQuoteClient {
|
|
|
483
523
|
interface CartSessionClientOptions {
|
|
484
524
|
/** Application UUID. */
|
|
485
525
|
applicationId: string;
|
|
486
|
-
/** Workspace environment UUID the
|
|
526
|
+
/** Workspace environment UUID the quote token was minted for. */
|
|
487
527
|
environmentId: string;
|
|
488
|
-
/**
|
|
528
|
+
/**
|
|
529
|
+
* Storefront quote token (`qt_…`), from the dashboard Shipping & Tax page or
|
|
530
|
+
* `POST /api/v1/shipping-tax/quote-tokens`. Tokens minted before `qt_` start
|
|
531
|
+
* with `pk_` and keep working. A `pk_` publishable API key is a different
|
|
532
|
+
* credential and is refused (`401 invalid_quote_token`).
|
|
533
|
+
*/
|
|
489
534
|
quoteToken: string;
|
|
490
535
|
baseUrl?: string;
|
|
491
536
|
fetch?: typeof globalThis.fetch;
|
|
@@ -605,7 +650,7 @@ declare class CartSessionClient {
|
|
|
605
650
|
/**
|
|
606
651
|
* Bind to an existing session without a publishable token.
|
|
607
652
|
*
|
|
608
|
-
* `create()` needs a
|
|
653
|
+
* `create()` needs a quote token; every other route is authorized by the
|
|
609
654
|
* opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
|
|
610
655
|
* hosted cart page, or a storefront restoring from localStorage — would
|
|
611
656
|
* otherwise have to invent a token to satisfy the constructor.
|
|
@@ -705,4 +750,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
705
750
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
706
751
|
}): ThrottleApiError;
|
|
707
752
|
|
|
708
|
-
export { type AddLineItemInput, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartClient, type CartEvent, CartNotFoundError, CartNotOpenError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, type ExternalShippingTaxSnapshotInput, type LineItem, type Order, type SelectShippingInput, type SelectedShipping, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, StorefrontQuoteClient, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
|
|
753
|
+
export { type AddLineItemInput, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartClient, type CartEvent, CartNotFoundError, CartNotOpenError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineRecurringInput, type Order, type SelectShippingInput, type SelectedShipping, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, type StoredLineRecurring, StorefrontQuoteClient, type SubscriptionInterval, type SubscriptionIntervalUnit, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,47 @@ interface CartSessionCart extends Omit<Cart, 'workspaceId'> {
|
|
|
79
79
|
*/
|
|
80
80
|
unitCount: number;
|
|
81
81
|
}
|
|
82
|
+
type SubscriptionInterval = 'weekly' | 'biweekly' | 'monthly' | 'quarterly' | 'yearly' | 'custom';
|
|
83
|
+
type SubscriptionIntervalUnit = 'hour' | 'day' | 'week' | 'month';
|
|
84
|
+
/**
|
|
85
|
+
* Terms that make a cart line a subscription. One subscription is created per
|
|
86
|
+
* line when the checkout completes, with `quantity` as seats; at most 10 per
|
|
87
|
+
* cart. Send `interval`, or `intervalUnit` + `intervalCount` (1 hour to 1
|
|
88
|
+
* year). `totalPayments` (2-60) makes an installment plan; `trialDays`
|
|
89
|
+
* (0-365) a free trial, not combinable with `totalPayments`. The line's
|
|
90
|
+
* `unitPrice` is the per-period price per seat.
|
|
91
|
+
*/
|
|
92
|
+
interface LineRecurringInput {
|
|
93
|
+
plan: string;
|
|
94
|
+
planName?: string;
|
|
95
|
+
interval?: SubscriptionInterval;
|
|
96
|
+
intervalUnit?: SubscriptionIntervalUnit;
|
|
97
|
+
intervalCount?: number;
|
|
98
|
+
totalPayments?: number;
|
|
99
|
+
trialDays?: number;
|
|
100
|
+
}
|
|
101
|
+
/** A merchant-declared subscription line's stored terms (it carries `plan`). */
|
|
102
|
+
interface StoredLineRecurring {
|
|
103
|
+
plan: string;
|
|
104
|
+
planName: string | null;
|
|
105
|
+
interval: string;
|
|
106
|
+
intervalUnit: string;
|
|
107
|
+
intervalCount: number;
|
|
108
|
+
totalPayments: number | null;
|
|
109
|
+
trialDays: number;
|
|
110
|
+
/** Renewal price per seat. Set only on a free-trial line, whose `unitPrice` is 0. */
|
|
111
|
+
amount: number | null;
|
|
112
|
+
/** Display mirror of `totalPayments`. */
|
|
113
|
+
count: number | null;
|
|
114
|
+
}
|
|
115
|
+
/** The plan line Throttle adds for a checkout session `recurring` intent. */
|
|
116
|
+
interface LegacyLineRecurring {
|
|
117
|
+
interval: string;
|
|
118
|
+
intervalUnit?: string | null;
|
|
119
|
+
intervalCount?: number | null;
|
|
120
|
+
/** Display metadata: the number of payments to show. Not enforced. */
|
|
121
|
+
count: number | null;
|
|
122
|
+
}
|
|
82
123
|
interface LineItem {
|
|
83
124
|
id: string;
|
|
84
125
|
cartId: string;
|
|
@@ -93,16 +134,13 @@ interface LineItem {
|
|
|
93
134
|
discountAmount: number;
|
|
94
135
|
total: number;
|
|
95
136
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* `
|
|
137
|
+
* Subscription terms. `'plan' in recurring` tells a merchant-declared
|
|
138
|
+
* subscription line (`StoredLineRecurring`) from the plan line a checkout
|
|
139
|
+
* session adds (`LegacyLineRecurring`). Null on a one-time line.
|
|
99
140
|
*/
|
|
100
|
-
recurring:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
intervalUnit?: string | null;
|
|
104
|
-
intervalCount?: number | null;
|
|
105
|
-
} | null;
|
|
141
|
+
recurring: StoredLineRecurring | LegacyLineRecurring | null;
|
|
142
|
+
/** The subscription this line created. Null until the checkout completes. */
|
|
143
|
+
subscriptionId: string | null;
|
|
106
144
|
imageUrl: string | null;
|
|
107
145
|
position: number;
|
|
108
146
|
metadata: Record<string, unknown>;
|
|
@@ -181,16 +219,12 @@ interface AddLineItemInput {
|
|
|
181
219
|
taxAmount?: number;
|
|
182
220
|
discountAmount?: number;
|
|
183
221
|
/**
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
* `
|
|
222
|
+
* Makes this line a subscription: `type` is forced to `subscription`, and it
|
|
223
|
+
* never ships (`requiresShipping: true` is rejected with it). A free-trial
|
|
224
|
+
* line is stored with `unitPrice` 0 and your price on `recurring.amount`.
|
|
225
|
+
* Terms cannot change later: remove the line and add it again.
|
|
187
226
|
*/
|
|
188
|
-
recurring?:
|
|
189
|
-
interval: string;
|
|
190
|
-
count: number | null;
|
|
191
|
-
intervalUnit?: string | null;
|
|
192
|
-
intervalCount?: number | null;
|
|
193
|
-
} | null;
|
|
227
|
+
recurring?: LineRecurringInput;
|
|
194
228
|
imageUrl?: string;
|
|
195
229
|
/**
|
|
196
230
|
* Whether this item is physically shippable. For external/ad-hoc catalogs
|
|
@@ -201,6 +235,11 @@ interface AddLineItemInput {
|
|
|
201
235
|
requiresShipping?: boolean;
|
|
202
236
|
metadata?: Record<string, unknown>;
|
|
203
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* On a subscription line only `quantity` (seats) and `metadata` may change;
|
|
240
|
+
* a different `unitPrice`, `taxAmount` or `discountAmount` is
|
|
241
|
+
* 422 `recurring_line_immutable`.
|
|
242
|
+
*/
|
|
204
243
|
interface UpdateLineItemInput {
|
|
205
244
|
quantity?: number;
|
|
206
245
|
unitPrice?: number;
|
|
@@ -467,8 +506,9 @@ declare class StorefrontQuoteClient {
|
|
|
467
506
|
/**
|
|
468
507
|
* Browser client for backend-less cart ownership. Unlike {@link CartClient}
|
|
469
508
|
* (which needs a server-side `sk_` key), `CartSessionClient` runs in the browser:
|
|
470
|
-
* it creates and mutates a Throttle cart authorized by a
|
|
471
|
-
* (`
|
|
509
|
+
* it creates and mutates a Throttle cart authorized by a storefront quote token
|
|
510
|
+
* (`qt_…`, or a legacy `pk_…` quote token; the same token used by
|
|
511
|
+
* {@link StorefrontQuoteClient}, not a `pk_` publishable API key) plus the
|
|
472
512
|
* application origin allowlist, and an opaque `cart_…` session id scoped to that
|
|
473
513
|
* one cart.
|
|
474
514
|
*
|
|
@@ -483,9 +523,14 @@ declare class StorefrontQuoteClient {
|
|
|
483
523
|
interface CartSessionClientOptions {
|
|
484
524
|
/** Application UUID. */
|
|
485
525
|
applicationId: string;
|
|
486
|
-
/** Workspace environment UUID the
|
|
526
|
+
/** Workspace environment UUID the quote token was minted for. */
|
|
487
527
|
environmentId: string;
|
|
488
|
-
/**
|
|
528
|
+
/**
|
|
529
|
+
* Storefront quote token (`qt_…`), from the dashboard Shipping & Tax page or
|
|
530
|
+
* `POST /api/v1/shipping-tax/quote-tokens`. Tokens minted before `qt_` start
|
|
531
|
+
* with `pk_` and keep working. A `pk_` publishable API key is a different
|
|
532
|
+
* credential and is refused (`401 invalid_quote_token`).
|
|
533
|
+
*/
|
|
489
534
|
quoteToken: string;
|
|
490
535
|
baseUrl?: string;
|
|
491
536
|
fetch?: typeof globalThis.fetch;
|
|
@@ -605,7 +650,7 @@ declare class CartSessionClient {
|
|
|
605
650
|
/**
|
|
606
651
|
* Bind to an existing session without a publishable token.
|
|
607
652
|
*
|
|
608
|
-
* `create()` needs a
|
|
653
|
+
* `create()` needs a quote token; every other route is authorized by the
|
|
609
654
|
* opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
|
|
610
655
|
* hosted cart page, or a storefront restoring from localStorage — would
|
|
611
656
|
* otherwise have to invent a token to satisfy the constructor.
|
|
@@ -705,4 +750,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
705
750
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
706
751
|
}): ThrottleApiError;
|
|
707
752
|
|
|
708
|
-
export { type AddLineItemInput, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartClient, type CartEvent, CartNotFoundError, CartNotOpenError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, type ExternalShippingTaxSnapshotInput, type LineItem, type Order, type SelectShippingInput, type SelectedShipping, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, StorefrontQuoteClient, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
|
|
753
|
+
export { type AddLineItemInput, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartClient, type CartEvent, CartNotFoundError, CartNotOpenError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineRecurringInput, type Order, type SelectShippingInput, type SelectedShipping, type ShippingTaxAddress, type ShippingTaxCalculationResponse, type ShippingTaxCartCalculateInput, type ShippingTaxMethod, type ShippingTaxQuoteInput, type ShippingTaxQuoteItem, type StoredLineRecurring, StorefrontQuoteClient, type SubscriptionInterval, type SubscriptionIntervalUnit, type TaxLine, type TaxLineInput, ThrottleApiError, type UpdateCartInput, type UpdateCartSessionInput, type UpdateLineItemInput, cartErrorFromResponse };
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "3.11.1",
|
|
4
4
|
"description": "Typed REST client for the Throttle Cart API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsup",
|
|
33
|
-
"test": "vitest run",
|
|
33
|
+
"test": "tsc --noEmit --strict --skipLibCheck --target es2022 --lib es2022,dom --module esnext --moduleResolution bundler __tests__/recurring-types.check.ts && vitest run",
|
|
34
34
|
"typecheck": "tsc --noEmit"
|
|
35
35
|
}
|
|
36
36
|
}
|