@final-commerce/common 2.11.0 → 2.11.1-online.10
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/README.md +20 -0
- package/bin/gate-done.mjs +76 -54
- package/bin/lib/budget.mjs +71 -0
- package/dist/index.d.mts +295 -2
- package/dist/index.d.ts +295 -2
- package/dist/index.js +367 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +341 -9
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +72 -13
- package/dist/pos-types/index.d.ts +72 -13
- package/package.json +1 -1
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,
|
|
@@ -77,6 +79,7 @@ __export(index_exports, {
|
|
|
77
79
|
ORDER_STATE_TOPIC: () => ORDER_STATE_TOPIC,
|
|
78
80
|
OrderPlatform: () => OrderPlatform,
|
|
79
81
|
OtherFixedRates: () => OtherFixedRates,
|
|
82
|
+
OutOfProvinceTaxes: () => OutOfProvinceTaxes,
|
|
80
83
|
OwnerType: () => OwnerType,
|
|
81
84
|
PATH_MODES: () => PATH_MODES,
|
|
82
85
|
PAYMENT_CHANNELS: () => PAYMENT_CHANNELS,
|
|
@@ -105,6 +108,12 @@ __export(index_exports, {
|
|
|
105
108
|
ResidualStatus: () => ResidualStatus,
|
|
106
109
|
ResourceAvailabilityState: () => ResourceAvailabilityState,
|
|
107
110
|
SHIPPING_COUNTRIES: () => SHIPPING_COUNTRIES,
|
|
111
|
+
SHOPPER_CONSENT_SOURCES: () => SHOPPER_CONSENT_SOURCES,
|
|
112
|
+
SHOPPER_ERROR_CODES: () => SHOPPER_ERROR_CODES,
|
|
113
|
+
SHOPPER_RETURN_DECLINE_REASON_MAX: () => SHOPPER_RETURN_DECLINE_REASON_MAX,
|
|
114
|
+
SHOPPER_RETURN_METHODS: () => SHOPPER_RETURN_METHODS,
|
|
115
|
+
SHOPPER_RETURN_STATUSES: () => SHOPPER_RETURN_STATUSES,
|
|
116
|
+
STANDARD_TAX_TYPE: () => STANDARD_TAX_TYPE,
|
|
108
117
|
STATE_SCHEMA: () => STATE_SCHEMA,
|
|
109
118
|
STRIPE_SUPPORTED_COUNTRIES: () => STRIPE_SUPPORTED_COUNTRIES,
|
|
110
119
|
SYSTEM_FAMILIES: () => SYSTEM_FAMILIES,
|
|
@@ -122,6 +131,11 @@ __export(index_exports, {
|
|
|
122
131
|
StationStatus: () => StationStatus,
|
|
123
132
|
StripeCurrencyCode: () => StripeCurrencyCode,
|
|
124
133
|
StripeStatus: () => StripeStatus,
|
|
134
|
+
TAX_EXCEPTION_REASON_MAX: () => TAX_EXCEPTION_REASON_MAX,
|
|
135
|
+
TaxExceptionSource: () => TaxExceptionSource,
|
|
136
|
+
TaxRegistrationKind: () => TaxRegistrationKind,
|
|
137
|
+
TaxSource: () => TaxSource,
|
|
138
|
+
TaxWarningCode: () => TaxWarningCode,
|
|
125
139
|
TimePeriod: () => TimePeriod,
|
|
126
140
|
TopMetericsSort: () => TopMetericsSort,
|
|
127
141
|
UserTypes: () => UserTypes,
|
|
@@ -136,11 +150,13 @@ __export(index_exports, {
|
|
|
136
150
|
ancestorChain: () => ancestorChain,
|
|
137
151
|
applyAssignment: () => applyAssignment,
|
|
138
152
|
assertUnitSane: () => assertUnitSane,
|
|
153
|
+
automaticTaxTableVersion: () => automaticTaxTableVersion,
|
|
139
154
|
availableIn: () => availableIn,
|
|
140
155
|
baseFor: () => baseFor,
|
|
141
156
|
baseFulfillmentDefinitions: () => baseFulfillmentDefinitions,
|
|
142
157
|
baseOf: () => baseOf,
|
|
143
158
|
basePaymentDefinitions: () => basePaymentDefinitions,
|
|
159
|
+
buildAutomaticTaxTable: () => buildAutomaticTaxTable,
|
|
144
160
|
buildAvailability: () => buildAvailability,
|
|
145
161
|
buildGrid: () => buildGrid,
|
|
146
162
|
buildOrderContext: () => buildOrderContext,
|
|
@@ -148,6 +164,7 @@ __export(index_exports, {
|
|
|
148
164
|
buildResolvedConfig: () => buildResolvedConfig,
|
|
149
165
|
calculatePercentage: () => calculatePercentage,
|
|
150
166
|
canTransition: () => canTransition,
|
|
167
|
+
cardFromProcessorData: () => cardFromProcessorData,
|
|
151
168
|
cheapestCompositeItem: () => cheapestCompositeItem,
|
|
152
169
|
cheapestCompositePrice: () => cheapestCompositePrice,
|
|
153
170
|
compositeItemCost: () => compositeItemCost,
|
|
@@ -166,6 +183,7 @@ __export(index_exports, {
|
|
|
166
183
|
deriveUnitId: () => deriveUnitId,
|
|
167
184
|
displayRuleMatchesPair: () => displayRuleMatchesPair,
|
|
168
185
|
divideAmount: () => divideAmount,
|
|
186
|
+
emailKey: () => emailKey,
|
|
169
187
|
evaluateCondition: () => evaluateCondition,
|
|
170
188
|
evaluateConditionSet: () => evaluateConditionSet,
|
|
171
189
|
extendPrice: () => extendPrice,
|
|
@@ -174,6 +192,7 @@ __export(index_exports, {
|
|
|
174
192
|
formatInUnit: () => formatInUnit,
|
|
175
193
|
formatMinorUnitsToString: () => formatMinorUnitsToString,
|
|
176
194
|
formatQuantity: () => formatQuantity,
|
|
195
|
+
formatShippingDuration: () => formatShippingDuration,
|
|
177
196
|
fromBase: () => fromBase,
|
|
178
197
|
fromMinorUnits: () => fromMinorUnits,
|
|
179
198
|
generateMongoID: () => generateMongoID,
|
|
@@ -222,11 +241,13 @@ __export(index_exports, {
|
|
|
222
241
|
normalizeMongoIdString: () => normalizeMongoIdString,
|
|
223
242
|
normalizePostCode: () => normalizePostCode,
|
|
224
243
|
normalizeProvince: () => normalizeProvince,
|
|
244
|
+
normalizeShopperEmail: () => normalizeShopperEmail,
|
|
225
245
|
occupancyIn: () => occupancyIn,
|
|
226
246
|
orderAssignments: () => orderAssignments,
|
|
227
247
|
parseAmountToMinorUnits: () => parseAmountToMinorUnits,
|
|
228
248
|
parseCurrencyCode: () => parseCurrencyCode,
|
|
229
249
|
parseStripeCurrencyCode: () => parseStripeCurrencyCode,
|
|
250
|
+
phoneKey: () => phoneKey,
|
|
230
251
|
placeKey: () => placeKey,
|
|
231
252
|
planWindow: () => planWindow,
|
|
232
253
|
poolDemand: () => poolDemand,
|
|
@@ -237,6 +258,7 @@ __export(index_exports, {
|
|
|
237
258
|
presentAt: () => presentAt,
|
|
238
259
|
priceForTotal: () => priceForTotal,
|
|
239
260
|
provincesForPostCode: () => provincesForPostCode,
|
|
261
|
+
registrationPlacesByKind: () => registrationPlacesByKind,
|
|
240
262
|
removeFragment: () => removeFragment,
|
|
241
263
|
resolveFamily: () => resolveFamily,
|
|
242
264
|
resolveModifiersForProduct: () => resolveModifiersForProduct,
|
|
@@ -246,9 +268,12 @@ __export(index_exports, {
|
|
|
246
268
|
roundToPrecision: () => roundToPrecision,
|
|
247
269
|
sameFamily: () => sameFamily,
|
|
248
270
|
setOrderState: () => setOrderState,
|
|
271
|
+
sha1Hex: () => sha1Hex,
|
|
272
|
+
shippingDuration: () => shippingDuration,
|
|
249
273
|
shipsToCountry: () => shipsToCountry,
|
|
250
274
|
shopDayKey: () => shopDayKey,
|
|
251
275
|
shopDayRange: () => shopDayRange,
|
|
276
|
+
shopperPaymentsOf: () => shopperPaymentsOf,
|
|
252
277
|
signReportForDisplay: () => signReportForDisplay,
|
|
253
278
|
slotsForWindow: () => slotsForWindow,
|
|
254
279
|
stringifyMinorUnits: () => stringifyMinorUnits,
|
|
@@ -259,6 +284,7 @@ __export(index_exports, {
|
|
|
259
284
|
validateFragmentCompatibility: () => validateFragmentCompatibility,
|
|
260
285
|
validateOrderStatuses: () => validateOrderStatuses,
|
|
261
286
|
validateShippingZone: () => validateShippingZone,
|
|
287
|
+
verifiedContactChange: () => verifiedContactChange,
|
|
262
288
|
violatesFinancialInvariant: () => violatesFinancialInvariant,
|
|
263
289
|
windowEndsAt: () => windowEndsAt,
|
|
264
290
|
withinPresence: () => withinPresence
|
|
@@ -808,6 +834,30 @@ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
|
|
|
808
834
|
return ShippingZoneError2;
|
|
809
835
|
})(ShippingZoneError || {});
|
|
810
836
|
|
|
837
|
+
// enums/tax.enum.ts
|
|
838
|
+
var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
|
|
839
|
+
TaxRegistrationKind2["GST_HST"] = "GST_HST";
|
|
840
|
+
TaxRegistrationKind2["PST"] = "PST";
|
|
841
|
+
TaxRegistrationKind2["QST"] = "QST";
|
|
842
|
+
return TaxRegistrationKind2;
|
|
843
|
+
})(TaxRegistrationKind || {});
|
|
844
|
+
var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
|
|
845
|
+
TaxSource2["MERCHANT"] = "merchant";
|
|
846
|
+
TaxSource2["AUTOMATIC"] = "automatic";
|
|
847
|
+
return TaxSource2;
|
|
848
|
+
})(TaxSource || {});
|
|
849
|
+
var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
|
|
850
|
+
OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
|
|
851
|
+
OutOfProvinceTaxes2["HOME"] = "home";
|
|
852
|
+
return OutOfProvinceTaxes2;
|
|
853
|
+
})(OutOfProvinceTaxes || {});
|
|
854
|
+
var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
|
|
855
|
+
TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
|
|
856
|
+
TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
|
|
857
|
+
TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
|
|
858
|
+
return TaxWarningCode2;
|
|
859
|
+
})(TaxWarningCode || {});
|
|
860
|
+
|
|
811
861
|
// enums/sales-line.enum.ts
|
|
812
862
|
var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
|
|
813
863
|
SalesLineAction2["SALE"] = "sale";
|
|
@@ -2048,6 +2098,32 @@ function lineStockMoves(item, quantity, reservations = []) {
|
|
|
2048
2098
|
});
|
|
2049
2099
|
}
|
|
2050
2100
|
|
|
2101
|
+
// utils/contact-keys.util.ts
|
|
2102
|
+
function emailKey(email) {
|
|
2103
|
+
const key = email?.trim().toLowerCase();
|
|
2104
|
+
return key && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(key) ? key : null;
|
|
2105
|
+
}
|
|
2106
|
+
function phoneKey(phone) {
|
|
2107
|
+
const raw = phone?.trim();
|
|
2108
|
+
if (!raw) return null;
|
|
2109
|
+
const digits = raw.replace(/\D/g, "");
|
|
2110
|
+
if (raw.startsWith("+")) return digits.length >= 8 && digits.length <= 15 ? `+${digits}` : null;
|
|
2111
|
+
if (digits.length === 10) return `+1${digits}`;
|
|
2112
|
+
if (digits.length === 11 && digits.startsWith("1")) return `+${digits}`;
|
|
2113
|
+
return null;
|
|
2114
|
+
}
|
|
2115
|
+
var CUSTOMER_CONTACT_VERIFIED = "CUSTOMER_CONTACT_VERIFIED";
|
|
2116
|
+
var CUSTOMER_EMAIL_TAKEN = "CUSTOMER_EMAIL_TAKEN";
|
|
2117
|
+
function sameContact(a, b, key) {
|
|
2118
|
+
return (key(a) ?? a?.trim().toLowerCase() ?? "") === (key(b) ?? b?.trim().toLowerCase() ?? "");
|
|
2119
|
+
}
|
|
2120
|
+
function verifiedContactChange(existing, change) {
|
|
2121
|
+
if (!existing.verifiedShopperAt) return null;
|
|
2122
|
+
if (change.email !== void 0 && !sameContact(existing.email, change.email, emailKey)) return "email";
|
|
2123
|
+
if (change.phone !== void 0 && !sameContact(existing.phone, change.phone, phoneKey)) return "phone";
|
|
2124
|
+
return null;
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2051
2127
|
// units/family-code.ts
|
|
2052
2128
|
var MAX_SLUG_LENGTH = 32;
|
|
2053
2129
|
var FALLBACK_SLUG = "family";
|
|
@@ -2090,6 +2166,7 @@ var FULFILLMENT_STATES = [
|
|
|
2090
2166
|
"in_progress",
|
|
2091
2167
|
"fulfilled",
|
|
2092
2168
|
"partially_fulfilled",
|
|
2169
|
+
"return_pending",
|
|
2093
2170
|
"returned",
|
|
2094
2171
|
"partially_returned",
|
|
2095
2172
|
"cancelled"
|
|
@@ -2115,10 +2192,7 @@ var CONDITION_OPERATORS = [
|
|
|
2115
2192
|
function isConditionOperator(value) {
|
|
2116
2193
|
return CONDITION_OPERATORS.includes(value);
|
|
2117
2194
|
}
|
|
2118
|
-
var PATH_MODES = [
|
|
2119
|
-
"strict",
|
|
2120
|
-
"permissive"
|
|
2121
|
-
];
|
|
2195
|
+
var PATH_MODES = ["strict", "permissive"];
|
|
2122
2196
|
|
|
2123
2197
|
// order-state-machine/state-schema.ts
|
|
2124
2198
|
var PAYMENT_DEFS = [
|
|
@@ -2139,6 +2213,9 @@ var FULFILLMENT_DEFS = [
|
|
|
2139
2213
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
2140
2214
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
2141
2215
|
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
2216
|
+
// The store accepted the shopper's return request: the goods are on their way back, no money has moved yet.
|
|
2217
|
+
// The refund lands `partially_returned` / `returned` as it does from `fulfilled`.
|
|
2218
|
+
{ id: "return_pending", label: "Return Accepted", terminal: false },
|
|
2142
2219
|
{ id: "returned", label: "Returned", terminal: true },
|
|
2143
2220
|
{ id: "partially_returned", label: "Partially Returned", terminal: false },
|
|
2144
2221
|
{ id: "cancelled", label: "Cancelled", terminal: true }
|
|
@@ -2168,6 +2245,8 @@ var STATE_SCHEMA = Object.freeze({
|
|
|
2168
2245
|
var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
|
|
2169
2246
|
var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
|
|
2170
2247
|
var UNRETURNED_MONEY_STATES = /* @__PURE__ */ new Set(["partially_paid", "paid", "partially_refunded"]);
|
|
2248
|
+
var RETURN_FROM_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "partially_returned"]);
|
|
2249
|
+
var RETURN_PENDING_PAYMENTS = /* @__PURE__ */ new Set(["paid", "partially_refunded"]);
|
|
2171
2250
|
var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
|
|
2172
2251
|
var FINANCIAL_INVARIANTS = [
|
|
2173
2252
|
{
|
|
@@ -2215,6 +2294,11 @@ var FINANCIAL_INVARIANTS = [
|
|
|
2215
2294
|
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",
|
|
2216
2295
|
check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
|
|
2217
2296
|
},
|
|
2297
|
+
{
|
|
2298
|
+
id: "return-pending-needs-goods-out",
|
|
2299
|
+
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",
|
|
2300
|
+
check: (from, to) => to.fulfillment === "return_pending" && (!RETURN_PENDING_PAYMENTS.has(to.payment) || from?.fulfillment !== "return_pending" && !(from && RETURN_FROM_FULFILLMENT.has(from.fulfillment)))
|
|
2301
|
+
},
|
|
2218
2302
|
{
|
|
2219
2303
|
id: "no-reopen-refunded-fulfillment",
|
|
2220
2304
|
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)",
|
|
@@ -2306,7 +2390,9 @@ var DISPLAY_LABEL_OVERRIDES = {
|
|
|
2306
2390
|
"paid|on_hold": "Parked - Paid",
|
|
2307
2391
|
"paid|fulfilled": "Completed",
|
|
2308
2392
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
2309
|
-
"partially_refunded|partially_returned": "Partially Refunded"
|
|
2393
|
+
"partially_refunded|partially_returned": "Partially Refunded",
|
|
2394
|
+
"paid|return_pending": "Return Accepted",
|
|
2395
|
+
"partially_refunded|return_pending": "Return Accepted"
|
|
2310
2396
|
};
|
|
2311
2397
|
var TERMINAL_LABEL_OVERRIDES = {
|
|
2312
2398
|
voided: "Cancelled"
|
|
@@ -2448,6 +2534,7 @@ function buildOrderContext(order, extras) {
|
|
|
2448
2534
|
}
|
|
2449
2535
|
|
|
2450
2536
|
// order-state-machine/display-state.ts
|
|
2537
|
+
var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
|
|
2451
2538
|
function atomLabel(atom, defs) {
|
|
2452
2539
|
return defs.find((d) => d.id === atom)?.label ?? atom;
|
|
2453
2540
|
}
|
|
@@ -2461,6 +2548,10 @@ function deriveDisplayState(payment, fulfillment, config) {
|
|
|
2461
2548
|
return { label: rule.label, color: rule.color, icon: rule.icon };
|
|
2462
2549
|
}
|
|
2463
2550
|
}
|
|
2551
|
+
if (ATOMS_ADDED_AFTER_SNAPSHOT.has(fulfillment)) {
|
|
2552
|
+
const fallback = DEFAULT_DISPLAY_STATE_MAP.find((rule) => displayRuleMatchesPair(rule, payment, fulfillment));
|
|
2553
|
+
if (fallback) return { label: fallback.label, color: fallback.color, icon: fallback.icon };
|
|
2554
|
+
}
|
|
2464
2555
|
return {
|
|
2465
2556
|
label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
|
|
2466
2557
|
};
|
|
@@ -4248,6 +4339,8 @@ function quote(option, zoneId, itemsTotal) {
|
|
|
4248
4339
|
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
4249
4340
|
minDays: option.minDays ?? null,
|
|
4250
4341
|
maxDays: option.maxDays ?? null,
|
|
4342
|
+
minMinutes: option.minMinutes ?? null,
|
|
4343
|
+
maxMinutes: option.maxMinutes ?? null,
|
|
4251
4344
|
outletId: option.outletId ?? null
|
|
4252
4345
|
};
|
|
4253
4346
|
}
|
|
@@ -4262,6 +4355,21 @@ function countriesShippedTo(zones) {
|
|
|
4262
4355
|
return [...countries].sort();
|
|
4263
4356
|
}
|
|
4264
4357
|
|
|
4358
|
+
// shipping/time.ts
|
|
4359
|
+
function shippingDuration(minMinutes, maxMinutes) {
|
|
4360
|
+
const min = minMinutes ?? maxMinutes;
|
|
4361
|
+
const max = maxMinutes ?? minMinutes;
|
|
4362
|
+
if (min == null || max == null) return null;
|
|
4363
|
+
const wholeHours = max > 0 && min % 60 === 0 && max % 60 === 0;
|
|
4364
|
+
return wholeHours ? { unit: "hour", min: min / 60, max: max / 60 } : { unit: "minute", min, max };
|
|
4365
|
+
}
|
|
4366
|
+
function formatShippingDuration(minMinutes, maxMinutes, locale, display = "long") {
|
|
4367
|
+
const duration = shippingDuration(minMinutes, maxMinutes);
|
|
4368
|
+
if (!duration) return null;
|
|
4369
|
+
const unit2 = new Intl.NumberFormat(locale ?? "en", { style: "unit", unit: duration.unit, unitDisplay: display });
|
|
4370
|
+
return duration.min === duration.max ? unit2.format(duration.max) : `${duration.min}\u2013${unit2.format(duration.max)}`;
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4265
4373
|
// shipping/validate.ts
|
|
4266
4374
|
function validateShippingZone(zone) {
|
|
4267
4375
|
const problems = [...placeProblems(zone)];
|
|
@@ -4290,7 +4398,15 @@ function fitsKind(place, kind) {
|
|
|
4290
4398
|
return false;
|
|
4291
4399
|
}
|
|
4292
4400
|
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4293
|
-
var
|
|
4401
|
+
var isTime = (value) => value == null || isAmount(value);
|
|
4402
|
+
var inOrder = (min, max) => (min ?? 0) <= (max ?? Infinity);
|
|
4403
|
+
function timeIsValid(option) {
|
|
4404
|
+
const { minDays, maxDays, minMinutes, maxMinutes } = option;
|
|
4405
|
+
if (![minDays, maxDays, minMinutes, maxMinutes].every(isTime)) return false;
|
|
4406
|
+
const hasDays = minDays != null || maxDays != null;
|
|
4407
|
+
const hasMinutes = minMinutes != null || maxMinutes != null;
|
|
4408
|
+
return !(hasDays && hasMinutes) && inOrder(minDays, maxDays) && inOrder(minMinutes, maxMinutes);
|
|
4409
|
+
}
|
|
4294
4410
|
function optionProblems(option) {
|
|
4295
4411
|
const problems = [];
|
|
4296
4412
|
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
@@ -4298,9 +4414,7 @@ function optionProblems(option) {
|
|
|
4298
4414
|
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4299
4415
|
}
|
|
4300
4416
|
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4301
|
-
if (!
|
|
4302
|
-
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4303
|
-
}
|
|
4417
|
+
if (!timeIsValid(option)) problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4304
4418
|
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4305
4419
|
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4306
4420
|
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
@@ -4312,6 +4426,224 @@ function tiersAreValid(option) {
|
|
|
4312
4426
|
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
4313
4427
|
}
|
|
4314
4428
|
|
|
4429
|
+
// tax/sha1.ts
|
|
4430
|
+
function utf8Bytes(text) {
|
|
4431
|
+
const bytes = [];
|
|
4432
|
+
for (const char of text) {
|
|
4433
|
+
const cp = char.codePointAt(0);
|
|
4434
|
+
if (cp < 128) bytes.push(cp);
|
|
4435
|
+
else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
|
|
4436
|
+
else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4437
|
+
else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4438
|
+
}
|
|
4439
|
+
return bytes;
|
|
4440
|
+
}
|
|
4441
|
+
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
4442
|
+
function sha1Hex(text) {
|
|
4443
|
+
const bytes = utf8Bytes(text);
|
|
4444
|
+
const bitLength = bytes.length * 8;
|
|
4445
|
+
bytes.push(128);
|
|
4446
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
4447
|
+
const high = Math.floor(bitLength / 4294967296);
|
|
4448
|
+
for (const word of [high, bitLength >>> 0])
|
|
4449
|
+
bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
|
|
4450
|
+
const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
4451
|
+
const w = new Array(80);
|
|
4452
|
+
for (let offset = 0; offset < bytes.length; offset += 64) {
|
|
4453
|
+
for (let i = 0; i < 16; i++) {
|
|
4454
|
+
const j = offset + i * 4;
|
|
4455
|
+
w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
|
|
4456
|
+
}
|
|
4457
|
+
for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
|
|
4458
|
+
let [a, b, c, d, e] = h;
|
|
4459
|
+
for (let i = 0; i < 80; i++) {
|
|
4460
|
+
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];
|
|
4461
|
+
const t = rotl(a, 5) + f + e + k + w[i] | 0;
|
|
4462
|
+
e = d;
|
|
4463
|
+
d = c;
|
|
4464
|
+
c = rotl(b, 30);
|
|
4465
|
+
b = a;
|
|
4466
|
+
a = t;
|
|
4467
|
+
}
|
|
4468
|
+
h[0] = h[0] + a | 0;
|
|
4469
|
+
h[1] = h[1] + b | 0;
|
|
4470
|
+
h[2] = h[2] + c | 0;
|
|
4471
|
+
h[3] = h[3] + d | 0;
|
|
4472
|
+
h[4] = h[4] + e | 0;
|
|
4473
|
+
}
|
|
4474
|
+
return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
|
|
4475
|
+
}
|
|
4476
|
+
|
|
4477
|
+
// tax/table.ts
|
|
4478
|
+
var STANDARD_TAX_TYPE = "standard";
|
|
4479
|
+
var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
|
|
4480
|
+
var RATE_FIELDS = [
|
|
4481
|
+
"code",
|
|
4482
|
+
"name",
|
|
4483
|
+
"kind",
|
|
4484
|
+
"places",
|
|
4485
|
+
"rate",
|
|
4486
|
+
"from",
|
|
4487
|
+
"to",
|
|
4488
|
+
"order",
|
|
4489
|
+
"compound",
|
|
4490
|
+
"registrationPlace",
|
|
4491
|
+
"harmonized",
|
|
4492
|
+
"parts",
|
|
4493
|
+
"sourceUrl",
|
|
4494
|
+
"status"
|
|
4495
|
+
];
|
|
4496
|
+
var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
|
|
4497
|
+
function canonical(row, fields) {
|
|
4498
|
+
return JSON.stringify(fields.map((field) => row[field] ?? null));
|
|
4499
|
+
}
|
|
4500
|
+
var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
|
|
4501
|
+
function automaticTaxTableVersion(table) {
|
|
4502
|
+
return sha1Hex(
|
|
4503
|
+
JSON.stringify([
|
|
4504
|
+
sortedCanonical(table.types, TYPE_FIELDS),
|
|
4505
|
+
sortedCanonical(table.rates, RATE_FIELDS),
|
|
4506
|
+
sortedCanonical(table.rules, RULE_FIELDS)
|
|
4507
|
+
])
|
|
4508
|
+
);
|
|
4509
|
+
}
|
|
4510
|
+
var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
|
|
4511
|
+
key,
|
|
4512
|
+
name,
|
|
4513
|
+
description,
|
|
4514
|
+
sortOrder,
|
|
4515
|
+
active
|
|
4516
|
+
});
|
|
4517
|
+
var toRateRow = (rate) => ({
|
|
4518
|
+
code: rate.code,
|
|
4519
|
+
name: rate.name,
|
|
4520
|
+
kind: rate.kind,
|
|
4521
|
+
places: rate.places,
|
|
4522
|
+
rate: rate.rate,
|
|
4523
|
+
from: rate.from,
|
|
4524
|
+
to: rate.to,
|
|
4525
|
+
order: rate.order,
|
|
4526
|
+
compound: rate.compound,
|
|
4527
|
+
registrationPlace: rate.registrationPlace,
|
|
4528
|
+
harmonized: rate.harmonized,
|
|
4529
|
+
parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
|
|
4530
|
+
sourceUrl: rate.sourceUrl,
|
|
4531
|
+
status: rate.status
|
|
4532
|
+
});
|
|
4533
|
+
var toRuleRow = ({
|
|
4534
|
+
taxType,
|
|
4535
|
+
codes: codes2,
|
|
4536
|
+
rate,
|
|
4537
|
+
from,
|
|
4538
|
+
to,
|
|
4539
|
+
sourceUrl,
|
|
4540
|
+
status,
|
|
4541
|
+
note
|
|
4542
|
+
}) => ({
|
|
4543
|
+
taxType,
|
|
4544
|
+
codes: codes2,
|
|
4545
|
+
rate,
|
|
4546
|
+
from,
|
|
4547
|
+
to,
|
|
4548
|
+
sourceUrl,
|
|
4549
|
+
status,
|
|
4550
|
+
note
|
|
4551
|
+
});
|
|
4552
|
+
function buildAutomaticTaxTable(rows) {
|
|
4553
|
+
const table = {
|
|
4554
|
+
types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
|
|
4555
|
+
rates: rows.rates.map(toRateRow),
|
|
4556
|
+
rules: rows.rules.map(toRuleRow)
|
|
4557
|
+
};
|
|
4558
|
+
return { version: automaticTaxTableVersion(table), ...table };
|
|
4559
|
+
}
|
|
4560
|
+
function registrationPlacesByKind(rates) {
|
|
4561
|
+
const places = /* @__PURE__ */ new Map();
|
|
4562
|
+
for (const rate of rates) {
|
|
4563
|
+
const list = places.get(rate.kind) ?? [];
|
|
4564
|
+
if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
|
|
4565
|
+
places.set(rate.kind, list);
|
|
4566
|
+
}
|
|
4567
|
+
return places;
|
|
4568
|
+
}
|
|
4569
|
+
|
|
4570
|
+
// tax/exceptions.ts
|
|
4571
|
+
var TaxExceptionSource = /* @__PURE__ */ ((TaxExceptionSource2) => {
|
|
4572
|
+
TaxExceptionSource2["PRODUCT"] = "product";
|
|
4573
|
+
TaxExceptionSource2["CATEGORY"] = "category";
|
|
4574
|
+
return TaxExceptionSource2;
|
|
4575
|
+
})(TaxExceptionSource || {});
|
|
4576
|
+
var TAX_EXCEPTION_REASON_MAX = 200;
|
|
4577
|
+
|
|
4578
|
+
// shopper/types.ts
|
|
4579
|
+
var SHOPPER_CONSENT_SOURCES = ["checkout", "my-account", "store-account"];
|
|
4580
|
+
var SHOPPER_RETURN_METHODS = ["mail", "in-store"];
|
|
4581
|
+
var SHOPPER_RETURN_STATUSES = ["requested", "accepted", "declined"];
|
|
4582
|
+
var SHOPPER_RETURN_DECLINE_REASON_MAX = 500;
|
|
4583
|
+
var SHOPPER_ERROR_CODES = {
|
|
4584
|
+
ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
|
|
4585
|
+
RETURN_ALREADY_REQUESTED: "RETURN_ALREADY_REQUESTED",
|
|
4586
|
+
RETURN_NOT_ALLOWED: "RETURN_NOT_ALLOWED",
|
|
4587
|
+
RETURN_ALREADY_DECIDED: "RETURN_ALREADY_DECIDED",
|
|
4588
|
+
STORE_HAS_NO_SUPPORT_EMAIL: "STORE_HAS_NO_SUPPORT_EMAIL",
|
|
4589
|
+
TOO_MANY_ADDRESSES: "TOO_MANY_ADDRESSES",
|
|
4590
|
+
STORE_NOT_LINKED: "STORE_NOT_LINKED",
|
|
4591
|
+
STORED_METHOD_NOT_FOUND: "STORED_METHOD_NOT_FOUND"
|
|
4592
|
+
};
|
|
4593
|
+
|
|
4594
|
+
// shopper/email.ts
|
|
4595
|
+
function normalizeShopperEmail(email) {
|
|
4596
|
+
if (typeof email !== "string") return null;
|
|
4597
|
+
const value = email.trim().toLowerCase();
|
|
4598
|
+
return /^[^\s@]+@[^\s@]+$/.test(value) ? value : null;
|
|
4599
|
+
}
|
|
4600
|
+
|
|
4601
|
+
// shopper/card.ts
|
|
4602
|
+
function cardFromProcessorData(processorData) {
|
|
4603
|
+
if (typeof processorData !== "string" || !processorData) return {};
|
|
4604
|
+
let data;
|
|
4605
|
+
try {
|
|
4606
|
+
data = JSON.parse(processorData);
|
|
4607
|
+
} catch {
|
|
4608
|
+
return {};
|
|
4609
|
+
}
|
|
4610
|
+
if (!data || typeof data !== "object") return {};
|
|
4611
|
+
const fields = new Map(Object.entries(data));
|
|
4612
|
+
const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
|
|
4613
|
+
const brand = text("Brand", "brand")?.trim();
|
|
4614
|
+
const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
|
|
4615
|
+
const issuer = text("Issuer", "issuer")?.trim();
|
|
4616
|
+
return {
|
|
4617
|
+
...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
|
|
4618
|
+
...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {},
|
|
4619
|
+
...issuer ? { cardIssuer: issuer } : {}
|
|
4620
|
+
};
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4623
|
+
// shopper/payments.ts
|
|
4624
|
+
var CARD_TYPES = /* @__PURE__ */ new Set(["card", "terminal", "taptopay", "moto", "cloud", "bluetooth"]);
|
|
4625
|
+
function kindOf(paymentType) {
|
|
4626
|
+
if (paymentType === "cash") return "cash";
|
|
4627
|
+
if (paymentType === "redeem") return "gift_card";
|
|
4628
|
+
if (paymentType === "pay_later") return "pay_later";
|
|
4629
|
+
if (CARD_TYPES.has(paymentType)) return "card";
|
|
4630
|
+
return "other";
|
|
4631
|
+
}
|
|
4632
|
+
function shopperPaymentsOf(legs) {
|
|
4633
|
+
return (legs ?? []).map((leg) => {
|
|
4634
|
+
const type = (leg.paymentType ?? "").trim();
|
|
4635
|
+
const kind = kindOf(type.toLowerCase());
|
|
4636
|
+
const card = kind === "card" ? cardFromProcessorData(leg.emv) : {};
|
|
4637
|
+
return {
|
|
4638
|
+
kind,
|
|
4639
|
+
// Cards: the issuer's name, else the brand. Other tenders the store named itself keep that name.
|
|
4640
|
+
name: kind === "card" ? card.cardIssuer ?? card.cardBrand ?? null : kind === "other" ? type || null : null,
|
|
4641
|
+
lastFour: card.cardLastFour ?? null,
|
|
4642
|
+
amount: (leg.amount ?? 0) + (leg.tip?.amount ?? 0)
|
|
4643
|
+
};
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4646
|
+
|
|
4315
4647
|
// constants/adyen.constants.ts
|
|
4316
4648
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
4317
4649
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4428,6 +4760,8 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4428
4760
|
CONDITION_OPERATORS,
|
|
4429
4761
|
COUNTRY_CURRENCIES,
|
|
4430
4762
|
CURRENCY_CONFIG,
|
|
4763
|
+
CUSTOMER_CONTACT_VERIFIED,
|
|
4764
|
+
CUSTOMER_EMAIL_TAKEN,
|
|
4431
4765
|
CompanyType,
|
|
4432
4766
|
CurrencyCode,
|
|
4433
4767
|
CustomTableAvailability,
|
|
@@ -4465,6 +4799,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4465
4799
|
ORDER_STATE_TOPIC,
|
|
4466
4800
|
OrderPlatform,
|
|
4467
4801
|
OtherFixedRates,
|
|
4802
|
+
OutOfProvinceTaxes,
|
|
4468
4803
|
OwnerType,
|
|
4469
4804
|
PATH_MODES,
|
|
4470
4805
|
PAYMENT_CHANNELS,
|
|
@@ -4493,6 +4828,12 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4493
4828
|
ResidualStatus,
|
|
4494
4829
|
ResourceAvailabilityState,
|
|
4495
4830
|
SHIPPING_COUNTRIES,
|
|
4831
|
+
SHOPPER_CONSENT_SOURCES,
|
|
4832
|
+
SHOPPER_ERROR_CODES,
|
|
4833
|
+
SHOPPER_RETURN_DECLINE_REASON_MAX,
|
|
4834
|
+
SHOPPER_RETURN_METHODS,
|
|
4835
|
+
SHOPPER_RETURN_STATUSES,
|
|
4836
|
+
STANDARD_TAX_TYPE,
|
|
4496
4837
|
STATE_SCHEMA,
|
|
4497
4838
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
4498
4839
|
SYSTEM_FAMILIES,
|
|
@@ -4510,6 +4851,11 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4510
4851
|
StationStatus,
|
|
4511
4852
|
StripeCurrencyCode,
|
|
4512
4853
|
StripeStatus,
|
|
4854
|
+
TAX_EXCEPTION_REASON_MAX,
|
|
4855
|
+
TaxExceptionSource,
|
|
4856
|
+
TaxRegistrationKind,
|
|
4857
|
+
TaxSource,
|
|
4858
|
+
TaxWarningCode,
|
|
4513
4859
|
TimePeriod,
|
|
4514
4860
|
TopMetericsSort,
|
|
4515
4861
|
UserTypes,
|
|
@@ -4524,11 +4870,13 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4524
4870
|
ancestorChain,
|
|
4525
4871
|
applyAssignment,
|
|
4526
4872
|
assertUnitSane,
|
|
4873
|
+
automaticTaxTableVersion,
|
|
4527
4874
|
availableIn,
|
|
4528
4875
|
baseFor,
|
|
4529
4876
|
baseFulfillmentDefinitions,
|
|
4530
4877
|
baseOf,
|
|
4531
4878
|
basePaymentDefinitions,
|
|
4879
|
+
buildAutomaticTaxTable,
|
|
4532
4880
|
buildAvailability,
|
|
4533
4881
|
buildGrid,
|
|
4534
4882
|
buildOrderContext,
|
|
@@ -4536,6 +4884,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4536
4884
|
buildResolvedConfig,
|
|
4537
4885
|
calculatePercentage,
|
|
4538
4886
|
canTransition,
|
|
4887
|
+
cardFromProcessorData,
|
|
4539
4888
|
cheapestCompositeItem,
|
|
4540
4889
|
cheapestCompositePrice,
|
|
4541
4890
|
compositeItemCost,
|
|
@@ -4554,6 +4903,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4554
4903
|
deriveUnitId,
|
|
4555
4904
|
displayRuleMatchesPair,
|
|
4556
4905
|
divideAmount,
|
|
4906
|
+
emailKey,
|
|
4557
4907
|
evaluateCondition,
|
|
4558
4908
|
evaluateConditionSet,
|
|
4559
4909
|
extendPrice,
|
|
@@ -4562,6 +4912,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4562
4912
|
formatInUnit,
|
|
4563
4913
|
formatMinorUnitsToString,
|
|
4564
4914
|
formatQuantity,
|
|
4915
|
+
formatShippingDuration,
|
|
4565
4916
|
fromBase,
|
|
4566
4917
|
fromMinorUnits,
|
|
4567
4918
|
generateMongoID,
|
|
@@ -4610,11 +4961,13 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4610
4961
|
normalizeMongoIdString,
|
|
4611
4962
|
normalizePostCode,
|
|
4612
4963
|
normalizeProvince,
|
|
4964
|
+
normalizeShopperEmail,
|
|
4613
4965
|
occupancyIn,
|
|
4614
4966
|
orderAssignments,
|
|
4615
4967
|
parseAmountToMinorUnits,
|
|
4616
4968
|
parseCurrencyCode,
|
|
4617
4969
|
parseStripeCurrencyCode,
|
|
4970
|
+
phoneKey,
|
|
4618
4971
|
placeKey,
|
|
4619
4972
|
planWindow,
|
|
4620
4973
|
poolDemand,
|
|
@@ -4625,6 +4978,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4625
4978
|
presentAt,
|
|
4626
4979
|
priceForTotal,
|
|
4627
4980
|
provincesForPostCode,
|
|
4981
|
+
registrationPlacesByKind,
|
|
4628
4982
|
removeFragment,
|
|
4629
4983
|
resolveFamily,
|
|
4630
4984
|
resolveModifiersForProduct,
|
|
@@ -4634,9 +4988,12 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4634
4988
|
roundToPrecision,
|
|
4635
4989
|
sameFamily,
|
|
4636
4990
|
setOrderState,
|
|
4991
|
+
sha1Hex,
|
|
4992
|
+
shippingDuration,
|
|
4637
4993
|
shipsToCountry,
|
|
4638
4994
|
shopDayKey,
|
|
4639
4995
|
shopDayRange,
|
|
4996
|
+
shopperPaymentsOf,
|
|
4640
4997
|
signReportForDisplay,
|
|
4641
4998
|
slotsForWindow,
|
|
4642
4999
|
stringifyMinorUnits,
|
|
@@ -4647,6 +5004,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4647
5004
|
validateFragmentCompatibility,
|
|
4648
5005
|
validateOrderStatuses,
|
|
4649
5006
|
validateShippingZone,
|
|
5007
|
+
verifiedContactChange,
|
|
4650
5008
|
violatesFinancialInvariant,
|
|
4651
5009
|
windowEndsAt,
|
|
4652
5010
|
withinPresence
|