@final-commerce/command-frame 0.3.1-beta.1 → 0.3.1
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 +1 -1
- package/dist/actions/add-custom-sale/mock.d.ts +1 -1
- package/dist/actions/add-custom-sale/mock.js +7 -6
- package/dist/actions/add-custom-sale/types.d.ts +3 -0
- package/dist/actions/edit-custom-sale/action.d.ts +6 -0
- package/dist/actions/edit-custom-sale/action.js +8 -0
- package/dist/actions/edit-custom-sale/mock.d.ts +2 -0
- package/dist/actions/edit-custom-sale/mock.js +43 -0
- package/dist/actions/edit-custom-sale/types.d.ts +21 -0
- package/dist/actions/edit-custom-sale/types.js +1 -0
- package/dist/actions/print/types.d.ts +0 -9
- package/dist/index.d.ts +168 -166
- package/dist/index.js +140 -138
- package/dist/projects/render/mocks.d.ts +1 -1
- package/dist/projects/render/mocks.js +100 -98
- package/dist/projects/render/types.d.ts +4 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AddCustomSale } from
|
|
1
|
+
import { AddCustomSale } from './types';
|
|
2
2
|
export declare const mockAddCustomSale: AddCustomSale;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { MOCK_CART, mockPublishEvent } from
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from '../../demo/database';
|
|
2
2
|
export const mockAddCustomSale = async (params) => {
|
|
3
|
-
console.log(
|
|
3
|
+
console.log('[Mock] addCustomSale called', params);
|
|
4
4
|
if (!params)
|
|
5
|
-
throw new Error(
|
|
5
|
+
throw new Error('Params required');
|
|
6
6
|
// Simple mock ID generation
|
|
7
7
|
const mockId = 'sale_' + Math.random().toString(36).substr(2, 9);
|
|
8
8
|
// Mirror render: the flow sends raw dollars ($4); render does toMinorUnits.
|
|
9
9
|
// MOCK_CART tracks minor units, so convert here too.
|
|
10
10
|
const minorFactor = 10 ** (MOCK_CART.minorUnits ?? 2);
|
|
11
11
|
const price = Math.round(Number(params.price) * minorFactor);
|
|
12
|
-
const quantity =
|
|
12
|
+
const quantity = params.quantity ?? 1;
|
|
13
13
|
const customSale = {
|
|
14
14
|
id: mockId,
|
|
15
15
|
name: params.label,
|
|
16
16
|
price: price,
|
|
17
17
|
quantity: quantity,
|
|
18
18
|
applyTaxes: params.applyTaxes ?? false,
|
|
19
|
-
taxTableId: params.taxTableId
|
|
19
|
+
taxTableId: params.taxTableId,
|
|
20
20
|
};
|
|
21
21
|
if (!MOCK_CART.customSales) {
|
|
22
22
|
MOCK_CART.customSales = [];
|
|
@@ -34,7 +34,8 @@ export const mockAddCustomSale = async (params) => {
|
|
|
34
34
|
customSaleId: mockId,
|
|
35
35
|
label: params.label,
|
|
36
36
|
price: price,
|
|
37
|
+
quantity: quantity,
|
|
37
38
|
applyTaxes: params.applyTaxes ?? false,
|
|
38
|
-
timestamp: new Date().toISOString()
|
|
39
|
+
timestamp: new Date().toISOString(),
|
|
39
40
|
};
|
|
40
41
|
};
|
|
@@ -2,6 +2,8 @@ export interface AddCustomSaleParams {
|
|
|
2
2
|
label: string;
|
|
3
3
|
/** Price in integer MINOR currency units (e.g. 1575 = $15.75). */
|
|
4
4
|
price: number | string;
|
|
5
|
+
/** Defaults to 1. Must be a positive integer. */
|
|
6
|
+
quantity?: number;
|
|
5
7
|
applyTaxes?: boolean;
|
|
6
8
|
taxTableId?: string;
|
|
7
9
|
}
|
|
@@ -10,6 +12,7 @@ export interface AddCustomSaleResponse {
|
|
|
10
12
|
customSaleId: string;
|
|
11
13
|
label: string;
|
|
12
14
|
price: number;
|
|
15
|
+
quantity: number;
|
|
13
16
|
applyTaxes: boolean;
|
|
14
17
|
timestamp: string;
|
|
15
18
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Edit custom sale action
|
|
3
|
+
* Calls the editCustomSale action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from '../../client';
|
|
6
|
+
export const editCustomSale = async (params) => {
|
|
7
|
+
return await commandFrameClient.call('editCustomSale', params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MOCK_CART, mockPublishEvent } from '../../demo/database';
|
|
2
|
+
export const mockEditCustomSale = async (params) => {
|
|
3
|
+
console.log('[Mock] editCustomSale called', params);
|
|
4
|
+
if (!params)
|
|
5
|
+
throw new Error('Params required');
|
|
6
|
+
if (!params.customSaleId)
|
|
7
|
+
throw new Error('customSaleId is required');
|
|
8
|
+
const sale = (MOCK_CART.customSales ?? []).find((s) => s.id === params.customSaleId);
|
|
9
|
+
if (!sale)
|
|
10
|
+
throw new Error(`Custom sale '${params.customSaleId}' not found in cart`);
|
|
11
|
+
// Remove the old line's contribution before applying the edit.
|
|
12
|
+
const oldLineTotal = sale.price * sale.quantity;
|
|
13
|
+
if (params.label !== undefined)
|
|
14
|
+
sale.name = params.label;
|
|
15
|
+
if (params.price !== undefined) {
|
|
16
|
+
// Mirror render: the flow sends raw dollars ($4); render does toMinorUnits.
|
|
17
|
+
// MOCK_CART tracks minor units, so convert here too.
|
|
18
|
+
const minorFactor = 10 ** (MOCK_CART.minorUnits ?? 2);
|
|
19
|
+
sale.price = Math.round(Number(params.price) * minorFactor);
|
|
20
|
+
}
|
|
21
|
+
if (params.quantity !== undefined)
|
|
22
|
+
sale.quantity = params.quantity;
|
|
23
|
+
if (params.applyTaxes !== undefined)
|
|
24
|
+
sale.applyTaxes = params.applyTaxes;
|
|
25
|
+
if (params.taxTableId !== undefined)
|
|
26
|
+
sale.taxTableId = params.taxTableId;
|
|
27
|
+
const newLineTotal = sale.price * sale.quantity;
|
|
28
|
+
MOCK_CART.subtotal += newLineTotal - oldLineTotal;
|
|
29
|
+
MOCK_CART.total += newLineTotal - oldLineTotal;
|
|
30
|
+
MOCK_CART.amountToBeCharged = MOCK_CART.total;
|
|
31
|
+
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
32
|
+
// Publish custom-sale-updated event so cart subscribers refresh
|
|
33
|
+
mockPublishEvent('cart', 'custom-sale-updated', { customSale: sale });
|
|
34
|
+
return {
|
|
35
|
+
success: true,
|
|
36
|
+
customSaleId: sale.id,
|
|
37
|
+
label: sale.name,
|
|
38
|
+
price: sale.price,
|
|
39
|
+
quantity: sale.quantity,
|
|
40
|
+
applyTaxes: sale.applyTaxes ?? false,
|
|
41
|
+
timestamp: new Date().toISOString(),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface EditCustomSaleParams {
|
|
2
|
+
/** The id returned by addCustomSale (`customSaleId`). */
|
|
3
|
+
customSaleId: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
/** Price in integer MINOR currency units (e.g. 1575 = $15.75). */
|
|
6
|
+
price?: number | string;
|
|
7
|
+
/** Must be a positive integer. */
|
|
8
|
+
quantity?: number;
|
|
9
|
+
applyTaxes?: boolean;
|
|
10
|
+
taxTableId?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface EditCustomSaleResponse {
|
|
13
|
+
success: boolean;
|
|
14
|
+
customSaleId: string;
|
|
15
|
+
label: string;
|
|
16
|
+
price: number;
|
|
17
|
+
quantity: number;
|
|
18
|
+
applyTaxes: boolean;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
}
|
|
21
|
+
export type EditCustomSale = (params?: EditCustomSaleParams) => Promise<EditCustomSaleResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -29,15 +29,6 @@ export interface PrintOptions {
|
|
|
29
29
|
};
|
|
30
30
|
paperSize?: string;
|
|
31
31
|
width?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Routing tag for multi-printer stations (FI-7113): names the print CATEGORY
|
|
34
|
-
* (e.g. "receipt", "kitchen"), never a printer. The station maps tags to its
|
|
35
|
-
* connected printers; at print time the host resolves the tag and prints to
|
|
36
|
-
* every matched printer at that printer's own paper size/margins. Declare the
|
|
37
|
-
* flow's tag set in flow-settings (`print.tags`) so the station can offer them
|
|
38
|
-
* for mapping. Untagged prints keep the station's default behavior.
|
|
39
|
-
*/
|
|
40
|
-
tag?: string;
|
|
41
32
|
}
|
|
42
33
|
export interface PrintResponse {
|
|
43
34
|
success: boolean;
|