@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.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";
|
|
@@ -1781,6 +1805,32 @@ function lineStockMoves(item, quantity, reservations = []) {
|
|
|
1781
1805
|
});
|
|
1782
1806
|
}
|
|
1783
1807
|
|
|
1808
|
+
// utils/contact-keys.util.ts
|
|
1809
|
+
function emailKey(email) {
|
|
1810
|
+
const key = email?.trim().toLowerCase();
|
|
1811
|
+
return key && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(key) ? key : null;
|
|
1812
|
+
}
|
|
1813
|
+
function phoneKey(phone) {
|
|
1814
|
+
const raw = phone?.trim();
|
|
1815
|
+
if (!raw) return null;
|
|
1816
|
+
const digits = raw.replace(/\D/g, "");
|
|
1817
|
+
if (raw.startsWith("+")) return digits.length >= 8 && digits.length <= 15 ? `+${digits}` : null;
|
|
1818
|
+
if (digits.length === 10) return `+1${digits}`;
|
|
1819
|
+
if (digits.length === 11 && digits.startsWith("1")) return `+${digits}`;
|
|
1820
|
+
return null;
|
|
1821
|
+
}
|
|
1822
|
+
var CUSTOMER_CONTACT_VERIFIED = "CUSTOMER_CONTACT_VERIFIED";
|
|
1823
|
+
var CUSTOMER_EMAIL_TAKEN = "CUSTOMER_EMAIL_TAKEN";
|
|
1824
|
+
function sameContact(a, b, key) {
|
|
1825
|
+
return (key(a) ?? a?.trim().toLowerCase() ?? "") === (key(b) ?? b?.trim().toLowerCase() ?? "");
|
|
1826
|
+
}
|
|
1827
|
+
function verifiedContactChange(existing, change) {
|
|
1828
|
+
if (!existing.verifiedShopperAt) return null;
|
|
1829
|
+
if (change.email !== void 0 && !sameContact(existing.email, change.email, emailKey)) return "email";
|
|
1830
|
+
if (change.phone !== void 0 && !sameContact(existing.phone, change.phone, phoneKey)) return "phone";
|
|
1831
|
+
return null;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1784
1834
|
// units/family-code.ts
|
|
1785
1835
|
var MAX_SLUG_LENGTH = 32;
|
|
1786
1836
|
var FALLBACK_SLUG = "family";
|
|
@@ -1823,6 +1873,7 @@ var FULFILLMENT_STATES = [
|
|
|
1823
1873
|
"in_progress",
|
|
1824
1874
|
"fulfilled",
|
|
1825
1875
|
"partially_fulfilled",
|
|
1876
|
+
"return_pending",
|
|
1826
1877
|
"returned",
|
|
1827
1878
|
"partially_returned",
|
|
1828
1879
|
"cancelled"
|
|
@@ -1848,10 +1899,7 @@ var CONDITION_OPERATORS = [
|
|
|
1848
1899
|
function isConditionOperator(value) {
|
|
1849
1900
|
return CONDITION_OPERATORS.includes(value);
|
|
1850
1901
|
}
|
|
1851
|
-
var PATH_MODES = [
|
|
1852
|
-
"strict",
|
|
1853
|
-
"permissive"
|
|
1854
|
-
];
|
|
1902
|
+
var PATH_MODES = ["strict", "permissive"];
|
|
1855
1903
|
|
|
1856
1904
|
// order-state-machine/state-schema.ts
|
|
1857
1905
|
var PAYMENT_DEFS = [
|
|
@@ -1872,6 +1920,9 @@ var FULFILLMENT_DEFS = [
|
|
|
1872
1920
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
1873
1921
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
1874
1922
|
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
1923
|
+
// The store accepted the shopper's return request: the goods are on their way back, no money has moved yet.
|
|
1924
|
+
// The refund lands `partially_returned` / `returned` as it does from `fulfilled`.
|
|
1925
|
+
{ id: "return_pending", label: "Return Accepted", terminal: false },
|
|
1875
1926
|
{ id: "returned", label: "Returned", terminal: true },
|
|
1876
1927
|
{ id: "partially_returned", label: "Partially Returned", terminal: false },
|
|
1877
1928
|
{ id: "cancelled", label: "Cancelled", terminal: true }
|
|
@@ -1901,6 +1952,8 @@ var STATE_SCHEMA = Object.freeze({
|
|
|
1901
1952
|
var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
|
|
1902
1953
|
var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
|
|
1903
1954
|
var UNRETURNED_MONEY_STATES = /* @__PURE__ */ new Set(["partially_paid", "paid", "partially_refunded"]);
|
|
1955
|
+
var RETURN_FROM_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "partially_returned"]);
|
|
1956
|
+
var RETURN_PENDING_PAYMENTS = /* @__PURE__ */ new Set(["paid", "partially_refunded"]);
|
|
1904
1957
|
var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
|
|
1905
1958
|
var FINANCIAL_INVARIANTS = [
|
|
1906
1959
|
{
|
|
@@ -1948,6 +2001,11 @@ var FINANCIAL_INVARIANTS = [
|
|
|
1948
2001
|
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",
|
|
1949
2002
|
check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
|
|
1950
2003
|
},
|
|
2004
|
+
{
|
|
2005
|
+
id: "return-pending-needs-goods-out",
|
|
2006
|
+
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",
|
|
2007
|
+
check: (from, to) => to.fulfillment === "return_pending" && (!RETURN_PENDING_PAYMENTS.has(to.payment) || from?.fulfillment !== "return_pending" && !(from && RETURN_FROM_FULFILLMENT.has(from.fulfillment)))
|
|
2008
|
+
},
|
|
1951
2009
|
{
|
|
1952
2010
|
id: "no-reopen-refunded-fulfillment",
|
|
1953
2011
|
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)",
|
|
@@ -2039,7 +2097,9 @@ var DISPLAY_LABEL_OVERRIDES = {
|
|
|
2039
2097
|
"paid|on_hold": "Parked - Paid",
|
|
2040
2098
|
"paid|fulfilled": "Completed",
|
|
2041
2099
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
2042
|
-
"partially_refunded|partially_returned": "Partially Refunded"
|
|
2100
|
+
"partially_refunded|partially_returned": "Partially Refunded",
|
|
2101
|
+
"paid|return_pending": "Return Accepted",
|
|
2102
|
+
"partially_refunded|return_pending": "Return Accepted"
|
|
2043
2103
|
};
|
|
2044
2104
|
var TERMINAL_LABEL_OVERRIDES = {
|
|
2045
2105
|
voided: "Cancelled"
|
|
@@ -2181,6 +2241,7 @@ function buildOrderContext(order, extras) {
|
|
|
2181
2241
|
}
|
|
2182
2242
|
|
|
2183
2243
|
// order-state-machine/display-state.ts
|
|
2244
|
+
var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
|
|
2184
2245
|
function atomLabel(atom, defs) {
|
|
2185
2246
|
return defs.find((d) => d.id === atom)?.label ?? atom;
|
|
2186
2247
|
}
|
|
@@ -2194,6 +2255,10 @@ function deriveDisplayState(payment, fulfillment, config) {
|
|
|
2194
2255
|
return { label: rule.label, color: rule.color, icon: rule.icon };
|
|
2195
2256
|
}
|
|
2196
2257
|
}
|
|
2258
|
+
if (ATOMS_ADDED_AFTER_SNAPSHOT.has(fulfillment)) {
|
|
2259
|
+
const fallback = DEFAULT_DISPLAY_STATE_MAP.find((rule) => displayRuleMatchesPair(rule, payment, fulfillment));
|
|
2260
|
+
if (fallback) return { label: fallback.label, color: fallback.color, icon: fallback.icon };
|
|
2261
|
+
}
|
|
2197
2262
|
return {
|
|
2198
2263
|
label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
|
|
2199
2264
|
};
|
|
@@ -3981,6 +4046,8 @@ function quote(option, zoneId, itemsTotal) {
|
|
|
3981
4046
|
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
3982
4047
|
minDays: option.minDays ?? null,
|
|
3983
4048
|
maxDays: option.maxDays ?? null,
|
|
4049
|
+
minMinutes: option.minMinutes ?? null,
|
|
4050
|
+
maxMinutes: option.maxMinutes ?? null,
|
|
3984
4051
|
outletId: option.outletId ?? null
|
|
3985
4052
|
};
|
|
3986
4053
|
}
|
|
@@ -3995,6 +4062,21 @@ function countriesShippedTo(zones) {
|
|
|
3995
4062
|
return [...countries].sort();
|
|
3996
4063
|
}
|
|
3997
4064
|
|
|
4065
|
+
// shipping/time.ts
|
|
4066
|
+
function shippingDuration(minMinutes, maxMinutes) {
|
|
4067
|
+
const min = minMinutes ?? maxMinutes;
|
|
4068
|
+
const max = maxMinutes ?? minMinutes;
|
|
4069
|
+
if (min == null || max == null) return null;
|
|
4070
|
+
const wholeHours = max > 0 && min % 60 === 0 && max % 60 === 0;
|
|
4071
|
+
return wholeHours ? { unit: "hour", min: min / 60, max: max / 60 } : { unit: "minute", min, max };
|
|
4072
|
+
}
|
|
4073
|
+
function formatShippingDuration(minMinutes, maxMinutes, locale, display = "long") {
|
|
4074
|
+
const duration = shippingDuration(minMinutes, maxMinutes);
|
|
4075
|
+
if (!duration) return null;
|
|
4076
|
+
const unit2 = new Intl.NumberFormat(locale ?? "en", { style: "unit", unit: duration.unit, unitDisplay: display });
|
|
4077
|
+
return duration.min === duration.max ? unit2.format(duration.max) : `${duration.min}\u2013${unit2.format(duration.max)}`;
|
|
4078
|
+
}
|
|
4079
|
+
|
|
3998
4080
|
// shipping/validate.ts
|
|
3999
4081
|
function validateShippingZone(zone) {
|
|
4000
4082
|
const problems = [...placeProblems(zone)];
|
|
@@ -4023,7 +4105,15 @@ function fitsKind(place, kind) {
|
|
|
4023
4105
|
return false;
|
|
4024
4106
|
}
|
|
4025
4107
|
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4026
|
-
var
|
|
4108
|
+
var isTime = (value) => value == null || isAmount(value);
|
|
4109
|
+
var inOrder = (min, max) => (min ?? 0) <= (max ?? Infinity);
|
|
4110
|
+
function timeIsValid(option) {
|
|
4111
|
+
const { minDays, maxDays, minMinutes, maxMinutes } = option;
|
|
4112
|
+
if (![minDays, maxDays, minMinutes, maxMinutes].every(isTime)) return false;
|
|
4113
|
+
const hasDays = minDays != null || maxDays != null;
|
|
4114
|
+
const hasMinutes = minMinutes != null || maxMinutes != null;
|
|
4115
|
+
return !(hasDays && hasMinutes) && inOrder(minDays, maxDays) && inOrder(minMinutes, maxMinutes);
|
|
4116
|
+
}
|
|
4027
4117
|
function optionProblems(option) {
|
|
4028
4118
|
const problems = [];
|
|
4029
4119
|
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
@@ -4031,9 +4121,7 @@ function optionProblems(option) {
|
|
|
4031
4121
|
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4032
4122
|
}
|
|
4033
4123
|
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4034
|
-
if (!
|
|
4035
|
-
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4036
|
-
}
|
|
4124
|
+
if (!timeIsValid(option)) problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4037
4125
|
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4038
4126
|
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4039
4127
|
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
@@ -4045,6 +4133,224 @@ function tiersAreValid(option) {
|
|
|
4045
4133
|
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
4046
4134
|
}
|
|
4047
4135
|
|
|
4136
|
+
// tax/sha1.ts
|
|
4137
|
+
function utf8Bytes(text) {
|
|
4138
|
+
const bytes = [];
|
|
4139
|
+
for (const char of text) {
|
|
4140
|
+
const cp = char.codePointAt(0);
|
|
4141
|
+
if (cp < 128) bytes.push(cp);
|
|
4142
|
+
else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
|
|
4143
|
+
else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4144
|
+
else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
|
|
4145
|
+
}
|
|
4146
|
+
return bytes;
|
|
4147
|
+
}
|
|
4148
|
+
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
4149
|
+
function sha1Hex(text) {
|
|
4150
|
+
const bytes = utf8Bytes(text);
|
|
4151
|
+
const bitLength = bytes.length * 8;
|
|
4152
|
+
bytes.push(128);
|
|
4153
|
+
while (bytes.length % 64 !== 56) bytes.push(0);
|
|
4154
|
+
const high = Math.floor(bitLength / 4294967296);
|
|
4155
|
+
for (const word of [high, bitLength >>> 0])
|
|
4156
|
+
bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
|
|
4157
|
+
const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
|
|
4158
|
+
const w = new Array(80);
|
|
4159
|
+
for (let offset = 0; offset < bytes.length; offset += 64) {
|
|
4160
|
+
for (let i = 0; i < 16; i++) {
|
|
4161
|
+
const j = offset + i * 4;
|
|
4162
|
+
w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
|
|
4163
|
+
}
|
|
4164
|
+
for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
|
|
4165
|
+
let [a, b, c, d, e] = h;
|
|
4166
|
+
for (let i = 0; i < 80; i++) {
|
|
4167
|
+
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];
|
|
4168
|
+
const t = rotl(a, 5) + f + e + k + w[i] | 0;
|
|
4169
|
+
e = d;
|
|
4170
|
+
d = c;
|
|
4171
|
+
c = rotl(b, 30);
|
|
4172
|
+
b = a;
|
|
4173
|
+
a = t;
|
|
4174
|
+
}
|
|
4175
|
+
h[0] = h[0] + a | 0;
|
|
4176
|
+
h[1] = h[1] + b | 0;
|
|
4177
|
+
h[2] = h[2] + c | 0;
|
|
4178
|
+
h[3] = h[3] + d | 0;
|
|
4179
|
+
h[4] = h[4] + e | 0;
|
|
4180
|
+
}
|
|
4181
|
+
return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
// tax/table.ts
|
|
4185
|
+
var STANDARD_TAX_TYPE = "standard";
|
|
4186
|
+
var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
|
|
4187
|
+
var RATE_FIELDS = [
|
|
4188
|
+
"code",
|
|
4189
|
+
"name",
|
|
4190
|
+
"kind",
|
|
4191
|
+
"places",
|
|
4192
|
+
"rate",
|
|
4193
|
+
"from",
|
|
4194
|
+
"to",
|
|
4195
|
+
"order",
|
|
4196
|
+
"compound",
|
|
4197
|
+
"registrationPlace",
|
|
4198
|
+
"harmonized",
|
|
4199
|
+
"parts",
|
|
4200
|
+
"sourceUrl",
|
|
4201
|
+
"status"
|
|
4202
|
+
];
|
|
4203
|
+
var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
|
|
4204
|
+
function canonical(row, fields) {
|
|
4205
|
+
return JSON.stringify(fields.map((field) => row[field] ?? null));
|
|
4206
|
+
}
|
|
4207
|
+
var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
|
|
4208
|
+
function automaticTaxTableVersion(table) {
|
|
4209
|
+
return sha1Hex(
|
|
4210
|
+
JSON.stringify([
|
|
4211
|
+
sortedCanonical(table.types, TYPE_FIELDS),
|
|
4212
|
+
sortedCanonical(table.rates, RATE_FIELDS),
|
|
4213
|
+
sortedCanonical(table.rules, RULE_FIELDS)
|
|
4214
|
+
])
|
|
4215
|
+
);
|
|
4216
|
+
}
|
|
4217
|
+
var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
|
|
4218
|
+
key,
|
|
4219
|
+
name,
|
|
4220
|
+
description,
|
|
4221
|
+
sortOrder,
|
|
4222
|
+
active
|
|
4223
|
+
});
|
|
4224
|
+
var toRateRow = (rate) => ({
|
|
4225
|
+
code: rate.code,
|
|
4226
|
+
name: rate.name,
|
|
4227
|
+
kind: rate.kind,
|
|
4228
|
+
places: rate.places,
|
|
4229
|
+
rate: rate.rate,
|
|
4230
|
+
from: rate.from,
|
|
4231
|
+
to: rate.to,
|
|
4232
|
+
order: rate.order,
|
|
4233
|
+
compound: rate.compound,
|
|
4234
|
+
registrationPlace: rate.registrationPlace,
|
|
4235
|
+
harmonized: rate.harmonized,
|
|
4236
|
+
parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
|
|
4237
|
+
sourceUrl: rate.sourceUrl,
|
|
4238
|
+
status: rate.status
|
|
4239
|
+
});
|
|
4240
|
+
var toRuleRow = ({
|
|
4241
|
+
taxType,
|
|
4242
|
+
codes: codes2,
|
|
4243
|
+
rate,
|
|
4244
|
+
from,
|
|
4245
|
+
to,
|
|
4246
|
+
sourceUrl,
|
|
4247
|
+
status,
|
|
4248
|
+
note
|
|
4249
|
+
}) => ({
|
|
4250
|
+
taxType,
|
|
4251
|
+
codes: codes2,
|
|
4252
|
+
rate,
|
|
4253
|
+
from,
|
|
4254
|
+
to,
|
|
4255
|
+
sourceUrl,
|
|
4256
|
+
status,
|
|
4257
|
+
note
|
|
4258
|
+
});
|
|
4259
|
+
function buildAutomaticTaxTable(rows) {
|
|
4260
|
+
const table = {
|
|
4261
|
+
types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
|
|
4262
|
+
rates: rows.rates.map(toRateRow),
|
|
4263
|
+
rules: rows.rules.map(toRuleRow)
|
|
4264
|
+
};
|
|
4265
|
+
return { version: automaticTaxTableVersion(table), ...table };
|
|
4266
|
+
}
|
|
4267
|
+
function registrationPlacesByKind(rates) {
|
|
4268
|
+
const places = /* @__PURE__ */ new Map();
|
|
4269
|
+
for (const rate of rates) {
|
|
4270
|
+
const list = places.get(rate.kind) ?? [];
|
|
4271
|
+
if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
|
|
4272
|
+
places.set(rate.kind, list);
|
|
4273
|
+
}
|
|
4274
|
+
return places;
|
|
4275
|
+
}
|
|
4276
|
+
|
|
4277
|
+
// tax/exceptions.ts
|
|
4278
|
+
var TaxExceptionSource = /* @__PURE__ */ ((TaxExceptionSource2) => {
|
|
4279
|
+
TaxExceptionSource2["PRODUCT"] = "product";
|
|
4280
|
+
TaxExceptionSource2["CATEGORY"] = "category";
|
|
4281
|
+
return TaxExceptionSource2;
|
|
4282
|
+
})(TaxExceptionSource || {});
|
|
4283
|
+
var TAX_EXCEPTION_REASON_MAX = 200;
|
|
4284
|
+
|
|
4285
|
+
// shopper/types.ts
|
|
4286
|
+
var SHOPPER_CONSENT_SOURCES = ["checkout", "my-account", "store-account"];
|
|
4287
|
+
var SHOPPER_RETURN_METHODS = ["mail", "in-store"];
|
|
4288
|
+
var SHOPPER_RETURN_STATUSES = ["requested", "accepted", "declined"];
|
|
4289
|
+
var SHOPPER_RETURN_DECLINE_REASON_MAX = 500;
|
|
4290
|
+
var SHOPPER_ERROR_CODES = {
|
|
4291
|
+
ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
|
|
4292
|
+
RETURN_ALREADY_REQUESTED: "RETURN_ALREADY_REQUESTED",
|
|
4293
|
+
RETURN_NOT_ALLOWED: "RETURN_NOT_ALLOWED",
|
|
4294
|
+
RETURN_ALREADY_DECIDED: "RETURN_ALREADY_DECIDED",
|
|
4295
|
+
STORE_HAS_NO_SUPPORT_EMAIL: "STORE_HAS_NO_SUPPORT_EMAIL",
|
|
4296
|
+
TOO_MANY_ADDRESSES: "TOO_MANY_ADDRESSES",
|
|
4297
|
+
STORE_NOT_LINKED: "STORE_NOT_LINKED",
|
|
4298
|
+
STORED_METHOD_NOT_FOUND: "STORED_METHOD_NOT_FOUND"
|
|
4299
|
+
};
|
|
4300
|
+
|
|
4301
|
+
// shopper/email.ts
|
|
4302
|
+
function normalizeShopperEmail(email) {
|
|
4303
|
+
if (typeof email !== "string") return null;
|
|
4304
|
+
const value = email.trim().toLowerCase();
|
|
4305
|
+
return /^[^\s@]+@[^\s@]+$/.test(value) ? value : null;
|
|
4306
|
+
}
|
|
4307
|
+
|
|
4308
|
+
// shopper/card.ts
|
|
4309
|
+
function cardFromProcessorData(processorData) {
|
|
4310
|
+
if (typeof processorData !== "string" || !processorData) return {};
|
|
4311
|
+
let data;
|
|
4312
|
+
try {
|
|
4313
|
+
data = JSON.parse(processorData);
|
|
4314
|
+
} catch {
|
|
4315
|
+
return {};
|
|
4316
|
+
}
|
|
4317
|
+
if (!data || typeof data !== "object") return {};
|
|
4318
|
+
const fields = new Map(Object.entries(data));
|
|
4319
|
+
const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
|
|
4320
|
+
const brand = text("Brand", "brand")?.trim();
|
|
4321
|
+
const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
|
|
4322
|
+
const issuer = text("Issuer", "issuer")?.trim();
|
|
4323
|
+
return {
|
|
4324
|
+
...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
|
|
4325
|
+
...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {},
|
|
4326
|
+
...issuer ? { cardIssuer: issuer } : {}
|
|
4327
|
+
};
|
|
4328
|
+
}
|
|
4329
|
+
|
|
4330
|
+
// shopper/payments.ts
|
|
4331
|
+
var CARD_TYPES = /* @__PURE__ */ new Set(["card", "terminal", "taptopay", "moto", "cloud", "bluetooth"]);
|
|
4332
|
+
function kindOf(paymentType) {
|
|
4333
|
+
if (paymentType === "cash") return "cash";
|
|
4334
|
+
if (paymentType === "redeem") return "gift_card";
|
|
4335
|
+
if (paymentType === "pay_later") return "pay_later";
|
|
4336
|
+
if (CARD_TYPES.has(paymentType)) return "card";
|
|
4337
|
+
return "other";
|
|
4338
|
+
}
|
|
4339
|
+
function shopperPaymentsOf(legs) {
|
|
4340
|
+
return (legs ?? []).map((leg) => {
|
|
4341
|
+
const type = (leg.paymentType ?? "").trim();
|
|
4342
|
+
const kind = kindOf(type.toLowerCase());
|
|
4343
|
+
const card = kind === "card" ? cardFromProcessorData(leg.emv) : {};
|
|
4344
|
+
return {
|
|
4345
|
+
kind,
|
|
4346
|
+
// Cards: the issuer's name, else the brand. Other tenders the store named itself keep that name.
|
|
4347
|
+
name: kind === "card" ? card.cardIssuer ?? card.cardBrand ?? null : kind === "other" ? type || null : null,
|
|
4348
|
+
lastFour: card.cardLastFour ?? null,
|
|
4349
|
+
amount: (leg.amount ?? 0) + (leg.tip?.amount ?? 0)
|
|
4350
|
+
};
|
|
4351
|
+
});
|
|
4352
|
+
}
|
|
4353
|
+
|
|
4048
4354
|
// constants/adyen.constants.ts
|
|
4049
4355
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
4050
4356
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4160,6 +4466,8 @@ export {
|
|
|
4160
4466
|
CONDITION_OPERATORS,
|
|
4161
4467
|
COUNTRY_CURRENCIES,
|
|
4162
4468
|
CURRENCY_CONFIG,
|
|
4469
|
+
CUSTOMER_CONTACT_VERIFIED,
|
|
4470
|
+
CUSTOMER_EMAIL_TAKEN,
|
|
4163
4471
|
CompanyType,
|
|
4164
4472
|
CurrencyCode,
|
|
4165
4473
|
CustomTableAvailability,
|
|
@@ -4197,6 +4505,7 @@ export {
|
|
|
4197
4505
|
ORDER_STATE_TOPIC,
|
|
4198
4506
|
OrderPlatform,
|
|
4199
4507
|
OtherFixedRates,
|
|
4508
|
+
OutOfProvinceTaxes,
|
|
4200
4509
|
OwnerType,
|
|
4201
4510
|
PATH_MODES,
|
|
4202
4511
|
PAYMENT_CHANNELS,
|
|
@@ -4225,6 +4534,12 @@ export {
|
|
|
4225
4534
|
ResidualStatus,
|
|
4226
4535
|
ResourceAvailabilityState,
|
|
4227
4536
|
SHIPPING_COUNTRIES,
|
|
4537
|
+
SHOPPER_CONSENT_SOURCES,
|
|
4538
|
+
SHOPPER_ERROR_CODES,
|
|
4539
|
+
SHOPPER_RETURN_DECLINE_REASON_MAX,
|
|
4540
|
+
SHOPPER_RETURN_METHODS,
|
|
4541
|
+
SHOPPER_RETURN_STATUSES,
|
|
4542
|
+
STANDARD_TAX_TYPE,
|
|
4228
4543
|
STATE_SCHEMA,
|
|
4229
4544
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
4230
4545
|
SYSTEM_FAMILIES,
|
|
@@ -4242,6 +4557,11 @@ export {
|
|
|
4242
4557
|
StationStatus,
|
|
4243
4558
|
StripeCurrencyCode,
|
|
4244
4559
|
StripeStatus,
|
|
4560
|
+
TAX_EXCEPTION_REASON_MAX,
|
|
4561
|
+
TaxExceptionSource,
|
|
4562
|
+
TaxRegistrationKind,
|
|
4563
|
+
TaxSource,
|
|
4564
|
+
TaxWarningCode,
|
|
4245
4565
|
TimePeriod,
|
|
4246
4566
|
TopMetericsSort,
|
|
4247
4567
|
UserTypes,
|
|
@@ -4256,11 +4576,13 @@ export {
|
|
|
4256
4576
|
ancestorChain,
|
|
4257
4577
|
applyAssignment,
|
|
4258
4578
|
assertUnitSane,
|
|
4579
|
+
automaticTaxTableVersion,
|
|
4259
4580
|
availableIn,
|
|
4260
4581
|
baseFor,
|
|
4261
4582
|
baseFulfillmentDefinitions,
|
|
4262
4583
|
baseOf,
|
|
4263
4584
|
basePaymentDefinitions,
|
|
4585
|
+
buildAutomaticTaxTable,
|
|
4264
4586
|
buildAvailability,
|
|
4265
4587
|
buildGrid,
|
|
4266
4588
|
buildOrderContext,
|
|
@@ -4268,6 +4590,7 @@ export {
|
|
|
4268
4590
|
buildResolvedConfig,
|
|
4269
4591
|
calculatePercentage,
|
|
4270
4592
|
canTransition,
|
|
4593
|
+
cardFromProcessorData,
|
|
4271
4594
|
cheapestCompositeItem,
|
|
4272
4595
|
cheapestCompositePrice,
|
|
4273
4596
|
compositeItemCost,
|
|
@@ -4286,6 +4609,7 @@ export {
|
|
|
4286
4609
|
deriveUnitId,
|
|
4287
4610
|
displayRuleMatchesPair,
|
|
4288
4611
|
divideAmount,
|
|
4612
|
+
emailKey,
|
|
4289
4613
|
evaluateCondition,
|
|
4290
4614
|
evaluateConditionSet,
|
|
4291
4615
|
extendPrice,
|
|
@@ -4294,6 +4618,7 @@ export {
|
|
|
4294
4618
|
formatInUnit,
|
|
4295
4619
|
formatMinorUnitsToString,
|
|
4296
4620
|
formatQuantity,
|
|
4621
|
+
formatShippingDuration,
|
|
4297
4622
|
fromBase,
|
|
4298
4623
|
fromMinorUnits,
|
|
4299
4624
|
generateMongoID,
|
|
@@ -4342,11 +4667,13 @@ export {
|
|
|
4342
4667
|
normalizeMongoIdString,
|
|
4343
4668
|
normalizePostCode,
|
|
4344
4669
|
normalizeProvince,
|
|
4670
|
+
normalizeShopperEmail,
|
|
4345
4671
|
occupancyIn,
|
|
4346
4672
|
orderAssignments,
|
|
4347
4673
|
parseAmountToMinorUnits,
|
|
4348
4674
|
parseCurrencyCode,
|
|
4349
4675
|
parseStripeCurrencyCode,
|
|
4676
|
+
phoneKey,
|
|
4350
4677
|
placeKey,
|
|
4351
4678
|
planWindow,
|
|
4352
4679
|
poolDemand,
|
|
@@ -4357,6 +4684,7 @@ export {
|
|
|
4357
4684
|
presentAt,
|
|
4358
4685
|
priceForTotal,
|
|
4359
4686
|
provincesForPostCode,
|
|
4687
|
+
registrationPlacesByKind,
|
|
4360
4688
|
removeFragment,
|
|
4361
4689
|
resolveFamily,
|
|
4362
4690
|
resolveModifiersForProduct,
|
|
@@ -4366,9 +4694,12 @@ export {
|
|
|
4366
4694
|
roundToPrecision,
|
|
4367
4695
|
sameFamily,
|
|
4368
4696
|
setOrderState,
|
|
4697
|
+
sha1Hex,
|
|
4698
|
+
shippingDuration,
|
|
4369
4699
|
shipsToCountry,
|
|
4370
4700
|
shopDayKey,
|
|
4371
4701
|
shopDayRange,
|
|
4702
|
+
shopperPaymentsOf,
|
|
4372
4703
|
signReportForDisplay,
|
|
4373
4704
|
slotsForWindow,
|
|
4374
4705
|
stringifyMinorUnits,
|
|
@@ -4379,6 +4710,7 @@ export {
|
|
|
4379
4710
|
validateFragmentCompatibility,
|
|
4380
4711
|
validateOrderStatuses,
|
|
4381
4712
|
validateShippingZone,
|
|
4713
|
+
verifiedContactChange,
|
|
4382
4714
|
violatesFinancialInvariant,
|
|
4383
4715
|
windowEndsAt,
|
|
4384
4716
|
withinPresence
|