@usethrottle/cart 3.11.0 → 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 +9 -6
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +2 -2
- package/package.json +1 -1
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({
|
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
|
@@ -506,8 +506,9 @@ declare class StorefrontQuoteClient {
|
|
|
506
506
|
/**
|
|
507
507
|
* Browser client for backend-less cart ownership. Unlike {@link CartClient}
|
|
508
508
|
* (which needs a server-side `sk_` key), `CartSessionClient` runs in the browser:
|
|
509
|
-
* it creates and mutates a Throttle cart authorized by a
|
|
510
|
-
* (`
|
|
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
|
|
511
512
|
* application origin allowlist, and an opaque `cart_…` session id scoped to that
|
|
512
513
|
* one cart.
|
|
513
514
|
*
|
|
@@ -522,9 +523,14 @@ declare class StorefrontQuoteClient {
|
|
|
522
523
|
interface CartSessionClientOptions {
|
|
523
524
|
/** Application UUID. */
|
|
524
525
|
applicationId: string;
|
|
525
|
-
/** Workspace environment UUID the
|
|
526
|
+
/** Workspace environment UUID the quote token was minted for. */
|
|
526
527
|
environmentId: string;
|
|
527
|
-
/**
|
|
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
|
+
*/
|
|
528
534
|
quoteToken: string;
|
|
529
535
|
baseUrl?: string;
|
|
530
536
|
fetch?: typeof globalThis.fetch;
|
|
@@ -644,7 +650,7 @@ declare class CartSessionClient {
|
|
|
644
650
|
/**
|
|
645
651
|
* Bind to an existing session without a publishable token.
|
|
646
652
|
*
|
|
647
|
-
* `create()` needs a
|
|
653
|
+
* `create()` needs a quote token; every other route is authorized by the
|
|
648
654
|
* opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
|
|
649
655
|
* hosted cart page, or a storefront restoring from localStorage — would
|
|
650
656
|
* otherwise have to invent a token to satisfy the constructor.
|
package/dist/index.d.ts
CHANGED
|
@@ -506,8 +506,9 @@ declare class StorefrontQuoteClient {
|
|
|
506
506
|
/**
|
|
507
507
|
* Browser client for backend-less cart ownership. Unlike {@link CartClient}
|
|
508
508
|
* (which needs a server-side `sk_` key), `CartSessionClient` runs in the browser:
|
|
509
|
-
* it creates and mutates a Throttle cart authorized by a
|
|
510
|
-
* (`
|
|
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
|
|
511
512
|
* application origin allowlist, and an opaque `cart_…` session id scoped to that
|
|
512
513
|
* one cart.
|
|
513
514
|
*
|
|
@@ -522,9 +523,14 @@ declare class StorefrontQuoteClient {
|
|
|
522
523
|
interface CartSessionClientOptions {
|
|
523
524
|
/** Application UUID. */
|
|
524
525
|
applicationId: string;
|
|
525
|
-
/** Workspace environment UUID the
|
|
526
|
+
/** Workspace environment UUID the quote token was minted for. */
|
|
526
527
|
environmentId: string;
|
|
527
|
-
/**
|
|
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
|
+
*/
|
|
528
534
|
quoteToken: string;
|
|
529
535
|
baseUrl?: string;
|
|
530
536
|
fetch?: typeof globalThis.fetch;
|
|
@@ -644,7 +650,7 @@ declare class CartSessionClient {
|
|
|
644
650
|
/**
|
|
645
651
|
* Bind to an existing session without a publishable token.
|
|
646
652
|
*
|
|
647
|
-
* `create()` needs a
|
|
653
|
+
* `create()` needs a quote token; every other route is authorized by the
|
|
648
654
|
* opaque `cart_…` id alone. A caller that only ever resumes — Throttle's own
|
|
649
655
|
* hosted cart page, or a storefront restoring from localStorage — would
|
|
650
656
|
* 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
|
|
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.
|