@final-commerce/command-frame 0.9.0-preprod.1 → 0.9.0-preprod.2

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.
Files changed (64) hide show
  1. package/dist/CommonTypes.d.ts +4 -1
  2. package/dist/actions/assign-order-user/action.d.ts +6 -0
  3. package/dist/actions/assign-order-user/action.js +8 -0
  4. package/dist/actions/assign-order-user/mock.d.ts +2 -0
  5. package/dist/actions/assign-order-user/mock.js +30 -0
  6. package/dist/actions/assign-order-user/types.d.ts +15 -0
  7. package/dist/actions/assign-order-user/types.js +1 -0
  8. package/dist/actions/get-order-statuses/action.d.ts +6 -0
  9. package/dist/actions/get-order-statuses/action.js +8 -0
  10. package/dist/actions/get-order-statuses/mock.d.ts +2 -0
  11. package/dist/actions/get-order-statuses/mock.js +5 -0
  12. package/dist/actions/get-order-statuses/types.d.ts +8 -0
  13. package/dist/actions/get-order-statuses/types.js +1 -0
  14. package/dist/actions/get-orders/action.d.ts +1 -1
  15. package/dist/actions/get-orders/action.js +2 -2
  16. package/dist/actions/get-orders/mock.d.ts +1 -1
  17. package/dist/actions/get-orders/mock.js +49 -19
  18. package/dist/actions/get-orders/types.d.ts +21 -1
  19. package/dist/actions/record-external-payment/action.d.ts +6 -0
  20. package/dist/actions/record-external-payment/action.js +8 -0
  21. package/dist/actions/record-external-payment/mock.d.ts +2 -0
  22. package/dist/actions/record-external-payment/mock.js +36 -0
  23. package/dist/actions/record-external-payment/types.d.ts +37 -0
  24. package/dist/actions/record-external-payment/types.js +1 -0
  25. package/dist/actions/release-from-cart/action.d.ts +6 -0
  26. package/dist/actions/release-from-cart/action.js +8 -0
  27. package/dist/actions/release-from-cart/mock.d.ts +2 -0
  28. package/dist/actions/release-from-cart/mock.js +26 -0
  29. package/dist/actions/release-from-cart/types.d.ts +8 -0
  30. package/dist/actions/release-from-cart/types.js +1 -0
  31. package/dist/actions/resume-order/action.d.ts +6 -0
  32. package/dist/actions/resume-order/action.js +8 -0
  33. package/dist/actions/resume-order/mock.d.ts +2 -0
  34. package/dist/actions/resume-order/mock.js +55 -0
  35. package/dist/actions/resume-order/types.d.ts +17 -0
  36. package/dist/actions/resume-order/types.js +1 -0
  37. package/dist/actions/resume-parked-order/mock.d.ts +6 -1
  38. package/dist/actions/resume-parked-order/mock.js +32 -31
  39. package/dist/actions/set-order-metadata/action.d.ts +6 -0
  40. package/dist/actions/set-order-metadata/action.js +8 -0
  41. package/dist/actions/set-order-metadata/mock.d.ts +5 -0
  42. package/dist/actions/set-order-metadata/mock.js +38 -0
  43. package/dist/actions/set-order-metadata/types.d.ts +20 -0
  44. package/dist/actions/set-order-metadata/types.js +1 -0
  45. package/dist/actions/set-order-status/action.d.ts +6 -0
  46. package/dist/actions/set-order-status/action.js +8 -0
  47. package/dist/actions/set-order-status/mock.d.ts +3 -0
  48. package/dist/actions/set-order-status/mock.js +39 -0
  49. package/dist/actions/set-order-status/types.d.ts +20 -0
  50. package/dist/actions/set-order-status/types.js +1 -0
  51. package/dist/actions/set-order-type/action.d.ts +6 -0
  52. package/dist/actions/set-order-type/action.js +8 -0
  53. package/dist/actions/set-order-type/mock.d.ts +3 -0
  54. package/dist/actions/set-order-type/mock.js +27 -0
  55. package/dist/actions/set-order-type/types.d.ts +17 -0
  56. package/dist/actions/set-order-type/types.js +1 -0
  57. package/dist/common-types/order-state.d.ts +15 -1
  58. package/dist/demo/database.d.ts +4 -0
  59. package/dist/demo/database.js +11 -0
  60. package/dist/index.d.ts +16 -0
  61. package/dist/index.js +16 -0
  62. package/dist/projects/render/mocks.js +16 -0
  63. package/dist/projects/render/types.d.ts +9 -1
  64. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  export * from './common-types';
2
- import type { Tax, Tip, Address, MetadataItem, PosDataItem, CartFeeTaxEntry, CartFeeItem, CartDiscountItem, OrderNote, NonRevenueItem, DiscountDetail, FeeDetail, DiscountLineItem, FeeLineItem, LineItem, TipPayment, RefundedTipPayment, PaymentMethod, Discount, CustomFee, Summary, CustomSale, RefundedCustomSale, RefundItem, RefundedLineItem, ActiveStation, ActiveSession, ActiveOutlet, ActiveUser, ActiveUserRole, ActiveOrder, ActiveCart, ActivePark, ActiveCompany, ActiveCustomSales, ActiveProduct, ActiveCustomer, FullProduct, ProductVariant, Inventory, ResolvedModifier, ResolvedModifierChoice, ModifierSelectionType, ModifierSelection, ModifierChoiceSelection, CartLineModifier, ProdModifierBreakdown, OrderLineItemModifier, CustomerNote, Attribute, AttributeOption, Category, Transaction, ActiveSplitPayment, BookingAvailability, BookingSlot, BookingSlotResource, BookingResource, Booking, CartReservation, OrderReservation } from '@final-commerce/common/pos-types';
2
+ import type { Tax, Tip, Address, MetadataItem, OrderAssignedUser, OrderInCart, OrderCustomStatus, PosDataItem, CartFeeTaxEntry, CartFeeItem, CartDiscountItem, OrderNote, NonRevenueItem, DiscountDetail, FeeDetail, DiscountLineItem, FeeLineItem, LineItem, TipPayment, RefundedTipPayment, PaymentMethod, Discount, CustomFee, Summary, CustomSale, RefundedCustomSale, RefundItem, RefundedLineItem, ActiveStation, ActiveSession, ActiveOutlet, ActiveUser, ActiveUserRole, ActiveOrder, ActiveCart, ActivePark, ActiveCompany, ActiveCustomSales, ActiveProduct, ActiveCustomer, FullProduct, ProductVariant, Inventory, ResolvedModifier, ResolvedModifierChoice, ModifierSelectionType, ModifierSelection, ModifierChoiceSelection, CartLineModifier, ProdModifierBreakdown, OrderLineItemModifier, CustomerNote, Attribute, AttributeOption, Category, Transaction, ActiveSplitPayment, BookingAvailability, BookingSlot, BookingSlotResource, BookingResource, Booking, CartReservation, OrderReservation } from '@final-commerce/common/pos-types';
3
3
  export { CurrencyCode, ProductType as CFProductType, UserTypes as CFUserTypes } from '@final-commerce/common';
4
4
  /** Open record used as a base for active entities. */
5
5
  export type CFActiveEntity = Record<string, unknown>;
@@ -7,6 +7,9 @@ export type CFDiscount = Discount;
7
7
  export type CFCustomFee = CustomFee;
8
8
  export type CFAddress = Address;
9
9
  export type CFMetadataItem = MetadataItem;
10
+ export type CFOrderAssignedUser = OrderAssignedUser;
11
+ export type CFOrderInCart = OrderInCart;
12
+ export type CFOrderCustomStatus = OrderCustomStatus;
10
13
  export type CFTax = Tax;
11
14
  export type CFCartFeeTaxEntry = CartFeeTaxEntry;
12
15
  export type CFInventory = Inventory;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Assign order user action
3
+ * Calls the assignOrderUser action on the parent window
4
+ */
5
+ import type { AssignOrderUser } from './types';
6
+ export declare const assignOrderUser: AssignOrderUser;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Assign order user action
3
+ * Calls the assignOrderUser action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const assignOrderUser = async (params) => {
7
+ return await commandFrameClient.call('assignOrderUser', params);
8
+ };
@@ -0,0 +1,2 @@
1
+ import type { AssignOrderUser } from './types';
2
+ export declare const mockAssignOrderUser: AssignOrderUser;
@@ -0,0 +1,30 @@
1
+ import { MOCK_ORDERS, MOCK_PARKED_ORDERS, MOCK_USERS, mockPublishEvent } from '../../demo/database';
2
+ export const mockAssignOrderUser = async (params) => {
3
+ console.log('[Mock] assignOrderUser called', params);
4
+ if (!params?.orderId) {
5
+ throw new Error('assignOrderUser: the demo has no live-cart order — pass an orderId');
6
+ }
7
+ if (params.userId !== null && typeof params.userId !== 'string') {
8
+ throw new Error('assignOrderUser: userId must be a user id or null');
9
+ }
10
+ const order = [...MOCK_ORDERS, ...MOCK_PARKED_ORDERS].find((o) => o._id === params.orderId);
11
+ if (!order) {
12
+ throw new Error(`Order with ID ${params.orderId} not found`);
13
+ }
14
+ if (params.userId === null) {
15
+ order.assignedUser = null;
16
+ }
17
+ else if (order.assignedUser?.userId !== params.userId) {
18
+ if (!MOCK_USERS.some((u) => u.id === params.userId)) {
19
+ throw new Error(`User with ID ${params.userId} not found`);
20
+ }
21
+ order.assignedUser = { userId: params.userId, assignedAt: new Date().toISOString() };
22
+ }
23
+ mockPublishEvent('orders', 'order-updated', { order });
24
+ return {
25
+ success: true,
26
+ orderId: order._id,
27
+ assignedUser: order.assignedUser ?? null,
28
+ timestamp: new Date().toISOString(),
29
+ };
30
+ };
@@ -0,0 +1,15 @@
1
+ import type { CFOrderAssignedUser } from '../../CommonTypes';
2
+ export interface AssignOrderUserParams {
3
+ /** Order to assign. Omit to target the live cart's order — it must already exist (parked, paid or transitioned). */
4
+ orderId?: string;
5
+ /** User to assign (e.g. the driver), or null to unassign. Replaces any current assignee. */
6
+ userId: string | null;
7
+ }
8
+ export interface AssignOrderUserResponse {
9
+ success: boolean;
10
+ orderId: string;
11
+ /** The order's assignee after the call; null when unassigned. */
12
+ assignedUser: CFOrderAssignedUser | null;
13
+ timestamp: string;
14
+ }
15
+ export type AssignOrderUser = (params: AssignOrderUserParams) => Promise<AssignOrderUserResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get order statuses action
3
+ * Calls the getOrderStatuses action on the parent window
4
+ */
5
+ import type { GetOrderStatuses } from './types';
6
+ export declare const getOrderStatuses: GetOrderStatuses;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Get order statuses action
3
+ * Calls the getOrderStatuses action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const getOrderStatuses = async () => {
7
+ return await commandFrameClient.call('getOrderStatuses', undefined);
8
+ };
@@ -0,0 +1,2 @@
1
+ import type { GetOrderStatuses } from './types';
2
+ export declare const mockGetOrderStatuses: GetOrderStatuses;
@@ -0,0 +1,5 @@
1
+ import { MOCK_ORDER_STATUSES } from '../../demo/database';
2
+ export const mockGetOrderStatuses = async () => {
3
+ console.log('[Mock] getOrderStatuses called');
4
+ return { success: true, statuses: MOCK_ORDER_STATUSES.map((s) => ({ ...s })), timestamp: new Date().toISOString() };
5
+ };
@@ -0,0 +1,8 @@
1
+ import type { CFOrderStatusDefinition } from '../../common-types/order-state';
2
+ export interface GetOrderStatusesResponse {
3
+ success: boolean;
4
+ /** The company's order statuses, in the order they were defined. Empty when none are defined. */
5
+ statuses: CFOrderStatusDefinition[];
6
+ timestamp: string;
7
+ }
8
+ export type GetOrderStatuses = () => Promise<GetOrderStatusesResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -2,5 +2,5 @@
2
2
  * Get orders action
3
3
  * Calls the getOrders action on the parent window
4
4
  */
5
- import type { GetOrders } from "./types";
5
+ import type { GetOrders } from './types';
6
6
  export declare const getOrders: GetOrders;
@@ -2,7 +2,7 @@
2
2
  * Get orders action
3
3
  * Calls the getOrders action on the parent window
4
4
  */
5
- import { commandFrameClient } from "../../client";
5
+ import { commandFrameClient } from '../../client';
6
6
  export const getOrders = async (params) => {
7
- return await commandFrameClient.call("getOrders", params);
7
+ return await commandFrameClient.call('getOrders', params);
8
8
  };
@@ -1,2 +1,2 @@
1
- import { GetOrders } from "./types";
1
+ import { GetOrders } from './types';
2
2
  export declare const mockGetOrders: GetOrders;
@@ -1,26 +1,60 @@
1
- import { MOCK_ORDERS, MOCK_PARKED_ORDERS, MOCK_USERS, MOCK_STATIONS, MOCK_OUTLETS, safeSerialize } from "../../demo/database";
1
+ import { MOCK_ORDERS, MOCK_PARKED_ORDERS, MOCK_USERS, MOCK_STATIONS, MOCK_OUTLETS, safeSerialize, } from '../../demo/database';
2
2
  export const mockGetOrders = async (params) => {
3
- console.log("[Mock] getOrders called", params);
3
+ console.log('[Mock] getOrders called', params);
4
4
  // Start with a safe copy of mock orders, including parked (status: "parked").
5
5
  let orders = safeSerialize([...MOCK_ORDERS, ...MOCK_PARKED_ORDERS]);
6
6
  // Filter simulation
7
7
  if (params) {
8
- const { customerId, status, sessionId, searchValue, limit, offset, sortBy, sortDirection } = params;
8
+ const { customerId, status, sessionId, paymentState, fulfillmentState, outletId, assignedUserId, inCart, orderType, customStatusId, searchValue, limit, offset, sortBy, sortDirection, } = params;
9
9
  // 1. Filtering
10
10
  if (customerId) {
11
- orders = orders.filter(o => o.customer &&
12
- '_id' in o.customer &&
13
- o.customer._id === customerId);
11
+ orders = orders.filter((o) => o.customer && '_id' in o.customer && o.customer._id === customerId);
14
12
  }
15
13
  if (status) {
16
- orders = orders.filter(o => o.status === status);
14
+ orders = orders.filter((o) => o.status === status);
17
15
  }
18
16
  if (sessionId) {
19
- orders = orders.filter(o => o.sessionId === sessionId);
17
+ orders = orders.filter((o) => o.sessionId === sessionId);
18
+ }
19
+ const anyOf = (criteria, value) => criteria === undefined ||
20
+ (Array.isArray(criteria) ? criteria.length === 0 || criteria.includes(value ?? '') : criteria === value);
21
+ if (paymentState !== undefined) {
22
+ orders = orders.filter((o) => anyOf(paymentState, o.paymentState));
23
+ }
24
+ if (fulfillmentState !== undefined) {
25
+ orders = orders.filter((o) => anyOf(fulfillmentState, o.fulfillmentState));
26
+ }
27
+ if (outletId) {
28
+ orders = orders.filter((o) => o.posData?.outlet === outletId);
29
+ }
30
+ if (assignedUserId) {
31
+ orders = orders.filter((o) => o.assignedUser?.userId === assignedUserId);
32
+ }
33
+ else if (assignedUserId === null) {
34
+ orders = orders.filter((o) => o.assignedUser == null);
35
+ }
36
+ if (orderType !== undefined) {
37
+ const types = Array.isArray(orderType) ? orderType : [orderType];
38
+ if (types.length)
39
+ orders = orders.filter((o) => types.includes(o.orderType ?? ''));
40
+ }
41
+ if (customStatusId !== undefined) {
42
+ const ids = Array.isArray(customStatusId) ? customStatusId : [customStatusId];
43
+ if (ids.length)
44
+ orders = orders.filter((o) => !!o.customStatus && ids.includes(o.customStatus.id));
45
+ }
46
+ if (typeof inCart === 'boolean') {
47
+ // Mirrors common's isInCart: the flag when present, else the legacy reading.
48
+ const orderInCart = (o) => o.inCart != null
49
+ ? o.inCart.active
50
+ : o.fulfillmentState
51
+ ? o.fulfillmentState === 'draft'
52
+ : o.status === 'in-cart';
53
+ orders = orders.filter((o) => orderInCart(o) === inCart);
20
54
  }
21
55
  if (searchValue) {
22
56
  const searchLower = String(searchValue).toLowerCase();
23
- orders = orders.filter(o => {
57
+ orders = orders.filter((o) => {
24
58
  const receiptMatch = o.receiptId?.toLowerCase().includes(searchLower);
25
59
  const customerNameMatch = o.customer && 'firstName' in o.customer
26
60
  ? `${o.customer.firstName} ${o.customer.lastName}`.toLowerCase().includes(searchLower)
@@ -42,14 +76,10 @@ export const mockGetOrders = async (params) => {
42
76
  if (!valB && sortBy === 'createdAt')
43
77
  valB = b.createdAt || '';
44
78
  if (typeof valA === 'string' && typeof valB === 'string') {
45
- return sortDirection === 'descending'
46
- ? valB.localeCompare(valA)
47
- : valA.localeCompare(valB);
79
+ return sortDirection === 'descending' ? valB.localeCompare(valA) : valA.localeCompare(valB);
48
80
  }
49
81
  // Number comparison
50
- return sortDirection === 'descending'
51
- ? (valB || 0) - (valA || 0)
52
- : (valA || 0) - (valB || 0);
82
+ return sortDirection === 'descending' ? (valB || 0) - (valA || 0) : (valA || 0) - (valB || 0);
53
83
  });
54
84
  }
55
85
  else {
@@ -73,21 +103,21 @@ export const mockGetOrders = async (params) => {
73
103
  if (enrichedOrder.posData) {
74
104
  // Enrich Employee
75
105
  if (typeof enrichedOrder.posData.employee === 'string') {
76
- const employee = MOCK_USERS.find(u => u.id === enrichedOrder.posData.employee);
106
+ const employee = MOCK_USERS.find((u) => u.id === enrichedOrder.posData.employee);
77
107
  if (employee) {
78
108
  enrichedOrder.posData.employee = employee;
79
109
  }
80
110
  }
81
111
  // Enrich Station
82
112
  if (typeof enrichedOrder.posData.station === 'string') {
83
- const station = MOCK_STATIONS.find(s => s._id === enrichedOrder.posData.station);
113
+ const station = MOCK_STATIONS.find((s) => s._id === enrichedOrder.posData.station);
84
114
  if (station) {
85
115
  enrichedOrder.posData.station = station;
86
116
  }
87
117
  }
88
118
  // Enrich Outlet
89
119
  if (typeof enrichedOrder.posData.outlet === 'string') {
90
- const outlet = MOCK_OUTLETS.find(o => o.id === enrichedOrder.posData.outlet);
120
+ const outlet = MOCK_OUTLETS.find((o) => o.id === enrichedOrder.posData.outlet);
91
121
  if (outlet) {
92
122
  enrichedOrder.posData.outlet = outlet;
93
123
  }
@@ -99,6 +129,6 @@ export const mockGetOrders = async (params) => {
99
129
  success: true,
100
130
  orders: enrichedOrders,
101
131
  total: MOCK_ORDERS.length, // Total before pagination
102
- timestamp: new Date().toISOString()
132
+ timestamp: new Date().toISOString(),
103
133
  };
104
134
  };
@@ -1,9 +1,29 @@
1
- import { CFOrder } from "../../CommonTypes";
1
+ import { CFOrder } from '../../CommonTypes';
2
2
  export interface GetOrdersParams {
3
3
  /** e.g. 'completed', 'parked', 'refunded'. */
4
4
  status?: string;
5
5
  customerId?: string;
6
6
  sessionId?: string;
7
+ /** Payment state(s), e.g. 'paid' or ['unpaid', 'partially_paid']. A list matches any of them. */
8
+ paymentState?: string | string[];
9
+ /** Fulfillment state(s), e.g. 'in_progress' or ['pending', 'in_progress']. A list matches any of them. */
10
+ fulfillmentState?: string | string[];
11
+ /** Only orders placed at this outlet (`posData.outlet`). Without it, orders from every outlet in the company are returned. */
12
+ outletId?: string;
13
+ /**
14
+ * Only orders assigned to this user (`assignedUser.userId`), e.g. a driver's deliveries.
15
+ * `null`: only orders nobody is assigned to yet (e.g. deliveries awaiting a driver).
16
+ */
17
+ assignedUserId?: string | null;
18
+ /**
19
+ * true: only orders loaded in a cart; false: only orders that aren't. Reads `order.inCart` when the order
20
+ * carries it, otherwise the legacy reading (fulfillment 'draft' / status 'in-cart').
21
+ */
22
+ inCart?: boolean;
23
+ /** Order type label(s) set with setOrderType, e.g. 'delivery' or ['pickup', 'takeout']. Exact match; a list matches any. */
24
+ orderType?: string | string[];
25
+ /** Custom status id(s) set with setOrderStatus, e.g. 'in-kitchen'. A list matches any of them. */
26
+ customStatusId?: string | string[];
7
27
  /** Default: 50. */
8
28
  limit?: number;
9
29
  /** Default: 0. */
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Record external payment action
3
+ * Calls the recordExternalPayment action on the parent window
4
+ */
5
+ import type { RecordExternalPayment } from './types';
6
+ export declare const recordExternalPayment: RecordExternalPayment;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Record external payment action
3
+ * Calls the recordExternalPayment action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const recordExternalPayment = async (params) => {
7
+ return await commandFrameClient.call('recordExternalPayment', params);
8
+ };
@@ -0,0 +1,2 @@
1
+ import type { RecordExternalPayment } from './types';
2
+ export declare const mockRecordExternalPayment: RecordExternalPayment;
@@ -0,0 +1,36 @@
1
+ import { isFulfillmentState } from '@final-commerce/common';
2
+ import { applyMockPayment, MOCK_CART } from '../../demo/database';
3
+ export const mockRecordExternalPayment = async (params) => {
4
+ console.log('[Mock] recordExternalPayment called', params);
5
+ const label = typeof params?.label === 'string' ? params.label.trim() : '';
6
+ if (!label) {
7
+ throw new Error('recordExternalPayment: label is required');
8
+ }
9
+ const balanceDue = MOCK_CART.amountToBeCharged ?? MOCK_CART.total;
10
+ const amount = params.amount ?? balanceDue;
11
+ // Same rule as the host: positive, except on a zero-balance checkout.
12
+ if (!Number.isFinite(amount) || amount < 0 || (amount === 0 && balanceDue > 0)) {
13
+ throw new Error('recordExternalPayment: amount must be a positive integer (minor units)');
14
+ }
15
+ const target = params.checkoutFulfillmentTarget;
16
+ if (target !== undefined && !isFulfillmentState(target)) {
17
+ throw new Error(`recordExternalPayment: invalid checkoutFulfillmentTarget "${String(target)}"`);
18
+ }
19
+ if (amount > balanceDue) {
20
+ throw new Error(`recordExternalPayment: amount ${amount} exceeds the balance due ${balanceDue}`);
21
+ }
22
+ const order = applyMockPayment(amount, 'external', label);
23
+ const remainingBalance = MOCK_CART.remainingBalance ?? 0;
24
+ return {
25
+ success: true,
26
+ amount,
27
+ label,
28
+ paymentType: 'external',
29
+ change: 0,
30
+ cashRounding: 0,
31
+ order,
32
+ saleFinalized: !!order,
33
+ remainingBalance: order ? 0 : remainingBalance,
34
+ timestamp: new Date().toISOString(),
35
+ };
36
+ };
@@ -0,0 +1,37 @@
1
+ import { CFOrder } from '../../CommonTypes';
2
+ export interface RecordExternalPaymentParams {
3
+ /**
4
+ * What the payment was — shown on the order and in reports, e.g. 'Paid online',
5
+ * 'Uber Eats', 'Voucher'. Required; trimmed. Not checked against a list, so keep
6
+ * labels consistent across flows.
7
+ */
8
+ label: string;
9
+ /**
10
+ * Amount to record, in integer MINOR currency units. Omit to record the full balance
11
+ * due (completing the order). Below the balance due it records a partial payment —
12
+ * the rest can be taken with any other tender. Above the balance due is an error.
13
+ */
14
+ amount?: number;
15
+ /** Fulfillment state to land on after full payment, e.g. 'pending' to keep the order going to the kitchen. */
16
+ checkoutFulfillmentTarget?: string;
17
+ }
18
+ export interface RecordExternalPaymentResponse {
19
+ success: boolean;
20
+ /** The amount recorded, in integer MINOR currency units. */
21
+ amount: number;
22
+ /** The label, as recorded. */
23
+ label: string;
24
+ paymentType: 'external';
25
+ /** Always 0 — no money changes hands at the terminal. */
26
+ change: number;
27
+ /** Always 0 — cash rounding applies to cash only. */
28
+ cashRounding: number;
29
+ /** The order once the sale completes; null for a partial (split) leg. */
30
+ order: CFOrder | null;
31
+ /** True when this payment settled the remaining balance. */
32
+ saleFinalized: boolean;
33
+ /** Balance still due after this payment, in integer MINOR currency units. */
34
+ remainingBalance: number;
35
+ timestamp: string;
36
+ }
37
+ export type RecordExternalPayment = (params: RecordExternalPaymentParams) => Promise<RecordExternalPaymentResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Release from cart action
3
+ * Calls the releaseFromCart action on the parent window
4
+ */
5
+ import type { ReleaseFromCart } from './types';
6
+ export declare const releaseFromCart: ReleaseFromCart;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Release from cart action
3
+ * Calls the releaseFromCart action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const releaseFromCart = async () => {
7
+ return await commandFrameClient.call('releaseFromCart', undefined);
8
+ };
@@ -0,0 +1,2 @@
1
+ import type { ReleaseFromCart } from './types';
2
+ export declare const mockReleaseFromCart: ReleaseFromCart;
@@ -0,0 +1,26 @@
1
+ import { MOCK_CART, MOCK_ORDERS, resetMockCart, mockPublishEvent } from '../../demo/database';
2
+ export const mockReleaseFromCart = async () => {
3
+ console.log('[Mock] releaseFromCart called');
4
+ if (!MOCK_CART.products.length) {
5
+ throw new Error('releaseFromCart: the cart is empty');
6
+ }
7
+ const now = new Date().toISOString();
8
+ // Best-effort: the demo has no live-cart order, so the cart becomes a new unpaid draft.
9
+ const order = {
10
+ _id: `order_released_${Date.now()}`,
11
+ receiptId: `REL-${MOCK_ORDERS.length + 1}`,
12
+ status: 'in-cart',
13
+ paymentState: 'unpaid',
14
+ fulfillmentState: 'draft',
15
+ inCart: { active: false, stationId: null, since: now },
16
+ lineItems: [],
17
+ customSales: [],
18
+ paymentMethods: [],
19
+ summary: { total: MOCK_CART.total },
20
+ createdAt: now,
21
+ };
22
+ MOCK_ORDERS.push(order);
23
+ resetMockCart();
24
+ mockPublishEvent('orders', 'order-updated', { order });
25
+ return { success: true, order, timestamp: now };
26
+ };
@@ -0,0 +1,8 @@
1
+ import type { CFOrder } from '../../CommonTypes';
2
+ export interface ReleaseFromCartResponse {
3
+ success: boolean;
4
+ /** The order that left the cart, as saved — its state is unchanged and `inCart.active` is false. */
5
+ order: CFOrder;
6
+ timestamp: string;
7
+ }
8
+ export type ReleaseFromCart = () => Promise<ReleaseFromCartResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Resume order action
3
+ * Calls the resumeOrder action on the parent window
4
+ */
5
+ import type { ResumeOrder } from './types';
6
+ export declare const resumeOrder: ResumeOrder;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resume order action
3
+ * Calls the resumeOrder action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const resumeOrder = async (params) => {
7
+ return await commandFrameClient.call('resumeOrder', params);
8
+ };
@@ -0,0 +1,2 @@
1
+ import type { ResumeOrder } from './types';
2
+ export declare const mockResumeOrder: ResumeOrder;
@@ -0,0 +1,55 @@
1
+ import { MOCK_ORDERS, MOCK_PARKED_ORDERS, mockPublishEvent } from '../../demo/database';
2
+ import { restoreMockCartFromOrder } from '../resume-parked-order/mock';
3
+ // Mirrors the host's rule (see README): anything not already in a cart and not finished.
4
+ const BLOCKED_PAYMENT = new Set(['refunded', 'partially_refunded', 'voided', 'payment_pending']);
5
+ const FINISHED_FULFILLMENT = new Set(['cancelled', 'returned', 'partially_returned']);
6
+ export const mockResumeOrder = async (params) => {
7
+ console.log('[Mock] resumeOrder called', params);
8
+ const orderId = params?.orderId;
9
+ if (!orderId) {
10
+ throw new Error('Order ID is required');
11
+ }
12
+ const order = [...MOCK_PARKED_ORDERS, ...MOCK_ORDERS].find((o) => o._id === orderId);
13
+ if (!order) {
14
+ throw new Error(`Order with ID ${orderId} not found`);
15
+ }
16
+ const from = { payment: order.paymentState ?? 'unpaid', fulfillment: order.fulfillmentState ?? 'draft' };
17
+ const inCart = order.inCart != null ? order.inCart.active : from.fulfillment === 'draft';
18
+ if (inCart) {
19
+ throw new Error(`Order ${orderId} is already in a cart`);
20
+ }
21
+ if (BLOCKED_PAYMENT.has(from.payment) ||
22
+ FINISHED_FULFILLMENT.has(from.fulfillment) ||
23
+ (from.payment === 'paid' && from.fulfillment === 'fulfilled')) {
24
+ throw new Error(`Order ${orderId} cannot be resumed from ${from.payment} × ${from.fulfillment}`);
25
+ }
26
+ // Keeps the state; only parked (on_hold) / draft move.
27
+ const leavesParked = from.fulfillment === 'on_hold' || from.fulfillment === 'draft';
28
+ const to = {
29
+ payment: from.payment,
30
+ fulfillment: !leavesParked ? from.fulfillment : from.payment === 'unpaid' ? 'draft' : 'in_progress',
31
+ };
32
+ restoreMockCartFromOrder(order);
33
+ const parkedIndex = MOCK_PARKED_ORDERS.findIndex((o) => o._id === orderId);
34
+ if (parkedIndex !== -1)
35
+ MOCK_PARKED_ORDERS.splice(parkedIndex, 1);
36
+ mockPublishEvent('cart', 'cart-created', { orderId });
37
+ mockPublishEvent('order-state', 'state-transition-completed', {
38
+ orderId,
39
+ from,
40
+ to,
41
+ timestamp: new Date().toISOString(),
42
+ });
43
+ return {
44
+ success: true,
45
+ order: {
46
+ ...order,
47
+ paymentState: to.payment,
48
+ fulfillmentState: to.fulfillment,
49
+ inCart: { active: true, stationId: null, since: new Date().toISOString() },
50
+ },
51
+ from,
52
+ to,
53
+ timestamp: new Date().toISOString(),
54
+ };
55
+ };
@@ -0,0 +1,17 @@
1
+ import { CFOrder } from '../../CommonTypes';
2
+ import type { CFStatePair } from '../../common-types/order-state';
3
+ export interface ResumeOrderParams {
4
+ /** The order to load back into the cart. Must be open — see the README for which states resume. */
5
+ orderId: string;
6
+ }
7
+ export interface ResumeOrderResponse {
8
+ success: boolean;
9
+ /** The resumed order, re-read after the transition. */
10
+ order: CFOrder;
11
+ /** State before resuming. */
12
+ from: CFStatePair;
13
+ /** State after resuming — `draft` when nothing was paid, otherwise the order stays out of the cart states. */
14
+ to: CFStatePair;
15
+ timestamp: string;
16
+ }
17
+ export type ResumeOrder = (params: ResumeOrderParams) => Promise<ResumeOrderResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,7 @@
1
- import { ResumeParkedOrder } from "./types";
1
+ import { ResumeParkedOrder } from './types';
2
+ import type { CFActiveOrder } from '../../CommonTypes';
3
+ /**
4
+ * Best-effort Order -> MOCK_CART mapping shared by the resume mocks.
5
+ */
6
+ export declare const restoreMockCartFromOrder: (orderToResume: CFActiveOrder) => void;
2
7
  export declare const mockResumeParkedOrder: ResumeParkedOrder;
@@ -1,11 +1,35 @@
1
- import { MOCK_PARKED_ORDERS, MOCK_CART, resetMockCart, mockPublishEvent } from "../../demo/database";
1
+ import { MOCK_PARKED_ORDERS, MOCK_CART, resetMockCart, mockPublishEvent } from '../../demo/database';
2
+ /**
3
+ * Best-effort Order -> MOCK_CART mapping shared by the resume mocks.
4
+ */
5
+ export const restoreMockCartFromOrder = (orderToResume) => {
6
+ resetMockCart();
7
+ MOCK_CART.customer = orderToResume.customer; // Cast if needed
8
+ MOCK_CART.products = orderToResume.lineItems.map((li) => ({
9
+ id: li.productId,
10
+ name: li.name,
11
+ quantity: li.quantity,
12
+ price: li.price,
13
+ internalId: li.internalId || li.productId,
14
+ variantId: li.variantId,
15
+ sku: li.sku,
16
+ images: [li.image],
17
+ stock: 100,
18
+ taxTableId: '',
19
+ attributes: li.attributes,
20
+ }));
21
+ MOCK_CART.subtotal = orderToResume.summary.subtotalAfterFees;
22
+ MOCK_CART.total = orderToResume.summary.total;
23
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
24
+ MOCK_CART.remainingBalance = MOCK_CART.total;
25
+ };
2
26
  export const mockResumeParkedOrder = async (params) => {
3
- console.log("[Mock] resumeParkedOrder called", params);
27
+ console.log('[Mock] resumeParkedOrder called', params);
4
28
  const orderId = params?.orderId;
5
29
  let orderToResume = null;
6
30
  let index = -1;
7
31
  if (orderId) {
8
- index = MOCK_PARKED_ORDERS.findIndex(o => o._id === orderId);
32
+ index = MOCK_PARKED_ORDERS.findIndex((o) => o._id === orderId);
9
33
  if (index !== -1)
10
34
  orderToResume = MOCK_PARKED_ORDERS[index];
11
35
  }
@@ -17,40 +41,17 @@ export const mockResumeParkedOrder = async (params) => {
17
41
  }
18
42
  }
19
43
  if (!orderToResume) {
20
- throw new Error("Parked order not found");
44
+ throw new Error('Parked order not found');
21
45
  }
22
- // Restore to MOCK_CART
23
- // Logic to convert Order back to Cart (simplified)
24
- resetMockCart();
25
- // Copy properties back
26
- MOCK_CART.customer = orderToResume.customer; // Cast if needed
27
- // MOCK_CART.products = orderToResume.lineItems... (Mapping needed)
28
- // For Mock demo, we'll do a best effort mapping
29
- MOCK_CART.products = orderToResume.lineItems.map(li => ({
30
- id: li.productId,
31
- name: li.name,
32
- quantity: li.quantity,
33
- price: li.price,
34
- internalId: li.internalId || li.productId,
35
- variantId: li.variantId,
36
- sku: li.sku,
37
- images: [li.image],
38
- stock: 100,
39
- taxTableId: "",
40
- attributes: li.attributes
41
- }));
42
- MOCK_CART.subtotal = orderToResume.summary.subtotalAfterFees;
43
- MOCK_CART.total = orderToResume.summary.total;
44
- MOCK_CART.amountToBeCharged = MOCK_CART.total;
45
- MOCK_CART.remainingBalance = MOCK_CART.total;
46
+ restoreMockCartFromOrder(orderToResume);
46
47
  // Remove from parked
47
48
  MOCK_PARKED_ORDERS.splice(index, 1);
48
49
  // Refresh the restored cart and the order lists.
49
- mockPublishEvent("cart", "parked-order-resumed", { orderId });
50
- mockPublishEvent("orders", "parked-order-resumed", { orderId });
50
+ mockPublishEvent('cart', 'parked-order-resumed', { orderId });
51
+ mockPublishEvent('orders', 'parked-order-resumed', { orderId });
51
52
  return {
52
53
  success: true,
53
54
  order: orderToResume,
54
- timestamp: new Date().toISOString()
55
+ timestamp: new Date().toISOString(),
55
56
  };
56
57
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Set order metadata action
3
+ * Calls the setOrderMetadata action on the parent window
4
+ */
5
+ import type { SetOrderMetadata } from './types';
6
+ export declare const setOrderMetadata: SetOrderMetadata;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Set order metadata action
3
+ * Calls the setOrderMetadata action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const setOrderMetadata = async (params) => {
7
+ return await commandFrameClient.call('setOrderMetadata', params);
8
+ };
@@ -0,0 +1,5 @@
1
+ import type { CFMetadataItem } from '../../CommonTypes';
2
+ import type { SetOrderMetadata } from './types';
3
+ /** Set/remove keys; untouched items (and extra fields such as `externalId`) are kept as-is. */
4
+ export declare const mergeMetadata: <T extends CFMetadataItem>(current: T[] | undefined, changes: Record<string, string | null>) => T[];
5
+ export declare const mockSetOrderMetadata: SetOrderMetadata;
@@ -0,0 +1,38 @@
1
+ import { MOCK_ORDERS, MOCK_PARKED_ORDERS, mockPublishEvent } from '../../demo/database';
2
+ /** Metadata for the demo's live cart, which has no order until it is paid or parked. */
3
+ let mockCartMetadata = [];
4
+ /** Set/remove keys; untouched items (and extra fields such as `externalId`) are kept as-is. */
5
+ export const mergeMetadata = (current, changes) => {
6
+ const byKey = new Map((current ?? []).map((m) => [m.key, m]));
7
+ for (const [key, value] of Object.entries(changes)) {
8
+ if (value === null)
9
+ byKey.delete(key);
10
+ else
11
+ byKey.set(key, { ...byKey.get(key), key, value });
12
+ }
13
+ return [...byKey.values()];
14
+ };
15
+ export const mockSetOrderMetadata = async (params) => {
16
+ console.log('[Mock] setOrderMetadata called', params);
17
+ if (!params?.metadata || Object.keys(params.metadata).length === 0) {
18
+ throw new Error('setOrderMetadata: metadata must set or remove at least one key');
19
+ }
20
+ for (const [key, value] of Object.entries(params.metadata)) {
21
+ if (!key.trim())
22
+ throw new Error('setOrderMetadata: metadata keys must be non-empty');
23
+ if (value !== null && typeof value !== 'string') {
24
+ throw new Error(`setOrderMetadata: value for "${key}" must be a string or null`);
25
+ }
26
+ }
27
+ if (!params.orderId) {
28
+ mockCartMetadata = mergeMetadata(mockCartMetadata, params.metadata);
29
+ return { success: true, orderId: null, metadata: mockCartMetadata, timestamp: new Date().toISOString() };
30
+ }
31
+ const order = [...MOCK_ORDERS, ...MOCK_PARKED_ORDERS].find((o) => o._id === params.orderId);
32
+ if (!order) {
33
+ throw new Error(`Order with ID ${params.orderId} not found`);
34
+ }
35
+ order.metadata = mergeMetadata(order.metadata, params.metadata);
36
+ mockPublishEvent('orders', 'order-updated', { order });
37
+ return { success: true, orderId: order._id, metadata: order.metadata, timestamp: new Date().toISOString() };
38
+ };
@@ -0,0 +1,20 @@
1
+ import type { CFMetadataItem } from '../../CommonTypes';
2
+ export interface SetOrderMetadataParams {
3
+ /**
4
+ * Order to update. Omit to target the live cart's order — including a cart
5
+ * that hasn't become an order yet (the metadata is carried onto the order
6
+ * when it is created).
7
+ */
8
+ orderId?: string;
9
+ /** Keys to set (string) or remove (null). Keys not listed are left as they are. */
10
+ metadata: Record<string, string | null>;
11
+ }
12
+ export interface SetOrderMetadataResponse {
13
+ success: boolean;
14
+ /** The order that was updated, or null when the live cart has no order yet. */
15
+ orderId: string | null;
16
+ /** The full metadata after the update. */
17
+ metadata: CFMetadataItem[];
18
+ timestamp: string;
19
+ }
20
+ export type SetOrderMetadata = (params: SetOrderMetadataParams) => Promise<SetOrderMetadataResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Set order status action
3
+ * Calls the setOrderStatus action on the parent window
4
+ */
5
+ import type { SetOrderStatus } from './types';
6
+ export declare const setOrderStatus: SetOrderStatus;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Set order status action
3
+ * Calls the setOrderStatus action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const setOrderStatus = async (params) => {
7
+ return await commandFrameClient.call('setOrderStatus', params);
8
+ };
@@ -0,0 +1,3 @@
1
+ import type { SetOrderStatus } from './types';
2
+ /** Best-effort mock: no state-machine guards beyond the status's payment requirement. */
3
+ export declare const mockSetOrderStatus: SetOrderStatus;
@@ -0,0 +1,39 @@
1
+ import { MOCK_ORDERS, MOCK_ORDER_STATUSES, MOCK_PARKED_ORDERS, mockPublishEvent } from '../../demo/database';
2
+ /** Best-effort mock: no state-machine guards beyond the status's payment requirement. */
3
+ export const mockSetOrderStatus = async (params) => {
4
+ console.log('[Mock] setOrderStatus called', params);
5
+ if (!params?.orderId) {
6
+ throw new Error('setOrderStatus: the demo has no live-cart order — pass an orderId');
7
+ }
8
+ const order = [...MOCK_ORDERS, ...MOCK_PARKED_ORDERS].find((o) => o._id === params.orderId);
9
+ if (!order) {
10
+ throw new Error(`Order with ID ${params.orderId} not found`);
11
+ }
12
+ const from = { payment: order.paymentState ?? 'unpaid', fulfillment: order.fulfillmentState ?? 'draft' };
13
+ if (params.statusId === null) {
14
+ order.customStatus = null;
15
+ }
16
+ else {
17
+ const def = MOCK_ORDER_STATUSES.find((s) => s.id === params.statusId);
18
+ if (!def) {
19
+ throw new Error(`setOrderStatus: unknown status "${params.statusId}"`);
20
+ }
21
+ if (def.requiresPaymentState && !def.requiresPaymentState.includes(from.payment)) {
22
+ throw new Error(`setOrderStatus: "${def.label}" requires payment state ${def.requiresPaymentState.join(' or ')} (order is ${from.payment})`);
23
+ }
24
+ if (def.fulfillmentState)
25
+ order.fulfillmentState = def.fulfillmentState;
26
+ order.customStatus = { id: def.id, label: def.label, setAt: new Date().toISOString(), setBy: null };
27
+ }
28
+ mockPublishEvent('orders', 'order-updated', { order });
29
+ const to = { payment: order.paymentState ?? 'unpaid', fulfillment: order.fulfillmentState ?? 'draft' };
30
+ return {
31
+ success: true,
32
+ orderId: order._id,
33
+ customStatus: order.customStatus ?? null,
34
+ from,
35
+ to,
36
+ order,
37
+ timestamp: new Date().toISOString(),
38
+ };
39
+ };
@@ -0,0 +1,20 @@
1
+ import type { CFOrder, CFOrderCustomStatus } from '../../CommonTypes';
2
+ import type { CFStatePair } from '../../common-types/order-state';
3
+ export interface SetOrderStatusParams {
4
+ /** Order to set the status on. Omit for the live cart's order. */
5
+ orderId?: string;
6
+ /** Id of one of the company's statuses (see getOrderStatuses), or null to clear the status. */
7
+ statusId: string | null;
8
+ }
9
+ export interface SetOrderStatusResponse {
10
+ success: boolean;
11
+ orderId: string;
12
+ /** The order's status after the call; null when cleared. */
13
+ customStatus: CFOrderCustomStatus | null;
14
+ /** State before and after — they differ only when the status is bound to a fulfillment state the order wasn't in. */
15
+ from: CFStatePair | null;
16
+ to: CFStatePair | null;
17
+ order: CFOrder;
18
+ timestamp: string;
19
+ }
20
+ export type SetOrderStatus = (params: SetOrderStatusParams) => Promise<SetOrderStatusResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Set order type action
3
+ * Calls the setOrderType action on the parent window
4
+ */
5
+ import type { SetOrderType } from './types';
6
+ export declare const setOrderType: SetOrderType;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Set order type action
3
+ * Calls the setOrderType action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const setOrderType = async (params) => {
7
+ return await commandFrameClient.call('setOrderType', params);
8
+ };
@@ -0,0 +1,3 @@
1
+ import type { SetOrderType } from './types';
2
+ export declare const normalizeOrderType: (value: unknown) => string | null;
3
+ export declare const mockSetOrderType: SetOrderType;
@@ -0,0 +1,27 @@
1
+ import { MOCK_ORDERS, MOCK_PARKED_ORDERS, mockPublishEvent } from '../../demo/database';
2
+ /** Type for the demo's live cart, which has no order until it is paid or parked. */
3
+ let mockCartOrderType = null;
4
+ export const normalizeOrderType = (value) => {
5
+ if (value === null)
6
+ return null;
7
+ if (typeof value !== 'string' || !value.trim()) {
8
+ throw new Error('setOrderType: orderType must be a non-empty string or null');
9
+ }
10
+ return value.trim();
11
+ };
12
+ export const mockSetOrderType = async (params) => {
13
+ console.log('[Mock] setOrderType called', params);
14
+ const orderType = normalizeOrderType(params?.orderType);
15
+ const timestamp = new Date().toISOString();
16
+ if (!params.orderId) {
17
+ mockCartOrderType = orderType;
18
+ return { success: true, orderId: null, orderType: mockCartOrderType, timestamp };
19
+ }
20
+ const order = [...MOCK_ORDERS, ...MOCK_PARKED_ORDERS].find((o) => o._id === params.orderId);
21
+ if (!order) {
22
+ throw new Error(`Order with ID ${params.orderId} not found`);
23
+ }
24
+ order.orderType = orderType;
25
+ mockPublishEvent('orders', 'order-updated', { order });
26
+ return { success: true, orderId: order._id, orderType, timestamp };
27
+ };
@@ -0,0 +1,17 @@
1
+ export interface SetOrderTypeParams {
2
+ /**
3
+ * Order to label. Omit to target the live cart — including a cart that isn't an
4
+ * order yet; the type is carried onto the order when it's created.
5
+ */
6
+ orderId?: string;
7
+ /** Any non-empty label (e.g. 'takeout', 'pickup', 'delivery'), or null to clear it. */
8
+ orderType: string | null;
9
+ }
10
+ export interface SetOrderTypeResponse {
11
+ success: boolean;
12
+ /** The order that was updated, or null when the live cart has no order yet. */
13
+ orderId: string | null;
14
+ orderType: string | null;
15
+ timestamp: string;
16
+ }
17
+ export type SetOrderType = (params: SetOrderTypeParams) => Promise<SetOrderTypeResponse>;
@@ -0,0 +1 @@
1
+ export {};
@@ -7,7 +7,7 @@ export interface CFStatePair {
7
7
  payment: string;
8
8
  fulfillment: string;
9
9
  }
10
- export type CFBlockedBy = "financial_invariant" | "cross_axis_rule" | "path" | "condition";
10
+ export type CFBlockedBy = 'financial_invariant' | 'cross_axis_rule' | 'path' | 'condition';
11
11
  export interface CFTransitionResult {
12
12
  allowed: boolean;
13
13
  blockedBy?: CFBlockedBy;
@@ -30,3 +30,17 @@ export interface CFAvailableTransition {
30
30
  displayLabel: string;
31
31
  conditions: CFConditionStatus[];
32
32
  }
33
+ /**
34
+ * A merchant-defined order status (per company). Mirrors common's OrderStatusDefinition.
35
+ * `fulfillmentState`: setting the status moves the order there (normal state-machine
36
+ * rules). `requiresPaymentState`: setting it fails unless the order's payment state is
37
+ * one of these — a status never moves money. Neither set = a label-only status.
38
+ */
39
+ export interface CFOrderStatusDefinition {
40
+ id: string;
41
+ label: string;
42
+ color?: string;
43
+ icon?: string;
44
+ fulfillmentState?: string;
45
+ requiresPaymentState?: string[];
46
+ }
@@ -2,6 +2,7 @@
2
2
  * Mock Database for Standalone/Demo Mode
3
3
  * Stores mock data that mimics the Render environment
4
4
  */
5
+ import type { CFOrderStatusDefinition } from '../common-types/order-state';
5
6
  import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout, CFBooking, CFBookingAvailability, CFBookingResource, CFCartLineModifier, CFProdModifierBreakdown, CFModifierSelection, CFResolvedModifier } from '../CommonTypes';
6
7
  export * from './mocks';
7
8
  /** Replace mock catalog / context data in place (same array references mock handlers use). */
@@ -19,6 +20,7 @@ export interface MockDatabaseConfig {
19
20
  bookingResources?: CFBookingResource[];
20
21
  /** Windows already taken when the dataset loads, so a calendar does not open empty. */
21
22
  bookings?: CFBooking[];
23
+ orderStatuses?: CFOrderStatusDefinition[];
22
24
  }
23
25
  export declare const MOCK_COMPANY: CFActiveCompany;
24
26
  export declare const MOCK_OUTLET_MAIN: CFActiveOutlet;
@@ -75,6 +77,8 @@ export declare let MOCK_ACTIVE_PRODUCT: CFActiveProduct;
75
77
  export declare const setMockActiveProduct: (activeProduct: CFActiveProduct) => void;
76
78
  export declare const MOCK_SMART_GRID_LAYOUTS: Record<string, CFSmartGridLayout>;
77
79
  export declare const resetMockCart: () => void;
80
+ /** The demo company's order statuses (getOrderStatuses / setOrderStatus). */
81
+ export declare const MOCK_ORDER_STATUSES: CFOrderStatusDefinition[];
78
82
  /**
79
83
  * Replace in-memory mock data used by default mock handlers. Arrays are mutated in place
80
84
  * so existing imports from this module keep working.
@@ -722,11 +722,22 @@ function resolveMockOrderCurrency() {
722
722
  }
723
723
  return CurrencyCode.USD;
724
724
  }
725
+ /** The demo company's order statuses (getOrderStatuses / setOrderStatus). */
726
+ export const MOCK_ORDER_STATUSES = [
727
+ { id: 'in-kitchen', label: 'In kitchen', color: '#f59e0b', fulfillmentState: 'pending' },
728
+ { id: 'ready-for-pickup', label: 'Ready for pickup', color: '#10b981', fulfillmentState: 'in_progress' },
729
+ { id: 'out-for-delivery', label: 'Out for delivery', color: '#3b82f6', fulfillmentState: 'partially_fulfilled' },
730
+ { id: 'delivered', label: 'Delivered', fulfillmentState: 'fulfilled', requiresPaymentState: ['paid'] },
731
+ { id: 'driver-called', label: 'Driver called' },
732
+ ];
725
733
  /**
726
734
  * Replace in-memory mock data used by default mock handlers. Arrays are mutated in place
727
735
  * so existing imports from this module keep working.
728
736
  */
729
737
  export function setMockDatabase(config) {
738
+ if (config.orderStatuses !== undefined) {
739
+ MOCK_ORDER_STATUSES.splice(0, MOCK_ORDER_STATUSES.length, ...config.orderStatuses);
740
+ }
730
741
  if (config.company !== undefined) {
731
742
  Object.assign(MOCK_COMPANY, config.company);
732
743
  }
package/dist/index.d.ts CHANGED
@@ -42,9 +42,17 @@ export declare const command: {
42
42
  readonly clearCart: import(".").ClearCart;
43
43
  readonly parkOrder: import(".").ParkOrder;
44
44
  readonly resumeParkedOrder: import(".").ResumeParkedOrder;
45
+ readonly resumeOrder: import(".").ResumeOrder;
46
+ readonly setOrderMetadata: import(".").SetOrderMetadata;
47
+ readonly assignOrderUser: import(".").AssignOrderUser;
48
+ readonly releaseFromCart: import(".").ReleaseFromCart;
49
+ readonly setOrderType: import(".").SetOrderType;
50
+ readonly setOrderStatus: import(".").SetOrderStatus;
51
+ readonly getOrderStatuses: import(".").GetOrderStatuses;
45
52
  readonly deleteParkedOrder: import(".").DeleteParkedOrder;
46
53
  readonly voidOrder: import(".").VoidOrder;
47
54
  readonly cashPayment: import(".").CashPayment;
55
+ readonly recordExternalPayment: import(".").RecordExternalPayment;
48
56
  readonly getCashRoundingAmount: import(".").GetCashRoundingAmount;
49
57
  readonly tapToPayPayment: import(".").TapToPayPayment;
50
58
  readonly terminalPayment: import(".").TerminalPayment;
@@ -187,9 +195,17 @@ export type { AddCartFee, AddCartFeeParams, AddCartFeeResponse } from './actions
187
195
  export type { ClearCart, ClearCartResponse } from './actions/clear-cart/types';
188
196
  export type { ParkOrder, ParkOrderResponse } from './actions/park-order/types';
189
197
  export type { ResumeParkedOrder, ResumeParkedOrderParams, ResumeParkedOrderResponse, } from './actions/resume-parked-order/types';
198
+ export type { ResumeOrder, ResumeOrderParams, ResumeOrderResponse } from './actions/resume-order/types';
199
+ export type { SetOrderMetadata, SetOrderMetadataParams, SetOrderMetadataResponse, } from './actions/set-order-metadata/types';
200
+ export type { AssignOrderUser, AssignOrderUserParams, AssignOrderUserResponse, } from './actions/assign-order-user/types';
201
+ export type { ReleaseFromCart, ReleaseFromCartResponse } from './actions/release-from-cart/types';
202
+ export type { SetOrderType, SetOrderTypeParams, SetOrderTypeResponse } from './actions/set-order-type/types';
203
+ export type { SetOrderStatus, SetOrderStatusParams, SetOrderStatusResponse } from './actions/set-order-status/types';
204
+ export type { GetOrderStatuses, GetOrderStatusesResponse } from './actions/get-order-statuses/types';
190
205
  export type { DeleteParkedOrder, DeleteParkedOrderParams, DeleteParkedOrderResponse, } from './actions/delete-parked-order/types';
191
206
  export type { VoidOrder, VoidOrderParams, VoidOrderResponse, VoidOrderOutcome } from './actions/void-order/types';
192
207
  export type { CashPayment, CashPaymentParams, CashPaymentResponse } from './actions/cash-payment/types';
208
+ export type { RecordExternalPayment, RecordExternalPaymentParams, RecordExternalPaymentResponse, } from './actions/record-external-payment/types';
193
209
  export type { GetCashRoundingAmount, GetCashRoundingAmountParams, GetCashRoundingAmountResponse, } from './actions/get-cash-rounding-amount/types';
194
210
  export type { TapToPayPayment, TapToPayPaymentParams, TapToPayPaymentResponse, } from './actions/tap-to-pay-payment/types';
195
211
  export type { TerminalPayment, TerminalPaymentParams, TerminalPaymentResponse } from './actions/terminal-payment/types';
package/dist/index.js CHANGED
@@ -42,9 +42,17 @@ import { getCurrentCart } from './actions/get-current-cart/action';
42
42
  import { clearCart } from './actions/clear-cart/action';
43
43
  import { parkOrder } from './actions/park-order/action';
44
44
  import { resumeParkedOrder } from './actions/resume-parked-order/action';
45
+ import { resumeOrder } from './actions/resume-order/action';
46
+ import { setOrderMetadata } from './actions/set-order-metadata/action';
47
+ import { assignOrderUser } from './actions/assign-order-user/action';
48
+ import { releaseFromCart } from './actions/release-from-cart/action';
49
+ import { setOrderType } from './actions/set-order-type/action';
50
+ import { setOrderStatus } from './actions/set-order-status/action';
51
+ import { getOrderStatuses } from './actions/get-order-statuses/action';
45
52
  import { deleteParkedOrder } from './actions/delete-parked-order/action';
46
53
  import { voidOrder } from './actions/void-order/action';
47
54
  import { cashPayment } from './actions/cash-payment/action';
55
+ import { recordExternalPayment } from './actions/record-external-payment/action';
48
56
  import { getCashRoundingAmount } from './actions/get-cash-rounding-amount/action';
49
57
  import { tapToPayPayment } from './actions/tap-to-pay-payment/action';
50
58
  import { terminalPayment } from './actions/terminal-payment/action';
@@ -189,9 +197,17 @@ export const command = {
189
197
  clearCart,
190
198
  parkOrder,
191
199
  resumeParkedOrder,
200
+ resumeOrder,
201
+ setOrderMetadata,
202
+ assignOrderUser,
203
+ releaseFromCart,
204
+ setOrderType,
205
+ setOrderStatus,
206
+ getOrderStatuses,
192
207
  deleteParkedOrder,
193
208
  voidOrder,
194
209
  cashPayment,
210
+ recordExternalPayment,
195
211
  getCashRoundingAmount,
196
212
  tapToPayPayment,
197
213
  terminalPayment,
@@ -31,6 +31,7 @@ import { mockAssignCustomer } from '../../actions/assign-customer/mock';
31
31
  import { mockAuthenticateUser } from '../../actions/authenticate-user/mock';
32
32
  import { mockCalculateRefundTotal } from '../../actions/calculate-refund-total/mock';
33
33
  import { mockCashPayment } from '../../actions/cash-payment/mock';
34
+ import { mockRecordExternalPayment } from '../../actions/record-external-payment/mock';
34
35
  import { mockGetCashRoundingAmount } from '../../actions/get-cash-rounding-amount/mock';
35
36
  import { mockCreatePaymentLink } from '../../actions/create-payment-link/mock';
36
37
  import { mockChargeMoto } from '../../actions/charge-moto/mock';
@@ -67,6 +68,13 @@ import { mockCheckPermission } from '../../actions/check-permission/mock';
67
68
  import { mockRemoveCustomerFromCart } from '../../actions/remove-customer-from-cart/mock';
68
69
  import { mockResetRefundDetails } from '../../actions/reset-refund-details/mock';
69
70
  import { mockResumeParkedOrder } from '../../actions/resume-parked-order/mock';
71
+ import { mockResumeOrder } from '../../actions/resume-order/mock';
72
+ import { mockSetOrderMetadata } from '../../actions/set-order-metadata/mock';
73
+ import { mockAssignOrderUser } from '../../actions/assign-order-user/mock';
74
+ import { mockReleaseFromCart } from '../../actions/release-from-cart/mock';
75
+ import { mockSetOrderType } from '../../actions/set-order-type/mock';
76
+ import { mockSetOrderStatus } from '../../actions/set-order-status/mock';
77
+ import { mockGetOrderStatuses } from '../../actions/get-order-statuses/mock';
70
78
  import { mockSelectAllRefundItems } from '../../actions/select-all-refund-items/mock';
71
79
  import { mockSetRefundStockAction } from '../../actions/set-refund-stock-action/mock';
72
80
  import { mockShowConfirmation } from '../../actions/show-confirmation/mock';
@@ -138,6 +146,7 @@ export const RENDER_MOCKS = {
138
146
  authenticateUser: mockAuthenticateUser,
139
147
  calculateRefundTotal: mockCalculateRefundTotal,
140
148
  cashPayment: mockCashPayment,
149
+ recordExternalPayment: mockRecordExternalPayment,
141
150
  getCashRoundingAmount: mockGetCashRoundingAmount,
142
151
  createPaymentLink: mockCreatePaymentLink,
143
152
  chargeMoto: mockChargeMoto,
@@ -174,6 +183,13 @@ export const RENDER_MOCKS = {
174
183
  removeCartDiscount: mockRemoveCartDiscount,
175
184
  resetRefundDetails: mockResetRefundDetails,
176
185
  resumeParkedOrder: mockResumeParkedOrder,
186
+ resumeOrder: mockResumeOrder,
187
+ setOrderMetadata: mockSetOrderMetadata,
188
+ assignOrderUser: mockAssignOrderUser,
189
+ releaseFromCart: mockReleaseFromCart,
190
+ setOrderType: mockSetOrderType,
191
+ setOrderStatus: mockSetOrderStatus,
192
+ getOrderStatuses: mockGetOrderStatuses,
177
193
  selectAllRefundItems: mockSelectAllRefundItems,
178
194
  setRefundStockAction: mockSetRefundStockAction,
179
195
  showConfirmation: mockShowConfirmation,
@@ -1,4 +1,4 @@
1
- import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, GetCustomStockActions, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetProductModifierSelections, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, 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, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, GetBookingResources, GetBookingAvailability, GetBookings, HoldBooking, AddBookingToCart, RemoveBookingFromCart, CancelBooking, CreatePaymentLink, ChargeMoto, GetTimeClockStatus } from '../../index';
1
+ import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, GetCustomStockActions, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetProductModifierSelections, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, ResumeOrder, SetOrderMetadata, AssignOrderUser, ReleaseFromCart, SetOrderType, SetOrderStatus, GetOrderStatuses, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, RecordExternalPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, 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, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, GetBookingResources, GetBookingAvailability, GetBookings, HoldBooking, AddBookingToCart, RemoveBookingFromCart, CancelBooking, CreatePaymentLink, ChargeMoto, GetTimeClockStatus } from '../../index';
2
2
  export interface RenderProviderActions {
3
3
  exampleFunction: ExampleFunction;
4
4
  getProducts: GetProducts;
@@ -41,10 +41,18 @@ export interface RenderProviderActions {
41
41
  clearCart: ClearCart;
42
42
  parkOrder: ParkOrder;
43
43
  resumeParkedOrder: ResumeParkedOrder;
44
+ resumeOrder: ResumeOrder;
45
+ setOrderMetadata: SetOrderMetadata;
46
+ assignOrderUser: AssignOrderUser;
47
+ releaseFromCart: ReleaseFromCart;
48
+ setOrderType: SetOrderType;
49
+ setOrderStatus: SetOrderStatus;
50
+ getOrderStatuses: GetOrderStatuses;
44
51
  deleteParkedOrder: DeleteParkedOrder;
45
52
  voidOrder: VoidOrder;
46
53
  initiateRefund: InitiateRefund;
47
54
  cashPayment: CashPayment;
55
+ recordExternalPayment: RecordExternalPayment;
48
56
  getCashRoundingAmount: GetCashRoundingAmount;
49
57
  tapToPayPayment: TapToPayPayment;
50
58
  terminalPayment: TerminalPayment;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.9.0-preprod.1",
3
+ "version": "0.9.0-preprod.2",
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.5.0-preprod.1"
60
+ "@final-commerce/common": "2.5.1-preprod.3"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",