@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.
- package/dist/CommonTypes.d.ts +1 -4
- package/dist/actions/get-current-cart/mock.js +0 -3
- package/dist/actions/get-current-cart/types.d.ts +0 -6
- package/dist/actions/get-orders/action.d.ts +1 -1
- package/dist/actions/get-orders/action.js +2 -2
- package/dist/actions/get-orders/mock.d.ts +1 -1
- package/dist/actions/get-orders/mock.js +19 -74
- package/dist/actions/get-orders/types.d.ts +2 -33
- package/dist/actions/resume-parked-order/mock.d.ts +0 -5
- package/dist/actions/resume-parked-order/mock.js +24 -25
- package/dist/actions/void-order/mock.js +7 -17
- package/dist/actions/void-order/types.d.ts +2 -6
- package/dist/common-types/order-state.d.ts +1 -20
- package/dist/demo/database.d.ts +0 -4
- package/dist/demo/database.js +0 -29
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -20
- package/dist/projects/render/mocks.js +0 -20
- package/dist/projects/render/types.d.ts +1 -11
- package/package.json +2 -2
- package/dist/actions/assign-order-user/action.d.ts +0 -6
- package/dist/actions/assign-order-user/action.js +0 -8
- package/dist/actions/assign-order-user/mock.d.ts +0 -2
- package/dist/actions/assign-order-user/mock.js +0 -30
- package/dist/actions/assign-order-user/types.d.ts +0 -15
- package/dist/actions/assign-order-user/types.js +0 -1
- package/dist/actions/get-moto-config/action.d.ts +0 -6
- package/dist/actions/get-moto-config/action.js +0 -8
- package/dist/actions/get-moto-config/mock.d.ts +0 -7
- package/dist/actions/get-moto-config/mock.js +0 -9
- package/dist/actions/get-moto-config/types.d.ts +0 -34
- package/dist/actions/get-moto-config/types.js +0 -5
- package/dist/actions/get-order-statuses/action.d.ts +0 -6
- package/dist/actions/get-order-statuses/action.js +0 -8
- package/dist/actions/get-order-statuses/mock.d.ts +0 -2
- package/dist/actions/get-order-statuses/mock.js +0 -5
- package/dist/actions/get-order-statuses/types.d.ts +0 -8
- package/dist/actions/get-order-statuses/types.js +0 -1
- package/dist/actions/record-external-payment/action.d.ts +0 -6
- package/dist/actions/record-external-payment/action.js +0 -8
- package/dist/actions/record-external-payment/mock.d.ts +0 -2
- package/dist/actions/record-external-payment/mock.js +0 -36
- package/dist/actions/record-external-payment/types.d.ts +0 -37
- package/dist/actions/record-external-payment/types.js +0 -1
- package/dist/actions/release-from-cart/action.d.ts +0 -6
- package/dist/actions/release-from-cart/action.js +0 -8
- package/dist/actions/release-from-cart/mock.d.ts +0 -2
- package/dist/actions/release-from-cart/mock.js +0 -26
- package/dist/actions/release-from-cart/types.d.ts +0 -8
- package/dist/actions/release-from-cart/types.js +0 -1
- package/dist/actions/resume-order/action.d.ts +0 -6
- package/dist/actions/resume-order/action.js +0 -8
- package/dist/actions/resume-order/mock.d.ts +0 -2
- package/dist/actions/resume-order/mock.js +0 -55
- package/dist/actions/resume-order/types.d.ts +0 -17
- package/dist/actions/resume-order/types.js +0 -1
- package/dist/actions/set-order-metadata/action.d.ts +0 -6
- package/dist/actions/set-order-metadata/action.js +0 -8
- package/dist/actions/set-order-metadata/mock.d.ts +0 -5
- package/dist/actions/set-order-metadata/mock.js +0 -38
- package/dist/actions/set-order-metadata/types.d.ts +0 -20
- package/dist/actions/set-order-metadata/types.js +0 -1
- package/dist/actions/set-order-status/action.d.ts +0 -6
- package/dist/actions/set-order-status/action.js +0 -8
- package/dist/actions/set-order-status/mock.d.ts +0 -3
- package/dist/actions/set-order-status/mock.js +0 -44
- package/dist/actions/set-order-status/types.d.ts +0 -25
- package/dist/actions/set-order-status/types.js +0 -1
- package/dist/actions/set-order-type/action.d.ts +0 -6
- package/dist/actions/set-order-type/action.js +0 -8
- package/dist/actions/set-order-type/mock.d.ts +0 -3
- package/dist/actions/set-order-type/mock.js +0 -27
- package/dist/actions/set-order-type/types.d.ts +0 -17
- package/dist/actions/set-order-type/types.js +0 -1
- package/dist/actions/set-scheduled-for/action.d.ts +0 -6
- package/dist/actions/set-scheduled-for/action.js +0 -8
- package/dist/actions/set-scheduled-for/mock.d.ts +0 -4
- package/dist/actions/set-scheduled-for/mock.js +0 -45
- package/dist/actions/set-scheduled-for/types.d.ts +0 -22
- package/dist/actions/set-scheduled-for/types.js +0 -1
|
@@ -1,20 +0,0 @@
|
|
|
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>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
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) {
|
|
18
|
-
order.customStatus = null;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const def = MOCK_ORDER_STATUSES.find((s) => s.key === requested) ??
|
|
22
|
-
(params.key === undefined ? MOCK_ORDER_STATUSES.find((s) => s.id === requested) : undefined);
|
|
23
|
-
if (!def) {
|
|
24
|
-
throw new Error(`setOrderStatus: unknown status "${requested}"`);
|
|
25
|
-
}
|
|
26
|
-
if (def.requiresPaymentState && !def.requiresPaymentState.includes(from.payment)) {
|
|
27
|
-
throw new Error(`setOrderStatus: "${def.label}" requires payment state ${def.requiresPaymentState.join(' or ')} (order is ${from.payment})`);
|
|
28
|
-
}
|
|
29
|
-
if (def.fulfillmentState)
|
|
30
|
-
order.fulfillmentState = def.fulfillmentState;
|
|
31
|
-
order.customStatus = { id: def.id, key: def.key, label: def.label, setAt: new Date().toISOString(), setBy: null };
|
|
32
|
-
}
|
|
33
|
-
mockPublishEvent('orders', 'order-updated', { order });
|
|
34
|
-
const to = { payment: order.paymentState ?? 'unpaid', fulfillment: order.fulfillmentState ?? 'draft' };
|
|
35
|
-
return {
|
|
36
|
-
success: true,
|
|
37
|
-
orderId: order._id,
|
|
38
|
-
customStatus: order.customStatus ?? null,
|
|
39
|
-
from,
|
|
40
|
-
to,
|
|
41
|
-
order,
|
|
42
|
-
timestamp: new Date().toISOString(),
|
|
43
|
-
};
|
|
44
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
/** 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;
|
|
13
|
-
}
|
|
14
|
-
export interface SetOrderStatusResponse {
|
|
15
|
-
success: boolean;
|
|
16
|
-
orderId: string;
|
|
17
|
-
/** The order's status after the call; null when cleared. */
|
|
18
|
-
customStatus: CFOrderCustomStatus | null;
|
|
19
|
-
/** State before and after — they differ only when the status is bound to a fulfillment state the order wasn't in. */
|
|
20
|
-
from: CFStatePair | null;
|
|
21
|
-
to: CFStatePair | null;
|
|
22
|
-
order: CFOrder;
|
|
23
|
-
timestamp: string;
|
|
24
|
-
}
|
|
25
|
-
export type SetOrderStatus = (params: SetOrderStatusParams) => Promise<SetOrderStatusResponse>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
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>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
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>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|