@managesome/eposmatic-toolkit 0.2.721 → 0.2.733
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/lib/helpers/types/order-engine.d.ts +17 -2
- package/lib/helpers/utils/cart-helpers.d.ts +2 -0
- package/lib/helpers/utils/halfhalf-setup-helpers.js +47 -27
- package/lib/helpers/utils/order-engine.d.ts +56 -15
- package/lib/helpers/utils/order-engine.js +240 -130
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/inventory_entries.d.ts +152 -0
- package/lib/schemas/models/inventory_entries.js +142 -0
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/inventory_entries.d.ts +41 -0
- package/lib/schemas/types/inventory_entries.js +2 -0
- package/lib/tests/choose-expensive-edge-cases.test.d.ts +1 -0
- package/lib/tests/choose-expensive-edge-cases.test.js +966 -0
- package/lib/tests/choose-expensive-flow-verification.test.d.ts +1 -0
- package/lib/tests/choose-expensive-flow-verification.test.js +702 -0
- package/lib/tests/halfhalf-selection-rules.test.d.ts +1 -0
- package/lib/tests/halfhalf-selection-rules.test.js +200 -0
- package/lib/tests/segment-price-floor.test.d.ts +1 -0
- package/lib/tests/segment-price-floor.test.js +143 -0
- package/lib/tests/specials-halfhalf-pricing.test.js +40 -19
- package/package.json +1 -1
|
@@ -27,17 +27,32 @@ export interface IOrderEngineModifier extends Omit<IModifier, 'options'> {
|
|
|
27
27
|
* mutates `price`, so this map is a COMPLETE reference of the original state:
|
|
28
28
|
* re-basing from it before every re-apply keeps the rule reversible (raise
|
|
29
29
|
* AND lower) while selections stay untouched.
|
|
30
|
+
*
|
|
31
|
+
* A key is ABSENT when the option has no definition entry (e.g. it was
|
|
32
|
+
* created outside the catalog definition) — readers must treat absence as
|
|
33
|
+
* "no reference, keep the current price", never as `0`.
|
|
30
34
|
*/
|
|
31
|
-
export type TOrderEnginePriceReferences =
|
|
35
|
+
export type TOrderEnginePriceReferences = {
|
|
36
|
+
[optionPath: string]: number | undefined;
|
|
37
|
+
};
|
|
32
38
|
/**
|
|
33
39
|
* Return of `convertCatalogItemToOrderEngineItem`: the immutable original
|
|
34
40
|
* price references plus the item the UI edits (working data). The references
|
|
35
41
|
* are never mutated; every normalization reads them to restore prices first.
|
|
36
42
|
*/
|
|
37
43
|
export interface IOrderEngineItemState {
|
|
38
|
-
originalPriceReferences: TOrderEnginePriceReferences;
|
|
44
|
+
readonly originalPriceReferences: TOrderEnginePriceReferences;
|
|
39
45
|
workingData: IOrderEngineItem;
|
|
40
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Options of `applyChooseExpensiveSegmentPrice` /
|
|
49
|
+
* `applyNestedChooseExpensiveSegmentPrice`: the immutable definition prices the
|
|
50
|
+
* rule re-bases from before every normalization (see
|
|
51
|
+
* `TOrderEnginePriceReferences`). Omitted → the legacy raise-only behaviour.
|
|
52
|
+
*/
|
|
53
|
+
export interface IChooseExpensiveSegmentPriceOptions {
|
|
54
|
+
originalPriceReferences?: TOrderEnginePriceReferences;
|
|
55
|
+
}
|
|
41
56
|
export interface IOrderEngineItem {
|
|
42
57
|
_id: string;
|
|
43
58
|
category_id: string;
|
|
@@ -37,6 +37,8 @@ export interface ICatalogItemOptionsDrawerProps<I extends ISimplifiedCatalogItem
|
|
|
37
37
|
rewardClaim?: IRewardClaim;
|
|
38
38
|
isRewardItem?: boolean;
|
|
39
39
|
chooseExpensiveSegmentPrice?: boolean;
|
|
40
|
+
segmentPriceFloor?: number;
|
|
41
|
+
isHalfHalfSegmentItem?: boolean;
|
|
40
42
|
onSelect?: (item: IOrderItem) => void;
|
|
41
43
|
}
|
|
42
44
|
interface IGetEditItemProps<I extends ISimplifiedCatalogItem | IItem> {
|
|
@@ -140,10 +140,6 @@ const zeroModifierPrices = (modifiers) => {
|
|
|
140
140
|
function zeroItemPrices(item) {
|
|
141
141
|
return { ...item, price: null, modifiers: zeroModifierPrices(item.modifiers) };
|
|
142
142
|
}
|
|
143
|
-
function isRequiredModifierGroup(modifier) {
|
|
144
|
-
return ((modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
145
|
-
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0));
|
|
146
|
-
}
|
|
147
143
|
function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, platform, tenant_id) {
|
|
148
144
|
if (!platform || !tenant_id)
|
|
149
145
|
return [];
|
|
@@ -277,7 +273,8 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
277
273
|
* Returns null only when no option can be resolved from the items map.
|
|
278
274
|
*/
|
|
279
275
|
function convertHalfHalfToItem(halfhalfSetup, itemsMap, options) {
|
|
280
|
-
const
|
|
276
|
+
const specialItems = options?.specialItems;
|
|
277
|
+
const isSpecialContext = specialItems != null;
|
|
281
278
|
// Fields are carried through as-is (no schedule resolution here).
|
|
282
279
|
const upsell_price = halfhalfSetup.upsell_price;
|
|
283
280
|
const discount_amount = halfhalfSetup.discount_amount;
|
|
@@ -286,8 +283,8 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, options) {
|
|
|
286
283
|
// In a special the segment options ARE the special's own items; the
|
|
287
284
|
// half-half's original item list is never used. Standalone uses the
|
|
288
285
|
// half-half's own list (respecting its excluded_refs).
|
|
289
|
-
const halfHalfItems =
|
|
290
|
-
? [...
|
|
286
|
+
const halfHalfItems = specialItems
|
|
287
|
+
? [...specialItems].sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0))
|
|
291
288
|
: [...halfhalfSetup.items]
|
|
292
289
|
// Respect excluded_refs: items whose item_id (ref) is listed are
|
|
293
290
|
// removed from the selectable list (same semantics as specials').
|
|
@@ -556,24 +553,35 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
556
553
|
});
|
|
557
554
|
});
|
|
558
555
|
};
|
|
559
|
-
|
|
556
|
+
// `exclusive_refs` items are FREE inside the half-half through PRICE ONLY
|
|
557
|
+
// (the workable conversion nulls their price). `is_free` is never set
|
|
558
|
+
// here: the "Free" tag belongs exclusively to `num_free_options` options.
|
|
559
|
+
const toEngineModifiers = (modifiers, depth, definitionModifiers) => (modifiers ?? []).map((modifier) => {
|
|
560
|
+
// Required/max flags come from the CATALOG definition: stored order-item
|
|
561
|
+
// modifiers don't carry them, and treating every group as required would
|
|
562
|
+
// let selected add-ons (e.g. toppings) inflate the choose_expensive
|
|
563
|
+
// comparison — they add on top of the segment instead.
|
|
564
|
+
const definitionModifier = (definitionModifiers ?? []).find((def) => def._id === modifier._id);
|
|
560
565
|
const options = modifier.options ?? [];
|
|
561
|
-
const engineOptions = options.map((option) =>
|
|
562
|
-
_id
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
566
|
+
const engineOptions = options.map((option) => {
|
|
567
|
+
const definitionOption = (definitionModifier?.options ?? []).find((def) => def._id === option._id);
|
|
568
|
+
return {
|
|
569
|
+
_id: option._id,
|
|
570
|
+
ref: option.ref,
|
|
571
|
+
name: option.name,
|
|
572
|
+
price: option.price,
|
|
573
|
+
quantity: option.quantity || 1,
|
|
574
|
+
is_free: option.is_free ?? false,
|
|
575
|
+
default: true,
|
|
576
|
+
loyalty_applied: false,
|
|
577
|
+
voucher_applied: false,
|
|
578
|
+
active: true,
|
|
579
|
+
sold_out: [],
|
|
580
|
+
sort_id: 0,
|
|
581
|
+
excluded_platforms: [],
|
|
582
|
+
modifiers: toEngineModifiers(option.modifiers, depth + 1, definitionOption?.modifiers),
|
|
583
|
+
};
|
|
584
|
+
});
|
|
577
585
|
return {
|
|
578
586
|
_id: modifier._id,
|
|
579
587
|
ref: modifier.ref,
|
|
@@ -584,8 +592,20 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
584
592
|
active: true,
|
|
585
593
|
sold_out: [],
|
|
586
594
|
sort_id: 0,
|
|
587
|
-
|
|
588
|
-
|
|
595
|
+
// Mirror the catalog flags EXACTLY when the definition is known
|
|
596
|
+
// (undefined/null min = optional). Unknown groups keep the previous
|
|
597
|
+
// conservative default (required, max = selection count).
|
|
598
|
+
...(definitionModifier != null
|
|
599
|
+
? {
|
|
600
|
+
min_num_options: definitionModifier.min_num_options,
|
|
601
|
+
max_num_options: definitionModifier.max_num_options,
|
|
602
|
+
min_aggregate_options_quantity: definitionModifier.min_aggregate_options_quantity,
|
|
603
|
+
max_aggregate_options_quantity: definitionModifier.max_aggregate_options_quantity,
|
|
604
|
+
}
|
|
605
|
+
: {
|
|
606
|
+
min_num_options: 1,
|
|
607
|
+
max_num_options: options.length || 1,
|
|
608
|
+
}),
|
|
589
609
|
options: engineOptions,
|
|
590
610
|
};
|
|
591
611
|
});
|
|
@@ -619,7 +639,7 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
619
639
|
sold_out: [],
|
|
620
640
|
sort_id: 0,
|
|
621
641
|
excluded_platforms: [],
|
|
622
|
-
modifiers: toEngineModifiers(selectedItem.modifiers, 1),
|
|
642
|
+
modifiers: toEngineModifiers(selectedItem.modifiers, 1, definitionItem?.modifiers),
|
|
623
643
|
},
|
|
624
644
|
];
|
|
625
645
|
const segmentModifier = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ORDER_ITEM_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
|
|
2
2
|
import { IDiscountDetails, IGiftCard, IItem, IModifier, IOffer, IOrderItem, IPrice } from '../../schemas';
|
|
3
3
|
import { ISimplifiedCatalogItem } from '../types';
|
|
4
|
-
import { IOrderEngineItem, IOrderEngineItemState, IOrderEngineModifier, IOrderEngineOption
|
|
4
|
+
import { IChooseExpensiveSegmentPriceOptions, IOrderEngineItem, IOrderEngineItemState, IOrderEngineModifier, IOrderEngineOption } from '../types/order-engine';
|
|
5
5
|
export declare function hasMissedRequiredItemModifier(currentModifiers: IModifier[] | null, platform: PLATFORMS_ENUM | undefined): boolean;
|
|
6
6
|
export declare function syncOrderEngineItem(orderEngineItem: IOrderEngineItem): IOrderEngineItem;
|
|
7
7
|
export declare function checkIfModifiersExist(modifiers: IModifier[] | null, platform: PLATFORMS_ENUM | undefined): boolean;
|
|
@@ -22,11 +22,16 @@ export declare function makeSpaceForFreeOptions(options: IOrderEngineOption[], n
|
|
|
22
22
|
* baked into the option price at conversion. choose_expensive compares every
|
|
23
23
|
* segment option (option price + required/price-defining modifier prices —
|
|
24
24
|
* e.g. a "Pizza Size" group whose Small/Large/X-Large options are part of the
|
|
25
|
-
* item's price) and levels the cheaper
|
|
25
|
+
* item's price) and levels the cheaper PICK to the most expensive SELECTED
|
|
26
26
|
* half — `A($5)+B($5)` charges 5+5, `B($5)+C($6)` charges 6+6, and switching
|
|
27
|
-
* `C+D -> A+B` lowers them again.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* `C+D -> A+B` lowers them again. Every option is levelled to `max(own value,
|
|
28
|
+
* the max of the OTHER segments' selected values)` — the level its OWN pick
|
|
29
|
+
* would produce: choosing an unselected sibling REPLACES its segment's
|
|
30
|
+
* current pick, so that pick never inflates its own siblings' prices (a
|
|
31
|
+
* segment holding the expensive half keeps its other options at their own
|
|
32
|
+
* prices — you can only pick the next half from the NEXT segment), while a
|
|
33
|
+
* segment with no pick yet previews the full level. Unselected options never
|
|
34
|
+
* contribute to totals. The raise is applied to the FIRST
|
|
30
35
|
* PRICED element along the segment's price chain: the segment option's own
|
|
31
36
|
* price when non-zero, else the first priced required leaf ("First Half ->
|
|
32
37
|
* ROMA -> Pizza Size -> Large 13"") — see `findRaiseTarget`. Optional/upsell
|
|
@@ -41,20 +46,45 @@ export declare function makeSpaceForFreeOptions(options: IOrderEngineOption[], n
|
|
|
41
46
|
* Returns the item unchanged when no segment option is selected (only
|
|
42
47
|
* re-based when references were provided).
|
|
43
48
|
*/
|
|
44
|
-
export declare function applyChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?:
|
|
45
|
-
originalPriceReferences?: TOrderEnginePriceReferences;
|
|
46
|
-
}): IOrderEngineItem;
|
|
49
|
+
export declare function applyChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?: IChooseExpensiveSegmentPriceOptions): IOrderEngineItem;
|
|
47
50
|
/**
|
|
48
|
-
*
|
|
49
|
-
* option
|
|
50
|
-
*
|
|
51
|
+
* Value `choose_expensive_segment_price` compares and levels: the option price
|
|
52
|
+
* (base + item/option level upsell, merged at conversion) + the prices of its
|
|
53
|
+
* SELECTED required (price-defining) options. Exposed so callers that show a
|
|
54
|
+
* price for a single segment (e.g. the segment customization drawer) use the
|
|
55
|
+
* SAME math.
|
|
51
56
|
*/
|
|
52
|
-
export declare function
|
|
57
|
+
export declare function getOrderEngineOptionSegmentValue(option: IOrderEngineOption): number;
|
|
53
58
|
/**
|
|
54
59
|
* True when the item has a top-level modifier group option that is a nested
|
|
55
60
|
* half-half (ref_type HALF_HALF) with its setup's choose_expensive flag.
|
|
56
61
|
*/
|
|
57
62
|
export declare function hasFlaggedHalfHalfOption(orderEngineItem: IOrderEngineItem): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Half-half selection rule: an item may fill at most `segments - 1` halves —
|
|
65
|
+
* it may never make ALL sides of the half-half (otherwise it is not a half-half
|
|
66
|
+
* anymore). Returns the option PATHS that would complete "all sides" when
|
|
67
|
+
* selected, formatted exactly like `setCheckFieldInOrderEngineItem`
|
|
68
|
+
* identifiers (`seg-2_roma`, `mod-pizza_halfhalf-1_seg-2_milan`), so callers
|
|
69
|
+
* can block, guard and label them.
|
|
70
|
+
*
|
|
71
|
+
* Handles both shapes:
|
|
72
|
+
* - a HALF_HALF item (its top-level groups are the segments — pass
|
|
73
|
+
* `isHalfHalfSegmentItem: false`),
|
|
74
|
+
* - a flagged half-half option nested in a SPECIAL (its own modifier groups
|
|
75
|
+
* are the segments).
|
|
76
|
+
* A drawer opened for a single half-half SEGMENT passes
|
|
77
|
+
* `isHalfHalfSegmentItem: true` so the item's own option groups are never
|
|
78
|
+
* treated as segments.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getBlockedHalfHalfOptionPaths(orderEngineItem: IOrderEngineItem, isHalfHalfSegmentItem?: boolean): Set<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Same half-half selection rule for the MODERN selection list (no engine tree
|
|
83
|
+
* yet): the item ids that cannot be picked for `segmentIndex` because doing so
|
|
84
|
+
* would make them occupy every segment. `segmentIndex` is the segment being
|
|
85
|
+
* picked/edited (its own current item does not count against itself).
|
|
86
|
+
*/
|
|
87
|
+
export declare function getHalfHalfBlockedItemIds(orderItems: (IOrderItem | null)[], segmentIndex: number | null): string[];
|
|
58
88
|
/**
|
|
59
89
|
* `choose_expensive_segment_price` for a half-half option nested in a special:
|
|
60
90
|
* the option's own top-level modifiers are its segment groups, so they get the
|
|
@@ -66,9 +96,20 @@ export declare function hasFlaggedHalfHalfOption(orderEngineItem: IOrderEngineIt
|
|
|
66
96
|
* ONLY inside the flagged half-half subtrees, so the special's own option
|
|
67
97
|
* prices keep whatever the conversion produced.
|
|
68
98
|
*/
|
|
69
|
-
export declare function applyNestedChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?:
|
|
70
|
-
|
|
71
|
-
|
|
99
|
+
export declare function applyNestedChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?: IChooseExpensiveSegmentPriceOptions): IOrderEngineItem;
|
|
100
|
+
/**
|
|
101
|
+
* Levels the item's segment VALUE (item price + required option prices — the
|
|
102
|
+
* value `getOrderEngineOptionSegmentValue` / `applyChooseExpensiveSegmentPrice`
|
|
103
|
+
* compare) UP to `floorPrice`, using the same raise mechanics as the rule: the
|
|
104
|
+
* raise lands on the FIRST PRICED element — the item price when non-zero,
|
|
105
|
+
* otherwise the first priced required leaf, otherwise the item price.
|
|
106
|
+
*
|
|
107
|
+
* Used by the drawer that edits a SINGLE half-half segment: the half-half
|
|
108
|
+
* screen passes the max value of the OTHER selected halves as the floor, so
|
|
109
|
+
* the drawer shows the amount this segment is actually charged once the
|
|
110
|
+
* choose_expensive rule levels it. It never lowers.
|
|
111
|
+
*/
|
|
112
|
+
export declare function applySegmentPriceFloor(orderEngineItem: IOrderEngineItem, floorPrice: number): IOrderEngineItem;
|
|
72
113
|
export type IOrderEngineItemRewardClaim = {
|
|
73
114
|
type: 'offer';
|
|
74
115
|
offerId: string;
|