@final-commerce/command-frame 0.3.2-preprod.1 → 0.4.0-beta.1
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 +1 -1
- package/dist/actions/add-product-to-cart/types.d.ts +13 -1
- package/dist/actions/update-cart-item-quantity/types.d.ts +8 -1
- package/dist/demo/database.d.ts +0 -1
- package/dist/demo/database.js +1 -54
- package/dist/index.d.ts +1 -3
- package/dist/index.js +0 -2
- package/dist/projects/render/mocks.js +0 -2
- package/dist/projects/render/types.d.ts +1 -2
- package/dist/pubsub/topics/orders/index.js +0 -5
- package/dist/pubsub/topics/orders/types.d.ts +2 -4
- package/dist/pubsub/topics/orders/types.js +0 -1
- package/package.json +2 -2
- package/dist/actions/void-order/action.d.ts +0 -6
- package/dist/actions/void-order/action.js +0 -8
- package/dist/actions/void-order/mock.d.ts +0 -2
- package/dist/actions/void-order/mock.js +0 -23
- package/dist/actions/void-order/types.d.ts +0 -27
- package/dist/actions/void-order/types.js +0 -1
- package/dist/pubsub/topics/orders/order-voided/types.d.ts +0 -14
- package/dist/pubsub/topics/orders/order-voided/types.js +0 -1
package/README.md
CHANGED
|
@@ -96,7 +96,7 @@ const context = await client.getContext();
|
|
|
96
96
|
The pub/sub system allows iframe extensions to subscribe to topics and receive real-time events published by the host (Render). Subscriptions are **page-scoped** -- they fire only while the iframe is mounted on the current page.
|
|
97
97
|
|
|
98
98
|
- **[Pub/Sub Documentation](./src/pubsub/README.md)**
|
|
99
|
-
- **Topics:** Cart (16), Customers (8), Orders (
|
|
99
|
+
- **Topics:** Cart (16), Customers (8), Orders (4), Payments (2), Products (4), Refunds (4), Print (3), Custom Tables (3), Outlet (2), Station (2), Session (2), Users (2).
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
102
|
import { topics } from "@final-commerce/command-frame";
|
|
@@ -3,7 +3,19 @@ import type { AddProductFeeParams } from "../add-product-fee/types";
|
|
|
3
3
|
export interface AddProductToCartParams {
|
|
4
4
|
/** ID of the variant to add. */
|
|
5
5
|
variantId: string;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Defaults to 1. **May be fractional** — a variant sold by weight, volume or length is priced
|
|
8
|
+
* per its own unit and keyed in that unit, so `0.456` kg is a quantity, not a typo.
|
|
9
|
+
*
|
|
10
|
+
* How many decimals are allowed is the variant's own business: `variant.unit.precision` —
|
|
11
|
+
* `3` for a litre, `0` for anything sold by the piece. The engine refuses a quantity finer
|
|
12
|
+
* than that and says which unit it was measured against; do not round, floor or clamp before
|
|
13
|
+
* sending, and never key a quantity in base units to work around it (a per-100g price with a
|
|
14
|
+
* gram count is explicitly not supported).
|
|
15
|
+
*
|
|
16
|
+
* A quantity field should take its step and its decimal count from `variant.unit.precision`,
|
|
17
|
+
* not from a constant.
|
|
18
|
+
*/
|
|
7
19
|
quantity?: number;
|
|
8
20
|
/** Array of discounts to apply immediately. */
|
|
9
21
|
discounts?: AddProductDiscountParams[];
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export interface UpdateCartItemQuantityParams {
|
|
2
2
|
/** The unique identifier for the specific cart item to update. */
|
|
3
3
|
internalId: string;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* The new quantity. If set to 0, the item will be removed from the cart.
|
|
6
|
+
*
|
|
7
|
+
* **May be fractional** for a variant sold by measure; the number of decimals allowed comes
|
|
8
|
+
* from `variant.unit.precision`. The engine refuses anything finer and names the unit in the
|
|
9
|
+
* error. Do not round or clamp before sending — a silently altered quantity is charged and
|
|
10
|
+
* deducted differently than the one the cashier typed.
|
|
11
|
+
*/
|
|
5
12
|
quantity: number;
|
|
6
13
|
}
|
|
7
14
|
export interface UpdateCartItemQuantityResponse {
|
package/dist/demo/database.d.ts
CHANGED
|
@@ -51,7 +51,6 @@ export declare const MOCK_PRODUCT_BLACK_GARLIC: import("@final-commerce/common/p
|
|
|
51
51
|
export declare const MOCK_ORDER_1: CFActiveOrder;
|
|
52
52
|
export declare const MOCK_ORDER_2: CFActiveOrder;
|
|
53
53
|
export declare const MOCK_ORDER_3: CFActiveOrder;
|
|
54
|
-
export declare const MOCK_ORDER_4: CFActiveOrder;
|
|
55
54
|
export declare const MOCK_PARKED_ORDER_1: CFActiveOrder;
|
|
56
55
|
export declare const MOCK_PARKED_ORDER_2: CFActiveOrder;
|
|
57
56
|
export declare const MOCK_USERS: import("@final-commerce/common/pos-types").ActiveUser[];
|
package/dist/demo/database.js
CHANGED
|
@@ -486,59 +486,6 @@ export const MOCK_ORDER_3 = {
|
|
|
486
486
|
station: MOCK_STATION_1,
|
|
487
487
|
createdAt: new Date(Date.now() - 7200000).toISOString()
|
|
488
488
|
};
|
|
489
|
-
// Open order with one captured deposit leg — voidable via the refund branch
|
|
490
|
-
// (demoes voidOrder's `refunded` outcome). Copied from MOCK_ORDER_1, id/state/
|
|
491
|
-
// paymentMethods changed.
|
|
492
|
-
export const MOCK_ORDER_4 = {
|
|
493
|
-
_id: "order_1004",
|
|
494
|
-
currency: CurrencyCode.USD,
|
|
495
|
-
minorUnits: 2,
|
|
496
|
-
receiptId: "1001-0004",
|
|
497
|
-
companyId: MOCK_COMPANY.id,
|
|
498
|
-
externalId: null,
|
|
499
|
-
status: "in_progress",
|
|
500
|
-
paymentState: "partially_paid",
|
|
501
|
-
fulfillmentState: "pending",
|
|
502
|
-
displayState: "Partially Paid",
|
|
503
|
-
customer: MOCK_CUSTOMER_5,
|
|
504
|
-
summary: {
|
|
505
|
-
total: 2500,
|
|
506
|
-
subtotalAfterFees: 2500,
|
|
507
|
-
discountTotal: 0,
|
|
508
|
-
shippingTotal: 0,
|
|
509
|
-
totalTaxes: 0,
|
|
510
|
-
taxes: [],
|
|
511
|
-
isTaxInclusive: false
|
|
512
|
-
},
|
|
513
|
-
cartDiscount: null,
|
|
514
|
-
cartFees: [],
|
|
515
|
-
paymentMethods: [
|
|
516
|
-
{
|
|
517
|
-
transactionId: "trans_cash_2",
|
|
518
|
-
paymentType: "cash",
|
|
519
|
-
amount: 1000,
|
|
520
|
-
timestamp: new Date(Date.now() - 600000).toISOString(),
|
|
521
|
-
processor: "cash"
|
|
522
|
-
}
|
|
523
|
-
],
|
|
524
|
-
source: "pos",
|
|
525
|
-
posData: {
|
|
526
|
-
outlet: MOCK_OUTLET_MAIN.id,
|
|
527
|
-
station: MOCK_STATION_2._id,
|
|
528
|
-
employee: MOCK_USER_MARIO.id
|
|
529
|
-
},
|
|
530
|
-
sessionId: "sess_4",
|
|
531
|
-
metadata: [],
|
|
532
|
-
billing: null,
|
|
533
|
-
shipping: null,
|
|
534
|
-
lineItems: [createLineItem(MOCK_PRODUCT_RED_PEPPER, 0, 1)],
|
|
535
|
-
customSales: [],
|
|
536
|
-
balance: 1500,
|
|
537
|
-
user: MOCK_USER_MARIO,
|
|
538
|
-
outlet: MOCK_OUTLET_MAIN,
|
|
539
|
-
station: MOCK_STATION_2,
|
|
540
|
-
createdAt: new Date(Date.now() - 600000).toISOString()
|
|
541
|
-
};
|
|
542
489
|
export const MOCK_PARKED_ORDER_1 = {
|
|
543
490
|
_id: "parked_2001",
|
|
544
491
|
currency: CurrencyCode.USD,
|
|
@@ -645,7 +592,7 @@ export const MOCK_PRODUCTS = [
|
|
|
645
592
|
MOCK_PRODUCT_HABANERO,
|
|
646
593
|
MOCK_PRODUCT_BLACK_GARLIC
|
|
647
594
|
];
|
|
648
|
-
export const MOCK_ORDERS = [MOCK_ORDER_1, MOCK_ORDER_2, MOCK_ORDER_3
|
|
595
|
+
export const MOCK_ORDERS = [MOCK_ORDER_1, MOCK_ORDER_2, MOCK_ORDER_3];
|
|
649
596
|
export const MOCK_PARKED_ORDERS = [MOCK_PARKED_ORDER_1, MOCK_PARKED_ORDER_2];
|
|
650
597
|
// Compatibility Exports (reassigned by setMockDatabase)
|
|
651
598
|
export let MOCK_USER = MOCK_USERS[0];
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ export declare const command: {
|
|
|
33
33
|
readonly parkOrder: import(".").ParkOrder;
|
|
34
34
|
readonly resumeParkedOrder: import(".").ResumeParkedOrder;
|
|
35
35
|
readonly deleteParkedOrder: import(".").DeleteParkedOrder;
|
|
36
|
-
readonly voidOrder: import(".").VoidOrder;
|
|
37
36
|
readonly cashPayment: import(".").CashPayment;
|
|
38
37
|
readonly getCashRoundingAmount: import(".").GetCashRoundingAmount;
|
|
39
38
|
readonly tapToPayPayment: import(".").TapToPayPayment;
|
|
@@ -162,7 +161,6 @@ export type { ClearCart, ClearCartResponse } from './actions/clear-cart/types';
|
|
|
162
161
|
export type { ParkOrder, ParkOrderResponse } from './actions/park-order/types';
|
|
163
162
|
export type { ResumeParkedOrder, ResumeParkedOrderParams, ResumeParkedOrderResponse, } from './actions/resume-parked-order/types';
|
|
164
163
|
export type { DeleteParkedOrder, DeleteParkedOrderParams, DeleteParkedOrderResponse, } from './actions/delete-parked-order/types';
|
|
165
|
-
export type { VoidOrder, VoidOrderParams, VoidOrderResponse, VoidOrderOutcome } from './actions/void-order/types';
|
|
166
164
|
export type { CashPayment, CashPaymentParams, CashPaymentResponse } from './actions/cash-payment/types';
|
|
167
165
|
export type { GetCashRoundingAmount, GetCashRoundingAmountParams, GetCashRoundingAmountResponse, } from './actions/get-cash-rounding-amount/types';
|
|
168
166
|
export type { TapToPayPayment, TapToPayPaymentParams, TapToPayPaymentResponse, } from './actions/tap-to-pay-payment/types';
|
|
@@ -242,7 +240,7 @@ export { transactionsTopic } from './pubsub/topics/transactions';
|
|
|
242
240
|
export { categoriesTopic } from './pubsub/topics/categories';
|
|
243
241
|
export { attributesTopic } from './pubsub/topics/attributes';
|
|
244
242
|
export type { CustomerCreatedPayload, CustomerUpdatedPayload, CustomerNoteAddedPayload, CustomerNoteDeletedPayload, CustomerAssignedPayload, CustomerUnassignedPayload, CustomerActiveSetPayload, CustomerActiveGetPayload, CustomerCreatedEvent, CustomerUpdatedEvent, CustomerNoteAddedEvent, CustomerNoteDeletedEvent, CustomerAssignedEvent, CustomerUnassignedEvent, CustomerActiveSetEvent, CustomerActiveGetEvent, CustomersEventType, CustomersEventPayload, } from './pubsub/topics/customers/types';
|
|
245
|
-
export type { OrderCreatedPayload, OrderUpdatedPayload,
|
|
243
|
+
export type { OrderCreatedPayload, OrderUpdatedPayload, OrderActiveSetPayload, OrderActiveGetPayload, OrderCreatedEvent, OrderUpdatedEvent, OrderActiveSetEvent, OrderActiveGetEvent, OrderStateTransitionCompletedPayload, OrderStateTransitionBlockedPayload, OrderStateTransitionCompletedEvent, OrderStateTransitionBlockedEvent, OrdersEventType, OrdersEventPayload, } from './pubsub/topics/orders/types';
|
|
246
244
|
export type { RefundCreatedPayload, RefundUpdatedPayload, RefundActiveSetPayload, RefundActiveGetPayload, RefundCreatedEvent, RefundUpdatedEvent, RefundActiveSetEvent, RefundActiveGetEvent, RefundsEventType, RefundsEventPayload, } from './pubsub/topics/refunds/types';
|
|
247
245
|
export type { ProductCreatedPayload, ProductUpdatedPayload, ProductSetActivePayload, ProductGetActivePayload, ProductCreatedEvent, ProductUpdatedEvent, ProductSetActiveEvent, ProductGetActiveEvent, ProductsEventType, ProductsEventPayload, } from './pubsub/topics/products/types';
|
|
248
246
|
export type { OutletActiveSetPayload, OutletActiveGetPayload, OutletActiveSetEvent, OutletActiveGetEvent, OutletEventType, OutletEventPayload, } from './pubsub/topics/outlet/types';
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,6 @@ import { clearCart } from './actions/clear-cart/action';
|
|
|
33
33
|
import { parkOrder } from './actions/park-order/action';
|
|
34
34
|
import { resumeParkedOrder } from './actions/resume-parked-order/action';
|
|
35
35
|
import { deleteParkedOrder } from './actions/delete-parked-order/action';
|
|
36
|
-
import { voidOrder } from './actions/void-order/action';
|
|
37
36
|
import { cashPayment } from './actions/cash-payment/action';
|
|
38
37
|
import { getCashRoundingAmount } from './actions/get-cash-rounding-amount/action';
|
|
39
38
|
import { tapToPayPayment } from './actions/tap-to-pay-payment/action';
|
|
@@ -164,7 +163,6 @@ export const command = {
|
|
|
164
163
|
parkOrder,
|
|
165
164
|
resumeParkedOrder,
|
|
166
165
|
deleteParkedOrder,
|
|
167
|
-
voidOrder,
|
|
168
166
|
cashPayment,
|
|
169
167
|
getCashRoundingAmount,
|
|
170
168
|
tapToPayPayment,
|
|
@@ -31,7 +31,6 @@ import { mockCashPayment } from '../../actions/cash-payment/mock';
|
|
|
31
31
|
import { mockGetCashRoundingAmount } from '../../actions/get-cash-rounding-amount/mock';
|
|
32
32
|
import { mockClearCart } from '../../actions/clear-cart/mock';
|
|
33
33
|
import { mockDeleteParkedOrder } from '../../actions/delete-parked-order/mock';
|
|
34
|
-
import { mockVoidOrder } from '../../actions/void-order/mock';
|
|
35
34
|
import { mockExampleFunction } from '../../actions/example-function/mock';
|
|
36
35
|
import { mockGetCategories } from '../../actions/get-categories/mock';
|
|
37
36
|
import { mockGetContext } from '../../actions/get-context/mock';
|
|
@@ -124,7 +123,6 @@ export const RENDER_MOCKS = {
|
|
|
124
123
|
getCashRoundingAmount: mockGetCashRoundingAmount,
|
|
125
124
|
clearCart: mockClearCart,
|
|
126
125
|
deleteParkedOrder: mockDeleteParkedOrder,
|
|
127
|
-
voidOrder: mockVoidOrder,
|
|
128
126
|
exampleFunction: mockExampleFunction,
|
|
129
127
|
getCategories: mockGetCategories,
|
|
130
128
|
getContext: mockGetContext,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder,
|
|
1
|
+
import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, InitiateRefund, CashPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, VendaraPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount, GetActiveOrder, GetActiveCustomer, SetActiveCustomer, GetActiveOutlet, GetActiveStation, GetActiveSession, GetActiveUser, SetActiveUser, SetActiveRefund, RemoveProductDiscount, RemoveProductFee, RemoveProductNote, RemoveCartFee, RemoveOrderNote, RemoveCustomSale, RemoveNonRevenueItem, CanTransition, GetAvailableTransitions, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms } from '../../index';
|
|
2
2
|
import type { OpenExtensionOverlay } from '../../actions/open-extension-overlay/types';
|
|
3
3
|
import type { ResolveExtensionOverlay } from '../../actions/resolve-extension-overlay/types';
|
|
4
4
|
export interface RenderProviderActions {
|
|
@@ -34,7 +34,6 @@ export interface RenderProviderActions {
|
|
|
34
34
|
parkOrder: ParkOrder;
|
|
35
35
|
resumeParkedOrder: ResumeParkedOrder;
|
|
36
36
|
deleteParkedOrder: DeleteParkedOrder;
|
|
37
|
-
voidOrder: VoidOrder;
|
|
38
37
|
initiateRefund: InitiateRefund;
|
|
39
38
|
openExtensionOverlay: OpenExtensionOverlay;
|
|
40
39
|
resolveExtensionOverlay: ResolveExtensionOverlay;
|
|
@@ -36,11 +36,6 @@ export const ordersTopic = {
|
|
|
36
36
|
id: "state-transition-blocked",
|
|
37
37
|
name: "State Transition Blocked",
|
|
38
38
|
description: "Published when an order state transition is blocked by the state machine"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
id: "order-voided",
|
|
42
|
-
name: "Order Voided",
|
|
43
|
-
description: "Published when an open order is voided (pure void, or captured legs refunded)"
|
|
44
39
|
}
|
|
45
40
|
]
|
|
46
41
|
};
|
|
@@ -4,17 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export * from "./order-created/types";
|
|
6
6
|
export * from "./order-updated/types";
|
|
7
|
-
export * from "./order-voided/types";
|
|
8
7
|
export * from "./set-active-order/types";
|
|
9
8
|
export * from "./get-active-order/types";
|
|
10
9
|
export * from "./state-transition-completed/types";
|
|
11
10
|
export * from "./state-transition-blocked/types";
|
|
12
11
|
import type { OrderCreatedPayload } from "./order-created/types";
|
|
13
12
|
import type { OrderUpdatedPayload } from "./order-updated/types";
|
|
14
|
-
import type { OrderVoidedPayload } from "./order-voided/types";
|
|
15
13
|
import type { OrderActiveSetPayload } from "./set-active-order/types";
|
|
16
14
|
import type { OrderActiveGetPayload } from "./get-active-order/types";
|
|
17
15
|
import type { OrderStateTransitionCompletedPayload } from "./state-transition-completed/types";
|
|
18
16
|
import type { OrderStateTransitionBlockedPayload } from "./state-transition-blocked/types";
|
|
19
|
-
export type OrdersEventPayload = OrderCreatedPayload | OrderUpdatedPayload |
|
|
20
|
-
export type OrdersEventType = "order-created" | "order-updated" | "
|
|
17
|
+
export type OrdersEventPayload = OrderCreatedPayload | OrderUpdatedPayload | OrderActiveSetPayload | OrderActiveGetPayload | OrderStateTransitionCompletedPayload | OrderStateTransitionBlockedPayload;
|
|
18
|
+
export type OrdersEventType = "order-created" | "order-updated" | "set-active-order" | "get-active-order" | "state-transition-completed" | "state-transition-blocked";
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
// Re-export all event types
|
|
6
6
|
export * from "./order-created/types";
|
|
7
7
|
export * from "./order-updated/types";
|
|
8
|
-
export * from "./order-voided/types";
|
|
9
8
|
export * from "./set-active-order/types";
|
|
10
9
|
export * from "./get-active-order/types";
|
|
11
10
|
export * from "./state-transition-completed/types";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@final-commerce/command-frame",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-beta.1",
|
|
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.0.
|
|
60
|
+
"@final-commerce/common": "^2.2.0-beta.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^19.0.0",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { MOCK_ORDERS, mockPublishEvent } from '../../demo/database';
|
|
2
|
-
// Payment states in which an order is still open — mirrors the runtime gate
|
|
3
|
-
// (kaching's OPEN_PAYMENT_STATES / handler.ts). Anything outside this set
|
|
4
|
-
// (paid, partially_refunded, refunded, voided, or unknown) is ORDER_NOT_VOIDABLE.
|
|
5
|
-
const OPEN_PAYMENT_STATES = ['unpaid', 'payment_pending', 'partially_paid'];
|
|
6
|
-
export const mockVoidOrder = async (params) => {
|
|
7
|
-
console.log('[Mock] voidOrder called', params);
|
|
8
|
-
const order = params?.orderId ? MOCK_ORDERS.find((o) => o._id === params.orderId) : MOCK_ORDERS[0];
|
|
9
|
-
if (!order) {
|
|
10
|
-
throw new Error(`Order with ID ${params?.orderId} not found`);
|
|
11
|
-
}
|
|
12
|
-
const orderId = order._id;
|
|
13
|
-
// Only OPEN orders are voidable — mirror the runtime gate.
|
|
14
|
-
if (!OPEN_PAYMENT_STATES.includes(order.paymentState)) {
|
|
15
|
-
throw new Error(`ORDER_NOT_VOIDABLE: order ${orderId} is '${order.paymentState}' — use the refund flow for completed orders`);
|
|
16
|
-
}
|
|
17
|
-
const hasCapturedLegs = (order.paymentMethods?.length ?? 0) > 0;
|
|
18
|
-
const outcome = hasCapturedLegs ? 'refunded' : 'voided';
|
|
19
|
-
order.paymentState = outcome;
|
|
20
|
-
order.fulfillmentState = 'cancelled';
|
|
21
|
-
mockPublishEvent('orders', 'order-voided', { orderId, outcome, reason: params?.reason });
|
|
22
|
-
return { success: true, orderId, outcome, timestamp: new Date().toISOString() };
|
|
23
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { CFTransitionResult } from '../../common-types/order-state';
|
|
2
|
-
export type VoidOrderOutcome = 'voided' | 'refunded';
|
|
3
|
-
export interface VoidOrderParams {
|
|
4
|
-
/** Order to void; defaults to the active order. */
|
|
5
|
-
orderId?: string;
|
|
6
|
-
/**
|
|
7
|
-
* Optional cashier-facing reason. On a pure void, recorded on the void audit
|
|
8
|
-
* row and carried on the `order-voided` event. On the refund branch it rides
|
|
9
|
-
* the event only — the refund dispatcher does not consume it.
|
|
10
|
-
*/
|
|
11
|
-
reason?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface VoidOrderResponse {
|
|
14
|
-
success: boolean;
|
|
15
|
-
orderId: string;
|
|
16
|
-
/**
|
|
17
|
-
* `voided` — nothing was captured; pure state transition to voided × cancelled.
|
|
18
|
-
* `refunded` — captured split legs were refunded to their original tenders;
|
|
19
|
-
* order lands refunded × cancelled (financially equivalent to a
|
|
20
|
-
* void, but the capture + payout stay on the audit trail).
|
|
21
|
-
*/
|
|
22
|
-
outcome: VoidOrderOutcome;
|
|
23
|
-
timestamp: string;
|
|
24
|
-
/** Present when the state machine blocked or forced the transition. */
|
|
25
|
-
transitionResult?: CFTransitionResult;
|
|
26
|
-
}
|
|
27
|
-
export type VoidOrder = (params?: VoidOrderParams) => Promise<VoidOrderResponse>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { TopicEvent } from '../../../types';
|
|
2
|
-
/**
|
|
3
|
-
* Order Voided Event Types
|
|
4
|
-
*/
|
|
5
|
-
export interface OrderVoidedPayload {
|
|
6
|
-
orderId: string;
|
|
7
|
-
/** 'voided' = nothing captured; 'refunded' = captured legs were refunded. */
|
|
8
|
-
outcome: 'voided' | 'refunded';
|
|
9
|
-
reason?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Typed event for order-voided
|
|
13
|
-
*/
|
|
14
|
-
export type OrderVoidedEvent = TopicEvent<OrderVoidedPayload>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|