@final-commerce/common 2.12.1-preprod.1 → 2.13.0-staging2.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 +26 -13
- package/bin/lib/budget.mjs +1 -1
- package/dist/index.d.mts +75 -367
- package/dist/index.d.ts +75 -367
- package/dist/index.js +177 -585
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -544
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +26 -101
- package/dist/pos-types/index.d.ts +26 -101
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -541,30 +541,6 @@ 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
|
-
|
|
568
544
|
// enums/sales-line.enum.ts
|
|
569
545
|
var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
|
|
570
546
|
SalesLineAction2["SALE"] = "sale";
|
|
@@ -1043,6 +1019,16 @@ function resolveUnit(unitId, companyUnits = []) {
|
|
|
1043
1019
|
if (!unit2) throw new Error(`Unknown measurement unit: ${unitId}`);
|
|
1044
1020
|
return unit2;
|
|
1045
1021
|
}
|
|
1022
|
+
function attachResolvedUnits(variants, companyUnits, logLabel = "attachUnits") {
|
|
1023
|
+
for (const variant of variants)
|
|
1024
|
+
if (variant.unitId)
|
|
1025
|
+
try {
|
|
1026
|
+
variant.unit = resolveUnit(variant.unitId, companyUnits);
|
|
1027
|
+
} catch (error) {
|
|
1028
|
+
console.error(`[${logLabel}] unit ${variant.unitId} does not resolve. ${error.message}`);
|
|
1029
|
+
}
|
|
1030
|
+
return variants;
|
|
1031
|
+
}
|
|
1046
1032
|
function resolveFamily(familyId, companyFamilies = []) {
|
|
1047
1033
|
const family = SYSTEM_FAMILIES.find((f) => f.familyId === familyId) ?? companyFamilies.find((f) => f.familyId === familyId);
|
|
1048
1034
|
if (!family) throw new Error(`Unknown measurement unit family: ${familyId}`);
|
|
@@ -1583,6 +1569,66 @@ function hasSellableChoice(modifier, outletId) {
|
|
|
1583
1569
|
}
|
|
1584
1570
|
var modifiersSellable = (modifiers, outletId) => modifiers.every((modifier) => !modifier.required || hasSellableChoice(modifier, outletId));
|
|
1585
1571
|
|
|
1572
|
+
// utils/line-stock-moves.util.ts
|
|
1573
|
+
function lineStockMoves(item, quantity, reservations = []) {
|
|
1574
|
+
const sign = Math.sign(quantity);
|
|
1575
|
+
const pool = (stockVariantId) => stockVariantId ? { stockVariantId: stockVariantId.toString() } : {};
|
|
1576
|
+
if (!item.components?.length)
|
|
1577
|
+
return [
|
|
1578
|
+
{
|
|
1579
|
+
productId: item.productId.toString(),
|
|
1580
|
+
variantId: item.variantId.toString(),
|
|
1581
|
+
fields: {
|
|
1582
|
+
quantity,
|
|
1583
|
+
...item.stockQuantity != null ? { stockQuantity: sign * item.stockQuantity, unitId: item.unitId?.toString() } : {},
|
|
1584
|
+
...pool(item.stockVariantId)
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
];
|
|
1588
|
+
const booked = new Set(
|
|
1589
|
+
reservations.filter((reservation) => reservation.lineItemInternalId && reservation.lineItemInternalId === item.internalId).map((reservation) => reservation.componentIndex)
|
|
1590
|
+
);
|
|
1591
|
+
return shelfComponents(item.components).flatMap(({ component, componentIndex, parentUnits }) => {
|
|
1592
|
+
if (booked.has(componentIndex)) return [];
|
|
1593
|
+
if (component.unitId && component.stockQuantity == null)
|
|
1594
|
+
throw new Error(
|
|
1595
|
+
`Composite ${item.productId?.toString()} component ${component.variantId.toString()} is sold in ${component.unitId.toString()} but carries no stockQuantity`
|
|
1596
|
+
);
|
|
1597
|
+
return [
|
|
1598
|
+
{
|
|
1599
|
+
productId: component.productId.toString(),
|
|
1600
|
+
variantId: component.variantId.toString(),
|
|
1601
|
+
componentIndex,
|
|
1602
|
+
fields: {
|
|
1603
|
+
quantity: component.quantity * parentUnits * quantity,
|
|
1604
|
+
...component.stockQuantity != null ? { stockQuantity: component.stockQuantity * parentUnits * quantity, unitId: component.unitId?.toString() } : {},
|
|
1605
|
+
...pool(component.stockVariantId),
|
|
1606
|
+
...item.productId ? { compositeProductId: item.productId.toString() } : {},
|
|
1607
|
+
...item.name ? { compositeName: item.name } : {}
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
];
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
function componentUnitsPerLine(components, index) {
|
|
1614
|
+
const component = components[index];
|
|
1615
|
+
if (!component) throw new Error(`No component ${index} on the line`);
|
|
1616
|
+
if (component.parentIndex == null) return component.quantity;
|
|
1617
|
+
if (component.parentIndex >= index)
|
|
1618
|
+
throw new Error(`Component ${index} points to parent ${component.parentIndex}, which is not before it`);
|
|
1619
|
+
return component.quantity * componentUnitsPerLine(components, component.parentIndex);
|
|
1620
|
+
}
|
|
1621
|
+
var isInnerComposite = (components, index) => components.some((child) => child.parentIndex === index);
|
|
1622
|
+
var shelfComponents = (components) => components.flatMap(
|
|
1623
|
+
(component, componentIndex) => isInnerComposite(components, componentIndex) ? [] : [
|
|
1624
|
+
{
|
|
1625
|
+
component,
|
|
1626
|
+
componentIndex,
|
|
1627
|
+
parentUnits: component.parentIndex == null ? 1 : componentUnitsPerLine(components, component.parentIndex)
|
|
1628
|
+
}
|
|
1629
|
+
]
|
|
1630
|
+
);
|
|
1631
|
+
|
|
1586
1632
|
// utils/composite-availability.util.ts
|
|
1587
1633
|
function poolStockAt(rows, outletId) {
|
|
1588
1634
|
if (!rows.some((row) => row.manageStock === true)) return null;
|
|
@@ -1721,7 +1767,9 @@ function poolDemand(lines) {
|
|
|
1721
1767
|
(demand.get(poolOf(line)) ?? 0) + (line.unit ? toBase(line.quantity * times, line.unit) : line.quantity * times)
|
|
1722
1768
|
);
|
|
1723
1769
|
for (const line of lines) {
|
|
1724
|
-
if (line.components)
|
|
1770
|
+
if (line.components)
|
|
1771
|
+
for (const { component, parentUnits } of shelfComponents(line.components))
|
|
1772
|
+
add(component, line.quantity * parentUnits);
|
|
1725
1773
|
else add(line, 1);
|
|
1726
1774
|
}
|
|
1727
1775
|
return demand;
|
|
@@ -1763,224 +1811,76 @@ function compositeReservationMismatches(order) {
|
|
|
1763
1811
|
});
|
|
1764
1812
|
}
|
|
1765
1813
|
|
|
1766
|
-
// utils/
|
|
1767
|
-
function
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
);
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
];
|
|
1814
|
+
// utils/variant-cost.util.ts
|
|
1815
|
+
function variantCostAtSale({
|
|
1816
|
+
costPrice,
|
|
1817
|
+
costPriceUpdatedAt,
|
|
1818
|
+
landedCost,
|
|
1819
|
+
lastReceivedAt
|
|
1820
|
+
}) {
|
|
1821
|
+
if (landedCost == null) return costPrice ?? null;
|
|
1822
|
+
if (costPrice == null) return landedCost;
|
|
1823
|
+
if (!costPriceUpdatedAt || !lastReceivedAt) return costPrice;
|
|
1824
|
+
return new Date(lastReceivedAt).getTime() > new Date(costPriceUpdatedAt).getTime() ? landedCost : costPrice;
|
|
1825
|
+
}
|
|
1826
|
+
function compositeCostOfKnown(items) {
|
|
1827
|
+
const known = items.filter((item) => item.cost !== null);
|
|
1828
|
+
if (!known.length) return null;
|
|
1829
|
+
return known.reduce((sum, { cost, quantity }) => sum + extendPrice(cost, quantity), 0);
|
|
1830
|
+
}
|
|
1831
|
+
function compositeCostRange(parts) {
|
|
1832
|
+
const missing = new Set(parts.flatMap((part) => part.options.flatMap((option) => option.missing)));
|
|
1833
|
+
const [low, high] = [pickedEnd(parts, "low"), pickedEnd(parts, "high")];
|
|
1834
|
+
const [lowCost, highCost] = [low.length ? compositeCostOfKnown(low) : 0, compositeCostOfKnown(high)];
|
|
1835
|
+
return { range: lowCost === null || highCost === null ? null : [lowCost, highCost], missing: [...missing] };
|
|
1836
|
+
}
|
|
1837
|
+
function innerCompositeOption(name, quantity, cost) {
|
|
1838
|
+
const [low, high] = cost.range ?? [null, null];
|
|
1839
|
+
return { name, quantity, low, high, missing: cost.range === null && !cost.missing.length ? [name] : cost.missing };
|
|
1840
|
+
}
|
|
1841
|
+
function variantLabel(variant, variantCount) {
|
|
1842
|
+
if (variantCount === 1) return "";
|
|
1843
|
+
const attributes = (variant.attributes ?? []).map((attribute) => attribute.value ?? attribute.values?.[0] ?? "");
|
|
1844
|
+
return attributes.filter(Boolean).join(" / ") || variant.name || variant.sku || "";
|
|
1845
|
+
}
|
|
1846
|
+
function variantDisplayName(productName, variant, variantCount) {
|
|
1847
|
+
const label = variantLabel(variant, variantCount);
|
|
1848
|
+
return label ? `${productName} \xB7 ${label}` : productName;
|
|
1849
|
+
}
|
|
1850
|
+
function pickedEnd(parts, end) {
|
|
1851
|
+
return parts.flatMap((part) => {
|
|
1852
|
+
if (!part.options.length) return [];
|
|
1853
|
+
const byCost = part.options.flatMap(({ quantity, [end]: cost }) => cost === null ? [] : [{ cost, quantity }]).sort((a, b) => extendPrice(a.cost, a.quantity) - extendPrice(b.cost, b.quantity));
|
|
1854
|
+
const pick = (end === "low" ? byCost[0] : byCost[byCost.length - 1]) ?? { cost: null, quantity: 1 };
|
|
1855
|
+
return Array(end === "low" ? part.minPicks : part.maxPicks).fill(pick);
|
|
1805
1856
|
});
|
|
1806
1857
|
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
}
|
|
1824
|
-
|
|
1825
|
-
var FIELD_ORDER = ["station"];
|
|
1826
|
-
var TIP_ORDER = ["station", "outlet", "flow", "company"];
|
|
1827
|
-
var TOP_FIELDS = [
|
|
1828
|
-
"pinSwitchUser",
|
|
1829
|
-
"pinSession",
|
|
1830
|
-
"stationLock",
|
|
1831
|
-
"buildTimeout",
|
|
1832
|
-
"lockedAccess",
|
|
1833
|
-
"cashManagement"
|
|
1834
|
-
];
|
|
1835
|
-
var TIP_FIELDS = ["enabled", "tip1", "tip2", "tip3", "customTipLabel", "noTipLabel"];
|
|
1836
|
-
function pick(levels, order, read, fallback) {
|
|
1837
|
-
for (const level of order) {
|
|
1838
|
-
const settings = levels[level];
|
|
1839
|
-
if (!settings) continue;
|
|
1840
|
-
const value = read(settings);
|
|
1841
|
-
if (value !== void 0 && value !== null) return { value, source: level };
|
|
1842
|
-
}
|
|
1843
|
-
return { value: fallback, source: "default" };
|
|
1844
|
-
}
|
|
1845
|
-
function resolveShellSettingsWithSources(levels) {
|
|
1846
|
-
const settings = { ...DEFAULT_SHELL_SETTINGS, tips: { ...DEFAULT_SHELL_SETTINGS.tips } };
|
|
1847
|
-
const sources = { fields: {}, tips: {} };
|
|
1848
|
-
for (const field of TOP_FIELDS) {
|
|
1849
|
-
const { value, source } = pick(levels, FIELD_ORDER, (s) => s[field], DEFAULT_SHELL_SETTINGS[field]);
|
|
1850
|
-
settings[field] = value;
|
|
1851
|
-
sources.fields[field] = source;
|
|
1852
|
-
}
|
|
1853
|
-
for (const field of TIP_FIELDS) {
|
|
1854
|
-
const { value, source } = pick(levels, TIP_ORDER, (s) => s.tips?.[field], DEFAULT_SHELL_SETTINGS.tips[field]);
|
|
1855
|
-
settings.tips[field] = value;
|
|
1856
|
-
sources.tips[field] = source;
|
|
1857
|
-
}
|
|
1858
|
-
return { settings, sources };
|
|
1859
|
-
}
|
|
1860
|
-
function resolveShellSettings(levels) {
|
|
1861
|
-
return resolveShellSettingsWithSources(levels).settings;
|
|
1862
|
-
}
|
|
1863
|
-
var SHELL_TIP_PERCENT_MIN = 1;
|
|
1864
|
-
var SHELL_TIP_PERCENT_MAX = 100;
|
|
1865
|
-
var SHELL_TIP_LABEL_MAX_LENGTH = 20;
|
|
1866
|
-
var isLabel = (raw) => typeof raw === "string" && raw.trim().length > 0 && raw.length <= SHELL_TIP_LABEL_MAX_LENGTH;
|
|
1867
|
-
var isShellTipPercent = (raw) => typeof raw === "number" && Number.isInteger(raw) && raw >= SHELL_TIP_PERCENT_MIN && raw <= SHELL_TIP_PERCENT_MAX;
|
|
1868
|
-
function shellTipSettingsProblems(tips) {
|
|
1869
|
-
if (!tips) return [];
|
|
1870
|
-
const problems = [];
|
|
1871
|
-
if (tips.enabled !== void 0 && typeof tips.enabled !== "boolean") {
|
|
1872
|
-
problems.push({ field: "tips.enabled", code: "boolean" });
|
|
1873
|
-
}
|
|
1874
|
-
for (const key of ["tip1", "tip2", "tip3"]) {
|
|
1875
|
-
const option = tips[key];
|
|
1876
|
-
if (option === void 0) continue;
|
|
1877
|
-
if (!option || typeof option !== "object") {
|
|
1878
|
-
problems.push({ field: `tips.${key}`, code: "preset" });
|
|
1879
|
-
continue;
|
|
1880
|
-
}
|
|
1881
|
-
if (!isShellTipPercent(option.value)) problems.push({ field: `tips.${key}`, code: "percent" });
|
|
1882
|
-
if (!isLabel(option.label)) problems.push({ field: `tips.${key}`, code: "label" });
|
|
1883
|
-
}
|
|
1884
|
-
for (const key of ["customTipLabel", "noTipLabel"]) {
|
|
1885
|
-
if (tips[key] !== void 0 && !isLabel(tips[key])) problems.push({ field: `tips.${key}`, code: "label" });
|
|
1886
|
-
}
|
|
1887
|
-
return problems;
|
|
1888
|
-
}
|
|
1889
|
-
function shellSettingsProblems(settings) {
|
|
1890
|
-
if (!settings) return [];
|
|
1891
|
-
const problems = [];
|
|
1892
|
-
for (const field of ["pinSwitchUser", "pinSession", "lockedAccess", "cashManagement"]) {
|
|
1893
|
-
if (settings[field] !== void 0 && typeof settings[field] !== "boolean")
|
|
1894
|
-
problems.push({ field, code: "boolean" });
|
|
1895
|
-
}
|
|
1896
|
-
for (const field of ["stationLock", "buildTimeout"]) {
|
|
1897
|
-
const value = settings[field];
|
|
1898
|
-
if (value !== void 0 && !(typeof value === "number" && Number.isInteger(value) && value >= 0)) {
|
|
1899
|
-
problems.push({ field, code: "timeout" });
|
|
1900
|
-
}
|
|
1901
|
-
}
|
|
1902
|
-
return [...problems, ...shellTipSettingsProblems(settings.tips)];
|
|
1903
|
-
}
|
|
1904
|
-
var SHELL_FLOW_SETTINGS_PREFIX = "flowSettingsKey";
|
|
1905
|
-
var SHELL_FLOW_TIPS_KEY = `${SHELL_FLOW_SETTINGS_PREFIX}.tips`;
|
|
1906
|
-
var readBoolean = (raw) => {
|
|
1907
|
-
if (raw === void 0 || raw === "") return void 0;
|
|
1908
|
-
const v = raw.trim().toLowerCase();
|
|
1909
|
-
if (v === "true") return true;
|
|
1910
|
-
if (v === "false") return false;
|
|
1911
|
-
return void 0;
|
|
1912
|
-
};
|
|
1913
|
-
function readTipOption(raw) {
|
|
1914
|
-
if (!raw || typeof raw !== "object") return void 0;
|
|
1915
|
-
const { label, value } = raw;
|
|
1916
|
-
const n = typeof value === "number" ? value : parseFloat(String(value ?? ""));
|
|
1917
|
-
if (typeof label !== "string" || !Number.isFinite(n) || n < 0) return void 0;
|
|
1918
|
-
return { label, value: n };
|
|
1919
|
-
}
|
|
1920
|
-
function readShellTipSettings(raw) {
|
|
1921
|
-
if (!raw || typeof raw !== "object") return void 0;
|
|
1922
|
-
const r = raw;
|
|
1923
|
-
const tips = {};
|
|
1924
|
-
if (typeof r.enabled === "boolean") tips.enabled = r.enabled;
|
|
1925
|
-
const tip1 = readTipOption(r.tip1);
|
|
1926
|
-
const tip2 = readTipOption(r.tip2);
|
|
1927
|
-
const tip3 = readTipOption(r.tip3);
|
|
1928
|
-
if (tip1) tips.tip1 = tip1;
|
|
1929
|
-
if (tip2) tips.tip2 = tip2;
|
|
1930
|
-
if (tip3) tips.tip3 = tip3;
|
|
1931
|
-
if (typeof r.customTipLabel === "string") tips.customTipLabel = r.customTipLabel;
|
|
1932
|
-
if (typeof r.noTipLabel === "string") tips.noTipLabel = r.noTipLabel;
|
|
1933
|
-
return Object.keys(tips).length > 0 ? tips : void 0;
|
|
1934
|
-
}
|
|
1935
|
-
var parseJson = (raw) => {
|
|
1936
|
-
if (!raw) return void 0;
|
|
1937
|
-
try {
|
|
1938
|
-
return JSON.parse(raw);
|
|
1939
|
-
} catch {
|
|
1940
|
-
return void 0;
|
|
1858
|
+
function costPriceChangeStamp(next, stored) {
|
|
1859
|
+
if (next === void 0 || next === (stored ?? null)) return {};
|
|
1860
|
+
return { costPriceUpdatedAt: /* @__PURE__ */ new Date() };
|
|
1861
|
+
}
|
|
1862
|
+
function bankersRoundDiv(numerator, denominator) {
|
|
1863
|
+
if (denominator === 0n) return 0n;
|
|
1864
|
+
const negative = numerator < 0n !== denominator < 0n;
|
|
1865
|
+
const n = numerator < 0n ? -numerator : numerator;
|
|
1866
|
+
const d = denominator < 0n ? -denominator : denominator;
|
|
1867
|
+
const quotient = n / d;
|
|
1868
|
+
const twiceRemainder = n % d * 2n;
|
|
1869
|
+
let result;
|
|
1870
|
+
if (twiceRemainder < d) {
|
|
1871
|
+
result = quotient;
|
|
1872
|
+
} else if (twiceRemainder > d) {
|
|
1873
|
+
result = quotient + 1n;
|
|
1874
|
+
} else {
|
|
1875
|
+
result = quotient % 2n === 0n ? quotient : quotient + 1n;
|
|
1941
1876
|
}
|
|
1942
|
-
|
|
1943
|
-
function shellSettingsFromFlowSettings(dict) {
|
|
1944
|
-
const tips = readShellTipSettings(parseJson(dict?.[SHELL_FLOW_TIPS_KEY]));
|
|
1945
|
-
return tips ? { tips } : {};
|
|
1946
|
-
}
|
|
1947
|
-
function flowSettingsFromShellSettings(settings) {
|
|
1948
|
-
return settings.tips && Object.keys(settings.tips).length > 0 ? { [SHELL_FLOW_TIPS_KEY]: JSON.stringify(settings.tips) } : {};
|
|
1877
|
+
return negative ? -result : result;
|
|
1949
1878
|
}
|
|
1950
|
-
function
|
|
1951
|
-
|
|
1952
|
-
...readShellTipSettings(typeof options === "string" ? parseJson(options) : options)
|
|
1953
|
-
};
|
|
1954
|
-
const on = typeof enabled === "boolean" ? enabled : readBoolean(typeof enabled === "string" ? enabled : void 0);
|
|
1955
|
-
if (on !== void 0) tips.enabled = on;
|
|
1956
|
-
return Object.keys(tips).length > 0 ? { tips } : {};
|
|
1957
|
-
}
|
|
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;
|
|
1879
|
+
function landedCostPerUnit(landedValue, baseQuantity, ratioToBase = 1) {
|
|
1880
|
+
return Number(bankersRoundDiv(BigInt(Math.round(landedValue * ratioToBase)), BigInt(baseQuantity)));
|
|
1983
1881
|
}
|
|
1882
|
+
var bookCostPerUnit = (book, ratioToBase) => book && book.totalQuantity > 0 && ratioToBase ? landedCostPerUnit(book.totalLandedValue, book.totalQuantity, ratioToBase) : null;
|
|
1883
|
+
var marginPercentOf = (grossProfit, costedGross) => grossProfit === null || !costedGross ? null : grossProfit * 100 / costedGross;
|
|
1984
1884
|
|
|
1985
1885
|
// units/family-code.ts
|
|
1986
1886
|
var MAX_SLUG_LENGTH = 32;
|
|
@@ -2024,7 +1924,6 @@ var FULFILLMENT_STATES = [
|
|
|
2024
1924
|
"in_progress",
|
|
2025
1925
|
"fulfilled",
|
|
2026
1926
|
"partially_fulfilled",
|
|
2027
|
-
"return_pending",
|
|
2028
1927
|
"returned",
|
|
2029
1928
|
"partially_returned",
|
|
2030
1929
|
"cancelled"
|
|
@@ -2050,7 +1949,10 @@ var CONDITION_OPERATORS = [
|
|
|
2050
1949
|
function isConditionOperator(value) {
|
|
2051
1950
|
return CONDITION_OPERATORS.includes(value);
|
|
2052
1951
|
}
|
|
2053
|
-
var PATH_MODES = [
|
|
1952
|
+
var PATH_MODES = [
|
|
1953
|
+
"strict",
|
|
1954
|
+
"permissive"
|
|
1955
|
+
];
|
|
2054
1956
|
|
|
2055
1957
|
// order-state-machine/state-schema.ts
|
|
2056
1958
|
var PAYMENT_DEFS = [
|
|
@@ -2071,9 +1973,6 @@ var FULFILLMENT_DEFS = [
|
|
|
2071
1973
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
2072
1974
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
2073
1975
|
{ 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 },
|
|
2077
1976
|
{ id: "returned", label: "Returned", terminal: true },
|
|
2078
1977
|
{ id: "partially_returned", label: "Partially Returned", terminal: false },
|
|
2079
1978
|
{ id: "cancelled", label: "Cancelled", terminal: true }
|
|
@@ -2103,8 +2002,6 @@ var STATE_SCHEMA = Object.freeze({
|
|
|
2103
2002
|
var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
|
|
2104
2003
|
var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
|
|
2105
2004
|
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"]);
|
|
2108
2005
|
var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
|
|
2109
2006
|
var FINANCIAL_INVARIANTS = [
|
|
2110
2007
|
{
|
|
@@ -2152,11 +2049,6 @@ var FINANCIAL_INVARIANTS = [
|
|
|
2152
2049
|
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",
|
|
2153
2050
|
check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
|
|
2154
2051
|
},
|
|
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
|
-
},
|
|
2160
2052
|
{
|
|
2161
2053
|
id: "no-reopen-refunded-fulfillment",
|
|
2162
2054
|
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)",
|
|
@@ -2248,9 +2140,7 @@ var DISPLAY_LABEL_OVERRIDES = {
|
|
|
2248
2140
|
"paid|on_hold": "Parked - Paid",
|
|
2249
2141
|
"paid|fulfilled": "Completed",
|
|
2250
2142
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
2251
|
-
"partially_refunded|partially_returned": "Partially Refunded"
|
|
2252
|
-
"paid|return_pending": "Return Accepted",
|
|
2253
|
-
"partially_refunded|return_pending": "Return Accepted"
|
|
2143
|
+
"partially_refunded|partially_returned": "Partially Refunded"
|
|
2254
2144
|
};
|
|
2255
2145
|
var TERMINAL_LABEL_OVERRIDES = {
|
|
2256
2146
|
voided: "Cancelled"
|
|
@@ -2392,7 +2282,6 @@ function buildOrderContext(order, extras) {
|
|
|
2392
2282
|
}
|
|
2393
2283
|
|
|
2394
2284
|
// order-state-machine/display-state.ts
|
|
2395
|
-
var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
|
|
2396
2285
|
function atomLabel(atom, defs) {
|
|
2397
2286
|
return defs.find((d) => d.id === atom)?.label ?? atom;
|
|
2398
2287
|
}
|
|
@@ -2406,10 +2295,6 @@ function deriveDisplayState(payment, fulfillment, config) {
|
|
|
2406
2295
|
return { label: rule.label, color: rule.color, icon: rule.icon };
|
|
2407
2296
|
}
|
|
2408
2297
|
}
|
|
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
|
-
}
|
|
2413
2298
|
return {
|
|
2414
2299
|
label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
|
|
2415
2300
|
};
|
|
@@ -4197,8 +4082,6 @@ function quote(option, zoneId, itemsTotal) {
|
|
|
4197
4082
|
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
4198
4083
|
minDays: option.minDays ?? null,
|
|
4199
4084
|
maxDays: option.maxDays ?? null,
|
|
4200
|
-
minMinutes: option.minMinutes ?? null,
|
|
4201
|
-
maxMinutes: option.maxMinutes ?? null,
|
|
4202
4085
|
outletId: option.outletId ?? null
|
|
4203
4086
|
};
|
|
4204
4087
|
}
|
|
@@ -4213,21 +4096,6 @@ function countriesShippedTo(zones) {
|
|
|
4213
4096
|
return [...countries].sort();
|
|
4214
4097
|
}
|
|
4215
4098
|
|
|
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
|
-
|
|
4231
4099
|
// shipping/validate.ts
|
|
4232
4100
|
function validateShippingZone(zone) {
|
|
4233
4101
|
const problems = [...placeProblems(zone)];
|
|
@@ -4256,15 +4124,7 @@ function fitsKind(place, kind) {
|
|
|
4256
4124
|
return false;
|
|
4257
4125
|
}
|
|
4258
4126
|
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4259
|
-
var
|
|
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
|
-
}
|
|
4127
|
+
var isDays = (value) => value == null || isAmount(value);
|
|
4268
4128
|
function optionProblems(option) {
|
|
4269
4129
|
const problems = [];
|
|
4270
4130
|
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
@@ -4272,7 +4132,9 @@ function optionProblems(option) {
|
|
|
4272
4132
|
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4273
4133
|
}
|
|
4274
4134
|
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4275
|
-
if (!
|
|
4135
|
+
if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
|
|
4136
|
+
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4137
|
+
}
|
|
4276
4138
|
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4277
4139
|
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4278
4140
|
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
@@ -4284,224 +4146,6 @@ function tiersAreValid(option) {
|
|
|
4284
4146
|
return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
|
|
4285
4147
|
}
|
|
4286
4148
|
|
|
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
|
-
|
|
4505
4149
|
// constants/adyen.constants.ts
|
|
4506
4150
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
4507
4151
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4617,8 +4261,6 @@ export {
|
|
|
4617
4261
|
CONDITION_OPERATORS,
|
|
4618
4262
|
COUNTRY_CURRENCIES,
|
|
4619
4263
|
CURRENCY_CONFIG,
|
|
4620
|
-
CUSTOMER_CONTACT_VERIFIED,
|
|
4621
|
-
CUSTOMER_EMAIL_TAKEN,
|
|
4622
4264
|
CompanyType,
|
|
4623
4265
|
CurrencyCode,
|
|
4624
4266
|
CustomTableAvailability,
|
|
@@ -4628,7 +4270,6 @@ export {
|
|
|
4628
4270
|
DEFAULT_DISPLAY_STATE_MAP,
|
|
4629
4271
|
DEFAULT_HOLD_MINUTES,
|
|
4630
4272
|
DEFAULT_RESOLVED_CONFIG,
|
|
4631
|
-
DEFAULT_SHELL_SETTINGS,
|
|
4632
4273
|
DEFAULT_UNIT_ID,
|
|
4633
4274
|
DualWriteStrategy,
|
|
4634
4275
|
EUFixedRates,
|
|
@@ -4657,7 +4298,6 @@ export {
|
|
|
4657
4298
|
ORDER_STATE_TOPIC,
|
|
4658
4299
|
OrderPlatform,
|
|
4659
4300
|
OtherFixedRates,
|
|
4660
|
-
OutOfProvinceTaxes,
|
|
4661
4301
|
OwnerType,
|
|
4662
4302
|
PATH_MODES,
|
|
4663
4303
|
PAYMENT_CHANNELS,
|
|
@@ -4685,18 +4325,7 @@ export {
|
|
|
4685
4325
|
ResidualPaymentMethod,
|
|
4686
4326
|
ResidualStatus,
|
|
4687
4327
|
ResourceAvailabilityState,
|
|
4688
|
-
SHELL_FLOW_SETTINGS_PREFIX,
|
|
4689
|
-
SHELL_FLOW_TIPS_KEY,
|
|
4690
|
-
SHELL_TIP_LABEL_MAX_LENGTH,
|
|
4691
|
-
SHELL_TIP_PERCENT_MAX,
|
|
4692
|
-
SHELL_TIP_PERCENT_MIN,
|
|
4693
4328
|
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,
|
|
4700
4329
|
STATE_SCHEMA,
|
|
4701
4330
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
4702
4331
|
SYSTEM_FAMILIES,
|
|
@@ -4714,11 +4343,6 @@ export {
|
|
|
4714
4343
|
StationStatus,
|
|
4715
4344
|
StripeCurrencyCode,
|
|
4716
4345
|
StripeStatus,
|
|
4717
|
-
TAX_EXCEPTION_REASON_MAX,
|
|
4718
|
-
TaxExceptionSource,
|
|
4719
|
-
TaxRegistrationKind,
|
|
4720
|
-
TaxSource,
|
|
4721
|
-
TaxWarningCode,
|
|
4722
4346
|
TimePeriod,
|
|
4723
4347
|
TopMetericsSort,
|
|
4724
4348
|
UserTypes,
|
|
@@ -4733,13 +4357,14 @@ export {
|
|
|
4733
4357
|
ancestorChain,
|
|
4734
4358
|
applyAssignment,
|
|
4735
4359
|
assertUnitSane,
|
|
4736
|
-
|
|
4360
|
+
attachResolvedUnits,
|
|
4737
4361
|
availableIn,
|
|
4362
|
+
bankersRoundDiv,
|
|
4738
4363
|
baseFor,
|
|
4739
4364
|
baseFulfillmentDefinitions,
|
|
4740
4365
|
baseOf,
|
|
4741
4366
|
basePaymentDefinitions,
|
|
4742
|
-
|
|
4367
|
+
bookCostPerUnit,
|
|
4743
4368
|
buildAvailability,
|
|
4744
4369
|
buildGrid,
|
|
4745
4370
|
buildOrderContext,
|
|
@@ -4747,9 +4372,11 @@ export {
|
|
|
4747
4372
|
buildResolvedConfig,
|
|
4748
4373
|
calculatePercentage,
|
|
4749
4374
|
canTransition,
|
|
4750
|
-
cardFromProcessorData,
|
|
4751
4375
|
cheapestCompositeItem,
|
|
4752
4376
|
cheapestCompositePrice,
|
|
4377
|
+
componentUnitsPerLine,
|
|
4378
|
+
compositeCostOfKnown,
|
|
4379
|
+
compositeCostRange,
|
|
4753
4380
|
compositeItemCost,
|
|
4754
4381
|
compositeItemUnavailable,
|
|
4755
4382
|
compositeMakeable,
|
|
@@ -4758,6 +4385,7 @@ export {
|
|
|
4758
4385
|
compositeVariantInStock,
|
|
4759
4386
|
conditionSummary,
|
|
4760
4387
|
convertFixedFeeToLocalCurrency,
|
|
4388
|
+
costPriceChangeStamp,
|
|
4761
4389
|
createAmount,
|
|
4762
4390
|
crossAxisRuleApplies,
|
|
4763
4391
|
currentAssignees,
|
|
@@ -4766,17 +4394,14 @@ export {
|
|
|
4766
4394
|
deriveUnitId,
|
|
4767
4395
|
displayRuleMatchesPair,
|
|
4768
4396
|
divideAmount,
|
|
4769
|
-
emailKey,
|
|
4770
4397
|
evaluateCondition,
|
|
4771
4398
|
evaluateConditionSet,
|
|
4772
4399
|
extendPrice,
|
|
4773
4400
|
extendPriceFor,
|
|
4774
|
-
flowSettingsFromShellSettings,
|
|
4775
4401
|
formatCurrency,
|
|
4776
4402
|
formatInUnit,
|
|
4777
4403
|
formatMinorUnitsToString,
|
|
4778
4404
|
formatQuantity,
|
|
4779
|
-
formatShippingDuration,
|
|
4780
4405
|
fromBase,
|
|
4781
4406
|
fromMinorUnits,
|
|
4782
4407
|
generateMongoID,
|
|
@@ -4798,6 +4423,7 @@ export {
|
|
|
4798
4423
|
hasSellableChoice,
|
|
4799
4424
|
holdExpiresAt,
|
|
4800
4425
|
inferStatesFromLegacyStatus,
|
|
4426
|
+
innerCompositeOption,
|
|
4801
4427
|
isAdyenRolloutCountry,
|
|
4802
4428
|
isAffirmCountry,
|
|
4803
4429
|
isAffirmPricePlan,
|
|
@@ -4805,17 +4431,19 @@ export {
|
|
|
4805
4431
|
isConditionOperator,
|
|
4806
4432
|
isFulfillmentState,
|
|
4807
4433
|
isInCart,
|
|
4434
|
+
isInnerComposite,
|
|
4808
4435
|
isPaymentState,
|
|
4809
|
-
isShellTipPercent,
|
|
4810
4436
|
isSupportedCurrency,
|
|
4811
4437
|
isSystemFamilyCode,
|
|
4812
4438
|
isValidQuantity,
|
|
4813
4439
|
isWhole,
|
|
4440
|
+
landedCostPerUnit,
|
|
4814
4441
|
lineStockMoves,
|
|
4815
4442
|
listCountries,
|
|
4816
4443
|
listProvinces,
|
|
4817
4444
|
listShippingCountries,
|
|
4818
4445
|
mapToLegacyStatus,
|
|
4446
|
+
marginPercentOf,
|
|
4819
4447
|
maxPrecisionFor,
|
|
4820
4448
|
mergeFragment,
|
|
4821
4449
|
modifiersSellable,
|
|
@@ -4826,13 +4454,11 @@ export {
|
|
|
4826
4454
|
normalizeMongoIdString,
|
|
4827
4455
|
normalizePostCode,
|
|
4828
4456
|
normalizeProvince,
|
|
4829
|
-
normalizeShopperEmail,
|
|
4830
4457
|
occupancyIn,
|
|
4831
4458
|
orderAssignments,
|
|
4832
4459
|
parseAmountToMinorUnits,
|
|
4833
4460
|
parseCurrencyCode,
|
|
4834
4461
|
parseStripeCurrencyCode,
|
|
4835
|
-
phoneKey,
|
|
4836
4462
|
placeKey,
|
|
4837
4463
|
planWindow,
|
|
4838
4464
|
poolDemand,
|
|
@@ -4843,29 +4469,19 @@ export {
|
|
|
4843
4469
|
presentAt,
|
|
4844
4470
|
priceForTotal,
|
|
4845
4471
|
provincesForPostCode,
|
|
4846
|
-
readShellTipSettings,
|
|
4847
|
-
registrationPlacesByKind,
|
|
4848
4472
|
removeFragment,
|
|
4849
4473
|
resolveFamily,
|
|
4850
4474
|
resolveModifiersForProduct,
|
|
4851
|
-
resolveShellSettings,
|
|
4852
|
-
resolveShellSettingsWithSources,
|
|
4853
4475
|
resolveShipping,
|
|
4854
4476
|
resolveTemplate,
|
|
4855
4477
|
resolveUnit,
|
|
4856
4478
|
roundToPrecision,
|
|
4857
4479
|
sameFamily,
|
|
4858
4480
|
setOrderState,
|
|
4859
|
-
|
|
4860
|
-
shellSettingsFromCompanyTips,
|
|
4861
|
-
shellSettingsFromFlowSettings,
|
|
4862
|
-
shellSettingsProblems,
|
|
4863
|
-
shellTipSettingsProblems,
|
|
4864
|
-
shippingDuration,
|
|
4481
|
+
shelfComponents,
|
|
4865
4482
|
shipsToCountry,
|
|
4866
4483
|
shopDayKey,
|
|
4867
4484
|
shopDayRange,
|
|
4868
|
-
shopperPaymentsOf,
|
|
4869
4485
|
signReportForDisplay,
|
|
4870
4486
|
slotsForWindow,
|
|
4871
4487
|
stringifyMinorUnits,
|
|
@@ -4876,7 +4492,9 @@ export {
|
|
|
4876
4492
|
validateFragmentCompatibility,
|
|
4877
4493
|
validateOrderStatuses,
|
|
4878
4494
|
validateShippingZone,
|
|
4879
|
-
|
|
4495
|
+
variantCostAtSale,
|
|
4496
|
+
variantDisplayName,
|
|
4497
|
+
variantLabel,
|
|
4880
4498
|
violatesFinancialInvariant,
|
|
4881
4499
|
windowEndsAt,
|
|
4882
4500
|
withinPresence
|