@final-commerce/command-frame 0.2.0-beta.6 → 0.3.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/dist/CommonTypes.d.ts +73 -622
- package/dist/CommonTypes.js +5 -65
- package/dist/actions/add-cart-discount/mock.js +6 -3
- package/dist/actions/add-cart-fee/mock.js +6 -6
- package/dist/actions/add-custom-sale/mock.js +7 -2
- package/dist/actions/add-order-note/mock.js +3 -1
- package/dist/actions/add-product/mock.js +1 -1
- package/dist/actions/add-product-discount/mock.js +5 -5
- package/dist/actions/add-product-fee/mock.js +6 -6
- package/dist/actions/apply-transition/action.d.ts +2 -0
- package/dist/actions/apply-transition/action.js +4 -0
- package/dist/actions/apply-transition/mock.d.ts +6 -0
- package/dist/actions/apply-transition/mock.js +33 -0
- package/dist/actions/apply-transition/types.d.ts +17 -0
- package/dist/actions/cash-payment/mock.js +12 -18
- package/dist/actions/delete-parked-order/mock.js +3 -1
- package/dist/actions/edit-product/mock.js +1 -1
- package/dist/actions/extension-payment/types.d.ts +4 -0
- package/dist/actions/get-context/mock.js +1 -1
- package/dist/actions/get-orders/mock.js +3 -3
- package/dist/actions/get-products/mock.js +9 -4
- package/dist/actions/get-products/types.d.ts +2 -0
- package/dist/actions/get-roles/mock.js +35 -41
- package/dist/actions/get-smart-grid-layout/action.d.ts +2 -0
- package/dist/actions/get-smart-grid-layout/action.js +4 -0
- package/dist/actions/get-smart-grid-layout/mock.d.ts +2 -0
- package/dist/actions/get-smart-grid-layout/mock.js +9 -0
- package/dist/actions/get-smart-grid-layout/types.d.ts +10 -0
- package/dist/actions/get-users/mock.js +16 -25
- package/dist/actions/integration-payment/action.d.ts +5 -0
- package/dist/actions/integration-payment/action.js +7 -0
- package/dist/actions/integration-payment/mock.d.ts +2 -0
- package/dist/actions/integration-payment/mock.js +4 -0
- package/dist/actions/integration-payment/types.d.ts +56 -0
- package/dist/actions/open-extension-overlay/action.d.ts +2 -0
- package/dist/actions/open-extension-overlay/action.js +4 -0
- package/dist/actions/open-extension-overlay/mock.d.ts +2 -0
- package/dist/actions/open-extension-overlay/mock.js +1 -0
- package/dist/actions/open-extension-overlay/types.d.ts +9 -0
- package/dist/actions/park-order/mock.js +4 -1
- package/dist/actions/partial-payment/mock.js +21 -3
- package/dist/actions/redeem-payment/types.d.ts +9 -5
- package/dist/actions/remove-custom-sale/mock.d.ts +2 -0
- package/dist/actions/remove-custom-sale/mock.js +29 -0
- package/dist/actions/remove-customer-from-cart/mock.js +3 -1
- package/dist/actions/remove-order-note/mock.d.ts +2 -0
- package/dist/actions/remove-order-note/mock.js +12 -0
- package/dist/actions/remove-product-discount/mock.d.ts +2 -0
- package/dist/actions/remove-product-discount/mock.js +17 -0
- package/dist/actions/remove-product-fee/mock.d.ts +2 -0
- package/dist/actions/remove-product-fee/mock.js +17 -0
- package/dist/actions/remove-product-from-cart/mock.js +5 -5
- package/dist/actions/resolve-extension-overlay/action.d.ts +2 -0
- package/dist/actions/resolve-extension-overlay/action.js +4 -0
- package/dist/actions/resolve-extension-overlay/mock.d.ts +2 -0
- package/dist/actions/resolve-extension-overlay/mock.js +1 -0
- package/dist/actions/resolve-extension-overlay/types.d.ts +9 -0
- package/dist/actions/resolve-extension-overlay/types.js +1 -0
- package/dist/actions/resume-parked-order/mock.js +5 -2
- package/dist/actions/save-smart-grid-layout/action.d.ts +2 -0
- package/dist/actions/save-smart-grid-layout/action.js +4 -0
- package/dist/actions/save-smart-grid-layout/mock.d.ts +2 -0
- package/dist/actions/save-smart-grid-layout/mock.js +10 -0
- package/dist/actions/save-smart-grid-layout/types.d.ts +10 -0
- package/dist/actions/save-smart-grid-layout/types.js +1 -0
- package/dist/actions/set-active-product-discount/mock.js +1 -1
- package/dist/actions/set-active-product-fee/mock.js +1 -1
- package/dist/actions/tap-to-pay-payment/mock.js +5 -3
- package/dist/actions/terminal-payment/mock.js +4 -5
- package/dist/actions/update-cart-item-quantity/mock.js +9 -9
- package/dist/demo/database.d.ts +33 -22
- package/dist/demo/database.js +191 -21
- package/dist/index.d.ts +116 -115
- package/dist/index.js +15 -13
- package/dist/interceptors/index.d.ts +21 -0
- package/dist/interceptors/index.js +53 -0
- package/dist/interceptors/types.d.ts +26 -0
- package/dist/interceptors/types.js +1 -0
- package/dist/projects/render/mocks.js +19 -15
- package/dist/projects/render/types.d.ts +8 -6
- package/dist/pubsub/topics/products/product-get-active/types.d.ts +6 -2
- package/dist/pubsub/topics/split-payments/index.d.ts +12 -0
- package/dist/pubsub/topics/split-payments/index.js +22 -0
- package/dist/pubsub/topics/split-payments/split-payment-updated/types.d.ts +16 -0
- package/dist/pubsub/topics/split-payments/split-payment-updated/types.js +1 -0
- package/dist/pubsub/topics/split-payments/types.d.ts +10 -0
- package/dist/pubsub/topics/split-payments/types.js +5 -0
- package/dist/pubsub/topics/types.d.ts +2 -0
- package/package.json +17 -14
- package/dist/actions/extension-refund/constants.d.ts +0 -2
- package/dist/actions/extension-refund/constants.js +0 -2
- package/dist/actions/extension-refund/extension-refund-listener.d.ts +0 -11
- package/dist/actions/extension-refund/extension-refund-listener.js +0 -60
- package/dist/actions/extension-refund/types.d.ts +0 -32
- package/dist/actions/extension-refund/types.js +0 -5
- package/dist/actions/set-active-outlet/action.d.ts +0 -2
- package/dist/actions/set-active-outlet/action.js +0 -4
- package/dist/actions/set-active-outlet/mock.d.ts +0 -2
- package/dist/actions/set-active-outlet/mock.js +0 -16
- package/dist/actions/set-active-outlet/types.d.ts +0 -10
- package/dist/actions/set-active-session/action.d.ts +0 -2
- package/dist/actions/set-active-session/action.js +0 -4
- package/dist/actions/set-active-session/mock.d.ts +0 -2
- package/dist/actions/set-active-session/mock.js +0 -15
- package/dist/actions/set-active-session/types.d.ts +0 -10
- package/dist/actions/set-active-station/action.d.ts +0 -2
- package/dist/actions/set-active-station/action.js +0 -4
- package/dist/actions/set-active-station/mock.d.ts +0 -2
- package/dist/actions/set-active-station/mock.js +0 -16
- package/dist/actions/set-active-station/types.d.ts +0 -10
- package/dist/actions/trigger-webhook/action.d.ts +0 -6
- package/dist/actions/trigger-webhook/action.js +0 -8
- package/dist/actions/trigger-webhook/mock.d.ts +0 -2
- package/dist/actions/trigger-webhook/mock.js +0 -8
- package/dist/actions/trigger-webhook/types.d.ts +0 -21
- package/dist/actions/trigger-webhook/types.js +0 -2
- package/dist/actions/trigger-zapier-webhook/action.d.ts +0 -6
- package/dist/actions/trigger-zapier-webhook/action.js +0 -8
- package/dist/actions/trigger-zapier-webhook/mock.d.ts +0 -2
- package/dist/actions/trigger-zapier-webhook/mock.js +0 -8
- package/dist/actions/trigger-zapier-webhook/types.d.ts +0 -9
- /package/dist/actions/{set-active-outlet → apply-transition}/types.js +0 -0
- /package/dist/actions/{set-active-session → get-smart-grid-layout}/types.js +0 -0
- /package/dist/actions/{set-active-station → integration-payment}/types.js +0 -0
- /package/dist/actions/{trigger-zapier-webhook → open-extension-overlay}/types.js +0 -0
|
@@ -5,7 +5,6 @@ export const mockGetUsers = async (params) => {
|
|
|
5
5
|
users: [
|
|
6
6
|
{
|
|
7
7
|
id: "691df9c2047bfc55994d703f",
|
|
8
|
-
_id: "691df9c2047bfc55994d703f",
|
|
9
8
|
firstName: "Sarah",
|
|
10
9
|
lastName: "Mitchell",
|
|
11
10
|
email: "sarah.mitchell@company.com",
|
|
@@ -13,25 +12,22 @@ export const mockGetUsers = async (params) => {
|
|
|
13
12
|
type: CFUserTypes.ORG_OWNER,
|
|
14
13
|
role: {
|
|
15
14
|
id: "691df9c6c478bada1fb23d0b",
|
|
16
|
-
_id: "691df9c6c478bada1fb23d0b",
|
|
17
15
|
name: "Owner",
|
|
18
|
-
companyId: "691df9c4c478bada1fb23bff",
|
|
19
16
|
permissions: [
|
|
20
|
-
{ category: "hub_access",
|
|
21
|
-
{ category: "hub_access",
|
|
22
|
-
{ category: "hub_access",
|
|
23
|
-
{ category: "hub_access",
|
|
24
|
-
{ category: "hub_access",
|
|
25
|
-
{ category: "hub_access",
|
|
26
|
-
{ category: "station_access",
|
|
27
|
-
{ category: "station_access",
|
|
17
|
+
{ category: "hub_access", label: "general", name: "general", value: true },
|
|
18
|
+
{ category: "hub_access", label: "products", name: "products", value: true },
|
|
19
|
+
{ category: "hub_access", label: "reports", name: "reports", value: true },
|
|
20
|
+
{ category: "hub_access", label: "users", name: "users", value: true },
|
|
21
|
+
{ category: "hub_access", label: "builder", name: "builder", value: true },
|
|
22
|
+
{ category: "hub_access", label: "billing", name: "billing", value: true },
|
|
23
|
+
{ category: "station_access", label: "give_discounts", name: "give_discounts", value: true },
|
|
24
|
+
{ category: "station_access", label: "issue_refunds", name: "issue_refunds", value: true },
|
|
28
25
|
]
|
|
29
26
|
},
|
|
30
27
|
outlets: []
|
|
31
28
|
},
|
|
32
29
|
{
|
|
33
30
|
id: "692a1b3c4d5e6f7890abcde1",
|
|
34
|
-
_id: "692a1b3c4d5e6f7890abcde1",
|
|
35
31
|
firstName: "James",
|
|
36
32
|
lastName: "Rodriguez",
|
|
37
33
|
email: "james.rodriguez@company.com",
|
|
@@ -39,22 +35,19 @@ export const mockGetUsers = async (params) => {
|
|
|
39
35
|
type: CFUserTypes.ADMIN,
|
|
40
36
|
role: {
|
|
41
37
|
id: "691df9c6c478bada1fb23d0c",
|
|
42
|
-
_id: "691df9c6c478bada1fb23d0c",
|
|
43
38
|
name: "admin",
|
|
44
|
-
companyId: "691df9c4c478bada1fb23bff",
|
|
45
39
|
permissions: [
|
|
46
|
-
{ category: "hub_access",
|
|
47
|
-
{ category: "hub_access",
|
|
48
|
-
{ category: "hub_access",
|
|
49
|
-
{ category: "hub_access",
|
|
50
|
-
{ category: "station_access",
|
|
40
|
+
{ category: "hub_access", label: "general", name: "general", value: true },
|
|
41
|
+
{ category: "hub_access", label: "products", name: "products", value: true },
|
|
42
|
+
{ category: "hub_access", label: "reports", name: "reports", value: true },
|
|
43
|
+
{ category: "hub_access", label: "users", name: "users", value: true },
|
|
44
|
+
{ category: "station_access", label: "give_discounts", name: "give_discounts", value: true },
|
|
51
45
|
]
|
|
52
46
|
},
|
|
53
47
|
outlets: ["outlet-main", "outlet-downtown"]
|
|
54
48
|
},
|
|
55
49
|
{
|
|
56
50
|
id: "692a1b3c4d5e6f7890abcde2",
|
|
57
|
-
_id: "692a1b3c4d5e6f7890abcde2",
|
|
58
51
|
firstName: "Lisa",
|
|
59
52
|
lastName: "Chen",
|
|
60
53
|
email: "lisa.chen@company.com",
|
|
@@ -62,13 +55,11 @@ export const mockGetUsers = async (params) => {
|
|
|
62
55
|
type: CFUserTypes.CASHIER,
|
|
63
56
|
role: {
|
|
64
57
|
id: "691df9c6c478bada1fb23d0d",
|
|
65
|
-
_id: "691df9c6c478bada1fb23d0d",
|
|
66
58
|
name: "cashier",
|
|
67
|
-
companyId: "691df9c4c478bada1fb23bff",
|
|
68
59
|
permissions: [
|
|
69
|
-
{ category: "station_access",
|
|
70
|
-
{ category: "station_access",
|
|
71
|
-
{ category: "station_access",
|
|
60
|
+
{ category: "station_access", label: "give_discounts", name: "give_discounts", value: false },
|
|
61
|
+
{ category: "station_access", label: "issue_refunds", name: "issue_refunds", value: false },
|
|
62
|
+
{ category: "station_access", label: "session_reports", name: "session_reports", value: true },
|
|
72
63
|
]
|
|
73
64
|
},
|
|
74
65
|
outlets: ["outlet-main"]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration payment — thin wrapper over {@link extensionPayment} with `paymentType: "integration"`.
|
|
3
|
+
*/
|
|
4
|
+
import { extensionPayment } from "../extension-payment/action";
|
|
5
|
+
export const integrationPayment = async (params) => {
|
|
6
|
+
return extensionPayment({ ...params, paymentType: "integration" });
|
|
7
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ExtensionPaymentResponse } from "../extension-payment/types";
|
|
2
|
+
/**
|
|
3
|
+
* Card display fields for an integration payment.
|
|
4
|
+
*
|
|
5
|
+
* Render JSON-serializes this object onto the order's `paymentMethod.emv` field;
|
|
6
|
+
* the transactions list, split-payment refund modal, and receipt mapper parse it
|
|
7
|
+
* back. Field names are translated to the platform's canonical EMV keys ("Brand",
|
|
8
|
+
* "Cardholder Name", "Card Number", etc.) on the host before serialization — your
|
|
9
|
+
* extension passes camelCase, the order's persisted shape is unchanged from the
|
|
10
|
+
* native card flow.
|
|
11
|
+
*
|
|
12
|
+
* All fields are optional; the more you supply, the richer the receipt and the
|
|
13
|
+
* transactions row will be. At minimum, supplying `brand` and `cardNumberLast4`
|
|
14
|
+
* produces the typical "Visa **** **** **** 4242" row.
|
|
15
|
+
*/
|
|
16
|
+
export interface IntegrationEmvData {
|
|
17
|
+
/** Card brand, e.g. "Visa", "MasterCard". → "Brand" */
|
|
18
|
+
brand?: string;
|
|
19
|
+
/** Cardholder name as printed on the card. → "Cardholder Name" */
|
|
20
|
+
cardholderName?: string;
|
|
21
|
+
/** Issuing country (ISO 3166-1 alpha-2), e.g. "US". → "Country" */
|
|
22
|
+
country?: string;
|
|
23
|
+
/** Display expiry, e.g. "12/26". → "Expiry date" */
|
|
24
|
+
expiryDate?: string;
|
|
25
|
+
/** Issuer / bank name. → "Issuer" */
|
|
26
|
+
issuer?: string;
|
|
27
|
+
/** Last 4 digits of the card. Render masks to "**** **** **** XXXX" before display. → "Card Number" */
|
|
28
|
+
cardNumberLast4?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Integration payment (e.g. Stripe-like) — always uses paymentType `"integration"` on the wire.
|
|
32
|
+
* The extension processes the payment with its own provider, then reports the result here so
|
|
33
|
+
* Render can record the transaction + order.
|
|
34
|
+
*
|
|
35
|
+
* Required fields (compile-time enforced by TS, runtime-enforced by the host handler):
|
|
36
|
+
* - `amount` — minor units of the captured amount
|
|
37
|
+
* - `emvData` — typed card display fields; the host maps + JSON-serializes to `paymentMethod.emv`
|
|
38
|
+
* (same persisted shape as the native card flow). Required: if the integration
|
|
39
|
+
* doesn't produce card data, use redeemPayment instead.
|
|
40
|
+
*/
|
|
41
|
+
export interface IntegrationPaymentParams {
|
|
42
|
+
amount: number;
|
|
43
|
+
emvData: IntegrationEmvData;
|
|
44
|
+
/** Human-readable label (e.g. "Visa ****4242"); shown in the transaction list. */
|
|
45
|
+
label?: string;
|
|
46
|
+
/** Identifier of the extension making the call; audit/debug link. */
|
|
47
|
+
extensionId?: string;
|
|
48
|
+
/** Label/name of the integration (e.g. "Stripe", "AMP"). Stored on the order's paymentMethod.processor. */
|
|
49
|
+
processor?: string;
|
|
50
|
+
referenceId?: string;
|
|
51
|
+
metadata?: Record<string, unknown>;
|
|
52
|
+
/** Provider fee in minor units — stored on paymentMethod.processorFee. */
|
|
53
|
+
processorFee?: number;
|
|
54
|
+
}
|
|
55
|
+
export type IntegrationPaymentResponse = ExtensionPaymentResponse;
|
|
56
|
+
export type IntegrationPayment = (params: IntegrationPaymentParams) => Promise<IntegrationPaymentResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const mockOpenExtensionOverlay = async (_params) => true;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InterceptorPoint, InterceptorReturn } from "../../interceptors/types";
|
|
2
|
+
export interface OpenExtensionOverlayParams {
|
|
3
|
+
point: InterceptorPoint;
|
|
4
|
+
payload?: any;
|
|
5
|
+
/** Owning extension id. Injected by the host for interceptor-originated calls; optional for direct calls. */
|
|
6
|
+
extensionId?: string;
|
|
7
|
+
}
|
|
8
|
+
export type OpenExtensionOverlayResponse = InterceptorReturn;
|
|
9
|
+
export type OpenExtensionOverlay = (params: OpenExtensionOverlayParams) => Promise<OpenExtensionOverlayResponse>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MOCK_PARKED_ORDERS, createOrderFromCart, MOCK_ORDERS } from "../../demo/database";
|
|
1
|
+
import { MOCK_PARKED_ORDERS, createOrderFromCart, MOCK_ORDERS, mockPublishEvent } from "../../demo/database";
|
|
2
2
|
export const mockParkOrder = async () => {
|
|
3
3
|
console.log("[Mock] parkOrder called");
|
|
4
4
|
// Create a temporary order to capture cart state
|
|
@@ -13,6 +13,9 @@ export const mockParkOrder = async () => {
|
|
|
13
13
|
MOCK_ORDERS.splice(foundIndex, 1);
|
|
14
14
|
}
|
|
15
15
|
MOCK_PARKED_ORDERS.push(tempOrder);
|
|
16
|
+
// Refresh order lists so the new parked order appears (createOrderFromCart
|
|
17
|
+
// already published the cart-created event that clears the cart).
|
|
18
|
+
mockPublishEvent("orders", "order-parked", { order: tempOrder });
|
|
16
19
|
return {
|
|
17
20
|
success: true,
|
|
18
21
|
order: tempOrder,
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from "../../demo/database";
|
|
2
2
|
export const mockPartialPayment = async (params) => {
|
|
3
3
|
console.log("[Mock] partialPayment called", params);
|
|
4
4
|
const openUI = params?.openUI ?? true;
|
|
5
5
|
if (openUI) {
|
|
6
|
-
//
|
|
6
|
+
// Split-payment UI is host-owned; nothing to simulate here.
|
|
7
7
|
window.alert("Demo: Split Payment UI would open here.");
|
|
8
|
+
return {
|
|
9
|
+
success: true,
|
|
10
|
+
amount: params?.amount,
|
|
11
|
+
isPercent: params?.isPercent || false,
|
|
12
|
+
openUI,
|
|
13
|
+
order: null,
|
|
14
|
+
timestamp: new Date().toISOString()
|
|
15
|
+
};
|
|
8
16
|
}
|
|
17
|
+
// Queue a partial amount as the next tender. The remaining balance is left
|
|
18
|
+
// untouched until the payment is actually taken (see applyMockPayment).
|
|
19
|
+
const remaining = MOCK_CART.remainingBalance ?? MOCK_CART.total;
|
|
20
|
+
const raw = params?.amount ?? 0;
|
|
21
|
+
// Mirror render: fixed amount is raw dollars (render does toMinorUnits), so
|
|
22
|
+
// convert to minor units here; percent is a percentage of the remaining total.
|
|
23
|
+
const minorFactor = 10 ** (MOCK_CART.minorUnits ?? 2);
|
|
24
|
+
const charge = params?.isPercent ? Math.round((remaining * raw) / 100) : Math.round(raw * minorFactor);
|
|
25
|
+
MOCK_CART.amountToBeCharged = Math.min(Math.max(0, charge), remaining);
|
|
26
|
+
mockPublishEvent("cart", "partial-payment-set", { amountToBeCharged: MOCK_CART.amountToBeCharged });
|
|
9
27
|
return {
|
|
10
28
|
success: true,
|
|
11
29
|
amount: params?.amount,
|
|
12
30
|
isPercent: params?.isPercent || false,
|
|
13
31
|
openUI,
|
|
14
|
-
order:
|
|
32
|
+
order: null,
|
|
15
33
|
timestamp: new Date().toISOString()
|
|
16
34
|
};
|
|
17
35
|
};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { ExtensionPaymentResponse } from "../extension-payment/types";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Redeem (e.g. gift card) — always uses paymentType `"redeem"` on the wire.
|
|
4
|
+
* `amount` is required so the persisted payment never silently falls back to the cart
|
|
5
|
+
* total. The host handler also re-validates this at runtime to catch raw-postMessage callers.
|
|
6
|
+
*/
|
|
3
7
|
export interface RedeemPaymentParams {
|
|
4
|
-
amount
|
|
5
|
-
processor?: string;
|
|
8
|
+
amount: number;
|
|
6
9
|
label?: string;
|
|
7
|
-
referenceId?: string;
|
|
8
10
|
extensionId?: string;
|
|
11
|
+
processor?: string;
|
|
12
|
+
referenceId?: string;
|
|
9
13
|
metadata?: Record<string, unknown>;
|
|
10
14
|
}
|
|
11
15
|
export type RedeemPaymentResponse = ExtensionPaymentResponse;
|
|
12
|
-
export type RedeemPayment = (params
|
|
16
|
+
export type RedeemPayment = (params: RedeemPaymentParams) => Promise<RedeemPaymentResponse>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from "../../demo/database";
|
|
2
|
+
export const mockRemoveCustomSale = (params) => {
|
|
3
|
+
console.log("[Mock] removeCustomSale called", params);
|
|
4
|
+
if (!params?.id) {
|
|
5
|
+
throw new Error("id is required");
|
|
6
|
+
}
|
|
7
|
+
const { id } = params;
|
|
8
|
+
const sales = MOCK_CART.customSales ?? [];
|
|
9
|
+
const index = sales.findIndex(s => s.id === id);
|
|
10
|
+
if (index === -1) {
|
|
11
|
+
throw new Error(`Custom sale with id ${id} not found`);
|
|
12
|
+
}
|
|
13
|
+
const sale = sales[index];
|
|
14
|
+
// Remove from cart
|
|
15
|
+
sales.splice(index, 1);
|
|
16
|
+
// Recalculate totals
|
|
17
|
+
const lineTotal = sale.price * sale.quantity;
|
|
18
|
+
MOCK_CART.subtotal -= lineTotal;
|
|
19
|
+
MOCK_CART.total -= lineTotal;
|
|
20
|
+
MOCK_CART.amountToBeCharged = MOCK_CART.total;
|
|
21
|
+
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
22
|
+
// Publish custom-sale-removed event so cart subscribers refresh
|
|
23
|
+
mockPublishEvent("cart", "custom-sale-removed", { customSale: sale, id });
|
|
24
|
+
return Promise.resolve({
|
|
25
|
+
success: true,
|
|
26
|
+
id,
|
|
27
|
+
timestamp: new Date().toISOString()
|
|
28
|
+
});
|
|
29
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { MOCK_CART } from "../../demo/database";
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from "../../demo/database";
|
|
2
2
|
export const mockRemoveCustomerFromCart = async () => {
|
|
3
3
|
console.log("[Mock] removeCustomerFromCart called");
|
|
4
4
|
// Actually remove the customer from the mock cart
|
|
5
5
|
MOCK_CART.customer = null;
|
|
6
|
+
// Publish customer-removed event so cart subscribers refresh
|
|
7
|
+
mockPublishEvent('cart', 'customer-removed', {});
|
|
6
8
|
return {
|
|
7
9
|
success: true,
|
|
8
10
|
timestamp: new Date().toISOString()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from "../../demo/database";
|
|
2
|
+
export const mockRemoveOrderNote = () => {
|
|
3
|
+
console.log("[Mock] removeOrderNote called");
|
|
4
|
+
// Clear the active cart's note.
|
|
5
|
+
MOCK_CART.orderNotes = undefined;
|
|
6
|
+
// Publish order-note-removed event so cart subscribers refresh.
|
|
7
|
+
mockPublishEvent("cart", "order-note-removed", {});
|
|
8
|
+
return Promise.resolve({
|
|
9
|
+
success: true,
|
|
10
|
+
timestamp: new Date().toISOString()
|
|
11
|
+
});
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from "../../demo/database";
|
|
2
|
+
export const mockRemoveProductDiscount = (params) => {
|
|
3
|
+
console.log("[Mock] removeProductDiscount called", params);
|
|
4
|
+
const item = params?.internalId
|
|
5
|
+
? MOCK_CART.products.find(p => p.internalId === params.internalId)
|
|
6
|
+
: MOCK_CART.products[MOCK_CART.products.length - 1];
|
|
7
|
+
if (item) {
|
|
8
|
+
item.discounts = [];
|
|
9
|
+
// Publish so cart subscribers refresh.
|
|
10
|
+
mockPublishEvent("cart", "product-discount-removed", { internalId: params?.internalId });
|
|
11
|
+
}
|
|
12
|
+
return Promise.resolve({
|
|
13
|
+
success: true,
|
|
14
|
+
internalId: params?.internalId,
|
|
15
|
+
timestamp: new Date().toISOString()
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from "../../demo/database";
|
|
2
|
+
export const mockRemoveProductFee = (params) => {
|
|
3
|
+
console.log("[Mock] removeProductFee called", params);
|
|
4
|
+
const item = params?.internalId
|
|
5
|
+
? MOCK_CART.products.find(p => p.internalId === params.internalId)
|
|
6
|
+
: MOCK_CART.products[MOCK_CART.products.length - 1];
|
|
7
|
+
if (item) {
|
|
8
|
+
item.fees = [];
|
|
9
|
+
// Publish so cart subscribers refresh.
|
|
10
|
+
mockPublishEvent("cart", "product-fee-removed", { internalId: params?.internalId });
|
|
11
|
+
}
|
|
12
|
+
return Promise.resolve({
|
|
13
|
+
success: true,
|
|
14
|
+
internalId: params?.internalId,
|
|
15
|
+
timestamp: new Date().toISOString()
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MOCK_CART, mockPublishEvent } from "../../demo/database";
|
|
2
|
-
export const mockRemoveProductFromCart =
|
|
2
|
+
export const mockRemoveProductFromCart = (params) => {
|
|
3
3
|
console.log("[Mock] removeProductFromCart called", params);
|
|
4
4
|
if (!params?.internalId) {
|
|
5
|
-
throw new Error(
|
|
5
|
+
throw new Error("internalId is required");
|
|
6
6
|
}
|
|
7
7
|
const { internalId } = params;
|
|
8
8
|
// Find the product in the cart
|
|
@@ -20,13 +20,13 @@ export const mockRemoveProductFromCart = async (params) => {
|
|
|
20
20
|
MOCK_CART.amountToBeCharged = MOCK_CART.total;
|
|
21
21
|
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
22
22
|
// Publish product-deleted event
|
|
23
|
-
mockPublishEvent(
|
|
23
|
+
mockPublishEvent("cart", "product-deleted", {
|
|
24
24
|
product: product,
|
|
25
25
|
internalId: internalId
|
|
26
26
|
});
|
|
27
|
-
return {
|
|
27
|
+
return Promise.resolve({
|
|
28
28
|
success: true,
|
|
29
29
|
internalId: internalId,
|
|
30
30
|
timestamp: new Date().toISOString()
|
|
31
|
-
};
|
|
31
|
+
});
|
|
32
32
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const mockResolveExtensionOverlay = async (_params) => ({ success: true });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InterceptorReturn } from "../../interceptors/types";
|
|
2
|
+
export interface ResolveExtensionOverlayParams {
|
|
3
|
+
overlayId: string;
|
|
4
|
+
result: InterceptorReturn;
|
|
5
|
+
}
|
|
6
|
+
export interface ResolveExtensionOverlayResponse {
|
|
7
|
+
success: boolean;
|
|
8
|
+
}
|
|
9
|
+
export type ResolveExtensionOverlay = (params: ResolveExtensionOverlayParams) => Promise<ResolveExtensionOverlayResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MOCK_PARKED_ORDERS, MOCK_CART, resetMockCart } from "../../demo/database";
|
|
1
|
+
import { MOCK_PARKED_ORDERS, MOCK_CART, resetMockCart, mockPublishEvent } from "../../demo/database";
|
|
2
2
|
export const mockResumeParkedOrder = async (params) => {
|
|
3
3
|
console.log("[Mock] resumeParkedOrder called", params);
|
|
4
4
|
const orderId = params?.orderId;
|
|
@@ -39,12 +39,15 @@ export const mockResumeParkedOrder = async (params) => {
|
|
|
39
39
|
taxTableId: "",
|
|
40
40
|
attributes: li.attributes
|
|
41
41
|
}));
|
|
42
|
-
MOCK_CART.subtotal = orderToResume.summary.
|
|
42
|
+
MOCK_CART.subtotal = orderToResume.summary.subtotalAfterFees;
|
|
43
43
|
MOCK_CART.total = orderToResume.summary.total;
|
|
44
44
|
MOCK_CART.amountToBeCharged = MOCK_CART.total;
|
|
45
45
|
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
46
46
|
// Remove from parked
|
|
47
47
|
MOCK_PARKED_ORDERS.splice(index, 1);
|
|
48
|
+
// Refresh the restored cart and the order lists.
|
|
49
|
+
mockPublishEvent("cart", "parked-order-resumed", { orderId });
|
|
50
|
+
mockPublishEvent("orders", "parked-order-resumed", { orderId });
|
|
48
51
|
return {
|
|
49
52
|
success: true,
|
|
50
53
|
order: orderToResume,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MOCK_SMART_GRID_LAYOUTS } from "../../demo/database";
|
|
2
|
+
export const mockSaveSmartGridLayout = (params) => {
|
|
3
|
+
console.log("[Mock] saveSmartGridLayout called", params);
|
|
4
|
+
MOCK_SMART_GRID_LAYOUTS[params.layout.gridId] = params.layout;
|
|
5
|
+
return Promise.resolve({
|
|
6
|
+
success: true,
|
|
7
|
+
gridId: params.layout.gridId,
|
|
8
|
+
timestamp: new Date().toISOString()
|
|
9
|
+
});
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CFSmartGridLayout } from "../../CommonTypes";
|
|
2
|
+
export interface SaveSmartGridLayoutParams {
|
|
3
|
+
layout: CFSmartGridLayout;
|
|
4
|
+
}
|
|
5
|
+
export interface SaveSmartGridLayoutResponse {
|
|
6
|
+
success: boolean;
|
|
7
|
+
gridId: string;
|
|
8
|
+
timestamp: string;
|
|
9
|
+
}
|
|
10
|
+
export type SaveSmartGridLayout = (params: SaveSmartGridLayoutParams) => Promise<SaveSmartGridLayoutResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,7 +9,7 @@ export const mockSetActiveProductDiscount = async (params) => {
|
|
|
9
9
|
isPercent: params.isPercent || false,
|
|
10
10
|
label: params.label || "Discount"
|
|
11
11
|
};
|
|
12
|
-
setMockActiveProduct({ ...MOCK_ACTIVE_PRODUCT, discount });
|
|
12
|
+
setMockActiveProduct({ ...MOCK_ACTIVE_PRODUCT, discounts: [discount] });
|
|
13
13
|
return {
|
|
14
14
|
success: true,
|
|
15
15
|
amount: params.amount,
|
|
@@ -10,7 +10,7 @@ export const mockSetActiveProductFee = async (params) => {
|
|
|
10
10
|
isPercent: params.isPercent || false,
|
|
11
11
|
applyTaxes: params.applyTaxes || false
|
|
12
12
|
};
|
|
13
|
-
setMockActiveProduct({ ...MOCK_ACTIVE_PRODUCT, fee });
|
|
13
|
+
setMockActiveProduct({ ...MOCK_ACTIVE_PRODUCT, fees: [fee] });
|
|
14
14
|
return {
|
|
15
15
|
success: true,
|
|
16
16
|
amount: params.amount,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { applyMockPayment, MOCK_CART } from "../../demo/database";
|
|
2
2
|
export const mockTapToPayPayment = async (params) => {
|
|
3
3
|
console.log("[Mock] tapToPayPayment called", params);
|
|
4
4
|
// Simulate Tap to Pay interaction
|
|
5
5
|
window.alert("Demo: Processing Tap to Pay...\n(Please tap card or device on screen)");
|
|
6
|
+
const due = params?.amount ?? MOCK_CART.amountToBeCharged ?? MOCK_CART.total;
|
|
7
|
+
const order = applyMockPayment(due, "card", "tapToPay");
|
|
6
8
|
return {
|
|
7
9
|
success: true,
|
|
8
|
-
amount:
|
|
10
|
+
amount: due,
|
|
9
11
|
paymentType: "tapToPay",
|
|
10
|
-
order
|
|
12
|
+
order,
|
|
11
13
|
timestamp: new Date().toISOString()
|
|
12
14
|
};
|
|
13
15
|
};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { applyMockPayment, MOCK_CART } from "../../demo/database";
|
|
2
2
|
export const mockTerminalPayment = async (params) => {
|
|
3
3
|
console.log("[Mock] terminalPayment called", params);
|
|
4
4
|
const connectionType = params?.paymentType || "Cloud";
|
|
5
5
|
// Simulate terminal interaction
|
|
6
6
|
window.alert(`Demo: Processing ${connectionType} Terminal Payment...\n(Please tap, insert, or swipe card on terminal)`);
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const order = createOrderFromCart("card", amount, "stripe_terminal");
|
|
7
|
+
const due = params?.amount ?? MOCK_CART.amountToBeCharged ?? MOCK_CART.total;
|
|
8
|
+
const order = applyMockPayment(due, "card", "stripe_terminal");
|
|
10
9
|
return {
|
|
11
10
|
success: true,
|
|
12
|
-
amount:
|
|
11
|
+
amount: due,
|
|
13
12
|
paymentType: "terminal",
|
|
14
13
|
order,
|
|
15
14
|
timestamp: new Date().toISOString()
|