@react-pakistan/util-functions 1.25.8 → 1.25.10

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 (63) hide show
  1. package/api/stellar-solutions/bank/cache.d.ts +0 -104
  2. package/api/stellar-solutions/bank/cache.js +237 -295
  3. package/api/stellar-solutions/bank/index.d.ts +1 -1
  4. package/api/stellar-solutions/bank/index.js +0 -15
  5. package/api/stellar-solutions/branch/cache.d.ts +0 -102
  6. package/api/stellar-solutions/branch/cache.js +241 -295
  7. package/api/stellar-solutions/branch/index.d.ts +1 -1
  8. package/api/stellar-solutions/branch/index.js +0 -15
  9. package/api/stellar-solutions/company/cache.d.ts +0 -106
  10. package/api/stellar-solutions/company/cache.js +247 -307
  11. package/api/stellar-solutions/company/index.d.ts +1 -1
  12. package/api/stellar-solutions/company/index.js +0 -15
  13. package/api/stellar-solutions/constants.d.ts +0 -2
  14. package/api/stellar-solutions/constants.js +1 -3
  15. package/api/stellar-solutions/contact/cache.d.ts +0 -108
  16. package/api/stellar-solutions/contact/cache.js +247 -307
  17. package/api/stellar-solutions/contact/index.d.ts +1 -1
  18. package/api/stellar-solutions/contact/index.js +0 -15
  19. package/api/stellar-solutions/currency/cache.d.ts +0 -104
  20. package/api/stellar-solutions/currency/cache.js +243 -295
  21. package/api/stellar-solutions/currency/index.d.ts +1 -1
  22. package/api/stellar-solutions/currency/index.js +0 -15
  23. package/api/stellar-solutions/customer/cache.d.ts +0 -108
  24. package/api/stellar-solutions/customer/cache.js +249 -307
  25. package/api/stellar-solutions/customer/index.d.ts +1 -1
  26. package/api/stellar-solutions/customer/index.js +0 -15
  27. package/api/stellar-solutions/expense/cache.d.ts +0 -106
  28. package/api/stellar-solutions/expense/cache.js +247 -307
  29. package/api/stellar-solutions/expense/index.d.ts +1 -1
  30. package/api/stellar-solutions/expense/index.js +0 -15
  31. package/api/stellar-solutions/expense-category/cache.d.ts +0 -94
  32. package/api/stellar-solutions/expense-category/cache.js +224 -280
  33. package/api/stellar-solutions/expense-category/index.d.ts +1 -1
  34. package/api/stellar-solutions/expense-category/index.js +0 -15
  35. package/api/stellar-solutions/payment-mode/cache.d.ts +0 -102
  36. package/api/stellar-solutions/payment-mode/cache.js +245 -295
  37. package/api/stellar-solutions/payment-mode/index.d.ts +1 -1
  38. package/api/stellar-solutions/payment-mode/index.js +0 -15
  39. package/api/stellar-solutions/preference/cache.d.ts +0 -90
  40. package/api/stellar-solutions/preference/cache.js +218 -268
  41. package/api/stellar-solutions/preference/index.d.ts +1 -1
  42. package/api/stellar-solutions/preference/index.js +0 -15
  43. package/api/stellar-solutions/product/cache.d.ts +0 -94
  44. package/api/stellar-solutions/product/cache.js +222 -280
  45. package/api/stellar-solutions/product/index.d.ts +1 -1
  46. package/api/stellar-solutions/product/index.js +0 -15
  47. package/api/stellar-solutions/product-category/cache.d.ts +0 -94
  48. package/api/stellar-solutions/product-category/cache.js +224 -280
  49. package/api/stellar-solutions/product-category/index.d.ts +1 -1
  50. package/api/stellar-solutions/product-category/index.js +0 -15
  51. package/api/stellar-solutions/tax/cache.d.ts +0 -102
  52. package/api/stellar-solutions/tax/cache.js +235 -295
  53. package/api/stellar-solutions/tax/index.d.ts +1 -1
  54. package/api/stellar-solutions/tax/index.js +0 -15
  55. package/constants/cache-time.d.ts +3 -0
  56. package/constants/cache-time.js +6 -0
  57. package/constants/index.d.ts +2 -1
  58. package/constants/index.js +2 -1
  59. package/general/generic-cache.d.ts +143 -0
  60. package/general/generic-cache.js +411 -0
  61. package/general/index.d.ts +1 -0
  62. package/general/index.js +1 -0
  63. package/package.json +1 -1
@@ -1,295 +1,245 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.isPaymentModesCacheStale = exports.preloadPaymentModes = exports.invalidatePaymentModesCache = exports.getCachedPaymentModesByLabel = exports.getCachedPaymentModeById = exports.getCachedPaymentModes = exports.getCachedPaymentModesSync = void 0;
49
- var constants_1 = require("../constants");
50
- var type_1 = require("../type");
51
- var api_methods_1 = require("../../../constants/api-methods");
52
- var fetch_data_1 = require("../../../general/fetch-data");
53
- var get_storage_value_1 = require("../../../local-storage/get-storage-value");
54
- var set_storage_value_1 = require("../../../local-storage/set-storage-value");
55
- /**
56
- * Synchronous utility function to get payment modes from cache only
57
- * Returns cached data immediately if available and fresh, otherwise returns empty array
58
- * Does not trigger any API calls
59
- *
60
- * @returns PaymentModeBE[] - Array of cached payment modes or empty array wrapper ({count, items})
61
- *
62
- * @example
63
- * const paymentModes = getCachedPaymentModesSync();
64
- * if (paymentModes.items.length > 0) {
65
- * console.log(paymentModes.items[0].label);
66
- * }
67
- */
68
- var getCachedPaymentModesSync = function () {
69
- try {
70
- var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PAYMENT_MODES);
71
- if (!cachedData) {
72
- return { count: 0, items: [] };
73
- }
74
- var currentTime = new Date().getTime();
75
- var cachedTime = new Date(cachedData.cachedAt).getTime();
76
- var ageInMs = currentTime - cachedTime;
77
- // If cached data is less than 1 week old, return it
78
- if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
79
- return {
80
- count: cachedData.paymentModes.length,
81
- items: cachedData.paymentModes,
82
- };
83
- }
84
- return { count: 0, items: [] };
85
- }
86
- catch (error) {
87
- console.error('Error getting cached payment modes:', error);
88
- return { count: 0, items: [] };
89
- }
90
- };
91
- exports.getCachedPaymentModesSync = getCachedPaymentModesSync;
92
- /**
93
- * Utility function to get payment modes from cache or fetch from API
94
- *
95
- * This function manages a localStorage cache of payment modes with the following logic:
96
- * - If payment modes exist in cache and are less than 1 week old, return cached version
97
- * - If payment modes exist but are older than 1 week, fetch fresh data and update cache
98
- * - If payment modes don't exist in cache, fetch from API and cache them
99
- *
100
- * @param searchQuery - Optional search query to filter payment modes
101
- * @param pageLimit - Number of payment modes to fetch (default: 100)
102
- * @returns Promise<{count:number, items: PaymentModeBE[]}> - Paged payment modes
103
- *
104
- * @example
105
- * const paymentModes = await getCachedPaymentModes();
106
- * console.log(paymentModes.items[0].label);
107
- *
108
- * // With search
109
- * const filtered = await getCachedPaymentModes('Cash');
110
- */
111
- var getCachedPaymentModes = function (searchQuery_1) {
112
- var args_1 = [];
113
- for (var _i = 1; _i < arguments.length; _i++) {
114
- args_1[_i - 1] = arguments[_i];
115
- }
116
- return __awaiter(void 0, __spreadArray([searchQuery_1], args_1, true), void 0, function (searchQuery, pageLimit) {
117
- var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
118
- var _a;
119
- if (pageLimit === void 0) { pageLimit = 100; }
120
- return __generator(this, function (_b) {
121
- switch (_b.label) {
122
- case 0:
123
- _b.trys.push([0, 4, , 5]);
124
- if (!(searchQuery && searchQuery.trim())) return [3 /*break*/, 2];
125
- return [4 /*yield*/, (0, fetch_data_1.fetchData)({
126
- url: constants_1.API_ROUTES.PAYMENT_MODES,
127
- body: JSON.stringify({
128
- searchQuery: searchQuery,
129
- pageLimit: pageLimit,
130
- currentPage: 1,
131
- }),
132
- method: api_methods_1.API_METHODS.POST,
133
- })];
134
- case 1:
135
- response_1 = _b.sent();
136
- return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
137
- case 2:
138
- cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PAYMENT_MODES);
139
- currentTime = new Date().getTime();
140
- // Check if cached data exists and is still fresh
141
- if (cachedData) {
142
- cachedTime = new Date(cachedData.cachedAt).getTime();
143
- ageInMs = currentTime - cachedTime;
144
- // If cached data is less than 1 week old, return it
145
- if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
146
- return [2 /*return*/, {
147
- count: cachedData.paymentModes.length,
148
- items: cachedData.paymentModes,
149
- }];
150
- }
151
- }
152
- return [4 /*yield*/, (0, fetch_data_1.fetchData)({
153
- url: constants_1.API_ROUTES.PAYMENT_MODES,
154
- body: JSON.stringify({
155
- pageLimit: pageLimit,
156
- currentPage: 1,
157
- }),
158
- method: api_methods_1.API_METHODS.POST,
159
- })];
160
- case 3:
161
- response = _b.sent();
162
- if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
163
- updatedCache = {
164
- paymentModes: response.data.items,
165
- cachedAt: new Date().toISOString(),
166
- };
167
- (0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.PAYMENT_MODES, updatedCache);
168
- return [2 /*return*/, response.data];
169
- }
170
- return [2 /*return*/, { count: 0, items: [] }];
171
- case 4:
172
- error_1 = _b.sent();
173
- console.error('Error fetching payment modes:', error_1);
174
- return [2 /*return*/, { count: 0, items: [] }];
175
- case 5: return [2 /*return*/];
176
- }
177
- });
178
- });
179
- };
180
- exports.getCachedPaymentModes = getCachedPaymentModes;
181
- /**
182
- * Utility function to get a specific payment mode by ID from cache
183
- * If not found in cache, returns null (does not trigger API call)
184
- *
185
- * @param paymentModeId - The ID of the payment mode to retrieve
186
- * @returns PaymentModeBE | null - The payment mode or null if not found
187
- *
188
- * @example
189
- * const paymentMode = getCachedPaymentModeById('pm-123');
190
- * if (paymentMode) {
191
- * console.log(paymentMode.label);
192
- * }
193
- */
194
- var getCachedPaymentModeById = function (paymentModeId) {
195
- if (!paymentModeId) {
196
- return null;
197
- }
198
- try {
199
- var paymentModes = (0, exports.getCachedPaymentModesSync)().items;
200
- return paymentModes.find(function (pm) { return pm.id === paymentModeId; }) || null;
201
- }
202
- catch (error) {
203
- console.error('Error getting cached payment mode by ID:', error);
204
- return null;
205
- }
206
- };
207
- exports.getCachedPaymentModeById = getCachedPaymentModeById;
208
- /**
209
- * Utility function to get payment modes by label from cache
210
- * If not found in cache, returns empty array (does not trigger API call)
211
- *
212
- * @param label - The label of the payment mode to search for
213
- * @returns PaymentModeBE[] - Array of matching payment modes or empty array
214
- *
215
- * @example
216
- * const paymentModes = getCachedPaymentModesByLabel('Cash');
217
- * console.log(paymentModes.length);
218
- */
219
- var getCachedPaymentModesByLabel = function (label) {
220
- if (!label) {
221
- return [];
222
- }
223
- try {
224
- var paymentModes = (0, exports.getCachedPaymentModesSync)().items;
225
- return paymentModes.filter(function (pm) {
226
- return pm.label.toLowerCase().includes(label.toLowerCase());
227
- });
228
- }
229
- catch (error) {
230
- console.error('Error getting cached payment modes by label:', error);
231
- return [];
232
- }
233
- };
234
- exports.getCachedPaymentModesByLabel = getCachedPaymentModesByLabel;
235
- /**
236
- * Utility function to invalidate (remove) payment modes from cache
237
- * Useful when payment modes have been updated and you want to force a refresh
238
- *
239
- * @example
240
- * invalidatePaymentModesCache();
241
- * const freshPaymentModes = await getCachedPaymentModes();
242
- */
243
- var invalidatePaymentModesCache = function () {
244
- try {
245
- localStorage.removeItem(type_1.LS_KEYS.PAYMENT_MODES);
246
- }
247
- catch (error) {
248
- console.error('Error invalidating payment modes cache:', error);
249
- }
250
- };
251
- exports.invalidatePaymentModesCache = invalidatePaymentModesCache;
252
- /**
253
- * Utility function to preload payment modes into cache
254
- * Useful to call on app initialization or login
255
- *
256
- * @returns Promise<{count:number, items: PaymentModeBE[]}> - Array of preloaded payment modes
257
- *
258
- * @example
259
- * // On app initialization
260
- * await preloadPaymentModes();
261
- */
262
- var preloadPaymentModes = function () { return __awaiter(void 0, void 0, void 0, function () {
263
- return __generator(this, function (_a) {
264
- return [2 /*return*/, (0, exports.getCachedPaymentModes)()];
265
- });
266
- }); };
267
- exports.preloadPaymentModes = preloadPaymentModes;
268
- /**
269
- * Utility function to check if payment modes cache is stale
270
- * Returns true if cache is older than 1 week or doesn't exist
271
- *
272
- * @returns boolean - True if cache is stale or doesn't exist
273
- *
274
- * @example
275
- * if (isPaymentModesCacheStale()) {
276
- * await getCachedPaymentModes(); // This will fetch fresh data
277
- * }
278
- */
279
- var isPaymentModesCacheStale = function () {
280
- try {
281
- var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PAYMENT_MODES);
282
- if (!cachedData) {
283
- return true;
284
- }
285
- var currentTime = new Date().getTime();
286
- var cachedTime = new Date(cachedData.cachedAt).getTime();
287
- var ageInMs = currentTime - cachedTime;
288
- return ageInMs >= constants_1.ONE_WEEK_IN_MS;
289
- }
290
- catch (error) {
291
- console.error('Error checking payment modes cache staleness:', error);
292
- return true;
293
- }
294
- };
295
- exports.isPaymentModesCacheStale = isPaymentModesCacheStale;
1
+ // import { API_ROUTES } from '../constants';
2
+ // import { PaymentModeBE, LS_KEYS } from '../type';
3
+ // import { API_METHODS } from '../../../constants/api-methods';
4
+ // import { fetchData } from '../../../general/fetch-data';
5
+ // import { getStorageValue } from '../../../local-storage/get-storage-value';
6
+ // import { setStorageValue } from '../../../local-storage/set-storage-value';
7
+ // import { ONE_WEEK_IN_MS } from '../../../constants';
8
+ // interface CachedPaymentModes {
9
+ // paymentModes: PaymentModeBE[];
10
+ // cachedAt: string;
11
+ // }
12
+ // /**
13
+ // * Synchronous utility function to get payment modes from cache only
14
+ // * Returns cached data immediately if available and fresh, otherwise returns empty array
15
+ // * Does not trigger any API calls
16
+ // *
17
+ // * @returns PaymentModeBE[] - Array of cached payment modes or empty array wrapper ({count, items})
18
+ // *
19
+ // * @example
20
+ // * const paymentModes = getCachedPaymentModesSync();
21
+ // * if (paymentModes.items.length > 0) {
22
+ // * console.log(paymentModes.items[0].label);
23
+ // * }
24
+ // */
25
+ // export const getCachedPaymentModesSync = (): {
26
+ // count: number;
27
+ // items: PaymentModeBE[];
28
+ // } => {
29
+ // try {
30
+ // const cachedData = getStorageValue(
31
+ // LS_KEYS.PAYMENT_MODES
32
+ // ) as CachedPaymentModes | null;
33
+ // if (!cachedData) {
34
+ // return { count: 0, items: [] };
35
+ // }
36
+ // const currentTime = new Date().getTime();
37
+ // const cachedTime = new Date(cachedData.cachedAt).getTime();
38
+ // const ageInMs = currentTime - cachedTime;
39
+ // // If cached data is less than 1 week old, return it
40
+ // if (ageInMs < ONE_WEEK_IN_MS) {
41
+ // return {
42
+ // count: cachedData.paymentModes.length,
43
+ // items: cachedData.paymentModes,
44
+ // };
45
+ // }
46
+ // return { count: 0, items: [] };
47
+ // } catch (error) {
48
+ // console.error('Error getting cached payment modes:', error);
49
+ // return { count: 0, items: [] };
50
+ // }
51
+ // };
52
+ // /**
53
+ // * Utility function to get payment modes from cache or fetch from API
54
+ // *
55
+ // * This function manages a localStorage cache of payment modes with the following logic:
56
+ // * - If payment modes exist in cache and are less than 1 week old, return cached version
57
+ // * - If payment modes exist but are older than 1 week, fetch fresh data and update cache
58
+ // * - If payment modes don't exist in cache, fetch from API and cache them
59
+ // *
60
+ // * @param searchQuery - Optional search query to filter payment modes
61
+ // * @param pageLimit - Number of payment modes to fetch (default: 100)
62
+ // * @returns Promise<{count:number, items: PaymentModeBE[]}> - Paged payment modes
63
+ // *
64
+ // * @example
65
+ // * const paymentModes = await getCachedPaymentModes();
66
+ // * console.log(paymentModes.items[0].label);
67
+ // *
68
+ // * // With search
69
+ // * const filtered = await getCachedPaymentModes('Cash');
70
+ // */
71
+ // export const getCachedPaymentModes = async (
72
+ // searchQuery?: string,
73
+ // pageLimit: number = 100
74
+ // ): Promise<{
75
+ // count: number;
76
+ // items: PaymentModeBE[];
77
+ // }> => {
78
+ // try {
79
+ // // If there's a search query, always fetch fresh data (don't use cache)
80
+ // if (searchQuery && searchQuery.trim()) {
81
+ // const response = await fetchData({
82
+ // url: API_ROUTES.PAYMENT_MODES,
83
+ // body: JSON.stringify({
84
+ // searchQuery,
85
+ // pageLimit,
86
+ // currentPage: 1,
87
+ // }),
88
+ // method: API_METHODS.POST,
89
+ // });
90
+ // return response?.data || { count: 0, items: [] };
91
+ // }
92
+ // // Get the cached data from localStorage
93
+ // const cachedData = getStorageValue(
94
+ // LS_KEYS.PAYMENT_MODES
95
+ // ) as CachedPaymentModes | null;
96
+ // const currentTime = new Date().getTime();
97
+ // // Check if cached data exists and is still fresh
98
+ // if (cachedData) {
99
+ // const cachedTime = new Date(cachedData.cachedAt).getTime();
100
+ // const ageInMs = currentTime - cachedTime;
101
+ // // If cached data is less than 1 week old, return it
102
+ // if (ageInMs < ONE_WEEK_IN_MS) {
103
+ // return {
104
+ // count: cachedData.paymentModes.length,
105
+ // items: cachedData.paymentModes,
106
+ // };
107
+ // }
108
+ // }
109
+ // // If no cached data or data is older than 1 week, fetch fresh data
110
+ // const response = await fetchData({
111
+ // url: API_ROUTES.PAYMENT_MODES,
112
+ // body: JSON.stringify({
113
+ // pageLimit,
114
+ // currentPage: 1,
115
+ // }),
116
+ // method: API_METHODS.POST,
117
+ // });
118
+ // if (response?.data?.items) {
119
+ // // Update the cache with fresh data
120
+ // const updatedCache: CachedPaymentModes = {
121
+ // paymentModes: response.data.items,
122
+ // cachedAt: new Date().toISOString(),
123
+ // };
124
+ // setStorageValue(LS_KEYS.PAYMENT_MODES, updatedCache);
125
+ // return response.data;
126
+ // }
127
+ // return { count: 0, items: [] };
128
+ // } catch (error) {
129
+ // console.error('Error fetching payment modes:', error);
130
+ // return { count: 0, items: [] };
131
+ // }
132
+ // };
133
+ // /**
134
+ // * Utility function to get a specific payment mode by ID from cache
135
+ // * If not found in cache, returns null (does not trigger API call)
136
+ // *
137
+ // * @param paymentModeId - The ID of the payment mode to retrieve
138
+ // * @returns PaymentModeBE | null - The payment mode or null if not found
139
+ // *
140
+ // * @example
141
+ // * const paymentMode = getCachedPaymentModeById('pm-123');
142
+ // * if (paymentMode) {
143
+ // * console.log(paymentMode.label);
144
+ // * }
145
+ // */
146
+ // export const getCachedPaymentModeById = (
147
+ // paymentModeId: string
148
+ // ): PaymentModeBE | null => {
149
+ // if (!paymentModeId) {
150
+ // return null;
151
+ // }
152
+ // try {
153
+ // const paymentModes = getCachedPaymentModesSync().items;
154
+ // return paymentModes.find((pm) => pm.id === paymentModeId) || null;
155
+ // } catch (error) {
156
+ // console.error('Error getting cached payment mode by ID:', error);
157
+ // return null;
158
+ // }
159
+ // };
160
+ // /**
161
+ // * Utility function to get payment modes by label from cache
162
+ // * If not found in cache, returns empty array (does not trigger API call)
163
+ // *
164
+ // * @param label - The label of the payment mode to search for
165
+ // * @returns PaymentModeBE[] - Array of matching payment modes or empty array
166
+ // *
167
+ // * @example
168
+ // * const paymentModes = getCachedPaymentModesByLabel('Cash');
169
+ // * console.log(paymentModes.length);
170
+ // */
171
+ // export const getCachedPaymentModesByLabel = (
172
+ // label: string
173
+ // ): PaymentModeBE[] => {
174
+ // if (!label) {
175
+ // return [];
176
+ // }
177
+ // try {
178
+ // const paymentModes = getCachedPaymentModesSync().items;
179
+ // return paymentModes.filter((pm) =>
180
+ // pm.label.toLowerCase().includes(label.toLowerCase())
181
+ // );
182
+ // } catch (error) {
183
+ // console.error('Error getting cached payment modes by label:', error);
184
+ // return [];
185
+ // }
186
+ // };
187
+ // /**
188
+ // * Utility function to invalidate (remove) payment modes from cache
189
+ // * Useful when payment modes have been updated and you want to force a refresh
190
+ // *
191
+ // * @example
192
+ // * invalidatePaymentModesCache();
193
+ // * const freshPaymentModes = await getCachedPaymentModes();
194
+ // */
195
+ // export const invalidatePaymentModesCache = (): void => {
196
+ // try {
197
+ // localStorage.removeItem(LS_KEYS.PAYMENT_MODES);
198
+ // } catch (error) {
199
+ // console.error('Error invalidating payment modes cache:', error);
200
+ // }
201
+ // };
202
+ // /**
203
+ // * Utility function to preload payment modes into cache
204
+ // * Useful to call on app initialization or login
205
+ // *
206
+ // * @returns Promise<{count:number, items: PaymentModeBE[]}> - Array of preloaded payment modes
207
+ // *
208
+ // * @example
209
+ // * // On app initialization
210
+ // * await preloadPaymentModes();
211
+ // */
212
+ // export const preloadPaymentModes = async (): Promise<{
213
+ // count: number;
214
+ // items: PaymentModeBE[];
215
+ // }> => {
216
+ // return getCachedPaymentModes();
217
+ // };
218
+ // /**
219
+ // * Utility function to check if payment modes cache is stale
220
+ // * Returns true if cache is older than 1 week or doesn't exist
221
+ // *
222
+ // * @returns boolean - True if cache is stale or doesn't exist
223
+ // *
224
+ // * @example
225
+ // * if (isPaymentModesCacheStale()) {
226
+ // * await getCachedPaymentModes(); // This will fetch fresh data
227
+ // * }
228
+ // */
229
+ // export const isPaymentModesCacheStale = (): boolean => {
230
+ // try {
231
+ // const cachedData = getStorageValue(
232
+ // LS_KEYS.PAYMENT_MODES
233
+ // ) as CachedPaymentModes | null;
234
+ // if (!cachedData) {
235
+ // return true;
236
+ // }
237
+ // const currentTime = new Date().getTime();
238
+ // const cachedTime = new Date(cachedData.cachedAt).getTime();
239
+ // const ageInMs = currentTime - cachedTime;
240
+ // return ageInMs >= ONE_WEEK_IN_MS;
241
+ // } catch (error) {
242
+ // console.error('Error checking payment modes cache staleness:', error);
243
+ // return true;
244
+ // }
245
+ // };
@@ -1,4 +1,3 @@
1
- export * from './cache';
2
1
  import { PaymentModeBE } from '../type';
3
2
  type PrismaClient = any;
4
3
  export interface ListPaymentModeArgs {
@@ -51,3 +50,4 @@ export declare const updatePaymentMode: ({ enabled, isDefault, id, prisma, }: Up
51
50
  * @returns {Promise<PaymentModeBE>} Deleted payment mode
52
51
  */
53
52
  export declare const deletePaymentMode: ({ id, prisma, }: DeletePaymentModeArgs) => Promise<PaymentModeBE>;
53
+ export {};
@@ -1,18 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -60,7 +46,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
60
46
  };
61
47
  Object.defineProperty(exports, "__esModule", { value: true });
62
48
  exports.deletePaymentMode = exports.updatePaymentMode = exports.unitPaymentModeById = exports.listPaymentMode = void 0;
63
- __exportStar(require("./cache"), exports);
64
49
  var multi_part_search_1 = require("../../../general/multi-part-search");
65
50
  /**
66
51
  * Retrieves a paginated list of payment modes