@react-pakistan/util-functions 1.25.39 → 1.25.41

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,10 +21,6 @@ export declare enum QUOTE_STATUS {
21
21
  ACCEPTED = "ACCEPTED",
22
22
  DECLINED = "DECLINED"
23
23
  }
24
- export declare enum QUOTE_INVOICE_MODE {
25
- CUSTOMER = "CUSTOMER",
26
- COMPANY = "COMPANY"
27
- }
28
24
  export declare enum PAYMENT_TYPE {
29
25
  FULL_AMOUNT = "FULL_AMOUNT",
30
26
  PARTIAL_AMOUNT = "PARTIAL_AMOUNT"
@@ -70,6 +66,52 @@ export declare enum LS_KEYS {
70
66
  PRODUCTS = "stellar_products_cache",
71
67
  TAXES = "stellar_taxes_cache"
72
68
  }
69
+ export declare enum POS_ORDER_STATUS {
70
+ OPEN = "OPEN",
71
+ CLOSED = "CLOSED",
72
+ CANCELLED = "CANCELLED",
73
+ REFUNDED = "REFUNDED"
74
+ }
75
+ export declare enum POS_PAYMENT_STATUS {
76
+ PENDING = "PENDING",
77
+ PAID = "PAID",
78
+ FAILED = "FAILED",
79
+ REFUNDED = "REFUNDED"
80
+ }
81
+ export declare enum POS_PAYMENT_METHOD_TYPE {
82
+ CASH = "CASH",
83
+ CARD = "CARD",
84
+ GIFT_CARD = "GIFT_CARD",
85
+ MOBILE_WALLET = "MOBILE_WALLET",
86
+ OTHER = "OTHER"
87
+ }
88
+ export declare enum POS_REGISTER_STATUS {
89
+ ACTIVE = "ACTIVE",
90
+ INACTIVE = "INACTIVE"
91
+ }
92
+ export declare enum POS_TAX_TYPE {
93
+ EXCLUSIVE = "EXCLUSIVE",
94
+ INCLUSIVE = "INCLUSIVE"
95
+ }
96
+ export declare enum POS_TABLE_STATUS {
97
+ AVAILABLE = "AVAILABLE",
98
+ OCCUPIED = "OCCUPIED",
99
+ RESERVED = "RESERVED"
100
+ }
101
+ export declare enum POS_RESERVATION_STATUS {
102
+ PENDING = "PENDING",
103
+ CONFIRMED = "CONFIRMED",
104
+ CANCELLED = "CANCELLED",
105
+ COMPLETED = "COMPLETED"
106
+ }
107
+ export declare enum POS_SHIFT_STATUS {
108
+ OPEN = "OPEN",
109
+ CLOSED = "CLOSED"
110
+ }
111
+ export declare enum POS_DISCOUNT_TYPE {
112
+ FIXED = "FIXED",
113
+ PERCENTAGE = "PERCENTAGE"
114
+ }
73
115
  /**
74
116
  * Base entity interface with common audit fields and meta support
75
117
  */
@@ -323,3 +365,132 @@ export interface QuotesInvoicesOnStellarProducts {
323
365
  quantity: number;
324
366
  quoteInvoiceId: string;
325
367
  }
368
+ export interface POSStoreBE extends BaseEntity {
369
+ name: string;
370
+ code?: string;
371
+ address?: string;
372
+ phone?: string;
373
+ email?: string;
374
+ currency: string;
375
+ meta?: any;
376
+ enabled: boolean;
377
+ }
378
+ export interface POSRegisterBE extends BaseEntity {
379
+ name: string;
380
+ storeId: string;
381
+ status: POS_REGISTER_STATUS;
382
+ meta?: any;
383
+ }
384
+ export interface POSShiftBE extends BaseEntity {
385
+ registerId: string;
386
+ openedByUserId?: string;
387
+ openedAt: Date;
388
+ closedAt?: Date;
389
+ openingAmount: number;
390
+ closingAmount?: number;
391
+ status: POS_SHIFT_STATUS;
392
+ meta?: any;
393
+ }
394
+ export interface POSCategoryBE extends BaseEntity {
395
+ name: string;
396
+ description?: string;
397
+ storeId: string;
398
+ parentId?: string;
399
+ meta?: any;
400
+ }
401
+ export interface POSProductBE extends BaseEntity {
402
+ sku?: string;
403
+ name: string;
404
+ description?: string;
405
+ price: number;
406
+ cost?: number;
407
+ stock: number;
408
+ storeId: string;
409
+ categoryId?: string;
410
+ meta?: any;
411
+ }
412
+ export interface POSProductVariantBE extends BaseEntity {
413
+ productId: string;
414
+ name: string;
415
+ sku?: string;
416
+ price: number;
417
+ stock: number;
418
+ meta?: any;
419
+ }
420
+ export interface POSCustomerBE extends BaseEntity {
421
+ name: string;
422
+ email?: string;
423
+ phone?: string;
424
+ storeId: string;
425
+ loyaltyPoints: number;
426
+ meta?: any;
427
+ }
428
+ export interface POSTableBE extends BaseEntity {
429
+ storeId: string;
430
+ name: string;
431
+ seats: number;
432
+ status: POS_TABLE_STATUS;
433
+ meta?: any;
434
+ }
435
+ export interface POSReservationBE extends BaseEntity {
436
+ tableId: string;
437
+ customerId: string;
438
+ startAt: Date;
439
+ endAt: Date;
440
+ partySize: number;
441
+ status: POS_RESERVATION_STATUS;
442
+ meta?: any;
443
+ }
444
+ export interface POSOrderBE extends BaseEntity {
445
+ orderNumber: string;
446
+ storeId: string;
447
+ registerId?: string;
448
+ customerId?: string;
449
+ tableId?: string;
450
+ status: POS_ORDER_STATUS;
451
+ paymentStatus: POS_PAYMENT_STATUS;
452
+ subTotal: number;
453
+ taxTotal: number;
454
+ discountTotal: number;
455
+ serviceCharge: number;
456
+ total: number;
457
+ note?: string;
458
+ meta?: any;
459
+ }
460
+ export interface POSOrderItemBE extends BaseEntity {
461
+ orderId: string;
462
+ productId?: string;
463
+ variantId?: string;
464
+ name: string;
465
+ quantity: number;
466
+ unitPrice: number;
467
+ total: number;
468
+ taxAmount: number;
469
+ discountAmount: number;
470
+ meta?: any;
471
+ }
472
+ export interface POSPaymentBE extends BaseEntity {
473
+ orderId: string;
474
+ amount: number;
475
+ method: POS_PAYMENT_METHOD_TYPE;
476
+ methodLabel?: string;
477
+ status: POS_PAYMENT_STATUS;
478
+ transactionRef?: string;
479
+ processedAt?: Date;
480
+ meta?: any;
481
+ }
482
+ export interface POSTaxBE extends BaseEntity {
483
+ name: string;
484
+ rate: number;
485
+ type: POS_TAX_TYPE;
486
+ isDefault: boolean;
487
+ storeId: string;
488
+ meta?: any;
489
+ }
490
+ export interface POSDiscountBE extends BaseEntity {
491
+ name: string;
492
+ type: POS_DISCOUNT_TYPE;
493
+ value: number;
494
+ storeId: string;
495
+ meta?: any;
496
+ }
@@ -3,7 +3,7 @@
3
3
  // ENUMS
4
4
  // ============================================================================
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LS_KEYS = exports.LEAD_STATUS = exports.LEAD_TYPE = exports.LEAD_SOURCE = exports.PAYMENT_TYPE = exports.QUOTE_INVOICE_MODE = exports.QUOTE_STATUS = exports.INVOICE_STATUS = exports.DISCOUNT_UNIT = exports.QUOTE_INVOICE_CATEGORY = exports.GENDER = void 0;
6
+ exports.POS_DISCOUNT_TYPE = exports.POS_SHIFT_STATUS = exports.POS_RESERVATION_STATUS = exports.POS_TABLE_STATUS = exports.POS_TAX_TYPE = exports.POS_REGISTER_STATUS = exports.POS_PAYMENT_METHOD_TYPE = exports.POS_PAYMENT_STATUS = exports.POS_ORDER_STATUS = exports.LS_KEYS = exports.LEAD_STATUS = exports.LEAD_TYPE = exports.LEAD_SOURCE = exports.PAYMENT_TYPE = exports.QUOTE_STATUS = exports.INVOICE_STATUS = exports.DISCOUNT_UNIT = exports.QUOTE_INVOICE_CATEGORY = exports.GENDER = void 0;
7
7
  var GENDER;
8
8
  (function (GENDER) {
9
9
  GENDER["MALE"] = "MALE";
@@ -32,11 +32,6 @@ var QUOTE_STATUS;
32
32
  QUOTE_STATUS["ACCEPTED"] = "ACCEPTED";
33
33
  QUOTE_STATUS["DECLINED"] = "DECLINED";
34
34
  })(QUOTE_STATUS || (exports.QUOTE_STATUS = QUOTE_STATUS = {}));
35
- var QUOTE_INVOICE_MODE;
36
- (function (QUOTE_INVOICE_MODE) {
37
- QUOTE_INVOICE_MODE["CUSTOMER"] = "CUSTOMER";
38
- QUOTE_INVOICE_MODE["COMPANY"] = "COMPANY";
39
- })(QUOTE_INVOICE_MODE || (exports.QUOTE_INVOICE_MODE = QUOTE_INVOICE_MODE = {}));
40
35
  var PAYMENT_TYPE;
41
36
  (function (PAYMENT_TYPE) {
42
37
  PAYMENT_TYPE["FULL_AMOUNT"] = "FULL_AMOUNT";
@@ -87,3 +82,61 @@ var LS_KEYS;
87
82
  LS_KEYS["PRODUCTS"] = "stellar_products_cache";
88
83
  LS_KEYS["TAXES"] = "stellar_taxes_cache";
89
84
  })(LS_KEYS || (exports.LS_KEYS = LS_KEYS = {}));
85
+ // ============================================================================
86
+ // POS ENUMS
87
+ // ============================================================================
88
+ var POS_ORDER_STATUS;
89
+ (function (POS_ORDER_STATUS) {
90
+ POS_ORDER_STATUS["OPEN"] = "OPEN";
91
+ POS_ORDER_STATUS["CLOSED"] = "CLOSED";
92
+ POS_ORDER_STATUS["CANCELLED"] = "CANCELLED";
93
+ POS_ORDER_STATUS["REFUNDED"] = "REFUNDED";
94
+ })(POS_ORDER_STATUS || (exports.POS_ORDER_STATUS = POS_ORDER_STATUS = {}));
95
+ var POS_PAYMENT_STATUS;
96
+ (function (POS_PAYMENT_STATUS) {
97
+ POS_PAYMENT_STATUS["PENDING"] = "PENDING";
98
+ POS_PAYMENT_STATUS["PAID"] = "PAID";
99
+ POS_PAYMENT_STATUS["FAILED"] = "FAILED";
100
+ POS_PAYMENT_STATUS["REFUNDED"] = "REFUNDED";
101
+ })(POS_PAYMENT_STATUS || (exports.POS_PAYMENT_STATUS = POS_PAYMENT_STATUS = {}));
102
+ var POS_PAYMENT_METHOD_TYPE;
103
+ (function (POS_PAYMENT_METHOD_TYPE) {
104
+ POS_PAYMENT_METHOD_TYPE["CASH"] = "CASH";
105
+ POS_PAYMENT_METHOD_TYPE["CARD"] = "CARD";
106
+ POS_PAYMENT_METHOD_TYPE["GIFT_CARD"] = "GIFT_CARD";
107
+ POS_PAYMENT_METHOD_TYPE["MOBILE_WALLET"] = "MOBILE_WALLET";
108
+ POS_PAYMENT_METHOD_TYPE["OTHER"] = "OTHER";
109
+ })(POS_PAYMENT_METHOD_TYPE || (exports.POS_PAYMENT_METHOD_TYPE = POS_PAYMENT_METHOD_TYPE = {}));
110
+ var POS_REGISTER_STATUS;
111
+ (function (POS_REGISTER_STATUS) {
112
+ POS_REGISTER_STATUS["ACTIVE"] = "ACTIVE";
113
+ POS_REGISTER_STATUS["INACTIVE"] = "INACTIVE";
114
+ })(POS_REGISTER_STATUS || (exports.POS_REGISTER_STATUS = POS_REGISTER_STATUS = {}));
115
+ var POS_TAX_TYPE;
116
+ (function (POS_TAX_TYPE) {
117
+ POS_TAX_TYPE["EXCLUSIVE"] = "EXCLUSIVE";
118
+ POS_TAX_TYPE["INCLUSIVE"] = "INCLUSIVE";
119
+ })(POS_TAX_TYPE || (exports.POS_TAX_TYPE = POS_TAX_TYPE = {}));
120
+ var POS_TABLE_STATUS;
121
+ (function (POS_TABLE_STATUS) {
122
+ POS_TABLE_STATUS["AVAILABLE"] = "AVAILABLE";
123
+ POS_TABLE_STATUS["OCCUPIED"] = "OCCUPIED";
124
+ POS_TABLE_STATUS["RESERVED"] = "RESERVED";
125
+ })(POS_TABLE_STATUS || (exports.POS_TABLE_STATUS = POS_TABLE_STATUS = {}));
126
+ var POS_RESERVATION_STATUS;
127
+ (function (POS_RESERVATION_STATUS) {
128
+ POS_RESERVATION_STATUS["PENDING"] = "PENDING";
129
+ POS_RESERVATION_STATUS["CONFIRMED"] = "CONFIRMED";
130
+ POS_RESERVATION_STATUS["CANCELLED"] = "CANCELLED";
131
+ POS_RESERVATION_STATUS["COMPLETED"] = "COMPLETED";
132
+ })(POS_RESERVATION_STATUS || (exports.POS_RESERVATION_STATUS = POS_RESERVATION_STATUS = {}));
133
+ var POS_SHIFT_STATUS;
134
+ (function (POS_SHIFT_STATUS) {
135
+ POS_SHIFT_STATUS["OPEN"] = "OPEN";
136
+ POS_SHIFT_STATUS["CLOSED"] = "CLOSED";
137
+ })(POS_SHIFT_STATUS || (exports.POS_SHIFT_STATUS = POS_SHIFT_STATUS = {}));
138
+ var POS_DISCOUNT_TYPE;
139
+ (function (POS_DISCOUNT_TYPE) {
140
+ POS_DISCOUNT_TYPE["FIXED"] = "FIXED";
141
+ POS_DISCOUNT_TYPE["PERCENTAGE"] = "PERCENTAGE";
142
+ })(POS_DISCOUNT_TYPE || (exports.POS_DISCOUNT_TYPE = POS_DISCOUNT_TYPE = {}));
@@ -1,11 +1,13 @@
1
1
  import { API_METHODS } from '../constants/api-methods';
2
+ export type FetchDataParamValue = string | number | boolean | null | undefined;
2
3
  export interface FetchDataParams {
3
4
  url: string;
4
5
  method?: API_METHODS;
5
6
  body?: string;
6
7
  headers?: Record<string, string>;
8
+ params?: Record<string, FetchDataParamValue>;
7
9
  }
8
- export declare const fetchData: ({ url, method, body, headers, }: FetchDataParams) => Promise<{
10
+ export declare const fetchData: ({ url, method, body, headers, params, }: FetchDataParams) => Promise<{
9
11
  data: any | undefined;
10
12
  error: Error | undefined;
11
13
  }>;
@@ -49,14 +49,29 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.fetchData = void 0;
51
51
  var api_methods_1 = require("../constants/api-methods");
52
+ var buildUrl = function (url, params) {
53
+ if (!params)
54
+ return url;
55
+ var filteredEntries = Object.entries(params).filter(function (entry) {
56
+ return entry[1] !== null && entry[1] !== undefined;
57
+ });
58
+ if (filteredEntries.length === 0)
59
+ return url;
60
+ var searchParams = new URLSearchParams(filteredEntries.map(function (_a) {
61
+ var key = _a[0], value = _a[1];
62
+ return [key, String(value)];
63
+ }));
64
+ var separator = url.includes('?') ? '&' : '?';
65
+ return "".concat(url).concat(separator).concat(searchParams.toString());
66
+ };
52
67
  var fetchData = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
53
68
  var data, error, res, err_1;
54
- var url = _b.url, _c = _b.method, method = _c === void 0 ? api_methods_1.API_METHODS.GET : _c, body = _b.body, headers = _b.headers;
69
+ var url = _b.url, _c = _b.method, method = _c === void 0 ? api_methods_1.API_METHODS.GET : _c, body = _b.body, headers = _b.headers, params = _b.params;
55
70
  return __generator(this, function (_d) {
56
71
  switch (_d.label) {
57
72
  case 0:
58
73
  _d.trys.push([0, 3, , 4]);
59
- return [4 /*yield*/, fetch(url, __assign(__assign({ method: method }, (headers ? { headers: headers } : {})), (method !== api_methods_1.API_METHODS.GET && body && { body: body })))];
74
+ return [4 /*yield*/, fetch(buildUrl(url, params), __assign(__assign({ method: method }, (headers ? { headers: headers } : {})), (method !== api_methods_1.API_METHODS.GET && body && { body: body })))];
60
75
  case 1:
61
76
  res = _d.sent();
62
77
  return [4 /*yield*/, res.json()];
@@ -132,6 +132,27 @@ export declare const getCachedSingleItemSync: <T>(cacheKey: string, expirationMs
132
132
  * const workspace = await getCachedSingleItem<WorkspaceBE>(config, { subdomain: 'school1' });
133
133
  */
134
134
  export declare const getCachedSingleItem: <T>(config: CacheConfig, params?: Record<string, string>, headers?: Record<string, string>) => Promise<T | null>;
135
+ /**
136
+ * Get cached data but fall back to the API when sync cache is empty.
137
+ *
138
+ * This helper first performs a quick synchronous cache check via
139
+ * `getCachedDataSync`. If that returns an empty result it will call
140
+ * the async `getCachedData` to fetch fresh data from the API and return
141
+ * the result. Use this when callers want a fast-path cache read but also
142
+ * need the ability to recall the API transparently when cache is missing.
143
+ */
144
+ export declare const getCachedDataWithFallback: <T>(config: CacheConfig, params?: Record<string, unknown>, headers?: Record<string, string>) => Promise<ListResponse<T>>;
145
+ /**
146
+ * Async variant to get a single item by ID with API fallback.
147
+ *
148
+ * Unlike `getCachedItemById` (sync), this function will call the API
149
+ * (via `getCachedDataWithFallback`) when the item is not available in
150
+ * the local cache. Requires a full `CacheConfig` so the API URL is
151
+ * available for fetching.
152
+ */
153
+ export declare const getCachedItemByIdAsync: <T extends {
154
+ id: string;
155
+ }>(config: CacheConfig, itemId: string, params?: Record<string, unknown>, headers?: Record<string, string>) => Promise<T | null>;
135
156
  /**
136
157
  * Invalidate (remove) cache for a module
137
158
  * Useful after create/update/delete operations
@@ -72,7 +72,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
72
72
  }
73
73
  };
74
74
  Object.defineProperty(exports, "__esModule", { value: true });
75
- exports.isCacheStale = exports.preloadCache = exports.invalidateCache = exports.getCachedSingleItem = exports.getCachedSingleItemSync = exports.getCachedItemById = exports.getCachedData = exports.getCachedDataSync = void 0;
75
+ exports.isCacheStale = exports.preloadCache = exports.invalidateCache = exports.getCachedItemByIdAsync = exports.getCachedDataWithFallback = exports.getCachedSingleItem = exports.getCachedSingleItemSync = exports.getCachedItemById = exports.getCachedData = exports.getCachedDataSync = void 0;
76
76
  var constants_1 = require("../constants");
77
77
  var fetch_data_1 = require("./fetch-data");
78
78
  var local_storage_1 = require("../local-storage");
@@ -508,6 +508,86 @@ var getCachedSingleItem = function (config, params, headers) { return __awaiter(
508
508
  });
509
509
  }); };
510
510
  exports.getCachedSingleItem = getCachedSingleItem;
511
+ /**
512
+ * Get cached data but fall back to the API when sync cache is empty.
513
+ *
514
+ * This helper first performs a quick synchronous cache check via
515
+ * `getCachedDataSync`. If that returns an empty result it will call
516
+ * the async `getCachedData` to fetch fresh data from the API and return
517
+ * the result. Use this when callers want a fast-path cache read but also
518
+ * need the ability to recall the API transparently when cache is missing.
519
+ */
520
+ var getCachedDataWithFallback = function (config, params, headers) { return __awaiter(void 0, void 0, void 0, function () {
521
+ var expirationMs, sync, error_3;
522
+ var _a;
523
+ return __generator(this, function (_b) {
524
+ switch (_b.label) {
525
+ case 0:
526
+ expirationMs = (_a = config.expirationMs) !== null && _a !== void 0 ? _a : constants_1.ONE_DAY_IN_MS;
527
+ _b.label = 1;
528
+ case 1:
529
+ _b.trys.push([1, 3, , 4]);
530
+ sync = (0, exports.getCachedDataSync)(config.cacheKey, expirationMs);
531
+ if (sync &&
532
+ sync.count > 0 &&
533
+ Array.isArray(sync.items) &&
534
+ sync.items.length > 0) {
535
+ return [2 /*return*/, sync];
536
+ }
537
+ return [4 /*yield*/, (0, exports.getCachedData)({ config: config, params: params, headers: headers })];
538
+ case 2:
539
+ // Sync cache empty — fetch from API and return result
540
+ return [2 /*return*/, _b.sent()];
541
+ case 3:
542
+ error_3 = _b.sent();
543
+ console.error("Error in getCachedDataWithFallback for ".concat(config.cacheKey, ":"), error_3);
544
+ return [2 /*return*/, { count: 0, items: [] }];
545
+ case 4: return [2 /*return*/];
546
+ }
547
+ });
548
+ }); };
549
+ exports.getCachedDataWithFallback = getCachedDataWithFallback;
550
+ /**
551
+ * Async variant to get a single item by ID with API fallback.
552
+ *
553
+ * Unlike `getCachedItemById` (sync), this function will call the API
554
+ * (via `getCachedDataWithFallback`) when the item is not available in
555
+ * the local cache. Requires a full `CacheConfig` so the API URL is
556
+ * available for fetching.
557
+ */
558
+ var getCachedItemByIdAsync = function (config, itemId, params, headers) { return __awaiter(void 0, void 0, void 0, function () {
559
+ var raw, found, list, error_4;
560
+ return __generator(this, function (_a) {
561
+ switch (_a.label) {
562
+ case 0:
563
+ if (!itemId)
564
+ return [2 /*return*/, null];
565
+ _a.label = 1;
566
+ case 1:
567
+ _a.trys.push([1, 3, , 4]);
568
+ raw = (0, local_storage_1.getStorageValue)(config.cacheKey);
569
+ if (isCachedArrayShape(raw)) {
570
+ found = raw.items.find(function (i) { return i.id === itemId; });
571
+ if (found)
572
+ return [2 /*return*/, found];
573
+ }
574
+ if (isCachedMapShape(raw)) {
575
+ if (raw.items && raw.items[itemId])
576
+ return [2 /*return*/, raw.items[itemId]];
577
+ }
578
+ return [4 /*yield*/, (0, exports.getCachedDataWithFallback)(config, params, headers)];
579
+ case 2:
580
+ list = _a.sent();
581
+ return [2 /*return*/, list.items.find(function (i) { return i.id === itemId; }) || null];
582
+ case 3:
583
+ error_4 = _a.sent();
584
+ console.error("Error in getCachedItemByIdAsync for ".concat(config.cacheKey, ":"), error_4);
585
+ return [2 /*return*/, null];
586
+ case 4: return [2 /*return*/];
587
+ }
588
+ });
589
+ }); };
590
+ exports.getCachedItemByIdAsync = getCachedItemByIdAsync;
511
591
  // ============================================================================
512
592
  // CACHE UTILITIES
513
593
  // ============================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.25.39",
3
+ "version": "1.25.41",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {