@usethrottle/cart 3.19.0 → 3.20.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 +2 -0
- package/dist/index.cjs +21 -3
- package/dist/index.d.cts +85 -4
- package/dist/index.d.ts +85 -4
- package/dist/index.js +21 -3
- package/package.json +4 -4
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;
|
|
@@ -229,6 +235,8 @@ interface SelectShippingMethodInput {
|
|
|
229
235
|
}
|
|
230
236
|
interface SelectedShipping {
|
|
231
237
|
methodId: string;
|
|
238
|
+
/** The connected adapter of a live carrier rate; absent when none was sent. */
|
|
239
|
+
provider?: string;
|
|
232
240
|
carrier: string | null;
|
|
233
241
|
serviceCode: string | null;
|
|
234
242
|
displayName: string;
|
|
@@ -242,10 +250,56 @@ interface AppliedDiscount {
|
|
|
242
250
|
type: 'percentage' | 'fixed_amount';
|
|
243
251
|
amount: number;
|
|
244
252
|
currency: CurrencyCode;
|
|
245
|
-
|
|
253
|
+
/** @deprecated Always `false`: a free-shipping code is `appliedShippingDiscount`, not the goods code. Use `appliedShippingDiscount`. */
|
|
254
|
+
freeShipping?: boolean;
|
|
246
255
|
validUntil: string | null;
|
|
247
256
|
snapshotHash: string;
|
|
248
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* A shipping option a free-shipping code makes free: a native shipping method,
|
|
260
|
+
* or a live carrier service of a connected shipping provider.
|
|
261
|
+
*/
|
|
262
|
+
type ShippingTarget = {
|
|
263
|
+
kind: 'method';
|
|
264
|
+
methodId: string;
|
|
265
|
+
} | {
|
|
266
|
+
kind: 'carrier_service';
|
|
267
|
+
provider: string;
|
|
268
|
+
carrier: string;
|
|
269
|
+
serviceCode: string;
|
|
270
|
+
};
|
|
271
|
+
/** Where a cart's free-shipping code stands against its address and shipping option. */
|
|
272
|
+
type AppliedShippingDiscountStatus = 'applied' | 'not_eligible' | 'pending_address' | 'pending_shipping' | 'merchant_applies';
|
|
273
|
+
/**
|
|
274
|
+
* The cart's free-shipping code (the goods code stays `appliedDiscount`).
|
|
275
|
+
* `zoneIds`, `targets` and `cap` are the code's rules, so a custom checkout can
|
|
276
|
+
* explain them; `null` means all regions, any option, or free in full.
|
|
277
|
+
*/
|
|
278
|
+
interface AppliedShippingDiscount {
|
|
279
|
+
discountId: string;
|
|
280
|
+
code: string;
|
|
281
|
+
/** The reduction the cart carries now, in minor units. */
|
|
282
|
+
amount: number;
|
|
283
|
+
status: AppliedShippingDiscountStatus;
|
|
284
|
+
/** Why the code does not apply, when `status` is `not_eligible`. */
|
|
285
|
+
reason?: 'zone' | 'shipping_option' | 'minimum_order';
|
|
286
|
+
/** How much more the order needs to reach the minimum, when `reason` is `minimum_order`. */
|
|
287
|
+
amountToMinimum?: number;
|
|
288
|
+
zoneIds: string[] | null;
|
|
289
|
+
targets: ShippingTarget[] | null;
|
|
290
|
+
cap: number | null;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Which code to take off a cart that holds a goods code and a free-shipping
|
|
294
|
+
* code. With both applied and neither given the API answers
|
|
295
|
+
* 400 `discount_kind_required`.
|
|
296
|
+
*/
|
|
297
|
+
interface RemoveDiscountOptions {
|
|
298
|
+
/** `order` removes the goods code, `shipping` the free-shipping code. */
|
|
299
|
+
kind?: 'order' | 'shipping';
|
|
300
|
+
/** Remove this code (case-insensitive). */
|
|
301
|
+
code?: string;
|
|
302
|
+
}
|
|
249
303
|
interface TaxLine {
|
|
250
304
|
id: string;
|
|
251
305
|
lineItemId: string;
|
|
@@ -362,6 +416,8 @@ interface SelectShippingInput {
|
|
|
362
416
|
displayName: string;
|
|
363
417
|
rateAmount: number;
|
|
364
418
|
currency?: string;
|
|
419
|
+
/** Connected shipping adapter id of a live carrier rate (`shippo`, `ups`); a free-shipping carrier target matches on it. */
|
|
420
|
+
provider?: string;
|
|
365
421
|
carrier?: string;
|
|
366
422
|
serviceCode?: string;
|
|
367
423
|
estimatedDeliveryDays?: number;
|
|
@@ -441,6 +497,8 @@ interface ShippingTaxCartCalculateInput {
|
|
|
441
497
|
}
|
|
442
498
|
interface ShippingTaxMethod {
|
|
443
499
|
id: string;
|
|
500
|
+
/** A native method's stable key: what a free-shipping `method` target names (`id` changes on every shipping save). */
|
|
501
|
+
stableKey?: string;
|
|
444
502
|
type?: 'ship' | 'pickup';
|
|
445
503
|
label: string;
|
|
446
504
|
amount: number;
|
|
@@ -448,6 +506,16 @@ interface ShippingTaxMethod {
|
|
|
448
506
|
deliveryWindowLabel?: string | null;
|
|
449
507
|
deliveryMinDays?: number | null;
|
|
450
508
|
deliveryMaxDays?: number | null;
|
|
509
|
+
/** Who a live carrier rate came from. Absent on a manual zone method. */
|
|
510
|
+
provider?: string;
|
|
511
|
+
carrier?: string;
|
|
512
|
+
serviceCode?: string;
|
|
513
|
+
/**
|
|
514
|
+
* What the buyer would pay for this option with the cart's free-shipping code
|
|
515
|
+
* applied. Present only when the code would apply to it; `amount` stays the
|
|
516
|
+
* full price.
|
|
517
|
+
*/
|
|
518
|
+
discountedAmount?: number;
|
|
451
519
|
warnings?: Array<{
|
|
452
520
|
code: string;
|
|
453
521
|
message: string;
|
|
@@ -504,7 +572,11 @@ interface ShippingTaxCalculationResponse {
|
|
|
504
572
|
shippingTotal: number;
|
|
505
573
|
taxTotal: number;
|
|
506
574
|
total: number;
|
|
575
|
+
/** What a free-shipping code took off shipping; present only on a cart holding one. */
|
|
576
|
+
shippingDiscountTotal?: number;
|
|
507
577
|
};
|
|
578
|
+
/** The cart's free-shipping code and how it stands; absent on a cart holding none. */
|
|
579
|
+
appliedShippingDiscount?: AppliedShippingDiscount | null;
|
|
508
580
|
/**
|
|
509
581
|
* Verbatim messaging the tax engine returned about this transaction. In
|
|
510
582
|
* several EU member states the engine's own wording is what makes the
|
|
@@ -584,7 +656,12 @@ declare class CartClient {
|
|
|
584
656
|
};
|
|
585
657
|
get discounts(): {
|
|
586
658
|
apply: (cartId: string, code: string) => Promise<Cart>;
|
|
587
|
-
|
|
659
|
+
/**
|
|
660
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code:
|
|
661
|
+
* with both applied, name one with `kind` or `code` (else
|
|
662
|
+
* 400 `discount_kind_required`).
|
|
663
|
+
*/
|
|
664
|
+
remove: (cartId: string, opts?: RemoveDiscountOptions) => Promise<Cart>;
|
|
588
665
|
};
|
|
589
666
|
get taxLines(): {
|
|
590
667
|
set: (cartId: string, lines: TaxLineInput[]) => Promise<Cart>;
|
|
@@ -798,7 +875,11 @@ declare class CartSessionClient {
|
|
|
798
875
|
selectShippingMethod(input: SelectShippingMethodInput): Promise<CartSessionCart>;
|
|
799
876
|
clearShipping(): Promise<CartSessionCart>;
|
|
800
877
|
applyDiscount(code: string): Promise<CartSessionCart>;
|
|
801
|
-
|
|
878
|
+
/**
|
|
879
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code: with
|
|
880
|
+
* both applied, name one with `kind` or `code` (else 400 `discount_kind_required`).
|
|
881
|
+
*/
|
|
882
|
+
removeDiscount(opts?: RemoveDiscountOptions): Promise<CartSessionCart>;
|
|
802
883
|
/** Set buyer-editable cart fields. Pass `null` to clear one. */
|
|
803
884
|
update(input: UpdateCartSessionInput): Promise<CartSessionCart>;
|
|
804
885
|
/**
|
|
@@ -1133,4 +1214,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
1133
1214
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
1134
1215
|
}): ThrottleApiError;
|
|
1135
1216
|
|
|
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 };
|
|
1217
|
+
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;
|
|
@@ -229,6 +235,8 @@ interface SelectShippingMethodInput {
|
|
|
229
235
|
}
|
|
230
236
|
interface SelectedShipping {
|
|
231
237
|
methodId: string;
|
|
238
|
+
/** The connected adapter of a live carrier rate; absent when none was sent. */
|
|
239
|
+
provider?: string;
|
|
232
240
|
carrier: string | null;
|
|
233
241
|
serviceCode: string | null;
|
|
234
242
|
displayName: string;
|
|
@@ -242,10 +250,56 @@ interface AppliedDiscount {
|
|
|
242
250
|
type: 'percentage' | 'fixed_amount';
|
|
243
251
|
amount: number;
|
|
244
252
|
currency: CurrencyCode;
|
|
245
|
-
|
|
253
|
+
/** @deprecated Always `false`: a free-shipping code is `appliedShippingDiscount`, not the goods code. Use `appliedShippingDiscount`. */
|
|
254
|
+
freeShipping?: boolean;
|
|
246
255
|
validUntil: string | null;
|
|
247
256
|
snapshotHash: string;
|
|
248
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* A shipping option a free-shipping code makes free: a native shipping method,
|
|
260
|
+
* or a live carrier service of a connected shipping provider.
|
|
261
|
+
*/
|
|
262
|
+
type ShippingTarget = {
|
|
263
|
+
kind: 'method';
|
|
264
|
+
methodId: string;
|
|
265
|
+
} | {
|
|
266
|
+
kind: 'carrier_service';
|
|
267
|
+
provider: string;
|
|
268
|
+
carrier: string;
|
|
269
|
+
serviceCode: string;
|
|
270
|
+
};
|
|
271
|
+
/** Where a cart's free-shipping code stands against its address and shipping option. */
|
|
272
|
+
type AppliedShippingDiscountStatus = 'applied' | 'not_eligible' | 'pending_address' | 'pending_shipping' | 'merchant_applies';
|
|
273
|
+
/**
|
|
274
|
+
* The cart's free-shipping code (the goods code stays `appliedDiscount`).
|
|
275
|
+
* `zoneIds`, `targets` and `cap` are the code's rules, so a custom checkout can
|
|
276
|
+
* explain them; `null` means all regions, any option, or free in full.
|
|
277
|
+
*/
|
|
278
|
+
interface AppliedShippingDiscount {
|
|
279
|
+
discountId: string;
|
|
280
|
+
code: string;
|
|
281
|
+
/** The reduction the cart carries now, in minor units. */
|
|
282
|
+
amount: number;
|
|
283
|
+
status: AppliedShippingDiscountStatus;
|
|
284
|
+
/** Why the code does not apply, when `status` is `not_eligible`. */
|
|
285
|
+
reason?: 'zone' | 'shipping_option' | 'minimum_order';
|
|
286
|
+
/** How much more the order needs to reach the minimum, when `reason` is `minimum_order`. */
|
|
287
|
+
amountToMinimum?: number;
|
|
288
|
+
zoneIds: string[] | null;
|
|
289
|
+
targets: ShippingTarget[] | null;
|
|
290
|
+
cap: number | null;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Which code to take off a cart that holds a goods code and a free-shipping
|
|
294
|
+
* code. With both applied and neither given the API answers
|
|
295
|
+
* 400 `discount_kind_required`.
|
|
296
|
+
*/
|
|
297
|
+
interface RemoveDiscountOptions {
|
|
298
|
+
/** `order` removes the goods code, `shipping` the free-shipping code. */
|
|
299
|
+
kind?: 'order' | 'shipping';
|
|
300
|
+
/** Remove this code (case-insensitive). */
|
|
301
|
+
code?: string;
|
|
302
|
+
}
|
|
249
303
|
interface TaxLine {
|
|
250
304
|
id: string;
|
|
251
305
|
lineItemId: string;
|
|
@@ -362,6 +416,8 @@ interface SelectShippingInput {
|
|
|
362
416
|
displayName: string;
|
|
363
417
|
rateAmount: number;
|
|
364
418
|
currency?: string;
|
|
419
|
+
/** Connected shipping adapter id of a live carrier rate (`shippo`, `ups`); a free-shipping carrier target matches on it. */
|
|
420
|
+
provider?: string;
|
|
365
421
|
carrier?: string;
|
|
366
422
|
serviceCode?: string;
|
|
367
423
|
estimatedDeliveryDays?: number;
|
|
@@ -441,6 +497,8 @@ interface ShippingTaxCartCalculateInput {
|
|
|
441
497
|
}
|
|
442
498
|
interface ShippingTaxMethod {
|
|
443
499
|
id: string;
|
|
500
|
+
/** A native method's stable key: what a free-shipping `method` target names (`id` changes on every shipping save). */
|
|
501
|
+
stableKey?: string;
|
|
444
502
|
type?: 'ship' | 'pickup';
|
|
445
503
|
label: string;
|
|
446
504
|
amount: number;
|
|
@@ -448,6 +506,16 @@ interface ShippingTaxMethod {
|
|
|
448
506
|
deliveryWindowLabel?: string | null;
|
|
449
507
|
deliveryMinDays?: number | null;
|
|
450
508
|
deliveryMaxDays?: number | null;
|
|
509
|
+
/** Who a live carrier rate came from. Absent on a manual zone method. */
|
|
510
|
+
provider?: string;
|
|
511
|
+
carrier?: string;
|
|
512
|
+
serviceCode?: string;
|
|
513
|
+
/**
|
|
514
|
+
* What the buyer would pay for this option with the cart's free-shipping code
|
|
515
|
+
* applied. Present only when the code would apply to it; `amount` stays the
|
|
516
|
+
* full price.
|
|
517
|
+
*/
|
|
518
|
+
discountedAmount?: number;
|
|
451
519
|
warnings?: Array<{
|
|
452
520
|
code: string;
|
|
453
521
|
message: string;
|
|
@@ -504,7 +572,11 @@ interface ShippingTaxCalculationResponse {
|
|
|
504
572
|
shippingTotal: number;
|
|
505
573
|
taxTotal: number;
|
|
506
574
|
total: number;
|
|
575
|
+
/** What a free-shipping code took off shipping; present only on a cart holding one. */
|
|
576
|
+
shippingDiscountTotal?: number;
|
|
507
577
|
};
|
|
578
|
+
/** The cart's free-shipping code and how it stands; absent on a cart holding none. */
|
|
579
|
+
appliedShippingDiscount?: AppliedShippingDiscount | null;
|
|
508
580
|
/**
|
|
509
581
|
* Verbatim messaging the tax engine returned about this transaction. In
|
|
510
582
|
* several EU member states the engine's own wording is what makes the
|
|
@@ -584,7 +656,12 @@ declare class CartClient {
|
|
|
584
656
|
};
|
|
585
657
|
get discounts(): {
|
|
586
658
|
apply: (cartId: string, code: string) => Promise<Cart>;
|
|
587
|
-
|
|
659
|
+
/**
|
|
660
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code:
|
|
661
|
+
* with both applied, name one with `kind` or `code` (else
|
|
662
|
+
* 400 `discount_kind_required`).
|
|
663
|
+
*/
|
|
664
|
+
remove: (cartId: string, opts?: RemoveDiscountOptions) => Promise<Cart>;
|
|
588
665
|
};
|
|
589
666
|
get taxLines(): {
|
|
590
667
|
set: (cartId: string, lines: TaxLineInput[]) => Promise<Cart>;
|
|
@@ -798,7 +875,11 @@ declare class CartSessionClient {
|
|
|
798
875
|
selectShippingMethod(input: SelectShippingMethodInput): Promise<CartSessionCart>;
|
|
799
876
|
clearShipping(): Promise<CartSessionCart>;
|
|
800
877
|
applyDiscount(code: string): Promise<CartSessionCart>;
|
|
801
|
-
|
|
878
|
+
/**
|
|
879
|
+
* Remove a code. A cart can hold a goods code and a free-shipping code: with
|
|
880
|
+
* both applied, name one with `kind` or `code` (else 400 `discount_kind_required`).
|
|
881
|
+
*/
|
|
882
|
+
removeDiscount(opts?: RemoveDiscountOptions): Promise<CartSessionCart>;
|
|
802
883
|
/** Set buyer-editable cart fields. Pass `null` to clear one. */
|
|
803
884
|
update(input: UpdateCartSessionInput): Promise<CartSessionCart>;
|
|
804
885
|
/**
|
|
@@ -1133,4 +1214,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
1133
1214
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
1134
1215
|
}): ThrottleApiError;
|
|
1135
1216
|
|
|
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 };
|
|
1217
|
+
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.0",
|
|
4
4
|
"description": "Typed REST client for the Throttle Cart API.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@usethrottle/
|
|
22
|
-
"@usethrottle/
|
|
21
|
+
"@usethrottle/errors": "^1.1.0",
|
|
22
|
+
"@usethrottle/money": "^1.1.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"tsup": "^8.0.0",
|
|
@@ -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
|
}
|