@usethrottle/cart 3.10.0 → 3.11.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 +33 -11
- package/dist/index.cjs +32 -7
- package/dist/index.d.cts +63 -20
- package/dist/index.d.ts +63 -20
- package/dist/index.js +32 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -222,23 +222,45 @@ await client.shippingTax.pushExternalSnapshot({
|
|
|
222
222
|
|
|
223
223
|
## Subscriptions
|
|
224
224
|
|
|
225
|
-
|
|
225
|
+
Put `recurring` on a line to make it a subscription. A cart can hold any
|
|
226
|
+
number of one-time lines and up to 10 subscription lines, with the same plan
|
|
227
|
+
or different ones. The whole cart is paid in one capture, with one shipping
|
|
228
|
+
fee, and completes as one order linked to every subscription it created.
|
|
226
229
|
|
|
227
230
|
```ts
|
|
231
|
+
await client.items.add(cart.id, { name: 'Coffee kit', unitPrice: 4500, quantity: 1 });
|
|
228
232
|
await client.items.add(cart.id, {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
+
name: 'Barista Club',
|
|
234
|
+
unitPrice: 2000, // per period, per seat
|
|
235
|
+
quantity: 2, // seats
|
|
236
|
+
recurring: { plan: 'club_monthly', interval: 'monthly', trialDays: 14 },
|
|
233
237
|
});
|
|
234
238
|
```
|
|
235
239
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
- `interval` (`weekly`, `biweekly`, `monthly`, `quarterly`, `yearly`), or
|
|
241
|
+
`intervalUnit` (`hour`, `day`, `week`, `month`) + `intervalCount`: 1 hour
|
|
242
|
+
to 1 year.
|
|
243
|
+
- `totalPayments` (2–60) makes an installment plan; `trialDays` (0–365) a free
|
|
244
|
+
trial. They cannot be combined (`400 invalid_combination`).
|
|
245
|
+
- `type` is forced to `subscription`, and the line never ships:
|
|
246
|
+
`requiresShipping: true` is rejected with `400 validation_error`.
|
|
247
|
+
- A free-trial line is stored with `unitPrice: 0` and your price on
|
|
248
|
+
`recurring.amount`, and its name gets a "— 14-day free trial" suffix.
|
|
249
|
+
- `PATCH` may change `quantity` (seats) and `metadata` only. Changing
|
|
250
|
+
`unitPrice`, `taxAmount` or `discountAmount` is `422 recurring_line_immutable`.
|
|
251
|
+
Remove the line and add it again to change its terms.
|
|
252
|
+
- Each line's `subscriptionId` is set when the checkout completes.
|
|
253
|
+
|
|
254
|
+
| Status | Code | When |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| 422 | `too_many_subscriptions` | An 11th subscription line |
|
|
257
|
+
| 422 | `recurring_not_supported_for_cart` | The cart is managed by an external cart provider |
|
|
258
|
+
| 422 | `recurring_line_immutable` | A PATCH changes a subscription line's price, tax or discount |
|
|
259
|
+
| 400 | `invalid_line_item` | A free-trial line carries `taxAmount` or `discountAmount` |
|
|
260
|
+
| 400 | `invalid_interval` / `interval_conflict` / `invalid_total_payments` / `invalid_combination` / `invalid_plan` / `invalid_trial_days` | Terms out of range |
|
|
261
|
+
|
|
262
|
+
Do not also send a session `recurring` intent for the same cart. The two are
|
|
263
|
+
exclusive, and session creation answers `422 recurring_source_conflict`.
|
|
242
264
|
|
|
243
265
|
## Events
|
|
244
266
|
|
package/dist/index.cjs
CHANGED
|
@@ -44,13 +44,25 @@ var ThrottleApiError = class extends import_errors.ThrottleError {
|
|
|
44
44
|
};
|
|
45
45
|
var CartNotOpenError = class extends ThrottleApiError {
|
|
46
46
|
constructor(args) {
|
|
47
|
-
super({
|
|
47
|
+
super({
|
|
48
|
+
code: "cart_not_open",
|
|
49
|
+
statusCode: args.statusCode ?? 409,
|
|
50
|
+
message: args.message,
|
|
51
|
+
details: args.details,
|
|
52
|
+
responseHeaders: args.responseHeaders
|
|
53
|
+
});
|
|
48
54
|
this.name = "CartNotOpenError";
|
|
49
55
|
}
|
|
50
56
|
};
|
|
51
57
|
var CartNotFoundError = class extends ThrottleApiError {
|
|
52
58
|
constructor(args) {
|
|
53
|
-
super({
|
|
59
|
+
super({
|
|
60
|
+
code: "cart_not_found",
|
|
61
|
+
statusCode: args.statusCode ?? 404,
|
|
62
|
+
message: args.message,
|
|
63
|
+
details: args.details,
|
|
64
|
+
responseHeaders: args.responseHeaders
|
|
65
|
+
});
|
|
54
66
|
this.name = "CartNotFoundError";
|
|
55
67
|
}
|
|
56
68
|
};
|
|
@@ -67,10 +79,20 @@ var CartTimeoutError = class extends import_errors.ThrottleError {
|
|
|
67
79
|
};
|
|
68
80
|
function cartErrorFromResponse(args) {
|
|
69
81
|
if (args.statusCode === 409 && args.code === "cart_not_open") {
|
|
70
|
-
return new CartNotOpenError({
|
|
82
|
+
return new CartNotOpenError({
|
|
83
|
+
message: args.message,
|
|
84
|
+
statusCode: args.statusCode,
|
|
85
|
+
details: args.details,
|
|
86
|
+
responseHeaders: args.responseHeaders
|
|
87
|
+
});
|
|
71
88
|
}
|
|
72
89
|
if (args.statusCode === 404 && (args.code === "cart_not_found" || args.code === "not_found")) {
|
|
73
|
-
return new CartNotFoundError({
|
|
90
|
+
return new CartNotFoundError({
|
|
91
|
+
message: args.message,
|
|
92
|
+
statusCode: args.statusCode,
|
|
93
|
+
details: args.details,
|
|
94
|
+
responseHeaders: args.responseHeaders
|
|
95
|
+
});
|
|
74
96
|
}
|
|
75
97
|
return new ThrottleApiError(args);
|
|
76
98
|
}
|
|
@@ -108,7 +130,8 @@ var CartClient = class {
|
|
|
108
130
|
code: json?.error?.code ?? "unknown_error",
|
|
109
131
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
110
132
|
statusCode: res.status,
|
|
111
|
-
details: json?.error?.details
|
|
133
|
+
details: json?.error?.details,
|
|
134
|
+
responseHeaders: res.headers
|
|
112
135
|
});
|
|
113
136
|
}
|
|
114
137
|
return json.data;
|
|
@@ -215,7 +238,8 @@ var StorefrontQuoteClient = class {
|
|
|
215
238
|
code: json?.error?.code ?? "unknown_error",
|
|
216
239
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
217
240
|
statusCode: res.status,
|
|
218
|
-
details: json?.error?.details
|
|
241
|
+
details: json?.error?.details,
|
|
242
|
+
responseHeaders: res.headers
|
|
219
243
|
});
|
|
220
244
|
}
|
|
221
245
|
return json.data;
|
|
@@ -385,7 +409,8 @@ var CartSessionClient = class _CartSessionClient {
|
|
|
385
409
|
code: json?.error?.code ?? "unknown_error",
|
|
386
410
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
387
411
|
statusCode: res.status,
|
|
388
|
-
details: json?.error?.details
|
|
412
|
+
details: json?.error?.details,
|
|
413
|
+
responseHeaders: res.headers
|
|
389
414
|
});
|
|
390
415
|
}
|
|
391
416
|
return json.data;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThrottleError } from '@usethrottle/errors';
|
|
1
|
+
import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
|
|
2
2
|
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -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;
|
|
@@ -641,6 +680,7 @@ declare class ThrottleApiError extends ThrottleError {
|
|
|
641
680
|
message: string;
|
|
642
681
|
statusCode: number;
|
|
643
682
|
details?: Record<string, unknown>;
|
|
683
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
644
684
|
});
|
|
645
685
|
}
|
|
646
686
|
/**
|
|
@@ -658,6 +698,7 @@ declare class CartNotOpenError extends ThrottleApiError {
|
|
|
658
698
|
message: string;
|
|
659
699
|
statusCode?: number;
|
|
660
700
|
details?: Record<string, unknown>;
|
|
701
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
661
702
|
});
|
|
662
703
|
}
|
|
663
704
|
/**
|
|
@@ -669,6 +710,7 @@ declare class CartNotFoundError extends ThrottleApiError {
|
|
|
669
710
|
message: string;
|
|
670
711
|
statusCode?: number;
|
|
671
712
|
details?: Record<string, unknown>;
|
|
713
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
672
714
|
});
|
|
673
715
|
}
|
|
674
716
|
/**
|
|
@@ -699,6 +741,7 @@ declare function cartErrorFromResponse(args: {
|
|
|
699
741
|
message: string;
|
|
700
742
|
statusCode: number;
|
|
701
743
|
details?: Record<string, unknown>;
|
|
744
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
702
745
|
}): ThrottleApiError;
|
|
703
746
|
|
|
704
|
-
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 };
|
|
747
|
+
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThrottleError } from '@usethrottle/errors';
|
|
1
|
+
import { ThrottleError, ThrottleErrorArgs } from '@usethrottle/errors';
|
|
2
2
|
export { ThrottleError, isThrottleError } from '@usethrottle/errors';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -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;
|
|
@@ -641,6 +680,7 @@ declare class ThrottleApiError extends ThrottleError {
|
|
|
641
680
|
message: string;
|
|
642
681
|
statusCode: number;
|
|
643
682
|
details?: Record<string, unknown>;
|
|
683
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
644
684
|
});
|
|
645
685
|
}
|
|
646
686
|
/**
|
|
@@ -658,6 +698,7 @@ declare class CartNotOpenError extends ThrottleApiError {
|
|
|
658
698
|
message: string;
|
|
659
699
|
statusCode?: number;
|
|
660
700
|
details?: Record<string, unknown>;
|
|
701
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
661
702
|
});
|
|
662
703
|
}
|
|
663
704
|
/**
|
|
@@ -669,6 +710,7 @@ declare class CartNotFoundError extends ThrottleApiError {
|
|
|
669
710
|
message: string;
|
|
670
711
|
statusCode?: number;
|
|
671
712
|
details?: Record<string, unknown>;
|
|
713
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
672
714
|
});
|
|
673
715
|
}
|
|
674
716
|
/**
|
|
@@ -699,6 +741,7 @@ declare function cartErrorFromResponse(args: {
|
|
|
699
741
|
message: string;
|
|
700
742
|
statusCode: number;
|
|
701
743
|
details?: Record<string, unknown>;
|
|
744
|
+
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
702
745
|
}): ThrottleApiError;
|
|
703
746
|
|
|
704
|
-
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 };
|
|
747
|
+
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
|
@@ -9,13 +9,25 @@ var ThrottleApiError = class extends ThrottleError {
|
|
|
9
9
|
};
|
|
10
10
|
var CartNotOpenError = class extends ThrottleApiError {
|
|
11
11
|
constructor(args) {
|
|
12
|
-
super({
|
|
12
|
+
super({
|
|
13
|
+
code: "cart_not_open",
|
|
14
|
+
statusCode: args.statusCode ?? 409,
|
|
15
|
+
message: args.message,
|
|
16
|
+
details: args.details,
|
|
17
|
+
responseHeaders: args.responseHeaders
|
|
18
|
+
});
|
|
13
19
|
this.name = "CartNotOpenError";
|
|
14
20
|
}
|
|
15
21
|
};
|
|
16
22
|
var CartNotFoundError = class extends ThrottleApiError {
|
|
17
23
|
constructor(args) {
|
|
18
|
-
super({
|
|
24
|
+
super({
|
|
25
|
+
code: "cart_not_found",
|
|
26
|
+
statusCode: args.statusCode ?? 404,
|
|
27
|
+
message: args.message,
|
|
28
|
+
details: args.details,
|
|
29
|
+
responseHeaders: args.responseHeaders
|
|
30
|
+
});
|
|
19
31
|
this.name = "CartNotFoundError";
|
|
20
32
|
}
|
|
21
33
|
};
|
|
@@ -32,10 +44,20 @@ var CartTimeoutError = class extends ThrottleError {
|
|
|
32
44
|
};
|
|
33
45
|
function cartErrorFromResponse(args) {
|
|
34
46
|
if (args.statusCode === 409 && args.code === "cart_not_open") {
|
|
35
|
-
return new CartNotOpenError({
|
|
47
|
+
return new CartNotOpenError({
|
|
48
|
+
message: args.message,
|
|
49
|
+
statusCode: args.statusCode,
|
|
50
|
+
details: args.details,
|
|
51
|
+
responseHeaders: args.responseHeaders
|
|
52
|
+
});
|
|
36
53
|
}
|
|
37
54
|
if (args.statusCode === 404 && (args.code === "cart_not_found" || args.code === "not_found")) {
|
|
38
|
-
return new CartNotFoundError({
|
|
55
|
+
return new CartNotFoundError({
|
|
56
|
+
message: args.message,
|
|
57
|
+
statusCode: args.statusCode,
|
|
58
|
+
details: args.details,
|
|
59
|
+
responseHeaders: args.responseHeaders
|
|
60
|
+
});
|
|
39
61
|
}
|
|
40
62
|
return new ThrottleApiError(args);
|
|
41
63
|
}
|
|
@@ -73,7 +95,8 @@ var CartClient = class {
|
|
|
73
95
|
code: json?.error?.code ?? "unknown_error",
|
|
74
96
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
75
97
|
statusCode: res.status,
|
|
76
|
-
details: json?.error?.details
|
|
98
|
+
details: json?.error?.details,
|
|
99
|
+
responseHeaders: res.headers
|
|
77
100
|
});
|
|
78
101
|
}
|
|
79
102
|
return json.data;
|
|
@@ -180,7 +203,8 @@ var StorefrontQuoteClient = class {
|
|
|
180
203
|
code: json?.error?.code ?? "unknown_error",
|
|
181
204
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
182
205
|
statusCode: res.status,
|
|
183
|
-
details: json?.error?.details
|
|
206
|
+
details: json?.error?.details,
|
|
207
|
+
responseHeaders: res.headers
|
|
184
208
|
});
|
|
185
209
|
}
|
|
186
210
|
return json.data;
|
|
@@ -350,7 +374,8 @@ var CartSessionClient = class _CartSessionClient {
|
|
|
350
374
|
code: json?.error?.code ?? "unknown_error",
|
|
351
375
|
message: json?.error?.message ?? `HTTP ${res.status}`,
|
|
352
376
|
statusCode: res.status,
|
|
353
|
-
details: json?.error?.details
|
|
377
|
+
details: json?.error?.details,
|
|
378
|
+
responseHeaders: res.headers
|
|
354
379
|
});
|
|
355
380
|
}
|
|
356
381
|
return json.data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/cart",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "Typed REST client for the Throttle Cart API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@usethrottle/errors": "^1.
|
|
21
|
+
"@usethrottle/errors": "^1.1.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"tsup": "^8.0.0",
|
|
@@ -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
|
}
|