@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.
Files changed (80) hide show
  1. package/dist/CommonTypes.d.ts +1 -4
  2. package/dist/actions/get-current-cart/mock.js +0 -3
  3. package/dist/actions/get-current-cart/types.d.ts +0 -6
  4. package/dist/actions/get-orders/action.d.ts +1 -1
  5. package/dist/actions/get-orders/action.js +2 -2
  6. package/dist/actions/get-orders/mock.d.ts +1 -1
  7. package/dist/actions/get-orders/mock.js +19 -74
  8. package/dist/actions/get-orders/types.d.ts +2 -33
  9. package/dist/actions/resume-parked-order/mock.d.ts +0 -5
  10. package/dist/actions/resume-parked-order/mock.js +24 -25
  11. package/dist/actions/void-order/mock.js +7 -17
  12. package/dist/actions/void-order/types.d.ts +2 -6
  13. package/dist/common-types/order-state.d.ts +1 -20
  14. package/dist/demo/database.d.ts +0 -4
  15. package/dist/demo/database.js +0 -29
  16. package/dist/index.d.ts +0 -20
  17. package/dist/index.js +0 -20
  18. package/dist/projects/render/mocks.js +0 -20
  19. package/dist/projects/render/types.d.ts +1 -11
  20. package/package.json +2 -2
  21. package/dist/actions/assign-order-user/action.d.ts +0 -6
  22. package/dist/actions/assign-order-user/action.js +0 -8
  23. package/dist/actions/assign-order-user/mock.d.ts +0 -2
  24. package/dist/actions/assign-order-user/mock.js +0 -30
  25. package/dist/actions/assign-order-user/types.d.ts +0 -15
  26. package/dist/actions/assign-order-user/types.js +0 -1
  27. package/dist/actions/get-moto-config/action.d.ts +0 -6
  28. package/dist/actions/get-moto-config/action.js +0 -8
  29. package/dist/actions/get-moto-config/mock.d.ts +0 -7
  30. package/dist/actions/get-moto-config/mock.js +0 -9
  31. package/dist/actions/get-moto-config/types.d.ts +0 -34
  32. package/dist/actions/get-moto-config/types.js +0 -5
  33. package/dist/actions/get-order-statuses/action.d.ts +0 -6
  34. package/dist/actions/get-order-statuses/action.js +0 -8
  35. package/dist/actions/get-order-statuses/mock.d.ts +0 -2
  36. package/dist/actions/get-order-statuses/mock.js +0 -5
  37. package/dist/actions/get-order-statuses/types.d.ts +0 -8
  38. package/dist/actions/get-order-statuses/types.js +0 -1
  39. package/dist/actions/record-external-payment/action.d.ts +0 -6
  40. package/dist/actions/record-external-payment/action.js +0 -8
  41. package/dist/actions/record-external-payment/mock.d.ts +0 -2
  42. package/dist/actions/record-external-payment/mock.js +0 -36
  43. package/dist/actions/record-external-payment/types.d.ts +0 -37
  44. package/dist/actions/record-external-payment/types.js +0 -1
  45. package/dist/actions/release-from-cart/action.d.ts +0 -6
  46. package/dist/actions/release-from-cart/action.js +0 -8
  47. package/dist/actions/release-from-cart/mock.d.ts +0 -2
  48. package/dist/actions/release-from-cart/mock.js +0 -26
  49. package/dist/actions/release-from-cart/types.d.ts +0 -8
  50. package/dist/actions/release-from-cart/types.js +0 -1
  51. package/dist/actions/resume-order/action.d.ts +0 -6
  52. package/dist/actions/resume-order/action.js +0 -8
  53. package/dist/actions/resume-order/mock.d.ts +0 -2
  54. package/dist/actions/resume-order/mock.js +0 -55
  55. package/dist/actions/resume-order/types.d.ts +0 -17
  56. package/dist/actions/resume-order/types.js +0 -1
  57. package/dist/actions/set-order-metadata/action.d.ts +0 -6
  58. package/dist/actions/set-order-metadata/action.js +0 -8
  59. package/dist/actions/set-order-metadata/mock.d.ts +0 -5
  60. package/dist/actions/set-order-metadata/mock.js +0 -38
  61. package/dist/actions/set-order-metadata/types.d.ts +0 -20
  62. package/dist/actions/set-order-metadata/types.js +0 -1
  63. package/dist/actions/set-order-status/action.d.ts +0 -6
  64. package/dist/actions/set-order-status/action.js +0 -8
  65. package/dist/actions/set-order-status/mock.d.ts +0 -3
  66. package/dist/actions/set-order-status/mock.js +0 -44
  67. package/dist/actions/set-order-status/types.d.ts +0 -25
  68. package/dist/actions/set-order-status/types.js +0 -1
  69. package/dist/actions/set-order-type/action.d.ts +0 -6
  70. package/dist/actions/set-order-type/action.js +0 -8
  71. package/dist/actions/set-order-type/mock.d.ts +0 -3
  72. package/dist/actions/set-order-type/mock.js +0 -27
  73. package/dist/actions/set-order-type/types.d.ts +0 -17
  74. package/dist/actions/set-order-type/types.js +0 -1
  75. package/dist/actions/set-scheduled-for/action.d.ts +0 -6
  76. package/dist/actions/set-scheduled-for/action.js +0 -8
  77. package/dist/actions/set-scheduled-for/mock.d.ts +0 -4
  78. package/dist/actions/set-scheduled-for/mock.js +0 -45
  79. package/dist/actions/set-scheduled-for/types.d.ts +0 -22
  80. package/dist/actions/set-scheduled-for/types.js +0 -1
@@ -34,11 +34,9 @@ import { mockAssignCustomer } from '../../actions/assign-customer/mock';
34
34
  import { mockAuthenticateUser } from '../../actions/authenticate-user/mock';
35
35
  import { mockCalculateRefundTotal } from '../../actions/calculate-refund-total/mock';
36
36
  import { mockCashPayment } from '../../actions/cash-payment/mock';
37
- import { mockRecordExternalPayment } from '../../actions/record-external-payment/mock';
38
37
  import { mockGetCashRoundingAmount } from '../../actions/get-cash-rounding-amount/mock';
39
38
  import { mockCreatePaymentLink } from '../../actions/create-payment-link/mock';
40
39
  import { mockChargeMoto } from '../../actions/charge-moto/mock';
41
- import { mockGetMotoConfig } from '../../actions/get-moto-config/mock';
42
40
  import { mockGetTimeClockStatus } from '../../actions/get-time-clock-status/mock';
43
41
  import { mockClearCart } from '../../actions/clear-cart/mock';
44
42
  import { mockDeleteParkedOrder } from '../../actions/delete-parked-order/mock';
@@ -72,14 +70,6 @@ import { mockCheckPermission } from '../../actions/check-permission/mock';
72
70
  import { mockRemoveCustomerFromCart } from '../../actions/remove-customer-from-cart/mock';
73
71
  import { mockResetRefundDetails } from '../../actions/reset-refund-details/mock';
74
72
  import { mockResumeParkedOrder } from '../../actions/resume-parked-order/mock';
75
- import { mockResumeOrder } from '../../actions/resume-order/mock';
76
- import { mockSetOrderMetadata } from '../../actions/set-order-metadata/mock';
77
- import { mockAssignOrderUser } from '../../actions/assign-order-user/mock';
78
- import { mockReleaseFromCart } from '../../actions/release-from-cart/mock';
79
- import { mockSetOrderType } from '../../actions/set-order-type/mock';
80
- import { mockSetScheduledFor } from '../../actions/set-scheduled-for/mock';
81
- import { mockSetOrderStatus } from '../../actions/set-order-status/mock';
82
- import { mockGetOrderStatuses } from '../../actions/get-order-statuses/mock';
83
73
  import { mockSelectAllRefundItems } from '../../actions/select-all-refund-items/mock';
84
74
  import { mockSetRefundStockAction } from '../../actions/set-refund-stock-action/mock';
85
75
  import { mockShowConfirmation } from '../../actions/show-confirmation/mock';
@@ -154,11 +144,9 @@ export const RENDER_MOCKS = {
154
144
  authenticateUser: mockAuthenticateUser,
155
145
  calculateRefundTotal: mockCalculateRefundTotal,
156
146
  cashPayment: mockCashPayment,
157
- recordExternalPayment: mockRecordExternalPayment,
158
147
  getCashRoundingAmount: mockGetCashRoundingAmount,
159
148
  createPaymentLink: mockCreatePaymentLink,
160
149
  chargeMoto: mockChargeMoto,
161
- getMotoConfig: mockGetMotoConfig,
162
150
  clearCart: mockClearCart,
163
151
  deleteParkedOrder: mockDeleteParkedOrder,
164
152
  voidOrder: mockVoidOrder,
@@ -192,14 +180,6 @@ export const RENDER_MOCKS = {
192
180
  removeCartDiscount: mockRemoveCartDiscount,
193
181
  resetRefundDetails: mockResetRefundDetails,
194
182
  resumeParkedOrder: mockResumeParkedOrder,
195
- resumeOrder: mockResumeOrder,
196
- setOrderMetadata: mockSetOrderMetadata,
197
- assignOrderUser: mockAssignOrderUser,
198
- releaseFromCart: mockReleaseFromCart,
199
- setOrderType: mockSetOrderType,
200
- setScheduledFor: mockSetScheduledFor,
201
- setOrderStatus: mockSetOrderStatus,
202
- getOrderStatuses: mockGetOrderStatuses,
203
183
  selectAllRefundItems: mockSelectAllRefundItems,
204
184
  setRefundStockAction: mockSetRefundStockAction,
205
185
  showConfirmation: mockShowConfirmation,
@@ -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, GetCompositePrice, GetCompositeAvailability, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, SetVariantUnavailable, 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';
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, GetCompositePrice, GetCompositeAvailability, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, SetVariantUnavailable, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, 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';
2
2
  export interface RenderProviderActions {
3
3
  exampleFunction: ExampleFunction;
4
4
  getProducts: GetProducts;
@@ -44,19 +44,10 @@ export interface RenderProviderActions {
44
44
  clearCart: ClearCart;
45
45
  parkOrder: ParkOrder;
46
46
  resumeParkedOrder: ResumeParkedOrder;
47
- resumeOrder: ResumeOrder;
48
- setOrderMetadata: SetOrderMetadata;
49
- assignOrderUser: AssignOrderUser;
50
- releaseFromCart: ReleaseFromCart;
51
- setOrderType: SetOrderType;
52
- setScheduledFor: SetScheduledFor;
53
- setOrderStatus: SetOrderStatus;
54
- getOrderStatuses: GetOrderStatuses;
55
47
  deleteParkedOrder: DeleteParkedOrder;
56
48
  voidOrder: VoidOrder;
57
49
  initiateRefund: InitiateRefund;
58
50
  cashPayment: CashPayment;
59
- recordExternalPayment: RecordExternalPayment;
60
51
  getCashRoundingAmount: GetCashRoundingAmount;
61
52
  tapToPayPayment: TapToPayPayment;
62
53
  terminalPayment: TerminalPayment;
@@ -65,7 +56,6 @@ export interface RenderProviderActions {
65
56
  integrationPayment: IntegrationPayment;
66
57
  createPaymentLink: CreatePaymentLink;
67
58
  chargeMoto: ChargeMoto;
68
- getMotoConfig: GetMotoConfig;
69
59
  addNonRevenueItem: AddNonRevenueItem;
70
60
  addCustomerNote: AddCustomerNote;
71
61
  removeCustomerNote: RemoveCustomerNote;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.11.0",
3
+ "version": "0.12.0-staging.1",
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.8.0"
60
+ "@final-commerce/common": "2.9.0-staging.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@commitlint/cli": "^19.0.0",
@@ -1,6 +0,0 @@
1
- /**
2
- * Assign order user action
3
- * Calls the assignOrderUser action on the parent window
4
- */
5
- import type { AssignOrderUser } from './types';
6
- export declare const assignOrderUser: AssignOrderUser;
@@ -1,8 +0,0 @@
1
- /**
2
- * Assign order user action
3
- * Calls the assignOrderUser action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const assignOrderUser = async (params) => {
7
- return await commandFrameClient.call('assignOrderUser', params);
8
- };
@@ -1,2 +0,0 @@
1
- import type { AssignOrderUser } from './types';
2
- export declare const mockAssignOrderUser: AssignOrderUser;
@@ -1,30 +0,0 @@
1
- import { MOCK_ORDERS, MOCK_PARKED_ORDERS, MOCK_USERS, mockPublishEvent } from '../../demo/database';
2
- export const mockAssignOrderUser = async (params) => {
3
- console.log('[Mock] assignOrderUser called', params);
4
- if (!params?.orderId) {
5
- throw new Error('assignOrderUser: the demo has no live-cart order — pass an orderId');
6
- }
7
- if (params.userId !== null && typeof params.userId !== 'string') {
8
- throw new Error('assignOrderUser: userId must be a user id or null');
9
- }
10
- const order = [...MOCK_ORDERS, ...MOCK_PARKED_ORDERS].find((o) => o._id === params.orderId);
11
- if (!order) {
12
- throw new Error(`Order with ID ${params.orderId} not found`);
13
- }
14
- if (params.userId === null) {
15
- order.assignedUser = null;
16
- }
17
- else if (order.assignedUser?.userId !== params.userId) {
18
- if (!MOCK_USERS.some((u) => u.id === params.userId)) {
19
- throw new Error(`User with ID ${params.userId} not found`);
20
- }
21
- order.assignedUser = { userId: params.userId, assignedAt: new Date().toISOString() };
22
- }
23
- mockPublishEvent('orders', 'order-updated', { order });
24
- return {
25
- success: true,
26
- orderId: order._id,
27
- assignedUser: order.assignedUser ?? null,
28
- timestamp: new Date().toISOString(),
29
- };
30
- };
@@ -1,15 +0,0 @@
1
- import type { CFOrderAssignedUser } from '../../CommonTypes';
2
- export interface AssignOrderUserParams {
3
- /** Order to assign. Omit to target the live cart's order — it must already exist (parked, paid or transitioned). */
4
- orderId?: string;
5
- /** User to assign (e.g. the driver), or null to unassign. Replaces any current assignee. */
6
- userId: string | null;
7
- }
8
- export interface AssignOrderUserResponse {
9
- success: boolean;
10
- orderId: string;
11
- /** The order's assignee after the call; null when unassigned. */
12
- assignedUser: CFOrderAssignedUser | null;
13
- timestamp: string;
14
- }
15
- export type AssignOrderUser = (params: AssignOrderUserParams) => Promise<AssignOrderUserResponse>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
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;
@@ -1,8 +0,0 @@
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
- };
@@ -1,7 +0,0 @@
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;
@@ -1,9 +0,0 @@
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
- };
@@ -1,34 +0,0 @@
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>;
@@ -1,5 +0,0 @@
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,6 +0,0 @@
1
- /**
2
- * Get order statuses action
3
- * Calls the getOrderStatuses action on the parent window
4
- */
5
- import type { GetOrderStatuses } from './types';
6
- export declare const getOrderStatuses: GetOrderStatuses;
@@ -1,8 +0,0 @@
1
- /**
2
- * Get order statuses action
3
- * Calls the getOrderStatuses action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const getOrderStatuses = async () => {
7
- return await commandFrameClient.call('getOrderStatuses', undefined);
8
- };
@@ -1,2 +0,0 @@
1
- import type { GetOrderStatuses } from './types';
2
- export declare const mockGetOrderStatuses: GetOrderStatuses;
@@ -1,5 +0,0 @@
1
- import { MOCK_ORDER_STATUSES } from '../../demo/database';
2
- export const mockGetOrderStatuses = async () => {
3
- console.log('[Mock] getOrderStatuses called');
4
- return { success: true, statuses: MOCK_ORDER_STATUSES.map((s) => ({ ...s })), timestamp: new Date().toISOString() };
5
- };
@@ -1,8 +0,0 @@
1
- import type { CFOrderStatusDefinition } from '../../common-types/order-state';
2
- export interface GetOrderStatusesResponse {
3
- success: boolean;
4
- /** The running flow's order statuses, in the order they were defined. Empty when it defines none. */
5
- statuses: CFOrderStatusDefinition[];
6
- timestamp: string;
7
- }
8
- export type GetOrderStatuses = () => Promise<GetOrderStatusesResponse>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Record external payment action
3
- * Calls the recordExternalPayment action on the parent window
4
- */
5
- import type { RecordExternalPayment } from './types';
6
- export declare const recordExternalPayment: RecordExternalPayment;
@@ -1,8 +0,0 @@
1
- /**
2
- * Record external payment action
3
- * Calls the recordExternalPayment action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const recordExternalPayment = async (params) => {
7
- return await commandFrameClient.call('recordExternalPayment', params);
8
- };
@@ -1,2 +0,0 @@
1
- import type { RecordExternalPayment } from './types';
2
- export declare const mockRecordExternalPayment: RecordExternalPayment;
@@ -1,36 +0,0 @@
1
- import { isFulfillmentState } from '@final-commerce/common';
2
- import { applyMockPayment, MOCK_CART } from '../../demo/database';
3
- export const mockRecordExternalPayment = async (params) => {
4
- console.log('[Mock] recordExternalPayment called', params);
5
- const label = typeof params?.label === 'string' ? params.label.trim() : '';
6
- if (!label) {
7
- throw new Error('recordExternalPayment: label is required');
8
- }
9
- const balanceDue = MOCK_CART.amountToBeCharged ?? MOCK_CART.total;
10
- const amount = params.amount ?? balanceDue;
11
- // Same rule as the host: positive, except on a zero-balance checkout.
12
- if (!Number.isFinite(amount) || amount < 0 || (amount === 0 && balanceDue > 0)) {
13
- throw new Error('recordExternalPayment: amount must be a positive integer (minor units)');
14
- }
15
- const target = params.checkoutFulfillmentTarget;
16
- if (target !== undefined && !isFulfillmentState(target)) {
17
- throw new Error(`recordExternalPayment: invalid checkoutFulfillmentTarget "${String(target)}"`);
18
- }
19
- if (amount > balanceDue) {
20
- throw new Error(`recordExternalPayment: amount ${amount} exceeds the balance due ${balanceDue}`);
21
- }
22
- const order = applyMockPayment(amount, 'external', label);
23
- const remainingBalance = MOCK_CART.remainingBalance ?? 0;
24
- return {
25
- success: true,
26
- amount,
27
- label,
28
- paymentType: 'external',
29
- change: 0,
30
- cashRounding: 0,
31
- order,
32
- saleFinalized: !!order,
33
- remainingBalance: order ? 0 : remainingBalance,
34
- timestamp: new Date().toISOString(),
35
- };
36
- };
@@ -1,37 +0,0 @@
1
- import { CFOrder } from '../../CommonTypes';
2
- export interface RecordExternalPaymentParams {
3
- /**
4
- * What the payment was — shown on the order and in reports, e.g. 'Paid online',
5
- * 'Uber Eats', 'Voucher'. Required; trimmed. Not checked against a list, so keep
6
- * labels consistent across flows.
7
- */
8
- label: string;
9
- /**
10
- * Amount to record, in integer MINOR currency units. Omit to record the full balance
11
- * due (completing the order). Below the balance due it records a partial payment —
12
- * the rest can be taken with any other tender. Above the balance due is an error.
13
- */
14
- amount?: number;
15
- /** Fulfillment state to land on after full payment, e.g. 'pending' to keep the order going to the kitchen. */
16
- checkoutFulfillmentTarget?: string;
17
- }
18
- export interface RecordExternalPaymentResponse {
19
- success: boolean;
20
- /** The amount recorded, in integer MINOR currency units. */
21
- amount: number;
22
- /** The label, as recorded. */
23
- label: string;
24
- paymentType: 'external';
25
- /** Always 0 — no money changes hands at the terminal. */
26
- change: number;
27
- /** Always 0 — cash rounding applies to cash only. */
28
- cashRounding: number;
29
- /** The order once the sale completes; null for a partial (split) leg. */
30
- order: CFOrder | null;
31
- /** True when this payment settled the remaining balance. */
32
- saleFinalized: boolean;
33
- /** Balance still due after this payment, in integer MINOR currency units. */
34
- remainingBalance: number;
35
- timestamp: string;
36
- }
37
- export type RecordExternalPayment = (params: RecordExternalPaymentParams) => Promise<RecordExternalPaymentResponse>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Release from cart action
3
- * Calls the releaseFromCart action on the parent window
4
- */
5
- import type { ReleaseFromCart } from './types';
6
- export declare const releaseFromCart: ReleaseFromCart;
@@ -1,8 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import type { ReleaseFromCart } from './types';
2
- export declare const mockReleaseFromCart: ReleaseFromCart;
@@ -1,26 +0,0 @@
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
- };
@@ -1,8 +0,0 @@
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>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * Resume order action
3
- * Calls the resumeOrder action on the parent window
4
- */
5
- import type { ResumeOrder } from './types';
6
- export declare const resumeOrder: ResumeOrder;
@@ -1,8 +0,0 @@
1
- /**
2
- * Resume order action
3
- * Calls the resumeOrder action on the parent window
4
- */
5
- import { commandFrameClient } from '../../client';
6
- export const resumeOrder = async (params) => {
7
- return await commandFrameClient.call('resumeOrder', params);
8
- };
@@ -1,2 +0,0 @@
1
- import type { ResumeOrder } from './types';
2
- export declare const mockResumeOrder: ResumeOrder;
@@ -1,55 +0,0 @@
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
- };
@@ -1,17 +0,0 @@
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>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
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;
@@ -1,8 +0,0 @@
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
- };
@@ -1,5 +0,0 @@
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;
@@ -1,38 +0,0 @@
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
- };