@final-commerce/common 2.9.0 → 2.9.2-preprod.1

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,
@@ -77,6 +79,7 @@ __export(index_exports, {
77
79
  OtherFixedRates: () => OtherFixedRates,
78
80
  OwnerType: () => OwnerType,
79
81
  PATH_MODES: () => PATH_MODES,
82
+ PAYMENT_CHANNELS: () => PAYMENT_CHANNELS,
80
83
  PAYMENT_STATES: () => PAYMENT_STATES,
81
84
  POS_VALID_INITIAL_STATES: () => POS_VALID_INITIAL_STATES,
82
85
  PaymentMethod: () => PaymentMethod,
@@ -86,6 +89,7 @@ __export(index_exports, {
86
89
  PricingLevel: () => PricingLevel,
87
90
  PricingPlanEnum: () => PricingPlanEnum,
88
91
  PricingRegionEnum: () => PricingRegionEnum,
92
+ ProcessorType: () => ProcessorType,
89
93
  ProductSalesChartStep: () => ProductSalesChartStep,
90
94
  ProductSalesReportCompare: () => ProductSalesReportCompare,
91
95
  ProductStatus: () => ProductStatus,
@@ -108,6 +112,12 @@ __export(index_exports, {
108
112
  SYSTEM_UNIT_IDS: () => SYSTEM_UNIT_IDS,
109
113
  SalesLineAction: () => SalesLineAction,
110
114
  SalesLineSourceArray: () => SalesLineSourceArray,
115
+ ShippingChannel: () => ShippingChannel,
116
+ ShippingNoOptionReason: () => ShippingNoOptionReason,
117
+ ShippingOptionType: () => ShippingOptionType,
118
+ ShippingRateType: () => ShippingRateType,
119
+ ShippingZoneError: () => ShippingZoneError,
120
+ ShippingZoneKind: () => ShippingZoneKind,
111
121
  StationStatus: () => StationStatus,
112
122
  StripeCurrencyCode: () => StripeCurrencyCode,
113
123
  StripeStatus: () => StripeStatus,
@@ -115,6 +125,7 @@ __export(index_exports, {
115
125
  TopMetericsSort: () => TopMetericsSort,
116
126
  UserTypes: () => UserTypes,
117
127
  addAmounts: () => addAmounts,
128
+ addressPlaceKeys: () => addressPlaceKeys,
118
129
  adyenLegalEntityRequiresStateOrProvince: () => adyenLegalEntityRequiresStateOrProvince,
119
130
  adyenRequiresJobTitle: () => adyenRequiresJobTitle,
120
131
  adyenStoreRequiresStateOrProvince: () => adyenStoreRequiresStateOrProvince,
@@ -122,6 +133,7 @@ __export(index_exports, {
122
133
  adyenTaxNumberFormat: () => adyenTaxNumberFormat,
123
134
  amountToString: () => amountToString,
124
135
  ancestorChain: () => ancestorChain,
136
+ applyAssignment: () => applyAssignment,
125
137
  assertUnitSane: () => assertUnitSane,
126
138
  availableIn: () => availableIn,
127
139
  baseFor: () => baseFor,
@@ -147,6 +159,7 @@ __export(index_exports, {
147
159
  convertFixedFeeToLocalCurrency: () => convertFixedFeeToLocalCurrency,
148
160
  createAmount: () => createAmount,
149
161
  crossAxisRuleApplies: () => crossAxisRuleApplies,
162
+ currentAssignees: () => currentAssignees,
150
163
  deriveDisplayState: () => deriveDisplayState,
151
164
  deriveFamilyCode: () => deriveFamilyCode,
152
165
  deriveUnitId: () => deriveUnitId,
@@ -193,25 +206,39 @@ __export(index_exports, {
193
206
  isSystemFamilyCode: () => isSystemFamilyCode,
194
207
  isValidQuantity: () => isValidQuantity,
195
208
  isWhole: () => isWhole,
209
+ lineStockMoves: () => lineStockMoves,
210
+ listCountries: () => listCountries,
211
+ listProvinces: () => listProvinces,
196
212
  mapToLegacyStatus: () => mapToLegacyStatus,
197
213
  maxPrecisionFor: () => maxPrecisionFor,
198
214
  mergeFragment: () => mergeFragment,
199
215
  modifiersSellable: () => modifiersSellable,
200
216
  multiplyAmount: () => multiplyAmount,
217
+ normalizeAddress: () => normalizeAddress,
218
+ normalizeCityKey: () => normalizeCityKey,
219
+ normalizeCountry: () => normalizeCountry,
201
220
  normalizeMongoIdString: () => normalizeMongoIdString,
221
+ normalizePostCode: () => normalizePostCode,
222
+ normalizeProvince: () => normalizeProvince,
202
223
  occupancyIn: () => occupancyIn,
224
+ orderAssignments: () => orderAssignments,
203
225
  parseAmountToMinorUnits: () => parseAmountToMinorUnits,
204
226
  parseCurrencyCode: () => parseCurrencyCode,
205
227
  parseStripeCurrencyCode: () => parseStripeCurrencyCode,
228
+ placeKey: () => placeKey,
206
229
  planWindow: () => planWindow,
207
230
  poolDemand: () => poolDemand,
208
231
  poolOf: () => poolOf,
209
232
  poolShortfall: () => poolShortfall,
210
233
  poolStockAt: () => poolStockAt,
234
+ postCodeMatchesProvince: () => postCodeMatchesProvince,
211
235
  presentAt: () => presentAt,
236
+ priceForTotal: () => priceForTotal,
237
+ provincesForPostCode: () => provincesForPostCode,
212
238
  removeFragment: () => removeFragment,
213
239
  resolveFamily: () => resolveFamily,
214
240
  resolveModifiersForProduct: () => resolveModifiersForProduct,
241
+ resolveShipping: () => resolveShipping,
215
242
  resolveTemplate: () => resolveTemplate,
216
243
  resolveUnit: () => resolveUnit,
217
244
  roundToPrecision: () => roundToPrecision,
@@ -228,6 +255,7 @@ __export(index_exports, {
228
255
  validateConfig: () => validateConfig,
229
256
  validateFragmentCompatibility: () => validateFragmentCompatibility,
230
257
  validateOrderStatuses: () => validateOrderStatuses,
258
+ validateShippingZone: () => validateShippingZone,
231
259
  violatesFinancialInvariant: () => violatesFinancialInvariant,
232
260
  windowEndsAt: () => windowEndsAt,
233
261
  withinPresence: () => withinPresence
@@ -436,6 +464,7 @@ var OrderPlatform = /* @__PURE__ */ ((OrderPlatform2) => {
436
464
  OrderPlatform2["POS"] = "in-store";
437
465
  OrderPlatform2["WOO_COMMERCE"] = "woo-commerce";
438
466
  OrderPlatform2["PUBLIC_API"] = "public-api";
467
+ OrderPlatform2["ONLINE_STORE"] = "online-store";
439
468
  return OrderPlatform2;
440
469
  })(OrderPlatform || {});
441
470
  var CustomerPlatform = /* @__PURE__ */ ((CustomerPlatform2) => {
@@ -732,6 +761,50 @@ var ResourceAvailabilityState = /* @__PURE__ */ ((ResourceAvailabilityState2) =>
732
761
  return ResourceAvailabilityState2;
733
762
  })(ResourceAvailabilityState || {});
734
763
 
764
+ // enums/shipping.enum.ts
765
+ var ShippingZoneKind = /* @__PURE__ */ ((ShippingZoneKind2) => {
766
+ ShippingZoneKind2["COUNTRY"] = "country";
767
+ ShippingZoneKind2["PROVINCE"] = "province";
768
+ ShippingZoneKind2["CITY"] = "city";
769
+ ShippingZoneKind2["EVERYWHERE"] = "everywhere";
770
+ return ShippingZoneKind2;
771
+ })(ShippingZoneKind || {});
772
+ var ShippingOptionType = /* @__PURE__ */ ((ShippingOptionType2) => {
773
+ ShippingOptionType2["SHIP"] = "ship";
774
+ ShippingOptionType2["PICKUP"] = "pickup";
775
+ return ShippingOptionType2;
776
+ })(ShippingOptionType || {});
777
+ var ShippingRateType = /* @__PURE__ */ ((ShippingRateType2) => {
778
+ ShippingRateType2["FLAT"] = "flat";
779
+ return ShippingRateType2;
780
+ })(ShippingRateType || {});
781
+ var ShippingChannel = /* @__PURE__ */ ((ShippingChannel2) => {
782
+ ShippingChannel2["WEB"] = "web";
783
+ ShippingChannel2["POS"] = "pos";
784
+ return ShippingChannel2;
785
+ })(ShippingChannel || {});
786
+ var ShippingNoOptionReason = /* @__PURE__ */ ((ShippingNoOptionReason2) => {
787
+ ShippingNoOptionReason2["INCOMPLETE"] = "INCOMPLETE";
788
+ ShippingNoOptionReason2["ADDRESS_MISMATCH"] = "ADDRESS_MISMATCH";
789
+ ShippingNoOptionReason2["NO_COVERAGE"] = "NO_COVERAGE";
790
+ ShippingNoOptionReason2["BLOCKED"] = "BLOCKED";
791
+ ShippingNoOptionReason2["NO_OPTION"] = "NO_OPTION";
792
+ return ShippingNoOptionReason2;
793
+ })(ShippingNoOptionReason || {});
794
+ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
795
+ ShippingZoneError2["NO_PLACES"] = "NO_PLACES";
796
+ ShippingZoneError2["INVALID_PLACE"] = "INVALID_PLACE";
797
+ ShippingZoneError2["DUPLICATE_PLACE"] = "DUPLICATE_PLACE";
798
+ ShippingZoneError2["NO_WEBSITE_OPTION"] = "NO_WEBSITE_OPTION";
799
+ ShippingZoneError2["INVALID_PRICE"] = "INVALID_PRICE";
800
+ ShippingZoneError2["INVALID_DAYS"] = "INVALID_DAYS";
801
+ ShippingZoneError2["INVALID_TIERS"] = "INVALID_TIERS";
802
+ ShippingZoneError2["NO_CHANNEL"] = "NO_CHANNEL";
803
+ ShippingZoneError2["PICKUP_WITHOUT_STORE"] = "PICKUP_WITHOUT_STORE";
804
+ ShippingZoneError2["MISSING_NAME"] = "MISSING_NAME";
805
+ return ShippingZoneError2;
806
+ })(ShippingZoneError || {});
807
+
735
808
  // enums/sales-line.enum.ts
736
809
  var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
737
810
  SalesLineAction2["SALE"] = "sale";
@@ -1930,6 +2003,48 @@ function compositeReservationMismatches(order) {
1930
2003
  });
1931
2004
  }
1932
2005
 
2006
+ // utils/line-stock-moves.util.ts
2007
+ function lineStockMoves(item, quantity, reservations = []) {
2008
+ const sign = Math.sign(quantity);
2009
+ const pool = (stockVariantId) => stockVariantId ? { stockVariantId: stockVariantId.toString() } : {};
2010
+ if (!item.components?.length)
2011
+ return [
2012
+ {
2013
+ productId: item.productId.toString(),
2014
+ variantId: item.variantId.toString(),
2015
+ fields: {
2016
+ quantity,
2017
+ ...item.stockQuantity != null ? { stockQuantity: sign * item.stockQuantity, unitId: item.unitId?.toString() } : {},
2018
+ ...pool(item.stockVariantId)
2019
+ }
2020
+ }
2021
+ ];
2022
+ const booked = new Set(
2023
+ reservations.filter((reservation) => reservation.lineItemInternalId && reservation.lineItemInternalId === item.internalId).map((reservation) => reservation.componentIndex)
2024
+ );
2025
+ return item.components.flatMap((component, componentIndex) => {
2026
+ if (booked.has(componentIndex)) return [];
2027
+ if (component.unitId && component.stockQuantity == null)
2028
+ throw new Error(
2029
+ `Composite ${item.productId?.toString()} component ${component.variantId.toString()} is sold in ${component.unitId.toString()} but carries no stockQuantity`
2030
+ );
2031
+ return [
2032
+ {
2033
+ productId: component.productId.toString(),
2034
+ variantId: component.variantId.toString(),
2035
+ componentIndex,
2036
+ fields: {
2037
+ quantity: component.quantity * quantity,
2038
+ ...component.stockQuantity != null ? { stockQuantity: component.stockQuantity * quantity, unitId: component.unitId?.toString() } : {},
2039
+ ...pool(component.stockVariantId),
2040
+ ...item.productId ? { compositeProductId: item.productId.toString() } : {},
2041
+ ...item.name ? { compositeName: item.name } : {}
2042
+ }
2043
+ }
2044
+ ];
2045
+ });
2046
+ }
2047
+
1933
2048
  // units/family-code.ts
1934
2049
  var MAX_SLUG_LENGTH = 32;
1935
2050
  var FALLBACK_SLUG = "family";
@@ -3078,6 +3193,39 @@ function isInCart(order) {
3078
3193
  return (order.status ?? "").trim().toLowerCase() === "in-cart";
3079
3194
  }
3080
3195
 
3196
+ // order-state-machine/assigned-users.ts
3197
+ function orderAssignments(order) {
3198
+ const value = order?.assignedUser;
3199
+ if (Array.isArray(value)) return value.filter((entry) => entry?.userId);
3200
+ return value?.userId ? [value] : [];
3201
+ }
3202
+ var sameLabel = (entry, label) => (entry.label ?? null) === (label ?? null);
3203
+ function currentAssignees(order, label) {
3204
+ return orderAssignments(order).filter(
3205
+ (entry) => !entry.unassignedAt && (label === void 0 || sameLabel(entry, label))
3206
+ );
3207
+ }
3208
+ function applyAssignment(order, change) {
3209
+ const { userId, at } = change;
3210
+ const label = change.label?.trim() || null;
3211
+ const entries = orderAssignments(order);
3212
+ if (userId === null) {
3213
+ const all = change.label === void 0;
3214
+ return entries.map(
3215
+ (entry) => !entry.unassignedAt && (all || sameLabel(entry, label)) ? { ...entry, unassignedAt: at } : entry
3216
+ );
3217
+ }
3218
+ if (entries.some((entry) => !entry.unassignedAt && entry.userId === userId && sameLabel(entry, label))) {
3219
+ return entries;
3220
+ }
3221
+ return [
3222
+ ...entries.map(
3223
+ (entry) => !entry.unassignedAt && sameLabel(entry, label) ? { ...entry, unassignedAt: at } : entry
3224
+ ),
3225
+ { userId, assignedAt: at, ...label ? { label } : {} }
3226
+ ];
3227
+ }
3228
+
3081
3229
  // order-state-machine/order-status.ts
3082
3230
  var STATUS_KEY = /^[a-z0-9][a-z0-9_-]*$/;
3083
3231
  function validateOrderStatuses(statuses) {
@@ -3833,6 +3981,321 @@ function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }
3833
3981
  }
3834
3982
  var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
3835
3983
 
3984
+ // shipping/fold-text.ts
3985
+ function foldText(value) {
3986
+ return value.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/&/g, " and ").replace(/[^a-z0-9]+/g, " ").trim();
3987
+ }
3988
+
3989
+ // shipping/countries.ts
3990
+ var NOT_COUNTRIES = /* @__PURE__ */ new Set(["AC", "CP", "CQ", "DG", "EA", "EU", "EZ", "IC", "QO", "TA", "UN", "XA", "XB", "ZZ"]);
3991
+ var ALIASES = {
3992
+ canada: "CA",
3993
+ "united states": "US",
3994
+ usa: "US",
3995
+ "united states of america": "US",
3996
+ uk: "GB",
3997
+ "great britain": "GB",
3998
+ england: "GB",
3999
+ uae: "AE",
4000
+ can: "CA",
4001
+ mex: "MX",
4002
+ aus: "AU",
4003
+ gbr: "GB"
4004
+ };
4005
+ var NAME_LOCALES = ["en", "fr"];
4006
+ function regionNames(locale) {
4007
+ try {
4008
+ return new Intl.DisplayNames([locale], { type: "region", fallback: "none" });
4009
+ } catch {
4010
+ return null;
4011
+ }
4012
+ }
4013
+ function canonicalCode(code) {
4014
+ try {
4015
+ return new Intl.Locale(`und-${code}`).maximize().region ?? code;
4016
+ } catch {
4017
+ return code;
4018
+ }
4019
+ }
4020
+ function allCodes() {
4021
+ const names = regionNames("en");
4022
+ if (!names) return [];
4023
+ const codes2 = [];
4024
+ for (let a = 65; a <= 90; a++) {
4025
+ for (let b = 65; b <= 90; b++) {
4026
+ const code = String.fromCharCode(a, b);
4027
+ if (!NOT_COUNTRIES.has(code) && names.of(code) && canonicalCode(code) === code) codes2.push(code);
4028
+ }
4029
+ }
4030
+ return codes2;
4031
+ }
4032
+ var lookup = null;
4033
+ var codes = null;
4034
+ function countryCodes() {
4035
+ codes ??= allCodes();
4036
+ return codes;
4037
+ }
4038
+ function countryLookup() {
4039
+ if (lookup) return lookup;
4040
+ lookup = new Map(Object.entries(ALIASES));
4041
+ for (const locale of NAME_LOCALES) {
4042
+ const names = regionNames(locale);
4043
+ if (!names) continue;
4044
+ for (const code of countryCodes()) {
4045
+ const name = names.of(code);
4046
+ if (name) lookup.set(foldText(name), code);
4047
+ }
4048
+ }
4049
+ return lookup;
4050
+ }
4051
+ function normalizeCountry(value) {
4052
+ const text = (value ?? "").trim();
4053
+ if (!text) return void 0;
4054
+ const upper = text.toUpperCase();
4055
+ if (upper.length === 2) {
4056
+ if (NOT_COUNTRIES.has(upper)) return void 0;
4057
+ if (countryCodes().length === 0) return /^[A-Z]{2}$/.test(upper) ? upper : void 0;
4058
+ const code = canonicalCode(upper);
4059
+ if (countryCodes().includes(code)) return code;
4060
+ }
4061
+ return countryLookup().get(foldText(text));
4062
+ }
4063
+ function listCountries(locale = "en") {
4064
+ const names = regionNames(locale) ?? regionNames("en");
4065
+ return countryCodes().map((code) => ({ code, name: names?.of(code) ?? code })).sort((a, b) => a.name.localeCompare(b.name, locale));
4066
+ }
4067
+
4068
+ // shipping/provinces.ts
4069
+ var CANADA_PROVINCES = [
4070
+ { code: "AB", name: "Alberta", nameFr: "Alberta", postalLetters: ["T"] },
4071
+ { code: "BC", name: "British Columbia", nameFr: "Colombie-Britannique", postalLetters: ["V"] },
4072
+ { code: "MB", name: "Manitoba", nameFr: "Manitoba", postalLetters: ["R"] },
4073
+ { code: "NB", name: "New Brunswick", nameFr: "Nouveau-Brunswick", postalLetters: ["E"] },
4074
+ {
4075
+ code: "NL",
4076
+ name: "Newfoundland and Labrador",
4077
+ nameFr: "Terre-Neuve-et-Labrador",
4078
+ postalLetters: ["A"],
4079
+ aliases: ["NF", "LB", "Newfoundland", "Labrador"]
4080
+ },
4081
+ { code: "NS", name: "Nova Scotia", nameFr: "Nouvelle-\xC9cosse", postalLetters: ["B"] },
4082
+ { code: "NT", name: "Northwest Territories", nameFr: "Territoires du Nord-Ouest", postalLetters: ["X"] },
4083
+ { code: "NU", name: "Nunavut", nameFr: "Nunavut", postalLetters: ["X"] },
4084
+ { code: "ON", name: "Ontario", nameFr: "Ontario", postalLetters: ["K", "L", "M", "N", "P"] },
4085
+ {
4086
+ code: "PE",
4087
+ name: "Prince Edward Island",
4088
+ nameFr: "\xCEle-du-Prince-\xC9douard",
4089
+ postalLetters: ["C"],
4090
+ aliases: ["PEI"]
4091
+ },
4092
+ { code: "QC", name: "Quebec", nameFr: "Qu\xE9bec", postalLetters: ["G", "H", "J"], aliases: ["PQ"] },
4093
+ { code: "SK", name: "Saskatchewan", nameFr: "Saskatchewan", postalLetters: ["S"] },
4094
+ { code: "YT", name: "Yukon", nameFr: "Yukon", postalLetters: ["Y"], aliases: ["YK"] }
4095
+ ];
4096
+ var PROVINCES_BY_COUNTRY = { CA: CANADA_PROVINCES };
4097
+ var lookups = /* @__PURE__ */ new Map();
4098
+ function provinceLookup(country) {
4099
+ const provinces = PROVINCES_BY_COUNTRY[country];
4100
+ if (!provinces) return void 0;
4101
+ let lookup2 = lookups.get(country);
4102
+ if (!lookup2) {
4103
+ lookup2 = /* @__PURE__ */ new Map();
4104
+ for (const p of provinces) {
4105
+ for (const label of [p.code, p.name, p.nameFr, ...p.aliases ?? []]) lookup2.set(foldText(label), p.code);
4106
+ }
4107
+ lookups.set(country, lookup2);
4108
+ }
4109
+ return lookup2;
4110
+ }
4111
+ function normalizeProvince(country, value) {
4112
+ if (!country || !value?.trim()) return void 0;
4113
+ return provinceLookup(country)?.get(foldText(value));
4114
+ }
4115
+ function listProvinces(country) {
4116
+ return PROVINCES_BY_COUNTRY[country] ?? [];
4117
+ }
4118
+ function provincesForPostCode(country, postCode) {
4119
+ const letter = postCode?.charAt(0);
4120
+ if (!country || !letter) return [];
4121
+ return listProvinces(country).filter((p) => p.postalLetters.includes(letter)).map((p) => p.code);
4122
+ }
4123
+
4124
+ // shipping/normalize.ts
4125
+ var EVERYWHERE_KEY = "*";
4126
+ function normalizeCityKey(value) {
4127
+ const words = foldText(value ?? "").split(" ").filter(Boolean).map((word) => word === "saint" ? "st" : word === "sainte" ? "ste" : word);
4128
+ return words.length ? words.join("") : void 0;
4129
+ }
4130
+ function normalizePostCode(value) {
4131
+ const compact = (value ?? "").replace(/[^0-9a-z]/gi, "").toUpperCase();
4132
+ return compact || void 0;
4133
+ }
4134
+ function normalizeAddress(address) {
4135
+ if (!address) return {};
4136
+ const country = normalizeCountry(address.country);
4137
+ const postCode = normalizePostCode(address.postCode ?? address.postalCode ?? address.zip);
4138
+ const fromPostCode = provincesForPostCode(country, postCode);
4139
+ const province = normalizeProvince(country, address.state ?? address.province) ?? (fromPostCode.length === 1 ? fromPostCode[0] : void 0);
4140
+ return { country, province, cityKey: normalizeCityKey(address.city), postCode };
4141
+ }
4142
+ function postCodeMatchesProvince(address) {
4143
+ const candidates = provincesForPostCode(address.country, address.postCode);
4144
+ if (!address.province || candidates.length === 0) return true;
4145
+ return candidates.includes(address.province);
4146
+ }
4147
+ function placeKey(place) {
4148
+ const country = normalizeCountry(place.country);
4149
+ if (!country) return void 0;
4150
+ if (!place.province) return country;
4151
+ const province = normalizeProvince(country, place.province);
4152
+ if (!province) return void 0;
4153
+ if (!place.city) return `${country}-${province}`;
4154
+ const city = normalizeCityKey(place.city);
4155
+ return city ? `${country}-${province}/${city}` : void 0;
4156
+ }
4157
+ function addressPlaceKeys(address) {
4158
+ const keys = [];
4159
+ if (address.country && address.province && address.cityKey) {
4160
+ keys.push(`${address.country}-${address.province}/${address.cityKey}`);
4161
+ }
4162
+ if (address.country && address.province) keys.push(`${address.country}-${address.province}`);
4163
+ if (address.country) keys.push(address.country);
4164
+ keys.push(EVERYWHERE_KEY);
4165
+ return keys;
4166
+ }
4167
+
4168
+ // shipping/resolve.ts
4169
+ function resolveShipping({ zones, address, itemsTotal, channel }) {
4170
+ const shipsToCountries = countriesShippedTo(zones);
4171
+ const none = (reason, zone2) => ({
4172
+ zoneId: zone2?.id ?? null,
4173
+ options: [],
4174
+ reason,
4175
+ message: zone2?.message?.trim() || null,
4176
+ shipsToCountries
4177
+ });
4178
+ const normalized = normalizeAddress(address);
4179
+ if (!normalized.country) return none("INCOMPLETE" /* INCOMPLETE */);
4180
+ if (!postCodeMatchesProvince(normalized)) return none("ADDRESS_MISMATCH" /* ADDRESS_MISMATCH */);
4181
+ const zone = findZone(zones, addressPlaceKeys(normalized));
4182
+ if (!zone) return none("NO_COVERAGE" /* NO_COVERAGE */);
4183
+ const offered = zone.options.filter((option) => isOffered(option, zone, channel));
4184
+ if (offered.length === 0) {
4185
+ return none(zone.ships ? "NO_OPTION" /* NO_OPTION */ : "BLOCKED" /* BLOCKED */, zone);
4186
+ }
4187
+ const quotes = offered.map((option) => quote(option, zone.id, itemsTotal));
4188
+ const ship = quotes.filter((q) => q.type === "ship" /* SHIP */).sort((a, b) => a.amount - b.amount);
4189
+ const pickup = quotes.filter((q) => q.type === "pickup" /* PICKUP */).sort((a, b) => a.amount - b.amount);
4190
+ return {
4191
+ zoneId: zone.id,
4192
+ options: [...ship, ...pickup],
4193
+ reason: null,
4194
+ message: zone.ships ? null : zone.message?.trim() || null,
4195
+ shipsToCountries
4196
+ };
4197
+ }
4198
+ function findZone(zones, keys) {
4199
+ const byKey = /* @__PURE__ */ new Map();
4200
+ for (const zone of zones) {
4201
+ for (const key of zoneKeys(zone)) if (!byKey.has(key)) byKey.set(key, zone);
4202
+ }
4203
+ for (const key of keys) {
4204
+ const zone = byKey.get(key);
4205
+ if (zone) return zone;
4206
+ }
4207
+ return void 0;
4208
+ }
4209
+ function zoneKeys(zone) {
4210
+ if (zone.kind === "everywhere" /* EVERYWHERE */) return [EVERYWHERE_KEY];
4211
+ return zone.places.map(placeKey).filter((key) => Boolean(key));
4212
+ }
4213
+ function isOffered(option, zone, channel) {
4214
+ if (!option.channels.some((c) => c === channel)) return false;
4215
+ if (option.type === "pickup" /* PICKUP */) return channel !== "pos" /* POS */;
4216
+ return zone.ships;
4217
+ }
4218
+ function priceForTotal(option, itemsTotal) {
4219
+ const tiers = [...option.priceByTotal ?? []].sort((a, b) => a.from - b.from);
4220
+ let price = option.price;
4221
+ for (const tier of tiers) if (itemsTotal >= tier.from) price = tier.price;
4222
+ if (option.freeOver != null && itemsTotal >= option.freeOver) return 0;
4223
+ return price;
4224
+ }
4225
+ function quote(option, zoneId, itemsTotal) {
4226
+ const amount = priceForTotal(option, itemsTotal);
4227
+ const freeOver = option.freeOver ?? null;
4228
+ return {
4229
+ optionId: option.id,
4230
+ zoneId,
4231
+ type: option.type,
4232
+ name: option.name?.trim() || null,
4233
+ amount,
4234
+ amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
4235
+ minDays: option.minDays ?? null,
4236
+ maxDays: option.maxDays ?? null,
4237
+ outletId: option.outletId ?? null
4238
+ };
4239
+ }
4240
+ function countriesShippedTo(zones) {
4241
+ const countries = /* @__PURE__ */ new Set();
4242
+ for (const zone of zones) {
4243
+ if (!zone.ships) continue;
4244
+ for (const key of zoneKeys(zone)) if (key !== EVERYWHERE_KEY) countries.add(key.slice(0, 2));
4245
+ }
4246
+ return [...countries].sort();
4247
+ }
4248
+
4249
+ // shipping/validate.ts
4250
+ function validateShippingZone(zone) {
4251
+ const problems = [...placeProblems(zone)];
4252
+ for (const option of zone.options) problems.push(...optionProblems(option));
4253
+ const reachesWebsite = zone.options.some((option) => option.channels.includes("web" /* WEB */));
4254
+ if (zone.ships && !reachesWebsite) problems.push({ code: "NO_WEBSITE_OPTION" /* NO_WEBSITE_OPTION */ });
4255
+ return problems;
4256
+ }
4257
+ function placeProblems(zone) {
4258
+ if (zone.kind === "everywhere" /* EVERYWHERE */) {
4259
+ return zone.places.length ? [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }] : [];
4260
+ }
4261
+ if (zone.places.length === 0) return [{ code: "NO_PLACES" /* NO_PLACES */ }];
4262
+ if (!zone.places.every((place) => fitsKind(place, zone.kind))) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
4263
+ const keys = zone.places.map(placeKey);
4264
+ if (keys.some((key) => !key)) return [{ code: "INVALID_PLACE" /* INVALID_PLACE */ }];
4265
+ if (new Set(keys).size !== keys.length) return [{ code: "DUPLICATE_PLACE" /* DUPLICATE_PLACE */ }];
4266
+ return [];
4267
+ }
4268
+ function fitsKind(place, kind) {
4269
+ const hasProvince = Boolean(place.province?.trim());
4270
+ const hasCity = Boolean(place.city?.trim());
4271
+ if (kind === "country" /* COUNTRY */) return !hasProvince && !hasCity;
4272
+ if (kind === "province" /* PROVINCE */) return hasProvince && !hasCity;
4273
+ if (kind === "city" /* CITY */) return hasProvince && hasCity;
4274
+ return false;
4275
+ }
4276
+ var isAmount = (value) => Number.isInteger(value) && value >= 0;
4277
+ var isDays = (value) => value == null || isAmount(value);
4278
+ function optionProblems(option) {
4279
+ const problems = [];
4280
+ const isPickup = option.type === "pickup" /* PICKUP */;
4281
+ if (!isAmount(option.price) || option.freeOver != null && !isAmount(option.freeOver)) {
4282
+ problems.push("INVALID_PRICE" /* INVALID_PRICE */);
4283
+ }
4284
+ if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
4285
+ if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
4286
+ problems.push("INVALID_DAYS" /* INVALID_DAYS */);
4287
+ }
4288
+ if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
4289
+ if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
4290
+ if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
4291
+ return problems.map((code) => ({ code, optionId: option.id }));
4292
+ }
4293
+ function tiersAreValid(option) {
4294
+ const tiers = option.priceByTotal ?? [];
4295
+ const froms = tiers.map((tier) => tier.from);
4296
+ return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
4297
+ }
4298
+
3836
4299
  // constants/adyen.constants.ts
3837
4300
  var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
3838
4301
  function isAdyenRolloutCountry(alpha2) {
@@ -3882,6 +4345,27 @@ var BNPL_SKIP_REASON = {
3882
4345
  NO_BUSINESS_LINE: "no_business_line"
3883
4346
  };
3884
4347
 
4348
+ // pos-types/active/ProcessorType.ts
4349
+ var ProcessorType = /* @__PURE__ */ ((ProcessorType2) => {
4350
+ ProcessorType2["FINAL_PAY"] = "Terminal";
4351
+ ProcessorType2["TAP_TO_PAY"] = "TapToPay";
4352
+ ProcessorType2["MOTO"] = "Moto";
4353
+ ProcessorType2["CLOUD"] = "Cloud";
4354
+ ProcessorType2["BLUETOOTH"] = "Bluetooth";
4355
+ ProcessorType2["CASH"] = "Cash";
4356
+ ProcessorType2["CUSTOM_PAY"] = "CustomPay";
4357
+ ProcessorType2["VENDARA"] = "Vendara";
4358
+ ProcessorType2["REDEEM"] = "Redeem";
4359
+ ProcessorType2["INTEGRATION"] = "Integration";
4360
+ ProcessorType2["PAYMENT_LINK"] = "PaymentLink";
4361
+ ProcessorType2["ONLINE_PAYMENT"] = "OnlinePayment";
4362
+ ProcessorType2["EXTERNAL"] = "External";
4363
+ return ProcessorType2;
4364
+ })(ProcessorType || {});
4365
+
4366
+ // constants/payment-channel.constants.ts
4367
+ var PAYMENT_CHANNELS = ["inPerson", "online"];
4368
+
3885
4369
  // constants/expense.constants.ts
3886
4370
  var EXPENSE_PAYMENT_METHOD_PRESETS = [
3887
4371
  "Cash",
@@ -3924,6 +4408,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
3924
4408
  BookingResourceStatus,
3925
4409
  BookingRulesError,
3926
4410
  BookingType,
4411
+ CANADA_PROVINCES,
3927
4412
  CONDITION_OPERATORS,
3928
4413
  COUNTRY_CURRENCIES,
3929
4414
  CURRENCY_CONFIG,
@@ -3940,6 +4425,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
3940
4425
  DualWriteStrategy,
3941
4426
  EUFixedRates,
3942
4427
  EUROPE,
4428
+ EVERYWHERE_KEY,
3943
4429
  EXPENSE_DEFAULT_CATEGORIES,
3944
4430
  EXPENSE_NAME_MAX_LENGTH,
3945
4431
  EXPENSE_PAYMENT_METHOD_PRESETS,
@@ -3965,6 +4451,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
3965
4451
  OtherFixedRates,
3966
4452
  OwnerType,
3967
4453
  PATH_MODES,
4454
+ PAYMENT_CHANNELS,
3968
4455
  PAYMENT_STATES,
3969
4456
  POS_VALID_INITIAL_STATES,
3970
4457
  PaymentMethod,
@@ -3974,6 +4461,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
3974
4461
  PricingLevel,
3975
4462
  PricingPlanEnum,
3976
4463
  PricingRegionEnum,
4464
+ ProcessorType,
3977
4465
  ProductSalesChartStep,
3978
4466
  ProductSalesReportCompare,
3979
4467
  ProductStatus,
@@ -3996,6 +4484,12 @@ var EXPENSE_DEFAULT_CATEGORIES = [
3996
4484
  SYSTEM_UNIT_IDS,
3997
4485
  SalesLineAction,
3998
4486
  SalesLineSourceArray,
4487
+ ShippingChannel,
4488
+ ShippingNoOptionReason,
4489
+ ShippingOptionType,
4490
+ ShippingRateType,
4491
+ ShippingZoneError,
4492
+ ShippingZoneKind,
3999
4493
  StationStatus,
4000
4494
  StripeCurrencyCode,
4001
4495
  StripeStatus,
@@ -4003,6 +4497,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4003
4497
  TopMetericsSort,
4004
4498
  UserTypes,
4005
4499
  addAmounts,
4500
+ addressPlaceKeys,
4006
4501
  adyenLegalEntityRequiresStateOrProvince,
4007
4502
  adyenRequiresJobTitle,
4008
4503
  adyenStoreRequiresStateOrProvince,
@@ -4010,6 +4505,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4010
4505
  adyenTaxNumberFormat,
4011
4506
  amountToString,
4012
4507
  ancestorChain,
4508
+ applyAssignment,
4013
4509
  assertUnitSane,
4014
4510
  availableIn,
4015
4511
  baseFor,
@@ -4035,6 +4531,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4035
4531
  convertFixedFeeToLocalCurrency,
4036
4532
  createAmount,
4037
4533
  crossAxisRuleApplies,
4534
+ currentAssignees,
4038
4535
  deriveDisplayState,
4039
4536
  deriveFamilyCode,
4040
4537
  deriveUnitId,
@@ -4081,25 +4578,39 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4081
4578
  isSystemFamilyCode,
4082
4579
  isValidQuantity,
4083
4580
  isWhole,
4581
+ lineStockMoves,
4582
+ listCountries,
4583
+ listProvinces,
4084
4584
  mapToLegacyStatus,
4085
4585
  maxPrecisionFor,
4086
4586
  mergeFragment,
4087
4587
  modifiersSellable,
4088
4588
  multiplyAmount,
4589
+ normalizeAddress,
4590
+ normalizeCityKey,
4591
+ normalizeCountry,
4089
4592
  normalizeMongoIdString,
4593
+ normalizePostCode,
4594
+ normalizeProvince,
4090
4595
  occupancyIn,
4596
+ orderAssignments,
4091
4597
  parseAmountToMinorUnits,
4092
4598
  parseCurrencyCode,
4093
4599
  parseStripeCurrencyCode,
4600
+ placeKey,
4094
4601
  planWindow,
4095
4602
  poolDemand,
4096
4603
  poolOf,
4097
4604
  poolShortfall,
4098
4605
  poolStockAt,
4606
+ postCodeMatchesProvince,
4099
4607
  presentAt,
4608
+ priceForTotal,
4609
+ provincesForPostCode,
4100
4610
  removeFragment,
4101
4611
  resolveFamily,
4102
4612
  resolveModifiersForProduct,
4613
+ resolveShipping,
4103
4614
  resolveTemplate,
4104
4615
  resolveUnit,
4105
4616
  roundToPrecision,
@@ -4116,6 +4627,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4116
4627
  validateConfig,
4117
4628
  validateFragmentCompatibility,
4118
4629
  validateOrderStatuses,
4630
+ validateShippingZone,
4119
4631
  violatesFinancialInvariant,
4120
4632
  windowEndsAt,
4121
4633
  withinPresence