@managesome/eposmatic-toolkit 0.2.647 → 0.2.648

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.
@@ -21,12 +21,7 @@ export declare function getSelectedVendorCatalogs(menus: {
21
21
  _id: string;
22
22
  included_categories: IIncludedCategory[];
23
23
  }[], selectedVendorId: string | null, mappedCatalog: Record<string, IWarehouseCatalog>): IWarehouseCatalog[];
24
- /**
25
- * Group inventory items by category_id for O(1) lookup.
26
- * Mirrors the warehouse's mappedCatalog. Items with a null/undefined
27
- * category_id are stored under the key '' (empty string).
28
- */
29
- export declare function getInventoryMappedItems(inventory: IKitchenInventory[]): Record<string, IKitchenInventory[]>;
24
+ export declare function getInventoryMappedItems(inventory: IKitchenInventory[], categories?: IInventoryCategory[]): Record<string, IKitchenInventory[]>;
30
25
  /**
31
26
  * Filter inventory items by a vendor's included_categories (whitelist).
32
27
  * Mirrors getSelectedCatalogs: iterates only the vendor's assigned
@@ -34,8 +29,13 @@ export declare function getInventoryMappedItems(inventory: IKitchenInventory[]):
34
29
  * and filters out excluded_items per category.
35
30
  *
36
31
  * When includedCategories is empty, returns ALL items (no filter).
32
+ *
33
+ * When `categories` is provided, each included category_id (which a vendor
34
+ * may store as the canonical _id or, for legacy vendors, the ref_id) is
35
+ * resolved to the canonical _id before lookup — matching how
36
+ * getInventoryMappedItems buckets the items.
37
37
  */
38
- export declare function getSelectedVendorInventoryItems(mappedInventory: Record<string, IKitchenInventory[]>, includedCategories: IInventoryIncludedCategory[]): IKitchenInventory[];
38
+ export declare function getSelectedVendorInventoryItems(mappedInventory: Record<string, IKitchenInventory[]>, includedCategories: IInventoryIncludedCategory[], categories?: IInventoryCategory[]): IKitchenInventory[];
39
39
  /**
40
40
  * Group inventory categories with their items, including a synthetic
41
41
  * "Uncategorized" entry for items without a category_id.
@@ -222,19 +222,27 @@ function getSelectedVendorCatalogs(menus, selectedVendorId, mappedCatalog) {
222
222
  // Mirrors getSelectedCatalogs / getSelectedVendorCatalogs but works with flat
223
223
  // IKitchenInventory[] items (inventory utility) instead of IWarehouseCatalog[].
224
224
  // ============================================================================
225
- /**
226
- * Group inventory items by category_id for O(1) lookup.
227
- * Mirrors the warehouse's mappedCatalog. Items with a null/undefined
228
- * category_id are stored under the key '' (empty string).
229
- */
230
- function getInventoryMappedItems(inventory) {
225
+ function getInventoryMappedItems(inventory, categories) {
226
+ // Resolve each synced category's ref_id → canonical _id (only when they
227
+ // differ) so items referencing a category by ref_id land under the same
228
+ // bucket as the canonical _id vendors store.
229
+ const refToId = new Map();
230
+ if (categories) {
231
+ for (let i = 0; i < categories.length; i++) {
232
+ const c = categories[i];
233
+ if (c.ref_id && c._id && c.ref_id !== c._id)
234
+ refToId.set(c.ref_id, c._id);
235
+ }
236
+ }
231
237
  const map = {};
232
238
  for (let i = 0; i < inventory.length; i++) {
233
239
  const item = inventory[i];
234
- const key = item.category_id ?? '';
240
+ const raw = item.category_id ?? '';
241
+ const canonicalId = refToId.get(raw);
242
+ const key = canonicalId ?? raw;
235
243
  if (!map[key])
236
244
  map[key] = [];
237
- map[key].push(item);
245
+ map[key].push(canonicalId ? { ...item, category_id: canonicalId } : item);
238
246
  }
239
247
  return map;
240
248
  }
@@ -245,8 +253,13 @@ function getInventoryMappedItems(inventory) {
245
253
  * and filters out excluded_items per category.
246
254
  *
247
255
  * When includedCategories is empty, returns ALL items (no filter).
256
+ *
257
+ * When `categories` is provided, each included category_id (which a vendor
258
+ * may store as the canonical _id or, for legacy vendors, the ref_id) is
259
+ * resolved to the canonical _id before lookup — matching how
260
+ * getInventoryMappedItems buckets the items.
248
261
  */
249
- function getSelectedVendorInventoryItems(mappedInventory, includedCategories) {
262
+ function getSelectedVendorInventoryItems(mappedInventory, includedCategories, categories) {
250
263
  if (!includedCategories || includedCategories.length === 0) {
251
264
  const all = [];
252
265
  const keys = Object.keys(mappedInventory);
@@ -258,10 +271,21 @@ function getSelectedVendorInventoryItems(mappedInventory, includedCategories) {
258
271
  }
259
272
  return all;
260
273
  }
274
+ // Legacy vendors may store the ref_id instead of the canonical _id, so
275
+ // resolve each included category id the same way before the lookup.
276
+ const refToId = new Map();
277
+ if (categories) {
278
+ for (let i = 0; i < categories.length; i++) {
279
+ const c = categories[i];
280
+ if (c.ref_id && c._id && c.ref_id !== c._id)
281
+ refToId.set(c.ref_id, c._id);
282
+ }
283
+ }
261
284
  const result = [];
262
285
  for (let i = 0; i < includedCategories.length; i++) {
263
286
  const { category_id, excluded_items } = includedCategories[i];
264
- const items = mappedInventory[category_id ?? ''];
287
+ const canonicalCategoryId = refToId.get(category_id ?? '') ?? category_id ?? '';
288
+ const items = mappedInventory[canonicalCategoryId];
265
289
  if (!items)
266
290
  continue;
267
291
  if (excluded_items.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.647",
3
+ "version": "0.2.648",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",