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