@react-pakistan/util-functions 1.25.17 → 1.25.19

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.
@@ -162,7 +162,7 @@ exports.getCachedDataSync = getCachedDataSync;
162
162
  * const active = await getCachedData<UserBE>({ config, filters: { enabled: true }, pageLimit: 200 });
163
163
  */
164
164
  var getCachedData = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
165
- var config, params, cacheKey, apiUrl, responseKey, expirationMs, fallBackPageLimit, fallBackCurrentPage, filters, searchQuery, queryObj_1, searchParams_1, response_1, items_1, raw, currentTime, cachedTime, ageInMs, cachedTime, ageInMs, itemsArray, queryObj, searchParams, response, itemsRaw, items, count, itemsMap, updatedCache, error_1;
165
+ var config, params, cacheKey, apiUrl, responseKey, expirationMs, fallBackPageLimit, fallBackCurrentPage, filters, searchQuery, paramsWithoutFilters_1, otherParams_1, queryObj_1, searchParams_1, response_1, items_1, raw, currentTime, cachedTime, ageInMs, cachedTime, ageInMs, itemsArray, paramsWithoutFilters_2, otherParams, queryObj, searchParams, response, itemsRaw, items, count, itemsMap, updatedCache, error_1;
166
166
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
167
167
  return __generator(this, function (_m) {
168
168
  switch (_m.label) {
@@ -179,12 +179,20 @@ var getCachedData = function (opts) { return __awaiter(void 0, void 0, void 0, f
179
179
  _m.trys.push([1, 5, , 6]);
180
180
  if (!((searchQuery && searchQuery.trim()) ||
181
181
  (filters && Object.keys(filters).length > 0))) return [3 /*break*/, 3];
182
+ paramsWithoutFilters_1 = __assign({}, (params || {}));
183
+ if (paramsWithoutFilters_1.filters !== undefined) {
184
+ delete paramsWithoutFilters_1.filters;
185
+ }
186
+ otherParams_1 = Object.keys(paramsWithoutFilters_1).reduce(function (acc, key) {
187
+ acc[key] = String(paramsWithoutFilters_1[key]);
188
+ return acc;
189
+ }, {});
182
190
  queryObj_1 = __assign(__assign(__assign({ pageLimit: fallBackPageLimit, currentPage: fallBackCurrentPage }, (searchQuery && { searchQuery: searchQuery })), (filters
183
191
  ? Object.keys(filters).reduce(function (acc, key) {
184
192
  acc[key] = String(filters[key]);
185
193
  return acc;
186
194
  }, {})
187
- : {})), (params || {}));
195
+ : {})), otherParams_1);
188
196
  searchParams_1 = new URLSearchParams(queryObj_1);
189
197
  return [4 /*yield*/, (0, fetch_data_1.fetchData)({
190
198
  url: "".concat(apiUrl, "?").concat(searchParams_1.toString()),
@@ -217,7 +225,15 @@ var getCachedData = function (opts) { return __awaiter(void 0, void 0, void 0, f
217
225
  return [2 /*return*/, { count: itemsArray.length, items: itemsArray }];
218
226
  }
219
227
  }
220
- queryObj = __assign({ pageLimit: fallBackPageLimit, currentPage: fallBackCurrentPage }, (params || {}));
228
+ paramsWithoutFilters_2 = __assign({}, (params || {}));
229
+ if (paramsWithoutFilters_2.filters !== undefined) {
230
+ delete paramsWithoutFilters_2.filters;
231
+ }
232
+ otherParams = Object.keys(paramsWithoutFilters_2).reduce(function (acc, key) {
233
+ acc[key] = String(paramsWithoutFilters_2[key]);
234
+ return acc;
235
+ }, {});
236
+ queryObj = __assign({ pageLimit: fallBackPageLimit, currentPage: fallBackCurrentPage }, otherParams);
221
237
  searchParams = new URLSearchParams(queryObj);
222
238
  return [4 /*yield*/, (0, fetch_data_1.fetchData)({
223
239
  url: "".concat(apiUrl, "?").concat(searchParams.toString()),
@@ -75,6 +75,8 @@ interface Params {
75
75
  listDeps?: Array<any> | Array<string>;
76
76
  listParams: object;
77
77
  listUrl: string;
78
+ /** Optional headers to include on every fetch made by this hook */
79
+ headers?: Record<string, string>;
78
80
  searchQuery: string;
79
81
  unitByIdUrl: string;
80
82
  unitUrl: string;
@@ -96,5 +98,5 @@ interface Return {
96
98
  updateFetchNow: (url?: string, config?: FetchConfig) => void;
97
99
  updateLoading: boolean;
98
100
  }
99
- export declare const useModuleEntityV2: ({ byIdCallback, byIdDeps, byIdParams, deleteCallback, deleteDeps, deleteParams, listCallback, listDeps, listParams, listUrl, searchQuery, unitByIdUrl, unitUrl, updateCallback, updateDeps, updateParams, }: Params) => Return;
101
+ export declare const useModuleEntityV2: ({ byIdCallback, byIdDeps, byIdParams, deleteCallback, deleteDeps, deleteParams, listCallback, listDeps, listParams, listUrl, headers, searchQuery, unitByIdUrl, unitUrl, updateCallback, updateDeps, updateParams, }: Params) => Return;
100
102
  export {};
@@ -74,7 +74,7 @@ var constants_1 = require("../constants");
74
74
  var use_fetch_1 = require("./use-fetch");
75
75
  var use_debounce_1 = require("./use-debounce");
76
76
  var useModuleEntityV2 = function (_a) {
77
- var byIdCallback = _a.byIdCallback, _b = _a.byIdDeps, byIdDeps = _b === void 0 ? [] : _b, byIdParams = _a.byIdParams, deleteCallback = _a.deleteCallback, _c = _a.deleteDeps, deleteDeps = _c === void 0 ? [] : _c, deleteParams = _a.deleteParams, listCallback = _a.listCallback, _d = _a.listDeps, listDeps = _d === void 0 ? [] : _d, listParams = _a.listParams, listUrl = _a.listUrl, searchQuery = _a.searchQuery, unitByIdUrl = _a.unitByIdUrl, unitUrl = _a.unitUrl, updateCallback = _a.updateCallback, _e = _a.updateDeps, updateDeps = _e === void 0 ? [] : _e, updateParams = _a.updateParams;
77
+ var byIdCallback = _a.byIdCallback, _b = _a.byIdDeps, byIdDeps = _b === void 0 ? [] : _b, byIdParams = _a.byIdParams, deleteCallback = _a.deleteCallback, _c = _a.deleteDeps, deleteDeps = _c === void 0 ? [] : _c, deleteParams = _a.deleteParams, listCallback = _a.listCallback, _d = _a.listDeps, listDeps = _d === void 0 ? [] : _d, listParams = _a.listParams, listUrl = _a.listUrl, headers = _a.headers, searchQuery = _a.searchQuery, unitByIdUrl = _a.unitByIdUrl, unitUrl = _a.unitUrl, updateCallback = _a.updateCallback, _e = _a.updateDeps, updateDeps = _e === void 0 ? [] : _e, updateParams = _a.updateParams;
78
78
  var debouncedQuery = (0, use_debounce_1.useDebounce)(searchQuery, 800);
79
79
  // debounced list refresh to batch multiple updates/deletes
80
80
  var refreshTimerRef = (0, react_1.useRef)(null);
@@ -88,6 +88,7 @@ var useModuleEntityV2 = function (_a) {
88
88
  var _f = (0, use_fetch_1.useFetch)(listUrl, {
89
89
  method: constants_1.API_METHODS.GET,
90
90
  params: listParams,
91
+ headers: headers,
91
92
  callback: listCallback,
92
93
  credentials: true,
93
94
  }, __spreadArray([debouncedQuery, listParams], listDeps, true)), listError = _f.error, listFetchNow = _f.fetchNow, listLoading = _f.loading;
@@ -102,6 +103,7 @@ var useModuleEntityV2 = function (_a) {
102
103
  listFetchNow(undefined, {
103
104
  method: constants_1.API_METHODS.GET,
104
105
  params: listParams,
106
+ headers: headers,
105
107
  });
106
108
  }
107
109
  catch (_a) {
@@ -114,6 +116,7 @@ var useModuleEntityV2 = function (_a) {
114
116
  var _g = (0, use_fetch_1.useFetch)(unitUrl, {
115
117
  method: constants_1.API_METHODS.PUT,
116
118
  body: JSON.stringify(updateParams),
119
+ headers: headers,
117
120
  callback: function (d) {
118
121
  if (updateCallback) {
119
122
  try {
@@ -139,12 +142,14 @@ var useModuleEntityV2 = function (_a) {
139
142
  var _h = (0, use_fetch_1.useFetch)(unitByIdUrl, {
140
143
  method: constants_1.API_METHODS.GET,
141
144
  params: byIdParams,
145
+ headers: headers,
142
146
  callback: byIdCallback,
143
147
  }, __spreadArray([], byIdDeps, true)), byIdError = _h.error, byIdLoading = _h.loading, byIdFetchNow = _h.fetchNow;
144
148
  // delete
145
149
  var _j = (0, use_fetch_1.useFetch)(unitUrl, {
146
150
  method: constants_1.API_METHODS.DELETE,
147
151
  body: JSON.stringify(deleteParams),
152
+ headers: headers,
148
153
  callback: function (d) {
149
154
  if (deleteCallback) {
150
155
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-pakistan/util-functions",
3
- "version": "1.25.17",
3
+ "version": "1.25.19",
4
4
  "description": "A library of all util functions",
5
5
  "main": "index.js",
6
6
  "scripts": {