@react-pakistan/util-functions 1.24.99 → 1.25.0

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 (73) hide show
  1. package/api/stellar-solutions/app-user/index.d.ts +9 -9
  2. package/api/stellar-solutions/app-user/index.js +4 -4
  3. package/api/stellar-solutions/bank/cache.d.ts +99 -0
  4. package/api/stellar-solutions/bank/cache.js +256 -0
  5. package/api/stellar-solutions/bank/index.d.ts +10 -10
  6. package/api/stellar-solutions/bank/index.js +19 -4
  7. package/api/stellar-solutions/branch/cache.d.ts +97 -0
  8. package/api/stellar-solutions/branch/cache.js +256 -0
  9. package/api/stellar-solutions/branch/index.d.ts +10 -10
  10. package/api/stellar-solutions/branch/index.js +19 -4
  11. package/api/stellar-solutions/company/cache.d.ts +106 -0
  12. package/api/stellar-solutions/company/cache.js +307 -0
  13. package/api/stellar-solutions/company/index.d.ts +10 -10
  14. package/api/stellar-solutions/company/index.js +19 -4
  15. package/api/stellar-solutions/company-report/index.d.ts +3 -3
  16. package/api/stellar-solutions/company-report/index.js +1 -1
  17. package/api/stellar-solutions/constants.d.ts +12 -0
  18. package/api/stellar-solutions/constants.js +13 -1
  19. package/api/stellar-solutions/contact/cache.d.ts +108 -0
  20. package/api/stellar-solutions/contact/cache.js +307 -0
  21. package/api/stellar-solutions/contact/index.d.ts +10 -10
  22. package/api/stellar-solutions/contact/index.js +19 -4
  23. package/api/stellar-solutions/currency/cache.d.ts +99 -0
  24. package/api/stellar-solutions/currency/cache.js +256 -0
  25. package/api/stellar-solutions/currency/index.d.ts +10 -10
  26. package/api/stellar-solutions/currency/index.js +19 -4
  27. package/api/stellar-solutions/customer/cache.d.ts +108 -0
  28. package/api/stellar-solutions/customer/cache.js +307 -0
  29. package/api/stellar-solutions/customer/index.d.ts +12 -12
  30. package/api/stellar-solutions/customer/index.js +20 -5
  31. package/api/stellar-solutions/expense/cache.d.ts +106 -0
  32. package/api/stellar-solutions/expense/cache.js +307 -0
  33. package/api/stellar-solutions/expense/index.d.ts +10 -10
  34. package/api/stellar-solutions/expense/index.js +19 -4
  35. package/api/stellar-solutions/expense-category/cache.d.ts +94 -0
  36. package/api/stellar-solutions/expense-category/cache.js +280 -0
  37. package/api/stellar-solutions/expense-category/index.d.ts +10 -10
  38. package/api/stellar-solutions/expense-category/index.js +19 -4
  39. package/api/stellar-solutions/lead/index.d.ts +9 -9
  40. package/api/stellar-solutions/lead/index.js +4 -4
  41. package/api/stellar-solutions/menu-order/index.d.ts +9 -9
  42. package/api/stellar-solutions/menu-order/index.js +4 -4
  43. package/api/stellar-solutions/payment/index.d.ts +9 -9
  44. package/api/stellar-solutions/payment/index.js +4 -4
  45. package/api/stellar-solutions/payment-mode/cache.d.ts +97 -0
  46. package/api/stellar-solutions/payment-mode/cache.js +256 -0
  47. package/api/stellar-solutions/payment-mode/index.d.ts +10 -10
  48. package/api/stellar-solutions/payment-mode/index.js +19 -4
  49. package/api/stellar-solutions/preference/cache.d.ts +85 -0
  50. package/api/stellar-solutions/preference/cache.js +229 -0
  51. package/api/stellar-solutions/preference/index.d.ts +6 -6
  52. package/api/stellar-solutions/preference/index.js +17 -2
  53. package/api/stellar-solutions/product/cache.d.ts +9 -9
  54. package/api/stellar-solutions/product/cache.js +4 -4
  55. package/api/stellar-solutions/product/index.d.ts +9 -9
  56. package/api/stellar-solutions/product/index.js +4 -4
  57. package/api/stellar-solutions/product-category/cache.d.ts +9 -9
  58. package/api/stellar-solutions/product-category/cache.js +4 -4
  59. package/api/stellar-solutions/product-category/index.d.ts +9 -9
  60. package/api/stellar-solutions/product-category/index.js +4 -4
  61. package/api/stellar-solutions/profile/index.d.ts +13 -13
  62. package/api/stellar-solutions/profile/index.js +6 -6
  63. package/api/stellar-solutions/quote-invoice/index.d.ts +9 -9
  64. package/api/stellar-solutions/quote-invoice/index.js +4 -4
  65. package/api/stellar-solutions/quote-invoice-report/index.d.ts +3 -3
  66. package/api/stellar-solutions/quote-invoice-report/index.js +1 -1
  67. package/api/stellar-solutions/tax/cache.d.ts +97 -0
  68. package/api/stellar-solutions/tax/cache.js +256 -0
  69. package/api/stellar-solutions/tax/index.d.ts +10 -10
  70. package/api/stellar-solutions/tax/index.js +19 -4
  71. package/api/stellar-solutions/type.d.ts +57 -46
  72. package/api/stellar-solutions/type.js +11 -0
  73. package/package.json +1 -1
@@ -0,0 +1,97 @@
1
+ import { PaymentModeBE } from '../type';
2
+ /**
3
+ * Synchronous utility function to get payment modes from cache only
4
+ * Returns cached data immediately if available and fresh, otherwise returns empty array
5
+ * Does not trigger any API calls
6
+ *
7
+ * @returns PaymentModeBE[] - Array of cached payment modes or empty array wrapper ({count, items})
8
+ *
9
+ * @example
10
+ * const paymentModes = getCachedPaymentModesSync();
11
+ * if (paymentModes.items.length > 0) {
12
+ * console.log(paymentModes.items[0].label);
13
+ * }
14
+ */
15
+ export declare const getCachedPaymentModesSync: () => {
16
+ count: number;
17
+ items: PaymentModeBE[];
18
+ };
19
+ /**
20
+ * Utility function to get payment modes from cache or fetch from API
21
+ *
22
+ * This function manages a localStorage cache of payment modes with the following logic:
23
+ * - If payment modes exist in cache and are less than 1 week old, return cached version
24
+ * - If payment modes exist but are older than 1 week, fetch fresh data and update cache
25
+ * - If payment modes don't exist in cache, fetch from API and cache them
26
+ *
27
+ * @returns Promise<{count:number, items: PaymentModeBE[]}> - Paged payment modes
28
+ *
29
+ * @example
30
+ * const paymentModes = await getCachedPaymentModes();
31
+ * console.log(paymentModes.items[0].label);
32
+ */
33
+ export declare const getCachedPaymentModes: () => Promise<{
34
+ count: number;
35
+ items: PaymentModeBE[];
36
+ }>;
37
+ /**
38
+ * Utility function to get a specific payment mode by ID from cache
39
+ * If not found in cache, returns null (does not trigger API call)
40
+ *
41
+ * @param paymentModeId - The ID of the payment mode to retrieve
42
+ * @returns PaymentModeBE | null - The payment mode or null if not found
43
+ *
44
+ * @example
45
+ * const paymentMode = getCachedPaymentModeById('pm-123');
46
+ * if (paymentMode) {
47
+ * console.log(paymentMode.label);
48
+ * }
49
+ */
50
+ export declare const getCachedPaymentModeById: (paymentModeId: string) => PaymentModeBE | null;
51
+ /**
52
+ * Utility function to get payment modes by label from cache
53
+ * If not found in cache, returns empty array (does not trigger API call)
54
+ *
55
+ * @param label - The label of the payment mode to search for
56
+ * @returns PaymentModeBE[] - Array of matching payment modes or empty array
57
+ *
58
+ * @example
59
+ * const paymentModes = getCachedPaymentModesByLabel('Cash');
60
+ * console.log(paymentModes.length);
61
+ */
62
+ export declare const getCachedPaymentModesByLabel: (label: string) => PaymentModeBE[];
63
+ /**
64
+ * Utility function to invalidate (remove) payment modes from cache
65
+ * Useful when payment modes have been updated and you want to force a refresh
66
+ *
67
+ * @example
68
+ * invalidatePaymentModesCache();
69
+ * const freshPaymentModes = await getCachedPaymentModes();
70
+ */
71
+ export declare const invalidatePaymentModesCache: () => void;
72
+ /**
73
+ * Utility function to preload payment modes into cache
74
+ * Useful to call on app initialization or login
75
+ *
76
+ * @returns Promise<{count:number, items: PaymentModeBE[]}> - Array of preloaded payment modes
77
+ *
78
+ * @example
79
+ * // On app initialization
80
+ * await preloadPaymentModes();
81
+ */
82
+ export declare const preloadPaymentModes: () => Promise<{
83
+ count: number;
84
+ items: PaymentModeBE[];
85
+ }>;
86
+ /**
87
+ * Utility function to check if payment modes cache is stale
88
+ * Returns true if cache is older than 1 week or doesn't exist
89
+ *
90
+ * @returns boolean - True if cache is stale or doesn't exist
91
+ *
92
+ * @example
93
+ * if (isPaymentModesCacheStale()) {
94
+ * await getCachedPaymentModes(); // This will fetch fresh data
95
+ * }
96
+ */
97
+ export declare const isPaymentModesCacheStale: () => boolean;
@@ -0,0 +1,256 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.isPaymentModesCacheStale = exports.preloadPaymentModes = exports.invalidatePaymentModesCache = exports.getCachedPaymentModesByLabel = exports.getCachedPaymentModeById = exports.getCachedPaymentModes = exports.getCachedPaymentModesSync = void 0;
40
+ var constants_1 = require("../constants");
41
+ var type_1 = require("../type");
42
+ var api_methods_1 = require("../../../constants/api-methods");
43
+ var fetch_data_1 = require("../../../general/fetch-data");
44
+ var get_storage_value_1 = require("../../../local-storage/get-storage-value");
45
+ var set_storage_value_1 = require("../../../local-storage/set-storage-value");
46
+ /**
47
+ * Synchronous utility function to get payment modes from cache only
48
+ * Returns cached data immediately if available and fresh, otherwise returns empty array
49
+ * Does not trigger any API calls
50
+ *
51
+ * @returns PaymentModeBE[] - Array of cached payment modes or empty array wrapper ({count, items})
52
+ *
53
+ * @example
54
+ * const paymentModes = getCachedPaymentModesSync();
55
+ * if (paymentModes.items.length > 0) {
56
+ * console.log(paymentModes.items[0].label);
57
+ * }
58
+ */
59
+ var getCachedPaymentModesSync = function () {
60
+ try {
61
+ var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PAYMENT_MODES);
62
+ if (!cachedData) {
63
+ return { count: 0, items: [] };
64
+ }
65
+ var currentTime = new Date().getTime();
66
+ var cachedTime = new Date(cachedData.cachedAt).getTime();
67
+ var ageInMs = currentTime - cachedTime;
68
+ // If cached data is less than 1 week old, return it
69
+ if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
70
+ return {
71
+ count: cachedData.paymentModes.length,
72
+ items: cachedData.paymentModes,
73
+ };
74
+ }
75
+ return { count: 0, items: [] };
76
+ }
77
+ catch (error) {
78
+ console.error('Error getting cached payment modes:', error);
79
+ return { count: 0, items: [] };
80
+ }
81
+ };
82
+ exports.getCachedPaymentModesSync = getCachedPaymentModesSync;
83
+ /**
84
+ * Utility function to get payment modes from cache or fetch from API
85
+ *
86
+ * This function manages a localStorage cache of payment modes with the following logic:
87
+ * - If payment modes exist in cache and are less than 1 week old, return cached version
88
+ * - If payment modes exist but are older than 1 week, fetch fresh data and update cache
89
+ * - If payment modes don't exist in cache, fetch from API and cache them
90
+ *
91
+ * @returns Promise<{count:number, items: PaymentModeBE[]}> - Paged payment modes
92
+ *
93
+ * @example
94
+ * const paymentModes = await getCachedPaymentModes();
95
+ * console.log(paymentModes.items[0].label);
96
+ */
97
+ var getCachedPaymentModes = function () { return __awaiter(void 0, void 0, void 0, function () {
98
+ var cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
99
+ var _a;
100
+ return __generator(this, function (_b) {
101
+ switch (_b.label) {
102
+ case 0:
103
+ _b.trys.push([0, 2, , 3]);
104
+ cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PAYMENT_MODES);
105
+ currentTime = new Date().getTime();
106
+ // Check if cached data exists and is still fresh
107
+ if (cachedData) {
108
+ cachedTime = new Date(cachedData.cachedAt).getTime();
109
+ ageInMs = currentTime - cachedTime;
110
+ // If cached data is less than 1 week old, return it
111
+ if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
112
+ return [2 /*return*/, {
113
+ count: cachedData.paymentModes.length,
114
+ items: cachedData.paymentModes,
115
+ }];
116
+ }
117
+ }
118
+ return [4 /*yield*/, (0, fetch_data_1.fetchData)({
119
+ url: constants_1.API_ROUTES.PAYMENT_MODES,
120
+ method: api_methods_1.API_METHODS.GET,
121
+ })];
122
+ case 1:
123
+ response = _b.sent();
124
+ if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
125
+ updatedCache = {
126
+ paymentModes: response.data.items,
127
+ cachedAt: new Date().toISOString(),
128
+ };
129
+ (0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.PAYMENT_MODES, updatedCache);
130
+ return [2 /*return*/, response.data];
131
+ }
132
+ return [2 /*return*/, { count: 0, items: [] }];
133
+ case 2:
134
+ error_1 = _b.sent();
135
+ console.error('Error fetching payment modes:', error_1);
136
+ return [2 /*return*/, { count: 0, items: [] }];
137
+ case 3: return [2 /*return*/];
138
+ }
139
+ });
140
+ }); };
141
+ exports.getCachedPaymentModes = getCachedPaymentModes;
142
+ /**
143
+ * Utility function to get a specific payment mode by ID from cache
144
+ * If not found in cache, returns null (does not trigger API call)
145
+ *
146
+ * @param paymentModeId - The ID of the payment mode to retrieve
147
+ * @returns PaymentModeBE | null - The payment mode or null if not found
148
+ *
149
+ * @example
150
+ * const paymentMode = getCachedPaymentModeById('pm-123');
151
+ * if (paymentMode) {
152
+ * console.log(paymentMode.label);
153
+ * }
154
+ */
155
+ var getCachedPaymentModeById = function (paymentModeId) {
156
+ if (!paymentModeId) {
157
+ return null;
158
+ }
159
+ try {
160
+ var paymentModes = (0, exports.getCachedPaymentModesSync)().items;
161
+ return paymentModes.find(function (pm) { return pm.id === paymentModeId; }) || null;
162
+ }
163
+ catch (error) {
164
+ console.error('Error getting cached payment mode by ID:', error);
165
+ return null;
166
+ }
167
+ };
168
+ exports.getCachedPaymentModeById = getCachedPaymentModeById;
169
+ /**
170
+ * Utility function to get payment modes by label from cache
171
+ * If not found in cache, returns empty array (does not trigger API call)
172
+ *
173
+ * @param label - The label of the payment mode to search for
174
+ * @returns PaymentModeBE[] - Array of matching payment modes or empty array
175
+ *
176
+ * @example
177
+ * const paymentModes = getCachedPaymentModesByLabel('Cash');
178
+ * console.log(paymentModes.length);
179
+ */
180
+ var getCachedPaymentModesByLabel = function (label) {
181
+ if (!label) {
182
+ return [];
183
+ }
184
+ try {
185
+ var paymentModes = (0, exports.getCachedPaymentModesSync)().items;
186
+ return paymentModes.filter(function (pm) {
187
+ return pm.label.toLowerCase().includes(label.toLowerCase());
188
+ });
189
+ }
190
+ catch (error) {
191
+ console.error('Error getting cached payment modes by label:', error);
192
+ return [];
193
+ }
194
+ };
195
+ exports.getCachedPaymentModesByLabel = getCachedPaymentModesByLabel;
196
+ /**
197
+ * Utility function to invalidate (remove) payment modes from cache
198
+ * Useful when payment modes have been updated and you want to force a refresh
199
+ *
200
+ * @example
201
+ * invalidatePaymentModesCache();
202
+ * const freshPaymentModes = await getCachedPaymentModes();
203
+ */
204
+ var invalidatePaymentModesCache = function () {
205
+ try {
206
+ localStorage.removeItem(type_1.LS_KEYS.PAYMENT_MODES);
207
+ }
208
+ catch (error) {
209
+ console.error('Error invalidating payment modes cache:', error);
210
+ }
211
+ };
212
+ exports.invalidatePaymentModesCache = invalidatePaymentModesCache;
213
+ /**
214
+ * Utility function to preload payment modes into cache
215
+ * Useful to call on app initialization or login
216
+ *
217
+ * @returns Promise<{count:number, items: PaymentModeBE[]}> - Array of preloaded payment modes
218
+ *
219
+ * @example
220
+ * // On app initialization
221
+ * await preloadPaymentModes();
222
+ */
223
+ var preloadPaymentModes = function () { return __awaiter(void 0, void 0, void 0, function () {
224
+ return __generator(this, function (_a) {
225
+ return [2 /*return*/, (0, exports.getCachedPaymentModes)()];
226
+ });
227
+ }); };
228
+ exports.preloadPaymentModes = preloadPaymentModes;
229
+ /**
230
+ * Utility function to check if payment modes cache is stale
231
+ * Returns true if cache is older than 1 week or doesn't exist
232
+ *
233
+ * @returns boolean - True if cache is stale or doesn't exist
234
+ *
235
+ * @example
236
+ * if (isPaymentModesCacheStale()) {
237
+ * await getCachedPaymentModes(); // This will fetch fresh data
238
+ * }
239
+ */
240
+ var isPaymentModesCacheStale = function () {
241
+ try {
242
+ var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PAYMENT_MODES);
243
+ if (!cachedData) {
244
+ return true;
245
+ }
246
+ var currentTime = new Date().getTime();
247
+ var cachedTime = new Date(cachedData.cachedAt).getTime();
248
+ var ageInMs = currentTime - cachedTime;
249
+ return ageInMs >= constants_1.ONE_WEEK_IN_MS;
250
+ }
251
+ catch (error) {
252
+ console.error('Error checking payment modes cache staleness:', error);
253
+ return true;
254
+ }
255
+ };
256
+ exports.isPaymentModesCacheStale = isPaymentModesCacheStale;
@@ -1,4 +1,5 @@
1
- import { PaymentModeTypeBE } from '../type';
1
+ export * from './cache';
2
+ import { PaymentModeBE } from '../type';
2
3
  type PrismaClient = any;
3
4
  export interface ListPaymentModeArgs {
4
5
  currentPage?: number;
@@ -29,25 +30,24 @@ export interface DeletePaymentModeArgs {
29
30
  /**
30
31
  * Retrieves a paginated list of payment modes
31
32
  * @param {ListPaymentModeArgs} args - Object containing prisma client, pagination, filtering, and ordering options
32
- * @returns {Promise<[number, Array<PaymentModeTypeBE>]>} Tuple containing total count and array of payment modes
33
+ * @returns {Promise<[number, Array<PaymentModeBE>]>} Tuple containing total count and array of payment modes
33
34
  */
34
- export declare const listPaymentMode: ({ currentPage, includePayments, includePreference, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListPaymentModeArgs) => Promise<[number, Array<PaymentModeTypeBE>]>;
35
+ export declare const listPaymentMode: ({ currentPage, includePayments, includePreference, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListPaymentModeArgs) => Promise<[number, Array<PaymentModeBE>]>;
35
36
  /**
36
37
  * Retrieves a single payment mode by its ID
37
38
  * @param {UnitPaymentModeByIdArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
38
- * @returns {Promise<PaymentModeTypeBE | null>} Payment mode or null if not found
39
+ * @returns {Promise<PaymentModeBE | null>} Payment mode or null if not found
39
40
  */
40
- export declare const unitPaymentModeById: ({ id, includePayments, includePreference, prisma, }: UnitPaymentModeByIdArgs) => Promise<PaymentModeTypeBE | null>;
41
+ export declare const unitPaymentModeById: ({ id, includePayments, includePreference, prisma, }: UnitPaymentModeByIdArgs) => Promise<PaymentModeBE | null>;
41
42
  /**
42
43
  * Updates a payment mode's enabled status
43
44
  * @param {UpdatePaymentModeArgs} args - Object containing prisma client, payment mode ID, enabled status, and optional query parameters
44
- * @returns {Promise<PaymentModeTypeBE>} Updated payment mode
45
+ * @returns {Promise<PaymentModeBE>} Updated payment mode
45
46
  */
46
- export declare const updatePaymentMode: ({ enabled, isDefault, id, prisma, }: UpdatePaymentModeArgs) => Promise<PaymentModeTypeBE>;
47
+ export declare const updatePaymentMode: ({ enabled, isDefault, id, prisma, }: UpdatePaymentModeArgs) => Promise<PaymentModeBE>;
47
48
  /**
48
49
  * Deletes a payment mode by ID
49
50
  * @param {DeletePaymentModeArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
50
- * @returns {Promise<PaymentModeTypeBE>} Deleted payment mode
51
+ * @returns {Promise<PaymentModeBE>} Deleted payment mode
51
52
  */
52
- export declare const deletePaymentMode: ({ id, prisma, }: DeletePaymentModeArgs) => Promise<PaymentModeTypeBE>;
53
- export {};
53
+ export declare const deletePaymentMode: ({ id, prisma, }: DeletePaymentModeArgs) => Promise<PaymentModeBE>;
@@ -1,4 +1,18 @@
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
+ };
2
16
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
17
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
18
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,11 +60,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
46
60
  };
47
61
  Object.defineProperty(exports, "__esModule", { value: true });
48
62
  exports.deletePaymentMode = exports.updatePaymentMode = exports.unitPaymentModeById = exports.listPaymentMode = void 0;
63
+ __exportStar(require("./cache"), exports);
49
64
  var multi_part_search_1 = require("../../../general/multi-part-search");
50
65
  /**
51
66
  * Retrieves a paginated list of payment modes
52
67
  * @param {ListPaymentModeArgs} args - Object containing prisma client, pagination, filtering, and ordering options
53
- * @returns {Promise<[number, Array<PaymentModeTypeBE>]>} Tuple containing total count and array of payment modes
68
+ * @returns {Promise<[number, Array<PaymentModeBE>]>} Tuple containing total count and array of payment modes
54
69
  */
55
70
  var listPaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
56
71
  var include, orderBy, idSearchQuery, labelSearchQuery, where, _c, count, items;
@@ -105,7 +120,7 @@ exports.listPaymentMode = listPaymentMode;
105
120
  /**
106
121
  * Retrieves a single payment mode by its ID
107
122
  * @param {UnitPaymentModeByIdArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
108
- * @returns {Promise<PaymentModeTypeBE | null>} Payment mode or null if not found
123
+ * @returns {Promise<PaymentModeBE | null>} Payment mode or null if not found
109
124
  */
110
125
  var unitPaymentModeById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
111
126
  var include, where, paymentMode;
@@ -135,7 +150,7 @@ exports.unitPaymentModeById = unitPaymentModeById;
135
150
  /**
136
151
  * Updates a payment mode's enabled status
137
152
  * @param {UpdatePaymentModeArgs} args - Object containing prisma client, payment mode ID, enabled status, and optional query parameters
138
- * @returns {Promise<PaymentModeTypeBE>} Updated payment mode
153
+ * @returns {Promise<PaymentModeBE>} Updated payment mode
139
154
  */
140
155
  var updatePaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
141
156
  var where, paymentMode;
@@ -167,7 +182,7 @@ exports.updatePaymentMode = updatePaymentMode;
167
182
  /**
168
183
  * Deletes a payment mode by ID
169
184
  * @param {DeletePaymentModeArgs} args - Object containing prisma client, payment mode ID, and optional query parameters
170
- * @returns {Promise<PaymentModeTypeBE>} Deleted payment mode
185
+ * @returns {Promise<PaymentModeBE>} Deleted payment mode
171
186
  */
172
187
  var deletePaymentMode = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
173
188
  var where, paymentMode;
@@ -0,0 +1,85 @@
1
+ import { PreferenceBE } from '../type';
2
+ /**
3
+ * Synchronous utility function to get preferences from cache only
4
+ * Returns cached data immediately if available and fresh, otherwise returns empty array
5
+ * Does not trigger any API calls
6
+ *
7
+ * @returns PreferenceBE[] - Array of cached preferences or empty array wrapper ({count, items})
8
+ *
9
+ * @example
10
+ * const preferences = getCachedPreferencesSync();
11
+ * if (preferences.items.length > 0) {
12
+ * console.log(preferences.items[0].onboarding);
13
+ * }
14
+ */
15
+ export declare const getCachedPreferencesSync: () => {
16
+ count: number;
17
+ items: PreferenceBE[];
18
+ };
19
+ /**
20
+ * Utility function to get preferences from cache or fetch from API
21
+ *
22
+ * This function manages a localStorage cache of preferences with the following logic:
23
+ * - If preferences exist in cache and are less than 1 day old, return cached version
24
+ * - If preferences exist but are older than 1 day, fetch fresh data and update cache
25
+ * - If preferences don't exist in cache, fetch from API and cache them
26
+ *
27
+ * @returns Promise<{count:number, items: PreferenceBE[]}> - Paged preferences
28
+ *
29
+ * @example
30
+ * const preferences = await getCachedPreferences();
31
+ * console.log(preferences.items[0].onboarding);
32
+ */
33
+ export declare const getCachedPreferences: () => Promise<{
34
+ count: number;
35
+ items: PreferenceBE[];
36
+ }>;
37
+ /**
38
+ * Utility function to get a specific preference by ID from cache
39
+ * If not found in cache, returns null (does not trigger API call)
40
+ *
41
+ * @param preferenceId - The ID of the preference to retrieve
42
+ * @returns PreferenceBE | null - The preference or null if not found
43
+ *
44
+ * @example
45
+ * const preference = getCachedPreferenceById('pref-123');
46
+ * if (preference) {
47
+ * console.log(preference.onboarding);
48
+ * }
49
+ */
50
+ export declare const getCachedPreferenceById: (preferenceId: string) => PreferenceBE | null;
51
+ /**
52
+ * Utility function to invalidate (remove) preferences from cache
53
+ * Useful when preferences have been updated and you want to force a refresh
54
+ *
55
+ * @example
56
+ * invalidatePreferencesCache();
57
+ * const freshPreferences = await getCachedPreferences();
58
+ */
59
+ export declare const invalidatePreferencesCache: () => void;
60
+ /**
61
+ * Utility function to preload preferences into cache
62
+ * Useful to call on app initialization or login
63
+ *
64
+ * @returns Promise<{count:number, items: PreferenceBE[]}> - Array of preloaded preferences
65
+ *
66
+ * @example
67
+ * // On app initialization
68
+ * await preloadPreferences();
69
+ */
70
+ export declare const preloadPreferences: () => Promise<{
71
+ count: number;
72
+ items: PreferenceBE[];
73
+ }>;
74
+ /**
75
+ * Utility function to check if preferences cache is stale
76
+ * Returns true if cache is older than 1 day or doesn't exist
77
+ *
78
+ * @returns boolean - True if cache is stale or doesn't exist
79
+ *
80
+ * @example
81
+ * if (isPreferencesCacheStale()) {
82
+ * await getCachedPreferences(); // This will fetch fresh data
83
+ * }
84
+ */
85
+ export declare const isPreferencesCacheStale: () => boolean;