@aglyn/plugins-commerce 1.32.0 → 1.33.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/package.json +13 -13
- package/src/lib/components/console/shipping-settings-card.component.js +237 -9
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/model/commerce-shipping.d.ts +44 -10
- package/src/lib/model/commerce-shipping.js +60 -5
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/store-setup-content.js +23 -2
- package/src/lib/model/store-setup-content.js.map +1 -1
- package/src/lib/server/carrier-shipping.d.ts +2 -0
- package/src/lib/server/carrier-shipping.js +8 -4
- package/src/lib/server/carrier-shipping.js.map +1 -1
- package/src/lib/server/cart-checkout.js +7 -2
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/checkout.js +5 -0
- package/src/lib/server/checkout.js.map +1 -1
|
@@ -96,7 +96,46 @@ export interface ShippingRate {
|
|
|
96
96
|
amountsByCurrency?: Record<string, number>;
|
|
97
97
|
/** free_over: the threshold in another currency (AGL-4248), minor units by ISO code. */
|
|
98
98
|
freeOverByCurrency?: Record<string, number>;
|
|
99
|
+
/**
|
|
100
|
+
* Conditions (AGL-4255), the way Shopify sets one on a rate: the rate is
|
|
101
|
+
* offered only to a cart whose PRE-discount items subtotal is at least
|
|
102
|
+
* `minSubtotalCents` and at most `maxSubtotalCents`, and whose weight is at
|
|
103
|
+
* least `minGrams` and at most `maxGrams`. Each bound is optional and
|
|
104
|
+
* inclusive. A cart no rate of its zone is offered to is refused as
|
|
105
|
+
* `cart-unpriceable`, the way Shopify says shipping is not available.
|
|
106
|
+
*/
|
|
107
|
+
minSubtotalCents?: number;
|
|
108
|
+
maxSubtotalCents?: number;
|
|
109
|
+
/** The order-price bounds in another currency, minor units by ISO code; a currency not listed uses the store figure converted. */
|
|
110
|
+
minSubtotalByCurrency?: Record<string, number>;
|
|
111
|
+
maxSubtotalByCurrency?: Record<string, number>;
|
|
112
|
+
minGrams?: number;
|
|
113
|
+
maxGrams?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The cart a rate is priced and conditioned against. `shopperSubtotal` is
|
|
117
|
+
* the same items subtotal in the currency the shopper is charged in
|
|
118
|
+
* (AGL-4248), when that is not the store's: a condition with its own figure
|
|
119
|
+
* in that currency is judged against it, every other against `subtotalCents`.
|
|
120
|
+
*/
|
|
121
|
+
export interface ShippingCart {
|
|
122
|
+
subtotalCents: number;
|
|
123
|
+
totalGrams?: number;
|
|
124
|
+
shopperSubtotal?: {
|
|
125
|
+
code: string;
|
|
126
|
+
minor: number;
|
|
127
|
+
};
|
|
99
128
|
}
|
|
129
|
+
/** Whether a rate carries any order-price or weight condition (AGL-4255). */
|
|
130
|
+
export declare function rateHasConditions(rate: ShippingRate): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Whether a cart meets a rate's conditions (AGL-4255). A rate with none
|
|
133
|
+
* meets every cart. A per-currency bound is used only when the cart says
|
|
134
|
+
* what the shopper is charged in that currency.
|
|
135
|
+
*/
|
|
136
|
+
export declare function rateConditionMet(rate: ShippingRate, cart: ShippingCart): boolean;
|
|
137
|
+
/** How a rate's conditions read in a list, e.g. `Orders $150.00 and up` (AGL-4255); empty with none. */
|
|
138
|
+
export declare function describeRateConditions(rate: ShippingRate, currencyCode?: string): string;
|
|
100
139
|
export interface ShippingSettings {
|
|
101
140
|
zones?: ShippingZone[];
|
|
102
141
|
rates?: ShippingRate[];
|
|
@@ -151,9 +190,8 @@ export declare function carrierOptionAmountCents(quotedCents: number, settings:
|
|
|
151
190
|
* Callers deciding whether a destination is served must filter pickup out
|
|
152
191
|
* first; `planCheckoutShipping` and `summarizeShippingCoverage` do (AGL-2325).
|
|
153
192
|
*/
|
|
154
|
-
export declare function resolveShippingRates(settings: ShippingSettings | undefined, destinationCountry: string | undefined, cart: {
|
|
155
|
-
|
|
156
|
-
totalGrams?: number;
|
|
193
|
+
export declare function resolveShippingRates(settings: ShippingSettings | undefined, destinationCountry: string | undefined, cart: ShippingCart, options?: {
|
|
194
|
+
ignoreConditions?: boolean;
|
|
157
195
|
}): ResolvedShippingRate[];
|
|
158
196
|
/** Stripe Checkout accepts at most 5 `shipping_options` on one session. */
|
|
159
197
|
export declare const MAX_CHECKOUT_SHIPPING_OPTIONS = 5;
|
|
@@ -183,9 +221,8 @@ export declare const CHECKOUT_SHIPPING_COUNTRIES: readonly ["US", "CA", "GB", "A
|
|
|
183
221
|
* then declare no `shipping_options` at all rather than an empty array — a
|
|
184
222
|
* merchant who never set shipping up keeps a session identical to today's.
|
|
185
223
|
*/
|
|
186
|
-
export declare function resolveCheckoutShippingOptions(settings: ShippingSettings | undefined, destinationCountries: readonly string[], cart: {
|
|
187
|
-
|
|
188
|
-
totalGrams?: number;
|
|
224
|
+
export declare function resolveCheckoutShippingOptions(settings: ShippingSettings | undefined, destinationCountries: readonly string[], cart: ShippingCart, options?: {
|
|
225
|
+
ignoreConditions?: boolean;
|
|
189
226
|
}): ResolvedShippingRate[];
|
|
190
227
|
/**
|
|
191
228
|
* {@link CHECKOUT_SHIPPING_COUNTRIES} as plain codes: the apps' draft order
|
|
@@ -307,10 +344,7 @@ export declare const CART_UNPRICEABLE_SHIPPING_MESSAGE: string;
|
|
|
307
344
|
* `cart.subtotalCents` is the PRE-discount items total, matching what the cart
|
|
308
345
|
* displays, so a free-over threshold means what the shopper saw it mean.
|
|
309
346
|
*/
|
|
310
|
-
export declare function planCheckoutShipping(settings: ShippingSettings | undefined, cart:
|
|
311
|
-
subtotalCents: number;
|
|
312
|
-
totalGrams?: number;
|
|
313
|
-
}, destinationCountry?: unknown): CheckoutShippingPlan;
|
|
347
|
+
export declare function planCheckoutShipping(settings: ShippingSettings | undefined, cart: ShippingCart, destinationCountry?: unknown): CheckoutShippingPlan;
|
|
314
348
|
/** What a merchant's saved zones and rates cost their shoppers (AGL-1791). */
|
|
315
349
|
export interface ShippingCoverage {
|
|
316
350
|
/** How many destinations checkout collects an address for. */
|
|
@@ -41,6 +41,55 @@
|
|
|
41
41
|
* a draft order.
|
|
42
42
|
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
43
43
|
/** How long checkout waits for live carrier quotes before it falls back. */ export const CARRIER_QUOTE_TIMEOUT_MS = 3000;
|
|
44
|
+
const conditionBound = (value)=>{
|
|
45
|
+
const n = Number(value);
|
|
46
|
+
return value == null || value === '' || !Number.isFinite(n) || n < 0 ? undefined : Math.round(n);
|
|
47
|
+
};
|
|
48
|
+
/** Whether a rate carries any order-price or weight condition (AGL-4255). */ export function rateHasConditions(rate) {
|
|
49
|
+
return conditionBound(rate.minSubtotalCents) != null || conditionBound(rate.maxSubtotalCents) != null || conditionBound(rate.minGrams) != null || conditionBound(rate.maxGrams) != null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether a cart meets a rate's conditions (AGL-4255). A rate with none
|
|
53
|
+
* meets every cart. A per-currency bound is used only when the cart says
|
|
54
|
+
* what the shopper is charged in that currency.
|
|
55
|
+
*/ export function rateConditionMet(rate, cart) {
|
|
56
|
+
var _cart_shopperSubtotal_code, _cart_shopperSubtotal;
|
|
57
|
+
const code = (_cart_shopperSubtotal = cart.shopperSubtotal) == null ? void 0 : (_cart_shopperSubtotal_code = _cart_shopperSubtotal.code) == null ? void 0 : _cart_shopperSubtotal_code.toUpperCase();
|
|
58
|
+
const own = (map)=>code && cart.shopperSubtotal ? conditionBound(map == null ? void 0 : map[code]) : undefined;
|
|
59
|
+
const bound = (base, map)=>{
|
|
60
|
+
var _cart_shopperSubtotal;
|
|
61
|
+
const local = own(map);
|
|
62
|
+
return local != null ? {
|
|
63
|
+
limit: local,
|
|
64
|
+
value: Number((_cart_shopperSubtotal = cart.shopperSubtotal) == null ? void 0 : _cart_shopperSubtotal.minor) || 0
|
|
65
|
+
} : conditionBound(base) != null ? {
|
|
66
|
+
limit: conditionBound(base),
|
|
67
|
+
value: Number(cart.subtotalCents) || 0
|
|
68
|
+
} : undefined;
|
|
69
|
+
};
|
|
70
|
+
const min = bound(rate.minSubtotalCents, rate.minSubtotalByCurrency);
|
|
71
|
+
if (min && min.value < min.limit) return false;
|
|
72
|
+
const max = bound(rate.maxSubtotalCents, rate.maxSubtotalByCurrency);
|
|
73
|
+
if (max && max.value > max.limit) return false;
|
|
74
|
+
const grams = Math.max(0, Number(cart.totalGrams) || 0);
|
|
75
|
+
const minGrams = conditionBound(rate.minGrams);
|
|
76
|
+
if (minGrams != null && grams < minGrams) return false;
|
|
77
|
+
const maxGrams = conditionBound(rate.maxGrams);
|
|
78
|
+
if (maxGrams != null && grams > maxGrams) return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
/** How a rate's conditions read in a list, e.g. `Orders $150.00 and up` (AGL-4255); empty with none. */ export function describeRateConditions(rate, currencyCode = 'USD') {
|
|
82
|
+
const money = (cents)=>new Intl.NumberFormat('en-US', {
|
|
83
|
+
style: 'currency',
|
|
84
|
+
currency: currencyCode
|
|
85
|
+
}).format(cents / 100);
|
|
86
|
+
const weight = (grams)=>grams >= 1000 ? `${Number((grams / 1000).toFixed(2))} kg` : `${grams} g`;
|
|
87
|
+
const range = (min, max, noun, show)=>min != null && max != null ? `${noun} ${show(min)} to ${show(max)}` : min != null ? `${noun} ${show(min)} and up` : max != null ? `${noun} up to ${show(max)}` : '';
|
|
88
|
+
return [
|
|
89
|
+
range(conditionBound(rate.minSubtotalCents), conditionBound(rate.maxSubtotalCents), 'Orders', money),
|
|
90
|
+
range(conditionBound(rate.minGrams), conditionBound(rate.maxGrams), 'Weighing', weight)
|
|
91
|
+
].filter(Boolean).join(', ');
|
|
92
|
+
}
|
|
44
93
|
/**
|
|
45
94
|
* The rate id appended for local pickup (AGL-2325).
|
|
46
95
|
*
|
|
@@ -132,7 +181,7 @@ function tierAmount(tiers, value) {
|
|
|
132
181
|
* collect — but it means A NON-EMPTY RESULT IS NOT A PROMISE TO SHIP THERE.
|
|
133
182
|
* Callers deciding whether a destination is served must filter pickup out
|
|
134
183
|
* first; `planCheckoutShipping` and `summarizeShippingCoverage` do (AGL-2325).
|
|
135
|
-
*/ export function resolveShippingRates(settings, destinationCountry, cart) {
|
|
184
|
+
*/ export function resolveShippingRates(settings, destinationCountry, cart, options = {}) {
|
|
136
185
|
var _settings_rates;
|
|
137
186
|
if (!settings || !destinationCountry) return [];
|
|
138
187
|
const zoneIds = matchedZoneIds(settings, destinationCountry);
|
|
@@ -146,6 +195,8 @@ function tierAmount(tiers, value) {
|
|
|
146
195
|
const resolved = [];
|
|
147
196
|
for (const rate of (_settings_rates = settings.rates) != null ? _settings_rates : []){
|
|
148
197
|
if (!zoneIds.has(rate.zoneId)) continue;
|
|
198
|
+
// A rate whose conditions this cart misses is not offered (AGL-4255).
|
|
199
|
+
if (!options.ignoreConditions && !rateConditionMet(rate, cart)) continue;
|
|
149
200
|
let amountCents = null;
|
|
150
201
|
switch(rate.kind){
|
|
151
202
|
case 'flat':
|
|
@@ -227,11 +278,11 @@ function tierAmount(tiers, value) {
|
|
|
227
278
|
* Returns `[]` for a merchant who has configured nothing, and the caller must
|
|
228
279
|
* then declare no `shipping_options` at all rather than an empty array — a
|
|
229
280
|
* merchant who never set shipping up keeps a session identical to today's.
|
|
230
|
-
*/ export function resolveCheckoutShippingOptions(settings, destinationCountries, cart) {
|
|
281
|
+
*/ export function resolveCheckoutShippingOptions(settings, destinationCountries, cart, options = {}) {
|
|
231
282
|
if (!settings) return [];
|
|
232
283
|
const byRateId = new Map();
|
|
233
284
|
for (const country of destinationCountries){
|
|
234
|
-
for (const rate of resolveShippingRates(settings, country, cart)){
|
|
285
|
+
for (const rate of resolveShippingRates(settings, country, cart, options)){
|
|
235
286
|
// Stripe requires a display name, and a rate id is the dedupe key —
|
|
236
287
|
// the console lets a merchant add a blank row, so neither is assured.
|
|
237
288
|
if (!rate.rateId || !rate.name) continue;
|
|
@@ -725,7 +776,9 @@ function tierAmount(tiers, value) {
|
|
|
725
776
|
* the four rate kinds price against one: `tierAmount` takes the first tier
|
|
726
777
|
* whose `upTo` is at least the value, so a zero subtotal and zero weight clear
|
|
727
778
|
* every tier a merchant would write, and a `free_over` rate resolves at any
|
|
728
|
-
* subtotal.
|
|
779
|
+
* subtotal. A rate's conditions (AGL-4255) are set aside for the same reason:
|
|
780
|
+
* some cart meets them, so a zone whose only rate is "free over $150" is
|
|
781
|
+
* served, not turned away.
|
|
729
782
|
*
|
|
730
783
|
* That makes a coverage answer a LOWER BOUND on the gaps. A destination
|
|
731
784
|
* reported unserved is unserved for every cart; a destination reported served
|
|
@@ -758,7 +811,9 @@ function tierAmount(tiers, value) {
|
|
|
758
811
|
for (const country of collectable){
|
|
759
812
|
const options = resolveCheckoutShippingOptions(settings, [
|
|
760
813
|
country
|
|
761
|
-
], COVERAGE_PROBE_CART
|
|
814
|
+
], COVERAGE_PROBE_CART, {
|
|
815
|
+
ignoreConditions: true
|
|
816
|
+
});
|
|
762
817
|
// `asksDestination` is asked of the FULL list — pickup is a real option a
|
|
763
818
|
// shopper picks, so a merchant whose US destination offers a rate plus
|
|
764
819
|
// pickup while France offers only pickup genuinely does make checkout ask.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-shipping.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Shipping v1 (AGL-288): zones own countries; rates belong to a zone and\n * price as flat, free-over-threshold, or subtotal/weight tiers. Settings\n * live on `hosts/{hostId}/settings/store` under `shipping`. Pure.\n *\n * `resolveShippingRates` is the per-destination resolver;\n * `resolveCheckoutShippingOptions` is the Stripe Checkout adapter,\n * `planCheckoutShipping` decides which destinations one session may serve,\n * `appendCheckoutShippingParams` emits it onto a session, and\n * `summarizeShippingCoverage` answers the same question for the console, so a\n * merchant can see which destinations their zones refuse. AGL-288 shipped this\n * model with no production call site at all — the doc comment here claimed the\n * cart estimator, checkout and POS pickup used it, and none of them did, so\n * nothing ever read the settings a merchant saved and no shipping was ever\n * charged. Cart checkout calls it (AGL-1707), buy-now calls it for physical\n * one-time products (AGL-1720), and a draft order's payment link calls it for\n * physical products (AGL-1792).\n *\n * POS DOES NOT, AND SHOULD NOT (AGL-1792). A register has no destination\n * anywhere in it — no address field, no delivery choice — and all three\n * tenders settle at the counter: cash, a card QR the customer scans while\n * standing there, and a room folio collected at check-out. There is nothing to\n * price a parcel against, so the only rate POS could resolve is the free\n * `Local pickup` one this module appends, which is 0¢ and would add a step to\n * a register flow in exchange for nothing. A POS sale that must be shipped is\n * a draft order.\n */\n\nexport interface ShippingZone {\n id: string\n name: string\n /** ISO-3166 alpha-2 codes; '*' = rest of world. */\n countries: string[]\n}\n\nexport interface ShippingTier {\n /** Tier applies while subtotal (cents) or weight (grams) ≤ this. */\n upTo: number\n amountCents: number\n}\n\n/**\n * A live carrier rate (AGL-3612): the zone's price is what a carrier quotes\n * for the parcel to the shopper's address, asked through core's\n * `core.shipping-rate-quoter` seam of whichever plugin quotes carriers. With\n * no quoter, a quoter that is not available for the site, no postal code to\n * quote against, or a quote slower than {@link CARRIER_QUOTE_TIMEOUT_MS}, it\n * offers nothing and its fallback rate is offered instead.\n */\nexport interface CarrierRateSettings {\n /** Service keys (`carrier:service`) to offer; empty offers every quoted service. */\n services?: string[]\n /** Added to each quote, in percent. */\n markupPct?: number\n /** Added to each quote after the markup, in cents. */\n handlingCents?: number\n /**\n * A rate of this zone offered when no live quote is: it is HIDDEN while\n * quotes are offered, so the shopper picks between carriers, not between a\n * carrier and the merchant's guess.\n */\n fallbackRateId?: string\n}\n\n/** How long checkout waits for live carrier quotes before it falls back. */\nexport const CARRIER_QUOTE_TIMEOUT_MS = 3_000\n\nexport interface ShippingRate {\n id: string\n zoneId: string\n name: string\n kind: 'flat' | 'free_over' | 'price_tiers' | 'weight_tiers' | 'carrier'\n /** flat + free_over base amount. */\n amountCents?: number\n /** free_over: order subtotal (cents) at/above which shipping is free. */\n freeOverCents?: number\n /** price_tiers (upTo = subtotal cents) / weight_tiers (upTo = grams). */\n tiers?: ShippingTier[]\n /** carrier: the live rate's options (AGL-3612). */\n carrier?: CarrierRateSettings\n /**\n * flat + free_over: the price in another currency the store sells in\n * (AGL-4248), minor units keyed by ISO code. A currency not listed converts.\n */\n amountsByCurrency?: Record<string, number>\n /** free_over: the threshold in another currency (AGL-4248), minor units by ISO code. */\n freeOverByCurrency?: Record<string, number>\n}\n\nexport interface ShippingSettings {\n zones?: ShippingZone[]\n rates?: ShippingRate[]\n /**\n * Offer free local pickup as a delivery choice. Does NOT widen where the\n * store ships: a destination no rate reaches is still refused (AGL-2325).\n */\n localPickup?: boolean\n}\n\nexport interface ResolvedShippingRate {\n rateId: string\n name: string\n amountCents: number\n}\n\n/**\n * The rate id appended for local pickup (AGL-2325).\n *\n * Exported because pickup is the one entry in a resolved list that is NOT a\n * shipping promise: it is appended AFTER and INDEPENDENT of zone matching, so\n * it resolves for every destination on earth. Anything asking \"does this store\n * ship there\" — the checkout refusal, the console coverage card — has to be\n * able to tell it apart from a rate, or it reads a merchant who offers\n * collection as a merchant who delivers worldwide.\n */\nexport const LOCAL_PICKUP_RATE_ID = 'pickup'\n\n/**\n * One stored country code, normalised (AGL-2298).\n *\n * TRIMMED as well as upper-cased. The console trims on save, so this only\n * matters for a document written any other way — an import, the REST API, a\n * hand edit — but the failure it produces is silent and expensive: `' US'`\n * upper-cases to `' US'`, matches nothing, and the store refuses every US\n * shopper with \"This store does not ship to the United States\" while its\n * settings card shows `US` right there.\n */\nconst zoneCode = (code: unknown): string => String(code ?? '').trim().toUpperCase()\n\n/** Whether a stored code is the rest-of-world wildcard. */\nconst isWildcard = (code: unknown): boolean => zoneCode(code) === '*'\n\nfunction zoneMatches(zone: ShippingZone, country: string): boolean {\n return (zone.countries ?? []).some(\n (code) => isWildcard(code) || zoneCode(code) === country,\n )\n}\n\nfunction tierAmount(\n tiers: ShippingTier[] | undefined,\n value: number,\n): number | null {\n const sorted = [...(tiers ?? [])].sort((a, b) => a.upTo - b.upTo)\n for (const tier of sorted) {\n if (value <= tier.upTo) return tier.amountCents\n }\n // Beyond the last tier the rate does not apply (merchant should add a\n // catch-all tier with a large upTo).\n return null\n}\n\n/**\n * The zones a destination falls in (AGL-1707, factored out for AGL-3612).\n * Specific country zones beat '*' zones: when any zone names the country\n * outright, rest-of-world zones are ignored.\n */\nexport function matchedZoneIds(\n settings: ShippingSettings | undefined,\n destinationCountry: string,\n): Set<string> {\n const country = destinationCountry.toUpperCase()\n const zones = settings?.zones ?? []\n // A zone is SPECIFIC when it names this country outright — not merely when\n // it is \"not wildcard-only\" (AGL-2298). The old test was `!every(code ===\n // '*')`, so a zone spelled `['*','US']` counted as specific for all six\n // destinations (it matches every country through the `*`) and suppressed\n // every genuine rest-of-world zone globally. Asking the narrower question\n // makes such a zone specific for `US` and wildcard for the rest, which is\n // what its two entries actually say.\n const specific = zones.filter((zone) =>\n (zone.countries ?? []).some((code) => zoneCode(code) === country),\n )\n const matched = specific.length\n ? specific\n : zones.filter((zone) => zoneMatches(zone, country))\n return new Set(matched.map((zone) => zone.id))\n}\n\n/** The live carrier rates a destination's zones carry (AGL-3612). */\nexport function carrierRatesFor(\n settings: ShippingSettings | undefined,\n destinationCountry: string,\n): ShippingRate[] {\n if (!settings) return []\n const zoneIds = matchedZoneIds(settings, destinationCountry)\n return (settings.rates ?? []).filter(\n (rate) => rate.kind === 'carrier' && zoneIds.has(rate.zoneId),\n )\n}\n\n/** Whether any zone carries a live carrier rate (AGL-3612). */\nexport function hasCarrierRates(settings: ShippingSettings | undefined): boolean {\n return (settings?.rates ?? []).some((rate) => rate.kind === 'carrier')\n}\n\n/** The rate id a quoted service is offered under: stable per rate and service. */\nexport function carrierOptionRateId(rateId: string, serviceKey: string): string {\n return `carrier:${rateId}:${serviceKey}`\n}\n\n/**\n * What a shopper pays for a carrier's quote under one carrier rate: the\n * quote, plus the markup, plus the handling fee, in whole cents.\n */\nexport function carrierOptionAmountCents(\n quotedCents: number,\n settings: CarrierRateSettings | undefined,\n): number {\n const quote = Math.max(0, Math.round(Number(quotedCents) || 0))\n const pct = Number(settings?.markupPct)\n const handling = Number(settings?.handlingCents)\n return (\n quote +\n (Number.isFinite(pct) && pct > 0 ? Math.round((quote * Math.min(pct, 500)) / 100) : 0) +\n (Number.isFinite(handling) && handling > 0 ? Math.round(handling) : 0)\n )\n}\n\n/**\n * Rates available for a destination + cart, cheapest first. Specific\n * country zones beat '*' zones: when any specific zone matches, '*'\n * zones are ignored (rest-of-world semantics).\n *\n * Local pickup is appended AFTER and INDEPENDENT of zone matching, so this\n * list is never empty for a merchant who offers it, at any destination. That\n * is correct for a resolver — a shopper anywhere may choose to come and\n * collect — but it means A NON-EMPTY RESULT IS NOT A PROMISE TO SHIP THERE.\n * Callers deciding whether a destination is served must filter pickup out\n * first; `planCheckoutShipping` and `summarizeShippingCoverage` do (AGL-2325).\n */\nexport function resolveShippingRates(\n settings: ShippingSettings | undefined,\n destinationCountry: string | undefined,\n cart: { subtotalCents: number; totalGrams?: number },\n): ResolvedShippingRate[] {\n if (!settings || !destinationCountry) return []\n const zoneIds = matchedZoneIds(settings, destinationCountry)\n // A zone is SPECIFIC when it names this country outright — not merely when\n // it is \"not wildcard-only\" (AGL-2298). The old test was `!every(code ===\n // '*')`, so a zone spelled `['*','US']` counted as specific for all six\n // destinations (it matches every country through the `*`) and suppressed\n // every genuine rest-of-world zone globally. Asking the narrower question\n // makes such a zone specific for `US` and wildcard for the rest, which is\n // what its two entries actually say.\n const resolved: ResolvedShippingRate[] = []\n for (const rate of settings.rates ?? []) {\n if (!zoneIds.has(rate.zoneId)) continue\n let amountCents: number | null = null\n switch (rate.kind) {\n case 'flat':\n amountCents = Math.max(0, Math.round(rate.amountCents ?? 0))\n break\n case 'free_over':\n amountCents =\n rate.freeOverCents != null &&\n cart.subtotalCents >= rate.freeOverCents\n ? 0\n : Math.max(0, Math.round(rate.amountCents ?? 0))\n break\n case 'price_tiers':\n amountCents = tierAmount(rate.tiers, cart.subtotalCents)\n break\n case 'weight_tiers':\n amountCents = tierAmount(rate.tiers, cart.totalGrams ?? 0)\n break\n // A carrier's price exists only once a carrier quoted it for an\n // address (AGL-3612), so a table read offers nothing for it and its\n // fallback rate is what resolves here. `carrier-shipping.ts` adds the\n // quotes where one can be had.\n case 'carrier':\n break\n }\n if (amountCents == null) continue\n resolved.push({ rateId: rate.id, name: rate.name, amountCents })\n }\n if (settings.localPickup) {\n resolved.push({\n rateId: LOCAL_PICKUP_RATE_ID,\n name: 'Local pickup',\n amountCents: 0,\n })\n }\n return resolved.sort((a, b) => a.amountCents - b.amountCents)\n}\n\n/**\n * The resolved options that actually carry a parcel (AGL-2325).\n *\n * Safe to apply AFTER `MAX_CHECKOUT_SHIPPING_OPTIONS` truncation: pickup is\n * 0¢ and sorts first, so it occupies at most one of the five slots and a\n * merchant with any shippable rate at all keeps at least one of them.\n */\nfunction shippableOnly(\n options: readonly ResolvedShippingRate[],\n): ResolvedShippingRate[] {\n return options.filter((option) => option.rateId !== LOCAL_PICKUP_RATE_ID)\n}\n\n/** Stripe Checkout accepts at most 5 `shipping_options` on one session. */\nexport const MAX_CHECKOUT_SHIPPING_OPTIONS = 5\n\n/**\n * The destinations a Checkout Session collects an address for when the\n * merchant prices NO shipping (AGL-1707), and so the session such a store has\n * always had. A merchant with zones gets `checkoutShippingCountries` instead:\n * the countries their zones name, or every country for rest of world.\n */\nexport const CHECKOUT_SHIPPING_COUNTRIES = [\n 'US',\n 'CA',\n 'GB',\n 'AU',\n 'DE',\n 'FR',\n] as const\n\n/**\n * The rates to declare as `shipping_options` on a Stripe Checkout Session\n * (AGL-1707), unioned over `destinationCountries`. Stripe charges shipping\n * ONLY when the session declares them.\n *\n * A UNION IS ONLY HONEST OVER DESTINATIONS THE SESSION IS ALSO RESTRICTED TO.\n * Called with every collectable country while the session accepted an address\n * in any of them — which is what AGL-1707 shipped — it offers a shopper in one\n * zone a rate belonging to another, and Stripe applies whichever the shopper\n * picks (a `shipping_rate_data` carries no country of its own, so nothing\n * downstream re-checks it against the address). That is AGL-1721. Callers now\n * reach this through `planCheckoutShipping`, which pairs the country list it\n * unions over with the country list the session allows, so the two cannot\n * disagree. Do not call it directly from a handler.\n *\n * Returns `[]` for a merchant who has configured nothing, and the caller must\n * then declare no `shipping_options` at all rather than an empty array — a\n * merchant who never set shipping up keeps a session identical to today's.\n */\nexport function resolveCheckoutShippingOptions(\n settings: ShippingSettings | undefined,\n destinationCountries: readonly string[],\n cart: { subtotalCents: number; totalGrams?: number },\n): ResolvedShippingRate[] {\n if (!settings) return []\n const byRateId = new Map<string, ResolvedShippingRate>()\n for (const country of destinationCountries) {\n for (const rate of resolveShippingRates(settings, country, cart)) {\n // Stripe requires a display name, and a rate id is the dedupe key —\n // the console lets a merchant add a blank row, so neither is assured.\n if (!rate.rateId || !rate.name) continue\n const amountCents = Math.max(0, Math.round(Number(rate.amountCents) || 0))\n const existing = byRateId.get(rate.rateId)\n // One rate resolving differently for two countries should not be\n // possible (a zone selects a rate, it does not reprice one), but if it\n // ever is, keep the dearer. Under-charging is the defect being fixed.\n if (!existing || amountCents > existing.amountCents) {\n byRateId.set(rate.rateId, { ...rate, amountCents })\n }\n }\n }\n return (\n [...byRateId.values()]\n // Cheapest first, id as a tie-break so the emitted params are stable.\n .sort(\n (a, b) =>\n a.amountCents - b.amountCents || a.rateId.localeCompare(b.rateId),\n )\n // Past Stripe's cap the dearest are dropped, which is the harmless end\n // to lose: a shopper offered the cheap options would have taken one.\n .slice(0, MAX_CHECKOUT_SHIPPING_OPTIONS)\n )\n}\n\n/**\n * {@link CHECKOUT_SHIPPING_COUNTRIES} as plain codes: the apps' draft order\n * falls back to it only when the server names no list (AGL-3841).\n */\nexport const CHECKOUT_SHIPPING_COUNTRY_CODES: readonly string[] = CHECKOUT_SHIPPING_COUNTRIES\n\n/**\n * Every country Stripe Checkout can collect a shipping address for\n * (`shipping_address_collection[allowed_countries]`), with the name a shopper\n * reads. A rest-of-world `*` zone opens checkout to all of them.\n */\nexport const CHECKOUT_SHIPPING_COUNTRY_NAMES: Readonly<Record<string, string>> =\n {\n AC: \"Ascension Island\",\n AD: \"Andorra\",\n AE: \"United Arab Emirates\",\n AF: \"Afghanistan\",\n AG: \"Antigua & Barbuda\",\n AI: \"Anguilla\",\n AL: \"Albania\",\n AM: \"Armenia\",\n AO: \"Angola\",\n AQ: \"Antarctica\",\n AR: \"Argentina\",\n AT: \"Austria\",\n AU: \"Australia\",\n AW: \"Aruba\",\n AX: \"Åland Islands\",\n AZ: \"Azerbaijan\",\n BA: \"Bosnia & Herzegovina\",\n BB: \"Barbados\",\n BD: \"Bangladesh\",\n BE: \"Belgium\",\n BF: \"Burkina Faso\",\n BG: \"Bulgaria\",\n BH: \"Bahrain\",\n BI: \"Burundi\",\n BJ: \"Benin\",\n BL: \"St. Barthélemy\",\n BM: \"Bermuda\",\n BN: \"Brunei\",\n BO: \"Bolivia\",\n BQ: \"Caribbean Netherlands\",\n BR: \"Brazil\",\n BS: \"Bahamas\",\n BT: \"Bhutan\",\n BV: \"Bouvet Island\",\n BW: \"Botswana\",\n BY: \"Belarus\",\n BZ: \"Belize\",\n CA: \"Canada\",\n CD: \"Congo - Kinshasa\",\n CF: \"Central African Republic\",\n CG: \"Congo - Brazzaville\",\n CH: \"Switzerland\",\n CI: \"Côte d’Ivoire\",\n CK: \"Cook Islands\",\n CL: \"Chile\",\n CM: \"Cameroon\",\n CN: \"China\",\n CO: \"Colombia\",\n CR: \"Costa Rica\",\n CV: \"Cape Verde\",\n CW: \"Curaçao\",\n CY: \"Cyprus\",\n CZ: \"Czechia\",\n DE: \"Germany\",\n DJ: \"Djibouti\",\n DK: \"Denmark\",\n DM: \"Dominica\",\n DO: \"Dominican Republic\",\n DZ: \"Algeria\",\n EC: \"Ecuador\",\n EE: \"Estonia\",\n EG: \"Egypt\",\n EH: \"Western Sahara\",\n ER: \"Eritrea\",\n ES: \"Spain\",\n ET: \"Ethiopia\",\n FI: \"Finland\",\n FJ: \"Fiji\",\n FK: \"Falkland Islands\",\n FO: \"Faroe Islands\",\n FR: \"France\",\n GA: \"Gabon\",\n GB: \"United Kingdom\",\n GD: \"Grenada\",\n GE: \"Georgia\",\n GF: \"French Guiana\",\n GG: \"Guernsey\",\n GH: \"Ghana\",\n GI: \"Gibraltar\",\n GL: \"Greenland\",\n GM: \"Gambia\",\n GN: \"Guinea\",\n GP: \"Guadeloupe\",\n GQ: \"Equatorial Guinea\",\n GR: \"Greece\",\n GS: \"South Georgia & South Sandwich Islands\",\n GT: \"Guatemala\",\n GU: \"Guam\",\n GW: \"Guinea-Bissau\",\n GY: \"Guyana\",\n HK: \"Hong Kong SAR China\",\n HN: \"Honduras\",\n HR: \"Croatia\",\n HT: \"Haiti\",\n HU: \"Hungary\",\n ID: \"Indonesia\",\n IE: \"Ireland\",\n IL: \"Israel\",\n IM: \"Isle of Man\",\n IN: \"India\",\n IO: \"British Indian Ocean Territory\",\n IQ: \"Iraq\",\n IS: \"Iceland\",\n IT: \"Italy\",\n JE: \"Jersey\",\n JM: \"Jamaica\",\n JO: \"Jordan\",\n JP: \"Japan\",\n KE: \"Kenya\",\n KG: \"Kyrgyzstan\",\n KH: \"Cambodia\",\n KI: \"Kiribati\",\n KM: \"Comoros\",\n KN: \"St. Kitts & Nevis\",\n KR: \"South Korea\",\n KW: \"Kuwait\",\n KY: \"Cayman Islands\",\n KZ: \"Kazakhstan\",\n LA: \"Laos\",\n LB: \"Lebanon\",\n LC: \"St. Lucia\",\n LI: \"Liechtenstein\",\n LK: \"Sri Lanka\",\n LR: \"Liberia\",\n LS: \"Lesotho\",\n LT: \"Lithuania\",\n LU: \"Luxembourg\",\n LV: \"Latvia\",\n LY: \"Libya\",\n MA: \"Morocco\",\n MC: \"Monaco\",\n MD: \"Moldova\",\n ME: \"Montenegro\",\n MF: \"St. Martin\",\n MG: \"Madagascar\",\n MK: \"North Macedonia\",\n ML: \"Mali\",\n MM: \"Myanmar (Burma)\",\n MN: \"Mongolia\",\n MO: \"Macao SAR China\",\n MQ: \"Martinique\",\n MR: \"Mauritania\",\n MS: \"Montserrat\",\n MT: \"Malta\",\n MU: \"Mauritius\",\n MV: \"Maldives\",\n MW: \"Malawi\",\n MX: \"Mexico\",\n MY: \"Malaysia\",\n MZ: \"Mozambique\",\n NA: \"Namibia\",\n NC: \"New Caledonia\",\n NE: \"Niger\",\n NG: \"Nigeria\",\n NI: \"Nicaragua\",\n NL: \"Netherlands\",\n NO: \"Norway\",\n NP: \"Nepal\",\n NR: \"Nauru\",\n NU: \"Niue\",\n NZ: \"New Zealand\",\n OM: \"Oman\",\n PA: \"Panama\",\n PE: \"Peru\",\n PF: \"French Polynesia\",\n PG: \"Papua New Guinea\",\n PH: \"Philippines\",\n PK: \"Pakistan\",\n PL: \"Poland\",\n PM: \"St. Pierre & Miquelon\",\n PN: \"Pitcairn Islands\",\n PR: \"Puerto Rico\",\n PS: \"Palestinian Territories\",\n PT: \"Portugal\",\n PY: \"Paraguay\",\n QA: \"Qatar\",\n RE: \"Réunion\",\n RO: \"Romania\",\n RS: \"Serbia\",\n RU: \"Russia\",\n RW: \"Rwanda\",\n SA: \"Saudi Arabia\",\n SB: \"Solomon Islands\",\n SC: \"Seychelles\",\n SE: \"Sweden\",\n SG: \"Singapore\",\n SH: \"St. Helena\",\n SI: \"Slovenia\",\n SJ: \"Svalbard & Jan Mayen\",\n SK: \"Slovakia\",\n SL: \"Sierra Leone\",\n SM: \"San Marino\",\n SN: \"Senegal\",\n SO: \"Somalia\",\n SR: \"Suriname\",\n SS: \"South Sudan\",\n ST: \"São Tomé & Príncipe\",\n SV: \"El Salvador\",\n SX: \"Sint Maarten\",\n SZ: \"Eswatini\",\n TA: \"Tristan da Cunha\",\n TC: \"Turks & Caicos Islands\",\n TD: \"Chad\",\n TF: \"French Southern Territories\",\n TG: \"Togo\",\n TH: \"Thailand\",\n TJ: \"Tajikistan\",\n TK: \"Tokelau\",\n TL: \"Timor-Leste\",\n TM: \"Turkmenistan\",\n TN: \"Tunisia\",\n TO: \"Tonga\",\n TR: \"Türkiye\",\n TT: \"Trinidad & Tobago\",\n TV: \"Tuvalu\",\n TW: \"Taiwan\",\n TZ: \"Tanzania\",\n UA: \"Ukraine\",\n UG: \"Uganda\",\n US: \"United States\",\n UY: \"Uruguay\",\n UZ: \"Uzbekistan\",\n VA: \"Vatican City\",\n VC: \"St. Vincent & Grenadines\",\n VE: \"Venezuela\",\n VG: \"British Virgin Islands\",\n VN: \"Vietnam\",\n VU: \"Vanuatu\",\n WF: \"Wallis & Futuna\",\n WS: \"Samoa\",\n XK: \"Kosovo\",\n YE: \"Yemen\",\n YT: \"Mayotte\",\n ZA: \"South Africa\",\n ZM: \"Zambia\",\n ZW: \"Zimbabwe\",\n }\n\n/** {@link CHECKOUT_SHIPPING_COUNTRY_NAMES}' codes, in order. */\nexport const STRIPE_SHIPPING_COUNTRY_CODES: readonly string[] = Object.keys(\n CHECKOUT_SHIPPING_COUNTRY_NAMES,\n)\n\n/**\n * The countries ONE merchant's checkout collects an address for: the\n * destinations their own zones name (international selling).\n *\n * `CHECKOUT_SHIPPING_COUNTRIES` used to be the only list, so a shopper in New\n * Zealand, Ireland or any EU country but Germany and France could not enter an\n * address at all, whatever zones the merchant saved. Now:\n *\n * - every country a zone names, in the order the merchant wrote them;\n * - every Stripe-collectable country when a zone claims rest of world (`*`);\n * - today's six for a merchant who prices no shipping (no zones and rates, or\n * pickup only), so a store that never set shipping up keeps the session it\n * has today, byte for byte.\n *\n * The AGL-1721 rule is unchanged, because `planCheckoutShipping` still pairs\n * this list with the options it unions over it.\n */\nexport function checkoutShippingCountries(\n settings: ShippingSettings | undefined,\n): readonly string[] {\n if (!merchantPricesShipping(settings) || !settings?.zones?.length) {\n return CHECKOUT_SHIPPING_COUNTRIES\n }\n const named: string[] = []\n for (const zone of settings.zones) {\n for (const raw of zone.countries ?? []) {\n const code = String(raw).trim().toUpperCase()\n if (code === '*') return STRIPE_SHIPPING_COUNTRY_CODES\n if (code in CHECKOUT_SHIPPING_COUNTRY_NAMES && !named.includes(code)) {\n named.push(code)\n }\n }\n }\n return named.length ? named : CHECKOUT_SHIPPING_COUNTRIES\n}\n\n/**\n * A destination a shopper declared, or `undefined` for anything this session\n * could not collect an address for anyway. Never throws: an unknown code is\n * an undeclared destination, not an error, so a stale storefront that posts\n * one is answered by the plan below rather than by a 400 nobody can act on.\n */\nexport function normalizeCheckoutShippingCountry(\n value: unknown,\n countries: readonly string[] = STRIPE_SHIPPING_COUNTRY_CODES,\n): string | undefined {\n // `typeof` rather than `String(value)`: a JSON body is caller-shaped, and\n // `String(['US'])` is 'US'. Coercing would let an array declare a\n // destination, which is not a spelling any storefront sends.\n if (typeof value !== 'string') return undefined\n const code = value.trim().toUpperCase()\n return countries.includes(code) ? code : undefined\n}\n\nexport interface CheckoutShippingPlan {\n /** `shipping_address_collection[allowed_countries]` for this session. */\n countries: readonly string[]\n /** `shipping_options` for this session — valid for EVERY `countries` entry. */\n options: ResolvedShippingRate[]\n /**\n * Set when no session may be created at all:\n *\n * - `destination-required` — the merchant's rates differ by destination, so\n * there is no set of options honest for every address Stripe would accept.\n * Ask the shopper where they are shipping and plan again.\n * - `destination-unserved` — the merchant ships somewhere, but not there.\n * - `cart-unpriceable` — the merchant priced shipping, but no rate of theirs\n * resolves for THIS cart at ANY destination (AGL-2232). A tier table that\n * stops at 2 kg says nothing about a 3 kg parcel, and the honest answer is\n * to refuse rather than to ship it for nothing.\n */\n refusal?: 'destination-required' | 'destination-unserved' | 'cart-unpriceable'\n}\n\n/**\n * Whether this merchant prices shipping AT ALL (AGL-2232).\n *\n * A pure question about the SETTINGS, deliberately taking no cart, and that is\n * the whole point of it existing. `planCheckoutShipping` used to ask \"does any\n * rate resolve for any destination?\" and pass the live cart into the probe, so\n * a cart that exhausted every tier made the probe empty too — and an empty\n * probe reads as \"this merchant never set shipping up\", the one case that must\n * complete with no `shipping_options` and nothing charged. A 3 kg order at a\n * store whose weight tiers stop at 2 kg therefore shipped free, silently, on\n * every one of the three doors.\n *\n * Answered from the stored zones and rates instead: a rate bound to a zone\n * that exists, or local pickup, means the merchant made a shipping decision\n * and a cart their table cannot price is a REFUSAL. A merchant with no zones,\n * no rates and no pickup has made no such decision, and their session stays\n * byte-identical to the one AGL-1707 shipped.\n */\nexport function merchantPricesShipping(\n settings: ShippingSettings | undefined,\n): boolean {\n if (!settings) return false\n if (settings.localPickup) return true\n const zoneIds = new Set((settings.zones ?? []).map((zone) => zone.id))\n // A rate whose `zoneId` names no zone is unreachable by every resolver here,\n // so it is not evidence of a decision — counting it would refuse carts at a\n // store with nothing but orphaned rows.\n return (settings.rates ?? []).some((rate) => zoneIds.has(rate.zoneId))\n}\n\n/**\n * What a shopper is told when `cart-unpriceable` refuses (AGL-2232).\n *\n * One string, shared by all three doors, because the three used to phrase the\n * two existing refusals identically and drifting here would make the same\n * store say different things depending on which button was pressed. It names\n * the cart rather than the destination on purpose — a `Ship to` select cannot\n * fix a parcel no tier covers, so the refusal deliberately does NOT set\n * `needsShippingCountry`.\n */\nexport const CART_UNPRICEABLE_SHIPPING_MESSAGE =\n 'This store cannot price shipping for this order — it falls outside every ' +\n 'shipping rate the store has set up. Try removing an item, or contact the ' +\n 'store.'\n\n/** Identity of a resolved list, for comparing two destinations' offers. */\nfunction optionsKey(options: readonly ResolvedShippingRate[]): string {\n return options\n .map((option) => `${option.rateId}:${option.amountCents}`)\n .join('|')\n}\n\n/**\n * The whole shipping half of a Checkout Session: which destinations it may\n * accept an address for, and which rates it may charge (AGL-1721).\n *\n * THE INVARIANT IS THAT EVERY RETURNED OPTION IS VALID FOR EVERY RETURNED\n * COUNTRY. Stripe offers a session's `shipping_options` to whoever reaches the\n * page and charges whichever the shopper picks — it does not filter them by\n * the address entered, and there is no field on a `shipping_rate_data` that\n * would let it. So the ONLY place a zone can be enforced is here, by choosing\n * the two lists together: narrowing the allowed countries to the declared\n * destination is what makes the rates offered for it unpickable by anyone\n * else. Filtering the rate list alone would leave a session that still accepts\n * a French address against a US rate.\n *\n * Three shapes come out of it:\n *\n * 1. A merchant whose rates resolve the SAME for every collectable country —\n * one zone, a single '*' zone, or none at all — needs no destination and\n * keeps the session AGL-1707 shipped, byte for byte. The issue notes this\n * is the common configuration, and it is the one that must not regress.\n * 2. A declared destination resolves exactly, and the session is restricted\n * to it. A caller may not skip the restriction: the country arrives in a\n * request body a shopper can craft, so a session that took the country's\n * cheap rate while still accepting any address would hand that shopper\n * the defect on purpose.\n * 3. Otherwise the caller must refuse — see `refusal`. Refusing is not lost\n * revenue in either case: with rates that differ by zone there is no\n * correct amount to charge without knowing where the parcel is going, and\n * the union AGL-1707 shipped chose the wrong one silently.\n *\n * `cart.subtotalCents` is the PRE-discount items total, matching what the cart\n * displays, so a free-over threshold means what the shopper saw it mean.\n */\nexport function planCheckoutShipping(\n settings: ShippingSettings | undefined,\n cart: { subtotalCents: number; totalGrams?: number },\n destinationCountry?: unknown,\n): CheckoutShippingPlan {\n const countries = checkoutShippingCountries(settings)\n // Any Stripe-collectable code counts as DECLARED, so a shopper naming a\n // country this store's zones do not reach is told it is not served rather\n // than asked again. Only a store whose list comes from its zones refuses\n // that way: one on the fallback list ships nowhere in particular, and an\n // outside code stays undeclared there exactly as it always was.\n const declared = normalizeCheckoutShippingCountry(destinationCountry)\n const fromZones = countries !== CHECKOUT_SHIPPING_COUNTRIES\n if (declared && !countries.includes(declared) && fromZones) {\n return { countries, options: [], refusal: 'destination-unserved' }\n }\n const destination =\n declared && countries.includes(declared) ? declared : undefined\n if (destination) {\n const options = resolveCheckoutShippingOptions(\n settings,\n [destination],\n cart,\n )\n // REFUSAL IS DECIDED ON SHIPPABLE RATES, PICKUP IS OFFERED AFTERWARDS\n // (AGL-2325). `resolveShippingRates` appends pickup independent of zone\n // matching, so a merchant who turned it on had a non-empty list for every\n // destination on earth and this branch returned before it could refuse\n // anyone: a shopper in France picked `Local pickup — Free` on a physical\n // order from a US-only store, Stripe collected their French address\n // because the session still allowed it, and the merchant was paid nothing\n // to carry the parcel there. Pickup is collection, not delivery, so it\n // cannot answer \"do you ship to France\".\n //\n // `shipsElsewhere` is the same question the old probe asked, narrowed to\n // shippable rates, and it keeps the same two-way fork: a merchant who\n // configured NO shipping is not refusing anyone, so that store keeps\n // completing exactly as it does today, while a merchant who ships\n // elsewhere but not here is refusing and saying so is the honest answer.\n // A merchant who ships NOWHERE is untouched by this: pickup-only is a\n // real configuration — they deliver to no one and refuse no one — and it\n // falls through to the offer below exactly as it did.\n const shipsElsewhere = countries.some(\n (country) =>\n shippableOnly(resolveCheckoutShippingOptions(settings, [country], cart))\n .length > 0,\n )\n if (shippableOnly(options).length === 0 && shipsElsewhere) {\n return { countries, options: [], refusal: 'destination-unserved' }\n }\n if (options.length > 0) return { countries: [destination], options }\n // NOTHING resolves anywhere for this cart, and the two reasons that can be\n // true of are opposite (AGL-2232). Asked of the SETTINGS rather than of\n // this cart, because the probe above cannot tell them apart: a merchant\n // who priced shipping and whose table simply does not reach this order is\n // refusing, and used to be handed the \"never set shipping up\" branch.\n return merchantPricesShipping(settings)\n ? { countries, options: [], refusal: 'cart-unpriceable' }\n : { countries, options: [] }\n }\n const offers = new Set(\n countries.map((country) =>\n optionsKey(resolveCheckoutShippingOptions(settings, [country], cart)),\n ),\n )\n // Compared as EMITTED — capped and sanitized — because that is the list a\n // shopper can pick from. Two destinations whose rates differ only past\n // Stripe's cap still offer the same five, and offering them is honest.\n if (offers.size > 1) {\n return { countries, options: [], refusal: 'destination-required' }\n }\n const union = resolveCheckoutShippingOptions(settings, countries, cart)\n // Every destination agrees, and what they agree on is NOTHING. The same\n // fork as the declared-destination branch above (AGL-2232): a store with no\n // shipping settings completes untouched, a store whose rates cannot reach\n // this cart refuses instead of carrying the parcel for free.\n if (union.length === 0 && merchantPricesShipping(settings)) {\n return { countries, options: [], refusal: 'cart-unpriceable' }\n }\n return { countries, options: union }\n}\n\n/**\n * A cart chosen so that every rate a merchant could have written resolves if\n * it can resolve at all (AGL-1791). The settings page has no cart, and two of\n * the four rate kinds price against one: `tierAmount` takes the first tier\n * whose `upTo` is at least the value, so a zero subtotal and zero weight clear\n * every tier a merchant would write, and a `free_over` rate resolves at any\n * subtotal.\n *\n * That makes a coverage answer a LOWER BOUND on the gaps. A destination\n * reported unserved is unserved for every cart; a destination reported served\n * may still be refused for a cart dearer or heavier than the merchant's last\n * tier. Erring in this direction is the deliberate half: the console must not\n * warn a merchant whose settings are fine.\n */\nconst COVERAGE_PROBE_CART = { subtotalCents: 0, totalGrams: 0 }\n\n/** What a merchant's saved zones and rates cost their shoppers (AGL-1791). */\nexport interface ShippingCoverage {\n /** How many destinations checkout collects an address for. */\n collectable: number\n /** Collectable destinations at least one rate reaches. */\n served: string[]\n /**\n * Collectable destinations CHECKOUT REFUSES — `destination-unserved`.\n *\n * EMPTY FOR A MERCHANT WHOSE RATES REACH NOWHERE, who is not misconfigured:\n * `planCheckoutShipping` refuses nobody when no rate resolves anywhere, so\n * that store charges no shipping and completes exactly as it always has.\n * The rule lives here rather than in the caller because reading `served`\n * against a bare partition is how a surface comes to warn every store that\n * does not ship.\n */\n unserved: string[]\n /** No rate reaches anywhere: no shipping is charged, and nobody refused. */\n shipsNowhere: boolean\n /**\n * Rates differ by destination, so the storefront asks the shopper where the\n * parcel is going before it can price one — a checkout step the merchant\n * added by saving these zones, and never chose.\n */\n asksDestination: boolean\n /** Some zone already claims rest of world, so `*` is not the missing piece. */\n hasRestOfWorldZone: boolean\n /**\n * The merchant offers local pickup, so checkout presents a free collection\n * choice at every destination it does not refuse (AGL-2325).\n *\n * Deliberately NOT folded into `served`: pickup resolves for every country\n * because it is appended independent of zone matching, so counting it as\n * coverage told a US-only merchant who had switched it on that checkout\n * \"can price shipping to every destination\", which is the sentence that\n * hid the defect. It is reported alongside instead, so the card can say\n * both true things: these destinations are refused, and pickup is offered\n * to the ones that are not.\n */\n offersLocalPickup: boolean\n}\n\n/**\n * Which of the collectable destinations a merchant's settings actually cover\n * (AGL-1791), for a console surface to show them.\n *\n * Measured against `checkoutShippingCountries(settings)` and nothing wider:\n * those are the only destinations this store's session collects an address\n * for, so they are the only ones a merchant can lose an order to.\n *\n * Answered through `resolveCheckoutShippingOptions` — the same function the\n * session is built from — so a row the console allows but Stripe would reject\n * (blank id, blank name) counts as the nothing it resolves to, and a specific\n * zone with no rates still hides a `*` zone here exactly as it does at\n * checkout.\n */\nexport function summarizeShippingCoverage(\n settings: ShippingSettings | undefined,\n): ShippingCoverage {\n const served: string[] = []\n const unserved: string[] = []\n const offers = new Set<string>()\n const collectable = checkoutShippingCountries(settings)\n for (const country of collectable) {\n const options = resolveCheckoutShippingOptions(\n settings,\n [country],\n COVERAGE_PROBE_CART,\n )\n // `asksDestination` is asked of the FULL list — pickup is a real option a\n // shopper picks, so a merchant whose US destination offers a rate plus\n // pickup while France offers only pickup genuinely does make checkout ask.\n offers.add(optionsKey(options))\n // `served` is asked of the SHIPPABLE list, so that it answers the same\n // question `planCheckoutShipping` refuses on (AGL-2325).\n ;(shippableOnly(options).length > 0 ? served : unserved).push(country)\n }\n return {\n collectable: collectable.length,\n served,\n unserved: served.length > 0 ? unserved : [],\n shipsNowhere: served.length === 0,\n asksDestination: offers.size > 1,\n offersLocalPickup: Boolean(settings?.localPickup),\n hasRestOfWorldZone: (settings?.zones ?? []).some((zone) =>\n zone.countries.some((code) => code === '*'),\n ),\n }\n}\n\n/**\n * What the Shipping card says about a store's coverage, in words (AGL-1791): the warning's headline and body when checkout\n * turns destinations away, otherwise the one line that says what it covers, and the line that says checkout asks where the\n * parcel is going. The console card and the native apps both read these, so the same store reads the same everywhere.\n */\nexport interface ShippingCoverageWords {\n /** Set when destinations are turned away: the warning's title. */\n headline: string\n /** The warning's body; empty when nothing is turned away. */\n detail: string\n /** The caption shown when nothing is turned away; empty when something is. */\n note: string\n /** Shown when rates differ by destination; empty otherwise. */\n asks: string\n}\n\n/** Names, the first eight in full: a rest-of-world gap can be 200 countries. */\nconst coverageCountryNames = (codes: readonly string[]) => {\n const names = codes.map((code) => CHECKOUT_SHIPPING_COUNTRY_NAMES[code] ?? code)\n return names.length > 8\n ? `${names.slice(0, 8).join(', ')} and ${names.length - 8} more`\n : names.join(', ')\n}\n\nexport function describeShippingCoverage(\n coverage: ShippingCoverage,\n): ShippingCoverageWords {\n const asks = coverage.asksDestination\n ? 'Rates differ by destination, so checkout asks the shopper where the parcel is going before it can price one.'\n : ''\n if (coverage.unserved.length > 0) {\n return {\n headline: `Checkout turns away ${coverage.unserved.length} of the ${coverage.collectable} destinations it collects addresses for`,\n detail:\n `No rate reaches ${coverageCountryNames(coverage.unserved)}, so an order shipping there is refused rather than posted for free. ` +\n (coverage.offersLocalPickup\n ? 'Local pickup does not cover them: it is a collection choice, not a rate, so it is offered where checkout completes and closes no gap here. '\n : '') +\n (coverage.hasRestOfWorldZone\n ? 'A rest-of-world zone is already saved, so what those destinations are missing is a rate on the zone that covers them.'\n : 'Give them a zone with a rate, or add a rest-of-world zone and price one on it.'),\n note: '',\n asks,\n }\n }\n return {\n headline: '',\n detail: '',\n note: coverage.shipsNowhere\n ? coverage.offersLocalPickup\n ? 'No rate reaches any destination, so local pickup is the only delivery choice checkout offers. Nobody is turned away and no shipping is charged.'\n : 'No rate reaches any destination, so checkout charges no shipping and turns nobody away.'\n : coverage.hasRestOfWorldZone &&\n coverage.served.length === STRIPE_SHIPPING_COUNTRY_CODES.length\n ? 'Checkout can price shipping to every country it can collect an address for.'\n : `Checkout can price shipping to every destination it collects an address for: ${coverageCountryNames(coverage.served)}.`,\n asks,\n }\n}\n\n/**\n * Emit `shipping_address_collection[allowed_countries][n]` onto a session's\n * form body. Stripe will not apply a `shipping_options` rate without an\n * address to ship to, so the two always travel together — and the countries\n * are the OTHER half of what makes a rate honest (AGL-1721), so pass the list\n * `planCheckoutShipping` returned rather than defaulting it beside a rate list\n * resolved for something narrower.\n */\nexport function appendShippingAddressCollectionParams(\n params: URLSearchParams,\n countries: readonly string[] = CHECKOUT_SHIPPING_COUNTRIES,\n): void {\n countries.forEach((code, index) => {\n params.set(`shipping_address_collection[allowed_countries][${index}]`, code)\n })\n}\n\n/**\n * Emit resolved rates as `shipping_options` on a Checkout Session's form body.\n *\n * THIS IS THE ONLY THING THAT MAKES STRIPE CHARGE SHIPPING. Without these keys\n * Stripe presents no shipping choice and `total_details.amount_shipping` is 0\n * however many zones and rates the merchant saved (AGL-1707).\n *\n * An empty list emits NOTHING — not an empty array — so a merchant who\n * configured no shipping keeps a session byte-identical to the one built\n * before shipping was wired at all. That guarantee lives here rather than in\n * each caller, so neither checkout path can lose it independently (AGL-1720).\n */\nexport function appendCheckoutShippingParams(\n params: URLSearchParams,\n options: readonly ResolvedShippingRate[],\n currency = 'usd',\n extra: { taxBehavior?: 'inclusive' | 'exclusive' } = {},\n): void {\n options.forEach((option, index) => {\n const field = `shipping_options[${index}][shipping_rate_data]`\n params.set(`${field}[type]`, 'fixed_amount')\n params.set(`${field}[display_name]`, option.name.slice(0, 100))\n params.set(`${field}[fixed_amount][amount]`, String(option.amountCents))\n params.set(`${field}[fixed_amount][currency]`, currency.toLowerCase())\n if (extra.taxBehavior) params.set(`${field}[tax_behavior]`, extra.taxBehavior)\n })\n}\n\n/**\n * Resolved options re-priced in a shopper currency (AGL-4248): a rate's own\n * amount in that currency when the merchant set one, else the store amount\n * converted; and a free-over rate with its own threshold there is free, or\n * not, against the goods in that currency rather than the store-currency\n * subtotal it was planned on. Pickup stays free. Order is kept.\n */\nexport function shippingOptionsInCurrency(\n options: readonly ResolvedShippingRate[],\n settings: ShippingSettings | undefined,\n currency: {\n code: string\n subtotalMinor: number\n convert: (baseCents: number, fixedMinor?: Record<string, number>) => number\n },\n): ResolvedShippingRate[] {\n const code = currency.code.toUpperCase()\n return options.map((option) => {\n if (option.rateId === LOCAL_PICKUP_RATE_ID) return option\n const rate = settings?.rates?.find((entry) => entry.id === option.rateId)\n const threshold = rate?.kind === 'free_over' ? rate.freeOverByCurrency?.[code] : undefined\n if (rate && typeof threshold === 'number') {\n const free = currency.subtotalMinor >= threshold\n const amount = free ? 0 : currency.convert(Math.max(0, Math.round(rate.amountCents ?? 0)), rate.amountsByCurrency)\n return { ...option, amountCents: amount }\n }\n if (option.amountCents === 0) return option\n const fixed =\n rate && (rate.kind === 'flat' || rate.kind === 'free_over') ? rate.amountsByCurrency : undefined\n return { ...option, amountCents: currency.convert(option.amountCents, fixed) }\n })\n}\n"],"names":["CARRIER_QUOTE_TIMEOUT_MS","LOCAL_PICKUP_RATE_ID","zoneCode","code","String","trim","toUpperCase","isWildcard","zoneMatches","zone","country","countries","some","tierAmount","tiers","value","sorted","sort","a","b","upTo","tier","amountCents","matchedZoneIds","settings","destinationCountry","zones","specific","filter","matched","length","Set","map","id","carrierRatesFor","zoneIds","rates","rate","kind","has","zoneId","hasCarrierRates","carrierOptionRateId","rateId","serviceKey","carrierOptionAmountCents","quotedCents","quote","Math","max","round","Number","pct","markupPct","handling","handlingCents","isFinite","min","resolveShippingRates","cart","resolved","freeOverCents","subtotalCents","totalGrams","push","name","localPickup","shippableOnly","options","option","MAX_CHECKOUT_SHIPPING_OPTIONS","CHECKOUT_SHIPPING_COUNTRIES","resolveCheckoutShippingOptions","destinationCountries","byRateId","Map","existing","get","set","values","localeCompare","slice","CHECKOUT_SHIPPING_COUNTRY_CODES","CHECKOUT_SHIPPING_COUNTRY_NAMES","AC","AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CV","CW","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MK","ML","MM","MN","MO","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SZ","TA","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","US","UY","UZ","VA","VC","VE","VG","VN","VU","WF","WS","XK","YE","YT","ZA","ZM","ZW","STRIPE_SHIPPING_COUNTRY_CODES","Object","keys","checkoutShippingCountries","merchantPricesShipping","named","raw","includes","normalizeCheckoutShippingCountry","undefined","CART_UNPRICEABLE_SHIPPING_MESSAGE","optionsKey","join","planCheckoutShipping","declared","fromZones","refusal","destination","shipsElsewhere","offers","size","union","COVERAGE_PROBE_CART","summarizeShippingCoverage","served","unserved","collectable","add","shipsNowhere","asksDestination","offersLocalPickup","Boolean","hasRestOfWorldZone","coverageCountryNames","codes","names","describeShippingCoverage","coverage","asks","headline","detail","note","appendShippingAddressCollectionParams","params","forEach","index","appendCheckoutShippingParams","currency","extra","field","toLowerCase","taxBehavior","shippingOptionsInCurrency","find","entry","threshold","freeOverByCurrency","free","subtotalMinor","amount","convert","amountsByCurrency","fixed"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC;AAsCD,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I;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IAC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Z,gBAAiB6V,IAAI,CAAC,CAACC,QAAUA,MAAMrV,EAAE,KAAKoC,OAAO1B,MAAM;QACxE,MAAM4U,YAAYlV,CAAAA,wBAAAA,KAAMC,IAAI,MAAK,eAAcD,2BAAAA,KAAKmV,kBAAkB,qBAAvBnV,wBAAyB,CAAClC,KAAK,GAAGsU;QACjF,IAAIpS,QAAQ,OAAOkV,cAAc,UAAU;gBAEyBlV;YADlE,MAAMoV,OAAOV,SAASW,aAAa,IAAIH;YACvC,MAAMI,SAASF,OAAO,IAAIV,SAASa,OAAO,CAAC5U,KAAKC,GAAG,CAAC,GAAGD,KAAKE,KAAK,EAACb,oBAAAA,KAAKf,WAAW,YAAhBe,oBAAoB,KAAKA,KAAKwV,iBAAiB;YACjH,OAAO,aAAKxT;gBAAQ/C,aAAaqW;;QACnC;QACA,IAAItT,OAAO/C,WAAW,KAAK,GAAG,OAAO+C;QACrC,MAAMyT,QACJzV,QAASA,CAAAA,KAAKC,IAAI,KAAK,UAAUD,KAAKC,IAAI,KAAK,WAAU,IAAKD,KAAKwV,iBAAiB,GAAGpD;QACzF,OAAO,aAAKpQ;YAAQ/C,aAAayV,SAASa,OAAO,CAACvT,OAAO/C,WAAW,EAAEwW;;IACxE;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce-shipping.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Shipping v1 (AGL-288): zones own countries; rates belong to a zone and\n * price as flat, free-over-threshold, or subtotal/weight tiers. Settings\n * live on `hosts/{hostId}/settings/store` under `shipping`. Pure.\n *\n * `resolveShippingRates` is the per-destination resolver;\n * `resolveCheckoutShippingOptions` is the Stripe Checkout adapter,\n * `planCheckoutShipping` decides which destinations one session may serve,\n * `appendCheckoutShippingParams` emits it onto a session, and\n * `summarizeShippingCoverage` answers the same question for the console, so a\n * merchant can see which destinations their zones refuse. AGL-288 shipped this\n * model with no production call site at all — the doc comment here claimed the\n * cart estimator, checkout and POS pickup used it, and none of them did, so\n * nothing ever read the settings a merchant saved and no shipping was ever\n * charged. Cart checkout calls it (AGL-1707), buy-now calls it for physical\n * one-time products (AGL-1720), and a draft order's payment link calls it for\n * physical products (AGL-1792).\n *\n * POS DOES NOT, AND SHOULD NOT (AGL-1792). A register has no destination\n * anywhere in it — no address field, no delivery choice — and all three\n * tenders settle at the counter: cash, a card QR the customer scans while\n * standing there, and a room folio collected at check-out. There is nothing to\n * price a parcel against, so the only rate POS could resolve is the free\n * `Local pickup` one this module appends, which is 0¢ and would add a step to\n * a register flow in exchange for nothing. A POS sale that must be shipped is\n * a draft order.\n */\n\nexport interface ShippingZone {\n id: string\n name: string\n /** ISO-3166 alpha-2 codes; '*' = rest of world. */\n countries: string[]\n}\n\nexport interface ShippingTier {\n /** Tier applies while subtotal (cents) or weight (grams) ≤ this. */\n upTo: number\n amountCents: number\n}\n\n/**\n * A live carrier rate (AGL-3612): the zone's price is what a carrier quotes\n * for the parcel to the shopper's address, asked through core's\n * `core.shipping-rate-quoter` seam of whichever plugin quotes carriers. With\n * no quoter, a quoter that is not available for the site, no postal code to\n * quote against, or a quote slower than {@link CARRIER_QUOTE_TIMEOUT_MS}, it\n * offers nothing and its fallback rate is offered instead.\n */\nexport interface CarrierRateSettings {\n /** Service keys (`carrier:service`) to offer; empty offers every quoted service. */\n services?: string[]\n /** Added to each quote, in percent. */\n markupPct?: number\n /** Added to each quote after the markup, in cents. */\n handlingCents?: number\n /**\n * A rate of this zone offered when no live quote is: it is HIDDEN while\n * quotes are offered, so the shopper picks between carriers, not between a\n * carrier and the merchant's guess.\n */\n fallbackRateId?: string\n}\n\n/** How long checkout waits for live carrier quotes before it falls back. */\nexport const CARRIER_QUOTE_TIMEOUT_MS = 3_000\n\nexport interface ShippingRate {\n id: string\n zoneId: string\n name: string\n kind: 'flat' | 'free_over' | 'price_tiers' | 'weight_tiers' | 'carrier'\n /** flat + free_over base amount. */\n amountCents?: number\n /** free_over: order subtotal (cents) at/above which shipping is free. */\n freeOverCents?: number\n /** price_tiers (upTo = subtotal cents) / weight_tiers (upTo = grams). */\n tiers?: ShippingTier[]\n /** carrier: the live rate's options (AGL-3612). */\n carrier?: CarrierRateSettings\n /**\n * flat + free_over: the price in another currency the store sells in\n * (AGL-4248), minor units keyed by ISO code. A currency not listed converts.\n */\n amountsByCurrency?: Record<string, number>\n /** free_over: the threshold in another currency (AGL-4248), minor units by ISO code. */\n freeOverByCurrency?: Record<string, number>\n /**\n * Conditions (AGL-4255), the way Shopify sets one on a rate: the rate is\n * offered only to a cart whose PRE-discount items subtotal is at least\n * `minSubtotalCents` and at most `maxSubtotalCents`, and whose weight is at\n * least `minGrams` and at most `maxGrams`. Each bound is optional and\n * inclusive. A cart no rate of its zone is offered to is refused as\n * `cart-unpriceable`, the way Shopify says shipping is not available.\n */\n minSubtotalCents?: number\n maxSubtotalCents?: number\n /** The order-price bounds in another currency, minor units by ISO code; a currency not listed uses the store figure converted. */\n minSubtotalByCurrency?: Record<string, number>\n maxSubtotalByCurrency?: Record<string, number>\n minGrams?: number\n maxGrams?: number\n}\n\n/**\n * The cart a rate is priced and conditioned against. `shopperSubtotal` is\n * the same items subtotal in the currency the shopper is charged in\n * (AGL-4248), when that is not the store's: a condition with its own figure\n * in that currency is judged against it, every other against `subtotalCents`.\n */\nexport interface ShippingCart {\n subtotalCents: number\n totalGrams?: number\n shopperSubtotal?: { code: string; minor: number }\n}\n\nconst conditionBound = (value: unknown): number | undefined => {\n const n = Number(value)\n return value == null || value === '' || !Number.isFinite(n) || n < 0 ? undefined : Math.round(n)\n}\n\n/** Whether a rate carries any order-price or weight condition (AGL-4255). */\nexport function rateHasConditions(rate: ShippingRate): boolean {\n return (\n conditionBound(rate.minSubtotalCents) != null ||\n conditionBound(rate.maxSubtotalCents) != null ||\n conditionBound(rate.minGrams) != null ||\n conditionBound(rate.maxGrams) != null\n )\n}\n\n/**\n * Whether a cart meets a rate's conditions (AGL-4255). A rate with none\n * meets every cart. A per-currency bound is used only when the cart says\n * what the shopper is charged in that currency.\n */\nexport function rateConditionMet(rate: ShippingRate, cart: ShippingCart): boolean {\n const code = cart.shopperSubtotal?.code?.toUpperCase()\n const own = (map: Record<string, number> | undefined) =>\n code && cart.shopperSubtotal ? conditionBound(map?.[code]) : undefined\n const bound = (base: unknown, map: Record<string, number> | undefined) => {\n const local = own(map)\n return local != null\n ? { limit: local, value: Number(cart.shopperSubtotal?.minor) || 0 }\n : conditionBound(base) != null\n ? { limit: conditionBound(base) as number, value: Number(cart.subtotalCents) || 0 }\n : undefined\n }\n const min = bound(rate.minSubtotalCents, rate.minSubtotalByCurrency)\n if (min && min.value < min.limit) return false\n const max = bound(rate.maxSubtotalCents, rate.maxSubtotalByCurrency)\n if (max && max.value > max.limit) return false\n const grams = Math.max(0, Number(cart.totalGrams) || 0)\n const minGrams = conditionBound(rate.minGrams)\n if (minGrams != null && grams < minGrams) return false\n const maxGrams = conditionBound(rate.maxGrams)\n if (maxGrams != null && grams > maxGrams) return false\n return true\n}\n\n/** How a rate's conditions read in a list, e.g. `Orders $150.00 and up` (AGL-4255); empty with none. */\nexport function describeRateConditions(rate: ShippingRate, currencyCode = 'USD'): string {\n const money = (cents: number) =>\n new Intl.NumberFormat('en-US', { style: 'currency', currency: currencyCode }).format(cents / 100)\n const weight = (grams: number) => (grams >= 1000 ? `${Number((grams / 1000).toFixed(2))} kg` : `${grams} g`)\n const range = (\n min: number | undefined,\n max: number | undefined,\n noun: string,\n show: (n: number) => string,\n ) =>\n min != null && max != null\n ? `${noun} ${show(min)} to ${show(max)}`\n : min != null\n ? `${noun} ${show(min)} and up`\n : max != null\n ? `${noun} up to ${show(max)}`\n : ''\n return [\n range(conditionBound(rate.minSubtotalCents), conditionBound(rate.maxSubtotalCents), 'Orders', money),\n range(conditionBound(rate.minGrams), conditionBound(rate.maxGrams), 'Weighing', weight),\n ]\n .filter(Boolean)\n .join(', ')\n}\n\nexport interface ShippingSettings {\n zones?: ShippingZone[]\n rates?: ShippingRate[]\n /**\n * Offer free local pickup as a delivery choice. Does NOT widen where the\n * store ships: a destination no rate reaches is still refused (AGL-2325).\n */\n localPickup?: boolean\n}\n\nexport interface ResolvedShippingRate {\n rateId: string\n name: string\n amountCents: number\n}\n\n/**\n * The rate id appended for local pickup (AGL-2325).\n *\n * Exported because pickup is the one entry in a resolved list that is NOT a\n * shipping promise: it is appended AFTER and INDEPENDENT of zone matching, so\n * it resolves for every destination on earth. Anything asking \"does this store\n * ship there\" — the checkout refusal, the console coverage card — has to be\n * able to tell it apart from a rate, or it reads a merchant who offers\n * collection as a merchant who delivers worldwide.\n */\nexport const LOCAL_PICKUP_RATE_ID = 'pickup'\n\n/**\n * One stored country code, normalised (AGL-2298).\n *\n * TRIMMED as well as upper-cased. The console trims on save, so this only\n * matters for a document written any other way — an import, the REST API, a\n * hand edit — but the failure it produces is silent and expensive: `' US'`\n * upper-cases to `' US'`, matches nothing, and the store refuses every US\n * shopper with \"This store does not ship to the United States\" while its\n * settings card shows `US` right there.\n */\nconst zoneCode = (code: unknown): string => String(code ?? '').trim().toUpperCase()\n\n/** Whether a stored code is the rest-of-world wildcard. */\nconst isWildcard = (code: unknown): boolean => zoneCode(code) === '*'\n\nfunction zoneMatches(zone: ShippingZone, country: string): boolean {\n return (zone.countries ?? []).some(\n (code) => isWildcard(code) || zoneCode(code) === country,\n )\n}\n\nfunction tierAmount(\n tiers: ShippingTier[] | undefined,\n value: number,\n): number | null {\n const sorted = [...(tiers ?? [])].sort((a, b) => a.upTo - b.upTo)\n for (const tier of sorted) {\n if (value <= tier.upTo) return tier.amountCents\n }\n // Beyond the last tier the rate does not apply (merchant should add a\n // catch-all tier with a large upTo).\n return null\n}\n\n/**\n * The zones a destination falls in (AGL-1707, factored out for AGL-3612).\n * Specific country zones beat '*' zones: when any zone names the country\n * outright, rest-of-world zones are ignored.\n */\nexport function matchedZoneIds(\n settings: ShippingSettings | undefined,\n destinationCountry: string,\n): Set<string> {\n const country = destinationCountry.toUpperCase()\n const zones = settings?.zones ?? []\n // A zone is SPECIFIC when it names this country outright — not merely when\n // it is \"not wildcard-only\" (AGL-2298). The old test was `!every(code ===\n // '*')`, so a zone spelled `['*','US']` counted as specific for all six\n // destinations (it matches every country through the `*`) and suppressed\n // every genuine rest-of-world zone globally. Asking the narrower question\n // makes such a zone specific for `US` and wildcard for the rest, which is\n // what its two entries actually say.\n const specific = zones.filter((zone) =>\n (zone.countries ?? []).some((code) => zoneCode(code) === country),\n )\n const matched = specific.length\n ? specific\n : zones.filter((zone) => zoneMatches(zone, country))\n return new Set(matched.map((zone) => zone.id))\n}\n\n/** The live carrier rates a destination's zones carry (AGL-3612). */\nexport function carrierRatesFor(\n settings: ShippingSettings | undefined,\n destinationCountry: string,\n): ShippingRate[] {\n if (!settings) return []\n const zoneIds = matchedZoneIds(settings, destinationCountry)\n return (settings.rates ?? []).filter(\n (rate) => rate.kind === 'carrier' && zoneIds.has(rate.zoneId),\n )\n}\n\n/** Whether any zone carries a live carrier rate (AGL-3612). */\nexport function hasCarrierRates(settings: ShippingSettings | undefined): boolean {\n return (settings?.rates ?? []).some((rate) => rate.kind === 'carrier')\n}\n\n/** The rate id a quoted service is offered under: stable per rate and service. */\nexport function carrierOptionRateId(rateId: string, serviceKey: string): string {\n return `carrier:${rateId}:${serviceKey}`\n}\n\n/**\n * What a shopper pays for a carrier's quote under one carrier rate: the\n * quote, plus the markup, plus the handling fee, in whole cents.\n */\nexport function carrierOptionAmountCents(\n quotedCents: number,\n settings: CarrierRateSettings | undefined,\n): number {\n const quote = Math.max(0, Math.round(Number(quotedCents) || 0))\n const pct = Number(settings?.markupPct)\n const handling = Number(settings?.handlingCents)\n return (\n quote +\n (Number.isFinite(pct) && pct > 0 ? Math.round((quote * Math.min(pct, 500)) / 100) : 0) +\n (Number.isFinite(handling) && handling > 0 ? Math.round(handling) : 0)\n )\n}\n\n/**\n * Rates available for a destination + cart, cheapest first. Specific\n * country zones beat '*' zones: when any specific zone matches, '*'\n * zones are ignored (rest-of-world semantics).\n *\n * Local pickup is appended AFTER and INDEPENDENT of zone matching, so this\n * list is never empty for a merchant who offers it, at any destination. That\n * is correct for a resolver — a shopper anywhere may choose to come and\n * collect — but it means A NON-EMPTY RESULT IS NOT A PROMISE TO SHIP THERE.\n * Callers deciding whether a destination is served must filter pickup out\n * first; `planCheckoutShipping` and `summarizeShippingCoverage` do (AGL-2325).\n */\nexport function resolveShippingRates(\n settings: ShippingSettings | undefined,\n destinationCountry: string | undefined,\n cart: ShippingCart,\n options: { ignoreConditions?: boolean } = {},\n): ResolvedShippingRate[] {\n if (!settings || !destinationCountry) return []\n const zoneIds = matchedZoneIds(settings, destinationCountry)\n // A zone is SPECIFIC when it names this country outright — not merely when\n // it is \"not wildcard-only\" (AGL-2298). The old test was `!every(code ===\n // '*')`, so a zone spelled `['*','US']` counted as specific for all six\n // destinations (it matches every country through the `*`) and suppressed\n // every genuine rest-of-world zone globally. Asking the narrower question\n // makes such a zone specific for `US` and wildcard for the rest, which is\n // what its two entries actually say.\n const resolved: ResolvedShippingRate[] = []\n for (const rate of settings.rates ?? []) {\n if (!zoneIds.has(rate.zoneId)) continue\n // A rate whose conditions this cart misses is not offered (AGL-4255).\n if (!options.ignoreConditions && !rateConditionMet(rate, cart)) continue\n let amountCents: number | null = null\n switch (rate.kind) {\n case 'flat':\n amountCents = Math.max(0, Math.round(rate.amountCents ?? 0))\n break\n case 'free_over':\n amountCents =\n rate.freeOverCents != null &&\n cart.subtotalCents >= rate.freeOverCents\n ? 0\n : Math.max(0, Math.round(rate.amountCents ?? 0))\n break\n case 'price_tiers':\n amountCents = tierAmount(rate.tiers, cart.subtotalCents)\n break\n case 'weight_tiers':\n amountCents = tierAmount(rate.tiers, cart.totalGrams ?? 0)\n break\n // A carrier's price exists only once a carrier quoted it for an\n // address (AGL-3612), so a table read offers nothing for it and its\n // fallback rate is what resolves here. `carrier-shipping.ts` adds the\n // quotes where one can be had.\n case 'carrier':\n break\n }\n if (amountCents == null) continue\n resolved.push({ rateId: rate.id, name: rate.name, amountCents })\n }\n if (settings.localPickup) {\n resolved.push({\n rateId: LOCAL_PICKUP_RATE_ID,\n name: 'Local pickup',\n amountCents: 0,\n })\n }\n return resolved.sort((a, b) => a.amountCents - b.amountCents)\n}\n\n/**\n * The resolved options that actually carry a parcel (AGL-2325).\n *\n * Safe to apply AFTER `MAX_CHECKOUT_SHIPPING_OPTIONS` truncation: pickup is\n * 0¢ and sorts first, so it occupies at most one of the five slots and a\n * merchant with any shippable rate at all keeps at least one of them.\n */\nfunction shippableOnly(\n options: readonly ResolvedShippingRate[],\n): ResolvedShippingRate[] {\n return options.filter((option) => option.rateId !== LOCAL_PICKUP_RATE_ID)\n}\n\n/** Stripe Checkout accepts at most 5 `shipping_options` on one session. */\nexport const MAX_CHECKOUT_SHIPPING_OPTIONS = 5\n\n/**\n * The destinations a Checkout Session collects an address for when the\n * merchant prices NO shipping (AGL-1707), and so the session such a store has\n * always had. A merchant with zones gets `checkoutShippingCountries` instead:\n * the countries their zones name, or every country for rest of world.\n */\nexport const CHECKOUT_SHIPPING_COUNTRIES = [\n 'US',\n 'CA',\n 'GB',\n 'AU',\n 'DE',\n 'FR',\n] as const\n\n/**\n * The rates to declare as `shipping_options` on a Stripe Checkout Session\n * (AGL-1707), unioned over `destinationCountries`. Stripe charges shipping\n * ONLY when the session declares them.\n *\n * A UNION IS ONLY HONEST OVER DESTINATIONS THE SESSION IS ALSO RESTRICTED TO.\n * Called with every collectable country while the session accepted an address\n * in any of them — which is what AGL-1707 shipped — it offers a shopper in one\n * zone a rate belonging to another, and Stripe applies whichever the shopper\n * picks (a `shipping_rate_data` carries no country of its own, so nothing\n * downstream re-checks it against the address). That is AGL-1721. Callers now\n * reach this through `planCheckoutShipping`, which pairs the country list it\n * unions over with the country list the session allows, so the two cannot\n * disagree. Do not call it directly from a handler.\n *\n * Returns `[]` for a merchant who has configured nothing, and the caller must\n * then declare no `shipping_options` at all rather than an empty array — a\n * merchant who never set shipping up keeps a session identical to today's.\n */\nexport function resolveCheckoutShippingOptions(\n settings: ShippingSettings | undefined,\n destinationCountries: readonly string[],\n cart: ShippingCart,\n options: { ignoreConditions?: boolean } = {},\n): ResolvedShippingRate[] {\n if (!settings) return []\n const byRateId = new Map<string, ResolvedShippingRate>()\n for (const country of destinationCountries) {\n for (const rate of resolveShippingRates(settings, country, cart, options)) {\n // Stripe requires a display name, and a rate id is the dedupe key —\n // the console lets a merchant add a blank row, so neither is assured.\n if (!rate.rateId || !rate.name) continue\n const amountCents = Math.max(0, Math.round(Number(rate.amountCents) || 0))\n const existing = byRateId.get(rate.rateId)\n // One rate resolving differently for two countries should not be\n // possible (a zone selects a rate, it does not reprice one), but if it\n // ever is, keep the dearer. Under-charging is the defect being fixed.\n if (!existing || amountCents > existing.amountCents) {\n byRateId.set(rate.rateId, { ...rate, amountCents })\n }\n }\n }\n return (\n [...byRateId.values()]\n // Cheapest first, id as a tie-break so the emitted params are stable.\n .sort(\n (a, b) =>\n a.amountCents - b.amountCents || a.rateId.localeCompare(b.rateId),\n )\n // Past Stripe's cap the dearest are dropped, which is the harmless end\n // to lose: a shopper offered the cheap options would have taken one.\n .slice(0, MAX_CHECKOUT_SHIPPING_OPTIONS)\n )\n}\n\n/**\n * {@link CHECKOUT_SHIPPING_COUNTRIES} as plain codes: the apps' draft order\n * falls back to it only when the server names no list (AGL-3841).\n */\nexport const CHECKOUT_SHIPPING_COUNTRY_CODES: readonly string[] = CHECKOUT_SHIPPING_COUNTRIES\n\n/**\n * Every country Stripe Checkout can collect a shipping address for\n * (`shipping_address_collection[allowed_countries]`), with the name a shopper\n * reads. A rest-of-world `*` zone opens checkout to all of them.\n */\nexport const CHECKOUT_SHIPPING_COUNTRY_NAMES: Readonly<Record<string, string>> =\n {\n AC: \"Ascension Island\",\n AD: \"Andorra\",\n AE: \"United Arab Emirates\",\n AF: \"Afghanistan\",\n AG: \"Antigua & Barbuda\",\n AI: \"Anguilla\",\n AL: \"Albania\",\n AM: \"Armenia\",\n AO: \"Angola\",\n AQ: \"Antarctica\",\n AR: \"Argentina\",\n AT: \"Austria\",\n AU: \"Australia\",\n AW: \"Aruba\",\n AX: \"Åland Islands\",\n AZ: \"Azerbaijan\",\n BA: \"Bosnia & Herzegovina\",\n BB: \"Barbados\",\n BD: \"Bangladesh\",\n BE: \"Belgium\",\n BF: \"Burkina Faso\",\n BG: \"Bulgaria\",\n BH: \"Bahrain\",\n BI: \"Burundi\",\n BJ: \"Benin\",\n BL: \"St. Barthélemy\",\n BM: \"Bermuda\",\n BN: \"Brunei\",\n BO: \"Bolivia\",\n BQ: \"Caribbean Netherlands\",\n BR: \"Brazil\",\n BS: \"Bahamas\",\n BT: \"Bhutan\",\n BV: \"Bouvet Island\",\n BW: \"Botswana\",\n BY: \"Belarus\",\n BZ: \"Belize\",\n CA: \"Canada\",\n CD: \"Congo - Kinshasa\",\n CF: \"Central African Republic\",\n CG: \"Congo - Brazzaville\",\n CH: \"Switzerland\",\n CI: \"Côte d’Ivoire\",\n CK: \"Cook Islands\",\n CL: \"Chile\",\n CM: \"Cameroon\",\n CN: \"China\",\n CO: \"Colombia\",\n CR: \"Costa Rica\",\n CV: \"Cape Verde\",\n CW: \"Curaçao\",\n CY: \"Cyprus\",\n CZ: \"Czechia\",\n DE: \"Germany\",\n DJ: \"Djibouti\",\n DK: \"Denmark\",\n DM: \"Dominica\",\n DO: \"Dominican Republic\",\n DZ: \"Algeria\",\n EC: \"Ecuador\",\n EE: \"Estonia\",\n EG: \"Egypt\",\n EH: \"Western Sahara\",\n ER: \"Eritrea\",\n ES: \"Spain\",\n ET: \"Ethiopia\",\n FI: \"Finland\",\n FJ: \"Fiji\",\n FK: \"Falkland Islands\",\n FO: \"Faroe Islands\",\n FR: \"France\",\n GA: \"Gabon\",\n GB: \"United Kingdom\",\n GD: \"Grenada\",\n GE: \"Georgia\",\n GF: \"French Guiana\",\n GG: \"Guernsey\",\n GH: \"Ghana\",\n GI: \"Gibraltar\",\n GL: \"Greenland\",\n GM: \"Gambia\",\n GN: \"Guinea\",\n GP: \"Guadeloupe\",\n GQ: \"Equatorial Guinea\",\n GR: \"Greece\",\n GS: \"South Georgia & South Sandwich Islands\",\n GT: \"Guatemala\",\n GU: \"Guam\",\n GW: \"Guinea-Bissau\",\n GY: \"Guyana\",\n HK: \"Hong Kong SAR China\",\n HN: \"Honduras\",\n HR: \"Croatia\",\n HT: \"Haiti\",\n HU: \"Hungary\",\n ID: \"Indonesia\",\n IE: \"Ireland\",\n IL: \"Israel\",\n IM: \"Isle of Man\",\n IN: \"India\",\n IO: \"British Indian Ocean Territory\",\n IQ: \"Iraq\",\n IS: \"Iceland\",\n IT: \"Italy\",\n JE: \"Jersey\",\n JM: \"Jamaica\",\n JO: \"Jordan\",\n JP: \"Japan\",\n KE: \"Kenya\",\n KG: \"Kyrgyzstan\",\n KH: \"Cambodia\",\n KI: \"Kiribati\",\n KM: \"Comoros\",\n KN: \"St. Kitts & Nevis\",\n KR: \"South Korea\",\n KW: \"Kuwait\",\n KY: \"Cayman Islands\",\n KZ: \"Kazakhstan\",\n LA: \"Laos\",\n LB: \"Lebanon\",\n LC: \"St. Lucia\",\n LI: \"Liechtenstein\",\n LK: \"Sri Lanka\",\n LR: \"Liberia\",\n LS: \"Lesotho\",\n LT: \"Lithuania\",\n LU: \"Luxembourg\",\n LV: \"Latvia\",\n LY: \"Libya\",\n MA: \"Morocco\",\n MC: \"Monaco\",\n MD: \"Moldova\",\n ME: \"Montenegro\",\n MF: \"St. Martin\",\n MG: \"Madagascar\",\n MK: \"North Macedonia\",\n ML: \"Mali\",\n MM: \"Myanmar (Burma)\",\n MN: \"Mongolia\",\n MO: \"Macao SAR China\",\n MQ: \"Martinique\",\n MR: \"Mauritania\",\n MS: \"Montserrat\",\n MT: \"Malta\",\n MU: \"Mauritius\",\n MV: \"Maldives\",\n MW: \"Malawi\",\n MX: \"Mexico\",\n MY: \"Malaysia\",\n MZ: \"Mozambique\",\n NA: \"Namibia\",\n NC: \"New Caledonia\",\n NE: \"Niger\",\n NG: \"Nigeria\",\n NI: \"Nicaragua\",\n NL: \"Netherlands\",\n NO: \"Norway\",\n NP: \"Nepal\",\n NR: \"Nauru\",\n NU: \"Niue\",\n NZ: \"New Zealand\",\n OM: \"Oman\",\n PA: \"Panama\",\n PE: \"Peru\",\n PF: \"French Polynesia\",\n PG: \"Papua New Guinea\",\n PH: \"Philippines\",\n PK: \"Pakistan\",\n PL: \"Poland\",\n PM: \"St. Pierre & Miquelon\",\n PN: \"Pitcairn Islands\",\n PR: \"Puerto Rico\",\n PS: \"Palestinian Territories\",\n PT: \"Portugal\",\n PY: \"Paraguay\",\n QA: \"Qatar\",\n RE: \"Réunion\",\n RO: \"Romania\",\n RS: \"Serbia\",\n RU: \"Russia\",\n RW: \"Rwanda\",\n SA: \"Saudi Arabia\",\n SB: \"Solomon Islands\",\n SC: \"Seychelles\",\n SE: \"Sweden\",\n SG: \"Singapore\",\n SH: \"St. Helena\",\n SI: \"Slovenia\",\n SJ: \"Svalbard & Jan Mayen\",\n SK: \"Slovakia\",\n SL: \"Sierra Leone\",\n SM: \"San Marino\",\n SN: \"Senegal\",\n SO: \"Somalia\",\n SR: \"Suriname\",\n SS: \"South Sudan\",\n ST: \"São Tomé & Príncipe\",\n SV: \"El Salvador\",\n SX: \"Sint Maarten\",\n SZ: \"Eswatini\",\n TA: \"Tristan da Cunha\",\n TC: \"Turks & Caicos Islands\",\n TD: \"Chad\",\n TF: \"French Southern Territories\",\n TG: \"Togo\",\n TH: \"Thailand\",\n TJ: \"Tajikistan\",\n TK: \"Tokelau\",\n TL: \"Timor-Leste\",\n TM: \"Turkmenistan\",\n TN: \"Tunisia\",\n TO: \"Tonga\",\n TR: \"Türkiye\",\n TT: \"Trinidad & Tobago\",\n TV: \"Tuvalu\",\n TW: \"Taiwan\",\n TZ: \"Tanzania\",\n UA: \"Ukraine\",\n UG: \"Uganda\",\n US: \"United States\",\n UY: \"Uruguay\",\n UZ: \"Uzbekistan\",\n VA: \"Vatican City\",\n VC: \"St. Vincent & Grenadines\",\n VE: \"Venezuela\",\n VG: \"British Virgin Islands\",\n VN: \"Vietnam\",\n VU: \"Vanuatu\",\n WF: \"Wallis & Futuna\",\n WS: \"Samoa\",\n XK: \"Kosovo\",\n YE: \"Yemen\",\n YT: \"Mayotte\",\n ZA: \"South Africa\",\n ZM: \"Zambia\",\n ZW: \"Zimbabwe\",\n }\n\n/** {@link CHECKOUT_SHIPPING_COUNTRY_NAMES}' codes, in order. */\nexport const STRIPE_SHIPPING_COUNTRY_CODES: readonly string[] = Object.keys(\n CHECKOUT_SHIPPING_COUNTRY_NAMES,\n)\n\n/**\n * The countries ONE merchant's checkout collects an address for: the\n * destinations their own zones name (international selling).\n *\n * `CHECKOUT_SHIPPING_COUNTRIES` used to be the only list, so a shopper in New\n * Zealand, Ireland or any EU country but Germany and France could not enter an\n * address at all, whatever zones the merchant saved. Now:\n *\n * - every country a zone names, in the order the merchant wrote them;\n * - every Stripe-collectable country when a zone claims rest of world (`*`);\n * - today's six for a merchant who prices no shipping (no zones and rates, or\n * pickup only), so a store that never set shipping up keeps the session it\n * has today, byte for byte.\n *\n * The AGL-1721 rule is unchanged, because `planCheckoutShipping` still pairs\n * this list with the options it unions over it.\n */\nexport function checkoutShippingCountries(\n settings: ShippingSettings | undefined,\n): readonly string[] {\n if (!merchantPricesShipping(settings) || !settings?.zones?.length) {\n return CHECKOUT_SHIPPING_COUNTRIES\n }\n const named: string[] = []\n for (const zone of settings.zones) {\n for (const raw of zone.countries ?? []) {\n const code = String(raw).trim().toUpperCase()\n if (code === '*') return STRIPE_SHIPPING_COUNTRY_CODES\n if (code in CHECKOUT_SHIPPING_COUNTRY_NAMES && !named.includes(code)) {\n named.push(code)\n }\n }\n }\n return named.length ? named : CHECKOUT_SHIPPING_COUNTRIES\n}\n\n/**\n * A destination a shopper declared, or `undefined` for anything this session\n * could not collect an address for anyway. Never throws: an unknown code is\n * an undeclared destination, not an error, so a stale storefront that posts\n * one is answered by the plan below rather than by a 400 nobody can act on.\n */\nexport function normalizeCheckoutShippingCountry(\n value: unknown,\n countries: readonly string[] = STRIPE_SHIPPING_COUNTRY_CODES,\n): string | undefined {\n // `typeof` rather than `String(value)`: a JSON body is caller-shaped, and\n // `String(['US'])` is 'US'. Coercing would let an array declare a\n // destination, which is not a spelling any storefront sends.\n if (typeof value !== 'string') return undefined\n const code = value.trim().toUpperCase()\n return countries.includes(code) ? code : undefined\n}\n\nexport interface CheckoutShippingPlan {\n /** `shipping_address_collection[allowed_countries]` for this session. */\n countries: readonly string[]\n /** `shipping_options` for this session — valid for EVERY `countries` entry. */\n options: ResolvedShippingRate[]\n /**\n * Set when no session may be created at all:\n *\n * - `destination-required` — the merchant's rates differ by destination, so\n * there is no set of options honest for every address Stripe would accept.\n * Ask the shopper where they are shipping and plan again.\n * - `destination-unserved` — the merchant ships somewhere, but not there.\n * - `cart-unpriceable` — the merchant priced shipping, but no rate of theirs\n * resolves for THIS cart at ANY destination (AGL-2232). A tier table that\n * stops at 2 kg says nothing about a 3 kg parcel, and the honest answer is\n * to refuse rather than to ship it for nothing.\n */\n refusal?: 'destination-required' | 'destination-unserved' | 'cart-unpriceable'\n}\n\n/**\n * Whether this merchant prices shipping AT ALL (AGL-2232).\n *\n * A pure question about the SETTINGS, deliberately taking no cart, and that is\n * the whole point of it existing. `planCheckoutShipping` used to ask \"does any\n * rate resolve for any destination?\" and pass the live cart into the probe, so\n * a cart that exhausted every tier made the probe empty too — and an empty\n * probe reads as \"this merchant never set shipping up\", the one case that must\n * complete with no `shipping_options` and nothing charged. A 3 kg order at a\n * store whose weight tiers stop at 2 kg therefore shipped free, silently, on\n * every one of the three doors.\n *\n * Answered from the stored zones and rates instead: a rate bound to a zone\n * that exists, or local pickup, means the merchant made a shipping decision\n * and a cart their table cannot price is a REFUSAL. A merchant with no zones,\n * no rates and no pickup has made no such decision, and their session stays\n * byte-identical to the one AGL-1707 shipped.\n */\nexport function merchantPricesShipping(\n settings: ShippingSettings | undefined,\n): boolean {\n if (!settings) return false\n if (settings.localPickup) return true\n const zoneIds = new Set((settings.zones ?? []).map((zone) => zone.id))\n // A rate whose `zoneId` names no zone is unreachable by every resolver here,\n // so it is not evidence of a decision — counting it would refuse carts at a\n // store with nothing but orphaned rows.\n return (settings.rates ?? []).some((rate) => zoneIds.has(rate.zoneId))\n}\n\n/**\n * What a shopper is told when `cart-unpriceable` refuses (AGL-2232).\n *\n * One string, shared by all three doors, because the three used to phrase the\n * two existing refusals identically and drifting here would make the same\n * store say different things depending on which button was pressed. It names\n * the cart rather than the destination on purpose — a `Ship to` select cannot\n * fix a parcel no tier covers, so the refusal deliberately does NOT set\n * `needsShippingCountry`.\n */\nexport const CART_UNPRICEABLE_SHIPPING_MESSAGE =\n 'This store cannot price shipping for this order — it falls outside every ' +\n 'shipping rate the store has set up. Try removing an item, or contact the ' +\n 'store.'\n\n/** Identity of a resolved list, for comparing two destinations' offers. */\nfunction optionsKey(options: readonly ResolvedShippingRate[]): string {\n return options\n .map((option) => `${option.rateId}:${option.amountCents}`)\n .join('|')\n}\n\n/**\n * The whole shipping half of a Checkout Session: which destinations it may\n * accept an address for, and which rates it may charge (AGL-1721).\n *\n * THE INVARIANT IS THAT EVERY RETURNED OPTION IS VALID FOR EVERY RETURNED\n * COUNTRY. Stripe offers a session's `shipping_options` to whoever reaches the\n * page and charges whichever the shopper picks — it does not filter them by\n * the address entered, and there is no field on a `shipping_rate_data` that\n * would let it. So the ONLY place a zone can be enforced is here, by choosing\n * the two lists together: narrowing the allowed countries to the declared\n * destination is what makes the rates offered for it unpickable by anyone\n * else. Filtering the rate list alone would leave a session that still accepts\n * a French address against a US rate.\n *\n * Three shapes come out of it:\n *\n * 1. A merchant whose rates resolve the SAME for every collectable country —\n * one zone, a single '*' zone, or none at all — needs no destination and\n * keeps the session AGL-1707 shipped, byte for byte. The issue notes this\n * is the common configuration, and it is the one that must not regress.\n * 2. A declared destination resolves exactly, and the session is restricted\n * to it. A caller may not skip the restriction: the country arrives in a\n * request body a shopper can craft, so a session that took the country's\n * cheap rate while still accepting any address would hand that shopper\n * the defect on purpose.\n * 3. Otherwise the caller must refuse — see `refusal`. Refusing is not lost\n * revenue in either case: with rates that differ by zone there is no\n * correct amount to charge without knowing where the parcel is going, and\n * the union AGL-1707 shipped chose the wrong one silently.\n *\n * `cart.subtotalCents` is the PRE-discount items total, matching what the cart\n * displays, so a free-over threshold means what the shopper saw it mean.\n */\nexport function planCheckoutShipping(\n settings: ShippingSettings | undefined,\n cart: ShippingCart,\n destinationCountry?: unknown,\n): CheckoutShippingPlan {\n const countries = checkoutShippingCountries(settings)\n // Any Stripe-collectable code counts as DECLARED, so a shopper naming a\n // country this store's zones do not reach is told it is not served rather\n // than asked again. Only a store whose list comes from its zones refuses\n // that way: one on the fallback list ships nowhere in particular, and an\n // outside code stays undeclared there exactly as it always was.\n const declared = normalizeCheckoutShippingCountry(destinationCountry)\n const fromZones = countries !== CHECKOUT_SHIPPING_COUNTRIES\n if (declared && !countries.includes(declared) && fromZones) {\n return { countries, options: [], refusal: 'destination-unserved' }\n }\n const destination =\n declared && countries.includes(declared) ? declared : undefined\n if (destination) {\n const options = resolveCheckoutShippingOptions(\n settings,\n [destination],\n cart,\n )\n // REFUSAL IS DECIDED ON SHIPPABLE RATES, PICKUP IS OFFERED AFTERWARDS\n // (AGL-2325). `resolveShippingRates` appends pickup independent of zone\n // matching, so a merchant who turned it on had a non-empty list for every\n // destination on earth and this branch returned before it could refuse\n // anyone: a shopper in France picked `Local pickup — Free` on a physical\n // order from a US-only store, Stripe collected their French address\n // because the session still allowed it, and the merchant was paid nothing\n // to carry the parcel there. Pickup is collection, not delivery, so it\n // cannot answer \"do you ship to France\".\n //\n // `shipsElsewhere` is the same question the old probe asked, narrowed to\n // shippable rates, and it keeps the same two-way fork: a merchant who\n // configured NO shipping is not refusing anyone, so that store keeps\n // completing exactly as it does today, while a merchant who ships\n // elsewhere but not here is refusing and saying so is the honest answer.\n // A merchant who ships NOWHERE is untouched by this: pickup-only is a\n // real configuration — they deliver to no one and refuse no one — and it\n // falls through to the offer below exactly as it did.\n const shipsElsewhere = countries.some(\n (country) =>\n shippableOnly(resolveCheckoutShippingOptions(settings, [country], cart))\n .length > 0,\n )\n if (shippableOnly(options).length === 0 && shipsElsewhere) {\n return { countries, options: [], refusal: 'destination-unserved' }\n }\n if (options.length > 0) return { countries: [destination], options }\n // NOTHING resolves anywhere for this cart, and the two reasons that can be\n // true of are opposite (AGL-2232). Asked of the SETTINGS rather than of\n // this cart, because the probe above cannot tell them apart: a merchant\n // who priced shipping and whose table simply does not reach this order is\n // refusing, and used to be handed the \"never set shipping up\" branch.\n return merchantPricesShipping(settings)\n ? { countries, options: [], refusal: 'cart-unpriceable' }\n : { countries, options: [] }\n }\n const offers = new Set(\n countries.map((country) =>\n optionsKey(resolveCheckoutShippingOptions(settings, [country], cart)),\n ),\n )\n // Compared as EMITTED — capped and sanitized — because that is the list a\n // shopper can pick from. Two destinations whose rates differ only past\n // Stripe's cap still offer the same five, and offering them is honest.\n if (offers.size > 1) {\n return { countries, options: [], refusal: 'destination-required' }\n }\n const union = resolveCheckoutShippingOptions(settings, countries, cart)\n // Every destination agrees, and what they agree on is NOTHING. The same\n // fork as the declared-destination branch above (AGL-2232): a store with no\n // shipping settings completes untouched, a store whose rates cannot reach\n // this cart refuses instead of carrying the parcel for free.\n if (union.length === 0 && merchantPricesShipping(settings)) {\n return { countries, options: [], refusal: 'cart-unpriceable' }\n }\n return { countries, options: union }\n}\n\n/**\n * A cart chosen so that every rate a merchant could have written resolves if\n * it can resolve at all (AGL-1791). The settings page has no cart, and two of\n * the four rate kinds price against one: `tierAmount` takes the first tier\n * whose `upTo` is at least the value, so a zero subtotal and zero weight clear\n * every tier a merchant would write, and a `free_over` rate resolves at any\n * subtotal. A rate's conditions (AGL-4255) are set aside for the same reason:\n * some cart meets them, so a zone whose only rate is \"free over $150\" is\n * served, not turned away.\n *\n * That makes a coverage answer a LOWER BOUND on the gaps. A destination\n * reported unserved is unserved for every cart; a destination reported served\n * may still be refused for a cart dearer or heavier than the merchant's last\n * tier. Erring in this direction is the deliberate half: the console must not\n * warn a merchant whose settings are fine.\n */\nconst COVERAGE_PROBE_CART = { subtotalCents: 0, totalGrams: 0 }\n\n/** What a merchant's saved zones and rates cost their shoppers (AGL-1791). */\nexport interface ShippingCoverage {\n /** How many destinations checkout collects an address for. */\n collectable: number\n /** Collectable destinations at least one rate reaches. */\n served: string[]\n /**\n * Collectable destinations CHECKOUT REFUSES — `destination-unserved`.\n *\n * EMPTY FOR A MERCHANT WHOSE RATES REACH NOWHERE, who is not misconfigured:\n * `planCheckoutShipping` refuses nobody when no rate resolves anywhere, so\n * that store charges no shipping and completes exactly as it always has.\n * The rule lives here rather than in the caller because reading `served`\n * against a bare partition is how a surface comes to warn every store that\n * does not ship.\n */\n unserved: string[]\n /** No rate reaches anywhere: no shipping is charged, and nobody refused. */\n shipsNowhere: boolean\n /**\n * Rates differ by destination, so the storefront asks the shopper where the\n * parcel is going before it can price one — a checkout step the merchant\n * added by saving these zones, and never chose.\n */\n asksDestination: boolean\n /** Some zone already claims rest of world, so `*` is not the missing piece. */\n hasRestOfWorldZone: boolean\n /**\n * The merchant offers local pickup, so checkout presents a free collection\n * choice at every destination it does not refuse (AGL-2325).\n *\n * Deliberately NOT folded into `served`: pickup resolves for every country\n * because it is appended independent of zone matching, so counting it as\n * coverage told a US-only merchant who had switched it on that checkout\n * \"can price shipping to every destination\", which is the sentence that\n * hid the defect. It is reported alongside instead, so the card can say\n * both true things: these destinations are refused, and pickup is offered\n * to the ones that are not.\n */\n offersLocalPickup: boolean\n}\n\n/**\n * Which of the collectable destinations a merchant's settings actually cover\n * (AGL-1791), for a console surface to show them.\n *\n * Measured against `checkoutShippingCountries(settings)` and nothing wider:\n * those are the only destinations this store's session collects an address\n * for, so they are the only ones a merchant can lose an order to.\n *\n * Answered through `resolveCheckoutShippingOptions` — the same function the\n * session is built from — so a row the console allows but Stripe would reject\n * (blank id, blank name) counts as the nothing it resolves to, and a specific\n * zone with no rates still hides a `*` zone here exactly as it does at\n * checkout.\n */\nexport function summarizeShippingCoverage(\n settings: ShippingSettings | undefined,\n): ShippingCoverage {\n const served: string[] = []\n const unserved: string[] = []\n const offers = new Set<string>()\n const collectable = checkoutShippingCountries(settings)\n for (const country of collectable) {\n const options = resolveCheckoutShippingOptions(\n settings,\n [country],\n COVERAGE_PROBE_CART,\n { ignoreConditions: true },\n )\n // `asksDestination` is asked of the FULL list — pickup is a real option a\n // shopper picks, so a merchant whose US destination offers a rate plus\n // pickup while France offers only pickup genuinely does make checkout ask.\n offers.add(optionsKey(options))\n // `served` is asked of the SHIPPABLE list, so that it answers the same\n // question `planCheckoutShipping` refuses on (AGL-2325).\n ;(shippableOnly(options).length > 0 ? served : unserved).push(country)\n }\n return {\n collectable: collectable.length,\n served,\n unserved: served.length > 0 ? unserved : [],\n shipsNowhere: served.length === 0,\n asksDestination: offers.size > 1,\n offersLocalPickup: Boolean(settings?.localPickup),\n hasRestOfWorldZone: (settings?.zones ?? []).some((zone) =>\n zone.countries.some((code) => code === '*'),\n ),\n }\n}\n\n/**\n * What the Shipping card says about a store's coverage, in words (AGL-1791): the warning's headline and body when checkout\n * turns destinations away, otherwise the one line that says what it covers, and the line that says checkout asks where the\n * parcel is going. The console card and the native apps both read these, so the same store reads the same everywhere.\n */\nexport interface ShippingCoverageWords {\n /** Set when destinations are turned away: the warning's title. */\n headline: string\n /** The warning's body; empty when nothing is turned away. */\n detail: string\n /** The caption shown when nothing is turned away; empty when something is. */\n note: string\n /** Shown when rates differ by destination; empty otherwise. */\n asks: string\n}\n\n/** Names, the first eight in full: a rest-of-world gap can be 200 countries. */\nconst coverageCountryNames = (codes: readonly string[]) => {\n const names = codes.map((code) => CHECKOUT_SHIPPING_COUNTRY_NAMES[code] ?? code)\n return names.length > 8\n ? `${names.slice(0, 8).join(', ')} and ${names.length - 8} more`\n : names.join(', ')\n}\n\nexport function describeShippingCoverage(\n coverage: ShippingCoverage,\n): ShippingCoverageWords {\n const asks = coverage.asksDestination\n ? 'Rates differ by destination, so checkout asks the shopper where the parcel is going before it can price one.'\n : ''\n if (coverage.unserved.length > 0) {\n return {\n headline: `Checkout turns away ${coverage.unserved.length} of the ${coverage.collectable} destinations it collects addresses for`,\n detail:\n `No rate reaches ${coverageCountryNames(coverage.unserved)}, so an order shipping there is refused rather than posted for free. ` +\n (coverage.offersLocalPickup\n ? 'Local pickup does not cover them: it is a collection choice, not a rate, so it is offered where checkout completes and closes no gap here. '\n : '') +\n (coverage.hasRestOfWorldZone\n ? 'A rest-of-world zone is already saved, so what those destinations are missing is a rate on the zone that covers them.'\n : 'Give them a zone with a rate, or add a rest-of-world zone and price one on it.'),\n note: '',\n asks,\n }\n }\n return {\n headline: '',\n detail: '',\n note: coverage.shipsNowhere\n ? coverage.offersLocalPickup\n ? 'No rate reaches any destination, so local pickup is the only delivery choice checkout offers. Nobody is turned away and no shipping is charged.'\n : 'No rate reaches any destination, so checkout charges no shipping and turns nobody away.'\n : coverage.hasRestOfWorldZone &&\n coverage.served.length === STRIPE_SHIPPING_COUNTRY_CODES.length\n ? 'Checkout can price shipping to every country it can collect an address for.'\n : `Checkout can price shipping to every destination it collects an address for: ${coverageCountryNames(coverage.served)}.`,\n asks,\n }\n}\n\n/**\n * Emit `shipping_address_collection[allowed_countries][n]` onto a session's\n * form body. Stripe will not apply a `shipping_options` rate without an\n * address to ship to, so the two always travel together — and the countries\n * are the OTHER half of what makes a rate honest (AGL-1721), so pass the list\n * `planCheckoutShipping` returned rather than defaulting it beside a rate list\n * resolved for something narrower.\n */\nexport function appendShippingAddressCollectionParams(\n params: URLSearchParams,\n countries: readonly string[] = CHECKOUT_SHIPPING_COUNTRIES,\n): void {\n countries.forEach((code, index) => {\n params.set(`shipping_address_collection[allowed_countries][${index}]`, code)\n })\n}\n\n/**\n * Emit resolved rates as `shipping_options` on a Checkout Session's form body.\n *\n * THIS IS THE ONLY THING THAT MAKES STRIPE CHARGE SHIPPING. Without these keys\n * Stripe presents no shipping choice and `total_details.amount_shipping` is 0\n * however many zones and rates the merchant saved (AGL-1707).\n *\n * An empty list emits NOTHING — not an empty array — so a merchant who\n * configured no shipping keeps a session byte-identical to the one built\n * before shipping was wired at all. That guarantee lives here rather than in\n * each caller, so neither checkout path can lose it independently (AGL-1720).\n */\nexport function appendCheckoutShippingParams(\n params: URLSearchParams,\n options: readonly ResolvedShippingRate[],\n currency = 'usd',\n extra: { taxBehavior?: 'inclusive' | 'exclusive' } = {},\n): void {\n options.forEach((option, index) => {\n const field = `shipping_options[${index}][shipping_rate_data]`\n params.set(`${field}[type]`, 'fixed_amount')\n params.set(`${field}[display_name]`, option.name.slice(0, 100))\n params.set(`${field}[fixed_amount][amount]`, String(option.amountCents))\n params.set(`${field}[fixed_amount][currency]`, currency.toLowerCase())\n if (extra.taxBehavior) params.set(`${field}[tax_behavior]`, extra.taxBehavior)\n })\n}\n\n/**\n * Resolved options re-priced in a shopper currency (AGL-4248): a rate's own\n * amount in that currency when the merchant set one, else the store amount\n * converted; and a free-over rate with its own threshold there is free, or\n * not, against the goods in that currency rather than the store-currency\n * subtotal it was planned on. Pickup stays free. Order is kept.\n */\nexport function shippingOptionsInCurrency(\n options: readonly ResolvedShippingRate[],\n settings: ShippingSettings | undefined,\n currency: {\n code: string\n subtotalMinor: number\n convert: (baseCents: number, fixedMinor?: Record<string, number>) => number\n },\n): ResolvedShippingRate[] {\n const code = currency.code.toUpperCase()\n return options.map((option) => {\n if (option.rateId === LOCAL_PICKUP_RATE_ID) return option\n const rate = settings?.rates?.find((entry) => entry.id === option.rateId)\n const threshold = rate?.kind === 'free_over' ? rate.freeOverByCurrency?.[code] : undefined\n if (rate && typeof threshold === 'number') {\n const free = currency.subtotalMinor >= threshold\n const amount = free ? 0 : currency.convert(Math.max(0, Math.round(rate.amountCents ?? 0)), rate.amountsByCurrency)\n return { ...option, amountCents: amount }\n }\n if (option.amountCents === 0) return option\n const fixed =\n rate && (rate.kind === 'flat' || rate.kind === 'free_over') ? rate.amountsByCurrency : undefined\n return { ...option, amountCents: currency.convert(option.amountCents, fixed) }\n })\n}\n"],"names":["CARRIER_QUOTE_TIMEOUT_MS","conditionBound","value","n","Number","isFinite","undefined","Math","round","rateHasConditions","rate","minSubtotalCents","maxSubtotalCents","minGrams","maxGrams","rateConditionMet","cart","code","shopperSubtotal","toUpperCase","own","map","bound","base","local","limit","minor","subtotalCents","min","minSubtotalByCurrency","max","maxSubtotalByCurrency","grams","totalGrams","describeRateConditions","currencyCode","money","cents","Intl","NumberFormat","style","currency","format","weight","toFixed","range","noun","show","filter","Boolean","join","LOCAL_PICKUP_RATE_ID","zoneCode","String","trim","isWildcard","zoneMatches","zone","country","countries","some","tierAmount","tiers","sorted","sort","a","b","upTo","tier","amountCents","matchedZoneIds","settings","destinationCountry","zones","specific","matched","length","Set","id","carrierRatesFor","zoneIds","rates","kind","has","zoneId","hasCarrierRates","carrierOptionRateId","rateId","serviceKey","carrierOptionAmountCents","quotedCents","quote","pct","markupPct","handling","handlingCents","resolveShippingRates","options","resolved","ignoreConditions","freeOverCents","push","name","localPickup","shippableOnly","option","MAX_CHECKOUT_SHIPPING_OPTIONS","CHECKOUT_SHIPPING_COUNTRIES","resolveCheckoutShippingOptions","destinationCountries","byRateId","Map","existing","get","set","values","localeCompare","slice","CHECKOUT_SHIPPING_COUNTRY_CODES","CHECKOUT_SHIPPING_COUNTRY_NAMES","AC","AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CV","CW","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MK","ML","MM","MN","MO","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SZ","TA","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","US","UY","UZ","VA","VC","VE","VG","VN","VU","WF","WS","XK","YE","YT","ZA","ZM","ZW","STRIPE_SHIPPING_COUNTRY_CODES","Object","keys","checkoutShippingCountries","merchantPricesShipping","named","raw","includes","normalizeCheckoutShippingCountry","CART_UNPRICEABLE_SHIPPING_MESSAGE","optionsKey","planCheckoutShipping","declared","fromZones","refusal","destination","shipsElsewhere","offers","size","union","COVERAGE_PROBE_CART","summarizeShippingCoverage","served","unserved","collectable","add","shipsNowhere","asksDestination","offersLocalPickup","hasRestOfWorldZone","coverageCountryNames","codes","names","describeShippingCoverage","coverage","asks","headline","detail","note","appendShippingAddressCollectionParams","params","forEach","index","appendCheckoutShippingParams","extra","field","toLowerCase","taxBehavior","shippingOptionsInCurrency","find","entry","threshold","freeOverByCurrency","free","subtotalMinor","amount","convert","amountsByCurrency","fixed"],"mappings":"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;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJC,IAAI;IACJ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;;;CAMC,GACD,OAAO,SAASC,0BACdnT,OAAwC,EACxC1B,QAAsC,EACtC9B,QAIC;IAED,MAAMxB,OAAOwB,SAASxB,IAAI,CAACE,WAAW;IACtC,OAAO8E,QAAQ5E,GAAG,CAAC,CAACoF;YAELlC,iBACkC7D;QAF/C,IAAI+F,OAAOlB,MAAM,KAAKpC,sBAAsB,OAAOsD;QACnD,MAAM/F,OAAO6D,6BAAAA,kBAAAA,SAAUU,KAAK,qBAAfV,gBAAiB8U,IAAI,CAAC,CAACC,QAAUA,MAAMxU,EAAE,KAAK2B,OAAOlB,MAAM;QACxE,MAAMgU,YAAY7Y,CAAAA,wBAAAA,KAAMwE,IAAI,MAAK,eAAcxE,2BAAAA,KAAK8Y,kBAAkB,qBAAvB9Y,wBAAyB,CAACO,KAAK,GAAGX;QACjF,IAAII,QAAQ,OAAO6Y,cAAc,UAAU;gBAEyB7Y;YADlE,MAAM+Y,OAAOhX,SAASiX,aAAa,IAAIH;YACvC,MAAMI,SAASF,OAAO,IAAIhX,SAASmX,OAAO,CAACrZ,KAAKuB,GAAG,CAAC,GAAGvB,KAAKC,KAAK,EAACE,oBAAAA,KAAK2D,WAAW,YAAhB3D,oBAAoB,KAAKA,KAAKmZ,iBAAiB;YACjH,OAAO,aAAKpT;gBAAQpC,aAAasV;;QACnC;QACA,IAAIlT,OAAOpC,WAAW,KAAK,GAAG,OAAOoC;QACrC,MAAMqT,QACJpZ,QAASA,CAAAA,KAAKwE,IAAI,KAAK,UAAUxE,KAAKwE,IAAI,KAAK,WAAU,IAAKxE,KAAKmZ,iBAAiB,GAAGvZ;QACzF,OAAO,aAAKmG;YAAQpC,aAAa5B,SAASmX,OAAO,CAACnT,OAAOpC,WAAW,EAAEyV;;IACxE;AACF"}
|
|
@@ -16,7 +16,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { invalidOpeningHoursLines } from "@aglyn/aglyn/app-utils/local-business";
|
|
18
18
|
import { COMMERCE_MAX_PRICE_USD } from "./commerce.js";
|
|
19
|
-
import { summarizeShippingCoverage } from "./commerce-shipping.js";
|
|
19
|
+
import { summarizeShippingCoverage, describeRateConditions } from "./commerce-shipping.js";
|
|
20
20
|
import { storefrontTaxMisconfiguration } from "./commerce-tax-decision.js";
|
|
21
21
|
import { LOCAL_DELIVERY_POSTCODES_MAX, LOCAL_DELIVERY_ZONES_MAX, PICKUP_HOURS_MAX, PICKUP_INSTRUCTIONS_MAX, localDeliveryProblems, normalizeLocalDeliverySettings, normalizePickupSettings } from "./local-fulfillment-settings.js";
|
|
22
22
|
/*==========================================
|
|
@@ -444,6 +444,10 @@ function findLocation(locations, phrase) {
|
|
|
444
444
|
return found[0];
|
|
445
445
|
}
|
|
446
446
|
function rateSummary(rate) {
|
|
447
|
+
const conditions = describeRateConditions(rate);
|
|
448
|
+
return conditions ? `${rateKindSummary(rate)} (${conditions.toLowerCase()})` : rateKindSummary(rate);
|
|
449
|
+
}
|
|
450
|
+
function rateKindSummary(rate) {
|
|
447
451
|
switch(rate.kind){
|
|
448
452
|
case 'flat':
|
|
449
453
|
return rate.amountCents ? `${usd(rate.amountCents)} flat` : 'free';
|
|
@@ -460,6 +464,16 @@ function rateSummary(rate) {
|
|
|
460
464
|
return rate.kind;
|
|
461
465
|
}
|
|
462
466
|
}
|
|
467
|
+
const RATE_KEPT_FIELDS = [
|
|
468
|
+
'minSubtotalCents',
|
|
469
|
+
'maxSubtotalCents',
|
|
470
|
+
'minSubtotalByCurrency',
|
|
471
|
+
'maxSubtotalByCurrency',
|
|
472
|
+
'minGrams',
|
|
473
|
+
'maxGrams',
|
|
474
|
+
'amountsByCurrency',
|
|
475
|
+
'freeOverByCurrency'
|
|
476
|
+
];
|
|
463
477
|
function applyShipping(state, change, ids) {
|
|
464
478
|
var _state_settings_shipping, _current_zones, _current_rates, _ref, _ref1;
|
|
465
479
|
const current = (_state_settings_shipping = state.settings['shipping']) != null ? _state_settings_shipping : {};
|
|
@@ -539,7 +553,14 @@ function applyShipping(state, change, ids) {
|
|
|
539
553
|
return fail(409, `"${existing.name}" is a carrier rate; change it in Shipping settings`);
|
|
540
554
|
}
|
|
541
555
|
const kind = change.kind;
|
|
542
|
-
|
|
556
|
+
// What this change does not speak to stays as the merchant set it: the
|
|
557
|
+
// rate's conditions (AGL-4255) and its figures in other currencies
|
|
558
|
+
// (AGL-4248).
|
|
559
|
+
const kept = {};
|
|
560
|
+
for (const key of RATE_KEPT_FIELDS){
|
|
561
|
+
if ((existing == null ? void 0 : existing[key]) !== undefined) kept[key] = existing[key];
|
|
562
|
+
}
|
|
563
|
+
const rate = _extends({}, kept, {
|
|
543
564
|
id: (_ref = existing == null ? void 0 : existing.id) != null ? _ref : ids.rateId,
|
|
544
565
|
zoneId,
|
|
545
566
|
name: change.rateName,
|