@usethrottle/cart 3.0.0 → 3.1.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
@@ -18,7 +18,11 @@ import { CartClient } from '@usethrottle/cart';
18
18
  const client = new CartClient({ apiKey: process.env.THROTTLE_API_KEY! });
19
19
 
20
20
  // 1. Create a cart
21
- const cart = await client.carts.create({ storeId: 'store_abc', currency: 'USD' });
21
+ const cart = await client.carts.create({
22
+ storeId: 'store_abc',
23
+ currency: 'USD',
24
+ netN: 45,
25
+ });
22
26
 
23
27
  // 2. Add a line item
24
28
  await client.items.add(cart.id, {
@@ -48,8 +52,25 @@ const order = await client.carts.checkout(cart.id, { paymentMethod: 'card' });
48
52
  console.log(order.id, order.status);
49
53
  ```
50
54
 
55
+ `applicationId` is accepted as an alias for `storeId` when your integration
56
+ already uses the newer application naming.
57
+
51
58
  All monetary values are integers in the smallest currency unit (cents for USD).
52
59
 
60
+ ## Net-N invoice terms
61
+
62
+ Cart-level invoice terms are optional. Pass `netN` on cart create or update to
63
+ set the cart override, or `null` to clear it. The final invoice term is resolved
64
+ when the buyer completes checkout with Invoice Terms:
65
+
66
+ ```text
67
+ customer.netN ?? cart.netN ?? DEFAULT_NET_N
68
+ ```
69
+
70
+ `allowedMethods` only controls which payment methods can appear in checkout; it
71
+ does not change the Net-N day count. For hosted/embed checkout, create a cart
72
+ with `netN` and then create a checkout session for that cart.
73
+
53
74
  ## Shipping and tax
54
75
 
55
76
  Use the secret-key client on your backend to calculate and persist cart totals
@@ -74,7 +95,7 @@ External stores can also request read-only storefront quotes with a publishable
74
95
  import { StorefrontQuoteClient } from '@usethrottle/cart';
75
96
 
76
97
  const quotes = new StorefrontQuoteClient({
77
- storeId: 'store_uuid',
98
+ applicationId: 'application_uuid',
78
99
  quoteToken: 'pk_publishable_quote_token',
79
100
  });
80
101
 
@@ -170,14 +191,14 @@ try {
170
191
 
171
192
  ## Client options
172
193
 
173
- | Option | Default | Description |
174
- |---|---|---|
175
- | `apiKey` | — | **Required.** Your Throttle secret key (`sk_…`). |
176
- | `baseUrl` | `https://throttle-api-gff1.onrender.com` | Override for local dev or staging. |
177
- | `timeoutMs` | `30000` | Per-request abort timeout in ms. |
178
- | `fetch` | `globalThis.fetch` | Custom fetch implementation (e.g. `node-fetch`). |
194
+ | Option | Default | Description |
195
+ | ----------- | ----------------------------- | ----------------------------------------------------------- |
196
+ | `apiKey` | — | **Required.** Your Throttle secret key (`sk_…`). |
197
+ | `baseUrl` | `https://api.usethrottle.dev` | Optional override for a dedicated Throttle API environment. |
198
+ | `timeoutMs` | `30000` | Per-request abort timeout in ms. |
199
+ | `fetch` | `globalThis.fetch` | Custom fetch implementation (e.g. `node-fetch`). |
179
200
 
180
201
  ## See also
181
202
 
182
- - [API client (auto-generated): `@usethrottle/api-client`](https://www.npmjs.com/package/@usethrottle/api-client)
203
+ - [Checkout SDK: `@usethrottle/checkout-sdk`](https://www.npmjs.com/package/@usethrottle/checkout-sdk)
183
204
  - [React embed components: `@usethrottle/checkout-react`](https://www.npmjs.com/package/@usethrottle/checkout-react)
package/dist/index.cjs CHANGED
@@ -133,18 +133,19 @@ var CartClient = class {
133
133
 
134
134
  // src/storefront.ts
135
135
  var StorefrontQuoteClient = class {
136
- storeId;
136
+ applicationId;
137
137
  quoteToken;
138
138
  baseUrl;
139
139
  fetchImpl;
140
140
  timeoutMs;
141
141
  origin;
142
142
  constructor(opts) {
143
- if (!opts.storeId) throw new Error("StorefrontQuoteClient: storeId is required");
143
+ const applicationId = opts.applicationId ?? opts.storeId;
144
+ if (!applicationId) throw new Error("StorefrontQuoteClient: applicationId is required");
144
145
  if (!opts.quoteToken?.startsWith("pk_")) {
145
146
  throw new Error("StorefrontQuoteClient: quoteToken must be a publishable pk_ token");
146
147
  }
147
- this.storeId = opts.storeId;
148
+ this.applicationId = applicationId;
148
149
  this.quoteToken = opts.quoteToken;
149
150
  this.baseUrl = (opts.baseUrl ?? "https://api.usethrottle.dev").replace(/\/+$/, "");
150
151
  this.fetchImpl = opts.fetch ?? globalThis.fetch;
@@ -161,7 +162,7 @@ var StorefrontQuoteClient = class {
161
162
  method: "POST",
162
163
  headers,
163
164
  body: JSON.stringify({
164
- storeId: this.storeId,
165
+ applicationId: this.applicationId,
165
166
  quoteToken: this.quoteToken,
166
167
  ...input
167
168
  }),
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  interface Cart {
2
2
  id: string;
3
3
  merchantId: string;
4
+ applicationId: string;
4
5
  storeId: string | null;
5
6
  customerId: string | null;
6
7
  status: 'open' | 'checkout' | 'converted' | 'abandoned';
@@ -10,6 +11,7 @@ interface Cart {
10
11
  discountTotal: number;
11
12
  shippingTotal: number;
12
13
  total: number;
14
+ netN: number | null;
13
15
  billingAddress: Record<string, unknown> | null;
14
16
  shippingAddress: Record<string, unknown> | null;
15
17
  notes: string | null;
@@ -86,17 +88,25 @@ interface CartEvent {
86
88
  actorId: string | null;
87
89
  createdAt: string;
88
90
  }
89
- interface CreateCartInput {
91
+ type CartApplicationRef = {
90
92
  storeId: string;
93
+ applicationId?: string;
94
+ } | {
95
+ applicationId: string;
96
+ storeId?: string;
97
+ };
98
+ type CreateCartInput = CartApplicationRef & {
91
99
  customerId?: string;
92
100
  currency?: string;
101
+ netN?: number | null;
93
102
  metadata?: Record<string, unknown>;
94
- }
103
+ };
95
104
  interface UpdateCartInput {
96
105
  customerId?: string;
97
106
  billingAddress?: Record<string, unknown>;
98
107
  shippingAddress?: Record<string, unknown>;
99
108
  notes?: string;
109
+ netN?: number | null;
100
110
  metadata?: Record<string, unknown>;
101
111
  }
102
112
  interface AddLineItemInput {
@@ -338,7 +348,10 @@ declare class CartClient {
338
348
  }
339
349
 
340
350
  interface StorefrontQuoteClientOptions {
341
- storeId: string;
351
+ /** Current API contract: the application/store UUID that owns the quote config. */
352
+ applicationId?: string;
353
+ /** @deprecated Use applicationId. Kept as an alias for older storefronts. */
354
+ storeId?: string;
342
355
  quoteToken: string;
343
356
  baseUrl?: string;
344
357
  fetch?: typeof globalThis.fetch;
@@ -346,7 +359,7 @@ interface StorefrontQuoteClientOptions {
346
359
  origin?: string;
347
360
  }
348
361
  declare class StorefrontQuoteClient {
349
- private readonly storeId;
362
+ private readonly applicationId;
350
363
  private readonly quoteToken;
351
364
  private readonly baseUrl;
352
365
  private readonly fetchImpl;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  interface Cart {
2
2
  id: string;
3
3
  merchantId: string;
4
+ applicationId: string;
4
5
  storeId: string | null;
5
6
  customerId: string | null;
6
7
  status: 'open' | 'checkout' | 'converted' | 'abandoned';
@@ -10,6 +11,7 @@ interface Cart {
10
11
  discountTotal: number;
11
12
  shippingTotal: number;
12
13
  total: number;
14
+ netN: number | null;
13
15
  billingAddress: Record<string, unknown> | null;
14
16
  shippingAddress: Record<string, unknown> | null;
15
17
  notes: string | null;
@@ -86,17 +88,25 @@ interface CartEvent {
86
88
  actorId: string | null;
87
89
  createdAt: string;
88
90
  }
89
- interface CreateCartInput {
91
+ type CartApplicationRef = {
90
92
  storeId: string;
93
+ applicationId?: string;
94
+ } | {
95
+ applicationId: string;
96
+ storeId?: string;
97
+ };
98
+ type CreateCartInput = CartApplicationRef & {
91
99
  customerId?: string;
92
100
  currency?: string;
101
+ netN?: number | null;
93
102
  metadata?: Record<string, unknown>;
94
- }
103
+ };
95
104
  interface UpdateCartInput {
96
105
  customerId?: string;
97
106
  billingAddress?: Record<string, unknown>;
98
107
  shippingAddress?: Record<string, unknown>;
99
108
  notes?: string;
109
+ netN?: number | null;
100
110
  metadata?: Record<string, unknown>;
101
111
  }
102
112
  interface AddLineItemInput {
@@ -338,7 +348,10 @@ declare class CartClient {
338
348
  }
339
349
 
340
350
  interface StorefrontQuoteClientOptions {
341
- storeId: string;
351
+ /** Current API contract: the application/store UUID that owns the quote config. */
352
+ applicationId?: string;
353
+ /** @deprecated Use applicationId. Kept as an alias for older storefronts. */
354
+ storeId?: string;
342
355
  quoteToken: string;
343
356
  baseUrl?: string;
344
357
  fetch?: typeof globalThis.fetch;
@@ -346,7 +359,7 @@ interface StorefrontQuoteClientOptions {
346
359
  origin?: string;
347
360
  }
348
361
  declare class StorefrontQuoteClient {
349
- private readonly storeId;
362
+ private readonly applicationId;
350
363
  private readonly quoteToken;
351
364
  private readonly baseUrl;
352
365
  private readonly fetchImpl;
package/dist/index.js CHANGED
@@ -105,18 +105,19 @@ var CartClient = class {
105
105
 
106
106
  // src/storefront.ts
107
107
  var StorefrontQuoteClient = class {
108
- storeId;
108
+ applicationId;
109
109
  quoteToken;
110
110
  baseUrl;
111
111
  fetchImpl;
112
112
  timeoutMs;
113
113
  origin;
114
114
  constructor(opts) {
115
- if (!opts.storeId) throw new Error("StorefrontQuoteClient: storeId is required");
115
+ const applicationId = opts.applicationId ?? opts.storeId;
116
+ if (!applicationId) throw new Error("StorefrontQuoteClient: applicationId is required");
116
117
  if (!opts.quoteToken?.startsWith("pk_")) {
117
118
  throw new Error("StorefrontQuoteClient: quoteToken must be a publishable pk_ token");
118
119
  }
119
- this.storeId = opts.storeId;
120
+ this.applicationId = applicationId;
120
121
  this.quoteToken = opts.quoteToken;
121
122
  this.baseUrl = (opts.baseUrl ?? "https://api.usethrottle.dev").replace(/\/+$/, "");
122
123
  this.fetchImpl = opts.fetch ?? globalThis.fetch;
@@ -133,7 +134,7 @@ var StorefrontQuoteClient = class {
133
134
  method: "POST",
134
135
  headers,
135
136
  body: JSON.stringify({
136
- storeId: this.storeId,
137
+ applicationId: this.applicationId,
137
138
  quoteToken: this.quoteToken,
138
139
  ...input
139
140
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usethrottle/cart",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Typed REST client for the Throttle Cart API.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",