@managesome/eposmatic-toolkit 0.2.708 → 0.2.710

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.
Files changed (33) hide show
  1. package/lib/constants/ENUMS.d.ts +1 -0
  2. package/lib/constants/ENUMS.js +1 -0
  3. package/lib/helpers/types/catalog.d.ts +2 -1
  4. package/lib/helpers/utils/halfhalf-setup-helpers.js +2 -0
  5. package/lib/helpers/utils/minified-catalog.js +2 -0
  6. package/lib/helpers/utils/order-engine.js +3 -0
  7. package/lib/helpers/utils/receipt-engine.js +62 -11
  8. package/lib/helpers/utils/selection-model.d.ts +3 -0
  9. package/lib/helpers/utils/selection-model.js +1 -0
  10. package/lib/helpers/utils/simplified-halfhalf.d.ts +4 -3
  11. package/lib/helpers/utils/simplified-halfhalf.js +8 -6
  12. package/lib/helpers/utils/simplified-specials.d.ts +4 -4
  13. package/lib/helpers/utils/simplified-specials.js +10 -9
  14. package/lib/helpers/utils/specials-helpers.d.ts +3 -3
  15. package/lib/helpers/utils/specials-helpers.js +39 -7
  16. package/lib/schemas/models/items.d.ts +27 -0
  17. package/lib/schemas/models/items.js +7 -0
  18. package/lib/schemas/models/modifier_extras.d.ts +9 -9
  19. package/lib/schemas/models/orders.d.ts +981 -0
  20. package/lib/schemas/models/orders.js +5 -0
  21. package/lib/schemas/models/rewards_usage.d.ts +3 -3
  22. package/lib/schemas/models/tenant_cash_in_out.d.ts +3 -3
  23. package/lib/schemas/models/warehouse_internal_movements.d.ts +3 -3
  24. package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.d.ts +3 -3
  25. package/lib/schemas/types/items.d.ts +2 -1
  26. package/lib/schemas/types/orders.d.ts +2 -1
  27. package/lib/tests/receipt-engine.test.d.ts +1 -0
  28. package/lib/tests/receipt-engine.test.js +204 -0
  29. package/lib/tests/simplified-halfhalf.test.js +4 -4
  30. package/lib/tests/simplified-specials.test.js +6 -6
  31. package/lib/tests/specials-halfhalf-options.test.d.ts +1 -0
  32. package/lib/tests/specials-halfhalf-options.test.js +327 -0
  33. package/package.json +1 -1
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ const specials_helpers_1 = require("../helpers/utils/specials-helpers");
5
+ const TENANT_ID = 'tenant-1';
6
+ function makeItem(id, overrides = {}) {
7
+ return {
8
+ _id: id,
9
+ brand_id: 'brand-1',
10
+ tenants: ['tenant-1'],
11
+ category_id: 'pizza-cat',
12
+ included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
13
+ name: `Item ${id}`,
14
+ active: true,
15
+ sold_out: [],
16
+ sort_id: 1,
17
+ image_url: `https://example.com/${id}.jpg`,
18
+ price: { BASE_PRICE: 1000 },
19
+ discount_amount: null,
20
+ is_discount_percentage: false,
21
+ tax_rate: null,
22
+ keywords: [],
23
+ caveats: [],
24
+ dietary_preferences: [],
25
+ hide_name: false,
26
+ description: '',
27
+ ingredients: null,
28
+ is_featured: false,
29
+ featured_sort_id: 0,
30
+ item_special_hours: null,
31
+ display_price: null,
32
+ show_starting_from: false,
33
+ use_source_ingredients: false,
34
+ createdAt: new Date('2024-01-01'),
35
+ updatedAt: new Date('2024-01-02'),
36
+ modifiers: null,
37
+ ...overrides,
38
+ };
39
+ }
40
+ function makeHalfHalfSetup(overrides = {}) {
41
+ return {
42
+ _id: 'halfhalf-1',
43
+ brand_id: 'brand-1',
44
+ tenants: ['tenant-1'],
45
+ category_id: 'pizza-cat',
46
+ included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
47
+ name: 'Half/Half Pizza Large',
48
+ description: 'Two halves',
49
+ active: true,
50
+ sold_out: [],
51
+ image_url: 'https://example.com/halfhalf.jpg',
52
+ upsell_price: null,
53
+ discount_amount: null,
54
+ is_discount_percentage: false,
55
+ choose_expensive_segment_price: false,
56
+ segments: [
57
+ { _id: 'seg-1', name: 'First Pizza', sort_id: 1 },
58
+ { _id: 'seg-2', name: 'Second Pizza', sort_id: 2 },
59
+ ],
60
+ items: [
61
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
62
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
63
+ ],
64
+ exclusive_refs: [],
65
+ excluded_refs: [],
66
+ item_special_hours: null,
67
+ createdAt: new Date('2024-01-01'),
68
+ updatedAt: new Date('2024-01-02'),
69
+ ...overrides,
70
+ };
71
+ }
72
+ function makeSpecialWithModifier(overrides = {}) {
73
+ return {
74
+ _id: 'special-1',
75
+ brand_id: 'brand-1',
76
+ tenants: ['tenant-1'],
77
+ category_id: 'combo-cat',
78
+ included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
79
+ name: 'Buy 1 Pizza Get 1 Free',
80
+ description: 'Deal',
81
+ active: true,
82
+ sold_out: [],
83
+ sort_id: 1,
84
+ image_url: 'https://example.com/special.jpg',
85
+ price: { BASE_PRICE: 1500 },
86
+ discount_amount: null,
87
+ is_discount_percentage: false,
88
+ display_price: null,
89
+ show_starting_from: false,
90
+ item_special_hours: null,
91
+ modifier_specials: [
92
+ {
93
+ _id: 'mod-pizza',
94
+ name: 'First Pizza',
95
+ sort_id: 1,
96
+ quantity: 1,
97
+ num_free_items: 0,
98
+ excluded_refs: [],
99
+ exclusive_refs: [],
100
+ omit_items_schedule: false,
101
+ items: [
102
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
103
+ { item_id: 'halfhalf-1', sort_id: 2, upsell_price: null },
104
+ ],
105
+ },
106
+ {
107
+ _id: 'mod-drink',
108
+ name: 'Drink',
109
+ sort_id: 2,
110
+ quantity: 1,
111
+ num_free_items: 0,
112
+ excluded_refs: [],
113
+ exclusive_refs: [],
114
+ omit_items_schedule: false,
115
+ items: [{ item_id: 'cola', sort_id: 1, upsell_price: null }],
116
+ },
117
+ ],
118
+ createdAt: new Date('2024-01-01'),
119
+ updatedAt: new Date('2024-01-02'),
120
+ ...overrides,
121
+ };
122
+ }
123
+ describe('convertSpecialToItem with half-half options', () => {
124
+ it('resolves a half-half setup mentioned in modifier_specials into a nested option', () => {
125
+ const itemsMap = {
126
+ milan: makeItem('milan'),
127
+ torent: makeItem('torent'),
128
+ cola: makeItem('cola'),
129
+ };
130
+ const halfhalfMap = {
131
+ 'halfhalf-1': makeHalfHalfSetup(),
132
+ };
133
+ const item = (0, specials_helpers_1.convertSpecialToItem)(makeSpecialWithModifier(), itemsMap, halfhalfMap);
134
+ expect(item).not.toBeNull();
135
+ expect(item.modifiers).toHaveLength(2);
136
+ const pizzaModifier = item.modifiers[0];
137
+ expect(pizzaModifier.options).toHaveLength(2);
138
+ // Normal item option -> ITEM; half-half option -> HALF_HALF.
139
+ const milanOption = pizzaModifier.options.find((option) => option._id === 'milan');
140
+ expect(milanOption?.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM);
141
+ // Second option is the half-half: its _id is the setup id and it carries
142
+ // the per-segment modifiers as nested modifiers.
143
+ const halfHalfOption = pizzaModifier.options.find((option) => option._id === 'halfhalf-1');
144
+ expect(halfHalfOption).toBeDefined();
145
+ expect(halfHalfOption.name).toBe('Half/Half Pizza Large');
146
+ expect(halfHalfOption.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF);
147
+ // Segment modifiers (one single-select per segment); their options are
148
+ // real items -> ITEM.
149
+ const segmentModifiers = halfHalfOption.modifiers ?? [];
150
+ expect(segmentModifiers).toHaveLength(2);
151
+ expect(segmentModifiers[0].options).toHaveLength(2);
152
+ expect(segmentModifiers[0].options[0].ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM);
153
+ const drinkModifier = item.modifiers[1];
154
+ expect(drinkModifier.name).toBe('Drink');
155
+ expect(drinkModifier.options.map((o) => o._id)).toEqual(['cola']);
156
+ });
157
+ it('keeps the special invalid when the half-half cannot be converted', () => {
158
+ const itemsMap = {
159
+ cola: makeItem('cola'),
160
+ };
161
+ // half-half-1 has no resolvable segment items -> convertHalfHalfToItem null
162
+ const halfhalfMap = {
163
+ 'halfhalf-1': makeHalfHalfSetup(),
164
+ };
165
+ const special = makeSpecialWithModifier({
166
+ modifier_specials: [
167
+ {
168
+ _id: 'mod-pizza',
169
+ name: 'First Pizza',
170
+ sort_id: 1,
171
+ quantity: 1,
172
+ num_free_items: 0,
173
+ excluded_refs: [],
174
+ exclusive_refs: [],
175
+ omit_items_schedule: false,
176
+ items: [{ item_id: 'halfhalf-1', sort_id: 1, upsell_price: null }],
177
+ },
178
+ ],
179
+ });
180
+ expect((0, specials_helpers_1.convertSpecialToItem)(special, itemsMap, halfhalfMap)).toBeNull();
181
+ });
182
+ });
183
+ describe('convertSpecialItemToOrderItem with ref_type', () => {
184
+ it('marks option ref_type for item and half-half selections', () => {
185
+ const workableSpecial = {
186
+ _id: 'special-1',
187
+ name: 'Buy 1 Pizza Get 1 Free',
188
+ description: 'Deal',
189
+ sold_out: [],
190
+ image_url: 'https://example.com/special.jpg',
191
+ category_id: 'combo-cat',
192
+ price: { BASE_PRICE: 1500 },
193
+ discount_amount: null,
194
+ is_discount_percentage: false,
195
+ display_price: null,
196
+ show_starting_from: false,
197
+ modifier_specials: [
198
+ {
199
+ _id: 'mod-pizza',
200
+ name: 'First Pizza',
201
+ quantity: 1,
202
+ num_free_items: 0,
203
+ items: [],
204
+ exclusive_refs: [],
205
+ excluded_refs: [],
206
+ },
207
+ {
208
+ _id: 'mod-drink',
209
+ name: 'Drink',
210
+ quantity: 1,
211
+ num_free_items: 0,
212
+ items: [],
213
+ exclusive_refs: [],
214
+ excluded_refs: [],
215
+ },
216
+ ],
217
+ };
218
+ const modifierSpecials = [
219
+ {
220
+ _id: 'mod-pizza',
221
+ selectedItems: [
222
+ {
223
+ item_id: 'milan',
224
+ item_type: 'SPECIAL',
225
+ name: 'Milan',
226
+ price: 0,
227
+ quantity: 1,
228
+ modifiers: null,
229
+ menu_id: 'menu-1',
230
+ },
231
+ ],
232
+ },
233
+ {
234
+ _id: 'mod-drink',
235
+ selectedItems: [
236
+ {
237
+ item_id: 'halfhalf-1',
238
+ item_type: 'HALF_HALF',
239
+ name: 'Half/Half Pizza Large',
240
+ price: 0,
241
+ quantity: 1,
242
+ modifiers: null,
243
+ menu_id: 'menu-1',
244
+ },
245
+ ],
246
+ },
247
+ ];
248
+ const converted = (0, specials_helpers_1.convertSpecialItemToOrderItem)({
249
+ specialItem: workableSpecial,
250
+ modifierSpecials: modifierSpecials,
251
+ quantity: 1,
252
+ platform: constants_1.PLATFORMS_ENUM.POS_WALK_IN,
253
+ });
254
+ expect(converted.modifiers).not.toBeNull();
255
+ const pizzaGroup = converted.modifiers.find((m) => m.ref === 'mod-pizza');
256
+ const drinkGroup = converted.modifiers.find((m) => m.ref === 'mod-drink');
257
+ expect(pizzaGroup?.options[0].ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM);
258
+ expect(drinkGroup?.options[0].ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF);
259
+ });
260
+ });
261
+ describe('convertSpecialsToWorkableSpecials with half-half references', () => {
262
+ it('keeps a modifier group selectable when it only references half-half setups', () => {
263
+ const itemsMap = {
264
+ milan: makeItem('milan'),
265
+ torent: makeItem('torent'),
266
+ cola: makeItem('cola'),
267
+ };
268
+ const halfhalfMap = {
269
+ 'halfhalf-1': makeHalfHalfSetup(),
270
+ };
271
+ const special = makeSpecialWithModifier({
272
+ modifier_specials: [
273
+ {
274
+ _id: 'mod-pizza',
275
+ name: 'First Pizza',
276
+ sort_id: 1,
277
+ quantity: 1,
278
+ num_free_items: 0,
279
+ excluded_refs: [],
280
+ exclusive_refs: [],
281
+ omit_items_schedule: false,
282
+ items: [{ item_id: 'halfhalf-1', sort_id: 1, upsell_price: null }],
283
+ },
284
+ {
285
+ _id: 'mod-drink',
286
+ name: 'Drink',
287
+ sort_id: 2,
288
+ quantity: 1,
289
+ num_free_items: 0,
290
+ excluded_refs: [],
291
+ exclusive_refs: [],
292
+ omit_items_schedule: false,
293
+ items: [{ item_id: 'cola', sort_id: 1, upsell_price: null }],
294
+ },
295
+ ],
296
+ });
297
+ const workable = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, constants_1.PLATFORMS_ENUM.POS_WALK_IN, TENANT_ID, halfhalfMap);
298
+ expect(workable).toHaveLength(1);
299
+ const firstPizza = workable[0].modifier_specials.find((m) => m._id === 'mod-pizza');
300
+ expect(firstPizza).toBeDefined();
301
+ // Half-half refs are not materialized as regular items, but the group is
302
+ // selectable (not marked empty).
303
+ expect(firstPizza.items).toHaveLength(0);
304
+ });
305
+ it('still drops the special when a group has no resolvable items at all', () => {
306
+ const itemsMap = {
307
+ cola: makeItem('cola'),
308
+ };
309
+ const special = makeSpecialWithModifier({
310
+ modifier_specials: [
311
+ {
312
+ _id: 'mod-pizza',
313
+ name: 'First Pizza',
314
+ sort_id: 1,
315
+ quantity: 1,
316
+ num_free_items: 0,
317
+ excluded_refs: [],
318
+ exclusive_refs: [],
319
+ omit_items_schedule: false,
320
+ items: [{ item_id: 'missing-item', sort_id: 1, upsell_price: null }],
321
+ },
322
+ ],
323
+ });
324
+ const workable = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, constants_1.PLATFORMS_ENUM.POS_WALK_IN, TENANT_ID, {});
325
+ expect(workable).toHaveLength(0);
326
+ });
327
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.708",
3
+ "version": "0.2.710",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",