@react-pakistan/util-functions 1.25.9 → 1.25.11

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