@final-commerce/common 2.0.18-beta.1 → 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.d.mts
CHANGED
|
@@ -830,6 +830,7 @@ interface StoredStateConfig {
|
|
|
830
830
|
crossAxisRules: CrossAxisRule[];
|
|
831
831
|
transitionConditions: TransitionConditionSet[];
|
|
832
832
|
validInitialStates: StatePair[];
|
|
833
|
+
enforceValidInitialStates?: boolean;
|
|
833
834
|
displayStateMap: DisplayStateRule[];
|
|
834
835
|
createdAt: Date;
|
|
835
836
|
updatedAt: Date;
|
package/dist/index.d.ts
CHANGED
|
@@ -830,6 +830,7 @@ interface StoredStateConfig {
|
|
|
830
830
|
crossAxisRules: CrossAxisRule[];
|
|
831
831
|
transitionConditions: TransitionConditionSet[];
|
|
832
832
|
validInitialStates: StatePair[];
|
|
833
|
+
enforceValidInitialStates?: boolean;
|
|
833
834
|
displayStateMap: DisplayStateRule[];
|
|
834
835
|
createdAt: Date;
|
|
835
836
|
updatedAt: Date;
|
package/dist/index.js
CHANGED
|
@@ -1260,7 +1260,9 @@ var PAYMENT_DEFS = [
|
|
|
1260
1260
|
var FULFILLMENT_DEFS = [
|
|
1261
1261
|
{ id: "draft", label: "Draft", terminal: false },
|
|
1262
1262
|
{ id: "pending", label: "Pending", terminal: false },
|
|
1263
|
-
|
|
1263
|
+
// 'Parked' is the product term for a held order (OS bug #30) — the atom id
|
|
1264
|
+
// stays `on_hold`; only the human label realigns.
|
|
1265
|
+
{ id: "on_hold", label: "Parked", terminal: false },
|
|
1264
1266
|
{ id: "in_progress", label: "In Progress", terminal: false },
|
|
1265
1267
|
{ id: "fulfilled", label: "Fulfilled", terminal: true },
|
|
1266
1268
|
{ id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
|
|
@@ -1392,29 +1394,31 @@ var DEFAULT_CROSS_AXIS_RULES = [
|
|
|
1392
1394
|
|
|
1393
1395
|
// order-state-machine/default-config.ts
|
|
1394
1396
|
var DEFAULT_EPOCH = /* @__PURE__ */ new Date(0);
|
|
1395
|
-
var PAYMENT_LABELS = new Map(
|
|
1396
|
-
|
|
1397
|
-
);
|
|
1398
|
-
var FULFILLMENT_LABELS = new Map(
|
|
1399
|
-
baseFulfillmentDefinitions().map((d) => [d.id, d.label])
|
|
1400
|
-
);
|
|
1397
|
+
var PAYMENT_LABELS = new Map(basePaymentDefinitions().map((d) => [d.id, d.label]));
|
|
1398
|
+
var FULFILLMENT_LABELS = new Map(baseFulfillmentDefinitions().map((d) => [d.id, d.label]));
|
|
1401
1399
|
var TERMINAL_PAYMENT_STATES = new Set(
|
|
1402
1400
|
basePaymentDefinitions().filter((d) => d.isTerminal).map((d) => d.id)
|
|
1403
1401
|
);
|
|
1404
1402
|
var DISPLAY_LABEL_OVERRIDES = {
|
|
1405
1403
|
"unpaid|draft": "In Cart",
|
|
1406
1404
|
"unpaid|pending": "Pending Payment",
|
|
1407
|
-
"unpaid|on_hold": "
|
|
1405
|
+
"unpaid|on_hold": "Parked",
|
|
1408
1406
|
"unpaid|cancelled": "Cancelled",
|
|
1409
1407
|
"partially_paid|pending": "Deposit Received",
|
|
1410
|
-
"partially_paid|on_hold": "
|
|
1408
|
+
"partially_paid|on_hold": "Parked - Deposit Received",
|
|
1409
|
+
"partially_paid|in_progress": "Partially Paid",
|
|
1411
1410
|
"paid|pending": "Paid - Awaiting Fulfillment",
|
|
1412
|
-
"paid|on_hold": "
|
|
1411
|
+
"paid|on_hold": "Parked - Paid",
|
|
1413
1412
|
"paid|fulfilled": "Completed",
|
|
1414
1413
|
"partially_refunded|fulfilled": "Partially Refunded",
|
|
1415
|
-
"partially_refunded|partially_returned": "Partially
|
|
1414
|
+
"partially_refunded|partially_returned": "Partially Refunded",
|
|
1416
1415
|
"refunded|fulfilled": "Refunded",
|
|
1417
|
-
"refunded|returned": "
|
|
1416
|
+
"refunded|returned": "Refunded",
|
|
1417
|
+
// Full refund of a never-fulfilled order (kaching refund op lands on
|
|
1418
|
+
// cancelled when nothing was delivered). Terminal payment states emit no
|
|
1419
|
+
// generic rows, so without this the pair fell through to the raw
|
|
1420
|
+
// "refunded / cancelled" engine fallback.
|
|
1421
|
+
"refunded|cancelled": "Refunded",
|
|
1418
1422
|
"voided|cancelled": "Cancelled"
|
|
1419
1423
|
};
|
|
1420
1424
|
function buildDefaultDisplayStateMap() {
|
|
@@ -1464,7 +1468,8 @@ var POS_VALID_INITIAL_STATES = [
|
|
|
1464
1468
|
{ payment: "unpaid", fulfillment: "pending" },
|
|
1465
1469
|
{ payment: "paid", fulfillment: "fulfilled" },
|
|
1466
1470
|
{ payment: "partially_paid", fulfillment: "draft" },
|
|
1467
|
-
{ payment: "partially_paid", fulfillment: "pending" }
|
|
1471
|
+
{ payment: "partially_paid", fulfillment: "pending" },
|
|
1472
|
+
{ payment: "partially_paid", fulfillment: "in_progress" }
|
|
1468
1473
|
];
|
|
1469
1474
|
function buildPosPresetConfig(companyId) {
|
|
1470
1475
|
return {
|
|
@@ -1666,9 +1671,7 @@ function conditionSummary(c) {
|
|
|
1666
1671
|
|
|
1667
1672
|
// order-state-machine/engine.ts
|
|
1668
1673
|
function pairInInitialList(to, config) {
|
|
1669
|
-
return config.validInitialStates.some(
|
|
1670
|
-
(p) => p.payment === to.payment && p.fulfillment === to.fulfillment
|
|
1671
|
-
);
|
|
1674
|
+
return config.validInitialStates.some((p) => p.payment === to.payment && p.fulfillment === to.fulfillment);
|
|
1672
1675
|
}
|
|
1673
1676
|
function triggerTargets(rule) {
|
|
1674
1677
|
const t = rule.trigger.to;
|
|
@@ -1716,17 +1719,13 @@ function collectPathConditionFailures(config, from, to, context) {
|
|
|
1716
1719
|
const failed = [];
|
|
1717
1720
|
if (from === null) return { failed };
|
|
1718
1721
|
if (from.payment !== to.payment) {
|
|
1719
|
-
const p = config.paymentPaths.find(
|
|
1720
|
-
(x) => x.from === from.payment && x.to === to.payment
|
|
1721
|
-
);
|
|
1722
|
+
const p = config.paymentPaths.find((x) => x.from === from.payment && x.to === to.payment);
|
|
1722
1723
|
const set = findConditionSet(config, p?.conditionSetId);
|
|
1723
1724
|
const ev = evaluateConditionSet(set, context);
|
|
1724
1725
|
if (!ev.ok) failed.push(...ev.failedConditions);
|
|
1725
1726
|
}
|
|
1726
1727
|
if (from.fulfillment !== to.fulfillment) {
|
|
1727
|
-
const p = config.fulfillmentPaths.find(
|
|
1728
|
-
(x) => x.from === from.fulfillment && x.to === to.fulfillment
|
|
1729
|
-
);
|
|
1728
|
+
const p = config.fulfillmentPaths.find((x) => x.from === from.fulfillment && x.to === to.fulfillment);
|
|
1730
1729
|
const set = findConditionSet(config, p?.conditionSetId);
|
|
1731
1730
|
const ev = evaluateConditionSet(set, context);
|
|
1732
1731
|
if (!ev.ok) failed.push(...ev.failedConditions);
|
|
@@ -1735,20 +1734,10 @@ function collectPathConditionFailures(config, from, to, context) {
|
|
|
1735
1734
|
}
|
|
1736
1735
|
function pathBlocked(config, from, to) {
|
|
1737
1736
|
if (from === null) return false;
|
|
1738
|
-
if (from.payment !== to.payment && !axisTransitionAllowed(
|
|
1739
|
-
config.paymentPathMode,
|
|
1740
|
-
config.paymentPaths,
|
|
1741
|
-
from.payment,
|
|
1742
|
-
to.payment
|
|
1743
|
-
)) {
|
|
1737
|
+
if (from.payment !== to.payment && !axisTransitionAllowed(config.paymentPathMode, config.paymentPaths, from.payment, to.payment)) {
|
|
1744
1738
|
return true;
|
|
1745
1739
|
}
|
|
1746
|
-
if (from.fulfillment !== to.fulfillment && !axisTransitionAllowed(
|
|
1747
|
-
config.fulfillmentPathMode,
|
|
1748
|
-
config.fulfillmentPaths,
|
|
1749
|
-
from.fulfillment,
|
|
1750
|
-
to.fulfillment
|
|
1751
|
-
)) {
|
|
1740
|
+
if (from.fulfillment !== to.fulfillment && !axisTransitionAllowed(config.fulfillmentPathMode, config.fulfillmentPaths, from.fulfillment, to.fulfillment)) {
|
|
1752
1741
|
return true;
|
|
1753
1742
|
}
|
|
1754
1743
|
return false;
|
|
@@ -1774,7 +1763,7 @@ function canTransition(request) {
|
|
|
1774
1763
|
};
|
|
1775
1764
|
}
|
|
1776
1765
|
if (from === null) {
|
|
1777
|
-
if (!pairInInitialList(to, config)) {
|
|
1766
|
+
if (config.enforceValidInitialStates === true && !pairInInitialList(to, config)) {
|
|
1778
1767
|
return {
|
|
1779
1768
|
allowed: false,
|
|
1780
1769
|
blockedBy: "path",
|
|
@@ -1832,15 +1821,11 @@ function conditionMetLines(config, from, to, context) {
|
|
|
1832
1821
|
}
|
|
1833
1822
|
};
|
|
1834
1823
|
if (from.payment !== to.payment) {
|
|
1835
|
-
const p = config.paymentPaths.find(
|
|
1836
|
-
(x) => x.from === from.payment && x.to === to.payment
|
|
1837
|
-
);
|
|
1824
|
+
const p = config.paymentPaths.find((x) => x.from === from.payment && x.to === to.payment);
|
|
1838
1825
|
appendForPath(p);
|
|
1839
1826
|
}
|
|
1840
1827
|
if (from.fulfillment !== to.fulfillment) {
|
|
1841
|
-
const p = config.fulfillmentPaths.find(
|
|
1842
|
-
(x) => x.from === from.fulfillment && x.to === to.fulfillment
|
|
1843
|
-
);
|
|
1828
|
+
const p = config.fulfillmentPaths.find((x) => x.from === from.fulfillment && x.to === to.fulfillment);
|
|
1844
1829
|
appendForPath(p);
|
|
1845
1830
|
}
|
|
1846
1831
|
return lines;
|