@usethrottle/cart 3.19.0 → 3.20.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 +2 -0
- package/dist/index.cjs +21 -3
- package/dist/index.d.cts +93 -4
- package/dist/index.d.ts +93 -4
- package/dist/index.js +21 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -89,6 +89,8 @@ await cart.create({ currency: 'USD' });
|
|
|
89
89
|
|
|
90
90
|
await cart.addItem({ name: 'Premium Widget', unitPrice: 2999, quantity: 2 });
|
|
91
91
|
await cart.applyDiscount('SAVE10');
|
|
92
|
+
// A cart holds one goods code and one free-shipping code. With both applied, name the one to remove:
|
|
93
|
+
// await cart.removeDiscount({ kind: 'shipping' }); // or 'order', or { code: 'SHIPFREE' }
|
|
92
94
|
await cart.selectShipping({ methodId: 'fedex_ground', displayName: 'FedEx Ground', rateAmount: 599 });
|
|
93
95
|
|
|
94
96
|
// Set buyer-editable fields. `customerEmail` is what makes a guest cart
|
package/dist/index.cjs
CHANGED
|
@@ -389,6 +389,15 @@ function withAnalyticsContext(input) {
|
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
+
// src/discount-query.ts
|
|
393
|
+
function removeDiscountQuery(opts) {
|
|
394
|
+
const query = new URLSearchParams();
|
|
395
|
+
if (opts?.kind) query.set("kind", opts.kind);
|
|
396
|
+
if (opts?.code) query.set("code", opts.code);
|
|
397
|
+
const text = query.toString();
|
|
398
|
+
return text ? `?${text}` : "";
|
|
399
|
+
}
|
|
400
|
+
|
|
392
401
|
// src/client.ts
|
|
393
402
|
function segment(value) {
|
|
394
403
|
return encodeURIComponent(value);
|
|
@@ -467,7 +476,12 @@ var CartClient = class {
|
|
|
467
476
|
get discounts() {
|
|
468
477
|
return {
|
|
469
478
|
apply: (cartId, code) => this.request("POST", `/api/v1/carts/${segment(cartId)}/apply-discount`, { code }),
|
|
470
|
-
|
|
479
|
+
/**
|
|
480
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code:
|
|
481
|
+
* with both applied, name one with `kind` or `code` (else
|
|
482
|
+
* 400 `discount_kind_required`).
|
|
483
|
+
*/
|
|
484
|
+
remove: (cartId, opts) => this.request("DELETE", `/api/v1/carts/${segment(cartId)}/discount${removeDiscountQuery(opts)}`)
|
|
471
485
|
};
|
|
472
486
|
}
|
|
473
487
|
get taxLines() {
|
|
@@ -682,8 +696,12 @@ var CartSessionClient = class _CartSessionClient {
|
|
|
682
696
|
async applyDiscount(code) {
|
|
683
697
|
return (await this.request("POST", `${this.basePath()}/discount`, { code })).cart;
|
|
684
698
|
}
|
|
685
|
-
|
|
686
|
-
|
|
699
|
+
/**
|
|
700
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code: with
|
|
701
|
+
* both applied, name one with `kind` or `code` (else 400 `discount_kind_required`).
|
|
702
|
+
*/
|
|
703
|
+
async removeDiscount(opts) {
|
|
704
|
+
return (await this.request("DELETE", `${this.basePath()}/discount${removeDiscountQuery(opts)}`)).cart;
|
|
687
705
|
}
|
|
688
706
|
/** Set buyer-editable cart fields. Pass `null` to clear one. */
|
|
689
707
|
async update(input) {
|
package/dist/index.d.cts
CHANGED
|
@@ -45,7 +45,10 @@ interface Cart {
|
|
|
45
45
|
subtotal: number;
|
|
46
46
|
taxTotal: number;
|
|
47
47
|
discountTotal: number;
|
|
48
|
+
/** Net shipping the buyer pays: already reduced by `shippingDiscountTotal`. */
|
|
48
49
|
shippingTotal: number;
|
|
50
|
+
/** What a free-shipping code took off shipping, in minor units (0 when none). Original shipping is `shippingTotal + shippingDiscountTotal`. */
|
|
51
|
+
shippingDiscountTotal?: number;
|
|
49
52
|
total: number;
|
|
50
53
|
netN: number | null;
|
|
51
54
|
billingAddress: CartAddress | null;
|
|
@@ -59,7 +62,10 @@ interface Cart {
|
|
|
59
62
|
externalMetadata: Record<string, unknown>;
|
|
60
63
|
};
|
|
61
64
|
selectedShipping?: SelectedShipping | null;
|
|
65
|
+
/** The goods code. A free-shipping code is `appliedShippingDiscount`. */
|
|
62
66
|
appliedDiscount?: AppliedDiscount | null;
|
|
67
|
+
/** The cart's free-shipping code and how it stands, or `null` when the cart holds none. */
|
|
68
|
+
appliedShippingDiscount: AppliedShippingDiscount | null;
|
|
63
69
|
taxLines?: TaxLine[];
|
|
64
70
|
lineItems?: LineItem[];
|
|
65
71
|
createdAt: string;
|
|
@@ -176,6 +182,14 @@ interface LineItem {
|
|
|
176
182
|
subscriptionId: string | null;
|
|
177
183
|
imageUrl: string | null;
|
|
178
184
|
position: number;
|
|
185
|
+
/**
|
|
186
|
+
* Free-form line metadata. A line from the Product Catalog also carries the
|
|
187
|
+
* variant's shipping measures, set by Throttle and read-only: `weight` (kg)
|
|
188
|
+
* with `weightUnit`, and `length`, `width` and `height` (cm) with
|
|
189
|
+
* `dimensionUnit`. A key is absent when the catalog has no value for it;
|
|
190
|
+
* the three dimensions come together or not at all. Writing any of them
|
|
191
|
+
* answers `400 price_locked`.
|
|
192
|
+
*/
|
|
179
193
|
metadata: Record<string, unknown>;
|
|
180
194
|
/**
|
|
181
195
|
* Resolved carts only: the app's last answer for this line, or null on a
|
|
@@ -229,6 +243,8 @@ interface SelectShippingMethodInput {
|
|
|
229
243
|
}
|
|
230
244
|
interface SelectedShipping {
|
|
231
245
|
methodId: string;
|
|
246
|
+
/** The connected adapter of a live carrier rate; absent when none was sent. */
|
|
247
|
+
provider?: string;
|
|
232
248
|
carrier: string | null;
|
|
233
249
|
serviceCode: string | null;
|
|
234
250
|
displayName: string;
|
|
@@ -242,10 +258,56 @@ interface AppliedDiscount {
|
|
|
242
258
|
type: 'percentage' | 'fixed_amount';
|
|
243
259
|
amount: number;
|
|
244
260
|
currency: CurrencyCode;
|
|
245
|
-
|
|
261
|
+
/** @deprecated Always `false`: a free-shipping code is `appliedShippingDiscount`, not the goods code. Use `appliedShippingDiscount`. */
|
|
262
|
+
freeShipping?: boolean;
|
|
246
263
|
validUntil: string | null;
|
|
247
264
|
snapshotHash: string;
|
|
248
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* A shipping option a free-shipping code makes free: a native shipping method,
|
|
268
|
+
* or a live carrier service of a connected shipping provider.
|
|
269
|
+
*/
|
|
270
|
+
type ShippingTarget = {
|
|
271
|
+
kind: 'method';
|
|
272
|
+
methodId: string;
|
|
273
|
+
} | {
|
|
274
|
+
kind: 'carrier_service';
|
|
275
|
+
provider: string;
|
|
276
|
+
carrier: string;
|
|
277
|
+
serviceCode: string;
|
|
278
|
+
};
|
|
279
|
+
/** Where a cart's free-shipping code stands against its address and shipping option. */
|
|
280
|
+
type AppliedShippingDiscountStatus = 'applied' | 'not_eligible' | 'pending_address' | 'pending_shipping' | 'merchant_applies';
|
|
281
|
+
/**
|
|
282
|
+
* The cart's free-shipping code (the goods code stays `appliedDiscount`).
|
|
283
|
+
* `zoneIds`, `targets` and `cap` are the code's rules, so a custom checkout can
|
|
284
|
+
* explain them; `null` means all regions, any option, or free in full.
|
|
285
|
+
*/
|
|
286
|
+
interface AppliedShippingDiscount {
|
|
287
|
+
discountId: string;
|
|
288
|
+
code: string;
|
|
289
|
+
/** The reduction the cart carries now, in minor units. */
|
|
290
|
+
amount: number;
|
|
291
|
+
status: AppliedShippingDiscountStatus;
|
|
292
|
+
/** Why the code does not apply, when `status` is `not_eligible`. */
|
|
293
|
+
reason?: 'zone' | 'shipping_option' | 'minimum_order';
|
|
294
|
+
/** How much more the order needs to reach the minimum, when `reason` is `minimum_order`. */
|
|
295
|
+
amountToMinimum?: number;
|
|
296
|
+
zoneIds: string[] | null;
|
|
297
|
+
targets: ShippingTarget[] | null;
|
|
298
|
+
cap: number | null;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Which code to take off a cart that holds a goods code and a free-shipping
|
|
302
|
+
* code. With both applied and neither given the API answers
|
|
303
|
+
* 400 `discount_kind_required`.
|
|
304
|
+
*/
|
|
305
|
+
interface RemoveDiscountOptions {
|
|
306
|
+
/** `order` removes the goods code, `shipping` the free-shipping code. */
|
|
307
|
+
kind?: 'order' | 'shipping';
|
|
308
|
+
/** Remove this code (case-insensitive). */
|
|
309
|
+
code?: string;
|
|
310
|
+
}
|
|
249
311
|
interface TaxLine {
|
|
250
312
|
id: string;
|
|
251
313
|
lineItemId: string;
|
|
@@ -362,6 +424,8 @@ interface SelectShippingInput {
|
|
|
362
424
|
displayName: string;
|
|
363
425
|
rateAmount: number;
|
|
364
426
|
currency?: string;
|
|
427
|
+
/** Connected shipping adapter id of a live carrier rate (`shippo`, `ups`); a free-shipping carrier target matches on it. */
|
|
428
|
+
provider?: string;
|
|
365
429
|
carrier?: string;
|
|
366
430
|
serviceCode?: string;
|
|
367
431
|
estimatedDeliveryDays?: number;
|
|
@@ -441,6 +505,8 @@ interface ShippingTaxCartCalculateInput {
|
|
|
441
505
|
}
|
|
442
506
|
interface ShippingTaxMethod {
|
|
443
507
|
id: string;
|
|
508
|
+
/** A native method's stable key: what a free-shipping `method` target names (`id` changes on every shipping save). */
|
|
509
|
+
stableKey?: string;
|
|
444
510
|
type?: 'ship' | 'pickup';
|
|
445
511
|
label: string;
|
|
446
512
|
amount: number;
|
|
@@ -448,6 +514,16 @@ interface ShippingTaxMethod {
|
|
|
448
514
|
deliveryWindowLabel?: string | null;
|
|
449
515
|
deliveryMinDays?: number | null;
|
|
450
516
|
deliveryMaxDays?: number | null;
|
|
517
|
+
/** Who a live carrier rate came from. Absent on a manual zone method. */
|
|
518
|
+
provider?: string;
|
|
519
|
+
carrier?: string;
|
|
520
|
+
serviceCode?: string;
|
|
521
|
+
/**
|
|
522
|
+
* What the buyer would pay for this option with the cart's free-shipping code
|
|
523
|
+
* applied. Present only when the code would apply to it; `amount` stays the
|
|
524
|
+
* full price.
|
|
525
|
+
*/
|
|
526
|
+
discountedAmount?: number;
|
|
451
527
|
warnings?: Array<{
|
|
452
528
|
code: string;
|
|
453
529
|
message: string;
|
|
@@ -504,7 +580,11 @@ interface ShippingTaxCalculationResponse {
|
|
|
504
580
|
shippingTotal: number;
|
|
505
581
|
taxTotal: number;
|
|
506
582
|
total: number;
|
|
583
|
+
/** What a free-shipping code took off shipping; present only on a cart holding one. */
|
|
584
|
+
shippingDiscountTotal?: number;
|
|
507
585
|
};
|
|
586
|
+
/** The cart's free-shipping code and how it stands; absent on a cart holding none. */
|
|
587
|
+
appliedShippingDiscount?: AppliedShippingDiscount | null;
|
|
508
588
|
/**
|
|
509
589
|
* Verbatim messaging the tax engine returned about this transaction. In
|
|
510
590
|
* several EU member states the engine's own wording is what makes the
|
|
@@ -584,7 +664,12 @@ declare class CartClient {
|
|
|
584
664
|
};
|
|
585
665
|
get discounts(): {
|
|
586
666
|
apply: (cartId: string, code: string) => Promise<Cart>;
|
|
587
|
-
|
|
667
|
+
/**
|
|
668
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code:
|
|
669
|
+
* with both applied, name one with `kind` or `code` (else
|
|
670
|
+
* 400 `discount_kind_required`).
|
|
671
|
+
*/
|
|
672
|
+
remove: (cartId: string, opts?: RemoveDiscountOptions) => Promise<Cart>;
|
|
588
673
|
};
|
|
589
674
|
get taxLines(): {
|
|
590
675
|
set: (cartId: string, lines: TaxLineInput[]) => Promise<Cart>;
|
|
@@ -798,7 +883,11 @@ declare class CartSessionClient {
|
|
|
798
883
|
selectShippingMethod(input: SelectShippingMethodInput): Promise<CartSessionCart>;
|
|
799
884
|
clearShipping(): Promise<CartSessionCart>;
|
|
800
885
|
applyDiscount(code: string): Promise<CartSessionCart>;
|
|
801
|
-
|
|
886
|
+
/**
|
|
887
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code: with
|
|
888
|
+
* both applied, name one with `kind` or `code` (else 400 `discount_kind_required`).
|
|
889
|
+
*/
|
|
890
|
+
removeDiscount(opts?: RemoveDiscountOptions): Promise<CartSessionCart>;
|
|
802
891
|
/** Set buyer-editable cart fields. Pass `null` to clear one. */
|
|
803
892
|
update(input: UpdateCartSessionInput): Promise<CartSessionCart>;
|
|
804
893
|
/**
|
|
@@ -1133,4 +1222,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
1133
1222
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
1134
1223
|
}): ThrottleApiError;
|
|
1135
1224
|
|
|
1136
|
-
export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, CurrencyLockedError, CurrencyNotAvailableInProductionError, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, CurrencyNotPayableError, CurrencyNotSupportedError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, QuoteAmountsNeedReviewError, type RefusedCartLine, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, 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 };
|
|
1225
|
+
export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type AppliedShippingDiscount, type AppliedShippingDiscountStatus, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, CurrencyLockedError, CurrencyNotAvailableInProductionError, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, CurrencyNotPayableError, CurrencyNotSupportedError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, QuoteAmountsNeedReviewError, type RefusedCartLine, type RemoveDiscountOptions, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, type ShippingTarget, 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
|
@@ -45,7 +45,10 @@ interface Cart {
|
|
|
45
45
|
subtotal: number;
|
|
46
46
|
taxTotal: number;
|
|
47
47
|
discountTotal: number;
|
|
48
|
+
/** Net shipping the buyer pays: already reduced by `shippingDiscountTotal`. */
|
|
48
49
|
shippingTotal: number;
|
|
50
|
+
/** What a free-shipping code took off shipping, in minor units (0 when none). Original shipping is `shippingTotal + shippingDiscountTotal`. */
|
|
51
|
+
shippingDiscountTotal?: number;
|
|
49
52
|
total: number;
|
|
50
53
|
netN: number | null;
|
|
51
54
|
billingAddress: CartAddress | null;
|
|
@@ -59,7 +62,10 @@ interface Cart {
|
|
|
59
62
|
externalMetadata: Record<string, unknown>;
|
|
60
63
|
};
|
|
61
64
|
selectedShipping?: SelectedShipping | null;
|
|
65
|
+
/** The goods code. A free-shipping code is `appliedShippingDiscount`. */
|
|
62
66
|
appliedDiscount?: AppliedDiscount | null;
|
|
67
|
+
/** The cart's free-shipping code and how it stands, or `null` when the cart holds none. */
|
|
68
|
+
appliedShippingDiscount: AppliedShippingDiscount | null;
|
|
63
69
|
taxLines?: TaxLine[];
|
|
64
70
|
lineItems?: LineItem[];
|
|
65
71
|
createdAt: string;
|
|
@@ -176,6 +182,14 @@ interface LineItem {
|
|
|
176
182
|
subscriptionId: string | null;
|
|
177
183
|
imageUrl: string | null;
|
|
178
184
|
position: number;
|
|
185
|
+
/**
|
|
186
|
+
* Free-form line metadata. A line from the Product Catalog also carries the
|
|
187
|
+
* variant's shipping measures, set by Throttle and read-only: `weight` (kg)
|
|
188
|
+
* with `weightUnit`, and `length`, `width` and `height` (cm) with
|
|
189
|
+
* `dimensionUnit`. A key is absent when the catalog has no value for it;
|
|
190
|
+
* the three dimensions come together or not at all. Writing any of them
|
|
191
|
+
* answers `400 price_locked`.
|
|
192
|
+
*/
|
|
179
193
|
metadata: Record<string, unknown>;
|
|
180
194
|
/**
|
|
181
195
|
* Resolved carts only: the app's last answer for this line, or null on a
|
|
@@ -229,6 +243,8 @@ interface SelectShippingMethodInput {
|
|
|
229
243
|
}
|
|
230
244
|
interface SelectedShipping {
|
|
231
245
|
methodId: string;
|
|
246
|
+
/** The connected adapter of a live carrier rate; absent when none was sent. */
|
|
247
|
+
provider?: string;
|
|
232
248
|
carrier: string | null;
|
|
233
249
|
serviceCode: string | null;
|
|
234
250
|
displayName: string;
|
|
@@ -242,10 +258,56 @@ interface AppliedDiscount {
|
|
|
242
258
|
type: 'percentage' | 'fixed_amount';
|
|
243
259
|
amount: number;
|
|
244
260
|
currency: CurrencyCode;
|
|
245
|
-
|
|
261
|
+
/** @deprecated Always `false`: a free-shipping code is `appliedShippingDiscount`, not the goods code. Use `appliedShippingDiscount`. */
|
|
262
|
+
freeShipping?: boolean;
|
|
246
263
|
validUntil: string | null;
|
|
247
264
|
snapshotHash: string;
|
|
248
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* A shipping option a free-shipping code makes free: a native shipping method,
|
|
268
|
+
* or a live carrier service of a connected shipping provider.
|
|
269
|
+
*/
|
|
270
|
+
type ShippingTarget = {
|
|
271
|
+
kind: 'method';
|
|
272
|
+
methodId: string;
|
|
273
|
+
} | {
|
|
274
|
+
kind: 'carrier_service';
|
|
275
|
+
provider: string;
|
|
276
|
+
carrier: string;
|
|
277
|
+
serviceCode: string;
|
|
278
|
+
};
|
|
279
|
+
/** Where a cart's free-shipping code stands against its address and shipping option. */
|
|
280
|
+
type AppliedShippingDiscountStatus = 'applied' | 'not_eligible' | 'pending_address' | 'pending_shipping' | 'merchant_applies';
|
|
281
|
+
/**
|
|
282
|
+
* The cart's free-shipping code (the goods code stays `appliedDiscount`).
|
|
283
|
+
* `zoneIds`, `targets` and `cap` are the code's rules, so a custom checkout can
|
|
284
|
+
* explain them; `null` means all regions, any option, or free in full.
|
|
285
|
+
*/
|
|
286
|
+
interface AppliedShippingDiscount {
|
|
287
|
+
discountId: string;
|
|
288
|
+
code: string;
|
|
289
|
+
/** The reduction the cart carries now, in minor units. */
|
|
290
|
+
amount: number;
|
|
291
|
+
status: AppliedShippingDiscountStatus;
|
|
292
|
+
/** Why the code does not apply, when `status` is `not_eligible`. */
|
|
293
|
+
reason?: 'zone' | 'shipping_option' | 'minimum_order';
|
|
294
|
+
/** How much more the order needs to reach the minimum, when `reason` is `minimum_order`. */
|
|
295
|
+
amountToMinimum?: number;
|
|
296
|
+
zoneIds: string[] | null;
|
|
297
|
+
targets: ShippingTarget[] | null;
|
|
298
|
+
cap: number | null;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Which code to take off a cart that holds a goods code and a free-shipping
|
|
302
|
+
* code. With both applied and neither given the API answers
|
|
303
|
+
* 400 `discount_kind_required`.
|
|
304
|
+
*/
|
|
305
|
+
interface RemoveDiscountOptions {
|
|
306
|
+
/** `order` removes the goods code, `shipping` the free-shipping code. */
|
|
307
|
+
kind?: 'order' | 'shipping';
|
|
308
|
+
/** Remove this code (case-insensitive). */
|
|
309
|
+
code?: string;
|
|
310
|
+
}
|
|
249
311
|
interface TaxLine {
|
|
250
312
|
id: string;
|
|
251
313
|
lineItemId: string;
|
|
@@ -362,6 +424,8 @@ interface SelectShippingInput {
|
|
|
362
424
|
displayName: string;
|
|
363
425
|
rateAmount: number;
|
|
364
426
|
currency?: string;
|
|
427
|
+
/** Connected shipping adapter id of a live carrier rate (`shippo`, `ups`); a free-shipping carrier target matches on it. */
|
|
428
|
+
provider?: string;
|
|
365
429
|
carrier?: string;
|
|
366
430
|
serviceCode?: string;
|
|
367
431
|
estimatedDeliveryDays?: number;
|
|
@@ -441,6 +505,8 @@ interface ShippingTaxCartCalculateInput {
|
|
|
441
505
|
}
|
|
442
506
|
interface ShippingTaxMethod {
|
|
443
507
|
id: string;
|
|
508
|
+
/** A native method's stable key: what a free-shipping `method` target names (`id` changes on every shipping save). */
|
|
509
|
+
stableKey?: string;
|
|
444
510
|
type?: 'ship' | 'pickup';
|
|
445
511
|
label: string;
|
|
446
512
|
amount: number;
|
|
@@ -448,6 +514,16 @@ interface ShippingTaxMethod {
|
|
|
448
514
|
deliveryWindowLabel?: string | null;
|
|
449
515
|
deliveryMinDays?: number | null;
|
|
450
516
|
deliveryMaxDays?: number | null;
|
|
517
|
+
/** Who a live carrier rate came from. Absent on a manual zone method. */
|
|
518
|
+
provider?: string;
|
|
519
|
+
carrier?: string;
|
|
520
|
+
serviceCode?: string;
|
|
521
|
+
/**
|
|
522
|
+
* What the buyer would pay for this option with the cart's free-shipping code
|
|
523
|
+
* applied. Present only when the code would apply to it; `amount` stays the
|
|
524
|
+
* full price.
|
|
525
|
+
*/
|
|
526
|
+
discountedAmount?: number;
|
|
451
527
|
warnings?: Array<{
|
|
452
528
|
code: string;
|
|
453
529
|
message: string;
|
|
@@ -504,7 +580,11 @@ interface ShippingTaxCalculationResponse {
|
|
|
504
580
|
shippingTotal: number;
|
|
505
581
|
taxTotal: number;
|
|
506
582
|
total: number;
|
|
583
|
+
/** What a free-shipping code took off shipping; present only on a cart holding one. */
|
|
584
|
+
shippingDiscountTotal?: number;
|
|
507
585
|
};
|
|
586
|
+
/** The cart's free-shipping code and how it stands; absent on a cart holding none. */
|
|
587
|
+
appliedShippingDiscount?: AppliedShippingDiscount | null;
|
|
508
588
|
/**
|
|
509
589
|
* Verbatim messaging the tax engine returned about this transaction. In
|
|
510
590
|
* several EU member states the engine's own wording is what makes the
|
|
@@ -584,7 +664,12 @@ declare class CartClient {
|
|
|
584
664
|
};
|
|
585
665
|
get discounts(): {
|
|
586
666
|
apply: (cartId: string, code: string) => Promise<Cart>;
|
|
587
|
-
|
|
667
|
+
/**
|
|
668
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code:
|
|
669
|
+
* with both applied, name one with `kind` or `code` (else
|
|
670
|
+
* 400 `discount_kind_required`).
|
|
671
|
+
*/
|
|
672
|
+
remove: (cartId: string, opts?: RemoveDiscountOptions) => Promise<Cart>;
|
|
588
673
|
};
|
|
589
674
|
get taxLines(): {
|
|
590
675
|
set: (cartId: string, lines: TaxLineInput[]) => Promise<Cart>;
|
|
@@ -798,7 +883,11 @@ declare class CartSessionClient {
|
|
|
798
883
|
selectShippingMethod(input: SelectShippingMethodInput): Promise<CartSessionCart>;
|
|
799
884
|
clearShipping(): Promise<CartSessionCart>;
|
|
800
885
|
applyDiscount(code: string): Promise<CartSessionCart>;
|
|
801
|
-
|
|
886
|
+
/**
|
|
887
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code: with
|
|
888
|
+
* both applied, name one with `kind` or `code` (else 400 `discount_kind_required`).
|
|
889
|
+
*/
|
|
890
|
+
removeDiscount(opts?: RemoveDiscountOptions): Promise<CartSessionCart>;
|
|
802
891
|
/** Set buyer-editable cart fields. Pass `null` to clear one. */
|
|
803
892
|
update(input: UpdateCartSessionInput): Promise<CartSessionCart>;
|
|
804
893
|
/**
|
|
@@ -1133,4 +1222,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
1133
1222
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
1134
1223
|
}): ThrottleApiError;
|
|
1135
1224
|
|
|
1136
|
-
export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, CurrencyLockedError, CurrencyNotAvailableInProductionError, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, CurrencyNotPayableError, CurrencyNotSupportedError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, QuoteAmountsNeedReviewError, type RefusedCartLine, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, 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 };
|
|
1225
|
+
export { type AddLineItemInput, type AddResolvedLineItemInput, AmountTooLargeError, type AppliedDiscount, type AppliedShippingDiscount, type AppliedShippingDiscountStatus, type Cart, type CartAddress, type CartBranding, CartChangedError, CartClient, type CartErrorArgs, type CartEvent, CartNotFoundError, CartNotOpenError, type CartPricesChangedDetails, CartPricesChangedError, type CartSession, type CartSessionCart, CartSessionClient, type CartSessionClientOptions, type CartSessionSummary, type CartShippingChange, CartTimeoutError, type CheckoutHandoff, type CheckoutHandoffInput, type CheckoutInput, type CreateCartInput, type CreateCartSessionInput, CurrencyLockedError, CurrencyNotAvailableInProductionError, type CurrencyNotEnabledDetails, CurrencyNotEnabledError, CurrencyNotPayableError, CurrencyNotSupportedError, DiscountCurrencyUnsupportedError, type ExternalShippingTaxSnapshotInput, type LegacyLineRecurring, type LineItem, type LineLimitReachedDetails, LineLimitReachedError, type LineNotPurchasableDetails, LineNotPurchasableError, type LineRecurringInput, type LineResolution, type LineResolverNotAvailableDetails, LineResolverNotAvailableError, type LineResolverUnavailableDetails, LineResolverUnavailableError, type Order, type PriceLockedDetails, PriceLockedError, type QuantityUnavailableDetails, QuantityUnavailableError, QuoteAmountsNeedReviewError, type RefusedCartLine, type RemoveDiscountOptions, ResolvedLinesRequiredError, type SelectShippingInput, type SelectShippingMethodInput, type SelectedShipping, ShippingCurrencyUnsupportedError, ShippingMethodUnavailableError, ShippingQuoteUnavailableError, type ShippingTarget, 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
|
@@ -313,6 +313,15 @@ function withAnalyticsContext(input) {
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
// src/discount-query.ts
|
|
317
|
+
function removeDiscountQuery(opts) {
|
|
318
|
+
const query = new URLSearchParams();
|
|
319
|
+
if (opts?.kind) query.set("kind", opts.kind);
|
|
320
|
+
if (opts?.code) query.set("code", opts.code);
|
|
321
|
+
const text = query.toString();
|
|
322
|
+
return text ? `?${text}` : "";
|
|
323
|
+
}
|
|
324
|
+
|
|
316
325
|
// src/client.ts
|
|
317
326
|
function segment(value) {
|
|
318
327
|
return encodeURIComponent(value);
|
|
@@ -391,7 +400,12 @@ var CartClient = class {
|
|
|
391
400
|
get discounts() {
|
|
392
401
|
return {
|
|
393
402
|
apply: (cartId, code) => this.request("POST", `/api/v1/carts/${segment(cartId)}/apply-discount`, { code }),
|
|
394
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code:
|
|
405
|
+
* with both applied, name one with `kind` or `code` (else
|
|
406
|
+
* 400 `discount_kind_required`).
|
|
407
|
+
*/
|
|
408
|
+
remove: (cartId, opts) => this.request("DELETE", `/api/v1/carts/${segment(cartId)}/discount${removeDiscountQuery(opts)}`)
|
|
395
409
|
};
|
|
396
410
|
}
|
|
397
411
|
get taxLines() {
|
|
@@ -606,8 +620,12 @@ var CartSessionClient = class _CartSessionClient {
|
|
|
606
620
|
async applyDiscount(code) {
|
|
607
621
|
return (await this.request("POST", `${this.basePath()}/discount`, { code })).cart;
|
|
608
622
|
}
|
|
609
|
-
|
|
610
|
-
|
|
623
|
+
/**
|
|
624
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code: with
|
|
625
|
+
* both applied, name one with `kind` or `code` (else 400 `discount_kind_required`).
|
|
626
|
+
*/
|
|
627
|
+
async removeDiscount(opts) {
|
|
628
|
+
return (await this.request("DELETE", `${this.basePath()}/discount${removeDiscountQuery(opts)}`)).cart;
|
|
611
629
|
}
|
|
612
630
|
/** Set buyer-editable cart fields. Pass `null` to clear one. */
|
|
613
631
|
async update(input) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/cart",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.1",
|
|
4
4
|
"description": "Typed REST client for the Throttle Cart API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsup",
|
|
34
|
-
"test": "tsc --noEmit --strict --skipLibCheck --target es2022 --lib es2022,dom --module esnext --moduleResolution bundler __tests__/recurring-types.check.ts __tests__/cart-customer-detach.check.ts __tests__/currency-types.check.ts && vitest run",
|
|
34
|
+
"test": "tsc --noEmit --strict --skipLibCheck --target es2022 --lib es2022,dom --module esnext --moduleResolution bundler __tests__/recurring-types.check.ts __tests__/cart-customer-detach.check.ts __tests__/currency-types.check.ts __tests__/free-shipping-types.check.ts && vitest run",
|
|
35
35
|
"typecheck": "tsc --noEmit"
|
|
36
36
|
}
|
|
37
37
|
}
|