@managesome/eposmatic-toolkit 0.2.647 → 0.2.649

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.
@@ -34,6 +34,7 @@ export declare const WORKER_ENDPOINTS: {
34
34
  readonly SYNC_SWITCHPAY_PAYMENT_SUCCESS: "/sync-switchpay-payment-success";
35
35
  readonly SYNC_SWITCHPAY_PAYMENT_STATUS: "/sync-switchpay-payment-status";
36
36
  readonly SYNC_ASAANBILL_PAYMENT_STATUS: "/sync-asaanbill-payment-status";
37
+ readonly REGEN_ASAANBILL_DQRC_AMOUNT: "/regen-asaanbill-dqrc-amount";
37
38
  readonly PROCESS_STRIPE_PAYMENT_POLLING: "/process-stripe-payment-polling";
38
39
  readonly SYNC_STRIPE_PAYMENT_SUCCESS: "/sync-stripe-payment-success";
39
40
  readonly UPDATE_ORDER_STATUS_ON_DELIVERY_STATUS_UPDATE: "/update-order-status-on-delivery-status-update";
@@ -42,6 +42,7 @@ exports.WORKER_ENDPOINTS = {
42
42
  SYNC_SWITCHPAY_PAYMENT_STATUS: '/sync-switchpay-payment-status',
43
43
  // ========================>> Payment (AsaanBill) <<======================= //
44
44
  SYNC_ASAANBILL_PAYMENT_STATUS: '/sync-asaanbill-payment-status',
45
+ REGEN_ASAANBILL_DQRC_AMOUNT: '/regen-asaanbill-dqrc-amount',
45
46
  // ========================>> Payment (Stripe) <<======================= //
46
47
  PROCESS_STRIPE_PAYMENT_POLLING: '/process-stripe-payment-polling',
47
48
  SYNC_STRIPE_PAYMENT_SUCCESS: '/sync-stripe-payment-success',
@@ -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) {
@@ -228,6 +228,30 @@ export interface IWorker_SyncAsaanBillPaymentStatus {
228
228
  account_title?: string;
229
229
  iban?: string;
230
230
  }
231
+ /**
232
+ * Regenerates a pending RAAST (AsaanBill DQRC) payment for a NEW amount.
233
+ *
234
+ * AsaanBill has no update-amount API — updating means re-adding with the SAME
235
+ * identifier (`order_payment:<order_id>:<payment_id>`, stable because
236
+ * payment_id is unchanged), which DISCARDs the previous unpaid QR and returns a
237
+ * fresh id/psid/qrString. The worker patches the new amount + QR onto the same
238
+ * payment row and emits an updated-order event so the POS refreshes in realtime.
239
+ */
240
+ export interface IWorker_RegenAsaanBillDqrcAmount {
241
+ order_id: string;
242
+ tenant_id: string;
243
+ /** The order payment row _id — keeps the AsaanBill identifier stable across regens. */
244
+ payment_id: string;
245
+ /** RAAST terminal register_id used for AsaanBill auth + /add. */
246
+ register_id: string;
247
+ /** New QR amount in cents (unpaid remainder). */
248
+ amount_due: number;
249
+ /** Tenant display name used in the AsaanBill payment title/description. */
250
+ tenant_name: string;
251
+ order_number?: number | null;
252
+ longitude?: number;
253
+ latitude?: number;
254
+ }
231
255
  export interface IWorker_UpdateTenantInventoryOnCreateOrder {
232
256
  order: IOrder;
233
257
  isInventoryEnabled: boolean;
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.649",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",