@final-commerce/command-frame 0.8.1-online.1 → 0.9.0-preprod.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CommonTypes.d.ts +4 -15
- package/dist/actions/adjust-inventory/mock.js +20 -0
- package/dist/actions/adjust-inventory/types.d.ts +13 -0
- package/dist/actions/adjust-inventory/types.js +1 -0
- package/dist/actions/assign-order-user/action.d.ts +6 -0
- package/dist/actions/assign-order-user/action.js +8 -0
- package/dist/actions/assign-order-user/mock.d.ts +2 -0
- package/dist/actions/assign-order-user/mock.js +30 -0
- package/dist/actions/assign-order-user/types.d.ts +15 -0
- package/dist/actions/get-custom-stock-actions/action.d.ts +5 -0
- package/dist/actions/get-custom-stock-actions/action.js +7 -0
- package/dist/actions/get-custom-stock-actions/mock.d.ts +2 -0
- package/dist/actions/get-custom-stock-actions/mock.js +11 -0
- package/dist/actions/get-custom-stock-actions/types.d.ts +12 -0
- package/dist/actions/get-custom-stock-actions/types.js +2 -0
- package/dist/actions/get-order-statuses/action.d.ts +6 -0
- package/dist/actions/get-order-statuses/action.js +8 -0
- package/dist/actions/get-order-statuses/mock.d.ts +2 -0
- package/dist/actions/get-order-statuses/mock.js +5 -0
- package/dist/actions/get-order-statuses/types.d.ts +8 -0
- 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 +49 -19
- package/dist/actions/get-orders/types.d.ts +21 -1
- package/dist/actions/get-outlets/action.js +2 -2
- package/dist/actions/get-outlets/mock.d.ts +0 -12
- package/dist/actions/get-outlets/mock.js +4 -28
- package/dist/actions/get-outlets/types.d.ts +1 -19
- package/dist/actions/record-external-payment/action.d.ts +6 -0
- package/dist/actions/record-external-payment/action.js +8 -0
- package/dist/actions/record-external-payment/mock.d.ts +2 -0
- package/dist/actions/record-external-payment/mock.js +36 -0
- package/dist/actions/record-external-payment/types.d.ts +37 -0
- package/dist/actions/release-from-cart/action.d.ts +6 -0
- package/dist/actions/release-from-cart/action.js +8 -0
- package/dist/actions/release-from-cart/mock.d.ts +2 -0
- package/dist/actions/release-from-cart/mock.js +26 -0
- package/dist/actions/release-from-cart/types.d.ts +8 -0
- package/dist/actions/release-from-cart/types.js +1 -0
- package/dist/actions/resume-order/action.d.ts +6 -0
- package/dist/actions/resume-order/action.js +8 -0
- package/dist/actions/resume-order/mock.d.ts +2 -0
- package/dist/actions/resume-order/mock.js +55 -0
- package/dist/actions/resume-order/types.d.ts +17 -0
- package/dist/actions/resume-order/types.js +1 -0
- package/dist/actions/resume-parked-order/mock.d.ts +6 -1
- package/dist/actions/resume-parked-order/mock.js +32 -31
- package/dist/actions/set-order-metadata/action.d.ts +6 -0
- package/dist/actions/set-order-metadata/action.js +8 -0
- package/dist/actions/set-order-metadata/mock.d.ts +5 -0
- package/dist/actions/set-order-metadata/mock.js +38 -0
- package/dist/actions/set-order-metadata/types.d.ts +20 -0
- package/dist/actions/set-order-metadata/types.js +1 -0
- package/dist/actions/set-order-status/action.d.ts +6 -0
- package/dist/actions/set-order-status/action.js +8 -0
- package/dist/actions/set-order-status/mock.d.ts +3 -0
- package/dist/actions/set-order-status/mock.js +39 -0
- package/dist/actions/set-order-status/types.d.ts +20 -0
- package/dist/actions/set-order-status/types.js +1 -0
- package/dist/actions/set-order-type/action.d.ts +6 -0
- package/dist/actions/set-order-type/action.js +8 -0
- package/dist/actions/set-order-type/mock.d.ts +3 -0
- package/dist/actions/set-order-type/mock.js +27 -0
- package/dist/actions/set-order-type/types.d.ts +17 -0
- package/dist/actions/set-order-type/types.js +1 -0
- package/dist/common-types/order-state.d.ts +15 -1
- package/dist/demo/database.d.ts +4 -0
- package/dist/demo/database.js +11 -0
- package/dist/index.d.ts +20 -12
- package/dist/index.js +18 -9
- package/dist/projects/render/mocks.js +18 -10
- package/dist/projects/render/types.d.ts +10 -16
- package/dist/pubsub/topics/index.d.ts +17 -18
- package/dist/pubsub/topics/index.js +17 -18
- package/dist/pubsub/topics/types.d.ts +0 -8
- package/package.json +2 -2
- package/dist/actions/attach-checkout-contact/action.d.ts +0 -6
- package/dist/actions/attach-checkout-contact/action.js +0 -8
- package/dist/actions/attach-checkout-contact/mock.d.ts +0 -15
- package/dist/actions/attach-checkout-contact/mock.js +0 -22
- package/dist/actions/attach-checkout-contact/types.d.ts +0 -35
- package/dist/actions/attach-checkout-contact/types.js +0 -16
- package/dist/actions/resume-checkout/action.d.ts +0 -6
- package/dist/actions/resume-checkout/action.js +0 -8
- package/dist/actions/resume-checkout/mock.d.ts +0 -16
- package/dist/actions/resume-checkout/mock.js +0 -51
- package/dist/actions/resume-checkout/types.d.ts +0 -59
- package/dist/actions/resume-checkout/types.js +0 -13
- package/dist/actions/set-outlet/action.d.ts +0 -6
- package/dist/actions/set-outlet/action.js +0 -8
- package/dist/actions/set-outlet/mock.d.ts +0 -13
- package/dist/actions/set-outlet/mock.js +0 -24
- package/dist/actions/set-outlet/types.d.ts +0 -31
- package/dist/actions/set-outlet/types.js +0 -21
- package/dist/actions/start-checkout/action.d.ts +0 -6
- package/dist/actions/start-checkout/action.js +0 -8
- package/dist/actions/start-checkout/mock.d.ts +0 -16
- package/dist/actions/start-checkout/mock.js +0 -80
- package/dist/actions/start-checkout/types.d.ts +0 -90
- package/dist/actions/start-checkout/types.js +0 -10
- package/dist/pubsub/topics/checkout/checkout-started/types.d.ts +0 -26
- package/dist/pubsub/topics/checkout/index.d.ts +0 -7
- package/dist/pubsub/topics/checkout/index.js +0 -28
- package/dist/pubsub/topics/checkout/payment-completed/types.d.ts +0 -31
- package/dist/pubsub/topics/checkout/payment-failed/types.d.ts +0 -20
- package/dist/pubsub/topics/checkout/types.d.ts +0 -12
- package/dist/pubsub/topics/checkout/types.js +0 -8
- /package/dist/{pubsub/topics/checkout/checkout-started → actions/assign-order-user}/types.js +0 -0
- /package/dist/{pubsub/topics/checkout/payment-completed → actions/get-order-statuses}/types.js +0 -0
- /package/dist/{pubsub/topics/checkout/payment-failed → actions/record-external-payment}/types.js +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Release from cart action
|
|
3
|
+
* Calls the releaseFromCart action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from '../../client';
|
|
6
|
+
export const releaseFromCart = async () => {
|
|
7
|
+
return await commandFrameClient.call('releaseFromCart', undefined);
|
|
8
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MOCK_CART, MOCK_ORDERS, resetMockCart, mockPublishEvent } from '../../demo/database';
|
|
2
|
+
export const mockReleaseFromCart = async () => {
|
|
3
|
+
console.log('[Mock] releaseFromCart called');
|
|
4
|
+
if (!MOCK_CART.products.length) {
|
|
5
|
+
throw new Error('releaseFromCart: the cart is empty');
|
|
6
|
+
}
|
|
7
|
+
const now = new Date().toISOString();
|
|
8
|
+
// Best-effort: the demo has no live-cart order, so the cart becomes a new unpaid draft.
|
|
9
|
+
const order = {
|
|
10
|
+
_id: `order_released_${Date.now()}`,
|
|
11
|
+
receiptId: `REL-${MOCK_ORDERS.length + 1}`,
|
|
12
|
+
status: 'in-cart',
|
|
13
|
+
paymentState: 'unpaid',
|
|
14
|
+
fulfillmentState: 'draft',
|
|
15
|
+
inCart: { active: false, stationId: null, since: now },
|
|
16
|
+
lineItems: [],
|
|
17
|
+
customSales: [],
|
|
18
|
+
paymentMethods: [],
|
|
19
|
+
summary: { total: MOCK_CART.total },
|
|
20
|
+
createdAt: now,
|
|
21
|
+
};
|
|
22
|
+
MOCK_ORDERS.push(order);
|
|
23
|
+
resetMockCart();
|
|
24
|
+
mockPublishEvent('orders', 'order-updated', { order });
|
|
25
|
+
return { success: true, order, timestamp: now };
|
|
26
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CFOrder } from '../../CommonTypes';
|
|
2
|
+
export interface ReleaseFromCartResponse {
|
|
3
|
+
success: boolean;
|
|
4
|
+
/** The order that left the cart, as saved — its state is unchanged and `inCart.active` is false. */
|
|
5
|
+
order: CFOrder;
|
|
6
|
+
timestamp: string;
|
|
7
|
+
}
|
|
8
|
+
export type ReleaseFromCart = () => Promise<ReleaseFromCartResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MOCK_ORDERS, MOCK_PARKED_ORDERS, mockPublishEvent } from '../../demo/database';
|
|
2
|
+
import { restoreMockCartFromOrder } from '../resume-parked-order/mock';
|
|
3
|
+
// Mirrors the host's rule (see README): anything not already in a cart and not finished.
|
|
4
|
+
const BLOCKED_PAYMENT = new Set(['refunded', 'partially_refunded', 'voided', 'payment_pending']);
|
|
5
|
+
const FINISHED_FULFILLMENT = new Set(['cancelled', 'returned', 'partially_returned']);
|
|
6
|
+
export const mockResumeOrder = async (params) => {
|
|
7
|
+
console.log('[Mock] resumeOrder called', params);
|
|
8
|
+
const orderId = params?.orderId;
|
|
9
|
+
if (!orderId) {
|
|
10
|
+
throw new Error('Order ID is required');
|
|
11
|
+
}
|
|
12
|
+
const order = [...MOCK_PARKED_ORDERS, ...MOCK_ORDERS].find((o) => o._id === orderId);
|
|
13
|
+
if (!order) {
|
|
14
|
+
throw new Error(`Order with ID ${orderId} not found`);
|
|
15
|
+
}
|
|
16
|
+
const from = { payment: order.paymentState ?? 'unpaid', fulfillment: order.fulfillmentState ?? 'draft' };
|
|
17
|
+
const inCart = order.inCart != null ? order.inCart.active : from.fulfillment === 'draft';
|
|
18
|
+
if (inCart) {
|
|
19
|
+
throw new Error(`Order ${orderId} is already in a cart`);
|
|
20
|
+
}
|
|
21
|
+
if (BLOCKED_PAYMENT.has(from.payment) ||
|
|
22
|
+
FINISHED_FULFILLMENT.has(from.fulfillment) ||
|
|
23
|
+
(from.payment === 'paid' && from.fulfillment === 'fulfilled')) {
|
|
24
|
+
throw new Error(`Order ${orderId} cannot be resumed from ${from.payment} × ${from.fulfillment}`);
|
|
25
|
+
}
|
|
26
|
+
// Keeps the state; only parked (on_hold) / draft move.
|
|
27
|
+
const leavesParked = from.fulfillment === 'on_hold' || from.fulfillment === 'draft';
|
|
28
|
+
const to = {
|
|
29
|
+
payment: from.payment,
|
|
30
|
+
fulfillment: !leavesParked ? from.fulfillment : from.payment === 'unpaid' ? 'draft' : 'in_progress',
|
|
31
|
+
};
|
|
32
|
+
restoreMockCartFromOrder(order);
|
|
33
|
+
const parkedIndex = MOCK_PARKED_ORDERS.findIndex((o) => o._id === orderId);
|
|
34
|
+
if (parkedIndex !== -1)
|
|
35
|
+
MOCK_PARKED_ORDERS.splice(parkedIndex, 1);
|
|
36
|
+
mockPublishEvent('cart', 'cart-created', { orderId });
|
|
37
|
+
mockPublishEvent('order-state', 'state-transition-completed', {
|
|
38
|
+
orderId,
|
|
39
|
+
from,
|
|
40
|
+
to,
|
|
41
|
+
timestamp: new Date().toISOString(),
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
order: {
|
|
46
|
+
...order,
|
|
47
|
+
paymentState: to.payment,
|
|
48
|
+
fulfillmentState: to.fulfillment,
|
|
49
|
+
inCart: { active: true, stationId: null, since: new Date().toISOString() },
|
|
50
|
+
},
|
|
51
|
+
from,
|
|
52
|
+
to,
|
|
53
|
+
timestamp: new Date().toISOString(),
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CFOrder } from '../../CommonTypes';
|
|
2
|
+
import type { CFStatePair } from '../../common-types/order-state';
|
|
3
|
+
export interface ResumeOrderParams {
|
|
4
|
+
/** The order to load back into the cart. Must be open — see the README for which states resume. */
|
|
5
|
+
orderId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ResumeOrderResponse {
|
|
8
|
+
success: boolean;
|
|
9
|
+
/** The resumed order, re-read after the transition. */
|
|
10
|
+
order: CFOrder;
|
|
11
|
+
/** State before resuming. */
|
|
12
|
+
from: CFStatePair;
|
|
13
|
+
/** State after resuming — `draft` when nothing was paid, otherwise the order stays out of the cart states. */
|
|
14
|
+
to: CFStatePair;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
}
|
|
17
|
+
export type ResumeOrder = (params: ResumeOrderParams) => Promise<ResumeOrderResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import { ResumeParkedOrder } from
|
|
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
|
|
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(
|
|
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(
|
|
44
|
+
throw new Error('Parked order not found');
|
|
21
45
|
}
|
|
22
|
-
|
|
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(
|
|
50
|
-
mockPublishEvent(
|
|
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,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,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,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,27 @@
|
|
|
1
|
+
import { MOCK_ORDERS, MOCK_PARKED_ORDERS, mockPublishEvent } from '../../demo/database';
|
|
2
|
+
/** Type for the demo's live cart, which has no order until it is paid or parked. */
|
|
3
|
+
let mockCartOrderType = null;
|
|
4
|
+
export const normalizeOrderType = (value) => {
|
|
5
|
+
if (value === null)
|
|
6
|
+
return null;
|
|
7
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
8
|
+
throw new Error('setOrderType: orderType must be a non-empty string or null');
|
|
9
|
+
}
|
|
10
|
+
return value.trim();
|
|
11
|
+
};
|
|
12
|
+
export const mockSetOrderType = async (params) => {
|
|
13
|
+
console.log('[Mock] setOrderType called', params);
|
|
14
|
+
const orderType = normalizeOrderType(params?.orderType);
|
|
15
|
+
const timestamp = new Date().toISOString();
|
|
16
|
+
if (!params.orderId) {
|
|
17
|
+
mockCartOrderType = orderType;
|
|
18
|
+
return { success: true, orderId: null, orderType: mockCartOrderType, timestamp };
|
|
19
|
+
}
|
|
20
|
+
const order = [...MOCK_ORDERS, ...MOCK_PARKED_ORDERS].find((o) => o._id === params.orderId);
|
|
21
|
+
if (!order) {
|
|
22
|
+
throw new Error(`Order with ID ${params.orderId} not found`);
|
|
23
|
+
}
|
|
24
|
+
order.orderType = orderType;
|
|
25
|
+
mockPublishEvent('orders', 'order-updated', { order });
|
|
26
|
+
return { success: true, orderId: order._id, orderType, timestamp };
|
|
27
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface SetOrderTypeParams {
|
|
2
|
+
/**
|
|
3
|
+
* Order to label. Omit to target the live cart — including a cart that isn't an
|
|
4
|
+
* order yet; the type is carried onto the order when it's created.
|
|
5
|
+
*/
|
|
6
|
+
orderId?: string;
|
|
7
|
+
/** Any non-empty label (e.g. 'takeout', 'pickup', 'delivery'), or null to clear it. */
|
|
8
|
+
orderType: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface SetOrderTypeResponse {
|
|
11
|
+
success: boolean;
|
|
12
|
+
/** The order that was updated, or null when the live cart has no order yet. */
|
|
13
|
+
orderId: string | null;
|
|
14
|
+
orderType: string | null;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
}
|
|
17
|
+
export type SetOrderType = (params: SetOrderTypeParams) => Promise<SetOrderTypeResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,7 +7,7 @@ export interface CFStatePair {
|
|
|
7
7
|
payment: string;
|
|
8
8
|
fulfillment: string;
|
|
9
9
|
}
|
|
10
|
-
export type CFBlockedBy =
|
|
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
|
+
}
|
package/dist/demo/database.d.ts
CHANGED
|
@@ -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.
|
package/dist/demo/database.js
CHANGED
|
@@ -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
|
}
|