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

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get MOTO config action
3
+ * Calls the getMotoConfig action on the parent window
4
+ */
5
+ import type { GetMotoConfig } from './types';
6
+ export declare const getMotoConfig: GetMotoConfig;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Get MOTO config action
3
+ * Calls the getMotoConfig action on the parent window
4
+ */
5
+ import { commandFrameClient } from '../../client';
6
+ export const getMotoConfig = async () => {
7
+ return await commandFrameClient.call('getMotoConfig', undefined);
8
+ };
@@ -0,0 +1,7 @@
1
+ import { GetMotoConfig } from './types';
2
+ /**
3
+ * The mock has no Adyen account to mount card fields against, so it answers honestly: not
4
+ * available. A flow that hides its manual card tender on `available: false` behaves the same
5
+ * in a preview as on a host without a key.
6
+ */
7
+ export declare const mockGetMotoConfig: GetMotoConfig;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The mock has no Adyen account to mount card fields against, so it answers honestly: not
3
+ * available. A flow that hides its manual card tender on `available: false` behaves the same
4
+ * in a preview as on a host without a key.
5
+ */
6
+ export const mockGetMotoConfig = async () => {
7
+ console.log('[Mock] getMotoConfig called');
8
+ return { success: true, timestamp: new Date().toISOString(), available: false, reason: 'no-client-key' };
9
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Get MOTO config — everything a flow needs to take a keyed (card-not-present) payment itself:
3
+ * mount the processor's own card-entry fields, then send what they produce to `chargeMoto`.
4
+ */
5
+ /** Why manual card entry is not available here. */
6
+ export type MotoUnavailableReason =
7
+ /** The company does not take new sales on Adyen (keyed charges are Adyen-only today). */
8
+ 'provider-unsupported'
9
+ /** The host injected no Adyen client key (an older host, or an environment without one). */
10
+ | 'no-client-key'
11
+ /** The company's Adyen integration has no country yet. */
12
+ | 'no-country'
13
+ /** No active company. */
14
+ | 'no-company';
15
+ export type GetMotoConfigResponse = {
16
+ success: boolean;
17
+ timestamp: string;
18
+ } & ({
19
+ available: true;
20
+ provider: 'adyen';
21
+ /**
22
+ * Adyen's PUBLISHABLE client key for `@adyen/adyen-web`'s `AdyenCheckout({ clientKey })`.
23
+ * Injected by the host at runtime — never bake one into a flow build.
24
+ */
25
+ clientKey: string;
26
+ /** `AdyenCheckout({ environment })`. */
27
+ environment: 'test' | 'live';
28
+ /** The company's country, ISO 3166-1 alpha-2 — `AdyenCheckout({ countryCode })`. */
29
+ countryCode: string;
30
+ } | {
31
+ available: false;
32
+ reason: MotoUnavailableReason;
33
+ });
34
+ export type GetMotoConfig = () => Promise<GetMotoConfigResponse>;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Get MOTO config — everything a flow needs to take a keyed (card-not-present) payment itself:
3
+ * mount the processor's own card-entry fields, then send what they produce to `chargeMoto`.
4
+ */
5
+ export {};
@@ -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/dist/index.d.ts CHANGED
@@ -62,6 +62,7 @@ export declare const command: {
62
62
  readonly integrationPayment: import(".").IntegrationPayment;
63
63
  readonly createPaymentLink: import(".").CreatePaymentLink;
64
64
  readonly chargeMoto: import(".").ChargeMoto;
65
+ readonly getMotoConfig: import(".").GetMotoConfig;
65
66
  readonly addCustomerNote: import(".").AddCustomerNote;
66
67
  readonly removeCustomerNote: import(".").RemoveCustomerNote;
67
68
  readonly removeCustomerFromCart: import(".").RemoveCustomerFromCart;
@@ -216,6 +217,7 @@ export type { RedeemPayment, RedeemPaymentParams, RedeemPaymentResponse } from '
216
217
  export type { IntegrationPayment, IntegrationPaymentParams, IntegrationPaymentResponse, IntegrationEmvData, } from './actions/integration-payment/types';
217
218
  export type { CreatePaymentLink, CreatePaymentLinkParams, CreatePaymentLinkResponse, } from './actions/create-payment-link/types';
218
219
  export type { ChargeMoto, ChargeMotoParams, ChargeMotoResponse, ChargeMotoCardFields, } from './actions/charge-moto/types';
220
+ export type { GetMotoConfig, GetMotoConfigResponse, MotoUnavailableReason } from './actions/get-moto-config/types';
219
221
  export type { AddCustomerNote, AddCustomerNoteParams, AddCustomerNoteResponse, } from './actions/add-customer-note/types';
220
222
  export type { RemoveCustomerNote, RemoveCustomerNoteParams, RemoveCustomerNoteResponse, } from './actions/remove-customer-note/types';
221
223
  export type { RemoveCustomerFromCart, RemoveCustomerFromCartResponse } from './actions/remove-customer-from-cart/types';
package/dist/index.js CHANGED
@@ -62,6 +62,7 @@ import { redeemPayment } from './actions/redeem-payment/action';
62
62
  import { integrationPayment } from './actions/integration-payment/action';
63
63
  import { createPaymentLink } from './actions/create-payment-link/action';
64
64
  import { chargeMoto } from './actions/charge-moto/action';
65
+ import { getMotoConfig } from './actions/get-moto-config/action';
65
66
  // Customer Actions
66
67
  import { addCustomerNote } from './actions/add-customer-note/action';
67
68
  import { removeCustomerNote } from './actions/remove-customer-note/action';
@@ -218,6 +219,7 @@ export const command = {
218
219
  integrationPayment,
219
220
  createPaymentLink,
220
221
  chargeMoto,
222
+ getMotoConfig,
221
223
  // Customer Actions
222
224
  addCustomerNote,
223
225
  removeCustomerNote,
@@ -35,6 +35,7 @@ import { mockRecordExternalPayment } from '../../actions/record-external-payment
35
35
  import { mockGetCashRoundingAmount } from '../../actions/get-cash-rounding-amount/mock';
36
36
  import { mockCreatePaymentLink } from '../../actions/create-payment-link/mock';
37
37
  import { mockChargeMoto } from '../../actions/charge-moto/mock';
38
+ import { mockGetMotoConfig } from '../../actions/get-moto-config/mock';
38
39
  import { mockGetTimeClockStatus } from '../../actions/get-time-clock-status/mock';
39
40
  import { mockClearCart } from '../../actions/clear-cart/mock';
40
41
  import { mockDeleteParkedOrder } from '../../actions/delete-parked-order/mock';
@@ -151,6 +152,7 @@ export const RENDER_MOCKS = {
151
152
  getCashRoundingAmount: mockGetCashRoundingAmount,
152
153
  createPaymentLink: mockCreatePaymentLink,
153
154
  chargeMoto: mockChargeMoto,
155
+ getMotoConfig: mockGetMotoConfig,
154
156
  clearCart: mockClearCart,
155
157
  deleteParkedOrder: mockDeleteParkedOrder,
156
158
  voidOrder: mockVoidOrder,
@@ -1,4 +1,4 @@
1
- import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, GetCustomStockActions, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetProductModifierSelections, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, ResumeOrder, SetOrderMetadata, AssignOrderUser, ReleaseFromCart, SetOrderType, SetScheduledFor, SetOrderStatus, GetOrderStatuses, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, RecordExternalPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount, GetActiveOrder, GetActiveCustomer, SetActiveCustomer, GetActiveOutlet, GetActiveStation, GetActiveSession, GetActiveUser, SetActiveUser, SetActiveRefund, RemoveProductDiscount, RemoveProductFee, RemoveProductNote, RemoveCartFee, RemoveOrderNote, RemoveCustomSale, RemoveNonRevenueItem, CanTransition, GetAvailableTransitions, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, GetBookingResources, GetBookingAvailability, GetBookings, HoldBooking, AddBookingToCart, RemoveBookingFromCart, CancelBooking, CreatePaymentLink, ChargeMoto, GetTimeClockStatus } from '../../index';
1
+ import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, GetCustomStockActions, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetProductModifierSelections, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, ResumeOrder, SetOrderMetadata, AssignOrderUser, ReleaseFromCart, SetOrderType, SetScheduledFor, SetOrderStatus, GetOrderStatuses, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, RecordExternalPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount, GetActiveOrder, GetActiveCustomer, SetActiveCustomer, GetActiveOutlet, GetActiveStation, GetActiveSession, GetActiveUser, SetActiveUser, SetActiveRefund, RemoveProductDiscount, RemoveProductFee, RemoveProductNote, RemoveCartFee, RemoveOrderNote, RemoveCustomSale, RemoveNonRevenueItem, CanTransition, GetAvailableTransitions, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, GetBookingResources, GetBookingAvailability, GetBookings, HoldBooking, AddBookingToCart, RemoveBookingFromCart, CancelBooking, CreatePaymentLink, ChargeMoto, GetMotoConfig, GetTimeClockStatus } from '../../index';
2
2
  export interface RenderProviderActions {
3
3
  exampleFunction: ExampleFunction;
4
4
  getProducts: GetProducts;
@@ -62,6 +62,7 @@ export interface RenderProviderActions {
62
62
  integrationPayment: IntegrationPayment;
63
63
  createPaymentLink: CreatePaymentLink;
64
64
  chargeMoto: ChargeMoto;
65
+ getMotoConfig: GetMotoConfig;
65
66
  addNonRevenueItem: AddNonRevenueItem;
66
67
  addCustomerNote: AddCustomerNote;
67
68
  removeCustomerNote: RemoveCustomerNote;
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.5",
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.9"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",