@final-commerce/common 2.11.1-online.1 → 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 +69 -34
- package/bin/lib/budget.mjs +71 -0
- package/dist/index.d.mts +212 -2
- package/dist/index.d.ts +212 -2
- package/dist/index.js +184 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +167 -9
- package/dist/index.mjs.map +1 -1
- package/dist/pos-types/index.d.mts +36 -1
- package/dist/pos-types/index.d.ts +36 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40,6 +40,8 @@ __export(index_exports, {
|
|
|
40
40
|
CONDITION_OPERATORS: () => CONDITION_OPERATORS,
|
|
41
41
|
COUNTRY_CURRENCIES: () => COUNTRY_CURRENCIES,
|
|
42
42
|
CURRENCY_CONFIG: () => CURRENCY_CONFIG,
|
|
43
|
+
CUSTOMER_CONTACT_VERIFIED: () => CUSTOMER_CONTACT_VERIFIED,
|
|
44
|
+
CUSTOMER_EMAIL_TAKEN: () => CUSTOMER_EMAIL_TAKEN,
|
|
43
45
|
CompanyType: () => CompanyType,
|
|
44
46
|
CurrencyCode: () => CurrencyCode,
|
|
45
47
|
CustomTableAvailability: () => CustomTableAvailability,
|
|
@@ -106,6 +108,11 @@ __export(index_exports, {
|
|
|
106
108
|
ResidualStatus: () => ResidualStatus,
|
|
107
109
|
ResourceAvailabilityState: () => ResourceAvailabilityState,
|
|
108
110
|
SHIPPING_COUNTRIES: () => SHIPPING_COUNTRIES,
|
|
111
|
+
SHOPPER_CONSENT_SOURCES: () => SHOPPER_CONSENT_SOURCES,
|
|
112
|
+
SHOPPER_ERROR_CODES: () => SHOPPER_ERROR_CODES,
|
|
113
|
+
SHOPPER_RETURN_DECLINE_REASON_MAX: () => SHOPPER_RETURN_DECLINE_REASON_MAX,
|
|
114
|
+
SHOPPER_RETURN_METHODS: () => SHOPPER_RETURN_METHODS,
|
|
115
|
+
SHOPPER_RETURN_STATUSES: () => SHOPPER_RETURN_STATUSES,
|
|
109
116
|
STANDARD_TAX_TYPE: () => STANDARD_TAX_TYPE,
|
|
110
117
|
STATE_SCHEMA: () => STATE_SCHEMA,
|
|
111
118
|
STRIPE_SUPPORTED_COUNTRIES: () => STRIPE_SUPPORTED_COUNTRIES,
|
|
@@ -124,6 +131,8 @@ __export(index_exports, {
|
|
|
124
131
|
StationStatus: () => StationStatus,
|
|
125
132
|
StripeCurrencyCode: () => StripeCurrencyCode,
|
|
126
133
|
StripeStatus: () => StripeStatus,
|
|
134
|
+
TAX_EXCEPTION_REASON_MAX: () => TAX_EXCEPTION_REASON_MAX,
|
|
135
|
+
TaxExceptionSource: () => TaxExceptionSource,
|
|
127
136
|
TaxRegistrationKind: () => TaxRegistrationKind,
|
|
128
137
|
TaxSource: () => TaxSource,
|
|
129
138
|
TaxWarningCode: () => TaxWarningCode,
|
|
@@ -155,6 +164,7 @@ __export(index_exports, {
|
|
|
155
164
|
buildResolvedConfig: () => buildResolvedConfig,
|
|
156
165
|
calculatePercentage: () => calculatePercentage,
|
|
157
166
|
canTransition: () => canTransition,
|
|
167
|
+
cardFromProcessorData: () => cardFromProcessorData,
|
|
158
168
|
cheapestCompositeItem: () => cheapestCompositeItem,
|
|
159
169
|
cheapestCompositePrice: () => cheapestCompositePrice,
|
|
160
170
|
compositeItemCost: () => compositeItemCost,
|
|
@@ -173,6 +183,7 @@ __export(index_exports, {
|
|
|
173
183
|
deriveUnitId: () => deriveUnitId,
|
|
174
184
|
displayRuleMatchesPair: () => displayRuleMatchesPair,
|
|
175
185
|
divideAmount: () => divideAmount,
|
|
186
|
+
emailKey: () => emailKey,
|
|
176
187
|
evaluateCondition: () => evaluateCondition,
|
|
177
188
|
evaluateConditionSet: () => evaluateConditionSet,
|
|
178
189
|
extendPrice: () => extendPrice,
|
|
@@ -181,6 +192,7 @@ __export(index_exports, {
|
|
|
181
192
|
formatInUnit: () => formatInUnit,
|
|
182
193
|
formatMinorUnitsToString: () => formatMinorUnitsToString,
|
|
183
194
|
formatQuantity: () => formatQuantity,
|
|
195
|
+
formatShippingDuration: () => formatShippingDuration,
|
|
184
196
|
fromBase: () => fromBase,
|
|
185
197
|
fromMinorUnits: () => fromMinorUnits,
|
|
186
198
|
generateMongoID: () => generateMongoID,
|
|
@@ -229,11 +241,13 @@ __export(index_exports, {
|
|
|
229
241
|
normalizeMongoIdString: () => normalizeMongoIdString,
|
|
230
242
|
normalizePostCode: () => normalizePostCode,
|
|
231
243
|
normalizeProvince: () => normalizeProvince,
|
|
244
|
+
normalizeShopperEmail: () => normalizeShopperEmail,
|
|
232
245
|
occupancyIn: () => occupancyIn,
|
|
233
246
|
orderAssignments: () => orderAssignments,
|
|
234
247
|
parseAmountToMinorUnits: () => parseAmountToMinorUnits,
|
|
235
248
|
parseCurrencyCode: () => parseCurrencyCode,
|
|
236
249
|
parseStripeCurrencyCode: () => parseStripeCurrencyCode,
|
|
250
|
+
phoneKey: () => phoneKey,
|
|
237
251
|
placeKey: () => placeKey,
|
|
238
252
|
planWindow: () => planWindow,
|
|
239
253
|
poolDemand: () => poolDemand,
|
|
@@ -255,9 +269,11 @@ __export(index_exports, {
|
|
|
255
269
|
sameFamily: () => sameFamily,
|
|
256
270
|
setOrderState: () => setOrderState,
|
|
257
271
|
sha1Hex: () => sha1Hex,
|
|
272
|
+
shippingDuration: () => shippingDuration,
|
|
258
273
|
shipsToCountry: () => shipsToCountry,
|
|
259
274
|
shopDayKey: () => shopDayKey,
|
|
260
275
|
shopDayRange: () => shopDayRange,
|
|
276
|
+
shopperPaymentsOf: () => shopperPaymentsOf,
|
|
261
277
|
signReportForDisplay: () => signReportForDisplay,
|
|
262
278
|
slotsForWindow: () => slotsForWindow,
|
|
263
279
|
stringifyMinorUnits: () => stringifyMinorUnits,
|
|
@@ -268,6 +284,7 @@ __export(index_exports, {
|
|
|
268
284
|
validateFragmentCompatibility: () => validateFragmentCompatibility,
|
|
269
285
|
validateOrderStatuses: () => validateOrderStatuses,
|
|
270
286
|
validateShippingZone: () => validateShippingZone,
|
|
287
|
+
verifiedContactChange: () => verifiedContactChange,
|
|
271
288
|
violatesFinancialInvariant: () => violatesFinancialInvariant,
|
|
272
289
|
windowEndsAt: () => windowEndsAt,
|
|
273
290
|
withinPresence: () => withinPresence
|
|
@@ -2081,6 +2098,32 @@ function lineStockMoves(item, quantity, reservations = []) {
|
|
|
2081
2098
|
});
|
|
2082
2099
|
}
|
|
2083
2100
|
|
|
2101
|
+
// utils/contact-keys.util.ts
|
|
2102
|
+
function emailKey(email) {
|
|
2103
|
+
const key = email?.trim().toLowerCase();
|
|
2104
|
+
return key && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(key) ? key : null;
|
|
2105
|
+
}
|
|
2106
|
+
function phoneKey(phone) {
|
|
2107
|
+
const raw = phone?.trim();
|
|
2108
|
+
if (!raw) return null;
|
|
2109
|
+
const digits = raw.replace(/\D/g, "");
|
|
2110
|
+
if (raw.startsWith("+")) return digits.length >= 8 && digits.length <= 15 ? `+${digits}` : null;
|
|
2111
|
+
if (digits.length === 10) return `+1${digits}`;
|
|
2112
|
+
if (digits.length === 11 && digits.startsWith("1")) return `+${digits}`;
|
|
2113
|
+
return null;
|
|
2114
|
+
}
|
|
2115
|
+
var CUSTOMER_CONTACT_VERIFIED = "CUSTOMER_CONTACT_VERIFIED";
|
|
2116
|
+
var CUSTOMER_EMAIL_TAKEN = "CUSTOMER_EMAIL_TAKEN";
|
|
2117
|
+
function sameContact(a, b, key) {
|
|
2118
|
+
return (key(a) ?? a?.trim().toLowerCase() ?? "") === (key(b) ?? b?.trim().toLowerCase() ?? "");
|
|
2119
|
+
}
|
|
2120
|
+
function verifiedContactChange(existing, change) {
|
|
2121
|
+
if (!existing.verifiedShopperAt) return null;
|
|
2122
|
+
if (change.email !== void 0 && !sameContact(existing.email, change.email, emailKey)) return "email";
|
|
2123
|
+
if (change.phone !== void 0 && !sameContact(existing.phone, change.phone, phoneKey)) return "phone";
|
|
2124
|
+
return null;
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2084
2127
|
// units/family-code.ts
|
|
2085
2128
|
var MAX_SLUG_LENGTH = 32;
|
|
2086
2129
|
var FALLBACK_SLUG = "family";
|
|
@@ -2123,6 +2166,7 @@ var FULFILLMENT_STATES = [
|
|
|
2123
2166
|
"in_progress",
|
|
2124
2167
|
"fulfilled",
|
|
2125
2168
|
"partially_fulfilled",
|
|
2169
|
+
"return_pending",
|
|
2126
2170
|
"returned",
|
|
2127
2171
|
"partially_returned",
|
|
2128
2172
|
"cancelled"
|
|
@@ -2148,10 +2192,7 @@ var CONDITION_OPERATORS = [
|
|
|
2148
2192
|
function isConditionOperator(value) {
|
|
2149
2193
|
return CONDITION_OPERATORS.includes(value);
|
|
2150
2194
|
}
|
|
2151
|
-
var PATH_MODES = [
|
|
2152
|
-
"strict",
|
|
2153
|
-
"permissive"
|
|
2154
|
-
];
|
|
2195
|
+
var PATH_MODES = ["strict", "permissive"];
|
|
2155
2196
|
|
|
2156
2197
|
// order-state-machine/state-schema.ts
|
|
2157
2198
|
var PAYMENT_DEFS = [
|
|
@@ -2172,6 +2213,9 @@ var FULFILLMENT_DEFS = [
|
|
|
2172
2213
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
2173
2214
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
2174
2215
|
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
2216
|
+
// The store accepted the shopper's return request: the goods are on their way back, no money has moved yet.
|
|
2217
|
+
// The refund lands `partially_returned` / `returned` as it does from `fulfilled`.
|
|
2218
|
+
{ id: "return_pending", label: "Return Accepted", terminal: false },
|
|
2175
2219
|
{ id: "returned", label: "Returned", terminal: true },
|
|
2176
2220
|
{ id: "partially_returned", label: "Partially Returned", terminal: false },
|
|
2177
2221
|
{ id: "cancelled", label: "Cancelled", terminal: true }
|
|
@@ -2201,6 +2245,8 @@ var STATE_SCHEMA = Object.freeze({
|
|
|
2201
2245
|
var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
|
|
2202
2246
|
var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
|
|
2203
2247
|
var UNRETURNED_MONEY_STATES = /* @__PURE__ */ new Set(["partially_paid", "paid", "partially_refunded"]);
|
|
2248
|
+
var RETURN_FROM_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "partially_returned"]);
|
|
2249
|
+
var RETURN_PENDING_PAYMENTS = /* @__PURE__ */ new Set(["paid", "partially_refunded"]);
|
|
2204
2250
|
var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
|
|
2205
2251
|
var FINANCIAL_INVARIANTS = [
|
|
2206
2252
|
{
|
|
@@ -2248,6 +2294,11 @@ var FINANCIAL_INVARIANTS = [
|
|
|
2248
2294
|
description: "A voided order exists only at cancelled fulfillment: a voided order cannot re-enter fulfillment, and a voided \xD7 non-cancelled pair cannot be materialized from nothing (complements no-leave-voided, which only freezes the payment axis). Moves INTO voided from a live payment state are the void flow\u2019s concern, not this rule\u2019s",
|
|
2249
2295
|
check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
|
|
2250
2296
|
},
|
|
2297
|
+
{
|
|
2298
|
+
id: "return-pending-needs-goods-out",
|
|
2299
|
+
description: "Fulfillment enters return_pending (return accepted) only from fulfilled, partially_fulfilled or partially_returned, and holds it only while payment is paid or partially_refunded \u2014 goods must have gone out and money must still be held",
|
|
2300
|
+
check: (from, to) => to.fulfillment === "return_pending" && (!RETURN_PENDING_PAYMENTS.has(to.payment) || from?.fulfillment !== "return_pending" && !(from && RETURN_FROM_FULFILLMENT.has(from.fulfillment)))
|
|
2301
|
+
},
|
|
2251
2302
|
{
|
|
2252
2303
|
id: "no-reopen-refunded-fulfillment",
|
|
2253
2304
|
description: "A fully refunded order cannot re-enter fulfillment \u2014 it may only relabel between its canonical landings, returned and cancelled (complements no-leave-refunded, which only freezes the payment axis)",
|
|
@@ -2339,7 +2390,9 @@ var DISPLAY_LABEL_OVERRIDES = {
|
|
|
2339
2390
|
"paid|on_hold": "Parked - Paid",
|
|
2340
2391
|
"paid|fulfilled": "Completed",
|
|
2341
2392
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
2342
|
-
"partially_refunded|partially_returned": "Partially Refunded"
|
|
2393
|
+
"partially_refunded|partially_returned": "Partially Refunded",
|
|
2394
|
+
"paid|return_pending": "Return Accepted",
|
|
2395
|
+
"partially_refunded|return_pending": "Return Accepted"
|
|
2343
2396
|
};
|
|
2344
2397
|
var TERMINAL_LABEL_OVERRIDES = {
|
|
2345
2398
|
voided: "Cancelled"
|
|
@@ -2481,6 +2534,7 @@ function buildOrderContext(order, extras) {
|
|
|
2481
2534
|
}
|
|
2482
2535
|
|
|
2483
2536
|
// order-state-machine/display-state.ts
|
|
2537
|
+
var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
|
|
2484
2538
|
function atomLabel(atom, defs) {
|
|
2485
2539
|
return defs.find((d) => d.id === atom)?.label ?? atom;
|
|
2486
2540
|
}
|
|
@@ -2494,6 +2548,10 @@ function deriveDisplayState(payment, fulfillment, config) {
|
|
|
2494
2548
|
return { label: rule.label, color: rule.color, icon: rule.icon };
|
|
2495
2549
|
}
|
|
2496
2550
|
}
|
|
2551
|
+
if (ATOMS_ADDED_AFTER_SNAPSHOT.has(fulfillment)) {
|
|
2552
|
+
const fallback = DEFAULT_DISPLAY_STATE_MAP.find((rule) => displayRuleMatchesPair(rule, payment, fulfillment));
|
|
2553
|
+
if (fallback) return { label: fallback.label, color: fallback.color, icon: fallback.icon };
|
|
2554
|
+
}
|
|
2497
2555
|
return {
|
|
2498
2556
|
label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
|
|
2499
2557
|
};
|
|
@@ -4281,6 +4339,8 @@ function quote(option, zoneId, itemsTotal) {
|
|
|
4281
4339
|
amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
|
|
4282
4340
|
minDays: option.minDays ?? null,
|
|
4283
4341
|
maxDays: option.maxDays ?? null,
|
|
4342
|
+
minMinutes: option.minMinutes ?? null,
|
|
4343
|
+
maxMinutes: option.maxMinutes ?? null,
|
|
4284
4344
|
outletId: option.outletId ?? null
|
|
4285
4345
|
};
|
|
4286
4346
|
}
|
|
@@ -4295,6 +4355,21 @@ function countriesShippedTo(zones) {
|
|
|
4295
4355
|
return [...countries].sort();
|
|
4296
4356
|
}
|
|
4297
4357
|
|
|
4358
|
+
// shipping/time.ts
|
|
4359
|
+
function shippingDuration(minMinutes, maxMinutes) {
|
|
4360
|
+
const min = minMinutes ?? maxMinutes;
|
|
4361
|
+
const max = maxMinutes ?? minMinutes;
|
|
4362
|
+
if (min == null || max == null) return null;
|
|
4363
|
+
const wholeHours = max > 0 && min % 60 === 0 && max % 60 === 0;
|
|
4364
|
+
return wholeHours ? { unit: "hour", min: min / 60, max: max / 60 } : { unit: "minute", min, max };
|
|
4365
|
+
}
|
|
4366
|
+
function formatShippingDuration(minMinutes, maxMinutes, locale, display = "long") {
|
|
4367
|
+
const duration = shippingDuration(minMinutes, maxMinutes);
|
|
4368
|
+
if (!duration) return null;
|
|
4369
|
+
const unit2 = new Intl.NumberFormat(locale ?? "en", { style: "unit", unit: duration.unit, unitDisplay: display });
|
|
4370
|
+
return duration.min === duration.max ? unit2.format(duration.max) : `${duration.min}\u2013${unit2.format(duration.max)}`;
|
|
4371
|
+
}
|
|
4372
|
+
|
|
4298
4373
|
// shipping/validate.ts
|
|
4299
4374
|
function validateShippingZone(zone) {
|
|
4300
4375
|
const problems = [...placeProblems(zone)];
|
|
@@ -4323,7 +4398,15 @@ function fitsKind(place, kind) {
|
|
|
4323
4398
|
return false;
|
|
4324
4399
|
}
|
|
4325
4400
|
var isAmount = (value) => Number.isInteger(value) && value >= 0;
|
|
4326
|
-
var
|
|
4401
|
+
var isTime = (value) => value == null || isAmount(value);
|
|
4402
|
+
var inOrder = (min, max) => (min ?? 0) <= (max ?? Infinity);
|
|
4403
|
+
function timeIsValid(option) {
|
|
4404
|
+
const { minDays, maxDays, minMinutes, maxMinutes } = option;
|
|
4405
|
+
if (![minDays, maxDays, minMinutes, maxMinutes].every(isTime)) return false;
|
|
4406
|
+
const hasDays = minDays != null || maxDays != null;
|
|
4407
|
+
const hasMinutes = minMinutes != null || maxMinutes != null;
|
|
4408
|
+
return !(hasDays && hasMinutes) && inOrder(minDays, maxDays) && inOrder(minMinutes, maxMinutes);
|
|
4409
|
+
}
|
|
4327
4410
|
function optionProblems(option) {
|
|
4328
4411
|
const problems = [];
|
|
4329
4412
|
const isPickup = option.type === "pickup" /* PICKUP */;
|
|
@@ -4331,9 +4414,7 @@ function optionProblems(option) {
|
|
|
4331
4414
|
problems.push("INVALID_PRICE" /* INVALID_PRICE */);
|
|
4332
4415
|
}
|
|
4333
4416
|
if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
|
|
4334
|
-
if (!
|
|
4335
|
-
problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4336
|
-
}
|
|
4417
|
+
if (!timeIsValid(option)) problems.push("INVALID_DAYS" /* INVALID_DAYS */);
|
|
4337
4418
|
if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
|
|
4338
4419
|
if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
|
|
4339
4420
|
if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
|
|
@@ -4486,6 +4567,83 @@ function registrationPlacesByKind(rates) {
|
|
|
4486
4567
|
return places;
|
|
4487
4568
|
}
|
|
4488
4569
|
|
|
4570
|
+
// tax/exceptions.ts
|
|
4571
|
+
var TaxExceptionSource = /* @__PURE__ */ ((TaxExceptionSource2) => {
|
|
4572
|
+
TaxExceptionSource2["PRODUCT"] = "product";
|
|
4573
|
+
TaxExceptionSource2["CATEGORY"] = "category";
|
|
4574
|
+
return TaxExceptionSource2;
|
|
4575
|
+
})(TaxExceptionSource || {});
|
|
4576
|
+
var TAX_EXCEPTION_REASON_MAX = 200;
|
|
4577
|
+
|
|
4578
|
+
// shopper/types.ts
|
|
4579
|
+
var SHOPPER_CONSENT_SOURCES = ["checkout", "my-account", "store-account"];
|
|
4580
|
+
var SHOPPER_RETURN_METHODS = ["mail", "in-store"];
|
|
4581
|
+
var SHOPPER_RETURN_STATUSES = ["requested", "accepted", "declined"];
|
|
4582
|
+
var SHOPPER_RETURN_DECLINE_REASON_MAX = 500;
|
|
4583
|
+
var SHOPPER_ERROR_CODES = {
|
|
4584
|
+
ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
|
|
4585
|
+
RETURN_ALREADY_REQUESTED: "RETURN_ALREADY_REQUESTED",
|
|
4586
|
+
RETURN_NOT_ALLOWED: "RETURN_NOT_ALLOWED",
|
|
4587
|
+
RETURN_ALREADY_DECIDED: "RETURN_ALREADY_DECIDED",
|
|
4588
|
+
STORE_HAS_NO_SUPPORT_EMAIL: "STORE_HAS_NO_SUPPORT_EMAIL",
|
|
4589
|
+
TOO_MANY_ADDRESSES: "TOO_MANY_ADDRESSES",
|
|
4590
|
+
STORE_NOT_LINKED: "STORE_NOT_LINKED",
|
|
4591
|
+
STORED_METHOD_NOT_FOUND: "STORED_METHOD_NOT_FOUND"
|
|
4592
|
+
};
|
|
4593
|
+
|
|
4594
|
+
// shopper/email.ts
|
|
4595
|
+
function normalizeShopperEmail(email) {
|
|
4596
|
+
if (typeof email !== "string") return null;
|
|
4597
|
+
const value = email.trim().toLowerCase();
|
|
4598
|
+
return /^[^\s@]+@[^\s@]+$/.test(value) ? value : null;
|
|
4599
|
+
}
|
|
4600
|
+
|
|
4601
|
+
// shopper/card.ts
|
|
4602
|
+
function cardFromProcessorData(processorData) {
|
|
4603
|
+
if (typeof processorData !== "string" || !processorData) return {};
|
|
4604
|
+
let data;
|
|
4605
|
+
try {
|
|
4606
|
+
data = JSON.parse(processorData);
|
|
4607
|
+
} catch {
|
|
4608
|
+
return {};
|
|
4609
|
+
}
|
|
4610
|
+
if (!data || typeof data !== "object") return {};
|
|
4611
|
+
const fields = new Map(Object.entries(data));
|
|
4612
|
+
const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
|
|
4613
|
+
const brand = text("Brand", "brand")?.trim();
|
|
4614
|
+
const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
|
|
4615
|
+
const issuer = text("Issuer", "issuer")?.trim();
|
|
4616
|
+
return {
|
|
4617
|
+
...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
|
|
4618
|
+
...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {},
|
|
4619
|
+
...issuer ? { cardIssuer: issuer } : {}
|
|
4620
|
+
};
|
|
4621
|
+
}
|
|
4622
|
+
|
|
4623
|
+
// shopper/payments.ts
|
|
4624
|
+
var CARD_TYPES = /* @__PURE__ */ new Set(["card", "terminal", "taptopay", "moto", "cloud", "bluetooth"]);
|
|
4625
|
+
function kindOf(paymentType) {
|
|
4626
|
+
if (paymentType === "cash") return "cash";
|
|
4627
|
+
if (paymentType === "redeem") return "gift_card";
|
|
4628
|
+
if (paymentType === "pay_later") return "pay_later";
|
|
4629
|
+
if (CARD_TYPES.has(paymentType)) return "card";
|
|
4630
|
+
return "other";
|
|
4631
|
+
}
|
|
4632
|
+
function shopperPaymentsOf(legs) {
|
|
4633
|
+
return (legs ?? []).map((leg) => {
|
|
4634
|
+
const type = (leg.paymentType ?? "").trim();
|
|
4635
|
+
const kind = kindOf(type.toLowerCase());
|
|
4636
|
+
const card = kind === "card" ? cardFromProcessorData(leg.emv) : {};
|
|
4637
|
+
return {
|
|
4638
|
+
kind,
|
|
4639
|
+
// Cards: the issuer's name, else the brand. Other tenders the store named itself keep that name.
|
|
4640
|
+
name: kind === "card" ? card.cardIssuer ?? card.cardBrand ?? null : kind === "other" ? type || null : null,
|
|
4641
|
+
lastFour: card.cardLastFour ?? null,
|
|
4642
|
+
amount: (leg.amount ?? 0) + (leg.tip?.amount ?? 0)
|
|
4643
|
+
};
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4646
|
+
|
|
4489
4647
|
// constants/adyen.constants.ts
|
|
4490
4648
|
var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
|
|
4491
4649
|
function isAdyenRolloutCountry(alpha2) {
|
|
@@ -4602,6 +4760,8 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4602
4760
|
CONDITION_OPERATORS,
|
|
4603
4761
|
COUNTRY_CURRENCIES,
|
|
4604
4762
|
CURRENCY_CONFIG,
|
|
4763
|
+
CUSTOMER_CONTACT_VERIFIED,
|
|
4764
|
+
CUSTOMER_EMAIL_TAKEN,
|
|
4605
4765
|
CompanyType,
|
|
4606
4766
|
CurrencyCode,
|
|
4607
4767
|
CustomTableAvailability,
|
|
@@ -4668,6 +4828,11 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4668
4828
|
ResidualStatus,
|
|
4669
4829
|
ResourceAvailabilityState,
|
|
4670
4830
|
SHIPPING_COUNTRIES,
|
|
4831
|
+
SHOPPER_CONSENT_SOURCES,
|
|
4832
|
+
SHOPPER_ERROR_CODES,
|
|
4833
|
+
SHOPPER_RETURN_DECLINE_REASON_MAX,
|
|
4834
|
+
SHOPPER_RETURN_METHODS,
|
|
4835
|
+
SHOPPER_RETURN_STATUSES,
|
|
4671
4836
|
STANDARD_TAX_TYPE,
|
|
4672
4837
|
STATE_SCHEMA,
|
|
4673
4838
|
STRIPE_SUPPORTED_COUNTRIES,
|
|
@@ -4686,6 +4851,8 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4686
4851
|
StationStatus,
|
|
4687
4852
|
StripeCurrencyCode,
|
|
4688
4853
|
StripeStatus,
|
|
4854
|
+
TAX_EXCEPTION_REASON_MAX,
|
|
4855
|
+
TaxExceptionSource,
|
|
4689
4856
|
TaxRegistrationKind,
|
|
4690
4857
|
TaxSource,
|
|
4691
4858
|
TaxWarningCode,
|
|
@@ -4717,6 +4884,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4717
4884
|
buildResolvedConfig,
|
|
4718
4885
|
calculatePercentage,
|
|
4719
4886
|
canTransition,
|
|
4887
|
+
cardFromProcessorData,
|
|
4720
4888
|
cheapestCompositeItem,
|
|
4721
4889
|
cheapestCompositePrice,
|
|
4722
4890
|
compositeItemCost,
|
|
@@ -4735,6 +4903,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4735
4903
|
deriveUnitId,
|
|
4736
4904
|
displayRuleMatchesPair,
|
|
4737
4905
|
divideAmount,
|
|
4906
|
+
emailKey,
|
|
4738
4907
|
evaluateCondition,
|
|
4739
4908
|
evaluateConditionSet,
|
|
4740
4909
|
extendPrice,
|
|
@@ -4743,6 +4912,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4743
4912
|
formatInUnit,
|
|
4744
4913
|
formatMinorUnitsToString,
|
|
4745
4914
|
formatQuantity,
|
|
4915
|
+
formatShippingDuration,
|
|
4746
4916
|
fromBase,
|
|
4747
4917
|
fromMinorUnits,
|
|
4748
4918
|
generateMongoID,
|
|
@@ -4791,11 +4961,13 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4791
4961
|
normalizeMongoIdString,
|
|
4792
4962
|
normalizePostCode,
|
|
4793
4963
|
normalizeProvince,
|
|
4964
|
+
normalizeShopperEmail,
|
|
4794
4965
|
occupancyIn,
|
|
4795
4966
|
orderAssignments,
|
|
4796
4967
|
parseAmountToMinorUnits,
|
|
4797
4968
|
parseCurrencyCode,
|
|
4798
4969
|
parseStripeCurrencyCode,
|
|
4970
|
+
phoneKey,
|
|
4799
4971
|
placeKey,
|
|
4800
4972
|
planWindow,
|
|
4801
4973
|
poolDemand,
|
|
@@ -4817,9 +4989,11 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4817
4989
|
sameFamily,
|
|
4818
4990
|
setOrderState,
|
|
4819
4991
|
sha1Hex,
|
|
4992
|
+
shippingDuration,
|
|
4820
4993
|
shipsToCountry,
|
|
4821
4994
|
shopDayKey,
|
|
4822
4995
|
shopDayRange,
|
|
4996
|
+
shopperPaymentsOf,
|
|
4823
4997
|
signReportForDisplay,
|
|
4824
4998
|
slotsForWindow,
|
|
4825
4999
|
stringifyMinorUnits,
|
|
@@ -4830,6 +5004,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
|
|
|
4830
5004
|
validateFragmentCompatibility,
|
|
4831
5005
|
validateOrderStatuses,
|
|
4832
5006
|
validateShippingZone,
|
|
5007
|
+
verifiedContactChange,
|
|
4833
5008
|
violatesFinancialInvariant,
|
|
4834
5009
|
windowEndsAt,
|
|
4835
5010
|
withinPresence
|