@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/store-setup-content.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\nimport { invalidOpeningHoursLines } from '@aglyn/aglyn/app-utils/local-business'\nimport { COMMERCE_MAX_PRICE_USD } from './commerce'\nimport {\n summarizeShippingCoverage,\n type ShippingRate,\n type ShippingSettings,\n type ShippingTier,\n type ShippingZone,\n} from './commerce-shipping'\nimport type { TaxRate, TaxSettings } from './commerce-tax'\nimport { storefrontTaxMisconfiguration } from './commerce-tax-decision'\nimport {\n LOCAL_DELIVERY_POSTCODES_MAX,\n LOCAL_DELIVERY_ZONES_MAX,\n PICKUP_HOURS_MAX,\n PICKUP_INSTRUCTIONS_MAX,\n localDeliveryProblems,\n normalizeLocalDeliverySettings,\n normalizePickupSettings,\n type LocalDeliverySettings,\n type LocalDeliveryZone,\n} from './local-fulfillment-settings'\nimport type { PickupLocationSettings } from './order-local-fulfillment'\n\n/*==========================================\n * STORE SETUP AN AI BUILD CHANGES (AGL-3749)\n *\n * One change to the store's shipping, pickup, local delivery or tax settings,\n * as the `store-settings` writer receives it, and the pure step that turns\n * the settings a site has into the settings it has after the change.\n *\n * Every field is one the console's cards already save, in the shape they\n * save it:\n *\n * - `shipping`: a zone (`settings/store.shipping.zones`) and one rate in it\n * (`.rates`), priced flat, free over a subtotal, or by subtotal or weight\n * tiers — the Shipping card's four kinds. Carrier rates are not offered:\n * they quote through a carrier account a person connects.\n * - `pickup`: the store-wide \"Offer free local pickup\" switch\n * (`shipping.localPickup`), or pickup at one of the store's inventory\n * locations (`locations/{id}.pickup`), as the Inventory locations card\n * saves it. A location is found, never created.\n * - `local-delivery`: the Local delivery card's settings\n * (`settings/store.localDelivery`) with postal-code zones. Distance zones\n * need the store placed on a map first, which is the card's to do.\n * - `tax`: how the store handles sales tax (`settings/store.tax.mode`),\n * whether prices include it, the store origin and manual rates. The\n * lodging and service rates are kept as they are.\n *\n * Nothing here names a price or a rate the change did not carry: a blank\n * flat rate charges nothing at checkout, so a flat or free-over rate needs\n * its amount, and a tax rate needs its percentage. Pure.\n *=========================================*/\n\n/** The resource the writer is registered under; the commerce record route `store-settings` links it. */\nexport const STORE_SETUP_RESOURCE = 'store-settings'\n\nexport const STORE_SETUP_SECTIONS = ['shipping', 'pickup', 'local-delivery', 'tax'] as const\nexport type StoreSetupSection = (typeof STORE_SETUP_SECTIONS)[number]\n\n/** The rate kinds an AI change may set: every kind of the Shipping card except carrier rates. */\nexport const STORE_SHIPPING_AI_KINDS = ['flat', 'free_over', 'price_tiers', 'weight_tiers'] as const\nexport type StoreShippingAiKind = (typeof STORE_SHIPPING_AI_KINDS)[number]\n\nexport const STORE_SHIPPING_ACTIONS = ['set', 'remove'] as const\nexport const STORE_TAX_MODES = ['manual', 'stripe', 'none'] as const\n\nexport const STORE_SETUP_NAME_MAX = 80\nexport const STORE_SETUP_COUNTRIES_MAX = 60\nexport const STORE_SHIPPING_TIERS_MAX = 10\nexport const STORE_SETUP_LOCATION_MAX = 80\nexport const STORE_TAX_LABEL_MAX = 60\n/** Grams; the heaviest tier a weight table may name (1,000 kg). */\nexport const STORE_SHIPPING_MAX_GRAMS = 1_000_000\n/** Two weeks, the longest preparation or lead time the cards keep. */\nexport const STORE_SETUP_MAX_MINUTES = 14 * 24 * 60\n\nexport interface StoreShippingChange {\n section: 'shipping'\n action: 'set' | 'remove'\n zoneName: string\n countries?: string[]\n rateName?: string\n kind?: StoreShippingAiKind\n amountCents?: number\n freeOverCents?: number\n tiers?: ShippingTier[]\n}\n\nexport interface StorePickupChange {\n section: 'pickup'\n /** An inventory location's name, city or address; absent = the store-wide switch. */\n location?: string\n enabled: boolean\n hours?: string\n instructions?: string\n readyWithinMinutes?: number\n}\n\nexport interface StoreLocalDeliveryChange {\n section: 'local-delivery'\n enabled: boolean\n country?: string\n location?: string\n zoneName?: string\n postcodes?: string[]\n feeCents?: number\n minimumCents?: number\n freeOverCents?: number\n removeZone?: boolean\n windows?: string\n leadTimeMinutes?: number\n daysAhead?: number\n instructions?: string\n}\n\nexport interface StoreTaxChange {\n section: 'tax'\n mode?: 'manual' | 'stripe' | 'none'\n pricesIncludeTax?: boolean\n originCountry?: string\n originState?: string\n rateCountry?: string\n rateState?: string\n ratePct?: number\n rateLabel?: string\n removeRate?: boolean\n}\n\nexport type StoreSetupChange = StoreShippingChange | StorePickupChange | StoreLocalDeliveryChange | StoreTaxChange\n\nexport type StoreSetupRead = { ok: true; value: StoreSetupChange } | { ok: false; problems: string[] }\n\nconst COUNTRY = /^[A-Z]{2}$/\nconst STATE = /^[A-Z0-9]{1,3}$/\n\ntype Raw = Readonly<Record<string, unknown>>\n\nconst has = (raw: Raw, key: string) => raw[key] !== undefined && raw[key] !== null && raw[key] !== ''\n\nfunction text(raw: Raw, key: string, max: number, problems: string[]): string | undefined {\n if (!has(raw, key)) return undefined\n const value = raw[key]\n if (typeof value !== 'string') {\n problems.push(`\"${key}\" must be text`)\n return undefined\n }\n const trimmed = value.trim()\n if (trimmed.length > max) problems.push(`\"${key}\" must be at most ${max} characters`)\n return trimmed || undefined\n}\n\nfunction bool(raw: Raw, key: string, problems: string[]): boolean | undefined {\n if (!has(raw, key)) return undefined\n if (typeof raw[key] !== 'boolean') {\n problems.push(`\"${key}\" must be true or false`)\n return undefined\n }\n return raw[key] as boolean\n}\n\nfunction number(raw: Raw, key: string, min: number, max: number, problems: string[]): number | undefined {\n if (!has(raw, key)) return undefined\n const value = raw[key]\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n problems.push(`\"${key}\" must be a number`)\n return undefined\n }\n if (value < min || value > max) {\n problems.push(`\"${key}\" must be between ${min} and ${max}`)\n return undefined\n }\n return value\n}\n\nfunction minutes(raw: Raw, key: string, problems: string[]): number | undefined {\n const value = number(raw, key, 0, STORE_SETUP_MAX_MINUTES, problems)\n return value === undefined ? undefined : Math.round(value)\n}\n\n/** Dollars to the cents the settings store. */\nfunction cents(raw: Raw, key: string, problems: string[]): number | undefined {\n const value = number(raw, key, 0, COMMERCE_MAX_PRICE_USD, problems)\n return value === undefined ? undefined : Math.round(value * 100)\n}\n\nfunction list(raw: Raw, key: string, max: number, problems: string[]): string[] | undefined {\n if (!has(raw, key)) return undefined\n const value = raw[key]\n if (!Array.isArray(value) || value.some((one) => typeof one !== 'string')) {\n problems.push(`\"${key}\" must be a list of text`)\n return undefined\n }\n const items = (value as string[]).map((one) => one.trim()).filter(Boolean)\n if (items.length > max) problems.push(`\"${key}\" must hold at most ${max}`)\n return items\n}\n\nfunction countryCode(raw: Raw, key: string, problems: string[]): string | undefined {\n const value = text(raw, key, 2, problems)?.toUpperCase()\n if (value !== undefined && !COUNTRY.test(value)) problems.push(`\"${key}\" must be a two-letter country code like US`)\n return value\n}\n\nfunction stateCode(raw: Raw, key: string, problems: string[]): string | undefined {\n const value = text(raw, key, 3, problems)?.toUpperCase()\n if (value !== undefined && !STATE.test(value)) problems.push(`\"${key}\" must be a state or region code like TX`)\n return value\n}\n\n/** Opening-hours lines; a `;` separates lines as a newline does. */\nfunction hoursText(raw: Raw, key: string, problems: string[]): string | undefined {\n const value = text(raw, key, PICKUP_HOURS_MAX, problems)\n if (value === undefined) return undefined\n const lines = value\n .split(/\\s*(?:;|\\r?\\n)\\s*/)\n .filter(Boolean)\n .join('\\n')\n const bad = invalidOpeningHoursLines(lines)\n if (bad.length) {\n problems.push(`\"${key}\" must be lines like \"Mo-Fr 09:00-17:00\" or \"Sa 10:00-14:00\"`)\n }\n return lines\n}\n\n/** \"50:5\" → up to 50 (dollars, or grams for weight) costs $5. */\nfunction tiersOf(raw: Raw, kind: StoreShippingAiKind | undefined, problems: string[]): ShippingTier[] | undefined {\n const entries = list(raw, 'tiers', STORE_SHIPPING_TIERS_MAX, problems)\n if (entries === undefined) return undefined\n const weight = kind === 'weight_tiers'\n const tiers: ShippingTier[] = []\n for (const entry of entries) {\n const match = /^\\s*\\$?([0-9]+(?:\\.[0-9]+)?)\\s*(?:g)?\\s*:\\s*\\$?([0-9]+(?:\\.[0-9]+)?)\\s*$/.exec(entry)\n const upTo = match ? Number(match[1]) : NaN\n const amount = match ? Number(match[2]) : NaN\n if (!match || !(upTo > 0) || amount > COMMERCE_MAX_PRICE_USD || (weight && upTo > STORE_SHIPPING_MAX_GRAMS)) {\n problems.push(`\"tiers\" holds \"${entry}\", which is not \"up to:price\" like \"50:5\"`)\n return undefined\n }\n tiers.push({ upTo: weight ? Math.round(upTo) : Math.round(upTo * 100), amountCents: Math.round(amount * 100) })\n }\n tiers.sort((a, b) => a.upTo - b.upTo)\n if (tiers.some((tier, index) => index > 0 && tier.upTo === tiers[index - 1].upTo)) {\n problems.push('\"tiers\" names the same limit twice')\n }\n return tiers\n}\n\nconst KNOWN: Record<StoreSetupSection, readonly string[]> = {\n shipping: ['action', 'zoneName', 'countries', 'rateName', 'kind', 'amountUsd', 'freeOverUsd', 'tiers'],\n pickup: ['location', 'enabled', 'hours', 'instructions', 'readyWithinMinutes'],\n 'local-delivery': [\n 'enabled',\n 'country',\n 'location',\n 'zoneName',\n 'postcodes',\n 'feeUsd',\n 'minimumUsd',\n 'freeOverUsd',\n 'removeZone',\n 'windows',\n 'leadTimeMinutes',\n 'daysAhead',\n 'instructions',\n ],\n tax: [\n 'mode',\n 'pricesIncludeTax',\n 'originCountry',\n 'originState',\n 'rateCountry',\n 'rateState',\n 'ratePercent',\n 'rateLabel',\n 'removeRate',\n ],\n}\n\nfunction readShipping(raw: Raw, problems: string[]): StoreShippingChange {\n const action = has(raw, 'action') ? raw['action'] : 'set'\n if (!STORE_SHIPPING_ACTIONS.includes(action as never)) problems.push('\"action\" must be set or remove')\n const zoneName = text(raw, 'zoneName', STORE_SETUP_NAME_MAX, problems)\n if (!zoneName) problems.push('\"zoneName\" is required: the shipping zone, like \"United States\"')\n const countries = list(raw, 'countries', STORE_SETUP_COUNTRIES_MAX, problems)?.map((code) => code.toUpperCase())\n for (const code of countries ?? []) {\n if (code !== '*' && !COUNTRY.test(code)) {\n problems.push(`\"countries\" holds \"${code}\", which is not a two-letter country code or *`)\n break\n }\n }\n const rateName = text(raw, 'rateName', STORE_SETUP_NAME_MAX, problems)\n const kind = has(raw, 'kind') ? (raw['kind'] as StoreShippingAiKind) : undefined\n if (kind !== undefined && !STORE_SHIPPING_AI_KINDS.includes(kind)) {\n problems.push(`\"kind\" must be one of ${STORE_SHIPPING_AI_KINDS.join(', ')}`)\n }\n const amountCents = cents(raw, 'amountUsd', problems)\n const freeOverCents = cents(raw, 'freeOverUsd', problems)\n const tiers = tiersOf(raw, kind, problems)\n if (action === 'set') {\n // A rate with no name is dropped at checkout (AGL-1791), and a blank\n // amount charges nothing: both are the person's to state.\n if (!rateName) problems.push('\"rateName\" is required: what the shopper sees, like \"Standard\"')\n if (!kind) problems.push('\"kind\" is required')\n if ((kind === 'flat' || kind === 'free_over') && amountCents === undefined) {\n problems.push(`\"amountUsd\" is required for a ${kind === 'flat' ? 'flat' : 'free-over'} rate`)\n }\n if (kind === 'free_over' && !freeOverCents) problems.push('\"freeOverUsd\" is required for a free-over rate')\n if ((kind === 'price_tiers' || kind === 'weight_tiers') && !tiers?.length) {\n problems.push('\"tiers\" is required for a tiered rate')\n }\n }\n return {\n section: 'shipping',\n action: action as StoreShippingChange['action'],\n zoneName: zoneName ?? '',\n ...(countries ? { countries } : {}),\n ...(rateName ? { rateName } : {}),\n ...(kind ? { kind } : {}),\n ...(amountCents !== undefined ? { amountCents } : {}),\n ...(freeOverCents !== undefined ? { freeOverCents } : {}),\n ...(tiers ? { tiers } : {}),\n }\n}\n\nfunction readPickup(raw: Raw, problems: string[]): StorePickupChange {\n const location = text(raw, 'location', STORE_SETUP_LOCATION_MAX, problems)\n const hours = hoursText(raw, 'hours', problems)\n const instructions = text(raw, 'instructions', PICKUP_INSTRUCTIONS_MAX, problems)\n const readyWithinMinutes = minutes(raw, 'readyWithinMinutes', problems)\n if (!location && (hours !== undefined || instructions !== undefined || readyWithinMinutes !== undefined)) {\n problems.push('Pickup hours, instructions and preparation time belong to a location: name the inventory location')\n }\n return {\n section: 'pickup',\n enabled: bool(raw, 'enabled', problems) ?? true,\n ...(location ? { location } : {}),\n ...(hours !== undefined ? { hours } : {}),\n ...(instructions !== undefined ? { instructions } : {}),\n ...(readyWithinMinutes !== undefined ? { readyWithinMinutes } : {}),\n }\n}\n\nfunction readLocalDelivery(raw: Raw, problems: string[]): StoreLocalDeliveryChange {\n const zoneName = text(raw, 'zoneName', STORE_SETUP_NAME_MAX, problems)\n const postcodes = list(raw, 'postcodes', LOCAL_DELIVERY_POSTCODES_MAX, problems)\n const feeCents = cents(raw, 'feeUsd', problems)\n const minimumCents = cents(raw, 'minimumUsd', problems)\n const freeOverCents = cents(raw, 'freeOverUsd', problems)\n const removeZone = bool(raw, 'removeZone', problems)\n if (!zoneName && (postcodes || feeCents !== undefined || minimumCents !== undefined || freeOverCents !== undefined || removeZone)) {\n problems.push('\"zoneName\" is required to add, change or remove a delivery zone')\n }\n const daysAhead = number(raw, 'daysAhead', 1, 30, problems)\n return {\n section: 'local-delivery',\n enabled: bool(raw, 'enabled', problems) ?? true,\n ...(has(raw, 'country') ? { country: countryCode(raw, 'country', problems) } : {}),\n ...(has(raw, 'location') ? { location: text(raw, 'location', STORE_SETUP_LOCATION_MAX, problems) } : {}),\n ...(zoneName ? { zoneName } : {}),\n ...(postcodes ? { postcodes } : {}),\n ...(feeCents !== undefined ? { feeCents } : {}),\n ...(minimumCents !== undefined ? { minimumCents } : {}),\n ...(freeOverCents !== undefined ? { freeOverCents } : {}),\n ...(removeZone ? { removeZone } : {}),\n ...(has(raw, 'windows') ? { windows: hoursText(raw, 'windows', problems) } : {}),\n ...(has(raw, 'leadTimeMinutes') ? { leadTimeMinutes: minutes(raw, 'leadTimeMinutes', problems) } : {}),\n ...(daysAhead !== undefined ? { daysAhead: Math.round(daysAhead) } : {}),\n ...(has(raw, 'instructions') ? { instructions: text(raw, 'instructions', PICKUP_INSTRUCTIONS_MAX, problems) } : {}),\n }\n}\n\nfunction readTax(raw: Raw, problems: string[]): StoreTaxChange {\n const mode = has(raw, 'mode') ? raw['mode'] : undefined\n if (mode !== undefined && !STORE_TAX_MODES.includes(mode as never)) {\n problems.push(`\"mode\" must be one of ${STORE_TAX_MODES.join(', ')}`)\n }\n const change: StoreTaxChange = {\n section: 'tax',\n ...(mode !== undefined ? { mode: mode as StoreTaxChange['mode'] } : {}),\n }\n const pricesIncludeTax = bool(raw, 'pricesIncludeTax', problems)\n if (pricesIncludeTax !== undefined) change.pricesIncludeTax = pricesIncludeTax\n const originCountry = countryCode(raw, 'originCountry', problems)\n if (originCountry) change.originCountry = originCountry\n const originState = stateCode(raw, 'originState', problems)\n if (originState) change.originState = originState\n const rateCountry = countryCode(raw, 'rateCountry', problems)\n if (rateCountry) change.rateCountry = rateCountry\n const rateState = stateCode(raw, 'rateState', problems)\n if (rateState) change.rateState = rateState\n if (has(raw, 'ratePercent')) {\n const value = raw['ratePercent']\n if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value > 100) {\n problems.push('\"ratePercent\" must be a percentage above 0 and at most 100')\n } else change.ratePct = value\n }\n const rateLabel = text(raw, 'rateLabel', STORE_TAX_LABEL_MAX, problems)\n if (rateLabel) change.rateLabel = rateLabel\n const removeRate = bool(raw, 'removeRate', problems)\n if (removeRate) change.removeRate = true\n\n const touchesRate = change.ratePct !== undefined || change.removeRate || change.rateState || change.rateLabel\n if (touchesRate && !change.rateCountry) problems.push('\"rateCountry\" is required with a tax rate')\n if (change.rateCountry && change.ratePct === undefined && !change.removeRate) {\n // Never a rate the person did not state.\n problems.push('\"ratePercent\" is required with a tax rate: the percentage the request states')\n }\n if (change.ratePct !== undefined && change.removeRate) problems.push('Give \"ratePercent\" or \"removeRate\", not both')\n if (originState && !originCountry) problems.push('\"originCountry\" is required with \"originState\"')\n const said = Object.keys(change).filter((key) => key !== 'section')\n if (!said.length) {\n problems.push(\n 'Say how the store handles sales tax: manual rates (with the percentage), automatic calculation, or not collecting it',\n )\n }\n return change\n}\n\n/** Reads a change from content; the problems name what is wrong, in words a person reads. */\nexport function readStoreSetupChange(content: Raw): StoreSetupRead {\n const section = content['section'] as StoreSetupSection\n if (!STORE_SETUP_SECTIONS.includes(section)) {\n return { ok: false, problems: [`\"section\" must be one of ${STORE_SETUP_SECTIONS.join(', ')}`] }\n }\n const problems: string[] = []\n for (const key of Object.keys(content)) {\n if (key !== 'section' && !KNOWN[section].includes(key)) problems.push(`\"${key}\" is not a ${section} setting`)\n }\n const value =\n section === 'shipping'\n ? readShipping(content, problems)\n : section === 'pickup'\n ? readPickup(content, problems)\n : section === 'local-delivery'\n ? readLocalDelivery(content, problems)\n : readTax(content, problems)\n return problems.length ? { ok: false, problems } : { ok: true, value }\n}\n\n// ---------------------------------------------------------------------------\n// Applying a change\n// ---------------------------------------------------------------------------\n\n/** An inventory location as the writer reads it. */\nexport interface StoreSetupLocation {\n id: string\n name?: string\n address?: string\n city?: string\n pickup?: unknown\n}\n\n/** What the change writes: one map of the settings document, or one location's pickup. */\nexport type StoreSetupWrite =\n | { target: 'settings'; field: 'shipping' | 'localDelivery' | 'tax'; value: Record<string, unknown> }\n | { target: 'location'; locationId: string; value: PickupLocationSettings }\n\nexport type StoreSetupApplied =\n | {\n ok: true\n /** `null` when the settings already say what the change asks: nothing to write. */\n write: StoreSetupWrite | null\n /** One sentence on what the store now does. */\n summary: string\n /** What the person should know, in the console's words. */\n warnings: string[]\n }\n | { ok: false; status: 400 | 404 | 409; error: string }\n\nexport interface StoreSetupState {\n /** `hosts/{hostId}/settings/store`, or `{}`. */\n settings: Readonly<Record<string, unknown>>\n locations: readonly StoreSetupLocation[]\n}\n\n/** Ids for what a change creates, derived from the request so a retry makes the same ones. */\nexport interface StoreSetupIds {\n zoneId: string\n rateId: string\n}\n\nconst fail = (status: 400 | 404 | 409, error: string): StoreSetupApplied => ({ ok: false, status, error })\n\n/** Key-order-blind equality over plain JSON values. */\nexport function sameSetting(a: unknown, b: unknown): boolean {\n if (a === b) return true\n if (Array.isArray(a) || Array.isArray(b)) {\n return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((one, index) => sameSetting(one, b[index]))\n }\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n const left = Object.entries(a as Record<string, unknown>).filter(([, value]) => value !== undefined)\n const right = Object.entries(b as Record<string, unknown>).filter(([, value]) => value !== undefined)\n return left.length === right.length && left.every(([key, value]) => sameSetting(value, (b as Record<string, unknown>)[key]))\n }\n return false\n}\n\nconst lower = (value: unknown) => String(value ?? '').trim().toLowerCase()\nconst usd = (centsValue: number) => `$${(centsValue / 100).toFixed(centsValue % 100 ? 2 : 0)}`\nconst sameSet = (a: readonly string[], b: readonly string[]) =>\n a.length === b.length && [...a].sort().join(',') === [...b].sort().join(',')\n\n/** The store's locations a phrase names: by exact name first, then by city or address. */\nexport function matchStoreLocations(\n locations: readonly StoreSetupLocation[],\n phrase: string,\n): StoreSetupLocation[] {\n const wanted = lower(phrase)\n const byName = locations.filter((one) => lower(one.name) === wanted)\n if (byName.length) return byName\n return locations.filter(\n (one) => lower(one.city) === wanted || (wanted.length >= 3 && lower(one.address).includes(wanted)) || lower(one.name).includes(wanted),\n )\n}\n\nfunction findLocation(\n locations: readonly StoreSetupLocation[],\n phrase: string,\n): StoreSetupLocation | StoreSetupApplied {\n const found = matchStoreLocations(locations, phrase)\n if (!found.length) {\n return fail(\n 404,\n `The store has no inventory location matching \"${phrase}\". Add it under Products → Inventory locations, then ask again.`,\n )\n }\n if (found.length > 1) {\n return fail(409, `More than one location matches \"${phrase}\" (${found.map((one) => one.name || one.id).join(', ')}); say which`)\n }\n return found[0]\n}\n\nfunction rateSummary(rate: ShippingRate): string {\n switch (rate.kind) {\n case 'flat':\n return rate.amountCents ? `${usd(rate.amountCents)} flat` : 'free'\n case 'free_over':\n return `free over ${usd(rate.freeOverCents ?? 0)}, otherwise ${usd(rate.amountCents ?? 0)}`\n case 'price_tiers':\n return `${(rate.tiers ?? []).length} subtotal tiers`\n case 'weight_tiers':\n return `${(rate.tiers ?? []).length} weight tiers`\n default:\n return rate.kind\n }\n}\n\nfunction applyShipping(state: StoreSetupState, change: StoreShippingChange, ids: StoreSetupIds): StoreSetupApplied {\n const current = (state.settings['shipping'] ?? {}) as ShippingSettings\n const zones: ShippingZone[] = [...(current.zones ?? [])]\n const rates: ShippingRate[] = [...(current.rates ?? [])]\n const zoneIndex = (() => {\n const byName = zones.findIndex((zone) => lower(zone.name) === lower(change.zoneName))\n if (byName >= 0 || !change.countries?.length) return byName\n return zones.findIndex((zone) => sameSet((zone.countries ?? []).map((code) => String(code).trim().toUpperCase()), change.countries ?? []))\n })()\n const zone = zoneIndex >= 0 ? zones[zoneIndex] : undefined\n\n if (change.action === 'remove') {\n if (!zone) return { ok: true, write: null, summary: `There is no \"${change.zoneName}\" shipping zone.`, warnings: [] }\n if (change.rateName) {\n const kept = rates.filter((rate) => !(rate.zoneId === zone.id && lower(rate.name) === lower(change.rateName)))\n if (kept.length === rates.length) {\n return { ok: true, write: null, summary: `\"${zone.name}\" has no \"${change.rateName}\" rate.`, warnings: [] }\n }\n return shippingResult(current, { ...current, zones, rates: kept }, `Removed the \"${change.rateName}\" rate from ${zone.name}.`)\n }\n // The card's ✕ on a zone: the zone and its rates go together.\n return shippingResult(\n current,\n { ...current, zones: zones.filter((one) => one.id !== zone.id), rates: rates.filter((rate) => rate.zoneId !== zone.id) },\n `Removed the ${zone.name} shipping zone and its rates.`,\n )\n }\n\n let zoneId: string\n if (zone) {\n zoneId = zone.id\n if (change.countries?.length && !sameSet(zone.countries ?? [], change.countries)) {\n zones[zoneIndex] = { ...zone, countries: [...change.countries] }\n }\n } else {\n if (!change.countries?.length) {\n return fail(400, `Say which countries the new \"${change.zoneName}\" zone ships to (two-letter codes, or * for everywhere else)`)\n }\n zoneId = ids.zoneId\n zones.push({ id: zoneId, name: change.zoneName, countries: [...change.countries] })\n }\n const rateIndex = rates.findIndex((rate) => rate.zoneId === zoneId && lower(rate.name) === lower(change.rateName))\n const existing = rateIndex >= 0 ? rates[rateIndex] : undefined\n if (existing?.kind === 'carrier') {\n return fail(409, `\"${existing.name}\" is a carrier rate; change it in Shipping settings`)\n }\n const kind = change.kind as StoreShippingAiKind\n const rate: ShippingRate = {\n id: existing?.id ?? ids.rateId,\n zoneId,\n name: change.rateName as string,\n kind,\n ...(kind === 'flat' || kind === 'free_over' ? { amountCents: change.amountCents } : {}),\n ...(kind === 'free_over' ? { freeOverCents: change.freeOverCents } : {}),\n ...(kind === 'price_tiers' || kind === 'weight_tiers' ? { tiers: change.tiers } : {}),\n }\n if (rateIndex >= 0) rates[rateIndex] = rate\n else rates.push(rate)\n const zoneName = zone?.name ?? change.zoneName\n return shippingResult(current, { ...current, zones, rates }, `${zoneName}: \"${rate.name}\" is ${rateSummary(rate)}.`, rate)\n}\n\nfunction shippingResult(\n before: ShippingSettings,\n after: ShippingSettings,\n summary: string,\n changed?: ShippingRate,\n): StoreSetupApplied {\n const coverage = summarizeShippingCoverage(after)\n const warnings: string[] = []\n if (coverage.unserved.length && !coverage.shipsNowhere) {\n warnings.push(`Checkout turns away buyers in ${coverage.unserved.join(', ')}: no rate reaches them.`)\n }\n if (changed?.kind === 'price_tiers' || changed?.kind === 'weight_tiers') {\n warnings.push(`\"${changed.name}\" applies only up to its last tier; a larger or heavier order gets no rate from it.`)\n }\n return {\n ok: true,\n write: sameSetting(before, after) ? null : { target: 'settings', field: 'shipping', value: after as Record<string, unknown> },\n summary,\n warnings,\n }\n}\n\nfunction applyPickup(state: StoreSetupState, change: StorePickupChange): StoreSetupApplied {\n if (!change.location) {\n const current = (state.settings['shipping'] ?? {}) as ShippingSettings\n const after: ShippingSettings = { ...current, localPickup: change.enabled }\n return {\n ok: true,\n write: Boolean(current.localPickup) === change.enabled ? null : { target: 'settings', field: 'shipping', value: after as Record<string, unknown> },\n summary: change.enabled ? 'Checkout offers free local pickup.' : 'Checkout no longer offers free local pickup.',\n warnings: change.enabled ? ['Pickup is a collection choice; it does not widen where the store ships.'] : [],\n }\n }\n const found = findLocation(state.locations, change.location)\n if ('ok' in found) return found\n const before = normalizePickupSettings(found.pickup)\n const after = normalizePickupSettings({\n ...before,\n enabled: change.enabled,\n ...(change.hours !== undefined ? { hours: change.hours } : {}),\n ...(change.instructions !== undefined ? { instructions: change.instructions } : {}),\n ...(change.readyWithinMinutes !== undefined ? { readyWithinMinutes: change.readyWithinMinutes } : {}),\n })\n const name = found.name || 'the location'\n return {\n ok: true,\n write: sameSetting(before, after) ? null : { target: 'location', locationId: found.id, value: after },\n summary: after.enabled ? `Buyers can pick up orders at ${name}.` : `Pickup at ${name} is off.`,\n warnings: after.enabled && !after.hours ? [`${name} has no pickup hours yet; buyers are not told when to come.`] : [],\n }\n}\n\nfunction applyLocalDelivery(state: StoreSetupState, change: StoreLocalDeliveryChange, ids: StoreSetupIds): StoreSetupApplied {\n const before = normalizeLocalDeliverySettings(state.settings['localDelivery'])\n const after: LocalDeliverySettings = { ...before, zones: [...(before.zones ?? [])] }\n if (!after.zones?.length) delete after.zones\n if (change.enabled) after.enabled = true\n else delete after.enabled\n if (change.country) after.country = change.country\n if (change.location) {\n const found = findLocation(state.locations, change.location)\n if ('ok' in found) return found\n after.locationId = found.id\n }\n if (change.windows !== undefined) after.windows = change.windows\n if (change.leadTimeMinutes !== undefined) after.leadTimeMinutes = change.leadTimeMinutes\n if (change.daysAhead !== undefined) after.daysAhead = change.daysAhead\n if (change.instructions !== undefined) after.instructions = change.instructions\n if (change.zoneName) {\n const zones: LocalDeliveryZone[] = [...(after.zones ?? [])]\n const index = zones.findIndex((zone) => lower(zone.name) === lower(change.zoneName))\n if (change.removeZone) {\n if (index >= 0) zones.splice(index, 1)\n } else if (index >= 0) {\n const zone = zones[index]\n if (change.postcodes && zone.kind === 'radius') {\n return fail(409, `\"${zone.name}\" is a distance zone; change it under Local delivery`)\n }\n zones[index] = {\n ...zone,\n ...(change.postcodes ? { postcodes: change.postcodes } : {}),\n ...(change.feeCents !== undefined ? { feeCents: change.feeCents } : {}),\n ...(change.minimumCents !== undefined ? { minimumCents: change.minimumCents } : {}),\n ...(change.freeOverCents !== undefined ? { freeOverCents: change.freeOverCents } : {}),\n }\n } else {\n if (!change.postcodes?.length) return fail(400, `Say which postal codes the \"${change.zoneName}\" zone delivers to`)\n if (change.feeCents === undefined) return fail(400, `Say what delivery to \"${change.zoneName}\" costs (0 for free)`)\n if (zones.length >= LOCAL_DELIVERY_ZONES_MAX) return fail(409, `Local delivery holds at most ${LOCAL_DELIVERY_ZONES_MAX} zones`)\n zones.push({\n id: ids.zoneId,\n name: change.zoneName,\n kind: 'postcode',\n postcodes: change.postcodes,\n feeCents: change.feeCents,\n ...(change.minimumCents !== undefined ? { minimumCents: change.minimumCents } : {}),\n ...(change.freeOverCents !== undefined ? { freeOverCents: change.freeOverCents } : {}),\n })\n }\n after.zones = zones\n }\n const normalized = normalizeLocalDeliverySettings(after)\n const problems = localDeliveryProblems(normalized)\n if (problems.length) {\n return fail(400, `Local delivery can't be switched on yet: ${problems.join(' ')}`)\n }\n return {\n ok: true,\n write: sameSetting(before, normalized)\n ? null\n : { target: 'settings', field: 'localDelivery', value: normalized as Record<string, unknown> },\n summary: normalized.enabled\n ? `The store delivers locally to ${(normalized.zones ?? []).length} zone${(normalized.zones ?? []).length === 1 ? '' : 's'}.`\n : 'Local delivery is off.',\n warnings: normalized.enabled && !normalized.locationId ? ['No location is set for delivery orders to leave from.'] : [],\n }\n}\n\nconst TAX_MODE_WORDS: Record<string, string> = {\n manual: 'manual rates',\n stripe: 'automatic calculation',\n none: 'not collecting sales tax',\n}\n\nfunction applyTax(state: StoreSetupState, change: StoreTaxChange): StoreSetupApplied {\n const before = (state.settings['tax'] ?? {}) as TaxSettings\n const after: TaxSettings = { ...before }\n const settingRate = change.ratePct !== undefined\n if (change.mode) after.mode = change.mode\n else if (settingRate && after.mode === undefined) after.mode = 'manual'\n if (settingRate && after.mode !== 'manual') {\n return fail(\n 409,\n `This store uses ${TAX_MODE_WORDS[String(after.mode)] ?? 'another tax mode'}, so a manual rate would not apply. Ask to switch to manual rates as well.`,\n )\n }\n if (change.pricesIncludeTax !== undefined) after.pricesIncludeTax = change.pricesIncludeTax\n if (change.originCountry) {\n after.origin = {\n country: change.originCountry,\n ...(change.originState ? { state: change.originState } : {}),\n }\n }\n if (change.rateCountry) {\n const rates: TaxRate[] = [...(before.rates ?? [])]\n const index = rates.findIndex(\n (rate) =>\n String(rate.country ?? '').toUpperCase() === change.rateCountry &&\n String(rate.state ?? '').toUpperCase() === (change.rateState ?? ''),\n )\n if (change.removeRate) {\n if (index >= 0) rates.splice(index, 1)\n } else {\n const rate: TaxRate = {\n country: change.rateCountry,\n ...(change.rateState ? { state: change.rateState } : {}),\n pct: change.ratePct as number,\n ...(change.rateLabel ? { label: change.rateLabel } : index >= 0 && rates[index].label ? { label: rates[index].label } : {}),\n }\n if (index >= 0) rates[index] = rate\n else rates.push(rate)\n }\n after.rates = rates\n }\n // Manual mode with no origin refuses every sale (AGL-2145): never leave a store there.\n if (storefrontTaxMisconfiguration(after)) {\n return fail(400, 'Manual tax rates need the store’s address: say which country (and state) the store sells from.')\n }\n const warnings: string[] = []\n if (after.mode === 'manual' && !(after.rates ?? []).length) {\n warnings.push('No tax rate is set yet, so orders are charged no sales tax.')\n }\n if (after.mode === 'stripe') {\n warnings.push('Automatic tax is calculated per buyer location at checkout; the register cannot calculate it for in-person sales.')\n }\n const mode = TAX_MODE_WORDS[String(after.mode)] ?? 'undecided'\n const rateLine = settingRate\n ? ` ${change.ratePct}% for ${change.rateCountry}${change.rateState ? `-${change.rateState}` : ''}.`\n : ''\n return {\n ok: true,\n write: sameSetting(before, after) ? null : { target: 'settings', field: 'tax', value: after as Record<string, unknown> },\n summary: `Sales tax: ${mode}.${rateLine}`,\n warnings,\n }\n}\n\n/** The settings after a change, what to write, and what the person is told. */\nexport function applyStoreSetupChange(\n state: StoreSetupState,\n change: StoreSetupChange,\n ids: StoreSetupIds,\n): StoreSetupApplied {\n switch (change.section) {\n case 'shipping':\n return applyShipping(state, change, ids)\n case 'pickup':\n return applyPickup(state, change)\n case 'local-delivery':\n return applyLocalDelivery(state, change, ids)\n case 'tax':\n return applyTax(state, change)\n }\n}\n\n/** What a reader is told about a store's setup, for the writer's `read`. */\nexport function storeSetupFacts(settings: Readonly<Record<string, unknown>>): Record<string, unknown> {\n const shipping = (settings['shipping'] ?? {}) as ShippingSettings\n const tax = (settings['tax'] ?? {}) as TaxSettings\n const delivery = normalizeLocalDeliverySettings(settings['localDelivery'])\n return {\n shippingZones: (shipping.zones ?? []).length,\n shippingRates: (shipping.rates ?? []).length,\n localPickup: Boolean(shipping.localPickup),\n localDelivery: Boolean(delivery.enabled),\n taxMode: tax.mode ?? null,\n taxRates: (tax.rates ?? []).length,\n live: true,\n }\n}\n"],"names":["invalidOpeningHoursLines","COMMERCE_MAX_PRICE_USD","summarizeShippingCoverage","storefrontTaxMisconfiguration","LOCAL_DELIVERY_POSTCODES_MAX","LOCAL_DELIVERY_ZONES_MAX","PICKUP_HOURS_MAX","PICKUP_INSTRUCTIONS_MAX","localDeliveryProblems","normalizeLocalDeliverySettings","normalizePickupSettings","STORE_SETUP_RESOURCE","STORE_SETUP_SECTIONS","STORE_SHIPPING_AI_KINDS","STORE_SHIPPING_ACTIONS","STORE_TAX_MODES","STORE_SETUP_NAME_MAX","STORE_SETUP_COUNTRIES_MAX","STORE_SHIPPING_TIERS_MAX","STORE_SETUP_LOCATION_MAX","STORE_TAX_LABEL_MAX","STORE_SHIPPING_MAX_GRAMS","STORE_SETUP_MAX_MINUTES","COUNTRY","STATE","has","raw","key","undefined","text","max","problems","value","push","trimmed","trim","length","bool","number","min","Number","isFinite","minutes","Math","round","cents","list","Array","isArray","some","one","items","map","filter","Boolean","countryCode","toUpperCase","test","stateCode","hoursText","lines","split","join","bad","tiersOf","kind","entries","weight","tiers","entry","match","exec","upTo","NaN","amount","amountCents","sort","a","b","tier","index","KNOWN","shipping","pickup","tax","readShipping","action","includes","zoneName","countries","code","rateName","freeOverCents","section","readPickup","location","hours","instructions","readyWithinMinutes","enabled","readLocalDelivery","postcodes","feeCents","minimumCents","removeZone","daysAhead","country","windows","leadTimeMinutes","readTax","mode","change","pricesIncludeTax","originCountry","originState","rateCountry","rateState","ratePct","rateLabel","removeRate","touchesRate","said","Object","keys","readStoreSetupChange","content","ok","fail","status","error","sameSetting","every","left","right","lower","String","toLowerCase","usd","centsValue","toFixed","sameSet","matchStoreLocations","locations","phrase","wanted","byName","name","city","address","findLocation","found","id","rateSummary","rate","applyShipping","state","ids","current","settings","zones","rates","zoneIndex","findIndex","zone","write","summary","warnings","kept","zoneId","shippingResult","rateIndex","existing","rateId","before","after","changed","coverage","unserved","shipsNowhere","target","field","applyPickup","localPickup","locationId","applyLocalDelivery","normalized","splice","TAX_MODE_WORDS","manual","stripe","none","applyTax","settingRate","origin","pct","label","rateLine","applyStoreSetupChange","storeSetupFacts","delivery","shippingZones","shippingRates","localDelivery","taxMode","taxRates","live"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,wBAAwB,QAAQ,wCAAuC;AAChF,SAASC,sBAAsB,QAAQ,gBAAY;AACnD,SACEC,yBAAyB,QAKpB,yBAAqB;AAE5B,SAASC,6BAA6B,QAAQ,6BAAyB;AACvE,SACEC,4BAA4B,EAC5BC,wBAAwB,EACxBC,gBAAgB,EAChBC,uBAAuB,EACvBC,qBAAqB,EACrBC,8BAA8B,EAC9BC,uBAAuB,QAGlB,kCAA8B;AAGrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CA4B2C,GAE3C,sGAAsG,GACtG,OAAO,MAAMC,uBAAuB,iBAAgB;AAEpD,OAAO,MAAMC,uBAAuB;IAAC;IAAY;IAAU;IAAkB;CAAM,CAAS;AAG5F,+FAA+F,GAC/F,OAAO,MAAMC,0BAA0B;IAAC;IAAQ;IAAa;IAAe;CAAe,CAAS;AAGpG,OAAO,MAAMC,yBAAyB;IAAC;IAAO;CAAS,CAAS;AAChE,OAAO,MAAMC,kBAAkB;IAAC;IAAU;IAAU;CAAO,CAAS;AAEpE,OAAO,MAAMC,uBAAuB,GAAE;AACtC,OAAO,MAAMC,4BAA4B,GAAE;AAC3C,OAAO,MAAMC,2BAA2B,GAAE;AAC1C,OAAO,MAAMC,2BAA2B,GAAE;AAC1C,OAAO,MAAMC,sBAAsB,GAAE;AACrC,iEAAiE,GACjE,OAAO,MAAMC,2BAA2B,QAAS;AACjD,oEAAoE,GACpE,OAAO,MAAMC,0BAA0B,KAAK,KAAK,GAAE;AA0DnD,MAAMC,UAAU;AAChB,MAAMC,QAAQ;AAId,MAAMC,MAAM,CAACC,KAAUC,MAAgBD,GA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,OAAOlB,OAAO;QACpB,KAAK;YACH,OAAO6D,cAAcC,OAAO5C,QAAQ6C;QACtC,KAAK;YACH,OAAOyB,YAAY1B,OAAO5C;QAC5B,KAAK;YACH,OAAOyE,mBAAmB7B,OAAO5C,QAAQ6C;QAC3C,KAAK;YACH,OAAOmC,SAASpC,OAAO5C;IAC3B;AACF;AAEA,0EAA0E,GAC1E,OAAO,SAASuF,gBAAgBxC,QAA2C;QACvDA,oBACLA,eAGK5E,iBACAA,iBAGPE,WACEA;IATb,MAAMF,YAAY4E,qBAAAA,QAAQ,CAAC,WAAW,YAApBA,qBAAwB,CAAC;IAC3C,MAAM1E,OAAO0E,gBAAAA,QAAQ,CAAC,MAAM,YAAfA,gBAAmB,CAAC;IACjC,MAAMyC,WAAW9L,+BAA+BqJ,QAAQ,CAAC,gBAAgB;IACzE,OAAO;QACL0C,eAAe,EAACtH,kBAAAA,SAAS6E,KAAK,YAAd7E,kBAAkB,EAAE,EAAE9C,MAAM;QAC5CqK,eAAe,EAACvH,kBAAAA,SAAS8E,KAAK,YAAd9E,kBAAkB,EAAE,EAAE9C,MAAM;QAC5CkJ,aAAahI,QAAQ4B,SAASoG,WAAW;QACzCoB,eAAepJ,QAAQiJ,SAASpG,OAAO;QACvCwG,OAAO,GAAEvH,YAAAA,IAAI0B,IAAI,YAAR1B,YAAY;QACrBwH,UAAU,EAACxH,aAAAA,IAAI4E,KAAK,YAAT5E,aAAa,EAAE,EAAEhD,MAAM;QAClCyK,MAAM;IACR;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/store-setup-content.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\nimport { invalidOpeningHoursLines } from '@aglyn/aglyn/app-utils/local-business'\nimport { COMMERCE_MAX_PRICE_USD } from './commerce'\nimport {\n summarizeShippingCoverage,\n describeRateConditions,\n type ShippingRate,\n type ShippingSettings,\n type ShippingTier,\n type ShippingZone,\n} from './commerce-shipping'\nimport type { TaxRate, TaxSettings } from './commerce-tax'\nimport { storefrontTaxMisconfiguration } from './commerce-tax-decision'\nimport {\n LOCAL_DELIVERY_POSTCODES_MAX,\n LOCAL_DELIVERY_ZONES_MAX,\n PICKUP_HOURS_MAX,\n PICKUP_INSTRUCTIONS_MAX,\n localDeliveryProblems,\n normalizeLocalDeliverySettings,\n normalizePickupSettings,\n type LocalDeliverySettings,\n type LocalDeliveryZone,\n} from './local-fulfillment-settings'\nimport type { PickupLocationSettings } from './order-local-fulfillment'\n\n/*==========================================\n * STORE SETUP AN AI BUILD CHANGES (AGL-3749)\n *\n * One change to the store's shipping, pickup, local delivery or tax settings,\n * as the `store-settings` writer receives it, and the pure step that turns\n * the settings a site has into the settings it has after the change.\n *\n * Every field is one the console's cards already save, in the shape they\n * save it:\n *\n * - `shipping`: a zone (`settings/store.shipping.zones`) and one rate in it\n * (`.rates`), priced flat, free over a subtotal, or by subtotal or weight\n * tiers — the Shipping card's four kinds. Carrier rates are not offered:\n * they quote through a carrier account a person connects.\n * - `pickup`: the store-wide \"Offer free local pickup\" switch\n * (`shipping.localPickup`), or pickup at one of the store's inventory\n * locations (`locations/{id}.pickup`), as the Inventory locations card\n * saves it. A location is found, never created.\n * - `local-delivery`: the Local delivery card's settings\n * (`settings/store.localDelivery`) with postal-code zones. Distance zones\n * need the store placed on a map first, which is the card's to do.\n * - `tax`: how the store handles sales tax (`settings/store.tax.mode`),\n * whether prices include it, the store origin and manual rates. The\n * lodging and service rates are kept as they are.\n *\n * Nothing here names a price or a rate the change did not carry: a blank\n * flat rate charges nothing at checkout, so a flat or free-over rate needs\n * its amount, and a tax rate needs its percentage. Pure.\n *=========================================*/\n\n/** The resource the writer is registered under; the commerce record route `store-settings` links it. */\nexport const STORE_SETUP_RESOURCE = 'store-settings'\n\nexport const STORE_SETUP_SECTIONS = ['shipping', 'pickup', 'local-delivery', 'tax'] as const\nexport type StoreSetupSection = (typeof STORE_SETUP_SECTIONS)[number]\n\n/** The rate kinds an AI change may set: every kind of the Shipping card except carrier rates. */\nexport const STORE_SHIPPING_AI_KINDS = ['flat', 'free_over', 'price_tiers', 'weight_tiers'] as const\nexport type StoreShippingAiKind = (typeof STORE_SHIPPING_AI_KINDS)[number]\n\nexport const STORE_SHIPPING_ACTIONS = ['set', 'remove'] as const\nexport const STORE_TAX_MODES = ['manual', 'stripe', 'none'] as const\n\nexport const STORE_SETUP_NAME_MAX = 80\nexport const STORE_SETUP_COUNTRIES_MAX = 60\nexport const STORE_SHIPPING_TIERS_MAX = 10\nexport const STORE_SETUP_LOCATION_MAX = 80\nexport const STORE_TAX_LABEL_MAX = 60\n/** Grams; the heaviest tier a weight table may name (1,000 kg). */\nexport const STORE_SHIPPING_MAX_GRAMS = 1_000_000\n/** Two weeks, the longest preparation or lead time the cards keep. */\nexport const STORE_SETUP_MAX_MINUTES = 14 * 24 * 60\n\nexport interface StoreShippingChange {\n section: 'shipping'\n action: 'set' | 'remove'\n zoneName: string\n countries?: string[]\n rateName?: string\n kind?: StoreShippingAiKind\n amountCents?: number\n freeOverCents?: number\n tiers?: ShippingTier[]\n}\n\nexport interface StorePickupChange {\n section: 'pickup'\n /** An inventory location's name, city or address; absent = the store-wide switch. */\n location?: string\n enabled: boolean\n hours?: string\n instructions?: string\n readyWithinMinutes?: number\n}\n\nexport interface StoreLocalDeliveryChange {\n section: 'local-delivery'\n enabled: boolean\n country?: string\n location?: string\n zoneName?: string\n postcodes?: string[]\n feeCents?: number\n minimumCents?: number\n freeOverCents?: number\n removeZone?: boolean\n windows?: string\n leadTimeMinutes?: number\n daysAhead?: number\n instructions?: string\n}\n\nexport interface StoreTaxChange {\n section: 'tax'\n mode?: 'manual' | 'stripe' | 'none'\n pricesIncludeTax?: boolean\n originCountry?: string\n originState?: string\n rateCountry?: string\n rateState?: string\n ratePct?: number\n rateLabel?: string\n removeRate?: boolean\n}\n\nexport type StoreSetupChange = StoreShippingChange | StorePickupChange | StoreLocalDeliveryChange | StoreTaxChange\n\nexport type StoreSetupRead = { ok: true; value: StoreSetupChange } | { ok: false; problems: string[] }\n\nconst COUNTRY = /^[A-Z]{2}$/\nconst STATE = /^[A-Z0-9]{1,3}$/\n\ntype Raw = Readonly<Record<string, unknown>>\n\nconst has = (raw: Raw, key: string) => raw[key] !== undefined && raw[key] !== null && raw[key] !== ''\n\nfunction text(raw: Raw, key: string, max: number, problems: string[]): string | undefined {\n if (!has(raw, key)) return undefined\n const value = raw[key]\n if (typeof value !== 'string') {\n problems.push(`\"${key}\" must be text`)\n return undefined\n }\n const trimmed = value.trim()\n if (trimmed.length > max) problems.push(`\"${key}\" must be at most ${max} characters`)\n return trimmed || undefined\n}\n\nfunction bool(raw: Raw, key: string, problems: string[]): boolean | undefined {\n if (!has(raw, key)) return undefined\n if (typeof raw[key] !== 'boolean') {\n problems.push(`\"${key}\" must be true or false`)\n return undefined\n }\n return raw[key] as boolean\n}\n\nfunction number(raw: Raw, key: string, min: number, max: number, problems: string[]): number | undefined {\n if (!has(raw, key)) return undefined\n const value = raw[key]\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n problems.push(`\"${key}\" must be a number`)\n return undefined\n }\n if (value < min || value > max) {\n problems.push(`\"${key}\" must be between ${min} and ${max}`)\n return undefined\n }\n return value\n}\n\nfunction minutes(raw: Raw, key: string, problems: string[]): number | undefined {\n const value = number(raw, key, 0, STORE_SETUP_MAX_MINUTES, problems)\n return value === undefined ? undefined : Math.round(value)\n}\n\n/** Dollars to the cents the settings store. */\nfunction cents(raw: Raw, key: string, problems: string[]): number | undefined {\n const value = number(raw, key, 0, COMMERCE_MAX_PRICE_USD, problems)\n return value === undefined ? undefined : Math.round(value * 100)\n}\n\nfunction list(raw: Raw, key: string, max: number, problems: string[]): string[] | undefined {\n if (!has(raw, key)) return undefined\n const value = raw[key]\n if (!Array.isArray(value) || value.some((one) => typeof one !== 'string')) {\n problems.push(`\"${key}\" must be a list of text`)\n return undefined\n }\n const items = (value as string[]).map((one) => one.trim()).filter(Boolean)\n if (items.length > max) problems.push(`\"${key}\" must hold at most ${max}`)\n return items\n}\n\nfunction countryCode(raw: Raw, key: string, problems: string[]): string | undefined {\n const value = text(raw, key, 2, problems)?.toUpperCase()\n if (value !== undefined && !COUNTRY.test(value)) problems.push(`\"${key}\" must be a two-letter country code like US`)\n return value\n}\n\nfunction stateCode(raw: Raw, key: string, problems: string[]): string | undefined {\n const value = text(raw, key, 3, problems)?.toUpperCase()\n if (value !== undefined && !STATE.test(value)) problems.push(`\"${key}\" must be a state or region code like TX`)\n return value\n}\n\n/** Opening-hours lines; a `;` separates lines as a newline does. */\nfunction hoursText(raw: Raw, key: string, problems: string[]): string | undefined {\n const value = text(raw, key, PICKUP_HOURS_MAX, problems)\n if (value === undefined) return undefined\n const lines = value\n .split(/\\s*(?:;|\\r?\\n)\\s*/)\n .filter(Boolean)\n .join('\\n')\n const bad = invalidOpeningHoursLines(lines)\n if (bad.length) {\n problems.push(`\"${key}\" must be lines like \"Mo-Fr 09:00-17:00\" or \"Sa 10:00-14:00\"`)\n }\n return lines\n}\n\n/** \"50:5\" → up to 50 (dollars, or grams for weight) costs $5. */\nfunction tiersOf(raw: Raw, kind: StoreShippingAiKind | undefined, problems: string[]): ShippingTier[] | undefined {\n const entries = list(raw, 'tiers', STORE_SHIPPING_TIERS_MAX, problems)\n if (entries === undefined) return undefined\n const weight = kind === 'weight_tiers'\n const tiers: ShippingTier[] = []\n for (const entry of entries) {\n const match = /^\\s*\\$?([0-9]+(?:\\.[0-9]+)?)\\s*(?:g)?\\s*:\\s*\\$?([0-9]+(?:\\.[0-9]+)?)\\s*$/.exec(entry)\n const upTo = match ? Number(match[1]) : NaN\n const amount = match ? Number(match[2]) : NaN\n if (!match || !(upTo > 0) || amount > COMMERCE_MAX_PRICE_USD || (weight && upTo > STORE_SHIPPING_MAX_GRAMS)) {\n problems.push(`\"tiers\" holds \"${entry}\", which is not \"up to:price\" like \"50:5\"`)\n return undefined\n }\n tiers.push({ upTo: weight ? Math.round(upTo) : Math.round(upTo * 100), amountCents: Math.round(amount * 100) })\n }\n tiers.sort((a, b) => a.upTo - b.upTo)\n if (tiers.some((tier, index) => index > 0 && tier.upTo === tiers[index - 1].upTo)) {\n problems.push('\"tiers\" names the same limit twice')\n }\n return tiers\n}\n\nconst KNOWN: Record<StoreSetupSection, readonly string[]> = {\n shipping: ['action', 'zoneName', 'countries', 'rateName', 'kind', 'amountUsd', 'freeOverUsd', 'tiers'],\n pickup: ['location', 'enabled', 'hours', 'instructions', 'readyWithinMinutes'],\n 'local-delivery': [\n 'enabled',\n 'country',\n 'location',\n 'zoneName',\n 'postcodes',\n 'feeUsd',\n 'minimumUsd',\n 'freeOverUsd',\n 'removeZone',\n 'windows',\n 'leadTimeMinutes',\n 'daysAhead',\n 'instructions',\n ],\n tax: [\n 'mode',\n 'pricesIncludeTax',\n 'originCountry',\n 'originState',\n 'rateCountry',\n 'rateState',\n 'ratePercent',\n 'rateLabel',\n 'removeRate',\n ],\n}\n\nfunction readShipping(raw: Raw, problems: string[]): StoreShippingChange {\n const action = has(raw, 'action') ? raw['action'] : 'set'\n if (!STORE_SHIPPING_ACTIONS.includes(action as never)) problems.push('\"action\" must be set or remove')\n const zoneName = text(raw, 'zoneName', STORE_SETUP_NAME_MAX, problems)\n if (!zoneName) problems.push('\"zoneName\" is required: the shipping zone, like \"United States\"')\n const countries = list(raw, 'countries', STORE_SETUP_COUNTRIES_MAX, problems)?.map((code) => code.toUpperCase())\n for (const code of countries ?? []) {\n if (code !== '*' && !COUNTRY.test(code)) {\n problems.push(`\"countries\" holds \"${code}\", which is not a two-letter country code or *`)\n break\n }\n }\n const rateName = text(raw, 'rateName', STORE_SETUP_NAME_MAX, problems)\n const kind = has(raw, 'kind') ? (raw['kind'] as StoreShippingAiKind) : undefined\n if (kind !== undefined && !STORE_SHIPPING_AI_KINDS.includes(kind)) {\n problems.push(`\"kind\" must be one of ${STORE_SHIPPING_AI_KINDS.join(', ')}`)\n }\n const amountCents = cents(raw, 'amountUsd', problems)\n const freeOverCents = cents(raw, 'freeOverUsd', problems)\n const tiers = tiersOf(raw, kind, problems)\n if (action === 'set') {\n // A rate with no name is dropped at checkout (AGL-1791), and a blank\n // amount charges nothing: both are the person's to state.\n if (!rateName) problems.push('\"rateName\" is required: what the shopper sees, like \"Standard\"')\n if (!kind) problems.push('\"kind\" is required')\n if ((kind === 'flat' || kind === 'free_over') && amountCents === undefined) {\n problems.push(`\"amountUsd\" is required for a ${kind === 'flat' ? 'flat' : 'free-over'} rate`)\n }\n if (kind === 'free_over' && !freeOverCents) problems.push('\"freeOverUsd\" is required for a free-over rate')\n if ((kind === 'price_tiers' || kind === 'weight_tiers') && !tiers?.length) {\n problems.push('\"tiers\" is required for a tiered rate')\n }\n }\n return {\n section: 'shipping',\n action: action as StoreShippingChange['action'],\n zoneName: zoneName ?? '',\n ...(countries ? { countries } : {}),\n ...(rateName ? { rateName } : {}),\n ...(kind ? { kind } : {}),\n ...(amountCents !== undefined ? { amountCents } : {}),\n ...(freeOverCents !== undefined ? { freeOverCents } : {}),\n ...(tiers ? { tiers } : {}),\n }\n}\n\nfunction readPickup(raw: Raw, problems: string[]): StorePickupChange {\n const location = text(raw, 'location', STORE_SETUP_LOCATION_MAX, problems)\n const hours = hoursText(raw, 'hours', problems)\n const instructions = text(raw, 'instructions', PICKUP_INSTRUCTIONS_MAX, problems)\n const readyWithinMinutes = minutes(raw, 'readyWithinMinutes', problems)\n if (!location && (hours !== undefined || instructions !== undefined || readyWithinMinutes !== undefined)) {\n problems.push('Pickup hours, instructions and preparation time belong to a location: name the inventory location')\n }\n return {\n section: 'pickup',\n enabled: bool(raw, 'enabled', problems) ?? true,\n ...(location ? { location } : {}),\n ...(hours !== undefined ? { hours } : {}),\n ...(instructions !== undefined ? { instructions } : {}),\n ...(readyWithinMinutes !== undefined ? { readyWithinMinutes } : {}),\n }\n}\n\nfunction readLocalDelivery(raw: Raw, problems: string[]): StoreLocalDeliveryChange {\n const zoneName = text(raw, 'zoneName', STORE_SETUP_NAME_MAX, problems)\n const postcodes = list(raw, 'postcodes', LOCAL_DELIVERY_POSTCODES_MAX, problems)\n const feeCents = cents(raw, 'feeUsd', problems)\n const minimumCents = cents(raw, 'minimumUsd', problems)\n const freeOverCents = cents(raw, 'freeOverUsd', problems)\n const removeZone = bool(raw, 'removeZone', problems)\n if (!zoneName && (postcodes || feeCents !== undefined || minimumCents !== undefined || freeOverCents !== undefined || removeZone)) {\n problems.push('\"zoneName\" is required to add, change or remove a delivery zone')\n }\n const daysAhead = number(raw, 'daysAhead', 1, 30, problems)\n return {\n section: 'local-delivery',\n enabled: bool(raw, 'enabled', problems) ?? true,\n ...(has(raw, 'country') ? { country: countryCode(raw, 'country', problems) } : {}),\n ...(has(raw, 'location') ? { location: text(raw, 'location', STORE_SETUP_LOCATION_MAX, problems) } : {}),\n ...(zoneName ? { zoneName } : {}),\n ...(postcodes ? { postcodes } : {}),\n ...(feeCents !== undefined ? { feeCents } : {}),\n ...(minimumCents !== undefined ? { minimumCents } : {}),\n ...(freeOverCents !== undefined ? { freeOverCents } : {}),\n ...(removeZone ? { removeZone } : {}),\n ...(has(raw, 'windows') ? { windows: hoursText(raw, 'windows', problems) } : {}),\n ...(has(raw, 'leadTimeMinutes') ? { leadTimeMinutes: minutes(raw, 'leadTimeMinutes', problems) } : {}),\n ...(daysAhead !== undefined ? { daysAhead: Math.round(daysAhead) } : {}),\n ...(has(raw, 'instructions') ? { instructions: text(raw, 'instructions', PICKUP_INSTRUCTIONS_MAX, problems) } : {}),\n }\n}\n\nfunction readTax(raw: Raw, problems: string[]): StoreTaxChange {\n const mode = has(raw, 'mode') ? raw['mode'] : undefined\n if (mode !== undefined && !STORE_TAX_MODES.includes(mode as never)) {\n problems.push(`\"mode\" must be one of ${STORE_TAX_MODES.join(', ')}`)\n }\n const change: StoreTaxChange = {\n section: 'tax',\n ...(mode !== undefined ? { mode: mode as StoreTaxChange['mode'] } : {}),\n }\n const pricesIncludeTax = bool(raw, 'pricesIncludeTax', problems)\n if (pricesIncludeTax !== undefined) change.pricesIncludeTax = pricesIncludeTax\n const originCountry = countryCode(raw, 'originCountry', problems)\n if (originCountry) change.originCountry = originCountry\n const originState = stateCode(raw, 'originState', problems)\n if (originState) change.originState = originState\n const rateCountry = countryCode(raw, 'rateCountry', problems)\n if (rateCountry) change.rateCountry = rateCountry\n const rateState = stateCode(raw, 'rateState', problems)\n if (rateState) change.rateState = rateState\n if (has(raw, 'ratePercent')) {\n const value = raw['ratePercent']\n if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value > 100) {\n problems.push('\"ratePercent\" must be a percentage above 0 and at most 100')\n } else change.ratePct = value\n }\n const rateLabel = text(raw, 'rateLabel', STORE_TAX_LABEL_MAX, problems)\n if (rateLabel) change.rateLabel = rateLabel\n const removeRate = bool(raw, 'removeRate', problems)\n if (removeRate) change.removeRate = true\n\n const touchesRate = change.ratePct !== undefined || change.removeRate || change.rateState || change.rateLabel\n if (touchesRate && !change.rateCountry) problems.push('\"rateCountry\" is required with a tax rate')\n if (change.rateCountry && change.ratePct === undefined && !change.removeRate) {\n // Never a rate the person did not state.\n problems.push('\"ratePercent\" is required with a tax rate: the percentage the request states')\n }\n if (change.ratePct !== undefined && change.removeRate) problems.push('Give \"ratePercent\" or \"removeRate\", not both')\n if (originState && !originCountry) problems.push('\"originCountry\" is required with \"originState\"')\n const said = Object.keys(change).filter((key) => key !== 'section')\n if (!said.length) {\n problems.push(\n 'Say how the store handles sales tax: manual rates (with the percentage), automatic calculation, or not collecting it',\n )\n }\n return change\n}\n\n/** Reads a change from content; the problems name what is wrong, in words a person reads. */\nexport function readStoreSetupChange(content: Raw): StoreSetupRead {\n const section = content['section'] as StoreSetupSection\n if (!STORE_SETUP_SECTIONS.includes(section)) {\n return { ok: false, problems: [`\"section\" must be one of ${STORE_SETUP_SECTIONS.join(', ')}`] }\n }\n const problems: string[] = []\n for (const key of Object.keys(content)) {\n if (key !== 'section' && !KNOWN[section].includes(key)) problems.push(`\"${key}\" is not a ${section} setting`)\n }\n const value =\n section === 'shipping'\n ? readShipping(content, problems)\n : section === 'pickup'\n ? readPickup(content, problems)\n : section === 'local-delivery'\n ? readLocalDelivery(content, problems)\n : readTax(content, problems)\n return problems.length ? { ok: false, problems } : { ok: true, value }\n}\n\n// ---------------------------------------------------------------------------\n// Applying a change\n// ---------------------------------------------------------------------------\n\n/** An inventory location as the writer reads it. */\nexport interface StoreSetupLocation {\n id: string\n name?: string\n address?: string\n city?: string\n pickup?: unknown\n}\n\n/** What the change writes: one map of the settings document, or one location's pickup. */\nexport type StoreSetupWrite =\n | { target: 'settings'; field: 'shipping' | 'localDelivery' | 'tax'; value: Record<string, unknown> }\n | { target: 'location'; locationId: string; value: PickupLocationSettings }\n\nexport type StoreSetupApplied =\n | {\n ok: true\n /** `null` when the settings already say what the change asks: nothing to write. */\n write: StoreSetupWrite | null\n /** One sentence on what the store now does. */\n summary: string\n /** What the person should know, in the console's words. */\n warnings: string[]\n }\n | { ok: false; status: 400 | 404 | 409; error: string }\n\nexport interface StoreSetupState {\n /** `hosts/{hostId}/settings/store`, or `{}`. */\n settings: Readonly<Record<string, unknown>>\n locations: readonly StoreSetupLocation[]\n}\n\n/** Ids for what a change creates, derived from the request so a retry makes the same ones. */\nexport interface StoreSetupIds {\n zoneId: string\n rateId: string\n}\n\nconst fail = (status: 400 | 404 | 409, error: string): StoreSetupApplied => ({ ok: false, status, error })\n\n/** Key-order-blind equality over plain JSON values. */\nexport function sameSetting(a: unknown, b: unknown): boolean {\n if (a === b) return true\n if (Array.isArray(a) || Array.isArray(b)) {\n return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((one, index) => sameSetting(one, b[index]))\n }\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n const left = Object.entries(a as Record<string, unknown>).filter(([, value]) => value !== undefined)\n const right = Object.entries(b as Record<string, unknown>).filter(([, value]) => value !== undefined)\n return left.length === right.length && left.every(([key, value]) => sameSetting(value, (b as Record<string, unknown>)[key]))\n }\n return false\n}\n\nconst lower = (value: unknown) => String(value ?? '').trim().toLowerCase()\nconst usd = (centsValue: number) => `$${(centsValue / 100).toFixed(centsValue % 100 ? 2 : 0)}`\nconst sameSet = (a: readonly string[], b: readonly string[]) =>\n a.length === b.length && [...a].sort().join(',') === [...b].sort().join(',')\n\n/** The store's locations a phrase names: by exact name first, then by city or address. */\nexport function matchStoreLocations(\n locations: readonly StoreSetupLocation[],\n phrase: string,\n): StoreSetupLocation[] {\n const wanted = lower(phrase)\n const byName = locations.filter((one) => lower(one.name) === wanted)\n if (byName.length) return byName\n return locations.filter(\n (one) => lower(one.city) === wanted || (wanted.length >= 3 && lower(one.address).includes(wanted)) || lower(one.name).includes(wanted),\n )\n}\n\nfunction findLocation(\n locations: readonly StoreSetupLocation[],\n phrase: string,\n): StoreSetupLocation | StoreSetupApplied {\n const found = matchStoreLocations(locations, phrase)\n if (!found.length) {\n return fail(\n 404,\n `The store has no inventory location matching \"${phrase}\". Add it under Products → Inventory locations, then ask again.`,\n )\n }\n if (found.length > 1) {\n return fail(409, `More than one location matches \"${phrase}\" (${found.map((one) => one.name || one.id).join(', ')}); say which`)\n }\n return found[0]\n}\n\nfunction rateSummary(rate: ShippingRate): string {\n const conditions = describeRateConditions(rate)\n return conditions ? `${rateKindSummary(rate)} (${conditions.toLowerCase()})` : rateKindSummary(rate)\n}\n\nfunction rateKindSummary(rate: ShippingRate): string {\n switch (rate.kind) {\n case 'flat':\n return rate.amountCents ? `${usd(rate.amountCents)} flat` : 'free'\n case 'free_over':\n return `free over ${usd(rate.freeOverCents ?? 0)}, otherwise ${usd(rate.amountCents ?? 0)}`\n case 'price_tiers':\n return `${(rate.tiers ?? []).length} subtotal tiers`\n case 'weight_tiers':\n return `${(rate.tiers ?? []).length} weight tiers`\n default:\n return rate.kind\n }\n}\n\nconst RATE_KEPT_FIELDS = [\n 'minSubtotalCents',\n 'maxSubtotalCents',\n 'minSubtotalByCurrency',\n 'maxSubtotalByCurrency',\n 'minGrams',\n 'maxGrams',\n 'amountsByCurrency',\n 'freeOverByCurrency',\n] as const satisfies readonly (keyof ShippingRate)[]\n\nfunction applyShipping(state: StoreSetupState, change: StoreShippingChange, ids: StoreSetupIds): StoreSetupApplied {\n const current = (state.settings['shipping'] ?? {}) as ShippingSettings\n const zones: ShippingZone[] = [...(current.zones ?? [])]\n const rates: ShippingRate[] = [...(current.rates ?? [])]\n const zoneIndex = (() => {\n const byName = zones.findIndex((zone) => lower(zone.name) === lower(change.zoneName))\n if (byName >= 0 || !change.countries?.length) return byName\n return zones.findIndex((zone) => sameSet((zone.countries ?? []).map((code) => String(code).trim().toUpperCase()), change.countries ?? []))\n })()\n const zone = zoneIndex >= 0 ? zones[zoneIndex] : undefined\n\n if (change.action === 'remove') {\n if (!zone) return { ok: true, write: null, summary: `There is no \"${change.zoneName}\" shipping zone.`, warnings: [] }\n if (change.rateName) {\n const kept = rates.filter((rate) => !(rate.zoneId === zone.id && lower(rate.name) === lower(change.rateName)))\n if (kept.length === rates.length) {\n return { ok: true, write: null, summary: `\"${zone.name}\" has no \"${change.rateName}\" rate.`, warnings: [] }\n }\n return shippingResult(current, { ...current, zones, rates: kept }, `Removed the \"${change.rateName}\" rate from ${zone.name}.`)\n }\n // The card's ✕ on a zone: the zone and its rates go together.\n return shippingResult(\n current,\n { ...current, zones: zones.filter((one) => one.id !== zone.id), rates: rates.filter((rate) => rate.zoneId !== zone.id) },\n `Removed the ${zone.name} shipping zone and its rates.`,\n )\n }\n\n let zoneId: string\n if (zone) {\n zoneId = zone.id\n if (change.countries?.length && !sameSet(zone.countries ?? [], change.countries)) {\n zones[zoneIndex] = { ...zone, countries: [...change.countries] }\n }\n } else {\n if (!change.countries?.length) {\n return fail(400, `Say which countries the new \"${change.zoneName}\" zone ships to (two-letter codes, or * for everywhere else)`)\n }\n zoneId = ids.zoneId\n zones.push({ id: zoneId, name: change.zoneName, countries: [...change.countries] })\n }\n const rateIndex = rates.findIndex((rate) => rate.zoneId === zoneId && lower(rate.name) === lower(change.rateName))\n const existing = rateIndex >= 0 ? rates[rateIndex] : undefined\n if (existing?.kind === 'carrier') {\n return fail(409, `\"${existing.name}\" is a carrier rate; change it in Shipping settings`)\n }\n const kind = change.kind as StoreShippingAiKind\n // What this change does not speak to stays as the merchant set it: the\n // rate's conditions (AGL-4255) and its figures in other currencies\n // (AGL-4248).\n const kept: Partial<ShippingRate> = {}\n for (const key of RATE_KEPT_FIELDS) {\n if (existing?.[key] !== undefined) (kept as Record<string, unknown>)[key] = existing[key]\n }\n const rate: ShippingRate = {\n ...kept,\n id: existing?.id ?? ids.rateId,\n zoneId,\n name: change.rateName as string,\n kind,\n ...(kind === 'flat' || kind === 'free_over' ? { amountCents: change.amountCents } : {}),\n ...(kind === 'free_over' ? { freeOverCents: change.freeOverCents } : {}),\n ...(kind === 'price_tiers' || kind === 'weight_tiers' ? { tiers: change.tiers } : {}),\n }\n if (rateIndex >= 0) rates[rateIndex] = rate\n else rates.push(rate)\n const zoneName = zone?.name ?? change.zoneName\n return shippingResult(current, { ...current, zones, rates }, `${zoneName}: \"${rate.name}\" is ${rateSummary(rate)}.`, rate)\n}\n\nfunction shippingResult(\n before: ShippingSettings,\n after: ShippingSettings,\n summary: string,\n changed?: ShippingRate,\n): StoreSetupApplied {\n const coverage = summarizeShippingCoverage(after)\n const warnings: string[] = []\n if (coverage.unserved.length && !coverage.shipsNowhere) {\n warnings.push(`Checkout turns away buyers in ${coverage.unserved.join(', ')}: no rate reaches them.`)\n }\n if (changed?.kind === 'price_tiers' || changed?.kind === 'weight_tiers') {\n warnings.push(`\"${changed.name}\" applies only up to its last tier; a larger or heavier order gets no rate from it.`)\n }\n return {\n ok: true,\n write: sameSetting(before, after) ? null : { target: 'settings', field: 'shipping', value: after as Record<string, unknown> },\n summary,\n warnings,\n }\n}\n\nfunction applyPickup(state: StoreSetupState, change: StorePickupChange): StoreSetupApplied {\n if (!change.location) {\n const current = (state.settings['shipping'] ?? {}) as ShippingSettings\n const after: ShippingSettings = { ...current, localPickup: change.enabled }\n return {\n ok: true,\n write: Boolean(current.localPickup) === change.enabled ? null : { target: 'settings', field: 'shipping', value: after as Record<string, unknown> },\n summary: change.enabled ? 'Checkout offers free local pickup.' : 'Checkout no longer offers free local pickup.',\n warnings: change.enabled ? ['Pickup is a collection choice; it does not widen where the store ships.'] : [],\n }\n }\n const found = findLocation(state.locations, change.location)\n if ('ok' in found) return found\n const before = normalizePickupSettings(found.pickup)\n const after = normalizePickupSettings({\n ...before,\n enabled: change.enabled,\n ...(change.hours !== undefined ? { hours: change.hours } : {}),\n ...(change.instructions !== undefined ? { instructions: change.instructions } : {}),\n ...(change.readyWithinMinutes !== undefined ? { readyWithinMinutes: change.readyWithinMinutes } : {}),\n })\n const name = found.name || 'the location'\n return {\n ok: true,\n write: sameSetting(before, after) ? null : { target: 'location', locationId: found.id, value: after },\n summary: after.enabled ? `Buyers can pick up orders at ${name}.` : `Pickup at ${name} is off.`,\n warnings: after.enabled && !after.hours ? [`${name} has no pickup hours yet; buyers are not told when to come.`] : [],\n }\n}\n\nfunction applyLocalDelivery(state: StoreSetupState, change: StoreLocalDeliveryChange, ids: StoreSetupIds): StoreSetupApplied {\n const before = normalizeLocalDeliverySettings(state.settings['localDelivery'])\n const after: LocalDeliverySettings = { ...before, zones: [...(before.zones ?? [])] }\n if (!after.zones?.length) delete after.zones\n if (change.enabled) after.enabled = true\n else delete after.enabled\n if (change.country) after.country = change.country\n if (change.location) {\n const found = findLocation(state.locations, change.location)\n if ('ok' in found) return found\n after.locationId = found.id\n }\n if (change.windows !== undefined) after.windows = change.windows\n if (change.leadTimeMinutes !== undefined) after.leadTimeMinutes = change.leadTimeMinutes\n if (change.daysAhead !== undefined) after.daysAhead = change.daysAhead\n if (change.instructions !== undefined) after.instructions = change.instructions\n if (change.zoneName) {\n const zones: LocalDeliveryZone[] = [...(after.zones ?? [])]\n const index = zones.findIndex((zone) => lower(zone.name) === lower(change.zoneName))\n if (change.removeZone) {\n if (index >= 0) zones.splice(index, 1)\n } else if (index >= 0) {\n const zone = zones[index]\n if (change.postcodes && zone.kind === 'radius') {\n return fail(409, `\"${zone.name}\" is a distance zone; change it under Local delivery`)\n }\n zones[index] = {\n ...zone,\n ...(change.postcodes ? { postcodes: change.postcodes } : {}),\n ...(change.feeCents !== undefined ? { feeCents: change.feeCents } : {}),\n ...(change.minimumCents !== undefined ? { minimumCents: change.minimumCents } : {}),\n ...(change.freeOverCents !== undefined ? { freeOverCents: change.freeOverCents } : {}),\n }\n } else {\n if (!change.postcodes?.length) return fail(400, `Say which postal codes the \"${change.zoneName}\" zone delivers to`)\n if (change.feeCents === undefined) return fail(400, `Say what delivery to \"${change.zoneName}\" costs (0 for free)`)\n if (zones.length >= LOCAL_DELIVERY_ZONES_MAX) return fail(409, `Local delivery holds at most ${LOCAL_DELIVERY_ZONES_MAX} zones`)\n zones.push({\n id: ids.zoneId,\n name: change.zoneName,\n kind: 'postcode',\n postcodes: change.postcodes,\n feeCents: change.feeCents,\n ...(change.minimumCents !== undefined ? { minimumCents: change.minimumCents } : {}),\n ...(change.freeOverCents !== undefined ? { freeOverCents: change.freeOverCents } : {}),\n })\n }\n after.zones = zones\n }\n const normalized = normalizeLocalDeliverySettings(after)\n const problems = localDeliveryProblems(normalized)\n if (problems.length) {\n return fail(400, `Local delivery can't be switched on yet: ${problems.join(' ')}`)\n }\n return {\n ok: true,\n write: sameSetting(before, normalized)\n ? null\n : { target: 'settings', field: 'localDelivery', value: normalized as Record<string, unknown> },\n summary: normalized.enabled\n ? `The store delivers locally to ${(normalized.zones ?? []).length} zone${(normalized.zones ?? []).length === 1 ? '' : 's'}.`\n : 'Local delivery is off.',\n warnings: normalized.enabled && !normalized.locationId ? ['No location is set for delivery orders to leave from.'] : [],\n }\n}\n\nconst TAX_MODE_WORDS: Record<string, string> = {\n manual: 'manual rates',\n stripe: 'automatic calculation',\n none: 'not collecting sales tax',\n}\n\nfunction applyTax(state: StoreSetupState, change: StoreTaxChange): StoreSetupApplied {\n const before = (state.settings['tax'] ?? {}) as TaxSettings\n const after: TaxSettings = { ...before }\n const settingRate = change.ratePct !== undefined\n if (change.mode) after.mode = change.mode\n else if (settingRate && after.mode === undefined) after.mode = 'manual'\n if (settingRate && after.mode !== 'manual') {\n return fail(\n 409,\n `This store uses ${TAX_MODE_WORDS[String(after.mode)] ?? 'another tax mode'}, so a manual rate would not apply. Ask to switch to manual rates as well.`,\n )\n }\n if (change.pricesIncludeTax !== undefined) after.pricesIncludeTax = change.pricesIncludeTax\n if (change.originCountry) {\n after.origin = {\n country: change.originCountry,\n ...(change.originState ? { state: change.originState } : {}),\n }\n }\n if (change.rateCountry) {\n const rates: TaxRate[] = [...(before.rates ?? [])]\n const index = rates.findIndex(\n (rate) =>\n String(rate.country ?? '').toUpperCase() === change.rateCountry &&\n String(rate.state ?? '').toUpperCase() === (change.rateState ?? ''),\n )\n if (change.removeRate) {\n if (index >= 0) rates.splice(index, 1)\n } else {\n const rate: TaxRate = {\n country: change.rateCountry,\n ...(change.rateState ? { state: change.rateState } : {}),\n pct: change.ratePct as number,\n ...(change.rateLabel ? { label: change.rateLabel } : index >= 0 && rates[index].label ? { label: rates[index].label } : {}),\n }\n if (index >= 0) rates[index] = rate\n else rates.push(rate)\n }\n after.rates = rates\n }\n // Manual mode with no origin refuses every sale (AGL-2145): never leave a store there.\n if (storefrontTaxMisconfiguration(after)) {\n return fail(400, 'Manual tax rates need the store’s address: say which country (and state) the store sells from.')\n }\n const warnings: string[] = []\n if (after.mode === 'manual' && !(after.rates ?? []).length) {\n warnings.push('No tax rate is set yet, so orders are charged no sales tax.')\n }\n if (after.mode === 'stripe') {\n warnings.push('Automatic tax is calculated per buyer location at checkout; the register cannot calculate it for in-person sales.')\n }\n const mode = TAX_MODE_WORDS[String(after.mode)] ?? 'undecided'\n const rateLine = settingRate\n ? ` ${change.ratePct}% for ${change.rateCountry}${change.rateState ? `-${change.rateState}` : ''}.`\n : ''\n return {\n ok: true,\n write: sameSetting(before, after) ? null : { target: 'settings', field: 'tax', value: after as Record<string, unknown> },\n summary: `Sales tax: ${mode}.${rateLine}`,\n warnings,\n }\n}\n\n/** The settings after a change, what to write, and what the person is told. */\nexport function applyStoreSetupChange(\n state: StoreSetupState,\n change: StoreSetupChange,\n ids: StoreSetupIds,\n): StoreSetupApplied {\n switch (change.section) {\n case 'shipping':\n return applyShipping(state, change, ids)\n case 'pickup':\n return applyPickup(state, change)\n case 'local-delivery':\n return applyLocalDelivery(state, change, ids)\n case 'tax':\n return applyTax(state, change)\n }\n}\n\n/** What a reader is told about a store's setup, for the writer's `read`. */\nexport function storeSetupFacts(settings: Readonly<Record<string, unknown>>): Record<string, unknown> {\n const shipping = (settings['shipping'] ?? {}) as ShippingSettings\n const tax = (settings['tax'] ?? {}) as TaxSettings\n const delivery = normalizeLocalDeliverySettings(settings['localDelivery'])\n return {\n shippingZones: (shipping.zones ?? []).length,\n shippingRates: (shipping.rates ?? []).length,\n localPickup: Boolean(shipping.localPickup),\n localDelivery: Boolean(delivery.enabled),\n taxMode: tax.mode ?? null,\n taxRates: (tax.rates ?? []).length,\n live: true,\n }\n}\n"],"names":["invalidOpeningHoursLines","COMMERCE_MAX_PRICE_USD","summarizeShippingCoverage","describeRateConditions","storefrontTaxMisconfiguration","LOCAL_DELIVERY_POSTCODES_MAX","LOCAL_DELIVERY_ZONES_MAX","PICKUP_HOURS_MAX","PICKUP_INSTRUCTIONS_MAX","localDeliveryProblems","normalizeLocalDeliverySettings","normalizePickupSettings","STORE_SETUP_RESOURCE","STORE_SETUP_SECTIONS","STORE_SHIPPING_AI_KINDS","STORE_SHIPPING_ACTIONS","STORE_TAX_MODES","STORE_SETUP_NAME_MAX","STORE_SETUP_COUNTRIES_MAX","STORE_SHIPPING_TIERS_MAX","STORE_SETUP_LOCATION_MAX","STORE_TAX_LABEL_MAX","STORE_SHIPPING_MAX_GRAMS","STORE_SETUP_MAX_MINUTES","COUNTRY","STATE","has","raw","key","undefined","text","max","problems","value","push","trimmed","trim","length","bool","number","min","Number","isFinite","minutes","Math","round","cents","list","Array","isArray","some","one","items","map","filter","Boolean","countryCode","toUpperCase","test","stateCode","hoursText","lines","split","join","bad","tiersOf","kind","entries","weight","tiers","entry","match","exec","upTo","NaN","amount","amountCents","sort","a","b","tier","index","KNOWN","shipping","pickup","tax","readShipping","action","includes","zoneName","countries","code","rateName","freeOverCents","section","readPickup","location","hours","instructions","readyWithinMinutes","enabled","readLocalDelivery","postcodes","feeCents","minimumCents","removeZone","daysAhead","country","windows","leadTimeMinutes","readTax","mode","change","pricesIncludeTax","originCountry","originState","rateCountry","rateState","ratePct","rateLabel","removeRate","touchesRate","said","Object","keys","readStoreSetupChange","content","ok","fail","status","error","sameSetting","every","left","right","lower","String","toLowerCase","usd","centsValue","toFixed","sameSet","matchStoreLocations","locations","phrase","wanted","byName","name","city","address","findLocation","found","id","rateSummary","rate","conditions","rateKindSummary","RATE_KEPT_FIELDS","applyShipping","state","ids","current","settings","zones","rates","zoneIndex","findIndex","zone","write","summary","warnings","kept","zoneId","shippingResult","rateIndex","existing","rateId","before","after","changed","coverage","unserved","shipsNowhere","target","field","applyPickup","localPickup","locationId","applyLocalDelivery","normalized","splice","TAX_MODE_WORDS","manual","stripe","none","applyTax","settingRate","origin","pct","label","rateLine","applyStoreSetupChange","storeSetupFacts","delivery","shippingZones","shippingRates","localDelivery","taxMode","taxRates","live"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,wBAAwB,QAAQ,wCAAuC;AAChF,SAASC,sBAAsB,QAAQ,gBAAY;AACnD,SACEC,yBAAyB,EACzBC,sBAAsB,QAKjB,yBAAq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AAS,CAAC,WAAW,EAAE1D,KAAK,CAAC,EAAEyF,UAAU;QACzC9B;IACF;AACF;AAEA,6EAA6E,GAC7E,OAAO,SAAS+B,sBACd1C,KAAsB,EACtB/C,MAAwB,EACxBgD,GAAkB;IAElB,OAAQhD,OAAOlB,OAAO;QACpB,KAAK;YACH,OAAOgE,cAAcC,OAAO/C,QAAQgD;QACtC,KAAK;YACH,OAAOyB,YAAY1B,OAAO/C;QAC5B,KAAK;YACH,OAAO4E,mBAAmB7B,OAAO/C,QAAQgD;QAC3C,KAAK;YACH,OAAOmC,SAASpC,OAAO/C;IAC3B;AACF;AAEA,0EAA0E,GAC1E,OAAO,SAAS0F,gBAAgBxC,QAA2C;QACvDA,oBACLA,eAGK/E,iBACAA,iBAGPE,WACEA;IATb,MAAMF,YAAY+E,qBAAAA,QAAQ,CAAC,WAAW,YAApBA,qBAAwB,CAAC;IAC3C,MAAM7E,OAAO6E,gBAAAA,QAAQ,CAAC,MAAM,YAAfA,gBAAmB,CAAC;IACjC,MAAMyC,WAAWjM,+BAA+BwJ,QAAQ,CAAC,gBAAgB;IACzE,OAAO;QACL0C,eAAe,EAACzH,kBAAAA,SAASgF,KAAK,YAAdhF,kBAAkB,EAAE,EAAE9C,MAAM;QAC5CwK,eAAe,EAAC1H,kBAAAA,SAASiF,KAAK,YAAdjF,kBAAkB,EAAE,EAAE9C,MAAM;QAC5CqJ,aAAanI,QAAQ4B,SAASuG,WAAW;QACzCoB,eAAevJ,QAAQoJ,SAASvG,OAAO;QACvC2G,OAAO,GAAE1H,YAAAA,IAAI0B,IAAI,YAAR1B,YAAY;QACrB2H,UAAU,EAAC3H,aAAAA,IAAI+E,KAAK,YAAT/E,aAAa,EAAE,EAAEhD,MAAM;QAClC4K,MAAM;IACR;AACF"}
|
|
@@ -47,6 +47,8 @@ import * as CommerceModel from '../model';
|
|
|
47
47
|
export interface CarrierShippingCart {
|
|
48
48
|
subtotalCents: number;
|
|
49
49
|
totalGrams: number;
|
|
50
|
+
/** The items subtotal in the shopper's currency, for a rate's own bound there (AGL-4255). */
|
|
51
|
+
shopperSubtotal?: CommerceModel.ShippingCart['shopperSubtotal'];
|
|
50
52
|
/** One parcel's dimensions, when the cart is one product that has them. */
|
|
51
53
|
parcel?: Omit<PluginShippingParcel, 'weightGrams'>;
|
|
52
54
|
}
|
|
@@ -29,10 +29,12 @@ import * as CommerceModel from "../model/index.js";
|
|
|
29
29
|
*/ export async function planCheckoutShippingWithCarriers(input) {
|
|
30
30
|
var _input_currency, _cart_parcel, _input_timeoutMs;
|
|
31
31
|
const { settings, cart } = input;
|
|
32
|
-
const tablePlan = ()=>CommerceModel.planCheckoutShipping(settings, {
|
|
32
|
+
const tablePlan = ()=>CommerceModel.planCheckoutShipping(settings, _extends({
|
|
33
33
|
subtotalCents: cart.subtotalCents,
|
|
34
34
|
totalGrams: cart.totalGrams
|
|
35
|
-
},
|
|
35
|
+
}, cart.shopperSubtotal ? {
|
|
36
|
+
shopperSubtotal: cart.shopperSubtotal
|
|
37
|
+
} : {}), input.destination.country);
|
|
36
38
|
if (!CommerceModel.hasCarrierRates(settings)) return tablePlan();
|
|
37
39
|
const quoter = pluginShippingRateQuoter();
|
|
38
40
|
if (!quoter) return tablePlan();
|
|
@@ -107,10 +109,12 @@ import * as CommerceModel from "../model/index.js";
|
|
|
107
109
|
// carrier rate replaced now that it has quotes.
|
|
108
110
|
const table = CommerceModel.resolveCheckoutShippingOptions(settings, [
|
|
109
111
|
country
|
|
110
|
-
], {
|
|
112
|
+
], _extends({
|
|
111
113
|
subtotalCents: cart.subtotalCents,
|
|
112
114
|
totalGrams: cart.totalGrams
|
|
113
|
-
}
|
|
115
|
+
}, cart.shopperSubtotal ? {
|
|
116
|
+
shopperSubtotal: cart.shopperSubtotal
|
|
117
|
+
} : {})).filter((option)=>!hidden.has(option.rateId));
|
|
114
118
|
// One option per name: two carrier rates quoting the same service keep the
|
|
115
119
|
// cheaper, so a shopper never sees the same service twice.
|
|
116
120
|
const byName = new Map();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/carrier-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\nimport {\n pluginShippingRateQuoter,\n quotePluginShippingRates,\n type PluginShippingParcel,\n} from '@aglyn/aglyn/plugin-manager/plugin-shipping-rates'\nimport * as CommerceModel from '../model'\n\n/**\n * LIVE CARRIER RATES AT CHECKOUT (AGL-3612): the `carrier` rate kind, priced\n * by asking core's `core.shipping-rate-quoter` — whichever plugin quotes\n * carriers — and never by importing it.\n *\n * ## Quoted before the session exists, on every door\n *\n * Stripe's hosted Checkout cannot change a session's shipping options once\n * the shopper types an address (\"The hosted page integration doesn't support\n * dynamically customizing shipping options\"), and the in-page form can only\n * by a server update after the fact — while this module's callers fix the\n * platform fee and the Connect transfer from the session's options at\n * creation. So the quote is taken BEFORE the session, against the\n * destination the shopper declares (country and postal code), and the\n * session is then restricted to that country exactly as a zone rate is\n * (AGL-1721). The same code serves cart checkout, buy-now and a draft\n * order's link, hosted and in-page, and the fee arithmetic downstream sees\n * ordinary options.\n *\n * ## The fallback is the merchant's own\n *\n * No quoter, a quoter not available for this site, or a quote that fails or\n * takes longer than {@link CommerceModel.CARRIER_QUOTE_TIMEOUT_MS}: the plan\n * is exactly the one {@link CommerceModel.planCheckoutShipping} makes from\n * the table, where a carrier rate offers nothing and its fallback rate is\n * offered. A store with no carrier rate never reaches the quoter at all, so\n * its sessions are byte-identical to the ones before this existed.\n */\n\nexport interface CarrierShippingCart {\n subtotalCents: number\n totalGrams: number\n /** One parcel's dimensions, when the cart is one product that has them. */\n parcel?: Omit<PluginShippingParcel, 'weightGrams'>\n}\n\nexport interface CarrierShippingDestination {\n country?: unknown\n postalCode?: unknown\n state?: unknown\n city?: unknown\n}\n\n/** A postal code a shopper declared, trimmed and bounded, or `undefined`. */\nexport function normalizeCheckoutPostalCode(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n const code = value.trim().toUpperCase().slice(0, 12)\n return /^[A-Z0-9][A-Z0-9 -]{1,11}$/.test(code) ? code : undefined\n}\n\nexport type CarrierShippingPlan = CommerceModel.CheckoutShippingPlan & {\n /** Set when the plan offers live quotes: the postal code they were priced for. */\n quotedPostalCode?: string\n /**\n * The destination's zone prices by carrier and the store can quote, but the\n * shopper has not said where in the country: ask for a postal code.\n */\n needsPostalCode?: boolean\n}\n\n/** What a shopper is told when a postal code is needed. */\nexport const CARRIER_POSTAL_CODE_MESSAGE = 'Enter the postal code you’re shipping to.'\n\n/**\n * The shipping half of a session for a store that may price by carrier.\n * See the module comment; `planCheckoutShipping` is the whole answer for any\n * store without a carrier rate.\n */\nexport async function planCheckoutShippingWithCarriers(input: {\n hostId: string\n settings: CommerceModel.ShippingSettings | undefined\n cart: CarrierShippingCart\n destination: CarrierShippingDestination\n currency?: string\n timeoutMs?: number\n}): Promise<CarrierShippingPlan> {\n const { settings, cart } = input\n const tablePlan = () =>\n CommerceModel.planCheckoutShipping(\n settings,\n { subtotalCents: cart.subtotalCents, totalGrams: cart.totalGrams },\n input.destination.country,\n )\n if (!CommerceModel.hasCarrierRates(settings)) return tablePlan()\n const quoter = pluginShippingRateQuoter()\n if (!quoter) return tablePlan()\n const available = await quoter.available(input.hostId).catch(() => false)\n if (!available) return tablePlan()\n\n const countries = CommerceModel.checkoutShippingCountries(settings)\n const country = CommerceModel.normalizeCheckoutShippingCountry(input.destination.country, countries)\n if (!country) {\n // Carrier prices differ by address by construction, so a session that\n // does not know the destination cannot be honest about any of them.\n return { countries, options: [], refusal: 'destination-required' }\n }\n const carrierRates = CommerceModel.carrierRatesFor(settings, country)\n if (!carrierRates.length) return tablePlan()\n const postalCode = normalizeCheckoutPostalCode(input.destination.postalCode)\n if (!postalCode) {\n return {\n countries: [country],\n options: [],\n refusal: 'destination-required',\n needsPostalCode: true,\n }\n }\n\n const currency = String(input.currency ?? 'usd').toLowerCase()\n const quotes = await quotePluginShippingRates(\n {\n hostId: input.hostId,\n to: {\n country,\n postalCode,\n ...(typeof input.destination.state === 'string' && input.destination.state.trim()\n ? { state: input.destination.state.trim().slice(0, 40) }\n : {}),\n ...(typeof input.destination.city === 'string' && input.destination.city.trim()\n ? { city: input.destination.city.trim().slice(0, 80) }\n : {}),\n },\n parcels: [{ weightGrams: Math.max(0, Math.round(cart.totalGrams)), ...(cart.parcel ?? {}) }],\n currency,\n valueCents: Math.max(0, Math.round(cart.subtotalCents)),\n },\n { timeoutMs: input.timeoutMs ?? CommerceModel.CARRIER_QUOTE_TIMEOUT_MS },\n )\n if (!quotes || !quotes.length) return tablePlan()\n\n const quoted: CommerceModel.ResolvedShippingRate[] = []\n const hidden = new Set<string>()\n for (const rate of carrierRates) {\n const services = (rate.carrier?.services ?? []).map((key) => key.toLowerCase())\n const offered = quotes.filter(\n (quote) => quote.currency === currency && (!services.length || services.includes(quote.serviceKey.toLowerCase())),\n )\n if (!offered.length) continue\n if (rate.carrier?.fallbackRateId) hidden.add(rate.carrier.fallbackRateId)\n for (const quote of offered) {\n quoted.push({\n rateId: CommerceModel.carrierOptionRateId(rate.id, quote.serviceKey),\n name: (quote.estimatedDays\n ? `${quote.label} (${quote.estimatedDays} business day${quote.estimatedDays === 1 ? '' : 's'})`\n : quote.label\n ).slice(0, 100),\n amountCents: CommerceModel.carrierOptionAmountCents(quote.amountCents, rate.carrier),\n })\n }\n }\n if (!quoted.length) return tablePlan()\n\n // The table's own options for this destination stay — a flat rate the\n // merchant offers beside carriers, local pickup — less any fallback a\n // carrier rate replaced now that it has quotes.\n const table = CommerceModel.resolveCheckoutShippingOptions(\n settings,\n [country],\n { subtotalCents: cart.subtotalCents, totalGrams: cart.totalGrams },\n ).filter((option) => !hidden.has(option.rateId))\n // One option per name: two carrier rates quoting the same service keep the\n // cheaper, so a shopper never sees the same service twice.\n const byName = new Map<string, CommerceModel.ResolvedShippingRate>()\n for (const option of [...table, ...quoted]) {\n const existing = byName.get(option.name)\n if (!existing || option.amountCents < existing.amountCents) byName.set(option.name, option)\n }\n const options = [...byName.values()]\n .sort((a, b) => a.amountCents - b.amountCents || a.rateId.localeCompare(b.rateId))\n .slice(0, CommerceModel.MAX_CHECKOUT_SHIPPING_OPTIONS)\n return { countries: [country], options, quotedPostalCode: postalCode }\n}\n"],"names":["pluginShippingRateQuoter","quotePluginShippingRates","CommerceModel","normalizeCheckoutPostalCode","value","undefined","code","trim","toUpperCase","slice","test","CARRIER_POSTAL_CODE_MESSAGE","planCheckoutShippingWithCarriers","input","cart","settings","tablePlan","planCheckoutShipping","subtotalCents","totalGrams","destination","country","hasCarrierRates","quoter","available","hostId","catch","countries","checkoutShippingCountries","normalizeCheckoutShippingCountry","options","refusal","carrierRates","carrierRatesFor","length","postalCode","needsPostalCode","currency","String","toLowerCase","quotes","to","state","city","parcels","weightGrams","Math","max","round","parcel","valueCents","timeoutMs","CARRIER_QUOTE_TIMEOUT_MS","quoted","hidden","Set","rate","services","carrier","map","key","offered","filter","quote","includes","serviceKey","fallbackRateId","add","push","rateId","carrierOptionRateId","id","name","estimatedDays","label","amountCents","carrierOptionAmountCents","table","resolveCheckoutShippingOptions","option","has","byName","Map","existing","get","set","values","sort","a","b","localeCompare","MAX_CHECKOUT_SHIPPING_OPTIONS","quotedPostalCode"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,wBAAwB,QAEnB,oDAAmD;AAC1D,YAAYC,mBAAmB,oBAAU;AA6CzC,2EAA2E,GAC3E,OAAO,SAASC,4BAA4BC,KAAc;IACxD,IAAI,OAAOA,UAA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AGQ,SAASR,WAAW,EAAEM,OAAOI,GAAG,CAACN,OAAOP,IAAI,EAAEO;IACtF;IACA,MAAMjD,UAAU;WAAImD,OAAOK,MAAM;KAAG,CACjCC,IAAI,CAAC,CAACC,GAAGC,IAAMD,EAAEb,WAAW,GAAGc,EAAEd,WAAW,IAAIa,EAAEnB,MAAM,CAACqB,aAAa,CAACD,EAAEpB,MAAM,GAC/E5D,KAAK,CAAC,GAAGP,cAAcyF,6BAA6B;IACvD,OAAO;QAAEhE,WAAW;YAACN;SAAQ;QAAES;QAAS8D,kBAAkBzD;IAAW;AACvE"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/carrier-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\nimport {\n pluginShippingRateQuoter,\n quotePluginShippingRates,\n type PluginShippingParcel,\n} from '@aglyn/aglyn/plugin-manager/plugin-shipping-rates'\nimport * as CommerceModel from '../model'\n\n/**\n * LIVE CARRIER RATES AT CHECKOUT (AGL-3612): the `carrier` rate kind, priced\n * by asking core's `core.shipping-rate-quoter` — whichever plugin quotes\n * carriers — and never by importing it.\n *\n * ## Quoted before the session exists, on every door\n *\n * Stripe's hosted Checkout cannot change a session's shipping options once\n * the shopper types an address (\"The hosted page integration doesn't support\n * dynamically customizing shipping options\"), and the in-page form can only\n * by a server update after the fact — while this module's callers fix the\n * platform fee and the Connect transfer from the session's options at\n * creation. So the quote is taken BEFORE the session, against the\n * destination the shopper declares (country and postal code), and the\n * session is then restricted to that country exactly as a zone rate is\n * (AGL-1721). The same code serves cart checkout, buy-now and a draft\n * order's link, hosted and in-page, and the fee arithmetic downstream sees\n * ordinary options.\n *\n * ## The fallback is the merchant's own\n *\n * No quoter, a quoter not available for this site, or a quote that fails or\n * takes longer than {@link CommerceModel.CARRIER_QUOTE_TIMEOUT_MS}: the plan\n * is exactly the one {@link CommerceModel.planCheckoutShipping} makes from\n * the table, where a carrier rate offers nothing and its fallback rate is\n * offered. A store with no carrier rate never reaches the quoter at all, so\n * its sessions are byte-identical to the ones before this existed.\n */\n\nexport interface CarrierShippingCart {\n subtotalCents: number\n totalGrams: number\n /** The items subtotal in the shopper's currency, for a rate's own bound there (AGL-4255). */\n shopperSubtotal?: CommerceModel.ShippingCart['shopperSubtotal']\n /** One parcel's dimensions, when the cart is one product that has them. */\n parcel?: Omit<PluginShippingParcel, 'weightGrams'>\n}\n\nexport interface CarrierShippingDestination {\n country?: unknown\n postalCode?: unknown\n state?: unknown\n city?: unknown\n}\n\n/** A postal code a shopper declared, trimmed and bounded, or `undefined`. */\nexport function normalizeCheckoutPostalCode(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n const code = value.trim().toUpperCase().slice(0, 12)\n return /^[A-Z0-9][A-Z0-9 -]{1,11}$/.test(code) ? code : undefined\n}\n\nexport type CarrierShippingPlan = CommerceModel.CheckoutShippingPlan & {\n /** Set when the plan offers live quotes: the postal code they were priced for. */\n quotedPostalCode?: string\n /**\n * The destination's zone prices by carrier and the store can quote, but the\n * shopper has not said where in the country: ask for a postal code.\n */\n needsPostalCode?: boolean\n}\n\n/** What a shopper is told when a postal code is needed. */\nexport const CARRIER_POSTAL_CODE_MESSAGE = 'Enter the postal code you’re shipping to.'\n\n/**\n * The shipping half of a session for a store that may price by carrier.\n * See the module comment; `planCheckoutShipping` is the whole answer for any\n * store without a carrier rate.\n */\nexport async function planCheckoutShippingWithCarriers(input: {\n hostId: string\n settings: CommerceModel.ShippingSettings | undefined\n cart: CarrierShippingCart\n destination: CarrierShippingDestination\n currency?: string\n timeoutMs?: number\n}): Promise<CarrierShippingPlan> {\n const { settings, cart } = input\n const tablePlan = () =>\n CommerceModel.planCheckoutShipping(\n settings,\n {\n subtotalCents: cart.subtotalCents,\n totalGrams: cart.totalGrams,\n ...(cart.shopperSubtotal ? { shopperSubtotal: cart.shopperSubtotal } : {}),\n },\n input.destination.country,\n )\n if (!CommerceModel.hasCarrierRates(settings)) return tablePlan()\n const quoter = pluginShippingRateQuoter()\n if (!quoter) return tablePlan()\n const available = await quoter.available(input.hostId).catch(() => false)\n if (!available) return tablePlan()\n\n const countries = CommerceModel.checkoutShippingCountries(settings)\n const country = CommerceModel.normalizeCheckoutShippingCountry(input.destination.country, countries)\n if (!country) {\n // Carrier prices differ by address by construction, so a session that\n // does not know the destination cannot be honest about any of them.\n return { countries, options: [], refusal: 'destination-required' }\n }\n const carrierRates = CommerceModel.carrierRatesFor(settings, country)\n if (!carrierRates.length) return tablePlan()\n const postalCode = normalizeCheckoutPostalCode(input.destination.postalCode)\n if (!postalCode) {\n return {\n countries: [country],\n options: [],\n refusal: 'destination-required',\n needsPostalCode: true,\n }\n }\n\n const currency = String(input.currency ?? 'usd').toLowerCase()\n const quotes = await quotePluginShippingRates(\n {\n hostId: input.hostId,\n to: {\n country,\n postalCode,\n ...(typeof input.destination.state === 'string' && input.destination.state.trim()\n ? { state: input.destination.state.trim().slice(0, 40) }\n : {}),\n ...(typeof input.destination.city === 'string' && input.destination.city.trim()\n ? { city: input.destination.city.trim().slice(0, 80) }\n : {}),\n },\n parcels: [{ weightGrams: Math.max(0, Math.round(cart.totalGrams)), ...(cart.parcel ?? {}) }],\n currency,\n valueCents: Math.max(0, Math.round(cart.subtotalCents)),\n },\n { timeoutMs: input.timeoutMs ?? CommerceModel.CARRIER_QUOTE_TIMEOUT_MS },\n )\n if (!quotes || !quotes.length) return tablePlan()\n\n const quoted: CommerceModel.ResolvedShippingRate[] = []\n const hidden = new Set<string>()\n for (const rate of carrierRates) {\n const services = (rate.carrier?.services ?? []).map((key) => key.toLowerCase())\n const offered = quotes.filter(\n (quote) => quote.currency === currency && (!services.length || services.includes(quote.serviceKey.toLowerCase())),\n )\n if (!offered.length) continue\n if (rate.carrier?.fallbackRateId) hidden.add(rate.carrier.fallbackRateId)\n for (const quote of offered) {\n quoted.push({\n rateId: CommerceModel.carrierOptionRateId(rate.id, quote.serviceKey),\n name: (quote.estimatedDays\n ? `${quote.label} (${quote.estimatedDays} business day${quote.estimatedDays === 1 ? '' : 's'})`\n : quote.label\n ).slice(0, 100),\n amountCents: CommerceModel.carrierOptionAmountCents(quote.amountCents, rate.carrier),\n })\n }\n }\n if (!quoted.length) return tablePlan()\n\n // The table's own options for this destination stay — a flat rate the\n // merchant offers beside carriers, local pickup — less any fallback a\n // carrier rate replaced now that it has quotes.\n const table = CommerceModel.resolveCheckoutShippingOptions(\n settings,\n [country],\n {\n subtotalCents: cart.subtotalCents,\n totalGrams: cart.totalGrams,\n ...(cart.shopperSubtotal ? { shopperSubtotal: cart.shopperSubtotal } : {}),\n },\n ).filter((option) => !hidden.has(option.rateId))\n // One option per name: two carrier rates quoting the same service keep the\n // cheaper, so a shopper never sees the same service twice.\n const byName = new Map<string, CommerceModel.ResolvedShippingRate>()\n for (const option of [...table, ...quoted]) {\n const existing = byName.get(option.name)\n if (!existing || option.amountCents < existing.amountCents) byName.set(option.name, option)\n }\n const options = [...byName.values()]\n .sort((a, b) => a.amountCents - b.amountCents || a.rateId.localeCompare(b.rateId))\n .slice(0, CommerceModel.MAX_CHECKOUT_SHIPPING_OPTIONS)\n return { countries: [country], options, quotedPostalCode: postalCode }\n}\n"],"names":["pluginShippingRateQuoter","quotePluginShippingRates","CommerceModel","normalizeCheckoutPostalCode","value","undefined","code","trim","toUpperCase","slice","test","CARRIER_POSTAL_CODE_MESSAGE","planCheckoutShippingWithCarriers","input","cart","settings","tablePlan","planCheckoutShipping","subtotalCents","totalGrams","shopperSubtotal","destination","country","hasCarrierRates","quoter","available","hostId","catch","countries","checkoutShippingCountries","normalizeCheckoutShippingCountry","options","refusal","carrierRates","carrierRatesFor","length","postalCode","needsPostalCode","currency","String","toLowerCase","quotes","to","state","city","parcels","weightGrams","Math","max","round","parcel","valueCents","timeoutMs","CARRIER_QUOTE_TIMEOUT_MS","quoted","hidden","Set","rate","services","carrier","map","key","offered","filter","quote","includes","serviceKey","fallbackRateId","add","push","rateId","carrierOptionRateId","id","name","estimatedDays","label","amountCents","carrierOptionAmountCents","table","resolveCheckoutShippingOptions","option","has","byName","Map","existing","get","set","values","sort","a","b","localeCompare","MAX_CHECKOUT_SHIPPING_OPTIONS","quotedPostalCode"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,wBAAwB,EACxBC,wBAAwB,QAEnB,oDAAmD;AAC1D,YAAYC,mBAAmB,oBAAU;AA+CzC,2EAA2E,GAC3E,OAAO,SAASC,4BAA4BC,KAAc;IACxD,IAAI,OAAOA,UAAU,UAAU,OAAOC;IACtC,MAAMC,OAAOF,MAAMG,IAAI,GAAGC,WAAW,GAAGC,KAAK,CAAC,GAAG;IACjD,OAAO,6BAA6BC,IAAI,CAACJ,QAAQA,OAAOD;AAC1D;AAYA,yDAAyD,GACzD,OAAO,MAAMM,8BAA8B,4CAA2C;AAEtF;;;;CAIC,GACD,OAAO,eAAeC,iCAAiCC,KAOtD;QAqCyBA,iBAcmDC,cAI5DD;IAtDf,MAAM,EAAEE,QAAQ,EAAED,IAAI,EAAE,GAAGD;IAC3B,MAAMG,YAAY,IAChBd,cAAce,oBAAoB,CAChCF,UACA;YACEG,eAAeJ,KAAKI,aAAa;YACjCC,YAAYL,KAAKK,UAAU;WACvBL,KAAKM,eAAe,GAAG;YAAEA,iBAAiBN,KAAKM,eAAe;QAAC,IAAI,CAAC,IAE1EP,MAAMQ,WAAW,CAACC,OAAO;IAE7B,IAAI,CAACpB,cAAcqB,eAAe,CAACR,WAAW,OAAOC;IACrD,MAAMQ,SAASxB;IACf,IAAI,CAACwB,QAAQ,OAAOR;IACpB,MA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AC7FV,MAAMW,KAAK,AAAD,EACZlE,KAAK,CAAC,GAAG;gBACXmE,aAAa1E,cAAc2E,wBAAwB,CAACb,MAAMY,WAAW,EAAEnB,KAAKE,OAAO;YACrF;QACF;IACF;IACA,IAAI,CAACL,OAAOnB,MAAM,EAAE,OAAOnB;IAE3B,sEAAsE;IACtE,sEAAsE;IACtE,gDAAgD;IAChD,MAAM8D,QAAQ5E,cAAc6E,8BAA8B,CACxDhE,UACA;QAACO;KAAQ,EACT;QACEJ,eAAeJ,KAAKI,aAAa;QACjCC,YAAYL,KAAKK,UAAU;OACvBL,KAAKM,eAAe,GAAG;QAAEA,iBAAiBN,KAAKM,eAAe;IAAC,IAAI,CAAC,IAE1E2C,MAAM,CAAC,CAACiB,SAAW,CAACzB,OAAO0B,GAAG,CAACD,OAAOV,MAAM;IAC9C,2EAA2E;IAC3E,2DAA2D;IAC3D,MAAMY,SAAS,IAAIC;IACnB,KAAK,MAAMH,UAAU;WAAIF;WAAUxB;KAAO,CAAE;QAC1C,MAAM8B,WAAWF,OAAOG,GAAG,CAACL,OAAOP,IAAI;QACvC,IAAI,CAACW,YAAYJ,OAAOJ,WAAW,GAAGQ,SAASR,WAAW,EAAEM,OAAOI,GAAG,CAACN,OAAOP,IAAI,EAAEO;IACtF;IACA,MAAMjD,UAAU;WAAImD,OAAOK,MAAM;KAAG,CACjCC,IAAI,CAAC,CAACC,GAAGC,IAAMD,EAAEb,WAAW,GAAGc,EAAEd,WAAW,IAAIa,EAAEnB,MAAM,CAACqB,aAAa,CAACD,EAAEpB,MAAM,GAC/E7D,KAAK,CAAC,GAAGP,cAAc0F,6BAA6B;IACvD,OAAO;QAAEhE,WAAW;YAACN;SAAQ;QAAES;QAAS8D,kBAAkBzD;IAAW;AACvE"}
|
|
@@ -491,10 +491,15 @@ import { boundedCreditCents, checkoutCreditProviderForCode, encodeCheckoutCredit
|
|
|
491
491
|
} : hasPhysicalLine ? await planCheckoutShippingWithCarriers({
|
|
492
492
|
hostId,
|
|
493
493
|
settings: storeSettings.get('shipping'),
|
|
494
|
-
cart: {
|
|
494
|
+
cart: _extends({
|
|
495
495
|
subtotalCents: itemsCents,
|
|
496
496
|
totalGrams
|
|
497
|
-
},
|
|
497
|
+
}, checkoutCurrency ? {
|
|
498
|
+
shopperSubtotal: {
|
|
499
|
+
code: checkoutCurrency.code,
|
|
500
|
+
minor: itemsChargeMinor
|
|
501
|
+
}
|
|
502
|
+
} : {}),
|
|
498
503
|
destination: {
|
|
499
504
|
country: body.shippingCountry,
|
|
500
505
|
postalCode: body.shippingPostalCode
|