@final-commerce/command-frame 0.1.51 → 0.1.55
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/actions/edit-customer/action.d.ts +2 -0
- package/dist/actions/edit-customer/action.js +4 -0
- package/dist/actions/edit-customer/mock.d.ts +2 -0
- package/dist/actions/edit-customer/mock.js +18 -0
- package/dist/actions/edit-customer/types.d.ts +11 -0
- package/dist/actions/edit-customer/types.js +1 -0
- package/dist/actions/extension-refund/extension-refund-listener.d.ts +2 -2
- package/dist/actions/extension-refund/extension-refund-listener.js +3 -3
- package/dist/actions/get-active-product/action.d.ts +6 -0
- package/dist/actions/get-active-product/action.js +8 -0
- package/dist/actions/get-active-product/mock.d.ts +2 -0
- package/dist/actions/get-active-product/mock.js +9 -0
- package/dist/actions/get-active-product/types.d.ts +7 -0
- package/dist/actions/get-active-product/types.js +1 -0
- package/dist/actions/set-active-product/action.d.ts +6 -0
- package/dist/actions/set-active-product/action.js +8 -0
- package/dist/actions/set-active-product/mock.d.ts +2 -0
- package/dist/actions/set-active-product/mock.js +34 -0
- package/dist/actions/set-active-product/types.d.ts +10 -0
- package/dist/actions/set-active-product/types.js +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +8 -8
- package/dist/demo/database.d.ts +3 -1
- package/dist/demo/database.js +4 -0
- package/dist/hooks/index.js +4 -4
- package/dist/index.d.ts +7 -1
- package/dist/index.js +7 -1
- package/dist/projects/render/mocks.js +6 -0
- package/dist/projects/render/types.d.ts +4 -1
- package/dist/pubsub/subscriber.js +7 -7
- package/dist/pubsub/topics/products/index.js +10 -0
- package/dist/pubsub/topics/products/product-get-active/types..d.ts +12 -0
- package/dist/pubsub/topics/products/product-get-active/types..js +1 -0
- package/dist/pubsub/topics/products/product-set-active/types.d.ts +12 -0
- package/dist/pubsub/topics/products/product-set-active/types.js +1 -0
- package/package.json +49 -49
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MOCK_CUSTOMERS } from "../../demo/database";
|
|
2
|
+
export const mockEditCustomer = async (params) => {
|
|
3
|
+
console.log("[Mock] editCustomer called", params);
|
|
4
|
+
if (!params?.customerId)
|
|
5
|
+
throw new Error("Customer ID required");
|
|
6
|
+
if (!params?.changes)
|
|
7
|
+
throw new Error("Changes object required");
|
|
8
|
+
const customer = MOCK_CUSTOMERS.find(c => c._id === params.customerId);
|
|
9
|
+
if (!customer)
|
|
10
|
+
throw new Error(`Customer not found: ${params.customerId}`);
|
|
11
|
+
Object.assign(customer, params.changes, { updatedAt: new Date().toISOString() });
|
|
12
|
+
window.alert(`Demo: Customer Updated!\nName: ${customer.firstName} ${customer.lastName}`);
|
|
13
|
+
return {
|
|
14
|
+
success: true,
|
|
15
|
+
customer: { ...customer },
|
|
16
|
+
timestamp: new Date().toISOString()
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CFCustomer } from "../../CommonTypes";
|
|
2
|
+
export interface EditCustomerParams {
|
|
3
|
+
customerId: string;
|
|
4
|
+
changes: Partial<Omit<CFCustomer, "_id" | "createdAt" | "updatedAt" | "companyId">>;
|
|
5
|
+
}
|
|
6
|
+
export interface EditCustomerResponse {
|
|
7
|
+
success: boolean;
|
|
8
|
+
customer: CFCustomer;
|
|
9
|
+
timestamp: string;
|
|
10
|
+
}
|
|
11
|
+
export type EditCustomer = (params: EditCustomerParams) => Promise<EditCustomerResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ExtensionRefundParams, ExtensionRefundResponse } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Install a message listener in the **extension iframe** so the host can request refunds.
|
|
4
|
-
* Validates `event.source === window.
|
|
4
|
+
* Validates `event.source === window.top` before handling.
|
|
5
5
|
*
|
|
6
|
-
* Replies with {@link PostMessageResponse}, using `event.origin` as the target origin when posting back to the
|
|
6
|
+
* Replies with {@link PostMessageResponse}, using `event.origin` as the target origin when posting back to the host.
|
|
7
7
|
*
|
|
8
8
|
* @param handler - Perform the extension-side refund (API call, etc.)
|
|
9
9
|
* @returns Unsubscribe function
|
|
@@ -4,9 +4,9 @@ function isRecord(value) {
|
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* Install a message listener in the **extension iframe** so the host can request refunds.
|
|
7
|
-
* Validates `event.source === window.
|
|
7
|
+
* Validates `event.source === window.top` before handling.
|
|
8
8
|
*
|
|
9
|
-
* Replies with {@link PostMessageResponse}, using `event.origin` as the target origin when posting back to the
|
|
9
|
+
* Replies with {@link PostMessageResponse}, using `event.origin` as the target origin when posting back to the host.
|
|
10
10
|
*
|
|
11
11
|
* @param handler - Perform the extension-side refund (API call, etc.)
|
|
12
12
|
* @returns Unsubscribe function
|
|
@@ -21,7 +21,7 @@ export function installExtensionRefundListener(handler) {
|
|
|
21
21
|
if (typeof requestId !== "string") {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (event.source !== window.
|
|
24
|
+
if (event.source !== window.top || !event.source) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
const source = event.source;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MOCK_ACTIVE_PRODUCT } from "../../demo/database";
|
|
2
|
+
export const mockGetActiveProduct = async () => {
|
|
3
|
+
console.log("[Mock] getActiveProduct called");
|
|
4
|
+
return {
|
|
5
|
+
success: true,
|
|
6
|
+
product: MOCK_ACTIVE_PRODUCT ? { ...MOCK_ACTIVE_PRODUCT } : null,
|
|
7
|
+
timestamp: new Date().toISOString()
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set active product action
|
|
3
|
+
* Calls the setActiveProduct action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from "../../client";
|
|
6
|
+
export const setActiveProduct = async (params) => {
|
|
7
|
+
return await commandFrameClient.call("setActiveProduct", params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const mockSetActiveProduct = async (params) => {
|
|
2
|
+
console.log("[Mock] setActiveProduct called", params);
|
|
3
|
+
if (!params?.variantId) {
|
|
4
|
+
throw new Error("Variant ID is required");
|
|
5
|
+
}
|
|
6
|
+
// Mock product response
|
|
7
|
+
return {
|
|
8
|
+
success: true,
|
|
9
|
+
product: {
|
|
10
|
+
id: "mock_product",
|
|
11
|
+
internalId: "mock_internal_id",
|
|
12
|
+
externalId: "mock_external_id",
|
|
13
|
+
productExternalId: "mock_product_external_id",
|
|
14
|
+
variantId: params.variantId,
|
|
15
|
+
name: "Mock Product",
|
|
16
|
+
sku: "mock_sku",
|
|
17
|
+
price: 100,
|
|
18
|
+
images: [],
|
|
19
|
+
taxTableId: "mock_tax_table_id",
|
|
20
|
+
quantity: 1,
|
|
21
|
+
note: "Mock Note",
|
|
22
|
+
discount: undefined,
|
|
23
|
+
description: "Mock Description",
|
|
24
|
+
barcodeId: "mock_barcode_id",
|
|
25
|
+
stock: 100,
|
|
26
|
+
allowBackOrder: false,
|
|
27
|
+
fee: undefined,
|
|
28
|
+
isUnlimited: false,
|
|
29
|
+
attributes: "Mock Attributes",
|
|
30
|
+
localQuantity: 1,
|
|
31
|
+
},
|
|
32
|
+
timestamp: new Date().toISOString()
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CFActiveProduct } from "../../CommonTypes";
|
|
2
|
+
export interface SetActiveProductParams {
|
|
3
|
+
variantId: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SetActiveProductResponse {
|
|
6
|
+
success: boolean;
|
|
7
|
+
product: CFActiveProduct;
|
|
8
|
+
timestamp: string;
|
|
9
|
+
}
|
|
10
|
+
export type SetActiveProduct = (params?: SetActiveProductParams) => Promise<SetActiveProductResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Command Frame Client for iframe communication
|
|
3
|
-
* Allows the iframe to call functions on the
|
|
3
|
+
* Allows the iframe to call functions on the host (top) window via postMessage
|
|
4
4
|
*/
|
|
5
5
|
export interface PostMessageRequest<T = any> {
|
|
6
6
|
action: string;
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Command Frame Client for iframe communication
|
|
3
|
-
* Allows the iframe to call functions on the
|
|
3
|
+
* Allows the iframe to call functions on the host (top) window via postMessage
|
|
4
4
|
*/
|
|
5
5
|
export class CommandFrameClient {
|
|
6
6
|
constructor(options = {}) {
|
|
@@ -14,7 +14,7 @@ export class CommandFrameClient {
|
|
|
14
14
|
this.mockRegistry = options.mockRegistry || {};
|
|
15
15
|
// If running standalone (no parent window), force Mock Mode immediately
|
|
16
16
|
// This prevents the 2s delay and ensures immediate response in dev/standalone mode
|
|
17
|
-
if (typeof window !== 'undefined' && (!window.
|
|
17
|
+
if (typeof window !== 'undefined' && (!window.top || window.top === window)) {
|
|
18
18
|
if (this.isDebugEnabled()) {
|
|
19
19
|
console.log("[ActionsClient] Standalone mode detected. Enabling Mock Mode immediately.");
|
|
20
20
|
}
|
|
@@ -118,15 +118,15 @@ export class CommandFrameClient {
|
|
|
118
118
|
timestamp: new Date().toISOString()
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
if (typeof window !== 'undefined' && window.
|
|
122
|
-
window.
|
|
121
|
+
if (typeof window !== 'undefined' && window.top) {
|
|
122
|
+
window.top.postMessage(message, this.origin);
|
|
123
123
|
}
|
|
124
124
|
else {
|
|
125
125
|
clearTimeout(timeoutHandle);
|
|
126
126
|
this.pendingRequests.delete(requestId);
|
|
127
|
-
const error = new Error("No
|
|
127
|
+
const error = new Error("No host window found. This app must run in an iframe.");
|
|
128
128
|
if (this.isDebugEnabled()) {
|
|
129
|
-
console.error("[ActionsClient] No
|
|
129
|
+
console.error("[ActionsClient] No host window", error);
|
|
130
130
|
}
|
|
131
131
|
reject(error);
|
|
132
132
|
}
|
|
@@ -135,7 +135,7 @@ export class CommandFrameClient {
|
|
|
135
135
|
// Private check to determine environment
|
|
136
136
|
detectContext() {
|
|
137
137
|
return new Promise((resolve) => {
|
|
138
|
-
if (typeof window === 'undefined' || !window.
|
|
138
|
+
if (typeof window === 'undefined' || !window.top || window.top === window)
|
|
139
139
|
return resolve(null);
|
|
140
140
|
const requestId = this.generateRequestId();
|
|
141
141
|
const timeout = setTimeout(() => {
|
|
@@ -148,7 +148,7 @@ export class CommandFrameClient {
|
|
|
148
148
|
timeout
|
|
149
149
|
});
|
|
150
150
|
try {
|
|
151
|
-
window.
|
|
151
|
+
window.top.postMessage({ action: "getFinalContext", requestId }, this.origin);
|
|
152
152
|
}
|
|
153
153
|
catch {
|
|
154
154
|
clearTimeout(timeout);
|
package/dist/demo/database.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Mock Database for Standalone/Demo Mode
|
|
3
3
|
* Stores mock data that mimics the Render environment
|
|
4
4
|
*/
|
|
5
|
-
import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory } from "../CommonTypes";
|
|
5
|
+
import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct } from "../CommonTypes";
|
|
6
6
|
export * from "./mocks";
|
|
7
7
|
/** Replace mock catalog / context data in place (same array references mock handlers use). */
|
|
8
8
|
export interface MockDatabaseConfig {
|
|
@@ -60,6 +60,8 @@ export declare let MOCK_USER: CFActiveUser;
|
|
|
60
60
|
export declare let MOCK_STATION: CFActiveStation;
|
|
61
61
|
export declare let MOCK_OUTLET: CFActiveOutlet;
|
|
62
62
|
export declare let MOCK_CART: CFActiveCart;
|
|
63
|
+
export declare let MOCK_ACTIVE_PRODUCT: CFActiveProduct;
|
|
64
|
+
export declare const setMockActiveProduct: (activeProduct: CFActiveProduct) => void;
|
|
63
65
|
export declare const resetMockCart: () => void;
|
|
64
66
|
/**
|
|
65
67
|
* Replace in-memory mock data used by default mock handlers. Arrays are mutated in place
|
package/dist/demo/database.js
CHANGED
|
@@ -458,6 +458,10 @@ export let MOCK_CART = {
|
|
|
458
458
|
nonRevenueItems: [],
|
|
459
459
|
customer: null
|
|
460
460
|
};
|
|
461
|
+
export let MOCK_ACTIVE_PRODUCT;
|
|
462
|
+
export const setMockActiveProduct = (activeProduct) => {
|
|
463
|
+
MOCK_ACTIVE_PRODUCT = activeProduct;
|
|
464
|
+
};
|
|
461
465
|
// Helper to reset cart
|
|
462
466
|
export const resetMockCart = () => {
|
|
463
467
|
MOCK_CART = {
|
package/dist/hooks/index.js
CHANGED
|
@@ -11,8 +11,8 @@ function getOrigin() {
|
|
|
11
11
|
function register(topic, callback, options) {
|
|
12
12
|
const hookId = options.hookId;
|
|
13
13
|
const functionBody = callback.toString();
|
|
14
|
-
if (typeof window !== "undefined" && window.
|
|
15
|
-
window.
|
|
14
|
+
if (typeof window !== "undefined" && window.top && window.top !== window) {
|
|
15
|
+
window.top.postMessage({
|
|
16
16
|
type: "hook-register",
|
|
17
17
|
topic,
|
|
18
18
|
functionBody,
|
|
@@ -26,8 +26,8 @@ function register(topic, callback, options) {
|
|
|
26
26
|
* Unregister a hook by ID. Sends a message to the host to remove the hook.
|
|
27
27
|
*/
|
|
28
28
|
function unregister(hookId) {
|
|
29
|
-
if (typeof window !== "undefined" && window.
|
|
30
|
-
window.
|
|
29
|
+
if (typeof window !== "undefined" && window.top && window.top !== window) {
|
|
30
|
+
window.top.postMessage({
|
|
31
31
|
type: "hook-unregister",
|
|
32
32
|
hookId
|
|
33
33
|
}, getOrigin());
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const command: {
|
|
|
7
7
|
readonly getCustomers: import("./actions/get-customers/types").GetCustomers;
|
|
8
8
|
readonly assignCustomer: import("./actions/assign-customer/types").AssignCustomer;
|
|
9
9
|
readonly addCustomer: import("./actions/add-customer/types").AddCustomer;
|
|
10
|
+
readonly editCustomer: import("./actions/edit-customer/types").EditCustomer;
|
|
10
11
|
readonly getCategories: import("./actions/get-categories/types").GetCategories;
|
|
11
12
|
readonly getOrders: import("./actions/get-orders/types").GetOrders;
|
|
12
13
|
readonly getRefunds: import("./actions/get-refunds/types").GetRefunds;
|
|
@@ -19,6 +20,8 @@ export declare const command: {
|
|
|
19
20
|
readonly getFinalContext: import("./actions/get-final-context/types").GetFinalContext;
|
|
20
21
|
readonly addProductNote: import("./actions/add-product-note/types").AddProductNote;
|
|
21
22
|
readonly addProductFee: import("./actions/add-product-fee/types").AddProductFee;
|
|
23
|
+
readonly getActiveProduct: import("./actions/get-active-product/types").GetActiveProduct;
|
|
24
|
+
readonly setActiveProduct: import("./actions/set-active-product/types").SetActiveProduct;
|
|
22
25
|
readonly adjustInventory: import("./actions/adjust-inventory/types").AdjustInventory;
|
|
23
26
|
readonly addOrderNote: import("./actions/add-order-note/types").AddOrderNote;
|
|
24
27
|
readonly addCartFee: import("./actions/add-cart-fee/types").AddCartFee;
|
|
@@ -88,6 +91,7 @@ export type { AddNonRevenueItem, AddNonRevenueItemParams, AddNonRevenueItemRespo
|
|
|
88
91
|
export type { GetCustomers, GetCustomersParams, GetCustomersResponse } from "./actions/get-customers/types";
|
|
89
92
|
export type { AssignCustomer, AssignCustomerParams, AssignCustomerResponse } from "./actions/assign-customer/types";
|
|
90
93
|
export type { AddCustomer, AddCustomerParams, AddCustomerResponse } from "./actions/add-customer/types";
|
|
94
|
+
export type { EditCustomer, EditCustomerParams, EditCustomerResponse } from "./actions/edit-customer/types";
|
|
91
95
|
export type { GetCategories, GetCategoriesParams, GetCategoriesResponse } from "./actions/get-categories/types";
|
|
92
96
|
export type { AddProduct, AddProductParams, AddProductResponse } from "./actions/add-product/types";
|
|
93
97
|
export type { EditProduct, EditProductParams, EditProductResponse } from "./actions/edit-product/types";
|
|
@@ -114,6 +118,8 @@ export type { GetContext, GetContextResponse, GetContextResponseManage, GetConte
|
|
|
114
118
|
export type { GetFinalContext, GetFinalContextResponse } from "./actions/get-final-context/types";
|
|
115
119
|
export type { AddProductNote, AddProductNoteParams, AddProductNoteResponse } from "./actions/add-product-note/types";
|
|
116
120
|
export type { AddProductFee, AddProductFeeParams, AddProductFeeResponse } from "./actions/add-product-fee/types";
|
|
121
|
+
export type { GetActiveProduct, GetActiveProductResponse } from "./actions/get-active-product/types";
|
|
122
|
+
export type { SetActiveProduct, SetActiveProductParams, SetActiveProductResponse } from "./actions/set-active-product/types";
|
|
117
123
|
export type { AdjustInventory, AdjustInventoryParams, AdjustInventoryResponse } from "./actions/adjust-inventory/types";
|
|
118
124
|
export type { AddOrderNote, AddOrderNoteParams, AddOrderNoteResponse } from "./actions/add-order-note/types";
|
|
119
125
|
export type { AddCartFee, AddCartFeeParams, AddCartFeeResponse } from "./actions/add-cart-fee/types";
|
|
@@ -151,7 +157,7 @@ export type { SetActiveOrder, SetActiveOrderParams, SetActiveOrderResponse } fro
|
|
|
151
157
|
export type { TriggerWebhook, TriggerWebhookPresetType, TriggerWebhookParams, TriggerWebhookResponse } from "./actions/trigger-webhook/types";
|
|
152
158
|
export type { TriggerZapierWebhook, TriggerZapierWebhookParams, TriggerZapierWebhookResponse } from "./actions/trigger-zapier-webhook/types";
|
|
153
159
|
export * from "./CommonTypes";
|
|
154
|
-
export { setMockDatabase } from "./demo/database";
|
|
160
|
+
export { setMockDatabase, setMockActiveProduct } from "./demo/database";
|
|
155
161
|
export type { MockDatabaseConfig } from "./demo/database";
|
|
156
162
|
export { CommandFrameProvider } from "./provider";
|
|
157
163
|
export type { ActionHandler, ActionHandlers } from "./provider";
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { addNonRevenueItem } from "./actions/add-non-revenue-item/action";
|
|
|
6
6
|
import { getCustomers } from "./actions/get-customers/action";
|
|
7
7
|
import { assignCustomer } from "./actions/assign-customer/action";
|
|
8
8
|
import { addCustomer } from "./actions/add-customer/action";
|
|
9
|
+
import { editCustomer } from "./actions/edit-customer/action";
|
|
9
10
|
import { getCategories } from "./actions/get-categories/action";
|
|
10
11
|
import { getOrders } from "./actions/get-orders/action";
|
|
11
12
|
import { addCartDiscount } from "./actions/add-cart-discount/action";
|
|
@@ -18,6 +19,8 @@ import { updateCartItemQuantity } from "./actions/update-cart-item-quantity/acti
|
|
|
18
19
|
// Product Actions
|
|
19
20
|
import { addProductNote } from "./actions/add-product-note/action";
|
|
20
21
|
import { addProductFee } from "./actions/add-product-fee/action";
|
|
22
|
+
import { getActiveProduct } from "./actions/get-active-product/action";
|
|
23
|
+
import { setActiveProduct } from "./actions/set-active-product/action";
|
|
21
24
|
import { adjustInventory } from "./actions/adjust-inventory/action";
|
|
22
25
|
// Order Actions
|
|
23
26
|
import { addOrderNote } from "./actions/add-order-note/action";
|
|
@@ -101,6 +104,7 @@ export const command = {
|
|
|
101
104
|
getCustomers,
|
|
102
105
|
assignCustomer,
|
|
103
106
|
addCustomer,
|
|
107
|
+
editCustomer,
|
|
104
108
|
getCategories,
|
|
105
109
|
getOrders,
|
|
106
110
|
getRefunds,
|
|
@@ -114,6 +118,8 @@ export const command = {
|
|
|
114
118
|
// Product Actions
|
|
115
119
|
addProductNote,
|
|
116
120
|
addProductFee,
|
|
121
|
+
getActiveProduct,
|
|
122
|
+
setActiveProduct,
|
|
117
123
|
adjustInventory,
|
|
118
124
|
// Order Actions
|
|
119
125
|
addOrderNote,
|
|
@@ -192,7 +198,7 @@ export { installExtensionRefundListener } from "./actions/extension-refund/exten
|
|
|
192
198
|
// Export Common Types
|
|
193
199
|
export * from "./CommonTypes";
|
|
194
200
|
// Mock database override (standalone / extension dev)
|
|
195
|
-
export { setMockDatabase } from "./demo/database";
|
|
201
|
+
export { setMockDatabase, setMockActiveProduct } from "./demo/database";
|
|
196
202
|
// Export Provider
|
|
197
203
|
export { CommandFrameProvider } from "./provider";
|
|
198
204
|
// Export Render Project
|
|
@@ -3,9 +3,12 @@ import { mockAddCartFee } from "../../actions/add-cart-fee/mock";
|
|
|
3
3
|
import { mockAddCustomSale } from "../../actions/add-custom-sale/mock";
|
|
4
4
|
import { mockAddCustomer } from "../../actions/add-customer/mock";
|
|
5
5
|
import { mockAddCustomerNote } from "../../actions/add-customer-note/mock";
|
|
6
|
+
import { mockEditCustomer } from "../../actions/edit-customer/mock";
|
|
6
7
|
import { mockAddOrderNote } from "../../actions/add-order-note/mock";
|
|
7
8
|
import { mockAddProductDiscount } from "../../actions/add-product-discount/mock";
|
|
8
9
|
import { mockAddProductFee } from "../../actions/add-product-fee/mock";
|
|
10
|
+
import { mockGetActiveProduct } from "../../actions/get-active-product/mock";
|
|
11
|
+
import { mockSetActiveProduct } from "../../actions/set-active-product/mock";
|
|
9
12
|
import { mockAddProductNote } from "../../actions/add-product-note/mock";
|
|
10
13
|
import { mockAddProductToCart } from "../../actions/add-product-to-cart/mock";
|
|
11
14
|
import { mockRemoveProductFromCart } from "../../actions/remove-product-from-cart/mock";
|
|
@@ -70,10 +73,13 @@ export const RENDER_MOCKS = {
|
|
|
70
73
|
addCartFee: mockAddCartFee,
|
|
71
74
|
addCustomSale: mockAddCustomSale,
|
|
72
75
|
addCustomer: mockAddCustomer,
|
|
76
|
+
editCustomer: mockEditCustomer,
|
|
73
77
|
addCustomerNote: mockAddCustomerNote,
|
|
74
78
|
addOrderNote: mockAddOrderNote,
|
|
75
79
|
addProductDiscount: mockAddProductDiscount,
|
|
76
80
|
addProductFee: mockAddProductFee,
|
|
81
|
+
getActiveProduct: mockGetActiveProduct,
|
|
82
|
+
setActiveProduct: mockSetActiveProduct,
|
|
77
83
|
addProductNote: mockAddProductNote,
|
|
78
84
|
addProductToCart: mockAddProductToCart,
|
|
79
85
|
removeProductFromCart: mockRemoveProductFromCart,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExampleFunction, GetProducts, AddCustomSale, GetCustomers, AssignCustomer, AddCustomer, GetCategories, GetOrders, GetRefunds, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, InitiateRefund, CashPayment, TapToPayPayment, TerminalPayment, VendaraPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, TriggerWebhook, TriggerZapierWebhook, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount } from "../../index";
|
|
1
|
+
import type { ExampleFunction, GetProducts, AddCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, InitiateRefund, CashPayment, TapToPayPayment, TerminalPayment, VendaraPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, TriggerWebhook, TriggerZapierWebhook, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount } from "../../index";
|
|
2
2
|
export interface RenderProviderActions {
|
|
3
3
|
exampleFunction: ExampleFunction;
|
|
4
4
|
getProducts: GetProducts;
|
|
@@ -6,6 +6,7 @@ export interface RenderProviderActions {
|
|
|
6
6
|
getCustomers: GetCustomers;
|
|
7
7
|
assignCustomer: AssignCustomer;
|
|
8
8
|
addCustomer: AddCustomer;
|
|
9
|
+
editCustomer: EditCustomer;
|
|
9
10
|
getCategories: GetCategories;
|
|
10
11
|
getOrders: GetOrders;
|
|
11
12
|
getRefunds: GetRefunds;
|
|
@@ -18,6 +19,8 @@ export interface RenderProviderActions {
|
|
|
18
19
|
getFinalContext: GetFinalContext;
|
|
19
20
|
addProductNote: AddProductNote;
|
|
20
21
|
addProductFee: AddProductFee;
|
|
22
|
+
getActiveProduct: GetActiveProduct;
|
|
23
|
+
setActiveProduct: SetActiveProduct;
|
|
21
24
|
adjustInventory: AdjustInventory;
|
|
22
25
|
addOrderNote: AddOrderNote;
|
|
23
26
|
addCartFee: AddCartFee;
|
|
@@ -12,8 +12,8 @@ export class TopicSubscriber {
|
|
|
12
12
|
this.origin = options.origin || "*";
|
|
13
13
|
this.debug = options.debug ?? false;
|
|
14
14
|
this.useGlobalDebug = options.debug === undefined;
|
|
15
|
-
// Detect standalone mode (
|
|
16
|
-
if (typeof window !== 'undefined' && (!window.
|
|
15
|
+
// Detect standalone mode (not inside any iframe)
|
|
16
|
+
if (typeof window !== 'undefined' && (!window.top || window.top === window)) {
|
|
17
17
|
this.mockMode = true;
|
|
18
18
|
if (this.isDebugEnabled()) {
|
|
19
19
|
console.log("[TopicSubscriber] Mock Mode enabled (standalone mode detected)");
|
|
@@ -70,7 +70,7 @@ export class TopicSubscriber {
|
|
|
70
70
|
* Request the list of available topics from the host
|
|
71
71
|
*/
|
|
72
72
|
requestTopics() {
|
|
73
|
-
if (typeof window !== "undefined" && window.
|
|
73
|
+
if (typeof window !== "undefined" && window.top && window.top !== window) {
|
|
74
74
|
const message = {
|
|
75
75
|
type: "pubsub-request-topics",
|
|
76
76
|
requestId: `topics_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
|
@@ -78,7 +78,7 @@ export class TopicSubscriber {
|
|
|
78
78
|
if (this.isDebugEnabled()) {
|
|
79
79
|
console.log("[TopicSubscriber] Requesting topics list", message);
|
|
80
80
|
}
|
|
81
|
-
window.
|
|
81
|
+
window.top.postMessage(message, this.origin);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
@@ -177,7 +177,7 @@ export class TopicSubscriber {
|
|
|
177
177
|
* Notify host about subscription changes
|
|
178
178
|
*/
|
|
179
179
|
notifySubscription(topic, isSubscribed) {
|
|
180
|
-
if (typeof window !== "undefined" && window.
|
|
180
|
+
if (typeof window !== "undefined" && window.top && window.top !== window) {
|
|
181
181
|
const message = {
|
|
182
182
|
type: isSubscribed ? "pubsub-subscribe" : "pubsub-unsubscribe",
|
|
183
183
|
topic,
|
|
@@ -186,7 +186,7 @@ export class TopicSubscriber {
|
|
|
186
186
|
if (this.isDebugEnabled()) {
|
|
187
187
|
console.log("[TopicSubscriber] Notifying subscription change", message);
|
|
188
188
|
}
|
|
189
|
-
window.
|
|
189
|
+
window.top.postMessage(message, this.origin);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
@@ -203,7 +203,7 @@ export class TopicSubscriber {
|
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
205
|
const data = event.data;
|
|
206
|
-
// Clear detection timeout on first valid message from
|
|
206
|
+
// Clear detection timeout on first valid message from host
|
|
207
207
|
if (this.detectionTimeout && data && (data.type === "pubsub-event" || data.type === "pubsub-topics-list")) {
|
|
208
208
|
clearTimeout(this.detectionTimeout);
|
|
209
209
|
this.detectionTimeout = undefined;
|
|
@@ -16,6 +16,16 @@ export const productsTopic = {
|
|
|
16
16
|
id: "product-updated",
|
|
17
17
|
name: "Product Updated",
|
|
18
18
|
description: "Published when a product is synced/updated"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
id: "set-active-product",
|
|
22
|
+
name: "Set Active Product",
|
|
23
|
+
description: "Published when a product is set as the active product"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "get-active-product",
|
|
27
|
+
name: "Get Active Product",
|
|
28
|
+
description: "Published when a product is retrieved as the active product"
|
|
19
29
|
}
|
|
20
30
|
]
|
|
21
31
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CFActiveProduct } from "../../../../CommonTypes";
|
|
2
|
+
import type { TopicEvent } from "../../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Payload for product-get-active event
|
|
5
|
+
*/
|
|
6
|
+
export interface ProductGetActivePayload {
|
|
7
|
+
product: CFActiveProduct;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Typed event for product-get-active
|
|
11
|
+
*/
|
|
12
|
+
export type ProductGetActiveEvent = TopicEvent<ProductGetActivePayload>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CFActiveProduct } from "../../../../CommonTypes";
|
|
2
|
+
import type { TopicEvent } from "../../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Payload for product-set-active event
|
|
5
|
+
*/
|
|
6
|
+
export interface ProductSetActivePayload {
|
|
7
|
+
product: CFActiveProduct;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Typed event for product-set-active
|
|
11
|
+
*/
|
|
12
|
+
export type ProductSetActiveEvent = TopicEvent<ProductSetActivePayload>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
2
|
+
"name": "@final-commerce/command-frame",
|
|
3
|
+
"version": "0.1.55",
|
|
4
|
+
"description": "Commands Frame library",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE",
|
|
11
|
+
"package.json"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"build:clean": "rm -rf dist && npm run build",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"test": "vitest",
|
|
18
|
+
"test:run": "vitest run",
|
|
19
|
+
"prepublishOnly": "npm run build",
|
|
20
|
+
"prepare": "npm run build",
|
|
21
|
+
"format": "prettier --write .",
|
|
22
|
+
"format:check": "prettier --check .",
|
|
23
|
+
"publish:npm": "npm publish --registry=https://registry.npmjs.org",
|
|
24
|
+
"publish:github": "npm publish --registry=https://npm.pkg.github.com",
|
|
25
|
+
"publish:all": "npm run publish:npm && npm run publish:github"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"final commerce",
|
|
29
|
+
"finalpos",
|
|
30
|
+
"final",
|
|
31
|
+
"command",
|
|
32
|
+
"frame"
|
|
33
|
+
],
|
|
34
|
+
"author": "Final Commerce",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"registry": "https://registry.npmjs.org/"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/Final-Commerce/command-frame.git"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
46
|
+
"@typescript-eslint/parser": "^8.48.0",
|
|
47
|
+
"prettier": "^3.7.1",
|
|
48
|
+
"typescript": "^5.0.0",
|
|
49
|
+
"vitest": "^3.0.5"
|
|
50
|
+
}
|
|
51
51
|
}
|