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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) 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-current-cart/mock.d.ts +1 -1
  9. package/dist/actions/get-current-cart/mock.js +6 -3
  10. package/dist/actions/get-current-cart/types.d.ts +7 -1
  11. package/dist/actions/get-order-statuses/action.d.ts +6 -0
  12. package/dist/actions/get-order-statuses/action.js +8 -0
  13. package/dist/actions/get-order-statuses/mock.d.ts +2 -0
  14. package/dist/actions/get-order-statuses/mock.js +5 -0
  15. package/dist/actions/get-order-statuses/types.d.ts +8 -0
  16. package/dist/actions/get-order-statuses/types.js +1 -0
  17. package/dist/actions/get-orders/action.d.ts +1 -1
  18. package/dist/actions/get-orders/action.js +2 -2
  19. package/dist/actions/get-orders/mock.d.ts +1 -1
  20. package/dist/actions/get-orders/mock.js +67 -19
  21. package/dist/actions/get-orders/types.d.ts +28 -2
  22. package/dist/actions/record-external-payment/action.d.ts +6 -0
  23. package/dist/actions/record-external-payment/action.js +8 -0
  24. package/dist/actions/record-external-payment/mock.d.ts +2 -0
  25. package/dist/actions/record-external-payment/mock.js +36 -0
  26. package/dist/actions/record-external-payment/types.d.ts +37 -0
  27. package/dist/actions/record-external-payment/types.js +1 -0
  28. package/dist/actions/release-from-cart/action.d.ts +6 -0
  29. package/dist/actions/release-from-cart/action.js +8 -0
  30. package/dist/actions/release-from-cart/mock.d.ts +2 -0
  31. package/dist/actions/release-from-cart/mock.js +26 -0
  32. package/dist/actions/release-from-cart/types.d.ts +8 -0
  33. package/dist/actions/release-from-cart/types.js +1 -0
  34. package/dist/actions/resume-order/action.d.ts +6 -0
  35. package/dist/actions/resume-order/action.js +8 -0
  36. package/dist/actions/resume-order/mock.d.ts +2 -0
  37. package/dist/actions/resume-order/mock.js +55 -0
  38. package/dist/actions/resume-order/types.d.ts +17 -0
  39. package/dist/actions/resume-order/types.js +1 -0
  40. package/dist/actions/resume-parked-order/mock.d.ts +6 -1
  41. package/dist/actions/resume-parked-order/mock.js +32 -31
  42. package/dist/actions/set-order-metadata/action.d.ts +6 -0
  43. package/dist/actions/set-order-metadata/action.js +8 -0
  44. package/dist/actions/set-order-metadata/mock.d.ts +5 -0
  45. package/dist/actions/set-order-metadata/mock.js +38 -0
  46. package/dist/actions/set-order-metadata/types.d.ts +20 -0
  47. package/dist/actions/set-order-metadata/types.js +1 -0
  48. package/dist/actions/set-order-status/action.d.ts +6 -0
  49. package/dist/actions/set-order-status/action.js +8 -0
  50. package/dist/actions/set-order-status/mock.d.ts +3 -0
  51. package/dist/actions/set-order-status/mock.js +39 -0
  52. package/dist/actions/set-order-status/types.d.ts +20 -0
  53. package/dist/actions/set-order-status/types.js +1 -0
  54. package/dist/actions/set-order-type/action.d.ts +6 -0
  55. package/dist/actions/set-order-type/action.js +8 -0
  56. package/dist/actions/set-order-type/mock.d.ts +3 -0
  57. package/dist/actions/set-order-type/mock.js +27 -0
  58. package/dist/actions/set-order-type/types.d.ts +17 -0
  59. package/dist/actions/set-order-type/types.js +1 -0
  60. package/dist/actions/set-scheduled-for/action.d.ts +6 -0
  61. package/dist/actions/set-scheduled-for/action.js +8 -0
  62. package/dist/actions/set-scheduled-for/mock.d.ts +4 -0
  63. package/dist/actions/set-scheduled-for/mock.js +45 -0
  64. package/dist/actions/set-scheduled-for/types.d.ts +22 -0
  65. package/dist/actions/set-scheduled-for/types.js +1 -0
  66. package/dist/common-types/order-state.d.ts +15 -1
  67. package/dist/demo/database.d.ts +4 -0
  68. package/dist/demo/database.js +11 -0
  69. package/dist/index.d.ts +18 -0
  70. package/dist/index.js +18 -0
  71. package/dist/projects/render/mocks.js +18 -0
  72. package/dist/projects/render/types.d.ts +10 -1
  73. package/package.json +2 -2
@@ -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 {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Set scheduled-for action
3
+ * Calls the setScheduledFor action on the parent window
4
+ */
5
+ import type { SetScheduledFor } from './types';
6
+ export declare const setScheduledFor: SetScheduledFor;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Set scheduled-for action
3
+ * Calls the setScheduledFor action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const setScheduledFor = async (params) => {
7
+ return await commandFrameClient.call('setScheduledFor', params);
8
+ };
@@ -0,0 +1,4 @@
1
+ import type { SetScheduledFor } from './types';
2
+ /** ISO 8601 in, UTC ISO 8601 out; null stays null (as soon as possible). */
3
+ export declare const normalizeScheduledFor: (value: unknown) => string | null;
4
+ export declare const mockSetScheduledFor: SetScheduledFor;
@@ -0,0 +1,45 @@
1
+ import { MOCK_ORDERS, MOCK_PARKED_ORDERS, mockPublishEvent } from '../../demo/database';
2
+ /** Time for the demo's live cart, which has no order until it is paid or parked. */
3
+ let mockCartScheduledFor = null;
4
+ /**
5
+ * An ISO 8601 date-time WITH a zone — 'Z' or an offset. A zoneless time ('2026-10-13T19:00') is
6
+ * refused: it would mean a different moment on every device. Date.parse alone is too lenient
7
+ * (it accepts strings like "tomorrow at 7"), so the shape is checked first.
8
+ */
9
+ const ISO_DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:?\d{2})$/;
10
+ /** The YYYY-MM-DD part is a real day — Date.parse quietly rolls "Feb 30" over to March 2. */
11
+ const isCalendarDate = (text) => {
12
+ const [y, m, d] = text.slice(0, 10).split('-').map(Number);
13
+ const day = new Date(Date.UTC(y, m - 1, d));
14
+ return day.getUTCFullYear() === y && day.getUTCMonth() === m - 1 && day.getUTCDate() === d;
15
+ };
16
+ /** ISO 8601 in, UTC ISO 8601 out; null stays null (as soon as possible). */
17
+ export const normalizeScheduledFor = (value) => {
18
+ if (value === null)
19
+ return null;
20
+ if (typeof value !== 'string' || !value.trim()) {
21
+ throw new Error('setScheduledFor: scheduledFor must be an ISO 8601 date-time or null');
22
+ }
23
+ const text = value.trim();
24
+ const ms = ISO_DATE_TIME.test(text) && isCalendarDate(text) ? Date.parse(text) : NaN;
25
+ if (Number.isNaN(ms)) {
26
+ throw new Error(`setScheduledFor: "${value}" is not an ISO 8601 date-time with Z or an offset`);
27
+ }
28
+ return new Date(ms).toISOString();
29
+ };
30
+ export const mockSetScheduledFor = async (params) => {
31
+ console.log('[Mock] setScheduledFor called', params);
32
+ const scheduledFor = normalizeScheduledFor(params?.scheduledFor);
33
+ const timestamp = new Date().toISOString();
34
+ if (!params.orderId) {
35
+ mockCartScheduledFor = scheduledFor;
36
+ return { success: true, orderId: null, scheduledFor: mockCartScheduledFor, timestamp };
37
+ }
38
+ const order = [...MOCK_ORDERS, ...MOCK_PARKED_ORDERS].find((o) => o._id === params.orderId);
39
+ if (!order) {
40
+ throw new Error(`Order with ID ${params.orderId} not found`);
41
+ }
42
+ order.scheduledFor = scheduledFor;
43
+ mockPublishEvent('orders', 'order-updated', { order });
44
+ return { success: true, orderId: order._id, scheduledFor, timestamp };
45
+ };
@@ -0,0 +1,22 @@
1
+ export interface SetScheduledForParams {
2
+ /**
3
+ * Order to schedule. Omit to target the live cart — including a cart that isn't an
4
+ * order yet; the time is carried onto the order when it's created.
5
+ */
6
+ orderId?: string;
7
+ /**
8
+ * When the customer wants the order, as an ISO 8601 date-time with Z or an offset (e.g.
9
+ * '2026-10-13T23:00:00.000Z' or '2026-10-13T19:00:00-04:00'), or null for as soon as possible.
10
+ * Stored in UTC.
11
+ */
12
+ scheduledFor: string | null;
13
+ }
14
+ export interface SetScheduledForResponse {
15
+ success: boolean;
16
+ /** The order that was updated, or null when the live cart has no order yet. */
17
+ orderId: string | null;
18
+ /** The time after the call, normalised to UTC ISO 8601 — or null (as soon as possible). */
19
+ scheduledFor: string | null;
20
+ timestamp: string;
21
+ }
22
+ export type SetScheduledFor = (params: SetScheduledForParams) => Promise<SetScheduledForResponse>;
@@ -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,18 @@ 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 setScheduledFor: import(".").SetScheduledFor;
51
+ readonly setOrderStatus: import(".").SetOrderStatus;
52
+ readonly getOrderStatuses: import(".").GetOrderStatuses;
45
53
  readonly deleteParkedOrder: import(".").DeleteParkedOrder;
46
54
  readonly voidOrder: import(".").VoidOrder;
47
55
  readonly cashPayment: import(".").CashPayment;
56
+ readonly recordExternalPayment: import(".").RecordExternalPayment;
48
57
  readonly getCashRoundingAmount: import(".").GetCashRoundingAmount;
49
58
  readonly tapToPayPayment: import(".").TapToPayPayment;
50
59
  readonly terminalPayment: import(".").TerminalPayment;
@@ -187,9 +196,18 @@ export type { AddCartFee, AddCartFeeParams, AddCartFeeResponse } from './actions
187
196
  export type { ClearCart, ClearCartResponse } from './actions/clear-cart/types';
188
197
  export type { ParkOrder, ParkOrderResponse } from './actions/park-order/types';
189
198
  export type { ResumeParkedOrder, ResumeParkedOrderParams, ResumeParkedOrderResponse, } from './actions/resume-parked-order/types';
199
+ export type { ResumeOrder, ResumeOrderParams, ResumeOrderResponse } from './actions/resume-order/types';
200
+ export type { SetOrderMetadata, SetOrderMetadataParams, SetOrderMetadataResponse, } from './actions/set-order-metadata/types';
201
+ export type { AssignOrderUser, AssignOrderUserParams, AssignOrderUserResponse, } from './actions/assign-order-user/types';
202
+ export type { ReleaseFromCart, ReleaseFromCartResponse } from './actions/release-from-cart/types';
203
+ export type { SetOrderType, SetOrderTypeParams, SetOrderTypeResponse } from './actions/set-order-type/types';
204
+ export type { SetScheduledFor, SetScheduledForParams, SetScheduledForResponse, } from './actions/set-scheduled-for/types';
205
+ export type { SetOrderStatus, SetOrderStatusParams, SetOrderStatusResponse } from './actions/set-order-status/types';
206
+ export type { GetOrderStatuses, GetOrderStatusesResponse } from './actions/get-order-statuses/types';
190
207
  export type { DeleteParkedOrder, DeleteParkedOrderParams, DeleteParkedOrderResponse, } from './actions/delete-parked-order/types';
191
208
  export type { VoidOrder, VoidOrderParams, VoidOrderResponse, VoidOrderOutcome } from './actions/void-order/types';
192
209
  export type { CashPayment, CashPaymentParams, CashPaymentResponse } from './actions/cash-payment/types';
210
+ export type { RecordExternalPayment, RecordExternalPaymentParams, RecordExternalPaymentResponse, } from './actions/record-external-payment/types';
193
211
  export type { GetCashRoundingAmount, GetCashRoundingAmountParams, GetCashRoundingAmountResponse, } from './actions/get-cash-rounding-amount/types';
194
212
  export type { TapToPayPayment, TapToPayPaymentParams, TapToPayPaymentResponse, } from './actions/tap-to-pay-payment/types';
195
213
  export type { TerminalPayment, TerminalPaymentParams, TerminalPaymentResponse } from './actions/terminal-payment/types';
package/dist/index.js CHANGED
@@ -42,9 +42,18 @@ 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 { setScheduledFor } from './actions/set-scheduled-for/action';
51
+ import { setOrderStatus } from './actions/set-order-status/action';
52
+ import { getOrderStatuses } from './actions/get-order-statuses/action';
45
53
  import { deleteParkedOrder } from './actions/delete-parked-order/action';
46
54
  import { voidOrder } from './actions/void-order/action';
47
55
  import { cashPayment } from './actions/cash-payment/action';
56
+ import { recordExternalPayment } from './actions/record-external-payment/action';
48
57
  import { getCashRoundingAmount } from './actions/get-cash-rounding-amount/action';
49
58
  import { tapToPayPayment } from './actions/tap-to-pay-payment/action';
50
59
  import { terminalPayment } from './actions/terminal-payment/action';
@@ -189,9 +198,18 @@ export const command = {
189
198
  clearCart,
190
199
  parkOrder,
191
200
  resumeParkedOrder,
201
+ resumeOrder,
202
+ setOrderMetadata,
203
+ assignOrderUser,
204
+ releaseFromCart,
205
+ setOrderType,
206
+ setScheduledFor,
207
+ setOrderStatus,
208
+ getOrderStatuses,
192
209
  deleteParkedOrder,
193
210
  voidOrder,
194
211
  cashPayment,
212
+ recordExternalPayment,
195
213
  getCashRoundingAmount,
196
214
  tapToPayPayment,
197
215
  terminalPayment,