@final-commerce/command-frame 0.1.15 → 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.
Files changed (44) hide show
  1. package/README.md +42 -449
  2. package/dist/CommonTypes.d.ts +4 -7
  3. package/dist/actions/add-cart-discount/mock.js +5 -1
  4. package/dist/actions/add-product-to-cart/mock.js +3 -1
  5. package/dist/actions/assign-customer/mock.js +3 -1
  6. package/dist/actions/cash-payment/mock.js +3 -1
  7. package/dist/actions/clear-cart/mock.js +3 -1
  8. package/dist/actions/get-products/mock.js +3 -3
  9. package/dist/client.d.ts +4 -1
  10. package/dist/client.js +24 -4
  11. package/dist/demo/database.d.ts +10 -0
  12. package/dist/demo/database.js +77 -17
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.js +6 -0
  15. package/dist/projects/manage/client.d.ts +13 -0
  16. package/dist/projects/manage/client.js +13 -0
  17. package/dist/projects/manage/index.d.ts +4 -0
  18. package/dist/projects/manage/index.js +4 -0
  19. package/dist/projects/manage/mocks.d.ts +2 -0
  20. package/dist/projects/manage/mocks.js +6 -0
  21. package/dist/projects/manage/provider.d.ts +8 -0
  22. package/dist/projects/manage/provider.js +6 -0
  23. package/dist/projects/manage/types.d.ts +5 -0
  24. package/dist/projects/manage/types.js +1 -0
  25. package/dist/projects/render/client.d.ts +13 -0
  26. package/dist/projects/render/client.js +13 -0
  27. package/dist/projects/render/index.d.ts +4 -0
  28. package/dist/projects/render/index.js +4 -0
  29. package/dist/projects/render/mocks.d.ts +2 -0
  30. package/dist/projects/render/mocks.js +94 -0
  31. package/dist/projects/render/provider.d.ts +8 -0
  32. package/dist/projects/render/provider.js +6 -0
  33. package/dist/projects/render/types.d.ts +49 -0
  34. package/dist/projects/render/types.js +1 -0
  35. package/dist/provider.d.ts +19 -0
  36. package/dist/provider.js +178 -0
  37. package/dist/pubsub/subscriber.d.ts +4 -0
  38. package/dist/pubsub/subscriber.js +53 -5
  39. package/dist/pubsub/topics/types.d.ts +14 -0
  40. package/dist/pubsub/topics/types.js +1 -0
  41. package/dist/pubsub/types.d.ts +9 -0
  42. package/package.json +1 -1
  43. package/dist/demo/registry.d.ts +0 -5
  44. package/dist/demo/registry.js +0 -94
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # @final-commerce/command-frame
2
2
 
3
- A TypeScript library for communication between iframes and their parent windows using postMessage with type safety and error handling. test.
3
+ A TypeScript library for type-safe communication between iframes and their parent windows in the Final Commerce ecosystem.
4
+
5
+ ## Overview
6
+
7
+ Command Frame provides a structured way to build integrations that run inside Final Commerce applications (like Render POS or Manage Dashboard). It handles the underlying `postMessage` communication while enforcing strict type safety for both the host application (Provider) and the embedded app (Client).
4
8
 
5
9
  ## Installation
6
10
 
@@ -8,484 +12,73 @@ A TypeScript library for communication between iframes and their parent windows
8
12
  npm install @final-commerce/command-frame
9
13
  ```
10
14
 
11
- This package is available on the public NPM registry.
12
-
13
- ## Table of Contents
14
-
15
- - [API Overview](#api-overview)
16
- - [Quick Start](#quick-start)
17
- - [Commands Documentation](#commands-documentation)
18
- - [Pub/Sub System](#pubsub-system)
19
- - [Examples](#examples)
20
- - [Debugging](#debugging)
21
- - [Type Safety](#type-safety)
22
- - [License](#license)
23
-
24
- ## API Overview
25
-
26
- The library provides a `command` namespace object containing all available commands. Each command is a typed function that communicates with the parent window via postMessage.
27
-
28
- ### Available Commands
29
-
30
- #### Data Retrieval
31
- - **[getCustomers](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-customers/README.md)** - Retrieve a list of customers from the parent application
32
- - **[getProducts](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-products/README.md)** - Retrieve a list of products from the parent application
33
- - **[getCategories](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-categories/README.md)** - Retrieve a list of categories from the parent application
34
- - **[getOrders](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-orders/README.md)** - Retrieve a list of orders from the system with optional filtering, sorting, and pagination
35
- - **[getCurrentCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-current-cart/README.md)** - Retrieve the current cart object with all its contents
36
- - **[getContext](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-context/README.md)** - Get current environment/context information (user, company, device, station, outlet, build)
37
- - **[getFinalContext](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-final-context/README.md)** - Get final context information (project name)
38
-
39
- #### Product Actions
40
- - **[addProductToCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-to-cart/README.md)** - Add a product to the cart with optional discounts, fees, and notes
41
- - **[addProductDiscount](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-discount/README.md)** - Add a discount to a specific product in the cart (using `internalId`)
42
- - **[addProductNote](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-note/README.md)** - Add a note to a specific product in the cart (using `internalId`)
43
- - **[addProductFee](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-fee/README.md)** - Add a fee to a specific product in the cart (using `internalId`)
44
- - **[adjustInventory](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/adjust-inventory/README.md)** - Adjust inventory/stock level for a specific product variant
45
-
46
- #### Order Actions
47
- - **[addCustomSale](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-custom-sale/README.md)** - Add a custom sale item to the cart
48
- - **[addCartDiscount](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-cart-discount/README.md)** - Add a discount to the entire cart
49
- - **[addOrderNote](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-order-note/README.md)** - Add a note to the current order/cart
50
- - **[addCartFee](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-cart-fee/README.md)** - Add a fee to the entire cart
51
- - **[clearCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/clear-cart/README.md)** - Clear all items from the current cart
52
- - **[parkOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/park-order/README.md)** - Park (save) the current order for later retrieval
53
- - **[resumeParkedOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/resume-parked-order/README.md)** - Resume a previously parked order
54
- - **[deleteParkedOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/delete-parked-order/README.md)** - Delete a parked order
55
- - **[initiateRefund](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/initiate-refund/README.md)** - Open the refund UI for an order
56
- - **[cashPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/cash-payment/README.md)** - Initiate a cash payment
57
- - **[tapToPayPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/tap-to-pay-payment/README.md)** - Initiate a tap-to-pay payment
58
- - **[terminalPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/terminal-payment/README.md)** - Initiate a terminal payment
59
- - **[vendaraPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/vendara-payment/README.md)** - Initiate a Vendara payment
60
- - **[partialPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/partial-payment/README.md)** - Initiate a partial/split payment
61
-
62
- #### Customer Actions
63
- - **[addCustomer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-customer/README.md)** - Add a new customer to the local database
64
- - **[assignCustomer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/assign-customer/README.md)** - Assign an existing customer to the current session/cart
65
- - **[addCustomerNote](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-customer-note/README.md)** - Add a note to a customer's record
66
- - **[removeCustomerFromCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/remove-customer-from-cart/README.md)** - Remove the currently assigned customer from the cart
67
-
68
- #### System Actions
69
- - **[goToStationHome](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/go-to-station-home/README.md)** - Navigate to the station home page
70
- - **[openCashDrawer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/open-cash-drawer/README.md)** - Open the cash drawer
71
- - **[showNotification](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-notification/README.md)** - Show a notification message
72
- - **[showConfirmation](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-confirmation/README.md)** - Show a confirmation dialog
73
- - **[authenticateUser](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/authenticate-user/README.md)** - Trigger user authentication for specific roles
74
- - **[switchUser](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/switch-user/README.md)** - Switch the current user to a different user
75
-
76
- #### Refund Actions
77
- - **[selectAllRefundItems](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/select-all-refund-items/README.md)** - Select all remaining refundable items for a full refund
78
- - **[resetRefundDetails](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/reset-refund-details/README.md)** - Clear all refund selections
79
- - **[setRefundStockAction](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/set-refund-stock-action/README.md)** - Set stock handling option (restock/damage) for a refunded item
80
- - **[calculateRefundTotal](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/calculate-refund-total/README.md)** - Calculate refund total based on current selections
81
- - **[processPartialRefund](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/process-partial-refund/README.md)** - Process a partial refund based on current selections
82
- - **[getRemainingRefundableQuantities](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-remaining-refundable-quantities/README.md)** - Get remaining refundable quantities for items in the active order
83
-
84
- #### Integration Actions
85
- - **[triggerWebhook](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/trigger-webhook/README.md)** - Trigger a webhook with the specified configuration
86
- - **[triggerZapierWebhook](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/trigger-zapier-webhook/README.md)** - Trigger a Zapier webhook with the current context data
87
-
88
- #### Reference
89
- - **[exampleFunction](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/example-function/README.md)** - Example/template function (for reference only)
90
-
91
- For detailed documentation on each command, including parameter descriptions, response structures, and usage examples, see the [Commands Documentation](#commands-documentation) section below.
92
-
93
- ## Quick Start
94
-
95
- ```typescript
96
- import { command } from '@final-commerce/command-frame';
97
-
98
- // Get products from parent window
99
- const products = await command.getProducts();
100
-
101
- // Get customers from parent window
102
- const customers = await command.getCustomers();
103
-
104
- // Get categories from parent window
105
- const categories = await command.getCategories();
106
-
107
- // Add product to cart with optional discounts and fees
108
- const addedProduct = await command.addProductToCart({
109
- variantId: '691df9c6c478bada1fb23d55',
110
- quantity: 1,
111
- discounts: [{
112
- amount: 10,
113
- isPercent: false,
114
- label: 'Discount'
115
- }],
116
- notes: 'No onions'
117
- });
118
-
119
- // Add a discount to the specific item just added (if you didn't add it during creation)
120
- await command.addProductDiscount({
121
- internalId: addedProduct.internalId,
122
- amount: 5,
123
- isPercent: true,
124
- label: 'Extra 5% Off'
125
- });
126
-
127
- // Add cart discount
128
- await command.addCartDiscount({
129
- amount: 10,
130
- isPercent: false,
131
- label: 'Cart Discount'
132
- });
133
-
134
- // Get current context/environment
135
- const context = await command.getContext();
136
- console.log('Current user:', context.userId);
137
- console.log('Current company:', context.companyName);
138
- console.log('Current build:', context.buildName);
139
- ```
140
-
141
- For complete usage examples and detailed parameter descriptions, see the documentation for each command in the [Commands Documentation](#commands-documentation) section.
142
-
143
-
144
- ## Commands Documentation
145
-
146
- Each command has detailed documentation with complete parameter descriptions, response structures, and multiple usage examples:
147
-
148
- ### [getCustomers](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-customers/README.md)
149
-
150
- Retrieves a list of customers from the parent application's local database. Supports MongoDB query syntax for filtering, text search across name/email/phone fields, and pagination.
151
-
152
- ### [getProducts](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-products/README.md)
153
-
154
- Retrieves a list of products from the parent application's local database. Supports filtering by name, SKU, status, product type, categories, tags, and more.
155
-
156
- ### [addCustomer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-customer/README.md)
157
-
158
- Adds a new customer to the local database in the parent application. Supports full customer structure including addresses, metadata, notes, and tags.
159
-
160
- ### [assignCustomer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/assign-customer/README.md)
161
-
162
- Assigns an existing customer to the current active session/cart. The customer must exist in the local database.
163
-
164
- ### [getCategories](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-categories/README.md)
165
-
166
- Retrieves a list of categories from the parent application's local database. Supports filtering by name, parent ID, and external ID.
167
-
168
- ### [getOrders](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-orders/README.md)
169
-
170
- Retrieves a list of orders from the system with optional filtering, sorting, and pagination. Supports filtering by status, customer ID, session ID, and text search.
171
-
172
- ### [getCurrentCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-current-cart/README.md)
173
-
174
- Retrieves the current cart object with all its contents including products, custom sales, discounts, fees, totals, and customer information.
175
-
176
- ### [addCustomSale](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-custom-sale/README.md)
177
-
178
- Adds a custom sale item to the cart in the parent window. Useful for adding non-product items like service fees, discounts, or custom charges.
179
-
180
- ### [addProductToCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-to-cart/README.md)
181
-
182
- Adds a product to the cart. Supports specifying quantity, applying discounts, fees, and notes in a single atomic operation.
183
-
184
- ### [addProductDiscount](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-discount/README.md)
185
-
186
- Adds a discount to a specific product in the cart (identified by `internalId`). Supports both fixed amount and percentage discounts.
187
-
188
- ### [addCartDiscount](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-cart-discount/README.md)
189
-
190
- Adds a discount to the entire cart. Supports both fixed amount and percentage discounts. Applies to the cart subtotal and affects all items.
191
-
192
- ### [getContext](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-context/README.md)
193
-
194
- Retrieves the current environment/context information from the parent application. Returns user, company, device, station, outlet, and build information including IDs, names, and other relevant details.
195
-
196
- ### Product Actions
197
-
198
- ### [addProductNote](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-note/README.md)
199
-
200
- Adds a note to a specific product in the cart (identified by `internalId`).
201
-
202
- ### [addProductFee](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-fee/README.md)
203
-
204
- Adds a fee to a specific product in the cart (identified by `internalId`). Supports both fixed amount and percentage-based fees.
205
-
206
- ### [adjustInventory](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/adjust-inventory/README.md)
207
-
208
- Adjusts the inventory/stock level for a specific product variant. Supports adding, subtracting, or setting stock to a specific value.
209
-
210
- ### Order Actions
211
-
212
- ### [addOrderNote](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-order-note/README.md)
213
-
214
- Adds a note to the current order/cart.
215
-
216
- ### [addCartFee](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-cart-fee/README.md)
217
-
218
- Adds a fee to the entire cart. Supports both fixed amount and percentage-based fees.
219
-
220
- ### [clearCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/clear-cart/README.md)
221
-
222
- Clears all items from the current cart and resets cart-related state.
223
-
224
- ### [parkOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/park-order/README.md)
225
-
226
- Parks (saves) the current order for later retrieval. The cart is cleared after parking.
227
-
228
- ### [resumeParkedOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/resume-parked-order/README.md)
229
-
230
- Resumes a previously parked order by loading it back into the cart.
231
-
232
- ### [deleteParkedOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/delete-parked-order/README.md)
233
-
234
- Deletes a parked order from the system.
235
-
236
- ### [initiateRefund](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/initiate-refund/README.md)
237
-
238
- Opens the refund UI for the specified order or the currently active order.
239
-
240
- ### [cashPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/cash-payment/README.md)
15
+ ## Available Integrations
241
16
 
242
- Initiates a cash payment for the current cart. Opens the cash payment UI if change calculation is enabled.
17
+ This library supports multiple host environments. Choose the client that matches the platform you are building for.
243
18
 
244
- ### [tapToPayPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/tap-to-pay-payment/README.md)
19
+ ### 1. Render (POS System)
245
20
 
246
- Initiates a tap-to-pay payment for the current cart. May request tip if tip functionality is enabled.
21
+ For building applications that run inside the Render Point of Sale interface.
247
22
 
248
- ### [terminalPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/terminal-payment/README.md)
23
+ - **[Render Documentation](./src/projects/render/README.md)**
24
+ - **Features:** Order management, Product catalog, Customer management, Payments, Hardware integration (Cash drawer, Printer).
249
25
 
250
- Initiates a terminal payment for the current cart. May request tip if tip functionality is enabled.
26
+ **Quick Start:**
251
27
 
252
- ### [vendaraPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/vendara-payment/README.md)
253
-
254
- Initiates a Vendara payment for the current cart. May request tip if tip functionality is enabled.
255
-
256
- ### [partialPayment](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/partial-payment/README.md)
257
-
258
- Initiates a partial/split payment for the current cart. Can open the split payment UI or process a payment with a specified amount.
259
-
260
- ### Customer Actions
261
-
262
- ### [addCustomerNote](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-customer-note/README.md)
263
-
264
- Adds a note to a customer's record. Requires the customer ID.
265
-
266
- ### [removeCustomerFromCart](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/remove-customer-from-cart/README.md)
267
-
268
- Removes the currently assigned customer from the cart.
269
-
270
- ### System Actions
271
-
272
- ### [goToStationHome](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/go-to-station-home/README.md)
273
-
274
- Navigates to the station home page.
275
-
276
- ### [openCashDrawer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/open-cash-drawer/README.md)
277
-
278
- Opens the cash drawer (if connected to a compatible device).
279
-
280
- ### [showNotification](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-notification/README.md)
281
-
282
- Shows a notification message to the user.
283
-
284
- ### [showConfirmation](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-confirmation/README.md)
285
-
286
- Shows a confirmation dialog to the user. The actual promise resolution (accept/decline) is handled by the parent application's handler system.
287
-
288
- ### [authenticateUser](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/authenticate-user/README.md)
289
-
290
- Triggers user authentication for specific roles. Shows an authentication dialog in the parent application.
291
-
292
- ### [switchUser](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/switch-user/README.md)
293
-
294
- Switches the current user to a different user. Supports three modes: dialog (select from all users), role (select from users with specific roles), or specific (switch to a specific user).
295
-
296
- ### Refund Actions
297
-
298
- ### [selectAllRefundItems](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/select-all-refund-items/README.md)
299
-
300
- Selects all remaining refundable items (line items, custom sales, cart fees, and tips) for a full refund.
301
-
302
- ### [resetRefundDetails](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/reset-refund-details/README.md)
303
-
304
- Clears all refund selections (quantities, custom sales, cart fees, tips, and stock actions).
305
-
306
- ### [setRefundStockAction](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/set-refund-stock-action/README.md)
307
-
308
- Sets the stock handling option for a refunded line item (restock or mark as damaged).
309
-
310
- ### [calculateRefundTotal](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/calculate-refund-total/README.md)
311
-
312
- Calculates and returns a preview of the refund total based on current refund selections, without processing the refund.
313
-
314
- ### [processPartialRefund](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/process-partial-refund/README.md)
315
-
316
- Processes a partial refund based on the current refund selections in the refund details state.
317
-
318
- ### [getRemainingRefundableQuantities](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-remaining-refundable-quantities/README.md)
319
-
320
- Gets the remaining refundable quantities for all line items and custom sales in the active order.
321
-
322
- ### Integration Actions
323
-
324
- ### [triggerWebhook](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/trigger-webhook/README.md)
325
-
326
- Triggers a webhook with the specified configuration. Supports custom data, authentication, and various payload types.
327
-
328
- ### [triggerZapierWebhook](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/trigger-zapier-webhook/README.md)
329
-
330
- Triggers a Zapier webhook with the current context data (cart, customer, order, etc.).
331
-
332
- ### Reference
333
-
334
- ### [exampleFunction](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/example-function/README.md)
335
-
336
- An example/template function for reference. See the documentation for the structure to follow when creating new commands.
337
-
338
- ## Pub/Sub System
28
+ ```typescript
29
+ import { RenderClient } from '@final-commerce/command-frame';
339
30
 
340
- The library includes a pub/sub system that allows iframe apps to subscribe to topics and receive events published by the host application (Render).
31
+ // Initialize the client
32
+ const client = new RenderClient();
341
33
 
342
- ### Available Topics
34
+ // Use typed methods
35
+ const products = await client.getProducts();
36
+ ```
343
37
 
344
- #### Customer Events
345
- - **[customers](https://github.com/Final-Commerce/command-frame/blob/main/src/pubsub/topics/customers/README.md)** - Customer lifecycle events
346
- - `customer-created` - Fired when a new customer is created
347
- - `customer-updated` - Fired when a customer's information is updated
348
- - `customer-note-added` - Fired when a note is added to a customer
349
- - `customer-note-deleted` - Fired when a note is deleted from a customer
350
- - `customer-assigned` - Fired when a customer is assigned to the cart
351
- - `customer-unassigned` - Fired when a customer is unassigned from the cart
38
+ ### 2. Manage (Dashboard)
352
39
 
353
- #### Order Events
354
- - **[orders](https://github.com/Final-Commerce/command-frame/blob/main/src/pubsub/topics/orders/README.md)** - Order lifecycle events
355
- - `order-created` - Fired when a new order is created
356
- - `order-updated` - Fired when an order is updated
40
+ For building applications that run inside the Final Commerce Management Dashboard.
357
41
 
358
- #### Refund Events
359
- - **[refunds](https://github.com/Final-Commerce/command-frame/blob/main/src/pubsub/topics/refunds/README.md)** - Refund lifecycle events
360
- - `refund-created` - Fired when a refund is created
361
- - `refund-updated` - Fired when a refund is updated
42
+ - **[Manage Documentation](./src/projects/manage/README.md)**
43
+ - **Features:** Context information, Dashboard widgets (More coming soon).
362
44
 
363
- #### Product Events
364
- - **[products](https://github.com/Final-Commerce/command-frame/blob/main/src/pubsub/topics/products/README.md)** - Product sync events
365
- - `product-created` - Fired when a product is created
366
- - `product-updated` - Fired when a product is updated
45
+ **Quick Start:**
367
46
 
368
- #### Cart Events
369
- - **[cart](https://github.com/Final-Commerce/command-frame/blob/main/src/pubsub/topics/cart/README.md)** - Cart operation events
370
- - `cart-created` - Fired when a cart is created
371
- - `customer-assigned` - Fired when a customer is assigned to the cart
372
- - `product-added` - Fired when a product is added to the cart
373
- - `product-deleted` - Fired when a product is removed from the cart
374
- - `cart-discount-added` - Fired when a discount is added to the cart
375
- - `cart-discount-removed` - Fired when a discount is removed from the cart
376
- - `cart-fee-added` - Fired when a fee is added to the cart
377
- - `cart-fee-removed` - Fired when a fee is removed from the cart
47
+ ```typescript
48
+ import { ManageClient } from '@final-commerce/command-frame';
378
49
 
379
- #### Payment Events
380
- - **[payments](https://github.com/Final-Commerce/command-frame/blob/main/src/pubsub/topics/payments/README.md)** - Payment processing events
381
- - `payment-done` - Fired when a payment is successfully completed
382
- - `payment-err` - Fired when a payment fails
50
+ const client = new ManageClient();
51
+ const context = await client.getContext();
52
+ ```
383
53
 
384
- For detailed documentation on each topic and its events, including payload structures and usage examples, see the [Pub/Sub Documentation](https://github.com/Final-Commerce/command-frame/blob/main/src/pubsub/README.md).
54
+ ## Development & Testing
385
55
 
386
- ## Examples
56
+ ### Demo Mode / Mocking
387
57
 
388
- See the [example/](https://github.com/Final-Commerce/command-frame/tree/main/example) folder for a working React + Vite demo application that demonstrates how to use this library in a real-world scenario.
58
+ Each client comes with built-in mock data for local development.
389
59
 
390
- To run the example:
60
+ - If the application detects it is not running inside a valid host iframe, it automatically switches to **Mock Mode**.
61
+ - In Mock Mode, all API calls return local dummy data instead of failing.
62
+ - You can force Mock Mode by passing `mockMode: true` to the client constructor.
391
63
 
392
- ```bash
393
- cd example
394
- npm install
395
- npm run dev
64
+ ```typescript
65
+ const client = new RenderClient({ mockMode: true, debug: true });
396
66
  ```
397
67
 
398
- ## Debugging
68
+ ### Debugging
399
69
 
400
- Enable debug logging by setting the debug flag before importing:
70
+ Enable debug logging to see all message passing activity in the console:
401
71
 
402
72
  ```typescript
403
- (window as any).__POSTMESSAGE_DEBUG__ = true;
404
- import { command } from '@final-commerce/command-frame';
73
+ const client = new RenderClient({ debug: true });
405
74
  ```
406
75
 
407
- This will log all postMessage communication to the console, including:
408
- - Request details (action name, parameters, request ID)
409
- - Response details (success status, data, errors)
410
- - Timing information
411
- - Origin validation
412
-
413
- ## Type Safety
414
-
415
- All commands are fully typed with TypeScript. Import types for use in your code:
76
+ Alternatively, set the global flag before initialization:
416
77
 
417
78
  ```typescript
418
- import type {
419
- // Data Retrieval
420
- GetCustomersParams, GetCustomersResponse, GetCustomers,
421
- GetProductsParams, GetProductsResponse, GetProducts,
422
- GetCategoriesParams, GetCategoriesResponse, GetCategories,
423
- GetOrdersParams, GetOrdersResponse, GetOrders,
424
- GetContext, GetContextResponse,
425
- GetFinalContext, GetFinalContextResponse,
426
- GetCurrentCart, GetCurrentCartResponse,
427
- // Product Actions
428
- AddProductDiscountParams, AddProductDiscountResponse, AddProductDiscount,
429
- AddProductToCartParams, AddProductToCartResponse, AddProductToCart,
430
- AddProductNoteParams, AddProductNoteResponse, AddProductNote,
431
- AddProductFeeParams, AddProductFeeResponse, AddProductFee,
432
- AdjustInventoryParams, AdjustInventoryResponse, AdjustInventory,
433
- // Order Actions
434
- AddCustomSaleParams, AddCustomSaleResponse, AddCustomSale,
435
- AddCartDiscountParams, AddCartDiscountResponse, AddCartDiscount,
436
- AddOrderNoteParams, AddOrderNoteResponse, AddOrderNote,
437
- AddCartFeeParams, AddCartFeeResponse, AddCartFee,
438
- ClearCartResponse, ClearCart,
439
- ParkOrderResponse, ParkOrder,
440
- ResumeParkedOrderParams, ResumeParkedOrderResponse, ResumeParkedOrder,
441
- DeleteParkedOrderParams, DeleteParkedOrderResponse, DeleteParkedOrder,
442
- InitiateRefundParams, InitiateRefundResponse, InitiateRefund,
443
- CashPaymentParams, CashPaymentResponse, CashPayment,
444
- TapToPayPaymentParams, TapToPayPaymentResponse, TapToPayPayment,
445
- TerminalPaymentParams, TerminalPaymentResponse, TerminalPayment,
446
- VendaraPaymentParams, VendaraPaymentResponse, VendaraPayment,
447
- PartialPaymentParams, PartialPaymentResponse, PartialPayment,
448
- // Customer Actions
449
- AddCustomerParams, AddCustomerResponse, AddCustomer,
450
- AssignCustomerParams, AssignCustomerResponse, AssignCustomer,
451
- AddCustomerNoteParams, AddCustomerNoteResponse, AddCustomerNote,
452
- RemoveCustomerFromCartResponse, RemoveCustomerFromCart,
453
- // System Actions
454
- GoToStationHomeResponse, GoToStationHome,
455
- OpenCashDrawerResponse, OpenCashDrawer,
456
- ShowNotificationParams, ShowNotificationResponse, ShowNotification,
457
- ShowConfirmationParams, ShowConfirmationResponse, ShowConfirmation,
458
- AuthenticateUserParams, AuthenticateUserResponse, AuthenticateUser,
459
- SwitchUserParams, SwitchUserResponse, SwitchUser,
460
- // Refund Actions
461
- SelectAllRefundItemsParams, SelectAllRefundItemsResponse, SelectAllRefundItems,
462
- ResetRefundDetailsResponse, ResetRefundDetails,
463
- SetRefundStockActionParams, SetRefundStockActionResponse, SetRefundStockAction,
464
- CalculateRefundTotalResponse, CalculateRefundTotal,
465
- ProcessPartialRefundParams, ProcessPartialRefundResponse, ProcessPartialRefund,
466
- GetRemainingRefundableQuantitiesParams, GetRemainingRefundableQuantitiesResponse, GetRemainingRefundableQuantities,
467
- // Integration Actions
468
- TriggerWebhookParams, TriggerWebhookResponse, TriggerWebhook,
469
- TriggerZapierWebhookParams, TriggerZapierWebhookResponse, TriggerZapierWebhook,
470
- // Reference
471
- ExampleFunctionParams, ExampleFunctionResponse, ExampleFunction,
472
- // Common Types (Directly exported)
473
- CFProduct, CFProductVariant, CFProductType,
474
- CFCustomer, CFActiveCustomer, CFCustomerNote,
475
- CFOrder, CFActiveOrder, CFActiveCart,
476
- CFActiveProduct, CFActiveCustomSales,
477
- CFLineItem, CFCustomSale,
478
- CFDiscount, CFCustomFee, CFTax,
479
- CFAddress, CFMetadataItem,
480
- CFActiveUser, CFActiveOutlet, CFActiveStation,
481
- CFContext
482
- } from '@final-commerce/command-frame';
79
+ (window as any).__POSTMESSAGE_DEBUG__ = true;
483
80
  ```
484
81
 
485
- **Note:** The library exports useful types like `CFProduct`, `CFActiveCart`, `CFCustomer`, etc., we recommend using them in your code to type args for components displaying Products/ Customers / Variations / Orders etc
486
-
487
82
  ## License
488
83
 
489
84
  MIT
490
-
491
- See [LICENSE](LICENSE) file for details.
@@ -55,9 +55,9 @@ export interface CFTax {
55
55
  taxTableId: string;
56
56
  }
57
57
  export interface CFInventory {
58
- warehouse: string;
59
58
  outletId: string;
60
59
  stock?: number | null;
60
+ _id?: string;
61
61
  }
62
62
  export interface CFCustomerNote {
63
63
  createdAt: string;
@@ -87,7 +87,7 @@ export interface CFProductVariant {
87
87
  barcode?: string;
88
88
  costPrice?: string;
89
89
  manageStock: boolean;
90
- externalId: string;
90
+ externalId?: string;
91
91
  inventory?: CFInventory[];
92
92
  allowBackorder?: boolean;
93
93
  images?: string[];
@@ -104,16 +104,13 @@ export interface CFProductVariant {
104
104
  export interface CFProduct {
105
105
  _id: string;
106
106
  companyId?: string;
107
- externalId: string;
107
+ externalId?: string;
108
108
  taxTable: string;
109
109
  name: string;
110
110
  description?: string;
111
111
  shortDescription?: string;
112
112
  images?: string[];
113
- categories: {
114
- name: string;
115
- externalId: string;
116
- };
113
+ categories: string[];
117
114
  attributes: {
118
115
  name: string;
119
116
  values: string[];
@@ -1,4 +1,4 @@
1
- import { MOCK_CART } from "../../demo/database";
1
+ import { MOCK_CART, mockPublishEvent } from "../../demo/database";
2
2
  export const mockAddCartDiscount = async (params) => {
3
3
  console.log("[Mock] addCartDiscount called", params);
4
4
  if (params) {
@@ -16,6 +16,10 @@ export const mockAddCartDiscount = async (params) => {
16
16
  }
17
17
  MOCK_CART.amountToBeCharged = MOCK_CART.total;
18
18
  MOCK_CART.remainingBalance = MOCK_CART.total;
19
+ // Publish cart-discount-added event
20
+ mockPublishEvent('cart', 'cart-discount-added', {
21
+ discount: MOCK_CART.discount
22
+ });
19
23
  }
20
24
  return {
21
25
  success: true,
@@ -1,4 +1,4 @@
1
- import { MOCK_CART, MOCK_PRODUCTS } from "../../demo/database";
1
+ import { MOCK_CART, MOCK_PRODUCTS, mockPublishEvent } from "../../demo/database";
2
2
  export const mockAddProductToCart = async (params) => {
3
3
  console.log("[Mock] addProductToCart called", params);
4
4
  const variantId = params?.variantId;
@@ -48,6 +48,8 @@ export const mockAddProductToCart = async (params) => {
48
48
  MOCK_CART.total += lineTotal;
49
49
  MOCK_CART.amountToBeCharged = MOCK_CART.total;
50
50
  MOCK_CART.remainingBalance = MOCK_CART.total;
51
+ // Publish cart event to simulate real behavior
52
+ mockPublishEvent('cart', 'product-added', { product: activeProduct });
51
53
  return {
52
54
  success: true,
53
55
  productId: activeProduct.id,
@@ -1,4 +1,4 @@
1
- import { MOCK_CUSTOMERS, MOCK_CART } from "../../demo/database";
1
+ import { MOCK_CUSTOMERS, MOCK_CART, mockPublishEvent } from "../../demo/database";
2
2
  export const mockAssignCustomer = async (params) => {
3
3
  console.log("[Mock] assignCustomer called", params);
4
4
  const customer = MOCK_CUSTOMERS.find(c => c._id === params.customerId);
@@ -6,6 +6,8 @@ export const mockAssignCustomer = async (params) => {
6
6
  throw new Error("Customer not found in mock DB");
7
7
  }
8
8
  MOCK_CART.customer = customer;
9
+ // Publish customer-assigned event
10
+ mockPublishEvent('cart', 'customer-assigned', { customer });
9
11
  window.alert(`Demo: Customer Assigned to Cart\nName: ${customer.firstName} ${customer.lastName}`);
10
12
  return {
11
13
  success: true,
@@ -1,4 +1,4 @@
1
- import { createOrderFromCart, MOCK_CART } from "../../demo/database";
1
+ import { createOrderFromCart, MOCK_CART, mockPublishEvent } from "../../demo/database";
2
2
  export const mockCashPayment = async (params) => {
3
3
  console.log("[Mock] cashPayment called", params);
4
4
  // Default to true to match action behavior
@@ -35,6 +35,8 @@ export const mockCashPayment = async (params) => {
35
35
  }
36
36
  }
37
37
  const order = createOrderFromCart("cash", amount, "cash");
38
+ // Publish payment-done event
39
+ mockPublishEvent('payments', 'payment-done', { order });
38
40
  return {
39
41
  success: true,
40
42
  amount,