@final-commerce/command-frame 0.11.0 → 0.12.0-staging.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.
Files changed (80) hide show
  1. package/dist/CommonTypes.d.ts +1 -4
  2. package/dist/actions/get-current-cart/mock.js +0 -3
  3. package/dist/actions/get-current-cart/types.d.ts +0 -6
  4. package/dist/actions/get-orders/action.d.ts +1 -1
  5. package/dist/actions/get-orders/action.js +2 -2
  6. package/dist/actions/get-orders/mock.d.ts +1 -1
  7. package/dist/actions/get-orders/mock.js +19 -74
  8. package/dist/actions/get-orders/types.d.ts +2 -33
  9. package/dist/actions/resume-parked-order/mock.d.ts +0 -5
  10. package/dist/actions/resume-parked-order/mock.js +24 -25
  11. package/dist/actions/void-order/mock.js +7 -17
  12. package/dist/actions/void-order/types.d.ts +2 -6
  13. package/dist/common-types/order-state.d.ts +1 -20
  14. package/dist/demo/database.d.ts +0 -4
  15. package/dist/demo/database.js +0 -29
  16. package/dist/index.d.ts +0 -20
  17. package/dist/index.js +0 -20
  18. package/dist/projects/render/mocks.js +0 -20
  19. package/dist/projects/render/types.d.ts +1 -11
  20. package/package.json +2 -2
  21. package/dist/actions/assign-order-user/action.d.ts +0 -6
  22. package/dist/actions/assign-order-user/action.js +0 -8
  23. package/dist/actions/assign-order-user/mock.d.ts +0 -2
  24. package/dist/actions/assign-order-user/mock.js +0 -30
  25. package/dist/actions/assign-order-user/types.d.ts +0 -15
  26. package/dist/actions/assign-order-user/types.js +0 -1
  27. package/dist/actions/get-moto-config/action.d.ts +0 -6
  28. package/dist/actions/get-moto-config/action.js +0 -8
  29. package/dist/actions/get-moto-config/mock.d.ts +0 -7
  30. package/dist/actions/get-moto-config/mock.js +0 -9
  31. package/dist/actions/get-moto-config/types.d.ts +0 -34
  32. package/dist/actions/get-moto-config/types.js +0 -5
  33. package/dist/actions/get-order-statuses/action.d.ts +0 -6
  34. package/dist/actions/get-order-statuses/action.js +0 -8
  35. package/dist/actions/get-order-statuses/mock.d.ts +0 -2
  36. package/dist/actions/get-order-statuses/mock.js +0 -5
  37. package/dist/actions/get-order-statuses/types.d.ts +0 -8
  38. package/dist/actions/get-order-statuses/types.js +0 -1
  39. package/dist/actions/record-external-payment/action.d.ts +0 -6
  40. package/dist/actions/record-external-payment/action.js +0 -8
  41. package/dist/actions/record-external-payment/mock.d.ts +0 -2
  42. package/dist/actions/record-external-payment/mock.js +0 -36
  43. package/dist/actions/record-external-payment/types.d.ts +0 -37
  44. package/dist/actions/record-external-payment/types.js +0 -1
  45. package/dist/actions/release-from-cart/action.d.ts +0 -6
  46. package/dist/actions/release-from-cart/action.js +0 -8
  47. package/dist/actions/release-from-cart/mock.d.ts +0 -2
  48. package/dist/actions/release-from-cart/mock.js +0 -26
  49. package/dist/actions/release-from-cart/types.d.ts +0 -8
  50. package/dist/actions/release-from-cart/types.js +0 -1
  51. package/dist/actions/resume-order/action.d.ts +0 -6
  52. package/dist/actions/resume-order/action.js +0 -8
  53. package/dist/actions/resume-order/mock.d.ts +0 -2
  54. package/dist/actions/resume-order/mock.js +0 -55
  55. package/dist/actions/resume-order/types.d.ts +0 -17
  56. package/dist/actions/resume-order/types.js +0 -1
  57. package/dist/actions/set-order-metadata/action.d.ts +0 -6
  58. package/dist/actions/set-order-metadata/action.js +0 -8
  59. package/dist/actions/set-order-metadata/mock.d.ts +0 -5
  60. package/dist/actions/set-order-metadata/mock.js +0 -38
  61. package/dist/actions/set-order-metadata/types.d.ts +0 -20
  62. package/dist/actions/set-order-metadata/types.js +0 -1
  63. package/dist/actions/set-order-status/action.d.ts +0 -6
  64. package/dist/actions/set-order-status/action.js +0 -8
  65. package/dist/actions/set-order-status/mock.d.ts +0 -3
  66. package/dist/actions/set-order-status/mock.js +0 -44
  67. package/dist/actions/set-order-status/types.d.ts +0 -25
  68. package/dist/actions/set-order-status/types.js +0 -1
  69. package/dist/actions/set-order-type/action.d.ts +0 -6
  70. package/dist/actions/set-order-type/action.js +0 -8
  71. package/dist/actions/set-order-type/mock.d.ts +0 -3
  72. package/dist/actions/set-order-type/mock.js +0 -27
  73. package/dist/actions/set-order-type/types.d.ts +0 -17
  74. package/dist/actions/set-order-type/types.js +0 -1
  75. package/dist/actions/set-scheduled-for/action.d.ts +0 -6
  76. package/dist/actions/set-scheduled-for/action.js +0 -8
  77. package/dist/actions/set-scheduled-for/mock.d.ts +0 -4
  78. package/dist/actions/set-scheduled-for/mock.js +0 -45
  79. package/dist/actions/set-scheduled-for/types.d.ts +0 -22
  80. package/dist/actions/set-scheduled-for/types.js +0 -1
@@ -1,5 +1,5 @@
1
1
  export * from './common-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, Composite, CompositePart, CompositeItem, CompositeChoice, CompositeItemUnavailable, CompositePick, CartLineComponent, OrderLineItemComponent } from '@final-commerce/common/pos-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, Composite, CompositePart, CompositeItem, CompositeChoice, CompositeItemUnavailable, CompositePick, CartLineComponent, OrderLineItemComponent } 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,9 +7,6 @@ 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;
13
10
  export type CFTax = Tax;
14
11
  export type CFCartFeeTaxEntry = CartFeeTaxEntry;
15
12
  export type CFInventory = Inventory;
@@ -13,9 +13,6 @@ export const mockGetCurrentCart = async () => {
13
13
  return {
14
14
  success: true,
15
15
  cart: safeSerialize(MOCK_CART),
16
- // Every mock tender settles the whole sale and clears the cart, so the demo cart
17
- // never holds an order with money on it — nothing to lock.
18
- itemsLocked: false,
19
16
  lineTotals,
20
17
  timestamp: new Date().toISOString(),
21
18
  };
@@ -2,12 +2,6 @@ import { CFActiveCart } from '../../CommonTypes';
2
2
  export interface GetCurrentCartResponse {
3
3
  success: boolean;
4
4
  cart: CFActiveCart;
5
- /**
6
- * `true` while the order in this cart has any payment on it (a split leg, a part payment,
7
- * or paid in full): its items, amounts and customer can no longer be changed — the
8
- * value-changing cart commands and clearCart refuse. Absent on hosts that predate the lock.
9
- */
10
- itemsLocked?: boolean;
11
5
  /**
12
6
  * What each line adds to the cart, minor units, keyed by the line's `internalId` (products, bookings) or `id`
13
7
  * (custom sales): price × quantity − its own discounts + its own fees + its modifiers. Before the cart discount
@@ -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,80 +1,26 @@
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, paymentState, fulfillmentState, outletId, assignedUserId, inCart, orderType, customStatusId, customStatusKey, scheduled, scheduledFrom, scheduledTo, searchValue, limit, offset, sortBy, sortDirection, } = params;
8
+ const { customerId, status, sessionId, searchValue, limit, offset, sortBy, sortDirection } = params;
9
9
  // 1. Filtering
10
10
  if (customerId) {
11
- orders = orders.filter((o) => o.customer && '_id' in o.customer && o.customer._id === customerId);
11
+ orders = orders.filter(o => o.customer &&
12
+ '_id' in o.customer &&
13
+ o.customer._id === customerId);
12
14
  }
13
15
  if (status) {
14
- orders = orders.filter((o) => o.status === status);
16
+ orders = orders.filter(o => o.status === status);
15
17
  }
16
18
  if (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 (customStatusKey !== undefined) {
42
- const keys = Array.isArray(customStatusKey) ? customStatusKey : [customStatusKey];
43
- if (keys.length)
44
- orders = orders.filter((o) => !!o.customStatus?.key && keys.includes(o.customStatus.key));
45
- }
46
- if (customStatusId !== undefined) {
47
- const ids = Array.isArray(customStatusId) ? customStatusId : [customStatusId];
48
- if (ids.length) {
49
- orders = orders.filter((o) => !!o.customStatus &&
50
- (ids.includes(o.customStatus.id) || (!!o.customStatus.key && ids.includes(o.customStatus.key))));
51
- }
52
- }
53
- // Requested time (setScheduledFor). ISO strings in UTC compare correctly as strings.
54
- const scheduledOf = (o) => o.scheduledFor ?? null;
55
- if (typeof scheduled === 'boolean') {
56
- orders = orders.filter((o) => (scheduledOf(o) !== null) === scheduled);
57
- }
58
- if (scheduledFrom) {
59
- const from = new Date(scheduledFrom).toISOString();
60
- orders = orders.filter((o) => (scheduledOf(o) ?? '') !== '' && scheduledOf(o) >= from);
61
- }
62
- if (scheduledTo) {
63
- const to = new Date(scheduledTo).toISOString();
64
- orders = orders.filter((o) => (scheduledOf(o) ?? '') !== '' && scheduledOf(o) <= to);
65
- }
66
- if (typeof inCart === 'boolean') {
67
- // Mirrors common's isInCart: the flag when present, else the legacy reading.
68
- const orderInCart = (o) => o.inCart != null
69
- ? o.inCart.active
70
- : o.fulfillmentState
71
- ? o.fulfillmentState === 'draft'
72
- : o.status === 'in-cart';
73
- orders = orders.filter((o) => orderInCart(o) === inCart);
19
+ orders = orders.filter(o => o.sessionId === sessionId);
74
20
  }
75
21
  if (searchValue) {
76
22
  const searchLower = String(searchValue).toLowerCase();
77
- orders = orders.filter((o) => {
23
+ orders = orders.filter(o => {
78
24
  const receiptMatch = o.receiptId?.toLowerCase().includes(searchLower);
79
25
  const customerNameMatch = o.customer && 'firstName' in o.customer
80
26
  ? `${o.customer.firstName} ${o.customer.lastName}`.toLowerCase().includes(searchLower)
@@ -90,21 +36,20 @@ export const mockGetOrders = async (params) => {
90
36
  orders.sort((a, b) => {
91
37
  let valA = a[sortBy];
92
38
  let valB = b[sortBy];
93
- // Like the host: a missing time sorts as '' (first when ascending).
94
- if (sortBy === 'scheduledFor') {
95
- valA = valA ?? '';
96
- valB = valB ?? '';
97
- }
98
39
  // Handle nested sort fields if necessary, basic support for now
99
40
  if (!valA && sortBy === 'createdAt')
100
41
  valA = a.createdAt || '';
101
42
  if (!valB && sortBy === 'createdAt')
102
43
  valB = b.createdAt || '';
103
44
  if (typeof valA === 'string' && typeof valB === 'string') {
104
- return sortDirection === 'descending' ? valB.localeCompare(valA) : valA.localeCompare(valB);
45
+ return sortDirection === 'descending'
46
+ ? valB.localeCompare(valA)
47
+ : valA.localeCompare(valB);
105
48
  }
106
49
  // Number comparison
107
- return sortDirection === 'descending' ? (valB || 0) - (valA || 0) : (valA || 0) - (valB || 0);
50
+ return sortDirection === 'descending'
51
+ ? (valB || 0) - (valA || 0)
52
+ : (valA || 0) - (valB || 0);
108
53
  });
109
54
  }
110
55
  else {
@@ -128,21 +73,21 @@ export const mockGetOrders = async (params) => {
128
73
  if (enrichedOrder.posData) {
129
74
  // Enrich Employee
130
75
  if (typeof enrichedOrder.posData.employee === 'string') {
131
- const employee = MOCK_USERS.find((u) => u.id === enrichedOrder.posData.employee);
76
+ const employee = MOCK_USERS.find(u => u.id === enrichedOrder.posData.employee);
132
77
  if (employee) {
133
78
  enrichedOrder.posData.employee = employee;
134
79
  }
135
80
  }
136
81
  // Enrich Station
137
82
  if (typeof enrichedOrder.posData.station === 'string') {
138
- const station = MOCK_STATIONS.find((s) => s._id === enrichedOrder.posData.station);
83
+ const station = MOCK_STATIONS.find(s => s._id === enrichedOrder.posData.station);
139
84
  if (station) {
140
85
  enrichedOrder.posData.station = station;
141
86
  }
142
87
  }
143
88
  // Enrich Outlet
144
89
  if (typeof enrichedOrder.posData.outlet === 'string') {
145
- const outlet = MOCK_OUTLETS.find((o) => o.id === enrichedOrder.posData.outlet);
90
+ const outlet = MOCK_OUTLETS.find(o => o.id === enrichedOrder.posData.outlet);
146
91
  if (outlet) {
147
92
  enrichedOrder.posData.outlet = outlet;
148
93
  }
@@ -154,6 +99,6 @@ export const mockGetOrders = async (params) => {
154
99
  success: true,
155
100
  orders: enrichedOrders,
156
101
  total: MOCK_ORDERS.length, // Total before pagination
157
- timestamp: new Date().toISOString(),
102
+ timestamp: new Date().toISOString()
158
103
  };
159
104
  };
@@ -1,46 +1,15 @@
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 key(s) set with setOrderStatus, e.g. 'in-kitchen'. A list matches any of them. */
26
- customStatusKey?: string | string[];
27
- /**
28
- * Durable custom status id(s) (getOrderStatuses `id`). Also matches a status's key, for
29
- * flows written before keys — prefer `customStatusKey`. A list matches any of them.
30
- */
31
- customStatusId?: string | string[];
32
- /** true: only orders with a time (setScheduledFor); false: only "as soon as possible" orders (no time). */
33
- scheduled?: boolean;
34
- /** Only orders scheduled at or after this ISO 8601 date-time. Orders with no time never match. */
35
- scheduledFrom?: string;
36
- /** Only orders scheduled at or before this ISO 8601 date-time. Orders with no time never match. */
37
- scheduledTo?: string;
38
7
  /** Default: 50. */
39
8
  limit?: number;
40
9
  /** Default: 0. */
41
10
  offset?: number;
42
11
  searchValue?: string;
43
- /** Default: 'createdAt'. 'scheduledFor' sorts by the customer's requested time — orders with no time come first ascending. */
12
+ /** Default: 'createdAt'. */
44
13
  sortBy?: string;
45
14
  /** Default: 'descending'. */
46
15
  sortDirection?: 'ascending' | 'descending';
@@ -1,7 +1,2 @@
1
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;
7
2
  export declare const mockResumeParkedOrder: ResumeParkedOrder;
@@ -1,28 +1,4 @@
1
1
  import { MOCK_PARKED_ORDERS, MOCK_CART, MOCK_PRODUCTS, 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
- };
26
2
  export const mockResumeParkedOrder = async (params) => {
27
3
  console.log('[Mock] resumeParkedOrder called', params);
28
4
  const orderId = params?.orderId;
@@ -49,7 +25,30 @@ export const mockResumeParkedOrder = async (params) => {
49
25
  .map((li) => li.name);
50
26
  if (notSoldNames.length)
51
27
  throw new Error(`${notSoldNames.join(', ')} is not sold in POS`);
52
- restoreMockCartFromOrder(orderToResume);
28
+ // Restore to MOCK_CART
29
+ // Logic to convert Order back to Cart (simplified)
30
+ resetMockCart();
31
+ // Copy properties back
32
+ MOCK_CART.customer = orderToResume.customer; // Cast if needed
33
+ // MOCK_CART.products = orderToResume.lineItems... (Mapping needed)
34
+ // For Mock demo, we'll do a best effort mapping
35
+ MOCK_CART.products = orderToResume.lineItems.map((li) => ({
36
+ id: li.productId,
37
+ name: li.name,
38
+ quantity: li.quantity,
39
+ price: li.price,
40
+ internalId: li.internalId || li.productId,
41
+ variantId: li.variantId,
42
+ sku: li.sku,
43
+ images: [li.image],
44
+ stock: 100,
45
+ taxTableId: '',
46
+ attributes: li.attributes,
47
+ }));
48
+ MOCK_CART.subtotal = orderToResume.summary.subtotalAfterFees;
49
+ MOCK_CART.total = orderToResume.summary.total;
50
+ MOCK_CART.amountToBeCharged = MOCK_CART.total;
51
+ MOCK_CART.remainingBalance = MOCK_CART.total;
53
52
  // Remove from parked
54
53
  MOCK_PARKED_ORDERS.splice(index, 1);
55
54
  // Refresh the restored cart and the order lists.
@@ -1,27 +1,17 @@
1
1
  import { MOCK_ORDERS, mockPublishEvent } from '../../demo/database';
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.
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.
6
5
  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');
16
6
  export const mockVoidOrder = async (params) => {
17
7
  console.log('[Mock] voidOrder called', params);
18
- const order = params?.orderId ? MOCK_ORDERS.find((o) => o._id === params.orderId) : MOCK_ORDERS.find(isCartOrder);
8
+ const order = params?.orderId ? MOCK_ORDERS.find((o) => o._id === params.orderId) : MOCK_ORDERS[0];
19
9
  if (!order) {
20
- throw new Error(params?.orderId ? `Order with ID ${params.orderId} not found` : 'No order selected. Please provide orderId.');
10
+ throw new Error(`Order with ID ${params?.orderId} not found`);
21
11
  }
22
12
  const orderId = order._id;
23
- const paidUnfulfilled = order.paymentState === 'paid' && UNFULFILLED_STATES.includes(order.fulfillmentState);
24
- if (!OPEN_PAYMENT_STATES.includes(order.paymentState) && !paidUnfulfilled) {
13
+ // Only OPEN orders are voidable — mirror the runtime gate.
14
+ if (!OPEN_PAYMENT_STATES.includes(order.paymentState)) {
25
15
  throw new Error(`ORDER_NOT_VOIDABLE: order ${orderId} is '${order.paymentState}' — use the refund flow for completed orders`);
26
16
  }
27
17
  const hasCapturedLegs = (order.paymentMethods?.length ?? 0) > 0;
@@ -1,9 +1,6 @@
1
1
  export type VoidOrderOutcome = 'voided' | 'refunded';
2
2
  export interface VoidOrderParams {
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
- */
3
+ /** Order to void; defaults to the active order. */
7
4
  orderId?: string;
8
5
  /**
9
6
  * Optional cashier-facing reason. Recorded on both branches — the void audit
@@ -18,8 +15,7 @@ export interface VoidOrderResponse {
18
15
  orderId: string;
19
16
  /**
20
17
  * `voided` — nothing was captured; pure state transition to voided × cancelled.
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;
18
+ * `refunded` — captured split legs were refunded to their original tenders;
23
19
  * order lands refunded × cancelled (financially equivalent to a
24
20
  * void, but the capture + payout stay on the audit trail).
25
21
  */
@@ -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,22 +30,3 @@ export interface CFAvailableTransition {
30
30
  displayLabel: string;
31
31
  conditions: CFConditionStatus[];
32
32
  }
33
- /**
34
- * An order status the running flow defines (authored in the flow builder, shipped with
35
- * each deployed version). `fulfillmentState`: setting the status moves the order there
36
- * (normal state-machine rules). `requiresPaymentState`: setting it fails unless the
37
- * order's payment state is one of these — a status never moves money. Neither set = a
38
- * label-only status.
39
- */
40
- export interface CFOrderStatusDefinition {
41
- /** Durable id; survives a renamed key or label. */
42
- id: string;
43
- /** What flow code passes to setOrderStatus and getOrders({ customStatusKey }), e.g. 'in-kitchen'. */
44
- key: string;
45
- /** What staff see. */
46
- label: string;
47
- color?: string;
48
- icon?: string;
49
- fulfillmentState?: string;
50
- requiresPaymentState?: string[];
51
- }
@@ -2,7 +2,6 @@
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';
6
5
  import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFComposite, CFCartLineComponent, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout, CFBooking, CFBookingAvailability, CFBookingResource, CFBookingSlot, CFCartLineModifier, CFProdModifierBreakdown, CFModifierSelection, CFResolvedModifier } from '../CommonTypes';
7
6
  export * from './mocks';
8
7
  /** Replace mock catalog / context data in place (same array references mock handlers use). */
@@ -20,7 +19,6 @@ export interface MockDatabaseConfig {
20
19
  bookingResources?: CFBookingResource[];
21
20
  /** Windows already taken when the dataset loads, so a calendar does not open empty. */
22
21
  bookings?: CFBooking[];
23
- orderStatuses?: CFOrderStatusDefinition[];
24
22
  /** Products hidden at an outlet (the host's `catalog-visibility`, product-level rows). Empty = sold everywhere. */
25
23
  catalogVisibility?: MockCatalogVisibility[];
26
24
  }
@@ -115,8 +113,6 @@ export declare let MOCK_ACTIVE_PRODUCT: CFActiveProduct;
115
113
  export declare const setMockActiveProduct: (activeProduct: CFActiveProduct) => void;
116
114
  export declare const MOCK_SMART_GRID_LAYOUTS: Record<string, CFSmartGridLayout>;
117
115
  export declare const resetMockCart: () => void;
118
- /** The demo flow's order statuses (getOrderStatuses / setOrderStatus). */
119
- export declare const MOCK_ORDER_STATUSES: CFOrderStatusDefinition[];
120
116
  /**
121
117
  * Replace in-memory mock data used by default mock handlers. Arrays are mutated in place
122
118
  * so existing imports from this module keep working.
@@ -936,40 +936,11 @@ function resolveMockOrderCurrency() {
936
936
  }
937
937
  return CurrencyCode.USD;
938
938
  }
939
- /** The demo flow's order statuses (getOrderStatuses / setOrderStatus). */
940
- export const MOCK_ORDER_STATUSES = [
941
- { id: 'status_1', key: 'in-kitchen', label: 'In kitchen', color: '#f59e0b', fulfillmentState: 'pending' },
942
- {
943
- id: 'status_2',
944
- key: 'ready-for-pickup',
945
- label: 'Ready for pickup',
946
- color: '#10b981',
947
- fulfillmentState: 'in_progress',
948
- },
949
- {
950
- id: 'status_3',
951
- key: 'out-for-delivery',
952
- label: 'Out for delivery',
953
- color: '#3b82f6',
954
- fulfillmentState: 'partially_fulfilled',
955
- },
956
- {
957
- id: 'status_4',
958
- key: 'delivered',
959
- label: 'Delivered',
960
- fulfillmentState: 'fulfilled',
961
- requiresPaymentState: ['paid'],
962
- },
963
- { id: 'status_5', key: 'driver-called', label: 'Driver called' },
964
- ];
965
939
  /**
966
940
  * Replace in-memory mock data used by default mock handlers. Arrays are mutated in place
967
941
  * so existing imports from this module keep working.
968
942
  */
969
943
  export function setMockDatabase(config) {
970
- if (config.orderStatuses !== undefined) {
971
- MOCK_ORDER_STATUSES.splice(0, MOCK_ORDER_STATUSES.length, ...config.orderStatuses);
972
- }
973
944
  if (config.company !== undefined) {
974
945
  Object.assign(MOCK_COMPANY, config.company);
975
946
  }
package/dist/index.d.ts CHANGED
@@ -45,18 +45,9 @@ export declare const command: {
45
45
  readonly clearCart: import(".").ClearCart;
46
46
  readonly parkOrder: import(".").ParkOrder;
47
47
  readonly resumeParkedOrder: import(".").ResumeParkedOrder;
48
- readonly resumeOrder: import(".").ResumeOrder;
49
- readonly setOrderMetadata: import(".").SetOrderMetadata;
50
- readonly assignOrderUser: import(".").AssignOrderUser;
51
- readonly releaseFromCart: import(".").ReleaseFromCart;
52
- readonly setOrderType: import(".").SetOrderType;
53
- readonly setScheduledFor: import(".").SetScheduledFor;
54
- readonly setOrderStatus: import(".").SetOrderStatus;
55
- readonly getOrderStatuses: import(".").GetOrderStatuses;
56
48
  readonly deleteParkedOrder: import(".").DeleteParkedOrder;
57
49
  readonly voidOrder: import(".").VoidOrder;
58
50
  readonly cashPayment: import(".").CashPayment;
59
- readonly recordExternalPayment: import(".").RecordExternalPayment;
60
51
  readonly getCashRoundingAmount: import(".").GetCashRoundingAmount;
61
52
  readonly tapToPayPayment: import(".").TapToPayPayment;
62
53
  readonly terminalPayment: import(".").TerminalPayment;
@@ -65,7 +56,6 @@ export declare const command: {
65
56
  readonly integrationPayment: import(".").IntegrationPayment;
66
57
  readonly createPaymentLink: import(".").CreatePaymentLink;
67
58
  readonly chargeMoto: import(".").ChargeMoto;
68
- readonly getMotoConfig: import(".").GetMotoConfig;
69
59
  readonly addCustomerNote: import(".").AddCustomerNote;
70
60
  readonly removeCustomerNote: import(".").RemoveCustomerNote;
71
61
  readonly removeCustomerFromCart: import(".").RemoveCustomerFromCart;
@@ -203,18 +193,9 @@ export type { AddCartFee, AddCartFeeParams, AddCartFeeResponse } from './actions
203
193
  export type { ClearCart, ClearCartResponse } from './actions/clear-cart/types';
204
194
  export type { ParkOrder, ParkOrderResponse } from './actions/park-order/types';
205
195
  export type { ResumeParkedOrder, ResumeParkedOrderParams, ResumeParkedOrderResponse, } from './actions/resume-parked-order/types';
206
- export type { ResumeOrder, ResumeOrderParams, ResumeOrderResponse } from './actions/resume-order/types';
207
- export type { SetOrderMetadata, SetOrderMetadataParams, SetOrderMetadataResponse, } from './actions/set-order-metadata/types';
208
- export type { AssignOrderUser, AssignOrderUserParams, AssignOrderUserResponse, } from './actions/assign-order-user/types';
209
- export type { ReleaseFromCart, ReleaseFromCartResponse } from './actions/release-from-cart/types';
210
- export type { SetOrderType, SetOrderTypeParams, SetOrderTypeResponse } from './actions/set-order-type/types';
211
- export type { SetScheduledFor, SetScheduledForParams, SetScheduledForResponse, } from './actions/set-scheduled-for/types';
212
- export type { SetOrderStatus, SetOrderStatusParams, SetOrderStatusResponse } from './actions/set-order-status/types';
213
- export type { GetOrderStatuses, GetOrderStatusesResponse } from './actions/get-order-statuses/types';
214
196
  export type { DeleteParkedOrder, DeleteParkedOrderParams, DeleteParkedOrderResponse, } from './actions/delete-parked-order/types';
215
197
  export type { VoidOrder, VoidOrderParams, VoidOrderResponse, VoidOrderOutcome } from './actions/void-order/types';
216
198
  export type { CashPayment, CashPaymentParams, CashPaymentResponse } from './actions/cash-payment/types';
217
- export type { RecordExternalPayment, RecordExternalPaymentParams, RecordExternalPaymentResponse, } from './actions/record-external-payment/types';
218
199
  export type { GetCashRoundingAmount, GetCashRoundingAmountParams, GetCashRoundingAmountResponse, } from './actions/get-cash-rounding-amount/types';
219
200
  export type { TapToPayPayment, TapToPayPaymentParams, TapToPayPaymentResponse, } from './actions/tap-to-pay-payment/types';
220
201
  export type { TerminalPayment, TerminalPaymentParams, TerminalPaymentResponse } from './actions/terminal-payment/types';
@@ -223,7 +204,6 @@ export type { RedeemPayment, RedeemPaymentParams, RedeemPaymentResponse } from '
223
204
  export type { IntegrationPayment, IntegrationPaymentParams, IntegrationPaymentResponse, IntegrationEmvData, } from './actions/integration-payment/types';
224
205
  export type { CreatePaymentLink, CreatePaymentLinkParams, CreatePaymentLinkResponse, } from './actions/create-payment-link/types';
225
206
  export type { ChargeMoto, ChargeMotoParams, ChargeMotoResponse, ChargeMotoCardFields, } from './actions/charge-moto/types';
226
- export type { GetMotoConfig, GetMotoConfigResponse, MotoUnavailableReason } from './actions/get-moto-config/types';
227
207
  export type { AddCustomerNote, AddCustomerNoteParams, AddCustomerNoteResponse, } from './actions/add-customer-note/types';
228
208
  export type { RemoveCustomerNote, RemoveCustomerNoteParams, RemoveCustomerNoteResponse, } from './actions/remove-customer-note/types';
229
209
  export type { RemoveCustomerFromCart, RemoveCustomerFromCartResponse } from './actions/remove-customer-from-cart/types';
package/dist/index.js CHANGED
@@ -45,18 +45,9 @@ import { getCurrentCart } from './actions/get-current-cart/action';
45
45
  import { clearCart } from './actions/clear-cart/action';
46
46
  import { parkOrder } from './actions/park-order/action';
47
47
  import { resumeParkedOrder } from './actions/resume-parked-order/action';
48
- import { resumeOrder } from './actions/resume-order/action';
49
- import { setOrderMetadata } from './actions/set-order-metadata/action';
50
- import { assignOrderUser } from './actions/assign-order-user/action';
51
- import { releaseFromCart } from './actions/release-from-cart/action';
52
- import { setOrderType } from './actions/set-order-type/action';
53
- import { setScheduledFor } from './actions/set-scheduled-for/action';
54
- import { setOrderStatus } from './actions/set-order-status/action';
55
- import { getOrderStatuses } from './actions/get-order-statuses/action';
56
48
  import { deleteParkedOrder } from './actions/delete-parked-order/action';
57
49
  import { voidOrder } from './actions/void-order/action';
58
50
  import { cashPayment } from './actions/cash-payment/action';
59
- import { recordExternalPayment } from './actions/record-external-payment/action';
60
51
  import { getCashRoundingAmount } from './actions/get-cash-rounding-amount/action';
61
52
  import { tapToPayPayment } from './actions/tap-to-pay-payment/action';
62
53
  import { terminalPayment } from './actions/terminal-payment/action';
@@ -65,7 +56,6 @@ import { redeemPayment } from './actions/redeem-payment/action';
65
56
  import { integrationPayment } from './actions/integration-payment/action';
66
57
  import { createPaymentLink } from './actions/create-payment-link/action';
67
58
  import { chargeMoto } from './actions/charge-moto/action';
68
- import { getMotoConfig } from './actions/get-moto-config/action';
69
59
  // Customer Actions
70
60
  import { addCustomerNote } from './actions/add-customer-note/action';
71
61
  import { removeCustomerNote } from './actions/remove-customer-note/action';
@@ -205,18 +195,9 @@ export const command = {
205
195
  clearCart,
206
196
  parkOrder,
207
197
  resumeParkedOrder,
208
- resumeOrder,
209
- setOrderMetadata,
210
- assignOrderUser,
211
- releaseFromCart,
212
- setOrderType,
213
- setScheduledFor,
214
- setOrderStatus,
215
- getOrderStatuses,
216
198
  deleteParkedOrder,
217
199
  voidOrder,
218
200
  cashPayment,
219
- recordExternalPayment,
220
201
  getCashRoundingAmount,
221
202
  tapToPayPayment,
222
203
  terminalPayment,
@@ -225,7 +206,6 @@ export const command = {
225
206
  integrationPayment,
226
207
  createPaymentLink,
227
208
  chargeMoto,
228
- getMotoConfig,
229
209
  // Customer Actions
230
210
  addCustomerNote,
231
211
  removeCustomerNote,