@final-commerce/command-frame 0.6.1 → 0.6.2-staging3.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/dist/CommonTypes.d.ts +14 -1
- package/dist/actions/add-product-to-cart/mock.js +18 -1
- package/dist/actions/add-product-to-cart/types.d.ts +10 -0
- package/dist/actions/get-product-modifier-selections/action.d.ts +6 -0
- package/dist/actions/get-product-modifier-selections/action.js +8 -0
- package/dist/actions/get-product-modifier-selections/mock.d.ts +2 -0
- package/dist/actions/get-product-modifier-selections/mock.js +30 -0
- package/dist/actions/get-product-modifier-selections/types.d.ts +23 -0
- package/dist/actions/get-product-modifier-selections/types.js +1 -0
- package/dist/actions/set-product-modifier-selections/action.d.ts +6 -0
- package/dist/actions/set-product-modifier-selections/action.js +8 -0
- package/dist/actions/set-product-modifier-selections/mock.d.ts +2 -0
- package/dist/actions/set-product-modifier-selections/mock.js +49 -0
- package/dist/actions/set-product-modifier-selections/types.d.ts +27 -0
- package/dist/actions/set-product-modifier-selections/types.js +1 -0
- package/dist/demo/database.d.ts +24 -1
- package/dist/demo/database.js +68 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/projects/render/mocks.js +4 -0
- package/dist/projects/render/types.d.ts +3 -1
- package/dist/pubsub/topics/cart/product-modifiers-updated/types.d.ts +16 -0
- package/dist/pubsub/topics/cart/product-modifiers-updated/types.js +1 -0
- package/dist/pubsub/topics/cart/types.d.ts +4 -2
- package/dist/pubsub/topics/cart/types.js +1 -0
- package/package.json +2 -2
package/dist/CommonTypes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './common-types';
|
|
2
|
-
import type { Tax, Tip, Address, MetadataItem, PosDataItem, CartFeeTaxEntry, CartFeeItem, CartDiscountItem, OrderNote, NonRevenueItem, DiscountDetail, FeeDetail, DiscountLineItem, FeeLineItem, LineItem, TipPayment, RefundedTipPayment, PaymentMethod, Discount, CustomFee, Summary, CustomSale, RefundedCustomSale, RefundItem, RefundedLineItem, ActiveStation, ActiveSession, ActiveOutlet, ActiveUser, ActiveUserRole, ActiveOrder, ActiveCart, ActivePark, ActiveCompany, ActiveCustomSales, ActiveProduct, ActiveCustomer, FullProduct, ProductVariant, Inventory, CustomerNote, Attribute, AttributeOption, Category, Transaction, ActiveSplitPayment } from '@final-commerce/common/pos-types';
|
|
2
|
+
import type { Tax, Tip, Address, MetadataItem, PosDataItem, CartFeeTaxEntry, CartFeeItem, CartDiscountItem, OrderNote, NonRevenueItem, DiscountDetail, FeeDetail, DiscountLineItem, FeeLineItem, LineItem, TipPayment, RefundedTipPayment, PaymentMethod, Discount, CustomFee, Summary, CustomSale, RefundedCustomSale, RefundItem, RefundedLineItem, ActiveStation, ActiveSession, ActiveOutlet, ActiveUser, ActiveUserRole, ActiveOrder, ActiveCart, ActivePark, ActiveCompany, ActiveCustomSales, ActiveProduct, ActiveCustomer, FullProduct, ProductVariant, Inventory, ResolvedModifier, ResolvedModifierChoice, ModifierSelectionType, ModifierSelection, ModifierChoiceSelection, CartLineModifier, ProdModifierBreakdown, OrderLineItemModifier, CustomerNote, Attribute, AttributeOption, Category, Transaction, ActiveSplitPayment } from '@final-commerce/common/pos-types';
|
|
3
3
|
export { CurrencyCode, ProductType as CFProductType, UserTypes as CFUserTypes } from '@final-commerce/common';
|
|
4
4
|
/** Open record used as a base for active entities. */
|
|
5
5
|
export type CFActiveEntity = Record<string, unknown>;
|
|
@@ -18,6 +18,19 @@ export type CFTransaction = Transaction;
|
|
|
18
18
|
export type CFCategory = Category;
|
|
19
19
|
export type CFProductVariant = ProductVariant;
|
|
20
20
|
export type CFProduct = FullProduct;
|
|
21
|
+
/** Modifier (the till question) resolved onto a product — `CFProduct.modifiers`. */
|
|
22
|
+
export type CFResolvedModifier = ResolvedModifier;
|
|
23
|
+
export type CFResolvedModifierChoice = ResolvedModifierChoice;
|
|
24
|
+
export type CFModifierSelectionType = ModifierSelectionType;
|
|
25
|
+
/** One selected modifier choice on an order line item (wire shape). */
|
|
26
|
+
export type CFOrderLineItemModifier = OrderLineItemModifier;
|
|
27
|
+
/** Cart-line modifier answer (pre-pricing) — `CFActiveProduct.modifierSelections`. */
|
|
28
|
+
export type CFModifierSelection = ModifierSelection;
|
|
29
|
+
export type CFModifierChoiceSelection = ModifierChoiceSelection;
|
|
30
|
+
/** One selected choice PRICED onto a cart line — `CFActiveProduct.modifiers` (not the resolved stack). */
|
|
31
|
+
export type CFCartLineModifier = CartLineModifier;
|
|
32
|
+
/** A priced, line-extended modifier row: "Toppings - Avocado" x2, `amount` 1000. */
|
|
33
|
+
export type CFProdModifierBreakdown = ProdModifierBreakdown;
|
|
21
34
|
export type CFActiveProduct = ActiveProduct;
|
|
22
35
|
export type CFCustomer = ActiveCustomer;
|
|
23
36
|
export type CFActiveCustomer = ActiveCustomer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MOCK_CART, MOCK_PRODUCTS, mockPublishEvent } from '../../demo/database';
|
|
1
|
+
import { MOCK_CART, MOCK_PRODUCTS, buildCartLineModifiers, buildModifierRows, mockPublishEvent, } from '../../demo/database';
|
|
2
2
|
import { extendPrice, isValidQuantity, resolveUnit } from '@final-commerce/common';
|
|
3
3
|
export const mockAddProductToCart = async (params) => {
|
|
4
4
|
console.log('[Mock] addProductToCart called', params);
|
|
@@ -53,6 +53,18 @@ export const mockAddProductToCart = async (params) => {
|
|
|
53
53
|
note: note,
|
|
54
54
|
// discount/fee could be added here to mock object if CFActiveProduct supports it
|
|
55
55
|
};
|
|
56
|
+
// The spread above copied the PRODUCT's `modifiers` — a ResolvedModifier[] menu — into a
|
|
57
|
+
// field that means "the choices this line carries" (CartLineModifier[]). Two different
|
|
58
|
+
// shapes, one name. Drop it before anything reads the line, or every surface renders the
|
|
59
|
+
// whole catalogue as if the cashier had picked all of it.
|
|
60
|
+
delete activeProduct.modifiers;
|
|
61
|
+
// Keep the raw answers AND the priced rows, the same pair the real host writes. The cart
|
|
62
|
+
// TOTAL is deliberately left alone: like a product fee (see add-product-fee), per-line
|
|
63
|
+
// money is not accumulated by this mock — `total` stays Σ extendPrice(price, quantity).
|
|
64
|
+
if (params?.modifiers?.length) {
|
|
65
|
+
activeProduct.modifierSelections = params.modifiers;
|
|
66
|
+
activeProduct.modifiers = buildCartLineModifiers(product.modifiers, params.modifiers, product.taxTable);
|
|
67
|
+
}
|
|
56
68
|
MOCK_CART.products.push(activeProduct);
|
|
57
69
|
// Recalculate totals. extendPrice, not a raw multiply: a fractional quantity times an
|
|
58
70
|
// integer-minor price leaves fractional cents, which no order may carry.
|
|
@@ -64,6 +76,9 @@ export const mockAddProductToCart = async (params) => {
|
|
|
64
76
|
MOCK_CART.remainingBalance = MOCK_CART.total;
|
|
65
77
|
// Publish cart event to simulate real behavior
|
|
66
78
|
mockPublishEvent('cart', 'product-added', { product: activeProduct });
|
|
79
|
+
// Display-ready modifier rows for the line that was just created, so a flow can
|
|
80
|
+
// show what the modifiers added without re-reading the cart or multiplying.
|
|
81
|
+
const { rows, modifiersTotal } = buildModifierRows(activeProduct.modifiers, quantity);
|
|
67
82
|
return {
|
|
68
83
|
success: true,
|
|
69
84
|
productId: activeProduct.id,
|
|
@@ -71,6 +86,8 @@ export const mockAddProductToCart = async (params) => {
|
|
|
71
86
|
internalId: activeProduct.internalId,
|
|
72
87
|
name: activeProduct.name,
|
|
73
88
|
quantity: quantity,
|
|
89
|
+
rows,
|
|
90
|
+
modifiersTotal,
|
|
74
91
|
timestamp: new Date().toISOString(),
|
|
75
92
|
};
|
|
76
93
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { AddProductDiscountParams } from '../add-product-discount/types';
|
|
2
2
|
import type { AddProductFeeParams } from '../add-product-fee/types';
|
|
3
|
+
import type { ModifierSelection } from '../get-product-modifier-selections/types';
|
|
4
|
+
import type { CFProdModifierBreakdown } from '../../CommonTypes';
|
|
3
5
|
export interface AddProductToCartParams {
|
|
4
6
|
/** ID of the variant to add. */
|
|
5
7
|
variantId: string;
|
|
@@ -21,17 +23,25 @@ export interface AddProductToCartParams {
|
|
|
21
23
|
discounts?: AddProductDiscountParams[];
|
|
22
24
|
/** Array of fees to apply immediately. */
|
|
23
25
|
fees?: AddProductFeeParams[];
|
|
26
|
+
/** Modifier selections to apply immediately. */
|
|
27
|
+
modifiers?: ModifierSelection[];
|
|
24
28
|
/** Note or array of notes to add immediately. */
|
|
25
29
|
notes?: string | string[];
|
|
26
30
|
}
|
|
27
31
|
export interface AddProductToCartResponse {
|
|
28
32
|
success: boolean;
|
|
33
|
+
/** Set when the add was rejected (e.g. a required modifier is unanswered). */
|
|
34
|
+
reason?: string;
|
|
29
35
|
productId: string;
|
|
30
36
|
variantId: string;
|
|
31
37
|
/** The unique identifier for the specific item instance added to the cart. */
|
|
32
38
|
internalId: string;
|
|
33
39
|
name: string;
|
|
34
40
|
quantity: number;
|
|
41
|
+
/** The modifiers the line was created with, display-ready. Empty when there are none. */
|
|
42
|
+
rows: CFProdModifierBreakdown[];
|
|
43
|
+
/** Sum of `rows[].amount` — what the modifiers added to this line, in minor units. */
|
|
44
|
+
modifiersTotal: number;
|
|
35
45
|
timestamp: string;
|
|
36
46
|
}
|
|
37
47
|
export type AddProductToCart = (params?: AddProductToCartParams) => Promise<AddProductToCartResponse>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get product modifier selections action (read-only)
|
|
3
|
+
* Calls the getProductModifierSelections action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import type { GetProductModifierSelections } from "./types";
|
|
6
|
+
export declare const getProductModifierSelections: GetProductModifierSelections;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get product modifier selections action (read-only)
|
|
3
|
+
* Calls the getProductModifierSelections action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from "../../client";
|
|
6
|
+
export const getProductModifierSelections = async (params) => {
|
|
7
|
+
return await commandFrameClient.call("getProductModifierSelections", params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MOCK_CART, buildModifierRows } from "../../demo/database";
|
|
2
|
+
export const mockGetProductModifierSelections = async (params) => {
|
|
3
|
+
console.log("[Mock] getProductModifierSelections called", params);
|
|
4
|
+
// Read the line's stored selections from the mock cart (last line when no internalId).
|
|
5
|
+
const line = params?.internalId
|
|
6
|
+
? MOCK_CART.products.find((p) => p.internalId === params.internalId)
|
|
7
|
+
: MOCK_CART.products[MOCK_CART.products.length - 1];
|
|
8
|
+
if (!line) {
|
|
9
|
+
return {
|
|
10
|
+
success: false,
|
|
11
|
+
reason: "No matching cart line",
|
|
12
|
+
internalId: params?.internalId,
|
|
13
|
+
selections: [],
|
|
14
|
+
rows: [],
|
|
15
|
+
modifiersTotal: 0,
|
|
16
|
+
timestamp: new Date().toISOString()
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// The priced rows already sit on the line; extending them by the line quantity is
|
|
20
|
+
// the host's job, not the flow's.
|
|
21
|
+
const { rows, modifiersTotal } = buildModifierRows(line.modifiers, line.quantity);
|
|
22
|
+
return {
|
|
23
|
+
success: true,
|
|
24
|
+
internalId: line.internalId,
|
|
25
|
+
selections: line.modifierSelections ?? [],
|
|
26
|
+
rows,
|
|
27
|
+
modifiersTotal,
|
|
28
|
+
timestamp: new Date().toISOString()
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CFModifierSelection, CFModifierChoiceSelection, CFProdModifierBreakdown } from "../../CommonTypes";
|
|
2
|
+
/** Alias of common's — `quantity` is units PER LINE-ITEM UNIT. */
|
|
3
|
+
export type ModifierChoiceSelection = CFModifierChoiceSelection;
|
|
4
|
+
/** Alias of common's — the cashier's answer to one modifier. */
|
|
5
|
+
export type ModifierSelection = CFModifierSelection;
|
|
6
|
+
export interface GetProductModifierSelectionsParams {
|
|
7
|
+
/** The cart line to read. Defaults to the active product's line. */
|
|
8
|
+
internalId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface GetProductModifierSelectionsResponse {
|
|
11
|
+
success: boolean;
|
|
12
|
+
/** Set when the read failed (e.g. no such line, no active product). */
|
|
13
|
+
reason?: string;
|
|
14
|
+
internalId?: string;
|
|
15
|
+
/** Raw ids — round-trips back into the setter. No names, no money: use `rows` to display. */
|
|
16
|
+
selections: ModifierSelection[];
|
|
17
|
+
/** Display-ready: "Toppings - Avocado" x2, `amount` 1000. One row per chosen choice. */
|
|
18
|
+
rows: CFProdModifierBreakdown[];
|
|
19
|
+
/** Sum of `rows[].amount` for THIS line, in minor units. */
|
|
20
|
+
modifiersTotal: number;
|
|
21
|
+
timestamp: string;
|
|
22
|
+
}
|
|
23
|
+
export type GetProductModifierSelections = (params?: GetProductModifierSelectionsParams) => Promise<GetProductModifierSelectionsResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set product modifier selections action
|
|
3
|
+
* Calls the setProductModifierSelections action on the parent window
|
|
4
|
+
*/
|
|
5
|
+
import { commandFrameClient } from "../../client";
|
|
6
|
+
export const setProductModifierSelections = async (params) => {
|
|
7
|
+
return await commandFrameClient.call("setProductModifierSelections", params);
|
|
8
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MOCK_CART, MOCK_PRODUCTS, buildCartLineModifiers, buildModifierRows } from "../../demo/database";
|
|
2
|
+
export const mockSetProductModifierSelections = async (params) => {
|
|
3
|
+
console.log("[Mock] setProductModifierSelections called", params);
|
|
4
|
+
if (!params?.selections) {
|
|
5
|
+
return {
|
|
6
|
+
success: false,
|
|
7
|
+
reason: "selections is required (pass [] to clear)",
|
|
8
|
+
internalId: params?.internalId,
|
|
9
|
+
selections: [],
|
|
10
|
+
rows: [],
|
|
11
|
+
modifiersTotal: 0,
|
|
12
|
+
timestamp: new Date().toISOString()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
// Write the selections onto the mock cart line (last line when no internalId).
|
|
16
|
+
// The mock does not re-run rule VALIDATION — the real host does — but it does reprice,
|
|
17
|
+
// because a replacement that left the old rows and the old money behind would make the
|
|
18
|
+
// cart disagree with itself the moment a cashier edits a line.
|
|
19
|
+
const line = params.internalId
|
|
20
|
+
? MOCK_CART.products.find((p) => p.internalId === params.internalId)
|
|
21
|
+
: MOCK_CART.products[MOCK_CART.products.length - 1];
|
|
22
|
+
if (!line) {
|
|
23
|
+
return {
|
|
24
|
+
success: false,
|
|
25
|
+
reason: "No matching cart line",
|
|
26
|
+
internalId: params.internalId,
|
|
27
|
+
selections: [],
|
|
28
|
+
rows: [],
|
|
29
|
+
modifiersTotal: 0,
|
|
30
|
+
timestamp: new Date().toISOString()
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// Full replacement — passing [] clears the rows. The line drops the product's resolved
|
|
34
|
+
// stack when it is built, so the menu is re-read from the catalogue to price against.
|
|
35
|
+
// Cart totals are not touched, for the same reason addProductToCart does not move them
|
|
36
|
+
// for modifiers: this mock does not accumulate per-line money.
|
|
37
|
+
const source = MOCK_PRODUCTS.find((product) => product._id === line.id);
|
|
38
|
+
line.modifierSelections = params.selections;
|
|
39
|
+
line.modifiers = buildCartLineModifiers(source?.modifiers, params.selections, source?.taxTable);
|
|
40
|
+
const { rows, modifiersTotal } = buildModifierRows(line.modifiers, line.quantity);
|
|
41
|
+
return {
|
|
42
|
+
success: true,
|
|
43
|
+
internalId: line.internalId,
|
|
44
|
+
selections: params.selections,
|
|
45
|
+
rows,
|
|
46
|
+
modifiersTotal,
|
|
47
|
+
timestamp: new Date().toISOString()
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ModifierSelection } from "../get-product-modifier-selections/types";
|
|
2
|
+
import type { CFProdModifierBreakdown } from "../../CommonTypes";
|
|
3
|
+
export interface SetProductModifierSelectionsParams {
|
|
4
|
+
/** The cart line to edit. Defaults to the active product's line. */
|
|
5
|
+
internalId?: string;
|
|
6
|
+
/**
|
|
7
|
+
* The line's COMPLETE new answers — replaces every existing selection on the
|
|
8
|
+
* line (send [] to clear all optional modifiers). Validated against the
|
|
9
|
+
* product's category-modifier rules exactly like addProductToCart({ modifiers }):
|
|
10
|
+
* a selection that breaks a rule rejects the edit and the line is unchanged.
|
|
11
|
+
*/
|
|
12
|
+
selections: ModifierSelection[];
|
|
13
|
+
}
|
|
14
|
+
export interface SetProductModifierSelectionsResponse {
|
|
15
|
+
success: boolean;
|
|
16
|
+
/** Set when the edit was rejected (rule violation) — the line is unchanged. */
|
|
17
|
+
reason?: string;
|
|
18
|
+
internalId?: string;
|
|
19
|
+
/** The selections now on the line (the new ones on success, the old ones on rejection). */
|
|
20
|
+
selections: ModifierSelection[];
|
|
21
|
+
/** Display-ready — repaint from this instead of re-reading after an edit. */
|
|
22
|
+
rows: CFProdModifierBreakdown[];
|
|
23
|
+
/** Sum of `rows[].amount` for THIS line, in minor units. */
|
|
24
|
+
modifiersTotal: number;
|
|
25
|
+
timestamp: string;
|
|
26
|
+
}
|
|
27
|
+
export type SetProductModifierSelections = (params?: SetProductModifierSelectionsParams) => Promise<SetProductModifierSelectionsResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/demo/database.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Mock Database for Standalone/Demo Mode
|
|
3
3
|
* Stores mock data that mimics the Render environment
|
|
4
4
|
*/
|
|
5
|
-
import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout } from '../CommonTypes';
|
|
5
|
+
import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout, CFCartLineModifier, CFProdModifierBreakdown, CFModifierSelection, CFResolvedModifier } from '../CommonTypes';
|
|
6
6
|
export * from './mocks';
|
|
7
7
|
/** Replace mock catalog / context data in place (same array references mock handlers use). */
|
|
8
8
|
export interface MockDatabaseConfig {
|
|
@@ -87,3 +87,26 @@ export declare const createOrderFromCart: (paymentType: string, amount: number,
|
|
|
87
87
|
* open with `amountToBeCharged` reset to what's left, and returns null.
|
|
88
88
|
*/
|
|
89
89
|
export declare const applyMockPayment: (amount: number, paymentType: string, processor?: string) => CFActiveOrder | null;
|
|
90
|
+
/**
|
|
91
|
+
* Price the cashier's raw modifier answers into the rows a CART line carries (FT-0010).
|
|
92
|
+
*
|
|
93
|
+
* Here rather than in an action folder because two mocks need it — addProductToCart and
|
|
94
|
+
* setProductModifierSelections — and this module is already where the shared mock helpers
|
|
95
|
+
* live (`safeSerialize`, `resetMockCart`, `mockPublishEvent`).
|
|
96
|
+
*
|
|
97
|
+
* Note the two shapes that share the name `modifiers` and are NOT interchangeable:
|
|
98
|
+
* `FullProduct.modifiers` is `ResolvedModifier[]` (the menu — question + every choice),
|
|
99
|
+
* `ActiveProduct.modifiers` is `CartLineModifier[]` (one row per CHOSEN choice). The mock
|
|
100
|
+
* builds a cart line by spreading the product, so the menu must be stripped off the line
|
|
101
|
+
* before anything reads it, or every surface renders the catalogue as if it were picked.
|
|
102
|
+
*
|
|
103
|
+
* Names and unitPrice are snapshotted, as the real host does — a later rename never
|
|
104
|
+
* rewrites an open cart. No `total`: a cart row is per line UNIT, and the host extends it.
|
|
105
|
+
* Rule validation (required/min/max) is deliberately not mocked; the real host owns it.
|
|
106
|
+
*/
|
|
107
|
+
/** Extend a line's priced modifier rows by the line quantity. Mirrors kaching's `buildProdModifiers`. */
|
|
108
|
+
export declare const buildModifierRows: (modifiers: CFCartLineModifier[] | undefined, lineQuantity: number | undefined) => {
|
|
109
|
+
rows: CFProdModifierBreakdown[];
|
|
110
|
+
modifiersTotal: number;
|
|
111
|
+
};
|
|
112
|
+
export declare const buildCartLineModifiers: (menu: CFResolvedModifier[] | undefined, selections: CFModifierSelection[] | undefined, productTaxTableId?: string) => CFCartLineModifier[];
|
package/dist/demo/database.js
CHANGED
|
@@ -914,3 +914,71 @@ export const applyMockPayment = (amount, paymentType, processor = 'cash') => {
|
|
|
914
914
|
mockPublishEvent('payments', 'payment-done', { order });
|
|
915
915
|
return order;
|
|
916
916
|
};
|
|
917
|
+
/**
|
|
918
|
+
* Price the cashier's raw modifier answers into the rows a CART line carries (FT-0010).
|
|
919
|
+
*
|
|
920
|
+
* Here rather than in an action folder because two mocks need it — addProductToCart and
|
|
921
|
+
* setProductModifierSelections — and this module is already where the shared mock helpers
|
|
922
|
+
* live (`safeSerialize`, `resetMockCart`, `mockPublishEvent`).
|
|
923
|
+
*
|
|
924
|
+
* Note the two shapes that share the name `modifiers` and are NOT interchangeable:
|
|
925
|
+
* `FullProduct.modifiers` is `ResolvedModifier[]` (the menu — question + every choice),
|
|
926
|
+
* `ActiveProduct.modifiers` is `CartLineModifier[]` (one row per CHOSEN choice). The mock
|
|
927
|
+
* builds a cart line by spreading the product, so the menu must be stripped off the line
|
|
928
|
+
* before anything reads it, or every surface renders the catalogue as if it were picked.
|
|
929
|
+
*
|
|
930
|
+
* Names and unitPrice are snapshotted, as the real host does — a later rename never
|
|
931
|
+
* rewrites an open cart. No `total`: a cart row is per line UNIT, and the host extends it.
|
|
932
|
+
* Rule validation (required/min/max) is deliberately not mocked; the real host owns it.
|
|
933
|
+
*/
|
|
934
|
+
/** Extend a line's priced modifier rows by the line quantity. Mirrors kaching's `buildProdModifiers`. */
|
|
935
|
+
export const buildModifierRows = (modifiers, lineQuantity) => {
|
|
936
|
+
const quantity = lineQuantity ?? 1;
|
|
937
|
+
const rows = (modifiers ?? []).map((modifier) => ({
|
|
938
|
+
modifierId: modifier.modifierId,
|
|
939
|
+
modifierName: modifier.modifierName,
|
|
940
|
+
choiceId: modifier.choiceId,
|
|
941
|
+
choiceName: modifier.choiceName,
|
|
942
|
+
label: modifier.label ?? `${modifier.modifierName} - ${modifier.choiceName}`,
|
|
943
|
+
unitPrice: modifier.unitPrice,
|
|
944
|
+
quantity: modifier.quantity,
|
|
945
|
+
// extendPrice, not a raw multiply: a fractional line quantity (1.5 kg) must not
|
|
946
|
+
// leave fractional minor units on the row.
|
|
947
|
+
amount: extendPrice(modifier.unitPrice * modifier.quantity, quantity),
|
|
948
|
+
tax: 0,
|
|
949
|
+
...(modifier.taxTableId ? { taxTableId: modifier.taxTableId } : {}),
|
|
950
|
+
...(modifier.taxRateId ? { taxRateId: modifier.taxRateId } : {})
|
|
951
|
+
}));
|
|
952
|
+
return { rows, modifiersTotal: rows.reduce((sum, row) => sum + row.amount, 0) };
|
|
953
|
+
};
|
|
954
|
+
export const buildCartLineModifiers = (menu, selections, productTaxTableId) => {
|
|
955
|
+
if (!menu?.length || !selections?.length)
|
|
956
|
+
return [];
|
|
957
|
+
const byModifier = new Map(menu.map((modifier) => [modifier._id, modifier]));
|
|
958
|
+
const rows = [];
|
|
959
|
+
for (const selection of selections) {
|
|
960
|
+
const modifier = byModifier.get(selection.modifierId);
|
|
961
|
+
if (!modifier)
|
|
962
|
+
continue;
|
|
963
|
+
const byChoice = new Map(modifier.choices.map((choice) => [choice._id, choice]));
|
|
964
|
+
for (const picked of selection.choices ?? []) {
|
|
965
|
+
const choice = byChoice.get(picked.choiceId);
|
|
966
|
+
// `quantity` is units per ONE line unit; 0 means "not chosen" and carries no row.
|
|
967
|
+
if (!choice || !(picked.quantity > 0))
|
|
968
|
+
continue;
|
|
969
|
+
rows.push({
|
|
970
|
+
modifierId: modifier._id,
|
|
971
|
+
modifierName: modifier.name,
|
|
972
|
+
choiceId: choice._id,
|
|
973
|
+
choiceName: choice.name,
|
|
974
|
+
// The cart's display label, like CustomFee.label — "Toppings - Avocado".
|
|
975
|
+
label: `${modifier.name} - ${choice.name}`,
|
|
976
|
+
unitPrice: choice.price,
|
|
977
|
+
quantity: picked.quantity,
|
|
978
|
+
// Modifier tax follows the parent product's table, as a fee's does.
|
|
979
|
+
...(productTaxTableId ? { taxTableId: productTaxTableId } : {}),
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return rows;
|
|
984
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export declare const command: {
|
|
|
21
21
|
readonly getFinalContext: import(".").GetFinalContext;
|
|
22
22
|
readonly addProductNote: import(".").AddProductNote;
|
|
23
23
|
readonly addProductFee: import(".").AddProductFee;
|
|
24
|
+
readonly getProductModifierSelections: import(".").GetProductModifierSelections;
|
|
25
|
+
readonly setProductModifierSelections: import(".").SetProductModifierSelections;
|
|
24
26
|
readonly setActiveProductFee: import(".").SetActiveProductFee;
|
|
25
27
|
readonly setActiveProductDiscount: import(".").SetActiveProductDiscount;
|
|
26
28
|
readonly getActiveProduct: import(".").GetActiveProduct;
|
|
@@ -157,6 +159,8 @@ export type { GetContext, GetContextResponse, GetContextResponseManage, GetConte
|
|
|
157
159
|
export type { GetFinalContext, GetFinalContextResponse } from './actions/get-final-context/types';
|
|
158
160
|
export type { AddProductNote, AddProductNoteParams, AddProductNoteResponse } from './actions/add-product-note/types';
|
|
159
161
|
export type { AddProductFee, AddProductFeeParams, AddProductFeeResponse } from './actions/add-product-fee/types';
|
|
162
|
+
export type { GetProductModifierSelections, GetProductModifierSelectionsParams, GetProductModifierSelectionsResponse, ModifierSelection, ModifierChoiceSelection, } from './actions/get-product-modifier-selections/types';
|
|
163
|
+
export type { SetProductModifierSelections, SetProductModifierSelectionsParams, SetProductModifierSelectionsResponse, } from './actions/set-product-modifier-selections/types';
|
|
160
164
|
export type { SetActiveProductFee, SetActiveProductFeeParams, SetActiveProductFeeResponse, } from './actions/set-active-product-fee/types';
|
|
161
165
|
export type { SetActiveProductDiscount, SetActiveProductDiscountParams, SetActiveProductDiscountResponse, } from './actions/set-active-product-discount/types';
|
|
162
166
|
export type { GetActiveProduct, GetActiveProductResponse } from './actions/get-active-product/types';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,8 @@ import { updateCartItemQuantity } from './actions/update-cart-item-quantity/acti
|
|
|
20
20
|
// Product Actions
|
|
21
21
|
import { addProductNote } from './actions/add-product-note/action';
|
|
22
22
|
import { addProductFee } from './actions/add-product-fee/action';
|
|
23
|
+
import { getProductModifierSelections } from './actions/get-product-modifier-selections/action';
|
|
24
|
+
import { setProductModifierSelections } from './actions/set-product-modifier-selections/action';
|
|
23
25
|
import { setActiveProductFee } from './actions/set-active-product-fee/action';
|
|
24
26
|
import { setActiveProductDiscount } from './actions/set-active-product-discount/action';
|
|
25
27
|
import { getActiveProduct } from './actions/get-active-product/action';
|
|
@@ -157,6 +159,8 @@ export const command = {
|
|
|
157
159
|
// Product Actions
|
|
158
160
|
addProductNote,
|
|
159
161
|
addProductFee,
|
|
162
|
+
getProductModifierSelections,
|
|
163
|
+
setProductModifierSelections,
|
|
160
164
|
setActiveProductFee,
|
|
161
165
|
setActiveProductDiscount,
|
|
162
166
|
getActiveProduct,
|
|
@@ -12,6 +12,8 @@ import { mockAddOrderNote } from '../../actions/add-order-note/mock';
|
|
|
12
12
|
import { mockRemoveOrderNote } from '../../actions/remove-order-note/mock';
|
|
13
13
|
import { mockAddProductDiscount } from '../../actions/add-product-discount/mock';
|
|
14
14
|
import { mockAddProductFee } from '../../actions/add-product-fee/mock';
|
|
15
|
+
import { mockGetProductModifierSelections } from '../../actions/get-product-modifier-selections/mock';
|
|
16
|
+
import { mockSetProductModifierSelections } from '../../actions/set-product-modifier-selections/mock';
|
|
15
17
|
import { mockRemoveProductDiscount } from '../../actions/remove-product-discount/mock';
|
|
16
18
|
import { mockRemoveProductFee } from '../../actions/remove-product-fee/mock';
|
|
17
19
|
import { mockSetActiveProductFee } from '../../actions/set-active-product-fee/mock';
|
|
@@ -112,6 +114,8 @@ export const RENDER_MOCKS = {
|
|
|
112
114
|
addOrderNote: mockAddOrderNote,
|
|
113
115
|
addProductDiscount: mockAddProductDiscount,
|
|
114
116
|
addProductFee: mockAddProductFee,
|
|
117
|
+
getProductModifierSelections: mockGetProductModifierSelections,
|
|
118
|
+
setProductModifierSelections: mockSetProductModifierSelections,
|
|
115
119
|
setActiveProductFee: mockSetActiveProductFee,
|
|
116
120
|
setActiveProductDiscount: mockSetActiveProductDiscount,
|
|
117
121
|
getActiveProduct: mockGetActiveProduct,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount, GetActiveOrder, GetActiveCustomer, SetActiveCustomer, GetActiveOutlet, GetActiveStation, GetActiveSession, GetActiveUser, SetActiveUser, SetActiveRefund, RemoveProductDiscount, RemoveProductFee, RemoveProductNote, RemoveCartFee, RemoveOrderNote, RemoveCustomSale, RemoveNonRevenueItem, CanTransition, GetAvailableTransitions, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, CreatePaymentLink, ChargeMoto, GetTimeClockStatus } from '../../index';
|
|
1
|
+
import type { ExampleFunction, GetProducts, AddCustomSale, EditCustomSale, GetCustomers, AssignCustomer, AddCustomer, EditCustomer, GetCategories, GetOrders, GetRefunds, GetTaxTables, AddProductDiscount, AddProductToCart, RemoveProductFromCart, UpdateCartItemQuantity, AddCartDiscount, GetContext, GetFinalContext, AddProductNote, AddProductFee, GetProductModifierSelections, SetProductModifierSelections, SetActiveProductFee, SetActiveProductDiscount, GetActiveProduct, SetActiveProduct, AdjustInventory, AddOrderNote, AddCartFee, ClearCart, ParkOrder, ResumeParkedOrder, DeleteParkedOrder, VoidOrder, InitiateRefund, CashPayment, GetCashRoundingAmount, TapToPayPayment, TerminalPayment, ExtensionPayment, RedeemPayment, AddNonRevenueItem, AddCustomerNote, RemoveCustomerNote, RemoveCustomerFromCart, GoToStationHome, OpenCashDrawer, ShowNotification, ShowConfirmation, AuthenticateUser, PartialPayment, SwitchUser, SetRefundStockAction, SelectAllRefundItems, ResetRefundDetails, CalculateRefundTotal, GetRemainingRefundableQuantities, ProcessPartialRefund, RedeemRefund, GetRefundPlan, CheckPermission, GetCurrentCart, Print, SetActiveOrder, GetCustomTables, GetCustomTableData, UpsertCustomTableData, DeleteCustomTableData, GetCustomExtensions, GetCurrentCompanyCustomExtensions, GetCustomExtensionCustomTables, GetCustomTableFields, GetSecretsKeys, GetSecretVal, SetSecretVal, GetUsers, GetRoles, RemoveCartDiscount, GetActiveOrder, GetActiveCustomer, SetActiveCustomer, GetActiveOutlet, GetActiveStation, GetActiveSession, GetActiveUser, SetActiveUser, SetActiveRefund, RemoveProductDiscount, RemoveProductFee, RemoveProductNote, RemoveCartFee, RemoveOrderNote, RemoveCustomSale, RemoveNonRevenueItem, CanTransition, GetAvailableTransitions, ApplyTransition, IntegrationPayment, GetSmartGridLayout, SaveSmartGridLayout, SendEmail, SendSms, CreatePaymentLink, ChargeMoto, GetTimeClockStatus } from '../../index';
|
|
2
2
|
export interface RenderProviderActions {
|
|
3
3
|
exampleFunction: ExampleFunction;
|
|
4
4
|
getProducts: GetProducts;
|
|
@@ -21,6 +21,8 @@ export interface RenderProviderActions {
|
|
|
21
21
|
getFinalContext: GetFinalContext;
|
|
22
22
|
addProductNote: AddProductNote;
|
|
23
23
|
addProductFee: AddProductFee;
|
|
24
|
+
getProductModifierSelections: GetProductModifierSelections;
|
|
25
|
+
setProductModifierSelections: SetProductModifierSelections;
|
|
24
26
|
setActiveProductFee: SetActiveProductFee;
|
|
25
27
|
setActiveProductDiscount: SetActiveProductDiscount;
|
|
26
28
|
getActiveProduct: GetActiveProduct;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CFActiveProduct, CFModifierSelection } from "../../../../CommonTypes";
|
|
2
|
+
import type { TopicEvent } from "../../../types";
|
|
3
|
+
/**
|
|
4
|
+
* Payload for product-modifiers-updated event (FT-0010) — fired when a cart
|
|
5
|
+
* line's modifier selections are replaced via setProductModifierSelections.
|
|
6
|
+
*/
|
|
7
|
+
export interface ProductModifiersUpdatedPayload {
|
|
8
|
+
product: CFActiveProduct;
|
|
9
|
+
internalId?: string;
|
|
10
|
+
/** The line's complete new answers (full replacement). */
|
|
11
|
+
selections: CFModifierSelection[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Typed event for product-modifiers-updated
|
|
15
|
+
*/
|
|
16
|
+
export type ProductModifiersUpdatedEvent = TopicEvent<ProductModifiersUpdatedPayload>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -17,6 +17,7 @@ export * from "./product-fee-added/types";
|
|
|
17
17
|
export * from "./product-fee-removed/types";
|
|
18
18
|
export * from "./product-note-added/types";
|
|
19
19
|
export * from "./product-note-removed/types";
|
|
20
|
+
export * from "./product-modifiers-updated/types";
|
|
20
21
|
import type { CartCreatedPayload } from "./cart-created/types";
|
|
21
22
|
import type { CartCustomerAssignedPayload } from "./customer-assigned/types";
|
|
22
23
|
import type { ProductAddedPayload } from "./product-added/types";
|
|
@@ -32,5 +33,6 @@ import type { ProductFeeAddedPayload } from "./product-fee-added/types";
|
|
|
32
33
|
import type { ProductFeeRemovedPayload } from "./product-fee-removed/types";
|
|
33
34
|
import type { ProductNoteAddedPayload } from "./product-note-added/types";
|
|
34
35
|
import type { ProductNoteRemovedPayload } from "./product-note-removed/types";
|
|
35
|
-
|
|
36
|
-
export type
|
|
36
|
+
import type { ProductModifiersUpdatedPayload } from "./product-modifiers-updated/types";
|
|
37
|
+
export type CartEventPayload = CartCreatedPayload | CartCustomerAssignedPayload | ProductAddedPayload | ProductDeletedPayload | CartProductUpdatedPayload | CartDiscountAddedPayload | CartDiscountRemovedPayload | CartFeeAddedPayload | CartFeeRemovedPayload | ProductDiscountAddedPayload | ProductDiscountRemovedPayload | ProductFeeAddedPayload | ProductFeeRemovedPayload | ProductNoteAddedPayload | ProductNoteRemovedPayload | ProductModifiersUpdatedPayload;
|
|
38
|
+
export type CartEventType = "cart-created" | "customer-assigned" | "customer-unassigned" | "product-added" | "product-deleted" | "product-updated" | "cart-discount-added" | "cart-discount-removed" | "cart-fee-added" | "cart-fee-removed" | "product-discount-added" | "product-discount-removed" | "product-fee-added" | "product-fee-removed" | "product-note-added" | "product-note-removed" | "product-modifiers-updated";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@final-commerce/command-frame",
|
|
3
|
-
"version": "0.6.1",
|
|
3
|
+
"version": "0.6.2-staging3.1",
|
|
4
4
|
"description": "Commands Frame library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"ignoreBranchesMissingTickets": true
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@final-commerce/common": "2.2.
|
|
60
|
+
"@final-commerce/common": "2.2.4-staging3.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^19.0.0",
|