@final-commerce/common 2.11.1-online.7 → 2.11.1-online.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +82 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -6
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +2 -1
- package/dist/pos-types/index.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1805,6 +1805,31 @@ function lineStockMoves(item, quantity, reservations = []) {
|
|
|
1805
1805
|
});
|
|
1806
1806
|
}
|
|
1807
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
|
+
function sameContact(a, b, key) {
|
|
1824
|
+
return (key(a) ?? a?.trim().toLowerCase() ?? "") === (key(b) ?? b?.trim().toLowerCase() ?? "");
|
|
1825
|
+
}
|
|
1826
|
+
function verifiedContactChange(existing, change) {
|
|
1827
|
+
if (!existing.verifiedShopperAt) return null;
|
|
1828
|
+
if (change.email !== void 0 && !sameContact(existing.email, change.email, emailKey)) return "email";
|
|
1829
|
+
if (change.phone !== void 0 && !sameContact(existing.phone, change.phone, phoneKey)) return "phone";
|
|
1830
|
+
return null;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1808
1833
|
// units/family-code.ts
|
|
1809
1834
|
var MAX_SLUG_LENGTH = 32;
|
|
1810
1835
|
var FALLBACK_SLUG = "family";
|
|
@@ -1847,6 +1872,7 @@ var FULFILLMENT_STATES = [
|
|
|
1847
1872
|
"in_progress",
|
|
1848
1873
|
"fulfilled",
|
|
1849
1874
|
"partially_fulfilled",
|
|
1875
|
+
"return_pending",
|
|
1850
1876
|
"returned",
|
|
1851
1877
|
"partially_returned",
|
|
1852
1878
|
"cancelled"
|
|
@@ -1872,10 +1898,7 @@ var CONDITION_OPERATORS = [
|
|
|
1872
1898
|
function isConditionOperator(value) {
|
|
1873
1899
|
return CONDITION_OPERATORS.includes(value);
|
|
1874
1900
|
}
|
|
1875
|
-
var PATH_MODES = [
|
|
1876
|
-
"strict",
|
|
1877
|
-
"permissive"
|
|
1878
|
-
];
|
|
1901
|
+
var PATH_MODES = ["strict", "permissive"];
|
|
1879
1902
|
|
|
1880
1903
|
// order-state-machine/state-schema.ts
|
|
1881
1904
|
var PAYMENT_DEFS = [
|
|
@@ -1896,6 +1919,9 @@ var FULFILLMENT_DEFS = [
|
|
|
1896
1919
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
1897
1920
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
1898
1921
|
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
1922
|
+
// The store accepted the shopper's return request: the goods are on their way back, no money has moved yet.
|
|
1923
|
+
// The refund lands `partially_returned` / `returned` as it does from `fulfilled`.
|
|
1924
|
+
{ id: "return_pending", label: "Return Accepted", terminal: false },
|
|
1899
1925
|
{ id: "returned", label: "Returned", terminal: true },
|
|
1900
1926
|
{ id: "partially_returned", label: "Partially Returned", terminal: false },
|
|
1901
1927
|
{ id: "cancelled", label: "Cancelled", terminal: true }
|
|
@@ -1925,6 +1951,8 @@ var STATE_SCHEMA = Object.freeze({
|
|
|
1925
1951
|
var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
|
|
1926
1952
|
var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
|
|
1927
1953
|
var UNRETURNED_MONEY_STATES = /* @__PURE__ */ new Set(["partially_paid", "paid", "partially_refunded"]);
|
|
1954
|
+
var RETURN_FROM_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "partially_returned"]);
|
|
1955
|
+
var RETURN_PENDING_PAYMENTS = /* @__PURE__ */ new Set(["paid", "partially_refunded"]);
|
|
1928
1956
|
var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
|
|
1929
1957
|
var FINANCIAL_INVARIANTS = [
|
|
1930
1958
|
{
|
|
@@ -1972,6 +2000,11 @@ var FINANCIAL_INVARIANTS = [
|
|
|
1972
2000
|
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",
|
|
1973
2001
|
check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
|
|
1974
2002
|
},
|
|
2003
|
+
{
|
|
2004
|
+
id: "return-pending-needs-goods-out",
|
|
2005
|
+
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",
|
|
2006
|
+
check: (from, to) => to.fulfillment === "return_pending" && (!RETURN_PENDING_PAYMENTS.has(to.payment) || from?.fulfillment !== "return_pending" && !(from && RETURN_FROM_FULFILLMENT.has(from.fulfillment)))
|
|
2007
|
+
},
|
|
1975
2008
|
{
|
|
1976
2009
|
id: "no-reopen-refunded-fulfillment",
|
|
1977
2010
|
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)",
|
|
@@ -2063,7 +2096,9 @@ var DISPLAY_LABEL_OVERRIDES = {
|
|
|
2063
2096
|
"paid|on_hold": "Parked - Paid",
|
|
2064
2097
|
"paid|fulfilled": "Completed",
|
|
2065
2098
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
2066
|
-
"partially_refunded|partially_returned": "Partially Refunded"
|
|
2099
|
+
"partially_refunded|partially_returned": "Partially Refunded",
|
|
2100
|
+
"paid|return_pending": "Return Accepted",
|
|
2101
|
+
"partially_refunded|return_pending": "Return Accepted"
|
|
2067
2102
|
};
|
|
2068
2103
|
var TERMINAL_LABEL_OVERRIDES = {
|
|
2069
2104
|
voided: "Cancelled"
|
|
@@ -2205,6 +2240,7 @@ function buildOrderContext(order, extras) {
|
|
|
2205
2240
|
}
|
|
2206
2241
|
|
|
2207
2242
|
// order-state-machine/display-state.ts
|
|
2243
|
+
var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
|
|
2208
2244
|
function atomLabel(atom, defs) {
|
|
2209
2245
|
return defs.find((d) => d.id === atom)?.label ?? atom;
|
|
2210
2246
|
}
|
|
@@ -2218,6 +2254,10 @@ function deriveDisplayState(payment, fulfillment, config) {
|
|
|
2218
2254
|
return { label: rule.label, color: rule.color, icon: rule.icon };
|
|
2219
2255
|
}
|
|
2220
2256
|
}
|
|
2257
|
+
if (ATOMS_ADDED_AFTER_SNAPSHOT.has(fulfillment)) {
|
|
2258
|
+
const fallback = DEFAULT_DISPLAY_STATE_MAP.find((rule) => displayRuleMatchesPair(rule, payment, fulfillment));
|
|
2259
|
+
if (fallback) return { label: fallback.label, color: fallback.color, icon: fallback.icon };
|
|
2260
|
+
}
|
|
2221
2261
|
return {
|
|
2222
2262
|
label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
|
|
2223
2263
|
};
|
|
@@ -4278,12 +4318,38 @@ function cardFromProcessorData(processorData) {
|
|
|
4278
4318
|
const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
|
|
4279
4319
|
const brand = text("Brand", "brand")?.trim();
|
|
4280
4320
|
const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
|
|
4321
|
+
const issuer = text("Issuer", "issuer")?.trim();
|
|
4281
4322
|
return {
|
|
4282
4323
|
...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
|
|
4283
|
-
...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {}
|
|
4324
|
+
...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {},
|
|
4325
|
+
...issuer ? { cardIssuer: issuer } : {}
|
|
4284
4326
|
};
|
|
4285
4327
|
}
|
|
4286
4328
|
|
|
4329
|
+
// shopper/payments.ts
|
|
4330
|
+
var CARD_TYPES = /* @__PURE__ */ new Set(["card", "terminal", "taptopay", "moto", "cloud", "bluetooth"]);
|
|
4331
|
+
function kindOf(paymentType) {
|
|
4332
|
+
if (paymentType === "cash") return "cash";
|
|
4333
|
+
if (paymentType === "redeem") return "gift_card";
|
|
4334
|
+
if (paymentType === "pay_later") return "pay_later";
|
|
4335
|
+
if (CARD_TYPES.has(paymentType)) return "card";
|
|
4336
|
+
return "other";
|
|
4337
|
+
}
|
|
4338
|
+
function shopperPaymentsOf(legs) {
|
|
4339
|
+
return (legs ?? []).map((leg) => {
|
|
4340
|
+
const type = (leg.paymentType ?? "").trim();
|
|
4341
|
+
const kind = kindOf(type.toLowerCase());
|
|
4342
|
+
const card = kind === "card" ? cardFromProcessorData(leg.emv) : {};
|
|
4343
|
+
return {
|
|
4344
|
+
kind,
|
|
4345
|
+
// Cards: the issuer's name, else the brand. Other tenders the store named itself keep that name.
|
|
4346
|
+
name: kind === "card" ? card.cardIssuer ?? card.cardBrand ?? null : kind === "other" ? type || null : null,
|
|
4347
|
+
lastFour: card.cardLastFour ?? null,
|
|
4348
|
+
amount: (leg.amount ?? 0) + (leg.tip?.amount ?? 0)
|
|
4349
|
+
};
|
|
4350
|
+
});
|
|
4351
|
+
}
|
|
4352
|
+
|
|
4287
4353
|
// constants/adyen.constants.ts
|
|
4288
4354
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
4289
4355
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4399,6 +4465,7 @@ export {
|
|
|
4399
4465
|
CONDITION_OPERATORS,
|
|
4400
4466
|
COUNTRY_CURRENCIES,
|
|
4401
4467
|
CURRENCY_CONFIG,
|
|
4468
|
+
CUSTOMER_CONTACT_VERIFIED,
|
|
4402
4469
|
CompanyType,
|
|
4403
4470
|
CurrencyCode,
|
|
4404
4471
|
CustomTableAvailability,
|
|
@@ -4540,6 +4607,7 @@ export {
|
|
|
4540
4607
|
deriveUnitId,
|
|
4541
4608
|
displayRuleMatchesPair,
|
|
4542
4609
|
divideAmount,
|
|
4610
|
+
emailKey,
|
|
4543
4611
|
evaluateCondition,
|
|
4544
4612
|
evaluateConditionSet,
|
|
4545
4613
|
extendPrice,
|
|
@@ -4603,6 +4671,7 @@ export {
|
|
|
4603
4671
|
parseAmountToMinorUnits,
|
|
4604
4672
|
parseCurrencyCode,
|
|
4605
4673
|
parseStripeCurrencyCode,
|
|
4674
|
+
phoneKey,
|
|
4606
4675
|
placeKey,
|
|
4607
4676
|
planWindow,
|
|
4608
4677
|
poolDemand,
|
|
@@ -4628,6 +4697,7 @@ export {
|
|
|
4628
4697
|
shipsToCountry,
|
|
4629
4698
|
shopDayKey,
|
|
4630
4699
|
shopDayRange,
|
|
4700
|
+
shopperPaymentsOf,
|
|
4631
4701
|
signReportForDisplay,
|
|
4632
4702
|
slotsForWindow,
|
|
4633
4703
|
stringifyMinorUnits,
|
|
@@ -4638,6 +4708,7 @@ export {
|
|
|
4638
4708
|
validateFragmentCompatibility,
|
|
4639
4709
|
validateOrderStatuses,
|
|
4640
4710
|
validateShippingZone,
|
|
4711
|
+
verifiedContactChange,
|
|
4641
4712
|
violatesFinancialInvariant,
|
|
4642
4713
|
windowEndsAt,
|
|
4643
4714
|
withinPresence
|