@final-commerce/command-frame 0.3.0-beta.3 → 0.3.0-beta.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.
Files changed (123) hide show
  1. package/README.md +50 -28
  2. package/dist/CommonTypes.d.ts +2 -1
  3. package/dist/actions/add-cart-discount/mock.js +6 -3
  4. package/dist/actions/add-cart-fee/mock.js +6 -6
  5. package/dist/actions/add-custom-sale/mock.js +7 -2
  6. package/dist/actions/add-order-note/mock.js +3 -1
  7. package/dist/actions/apply-transition/action.d.ts +2 -0
  8. package/dist/actions/apply-transition/action.js +4 -0
  9. package/dist/actions/apply-transition/mock.d.ts +6 -0
  10. package/dist/actions/apply-transition/mock.js +33 -0
  11. package/dist/actions/apply-transition/types.d.ts +17 -0
  12. package/dist/actions/can-transition/action.d.ts +2 -0
  13. package/dist/actions/can-transition/action.js +4 -0
  14. package/dist/actions/can-transition/mock.d.ts +6 -0
  15. package/dist/actions/can-transition/mock.js +28 -0
  16. package/dist/actions/can-transition/types.d.ts +11 -0
  17. package/dist/actions/cash-payment/mock.js +12 -18
  18. package/dist/actions/cash-payment/types.d.ts +5 -0
  19. package/dist/actions/delete-parked-order/mock.js +3 -1
  20. package/dist/actions/delete-parked-order/types.d.ts +3 -0
  21. package/dist/actions/extension-payment/types.d.ts +8 -3
  22. package/dist/actions/get-available-transitions/action.d.ts +2 -0
  23. package/dist/actions/get-available-transitions/action.js +4 -0
  24. package/dist/actions/get-available-transitions/mock.d.ts +6 -0
  25. package/dist/actions/get-available-transitions/mock.js +26 -0
  26. package/dist/actions/get-available-transitions/types.d.ts +9 -0
  27. package/dist/actions/get-context/mock.js +1 -1
  28. package/dist/actions/get-orders/mock.js +3 -3
  29. package/dist/actions/get-products/mock.js +6 -1
  30. package/dist/actions/get-products/types.d.ts +2 -0
  31. package/dist/actions/get-smart-grid-layout/mock.d.ts +1 -1
  32. package/dist/actions/get-smart-grid-layout/mock.js +3 -1
  33. package/dist/actions/get-smart-grid-layout/types.d.ts +1 -3
  34. package/dist/actions/initiate-refund/types.d.ts +3 -0
  35. package/dist/actions/integration-payment/types.d.ts +48 -8
  36. package/dist/actions/open-extension-overlay/mock.js +1 -1
  37. package/dist/actions/open-extension-overlay/types.d.ts +1 -1
  38. package/dist/actions/park-order/mock.js +4 -1
  39. package/dist/actions/park-order/types.d.ts +3 -0
  40. package/dist/actions/partial-payment/mock.js +21 -3
  41. package/dist/actions/partial-payment/types.d.ts +5 -0
  42. package/dist/actions/process-partial-refund/types.d.ts +3 -0
  43. package/dist/actions/redeem-payment/types.d.ts +9 -5
  44. package/dist/actions/remove-custom-sale/mock.d.ts +2 -0
  45. package/dist/actions/remove-custom-sale/mock.js +29 -0
  46. package/dist/actions/remove-customer-from-cart/mock.js +3 -1
  47. package/dist/actions/remove-order-note/mock.d.ts +2 -0
  48. package/dist/actions/remove-order-note/mock.js +12 -0
  49. package/dist/actions/remove-product-discount/mock.d.ts +2 -0
  50. package/dist/actions/remove-product-discount/mock.js +17 -0
  51. package/dist/actions/remove-product-fee/mock.d.ts +2 -0
  52. package/dist/actions/remove-product-fee/mock.js +17 -0
  53. package/dist/actions/remove-product-from-cart/mock.js +5 -5
  54. package/dist/actions/resolve-extension-overlay/mock.js +1 -1
  55. package/dist/actions/resume-parked-order/mock.js +4 -1
  56. package/dist/actions/resume-parked-order/types.d.ts +3 -0
  57. package/dist/actions/save-smart-grid-layout/mock.d.ts +1 -1
  58. package/dist/actions/save-smart-grid-layout/mock.js +3 -0
  59. package/dist/actions/save-smart-grid-layout/types.d.ts +1 -3
  60. package/dist/actions/tap-to-pay-payment/mock.js +5 -3
  61. package/dist/actions/tap-to-pay-payment/types.d.ts +5 -0
  62. package/dist/actions/terminal-payment/mock.js +4 -5
  63. package/dist/actions/terminal-payment/types.d.ts +5 -0
  64. package/dist/actions/update-cart-item-quantity/mock.js +9 -9
  65. package/dist/actions/vendara-payment/types.d.ts +5 -0
  66. package/dist/common-types/index.d.ts +1 -0
  67. package/dist/common-types/index.js +1 -0
  68. package/dist/common-types/order-state.d.ts +32 -0
  69. package/dist/common-types/order-state.js +6 -0
  70. package/dist/common-types/state-fragment.d.ts +77 -0
  71. package/dist/common-types/state-fragment.js +10 -0
  72. package/dist/demo/database.d.ts +12 -1
  73. package/dist/demo/database.js +173 -3
  74. package/dist/fragments/index.d.ts +1 -0
  75. package/dist/fragments/index.js +1 -0
  76. package/dist/fragments/preorder-no-deposit.d.ts +26 -0
  77. package/dist/fragments/preorder-no-deposit.js +166 -0
  78. package/dist/index.d.ts +21 -20
  79. package/dist/index.js +23 -21
  80. package/dist/interceptors/index.d.ts +21 -0
  81. package/dist/interceptors/index.js +53 -0
  82. package/dist/interceptors/types.d.ts +8 -16
  83. package/dist/projects/render/mocks.js +19 -17
  84. package/dist/projects/render/types.d.ts +7 -6
  85. package/dist/pubsub/topics/orders/index.js +10 -0
  86. package/dist/pubsub/topics/orders/state-transition-blocked/types.d.ts +16 -0
  87. package/dist/pubsub/topics/orders/state-transition-blocked/types.js +1 -0
  88. package/dist/pubsub/topics/orders/state-transition-completed/types.d.ts +15 -0
  89. package/dist/pubsub/topics/orders/state-transition-completed/types.js +1 -0
  90. package/dist/pubsub/topics/orders/types.d.ts +6 -2
  91. package/dist/pubsub/topics/orders/types.js +2 -0
  92. package/dist/pubsub/topics/split-payments/index.d.ts +12 -0
  93. package/dist/pubsub/topics/split-payments/index.js +22 -0
  94. package/dist/pubsub/topics/split-payments/split-payment-updated/types.d.ts +16 -0
  95. package/dist/pubsub/topics/split-payments/split-payment-updated/types.js +1 -0
  96. package/dist/pubsub/topics/split-payments/types.d.ts +10 -0
  97. package/dist/pubsub/topics/split-payments/types.js +5 -0
  98. package/dist/pubsub/topics/types.d.ts +2 -0
  99. package/package.json +3 -3
  100. package/dist/actions/extension-refund/constants.d.ts +0 -2
  101. package/dist/actions/extension-refund/constants.js +0 -2
  102. package/dist/actions/extension-refund/extension-refund-listener.d.ts +0 -11
  103. package/dist/actions/extension-refund/extension-refund-listener.js +0 -60
  104. package/dist/actions/extension-refund/types.d.ts +0 -32
  105. package/dist/actions/extension-refund/types.js +0 -5
  106. package/dist/actions/set-active-outlet/action.d.ts +0 -2
  107. package/dist/actions/set-active-outlet/action.js +0 -4
  108. package/dist/actions/set-active-outlet/mock.d.ts +0 -2
  109. package/dist/actions/set-active-outlet/mock.js +0 -16
  110. package/dist/actions/set-active-outlet/types.d.ts +0 -10
  111. package/dist/actions/set-active-session/action.d.ts +0 -2
  112. package/dist/actions/set-active-session/action.js +0 -4
  113. package/dist/actions/set-active-session/mock.d.ts +0 -2
  114. package/dist/actions/set-active-session/mock.js +0 -15
  115. package/dist/actions/set-active-session/types.d.ts +0 -10
  116. package/dist/actions/set-active-station/action.d.ts +0 -2
  117. package/dist/actions/set-active-station/action.js +0 -4
  118. package/dist/actions/set-active-station/mock.d.ts +0 -2
  119. package/dist/actions/set-active-station/mock.js +0 -16
  120. package/dist/actions/set-active-station/types.d.ts +0 -10
  121. /package/dist/actions/{set-active-outlet → apply-transition}/types.js +0 -0
  122. /package/dist/actions/{set-active-session → can-transition}/types.js +0 -0
  123. /package/dist/actions/{set-active-station → get-available-transitions}/types.js +0 -0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Split Payments Topic Definition
3
+ * Defines the split-payments topic and its available event types.
4
+ *
5
+ * This topic mirrors render's `activeEntities.splitPayment` Redux slice. The
6
+ * host (render) publishes the full current `CFSplitPayment` (or `null` when
7
+ * reset) on every mutation and on the command-frame handshake so consumers
8
+ * stay in sync without owning the underlying state.
9
+ */
10
+ export const splitPaymentsTopic = {
11
+ id: "split-payments",
12
+ name: "Split Payments",
13
+ description: "Topic for in-progress split-payment session updates",
14
+ eventTypes: [
15
+ {
16
+ id: "split-payment-updated",
17
+ name: "Split Payment Updated",
18
+ description: "Published whenever the host's split-payment slice mutates (partial added, reset, etc.); payload carries the full current slice or null."
19
+ }
20
+ ]
21
+ };
22
+ export * from "./types";
@@ -0,0 +1,16 @@
1
+ import type { CFSplitPayment } from "../../../../CommonTypes";
2
+ import type { TopicEvent } from "../../../types";
3
+ /**
4
+ * Payload for split-payment-updated event.
5
+ *
6
+ * Mirrors the host's full split-payment slice. When no split-payment session is
7
+ * active (initial state or after `resetSplitPayment`) the host publishes
8
+ * `{ splitPayment: null }` so subscribers can clear their mirror.
9
+ */
10
+ export interface SplitPaymentUpdatedPayload {
11
+ splitPayment: CFSplitPayment | null;
12
+ }
13
+ /**
14
+ * Typed event for split-payment-updated.
15
+ */
16
+ export type SplitPaymentUpdatedEvent = TopicEvent<SplitPaymentUpdatedPayload>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Split Payments Topic Types
3
+ * Aggregated types for all split-payment-related events.
4
+ */
5
+ export * from "./split-payment-updated/types";
6
+ import type { SplitPaymentUpdatedPayload } from "./split-payment-updated/types";
7
+ /** Union type for all split-payments event payloads. */
8
+ export type SplitPaymentsEventPayload = SplitPaymentUpdatedPayload;
9
+ /** Literal types for split-payments event IDs. */
10
+ export type SplitPaymentsEventType = "split-payment-updated";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Split Payments Topic Types
3
+ * Aggregated types for all split-payment-related events.
4
+ */
5
+ export * from "./split-payment-updated/types";
@@ -4,6 +4,7 @@ import { RefundsEventType, RefundsEventPayload } from "./refunds/types";
4
4
  import { ProductsEventType, ProductsEventPayload } from "./products/types";
5
5
  import { CartEventType, CartEventPayload } from "./cart/types";
6
6
  import { PaymentsEventType, PaymentsEventPayload } from "./payments/types";
7
+ import { SplitPaymentsEventType, SplitPaymentsEventPayload } from "./split-payments/types";
7
8
  import { CustomTablesEventPayload, CustomTablesEventType } from "./custom-tables/types";
8
9
  import { PrintEventType, PrintEventPayload } from "./print/types";
9
10
  import { OutletEventType, OutletEventPayload } from "./outlet/types";
@@ -21,6 +22,7 @@ export interface TopicEventPayloadMap {
21
22
  products: Record<ProductsEventType, ProductsEventPayload>;
22
23
  cart: Record<CartEventType, CartEventPayload>;
23
24
  payments: Record<PaymentsEventType, PaymentsEventPayload>;
25
+ "split-payments": Record<SplitPaymentsEventType, SplitPaymentsEventPayload>;
24
26
  customTables: Record<CustomTablesEventType, CustomTablesEventPayload>;
25
27
  print: Record<PrintEventType, PrintEventPayload>;
26
28
  outlet: Record<OutletEventType, OutletEventPayload>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.3.0-beta.3",
3
+ "version": "0.3.0-beta.5",
4
4
  "description": "Commands Frame library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "format": "prettier --write .",
24
24
  "format:check": "prettier --check .",
25
25
  "publish:npm": "npm publish --registry=https://registry.npmjs.org",
26
- "publish:github": "npm publish --registry=https://npm.pkg.github.com",
27
- "publish:all": "npm run publish:npm && npm run publish:github"
26
+ "publish:ar": "npm publish --registry=https://us-npm.pkg.dev/final-preproduction/npm/",
27
+ "publish:all": "npm run publish:npm && npm run publish:ar"
28
28
  },
29
29
  "keywords": [
30
30
  "final commerce",
@@ -1,2 +0,0 @@
1
- /** postMessage `action` for host → iframe extension refund requests. */
2
- export declare const EXTENSION_REFUND_REQUEST_ACTION = "extensionRefundRequest";
@@ -1,2 +0,0 @@
1
- /** postMessage `action` for host → iframe extension refund requests. */
2
- export const EXTENSION_REFUND_REQUEST_ACTION = "extensionRefundRequest";
@@ -1,11 +0,0 @@
1
- import type { ExtensionRefundParams, ExtensionRefundResponse } from "./types";
2
- /**
3
- * Install a message listener in the **extension iframe** so the host can request refunds.
4
- * Validates `event.source === window.top` before handling.
5
- *
6
- * Replies with {@link PostMessageResponse}, using `event.origin` as the target origin when posting back to the host.
7
- *
8
- * @param handler - Perform the extension-side refund (API call, etc.)
9
- * @returns Unsubscribe function
10
- */
11
- export declare function installExtensionRefundListener(handler: (params: ExtensionRefundParams) => Promise<ExtensionRefundResponse>): () => void;
@@ -1,60 +0,0 @@
1
- import { EXTENSION_REFUND_REQUEST_ACTION } from "./constants";
2
- function isRecord(value) {
3
- return typeof value === "object" && value !== null;
4
- }
5
- /**
6
- * Install a message listener in the **extension iframe** so the host can request refunds.
7
- * Validates `event.source === window.top` before handling.
8
- *
9
- * Replies with {@link PostMessageResponse}, using `event.origin` as the target origin when posting back to the host.
10
- *
11
- * @param handler - Perform the extension-side refund (API call, etc.)
12
- * @returns Unsubscribe function
13
- */
14
- export function installExtensionRefundListener(handler) {
15
- const onMessage = async (event) => {
16
- const raw = event.data;
17
- if (!isRecord(raw) || raw.action !== EXTENSION_REFUND_REQUEST_ACTION) {
18
- return;
19
- }
20
- const requestId = raw.requestId;
21
- if (typeof requestId !== "string") {
22
- return;
23
- }
24
- if (event.source !== window.top || !event.source) {
25
- return;
26
- }
27
- const source = event.source;
28
- const replyOrigin = typeof event.origin === "string" ? event.origin : "*";
29
- const params = raw.params;
30
- try {
31
- if (!params || typeof params.paymentType !== "string" || typeof params.amount !== "number" || typeof params.saleId !== "string") {
32
- const errPayload = {
33
- requestId,
34
- success: false,
35
- error: "Invalid extension refund params"
36
- };
37
- source.postMessage(errPayload, replyOrigin);
38
- return;
39
- }
40
- const result = await handler(params);
41
- const payload = {
42
- requestId,
43
- success: true,
44
- data: result
45
- };
46
- source.postMessage(payload, replyOrigin);
47
- }
48
- catch (e) {
49
- const message = e instanceof Error ? e.message : String(e);
50
- const errPayload = {
51
- requestId,
52
- success: false,
53
- error: message
54
- };
55
- source.postMessage(errPayload, replyOrigin);
56
- }
57
- };
58
- window.addEventListener("message", onMessage);
59
- return () => window.removeEventListener("message", onMessage);
60
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Host-initiated refund request for extension-controlled payments (e.g. redeem / gift card).
3
- * The host (Render) postMessages the iframe; the extension performs the provider refund and replies.
4
- */
5
- /**
6
- * Parameters sent from host to extension for a refund.
7
- *
8
- * **`amount` uses major currency units** (e.g. dollars), consistent with the string amount
9
- * passed through `sendRefundPaymentRequest` in Render (parsed with `parseFloat` / `+amount`).
10
- */
11
- export interface ExtensionRefundParams {
12
- /** e.g. `"redeem"` — matches order paymentMethods[].paymentType */
13
- paymentType: string;
14
- processor?: string;
15
- /** Major currency units (same as refund flow amount string, not cents). */
16
- amount: number;
17
- /** Local sale transaction id (Mongo-style id from paymentMethods[].transactionId). */
18
- saleId: string;
19
- orderId?: string;
20
- referenceId?: string;
21
- metadata?: Record<string, unknown>;
22
- }
23
- /**
24
- * Business result from the extension after attempting the refund.
25
- * Transport success/failure uses {@link import("../../client").PostMessageResponse}.
26
- */
27
- export interface ExtensionRefundResponse {
28
- success: boolean;
29
- error?: string;
30
- /** Provider/extension reference for the refund transaction, stored in local DB paymentData when present. */
31
- extensionTransactionId?: string;
32
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Host-initiated refund request for extension-controlled payments (e.g. redeem / gift card).
3
- * The host (Render) postMessages the iframe; the extension performs the provider refund and replies.
4
- */
5
- export {};
@@ -1,2 +0,0 @@
1
- import type { SetActiveOutlet } from "./types";
2
- export declare const setActiveOutlet: SetActiveOutlet;
@@ -1,4 +0,0 @@
1
- import { commandFrameClient } from "../../client";
2
- export const setActiveOutlet = async (params) => {
3
- return await commandFrameClient.call("setActiveOutlet", params);
4
- };
@@ -1,2 +0,0 @@
1
- import { SetActiveOutlet } from "./types";
2
- export declare const mockSetActiveOutlet: SetActiveOutlet;
@@ -1,16 +0,0 @@
1
- import { MOCK_OUTLETS } from "../../demo/database";
2
- export const mockSetActiveOutlet = async (params) => {
3
- console.log("[Mock] setActiveOutlet called", params);
4
- if (!params?.outletId) {
5
- throw new Error("outletId is required");
6
- }
7
- const found = MOCK_OUTLETS.find(o => o.id === params.outletId || o._id === params.outletId);
8
- if (!found) {
9
- throw new Error(`Outlet with ID ${params.outletId} not found`);
10
- }
11
- return {
12
- success: true,
13
- outlet: found,
14
- timestamp: new Date().toISOString()
15
- };
16
- };
@@ -1,10 +0,0 @@
1
- import { CFActiveOutlet } from "../../CommonTypes";
2
- export interface SetActiveOutletParams {
3
- outletId: string;
4
- }
5
- export interface SetActiveOutletResponse {
6
- success: boolean;
7
- outlet: CFActiveOutlet;
8
- timestamp: string;
9
- }
10
- export type SetActiveOutlet = (params?: SetActiveOutletParams) => Promise<SetActiveOutletResponse>;
@@ -1,2 +0,0 @@
1
- import type { SetActiveSession } from "./types";
2
- export declare const setActiveSession: SetActiveSession;
@@ -1,4 +0,0 @@
1
- import { commandFrameClient } from "../../client";
2
- export const setActiveSession = async (params) => {
3
- return await commandFrameClient.call("setActiveSession", params);
4
- };
@@ -1,2 +0,0 @@
1
- import { SetActiveSession } from "./types";
2
- export declare const mockSetActiveSession: SetActiveSession;
@@ -1,15 +0,0 @@
1
- import { MOCK_SESSION } from "../../demo/database";
2
- export const mockSetActiveSession = async (params) => {
3
- console.log("[Mock] setActiveSession called", params);
4
- if (!params?.sessionId) {
5
- throw new Error("sessionId is required");
6
- }
7
- if (params.sessionId !== MOCK_SESSION.id) {
8
- throw new Error(`Session with ID ${params.sessionId} not found`);
9
- }
10
- return {
11
- success: true,
12
- session: MOCK_SESSION,
13
- timestamp: new Date().toISOString()
14
- };
15
- };
@@ -1,10 +0,0 @@
1
- import { CFSession } from "../../CommonTypes";
2
- export interface SetActiveSessionParams {
3
- sessionId: string;
4
- }
5
- export interface SetActiveSessionResponse {
6
- success: boolean;
7
- session: CFSession;
8
- timestamp: string;
9
- }
10
- export type SetActiveSession = (params?: SetActiveSessionParams) => Promise<SetActiveSessionResponse>;
@@ -1,2 +0,0 @@
1
- import type { SetActiveStation } from "./types";
2
- export declare const setActiveStation: SetActiveStation;
@@ -1,4 +0,0 @@
1
- import { commandFrameClient } from "../../client";
2
- export const setActiveStation = async (params) => {
3
- return await commandFrameClient.call("setActiveStation", params);
4
- };
@@ -1,2 +0,0 @@
1
- import { SetActiveStation } from "./types";
2
- export declare const mockSetActiveStation: SetActiveStation;
@@ -1,16 +0,0 @@
1
- import { MOCK_STATIONS } from "../../demo/database";
2
- export const mockSetActiveStation = async (params) => {
3
- console.log("[Mock] setActiveStation called", params);
4
- if (!params?.stationId) {
5
- throw new Error("stationId is required");
6
- }
7
- const found = MOCK_STATIONS.find(s => s._id === params.stationId);
8
- if (!found) {
9
- throw new Error(`Station with ID ${params.stationId} not found`);
10
- }
11
- return {
12
- success: true,
13
- station: found,
14
- timestamp: new Date().toISOString()
15
- };
16
- };
@@ -1,10 +0,0 @@
1
- import { CFActiveStation } from "../../CommonTypes";
2
- export interface SetActiveStationParams {
3
- stationId: string;
4
- }
5
- export interface SetActiveStationResponse {
6
- success: boolean;
7
- station: CFActiveStation;
8
- timestamp: string;
9
- }
10
- export type SetActiveStation = (params?: SetActiveStationParams) => Promise<SetActiveStationResponse>;