@final-commerce/command-frame 0.1.11 → 0.1.13
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 +7 -48
- package/dist/actions/add-custom-sale/mock.js +21 -1
- package/dist/actions/add-custom-sale/types.d.ts +1 -0
- package/dist/actions/add-customer/mock.js +1 -0
- package/dist/actions/add-customer-note/mock.js +13 -0
- package/dist/actions/add-order-note/mock.js +10 -0
- package/dist/actions/add-product-discount/mock.js +20 -1
- package/dist/actions/add-product-discount/types.d.ts +3 -2
- package/dist/actions/add-product-fee/mock.js +19 -1
- package/dist/actions/add-product-fee/types.d.ts +3 -2
- package/dist/actions/add-product-note/mock.js +12 -1
- package/dist/actions/add-product-note/types.d.ts +3 -3
- package/dist/actions/add-product-to-cart/types.d.ts +1 -0
- package/dist/actions/adjust-inventory/mock.js +26 -8
- package/dist/actions/adjust-inventory/types.d.ts +1 -0
- package/dist/actions/assign-customer/mock.js +1 -0
- package/dist/actions/cash-payment/action.js +5 -1
- package/dist/actions/cash-payment/mock.js +35 -3
- package/dist/actions/delete-parked-order/mock.js +7 -0
- package/dist/actions/initiate-refund/mock.js +1 -0
- package/dist/actions/open-cash-drawer/mock.js +1 -0
- package/dist/actions/park-order/mock.js +14 -2
- package/dist/actions/partial-payment/action.js +5 -1
- package/dist/actions/partial-payment/mock.js +7 -2
- package/dist/actions/remove-customer-from-cart/mock.js +1 -0
- package/dist/actions/resume-parked-order/mock.js +46 -2
- package/dist/actions/show-confirmation/mock.js +4 -1
- package/dist/actions/show-notification/mock.js +1 -0
- package/dist/actions/tap-to-pay-payment/mock.js +2 -0
- package/dist/actions/terminal-payment/mock.js +4 -2
- package/dist/demo/database.d.ts +1 -0
- package/dist/demo/database.js +1 -0
- package/dist/demo/registry.js +0 -12
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -12
- package/package.json +1 -1
- package/dist/actions/get-line-items-by-order/action.d.ts +0 -6
- package/dist/actions/get-line-items-by-order/action.js +0 -8
- package/dist/actions/get-line-items-by-order/mock.d.ts +0 -2
- package/dist/actions/get-line-items-by-order/mock.js +0 -12
- package/dist/actions/get-line-items-by-order/types.d.ts +0 -15
- package/dist/actions/get-line-items-by-order/types.js +0 -1
- package/dist/actions/get-product-variants/action.d.ts +0 -6
- package/dist/actions/get-product-variants/action.js +0 -8
- package/dist/actions/get-product-variants/mock.d.ts +0 -2
- package/dist/actions/get-product-variants/mock.js +0 -14
- package/dist/actions/get-product-variants/types.d.ts +0 -10
- package/dist/actions/get-product-variants/types.js +0 -1
- package/dist/actions/go-to-page/action.d.ts +0 -6
- package/dist/actions/go-to-page/action.js +0 -8
- package/dist/actions/go-to-page/mock.d.ts +0 -2
- package/dist/actions/go-to-page/mock.js +0 -8
- package/dist/actions/go-to-page/types.d.ts +0 -9
- package/dist/actions/go-to-page/types.js +0 -1
- package/dist/actions/open-popup/action.d.ts +0 -6
- package/dist/actions/open-popup/action.js +0 -8
- package/dist/actions/open-popup/mock.d.ts +0 -2
- package/dist/actions/open-popup/mock.js +0 -8
- package/dist/actions/open-popup/types.d.ts +0 -9
- package/dist/actions/open-popup/types.js +0 -1
- package/dist/actions/toggle-slide-out/action.d.ts +0 -6
- package/dist/actions/toggle-slide-out/action.js +0 -8
- package/dist/actions/toggle-slide-out/mock.d.ts +0 -2
- package/dist/actions/toggle-slide-out/mock.js +0 -8
- package/dist/actions/toggle-slide-out/types.d.ts +0 -9
- package/dist/actions/toggle-slide-out/types.js +0 -1
- package/dist/actions/update-customer-facing-display/action.d.ts +0 -6
- package/dist/actions/update-customer-facing-display/action.js +0 -8
- package/dist/actions/update-customer-facing-display/mock.d.ts +0 -2
- package/dist/actions/update-customer-facing-display/mock.js +0 -8
- package/dist/actions/update-customer-facing-display/types.d.ts +0 -9
- package/dist/actions/update-customer-facing-display/types.js +0 -1
package/README.md
CHANGED
|
@@ -31,7 +31,6 @@ The library provides a `command` namespace object containing all available comma
|
|
|
31
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
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
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
|
-
- **[getProductVariants](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-product-variants/README.md)** - Retrieve all variants for a specific product
|
|
35
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
|
|
36
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
|
|
37
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)
|
|
@@ -39,9 +38,9 @@ The library provides a `command` namespace object containing all available comma
|
|
|
39
38
|
|
|
40
39
|
#### Product Actions
|
|
41
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
|
|
42
|
-
- **[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 `
|
|
43
|
-
- **[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 `
|
|
44
|
-
- **[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 `
|
|
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`)
|
|
45
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
|
|
46
45
|
|
|
47
46
|
#### Order Actions
|
|
@@ -68,18 +67,13 @@ The library provides a `command` namespace object containing all available comma
|
|
|
68
67
|
|
|
69
68
|
#### System Actions
|
|
70
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
|
|
71
|
-
- **[goToPage](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/go-to-page/README.md)** - Navigate to a specific page
|
|
72
70
|
- **[openCashDrawer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/open-cash-drawer/README.md)** - Open the cash drawer
|
|
73
|
-
- **[openPopup](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/open-popup/README.md)** - Open a popup/modal by ID
|
|
74
71
|
- **[showNotification](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-notification/README.md)** - Show a notification message
|
|
75
|
-
- **[toggleSlideOut](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/toggle-slide-out/README.md)** - Toggle a slide-out panel
|
|
76
72
|
- **[showConfirmation](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-confirmation/README.md)** - Show a confirmation dialog
|
|
77
73
|
- **[authenticateUser](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/authenticate-user/README.md)** - Trigger user authentication for specific roles
|
|
78
|
-
- **[updateCustomerFacingDisplay](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/update-customer-facing-display/README.md)** - Update the customer-facing display to show a specific page
|
|
79
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
|
|
80
75
|
|
|
81
76
|
#### Refund Actions
|
|
82
|
-
- **[getLineItemsByOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-line-items-by-order/README.md)** - Retrieve line items and custom sales from an order for refund purposes
|
|
83
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
|
|
84
78
|
- **[resetRefundDetails](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/reset-refund-details/README.md)** - Clear all refund selections
|
|
85
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
|
|
@@ -110,11 +104,6 @@ const customers = await command.getCustomers();
|
|
|
110
104
|
// Get categories from parent window
|
|
111
105
|
const categories = await command.getCategories();
|
|
112
106
|
|
|
113
|
-
// Get variants for a product
|
|
114
|
-
const variants = await command.getProductVariants({
|
|
115
|
-
productId: '691df9c6c478bada1fb23d31'
|
|
116
|
-
});
|
|
117
|
-
|
|
118
107
|
// Add product to cart with optional discounts and fees
|
|
119
108
|
const addedProduct = await command.addProductToCart({
|
|
120
109
|
variantId: '691df9c6c478bada1fb23d55',
|
|
@@ -129,7 +118,7 @@ const addedProduct = await command.addProductToCart({
|
|
|
129
118
|
|
|
130
119
|
// Add a discount to the specific item just added (if you didn't add it during creation)
|
|
131
120
|
await command.addProductDiscount({
|
|
132
|
-
|
|
121
|
+
internalId: addedProduct.internalId,
|
|
133
122
|
amount: 5,
|
|
134
123
|
isPercent: true,
|
|
135
124
|
label: 'Extra 5% Off'
|
|
@@ -176,10 +165,6 @@ Assigns an existing customer to the current active session/cart. The customer mu
|
|
|
176
165
|
|
|
177
166
|
Retrieves a list of categories from the parent application's local database. Supports filtering by name, parent ID, and external ID.
|
|
178
167
|
|
|
179
|
-
### [getProductVariants](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-product-variants/README.md)
|
|
180
|
-
|
|
181
|
-
Retrieves all variants for a specific product from the parent application's local database. Useful for displaying variant options or selecting a specific variant.
|
|
182
|
-
|
|
183
168
|
### [getOrders](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-orders/README.md)
|
|
184
169
|
|
|
185
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.
|
|
@@ -198,7 +183,7 @@ Adds a product to the cart. Supports specifying quantity, applying discounts, fe
|
|
|
198
183
|
|
|
199
184
|
### [addProductDiscount](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-discount/README.md)
|
|
200
185
|
|
|
201
|
-
Adds a discount to a specific product in the cart (identified by `
|
|
186
|
+
Adds a discount to a specific product in the cart (identified by `internalId`). Supports both fixed amount and percentage discounts.
|
|
202
187
|
|
|
203
188
|
### [addCartDiscount](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-cart-discount/README.md)
|
|
204
189
|
|
|
@@ -212,11 +197,11 @@ Retrieves the current environment/context information from the parent applicatio
|
|
|
212
197
|
|
|
213
198
|
### [addProductNote](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-note/README.md)
|
|
214
199
|
|
|
215
|
-
Adds a note to a specific product in the cart (identified by `
|
|
200
|
+
Adds a note to a specific product in the cart (identified by `internalId`).
|
|
216
201
|
|
|
217
202
|
### [addProductFee](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/add-product-fee/README.md)
|
|
218
203
|
|
|
219
|
-
Adds a fee to a specific product in the cart (identified by `
|
|
204
|
+
Adds a fee to a specific product in the cart (identified by `internalId`). Supports both fixed amount and percentage-based fees.
|
|
220
205
|
|
|
221
206
|
### [adjustInventory](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/adjust-inventory/README.md)
|
|
222
207
|
|
|
@@ -288,26 +273,14 @@ Removes the currently assigned customer from the cart.
|
|
|
288
273
|
|
|
289
274
|
Navigates to the station home page.
|
|
290
275
|
|
|
291
|
-
### [goToPage](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/go-to-page/README.md)
|
|
292
|
-
|
|
293
|
-
Navigates to a specific page in the application by page ID.
|
|
294
|
-
|
|
295
276
|
### [openCashDrawer](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/open-cash-drawer/README.md)
|
|
296
277
|
|
|
297
278
|
Opens the cash drawer (if connected to a compatible device).
|
|
298
279
|
|
|
299
|
-
### [openPopup](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/open-popup/README.md)
|
|
300
|
-
|
|
301
|
-
Opens a popup/modal by ID. If the popup is already open, calling this will close it (toggle behavior).
|
|
302
|
-
|
|
303
280
|
### [showNotification](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-notification/README.md)
|
|
304
281
|
|
|
305
282
|
Shows a notification message to the user.
|
|
306
283
|
|
|
307
|
-
### [toggleSlideOut](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/toggle-slide-out/README.md)
|
|
308
|
-
|
|
309
|
-
Toggles (opens/closes) a slide-out panel by ID.
|
|
310
|
-
|
|
311
284
|
### [showConfirmation](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/show-confirmation/README.md)
|
|
312
285
|
|
|
313
286
|
Shows a confirmation dialog to the user. The actual promise resolution (accept/decline) is handled by the parent application's handler system.
|
|
@@ -316,20 +289,12 @@ Shows a confirmation dialog to the user. The actual promise resolution (accept/d
|
|
|
316
289
|
|
|
317
290
|
Triggers user authentication for specific roles. Shows an authentication dialog in the parent application.
|
|
318
291
|
|
|
319
|
-
### [updateCustomerFacingDisplay](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/update-customer-facing-display/README.md)
|
|
320
|
-
|
|
321
|
-
Updates the customer-facing display to show a specific page by page ID.
|
|
322
|
-
|
|
323
292
|
### [switchUser](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/switch-user/README.md)
|
|
324
293
|
|
|
325
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).
|
|
326
295
|
|
|
327
296
|
### Refund Actions
|
|
328
297
|
|
|
329
|
-
### [getLineItemsByOrder](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/get-line-items-by-order/README.md)
|
|
330
|
-
|
|
331
|
-
Retrieves line items and custom sales from an order, along with calculated remaining refundable quantities for each item.
|
|
332
|
-
|
|
333
298
|
### [selectAllRefundItems](https://github.com/Final-Commerce/command-frame/blob/main/src/actions/select-all-refund-items/README.md)
|
|
334
299
|
|
|
335
300
|
Selects all remaining refundable items (line items, custom sales, cart fees, and tips) for a full refund.
|
|
@@ -455,7 +420,6 @@ import type {
|
|
|
455
420
|
GetCustomersParams, GetCustomersResponse, GetCustomers,
|
|
456
421
|
GetProductsParams, GetProductsResponse, GetProducts,
|
|
457
422
|
GetCategoriesParams, GetCategoriesResponse, GetCategories,
|
|
458
|
-
GetProductVariantsParams, GetProductVariantsResponse, GetProductVariants,
|
|
459
423
|
GetOrdersParams, GetOrdersResponse, GetOrders,
|
|
460
424
|
GetContext, GetContextResponse,
|
|
461
425
|
GetFinalContext, GetFinalContextResponse,
|
|
@@ -488,17 +452,12 @@ import type {
|
|
|
488
452
|
RemoveCustomerFromCartResponse, RemoveCustomerFromCart,
|
|
489
453
|
// System Actions
|
|
490
454
|
GoToStationHomeResponse, GoToStationHome,
|
|
491
|
-
GoToPageParams, GoToPageResponse, GoToPage,
|
|
492
455
|
OpenCashDrawerResponse, OpenCashDrawer,
|
|
493
|
-
OpenPopupParams, OpenPopupResponse, OpenPopup,
|
|
494
456
|
ShowNotificationParams, ShowNotificationResponse, ShowNotification,
|
|
495
|
-
ToggleSlideOutParams, ToggleSlideOutResponse, ToggleSlideOut,
|
|
496
457
|
ShowConfirmationParams, ShowConfirmationResponse, ShowConfirmation,
|
|
497
458
|
AuthenticateUserParams, AuthenticateUserResponse, AuthenticateUser,
|
|
498
|
-
UpdateCustomerFacingDisplayParams, UpdateCustomerFacingDisplayResponse, UpdateCustomerFacingDisplay,
|
|
499
459
|
SwitchUserParams, SwitchUserResponse, SwitchUser,
|
|
500
460
|
// Refund Actions
|
|
501
|
-
GetLineItemsByOrderParams, GetLineItemsByOrderResponse, GetLineItemsByOrder,
|
|
502
461
|
SelectAllRefundItemsParams, SelectAllRefundItemsResponse, SelectAllRefundItems,
|
|
503
462
|
ResetRefundDetailsResponse, ResetRefundDetails,
|
|
504
463
|
SetRefundStockActionParams, SetRefundStockActionResponse, SetRefundStockAction,
|
|
@@ -1,14 +1,34 @@
|
|
|
1
|
+
import { MOCK_CART } from "../../demo/database";
|
|
1
2
|
export const mockAddCustomSale = async (params) => {
|
|
2
3
|
console.log("[Mock] addCustomSale called", params);
|
|
3
4
|
if (!params)
|
|
4
5
|
throw new Error("Params required");
|
|
5
6
|
// Simple mock ID generation
|
|
6
7
|
const mockId = 'sale_' + Math.random().toString(36).substr(2, 9);
|
|
8
|
+
const price = Number(params.price);
|
|
9
|
+
const quantity = 1; // Default to 1 for custom sale usually
|
|
10
|
+
const customSale = {
|
|
11
|
+
id: mockId,
|
|
12
|
+
name: params.label,
|
|
13
|
+
price: price,
|
|
14
|
+
quantity: quantity,
|
|
15
|
+
applyTaxes: params.applyTaxes ?? false,
|
|
16
|
+
taxTableId: params.taxTableId
|
|
17
|
+
};
|
|
18
|
+
if (!MOCK_CART.customSales) {
|
|
19
|
+
MOCK_CART.customSales = [];
|
|
20
|
+
}
|
|
21
|
+
MOCK_CART.customSales.push(customSale);
|
|
22
|
+
// Update Cart Totals
|
|
23
|
+
MOCK_CART.subtotal += price * quantity;
|
|
24
|
+
MOCK_CART.total += price * quantity;
|
|
25
|
+
MOCK_CART.amountToBeCharged = MOCK_CART.total;
|
|
26
|
+
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
7
27
|
return {
|
|
8
28
|
success: true,
|
|
9
29
|
customSaleId: mockId,
|
|
10
30
|
label: params.label,
|
|
11
|
-
price:
|
|
31
|
+
price: price,
|
|
12
32
|
applyTaxes: params.applyTaxes ?? false,
|
|
13
33
|
timestamp: new Date().toISOString()
|
|
14
34
|
};
|
|
@@ -10,6 +10,7 @@ export const mockAddCustomer = async (params) => {
|
|
|
10
10
|
updatedAt: new Date().toISOString()
|
|
11
11
|
};
|
|
12
12
|
MOCK_CUSTOMERS.push(newCustomer);
|
|
13
|
+
window.alert(`Demo: Customer Created!\nName: ${newCustomer.firstName} ${newCustomer.lastName}\nEmail: ${newCustomer.email}`);
|
|
13
14
|
return {
|
|
14
15
|
success: true,
|
|
15
16
|
customer: newCustomer,
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
import { MOCK_CUSTOMERS } from "../../demo/database";
|
|
1
2
|
export const mockAddCustomerNote = async (params) => {
|
|
2
3
|
console.log("[Mock] addCustomerNote called", params);
|
|
4
|
+
if (params?.customerId && params.note) {
|
|
5
|
+
const customer = MOCK_CUSTOMERS.find(c => c._id === params.customerId);
|
|
6
|
+
if (customer) {
|
|
7
|
+
if (!customer.notes) {
|
|
8
|
+
customer.notes = [];
|
|
9
|
+
}
|
|
10
|
+
customer.notes.push({
|
|
11
|
+
message: params.note,
|
|
12
|
+
createdAt: new Date().toISOString()
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
3
16
|
return {
|
|
4
17
|
success: true,
|
|
5
18
|
customerId: params?.customerId || "",
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
import { MOCK_CART } from "../../demo/database";
|
|
1
2
|
export const mockAddOrderNote = async (params) => {
|
|
2
3
|
console.log("[Mock] addOrderNote called", params);
|
|
4
|
+
// In Render, AddOrderNote usually adds a note to the active cart if it's not checked out yet.
|
|
5
|
+
if (params?.note) {
|
|
6
|
+
if (MOCK_CART.orderNotes) {
|
|
7
|
+
MOCK_CART.orderNotes += "\n" + params.note;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
MOCK_CART.orderNotes = params.note;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
3
13
|
return {
|
|
4
14
|
success: true,
|
|
5
15
|
note: params?.note || "",
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
+
import { MOCK_CART } from "../../demo/database";
|
|
1
2
|
export const mockAddProductDiscount = async (params) => {
|
|
2
3
|
console.log("[Mock] addProductDiscount called", params);
|
|
4
|
+
if (params && (params.amount > 0 || params.amount < 0)) { // Allow 0 to clear discount if logic permits
|
|
5
|
+
let item = null;
|
|
6
|
+
if (params.internalId) {
|
|
7
|
+
item = MOCK_CART.products.find(p => p.internalId === params.internalId);
|
|
8
|
+
}
|
|
9
|
+
else if (MOCK_CART.products.length > 0) {
|
|
10
|
+
item = MOCK_CART.products[MOCK_CART.products.length - 1];
|
|
11
|
+
}
|
|
12
|
+
if (item) {
|
|
13
|
+
item.discount = {
|
|
14
|
+
value: params.amount,
|
|
15
|
+
isPercent: params.isPercent || false,
|
|
16
|
+
label: params.label
|
|
17
|
+
};
|
|
18
|
+
// Recalculate cart totals (simplified)
|
|
19
|
+
// Ideally, this should trigger a full recalculation function
|
|
20
|
+
}
|
|
21
|
+
}
|
|
3
22
|
return {
|
|
4
23
|
success: true,
|
|
5
24
|
amount: params?.amount || 0,
|
|
6
25
|
isPercent: params?.isPercent || false,
|
|
7
26
|
label: params?.label || "",
|
|
8
|
-
|
|
27
|
+
internalId: params?.internalId,
|
|
9
28
|
timestamp: new Date().toISOString()
|
|
10
29
|
};
|
|
11
30
|
};
|
|
@@ -5,14 +5,15 @@ export interface AddProductDiscountParams {
|
|
|
5
5
|
isPercent?: boolean;
|
|
6
6
|
/** Defaults to "Discount". */
|
|
7
7
|
label?: string;
|
|
8
|
-
|
|
8
|
+
/** The unique identifier for a specific line item in the cart. */
|
|
9
|
+
internalId?: string;
|
|
9
10
|
}
|
|
10
11
|
export interface AddProductDiscountResponse {
|
|
11
12
|
success: boolean;
|
|
12
13
|
amount: number;
|
|
13
14
|
isPercent: boolean;
|
|
14
15
|
label: string;
|
|
15
|
-
|
|
16
|
+
internalId?: string;
|
|
16
17
|
timestamp: string;
|
|
17
18
|
}
|
|
18
19
|
export type AddProductDiscount = (params?: AddProductDiscountParams) => Promise<AddProductDiscountResponse>;
|
|
@@ -1,12 +1,30 @@
|
|
|
1
|
+
import { MOCK_CART } from "../../demo/database";
|
|
1
2
|
export const mockAddProductFee = async (params) => {
|
|
2
3
|
console.log("[Mock] addProductFee called", params);
|
|
4
|
+
if (params) {
|
|
5
|
+
let item = null;
|
|
6
|
+
if (params.internalId) {
|
|
7
|
+
item = MOCK_CART.products.find(p => p.internalId === params.internalId);
|
|
8
|
+
}
|
|
9
|
+
else if (MOCK_CART.products.length > 0) {
|
|
10
|
+
item = MOCK_CART.products[MOCK_CART.products.length - 1];
|
|
11
|
+
}
|
|
12
|
+
if (item) {
|
|
13
|
+
item.fee = {
|
|
14
|
+
label: params.label || "Fee",
|
|
15
|
+
amount: params.amount,
|
|
16
|
+
isPercent: params.isPercent || false,
|
|
17
|
+
applyTaxes: params.applyTaxes || false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
3
21
|
return {
|
|
4
22
|
success: true,
|
|
5
23
|
amount: params?.amount || 0,
|
|
6
24
|
isPercent: params?.isPercent || false,
|
|
7
25
|
label: params?.label || "",
|
|
8
26
|
applyTaxes: params?.applyTaxes || false,
|
|
9
|
-
|
|
27
|
+
internalId: params?.internalId,
|
|
10
28
|
timestamp: new Date().toISOString()
|
|
11
29
|
};
|
|
12
30
|
};
|
|
@@ -7,7 +7,8 @@ export interface AddProductFeeParams {
|
|
|
7
7
|
/** Defaults to `false`. */
|
|
8
8
|
applyTaxes?: boolean;
|
|
9
9
|
taxTableId?: string;
|
|
10
|
-
|
|
10
|
+
/** The unique identifier for a specific line item in the cart. */
|
|
11
|
+
internalId?: string;
|
|
11
12
|
}
|
|
12
13
|
export interface AddProductFeeResponse {
|
|
13
14
|
success: boolean;
|
|
@@ -15,7 +16,7 @@ export interface AddProductFeeResponse {
|
|
|
15
16
|
isPercent: boolean;
|
|
16
17
|
label: string;
|
|
17
18
|
applyTaxes: boolean;
|
|
18
|
-
|
|
19
|
+
internalId?: string;
|
|
19
20
|
timestamp: string;
|
|
20
21
|
}
|
|
21
22
|
export type AddProductFee = (params?: AddProductFeeParams) => Promise<AddProductFeeResponse>;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
import { MOCK_CART } from "../../demo/database";
|
|
1
2
|
export const mockAddProductNote = async (params) => {
|
|
2
3
|
console.log("[Mock] addProductNote called", params);
|
|
4
|
+
if (params?.note && params.internalId) {
|
|
5
|
+
const item = MOCK_CART.products.find(p => p.internalId === params.internalId);
|
|
6
|
+
if (item) {
|
|
7
|
+
item.note = params.note;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
else if (params?.note && MOCK_CART.products.length > 0) {
|
|
11
|
+
// Fallback to last added item if no ID provided (common behavior in some POS flows)
|
|
12
|
+
MOCK_CART.products[MOCK_CART.products.length - 1].note = params.note;
|
|
13
|
+
}
|
|
3
14
|
return {
|
|
4
15
|
success: true,
|
|
5
16
|
note: params?.note || "",
|
|
6
|
-
|
|
17
|
+
internalId: params?.internalId,
|
|
7
18
|
timestamp: new Date().toISOString()
|
|
8
19
|
};
|
|
9
20
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export interface AddProductNoteParams {
|
|
2
2
|
note: string;
|
|
3
|
-
/** The
|
|
4
|
-
|
|
3
|
+
/** The unique identifier for a specific line item in the cart. If not provided, it may attempt to modify the active product context. */
|
|
4
|
+
internalId?: string;
|
|
5
5
|
}
|
|
6
6
|
export interface AddProductNoteResponse {
|
|
7
7
|
success: boolean;
|
|
8
8
|
note: string;
|
|
9
|
-
|
|
9
|
+
internalId?: string;
|
|
10
10
|
timestamp: string;
|
|
11
11
|
}
|
|
12
12
|
export type AddProductNote = (params?: AddProductNoteParams) => Promise<AddProductNoteResponse>;
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
import { MOCK_PRODUCTS } from "../../demo/database";
|
|
1
2
|
export const mockAdjustInventory = async (params) => {
|
|
2
3
|
console.log("[Mock] adjustInventory called", params);
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
let newStock = 0;
|
|
5
|
+
if (params && params.productId) {
|
|
6
|
+
const product = MOCK_PRODUCTS.find(p => p._id === params.productId);
|
|
7
|
+
if (product) {
|
|
8
|
+
// Find variant
|
|
9
|
+
const variant = params.variantId
|
|
10
|
+
? product.variants.find(v => v._id === params.variantId)
|
|
11
|
+
: product.variants[0];
|
|
12
|
+
if (variant && variant.inventory && variant.inventory.length > 0) {
|
|
13
|
+
const currentStock = variant.inventory[0].stock || 0;
|
|
14
|
+
const changeAmount = Number(params.amount);
|
|
15
|
+
if (params.stockType === 'add') {
|
|
16
|
+
newStock = currentStock + changeAmount;
|
|
17
|
+
}
|
|
18
|
+
else if (params.stockType === 'subtract') {
|
|
19
|
+
newStock = currentStock - changeAmount;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
newStock = changeAmount;
|
|
23
|
+
}
|
|
24
|
+
// Update mock DB
|
|
25
|
+
variant.inventory[0].stock = newStock;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
11
29
|
return {
|
|
12
30
|
success: true,
|
|
13
31
|
amount: params?.amount || "0",
|
|
@@ -6,6 +6,7 @@ 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
|
+
window.alert(`Demo: Customer Assigned to Cart\nName: ${customer.firstName} ${customer.lastName}`);
|
|
9
10
|
return {
|
|
10
11
|
success: true,
|
|
11
12
|
customer,
|
|
@@ -4,5 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { commandFrameClient } from "../../client";
|
|
6
6
|
export const cashPayment = async (params) => {
|
|
7
|
-
|
|
7
|
+
const finalParams = {
|
|
8
|
+
...params,
|
|
9
|
+
openChangeCalculator: params?.openChangeCalculator ?? true
|
|
10
|
+
};
|
|
11
|
+
return await commandFrameClient.call("cashPayment", finalParams);
|
|
8
12
|
};
|
|
@@ -1,12 +1,44 @@
|
|
|
1
|
-
import { createOrderFromCart } from "../../demo/database";
|
|
1
|
+
import { createOrderFromCart, MOCK_CART } 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
|
|
5
|
+
const openChangeCalculator = params?.openChangeCalculator ?? true;
|
|
6
|
+
let amount = params?.amount || MOCK_CART.total;
|
|
7
|
+
if (openChangeCalculator) {
|
|
8
|
+
try {
|
|
9
|
+
const input = window.prompt(`Total Due: $${MOCK_CART.total.toFixed(2)}\nEnter amount tendered:`, amount.toString());
|
|
10
|
+
if (input === null) {
|
|
11
|
+
// User cancelled
|
|
12
|
+
return {
|
|
13
|
+
success: false,
|
|
14
|
+
amount: 0,
|
|
15
|
+
openChangeCalculator,
|
|
16
|
+
paymentType: "cash",
|
|
17
|
+
order: null,
|
|
18
|
+
timestamp: new Date().toISOString()
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const tendered = parseFloat(input);
|
|
22
|
+
if (!isNaN(tendered)) {
|
|
23
|
+
amount = tendered;
|
|
24
|
+
const change = tendered - MOCK_CART.total;
|
|
25
|
+
if (change >= 0) {
|
|
26
|
+
window.alert(`Change Due: $${change.toFixed(2)}`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
window.alert(`Warning: Tendered amount is less than total. Short by: $${Math.abs(change).toFixed(2)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
console.warn("Could not open prompt/alert (possibly in non-interactive environment)", e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
5
37
|
const order = createOrderFromCart("cash", amount, "cash");
|
|
6
38
|
return {
|
|
7
39
|
success: true,
|
|
8
40
|
amount,
|
|
9
|
-
openChangeCalculator
|
|
41
|
+
openChangeCalculator,
|
|
10
42
|
paymentType: "cash",
|
|
11
43
|
order,
|
|
12
44
|
timestamp: new Date().toISOString()
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { MOCK_PARKED_ORDERS } from "../../demo/database";
|
|
1
2
|
export const mockDeleteParkedOrder = async (params) => {
|
|
2
3
|
console.log("[Mock] deleteParkedOrder called", params);
|
|
4
|
+
if (params?.orderId) {
|
|
5
|
+
const index = MOCK_PARKED_ORDERS.findIndex(o => o._id === params.orderId);
|
|
6
|
+
if (index !== -1) {
|
|
7
|
+
MOCK_PARKED_ORDERS.splice(index, 1);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
return {
|
|
4
11
|
success: true,
|
|
5
12
|
orderId: params?.orderId || "",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const mockInitiateRefund = async (params) => {
|
|
2
2
|
console.log("[Mock] initiateRefund called", params);
|
|
3
|
+
window.alert(`Demo: Initiating Refund for Order: ${params?.orderId || "Current Active Order"}\n(Refund UI would open here)`);
|
|
3
4
|
return {
|
|
4
5
|
success: true,
|
|
5
6
|
orderId: params?.orderId || "mock_order_id",
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { MOCK_ORDERS } from "../../demo/database";
|
|
1
|
+
import { MOCK_PARKED_ORDERS, createOrderFromCart, MOCK_ORDERS } from "../../demo/database";
|
|
2
2
|
export const mockParkOrder = async () => {
|
|
3
3
|
console.log("[Mock] parkOrder called");
|
|
4
|
+
// Create a temporary order to capture cart state
|
|
5
|
+
// We use createOrderFromCart which resets the cart and pushes to MOCK_ORDERS
|
|
6
|
+
const tempOrder = createOrderFromCart("none", 0, "none");
|
|
7
|
+
// Modify to reflect parked status
|
|
8
|
+
tempOrder.status = "parked";
|
|
9
|
+
tempOrder.paymentMethods = []; // clear dummy payment
|
|
10
|
+
// Move from MOCK_ORDERS to MOCK_PARKED_ORDERS
|
|
11
|
+
const foundIndex = MOCK_ORDERS.findIndex(o => o._id === tempOrder._id);
|
|
12
|
+
if (foundIndex !== -1) {
|
|
13
|
+
MOCK_ORDERS.splice(foundIndex, 1);
|
|
14
|
+
}
|
|
15
|
+
MOCK_PARKED_ORDERS.push(tempOrder);
|
|
4
16
|
return {
|
|
5
17
|
success: true,
|
|
6
|
-
order:
|
|
18
|
+
order: tempOrder,
|
|
7
19
|
timestamp: new Date().toISOString()
|
|
8
20
|
};
|
|
9
21
|
};
|
|
@@ -4,5 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { commandFrameClient } from "../../client";
|
|
6
6
|
export const partialPayment = async (params) => {
|
|
7
|
-
|
|
7
|
+
const finalParams = {
|
|
8
|
+
...params,
|
|
9
|
+
openUI: params?.openUI ?? true
|
|
10
|
+
};
|
|
11
|
+
return await commandFrameClient.call("partialPayment", finalParams);
|
|
8
12
|
};
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { MOCK_ORDERS } from "../../demo/database";
|
|
2
2
|
export const mockPartialPayment = async (params) => {
|
|
3
3
|
console.log("[Mock] partialPayment called", params);
|
|
4
|
+
const openUI = params?.openUI ?? true;
|
|
5
|
+
if (openUI) {
|
|
6
|
+
// Simulate UI opening
|
|
7
|
+
window.alert("Demo: Split Payment UI would open here.");
|
|
8
|
+
}
|
|
4
9
|
return {
|
|
5
10
|
success: true,
|
|
6
11
|
amount: params?.amount,
|
|
7
12
|
isPercent: params?.isPercent || false,
|
|
8
|
-
openUI
|
|
9
|
-
order:
|
|
13
|
+
openUI,
|
|
14
|
+
order: openUI ? null : MOCK_ORDERS[0],
|
|
10
15
|
timestamp: new Date().toISOString()
|
|
11
16
|
};
|
|
12
17
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MOCK_CART } from "../../demo/database";
|
|
2
2
|
export const mockRemoveCustomerFromCart = async () => {
|
|
3
3
|
console.log("[Mock] removeCustomerFromCart called");
|
|
4
|
+
// Actually remove the customer from the mock cart
|
|
4
5
|
MOCK_CART.customer = null;
|
|
5
6
|
return {
|
|
6
7
|
success: true,
|