@final-commerce/common 2.9.1 → 2.9.2-preprod.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  BookingResourceStatus: () => BookingResourceStatus,
37
37
  BookingRulesError: () => BookingRulesError,
38
38
  BookingType: () => BookingType,
39
+ CANADA_PROVINCES: () => CANADA_PROVINCES,
39
40
  CONDITION_OPERATORS: () => CONDITION_OPERATORS,
40
41
  COUNTRY_CURRENCIES: () => COUNTRY_CURRENCIES,
41
42
  CURRENCY_CONFIG: () => CURRENCY_CONFIG,
@@ -52,6 +53,7 @@ __export(index_exports, {
52
53
  DualWriteStrategy: () => DualWriteStrategy,
53
54
  EUFixedRates: () => EUFixedRates,
54
55
  EUROPE: () => EUROPE,
56
+ EVERYWHERE_KEY: () => EVERYWHERE_KEY,
55
57
  EXPENSE_DEFAULT_CATEGORIES: () => EXPENSE_DEFAULT_CATEGORIES,
56
58
  EXPENSE_NAME_MAX_LENGTH: () => EXPENSE_NAME_MAX_LENGTH,
57
59
  EXPENSE_PAYMENT_METHOD_PRESETS: () => EXPENSE_PAYMENT_METHOD_PRESETS,
@@ -102,6 +104,7 @@ __export(index_exports, {
102
104
  ResidualPaymentMethod: () => ResidualPaymentMethod,
103
105
  ResidualStatus: () => ResidualStatus,
104
106
  ResourceAvailabilityState: () => ResourceAvailabilityState,
107
+ SHIPPING_COUNTRIES: () => SHIPPING_COUNTRIES,
105
108
  STATE_SCHEMA: () => STATE_SCHEMA,
106
109
  STRIPE_SUPPORTED_COUNTRIES: () => STRIPE_SUPPORTED_COUNTRIES,
107
110
  SYSTEM_FAMILIES: () => SYSTEM_FAMILIES,
@@ -110,6 +113,12 @@ __export(index_exports, {
110
113
  SYSTEM_UNIT_IDS: () => SYSTEM_UNIT_IDS,
111
114
  SalesLineAction: () => SalesLineAction,
112
115
  SalesLineSourceArray: () => SalesLineSourceArray,
116
+ ShippingChannel: () => ShippingChannel,
117
+ ShippingNoOptionReason: () => ShippingNoOptionReason,
118
+ ShippingOptionType: () => ShippingOptionType,
119
+ ShippingRateType: () => ShippingRateType,
120
+ ShippingZoneError: () => ShippingZoneError,
121
+ ShippingZoneKind: () => ShippingZoneKind,
113
122
  StationStatus: () => StationStatus,
114
123
  StripeCurrencyCode: () => StripeCurrencyCode,
115
124
  StripeStatus: () => StripeStatus,
@@ -117,6 +126,7 @@ __export(index_exports, {
117
126
  TopMetericsSort: () => TopMetericsSort,
118
127
  UserTypes: () => UserTypes,
119
128
  addAmounts: () => addAmounts,
129
+ addressPlaceKeys: () => addressPlaceKeys,
120
130
  adyenLegalEntityRequiresStateOrProvince: () => adyenLegalEntityRequiresStateOrProvince,
121
131
  adyenRequiresJobTitle: () => adyenRequiresJobTitle,
122
132
  adyenStoreRequiresStateOrProvince: () => adyenStoreRequiresStateOrProvince,
@@ -124,6 +134,7 @@ __export(index_exports, {
124
134
  adyenTaxNumberFormat: () => adyenTaxNumberFormat,
125
135
  amountToString: () => amountToString,
126
136
  ancestorChain: () => ancestorChain,
137
+ applyAssignment: () => applyAssignment,
127
138
  assertUnitSane: () => assertUnitSane,
128
139
  availableIn: () => availableIn,
129
140
  baseFor: () => baseFor,
@@ -149,6 +160,7 @@ __export(index_exports, {
149
160
  convertFixedFeeToLocalCurrency: () => convertFixedFeeToLocalCurrency,
150
161
  createAmount: () => createAmount,
151
162
  crossAxisRuleApplies: () => crossAxisRuleApplies,
163
+ currentAssignees: () => currentAssignees,
152
164
  deriveDisplayState: () => deriveDisplayState,
153
165
  deriveFamilyCode: () => deriveFamilyCode,
154
166
  deriveUnitId: () => deriveUnitId,
@@ -195,30 +207,46 @@ __export(index_exports, {
195
207
  isSystemFamilyCode: () => isSystemFamilyCode,
196
208
  isValidQuantity: () => isValidQuantity,
197
209
  isWhole: () => isWhole,
210
+ lineStockMoves: () => lineStockMoves,
211
+ listCountries: () => listCountries,
212
+ listProvinces: () => listProvinces,
213
+ listShippingCountries: () => listShippingCountries,
198
214
  mapToLegacyStatus: () => mapToLegacyStatus,
199
215
  maxPrecisionFor: () => maxPrecisionFor,
200
216
  mergeFragment: () => mergeFragment,
201
217
  modifiersSellable: () => modifiersSellable,
202
218
  multiplyAmount: () => multiplyAmount,
219
+ normalizeAddress: () => normalizeAddress,
220
+ normalizeCityKey: () => normalizeCityKey,
221
+ normalizeCountry: () => normalizeCountry,
203
222
  normalizeMongoIdString: () => normalizeMongoIdString,
223
+ normalizePostCode: () => normalizePostCode,
224
+ normalizeProvince: () => normalizeProvince,
204
225
  occupancyIn: () => occupancyIn,
226
+ orderAssignments: () => orderAssignments,
205
227
  parseAmountToMinorUnits: () => parseAmountToMinorUnits,
206
228
  parseCurrencyCode: () => parseCurrencyCode,
207
229
  parseStripeCurrencyCode: () => parseStripeCurrencyCode,
230
+ placeKey: () => placeKey,
208
231
  planWindow: () => planWindow,
209
232
  poolDemand: () => poolDemand,
210
233
  poolOf: () => poolOf,
211
234
  poolShortfall: () => poolShortfall,
212
235
  poolStockAt: () => poolStockAt,
236
+ postCodeMatchesProvince: () => postCodeMatchesProvince,
213
237
  presentAt: () => presentAt,
238
+ priceForTotal: () => priceForTotal,
239
+ provincesForPostCode: () => provincesForPostCode,
214
240
  removeFragment: () => removeFragment,
215
241
  resolveFamily: () => resolveFamily,
216
242
  resolveModifiersForProduct: () => resolveModifiersForProduct,
243
+ resolveShipping: () => resolveShipping,
217
244
  resolveTemplate: () => resolveTemplate,
218
245
  resolveUnit: () => resolveUnit,
219
246
  roundToPrecision: () => roundToPrecision,
220
247
  sameFamily: () => sameFamily,
221
248
  setOrderState: () => setOrderState,
249
+ shipsToCountry: () => shipsToCountry,
222
250
  shopDayKey: () => shopDayKey,
223
251
  shopDayRange: () => shopDayRange,
224
252
  signReportForDisplay: () => signReportForDisplay,
@@ -230,6 +258,7 @@ __export(index_exports, {
230
258
  validateConfig: () => validateConfig,
231
259
  validateFragmentCompatibility: () => validateFragmentCompatibility,
232
260
  validateOrderStatuses: () => validateOrderStatuses,
261
+ validateShippingZone: () => validateShippingZone,
233
262
  violatesFinancialInvariant: () => violatesFinancialInvariant,
234
263
  windowEndsAt: () => windowEndsAt,
235
264
  withinPresence: () => withinPresence
@@ -438,6 +467,7 @@ var OrderPlatform = /* @__PURE__ */ ((OrderPlatform2) => {
438
467
  OrderPlatform2["POS"] = "in-store";
439
468
  OrderPlatform2["WOO_COMMERCE"] = "woo-commerce";
440
469
  OrderPlatform2["PUBLIC_API"] = "public-api";
470
+ OrderPlatform2["ONLINE_STORE"] = "online-store";
441
471
  return OrderPlatform2;
442
472
  })(OrderPlatform || {});
443
473
  var CustomerPlatform = /* @__PURE__ */ ((CustomerPlatform2) => {
@@ -734,6 +764,50 @@ var ResourceAvailabilityState = /* @__PURE__ */ ((ResourceAvailabilityState2) =>
734
764
  return ResourceAvailabilityState2;
735
765
  })(ResourceAvailabilityState || {});
736
766
 
767
+ // enums/shipping.enum.ts
768
+ var ShippingZoneKind = /* @__PURE__ */ ((ShippingZoneKind2) => {
769
+ ShippingZoneKind2["COUNTRY"] = "country";
770
+ ShippingZoneKind2["PROVINCE"] = "province";
771
+ ShippingZoneKind2["CITY"] = "city";
772
+ ShippingZoneKind2["EVERYWHERE"] = "everywhere";
773
+ return ShippingZoneKind2;
774
+ })(ShippingZoneKind || {});
775
+ var ShippingOptionType = /* @__PURE__ */ ((ShippingOptionType2) => {
776
+ ShippingOptionType2["SHIP"] = "ship";
777
+ ShippingOptionType2["PICKUP"] = "pickup";
778
+ return ShippingOptionType2;
779
+ })(ShippingOptionType || {});
780
+ var ShippingRateType = /* @__PURE__ */ ((ShippingRateType2) => {
781
+ ShippingRateType2["FLAT"] = "flat";
782
+ return ShippingRateType2;
783
+ })(ShippingRateType || {});
784
+ var ShippingChannel = /* @__PURE__ */ ((ShippingChannel2) => {
785
+ ShippingChannel2["WEB"] = "web";
786
+ ShippingChannel2["POS"] = "pos";
787
+ return ShippingChannel2;
788
+ })(ShippingChannel || {});
789
+ var ShippingNoOptionReason = /* @__PURE__ */ ((ShippingNoOptionReason2) => {
790
+ ShippingNoOptionReason2["INCOMPLETE"] = "INCOMPLETE";
791
+ ShippingNoOptionReason2["ADDRESS_MISMATCH"] = "ADDRESS_MISMATCH";
792
+ ShippingNoOptionReason2["NO_COVERAGE"] = "NO_COVERAGE";
793
+ ShippingNoOptionReason2["BLOCKED"] = "BLOCKED";
794
+ ShippingNoOptionReason2["NO_OPTION"] = "NO_OPTION";
795
+ return ShippingNoOptionReason2;
796
+ })(ShippingNoOptionReason || {});
797
+ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
798
+ ShippingZoneError2["NO_PLACES"] = "NO_PLACES";
799
+ ShippingZoneError2["INVALID_PLACE"] = "INVALID_PLACE";
800
+ ShippingZoneError2["DUPLICATE_PLACE"] = "DUPLICATE_PLACE";
801
+ ShippingZoneError2["NO_WEBSITE_OPTION"] = "NO_WEBSITE_OPTION";
802
+ ShippingZoneError2["INVALID_PRICE"] = "INVALID_PRICE";
803
+ ShippingZoneError2["INVALID_DAYS"] = "INVALID_DAYS";
804
+ ShippingZoneError2["INVALID_TIERS"] = "INVALID_TIERS";
805
+ ShippingZoneError2["NO_CHANNEL"] = "NO_CHANNEL";
806
+ ShippingZoneError2["PICKUP_WITHOUT_STORE"] = "PICKUP_WITHOUT_STORE";
807
+ ShippingZoneError2["MISSING_NAME"] = "MISSING_NAME";
808
+ return ShippingZoneError2;
809
+ })(ShippingZoneError || {});
810
+
737
811
  // enums/sales-line.enum.ts
738
812
  var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
739
813
  SalesLineAction2["SALE"] = "sale";
@@ -1932,6 +2006,48 @@ function compositeReservationMismatches(order) {
1932
2006
  });
1933
2007
  }
1934
2008
 
2009
+ // utils/line-stock-moves.util.ts
2010
+ function lineStockMoves(item, quantity, reservations = []) {
2011
+ const sign = Math.sign(quantity);
2012
+ const pool = (stockVariantId) => stockVariantId ? { stockVariantId: stockVariantId.toString() } : {};
2013
+ if (!item.components?.length)
2014
+ return [
2015
+ {
2016
+ productId: item.productId.toString(),
2017
+ variantId: item.variantId.toString(),
2018
+ fields: {
2019
+ quantity,
2020
+ ...item.stockQuantity != null ? { stockQuantity: sign * item.stockQuantity, unitId: item.unitId?.toString() } : {},
2021
+ ...pool(item.stockVariantId)
2022
+ }
2023
+ }
2024
+ ];
2025
+ const booked = new Set(
2026
+ reservations.filter((reservation) => reservation.lineItemInternalId && reservation.lineItemInternalId === item.internalId).map((reservation) => reservation.componentIndex)
2027
+ );
2028
+ return item.components.flatMap((component, componentIndex) => {
2029
+ if (booked.has(componentIndex)) return [];
2030
+ if (component.unitId && component.stockQuantity == null)
2031
+ throw new Error(
2032
+ `Composite ${item.productId?.toString()} component ${component.variantId.toString()} is sold in ${component.unitId.toString()} but carries no stockQuantity`
2033
+ );
2034
+ return [
2035
+ {
2036
+ productId: component.productId.toString(),
2037
+ variantId: component.variantId.toString(),
2038
+ componentIndex,
2039
+ fields: {
2040
+ quantity: component.quantity * quantity,
2041
+ ...component.stockQuantity != null ? { stockQuantity: component.stockQuantity * quantity, unitId: component.unitId?.toString() } : {},
2042
+ ...pool(component.stockVariantId),
2043
+ ...item.productId ? { compositeProductId: item.productId.toString() } : {},
2044
+ ...item.name ? { compositeName: item.name } : {}
2045
+ }
2046
+ }
2047
+ ];
2048
+ });
2049
+ }
2050
+
1935
2051
  // units/family-code.ts
1936
2052
  var MAX_SLUG_LENGTH = 32;
1937
2053
  var FALLBACK_SLUG = "family";
@@ -3080,6 +3196,39 @@ function isInCart(order) {
3080
3196
  return (order.status ?? "").trim().toLowerCase() === "in-cart";
3081
3197
  }
3082
3198
 
3199
+ // order-state-machine/assigned-users.ts
3200
+ function orderAssignments(order) {
3201
+ const value = order?.assignedUser;
3202
+ if (Array.isArray(value)) return value.filter((entry) => entry?.userId);
3203
+ return value?.userId ? [value] : [];
3204
+ }
3205
+ var sameLabel = (entry, label) => (entry.label ?? null) === (label ?? null);
3206
+ function currentAssignees(order, label) {
3207
+ return orderAssignments(order).filter(
3208
+ (entry) => !entry.unassignedAt && (label === void 0 || sameLabel(entry, label))
3209
+ );
3210
+ }
3211
+ function applyAssignment(order, change) {
3212
+ const { userId, at } = change;
3213
+ const label = change.label?.trim() || null;
3214
+ const entries = orderAssignments(order);
3215
+ if (userId === null) {
3216
+ const all = change.label === void 0;
3217
+ return entries.map(
3218
+ (entry) => !entry.unassignedAt && (all || sameLabel(entry, label)) ? { ...entry, unassignedAt: at } : entry
3219
+ );
3220
+ }
3221
+ if (entries.some((entry) => !entry.unassignedAt && entry.userId === userId && sameLabel(entry, label))) {
3222
+ return entries;
3223
+ }
3224
+ return [
3225
+ ...entries.map(
3226
+ (entry) => !entry.unassignedAt && sameLabel(entry, label) ? { ...entry, unassignedAt: at } : entry
3227
+ ),
3228
+ { userId, assignedAt: at, ...label ? { label } : {} }
3229
+ ];
3230
+ }
3231
+
3083
3232
  // order-state-machine/order-status.ts
3084
3233
  var STATUS_KEY = /^[a-z0-9][a-z0-9_-]*$/;
3085
3234
  function validateOrderStatuses(statuses) {
@@ -3835,6 +3984,334 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
3835
3984
  }
3836
3985
  var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
3837
3986
 
3987
+ // shipping/fold-text.ts
3988
+ function foldText(value) {
3989
+ return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9]+/g, " ").trim();
3990
+ }
3991
+
3992
+ // shipping/countries.ts
3993
+ var NOT_COUNTRIES = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
3994
+ var ALIASES = {
3995
+ canada: "CA",
3996
+ "united states": "US",
3997
+ usa: "US",
3998
+ "united states of america": "US",
3999
+ uk: "GB",
4000
+ "great britain": "GB",
4001
+ england: "GB",
4002
+ uae: "AE",
4003
+ can: "CA",
4004
+ mex: "MX",
4005
+ aus: "AU",
4006
+ gbr: "GB"
4007
+ };
4008
+ var NAME_LOCALES = ["en", "fr"];
4009
+ function regionNames(locale) {
4010
+ try {
4011
+ return new Intl.DisplayNames([locale], { type: "region", fallback: "none" });
4012
+ } catch {
4013
+ return null;
4014
+ }
4015
+ }
4016
+ function canonicalCode(code) {
4017
+ try {
4018
+ return new Intl.Locale(`und-${code}`).maximize().region ?? code;
4019
+ } catch {
4020
+ return code;
4021
+ }
4022
+ }
4023
+ function allCodes() {
4024
+ const names = regionNames("en");
4025
+ if (!names) return [];
4026
+ const codes2 = [];
4027
+ for (let a = 65; a <= 90; a++) {
4028
+ for (let b = 65; b <= 90; b++) {
4029
+ const code = String.fromCharCode(a, b);
4030
+ if (!NOT_COUNTRIES.has(code) && names.of(code) && canonicalCode(code) === code) codes2.push(code);
4031
+ }
4032
+ }
4033
+ return codes2;
4034
+ }
4035
+ var lookup = null;
4036
+ var codes = null;
4037
+ function countryCodes() {
4038
+ codes ??= allCodes();
4039
+ return codes;
4040
+ }
4041
+ function countryLookup() {
4042
+ if (lookup) return lookup;
4043
+ lookup = new Map(Object.entries(ALIASES));
4044
+ for (const locale of NAME_LOCALES) {
4045
+ const names = regionNames(locale);
4046
+ if (!names) continue;
4047
+ for (const code of countryCodes()) {
4048
+ const name = names.of(code);
4049
+ if (name) lookup.set(foldText(name), code);
4050
+ }
4051
+ }
4052
+ return lookup;
4053
+ }
4054
+ function normalizeCountry(value) {
4055
+ const text = (value ?? "").trim();
4056
+ if (!text) return void 0;
4057
+ const upper = text.toUpperCase();
4058
+ if (upper.length === 2) {
4059
+ if (NOT_COUNTRIES.has(upper)) return void 0;
4060
+ if (countryCodes().length === 0) return /^[A-Z]{2}$/.test(upper) ? upper : void 0;
4061
+ const code = canonicalCode(upper);
4062
+ if (countryCodes().includes(code)) return code;
4063
+ }
4064
+ return countryLookup().get(foldText(text));
4065
+ }
4066
+ function listCountries(locale = "en") {
4067
+ const names = regionNames(locale) ?? regionNames("en");
4068
+ return countryCodes().map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, locale));
4069
+ }
4070
+ var SHIPPING_COUNTRIES = ["CA"];
4071
+ function shipsToCountry(code) {
4072
+ return !!code && SHIPPING_COUNTRIES.includes(code);
4073
+ }
4074
+ function listShippingCountries(locale = "en") {
4075
+ const names = regionNames(locale) ?? regionNames("en");
4076
+ return SHIPPING_COUNTRIES.map((code) => ({ code, name: names?.of(code) ?? code })).sort(
4077
+ (a, b) => a.name.localeCompare(b.name, locale)
4078
+ );
4079
+ }
4080
+
4081
+ // shipping/provinces.ts
4082
+ var CANADA_PROVINCES = [
4083
+ { code: "AB", name: "Alberta", nameFr: "Alberta", postalLetters: ["T"] },
4084
+ { code: "BC", name: "British Columbia", nameFr: "Colombie-Britannique", postalLetters: ["V"] },
4085
+ { code: "MB", name: "Manitoba", nameFr: "Manitoba", postalLetters: ["R"] },
4086
+ { code: "NB", name: "New Brunswick", nameFr: "Nouveau-Brunswick", postalLetters: ["E"] },
4087
+ {
4088
+ code: "NL",
4089
+ name: "Newfoundland and Labrador",
4090
+ nameFr: "Terre-Neuve-et-Labrador",
4091
+ postalLetters: ["A"],
4092
+ aliases: ["NF", "LB", "Newfoundland", "Labrador"]
4093
+ },
4094
+ { code: "NS", name: "Nova Scotia", nameFr: "Nouvelle-\xC9cosse", postalLetters: ["B"] },
4095
+ { code: "NT", name: "Northwest Territories", nameFr: "Territoires du Nord-Ouest", postalLetters: ["X"] },
4096
+ { code: "NU", name: "Nunavut", nameFr: "Nunavut", postalLetters: ["X"] },
4097
+ { code: "ON", name: "Ontario", nameFr: "Ontario", postalLetters: ["K", "L", "M", "N", "P"] },
4098
+ {
4099
+ code: "PE",
4100
+ name: "Prince Edward Island",
4101
+ nameFr: "\xCEle-du-Prince-\xC9douard",
4102
+ postalLetters: ["C"],
4103
+ aliases: ["PEI"]
4104
+ },
4105
+ { code: "QC", name: "Quebec", nameFr: "Qu\xE9bec", postalLetters: ["G", "H", "J"], aliases: ["PQ"] },
4106
+ { code: "SK", name: "Saskatchewan", nameFr: "Saskatchewan", postalLetters: ["S"] },
4107
+ { code: "YT", name: "Yukon", nameFr: "Yukon", postalLetters: ["Y"], aliases: ["YK"] }
4108
+ ];
4109
+ var PROVINCES_BY_COUNTRY = { CA: CANADA_PROVINCES };
4110
+ var lookups = /* @__PURE__ */ new Map();
4111
+ function provinceLookup(country) {
4112
+ const provinces = PROVINCES_BY_COUNTRY[country];
4113
+ if (!provinces) return void 0;
4114
+ let lookup2 = lookups.get(country);
4115
+ if (!lookup2) {
4116
+ lookup2 = /* @__PURE__ */ new Map();
4117
+ for (const p of provinces) {
4118
+ for (const label of [p.code, p.name, p.nameFr, ...p.aliases ?? []]) lookup2.set(foldText(label), p.code);
4119
+ }
4120
+ lookups.set(country, lookup2);
4121
+ }
4122
+ return lookup2;
4123
+ }
4124
+ function normalizeProvince(country, value) {
4125
+ if (!country || !value?.trim()) return void 0;
4126
+ return provinceLookup(country)?.get(foldText(value));
4127
+ }
4128
+ function listProvinces(country) {
4129
+ return PROVINCES_BY_COUNTRY[country] ?? [];
4130
+ }
4131
+ function provincesForPostCode(country, postCode) {
4132
+ const letter = postCode?.charAt(0);
4133
+ if (!country || !letter) return [];
4134
+ return listProvinces(country).filter((p) => p.postalLetters.includes(letter)).map((p) => p.code);
4135
+ }
4136
+
4137
+ // shipping/normalize.ts
4138
+ var EVERYWHERE_KEY = "*";
4139
+ function normalizeCityKey(value) {
4140
+ const words = foldText(value ?? "").split(" ").filter(Boolean).map((word) => word === "saint" ? "st" : word === "sainte" ? "ste" : word);
4141
+ return words.length ? words.join("") : void 0;
4142
+ }
4143
+ function normalizePostCode(value) {
4144
+ const compact = (value ?? "").replace(/[^0-9a-z]/gi, "").toUpperCase();
4145
+ return compact || void 0;
4146
+ }
4147
+ function normalizeAddress(address) {
4148
+ if (!address) return {};
4149
+ const country = normalizeCountry(address.country);
4150
+ const postCode = normalizePostCode(address.postCode ?? address.postalCode ?? address.zip);
4151
+ const fromPostCode = provincesForPostCode(country, postCode);
4152
+ const province = normalizeProvince(country, address.state ?? address.province) ?? (fromPostCode.length === 1 ? fromPostCode[0] : void 0);
4153
+ return { country, province, cityKey: normalizeCityKey(address.city), postCode };
4154
+ }
4155
+ function postCodeMatchesProvince(address) {
4156
+ const candidates = provincesForPostCode(address.country, address.postCode);
4157
+ if (!address.province || candidates.length === 0) return true;
4158
+ return candidates.includes(address.province);
4159
+ }
4160
+ function placeKey(place) {
4161
+ const country = normalizeCountry(place.country);
4162
+ if (!country) return void 0;
4163
+ if (!place.province) return country;
4164
+ const province = normalizeProvince(country, place.province);
4165
+ if (!province) return void 0;
4166
+ if (!place.city) return `${country}-${province}`;
4167
+ const city = normalizeCityKey(place.city);
4168
+ return city ? `${country}-${province}/${city}` : void 0;
4169
+ }
4170
+ function addressPlaceKeys(address) {
4171
+ const keys = [];
4172
+ if (address.country && address.province && address.cityKey) {
4173
+ keys.push(`${address.country}-${address.province}/${address.cityKey}`);
4174
+ }
4175
+ if (address.country && address.province) keys.push(`${address.country}-${address.province}`);
4176
+ if (address.country) keys.push(address.country);
4177
+ keys.push(EVERYWHERE_KEY);
4178
+ return keys;
4179
+ }
4180
+
4181
+ // shipping/resolve.ts
4182
+ function resolveShipping({ zones, address, itemsTotal, channel }) {
4183
+ const shipsToCountries = countriesShippedTo(zones);
4184
+ const none = (reason, zone2) => ({
4185
+ zoneId: zone2?.id ?? null,
4186
+ options: [],
4187
+ reason,
4188
+ message: zone2?.message?.trim() || null,
4189
+ shipsToCountries
4190
+ });
4191
+ const normalized = normalizeAddress(address);
4192
+ if (!normalized.country) return none("INCOMPLETE" /* INCOMPLETE */);
4193
+ if (!shipsToCountry(normalized.country)) return none("NO_COVERAGE" /* NO_COVERAGE */);
4194
+ if (!postCodeMatchesProvince(normalized)) return none("ADDRESS_MISMATCH" /* ADDRESS_MISMATCH */);
4195
+ const zone = findZone(zones, addressPlaceKeys(normalized));
4196
+ if (!zone) return none("NO_COVERAGE" /* NO_COVERAGE */);
4197
+ const offered = zone.options.filter((option) => isOffered(option, zone, channel));
4198
+ if (offered.length === 0) {
4199
+ return none(zone.ships ? "NO_OPTION" /* NO_OPTION */ : "BLOCKED" /* BLOCKED */, zone);
4200
+ }
4201
+ const quotes = offered.map((option) => quote(option, zone.id, itemsTotal));
4202
+ const ship = quotes.filter((q) => q.type === "ship" /* SHIP */).sort((a, b) => a.amount - b.amount);
4203
+ const pickup = quotes.filter((q) => q.type === "pickup" /* PICKUP */).sort((a, b) => a.amount - b.amount);
4204
+ return {
4205
+ zoneId: zone.id,
4206
+ options: [...ship, ...pickup],
4207
+ reason: null,
4208
+ message: zone.ships ? null : zone.message?.trim() || null,
4209
+ shipsToCountries
4210
+ };
4211
+ }
4212
+ function findZone(zones, keys) {
4213
+ const byKey = /* @__PURE__ */ new Map();
4214
+ for (const zone of zones) {
4215
+ for (const key of zoneKeys(zone)) if (!byKey.has(key)) byKey.set(key, zone);
4216
+ }
4217
+ for (const key of keys) {
4218
+ const zone = byKey.get(key);
4219
+ if (zone) return zone;
4220
+ }
4221
+ return void 0;
4222
+ }
4223
+ function zoneKeys(zone) {
4224
+ if (zone.kind === "everywhere" /* EVERYWHERE */) return [EVERYWHERE_KEY];
4225
+ return zone.places.map(placeKey).filter((key) => Boolean(key));
4226
+ }
4227
+ function isOffered(option, zone, channel) {
4228
+ if (!option.channels.some((c) => c === channel)) return false;
4229
+ if (option.type === "pickup" /* PICKUP */) return channel !== "pos" /* POS */;
4230
+ return zone.ships;
4231
+ }
4232
+ function priceForTotal(option, itemsTotal) {
4233
+ const tiers = [...option.priceByTotal ?? []].sort((a, b) => a.from - b.from);
4234
+ let price = option.price;
4235
+ for (const tier of tiers) if (itemsTotal >= tier.from) price = tier.price;
4236
+ if (option.freeOver != null && itemsTotal >= option.freeOver) return 0;
4237
+ return price;
4238
+ }
4239
+ function quote(option, zoneId, itemsTotal) {
4240
+ const amount = priceForTotal(option, itemsTotal);
4241
+ const freeOver = option.freeOver ?? null;
4242
+ return {
4243
+ optionId: option.id,
4244
+ zoneId,
4245
+ type: option.type,
4246
+ name: option.name?.trim() || null,
4247
+ amount,
4248
+ amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
4249
+ minDays: option.minDays ?? null,
4250
+ maxDays: option.maxDays ?? null,
4251
+ outletId: option.outletId ?? null
4252
+ };
4253
+ }
4254
+ function countriesShippedTo(zones) {
4255
+ const countries = /* @__PURE__ */ new Set();
4256
+ for (const zone of zones) {
4257
+ if (!zone.ships) continue;
4258
+ for (const key of zoneKeys(zone)) {
4259
+ if (key !== EVERYWHERE_KEY && shipsToCountry(key.slice(0, 2))) countries.add(key.slice(0, 2));
4260
+ }
4261
+ }
4262
+ return [...countries].sort();
4263
+ }
4264
+
4265
+ // shipping/validate.ts
4266
+ function validateShippingZone(zone) {
4267
+ const problems = [...placeProblems(zone)];
4268
+ for (const option of zone.options) problems.push(...optionProblems(option));
4269
+ const reachesWebsite = zone.options.some((option) => option.channels.includes("web" /* WEB */));
4270
+ if (zone.ships && !reachesWebsite) problems.push({ code: "NO_WEBSITE_OPTION" /* NO_WEBSITE_OPTION */ });
4271
+ return problems;
4272
+ }
4273
+ function placeProblems(zone) {
4274
+ if (zone.kind === "everywhere" /* EVERYWHERE */) {
4275
+ return zone.places.length ? [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }] : [];
4276
+ }
4277
+ if (zone.places.length === 0) return [{ code: "NO_PLACES" /* NO_PLACES */ }];
4278
+ if (!zone.places.every((place) => fitsKind(place, zone.kind))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
4279
+ const keys = zone.places.map(placeKey);
4280
+ if (keys.some((key) => !key || !shipsToCountry(key.slice(0, 2)))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
4281
+ if (new Set(keys).size !== keys.length) return [{ code: "DUPLICATE_PLACE" /* DUPLICATE_PLACE */ }];
4282
+ return [];
4283
+ }
4284
+ function fitsKind(place, kind) {
4285
+ const hasProvince = Boolean(place.province?.trim());
4286
+ const hasCity = Boolean(place.city?.trim());
4287
+ if (kind === "country" /* COUNTRY */) return !hasProvince && !hasCity;
4288
+ if (kind === "province" /* PROVINCE */) return hasProvince && !hasCity;
4289
+ if (kind === "city" /* CITY */) return hasProvince && hasCity;
4290
+ return false;
4291
+ }
4292
+ var isAmount = (value) => Number.isInteger(value) && value >= 0;
4293
+ var isDays = (value) => value == null || isAmount(value);
4294
+ function optionProblems(option) {
4295
+ const problems = [];
4296
+ const isPickup = option.type === "pickup" /* PICKUP */;
4297
+ if (!isAmount(option.price) || option.freeOver != null && !isAmount(option.freeOver)) {
4298
+ problems.push("INVALID_PRICE" /* INVALID_PRICE */);
4299
+ }
4300
+ if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
4301
+ if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
4302
+ problems.push("INVALID_DAYS" /* INVALID_DAYS */);
4303
+ }
4304
+ if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
4305
+ if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
4306
+ if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
4307
+ return problems.map((code) => ({ code, optionId: option.id }));
4308
+ }
4309
+ function tiersAreValid(option) {
4310
+ const tiers = option.priceByTotal ?? [];
4311
+ const froms = tiers.map((tier) => tier.from);
4312
+ return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
4313
+ }
4314
+
3838
4315
  // constants/adyen.constants.ts
3839
4316
  var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
3840
4317
  function isAdyenRolloutCountry(alpha2) {
@@ -3884,6 +4361,27 @@ var BNPL_SKIP_REASON = {
3884
4361
  NO_BUSINESS_LINE: "no_business_line"
3885
4362
  };
3886
4363
 
4364
+ // pos-types/active/ProcessorType.ts
4365
+ var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
4366
+ ProcessorType2["FINAL_PAY"] = "Terminal";
4367
+ ProcessorType2["TAP_TO_PAY"] = "TapToPay";
4368
+ ProcessorType2["MOTO"] = "Moto";
4369
+ ProcessorType2["CLOUD"] = "Cloud";
4370
+ ProcessorType2["BLUETOOTH"] = "Bluetooth";
4371
+ ProcessorType2["CASH"] = "Cash";
4372
+ ProcessorType2["CUSTOM_PAY"] = "CustomPay";
4373
+ ProcessorType2["VENDARA"] = "Vendara";
4374
+ ProcessorType2["REDEEM"] = "Redeem";
4375
+ ProcessorType2["INTEGRATION"] = "Integration";
4376
+ ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
4377
+ ProcessorType2["ONLINE_PAYMENT"] = "OnlinePayment";
4378
+ ProcessorType2["EXTERNAL"] = "External";
4379
+ return ProcessorType2;
4380
+ })(ProcessorType || {});
4381
+
4382
+ // constants/payment-channel.constants.ts
4383
+ var PAYMENT_CHANNELS = ["inPerson", "online"];
4384
+
3887
4385
  // constants/expense.constants.ts
3888
4386
  var EXPENSE_PAYMENT_METHOD_PRESETS = [
3889
4387
  "Cash",
@@ -3907,26 +4405,6 @@ var EXPENSE_DEFAULT_CATEGORIES = [
3907
4405
  { key: "vehicle-fuel", name: "Vehicle & fuel" },
3908
4406
  { key: "other", name: "Other" }
3909
4407
  ];
3910
-
3911
- // pos-types/active/ProcessorType.ts
3912
- var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
3913
- ProcessorType2["FINAL_PAY"] = "Terminal";
3914
- ProcessorType2["TAP_TO_PAY"] = "TapToPay";
3915
- ProcessorType2["MOTO"] = "Moto";
3916
- ProcessorType2["CLOUD"] = "Cloud";
3917
- ProcessorType2["BLUETOOTH"] = "Bluetooth";
3918
- ProcessorType2["CASH"] = "Cash";
3919
- ProcessorType2["CUSTOM_PAY"] = "CustomPay";
3920
- ProcessorType2["VENDARA"] = "Vendara";
3921
- ProcessorType2["REDEEM"] = "Redeem";
3922
- ProcessorType2["INTEGRATION"] = "Integration";
3923
- ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
3924
- ProcessorType2["EXTERNAL"] = "External";
3925
- return ProcessorType2;
3926
- })(ProcessorType || {});
3927
-
3928
- // constants/payment-channel.constants.ts
3929
- var PAYMENT_CHANNELS = ["inPerson", "online"];
3930
4408
  // Annotate the CommonJS export names for ESM import in node:
3931
4409
  0 && (module.exports = {
3932
4410
  ADYEN_JOB_TITLE_ASSOCIATION_TYPES,
@@ -3946,6 +4424,7 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
3946
4424
  BookingResourceStatus,
3947
4425
  BookingRulesError,
3948
4426
  BookingType,
4427
+ CANADA_PROVINCES,
3949
4428
  CONDITION_OPERATORS,
3950
4429
  COUNTRY_CURRENCIES,
3951
4430
  CURRENCY_CONFIG,
@@ -3962,6 +4441,7 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
3962
4441
  DualWriteStrategy,
3963
4442
  EUFixedRates,
3964
4443
  EUROPE,
4444
+ EVERYWHERE_KEY,
3965
4445
  EXPENSE_DEFAULT_CATEGORIES,
3966
4446
  EXPENSE_NAME_MAX_LENGTH,
3967
4447
  EXPENSE_PAYMENT_METHOD_PRESETS,
@@ -4012,6 +4492,7 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
4012
4492
  ResidualPaymentMethod,
4013
4493
  ResidualStatus,
4014
4494
  ResourceAvailabilityState,
4495
+ SHIPPING_COUNTRIES,
4015
4496
  STATE_SCHEMA,
4016
4497
  STRIPE_SUPPORTED_COUNTRIES,
4017
4498
  SYSTEM_FAMILIES,
@@ -4020,6 +4501,12 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
4020
4501
  SYSTEM_UNIT_IDS,
4021
4502
  SalesLineAction,
4022
4503
  SalesLineSourceArray,
4504
+ ShippingChannel,
4505
+ ShippingNoOptionReason,
4506
+ ShippingOptionType,
4507
+ ShippingRateType,
4508
+ ShippingZoneError,
4509
+ ShippingZoneKind,
4023
4510
  StationStatus,
4024
4511
  StripeCurrencyCode,
4025
4512
  StripeStatus,
@@ -4027,6 +4514,7 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
4027
4514
  TopMetericsSort,
4028
4515
  UserTypes,
4029
4516
  addAmounts,
4517
+ addressPlaceKeys,
4030
4518
  adyenLegalEntityRequiresStateOrProvince,
4031
4519
  adyenRequiresJobTitle,
4032
4520
  adyenStoreRequiresStateOrProvince,
@@ -4034,6 +4522,7 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
4034
4522
  adyenTaxNumberFormat,
4035
4523
  amountToString,
4036
4524
  ancestorChain,
4525
+ applyAssignment,
4037
4526
  assertUnitSane,
4038
4527
  availableIn,
4039
4528
  baseFor,
@@ -4059,6 +4548,7 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
4059
4548
  convertFixedFeeToLocalCurrency,
4060
4549
  createAmount,
4061
4550
  crossAxisRuleApplies,
4551
+ currentAssignees,
4062
4552
  deriveDisplayState,
4063
4553
  deriveFamilyCode,
4064
4554
  deriveUnitId,
@@ -4105,30 +4595,46 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
4105
4595
  isSystemFamilyCode,
4106
4596
  isValidQuantity,
4107
4597
  isWhole,
4598
+ lineStockMoves,
4599
+ listCountries,
4600
+ listProvinces,
4601
+ listShippingCountries,
4108
4602
  mapToLegacyStatus,
4109
4603
  maxPrecisionFor,
4110
4604
  mergeFragment,
4111
4605
  modifiersSellable,
4112
4606
  multiplyAmount,
4607
+ normalizeAddress,
4608
+ normalizeCityKey,
4609
+ normalizeCountry,
4113
4610
  normalizeMongoIdString,
4611
+ normalizePostCode,
4612
+ normalizeProvince,
4114
4613
  occupancyIn,
4614
+ orderAssignments,
4115
4615
  parseAmountToMinorUnits,
4116
4616
  parseCurrencyCode,
4117
4617
  parseStripeCurrencyCode,
4618
+ placeKey,
4118
4619
  planWindow,
4119
4620
  poolDemand,
4120
4621
  poolOf,
4121
4622
  poolShortfall,
4122
4623
  poolStockAt,
4624
+ postCodeMatchesProvince,
4123
4625
  presentAt,
4626
+ priceForTotal,
4627
+ provincesForPostCode,
4124
4628
  removeFragment,
4125
4629
  resolveFamily,
4126
4630
  resolveModifiersForProduct,
4631
+ resolveShipping,
4127
4632
  resolveTemplate,
4128
4633
  resolveUnit,
4129
4634
  roundToPrecision,
4130
4635
  sameFamily,
4131
4636
  setOrderState,
4637
+ shipsToCountry,
4132
4638
  shopDayKey,
4133
4639
  shopDayRange,
4134
4640
  signReportForDisplay,
@@ -4140,6 +4646,7 @@ var PAYMENT_CHANNELS = ["inPerson", "online"];
4140
4646
  validateConfig,
4141
4647
  validateFragmentCompatibility,
4142
4648
  validateOrderStatuses,
4649
+ validateShippingZone,
4143
4650
  violatesFinancialInvariant,
4144
4651
  windowEndsAt,
4145
4652
  withinPresence