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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import type { CFOrderStatusDefinition } from '../../common-types/order-state';
2
2
  export interface GetOrderStatusesResponse {
3
3
  success: boolean;
4
- /** The company's order statuses, in the order they were defined. Empty when none are defined. */
4
+ /** The running flow's order statuses, in the order they were defined. Empty when it defines none. */
5
5
  statuses: CFOrderStatusDefinition[];
6
6
  timestamp: string;
7
7
  }
@@ -5,7 +5,7 @@ export const mockGetOrders = async (params) => {
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, scheduled, scheduledFrom, scheduledTo, searchValue, limit, offset, sortBy, sortDirection, } = params;
8
+ const { customerId, status, sessionId, paymentState, fulfillmentState, outletId, assignedUserId, inCart, orderType, customStatusId, customStatusKey, scheduled, scheduledFrom, scheduledTo, searchValue, limit, offset, sortBy, sortDirection, } = params;
9
9
  // 1. Filtering
10
10
  if (customerId) {
11
11
  orders = orders.filter((o) => o.customer && '_id' in o.customer && o.customer._id === customerId);
@@ -38,10 +38,17 @@ export const mockGetOrders = async (params) => {
38
38
  if (types.length)
39
39
  orders = orders.filter((o) => types.includes(o.orderType ?? ''));
40
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
+ }
41
46
  if (customStatusId !== undefined) {
42
47
  const ids = Array.isArray(customStatusId) ? customStatusId : [customStatusId];
43
- if (ids.length)
44
- orders = orders.filter((o) => !!o.customStatus && ids.includes(o.customStatus.id));
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
+ }
45
52
  }
46
53
  // Requested time (setScheduledFor). ISO strings in UTC compare correctly as strings.
47
54
  const scheduledOf = (o) => o.scheduledFor ?? null;
@@ -22,7 +22,12 @@ export interface GetOrdersParams {
22
22
  inCart?: boolean;
23
23
  /** Order type label(s) set with setOrderType, e.g. 'delivery' or ['pickup', 'takeout']. Exact match; a list matches any. */
24
24
  orderType?: string | string[];
25
- /** Custom status id(s) set with setOrderStatus, e.g. 'in-kitchen'. A list matches any of them. */
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
+ */
26
31
  customStatusId?: string | string[];
27
32
  /** true: only orders with a time (setScheduledFor); false: only "as soon as possible" orders (no time). */
28
33
  scheduled?: boolean;
@@ -10,20 +10,25 @@ export const mockSetOrderStatus = async (params) => {
10
10
  throw new Error(`Order with ID ${params.orderId} not found`);
11
11
  }
12
12
  const from = { payment: order.paymentState ?? 'unpaid', fulfillment: order.fulfillmentState ?? 'draft' };
13
- if (params.statusId === null) {
13
+ const requested = params.key !== undefined ? params.key : params.statusId;
14
+ if (requested === undefined) {
15
+ throw new Error('setOrderStatus: pass a status key, or null to clear the status');
16
+ }
17
+ if (requested === null) {
14
18
  order.customStatus = null;
15
19
  }
16
20
  else {
17
- const def = MOCK_ORDER_STATUSES.find((s) => s.id === params.statusId);
21
+ const def = MOCK_ORDER_STATUSES.find((s) => s.key === requested) ??
22
+ (params.key === undefined ? MOCK_ORDER_STATUSES.find((s) => s.id === requested) : undefined);
18
23
  if (!def) {
19
- throw new Error(`setOrderStatus: unknown status "${params.statusId}"`);
24
+ throw new Error(`setOrderStatus: unknown status "${requested}"`);
20
25
  }
21
26
  if (def.requiresPaymentState && !def.requiresPaymentState.includes(from.payment)) {
22
27
  throw new Error(`setOrderStatus: "${def.label}" requires payment state ${def.requiresPaymentState.join(' or ')} (order is ${from.payment})`);
23
28
  }
24
29
  if (def.fulfillmentState)
25
30
  order.fulfillmentState = def.fulfillmentState;
26
- order.customStatus = { id: def.id, label: def.label, setAt: new Date().toISOString(), setBy: null };
31
+ order.customStatus = { id: def.id, key: def.key, label: def.label, setAt: new Date().toISOString(), setBy: null };
27
32
  }
28
33
  mockPublishEvent('orders', 'order-updated', { order });
29
34
  const to = { payment: order.paymentState ?? 'unpaid', fulfillment: order.fulfillmentState ?? 'draft' };
@@ -3,8 +3,13 @@ import type { CFStatePair } from '../../common-types/order-state';
3
3
  export interface SetOrderStatusParams {
4
4
  /** Order to set the status on. Omit for the live cart's order. */
5
5
  orderId?: string;
6
- /** Id of one of the company's statuses (see getOrderStatuses), or null to clear the status. */
7
- statusId: string | null;
6
+ /** Key of one of the flow's statuses (see getOrderStatuses), or null to clear the status. */
7
+ key?: string | null;
8
+ /**
9
+ * @deprecated Use `key`. Kept for flows written before keys: matched against a status's
10
+ * key, then its id. Ignored when `key` is given.
11
+ */
12
+ statusId?: string | null;
8
13
  }
9
14
  export interface SetOrderStatusResponse {
10
15
  success: boolean;
@@ -31,13 +31,18 @@ export interface CFAvailableTransition {
31
31
  conditions: CFConditionStatus[];
32
32
  }
33
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.
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.
38
39
  */
39
40
  export interface CFOrderStatusDefinition {
41
+ /** Durable id; survives a renamed key or label. */
40
42
  id: string;
43
+ /** What flow code passes to setOrderStatus and getOrders({ customStatusKey }), e.g. 'in-kitchen'. */
44
+ key: string;
45
+ /** What staff see. */
41
46
  label: string;
42
47
  color?: string;
43
48
  icon?: string;
@@ -77,7 +77,7 @@ export declare let MOCK_ACTIVE_PRODUCT: CFActiveProduct;
77
77
  export declare const setMockActiveProduct: (activeProduct: CFActiveProduct) => void;
78
78
  export declare const MOCK_SMART_GRID_LAYOUTS: Record<string, CFSmartGridLayout>;
79
79
  export declare const resetMockCart: () => void;
80
- /** The demo company's order statuses (getOrderStatuses / setOrderStatus). */
80
+ /** The demo flow's order statuses (getOrderStatuses / setOrderStatus). */
81
81
  export declare const MOCK_ORDER_STATUSES: CFOrderStatusDefinition[];
82
82
  /**
83
83
  * Replace in-memory mock data used by default mock handlers. Arrays are mutated in place
@@ -722,13 +722,31 @@ function resolveMockOrderCurrency() {
722
722
  }
723
723
  return CurrencyCode.USD;
724
724
  }
725
- /** The demo company's order statuses (getOrderStatuses / setOrderStatus). */
725
+ /** The demo flow's order statuses (getOrderStatuses / setOrderStatus). */
726
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' },
727
+ { id: 'status_1', key: 'in-kitchen', label: 'In kitchen', color: '#f59e0b', fulfillmentState: 'pending' },
728
+ {
729
+ id: 'status_2',
730
+ key: 'ready-for-pickup',
731
+ label: 'Ready for pickup',
732
+ color: '#10b981',
733
+ fulfillmentState: 'in_progress',
734
+ },
735
+ {
736
+ id: 'status_3',
737
+ key: 'out-for-delivery',
738
+ label: 'Out for delivery',
739
+ color: '#3b82f6',
740
+ fulfillmentState: 'partially_fulfilled',
741
+ },
742
+ {
743
+ id: 'status_4',
744
+ key: 'delivered',
745
+ label: 'Delivered',
746
+ fulfillmentState: 'fulfilled',
747
+ requiresPaymentState: ['paid'],
748
+ },
749
+ { id: 'status_5', key: 'driver-called', label: 'Driver called' },
732
750
  ];
733
751
  /**
734
752
  * Replace in-memory mock data used by default mock handlers. Arrays are mutated in place
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.9.0-preprod.3",
3
+ "version": "0.9.0-preprod.4",
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.1-preprod.6"
60
+ "@final-commerce/common": "2.5.1-preprod.8"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",