@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/README.md +6 -6
- package/bin/gate-done.mjs +13 -26
- package/bin/lib/budget.mjs +1 -1
- 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.mjs
CHANGED
|
@@ -541,6 +541,30 @@ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
|
|
|
541
541
|
return ShippingZoneError2;
|
|
542
542
|
})(ShippingZoneError || {});
|
|
543
543
|
|
|
544
|
+
// enums/tax.enum.ts
|
|
545
|
+
var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
|
|
546
|
+
TaxRegistrationKind2["GST_HST"] = "GST_HST";
|
|
547
|
+
TaxRegistrationKind2["PST"] = "PST";
|
|
548
|
+
TaxRegistrationKind2["QST"] = "QST";
|
|
549
|
+
return TaxRegistrationKind2;
|
|
550
|
+
})(TaxRegistrationKind || {});
|
|
551
|
+
var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
|
|
552
|
+
TaxSource2["MERCHANT"] = "merchant";
|
|
553
|
+
TaxSource2["AUTOMATIC"] = "automatic";
|
|
554
|
+
return TaxSource2;
|
|
555
|
+
})(TaxSource || {});
|
|
556
|
+
var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
|
|
557
|
+
OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
|
|
558
|
+
OutOfProvinceTaxes2["HOME"] = "home";
|
|
559
|
+
return OutOfProvinceTaxes2;
|
|
560
|
+
})(OutOfProvinceTaxes || {});
|
|
561
|
+
var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
|
|
562
|
+
TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
|
|
563
|
+
TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
|
|
564
|
+
TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
|
|
565
|
+
return TaxWarningCode2;
|
|
566
|
+
})(TaxWarningCode || {});
|
|
567
|
+
|
|
544
568
|
// enums/sales-line.enum.ts
|
|
545
569
|
var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
|
|
546
570
|
SalesLineAction2["SALE"] = "sale";
|
|
@@ -1932,6 +1956,32 @@ function shellSettingsFromCompanyTips(enabled, options) {
|
|
|
1932
1956
|
return Object.keys(tips).length > 0 ? { tips } : {};
|
|
1933
1957
|
}
|
|
1934
1958
|
|
|
1959
|
+
// utils/contact-keys.util.ts
|
|
1960
|
+
function emailKey(email) {
|
|
1961
|
+
const key = email?.trim().toLowerCase();
|
|
1962
|
+
return key && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(key) ? key : null;
|
|
1963
|
+
}
|
|
1964
|
+
function phoneKey(phone) {
|
|
1965
|
+
const raw = phone?.trim();
|
|
1966
|
+
if (!raw) return null;
|
|
1967
|
+
const digits = raw.replace(/\D/g, "");
|
|
1968
|
+
if (raw.startsWith("+")) return digits.length >= 8 && digits.length <= 15 ? `+${digits}` : null;
|
|
1969
|
+
if (digits.length === 10) return `+1${digits}`;
|
|
1970
|
+
if (digits.length === 11 && digits.startsWith("1")) return `+${digits}`;
|
|
1971
|
+
return null;
|
|
1972
|
+
}
|
|
1973
|
+
var CUSTOMER_CONTACT_VERIFIED = "CUSTOMER_CONTACT_VERIFIED";
|
|
1974
|
+
var CUSTOMER_EMAIL_TAKEN = "CUSTOMER_EMAIL_TAKEN";
|
|
1975
|
+
function sameContact(a, b, key) {
|
|
1976
|
+
return (key(a) ?? a?.trim().toLowerCase() ?? "") === (key(b) ?? b?.trim().toLowerCase() ?? "");
|
|
1977
|
+
}
|
|
1978
|
+
function verifiedContactChange(existing, change) {
|
|
1979
|
+
if (!existing.verifiedShopperAt) return null;
|
|
1980
|
+
if (change.email !== void 0 && !sameContact(existing.email, change.email, emailKey)) return "email";
|
|
1981
|
+
if (change.phone !== void 0 && !sameContact(existing.phone, change.phone, phoneKey)) return "phone";
|
|
1982
|
+
return null;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1935
1985
|
// units/family-code.ts
|
|
1936
1986
|
var MAX_SLUG_LENGTH = 32;
|
|
1937
1987
|
var FALLBACK_SLUG = "family";
|
|
@@ -1974,6 +2024,7 @@ var FULFILLMENT_STATES = [
|
|
|
1974
2024
|
"in_progress",
|
|
1975
2025
|
"fulfilled",
|
|
1976
2026
|
"partially_fulfilled",
|
|
2027
|
+
"return_pending",
|
|
1977
2028
|
"returned",
|
|
1978
2029
|
"partially_returned",
|
|
1979
2030
|
"cancelled"
|
|
@@ -1999,10 +2050,7 @@ var CONDITION_OPERATORS = [
|
|
|
1999
2050
|
function isConditionOperator(value) {
|
|
2000
2051
|
return CONDITION_OPERATORS.includes(value);
|
|
2001
2052
|
}
|
|
2002
|
-
var PATH_MODES = [
|
|
2003
|
-
"strict",
|
|
2004
|
-
"permissive"
|
|
2005
|
-
];
|
|
2053
|
+
var PATH_MODES = ["strict", "permissive"];
|
|
2006
2054
|
|
|
2007
2055
|
// order-state-machine/state-schema.ts
|
|
2008
2056
|
var PAYMENT_DEFS = [
|
|
@@ -2023,6 +2071,9 @@ var FULFILLMENT_DEFS = [
|
|
|
2023
2071
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
2024
2072
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
2025
2073
|
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
2074
|
+
// The store accepted the shopper's return request: the goods are on their way back, no money has moved yet.
|
|
2075
|
+
// The refund lands `partially_returned` / `returned` as it does from `fulfilled`.
|
|
2076
|
+
{ id: "return_pending", label: "Return Accepted", terminal: false },
|
|
2026
2077
|
{ id: "returned", label: "Returned", terminal: true },
|
|
2027
2078
|
{ id: "partially_returned", label: "Partially Returned", terminal: false },
|
|
2028
2079
|
{ id: "cancelled", label: "Cancelled", terminal: true }
|
|
@@ -2052,6 +2103,8 @@ var STATE_SCHEMA = Object.freeze({
|
|
|
2052
2103
|
var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
|
|
2053
2104
|
var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
|
|
2054
2105
|
var UNRETURNED_MONEY_STATES = /* @__PURE__ */ new Set(["partially_paid", "paid", "partially_refunded"]);
|
|
2106
|
+
var RETURN_FROM_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "partially_returned"]);
|
|
2107
|
+
var RETURN_PENDING_PAYMENTS = /* @__PURE__ */ new Set(["paid", "partially_refunded"]);
|
|
2055
2108
|
var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
|
|
2056
2109
|
var FINANCIAL_INVARIANTS = [
|
|
2057
2110
|
{
|
|
@@ -2099,6 +2152,11 @@ var FINANCIAL_INVARIANTS = [
|
|
|
2099
2152
|
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",
|
|
2100
2153
|
check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
|
|
2101
2154
|
},
|
|
2155
|
+
{
|
|
2156
|
+
id: "return-pending-needs-goods-out",
|
|
2157
|
+
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",
|
|
2158
|
+
check: (from, to) => to.fulfillment === "return_pending" && (!RETURN_PENDING_PAYMENTS.has(to.payment) || from?.fulfillment !== "return_pending" && !(from && RETURN_FROM_FULFILLMENT.has(from.fulfillment)))
|
|
2159
|
+
},
|
|
2102
2160
|
{
|
|
2103
2161
|
id: "no-reopen-refunded-fulfillment",
|
|
2104
2162
|
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)",
|
|
@@ -2190,7 +2248,9 @@ var DISPLAY_LABEL_OVERRIDES = {
|
|
|
2190
2248
|
"paid|on_hold": "Parked - Paid",
|
|
2191
2249
|
"paid|fulfilled": "Completed",
|
|
2192
2250
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
2193
|
-
"partially_refunded|partially_returned": "Partially Refunded"
|
|
2251
|
+
"partially_refunded|partially_returned": "Partially Refunded",
|
|
2252
|
+
"paid|return_pending": "Return Accepted",
|
|
2253
|
+
"partially_refunded|return_pending": "Return Accepted"
|
|
2194
2254
|
};
|
|
2195
2255
|
var TERMINAL_LABEL_OVERRIDES = {
|
|
2196
2256
|
voided: "Cancelled"
|
|
@@ -2332,6 +2392,7 @@ function buildOrderContext(order, extras) {
|
|
|
2332
2392
|
}
|
|
2333
2393
|
|
|
2334
2394
|
// order-state-machine/display-state.ts
|
|
2395
|
+
var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
|
|
2335
2396
|
function atomLabel(atom, defs) {
|
|
2336
2397
|
return defs.find((d) => d.id === atom)?.label ?? atom;
|
|
2337
2398
|
}
|
|
@@ -2345,6 +2406,10 @@ function deriveDisplayState(payment, fulfillment, config) {
|
|
|
2345
2406
|
return { label: rule.label, color: rule.color, icon: rule.icon };
|
|
2346
2407
|
}
|
|
2347
2408
|
}
|
|
2409
|
+
if (ATOMS_ADDED_AFTER_SNAPSHOT.has(fulfillment)) {
|
|
2410
|
+
const fallback = DEFAULT_DISPLAY_STATE_MAP.find((rule) => displayRuleMatchesPair(rule, payment, fulfillment));
|
|
2411
|
+
if (fallback) return { label: fallback.label, color: fallback.color, icon: fallback.icon };
|
|
2412
|
+
}
|
|
2348
2413
|
return {
|
|
2349
2414
|
label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
|
|
2350
2415
|
};
|
|
@@ -4132,6 +4197,8 @@ function quote(option, zoneId, itemsTotal) {
|
|
|
4132
4197
|
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
4133
4198
|
minDays: option.minDays ?? null,
|
|
4134
4199
|
maxDays: option.maxDays ?? null,
|
|
4200
|
+
minMinutes: option.minMinutes ?? null,
|
|
4201
|
+
maxMinutes: option.maxMinutes ?? null,
|
|
4135
4202
|
outletId: option.outletId ?? null
|
|
4136
4203
|
};
|
|
4137
4204
|
}
|
|
@@ -4146,6 +4213,21 @@ function countriesShippedTo(zones) {
|
|
|
4146
4213
|
return [...countries].sort();
|
|
4147
4214
|
}
|
|
4148
4215
|
|
|
4216
|
+
// shipping/time.ts
|
|
4217
|
+
function shippingDuration(minMinutes, maxMinutes) {
|
|
4218
|
+
const min = minMinutes ?? maxMinutes;
|
|
4219
|
+
const max = maxMinutes ?? minMinutes;
|
|
4220
|
+
if (min == null || max == null) return null;
|
|
4221
|
+
const wholeHours = max > 0 && min % 60 === 0 && max % 60 === 0;
|
|
4222
|
+
return wholeHours ? { unit: "hour", min: min / 60, max: max / 60 } : { unit: "minute", min, max };
|
|
4223
|
+
}
|
|
4224
|
+
function formatShippingDuration(minMinutes, maxMinutes, locale, display = "long") {
|
|
4225
|
+
const duration = shippingDuration(minMinutes, maxMinutes);
|
|
4226
|
+
if (!duration) return null;
|
|
4227
|
+
const unit2 = new Intl.NumberFormat(locale ?? "en", { style: "unit", unit: duration.unit, unitDisplay: display });
|
|
4228
|
+
return duration.min === duration.max ? unit2.format(duration.max) : `${duration.min}\u2013${unit2.format(duration.max)}`;
|
|
4229
|
+
}
|
|
4230
|
+
|
|
4149
4231
|
// shipping/validate.ts
|
|
4150
4232
|
function validateShippingZone(zone) {
|
|
4151
4233
|
const problems = [...placeProblems(zone)];
|
|
@@ -4174,7 +4256,15 @@ function fitsKind(place, kind) {
|
|
|
4174
4256
|
return false;
|
|
4175
4257
|
}
|
|
4176
4258
|
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4177
|
-
var
|
|
4259
|
+
var isTime = (value) => value == null || isAmount(value);
|
|
4260
|
+
var inOrder = (min, max) => (min ?? 0) <= (max ?? Infinity);
|
|
4261
|
+
function timeIsValid(option) {
|
|
4262
|
+
const { minDays, maxDays, minMinutes, maxMinutes } = option;
|
|
4263
|
+
if (![minDays, maxDays, minMinutes, maxMinutes].every(isTime)) return false;
|
|
4264
|
+
const hasDays = minDays != null || maxDays != null;
|
|
4265
|
+
const hasMinutes = minMinutes != null || maxMinutes != null;
|
|
4266
|
+
return !(hasDays && hasMinutes) && inOrder(minDays, maxDays) && inOrder(minMinutes, maxMinutes);
|
|
4267
|
+
}
|
|
4178
4268
|
function optionProblems(option) {
|
|
4179
4269
|
const problems = [];
|
|
4180
4270
|
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
@@ -4182,9 +4272,7 @@ function optionProblems(option) {
|
|
|
4182
4272
|
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4183
4273
|
}
|
|
4184
4274
|
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4185
|
-
if (!
|
|
4186
|
-
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4187
|
-
}
|
|
4275
|
+
if (!timeIsValid(option)) problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4188
4276
|
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4189
4277
|
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4190
4278
|
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
@@ -4196,6 +4284,224 @@ function tiersAreValid(option) {
|
|
|
4196
4284
|
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
4197
4285
|
}
|
|
4198
4286
|
|
|
4287
|
+
// tax/sha1.ts
|
|
4288
|
+
function utf8Bytes(text) {
|
|
4289
|
+
const bytes = [];
|
|
4290
|
+
for (const char of text) {
|
|
4291
|
+
const cp = char.codePointAt(0);
|
|
4292
|
+
if (cp < 128) bytes.push(cp);
|
|
4293
|
+
else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
|
|
4294
|
+
else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4295
|
+
else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4296
|
+
}
|
|
4297
|
+
return bytes;
|
|
4298
|
+
}
|
|
4299
|
+
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
4300
|
+
function sha1Hex(text) {
|
|
4301
|
+
const bytes = utf8Bytes(text);
|
|
4302
|
+
const bitLength = bytes.length * 8;
|
|
4303
|
+
bytes.push(128);
|
|
4304
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
4305
|
+
const high = Math.floor(bitLength / 4294967296);
|
|
4306
|
+
for (const word of [high, bitLength >>> 0])
|
|
4307
|
+
bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
|
|
4308
|
+
const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
4309
|
+
const w = new Array(80);
|
|
4310
|
+
for (let offset = 0; offset < bytes.length; offset += 64) {
|
|
4311
|
+
for (let i = 0; i < 16; i++) {
|
|
4312
|
+
const j = offset + i * 4;
|
|
4313
|
+
w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
|
|
4314
|
+
}
|
|
4315
|
+
for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
|
|
4316
|
+
let [a, b, c, d, e] = h;
|
|
4317
|
+
for (let i = 0; i < 80; i++) {
|
|
4318
|
+
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];
|
|
4319
|
+
const t = rotl(a, 5) + f + e + k + w[i] | 0;
|
|
4320
|
+
e = d;
|
|
4321
|
+
d = c;
|
|
4322
|
+
c = rotl(b, 30);
|
|
4323
|
+
b = a;
|
|
4324
|
+
a = t;
|
|
4325
|
+
}
|
|
4326
|
+
h[0] = h[0] + a | 0;
|
|
4327
|
+
h[1] = h[1] + b | 0;
|
|
4328
|
+
h[2] = h[2] + c | 0;
|
|
4329
|
+
h[3] = h[3] + d | 0;
|
|
4330
|
+
h[4] = h[4] + e | 0;
|
|
4331
|
+
}
|
|
4332
|
+
return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
|
|
4333
|
+
}
|
|
4334
|
+
|
|
4335
|
+
// tax/table.ts
|
|
4336
|
+
var STANDARD_TAX_TYPE = "standard";
|
|
4337
|
+
var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
|
|
4338
|
+
var RATE_FIELDS = [
|
|
4339
|
+
"code",
|
|
4340
|
+
"name",
|
|
4341
|
+
"kind",
|
|
4342
|
+
"places",
|
|
4343
|
+
"rate",
|
|
4344
|
+
"from",
|
|
4345
|
+
"to",
|
|
4346
|
+
"order",
|
|
4347
|
+
"compound",
|
|
4348
|
+
"registrationPlace",
|
|
4349
|
+
"harmonized",
|
|
4350
|
+
"parts",
|
|
4351
|
+
"sourceUrl",
|
|
4352
|
+
"status"
|
|
4353
|
+
];
|
|
4354
|
+
var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
|
|
4355
|
+
function canonical(row, fields) {
|
|
4356
|
+
return JSON.stringify(fields.map((field) => row[field] ?? null));
|
|
4357
|
+
}
|
|
4358
|
+
var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
|
|
4359
|
+
function automaticTaxTableVersion(table) {
|
|
4360
|
+
return sha1Hex(
|
|
4361
|
+
JSON.stringify([
|
|
4362
|
+
sortedCanonical(table.types, TYPE_FIELDS),
|
|
4363
|
+
sortedCanonical(table.rates, RATE_FIELDS),
|
|
4364
|
+
sortedCanonical(table.rules, RULE_FIELDS)
|
|
4365
|
+
])
|
|
4366
|
+
);
|
|
4367
|
+
}
|
|
4368
|
+
var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
|
|
4369
|
+
key,
|
|
4370
|
+
name,
|
|
4371
|
+
description,
|
|
4372
|
+
sortOrder,
|
|
4373
|
+
active
|
|
4374
|
+
});
|
|
4375
|
+
var toRateRow = (rate) => ({
|
|
4376
|
+
code: rate.code,
|
|
4377
|
+
name: rate.name,
|
|
4378
|
+
kind: rate.kind,
|
|
4379
|
+
places: rate.places,
|
|
4380
|
+
rate: rate.rate,
|
|
4381
|
+
from: rate.from,
|
|
4382
|
+
to: rate.to,
|
|
4383
|
+
order: rate.order,
|
|
4384
|
+
compound: rate.compound,
|
|
4385
|
+
registrationPlace: rate.registrationPlace,
|
|
4386
|
+
harmonized: rate.harmonized,
|
|
4387
|
+
parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
|
|
4388
|
+
sourceUrl: rate.sourceUrl,
|
|
4389
|
+
status: rate.status
|
|
4390
|
+
});
|
|
4391
|
+
var toRuleRow = ({
|
|
4392
|
+
taxType,
|
|
4393
|
+
codes: codes2,
|
|
4394
|
+
rate,
|
|
4395
|
+
from,
|
|
4396
|
+
to,
|
|
4397
|
+
sourceUrl,
|
|
4398
|
+
status,
|
|
4399
|
+
note
|
|
4400
|
+
}) => ({
|
|
4401
|
+
taxType,
|
|
4402
|
+
codes: codes2,
|
|
4403
|
+
rate,
|
|
4404
|
+
from,
|
|
4405
|
+
to,
|
|
4406
|
+
sourceUrl,
|
|
4407
|
+
status,
|
|
4408
|
+
note
|
|
4409
|
+
});
|
|
4410
|
+
function buildAutomaticTaxTable(rows) {
|
|
4411
|
+
const table = {
|
|
4412
|
+
types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
|
|
4413
|
+
rates: rows.rates.map(toRateRow),
|
|
4414
|
+
rules: rows.rules.map(toRuleRow)
|
|
4415
|
+
};
|
|
4416
|
+
return { version: automaticTaxTableVersion(table), ...table };
|
|
4417
|
+
}
|
|
4418
|
+
function registrationPlacesByKind(rates) {
|
|
4419
|
+
const places = /* @__PURE__ */ new Map();
|
|
4420
|
+
for (const rate of rates) {
|
|
4421
|
+
const list = places.get(rate.kind) ?? [];
|
|
4422
|
+
if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
|
|
4423
|
+
places.set(rate.kind, list);
|
|
4424
|
+
}
|
|
4425
|
+
return places;
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4428
|
+
// tax/exceptions.ts
|
|
4429
|
+
var TaxExceptionSource = /* @__PURE__ */ ((TaxExceptionSource2) => {
|
|
4430
|
+
TaxExceptionSource2["PRODUCT"] = "product";
|
|
4431
|
+
TaxExceptionSource2["CATEGORY"] = "category";
|
|
4432
|
+
return TaxExceptionSource2;
|
|
4433
|
+
})(TaxExceptionSource || {});
|
|
4434
|
+
var TAX_EXCEPTION_REASON_MAX = 200;
|
|
4435
|
+
|
|
4436
|
+
// shopper/types.ts
|
|
4437
|
+
var SHOPPER_CONSENT_SOURCES = ["checkout", "my-account", "store-account"];
|
|
4438
|
+
var SHOPPER_RETURN_METHODS = ["mail", "in-store"];
|
|
4439
|
+
var SHOPPER_RETURN_STATUSES = ["requested", "accepted", "declined"];
|
|
4440
|
+
var SHOPPER_RETURN_DECLINE_REASON_MAX = 500;
|
|
4441
|
+
var SHOPPER_ERROR_CODES = {
|
|
4442
|
+
ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
|
|
4443
|
+
RETURN_ALREADY_REQUESTED: "RETURN_ALREADY_REQUESTED",
|
|
4444
|
+
RETURN_NOT_ALLOWED: "RETURN_NOT_ALLOWED",
|
|
4445
|
+
RETURN_ALREADY_DECIDED: "RETURN_ALREADY_DECIDED",
|
|
4446
|
+
STORE_HAS_NO_SUPPORT_EMAIL: "STORE_HAS_NO_SUPPORT_EMAIL",
|
|
4447
|
+
TOO_MANY_ADDRESSES: "TOO_MANY_ADDRESSES",
|
|
4448
|
+
STORE_NOT_LINKED: "STORE_NOT_LINKED",
|
|
4449
|
+
STORED_METHOD_NOT_FOUND: "STORED_METHOD_NOT_FOUND"
|
|
4450
|
+
};
|
|
4451
|
+
|
|
4452
|
+
// shopper/email.ts
|
|
4453
|
+
function normalizeShopperEmail(email) {
|
|
4454
|
+
if (typeof email !== "string") return null;
|
|
4455
|
+
const value = email.trim().toLowerCase();
|
|
4456
|
+
return /^[^\s@]+@[^\s@]+$/.test(value) ? value : null;
|
|
4457
|
+
}
|
|
4458
|
+
|
|
4459
|
+
// shopper/card.ts
|
|
4460
|
+
function cardFromProcessorData(processorData) {
|
|
4461
|
+
if (typeof processorData !== "string" || !processorData) return {};
|
|
4462
|
+
let data;
|
|
4463
|
+
try {
|
|
4464
|
+
data = JSON.parse(processorData);
|
|
4465
|
+
} catch {
|
|
4466
|
+
return {};
|
|
4467
|
+
}
|
|
4468
|
+
if (!data || typeof data !== "object") return {};
|
|
4469
|
+
const fields = new Map(Object.entries(data));
|
|
4470
|
+
const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
|
|
4471
|
+
const brand = text("Brand", "brand")?.trim();
|
|
4472
|
+
const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
|
|
4473
|
+
const issuer = text("Issuer", "issuer")?.trim();
|
|
4474
|
+
return {
|
|
4475
|
+
...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
|
|
4476
|
+
...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {},
|
|
4477
|
+
...issuer ? { cardIssuer: issuer } : {}
|
|
4478
|
+
};
|
|
4479
|
+
}
|
|
4480
|
+
|
|
4481
|
+
// shopper/payments.ts
|
|
4482
|
+
var CARD_TYPES = /* @__PURE__ */ new Set(["card", "terminal", "taptopay", "moto", "cloud", "bluetooth"]);
|
|
4483
|
+
function kindOf(paymentType) {
|
|
4484
|
+
if (paymentType === "cash") return "cash";
|
|
4485
|
+
if (paymentType === "redeem") return "gift_card";
|
|
4486
|
+
if (paymentType === "pay_later") return "pay_later";
|
|
4487
|
+
if (CARD_TYPES.has(paymentType)) return "card";
|
|
4488
|
+
return "other";
|
|
4489
|
+
}
|
|
4490
|
+
function shopperPaymentsOf(legs) {
|
|
4491
|
+
return (legs ?? []).map((leg) => {
|
|
4492
|
+
const type = (leg.paymentType ?? "").trim();
|
|
4493
|
+
const kind = kindOf(type.toLowerCase());
|
|
4494
|
+
const card = kind === "card" ? cardFromProcessorData(leg.emv) : {};
|
|
4495
|
+
return {
|
|
4496
|
+
kind,
|
|
4497
|
+
// Cards: the issuer's name, else the brand. Other tenders the store named itself keep that name.
|
|
4498
|
+
name: kind === "card" ? card.cardIssuer ?? card.cardBrand ?? null : kind === "other" ? type || null : null,
|
|
4499
|
+
lastFour: card.cardLastFour ?? null,
|
|
4500
|
+
amount: (leg.amount ?? 0) + (leg.tip?.amount ?? 0)
|
|
4501
|
+
};
|
|
4502
|
+
});
|
|
4503
|
+
}
|
|
4504
|
+
|
|
4199
4505
|
// constants/adyen.constants.ts
|
|
4200
4506
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
4201
4507
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4311,6 +4617,8 @@ export {
|
|
|
4311
4617
|
CONDITION_OPERATORS,
|
|
4312
4618
|
COUNTRY_CURRENCIES,
|
|
4313
4619
|
CURRENCY_CONFIG,
|
|
4620
|
+
CUSTOMER_CONTACT_VERIFIED,
|
|
4621
|
+
CUSTOMER_EMAIL_TAKEN,
|
|
4314
4622
|
CompanyType,
|
|
4315
4623
|
CurrencyCode,
|
|
4316
4624
|
CustomTableAvailability,
|
|
@@ -4349,6 +4657,7 @@ export {
|
|
|
4349
4657
|
ORDER_STATE_TOPIC,
|
|
4350
4658
|
OrderPlatform,
|
|
4351
4659
|
OtherFixedRates,
|
|
4660
|
+
OutOfProvinceTaxes,
|
|
4352
4661
|
OwnerType,
|
|
4353
4662
|
PATH_MODES,
|
|
4354
4663
|
PAYMENT_CHANNELS,
|
|
@@ -4382,6 +4691,12 @@ export {
|
|
|
4382
4691
|
SHELL_TIP_PERCENT_MAX,
|
|
4383
4692
|
SHELL_TIP_PERCENT_MIN,
|
|
4384
4693
|
SHIPPING_COUNTRIES,
|
|
4694
|
+
SHOPPER_CONSENT_SOURCES,
|
|
4695
|
+
SHOPPER_ERROR_CODES,
|
|
4696
|
+
SHOPPER_RETURN_DECLINE_REASON_MAX,
|
|
4697
|
+
SHOPPER_RETURN_METHODS,
|
|
4698
|
+
SHOPPER_RETURN_STATUSES,
|
|
4699
|
+
STANDARD_TAX_TYPE,
|
|
4385
4700
|
STATE_SCHEMA,
|
|
4386
4701
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
4387
4702
|
SYSTEM_FAMILIES,
|
|
@@ -4399,6 +4714,11 @@ export {
|
|
|
4399
4714
|
StationStatus,
|
|
4400
4715
|
StripeCurrencyCode,
|
|
4401
4716
|
StripeStatus,
|
|
4717
|
+
TAX_EXCEPTION_REASON_MAX,
|
|
4718
|
+
TaxExceptionSource,
|
|
4719
|
+
TaxRegistrationKind,
|
|
4720
|
+
TaxSource,
|
|
4721
|
+
TaxWarningCode,
|
|
4402
4722
|
TimePeriod,
|
|
4403
4723
|
TopMetericsSort,
|
|
4404
4724
|
UserTypes,
|
|
@@ -4413,11 +4733,13 @@ export {
|
|
|
4413
4733
|
ancestorChain,
|
|
4414
4734
|
applyAssignment,
|
|
4415
4735
|
assertUnitSane,
|
|
4736
|
+
automaticTaxTableVersion,
|
|
4416
4737
|
availableIn,
|
|
4417
4738
|
baseFor,
|
|
4418
4739
|
baseFulfillmentDefinitions,
|
|
4419
4740
|
baseOf,
|
|
4420
4741
|
basePaymentDefinitions,
|
|
4742
|
+
buildAutomaticTaxTable,
|
|
4421
4743
|
buildAvailability,
|
|
4422
4744
|
buildGrid,
|
|
4423
4745
|
buildOrderContext,
|
|
@@ -4425,6 +4747,7 @@ export {
|
|
|
4425
4747
|
buildResolvedConfig,
|
|
4426
4748
|
calculatePercentage,
|
|
4427
4749
|
canTransition,
|
|
4750
|
+
cardFromProcessorData,
|
|
4428
4751
|
cheapestCompositeItem,
|
|
4429
4752
|
cheapestCompositePrice,
|
|
4430
4753
|
compositeItemCost,
|
|
@@ -4443,6 +4766,7 @@ export {
|
|
|
4443
4766
|
deriveUnitId,
|
|
4444
4767
|
displayRuleMatchesPair,
|
|
4445
4768
|
divideAmount,
|
|
4769
|
+
emailKey,
|
|
4446
4770
|
evaluateCondition,
|
|
4447
4771
|
evaluateConditionSet,
|
|
4448
4772
|
extendPrice,
|
|
@@ -4452,6 +4776,7 @@ export {
|
|
|
4452
4776
|
formatInUnit,
|
|
4453
4777
|
formatMinorUnitsToString,
|
|
4454
4778
|
formatQuantity,
|
|
4779
|
+
formatShippingDuration,
|
|
4455
4780
|
fromBase,
|
|
4456
4781
|
fromMinorUnits,
|
|
4457
4782
|
generateMongoID,
|
|
@@ -4501,11 +4826,13 @@ export {
|
|
|
4501
4826
|
normalizeMongoIdString,
|
|
4502
4827
|
normalizePostCode,
|
|
4503
4828
|
normalizeProvince,
|
|
4829
|
+
normalizeShopperEmail,
|
|
4504
4830
|
occupancyIn,
|
|
4505
4831
|
orderAssignments,
|
|
4506
4832
|
parseAmountToMinorUnits,
|
|
4507
4833
|
parseCurrencyCode,
|
|
4508
4834
|
parseStripeCurrencyCode,
|
|
4835
|
+
phoneKey,
|
|
4509
4836
|
placeKey,
|
|
4510
4837
|
planWindow,
|
|
4511
4838
|
poolDemand,
|
|
@@ -4517,6 +4844,7 @@ export {
|
|
|
4517
4844
|
priceForTotal,
|
|
4518
4845
|
provincesForPostCode,
|
|
4519
4846
|
readShellTipSettings,
|
|
4847
|
+
registrationPlacesByKind,
|
|
4520
4848
|
removeFragment,
|
|
4521
4849
|
resolveFamily,
|
|
4522
4850
|
resolveModifiersForProduct,
|
|
@@ -4528,13 +4856,16 @@ export {
|
|
|
4528
4856
|
roundToPrecision,
|
|
4529
4857
|
sameFamily,
|
|
4530
4858
|
setOrderState,
|
|
4859
|
+
sha1Hex,
|
|
4531
4860
|
shellSettingsFromCompanyTips,
|
|
4532
4861
|
shellSettingsFromFlowSettings,
|
|
4533
4862
|
shellSettingsProblems,
|
|
4534
4863
|
shellTipSettingsProblems,
|
|
4864
|
+
shippingDuration,
|
|
4535
4865
|
shipsToCountry,
|
|
4536
4866
|
shopDayKey,
|
|
4537
4867
|
shopDayRange,
|
|
4868
|
+
shopperPaymentsOf,
|
|
4538
4869
|
signReportForDisplay,
|
|
4539
4870
|
slotsForWindow,
|
|
4540
4871
|
stringifyMinorUnits,
|
|
@@ -4545,6 +4876,7 @@ export {
|
|
|
4545
4876
|
validateFragmentCompatibility,
|
|
4546
4877
|
validateOrderStatuses,
|
|
4547
4878
|
validateShippingZone,
|
|
4879
|
+
verifiedContactChange,
|
|
4548
4880
|
violatesFinancialInvariant,
|
|
4549
4881
|
windowEndsAt,
|
|
4550
4882
|
withinPresence
|