@final-commerce/command-frame 0.11.0-preprod.1 → 0.11.0-preprod.3
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.
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import { MOCK_ORDERS, mockPublishEvent } from '../../demo/database';
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// (
|
|
2
|
+
// Mirrors the runtime gate (kaching's void-order/handler.ts): an order is
|
|
3
|
+
// voidable while it is still OPEN, or when it is PAID but was never fulfilled
|
|
4
|
+
// (still in the kitchen). Anything else (a handed-over paid order,
|
|
5
|
+
// partially_refunded, refunded, voided, or unknown) is ORDER_NOT_VOIDABLE.
|
|
5
6
|
const OPEN_PAYMENT_STATES = ['unpaid', 'payment_pending', 'partially_paid'];
|
|
7
|
+
const UNFULFILLED_STATES = ['draft', 'pending', 'on_hold'];
|
|
8
|
+
// No orderId means the order in the cart, never just any order: the runtime refuses an
|
|
9
|
+
// id-less void unless the order is the live cart's (a finished sale kept for receipts is
|
|
10
|
+
// not), and a legacy order with no cart flag counts only while it is still open. The demo
|
|
11
|
+
// has no stations, so the flag alone decides.
|
|
12
|
+
const isCartOrder = (o) => o.inCart != null
|
|
13
|
+
? o.inCart.active
|
|
14
|
+
: OPEN_PAYMENT_STATES.includes(o.paymentState) &&
|
|
15
|
+
(o.fulfillmentState ? o.fulfillmentState === 'draft' : o.status === 'in-cart');
|
|
6
16
|
export const mockVoidOrder = async (params) => {
|
|
7
17
|
console.log('[Mock] voidOrder called', params);
|
|
8
|
-
const order = params?.orderId ? MOCK_ORDERS.find((o) => o._id === params.orderId) : MOCK_ORDERS
|
|
18
|
+
const order = params?.orderId ? MOCK_ORDERS.find((o) => o._id === params.orderId) : MOCK_ORDERS.find(isCartOrder);
|
|
9
19
|
if (!order) {
|
|
10
|
-
throw new Error(`Order with ID ${params
|
|
20
|
+
throw new Error(params?.orderId ? `Order with ID ${params.orderId} not found` : 'No order selected. Please provide orderId.');
|
|
11
21
|
}
|
|
12
22
|
const orderId = order._id;
|
|
13
|
-
|
|
14
|
-
if (!OPEN_PAYMENT_STATES.includes(order.paymentState)) {
|
|
23
|
+
const paidUnfulfilled = order.paymentState === 'paid' && UNFULFILLED_STATES.includes(order.fulfillmentState);
|
|
24
|
+
if (!OPEN_PAYMENT_STATES.includes(order.paymentState) && !paidUnfulfilled) {
|
|
15
25
|
throw new Error(`ORDER_NOT_VOIDABLE: order ${orderId} is '${order.paymentState}' — use the refund flow for completed orders`);
|
|
16
26
|
}
|
|
17
27
|
const hasCapturedLegs = (order.paymentMethods?.length ?? 0) > 0;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type VoidOrderOutcome = 'voided' | 'refunded';
|
|
2
2
|
export interface VoidOrderParams {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Order to void. Omit for the live cart's order (resumed, or part-paid). A finished
|
|
5
|
+
* sale kept for receipts after payment is not the cart's order — pass its id.
|
|
6
|
+
*/
|
|
4
7
|
orderId?: string;
|
|
5
8
|
/**
|
|
6
9
|
* Optional cashier-facing reason. Recorded on both branches — the void audit
|
|
@@ -15,7 +18,8 @@ export interface VoidOrderResponse {
|
|
|
15
18
|
orderId: string;
|
|
16
19
|
/**
|
|
17
20
|
* `voided` — nothing was captured; pure state transition to voided × cancelled.
|
|
18
|
-
* `refunded` — captured
|
|
21
|
+
* `refunded` — captured payments (a deposit / split legs, or the whole
|
|
22
|
+
* payment of a paid order never fulfilled) were refunded to their original tenders;
|
|
19
23
|
* order lands refunded × cancelled (financially equivalent to a
|
|
20
24
|
* void, but the capture + payout stay on the audit trail).
|
|
21
25
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@final-commerce/command-frame",
|
|
3
|
-
"version": "0.11.0-preprod.
|
|
3
|
+
"version": "0.11.0-preprod.3",
|
|
4
4
|
"description": "Commands Frame library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"ignoreBranchesMissingTickets": true
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@final-commerce/common": "2.
|
|
60
|
+
"@final-commerce/common": "2.8.0-preprod.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^19.0.0",
|