@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
@@ -1,4 +1,4 @@
1
- import { AppUserTypeBE } from '../type';
1
+ import { AppUserBE } from '../type';
2
2
  type PrismaClient = any;
3
3
  export interface ListAppUserArgs {
4
4
  currentPage?: number;
@@ -26,26 +26,26 @@ export interface DeleteAppUserArgs {
26
26
  /**
27
27
  * Retrieves all app users from the database with pagination
28
28
  * @param {ListAppUserArgs} args - Object containing prisma client, pagination, and query options
29
- * @returns {Promise<[number, Array<AppUserTypeBE>]>} Tuple of [total count, array of app users]
29
+ * @returns {Promise<[number, Array<AppUserBE>]>} Tuple of [total count, array of app users]
30
30
  */
31
- export declare const listAppUser: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListAppUserArgs) => Promise<[number, Array<AppUserTypeBE>]>;
31
+ export declare const listAppUser: ({ currentPage, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListAppUserArgs) => Promise<[number, Array<AppUserBE>]>;
32
32
  /**
33
33
  * Retrieves a single app user by ID
34
34
  * @param {UnitAppUserByIdArgs} args - Object containing prisma client and user query
35
- * @returns {Promise<AppUserTypeBE | null>} App user if found, null otherwise
35
+ * @returns {Promise<AppUserBE | null>} App user if found, null otherwise
36
36
  */
37
- export declare const unitAppUserById: ({ id, prisma, }: UnitAppUserByIdArgs) => Promise<AppUserTypeBE | null>;
37
+ export declare const unitAppUserById: ({ id, prisma, }: UnitAppUserByIdArgs) => Promise<AppUserBE | null>;
38
38
  /**
39
39
  * Creates a new app user or updates an existing one
40
40
  * @param {UpdateAppUserArgs} args - Object containing prisma client and user data
41
- * @returns {Promise<AppUserTypeBE>} Created or updated app user
41
+ * @returns {Promise<AppUserBE>} Created or updated app user
42
42
  */
43
- export declare const updateAppUser: ({ email, firstName, id, lastName, prisma, }: UpdateAppUserArgs) => Promise<AppUserTypeBE>;
43
+ export declare const updateAppUser: ({ email, firstName, id, lastName, prisma, }: UpdateAppUserArgs) => Promise<AppUserBE>;
44
44
  /**
45
45
  * Deletes an app user by ID
46
46
  * @param {DeleteAppUserArgs} args - Object containing prisma client and user query
47
- * @returns {Promise<AppUserTypeBE>} Deleted app user
47
+ * @returns {Promise<AppUserBE>} Deleted app user
48
48
  * @throws {Error} If user ID is not provided or user not found
49
49
  */
50
- export declare const deleteAppUser: ({ id, prisma, }: DeleteAppUserArgs) => Promise<AppUserTypeBE>;
50
+ export declare const deleteAppUser: ({ id, prisma, }: DeleteAppUserArgs) => Promise<AppUserBE>;
51
51
  export {};
@@ -61,7 +61,7 @@ var general_1 = require("../../../general");
61
61
  /**
62
62
  * Retrieves all app users from the database with pagination
63
63
  * @param {ListAppUserArgs} args - Object containing prisma client, pagination, and query options
64
- * @returns {Promise<[number, Array<AppUserTypeBE>]>} Tuple of [total count, array of app users]
64
+ * @returns {Promise<[number, Array<AppUserBE>]>} Tuple of [total count, array of app users]
65
65
  */
66
66
  var listAppUser = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
67
67
  var orderBy, idSearchQuery, emailSearchQuery, firstNameSearchQuery, lastNameSearchQuery, where, _c, count, items;
@@ -119,7 +119,7 @@ exports.listAppUser = listAppUser;
119
119
  /**
120
120
  * Retrieves a single app user by ID
121
121
  * @param {UnitAppUserByIdArgs} args - Object containing prisma client and user query
122
- * @returns {Promise<AppUserTypeBE | null>} App user if found, null otherwise
122
+ * @returns {Promise<AppUserBE | null>} App user if found, null otherwise
123
123
  */
124
124
  var unitAppUserById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
125
125
  var where, appUser;
@@ -146,7 +146,7 @@ exports.unitAppUserById = unitAppUserById;
146
146
  /**
147
147
  * Creates a new app user or updates an existing one
148
148
  * @param {UpdateAppUserArgs} args - Object containing prisma client and user data
149
- * @returns {Promise<AppUserTypeBE>} Created or updated app user
149
+ * @returns {Promise<AppUserBE>} Created or updated app user
150
150
  */
151
151
  var updateAppUser = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
152
152
  var userData, where, appUser;
@@ -183,7 +183,7 @@ exports.updateAppUser = updateAppUser;
183
183
  /**
184
184
  * Deletes an app user by ID
185
185
  * @param {DeleteAppUserArgs} args - Object containing prisma client and user query
186
- * @returns {Promise<AppUserTypeBE>} Deleted app user
186
+ * @returns {Promise<AppUserBE>} Deleted app user
187
187
  * @throws {Error} If user ID is not provided or user not found
188
188
  */
189
189
  var deleteAppUser = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
@@ -0,0 +1,99 @@
1
+ import { BankBE } from '../type';
2
+ /**
3
+ * Synchronous utility function to get banks 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 BankBE[] - Array of cached banks or empty array wrapper ({count, items})
8
+ *
9
+ * @example
10
+ * const banks = getCachedBanksSync();
11
+ * if (banks.items.length > 0) {
12
+ * console.log(banks.items[0].bankName);
13
+ * }
14
+ */
15
+ export declare const getCachedBanksSync: () => {
16
+ count: number;
17
+ items: BankBE[];
18
+ };
19
+ /**
20
+ * Utility function to get banks from cache or fetch from API
21
+ *
22
+ * This function manages a localStorage cache of banks with the following logic:
23
+ * - If banks exist in cache and are less than 1 week old, return cached version
24
+ * - If banks exist but are older than 1 week, fetch fresh data and update cache
25
+ * - If banks don't exist in cache, fetch from API and cache them
26
+ *
27
+ * @returns Promise<{count:number, items: BankBE[]}> - Paged banks
28
+ *
29
+ * @example
30
+ * const banks = await getCachedBanks();
31
+ * console.log(banks.items[0].bankName);
32
+ */
33
+ export declare const getCachedBanks: () => Promise<{
34
+ count: number;
35
+ items: BankBE[];
36
+ }>;
37
+ /**
38
+ * Utility function to get a specific bank by ID from cache
39
+ * If not found in cache, returns null (does not trigger API call)
40
+ *
41
+ * @param bankId - The ID of the bank to retrieve
42
+ * @returns BankBE | null - The bank or null if not found
43
+ *
44
+ * @example
45
+ * const bank = getCachedBankById('bank-123');
46
+ * if (bank) {
47
+ * console.log(bank.bankName);
48
+ * }
49
+ */
50
+ export declare const getCachedBankById: (bankId: string) => BankBE | null;
51
+ /**
52
+ * Utility function to get a specific bank by account number from cache
53
+ * If not found in cache, returns null (does not trigger API call)
54
+ *
55
+ * @param accountNumber - The account number of the bank to retrieve
56
+ * @returns BankBE | null - The bank or null if not found
57
+ *
58
+ * @example
59
+ * const bank = getCachedBankByAccountNumber('1234567890');
60
+ * if (bank) {
61
+ * console.log(bank.bankName);
62
+ * }
63
+ */
64
+ export declare const getCachedBankByAccountNumber: (accountNumber: string) => BankBE | null;
65
+ /**
66
+ * Utility function to invalidate (remove) banks from cache
67
+ * Useful when banks have been updated and you want to force a refresh
68
+ *
69
+ * @example
70
+ * invalidateBanksCache();
71
+ * const freshBanks = await getCachedBanks();
72
+ */
73
+ export declare const invalidateBanksCache: () => void;
74
+ /**
75
+ * Utility function to preload banks into cache
76
+ * Useful to call on app initialization or login
77
+ *
78
+ * @returns Promise<{count:number, items: BankBE[]}> - Array of preloaded banks
79
+ *
80
+ * @example
81
+ * // On app initialization
82
+ * await preloadBanks();
83
+ */
84
+ export declare const preloadBanks: () => Promise<{
85
+ count: number;
86
+ items: BankBE[];
87
+ }>;
88
+ /**
89
+ * Utility function to check if banks cache is stale
90
+ * Returns true if cache is older than 1 week or doesn't exist
91
+ *
92
+ * @returns boolean - True if cache is stale or doesn't exist
93
+ *
94
+ * @example
95
+ * if (isBanksCacheStale()) {
96
+ * await getCachedBanks(); // This will fetch fresh data
97
+ * }
98
+ */
99
+ export declare const isBanksCacheStale: () => 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.isBanksCacheStale = exports.preloadBanks = exports.invalidateBanksCache = exports.getCachedBankByAccountNumber = exports.getCachedBankById = exports.getCachedBanks = exports.getCachedBanksSync = 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 banks 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 BankBE[] - Array of cached banks or empty array wrapper ({count, items})
52
+ *
53
+ * @example
54
+ * const banks = getCachedBanksSync();
55
+ * if (banks.items.length > 0) {
56
+ * console.log(banks.items[0].bankName);
57
+ * }
58
+ */
59
+ var getCachedBanksSync = function () {
60
+ try {
61
+ var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.BANKS);
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.banks.length,
72
+ items: cachedData.banks,
73
+ };
74
+ }
75
+ return { count: 0, items: [] };
76
+ }
77
+ catch (error) {
78
+ console.error('Error getting cached banks:', error);
79
+ return { count: 0, items: [] };
80
+ }
81
+ };
82
+ exports.getCachedBanksSync = getCachedBanksSync;
83
+ /**
84
+ * Utility function to get banks from cache or fetch from API
85
+ *
86
+ * This function manages a localStorage cache of banks with the following logic:
87
+ * - If banks exist in cache and are less than 1 week old, return cached version
88
+ * - If banks exist but are older than 1 week, fetch fresh data and update cache
89
+ * - If banks don't exist in cache, fetch from API and cache them
90
+ *
91
+ * @returns Promise<{count:number, items: BankBE[]}> - Paged banks
92
+ *
93
+ * @example
94
+ * const banks = await getCachedBanks();
95
+ * console.log(banks.items[0].bankName);
96
+ */
97
+ var getCachedBanks = 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.BANKS);
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.banks.length,
114
+ items: cachedData.banks,
115
+ }];
116
+ }
117
+ }
118
+ return [4 /*yield*/, (0, fetch_data_1.fetchData)({
119
+ url: constants_1.API_ROUTES.BANKS,
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
+ banks: response.data.items,
127
+ cachedAt: new Date().toISOString(),
128
+ };
129
+ (0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.BANKS, 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 banks:', error_1);
136
+ return [2 /*return*/, { count: 0, items: [] }];
137
+ case 3: return [2 /*return*/];
138
+ }
139
+ });
140
+ }); };
141
+ exports.getCachedBanks = getCachedBanks;
142
+ /**
143
+ * Utility function to get a specific bank by ID from cache
144
+ * If not found in cache, returns null (does not trigger API call)
145
+ *
146
+ * @param bankId - The ID of the bank to retrieve
147
+ * @returns BankBE | null - The bank or null if not found
148
+ *
149
+ * @example
150
+ * const bank = getCachedBankById('bank-123');
151
+ * if (bank) {
152
+ * console.log(bank.bankName);
153
+ * }
154
+ */
155
+ var getCachedBankById = function (bankId) {
156
+ if (!bankId) {
157
+ return null;
158
+ }
159
+ try {
160
+ var banks = (0, exports.getCachedBanksSync)().items;
161
+ return banks.find(function (bank) { return bank.id === bankId; }) || null;
162
+ }
163
+ catch (error) {
164
+ console.error('Error getting cached bank by ID:', error);
165
+ return null;
166
+ }
167
+ };
168
+ exports.getCachedBankById = getCachedBankById;
169
+ /**
170
+ * Utility function to get a specific bank by account number from cache
171
+ * If not found in cache, returns null (does not trigger API call)
172
+ *
173
+ * @param accountNumber - The account number of the bank to retrieve
174
+ * @returns BankBE | null - The bank or null if not found
175
+ *
176
+ * @example
177
+ * const bank = getCachedBankByAccountNumber('1234567890');
178
+ * if (bank) {
179
+ * console.log(bank.bankName);
180
+ * }
181
+ */
182
+ var getCachedBankByAccountNumber = function (accountNumber) {
183
+ if (!accountNumber) {
184
+ return null;
185
+ }
186
+ try {
187
+ var banks = (0, exports.getCachedBanksSync)().items;
188
+ return banks.find(function (bank) { return bank.accountNumber === accountNumber; }) || null;
189
+ }
190
+ catch (error) {
191
+ console.error('Error getting cached bank by account number:', error);
192
+ return null;
193
+ }
194
+ };
195
+ exports.getCachedBankByAccountNumber = getCachedBankByAccountNumber;
196
+ /**
197
+ * Utility function to invalidate (remove) banks from cache
198
+ * Useful when banks have been updated and you want to force a refresh
199
+ *
200
+ * @example
201
+ * invalidateBanksCache();
202
+ * const freshBanks = await getCachedBanks();
203
+ */
204
+ var invalidateBanksCache = function () {
205
+ try {
206
+ localStorage.removeItem(type_1.LS_KEYS.BANKS);
207
+ }
208
+ catch (error) {
209
+ console.error('Error invalidating banks cache:', error);
210
+ }
211
+ };
212
+ exports.invalidateBanksCache = invalidateBanksCache;
213
+ /**
214
+ * Utility function to preload banks into cache
215
+ * Useful to call on app initialization or login
216
+ *
217
+ * @returns Promise<{count:number, items: BankBE[]}> - Array of preloaded banks
218
+ *
219
+ * @example
220
+ * // On app initialization
221
+ * await preloadBanks();
222
+ */
223
+ var preloadBanks = function () { return __awaiter(void 0, void 0, void 0, function () {
224
+ return __generator(this, function (_a) {
225
+ return [2 /*return*/, (0, exports.getCachedBanks)()];
226
+ });
227
+ }); };
228
+ exports.preloadBanks = preloadBanks;
229
+ /**
230
+ * Utility function to check if banks 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 (isBanksCacheStale()) {
237
+ * await getCachedBanks(); // This will fetch fresh data
238
+ * }
239
+ */
240
+ var isBanksCacheStale = function () {
241
+ try {
242
+ var cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.BANKS);
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 banks cache staleness:', error);
253
+ return true;
254
+ }
255
+ };
256
+ exports.isBanksCacheStale = isBanksCacheStale;
@@ -1,4 +1,5 @@
1
- import { BankTypeBE } from '../type';
1
+ export * from './cache';
2
+ import { BankBE } from '../type';
2
3
  type PrismaClient = any;
3
4
  export interface ListBankArgs {
4
5
  currentPage?: number;
@@ -34,26 +35,25 @@ export interface DeleteBankArgs {
34
35
  /**
35
36
  * Retrieves all banks from the database with pagination
36
37
  * @param {ListBankArgs} args - Object containing prisma client, pagination, and filter options
37
- * @returns {Promise<[number, Array<BankTypeBE>]>} Tuple of [total count, array of banks]
38
+ * @returns {Promise<[number, Array<BankBE>]>} Tuple of [total count, array of banks]
38
39
  */
39
- export declare const listBank: ({ currentPage, includePreference, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListBankArgs) => Promise<[number, Array<BankTypeBE>]>;
40
+ export declare const listBank: ({ currentPage, includePreference, orderByColumn, orderByDirection, pageLimit, prisma, searchQuery, }: ListBankArgs) => Promise<[number, Array<BankBE>]>;
40
41
  /**
41
42
  * Retrieves a single bank by ID
42
43
  * @param {UnitBankByIdArgs} args - Object containing prisma client and bank id
43
- * @returns {Promise<BankTypeBE | null>} Bank if found, null otherwise
44
+ * @returns {Promise<BankBE | null>} Bank if found, null otherwise
44
45
  */
45
- export declare const unitBankById: ({ id, includePreference, prisma, }: UnitBankByIdArgs) => Promise<BankTypeBE | null>;
46
+ export declare const unitBankById: ({ id, includePreference, prisma, }: UnitBankByIdArgs) => Promise<BankBE | null>;
46
47
  /**
47
48
  * Creates a new bank or updates an existing one
48
49
  * @param {UpdateBankArgs} args - Object containing prisma client and bank data
49
- * @returns {Promise<BankTypeBE>} Created or updated bank
50
+ * @returns {Promise<BankBE>} Created or updated bank
50
51
  */
51
- export declare const updateBank: ({ accountNumber, accountTitle, bankAddress, bankName, enabled, iban, id, isDefault, preferenceId, prisma, swiftCode, }: UpdateBankArgs) => Promise<BankTypeBE>;
52
+ export declare const updateBank: ({ accountNumber, accountTitle, bankAddress, bankName, enabled, iban, id, isDefault, preferenceId, prisma, swiftCode, }: UpdateBankArgs) => Promise<BankBE>;
52
53
  /**
53
54
  * Deletes a bank by ID
54
55
  * @param {DeleteBankArgs} args - Object containing prisma client and bank id
55
- * @returns {Promise<BankTypeBE>} Deleted bank
56
+ * @returns {Promise<BankBE>} Deleted bank
56
57
  * @throws {Error} If bank ID is not provided or bank not found
57
58
  */
58
- export declare const deleteBank: ({ prisma, id, }: DeleteBankArgs) => Promise<BankTypeBE>;
59
- export {};
59
+ export declare const deleteBank: ({ prisma, id, }: DeleteBankArgs) => Promise<BankBE>;
@@ -10,6 +10,20 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
+ };
13
27
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
28
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
29
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -57,11 +71,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
71
  };
58
72
  Object.defineProperty(exports, "__esModule", { value: true });
59
73
  exports.deleteBank = exports.updateBank = exports.unitBankById = exports.listBank = void 0;
74
+ __exportStar(require("./cache"), exports);
60
75
  var multi_part_search_1 = require("../../../general/multi-part-search");
61
76
  /**
62
77
  * Retrieves all banks from the database with pagination
63
78
  * @param {ListBankArgs} args - Object containing prisma client, pagination, and filter options
64
- * @returns {Promise<[number, Array<BankTypeBE>]>} Tuple of [total count, array of banks]
79
+ * @returns {Promise<[number, Array<BankBE>]>} Tuple of [total count, array of banks]
65
80
  */
66
81
  var listBank = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
67
82
  var include, orderBy, idSearchQuery, bankNameSearchQuery, where, _c, count, items;
@@ -115,7 +130,7 @@ exports.listBank = listBank;
115
130
  /**
116
131
  * Retrieves a single bank by ID
117
132
  * @param {UnitBankByIdArgs} args - Object containing prisma client and bank id
118
- * @returns {Promise<BankTypeBE | null>} Bank if found, null otherwise
133
+ * @returns {Promise<BankBE | null>} Bank if found, null otherwise
119
134
  */
120
135
  var unitBankById = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
121
136
  var include, where, bank;
@@ -144,7 +159,7 @@ exports.unitBankById = unitBankById;
144
159
  /**
145
160
  * Creates a new bank or updates an existing one
146
161
  * @param {UpdateBankArgs} args - Object containing prisma client and bank data
147
- * @returns {Promise<BankTypeBE>} Created or updated bank
162
+ * @returns {Promise<BankBE>} Created or updated bank
148
163
  */
149
164
  var updateBank = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
150
165
  var bankData, where, bank;
@@ -185,7 +200,7 @@ exports.updateBank = updateBank;
185
200
  /**
186
201
  * Deletes a bank by ID
187
202
  * @param {DeleteBankArgs} args - Object containing prisma client and bank id
188
- * @returns {Promise<BankTypeBE>} Deleted bank
203
+ * @returns {Promise<BankBE>} Deleted bank
189
204
  * @throws {Error} If bank ID is not provided or bank not found
190
205
  */
191
206
  var deleteBank = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
@@ -0,0 +1,97 @@
1
+ import { BranchBE } from '../type';
2
+ /**
3
+ * Synchronous utility function to get branches 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 BranchBE[] - Array of cached branches or empty array wrapper ({count, items})
8
+ *
9
+ * @example
10
+ * const branches = getCachedBranchesSync();
11
+ * if (branches.items.length > 0) {
12
+ * console.log(branches.items[0].branchName);
13
+ * }
14
+ */
15
+ export declare const getCachedBranchesSync: () => {
16
+ count: number;
17
+ items: BranchBE[];
18
+ };
19
+ /**
20
+ * Utility function to get branches from cache or fetch from API
21
+ *
22
+ * This function manages a localStorage cache of branches with the following logic:
23
+ * - If branches exist in cache and are less than 1 week old, return cached version
24
+ * - If branches exist but are older than 1 week, fetch fresh data and update cache
25
+ * - If branches don't exist in cache, fetch from API and cache them
26
+ *
27
+ * @returns Promise<{count:number, items: BranchBE[]}> - Paged branches
28
+ *
29
+ * @example
30
+ * const branches = await getCachedBranches();
31
+ * console.log(branches.items[0].branchName);
32
+ */
33
+ export declare const getCachedBranches: () => Promise<{
34
+ count: number;
35
+ items: BranchBE[];
36
+ }>;
37
+ /**
38
+ * Utility function to get a specific branch by ID from cache
39
+ * If not found in cache, returns null (does not trigger API call)
40
+ *
41
+ * @param branchId - The ID of the branch to retrieve
42
+ * @returns BranchBE | null - The branch or null if not found
43
+ *
44
+ * @example
45
+ * const branch = getCachedBranchById('branch-123');
46
+ * if (branch) {
47
+ * console.log(branch.branchName);
48
+ * }
49
+ */
50
+ export declare const getCachedBranchById: (branchId: string) => BranchBE | null;
51
+ /**
52
+ * Utility function to get branches by name from cache
53
+ * If not found in cache, returns empty array (does not trigger API call)
54
+ *
55
+ * @param branchName - The name of the branch to search for
56
+ * @returns BranchBE[] - Array of matching branches or empty array
57
+ *
58
+ * @example
59
+ * const branches = getCachedBranchesByName('Main Branch');
60
+ * console.log(branches.length);
61
+ */
62
+ export declare const getCachedBranchesByName: (branchName: string) => BranchBE[];
63
+ /**
64
+ * Utility function to invalidate (remove) branches from cache
65
+ * Useful when branches have been updated and you want to force a refresh
66
+ *
67
+ * @example
68
+ * invalidateBranchesCache();
69
+ * const freshBranches = await getCachedBranches();
70
+ */
71
+ export declare const invalidateBranchesCache: () => void;
72
+ /**
73
+ * Utility function to preload branches into cache
74
+ * Useful to call on app initialization or login
75
+ *
76
+ * @returns Promise<{count:number, items: BranchBE[]}> - Array of preloaded branches
77
+ *
78
+ * @example
79
+ * // On app initialization
80
+ * await preloadBranches();
81
+ */
82
+ export declare const preloadBranches: () => Promise<{
83
+ count: number;
84
+ items: BranchBE[];
85
+ }>;
86
+ /**
87
+ * Utility function to check if branches 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 (isBranchesCacheStale()) {
94
+ * await getCachedBranches(); // This will fetch fresh data
95
+ * }
96
+ */
97
+ export declare const isBranchesCacheStale: () => boolean;