@final-commerce/common 2.0.17 → 2.1.0
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 +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1118,7 +1118,9 @@ var PAYMENT_DEFS = [
|
|
|
1118
1118
|
var FULFILLMENT_DEFS = [
|
|
1119
1119
|
{ id: "draft", label: "Draft", terminal: false },
|
|
1120
1120
|
{ id: "pending", label: "Pending", terminal: false },
|
|
1121
|
-
|
|
1121
|
+
// 'Parked' is the product term for a held order (OS bug #30) — the atom id
|
|
1122
|
+
// stays `on_hold`; only the human label realigns.
|
|
1123
|
+
{ id: "on_hold", label: "Parked", terminal: false },
|
|
1122
1124
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
1123
1125
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
1124
1126
|
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
@@ -1250,29 +1252,31 @@ var DEFAULT_CROSS_AXIS_RULES = [
|
|
|
1250
1252
|
|
|
1251
1253
|
// order-state-machine/default-config.ts
|
|
1252
1254
|
var DEFAULT_EPOCH = /* @__PURE__ */ new Date(0);
|
|
1253
|
-
var PAYMENT_LABELS = new Map(
|
|
1254
|
-
|
|
1255
|
-
);
|
|
1256
|
-
var FULFILLMENT_LABELS = new Map(
|
|
1257
|
-
baseFulfillmentDefinitions().map((d) => [d.id, d.label])
|
|
1258
|
-
);
|
|
1255
|
+
var PAYMENT_LABELS = new Map(basePaymentDefinitions().map((d) => [d.id, d.label]));
|
|
1256
|
+
var FULFILLMENT_LABELS = new Map(baseFulfillmentDefinitions().map((d) => [d.id, d.label]));
|
|
1259
1257
|
var TERMINAL_PAYMENT_STATES = new Set(
|
|
1260
1258
|
basePaymentDefinitions().filter((d) => d.isTerminal).map((d) => d.id)
|
|
1261
1259
|
);
|
|
1262
1260
|
var DISPLAY_LABEL_OVERRIDES = {
|
|
1263
1261
|
"unpaid|draft": "In Cart",
|
|
1264
1262
|
"unpaid|pending": "Pending Payment",
|
|
1265
|
-
"unpaid|on_hold": "
|
|
1263
|
+
"unpaid|on_hold": "Parked",
|
|
1266
1264
|
"unpaid|cancelled": "Cancelled",
|
|
1267
1265
|
"partially_paid|pending": "Deposit Received",
|
|
1268
|
-
"partially_paid|on_hold": "
|
|
1266
|
+
"partially_paid|on_hold": "Parked - Deposit Received",
|
|
1267
|
+
"partially_paid|in_progress": "Partially Paid",
|
|
1269
1268
|
"paid|pending": "Paid - Awaiting Fulfillment",
|
|
1270
|
-
"paid|on_hold": "
|
|
1269
|
+
"paid|on_hold": "Parked - Paid",
|
|
1271
1270
|
"paid|fulfilled": "Completed",
|
|
1272
1271
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
1273
|
-
"partially_refunded|partially_returned": "Partially
|
|
1272
|
+
"partially_refunded|partially_returned": "Partially Refunded",
|
|
1274
1273
|
"refunded|fulfilled": "Refunded",
|
|
1275
|
-
"refunded|returned": "
|
|
1274
|
+
"refunded|returned": "Refunded",
|
|
1275
|
+
// Full refund of a never-fulfilled order (kaching refund op lands on
|
|
1276
|
+
// cancelled when nothing was delivered). Terminal payment states emit no
|
|
1277
|
+
// generic rows, so without this the pair fell through to the raw
|
|
1278
|
+
// "refunded / cancelled" engine fallback.
|
|
1279
|
+
"refunded|cancelled": "Refunded",
|
|
1276
1280
|
"voided|cancelled": "Cancelled"
|
|
1277
1281
|
};
|
|
1278
1282
|
function buildDefaultDisplayStateMap() {
|
|
@@ -1322,7 +1326,8 @@ var POS_VALID_INITIAL_STATES = [
|
|
|
1322
1326
|
{ payment: "unpaid", fulfillment: "pending" },
|
|
1323
1327
|
{ payment: "paid", fulfillment: "fulfilled" },
|
|
1324
1328
|
{ payment: "partially_paid", fulfillment: "draft" },
|
|
1325
|
-
{ payment: "partially_paid", fulfillment: "pending" }
|
|
1329
|
+
{ payment: "partially_paid", fulfillment: "pending" },
|
|
1330
|
+
{ payment: "partially_paid", fulfillment: "in_progress" }
|
|
1326
1331
|
];
|
|
1327
1332
|
function buildPosPresetConfig(companyId) {
|
|
1328
1333
|
return {
|
|
@@ -1524,9 +1529,7 @@ function conditionSummary(c) {
|
|
|
1524
1529
|
|
|
1525
1530
|
// order-state-machine/engine.ts
|
|
1526
1531
|
function pairInInitialList(to, config) {
|
|
1527
|
-
return config.validInitialStates.some(
|
|
1528
|
-
(p) => p.payment === to.payment && p.fulfillment === to.fulfillment
|
|
1529
|
-
);
|
|
1532
|
+
return config.validInitialStates.some((p) => p.payment === to.payment && p.fulfillment === to.fulfillment);
|
|
1530
1533
|
}
|
|
1531
1534
|
function triggerTargets(rule) {
|
|
1532
1535
|
const t = rule.trigger.to;
|
|
@@ -1574,17 +1577,13 @@ function collectPathConditionFailures(config, from, to, context) {
|
|
|
1574
1577
|
const failed = [];
|
|
1575
1578
|
if (from === null) return { failed };
|
|
1576
1579
|
if (from.payment !== to.payment) {
|
|
1577
|
-
const p = config.paymentPaths.find(
|
|
1578
|
-
(x) => x.from === from.payment && x.to === to.payment
|
|
1579
|
-
);
|
|
1580
|
+
const p = config.paymentPaths.find((x) => x.from === from.payment && x.to === to.payment);
|
|
1580
1581
|
const set = findConditionSet(config, p?.conditionSetId);
|
|
1581
1582
|
const ev = evaluateConditionSet(set, context);
|
|
1582
1583
|
if (!ev.ok) failed.push(...ev.failedConditions);
|
|
1583
1584
|
}
|
|
1584
1585
|
if (from.fulfillment !== to.fulfillment) {
|
|
1585
|
-
const p = config.fulfillmentPaths.find(
|
|
1586
|
-
(x) => x.from === from.fulfillment && x.to === to.fulfillment
|
|
1587
|
-
);
|
|
1586
|
+
const p = config.fulfillmentPaths.find((x) => x.from === from.fulfillment && x.to === to.fulfillment);
|
|
1588
1587
|
const set = findConditionSet(config, p?.conditionSetId);
|
|
1589
1588
|
const ev = evaluateConditionSet(set, context);
|
|
1590
1589
|
if (!ev.ok) failed.push(...ev.failedConditions);
|
|
@@ -1593,20 +1592,10 @@ function collectPathConditionFailures(config, from, to, context) {
|
|
|
1593
1592
|
}
|
|
1594
1593
|
function pathBlocked(config, from, to) {
|
|
1595
1594
|
if (from === null) return false;
|
|
1596
|
-
if (from.payment !== to.payment && !axisTransitionAllowed(
|
|
1597
|
-
config.paymentPathMode,
|
|
1598
|
-
config.paymentPaths,
|
|
1599
|
-
from.payment,
|
|
1600
|
-
to.payment
|
|
1601
|
-
)) {
|
|
1595
|
+
if (from.payment !== to.payment && !axisTransitionAllowed(config.paymentPathMode, config.paymentPaths, from.payment, to.payment)) {
|
|
1602
1596
|
return true;
|
|
1603
1597
|
}
|
|
1604
|
-
if (from.fulfillment !== to.fulfillment && !axisTransitionAllowed(
|
|
1605
|
-
config.fulfillmentPathMode,
|
|
1606
|
-
config.fulfillmentPaths,
|
|
1607
|
-
from.fulfillment,
|
|
1608
|
-
to.fulfillment
|
|
1609
|
-
)) {
|
|
1598
|
+
if (from.fulfillment !== to.fulfillment && !axisTransitionAllowed(config.fulfillmentPathMode, config.fulfillmentPaths, from.fulfillment, to.fulfillment)) {
|
|
1610
1599
|
return true;
|
|
1611
1600
|
}
|
|
1612
1601
|
return false;
|
|
@@ -1632,7 +1621,7 @@ function canTransition(request) {
|
|
|
1632
1621
|
};
|
|
1633
1622
|
}
|
|
1634
1623
|
if (from === null) {
|
|
1635
|
-
if (!pairInInitialList(to, config)) {
|
|
1624
|
+
if (config.enforceValidInitialStates === true && !pairInInitialList(to, config)) {
|
|
1636
1625
|
return {
|
|
1637
1626
|
allowed: false,
|
|
1638
1627
|
blockedBy: "path",
|
|
@@ -1690,15 +1679,11 @@ function conditionMetLines(config, from, to, context) {
|
|
|
1690
1679
|
}
|
|
1691
1680
|
};
|
|
1692
1681
|
if (from.payment !== to.payment) {
|
|
1693
|
-
const p = config.paymentPaths.find(
|
|
1694
|
-
(x) => x.from === from.payment && x.to === to.payment
|
|
1695
|
-
);
|
|
1682
|
+
const p = config.paymentPaths.find((x) => x.from === from.payment && x.to === to.payment);
|
|
1696
1683
|
appendForPath(p);
|
|
1697
1684
|
}
|
|
1698
1685
|
if (from.fulfillment !== to.fulfillment) {
|
|
1699
|
-
const p = config.fulfillmentPaths.find(
|
|
1700
|
-
(x) => x.from === from.fulfillment && x.to === to.fulfillment
|
|
1701
|
-
);
|
|
1686
|
+
const p = config.fulfillmentPaths.find((x) => x.from === from.fulfillment && x.to === to.fulfillment);
|
|
1702
1687
|
appendForPath(p);
|
|
1703
1688
|
}
|
|
1704
1689
|
return lines;
|