@react-pakistan/util-functions 1.25.1 → 1.25.3
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.
- package/api/stellar-solutions/bank/cache.d.ts +6 -1
- package/api/stellar-solutions/bank/cache.js +81 -42
- package/api/stellar-solutions/branch/cache.d.ts +6 -1
- package/api/stellar-solutions/branch/cache.js +81 -42
- package/api/stellar-solutions/currency/cache.d.ts +6 -1
- package/api/stellar-solutions/currency/cache.js +81 -42
- package/api/stellar-solutions/payment-mode/cache.d.ts +6 -1
- package/api/stellar-solutions/payment-mode/cache.js +81 -42
- package/api/stellar-solutions/preference/cache.d.ts +8 -3
- package/api/stellar-solutions/preference/cache.js +83 -44
- package/api/stellar-solutions/tax/cache.d.ts +6 -1
- package/api/stellar-solutions/tax/cache.js +81 -42
- package/package.json +1 -1
|
@@ -24,13 +24,18 @@ export declare const getCachedBanksSync: () => {
|
|
|
24
24
|
* - If banks exist but are older than 1 week, fetch fresh data and update cache
|
|
25
25
|
* - If banks don't exist in cache, fetch from API and cache them
|
|
26
26
|
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter banks
|
|
28
|
+
* @param pageLimit - Number of banks to fetch (default: 100)
|
|
27
29
|
* @returns Promise<{count:number, items: BankBE[]}> - Paged banks
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
30
32
|
* const banks = await getCachedBanks();
|
|
31
33
|
* console.log(banks.items[0].bankName);
|
|
34
|
+
*
|
|
35
|
+
* // With search
|
|
36
|
+
* const filtered = await getCachedBanks('Chase');
|
|
32
37
|
*/
|
|
33
|
-
export declare const getCachedBanks: () => Promise<{
|
|
38
|
+
export declare const getCachedBanks: (searchQuery?: string, pageLimit?: number) => Promise<{
|
|
34
39
|
count: number;
|
|
35
40
|
items: BankBE[];
|
|
36
41
|
}>;
|
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
48
|
exports.isBanksCacheStale = exports.preloadBanks = exports.invalidateBanksCache = exports.getCachedBankByAccountNumber = exports.getCachedBankById = exports.getCachedBanks = exports.getCachedBanksSync = void 0;
|
|
40
49
|
var constants_1 = require("../constants");
|
|
@@ -88,56 +97,86 @@ exports.getCachedBanksSync = getCachedBanksSync;
|
|
|
88
97
|
* - If banks exist but are older than 1 week, fetch fresh data and update cache
|
|
89
98
|
* - If banks don't exist in cache, fetch from API and cache them
|
|
90
99
|
*
|
|
100
|
+
* @param searchQuery - Optional search query to filter banks
|
|
101
|
+
* @param pageLimit - Number of banks to fetch (default: 100)
|
|
91
102
|
* @returns Promise<{count:number, items: BankBE[]}> - Paged banks
|
|
92
103
|
*
|
|
93
104
|
* @example
|
|
94
105
|
* const banks = await getCachedBanks();
|
|
95
106
|
* console.log(banks.items[0].bankName);
|
|
107
|
+
*
|
|
108
|
+
* // With search
|
|
109
|
+
* const filtered = await getCachedBanks('Chase');
|
|
96
110
|
*/
|
|
97
|
-
var getCachedBanks = function () {
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
var getCachedBanks = function (searchQuery_1) {
|
|
112
|
+
var args_1 = [];
|
|
113
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
114
|
+
args_1[_i - 1] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
return __awaiter(void 0, __spreadArray([searchQuery_1], args_1, true), void 0, function (searchQuery, pageLimit) {
|
|
117
|
+
var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
118
|
+
var _a;
|
|
119
|
+
if (pageLimit === void 0) { pageLimit = 100; }
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
_b.trys.push([0, 4, , 5]);
|
|
124
|
+
if (!(searchQuery && searchQuery.trim())) return [3 /*break*/, 2];
|
|
125
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
126
|
+
url: constants_1.API_ROUTES.BANKS,
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
searchQuery: searchQuery,
|
|
129
|
+
pageLimit: pageLimit,
|
|
130
|
+
currentPage: 1,
|
|
131
|
+
}),
|
|
132
|
+
method: api_methods_1.API_METHODS.POST,
|
|
133
|
+
})];
|
|
134
|
+
case 1:
|
|
135
|
+
response_1 = _b.sent();
|
|
136
|
+
return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
|
|
137
|
+
case 2:
|
|
138
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.BANKS);
|
|
139
|
+
currentTime = new Date().getTime();
|
|
140
|
+
// Check if cached data exists and is still fresh
|
|
141
|
+
if (cachedData) {
|
|
142
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
143
|
+
ageInMs = currentTime - cachedTime;
|
|
144
|
+
// If cached data is less than 1 week old, return it
|
|
145
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
count: cachedData.banks.length,
|
|
148
|
+
items: cachedData.banks,
|
|
149
|
+
}];
|
|
150
|
+
}
|
|
116
151
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
153
|
+
url: constants_1.API_ROUTES.BANKS,
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
pageLimit: pageLimit,
|
|
156
|
+
currentPage: 1,
|
|
157
|
+
}),
|
|
158
|
+
method: api_methods_1.API_METHODS.POST,
|
|
159
|
+
})];
|
|
160
|
+
case 3:
|
|
161
|
+
response = _b.sent();
|
|
162
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
163
|
+
updatedCache = {
|
|
164
|
+
banks: response.data.items,
|
|
165
|
+
cachedAt: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.BANKS, updatedCache);
|
|
168
|
+
return [2 /*return*/, response.data];
|
|
169
|
+
}
|
|
170
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
171
|
+
case 4:
|
|
172
|
+
error_1 = _b.sent();
|
|
173
|
+
console.error('Error fetching banks:', error_1);
|
|
174
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
175
|
+
case 5: return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
139
178
|
});
|
|
140
|
-
}
|
|
179
|
+
};
|
|
141
180
|
exports.getCachedBanks = getCachedBanks;
|
|
142
181
|
/**
|
|
143
182
|
* Utility function to get a specific bank by ID from cache
|
|
@@ -24,13 +24,18 @@ export declare const getCachedBranchesSync: () => {
|
|
|
24
24
|
* - If branches exist but are older than 1 week, fetch fresh data and update cache
|
|
25
25
|
* - If branches don't exist in cache, fetch from API and cache them
|
|
26
26
|
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter branches
|
|
28
|
+
* @param pageLimit - Number of branches to fetch (default: 100)
|
|
27
29
|
* @returns Promise<{count:number, items: BranchBE[]}> - Paged branches
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
30
32
|
* const branches = await getCachedBranches();
|
|
31
33
|
* console.log(branches.items[0].branchName);
|
|
34
|
+
*
|
|
35
|
+
* // With search
|
|
36
|
+
* const filtered = await getCachedBranches('Main Branch');
|
|
32
37
|
*/
|
|
33
|
-
export declare const getCachedBranches: () => Promise<{
|
|
38
|
+
export declare const getCachedBranches: (searchQuery?: string, pageLimit?: number) => Promise<{
|
|
34
39
|
count: number;
|
|
35
40
|
items: BranchBE[];
|
|
36
41
|
}>;
|
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
48
|
exports.isBranchesCacheStale = exports.preloadBranches = exports.invalidateBranchesCache = exports.getCachedBranchesByName = exports.getCachedBranchById = exports.getCachedBranches = exports.getCachedBranchesSync = void 0;
|
|
40
49
|
var constants_1 = require("../constants");
|
|
@@ -88,56 +97,86 @@ exports.getCachedBranchesSync = getCachedBranchesSync;
|
|
|
88
97
|
* - If branches exist but are older than 1 week, fetch fresh data and update cache
|
|
89
98
|
* - If branches don't exist in cache, fetch from API and cache them
|
|
90
99
|
*
|
|
100
|
+
* @param searchQuery - Optional search query to filter branches
|
|
101
|
+
* @param pageLimit - Number of branches to fetch (default: 100)
|
|
91
102
|
* @returns Promise<{count:number, items: BranchBE[]}> - Paged branches
|
|
92
103
|
*
|
|
93
104
|
* @example
|
|
94
105
|
* const branches = await getCachedBranches();
|
|
95
106
|
* console.log(branches.items[0].branchName);
|
|
107
|
+
*
|
|
108
|
+
* // With search
|
|
109
|
+
* const filtered = await getCachedBranches('Main Branch');
|
|
96
110
|
*/
|
|
97
|
-
var getCachedBranches = function () {
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
var getCachedBranches = function (searchQuery_1) {
|
|
112
|
+
var args_1 = [];
|
|
113
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
114
|
+
args_1[_i - 1] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
return __awaiter(void 0, __spreadArray([searchQuery_1], args_1, true), void 0, function (searchQuery, pageLimit) {
|
|
117
|
+
var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
118
|
+
var _a;
|
|
119
|
+
if (pageLimit === void 0) { pageLimit = 100; }
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
_b.trys.push([0, 4, , 5]);
|
|
124
|
+
if (!(searchQuery && searchQuery.trim())) return [3 /*break*/, 2];
|
|
125
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
126
|
+
url: constants_1.API_ROUTES.BRANCHES,
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
searchQuery: searchQuery,
|
|
129
|
+
pageLimit: pageLimit,
|
|
130
|
+
currentPage: 1,
|
|
131
|
+
}),
|
|
132
|
+
method: api_methods_1.API_METHODS.POST,
|
|
133
|
+
})];
|
|
134
|
+
case 1:
|
|
135
|
+
response_1 = _b.sent();
|
|
136
|
+
return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
|
|
137
|
+
case 2:
|
|
138
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.BRANCHES);
|
|
139
|
+
currentTime = new Date().getTime();
|
|
140
|
+
// Check if cached data exists and is still fresh
|
|
141
|
+
if (cachedData) {
|
|
142
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
143
|
+
ageInMs = currentTime - cachedTime;
|
|
144
|
+
// If cached data is less than 1 week old, return it
|
|
145
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
count: cachedData.branches.length,
|
|
148
|
+
items: cachedData.branches,
|
|
149
|
+
}];
|
|
150
|
+
}
|
|
116
151
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
153
|
+
url: constants_1.API_ROUTES.BRANCHES,
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
pageLimit: pageLimit,
|
|
156
|
+
currentPage: 1,
|
|
157
|
+
}),
|
|
158
|
+
method: api_methods_1.API_METHODS.POST,
|
|
159
|
+
})];
|
|
160
|
+
case 3:
|
|
161
|
+
response = _b.sent();
|
|
162
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
163
|
+
updatedCache = {
|
|
164
|
+
branches: response.data.items,
|
|
165
|
+
cachedAt: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.BRANCHES, updatedCache);
|
|
168
|
+
return [2 /*return*/, response.data];
|
|
169
|
+
}
|
|
170
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
171
|
+
case 4:
|
|
172
|
+
error_1 = _b.sent();
|
|
173
|
+
console.error('Error fetching branches:', error_1);
|
|
174
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
175
|
+
case 5: return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
139
178
|
});
|
|
140
|
-
}
|
|
179
|
+
};
|
|
141
180
|
exports.getCachedBranches = getCachedBranches;
|
|
142
181
|
/**
|
|
143
182
|
* Utility function to get a specific branch by ID from cache
|
|
@@ -24,13 +24,18 @@ export declare const getCachedCurrenciesSync: () => {
|
|
|
24
24
|
* - If currencies exist but are older than 1 week, fetch fresh data and update cache
|
|
25
25
|
* - If currencies don't exist in cache, fetch from API and cache them
|
|
26
26
|
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter currencies
|
|
28
|
+
* @param pageLimit - Number of currencies to fetch (default: 100)
|
|
27
29
|
* @returns Promise<{count:number, items: CurrencyBE[]}> - Paged currencies
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
30
32
|
* const currencies = await getCachedCurrencies();
|
|
31
33
|
* console.log(currencies.items[0].label);
|
|
34
|
+
*
|
|
35
|
+
* // With search
|
|
36
|
+
* const filtered = await getCachedCurrencies('USD');
|
|
32
37
|
*/
|
|
33
|
-
export declare const getCachedCurrencies: () => Promise<{
|
|
38
|
+
export declare const getCachedCurrencies: (searchQuery?: string, pageLimit?: number) => Promise<{
|
|
34
39
|
count: number;
|
|
35
40
|
items: CurrencyBE[];
|
|
36
41
|
}>;
|
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
48
|
exports.isCurrenciesCacheStale = exports.preloadCurrencies = exports.invalidateCurrenciesCache = exports.getCachedCurrencyByCode = exports.getCachedCurrencyById = exports.getCachedCurrencies = exports.getCachedCurrenciesSync = void 0;
|
|
40
49
|
var constants_1 = require("../constants");
|
|
@@ -88,56 +97,86 @@ exports.getCachedCurrenciesSync = getCachedCurrenciesSync;
|
|
|
88
97
|
* - If currencies exist but are older than 1 week, fetch fresh data and update cache
|
|
89
98
|
* - If currencies don't exist in cache, fetch from API and cache them
|
|
90
99
|
*
|
|
100
|
+
* @param searchQuery - Optional search query to filter currencies
|
|
101
|
+
* @param pageLimit - Number of currencies to fetch (default: 100)
|
|
91
102
|
* @returns Promise<{count:number, items: CurrencyBE[]}> - Paged currencies
|
|
92
103
|
*
|
|
93
104
|
* @example
|
|
94
105
|
* const currencies = await getCachedCurrencies();
|
|
95
106
|
* console.log(currencies.items[0].label);
|
|
107
|
+
*
|
|
108
|
+
* // With search
|
|
109
|
+
* const filtered = await getCachedCurrencies('USD');
|
|
96
110
|
*/
|
|
97
|
-
var getCachedCurrencies = function () {
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
var getCachedCurrencies = function (searchQuery_1) {
|
|
112
|
+
var args_1 = [];
|
|
113
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
114
|
+
args_1[_i - 1] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
return __awaiter(void 0, __spreadArray([searchQuery_1], args_1, true), void 0, function (searchQuery, pageLimit) {
|
|
117
|
+
var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
118
|
+
var _a;
|
|
119
|
+
if (pageLimit === void 0) { pageLimit = 100; }
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
_b.trys.push([0, 4, , 5]);
|
|
124
|
+
if (!(searchQuery && searchQuery.trim())) return [3 /*break*/, 2];
|
|
125
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
126
|
+
url: constants_1.API_ROUTES.CURRENCIES,
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
searchQuery: searchQuery,
|
|
129
|
+
pageLimit: pageLimit,
|
|
130
|
+
currentPage: 1,
|
|
131
|
+
}),
|
|
132
|
+
method: api_methods_1.API_METHODS.POST,
|
|
133
|
+
})];
|
|
134
|
+
case 1:
|
|
135
|
+
response_1 = _b.sent();
|
|
136
|
+
return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
|
|
137
|
+
case 2:
|
|
138
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.CURRENCIES);
|
|
139
|
+
currentTime = new Date().getTime();
|
|
140
|
+
// Check if cached data exists and is still fresh
|
|
141
|
+
if (cachedData) {
|
|
142
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
143
|
+
ageInMs = currentTime - cachedTime;
|
|
144
|
+
// If cached data is less than 1 week old, return it
|
|
145
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
count: cachedData.currencies.length,
|
|
148
|
+
items: cachedData.currencies,
|
|
149
|
+
}];
|
|
150
|
+
}
|
|
116
151
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
153
|
+
url: constants_1.API_ROUTES.CURRENCIES,
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
pageLimit: pageLimit,
|
|
156
|
+
currentPage: 1,
|
|
157
|
+
}),
|
|
158
|
+
method: api_methods_1.API_METHODS.POST,
|
|
159
|
+
})];
|
|
160
|
+
case 3:
|
|
161
|
+
response = _b.sent();
|
|
162
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
163
|
+
updatedCache = {
|
|
164
|
+
currencies: response.data.items,
|
|
165
|
+
cachedAt: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.CURRENCIES, updatedCache);
|
|
168
|
+
return [2 /*return*/, response.data];
|
|
169
|
+
}
|
|
170
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
171
|
+
case 4:
|
|
172
|
+
error_1 = _b.sent();
|
|
173
|
+
console.error('Error fetching currencies:', error_1);
|
|
174
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
175
|
+
case 5: return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
139
178
|
});
|
|
140
|
-
}
|
|
179
|
+
};
|
|
141
180
|
exports.getCachedCurrencies = getCachedCurrencies;
|
|
142
181
|
/**
|
|
143
182
|
* Utility function to get a specific currency by ID from cache
|
|
@@ -24,13 +24,18 @@ export declare const getCachedPaymentModesSync: () => {
|
|
|
24
24
|
* - If payment modes exist but are older than 1 week, fetch fresh data and update cache
|
|
25
25
|
* - If payment modes don't exist in cache, fetch from API and cache them
|
|
26
26
|
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter payment modes
|
|
28
|
+
* @param pageLimit - Number of payment modes to fetch (default: 100)
|
|
27
29
|
* @returns Promise<{count:number, items: PaymentModeBE[]}> - Paged payment modes
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
30
32
|
* const paymentModes = await getCachedPaymentModes();
|
|
31
33
|
* console.log(paymentModes.items[0].label);
|
|
34
|
+
*
|
|
35
|
+
* // With search
|
|
36
|
+
* const filtered = await getCachedPaymentModes('Cash');
|
|
32
37
|
*/
|
|
33
|
-
export declare const getCachedPaymentModes: () => Promise<{
|
|
38
|
+
export declare const getCachedPaymentModes: (searchQuery?: string, pageLimit?: number) => Promise<{
|
|
34
39
|
count: number;
|
|
35
40
|
items: PaymentModeBE[];
|
|
36
41
|
}>;
|
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
48
|
exports.isPaymentModesCacheStale = exports.preloadPaymentModes = exports.invalidatePaymentModesCache = exports.getCachedPaymentModesByLabel = exports.getCachedPaymentModeById = exports.getCachedPaymentModes = exports.getCachedPaymentModesSync = void 0;
|
|
40
49
|
var constants_1 = require("../constants");
|
|
@@ -88,56 +97,86 @@ exports.getCachedPaymentModesSync = getCachedPaymentModesSync;
|
|
|
88
97
|
* - If payment modes exist but are older than 1 week, fetch fresh data and update cache
|
|
89
98
|
* - If payment modes don't exist in cache, fetch from API and cache them
|
|
90
99
|
*
|
|
100
|
+
* @param searchQuery - Optional search query to filter payment modes
|
|
101
|
+
* @param pageLimit - Number of payment modes to fetch (default: 100)
|
|
91
102
|
* @returns Promise<{count:number, items: PaymentModeBE[]}> - Paged payment modes
|
|
92
103
|
*
|
|
93
104
|
* @example
|
|
94
105
|
* const paymentModes = await getCachedPaymentModes();
|
|
95
106
|
* console.log(paymentModes.items[0].label);
|
|
107
|
+
*
|
|
108
|
+
* // With search
|
|
109
|
+
* const filtered = await getCachedPaymentModes('Cash');
|
|
96
110
|
*/
|
|
97
|
-
var getCachedPaymentModes = function () {
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
var getCachedPaymentModes = function (searchQuery_1) {
|
|
112
|
+
var args_1 = [];
|
|
113
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
114
|
+
args_1[_i - 1] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
return __awaiter(void 0, __spreadArray([searchQuery_1], args_1, true), void 0, function (searchQuery, pageLimit) {
|
|
117
|
+
var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
118
|
+
var _a;
|
|
119
|
+
if (pageLimit === void 0) { pageLimit = 100; }
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
_b.trys.push([0, 4, , 5]);
|
|
124
|
+
if (!(searchQuery && searchQuery.trim())) return [3 /*break*/, 2];
|
|
125
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
126
|
+
url: constants_1.API_ROUTES.PAYMENT_MODES,
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
searchQuery: searchQuery,
|
|
129
|
+
pageLimit: pageLimit,
|
|
130
|
+
currentPage: 1,
|
|
131
|
+
}),
|
|
132
|
+
method: api_methods_1.API_METHODS.POST,
|
|
133
|
+
})];
|
|
134
|
+
case 1:
|
|
135
|
+
response_1 = _b.sent();
|
|
136
|
+
return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
|
|
137
|
+
case 2:
|
|
138
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PAYMENT_MODES);
|
|
139
|
+
currentTime = new Date().getTime();
|
|
140
|
+
// Check if cached data exists and is still fresh
|
|
141
|
+
if (cachedData) {
|
|
142
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
143
|
+
ageInMs = currentTime - cachedTime;
|
|
144
|
+
// If cached data is less than 1 week old, return it
|
|
145
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
count: cachedData.paymentModes.length,
|
|
148
|
+
items: cachedData.paymentModes,
|
|
149
|
+
}];
|
|
150
|
+
}
|
|
116
151
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
153
|
+
url: constants_1.API_ROUTES.PAYMENT_MODES,
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
pageLimit: pageLimit,
|
|
156
|
+
currentPage: 1,
|
|
157
|
+
}),
|
|
158
|
+
method: api_methods_1.API_METHODS.POST,
|
|
159
|
+
})];
|
|
160
|
+
case 3:
|
|
161
|
+
response = _b.sent();
|
|
162
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
163
|
+
updatedCache = {
|
|
164
|
+
paymentModes: response.data.items,
|
|
165
|
+
cachedAt: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.PAYMENT_MODES, updatedCache);
|
|
168
|
+
return [2 /*return*/, response.data];
|
|
169
|
+
}
|
|
170
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
171
|
+
case 4:
|
|
172
|
+
error_1 = _b.sent();
|
|
173
|
+
console.error('Error fetching payment modes:', error_1);
|
|
174
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
175
|
+
case 5: return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
139
178
|
});
|
|
140
|
-
}
|
|
179
|
+
};
|
|
141
180
|
exports.getCachedPaymentModes = getCachedPaymentModes;
|
|
142
181
|
/**
|
|
143
182
|
* Utility function to get a specific payment mode by ID from cache
|
|
@@ -20,17 +20,22 @@ export declare const getCachedPreferencesSync: () => {
|
|
|
20
20
|
* Utility function to get preferences from cache or fetch from API
|
|
21
21
|
*
|
|
22
22
|
* This function manages a localStorage cache of preferences with the following logic:
|
|
23
|
-
* - If preferences exist in cache and are less than 1
|
|
24
|
-
* - If preferences exist but are older than 1
|
|
23
|
+
* - If preferences exist in cache and are less than 1 week old, return cached version
|
|
24
|
+
* - If preferences exist but are older than 1 week, fetch fresh data and update cache
|
|
25
25
|
* - If preferences don't exist in cache, fetch from API and cache them
|
|
26
26
|
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter preferences
|
|
28
|
+
* @param pageLimit - Number of preferences to fetch (default: 100)
|
|
27
29
|
* @returns Promise<{count:number, items: PreferenceBE[]}> - Paged preferences
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
30
32
|
* const preferences = await getCachedPreferences();
|
|
31
33
|
* console.log(preferences.items[0].onboarding);
|
|
34
|
+
*
|
|
35
|
+
* // With search
|
|
36
|
+
* const filtered = await getCachedPreferences('theme');
|
|
32
37
|
*/
|
|
33
|
-
export declare const getCachedPreferences: () => Promise<{
|
|
38
|
+
export declare const getCachedPreferences: (searchQuery?: string, pageLimit?: number) => Promise<{
|
|
34
39
|
count: number;
|
|
35
40
|
items: PreferenceBE[];
|
|
36
41
|
}>;
|
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
48
|
exports.isPreferencesCacheStale = exports.preloadPreferences = exports.invalidatePreferencesCache = exports.getCachedPreferenceById = exports.getCachedPreferences = exports.getCachedPreferencesSync = void 0;
|
|
40
49
|
var constants_1 = require("../constants");
|
|
@@ -84,60 +93,90 @@ exports.getCachedPreferencesSync = getCachedPreferencesSync;
|
|
|
84
93
|
* Utility function to get preferences from cache or fetch from API
|
|
85
94
|
*
|
|
86
95
|
* This function manages a localStorage cache of preferences with the following logic:
|
|
87
|
-
* - If preferences exist in cache and are less than 1
|
|
88
|
-
* - If preferences exist but are older than 1
|
|
96
|
+
* - If preferences exist in cache and are less than 1 week old, return cached version
|
|
97
|
+
* - If preferences exist but are older than 1 week, fetch fresh data and update cache
|
|
89
98
|
* - If preferences don't exist in cache, fetch from API and cache them
|
|
90
99
|
*
|
|
100
|
+
* @param searchQuery - Optional search query to filter preferences
|
|
101
|
+
* @param pageLimit - Number of preferences to fetch (default: 100)
|
|
91
102
|
* @returns Promise<{count:number, items: PreferenceBE[]}> - Paged preferences
|
|
92
103
|
*
|
|
93
104
|
* @example
|
|
94
105
|
* const preferences = await getCachedPreferences();
|
|
95
106
|
* console.log(preferences.items[0].onboarding);
|
|
107
|
+
*
|
|
108
|
+
* // With search
|
|
109
|
+
* const filtered = await getCachedPreferences('theme');
|
|
96
110
|
*/
|
|
97
|
-
var getCachedPreferences = function () {
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
var getCachedPreferences = function (searchQuery_1) {
|
|
112
|
+
var args_1 = [];
|
|
113
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
114
|
+
args_1[_i - 1] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
return __awaiter(void 0, __spreadArray([searchQuery_1], args_1, true), void 0, function (searchQuery, pageLimit) {
|
|
117
|
+
var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
118
|
+
var _a;
|
|
119
|
+
if (pageLimit === void 0) { pageLimit = 100; }
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
_b.trys.push([0, 4, , 5]);
|
|
124
|
+
if (!(searchQuery && searchQuery.trim())) return [3 /*break*/, 2];
|
|
125
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
126
|
+
url: constants_1.API_ROUTES.PREFERENCES,
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
searchQuery: searchQuery,
|
|
129
|
+
pageLimit: pageLimit,
|
|
130
|
+
currentPage: 1,
|
|
131
|
+
}),
|
|
132
|
+
method: api_methods_1.API_METHODS.POST,
|
|
133
|
+
})];
|
|
134
|
+
case 1:
|
|
135
|
+
response_1 = _b.sent();
|
|
136
|
+
return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
|
|
137
|
+
case 2:
|
|
138
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.PREFERENCES);
|
|
139
|
+
currentTime = new Date().getTime();
|
|
140
|
+
// Check if cached data exists and is still fresh
|
|
141
|
+
if (cachedData) {
|
|
142
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
143
|
+
ageInMs = currentTime - cachedTime;
|
|
144
|
+
// If cached data is less than 1 week old, return it
|
|
145
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
count: cachedData.preferences.length,
|
|
148
|
+
items: cachedData.preferences,
|
|
149
|
+
}];
|
|
150
|
+
}
|
|
116
151
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
153
|
+
url: constants_1.API_ROUTES.PREFERENCES,
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
pageLimit: pageLimit,
|
|
156
|
+
currentPage: 1,
|
|
157
|
+
}),
|
|
158
|
+
method: api_methods_1.API_METHODS.POST,
|
|
159
|
+
})];
|
|
160
|
+
case 3:
|
|
161
|
+
response = _b.sent();
|
|
162
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
163
|
+
updatedCache = {
|
|
164
|
+
preferences: response.data.items,
|
|
165
|
+
cachedAt: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.PREFERENCES, updatedCache);
|
|
168
|
+
return [2 /*return*/, response.data];
|
|
169
|
+
}
|
|
170
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
171
|
+
case 4:
|
|
172
|
+
error_1 = _b.sent();
|
|
173
|
+
console.error('Error fetching preferences:', error_1);
|
|
174
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
175
|
+
case 5: return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
139
178
|
});
|
|
140
|
-
}
|
|
179
|
+
};
|
|
141
180
|
exports.getCachedPreferences = getCachedPreferences;
|
|
142
181
|
/**
|
|
143
182
|
* Utility function to get a specific preference by ID from cache
|
|
@@ -24,13 +24,18 @@ export declare const getCachedTaxesSync: () => {
|
|
|
24
24
|
* - If taxes exist but are older than 1 week, fetch fresh data and update cache
|
|
25
25
|
* - If taxes don't exist in cache, fetch from API and cache them
|
|
26
26
|
*
|
|
27
|
+
* @param searchQuery - Optional search query to filter taxes
|
|
28
|
+
* @param pageLimit - Number of taxes to fetch (default: 100)
|
|
27
29
|
* @returns Promise<{count:number, items: TaxBE[]}> - Paged taxes
|
|
28
30
|
*
|
|
29
31
|
* @example
|
|
30
32
|
* const taxes = await getCachedTaxes();
|
|
31
33
|
* console.log(taxes.items[0].taxName);
|
|
34
|
+
*
|
|
35
|
+
* // With search
|
|
36
|
+
* const filtered = await getCachedTaxes('VAT');
|
|
32
37
|
*/
|
|
33
|
-
export declare const getCachedTaxes: () => Promise<{
|
|
38
|
+
export declare const getCachedTaxes: (searchQuery?: string, pageLimit?: number) => Promise<{
|
|
34
39
|
count: number;
|
|
35
40
|
items: TaxBE[];
|
|
36
41
|
}>;
|
|
@@ -35,6 +35,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
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
|
+
};
|
|
38
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
48
|
exports.isTaxesCacheStale = exports.preloadTaxes = exports.invalidateTaxesCache = exports.getCachedTaxesByName = exports.getCachedTaxById = exports.getCachedTaxes = exports.getCachedTaxesSync = void 0;
|
|
40
49
|
var constants_1 = require("../constants");
|
|
@@ -88,56 +97,86 @@ exports.getCachedTaxesSync = getCachedTaxesSync;
|
|
|
88
97
|
* - If taxes exist but are older than 1 week, fetch fresh data and update cache
|
|
89
98
|
* - If taxes don't exist in cache, fetch from API and cache them
|
|
90
99
|
*
|
|
100
|
+
* @param searchQuery - Optional search query to filter taxes
|
|
101
|
+
* @param pageLimit - Number of taxes to fetch (default: 100)
|
|
91
102
|
* @returns Promise<{count:number, items: TaxBE[]}> - Paged taxes
|
|
92
103
|
*
|
|
93
104
|
* @example
|
|
94
105
|
* const taxes = await getCachedTaxes();
|
|
95
106
|
* console.log(taxes.items[0].taxName);
|
|
107
|
+
*
|
|
108
|
+
* // With search
|
|
109
|
+
* const filtered = await getCachedTaxes('VAT');
|
|
96
110
|
*/
|
|
97
|
-
var getCachedTaxes = function () {
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
var getCachedTaxes = function (searchQuery_1) {
|
|
112
|
+
var args_1 = [];
|
|
113
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
114
|
+
args_1[_i - 1] = arguments[_i];
|
|
115
|
+
}
|
|
116
|
+
return __awaiter(void 0, __spreadArray([searchQuery_1], args_1, true), void 0, function (searchQuery, pageLimit) {
|
|
117
|
+
var response_1, cachedData, currentTime, cachedTime, ageInMs, response, updatedCache, error_1;
|
|
118
|
+
var _a;
|
|
119
|
+
if (pageLimit === void 0) { pageLimit = 100; }
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0:
|
|
123
|
+
_b.trys.push([0, 4, , 5]);
|
|
124
|
+
if (!(searchQuery && searchQuery.trim())) return [3 /*break*/, 2];
|
|
125
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
126
|
+
url: constants_1.API_ROUTES.TAXES,
|
|
127
|
+
body: JSON.stringify({
|
|
128
|
+
searchQuery: searchQuery,
|
|
129
|
+
pageLimit: pageLimit,
|
|
130
|
+
currentPage: 1,
|
|
131
|
+
}),
|
|
132
|
+
method: api_methods_1.API_METHODS.POST,
|
|
133
|
+
})];
|
|
134
|
+
case 1:
|
|
135
|
+
response_1 = _b.sent();
|
|
136
|
+
return [2 /*return*/, (response_1 === null || response_1 === void 0 ? void 0 : response_1.data) || { count: 0, items: [] }];
|
|
137
|
+
case 2:
|
|
138
|
+
cachedData = (0, get_storage_value_1.getStorageValue)(type_1.LS_KEYS.TAXES);
|
|
139
|
+
currentTime = new Date().getTime();
|
|
140
|
+
// Check if cached data exists and is still fresh
|
|
141
|
+
if (cachedData) {
|
|
142
|
+
cachedTime = new Date(cachedData.cachedAt).getTime();
|
|
143
|
+
ageInMs = currentTime - cachedTime;
|
|
144
|
+
// If cached data is less than 1 week old, return it
|
|
145
|
+
if (ageInMs < constants_1.ONE_WEEK_IN_MS) {
|
|
146
|
+
return [2 /*return*/, {
|
|
147
|
+
count: cachedData.taxes.length,
|
|
148
|
+
items: cachedData.taxes,
|
|
149
|
+
}];
|
|
150
|
+
}
|
|
116
151
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
return [4 /*yield*/, (0, fetch_data_1.fetchData)({
|
|
153
|
+
url: constants_1.API_ROUTES.TAXES,
|
|
154
|
+
body: JSON.stringify({
|
|
155
|
+
pageLimit: pageLimit,
|
|
156
|
+
currentPage: 1,
|
|
157
|
+
}),
|
|
158
|
+
method: api_methods_1.API_METHODS.POST,
|
|
159
|
+
})];
|
|
160
|
+
case 3:
|
|
161
|
+
response = _b.sent();
|
|
162
|
+
if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) {
|
|
163
|
+
updatedCache = {
|
|
164
|
+
taxes: response.data.items,
|
|
165
|
+
cachedAt: new Date().toISOString(),
|
|
166
|
+
};
|
|
167
|
+
(0, set_storage_value_1.setStorageValue)(type_1.LS_KEYS.TAXES, updatedCache);
|
|
168
|
+
return [2 /*return*/, response.data];
|
|
169
|
+
}
|
|
170
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
171
|
+
case 4:
|
|
172
|
+
error_1 = _b.sent();
|
|
173
|
+
console.error('Error fetching taxes:', error_1);
|
|
174
|
+
return [2 /*return*/, { count: 0, items: [] }];
|
|
175
|
+
case 5: return [2 /*return*/];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
139
178
|
});
|
|
140
|
-
}
|
|
179
|
+
};
|
|
141
180
|
exports.getCachedTaxes = getCachedTaxes;
|
|
142
181
|
/**
|
|
143
182
|
* Utility function to get a specific tax by ID from cache
|