@managesome/eposmatic-toolkit 0.2.762 → 0.2.763

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.
@@ -1427,6 +1427,8 @@ function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calcu
1427
1427
  // ready_minutes in sync with that transition (mirrors the order status
1428
1428
  // updates): measured from the item's own prep clock, falling back to the
1429
1429
  // order's stage clock. Already-ready items keep their stored duration.
1430
+ // Keep in sync with items-service updateOrderStatus (aggregation pipeline
1431
+ // stamp) and updateOrder (new-item prep stamp).
1430
1432
  let readyMinutes;
1431
1433
  if (item.is_ready !== true && isCompleted) {
1432
1434
  const readyMinutesAnchor = item.prep_started_at ?? data.order_status_updated_at;
@@ -47,7 +47,7 @@ type ISimplifiedSetupWithAvailability = {
47
47
  export declare function isSimplifiedSetupApplicable(setup: ISimplifiedSetupWithAvailability, platform: PLATFORMS_ENUM): boolean;
48
48
  export declare function getPlatformModifierOptions(options: IModifierOption[], platform: PLATFORMS_ENUM, excludeIds?: string[]): IModifierOption[];
49
49
  export declare function getPlatformModifiers(modifiers: IModifier[] | null | undefined, platform: PLATFORMS_ENUM | undefined, excludeIds?: string[]): IModifier[] | null;
50
- export declare function convertItemToWorkableItem<T extends IItem | ISimplifiedCatalogItem>(item: T, platform: PLATFORMS_ENUM, tenantId: string | undefined, omitSchedule?: boolean, omitSchedulePricing?: boolean): T | null;
50
+ export declare function convertItemToWorkableItem<T extends IItem | ISimplifiedCatalogItem>(item: T, platform: PLATFORMS_ENUM, tenantId: string | undefined, omitSchedule?: boolean, omitSchedulePricing?: boolean, omitPlatformCheck?: boolean): T | null;
51
51
  export declare function convertOptionToWorkableOption(option: IModifierOption, platform: PLATFORMS_ENUM): IModifierOption | null;
52
52
  export declare function convertCatalogToWorkableCatalog<T extends ICatalog | ISimplifiedCatalog>(catalogs: T[], platform: PLATFORMS_ENUM | undefined, tenantId: string | undefined): T[];
53
53
  /**
@@ -184,10 +184,13 @@ function getPlatformModifiers(modifiers, platform, excludeIds = []) {
184
184
  return platformModifiers;
185
185
  }
186
186
  // ==========================================================><====================================================
187
- function convertItemToWorkableItem(item, platform, tenantId, omitSchedule, omitSchedulePricing) {
187
+ function convertItemToWorkableItem(item, platform, tenantId, omitSchedule, omitSchedulePricing, omitPlatformCheck) {
188
188
  // if item is not active or it is not included in the current platform, we skip it
189
189
  if (!item.active ||
190
- !item.included_platforms.includes(platform) ||
190
+ // Items resolved INSIDE a setup (specials) pass `omitPlatformCheck`: the
191
+ // setup's own platform membership is that gate, and its items are shown
192
+ // even when they don't belong to the current platform.
193
+ (!omitPlatformCheck && !item.included_platforms.includes(platform)) ||
191
194
  // This condition will only work in POS. This condition is for call center
192
195
  (item.tenants != null && !item.tenants.includes(tenantId))) {
193
196
  return null;
@@ -174,12 +174,18 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
174
174
  }
175
175
  continue;
176
176
  }
177
- const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, omitItemLevelSchedule, true);
177
+ // Constituent items are NOT gated by platform membership (the last
178
+ // `true`): the special's own `included_platforms` is the platform gate,
179
+ // and a deal may legitimately feature items that don't belong to the
180
+ // current platform — they are shown and selectable anyway. Inactive
181
+ // items stay excluded here; when EVERY item of a group is inactive the
182
+ // group resolves empty and blocks the special (see `hasEmptyGroup`).
183
+ const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, omitItemLevelSchedule, true, true);
178
184
  if (!workableItem) {
179
185
  // The item failed ONLY its own schedule: probe without the schedule
180
186
  // check to tell "scheduled out right now" apart from "structurally
181
- // unavailable" (inactive / platform / tenant filtered).
182
- if ((0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, true, true) != null) {
187
+ // unavailable" (inactive / tenant filtered).
188
+ if ((0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, true, true, true) != null) {
183
189
  hasScheduledOutItem = true;
184
190
  }
185
191
  continue;
@@ -202,6 +208,12 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
202
208
  // its items are merely outside their own schedule right now. Item
203
209
  // schedules filter the selectable options at selection time; menu-level
204
210
  // validity is governed by the special's own schedule.
211
+ //
212
+ // With platform membership no longer gating constituent items, a group
213
+ // only ends up here when NONE of its items are usable: they are all
214
+ // INACTIVE (product rule: all-inactive group blocks the deal), missing
215
+ // from the catalog, or belong to another tenant. Out-of-platform items
216
+ // are resolvable and are shown.
205
217
  if (items.length === 0 && !hasHalfHalfRef && !hasScheduledOutItem) {
206
218
  hasEmptyGroup = true;
207
219
  continue;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,240 @@
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
+ // ============================================================================
6
+ // Specials: platform membership of CONSTITUENT items.
7
+ //
8
+ // - The special's own `included_platforms` is the platform gate for the
9
+ // deal. Its items are NOT gated by platform membership: a deal may
10
+ // legitimately feature items that don't belong to the current platform and
11
+ // they are shown and selectable anyway.
12
+ // - INACTIVE items stay excluded. A group whose items are ALL inactive
13
+ // resolves empty and blocks the special (nothing to select); a group with
14
+ // at least one active item keeps the deal, hiding only the inactive ones.
15
+ // - Tenant / schedule checks on the items are unchanged.
16
+ // ============================================================================
17
+ const TENANT_ID = 'tenant-1';
18
+ const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
19
+ const OTHER_PLATFORM = constants_1.PLATFORMS_ENUM.WEB_DELIVERY;
20
+ /**
21
+ * Never-applicable schedule: no days at all, so `findApplicableSchedule`
22
+ * finds no schedule for the current day and returns `false`.
23
+ */
24
+ function makeScheduledOutHours() {
25
+ return [
26
+ {
27
+ days_index: [],
28
+ disabled_outside_date_range: false,
29
+ start_time: 0,
30
+ end_time: 24 * 3600000,
31
+ start_date: null,
32
+ end_date: null,
33
+ price: null,
34
+ is_discount_percentage: false,
35
+ excluded_platforms: [],
36
+ },
37
+ ];
38
+ }
39
+ function makeItem(id, overrides = {}) {
40
+ return {
41
+ _id: id,
42
+ brand_id: 'brand-1',
43
+ tenants: [TENANT_ID],
44
+ category_id: 'pizza-cat',
45
+ included_platforms: [PLATFORM],
46
+ name: `Item ${id}`,
47
+ active: true,
48
+ sold_out: [],
49
+ sort_id: 1,
50
+ image_url: `https://example.com/${id}.jpg`,
51
+ price: { BASE_PRICE: 1000 },
52
+ discount_amount: null,
53
+ is_discount_percentage: false,
54
+ tax_rate: null,
55
+ keywords: [],
56
+ caveats: [],
57
+ dietary_preferences: [],
58
+ hide_name: false,
59
+ description: '',
60
+ ingredients: null,
61
+ is_featured: false,
62
+ featured_sort_id: 0,
63
+ item_special_hours: null,
64
+ display_price: null,
65
+ show_starting_from: false,
66
+ createdAt: new Date('2024-01-01'),
67
+ updatedAt: new Date('2024-01-02'),
68
+ modifiers: null,
69
+ ...overrides,
70
+ };
71
+ }
72
+ function makeModifierSpecial(overrides = {}) {
73
+ return {
74
+ _id: 'mod-pizza',
75
+ name: 'First Pizza',
76
+ sort_id: 1,
77
+ quantity: 1,
78
+ num_free_items: 0,
79
+ excluded_refs: [],
80
+ exclusive_refs: [],
81
+ omit_items_schedule: false,
82
+ items: [{ item_id: 'milan', sort_id: 1, upsell_price: null }],
83
+ ...overrides,
84
+ };
85
+ }
86
+ function makeSpecialWithModifier(overrides = {}) {
87
+ return {
88
+ _id: 'special-1',
89
+ brand_id: 'brand-1',
90
+ tenants: [TENANT_ID],
91
+ category_id: 'combo-cat',
92
+ included_platforms: [PLATFORM],
93
+ name: 'Buy 1 Pizza Get 1 Free',
94
+ description: 'Deal',
95
+ active: true,
96
+ sold_out: [],
97
+ sort_id: 1,
98
+ image_url: 'https://example.com/special.jpg',
99
+ price: { BASE_PRICE: 1500 },
100
+ discount_amount: null,
101
+ is_discount_percentage: false,
102
+ display_price: null,
103
+ show_starting_from: false,
104
+ item_special_hours: null,
105
+ modifier_specials: [makeModifierSpecial()],
106
+ createdAt: new Date('2024-01-01'),
107
+ updatedAt: new Date('2024-01-02'),
108
+ ...overrides,
109
+ };
110
+ }
111
+ describe('specials: constituent items are not gated by platform membership', () => {
112
+ it('shows the special when every item of the group is outside the platform', () => {
113
+ const itemsMap = {
114
+ milan: makeItem('milan', { included_platforms: [OTHER_PLATFORM] }),
115
+ };
116
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
117
+ expect(workable).toBeDefined();
118
+ expect(workable.modifier_specials).toHaveLength(1);
119
+ expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['milan']);
120
+ // The item keeps its own platform membership — it is shown as-is.
121
+ expect(workable.modifier_specials[0].items[0].included_platforms).toEqual([OTHER_PLATFORM]);
122
+ });
123
+ it('shows out-of-platform items alongside in-platform items', () => {
124
+ const itemsMap = {
125
+ milan: makeItem('milan'),
126
+ torent: makeItem('torent', { included_platforms: [OTHER_PLATFORM] }),
127
+ };
128
+ const special = makeSpecialWithModifier({
129
+ modifier_specials: [
130
+ makeModifierSpecial({
131
+ items: [
132
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
133
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
134
+ ],
135
+ }),
136
+ ],
137
+ });
138
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
139
+ expect(workable).toBeDefined();
140
+ expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['milan', 'torent']);
141
+ });
142
+ });
143
+ describe('specials: inactive items still gate the deal', () => {
144
+ it('hides the special when every item of a group is inactive', () => {
145
+ const itemsMap = {
146
+ milan: makeItem('milan', { active: false }),
147
+ torent: makeItem('torent', { active: false }),
148
+ };
149
+ const special = makeSpecialWithModifier({
150
+ modifier_specials: [
151
+ makeModifierSpecial({
152
+ items: [
153
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
154
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
155
+ ],
156
+ }),
157
+ ],
158
+ });
159
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
160
+ expect(workable).toBeUndefined();
161
+ });
162
+ it('hides the special when every item is inactive, regardless of platform membership', () => {
163
+ const itemsMap = {
164
+ milan: makeItem('milan', { active: false }),
165
+ torent: makeItem('torent', { active: false, included_platforms: [OTHER_PLATFORM] }),
166
+ };
167
+ const special = makeSpecialWithModifier({
168
+ modifier_specials: [
169
+ makeModifierSpecial({
170
+ items: [
171
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
172
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
173
+ ],
174
+ }),
175
+ ],
176
+ });
177
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
178
+ expect(workable).toBeUndefined();
179
+ });
180
+ it('keeps the special when only some items are inactive', () => {
181
+ const itemsMap = {
182
+ milan: makeItem('milan', { active: false }),
183
+ torent: makeItem('torent'),
184
+ };
185
+ const special = makeSpecialWithModifier({
186
+ modifier_specials: [
187
+ makeModifierSpecial({
188
+ items: [
189
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
190
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
191
+ ],
192
+ }),
193
+ ],
194
+ });
195
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
196
+ expect(workable).toBeDefined();
197
+ expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['torent']);
198
+ });
199
+ it('keeps the special when an inactive item is mixed with an out-of-platform item', () => {
200
+ const itemsMap = {
201
+ milan: makeItem('milan', { active: false }),
202
+ torent: makeItem('torent', { included_platforms: [OTHER_PLATFORM] }),
203
+ };
204
+ const special = makeSpecialWithModifier({
205
+ modifier_specials: [
206
+ makeModifierSpecial({
207
+ items: [
208
+ { item_id: 'milan', sort_id: 1, upsell_price: null },
209
+ { item_id: 'torent', sort_id: 2, upsell_price: null },
210
+ ],
211
+ }),
212
+ ],
213
+ });
214
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([special], itemsMap, PLATFORM, TENANT_ID);
215
+ expect(workable).toBeDefined();
216
+ expect(workable.modifier_specials[0].items.map((item) => item._id)).toEqual(['torent']);
217
+ });
218
+ });
219
+ describe('specials: tenant and schedule checks on items are unchanged', () => {
220
+ it("hides the special when a group's items all belong to another tenant", () => {
221
+ const itemsMap = {
222
+ milan: makeItem('milan', { tenants: ['other-tenant'] }),
223
+ };
224
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
225
+ expect(workable).toBeUndefined();
226
+ });
227
+ it('still filters scheduled-out out-of-platform items from the options (deal kept)', () => {
228
+ const itemsMap = {
229
+ milan: makeItem('milan', {
230
+ included_platforms: [OTHER_PLATFORM],
231
+ item_special_hours: makeScheduledOutHours(),
232
+ }),
233
+ };
234
+ const [workable] = (0, specials_helpers_1.convertSpecialsToWorkableSpecials)([makeSpecialWithModifier()], itemsMap, PLATFORM, TENANT_ID);
235
+ // The item is outside its own schedule right now -> not selectable, but
236
+ // the special itself stays (its own schedule is the menu-level gate).
237
+ expect(workable).toBeDefined();
238
+ expect(workable.modifier_specials[0].items).toHaveLength(0);
239
+ });
240
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.762",
3
+ "version": "0.2.763",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",