@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-commerce",
3
- "version": "1.32.0",
3
+ "version": "1.33.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,18 +25,18 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.32.0",
29
- "@aglyn/shared-data-mdi": "1.32.0",
30
- "@aglyn/shared-ui-jsx": "1.32.0",
31
- "@aglyn/shared-ui-next": "1.32.0",
32
- "@aglyn/shared-ui-snackstack": "1.32.0",
33
- "@aglyn/shared-util-email": "1.32.0",
34
- "@aglyn/shared-util-http": "1.32.0",
35
- "@aglyn/shared-util-timestamp": "1.32.0",
36
- "@aglyn/shared-util-tools": "1.32.0",
37
- "@aglyn/tenant-data-admin": "1.32.0",
38
- "@aglyn/tenant-feature-instance": "1.32.0",
39
- "@aglyn/tenant-runtime": "1.32.0",
28
+ "@aglyn/aglyn": "1.33.0",
29
+ "@aglyn/shared-data-mdi": "1.33.0",
30
+ "@aglyn/shared-ui-jsx": "1.33.0",
31
+ "@aglyn/shared-ui-next": "1.33.0",
32
+ "@aglyn/shared-ui-snackstack": "1.33.0",
33
+ "@aglyn/shared-util-email": "1.33.0",
34
+ "@aglyn/shared-util-http": "1.33.0",
35
+ "@aglyn/shared-util-timestamp": "1.33.0",
36
+ "@aglyn/shared-util-tools": "1.33.0",
37
+ "@aglyn/tenant-data-admin": "1.33.0",
38
+ "@aglyn/tenant-feature-instance": "1.33.0",
39
+ "@aglyn/tenant-runtime": "1.33.0",
40
40
  "@stripe/react-stripe-js": "^7.0.1",
41
41
  "@stripe/stripe-js": "^10.2.1",
42
42
  "@swc/helpers": "0.5.24",
@@ -70,7 +70,7 @@ function zoneCountryLabel(code) {
70
70
  * that store charges no shipping and refuses nobody — and warning them would
71
71
  * nag every store selling downloads.
72
72
  */ export function ShippingSettingsCard(props) {
73
- var _ref, _current_zones, _current_rates, _ref1;
73
+ var _ref, _current_zones, _current_rates, _ref1, _current_rates1;
74
74
  var _current_zones1;
75
75
  const { hostId } = props;
76
76
  const firestore = useFirestore();
@@ -153,18 +153,27 @@ function zoneCountryLabel(code) {
153
153
  });
154
154
  };
155
155
  const updateRate = (index, patch)=>{
156
- var _current_rates, _ref;
157
- var _current_zones_, _current_zones;
156
+ var _current_rates;
158
157
  const rates = [
159
158
  ...(_current_rates = current.rates) != null ? _current_rates : []
160
159
  ];
161
160
  if (patch === null) rates.splice(index, 1);
162
- else rates[index] = _extends({
163
- id: Aglyn.createResourceUid(),
164
- zoneId: (_ref = (_current_zones = current.zones) == null ? void 0 : (_current_zones_ = _current_zones[0]) == null ? void 0 : _current_zones_.id) != null ? _ref : '',
165
- name: '',
166
- kind: 'flat'
167
- }, rates[index], patch);
161
+ else {
162
+ var _ref;
163
+ var _current_zones_, _current_zones;
164
+ const next = _extends({
165
+ id: Aglyn.createResourceUid(),
166
+ zoneId: (_ref = (_current_zones = current.zones) == null ? void 0 : (_current_zones_ = _current_zones[0]) == null ? void 0 : _current_zones_.id) != null ? _ref : '',
167
+ name: '',
168
+ kind: 'flat'
169
+ }, rates[index], patch);
170
+ // A field emptied on screen is taken off the rate, not stored as
171
+ // `undefined`: this Firestore client rejects the whole save on one.
172
+ for (const key of Object.keys(next)){
173
+ if (next[key] === undefined) delete next[key];
174
+ }
175
+ rates[index] = next;
176
+ }
168
177
  update({
169
178
  rates
170
179
  });
@@ -585,6 +594,12 @@ function zoneCountryLabel(code) {
585
594
  children: 'Add tier'
586
595
  })
587
596
  ]
597
+ }),
598
+ rate.kind === 'carrier' ? null : /*#__PURE__*/ _jsx(RateConditionFields, {
599
+ rate: rate,
600
+ currencies: otherCurrencies,
601
+ onChange: (patch)=>updateRate(index, patch),
602
+ onCurrencyChange: (field, code, raw)=>updateRateCurrency(index, field, code, raw)
588
603
  })
589
604
  ]
590
605
  }, rate.id);
@@ -651,6 +666,11 @@ function zoneCountryLabel(code) {
651
666
  color: "text.secondary",
652
667
  children: words.asks
653
668
  }) : null,
669
+ ((_current_rates1 = current.rates) != null ? _current_rates1 : []).some((rate)=>rate.kind !== 'carrier' && CommerceModel.rateHasConditions(rate)) ? /*#__PURE__*/ _jsx(Typography, {
670
+ variant: "caption",
671
+ color: "text.secondary",
672
+ children: 'Rates with conditions are offered only to orders that meet them, so the destinations above are covered for some orders. An order that meets no rate of its zone is told shipping is not available.'
673
+ }) : null,
654
674
  /*#__PURE__*/ _jsx(Button, {
655
675
  variant: "contained",
656
676
  color: "primary",
@@ -793,6 +813,214 @@ export default ShippingSettingsCard;
793
813
  ]
794
814
  });
795
815
  }
816
+ /** Every condition field, cleared together when the merchant removes them (AGL-4255). */ const NO_CONDITIONS = {
817
+ minSubtotalCents: undefined,
818
+ maxSubtotalCents: undefined,
819
+ minSubtotalByCurrency: undefined,
820
+ maxSubtotalByCurrency: undefined,
821
+ minGrams: undefined,
822
+ maxGrams: undefined
823
+ };
824
+ /**
825
+ * A rate's conditions (AGL-4255), as Shopify sets them: offered only to
826
+ * carts whose order price, or whose item weight, falls between a minimum and
827
+ * a maximum. One basis at a time; switching clears the other's figures.
828
+ */ function RateConditionFields(props) {
829
+ var _rate_minGrams, _rate_maxGrams;
830
+ const { rate, currencies, onChange, onCurrencyChange } = props;
831
+ const byWeight = rate.minGrams != null || rate.maxGrams != null;
832
+ const has = CommerceModel.rateHasConditions(rate);
833
+ const [adding, setAdding] = useState(null);
834
+ const basis = has ? byWeight ? 'weight' : 'price' : adding != null ? adding : 'price';
835
+ const usd = (cents)=>cents == null ? '' : String(cents / 100);
836
+ const cents = (raw)=>raw.trim() === '' || !Number.isFinite(Number(raw)) ? undefined : Math.max(0, Math.round(Number(raw) * 100));
837
+ const grams = (raw)=>raw.trim() === '' || !Number.isFinite(Number(raw)) ? undefined : Math.max(0, Math.round(Number(raw)));
838
+ // Emptying every figure keeps the block open while the merchant types.
839
+ const keep = (patch)=>{
840
+ setAdding(basis);
841
+ onChange(patch);
842
+ };
843
+ if (!has && adding === null) {
844
+ return /*#__PURE__*/ _jsx(Button, {
845
+ size: "small",
846
+ sx: {
847
+ alignSelf: 'flex-start'
848
+ },
849
+ onClick: ()=>setAdding('price'),
850
+ children: 'Add conditions'
851
+ });
852
+ }
853
+ const minMax = rate.minSubtotalCents != null && rate.maxSubtotalCents != null && rate.minSubtotalCents > rate.maxSubtotalCents ? 'The minimum is above the maximum, so no order gets this rate.' : rate.minGrams != null && rate.maxGrams != null && rate.minGrams > rate.maxGrams ? 'The minimum is above the maximum, so no order gets this rate.' : '';
854
+ return /*#__PURE__*/ _jsxs(Stack, {
855
+ spacing: 1,
856
+ sx: {
857
+ pl: 2
858
+ },
859
+ children: [
860
+ /*#__PURE__*/ _jsxs(Stack, {
861
+ direction: "row",
862
+ spacing: 1,
863
+ sx: {
864
+ alignItems: 'center'
865
+ },
866
+ children: [
867
+ /*#__PURE__*/ _jsxs(TextField, {
868
+ label: "Conditions",
869
+ value: basis,
870
+ onChange: (event)=>{
871
+ const next = event.target.value;
872
+ setAdding(next);
873
+ if (next !== basis) onChange(NO_CONDITIONS);
874
+ },
875
+ size: "small",
876
+ select: true,
877
+ sx: {
878
+ width: 220
879
+ },
880
+ children: [
881
+ /*#__PURE__*/ _jsx(MenuItem, {
882
+ value: "price",
883
+ children: 'Based on order price'
884
+ }),
885
+ /*#__PURE__*/ _jsx(MenuItem, {
886
+ value: "weight",
887
+ children: 'Based on item weight'
888
+ })
889
+ ]
890
+ }),
891
+ /*#__PURE__*/ _jsx(Button, {
892
+ size: "small",
893
+ color: "error",
894
+ onClick: ()=>{
895
+ setAdding(null);
896
+ onChange(NO_CONDITIONS);
897
+ },
898
+ children: 'Remove conditions'
899
+ })
900
+ ]
901
+ }),
902
+ basis === 'price' ? /*#__PURE__*/ _jsxs(Stack, {
903
+ direction: "row",
904
+ spacing: 1,
905
+ children: [
906
+ /*#__PURE__*/ _jsx(TextField, {
907
+ label: "Minimum order price ($)",
908
+ value: usd(rate.minSubtotalCents),
909
+ onChange: (event)=>keep({
910
+ minSubtotalCents: cents(event.target.value)
911
+ }),
912
+ size: "small",
913
+ sx: {
914
+ width: 200
915
+ },
916
+ slotProps: {
917
+ htmlInput: {
918
+ inputMode: 'decimal'
919
+ }
920
+ }
921
+ }),
922
+ /*#__PURE__*/ _jsx(TextField, {
923
+ label: "Maximum order price ($)",
924
+ value: usd(rate.maxSubtotalCents),
925
+ onChange: (event)=>keep({
926
+ maxSubtotalCents: cents(event.target.value)
927
+ }),
928
+ size: "small",
929
+ sx: {
930
+ width: 200
931
+ },
932
+ slotProps: {
933
+ htmlInput: {
934
+ inputMode: 'decimal'
935
+ }
936
+ }
937
+ })
938
+ ]
939
+ }) : /*#__PURE__*/ _jsxs(Stack, {
940
+ direction: "row",
941
+ spacing: 1,
942
+ children: [
943
+ /*#__PURE__*/ _jsx(TextField, {
944
+ label: "Minimum weight (g)",
945
+ value: (_rate_minGrams = rate.minGrams) != null ? _rate_minGrams : '',
946
+ onChange: (event)=>keep({
947
+ minGrams: grams(event.target.value)
948
+ }),
949
+ size: "small",
950
+ sx: {
951
+ width: 200
952
+ },
953
+ slotProps: {
954
+ htmlInput: {
955
+ inputMode: 'numeric'
956
+ }
957
+ }
958
+ }),
959
+ /*#__PURE__*/ _jsx(TextField, {
960
+ label: "Maximum weight (g)",
961
+ value: (_rate_maxGrams = rate.maxGrams) != null ? _rate_maxGrams : '',
962
+ onChange: (event)=>keep({
963
+ maxGrams: grams(event.target.value)
964
+ }),
965
+ size: "small",
966
+ sx: {
967
+ width: 200
968
+ },
969
+ slotProps: {
970
+ htmlInput: {
971
+ inputMode: 'numeric'
972
+ }
973
+ }
974
+ })
975
+ ]
976
+ }),
977
+ basis === 'price' && currencies.length ? currencies.map((entry)=>{
978
+ var _rate_minSubtotalByCurrency, _rate_maxSubtotalByCurrency;
979
+ return /*#__PURE__*/ _jsxs(Stack, {
980
+ direction: "row",
981
+ spacing: 1,
982
+ children: [
983
+ /*#__PURE__*/ _jsx(TextField, {
984
+ label: `Minimum (${entry.code})`,
985
+ defaultValue: CommerceModel.minorToInput((_rate_minSubtotalByCurrency = rate.minSubtotalByCurrency) == null ? void 0 : _rate_minSubtotalByCurrency[entry.code], entry.code),
986
+ placeholder: "Converted",
987
+ onBlur: (event)=>onCurrencyChange('minSubtotalByCurrency', entry.code, event.target.value),
988
+ size: "small",
989
+ sx: {
990
+ width: 200
991
+ },
992
+ slotProps: {
993
+ htmlInput: {
994
+ inputMode: 'decimal'
995
+ }
996
+ }
997
+ }, `${rate.id}-min-${entry.code}`),
998
+ /*#__PURE__*/ _jsx(TextField, {
999
+ label: `Maximum (${entry.code})`,
1000
+ defaultValue: CommerceModel.minorToInput((_rate_maxSubtotalByCurrency = rate.maxSubtotalByCurrency) == null ? void 0 : _rate_maxSubtotalByCurrency[entry.code], entry.code),
1001
+ placeholder: "Converted",
1002
+ onBlur: (event)=>onCurrencyChange('maxSubtotalByCurrency', entry.code, event.target.value),
1003
+ size: "small",
1004
+ sx: {
1005
+ width: 200
1006
+ },
1007
+ slotProps: {
1008
+ htmlInput: {
1009
+ inputMode: 'decimal'
1010
+ }
1011
+ }
1012
+ }, `${rate.id}-max-${entry.code}`)
1013
+ ]
1014
+ }, entry.code);
1015
+ }) : null,
1016
+ /*#__PURE__*/ _jsx(Typography, {
1017
+ variant: "caption",
1018
+ color: minMax ? 'error' : 'text.secondary',
1019
+ children: minMax || (basis === 'price' ? 'Checkout offers this rate only when the order, before discounts, is within these amounts. Leave one blank for no limit.' : 'Checkout offers this rate only when the items weigh within these amounts. Leave one blank for no limit.')
1020
+ })
1021
+ ]
1022
+ });
1023
+ }
796
1024
  /**
797
1025
  * A flat or free-over rate in each other currency the store sells in
798
1026
  * (AGL-4248). A blank field is converted at the day's rate, and shows the
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/shipping-settings-card.component.tsx"],"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'use client'\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport * as CommerceModel from '../../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n AlertTitle,\n Autocomplete,\n Button,\n Divider,\n FormControlLabel,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { doc, setDoc } from 'firebase/firestore'\nimport { useCallback, useEffect, useState } from 'react'\nimport { useFirestore, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n useFirestoreDoc,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n heldSaveLabel,\n isSeedChecking,\n seedCheckingText,\n useHeldSave,\n useSeedEdits,\n} from '@aglyn/tenant-feature-instance/hooks/use-seed-edits'\nimport { useCurrencySetup } from './use-currency-setup'\n\nexport interface ShippingSettingsCardProps {\n hostId: string\n}\n\n/** Every country checkout can ship to, plus rest of world, for a zone. */\nconst ZONE_COUNTRY_OPTIONS: string[] = [\n '*',\n ...[...CommerceModel.STRIPE_SHIPPING_COUNTRY_CODES].sort((a, b) =>\n zoneCountryLabel(a).localeCompare(zoneCountryLabel(b)),\n ),\n]\n\nfunction zoneCountryLabel(code: string): string {\n if (code === '*') return 'Rest of world'\n return CommerceModel.CHECKOUT_SHIPPING_COUNTRY_NAMES[code] ?? code\n}\n\n/**\n * Shipping settings (AGL-288): zones (countries, '*' = rest of world)\n * and rates (flat / free-over / subtotal or weight tiers), stored on\n * `hosts/{hostId}/settings/store` under `shipping`. Cart checkout (AGL-1707)\n * and buy-now (AGL-1720) both read this document and declare the rates as\n * Stripe `shipping_options` (`planCheckoutShipping`) — until those landed\n * nothing read it, and everything saved here was charged to nobody. Buy-now\n * resolves only for physical one-time sales; draft orders and POS still\n * resolve no shipping at all.\n *\n * WHAT A ZONE LAYOUT COSTS THE SHOPPER (AGL-1721). A session's rates are\n * charged as picked and never re-checked against the address, so the checkout\n * can only offer rates that hold for every country it will ship to. Saving\n * zones whose rates DIFFER therefore makes the storefront ask the shopper\n * where the parcel is going before it can price one, and a destination no\n * zone covers is refused outright rather than shipped for free. One zone, or\n * one '*' zone, needs neither: the shopper is asked nothing.\n *\n * AND THE MERCHANT HAS TO BE ABLE TO SEE IT (AGL-1791). Both consequences\n * were invisible here: a merchant saved zones and the checkouts they refused\n * were refused with nothing on this page saying so, which is a support ticket\n * from someone who did nothing wrong. The coverage block reads\n * `summarizeShippingCoverage` off the same `current` object the save writes,\n * so it moves as the form is typed rather than after a round trip.\n *\n * It escalates to a warning ONLY for a merchant who priced some destinations\n * and not others. A merchant whose rates reach nowhere is not misconfigured —\n * that store charges no shipping and refuses nobody — and warning them would\n * nag every store selling downloads.\n */\nexport function ShippingSettingsCard(props: ShippingSettingsCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const {\n data: store,\n status: storeStatus,\n /**\n * The settings doc this form is seeded from is unconfirmed by the server\n * (AGL-1358). `current` is `draft ?? store?.shipping ?? {}` and the save\n * writes `{shipping: current}`, so `merge: true` protects the doc's other\n * maps and nothing inside this one — `zones` and `rates` are arrays, and\n * a merge replaces an array wholesale. Against a cached read, adding one\n * rate restores that snapshot's whole price table, and a zone that\n * disappears with it means `resolveShippingRates` matches nothing, which\n * is a checkout offering no shipping option at all.\n */\n fromCache: storeFromCache,\n listen: storeListen,\n } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId, 'settings', 'store'),\n [firestore, hostId],\n )\n // What was typed, kept as edits over the stored settings, and Save held\n // until the server has confirmed them (AGL-4047).\n const form = useSeedEdits<CommerceModel.ShippingSettings>(store?.shipping ?? {})\n const current = form.values\n const checking = isSeedChecking({ fromCache: storeFromCache, unreadable: storeStatus === 'error' })\n /*\n * Live carrier rates (AGL-3612) are offered only where a plugin quotes\n * carriers for this site — the server asks core's quoter seam. A rate\n * already saved as `carrier` stays editable either way, so a merchant can\n * still see and change what checkout falls back to.\n */\n const { data: user } = useUser()\n const [carrier, setCarrier] = useState<{\n available: boolean\n services: Array<{ serviceKey: string; label: string }>\n }>({ available: false, services: [] })\n useEffect(() => {\n let live = true\n authorizedFetch(user, `/api/commerce/shipping/carrier-rates?hostId=${encodeURIComponent(hostId)}`)\n .then((response) => (response.ok ? response.json() : null))\n .then((answer) => {\n if (live && answer) setCarrier({ available: Boolean(answer.available), services: answer.services ?? [] })\n })\n .catch(() => undefined)\n return () => {\n live = false\n }\n }, [hostId, user])\n const update = (patch: Partial<CommerceModel.ShippingSettings>) =>\n form.edit(patch)\n /*\n * The store's other currencies (AGL-4248), from the same settings doc, and\n * the day's rates for the converted figure each blank field stands for.\n */\n const { rates: fxRates } = useCurrencySetup(hostId)\n const storeBase = CommerceModel.storeBaseCurrency(store)\n const otherCurrencies = CommerceModel.otherStoreCurrencies(store?.currencies, storeBase)\n\n const updateZone = (\n index: number,\n patch: Partial<CommerceModel.ShippingZone> | null,\n ) => {\n const zones = [...(current.zones ?? [])]\n if (patch === null) {\n const removed = zones.splice(index, 1)[0]\n update({\n zones,\n rates: (current.rates ?? []).filter(\n (rate) => rate.zoneId !== removed?.id,\n ),\n })\n return\n }\n zones[index] = {\n id: Aglyn.createResourceUid(),\n name: '',\n countries: [],\n ...zones[index],\n ...patch,\n }\n update({ zones })\n }\n\n const updateRate = (\n index: number,\n patch: Partial<CommerceModel.ShippingRate> | null,\n ) => {\n const rates = [...(current.rates ?? [])]\n if (patch === null) rates.splice(index, 1)\n else\n rates[index] = {\n id: Aglyn.createResourceUid(),\n zoneId: current.zones?.[0]?.id ?? '',\n name: '',\n kind: 'flat',\n ...rates[index],\n ...patch,\n }\n update({ rates })\n }\n\n /**\n * One rate's price, or free-over threshold, in another currency\n * (AGL-4248). Blank is converted from the store-currency figure, and drops\n * the key: an emptied map is removed rather than stored as `undefined`.\n */\n const updateRateCurrency = (\n index: number,\n field: 'amountsByCurrency' | 'freeOverByCurrency',\n code: string,\n raw: string,\n ) => {\n const rate = current.rates?.[index]\n if (!rate) return\n const major = CommerceModel.parseMajorInput(raw)\n if (major === null) return\n const map = CommerceModel.withCurrencyAmount(\n rate[field],\n code,\n major === undefined ? undefined : CommerceModel.majorToMinor(major, code),\n )\n const next: CommerceModel.ShippingRate = { ...rate }\n if (map) next[field] = map\n else delete next[field]\n const rates = [...(current.rates ?? [])]\n rates[index] = next\n update({ rates })\n }\n\n const handleSave = useCallback(async () => {\n /**\n * Refuse a save whose seed the server never confirmed (AGL-1358).\n *\n * No create path to exempt: this is a FIXED document path, so the empty\n * `{}` that `store?.shipping ?? {}` yields when the cache has never seen\n * the map is not the harmless blank a fresh uid would be — it replaces\n * the real zones and rates with nothing.\n *\n * The guard WRAPS the write — an early return is a shape you can keep\n * while losing the protection.\n */\n const written = form.edits\n const verdict = await writeGuardedBySeed(\n {\n subject: 'shipping settings',\n unreadable: storeStatus === 'error',\n fromCache: storeFromCache,\n listen: storeListen,\n },\n async () => {\n await setDoc(\n doc(firestore, 'hosts', hostId, 'settings', 'store'),\n { shipping: current },\n { merge: true },\n )\n },\n )\n // Before `settle`, so a refusal keeps every zone and rate that\n // was typed on screen.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n form.settle(written)\n enqueueSnackbar('Shipping settings saved', {\n variant: 'success',\n persist: false,\n })\n }, [current, form, firestore, hostId, enqueueSnackbar, storeStatus, storeFromCache, storeListen])\n\n /**\n * Recomputed from `current` on every render, so the block answers for what\n * is typed rather than for what was last saved — a merchant deleting the\n * zone that covered France should see France go uncovered before they\n * commit it, not after.\n */\n const coverage = CommerceModel.summarizeShippingCoverage(current)\n const words = CommerceModel.describeShippingCoverage(coverage)\n /**\n * The one-click half of the fix: a zone claiming everywhere the merchant\n * has not named. It adds the ZONE only — a rate on it prices the parcel,\n * and choosing that price is the merchant's call, not ours. A rate row\n * defaulted here would post at whatever we picked, and a blank flat rate\n * resolves to free.\n */\n const addRestOfWorldZone = () =>\n updateZone(current.zones?.length ?? 0, {\n name: 'Rest of world',\n countries: ['*'],\n })\n\n const usd = (cents: number | undefined) =>\n cents == null ? '' : String(cents / 100)\n const cents = (raw: string) =>\n raw.trim() === '' ? undefined : Math.round(Number(raw) * 100)\n\n // A press while Save is held is kept, and saves once confirmed (AGL-4047).\n const held = useHeldSave(handleSave, {\n checking,\n subject: 'shipping settings',\n onRefused: (message) => enqueueSnackbar(message, { variant: 'warning', persist: false }),\n })\n\n return (\n <CardDisplay\n header={'Shipping'}\n help={pluginDocsHelp('shipping', { anchor: '#zones-and-rates' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1.5}>\n <Typography variant=\"subtitle2\">{'Zones'}</Typography>\n {(current.zones ?? []).map((zone, index) => (\n <Stack key={zone.id} direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone name\"\n value={zone.name}\n onChange={(event) =>\n updateZone(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ width: 180 }}\n />\n <Autocomplete\n multiple\n size=\"small\"\n sx={{ flex: 1, minWidth: 240 }}\n options={ZONE_COUNTRY_OPTIONS}\n value={zone.countries}\n filterSelectedOptions\n getOptionLabel={zoneCountryLabel}\n onChange={(_event, countries) =>\n updateZone(index, {\n // Rest of world stands alone: a zone that names it AND a\n // country says the same thing twice.\n countries:\n countries.at(-1) === '*'\n ? ['*']\n : countries.filter((code) => code !== '*'),\n })\n }\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Countries\"\n placeholder={zone.countries.length ? '' : 'Search countries, or Rest of world'}\n />\n )}\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateZone(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateZone(current.zones?.length ?? 0, {})}\n >\n {'Add zone'}\n </Button>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Rates'}</Typography>\n {(current.rates ?? []).map((rate, index) => (\n <Stack key={rate.id} spacing={1}>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone\"\n value={rate.zoneId}\n onChange={(event) =>\n updateRate(index, { zoneId: event.target.value })\n }\n size=\"small\"\n select\n sx={{ width: 150 }}\n >\n {(current.zones ?? []).map((zone) => (\n <MenuItem key={zone.id} value={zone.id}>\n {zone.name || zone.countries.join(',')}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n label=\"Name\"\n value={rate.name}\n onChange={(event) =>\n updateRate(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ flex: 1 }}\n placeholder=\"Standard\"\n /**\n * A rate with no name is DROPPED at checkout, silently\n * (AGL-1791): Stripe requires a `display_name`, so\n * `resolveCheckoutShippingOptions` skips the row rather than\n * emit a session Stripe would reject. Saved blank it looks\n * like a priced rate on this page and is not one anywhere\n * else, which is the same invisibility the coverage block\n * below exists to end — said on the row that causes it,\n * because the block can only report the destination it costs.\n */\n error={!rate.name.trim()}\n helperText={\n rate.name.trim() ? undefined : 'Needed — checkout drops it'\n }\n />\n <TextField\n label=\"Type\"\n value={rate.kind}\n onChange={(event) =>\n updateRate(index, {\n kind: event.target.value as CommerceModel.ShippingRate['kind'],\n })\n }\n size=\"small\"\n select\n sx={{ width: 170 }}\n >\n <MenuItem value=\"flat\">{'Flat'}</MenuItem>\n <MenuItem value=\"free_over\">{'Free over subtotal'}</MenuItem>\n <MenuItem value=\"price_tiers\">{'Subtotal tiers'}</MenuItem>\n <MenuItem value=\"weight_tiers\">{'Weight tiers'}</MenuItem>\n {carrier.available || rate.kind === 'carrier' ? (\n <MenuItem value=\"carrier\">{'Carrier rates'}</MenuItem>\n ) : null}\n </TextField>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateRate(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n {rate.kind === 'carrier' ? (\n <CarrierRateFields\n rate={rate}\n services={carrier.services}\n available={carrier.available}\n fallbacks={(current.rates ?? []).filter(\n (other) =>\n other.id !== rate.id &&\n other.zoneId === rate.zoneId &&\n other.kind !== 'carrier',\n )}\n onChange={(patch) => updateRate(index, patch)}\n />\n ) : rate.kind === 'flat' || rate.kind === 'free_over' ? (\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Price ($)\"\n value={usd(rate.amountCents)}\n onChange={(event) =>\n updateRate(index, { amountCents: cents(event.target.value) })\n }\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {rate.kind === 'free_over' ? (\n <TextField\n label=\"Free at subtotal ($)\"\n value={usd(rate.freeOverCents)}\n onChange={(event) =>\n updateRate(index, {\n freeOverCents: cents(event.target.value),\n })\n }\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ) : null}\n </Stack>\n ) : null}\n {(rate.kind === 'flat' || rate.kind === 'free_over') && otherCurrencies.length ? (\n <RateCurrencyFields\n rate={rate}\n base={storeBase}\n currencies={otherCurrencies}\n rates={fxRates}\n onChange={(field, code, raw) => updateRateCurrency(index, field, code, raw)}\n />\n ) : null}\n {rate.kind === 'carrier' || rate.kind === 'flat' || rate.kind === 'free_over' ? null : (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {(rate.tiers ?? []).map((tier, tierIndex) => (\n <Stack key={tierIndex} direction=\"row\" spacing={1}>\n <TextField\n label={\n rate.kind === 'weight_tiers'\n ? 'Up to (g)'\n : 'Up to subtotal ($)'\n }\n value={\n rate.kind === 'weight_tiers'\n ? tier.upTo\n : tier.upTo / 100\n }\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n const value = Number(event.target.value) || 0\n tiers[tierIndex] = {\n ...tier,\n upTo:\n rate.kind === 'weight_tiers'\n ? Math.round(value)\n : Math.round(value * 100),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Price ($)\"\n value={tier.amountCents / 100}\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n tiers[tierIndex] = {\n ...tier,\n amountCents: Math.round(\n (Number(event.target.value) || 0) * 100,\n ),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() =>\n updateRate(index, {\n tiers: (rate.tiers ?? []).filter(\n (_item, itemIndex) => itemIndex !== tierIndex,\n ),\n })\n }\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() =>\n updateRate(index, {\n tiers: [\n ...(rate.tiers ?? []),\n { upTo: 0, amountCents: 0 },\n ],\n })\n }\n >\n {'Add tier'}\n </Button>\n </Stack>\n )}\n </Stack>\n ))}\n <Button\n size=\"small\"\n disabled={(current.zones?.length ?? 0) === 0}\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateRate(current.rates?.length ?? 0, {})}\n >\n {'Add rate'}\n </Button>\n\n <Stack spacing={0}>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={Boolean(current.localPickup)}\n onChange={(event) =>\n update({ localPickup: event.target.checked })\n }\n />\n }\n label=\"Offer free local pickup\"\n />\n {/*\n What the toggle does NOT do, said on the toggle (AGL-2325). It\n used to silently switch off every \"we don't ship there\" refusal,\n because pickup resolved for every destination and checkout read a\n non-empty list as coverage. It no longer does — but a merchant\n reading one line of label still has to be told that turning\n collection on is not the same as adding a destination.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {\n 'A free collection choice at checkout. It does not widen where ' +\n 'you ship — a destination none of your rates reaches is still ' +\n 'turned away. To let buyers choose WHERE to collect, with hours ' +\n 'and a ready-for-pickup email, turn on pickup for a location ' +\n 'under Inventory locations; this choice then gives way to it.'\n }\n </Typography>\n </Stack>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Coverage'}</Typography>\n {coverage.unserved.length > 0 ? (\n <Alert\n severity=\"warning\"\n action={\n coverage.hasRestOfWorldZone ? undefined : (\n <Button\n size=\"small\"\n color=\"inherit\"\n onClick={addRestOfWorldZone}\n >\n {'Add rest-of-world zone'}\n </Button>\n )\n }\n >\n <AlertTitle>{words.headline}</AlertTitle>\n {words.detail}\n </Alert>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.note}\n </Typography>\n )}\n {words.asks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.asks}\n </Typography>\n ) : null}\n\n <Button\n variant=\"contained\"\n color=\"primary\"\n size=\"small\"\n disabled={!form.dirty || held.saving}\n onClick={held.press}\n sx={{ alignSelf: 'flex-start' }}\n >\n {heldSaveLabel(held, 'Save shipping settings')}\n </Button>\n {form.dirty && checking ? (\n <Typography variant=\"body2\" color=\"text.secondary\" role=\"status\">\n {seedCheckingText('shipping settings')}\n </Typography>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nShippingSettingsCard.displayName = 'ShippingSettingsCard'\n\nexport default ShippingSettingsCard\n\ninterface CarrierRateFieldsProps {\n rate: CommerceModel.ShippingRate\n services: Array<{ serviceKey: string; label: string }>\n available: boolean\n /** The zone's other rates, any of which checkout may fall back to. */\n fallbacks: CommerceModel.ShippingRate[]\n onChange: (patch: Partial<CommerceModel.ShippingRate>) => void\n}\n\n/**\n * A carrier rate's options (AGL-3612): which services checkout offers, what\n * is added to each quote, and the zone's rate offered when no live quote is.\n */\nfunction CarrierRateFields(props: CarrierRateFieldsProps) {\n const { rate, services, available, fallbacks, onChange } = props\n const options = rate.carrier ?? {}\n const set = (patch: Partial<CommerceModel.CarrierRateSettings>) =>\n onChange({ carrier: { ...options, ...patch } })\n const picked = new Set(options.services ?? [])\n return (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {!available ? (\n <Alert severity=\"info\">\n {'Live carrier rates are not available on this site right now, so checkout offers the fallback rate.'}\n </Alert>\n ) : null}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Shoppers see each carrier’s price for their address. Leave every service unticked to offer all of them.'}\n </Typography>\n <Stack direction=\"row\" sx={{ flexWrap: 'wrap', columnGap: 2 }}>\n {services.map((service) => (\n <FormControlLabel\n key={service.serviceKey}\n control={\n <Switch\n size=\"small\"\n checked={picked.has(service.serviceKey)}\n onChange={(event) =>\n set({\n services: event.target.checked\n ? [...picked, service.serviceKey]\n : [...picked].filter((key) => key !== service.serviceKey),\n })\n }\n />\n }\n label={service.label}\n />\n ))}\n </Stack>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Markup (%)\"\n value={options.markupPct ?? ''}\n onChange={(event) => {\n const pct = Number(event.target.value)\n set({ markupPct: Number.isFinite(pct) && pct > 0 ? Math.min(pct, 500) : 0 })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Handling fee ($)\"\n value={options.handlingCents ? options.handlingCents / 100 : ''}\n onChange={(event) => {\n const dollars = Number(event.target.value)\n set({ handlingCents: Number.isFinite(dollars) && dollars > 0 ? Math.round(dollars * 100) : 0 })\n }}\n size=\"small\"\n sx={{ width: 150 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n select\n label=\"If no live rate\"\n value={options.fallbackRateId ?? ''}\n onChange={(event) => set({ fallbackRateId: event.target.value })}\n size=\"small\"\n sx={{ minWidth: 200 }}\n error={!options.fallbackRateId}\n helperText={\n options.fallbackRateId ? undefined : 'Pick a rate of this zone, or checkout can’t price without a quote'\n }\n >\n <MenuItem value=\"\">{'None'}</MenuItem>\n {fallbacks.map((fallback) => (\n <MenuItem key={fallback.id} value={fallback.id}>\n {fallback.name || 'Unnamed rate'}\n </MenuItem>\n ))}\n </TextField>\n </Stack>\n </Stack>\n )\n}\n\ninterface RateCurrencyFieldsProps {\n rate: CommerceModel.ShippingRate\n base: string\n currencies: CommerceModel.StoreCurrency[]\n rates: CommerceModel.FxRates | undefined\n onChange: (\n field: 'amountsByCurrency' | 'freeOverByCurrency',\n code: string,\n raw: string,\n ) => void\n}\n\n/**\n * A flat or free-over rate in each other currency the store sells in\n * (AGL-4248). A blank field is converted at the day's rate, and shows the\n * converted figure as its placeholder; a typed one is charged as typed.\n */\nfunction RateCurrencyFields(props: RateCurrencyFieldsProps) {\n const { rate, base, currencies, rates, onChange } = props\n const converted = (minor: number | undefined, entry: CommerceModel.StoreCurrency) =>\n minor == null\n ? ''\n : CommerceModel.minorToInput(\n CommerceModel.amountMinorIn(minor, base, entry, rates),\n entry.code,\n )\n return (\n <Stack spacing={1} sx={{ pl: 2 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'In other currencies. Leave one blank to convert it from the price above.'}\n </Typography>\n {currencies.map((entry) => (\n <Stack key={entry.code} direction=\"row\" spacing={1}>\n <TextField\n key={`${rate.id}-amount-${entry.code}`}\n label={`Price (${entry.code})`}\n defaultValue={CommerceModel.minorToInput(rate.amountsByCurrency?.[entry.code], entry.code)}\n placeholder={converted(rate.amountCents ?? 0, entry)}\n onBlur={(event) => onChange('amountsByCurrency', entry.code, event.target.value)}\n size=\"small\"\n sx={{ width: 140 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {rate.kind === 'free_over' ? (\n <TextField\n key={`${rate.id}-free-${entry.code}`}\n label={`Free at subtotal (${entry.code})`}\n defaultValue={CommerceModel.minorToInput(rate.freeOverByCurrency?.[entry.code], entry.code)}\n placeholder={converted(rate.freeOverCents, entry)}\n onBlur={(event) => onChange('freeOverByCurrency', entry.code, event.target.value)}\n size=\"small\"\n sx={{ width: 190 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ) : null}\n </Stack>\n ))}\n </Stack>\n )\n}\n"],"names":["Aglyn","CommerceModel","CardDisplay","useSnackbar","Alert","AlertTitle","Autocomplete","Button","Divider","FormControlLabel","MenuItem","Stack","Switch","TextField","Typography","authorizedFetch","doc","setDoc","useCallback","useEffect","useState","useFirestore","useUser","useFirestoreDoc","writeGuardedBySeed","pluginDocsHelp","heldSaveLabel","isSeedChecking","seedCheckingText","useHeldSave","useSeedEdits","useCurrencySetup","ZONE_COUNTRY_OPTIONS","STRIPE_SHIPPING_COUNTRY_CODES","sort","a","b","zoneCountryLabel","localeCompare","code","CHECKOUT_SHIPPING_COUNTRY_NAMES","ShippingSettingsCard","props","current","hostId","firestore","enqueueSnackbar","data","store","status","storeStatus","fromCache","storeFromCache","listen","storeListen","form","shipping","values","checking","unreadable","user","carrier","setCarrier","available","services","live","encodeURIComponent","then","response","ok","json","answer","Boolean","catch","undefined","update","patch","edit","rates","fxRates","storeBase","storeBaseCurrency","otherCurrencies","otherStoreCurrencies","currencies","updateZone","index","zones","removed","splice","filter","rate","zoneId","id","createResourceUid","name","countries","updateRate","kind","updateRateCurrency","field","raw","major","parseMajorInput","map","withCurrencyAmount","majorToMinor","next","handleSave","written","edits","verdict","subject","merge","message","variant","persist","settle","coverage","summarizeShippingCoverage","words","describeShippingCoverage","addRestOfWorldZone","length","usd","cents","String","trim","Math","round","Number","held","onRefused","header","help","anchor","contentGutterX","contentGutterY","spacing","zone","direction","label","value","onChange","event","target","size","sx","width","multiple","flex","minWidth","options","filterSelectedOptions","getOptionLabel","_event","at","renderInput","params","placeholder","color","onClick","alignSelf","select","join","error","helperText","CarrierRateFields","fallbacks","other","amountCents","slotProps","htmlInput","inputMode","freeOverCents","RateCurrencyFields","base","pl","tiers","tier","tierIndex","upTo","_item","itemIndex","disabled","control","checked","localPickup","unserved","severity","action","hasRestOfWorldZone","headline","detail","note","asks","dirty","saving","press","role","displayName","set","picked","Set","flexWrap","columnGap","service","has","serviceKey","key","markupPct","pct","isFinite","min","handlingCents","dollars","fallbackRateId","fallback","converted","minor","entry","minorToInput","amountMinorIn","defaultValue","amountsByCurrency","onBlur","freeOverByCurrency"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AACrC,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,OAAO,EACPC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,GAAG,EAAEC,MAAM,QAAQ,qBAAoB;AAChD,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AACxD,SAASC,YAAY,EAAEC,OAAO,QAAQ,iCAAgC;AACtE,SACEC,eAAe,EACfC,kBAAkB,QACb,iCAAgC;AACvC,SAASC,cAAc,QAAQ,eAAc;AAC7C,SACEC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,QACP,sDAAqD;AAC5D,SAASC,gBAAgB,QAAQ,0BAAsB;AAMvD,wEAAwE,GACxE,MAAMC,uBAAiC;IACrC;OACG;WAAI/B,cAAcgC,6BAA6B;KAAC,CAACC,IAAI,CAAC,CAACC,GAAGC,IAC3DC,iBAAiBF,GAAGG,aAAa,CAACD,iBAAiBD;CAEtD;AAED,SAASC,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a,EAAE8C;4BAC3CK,QAAQ,CAACjF,QAAUD,SAAS,sBAAsB6E,MAAMrL,IAAI,EAAEyG,MAAMC,MAAM,CAACH,KAAK;4BAChFI,MAAK;4BACLC,IAAI;gCAAEC,OAAO;4BAAI;4BACjBuB,WAAW;gCAAEC,WAAW;oCAAEC,WAAW;gCAAU;4BAAE;2BAP5C,GAAGlF,KAAKE,EAAE,CAAC,MAAM,EAAE+H,MAAMrL,IAAI,EAAE,IASpC;;mBAtBMqL,MAAMrL,IAAI;;;;AA2B9B"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/shipping-settings-card.component.tsx"],"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'use client'\n\nimport * as Aglyn from '@aglyn/aglyn'\nimport * as CommerceModel from '../../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n AlertTitle,\n Autocomplete,\n Button,\n Divider,\n FormControlLabel,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { doc, setDoc } from 'firebase/firestore'\nimport { useCallback, useEffect, useState } from 'react'\nimport { useFirestore, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n useFirestoreDoc,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n heldSaveLabel,\n isSeedChecking,\n seedCheckingText,\n useHeldSave,\n useSeedEdits,\n} from '@aglyn/tenant-feature-instance/hooks/use-seed-edits'\nimport { useCurrencySetup } from './use-currency-setup'\n\nexport interface ShippingSettingsCardProps {\n hostId: string\n}\n\n/** Every country checkout can ship to, plus rest of world, for a zone. */\nconst ZONE_COUNTRY_OPTIONS: string[] = [\n '*',\n ...[...CommerceModel.STRIPE_SHIPPING_COUNTRY_CODES].sort((a, b) =>\n zoneCountryLabel(a).localeCompare(zoneCountryLabel(b)),\n ),\n]\n\nfunction zoneCountryLabel(code: string): string {\n if (code === '*') return 'Rest of world'\n return CommerceModel.CHECKOUT_SHIPPING_COUNTRY_NAMES[code] ?? code\n}\n\n/**\n * Shipping settings (AGL-288): zones (countries, '*' = rest of world)\n * and rates (flat / free-over / subtotal or weight tiers), stored on\n * `hosts/{hostId}/settings/store` under `shipping`. Cart checkout (AGL-1707)\n * and buy-now (AGL-1720) both read this document and declare the rates as\n * Stripe `shipping_options` (`planCheckoutShipping`) — until those landed\n * nothing read it, and everything saved here was charged to nobody. Buy-now\n * resolves only for physical one-time sales; draft orders and POS still\n * resolve no shipping at all.\n *\n * WHAT A ZONE LAYOUT COSTS THE SHOPPER (AGL-1721). A session's rates are\n * charged as picked and never re-checked against the address, so the checkout\n * can only offer rates that hold for every country it will ship to. Saving\n * zones whose rates DIFFER therefore makes the storefront ask the shopper\n * where the parcel is going before it can price one, and a destination no\n * zone covers is refused outright rather than shipped for free. One zone, or\n * one '*' zone, needs neither: the shopper is asked nothing.\n *\n * AND THE MERCHANT HAS TO BE ABLE TO SEE IT (AGL-1791). Both consequences\n * were invisible here: a merchant saved zones and the checkouts they refused\n * were refused with nothing on this page saying so, which is a support ticket\n * from someone who did nothing wrong. The coverage block reads\n * `summarizeShippingCoverage` off the same `current` object the save writes,\n * so it moves as the form is typed rather than after a round trip.\n *\n * It escalates to a warning ONLY for a merchant who priced some destinations\n * and not others. A merchant whose rates reach nowhere is not misconfigured —\n * that store charges no shipping and refuses nobody — and warning them would\n * nag every store selling downloads.\n */\nexport function ShippingSettingsCard(props: ShippingSettingsCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const {\n data: store,\n status: storeStatus,\n /**\n * The settings doc this form is seeded from is unconfirmed by the server\n * (AGL-1358). `current` is `draft ?? store?.shipping ?? {}` and the save\n * writes `{shipping: current}`, so `merge: true` protects the doc's other\n * maps and nothing inside this one — `zones` and `rates` are arrays, and\n * a merge replaces an array wholesale. Against a cached read, adding one\n * rate restores that snapshot's whole price table, and a zone that\n * disappears with it means `resolveShippingRates` matches nothing, which\n * is a checkout offering no shipping option at all.\n */\n fromCache: storeFromCache,\n listen: storeListen,\n } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId, 'settings', 'store'),\n [firestore, hostId],\n )\n // What was typed, kept as edits over the stored settings, and Save held\n // until the server has confirmed them (AGL-4047).\n const form = useSeedEdits<CommerceModel.ShippingSettings>(store?.shipping ?? {})\n const current = form.values\n const checking = isSeedChecking({ fromCache: storeFromCache, unreadable: storeStatus === 'error' })\n /*\n * Live carrier rates (AGL-3612) are offered only where a plugin quotes\n * carriers for this site — the server asks core's quoter seam. A rate\n * already saved as `carrier` stays editable either way, so a merchant can\n * still see and change what checkout falls back to.\n */\n const { data: user } = useUser()\n const [carrier, setCarrier] = useState<{\n available: boolean\n services: Array<{ serviceKey: string; label: string }>\n }>({ available: false, services: [] })\n useEffect(() => {\n let live = true\n authorizedFetch(user, `/api/commerce/shipping/carrier-rates?hostId=${encodeURIComponent(hostId)}`)\n .then((response) => (response.ok ? response.json() : null))\n .then((answer) => {\n if (live && answer) setCarrier({ available: Boolean(answer.available), services: answer.services ?? [] })\n })\n .catch(() => undefined)\n return () => {\n live = false\n }\n }, [hostId, user])\n const update = (patch: Partial<CommerceModel.ShippingSettings>) =>\n form.edit(patch)\n /*\n * The store's other currencies (AGL-4248), from the same settings doc, and\n * the day's rates for the converted figure each blank field stands for.\n */\n const { rates: fxRates } = useCurrencySetup(hostId)\n const storeBase = CommerceModel.storeBaseCurrency(store)\n const otherCurrencies = CommerceModel.otherStoreCurrencies(store?.currencies, storeBase)\n\n const updateZone = (\n index: number,\n patch: Partial<CommerceModel.ShippingZone> | null,\n ) => {\n const zones = [...(current.zones ?? [])]\n if (patch === null) {\n const removed = zones.splice(index, 1)[0]\n update({\n zones,\n rates: (current.rates ?? []).filter(\n (rate) => rate.zoneId !== removed?.id,\n ),\n })\n return\n }\n zones[index] = {\n id: Aglyn.createResourceUid(),\n name: '',\n countries: [],\n ...zones[index],\n ...patch,\n }\n update({ zones })\n }\n\n const updateRate = (\n index: number,\n patch: Partial<CommerceModel.ShippingRate> | null,\n ) => {\n const rates = [...(current.rates ?? [])]\n if (patch === null) rates.splice(index, 1)\n else {\n const next: CommerceModel.ShippingRate = {\n id: Aglyn.createResourceUid(),\n zoneId: current.zones?.[0]?.id ?? '',\n name: '',\n kind: 'flat',\n ...rates[index],\n ...patch,\n }\n // A field emptied on screen is taken off the rate, not stored as\n // `undefined`: this Firestore client rejects the whole save on one.\n for (const key of Object.keys(next) as (keyof CommerceModel.ShippingRate)[]) {\n if (next[key] === undefined) delete next[key]\n }\n rates[index] = next\n }\n update({ rates })\n }\n\n /**\n * One rate's price, or free-over threshold, in another currency\n * (AGL-4248). Blank is converted from the store-currency figure, and drops\n * the key: an emptied map is removed rather than stored as `undefined`.\n */\n const updateRateCurrency = (\n index: number,\n field: CurrencyMapField,\n code: string,\n raw: string,\n ) => {\n const rate = current.rates?.[index]\n if (!rate) return\n const major = CommerceModel.parseMajorInput(raw)\n if (major === null) return\n const map = CommerceModel.withCurrencyAmount(\n rate[field],\n code,\n major === undefined ? undefined : CommerceModel.majorToMinor(major, code),\n )\n const next: CommerceModel.ShippingRate = { ...rate }\n if (map) next[field] = map\n else delete next[field]\n const rates = [...(current.rates ?? [])]\n rates[index] = next\n update({ rates })\n }\n\n const handleSave = useCallback(async () => {\n /**\n * Refuse a save whose seed the server never confirmed (AGL-1358).\n *\n * No create path to exempt: this is a FIXED document path, so the empty\n * `{}` that `store?.shipping ?? {}` yields when the cache has never seen\n * the map is not the harmless blank a fresh uid would be — it replaces\n * the real zones and rates with nothing.\n *\n * The guard WRAPS the write — an early return is a shape you can keep\n * while losing the protection.\n */\n const written = form.edits\n const verdict = await writeGuardedBySeed(\n {\n subject: 'shipping settings',\n unreadable: storeStatus === 'error',\n fromCache: storeFromCache,\n listen: storeListen,\n },\n async () => {\n await setDoc(\n doc(firestore, 'hosts', hostId, 'settings', 'store'),\n { shipping: current },\n { merge: true },\n )\n },\n )\n // Before `settle`, so a refusal keeps every zone and rate that\n // was typed on screen.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n form.settle(written)\n enqueueSnackbar('Shipping settings saved', {\n variant: 'success',\n persist: false,\n })\n }, [current, form, firestore, hostId, enqueueSnackbar, storeStatus, storeFromCache, storeListen])\n\n /**\n * Recomputed from `current` on every render, so the block answers for what\n * is typed rather than for what was last saved — a merchant deleting the\n * zone that covered France should see France go uncovered before they\n * commit it, not after.\n */\n const coverage = CommerceModel.summarizeShippingCoverage(current)\n const words = CommerceModel.describeShippingCoverage(coverage)\n /**\n * The one-click half of the fix: a zone claiming everywhere the merchant\n * has not named. It adds the ZONE only — a rate on it prices the parcel,\n * and choosing that price is the merchant's call, not ours. A rate row\n * defaulted here would post at whatever we picked, and a blank flat rate\n * resolves to free.\n */\n const addRestOfWorldZone = () =>\n updateZone(current.zones?.length ?? 0, {\n name: 'Rest of world',\n countries: ['*'],\n })\n\n const usd = (cents: number | undefined) =>\n cents == null ? '' : String(cents / 100)\n const cents = (raw: string) =>\n raw.trim() === '' ? undefined : Math.round(Number(raw) * 100)\n\n // A press while Save is held is kept, and saves once confirmed (AGL-4047).\n const held = useHeldSave(handleSave, {\n checking,\n subject: 'shipping settings',\n onRefused: (message) => enqueueSnackbar(message, { variant: 'warning', persist: false }),\n })\n\n return (\n <CardDisplay\n header={'Shipping'}\n help={pluginDocsHelp('shipping', { anchor: '#zones-and-rates' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1.5}>\n <Typography variant=\"subtitle2\">{'Zones'}</Typography>\n {(current.zones ?? []).map((zone, index) => (\n <Stack key={zone.id} direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone name\"\n value={zone.name}\n onChange={(event) =>\n updateZone(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ width: 180 }}\n />\n <Autocomplete\n multiple\n size=\"small\"\n sx={{ flex: 1, minWidth: 240 }}\n options={ZONE_COUNTRY_OPTIONS}\n value={zone.countries}\n filterSelectedOptions\n getOptionLabel={zoneCountryLabel}\n onChange={(_event, countries) =>\n updateZone(index, {\n // Rest of world stands alone: a zone that names it AND a\n // country says the same thing twice.\n countries:\n countries.at(-1) === '*'\n ? ['*']\n : countries.filter((code) => code !== '*'),\n })\n }\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Countries\"\n placeholder={zone.countries.length ? '' : 'Search countries, or Rest of world'}\n />\n )}\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateZone(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateZone(current.zones?.length ?? 0, {})}\n >\n {'Add zone'}\n </Button>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Rates'}</Typography>\n {(current.rates ?? []).map((rate, index) => (\n <Stack key={rate.id} spacing={1}>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Zone\"\n value={rate.zoneId}\n onChange={(event) =>\n updateRate(index, { zoneId: event.target.value })\n }\n size=\"small\"\n select\n sx={{ width: 150 }}\n >\n {(current.zones ?? []).map((zone) => (\n <MenuItem key={zone.id} value={zone.id}>\n {zone.name || zone.countries.join(',')}\n </MenuItem>\n ))}\n </TextField>\n <TextField\n label=\"Name\"\n value={rate.name}\n onChange={(event) =>\n updateRate(index, { name: event.target.value })\n }\n size=\"small\"\n sx={{ flex: 1 }}\n placeholder=\"Standard\"\n /**\n * A rate with no name is DROPPED at checkout, silently\n * (AGL-1791): Stripe requires a `display_name`, so\n * `resolveCheckoutShippingOptions` skips the row rather than\n * emit a session Stripe would reject. Saved blank it looks\n * like a priced rate on this page and is not one anywhere\n * else, which is the same invisibility the coverage block\n * below exists to end — said on the row that causes it,\n * because the block can only report the destination it costs.\n */\n error={!rate.name.trim()}\n helperText={\n rate.name.trim() ? undefined : 'Needed — checkout drops it'\n }\n />\n <TextField\n label=\"Type\"\n value={rate.kind}\n onChange={(event) =>\n updateRate(index, {\n kind: event.target.value as CommerceModel.ShippingRate['kind'],\n })\n }\n size=\"small\"\n select\n sx={{ width: 170 }}\n >\n <MenuItem value=\"flat\">{'Flat'}</MenuItem>\n <MenuItem value=\"free_over\">{'Free over subtotal'}</MenuItem>\n <MenuItem value=\"price_tiers\">{'Subtotal tiers'}</MenuItem>\n <MenuItem value=\"weight_tiers\">{'Weight tiers'}</MenuItem>\n {carrier.available || rate.kind === 'carrier' ? (\n <MenuItem value=\"carrier\">{'Carrier rates'}</MenuItem>\n ) : null}\n </TextField>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => updateRate(index, null)}\n >\n {'✕'}\n </Button>\n </Stack>\n {rate.kind === 'carrier' ? (\n <CarrierRateFields\n rate={rate}\n services={carrier.services}\n available={carrier.available}\n fallbacks={(current.rates ?? []).filter(\n (other) =>\n other.id !== rate.id &&\n other.zoneId === rate.zoneId &&\n other.kind !== 'carrier',\n )}\n onChange={(patch) => updateRate(index, patch)}\n />\n ) : rate.kind === 'flat' || rate.kind === 'free_over' ? (\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Price ($)\"\n value={usd(rate.amountCents)}\n onChange={(event) =>\n updateRate(index, { amountCents: cents(event.target.value) })\n }\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {rate.kind === 'free_over' ? (\n <TextField\n label=\"Free at subtotal ($)\"\n value={usd(rate.freeOverCents)}\n onChange={(event) =>\n updateRate(index, {\n freeOverCents: cents(event.target.value),\n })\n }\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ) : null}\n </Stack>\n ) : null}\n {(rate.kind === 'flat' || rate.kind === 'free_over') && otherCurrencies.length ? (\n <RateCurrencyFields\n rate={rate}\n base={storeBase}\n currencies={otherCurrencies}\n rates={fxRates}\n onChange={(field, code, raw) => updateRateCurrency(index, field, code, raw)}\n />\n ) : null}\n {rate.kind === 'carrier' || rate.kind === 'flat' || rate.kind === 'free_over' ? null : (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {(rate.tiers ?? []).map((tier, tierIndex) => (\n <Stack key={tierIndex} direction=\"row\" spacing={1}>\n <TextField\n label={\n rate.kind === 'weight_tiers'\n ? 'Up to (g)'\n : 'Up to subtotal ($)'\n }\n value={\n rate.kind === 'weight_tiers'\n ? tier.upTo\n : tier.upTo / 100\n }\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n const value = Number(event.target.value) || 0\n tiers[tierIndex] = {\n ...tier,\n upTo:\n rate.kind === 'weight_tiers'\n ? Math.round(value)\n : Math.round(value * 100),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 160 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Price ($)\"\n value={tier.amountCents / 100}\n onChange={(event) => {\n const tiers = [...(rate.tiers ?? [])]\n tiers[tierIndex] = {\n ...tier,\n amountCents: Math.round(\n (Number(event.target.value) || 0) * 100,\n ),\n }\n updateRate(index, { tiers })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() =>\n updateRate(index, {\n tiers: (rate.tiers ?? []).filter(\n (_item, itemIndex) => itemIndex !== tierIndex,\n ),\n })\n }\n >\n {'✕'}\n </Button>\n </Stack>\n ))}\n <Button\n size=\"small\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() =>\n updateRate(index, {\n tiers: [\n ...(rate.tiers ?? []),\n { upTo: 0, amountCents: 0 },\n ],\n })\n }\n >\n {'Add tier'}\n </Button>\n </Stack>\n )}\n {rate.kind === 'carrier' ? null : (\n <RateConditionFields\n rate={rate}\n currencies={otherCurrencies}\n onChange={(patch) => updateRate(index, patch)}\n onCurrencyChange={(field, code, raw) => updateRateCurrency(index, field, code, raw)}\n />\n )}\n </Stack>\n ))}\n <Button\n size=\"small\"\n disabled={(current.zones?.length ?? 0) === 0}\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => updateRate(current.rates?.length ?? 0, {})}\n >\n {'Add rate'}\n </Button>\n\n <Stack spacing={0}>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={Boolean(current.localPickup)}\n onChange={(event) =>\n update({ localPickup: event.target.checked })\n }\n />\n }\n label=\"Offer free local pickup\"\n />\n {/*\n What the toggle does NOT do, said on the toggle (AGL-2325). It\n used to silently switch off every \"we don't ship there\" refusal,\n because pickup resolved for every destination and checkout read a\n non-empty list as coverage. It no longer does — but a merchant\n reading one line of label still has to be told that turning\n collection on is not the same as adding a destination.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {\n 'A free collection choice at checkout. It does not widen where ' +\n 'you ship — a destination none of your rates reaches is still ' +\n 'turned away. To let buyers choose WHERE to collect, with hours ' +\n 'and a ready-for-pickup email, turn on pickup for a location ' +\n 'under Inventory locations; this choice then gives way to it.'\n }\n </Typography>\n </Stack>\n\n <Divider />\n <Typography variant=\"subtitle2\">{'Coverage'}</Typography>\n {coverage.unserved.length > 0 ? (\n <Alert\n severity=\"warning\"\n action={\n coverage.hasRestOfWorldZone ? undefined : (\n <Button\n size=\"small\"\n color=\"inherit\"\n onClick={addRestOfWorldZone}\n >\n {'Add rest-of-world zone'}\n </Button>\n )\n }\n >\n <AlertTitle>{words.headline}</AlertTitle>\n {words.detail}\n </Alert>\n ) : (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.note}\n </Typography>\n )}\n {words.asks ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {words.asks}\n </Typography>\n ) : null}\n {(current.rates ?? []).some((rate) => rate.kind !== 'carrier' && CommerceModel.rateHasConditions(rate)) ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {\n 'Rates with conditions are offered only to orders that meet them, so the destinations above are covered for some orders. An order that meets no rate of its zone is told shipping is not available.'\n }\n </Typography>\n ) : null}\n\n <Button\n variant=\"contained\"\n color=\"primary\"\n size=\"small\"\n disabled={!form.dirty || held.saving}\n onClick={held.press}\n sx={{ alignSelf: 'flex-start' }}\n >\n {heldSaveLabel(held, 'Save shipping settings')}\n </Button>\n {form.dirty && checking ? (\n <Typography variant=\"body2\" color=\"text.secondary\" role=\"status\">\n {seedCheckingText('shipping settings')}\n </Typography>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nShippingSettingsCard.displayName = 'ShippingSettingsCard'\n\nexport default ShippingSettingsCard\n\ninterface CarrierRateFieldsProps {\n rate: CommerceModel.ShippingRate\n services: Array<{ serviceKey: string; label: string }>\n available: boolean\n /** The zone's other rates, any of which checkout may fall back to. */\n fallbacks: CommerceModel.ShippingRate[]\n onChange: (patch: Partial<CommerceModel.ShippingRate>) => void\n}\n\n/**\n * A carrier rate's options (AGL-3612): which services checkout offers, what\n * is added to each quote, and the zone's rate offered when no live quote is.\n */\nfunction CarrierRateFields(props: CarrierRateFieldsProps) {\n const { rate, services, available, fallbacks, onChange } = props\n const options = rate.carrier ?? {}\n const set = (patch: Partial<CommerceModel.CarrierRateSettings>) =>\n onChange({ carrier: { ...options, ...patch } })\n const picked = new Set(options.services ?? [])\n return (\n <Stack spacing={1} sx={{ pl: 2 }}>\n {!available ? (\n <Alert severity=\"info\">\n {'Live carrier rates are not available on this site right now, so checkout offers the fallback rate.'}\n </Alert>\n ) : null}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Shoppers see each carrier’s price for their address. Leave every service unticked to offer all of them.'}\n </Typography>\n <Stack direction=\"row\" sx={{ flexWrap: 'wrap', columnGap: 2 }}>\n {services.map((service) => (\n <FormControlLabel\n key={service.serviceKey}\n control={\n <Switch\n size=\"small\"\n checked={picked.has(service.serviceKey)}\n onChange={(event) =>\n set({\n services: event.target.checked\n ? [...picked, service.serviceKey]\n : [...picked].filter((key) => key !== service.serviceKey),\n })\n }\n />\n }\n label={service.label}\n />\n ))}\n </Stack>\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Markup (%)\"\n value={options.markupPct ?? ''}\n onChange={(event) => {\n const pct = Number(event.target.value)\n set({ markupPct: Number.isFinite(pct) && pct > 0 ? Math.min(pct, 500) : 0 })\n }}\n size=\"small\"\n sx={{ width: 120 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Handling fee ($)\"\n value={options.handlingCents ? options.handlingCents / 100 : ''}\n onChange={(event) => {\n const dollars = Number(event.target.value)\n set({ handlingCents: Number.isFinite(dollars) && dollars > 0 ? Math.round(dollars * 100) : 0 })\n }}\n size=\"small\"\n sx={{ width: 150 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n select\n label=\"If no live rate\"\n value={options.fallbackRateId ?? ''}\n onChange={(event) => set({ fallbackRateId: event.target.value })}\n size=\"small\"\n sx={{ minWidth: 200 }}\n error={!options.fallbackRateId}\n helperText={\n options.fallbackRateId ? undefined : 'Pick a rate of this zone, or checkout can’t price without a quote'\n }\n >\n <MenuItem value=\"\">{'None'}</MenuItem>\n {fallbacks.map((fallback) => (\n <MenuItem key={fallback.id} value={fallback.id}>\n {fallback.name || 'Unnamed rate'}\n </MenuItem>\n ))}\n </TextField>\n </Stack>\n </Stack>\n )\n}\n\n/** The per-currency maps a rate carries (AGL-4248, AGL-4255). */\ntype CurrencyMapField =\n | 'amountsByCurrency'\n | 'freeOverByCurrency'\n | 'minSubtotalByCurrency'\n | 'maxSubtotalByCurrency'\n\n/** Every condition field, cleared together when the merchant removes them (AGL-4255). */\nconst NO_CONDITIONS: Partial<CommerceModel.ShippingRate> = {\n minSubtotalCents: undefined,\n maxSubtotalCents: undefined,\n minSubtotalByCurrency: undefined,\n maxSubtotalByCurrency: undefined,\n minGrams: undefined,\n maxGrams: undefined,\n}\n\ninterface RateConditionFieldsProps {\n rate: CommerceModel.ShippingRate\n currencies: CommerceModel.StoreCurrency[]\n onChange: (patch: Partial<CommerceModel.ShippingRate>) => void\n onCurrencyChange: (field: CurrencyMapField, code: string, raw: string) => void\n}\n\n/**\n * A rate's conditions (AGL-4255), as Shopify sets them: offered only to\n * carts whose order price, or whose item weight, falls between a minimum and\n * a maximum. One basis at a time; switching clears the other's figures.\n */\nfunction RateConditionFields(props: RateConditionFieldsProps) {\n const { rate, currencies, onChange, onCurrencyChange } = props\n const byWeight = rate.minGrams != null || rate.maxGrams != null\n const has = CommerceModel.rateHasConditions(rate)\n const [adding, setAdding] = useState<null | 'price' | 'weight'>(null)\n const basis: 'price' | 'weight' = has ? (byWeight ? 'weight' : 'price') : (adding ?? 'price')\n const usd = (cents: number | undefined) => (cents == null ? '' : String(cents / 100))\n const cents = (raw: string) => (raw.trim() === '' || !Number.isFinite(Number(raw)) ? undefined : Math.max(0, Math.round(Number(raw) * 100)))\n const grams = (raw: string) => (raw.trim() === '' || !Number.isFinite(Number(raw)) ? undefined : Math.max(0, Math.round(Number(raw))))\n // Emptying every figure keeps the block open while the merchant types.\n const keep = (patch: Partial<CommerceModel.ShippingRate>) => {\n setAdding(basis)\n onChange(patch)\n }\n if (!has && adding === null) {\n return (\n <Button size=\"small\" sx={{ alignSelf: 'flex-start' }} onClick={() => setAdding('price')}>\n {'Add conditions'}\n </Button>\n )\n }\n const minMax =\n rate.minSubtotalCents != null && rate.maxSubtotalCents != null && rate.minSubtotalCents > rate.maxSubtotalCents\n ? 'The minimum is above the maximum, so no order gets this rate.'\n : rate.minGrams != null && rate.maxGrams != null && rate.minGrams > rate.maxGrams\n ? 'The minimum is above the maximum, so no order gets this rate.'\n : ''\n return (\n <Stack spacing={1} sx={{ pl: 2 }}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <TextField\n label=\"Conditions\"\n value={basis}\n onChange={(event) => {\n const next = event.target.value as 'price' | 'weight'\n setAdding(next)\n if (next !== basis) onChange(NO_CONDITIONS)\n }}\n size=\"small\"\n select\n sx={{ width: 220 }}\n >\n <MenuItem value=\"price\">{'Based on order price'}</MenuItem>\n <MenuItem value=\"weight\">{'Based on item weight'}</MenuItem>\n </TextField>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={() => {\n setAdding(null)\n onChange(NO_CONDITIONS)\n }}\n >\n {'Remove conditions'}\n </Button>\n </Stack>\n {basis === 'price' ? (\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Minimum order price ($)\"\n value={usd(rate.minSubtotalCents)}\n onChange={(event) => keep({ minSubtotalCents: cents(event.target.value) })}\n size=\"small\"\n sx={{ width: 200 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label=\"Maximum order price ($)\"\n value={usd(rate.maxSubtotalCents)}\n onChange={(event) => keep({ maxSubtotalCents: cents(event.target.value) })}\n size=\"small\"\n sx={{ width: 200 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n </Stack>\n ) : (\n <Stack direction=\"row\" spacing={1}>\n <TextField\n label=\"Minimum weight (g)\"\n value={rate.minGrams ?? ''}\n onChange={(event) => keep({ minGrams: grams(event.target.value) })}\n size=\"small\"\n sx={{ width: 200 }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"Maximum weight (g)\"\n value={rate.maxGrams ?? ''}\n onChange={(event) => keep({ maxGrams: grams(event.target.value) })}\n size=\"small\"\n sx={{ width: 200 }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n </Stack>\n )}\n {basis === 'price' && currencies.length\n ? currencies.map((entry) => (\n <Stack key={entry.code} direction=\"row\" spacing={1}>\n <TextField\n key={`${rate.id}-min-${entry.code}`}\n label={`Minimum (${entry.code})`}\n defaultValue={CommerceModel.minorToInput(rate.minSubtotalByCurrency?.[entry.code], entry.code)}\n placeholder=\"Converted\"\n onBlur={(event) => onCurrencyChange('minSubtotalByCurrency', entry.code, event.target.value)}\n size=\"small\"\n sx={{ width: 200 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n key={`${rate.id}-max-${entry.code}`}\n label={`Maximum (${entry.code})`}\n defaultValue={CommerceModel.minorToInput(rate.maxSubtotalByCurrency?.[entry.code], entry.code)}\n placeholder=\"Converted\"\n onBlur={(event) => onCurrencyChange('maxSubtotalByCurrency', entry.code, event.target.value)}\n size=\"small\"\n sx={{ width: 200 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n </Stack>\n ))\n : null}\n <Typography variant=\"caption\" color={minMax ? 'error' : 'text.secondary'}>\n {minMax ||\n (basis === 'price'\n ? 'Checkout offers this rate only when the order, before discounts, is within these amounts. Leave one blank for no limit.'\n : 'Checkout offers this rate only when the items weigh within these amounts. Leave one blank for no limit.')}\n </Typography>\n </Stack>\n )\n}\n\ninterface RateCurrencyFieldsProps {\n rate: CommerceModel.ShippingRate\n base: string\n currencies: CommerceModel.StoreCurrency[]\n rates: CommerceModel.FxRates | undefined\n onChange: (\n field: CurrencyMapField,\n code: string,\n raw: string,\n ) => void\n}\n\n/**\n * A flat or free-over rate in each other currency the store sells in\n * (AGL-4248). A blank field is converted at the day's rate, and shows the\n * converted figure as its placeholder; a typed one is charged as typed.\n */\nfunction RateCurrencyFields(props: RateCurrencyFieldsProps) {\n const { rate, base, currencies, rates, onChange } = props\n const converted = (minor: number | undefined, entry: CommerceModel.StoreCurrency) =>\n minor == null\n ? ''\n : CommerceModel.minorToInput(\n CommerceModel.amountMinorIn(minor, base, entry, rates),\n entry.code,\n )\n return (\n <Stack spacing={1} sx={{ pl: 2 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'In other currencies. Leave one blank to convert it from the price above.'}\n </Typography>\n {currencies.map((entry) => (\n <Stack key={entry.code} direction=\"row\" spacing={1}>\n <TextField\n key={`${rate.id}-amount-${entry.code}`}\n label={`Price (${entry.code})`}\n defaultValue={CommerceModel.minorToInput(rate.amountsByCurrency?.[entry.code], entry.code)}\n placeholder={converted(rate.amountCents ?? 0, entry)}\n onBlur={(event) => onChange('amountsByCurrency', entry.code, event.target.value)}\n size=\"small\"\n sx={{ width: 140 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {rate.kind === 'free_over' ? (\n <TextField\n key={`${rate.id}-free-${entry.code}`}\n label={`Free at subtotal (${entry.code})`}\n defaultValue={CommerceModel.minorToInput(rate.freeOverByCurrency?.[entry.code], entry.code)}\n placeholder={converted(rate.freeOverCents, entry)}\n onBlur={(event) => onChange('freeOverByCurrency', entry.code, event.target.value)}\n size=\"small\"\n sx={{ width: 190 }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ) : null}\n </Stack>\n ))}\n </Stack>\n )\n}\n"],"names":["Aglyn","CommerceModel","CardDisplay","useSnackbar","Alert","AlertTitle","Autocomplete","Button","Divider","FormControlLabel","MenuItem","Stack","Switch","TextField","Typography","authorizedFetch","doc","setDoc","useCallback","useEffect","useState","useFirestore","useUser","useFirestoreDoc","writeGuardedBySeed","pluginDocsHelp","heldSaveLabel","isSeedChecking","seedCheckingText","useHeldSave","useSeedEdits","useCurrencySetup","ZONE_COUNTRY_OPTIONS","STRIPE_SHIPPING_COUNTRY_CODES","sort","a","b","zoneCountryLabel","localeCompare","code","CHECKOUT_SHIPPING_COUNTRY_NAMES","ShippingSettingsCard","props","current","hostId","firestore","enqueueSnackbar","data","store","status","storeStatus","fromCache","storeFromCache","listen","storeListen","form","shipping","values","checking","unreadable","user","carrier","setCarrier","available","services","live","encodeURIComponent","then","response","ok","json","answer","Boolean","catch","undefined","update","patch","edit","rates","fxRates","storeBase","storeBaseCurrency","otherCurrencies","otherStoreCurrencies","currencies","updateZone","index","zones","removed","splice","filter","rate","zoneId","id","createResourceUid","name","countries","updateRate","next","kind","key","Object","keys","updateRateCurrency","field","raw","major","parseMajorInput","map","withCurrencyAmount","majorToMinor","handleSave","written","edits","verdict","subject","merge","message","variant","persist","settle","coverage","summarizeShippingCoverage","words","describeShippingCoverage","addRestOfWorldZone","length","usd","cents","String","trim","Math","round","Number","held","onRefused","header","help","anchor","contentGutterX","contentGutterY","spacing","zone","direction","label","value","onChange","event","target","size","sx","width","multiple","flex","minWidth","options","filterSelectedOptions","getOptionLabel","_event","at","renderInput","params","placeholder","color","onClick","alignSelf","select","join","error","helperText","CarrierRateFields","fallbacks","other","amountCents","slotProps","htmlInput","inputMode","freeOverCents","RateCurrencyFields","base","pl","tiers","tier","tierIndex","upTo","_item","itemIndex","RateConditionFields","onCurrencyChange","disabled","control","checked","localPickup","unserved","severity","action","hasRestOfWorldZone","headline","detail","note","asks","some","rateHasConditions","dirty","saving","press","role","displayName","set","picked","Set","flexWrap","columnGap","service","has","serviceKey","markupPct","pct","isFinite","min","handlingCents","dollars","fallbackRateId","fallback","NO_CONDITIONS","minSubtotalCents","maxSubtotalCents","minSubtotalByCurrency","maxSubtotalByCurrency","minGrams","maxGrams","byWeight","adding","setAdding","basis","max","grams","keep","minMax","alignItems","entry","defaultValue","minorToInput","onBlur","converted","minor","amountMinorIn","amountsByCurrency","freeOverByCurrency"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,YAAYA,WAAW,eAAc;AACrC,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,UAAU,EACVC,YAAY,EACZC,MAAM,EACNC,OAAO,EACPC,gBAAgB,EAChBC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SA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