@final-commerce/command-frame 0.1.16 → 0.1.17
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/README.md +42 -449
- package/dist/actions/add-cart-discount/mock.js +5 -1
- package/dist/actions/add-product-to-cart/mock.js +3 -1
- package/dist/actions/assign-customer/mock.js +3 -1
- package/dist/actions/cash-payment/mock.js +3 -1
- package/dist/actions/clear-cart/mock.js +3 -1
- package/dist/client.d.ts +4 -1
- package/dist/client.js +24 -4
- package/dist/demo/database.d.ts +4 -0
- package/dist/demo/database.js +26 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +6 -0
- package/dist/projects/manage/client.d.ts +13 -0
- package/dist/projects/manage/client.js +13 -0
- package/dist/projects/manage/index.d.ts +4 -0
- package/dist/projects/manage/index.js +4 -0
- package/dist/projects/manage/mocks.d.ts +2 -0
- package/dist/projects/manage/mocks.js +6 -0
- package/dist/projects/manage/provider.d.ts +8 -0
- package/dist/projects/manage/provider.js +6 -0
- package/dist/projects/manage/types.d.ts +5 -0
- package/dist/projects/manage/types.js +1 -0
- package/dist/projects/render/client.d.ts +13 -0
- package/dist/projects/render/client.js +13 -0
- package/dist/projects/render/index.d.ts +4 -0
- package/dist/projects/render/index.js +4 -0
- package/dist/projects/render/mocks.d.ts +2 -0
- package/dist/projects/render/mocks.js +94 -0
- package/dist/projects/render/provider.d.ts +8 -0
- package/dist/projects/render/provider.js +6 -0
- package/dist/projects/render/types.d.ts +49 -0
- package/dist/projects/render/types.js +1 -0
- package/dist/provider.d.ts +19 -0
- package/dist/provider.js +178 -0
- package/dist/pubsub/subscriber.d.ts +4 -0
- package/dist/pubsub/subscriber.js +53 -5
- package/dist/pubsub/topics/types.d.ts +14 -0
- package/dist/pubsub/topics/types.js +1 -0
- package/dist/pubsub/types.d.ts +9 -0
- package/package.json +1 -1
- package/dist/demo/registry.d.ts +0 -5
- package/dist/demo/registry.js +0 -94
|
@@ -2,28 +2,64 @@
|
|
|
2
2
|
* Topic Subscriber for iframe communication
|
|
3
3
|
* Manages subscriptions to topics and receives events from the host window
|
|
4
4
|
*/
|
|
5
|
+
import { mockSubscribeToTopic } from "../demo/database";
|
|
5
6
|
export class TopicSubscriber {
|
|
6
7
|
constructor(options = {}) {
|
|
7
8
|
this.subscriptions = new Map();
|
|
8
9
|
this.topics = [];
|
|
9
10
|
this.subscriptionIdCounter = 0;
|
|
11
|
+
this.mockMode = false;
|
|
10
12
|
this.origin = options.origin || "*";
|
|
11
13
|
this.debug = options.debug ?? false;
|
|
12
14
|
this.useGlobalDebug = options.debug === undefined;
|
|
15
|
+
// Detect standalone mode (no parent iframe)
|
|
16
|
+
if (typeof window !== 'undefined' && (!window.parent || window.parent === window)) {
|
|
17
|
+
this.mockMode = true;
|
|
18
|
+
if (this.isDebugEnabled()) {
|
|
19
|
+
console.log("[TopicSubscriber] Mock Mode enabled (standalone mode detected)");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
13
22
|
// Store bound handler for cleanup
|
|
14
23
|
this.boundHandleMessage = this.handleMessage.bind(this);
|
|
15
24
|
if (typeof window !== "undefined") {
|
|
16
25
|
window.addEventListener("message", this.boundHandleMessage);
|
|
17
26
|
}
|
|
18
|
-
//
|
|
19
|
-
this.
|
|
27
|
+
// Initialize connection detection
|
|
28
|
+
if (!this.mockMode) {
|
|
29
|
+
this.initDetection();
|
|
30
|
+
this.requestTopics();
|
|
31
|
+
}
|
|
20
32
|
if (this.isDebugEnabled()) {
|
|
21
33
|
console.log("[TopicSubscriber] Initialized", {
|
|
22
34
|
origin: this.origin,
|
|
23
|
-
debug: this.isDebugEnabled()
|
|
35
|
+
debug: this.isDebugEnabled(),
|
|
36
|
+
mockMode: this.mockMode
|
|
24
37
|
});
|
|
25
38
|
}
|
|
26
39
|
}
|
|
40
|
+
initDetection() {
|
|
41
|
+
// If we don't receive any message from parent within 2 seconds, switch to mock mode
|
|
42
|
+
this.detectionTimeout = setTimeout(() => {
|
|
43
|
+
if (this.isDebugEnabled()) {
|
|
44
|
+
console.warn("[TopicSubscriber] Connection timeout. Switching to Mock Mode.");
|
|
45
|
+
}
|
|
46
|
+
this.switchToMockMode();
|
|
47
|
+
}, 2000);
|
|
48
|
+
}
|
|
49
|
+
switchToMockMode() {
|
|
50
|
+
if (this.mockMode)
|
|
51
|
+
return;
|
|
52
|
+
this.mockMode = true;
|
|
53
|
+
// Migrate existing subscriptions to mock system
|
|
54
|
+
this.subscriptions.forEach((subs, topic) => {
|
|
55
|
+
subs.forEach(sub => {
|
|
56
|
+
if (this.isDebugEnabled()) {
|
|
57
|
+
console.log("[TopicSubscriber] Migrating subscription to mock system", { topic, id: sub.id });
|
|
58
|
+
}
|
|
59
|
+
mockSubscribeToTopic(topic, sub.callback);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
27
63
|
isDebugEnabled() {
|
|
28
64
|
if (!this.useGlobalDebug) {
|
|
29
65
|
return this.debug;
|
|
@@ -60,12 +96,19 @@ export class TopicSubscriber {
|
|
|
60
96
|
callback: callback
|
|
61
97
|
};
|
|
62
98
|
this.subscriptions.get(topic).push(subscription);
|
|
63
|
-
//
|
|
64
|
-
this.
|
|
99
|
+
// In mock mode, also register with the mock event system
|
|
100
|
+
if (this.mockMode) {
|
|
101
|
+
mockSubscribeToTopic(topic, callback);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Notify host about the subscription (only in real mode)
|
|
105
|
+
this.notifySubscription(topic, true);
|
|
106
|
+
}
|
|
65
107
|
if (this.isDebugEnabled()) {
|
|
66
108
|
console.log("[TopicSubscriber] Subscribed to topic", {
|
|
67
109
|
topic,
|
|
68
110
|
subscriptionId,
|
|
111
|
+
mockMode: this.mockMode,
|
|
69
112
|
totalSubscriptions: this.subscriptions.get(topic).length
|
|
70
113
|
});
|
|
71
114
|
}
|
|
@@ -160,6 +203,11 @@ export class TopicSubscriber {
|
|
|
160
203
|
return;
|
|
161
204
|
}
|
|
162
205
|
const data = event.data;
|
|
206
|
+
// Clear detection timeout on first valid message from parent
|
|
207
|
+
if (this.detectionTimeout && data && (data.type === "pubsub-event" || data.type === "pubsub-topics-list")) {
|
|
208
|
+
clearTimeout(this.detectionTimeout);
|
|
209
|
+
this.detectionTimeout = undefined;
|
|
210
|
+
}
|
|
163
211
|
// Handle topic event
|
|
164
212
|
if (data && data.type === "pubsub-event") {
|
|
165
213
|
const eventMessage = data;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CustomersEventType, CustomersEventPayload } from "./customers/types";
|
|
2
|
+
import { OrdersEventType, OrdersEventPayload } from "./orders/types";
|
|
3
|
+
import { RefundsEventType, RefundsEventPayload } from "./refunds/types";
|
|
4
|
+
import { ProductsEventType, ProductsEventPayload } from "./products/types";
|
|
5
|
+
import { CartEventType, CartEventPayload } from "./cart/types";
|
|
6
|
+
import { PaymentsEventType, PaymentsEventPayload } from "./payments/types";
|
|
7
|
+
export interface TopicEventPayloadMap {
|
|
8
|
+
customers: Record<CustomersEventType, CustomersEventPayload>;
|
|
9
|
+
orders: Record<OrdersEventType, OrdersEventPayload>;
|
|
10
|
+
refunds: Record<RefundsEventType, RefundsEventPayload>;
|
|
11
|
+
products: Record<ProductsEventType, ProductsEventPayload>;
|
|
12
|
+
cart: Record<CartEventType, CartEventPayload>;
|
|
13
|
+
payments: Record<PaymentsEventType, PaymentsEventPayload>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/pubsub/types.d.ts
CHANGED
|
@@ -40,3 +40,12 @@ export interface TopicSubscription {
|
|
|
40
40
|
topic: string;
|
|
41
41
|
callback: TopicSubscriptionCallback;
|
|
42
42
|
}
|
|
43
|
+
export interface TopicRegistration {
|
|
44
|
+
definition: TopicDefinition;
|
|
45
|
+
subscribers: {
|
|
46
|
+
iframeWindow: Window;
|
|
47
|
+
topic: string;
|
|
48
|
+
subscribedAt: number;
|
|
49
|
+
subscriptionCount: number;
|
|
50
|
+
}[];
|
|
51
|
+
}
|
package/package.json
CHANGED
package/dist/demo/registry.d.ts
DELETED
package/dist/demo/registry.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { mockAddCartDiscount } from "../actions/add-cart-discount/mock";
|
|
2
|
-
import { mockAddCartFee } from "../actions/add-cart-fee/mock";
|
|
3
|
-
import { mockAddCustomSale } from "../actions/add-custom-sale/mock";
|
|
4
|
-
import { mockAddCustomer } from "../actions/add-customer/mock";
|
|
5
|
-
import { mockAddCustomerNote } from "../actions/add-customer-note/mock";
|
|
6
|
-
import { mockAddOrderNote } from "../actions/add-order-note/mock";
|
|
7
|
-
import { mockAddProductDiscount } from "../actions/add-product-discount/mock";
|
|
8
|
-
import { mockAddProductFee } from "../actions/add-product-fee/mock";
|
|
9
|
-
import { mockAddProductNote } from "../actions/add-product-note/mock";
|
|
10
|
-
import { mockAddProductToCart } from "../actions/add-product-to-cart/mock";
|
|
11
|
-
import { mockAdjustInventory } from "../actions/adjust-inventory/mock";
|
|
12
|
-
import { mockAssignCustomer } from "../actions/assign-customer/mock";
|
|
13
|
-
import { mockAuthenticateUser } from "../actions/authenticate-user/mock";
|
|
14
|
-
import { mockCalculateRefundTotal } from "../actions/calculate-refund-total/mock";
|
|
15
|
-
import { mockCashPayment } from "../actions/cash-payment/mock";
|
|
16
|
-
import { mockClearCart } from "../actions/clear-cart/mock";
|
|
17
|
-
import { mockDeleteParkedOrder } from "../actions/delete-parked-order/mock";
|
|
18
|
-
import { mockExampleFunction } from "../actions/example-function/mock";
|
|
19
|
-
import { mockGetCategories } from "../actions/get-categories/mock";
|
|
20
|
-
import { mockGetContext } from "../actions/get-context/mock";
|
|
21
|
-
import { mockGetCurrentCart } from "../actions/get-current-cart/mock";
|
|
22
|
-
import { mockGetCustomers } from "../actions/get-customers/mock";
|
|
23
|
-
import { mockGetOrders } from "../actions/get-orders/mock";
|
|
24
|
-
import { mockGetProducts } from "../actions/get-products/mock";
|
|
25
|
-
import { mockGetRefunds } from "../actions/get-refunds/mock";
|
|
26
|
-
import { mockGetRemainingRefundableQuantities } from "../actions/get-remaining-refundable-quantities/mock";
|
|
27
|
-
import { mockGoToStationHome } from "../actions/go-to-station-home/mock";
|
|
28
|
-
import { mockInitiateRefund } from "../actions/initiate-refund/mock";
|
|
29
|
-
import { mockOpenCashDrawer } from "../actions/open-cash-drawer/mock";
|
|
30
|
-
import { mockParkOrder } from "../actions/park-order/mock";
|
|
31
|
-
import { mockPartialPayment } from "../actions/partial-payment/mock";
|
|
32
|
-
import { mockProcessPartialRefund } from "../actions/process-partial-refund/mock";
|
|
33
|
-
import { mockRemoveCustomerFromCart } from "../actions/remove-customer-from-cart/mock";
|
|
34
|
-
import { mockResetRefundDetails } from "../actions/reset-refund-details/mock";
|
|
35
|
-
import { mockResumeParkedOrder } from "../actions/resume-parked-order/mock";
|
|
36
|
-
import { mockSelectAllRefundItems } from "../actions/select-all-refund-items/mock";
|
|
37
|
-
import { mockSetRefundStockAction } from "../actions/set-refund-stock-action/mock";
|
|
38
|
-
import { mockShowConfirmation } from "../actions/show-confirmation/mock";
|
|
39
|
-
import { mockShowNotification } from "../actions/show-notification/mock";
|
|
40
|
-
import { mockSwitchUser } from "../actions/switch-user/mock";
|
|
41
|
-
import { mockTapToPayPayment } from "../actions/tap-to-pay-payment/mock";
|
|
42
|
-
import { mockTerminalPayment } from "../actions/terminal-payment/mock";
|
|
43
|
-
import { mockTriggerWebhook } from "../actions/trigger-webhook/mock";
|
|
44
|
-
import { mockTriggerZapierWebhook } from "../actions/trigger-zapier-webhook/mock";
|
|
45
|
-
import { mockVendaraPayment } from "../actions/vendara-payment/mock";
|
|
46
|
-
import { mockGetFinalContext } from "../actions/get-final-context/mock";
|
|
47
|
-
export const MOCK_REGISTRY = {
|
|
48
|
-
"addCartDiscount": mockAddCartDiscount,
|
|
49
|
-
"addCartFee": mockAddCartFee,
|
|
50
|
-
"addCustomSale": mockAddCustomSale,
|
|
51
|
-
"addCustomer": mockAddCustomer,
|
|
52
|
-
"addCustomerNote": mockAddCustomerNote,
|
|
53
|
-
"addOrderNote": mockAddOrderNote,
|
|
54
|
-
"addProductDiscount": mockAddProductDiscount,
|
|
55
|
-
"addProductFee": mockAddProductFee,
|
|
56
|
-
"addProductNote": mockAddProductNote,
|
|
57
|
-
"addProductToCart": mockAddProductToCart,
|
|
58
|
-
"adjustInventory": mockAdjustInventory,
|
|
59
|
-
"assignCustomer": mockAssignCustomer,
|
|
60
|
-
"authenticateUser": mockAuthenticateUser,
|
|
61
|
-
"calculateRefundTotal": mockCalculateRefundTotal,
|
|
62
|
-
"cashPayment": mockCashPayment,
|
|
63
|
-
"clearCart": mockClearCart,
|
|
64
|
-
"deleteParkedOrder": mockDeleteParkedOrder,
|
|
65
|
-
"exampleFunction": mockExampleFunction,
|
|
66
|
-
"getCategories": mockGetCategories,
|
|
67
|
-
"getContext": mockGetContext,
|
|
68
|
-
"getCurrentCart": mockGetCurrentCart,
|
|
69
|
-
"getCustomers": mockGetCustomers,
|
|
70
|
-
"getOrders": mockGetOrders,
|
|
71
|
-
"getProducts": mockGetProducts,
|
|
72
|
-
"getRefunds": mockGetRefunds,
|
|
73
|
-
"getRemainingRefundableQuantities": mockGetRemainingRefundableQuantities,
|
|
74
|
-
"goToStationHome": mockGoToStationHome,
|
|
75
|
-
"initiateRefund": mockInitiateRefund,
|
|
76
|
-
"openCashDrawer": mockOpenCashDrawer,
|
|
77
|
-
"parkOrder": mockParkOrder,
|
|
78
|
-
"partialPayment": mockPartialPayment,
|
|
79
|
-
"processPartialRefund": mockProcessPartialRefund,
|
|
80
|
-
"removeCustomerFromCart": mockRemoveCustomerFromCart,
|
|
81
|
-
"resetRefundDetails": mockResetRefundDetails,
|
|
82
|
-
"resumeParkedOrder": mockResumeParkedOrder,
|
|
83
|
-
"selectAllRefundItems": mockSelectAllRefundItems,
|
|
84
|
-
"setRefundStockAction": mockSetRefundStockAction,
|
|
85
|
-
"showConfirmation": mockShowConfirmation,
|
|
86
|
-
"showNotification": mockShowNotification,
|
|
87
|
-
"switchUser": mockSwitchUser,
|
|
88
|
-
"tapToPayPayment": mockTapToPayPayment,
|
|
89
|
-
"terminalPayment": mockTerminalPayment,
|
|
90
|
-
"triggerWebhook": mockTriggerWebhook,
|
|
91
|
-
"triggerZapierWebhook": mockTriggerZapierWebhook,
|
|
92
|
-
"vendaraPayment": mockVendaraPayment,
|
|
93
|
-
"getFinalContext": mockGetFinalContext,
|
|
94
|
-
};
|