@usethrottle/cart 3.17.0 → 3.19.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/dist/index.cjs +77 -2
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +76 -2
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
CurrencyLockedError: () => CurrencyLockedError,
|
|
43
43
|
CurrencyNotAvailableInProductionError: () => CurrencyNotAvailableInProductionError,
|
|
44
44
|
CurrencyNotEnabledError: () => CurrencyNotEnabledError,
|
|
45
|
+
CurrencyNotPayableError: () => CurrencyNotPayableError,
|
|
45
46
|
CurrencyNotSupportedError: () => CurrencyNotSupportedError,
|
|
46
47
|
DiscountCurrencyUnsupportedError: () => DiscountCurrencyUnsupportedError,
|
|
47
48
|
LineLimitReachedError: () => LineLimitReachedError,
|
|
@@ -253,6 +254,17 @@ var CurrencyNotAvailableInProductionError = class extends ThrottleApiError {
|
|
|
253
254
|
this.name = "CurrencyNotAvailableInProductionError";
|
|
254
255
|
}
|
|
255
256
|
};
|
|
257
|
+
var CurrencyNotPayableError = class extends ThrottleApiError {
|
|
258
|
+
currency;
|
|
259
|
+
payableCurrencies;
|
|
260
|
+
constructor(args) {
|
|
261
|
+
super(coded("currency_not_payable", 422, args));
|
|
262
|
+
this.name = "CurrencyNotPayableError";
|
|
263
|
+
const d = args.details;
|
|
264
|
+
this.currency = str(d?.currency);
|
|
265
|
+
this.payableCurrencies = Array.isArray(d?.payableCurrencies) ? d.payableCurrencies.filter((c) => typeof c === "string") : [];
|
|
266
|
+
}
|
|
267
|
+
};
|
|
256
268
|
var CurrencyLockedError = class extends ThrottleApiError {
|
|
257
269
|
constructor(args) {
|
|
258
270
|
super(coded("currency_locked", 409, args));
|
|
@@ -283,6 +295,7 @@ var RESOLVED_CART_ERRORS = {
|
|
|
283
295
|
shipping_currency_unsupported: ShippingCurrencyUnsupportedError,
|
|
284
296
|
currency_not_supported: CurrencyNotSupportedError,
|
|
285
297
|
currency_not_available_in_production: CurrencyNotAvailableInProductionError,
|
|
298
|
+
currency_not_payable: CurrencyNotPayableError,
|
|
286
299
|
currency_locked: CurrencyLockedError,
|
|
287
300
|
quote_amounts_need_review: QuoteAmountsNeedReviewError
|
|
288
301
|
};
|
|
@@ -315,6 +328,67 @@ function cartErrorFromResponse(args) {
|
|
|
315
328
|
return new ThrottleApiError(args);
|
|
316
329
|
}
|
|
317
330
|
|
|
331
|
+
// src/analytics-context.ts
|
|
332
|
+
var LONG_KEYS = ["landingPage", "referrer"];
|
|
333
|
+
var SHORT_KEYS = [
|
|
334
|
+
"utmSource",
|
|
335
|
+
"utmMedium",
|
|
336
|
+
"utmCampaign",
|
|
337
|
+
"utmTerm",
|
|
338
|
+
"utmContent",
|
|
339
|
+
"gclid",
|
|
340
|
+
"fbclid",
|
|
341
|
+
"msclkid",
|
|
342
|
+
"ttclid",
|
|
343
|
+
"gaClientId",
|
|
344
|
+
"gaSessionId",
|
|
345
|
+
"fbp",
|
|
346
|
+
"fbc"
|
|
347
|
+
];
|
|
348
|
+
var CONSENT_KEYS = ["analytics", "marketing", "adUserData", "adPersonalization"];
|
|
349
|
+
var MAX_SHORT = 512;
|
|
350
|
+
var MAX_LONG = 2048;
|
|
351
|
+
var MAX_BYTES = 8192;
|
|
352
|
+
function sanitize(raw) {
|
|
353
|
+
const out = {};
|
|
354
|
+
const take = (keys, max) => {
|
|
355
|
+
for (const key of keys) {
|
|
356
|
+
const v = raw[key];
|
|
357
|
+
if (typeof v !== "string") continue;
|
|
358
|
+
const t = v.trim().slice(0, max).trim();
|
|
359
|
+
if (t) out[key] = t;
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
take(LONG_KEYS, MAX_LONG);
|
|
363
|
+
take(SHORT_KEYS, MAX_SHORT);
|
|
364
|
+
const consent = raw.consent;
|
|
365
|
+
if (consent && typeof consent === "object") {
|
|
366
|
+
const c = {};
|
|
367
|
+
for (const key of CONSENT_KEYS) {
|
|
368
|
+
const v = consent[key];
|
|
369
|
+
if (typeof v === "boolean") c[key] = v;
|
|
370
|
+
}
|
|
371
|
+
if (Object.keys(c).length > 0) out.consent = c;
|
|
372
|
+
}
|
|
373
|
+
if (Object.keys(out).length === 0) return void 0;
|
|
374
|
+
if (new TextEncoder().encode(JSON.stringify(out)).length > MAX_BYTES) return void 0;
|
|
375
|
+
return out;
|
|
376
|
+
}
|
|
377
|
+
function withAnalyticsContext(input) {
|
|
378
|
+
if (input.clientContext !== void 0) return input;
|
|
379
|
+
try {
|
|
380
|
+
const throttle = globalThis.Throttle;
|
|
381
|
+
const fn = throttle?.analyticsContext;
|
|
382
|
+
if (typeof fn !== "function") return input;
|
|
383
|
+
const raw = fn.call(throttle);
|
|
384
|
+
if (!raw || typeof raw !== "object") return input;
|
|
385
|
+
const clientContext = sanitize(raw);
|
|
386
|
+
return clientContext ? { ...input, clientContext } : input;
|
|
387
|
+
} catch {
|
|
388
|
+
return input;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
318
392
|
// src/client.ts
|
|
319
393
|
function segment(value) {
|
|
320
394
|
return encodeURIComponent(value);
|
|
@@ -362,7 +436,7 @@ var CartClient = class {
|
|
|
362
436
|
create: (input) => this.request("POST", "/api/v1/carts", input),
|
|
363
437
|
get: (id) => this.request("GET", `/api/v1/carts/${segment(id)}`),
|
|
364
438
|
update: (id, input) => this.request("PATCH", `/api/v1/carts/${segment(id)}`, input),
|
|
365
|
-
checkout: (id, input) => this.request("POST", `/api/v1/carts/${segment(id)}/checkout`, input ?? {}),
|
|
439
|
+
checkout: (id, input) => this.request("POST", `/api/v1/carts/${segment(id)}/checkout`, withAnalyticsContext(input ?? {})),
|
|
366
440
|
merge: (id, customerId) => this.request("POST", `/api/v1/carts/${segment(id)}/merge`, { customerId })
|
|
367
441
|
};
|
|
368
442
|
}
|
|
@@ -645,7 +719,7 @@ var CartSessionClient = class _CartSessionClient {
|
|
|
645
719
|
}
|
|
646
720
|
/** Hand off to hosted/embedded checkout. Marks the session converted (no more edits). */
|
|
647
721
|
checkout(input) {
|
|
648
|
-
return this.request("POST", `${this.basePath()}/checkout-session`, input);
|
|
722
|
+
return this.request("POST", `${this.basePath()}/checkout-session`, withAnalyticsContext(input));
|
|
649
723
|
}
|
|
650
724
|
basePath() {
|
|
651
725
|
if (!this.sessionId) {
|
|
@@ -706,6 +780,7 @@ var import_money = require("@usethrottle/money");
|
|
|
706
780
|
CurrencyLockedError,
|
|
707
781
|
CurrencyNotAvailableInProductionError,
|
|
708
782
|
CurrencyNotEnabledError,
|
|
783
|
+
CurrencyNotPayableError,
|
|
709
784
|
CurrencyNotSupportedError,
|
|
710
785
|
DiscountCurrencyUnsupportedError,
|
|
711
786
|
LineLimitReachedError,
|
package/dist/index.d.cts
CHANGED
|
@@ -382,6 +382,8 @@ interface CheckoutInput {
|
|
|
382
382
|
termsSnapshot?: string;
|
|
383
383
|
invoiceNumber?: string;
|
|
384
384
|
metadata?: Record<string, unknown>;
|
|
385
|
+
/** The buyer's GA4 ids, UTMs and consent. Defaults to `Throttle.analyticsContext()` when that exists. */
|
|
386
|
+
clientContext?: Record<string, unknown>;
|
|
385
387
|
}
|
|
386
388
|
interface Order {
|
|
387
389
|
id: string;
|
|
@@ -731,6 +733,8 @@ interface CheckoutHandoffInput {
|
|
|
731
733
|
* checkout returns to a live cart. Throttle's own hosted cart page sets this.
|
|
732
734
|
*/
|
|
733
735
|
keepOpen?: boolean;
|
|
736
|
+
/** The buyer's GA4 ids, UTMs and consent. Defaults to `Throttle.analyticsContext()` when that exists. */
|
|
737
|
+
clientContext?: Record<string, unknown>;
|
|
734
738
|
}
|
|
735
739
|
interface CheckoutHandoff {
|
|
736
740
|
cartSessionId: string;
|
|
@@ -1096,6 +1100,16 @@ declare class CurrencyNotSupportedError extends ThrottleApiError {
|
|
|
1096
1100
|
declare class CurrencyNotAvailableInProductionError extends ThrottleApiError {
|
|
1097
1101
|
constructor(args: CartErrorArgs);
|
|
1098
1102
|
}
|
|
1103
|
+
/**
|
|
1104
|
+
* `422 currency_not_payable`: the store cannot take payment in this currency
|
|
1105
|
+
* (payment path). `details` is `{ currency, payableCurrencies }`; a missing or
|
|
1106
|
+
* malformed `details` yields `currency: null` and `payableCurrencies: []`.
|
|
1107
|
+
*/
|
|
1108
|
+
declare class CurrencyNotPayableError extends ThrottleApiError {
|
|
1109
|
+
readonly currency: string | null;
|
|
1110
|
+
readonly payableCurrencies: string[];
|
|
1111
|
+
constructor(args: CartErrorArgs);
|
|
1112
|
+
}
|
|
1099
1113
|
/** `409 currency_locked`: the main currency can't change after the first production sale. */
|
|
1100
1114
|
declare class CurrencyLockedError extends ThrottleApiError {
|
|
1101
1115
|
constructor(args: CartErrorArgs);
|
|
@@ -1119,4 +1133,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
1119
1133
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
1120
1134
|
}): ThrottleApiError;
|
|
1121
1135
|
|
|
1122
|
-
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, 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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -382,6 +382,8 @@ interface CheckoutInput {
|
|
|
382
382
|
termsSnapshot?: string;
|
|
383
383
|
invoiceNumber?: string;
|
|
384
384
|
metadata?: Record<string, unknown>;
|
|
385
|
+
/** The buyer's GA4 ids, UTMs and consent. Defaults to `Throttle.analyticsContext()` when that exists. */
|
|
386
|
+
clientContext?: Record<string, unknown>;
|
|
385
387
|
}
|
|
386
388
|
interface Order {
|
|
387
389
|
id: string;
|
|
@@ -731,6 +733,8 @@ interface CheckoutHandoffInput {
|
|
|
731
733
|
* checkout returns to a live cart. Throttle's own hosted cart page sets this.
|
|
732
734
|
*/
|
|
733
735
|
keepOpen?: boolean;
|
|
736
|
+
/** The buyer's GA4 ids, UTMs and consent. Defaults to `Throttle.analyticsContext()` when that exists. */
|
|
737
|
+
clientContext?: Record<string, unknown>;
|
|
734
738
|
}
|
|
735
739
|
interface CheckoutHandoff {
|
|
736
740
|
cartSessionId: string;
|
|
@@ -1096,6 +1100,16 @@ declare class CurrencyNotSupportedError extends ThrottleApiError {
|
|
|
1096
1100
|
declare class CurrencyNotAvailableInProductionError extends ThrottleApiError {
|
|
1097
1101
|
constructor(args: CartErrorArgs);
|
|
1098
1102
|
}
|
|
1103
|
+
/**
|
|
1104
|
+
* `422 currency_not_payable`: the store cannot take payment in this currency
|
|
1105
|
+
* (payment path). `details` is `{ currency, payableCurrencies }`; a missing or
|
|
1106
|
+
* malformed `details` yields `currency: null` and `payableCurrencies: []`.
|
|
1107
|
+
*/
|
|
1108
|
+
declare class CurrencyNotPayableError extends ThrottleApiError {
|
|
1109
|
+
readonly currency: string | null;
|
|
1110
|
+
readonly payableCurrencies: string[];
|
|
1111
|
+
constructor(args: CartErrorArgs);
|
|
1112
|
+
}
|
|
1099
1113
|
/** `409 currency_locked`: the main currency can't change after the first production sale. */
|
|
1100
1114
|
declare class CurrencyLockedError extends ThrottleApiError {
|
|
1101
1115
|
constructor(args: CartErrorArgs);
|
|
@@ -1119,4 +1133,4 @@ declare function cartErrorFromResponse(args: {
|
|
|
1119
1133
|
responseHeaders?: ThrottleErrorArgs['responseHeaders'];
|
|
1120
1134
|
}): ThrottleApiError;
|
|
1121
1135
|
|
|
1122
|
-
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, 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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -178,6 +178,17 @@ var CurrencyNotAvailableInProductionError = class extends ThrottleApiError {
|
|
|
178
178
|
this.name = "CurrencyNotAvailableInProductionError";
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
|
+
var CurrencyNotPayableError = class extends ThrottleApiError {
|
|
182
|
+
currency;
|
|
183
|
+
payableCurrencies;
|
|
184
|
+
constructor(args) {
|
|
185
|
+
super(coded("currency_not_payable", 422, args));
|
|
186
|
+
this.name = "CurrencyNotPayableError";
|
|
187
|
+
const d = args.details;
|
|
188
|
+
this.currency = str(d?.currency);
|
|
189
|
+
this.payableCurrencies = Array.isArray(d?.payableCurrencies) ? d.payableCurrencies.filter((c) => typeof c === "string") : [];
|
|
190
|
+
}
|
|
191
|
+
};
|
|
181
192
|
var CurrencyLockedError = class extends ThrottleApiError {
|
|
182
193
|
constructor(args) {
|
|
183
194
|
super(coded("currency_locked", 409, args));
|
|
@@ -208,6 +219,7 @@ var RESOLVED_CART_ERRORS = {
|
|
|
208
219
|
shipping_currency_unsupported: ShippingCurrencyUnsupportedError,
|
|
209
220
|
currency_not_supported: CurrencyNotSupportedError,
|
|
210
221
|
currency_not_available_in_production: CurrencyNotAvailableInProductionError,
|
|
222
|
+
currency_not_payable: CurrencyNotPayableError,
|
|
211
223
|
currency_locked: CurrencyLockedError,
|
|
212
224
|
quote_amounts_need_review: QuoteAmountsNeedReviewError
|
|
213
225
|
};
|
|
@@ -240,6 +252,67 @@ function cartErrorFromResponse(args) {
|
|
|
240
252
|
return new ThrottleApiError(args);
|
|
241
253
|
}
|
|
242
254
|
|
|
255
|
+
// src/analytics-context.ts
|
|
256
|
+
var LONG_KEYS = ["landingPage", "referrer"];
|
|
257
|
+
var SHORT_KEYS = [
|
|
258
|
+
"utmSource",
|
|
259
|
+
"utmMedium",
|
|
260
|
+
"utmCampaign",
|
|
261
|
+
"utmTerm",
|
|
262
|
+
"utmContent",
|
|
263
|
+
"gclid",
|
|
264
|
+
"fbclid",
|
|
265
|
+
"msclkid",
|
|
266
|
+
"ttclid",
|
|
267
|
+
"gaClientId",
|
|
268
|
+
"gaSessionId",
|
|
269
|
+
"fbp",
|
|
270
|
+
"fbc"
|
|
271
|
+
];
|
|
272
|
+
var CONSENT_KEYS = ["analytics", "marketing", "adUserData", "adPersonalization"];
|
|
273
|
+
var MAX_SHORT = 512;
|
|
274
|
+
var MAX_LONG = 2048;
|
|
275
|
+
var MAX_BYTES = 8192;
|
|
276
|
+
function sanitize(raw) {
|
|
277
|
+
const out = {};
|
|
278
|
+
const take = (keys, max) => {
|
|
279
|
+
for (const key of keys) {
|
|
280
|
+
const v = raw[key];
|
|
281
|
+
if (typeof v !== "string") continue;
|
|
282
|
+
const t = v.trim().slice(0, max).trim();
|
|
283
|
+
if (t) out[key] = t;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
take(LONG_KEYS, MAX_LONG);
|
|
287
|
+
take(SHORT_KEYS, MAX_SHORT);
|
|
288
|
+
const consent = raw.consent;
|
|
289
|
+
if (consent && typeof consent === "object") {
|
|
290
|
+
const c = {};
|
|
291
|
+
for (const key of CONSENT_KEYS) {
|
|
292
|
+
const v = consent[key];
|
|
293
|
+
if (typeof v === "boolean") c[key] = v;
|
|
294
|
+
}
|
|
295
|
+
if (Object.keys(c).length > 0) out.consent = c;
|
|
296
|
+
}
|
|
297
|
+
if (Object.keys(out).length === 0) return void 0;
|
|
298
|
+
if (new TextEncoder().encode(JSON.stringify(out)).length > MAX_BYTES) return void 0;
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
301
|
+
function withAnalyticsContext(input) {
|
|
302
|
+
if (input.clientContext !== void 0) return input;
|
|
303
|
+
try {
|
|
304
|
+
const throttle = globalThis.Throttle;
|
|
305
|
+
const fn = throttle?.analyticsContext;
|
|
306
|
+
if (typeof fn !== "function") return input;
|
|
307
|
+
const raw = fn.call(throttle);
|
|
308
|
+
if (!raw || typeof raw !== "object") return input;
|
|
309
|
+
const clientContext = sanitize(raw);
|
|
310
|
+
return clientContext ? { ...input, clientContext } : input;
|
|
311
|
+
} catch {
|
|
312
|
+
return input;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
243
316
|
// src/client.ts
|
|
244
317
|
function segment(value) {
|
|
245
318
|
return encodeURIComponent(value);
|
|
@@ -287,7 +360,7 @@ var CartClient = class {
|
|
|
287
360
|
create: (input) => this.request("POST", "/api/v1/carts", input),
|
|
288
361
|
get: (id) => this.request("GET", `/api/v1/carts/${segment(id)}`),
|
|
289
362
|
update: (id, input) => this.request("PATCH", `/api/v1/carts/${segment(id)}`, input),
|
|
290
|
-
checkout: (id, input) => this.request("POST", `/api/v1/carts/${segment(id)}/checkout`, input ?? {}),
|
|
363
|
+
checkout: (id, input) => this.request("POST", `/api/v1/carts/${segment(id)}/checkout`, withAnalyticsContext(input ?? {})),
|
|
291
364
|
merge: (id, customerId) => this.request("POST", `/api/v1/carts/${segment(id)}/merge`, { customerId })
|
|
292
365
|
};
|
|
293
366
|
}
|
|
@@ -570,7 +643,7 @@ var CartSessionClient = class _CartSessionClient {
|
|
|
570
643
|
}
|
|
571
644
|
/** Hand off to hosted/embedded checkout. Marks the session converted (no more edits). */
|
|
572
645
|
checkout(input) {
|
|
573
|
-
return this.request("POST", `${this.basePath()}/checkout-session`, input);
|
|
646
|
+
return this.request("POST", `${this.basePath()}/checkout-session`, withAnalyticsContext(input));
|
|
574
647
|
}
|
|
575
648
|
basePath() {
|
|
576
649
|
if (!this.sessionId) {
|
|
@@ -641,6 +714,7 @@ export {
|
|
|
641
714
|
CurrencyLockedError,
|
|
642
715
|
CurrencyNotAvailableInProductionError,
|
|
643
716
|
CurrencyNotEnabledError,
|
|
717
|
+
CurrencyNotPayableError,
|
|
644
718
|
CurrencyNotSupportedError,
|
|
645
719
|
DiscountCurrencyUnsupportedError,
|
|
646
720
|
LineLimitReachedError,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/cart",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.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/money": "^1.1.0",
|
|
22
|
+
"@usethrottle/errors": "^1.1.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"tsup": "^8.0.0",
|