@final-commerce/common 2.12.0 → 2.12.1-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
@@ -40,6 +40,8 @@ __export(index_exports, {
40
40
  CONDITION_OPERATORS: () => CONDITION_OPERATORS,
41
41
  COUNTRY_CURRENCIES: () => COUNTRY_CURRENCIES,
42
42
  CURRENCY_CONFIG: () => CURRENCY_CONFIG,
43
+ CUSTOMER_CONTACT_VERIFIED: () => CUSTOMER_CONTACT_VERIFIED,
44
+ CUSTOMER_EMAIL_TAKEN: () => CUSTOMER_EMAIL_TAKEN,
43
45
  CompanyType: () => CompanyType,
44
46
  CurrencyCode: () => CurrencyCode,
45
47
  CustomTableAvailability: () => CustomTableAvailability,
@@ -78,6 +80,7 @@ __export(index_exports, {
78
80
  ORDER_STATE_TOPIC: () => ORDER_STATE_TOPIC,
79
81
  OrderPlatform: () => OrderPlatform,
80
82
  OtherFixedRates: () => OtherFixedRates,
83
+ OutOfProvinceTaxes: () => OutOfProvinceTaxes,
81
84
  OwnerType: () => OwnerType,
82
85
  PATH_MODES: () => PATH_MODES,
83
86
  PAYMENT_CHANNELS: () => PAYMENT_CHANNELS,
@@ -111,6 +114,12 @@ __export(index_exports, {
111
114
  SHELL_TIP_PERCENT_MAX: () => SHELL_TIP_PERCENT_MAX,
112
115
  SHELL_TIP_PERCENT_MIN: () => SHELL_TIP_PERCENT_MIN,
113
116
  SHIPPING_COUNTRIES: () => SHIPPING_COUNTRIES,
117
+ SHOPPER_CONSENT_SOURCES: () => SHOPPER_CONSENT_SOURCES,
118
+ SHOPPER_ERROR_CODES: () => SHOPPER_ERROR_CODES,
119
+ SHOPPER_RETURN_DECLINE_REASON_MAX: () => SHOPPER_RETURN_DECLINE_REASON_MAX,
120
+ SHOPPER_RETURN_METHODS: () => SHOPPER_RETURN_METHODS,
121
+ SHOPPER_RETURN_STATUSES: () => SHOPPER_RETURN_STATUSES,
122
+ STANDARD_TAX_TYPE: () => STANDARD_TAX_TYPE,
114
123
  STATE_SCHEMA: () => STATE_SCHEMA,
115
124
  STRIPE_SUPPORTED_COUNTRIES: () => STRIPE_SUPPORTED_COUNTRIES,
116
125
  SYSTEM_FAMILIES: () => SYSTEM_FAMILIES,
@@ -128,6 +137,11 @@ __export(index_exports, {
128
137
  StationStatus: () => StationStatus,
129
138
  StripeCurrencyCode: () => StripeCurrencyCode,
130
139
  StripeStatus: () => StripeStatus,
140
+ TAX_EXCEPTION_REASON_MAX: () => TAX_EXCEPTION_REASON_MAX,
141
+ TaxExceptionSource: () => TaxExceptionSource,
142
+ TaxRegistrationKind: () => TaxRegistrationKind,
143
+ TaxSource: () => TaxSource,
144
+ TaxWarningCode: () => TaxWarningCode,
131
145
  TimePeriod: () => TimePeriod,
132
146
  TopMetericsSort: () => TopMetericsSort,
133
147
  UserTypes: () => UserTypes,
@@ -142,11 +156,13 @@ __export(index_exports, {
142
156
  ancestorChain: () => ancestorChain,
143
157
  applyAssignment: () => applyAssignment,
144
158
  assertUnitSane: () => assertUnitSane,
159
+ automaticTaxTableVersion: () => automaticTaxTableVersion,
145
160
  availableIn: () => availableIn,
146
161
  baseFor: () => baseFor,
147
162
  baseFulfillmentDefinitions: () => baseFulfillmentDefinitions,
148
163
  baseOf: () => baseOf,
149
164
  basePaymentDefinitions: () => basePaymentDefinitions,
165
+ buildAutomaticTaxTable: () => buildAutomaticTaxTable,
150
166
  buildAvailability: () => buildAvailability,
151
167
  buildGrid: () => buildGrid,
152
168
  buildOrderContext: () => buildOrderContext,
@@ -154,6 +170,7 @@ __export(index_exports, {
154
170
  buildResolvedConfig: () => buildResolvedConfig,
155
171
  calculatePercentage: () => calculatePercentage,
156
172
  canTransition: () => canTransition,
173
+ cardFromProcessorData: () => cardFromProcessorData,
157
174
  cheapestCompositeItem: () => cheapestCompositeItem,
158
175
  cheapestCompositePrice: () => cheapestCompositePrice,
159
176
  compositeItemCost: () => compositeItemCost,
@@ -172,6 +189,7 @@ __export(index_exports, {
172
189
  deriveUnitId: () => deriveUnitId,
173
190
  displayRuleMatchesPair: () => displayRuleMatchesPair,
174
191
  divideAmount: () => divideAmount,
192
+ emailKey: () => emailKey,
175
193
  evaluateCondition: () => evaluateCondition,
176
194
  evaluateConditionSet: () => evaluateConditionSet,
177
195
  extendPrice: () => extendPrice,
@@ -181,6 +199,7 @@ __export(index_exports, {
181
199
  formatInUnit: () => formatInUnit,
182
200
  formatMinorUnitsToString: () => formatMinorUnitsToString,
183
201
  formatQuantity: () => formatQuantity,
202
+ formatShippingDuration: () => formatShippingDuration,
184
203
  fromBase: () => fromBase,
185
204
  fromMinorUnits: () => fromMinorUnits,
186
205
  generateMongoID: () => generateMongoID,
@@ -230,11 +249,13 @@ __export(index_exports, {
230
249
  normalizeMongoIdString: () => normalizeMongoIdString,
231
250
  normalizePostCode: () => normalizePostCode,
232
251
  normalizeProvince: () => normalizeProvince,
252
+ normalizeShopperEmail: () => normalizeShopperEmail,
233
253
  occupancyIn: () => occupancyIn,
234
254
  orderAssignments: () => orderAssignments,
235
255
  parseAmountToMinorUnits: () => parseAmountToMinorUnits,
236
256
  parseCurrencyCode: () => parseCurrencyCode,
237
257
  parseStripeCurrencyCode: () => parseStripeCurrencyCode,
258
+ phoneKey: () => phoneKey,
238
259
  placeKey: () => placeKey,
239
260
  planWindow: () => planWindow,
240
261
  poolDemand: () => poolDemand,
@@ -246,6 +267,7 @@ __export(index_exports, {
246
267
  priceForTotal: () => priceForTotal,
247
268
  provincesForPostCode: () => provincesForPostCode,
248
269
  readShellTipSettings: () => readShellTipSettings,
270
+ registrationPlacesByKind: () => registrationPlacesByKind,
249
271
  removeFragment: () => removeFragment,
250
272
  resolveFamily: () => resolveFamily,
251
273
  resolveModifiersForProduct: () => resolveModifiersForProduct,
@@ -257,13 +279,16 @@ __export(index_exports, {
257
279
  roundToPrecision: () => roundToPrecision,
258
280
  sameFamily: () => sameFamily,
259
281
  setOrderState: () => setOrderState,
282
+ sha1Hex: () => sha1Hex,
260
283
  shellSettingsFromCompanyTips: () => shellSettingsFromCompanyTips,
261
284
  shellSettingsFromFlowSettings: () => shellSettingsFromFlowSettings,
262
285
  shellSettingsProblems: () => shellSettingsProblems,
263
286
  shellTipSettingsProblems: () => shellTipSettingsProblems,
287
+ shippingDuration: () => shippingDuration,
264
288
  shipsToCountry: () => shipsToCountry,
265
289
  shopDayKey: () => shopDayKey,
266
290
  shopDayRange: () => shopDayRange,
291
+ shopperPaymentsOf: () => shopperPaymentsOf,
267
292
  signReportForDisplay: () => signReportForDisplay,
268
293
  slotsForWindow: () => slotsForWindow,
269
294
  stringifyMinorUnits: () => stringifyMinorUnits,
@@ -274,6 +299,7 @@ __export(index_exports, {
274
299
  validateFragmentCompatibility: () => validateFragmentCompatibility,
275
300
  validateOrderStatuses: () => validateOrderStatuses,
276
301
  validateShippingZone: () => validateShippingZone,
302
+ verifiedContactChange: () => verifiedContactChange,
277
303
  violatesFinancialInvariant: () => violatesFinancialInvariant,
278
304
  windowEndsAt: () => windowEndsAt,
279
305
  withinPresence: () => withinPresence
@@ -823,6 +849,30 @@ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
823
849
  return ShippingZoneError2;
824
850
  })(ShippingZoneError || {});
825
851
 
852
+ // enums/tax.enum.ts
853
+ var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
854
+ TaxRegistrationKind2["GST_HST"] = "GST_HST";
855
+ TaxRegistrationKind2["PST"] = "PST";
856
+ TaxRegistrationKind2["QST"] = "QST";
857
+ return TaxRegistrationKind2;
858
+ })(TaxRegistrationKind || {});
859
+ var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
860
+ TaxSource2["MERCHANT"] = "merchant";
861
+ TaxSource2["AUTOMATIC"] = "automatic";
862
+ return TaxSource2;
863
+ })(TaxSource || {});
864
+ var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
865
+ OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
866
+ OutOfProvinceTaxes2["HOME"] = "home";
867
+ return OutOfProvinceTaxes2;
868
+ })(OutOfProvinceTaxes || {});
869
+ var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
870
+ TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
871
+ TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
872
+ TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
873
+ return TaxWarningCode2;
874
+ })(TaxWarningCode || {});
875
+
826
876
  // enums/sales-line.enum.ts
827
877
  var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
828
878
  SalesLineAction2["SALE"] = "sale";
@@ -2214,6 +2264,32 @@ function shellSettingsFromCompanyTips(enabled, options) {
2214
2264
  return Object.keys(tips).length > 0 ? { tips } : {};
2215
2265
  }
2216
2266
 
2267
+ // utils/contact-keys.util.ts
2268
+ function emailKey(email) {
2269
+ const key = email?.trim().toLowerCase();
2270
+ return key && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(key) ? key : null;
2271
+ }
2272
+ function phoneKey(phone) {
2273
+ const raw = phone?.trim();
2274
+ if (!raw) return null;
2275
+ const digits = raw.replace(/\D/g, "");
2276
+ if (raw.startsWith("+")) return digits.length >= 8 && digits.length <= 15 ? `+${digits}` : null;
2277
+ if (digits.length === 10) return `+1${digits}`;
2278
+ if (digits.length === 11 && digits.startsWith("1")) return `+${digits}`;
2279
+ return null;
2280
+ }
2281
+ var CUSTOMER_CONTACT_VERIFIED = "CUSTOMER_CONTACT_VERIFIED";
2282
+ var CUSTOMER_EMAIL_TAKEN = "CUSTOMER_EMAIL_TAKEN";
2283
+ function sameContact(a, b, key) {
2284
+ return (key(a) ?? a?.trim().toLowerCase() ?? "") === (key(b) ?? b?.trim().toLowerCase() ?? "");
2285
+ }
2286
+ function verifiedContactChange(existing, change) {
2287
+ if (!existing.verifiedShopperAt) return null;
2288
+ if (change.email !== void 0 && !sameContact(existing.email, change.email, emailKey)) return "email";
2289
+ if (change.phone !== void 0 && !sameContact(existing.phone, change.phone, phoneKey)) return "phone";
2290
+ return null;
2291
+ }
2292
+
2217
2293
  // units/family-code.ts
2218
2294
  var MAX_SLUG_LENGTH = 32;
2219
2295
  var FALLBACK_SLUG = "family";
@@ -2256,6 +2332,7 @@ var FULFILLMENT_STATES = [
2256
2332
  "in_progress",
2257
2333
  "fulfilled",
2258
2334
  "partially_fulfilled",
2335
+ "return_pending",
2259
2336
  "returned",
2260
2337
  "partially_returned",
2261
2338
  "cancelled"
@@ -2281,10 +2358,7 @@ var CONDITION_OPERATORS = [
2281
2358
  function isConditionOperator(value) {
2282
2359
  return CONDITION_OPERATORS.includes(value);
2283
2360
  }
2284
- var PATH_MODES = [
2285
- "strict",
2286
- "permissive"
2287
- ];
2361
+ var PATH_MODES = ["strict", "permissive"];
2288
2362
 
2289
2363
  // order-state-machine/state-schema.ts
2290
2364
  var PAYMENT_DEFS = [
@@ -2305,6 +2379,9 @@ var FULFILLMENT_DEFS = [
2305
2379
  { id: "in_progress", label: "In Progress", terminal: false },
2306
2380
  { id: "fulfilled", label: "Fulfilled", terminal: true },
2307
2381
  { id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
2382
+ // The store accepted the shopper's return request: the goods are on their way back, no money has moved yet.
2383
+ // The refund lands `partially_returned` / `returned` as it does from `fulfilled`.
2384
+ { id: "return_pending", label: "Return Accepted", terminal: false },
2308
2385
  { id: "returned", label: "Returned", terminal: true },
2309
2386
  { id: "partially_returned", label: "Partially Returned", terminal: false },
2310
2387
  { id: "cancelled", label: "Cancelled", terminal: true }
@@ -2334,6 +2411,8 @@ var STATE_SCHEMA = Object.freeze({
2334
2411
  var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
2335
2412
  var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
2336
2413
  var UNRETURNED_MONEY_STATES = /* @__PURE__ */ new Set(["partially_paid", "paid", "partially_refunded"]);
2414
+ var RETURN_FROM_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "partially_returned"]);
2415
+ var RETURN_PENDING_PAYMENTS = /* @__PURE__ */ new Set(["paid", "partially_refunded"]);
2337
2416
  var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
2338
2417
  var FINANCIAL_INVARIANTS = [
2339
2418
  {
@@ -2381,6 +2460,11 @@ var FINANCIAL_INVARIANTS = [
2381
2460
  description: "A voided order exists only at cancelled fulfillment: a voided order cannot re-enter fulfillment, and a voided \xD7 non-cancelled pair cannot be materialized from nothing (complements no-leave-voided, which only freezes the payment axis). Moves INTO voided from a live payment state are the void flow\u2019s concern, not this rule\u2019s",
2382
2461
  check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
2383
2462
  },
2463
+ {
2464
+ id: "return-pending-needs-goods-out",
2465
+ description: "Fulfillment enters return_pending (return accepted) only from fulfilled, partially_fulfilled or partially_returned, and holds it only while payment is paid or partially_refunded \u2014 goods must have gone out and money must still be held",
2466
+ check: (from, to) => to.fulfillment === "return_pending" && (!RETURN_PENDING_PAYMENTS.has(to.payment) || from?.fulfillment !== "return_pending" && !(from && RETURN_FROM_FULFILLMENT.has(from.fulfillment)))
2467
+ },
2384
2468
  {
2385
2469
  id: "no-reopen-refunded-fulfillment",
2386
2470
  description: "A fully refunded order cannot re-enter fulfillment \u2014 it may only relabel between its canonical landings, returned and cancelled (complements no-leave-refunded, which only freezes the payment axis)",
@@ -2472,7 +2556,9 @@ var DISPLAY_LABEL_OVERRIDES = {
2472
2556
  "paid|on_hold": "Parked - Paid",
2473
2557
  "paid|fulfilled": "Completed",
2474
2558
  "partially_refunded|fulfilled": "Partially Refunded",
2475
- "partially_refunded|partially_returned": "Partially Refunded"
2559
+ "partially_refunded|partially_returned": "Partially Refunded",
2560
+ "paid|return_pending": "Return Accepted",
2561
+ "partially_refunded|return_pending": "Return Accepted"
2476
2562
  };
2477
2563
  var TERMINAL_LABEL_OVERRIDES = {
2478
2564
  voided: "Cancelled"
@@ -2614,6 +2700,7 @@ function buildOrderContext(order, extras) {
2614
2700
  }
2615
2701
 
2616
2702
  // order-state-machine/display-state.ts
2703
+ var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
2617
2704
  function atomLabel(atom, defs) {
2618
2705
  return defs.find((d) => d.id === atom)?.label ?? atom;
2619
2706
  }
@@ -2627,6 +2714,10 @@ function deriveDisplayState(payment, fulfillment, config) {
2627
2714
  return { label: rule.label, color: rule.color, icon: rule.icon };
2628
2715
  }
2629
2716
  }
2717
+ if (ATOMS_ADDED_AFTER_SNAPSHOT.has(fulfillment)) {
2718
+ const fallback = DEFAULT_DISPLAY_STATE_MAP.find((rule) => displayRuleMatchesPair(rule, payment, fulfillment));
2719
+ if (fallback) return { label: fallback.label, color: fallback.color, icon: fallback.icon };
2720
+ }
2630
2721
  return {
2631
2722
  label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
2632
2723
  };
@@ -4414,6 +4505,8 @@ function quote(option, zoneId, itemsTotal) {
4414
4505
  amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
4415
4506
  minDays: option.minDays ?? null,
4416
4507
  maxDays: option.maxDays ?? null,
4508
+ minMinutes: option.minMinutes ?? null,
4509
+ maxMinutes: option.maxMinutes ?? null,
4417
4510
  outletId: option.outletId ?? null
4418
4511
  };
4419
4512
  }
@@ -4428,6 +4521,21 @@ function countriesShippedTo(zones) {
4428
4521
  return [...countries].sort();
4429
4522
  }
4430
4523
 
4524
+ // shipping/time.ts
4525
+ function shippingDuration(minMinutes, maxMinutes) {
4526
+ const min = minMinutes ?? maxMinutes;
4527
+ const max = maxMinutes ?? minMinutes;
4528
+ if (min == null || max == null) return null;
4529
+ const wholeHours = max > 0 && min % 60 === 0 && max % 60 === 0;
4530
+ return wholeHours ? { unit: "hour", min: min / 60, max: max / 60 } : { unit: "minute", min, max };
4531
+ }
4532
+ function formatShippingDuration(minMinutes, maxMinutes, locale, display = "long") {
4533
+ const duration = shippingDuration(minMinutes, maxMinutes);
4534
+ if (!duration) return null;
4535
+ const unit2 = new Intl.NumberFormat(locale ?? "en", { style: "unit", unit: duration.unit, unitDisplay: display });
4536
+ return duration.min === duration.max ? unit2.format(duration.max) : `${duration.min}\u2013${unit2.format(duration.max)}`;
4537
+ }
4538
+
4431
4539
  // shipping/validate.ts
4432
4540
  function validateShippingZone(zone) {
4433
4541
  const problems = [...placeProblems(zone)];
@@ -4456,7 +4564,15 @@ function fitsKind(place, kind) {
4456
4564
  return false;
4457
4565
  }
4458
4566
  var isAmount = (value) => Number.isInteger(value) && value >= 0;
4459
- var isDays = (value) => value == null || isAmount(value);
4567
+ var isTime = (value) => value == null || isAmount(value);
4568
+ var inOrder = (min, max) => (min ?? 0) <= (max ?? Infinity);
4569
+ function timeIsValid(option) {
4570
+ const { minDays, maxDays, minMinutes, maxMinutes } = option;
4571
+ if (![minDays, maxDays, minMinutes, maxMinutes].every(isTime)) return false;
4572
+ const hasDays = minDays != null || maxDays != null;
4573
+ const hasMinutes = minMinutes != null || maxMinutes != null;
4574
+ return !(hasDays && hasMinutes) && inOrder(minDays, maxDays) && inOrder(minMinutes, maxMinutes);
4575
+ }
4460
4576
  function optionProblems(option) {
4461
4577
  const problems = [];
4462
4578
  const isPickup = option.type === "pickup" /* PICKUP */;
@@ -4464,9 +4580,7 @@ function optionProblems(option) {
4464
4580
  problems.push("INVALID_PRICE" /* INVALID_PRICE */);
4465
4581
  }
4466
4582
  if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
4467
- if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
4468
- problems.push("INVALID_DAYS" /* INVALID_DAYS */);
4469
- }
4583
+ if (!timeIsValid(option)) problems.push("INVALID_DAYS" /* INVALID_DAYS */);
4470
4584
  if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
4471
4585
  if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
4472
4586
  if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
@@ -4478,6 +4592,224 @@ function tiersAreValid(option) {
4478
4592
  return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
4479
4593
  }
4480
4594
 
4595
+ // tax/sha1.ts
4596
+ function utf8Bytes(text) {
4597
+ const bytes = [];
4598
+ for (const char of text) {
4599
+ const cp = char.codePointAt(0);
4600
+ if (cp < 128) bytes.push(cp);
4601
+ else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
4602
+ else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
4603
+ else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
4604
+ }
4605
+ return bytes;
4606
+ }
4607
+ var rotl = (x, n) => x << n | x >>> 32 - n;
4608
+ function sha1Hex(text) {
4609
+ const bytes = utf8Bytes(text);
4610
+ const bitLength = bytes.length * 8;
4611
+ bytes.push(128);
4612
+ while (bytes.length % 64 !== 56) bytes.push(0);
4613
+ const high = Math.floor(bitLength / 4294967296);
4614
+ for (const word of [high, bitLength >>> 0])
4615
+ bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
4616
+ const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
4617
+ const w = new Array(80);
4618
+ for (let offset = 0; offset < bytes.length; offset += 64) {
4619
+ for (let i = 0; i < 16; i++) {
4620
+ const j = offset + i * 4;
4621
+ w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
4622
+ }
4623
+ for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
4624
+ let [a, b, c, d, e] = h;
4625
+ for (let i = 0; i < 80; i++) {
4626
+ const [f, k] = i < 20 ? [b & c | ~b & d, 1518500249] : i < 40 ? [b ^ c ^ d, 1859775393] : i < 60 ? [b & c | b & d | c & d, 2400959708] : [b ^ c ^ d, 3395469782];
4627
+ const t = rotl(a, 5) + f + e + k + w[i] | 0;
4628
+ e = d;
4629
+ d = c;
4630
+ c = rotl(b, 30);
4631
+ b = a;
4632
+ a = t;
4633
+ }
4634
+ h[0] = h[0] + a | 0;
4635
+ h[1] = h[1] + b | 0;
4636
+ h[2] = h[2] + c | 0;
4637
+ h[3] = h[3] + d | 0;
4638
+ h[4] = h[4] + e | 0;
4639
+ }
4640
+ return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
4641
+ }
4642
+
4643
+ // tax/table.ts
4644
+ var STANDARD_TAX_TYPE = "standard";
4645
+ var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
4646
+ var RATE_FIELDS = [
4647
+ "code",
4648
+ "name",
4649
+ "kind",
4650
+ "places",
4651
+ "rate",
4652
+ "from",
4653
+ "to",
4654
+ "order",
4655
+ "compound",
4656
+ "registrationPlace",
4657
+ "harmonized",
4658
+ "parts",
4659
+ "sourceUrl",
4660
+ "status"
4661
+ ];
4662
+ var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
4663
+ function canonical(row, fields) {
4664
+ return JSON.stringify(fields.map((field) => row[field] ?? null));
4665
+ }
4666
+ var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
4667
+ function automaticTaxTableVersion(table) {
4668
+ return sha1Hex(
4669
+ JSON.stringify([
4670
+ sortedCanonical(table.types, TYPE_FIELDS),
4671
+ sortedCanonical(table.rates, RATE_FIELDS),
4672
+ sortedCanonical(table.rules, RULE_FIELDS)
4673
+ ])
4674
+ );
4675
+ }
4676
+ var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
4677
+ key,
4678
+ name,
4679
+ description,
4680
+ sortOrder,
4681
+ active
4682
+ });
4683
+ var toRateRow = (rate) => ({
4684
+ code: rate.code,
4685
+ name: rate.name,
4686
+ kind: rate.kind,
4687
+ places: rate.places,
4688
+ rate: rate.rate,
4689
+ from: rate.from,
4690
+ to: rate.to,
4691
+ order: rate.order,
4692
+ compound: rate.compound,
4693
+ registrationPlace: rate.registrationPlace,
4694
+ harmonized: rate.harmonized,
4695
+ parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
4696
+ sourceUrl: rate.sourceUrl,
4697
+ status: rate.status
4698
+ });
4699
+ var toRuleRow = ({
4700
+ taxType,
4701
+ codes: codes2,
4702
+ rate,
4703
+ from,
4704
+ to,
4705
+ sourceUrl,
4706
+ status,
4707
+ note
4708
+ }) => ({
4709
+ taxType,
4710
+ codes: codes2,
4711
+ rate,
4712
+ from,
4713
+ to,
4714
+ sourceUrl,
4715
+ status,
4716
+ note
4717
+ });
4718
+ function buildAutomaticTaxTable(rows) {
4719
+ const table = {
4720
+ types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
4721
+ rates: rows.rates.map(toRateRow),
4722
+ rules: rows.rules.map(toRuleRow)
4723
+ };
4724
+ return { version: automaticTaxTableVersion(table), ...table };
4725
+ }
4726
+ function registrationPlacesByKind(rates) {
4727
+ const places = /* @__PURE__ */ new Map();
4728
+ for (const rate of rates) {
4729
+ const list = places.get(rate.kind) ?? [];
4730
+ if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
4731
+ places.set(rate.kind, list);
4732
+ }
4733
+ return places;
4734
+ }
4735
+
4736
+ // tax/exceptions.ts
4737
+ var TaxExceptionSource = /* @__PURE__ */ ((TaxExceptionSource2) => {
4738
+ TaxExceptionSource2["PRODUCT"] = "product";
4739
+ TaxExceptionSource2["CATEGORY"] = "category";
4740
+ return TaxExceptionSource2;
4741
+ })(TaxExceptionSource || {});
4742
+ var TAX_EXCEPTION_REASON_MAX = 200;
4743
+
4744
+ // shopper/types.ts
4745
+ var SHOPPER_CONSENT_SOURCES = ["checkout", "my-account", "store-account"];
4746
+ var SHOPPER_RETURN_METHODS = ["mail", "in-store"];
4747
+ var SHOPPER_RETURN_STATUSES = ["requested", "accepted", "declined"];
4748
+ var SHOPPER_RETURN_DECLINE_REASON_MAX = 500;
4749
+ var SHOPPER_ERROR_CODES = {
4750
+ ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
4751
+ RETURN_ALREADY_REQUESTED: "RETURN_ALREADY_REQUESTED",
4752
+ RETURN_NOT_ALLOWED: "RETURN_NOT_ALLOWED",
4753
+ RETURN_ALREADY_DECIDED: "RETURN_ALREADY_DECIDED",
4754
+ STORE_HAS_NO_SUPPORT_EMAIL: "STORE_HAS_NO_SUPPORT_EMAIL",
4755
+ TOO_MANY_ADDRESSES: "TOO_MANY_ADDRESSES",
4756
+ STORE_NOT_LINKED: "STORE_NOT_LINKED",
4757
+ STORED_METHOD_NOT_FOUND: "STORED_METHOD_NOT_FOUND"
4758
+ };
4759
+
4760
+ // shopper/email.ts
4761
+ function normalizeShopperEmail(email) {
4762
+ if (typeof email !== "string") return null;
4763
+ const value = email.trim().toLowerCase();
4764
+ return /^[^\s@]+@[^\s@]+$/.test(value) ? value : null;
4765
+ }
4766
+
4767
+ // shopper/card.ts
4768
+ function cardFromProcessorData(processorData) {
4769
+ if (typeof processorData !== "string" || !processorData) return {};
4770
+ let data;
4771
+ try {
4772
+ data = JSON.parse(processorData);
4773
+ } catch {
4774
+ return {};
4775
+ }
4776
+ if (!data || typeof data !== "object") return {};
4777
+ const fields = new Map(Object.entries(data));
4778
+ const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
4779
+ const brand = text("Brand", "brand")?.trim();
4780
+ const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
4781
+ const issuer = text("Issuer", "issuer")?.trim();
4782
+ return {
4783
+ ...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
4784
+ ...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {},
4785
+ ...issuer ? { cardIssuer: issuer } : {}
4786
+ };
4787
+ }
4788
+
4789
+ // shopper/payments.ts
4790
+ var CARD_TYPES = /* @__PURE__ */ new Set(["card", "terminal", "taptopay", "moto", "cloud", "bluetooth"]);
4791
+ function kindOf(paymentType) {
4792
+ if (paymentType === "cash") return "cash";
4793
+ if (paymentType === "redeem") return "gift_card";
4794
+ if (paymentType === "pay_later") return "pay_later";
4795
+ if (CARD_TYPES.has(paymentType)) return "card";
4796
+ return "other";
4797
+ }
4798
+ function shopperPaymentsOf(legs) {
4799
+ return (legs ?? []).map((leg) => {
4800
+ const type = (leg.paymentType ?? "").trim();
4801
+ const kind = kindOf(type.toLowerCase());
4802
+ const card = kind === "card" ? cardFromProcessorData(leg.emv) : {};
4803
+ return {
4804
+ kind,
4805
+ // Cards: the issuer's name, else the brand. Other tenders the store named itself keep that name.
4806
+ name: kind === "card" ? card.cardIssuer ?? card.cardBrand ?? null : kind === "other" ? type || null : null,
4807
+ lastFour: card.cardLastFour ?? null,
4808
+ amount: (leg.amount ?? 0) + (leg.tip?.amount ?? 0)
4809
+ };
4810
+ });
4811
+ }
4812
+
4481
4813
  // constants/adyen.constants.ts
4482
4814
  var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
4483
4815
  function isAdyenRolloutCountry(alpha2) {
@@ -4594,6 +4926,8 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4594
4926
  CONDITION_OPERATORS,
4595
4927
  COUNTRY_CURRENCIES,
4596
4928
  CURRENCY_CONFIG,
4929
+ CUSTOMER_CONTACT_VERIFIED,
4930
+ CUSTOMER_EMAIL_TAKEN,
4597
4931
  CompanyType,
4598
4932
  CurrencyCode,
4599
4933
  CustomTableAvailability,
@@ -4632,6 +4966,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4632
4966
  ORDER_STATE_TOPIC,
4633
4967
  OrderPlatform,
4634
4968
  OtherFixedRates,
4969
+ OutOfProvinceTaxes,
4635
4970
  OwnerType,
4636
4971
  PATH_MODES,
4637
4972
  PAYMENT_CHANNELS,
@@ -4665,6 +5000,12 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4665
5000
  SHELL_TIP_PERCENT_MAX,
4666
5001
  SHELL_TIP_PERCENT_MIN,
4667
5002
  SHIPPING_COUNTRIES,
5003
+ SHOPPER_CONSENT_SOURCES,
5004
+ SHOPPER_ERROR_CODES,
5005
+ SHOPPER_RETURN_DECLINE_REASON_MAX,
5006
+ SHOPPER_RETURN_METHODS,
5007
+ SHOPPER_RETURN_STATUSES,
5008
+ STANDARD_TAX_TYPE,
4668
5009
  STATE_SCHEMA,
4669
5010
  STRIPE_SUPPORTED_COUNTRIES,
4670
5011
  SYSTEM_FAMILIES,
@@ -4682,6 +5023,11 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4682
5023
  StationStatus,
4683
5024
  StripeCurrencyCode,
4684
5025
  StripeStatus,
5026
+ TAX_EXCEPTION_REASON_MAX,
5027
+ TaxExceptionSource,
5028
+ TaxRegistrationKind,
5029
+ TaxSource,
5030
+ TaxWarningCode,
4685
5031
  TimePeriod,
4686
5032
  TopMetericsSort,
4687
5033
  UserTypes,
@@ -4696,11 +5042,13 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4696
5042
  ancestorChain,
4697
5043
  applyAssignment,
4698
5044
  assertUnitSane,
5045
+ automaticTaxTableVersion,
4699
5046
  availableIn,
4700
5047
  baseFor,
4701
5048
  baseFulfillmentDefinitions,
4702
5049
  baseOf,
4703
5050
  basePaymentDefinitions,
5051
+ buildAutomaticTaxTable,
4704
5052
  buildAvailability,
4705
5053
  buildGrid,
4706
5054
  buildOrderContext,
@@ -4708,6 +5056,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4708
5056
  buildResolvedConfig,
4709
5057
  calculatePercentage,
4710
5058
  canTransition,
5059
+ cardFromProcessorData,
4711
5060
  cheapestCompositeItem,
4712
5061
  cheapestCompositePrice,
4713
5062
  compositeItemCost,
@@ -4726,6 +5075,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4726
5075
  deriveUnitId,
4727
5076
  displayRuleMatchesPair,
4728
5077
  divideAmount,
5078
+ emailKey,
4729
5079
  evaluateCondition,
4730
5080
  evaluateConditionSet,
4731
5081
  extendPrice,
@@ -4735,6 +5085,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4735
5085
  formatInUnit,
4736
5086
  formatMinorUnitsToString,
4737
5087
  formatQuantity,
5088
+ formatShippingDuration,
4738
5089
  fromBase,
4739
5090
  fromMinorUnits,
4740
5091
  generateMongoID,
@@ -4784,11 +5135,13 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4784
5135
  normalizeMongoIdString,
4785
5136
  normalizePostCode,
4786
5137
  normalizeProvince,
5138
+ normalizeShopperEmail,
4787
5139
  occupancyIn,
4788
5140
  orderAssignments,
4789
5141
  parseAmountToMinorUnits,
4790
5142
  parseCurrencyCode,
4791
5143
  parseStripeCurrencyCode,
5144
+ phoneKey,
4792
5145
  placeKey,
4793
5146
  planWindow,
4794
5147
  poolDemand,
@@ -4800,6 +5153,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4800
5153
  priceForTotal,
4801
5154
  provincesForPostCode,
4802
5155
  readShellTipSettings,
5156
+ registrationPlacesByKind,
4803
5157
  removeFragment,
4804
5158
  resolveFamily,
4805
5159
  resolveModifiersForProduct,
@@ -4811,13 +5165,16 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4811
5165
  roundToPrecision,
4812
5166
  sameFamily,
4813
5167
  setOrderState,
5168
+ sha1Hex,
4814
5169
  shellSettingsFromCompanyTips,
4815
5170
  shellSettingsFromFlowSettings,
4816
5171
  shellSettingsProblems,
4817
5172
  shellTipSettingsProblems,
5173
+ shippingDuration,
4818
5174
  shipsToCountry,
4819
5175
  shopDayKey,
4820
5176
  shopDayRange,
5177
+ shopperPaymentsOf,
4821
5178
  signReportForDisplay,
4822
5179
  slotsForWindow,
4823
5180
  stringifyMinorUnits,
@@ -4828,6 +5185,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
4828
5185
  validateFragmentCompatibility,
4829
5186
  validateOrderStatuses,
4830
5187
  validateShippingZone,
5188
+ verifiedContactChange,
4831
5189
  violatesFinancialInvariant,
4832
5190
  windowEndsAt,
4833
5191
  withinPresence