api-core-lib 12.0.25 → 12.0.27

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/dist/index.cjs CHANGED
@@ -1,52 +1,19 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1
+ #!/usr/bin/env node
2
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
3
+
4
+
5
+
6
+
7
+
8
+
9
+ var _chunkNCMDUWNOcjs = require('./chunk-NCMDUWNO.cjs');
31
10
 
32
- // src/index.ts
33
- var index_exports = {};
34
- __export(index_exports, {
35
- buildPaginateQuery: () => buildPaginateQuery,
36
- cacheManager: () => cacheManager,
37
- callDynamicApi: () => callDynamicApi,
38
- createApiActions: () => createApiActions,
39
- createApiClient: () => createApiClient,
40
- createApiServices: () => createApiServices,
41
- generateCacheKey: () => generateCacheKey,
42
- globalStateManager: () => globalStateManager,
43
- processResponse: () => processResponse
44
- });
45
- module.exports = __toCommonJS(index_exports);
11
+
12
+ var _chunkQOOQGLEXcjs = require('./chunk-QOOQGLEX.cjs');
46
13
 
47
14
  // src/core/client.ts
48
- var import_axios = __toESM(require("axios"), 1);
49
- var import_uuid = require("uuid");
15
+ var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
16
+ var _uuid = require('uuid');
50
17
  async function runMiddleware(context, middlewares = []) {
51
18
  const run = async (index) => {
52
19
  if (index >= middlewares.length) return;
@@ -70,7 +37,7 @@ async function refreshToken(config, tokenManager) {
70
37
  const { path, buildRequestBody, buildRequestHeaders, extractTokens } = refreshTokenConfig;
71
38
  const requestBody = buildRequestBody ? buildRequestBody(currentTokens.refreshToken) : { refresh_token: currentTokens.refreshToken };
72
39
  const requestHeaders = buildRequestHeaders ? buildRequestHeaders(currentTokens) : {};
73
- const response = await import_axios.default.post(
40
+ const response = await _axios2.default.post(
74
41
  `${config.baseURL}${path}`,
75
42
  requestBody,
76
43
  { headers: requestHeaders, withCredentials: config.withCredentials }
@@ -89,7 +56,7 @@ async function refreshToken(config, tokenManager) {
89
56
  console.info("Tokens refreshed successfully.");
90
57
  return newTokens;
91
58
  } catch (err) {
92
- console.error("Failed to refresh token.", err.response?.data || err.message);
59
+ console.error("Failed to refresh token.", _optionalChain([err, 'access', _ => _.response, 'optionalAccess', _2 => _2.data]) || err.message);
93
60
  if (config.onRefreshError) {
94
61
  config.onRefreshError(err);
95
62
  }
@@ -110,7 +77,7 @@ function createApiClient(config) {
110
77
  maxQueueSize = 50,
111
78
  onRefreshError
112
79
  } = config;
113
- const axiosInstance = import_axios.default.create({
80
+ const axiosInstance = _axios2.default.create({
114
81
  baseURL,
115
82
  timeout,
116
83
  headers: { "Content-Type": "application/json", ...headers },
@@ -131,15 +98,15 @@ function createApiClient(config) {
131
98
  }
132
99
  };
133
100
  axiosInstance.interceptors.request.use(async (req) => {
134
- req.headers["X-Request-ID"] = (0, import_uuid.v4)();
101
+ req.headers["X-Request-ID"] = _uuid.v4.call(void 0, );
135
102
  try {
136
- const fullUrl = import_axios.default.getUri({ ...req, baseURL: req.baseURL ?? baseURL });
137
- console.log(`Request Sent > ${req.method?.toUpperCase()} ${fullUrl}`, `(ID: ${req.headers["X-Request-ID"]})`);
138
- } catch {
103
+ const fullUrl = _axios2.default.getUri({ ...req, baseURL: _nullishCoalesce(req.baseURL, () => ( baseURL)) });
104
+ console.log(`Request Sent > ${_optionalChain([req, 'access', _3 => _3.method, 'optionalAccess', _4 => _4.toUpperCase, 'call', _5 => _5()])} ${fullUrl}`, `(ID: ${req.headers["X-Request-ID"]})`);
105
+ } catch (e) {
139
106
  console.warn("Failed to build full request URL for logging.");
140
107
  }
141
108
  await safeRunMiddleware({ req, custom: {} }, middleware);
142
- if (req.isPublic ?? defaultIsPublic) {
109
+ if (_nullishCoalesce(req.isPublic, () => ( defaultIsPublic))) {
143
110
  return req;
144
111
  }
145
112
  if (tokenManager.isHttpOnly()) return req;
@@ -168,9 +135,9 @@ function createApiClient(config) {
168
135
  axiosInstance.interceptors.response.use(
169
136
  async (res) => {
170
137
  try {
171
- const fullUrl = import_axios.default.getUri(res.config);
172
- console.log(`Response Received < ${res.config.method?.toUpperCase()} ${fullUrl}`, `(ID: ${res.config.headers["X-Request-ID"]}, Status: ${res.status})`);
173
- } catch {
138
+ const fullUrl = _axios2.default.getUri(res.config);
139
+ console.log(`Response Received < ${_optionalChain([res, 'access', _6 => _6.config, 'access', _7 => _7.method, 'optionalAccess', _8 => _8.toUpperCase, 'call', _9 => _9()])} ${fullUrl}`, `(ID: ${res.config.headers["X-Request-ID"]}, Status: ${res.status})`);
140
+ } catch (e2) {
174
141
  console.warn("Failed to build full response URL for logging.");
175
142
  }
176
143
  await safeRunMiddleware({ req: res.config, res, custom: {} }, middleware);
@@ -179,12 +146,12 @@ function createApiClient(config) {
179
146
  async (error) => {
180
147
  const originalRequest = error.config;
181
148
  try {
182
- const fullUrl = import_axios.default.getUri(originalRequest);
183
- const method = originalRequest.method?.toUpperCase();
184
- const status = error.response?.status;
185
- const responseData = error.response?.data;
149
+ const fullUrl = _axios2.default.getUri(originalRequest);
150
+ const method = _optionalChain([originalRequest, 'access', _10 => _10.method, 'optionalAccess', _11 => _11.toUpperCase, 'call', _12 => _12()]);
151
+ const status = _optionalChain([error, 'access', _13 => _13.response, 'optionalAccess', _14 => _14.status]);
152
+ const responseData = _optionalChain([error, 'access', _15 => _15.response, 'optionalAccess', _16 => _16.data]);
186
153
  const summary = `Response Error < ${method} ${fullUrl} | Status: ${status || "N/A"}`;
187
- const apiMessage = responseData?.message || error.message;
154
+ const apiMessage = _optionalChain([responseData, 'optionalAccess', _17 => _17.message]) || error.message;
188
155
  console.error(summary);
189
156
  console.error(`> Message: ${apiMessage}`);
190
157
  if (error.response) {
@@ -192,12 +159,12 @@ function createApiClient(config) {
192
159
  console.dir(error.response.data);
193
160
  console.groupEnd();
194
161
  }
195
- } catch {
162
+ } catch (e3) {
196
163
  console.error("Response Error: Failed to build full URL for logging.", error.message);
197
164
  }
198
165
  await safeRunMiddleware({ req: originalRequest, error, custom: {} }, middleware);
199
166
  const isHttpOnlyMode = tokenManager.isHttpOnly();
200
- const canAttemptRefresh = error.response?.status === 401 && !originalRequest._retry && config.refreshTokenConfig;
167
+ const canAttemptRefresh = _optionalChain([error, 'access', _18 => _18.response, 'optionalAccess', _19 => _19.status]) === 401 && !originalRequest._retry && config.refreshTokenConfig;
201
168
  if (isHttpOnlyMode && canAttemptRefresh) {
202
169
  console.error("401 in httpOnly mode. Token refresh must be handled by the server.");
203
170
  return Promise.reject(error);
@@ -222,7 +189,7 @@ function createApiClient(config) {
222
189
  isRefreshing = true;
223
190
  try {
224
191
  const newTokens = await refreshToken(config, tokenManager);
225
- if (!newTokens?.accessToken) {
192
+ if (!_optionalChain([newTokens, 'optionalAccess', _20 => _20.accessToken])) {
226
193
  throw new Error("Token refresh failed to produce a new access token.");
227
194
  }
228
195
  processQueue(null, newTokens.accessToken);
@@ -241,264 +208,6 @@ function createApiClient(config) {
241
208
  return axiosInstance;
242
209
  }
243
210
 
244
- // src/core/processor.ts
245
- var import_axios3 = __toESM(require("axios"), 1);
246
-
247
- // src/core/utils.ts
248
- var import_axios2 = __toESM(require("axios"), 1);
249
- function isAxiosResponse(obj) {
250
- return obj && obj.data !== void 0 && obj.status !== void 0 && obj.config !== void 0;
251
- }
252
- function buildPaginateQuery(options) {
253
- const params = new URLSearchParams();
254
- for (const key in options) {
255
- const value = options[key];
256
- if (value === null || value === void 0) {
257
- continue;
258
- }
259
- if (key === "filter" && typeof value === "object" && !Array.isArray(value)) {
260
- for (const filterKey in value) {
261
- const filterValue = value[filterKey];
262
- if (filterValue !== null && filterValue !== void 0) {
263
- params.append(`filter[${filterKey}]`, String(filterValue));
264
- }
265
- }
266
- } else if (key === "sortBy" && Array.isArray(value)) {
267
- value.forEach((sortItem) => {
268
- if (sortItem && sortItem.key && sortItem.direction) {
269
- params.append("sortBy[]", `${sortItem.key}:${sortItem.direction}`);
270
- }
271
- });
272
- } else {
273
- params.append(key, String(value));
274
- }
275
- }
276
- return params.toString();
277
- }
278
- function isServerError(error) {
279
- return import_axios2.default.isAxiosError(error) && error.response !== void 0;
280
- }
281
- function isNetworkError(error) {
282
- return import_axios2.default.isAxiosError(error) && error.response === void 0 && error.request !== void 0;
283
- }
284
-
285
- // src/core/processor.ts
286
- var processResponse = (responseOrError) => {
287
- if (isAxiosResponse(responseOrError)) {
288
- const response = responseOrError;
289
- const rawData = response.data;
290
- const isStandardApiResponse = rawData && typeof rawData.success === "boolean" && rawData.data !== void 0;
291
- return {
292
- data: isStandardApiResponse ? rawData.data : rawData,
293
- links: isStandardApiResponse ? rawData.links : void 0,
294
- meta: isStandardApiResponse ? rawData.meta : void 0,
295
- rawResponse: rawData,
296
- loading: false,
297
- success: true,
298
- error: null,
299
- message: isStandardApiResponse ? rawData.message : "Request successful.",
300
- validationErrors: []
301
- };
302
- }
303
- if (isServerError(responseOrError)) {
304
- const error = responseOrError;
305
- const responseData = error.response.data;
306
- const status = error.response.status;
307
- let defaultMessage = "An unexpected server error occurred.";
308
- switch (status) {
309
- case 400:
310
- defaultMessage = "Bad Request";
311
- break;
312
- case 401:
313
- defaultMessage = "Unauthorized";
314
- break;
315
- case 403:
316
- defaultMessage = "Forbidden";
317
- break;
318
- case 404:
319
- defaultMessage = "Not Found";
320
- break;
321
- case 422:
322
- defaultMessage = "Validation Failed";
323
- break;
324
- case 500:
325
- defaultMessage = "Internal Server Error";
326
- break;
327
- case 503:
328
- defaultMessage = "Service Unavailable";
329
- break;
330
- default:
331
- defaultMessage = `Server Error (${status})`;
332
- }
333
- const finalApiError = {
334
- message: responseData?.message || defaultMessage,
335
- status,
336
- code: responseData?.code || error.code,
337
- errors: responseData?.errors || []
338
- };
339
- return {
340
- data: null,
341
- rawResponse: responseData,
342
- error: finalApiError,
343
- validationErrors: finalApiError.errors,
344
- success: false,
345
- loading: false,
346
- message: finalApiError.message
347
- };
348
- }
349
- if (isNetworkError(responseOrError)) {
350
- const error = responseOrError;
351
- return {
352
- data: null,
353
- rawResponse: error.request,
354
- error: { message: "Network Error: Unable to connect.", status: 0, code: error.code },
355
- success: false,
356
- loading: false,
357
- message: "Network Error."
358
- };
359
- }
360
- if (import_axios3.default.isCancel(responseOrError)) {
361
- return {
362
- data: null,
363
- rawResponse: null,
364
- error: { message: "Request Canceled.", status: 499 },
365
- success: false,
366
- loading: false,
367
- message: "Request Canceled."
368
- };
369
- }
370
- return {
371
- data: null,
372
- rawResponse: responseOrError,
373
- error: { message: "An unknown error occurred.", status: -1 },
374
- success: false,
375
- loading: false,
376
- message: "An unknown error occurred."
377
- };
378
- };
379
-
380
- // src/core/buildDynamicUrl.ts
381
- function buildDynamicUrl(template, params) {
382
- if (!params) {
383
- return template;
384
- }
385
- return template.replace(/\{(\w+)\}/g, (placeholder, key) => {
386
- return params.hasOwnProperty(key) ? String(params[key]) : placeholder;
387
- });
388
- }
389
-
390
- // src/services/crud.ts
391
- function createApiServices(axiosInstance, baseEndpoint) {
392
- const resolveUrl = (config = {}, id) => {
393
- const endpointTemplate = config.endpoint || (id != null ? `${baseEndpoint}/{id}` : baseEndpoint);
394
- const params = id != null ? { id, tenant: id, tenantId: id, recordId: id } : {};
395
- return buildDynamicUrl(endpointTemplate, params);
396
- };
397
- const get = async (id, config) => {
398
- const url = resolveUrl(config, id);
399
- try {
400
- const response = await axiosInstance.get(url, config);
401
- return processResponse(response);
402
- } catch (error) {
403
- return processResponse(error);
404
- }
405
- };
406
- const getWithQuery = async (query, config) => {
407
- const url = `${baseEndpoint}?${query}`;
408
- try {
409
- const response = await axiosInstance.get(url, config);
410
- return processResponse(response);
411
- } catch (error) {
412
- return processResponse(error);
413
- }
414
- };
415
- const post = async (data, config) => {
416
- const url = resolveUrl(config);
417
- try {
418
- const response = await axiosInstance.post(url, data, config);
419
- console.log("[lib] response POST: ", response);
420
- console.log("[lib] response processResponse POST: ", processResponse(response));
421
- return processResponse(response);
422
- } catch (error) {
423
- console.log("[lib] response error POST: ", processResponse(error));
424
- return processResponse(error);
425
- }
426
- };
427
- const put = async (id, data, config) => {
428
- const url = resolveUrl(config, id);
429
- try {
430
- const response = await axiosInstance.put(url, data, config);
431
- return processResponse(response);
432
- } catch (error) {
433
- return processResponse(error);
434
- }
435
- };
436
- const patch = async (id, data, config) => {
437
- const url = resolveUrl(config, id);
438
- try {
439
- const response = await axiosInstance.patch(url, data, config);
440
- return processResponse(response);
441
- } catch (error) {
442
- return processResponse(error);
443
- }
444
- };
445
- const remove = async (id, config) => {
446
- const url = resolveUrl(config, id);
447
- try {
448
- const response = await axiosInstance.delete(url, config);
449
- return processResponse(response);
450
- } catch (error) {
451
- return processResponse(error);
452
- }
453
- };
454
- const bulkDelete = async (ids, config) => {
455
- const url = resolveUrl(config);
456
- try {
457
- const response = await axiosInstance.delete(url, { data: { ids }, ...config });
458
- return processResponse(response);
459
- } catch (error) {
460
- return processResponse(error);
461
- }
462
- };
463
- const upload = async (file, additionalData, config) => {
464
- const url = resolveUrl(config);
465
- const formData = new FormData();
466
- formData.append("file", file);
467
- if (additionalData) {
468
- Object.keys(additionalData).forEach((key) => formData.append(key, String(additionalData[key])));
469
- }
470
- try {
471
- const response = await axiosInstance.post(url, formData, {
472
- ...config,
473
- headers: { ...config?.headers, "Content-Type": "multipart/form-data" }
474
- });
475
- return processResponse(response);
476
- } catch (error) {
477
- return processResponse(error);
478
- }
479
- };
480
- return { get, getWithQuery, post, put, patch, remove, bulkDelete, upload };
481
- }
482
- async function callDynamicApi(axiosInstance, baseEndpoint, actionConfig, params) {
483
- const { pathParams, body, config } = params;
484
- const urlTemplate = `${baseEndpoint}${actionConfig.path}`;
485
- const finalUrl = buildDynamicUrl(urlTemplate, pathParams || {});
486
- try {
487
- const { method } = actionConfig;
488
- let response;
489
- if (method === "POST" || method === "PUT" || method === "PATCH") {
490
- response = await axiosInstance[method.toLowerCase()](finalUrl, body, config);
491
- } else if (method === "DELETE") {
492
- response = await axiosInstance.delete(finalUrl, { data: body, ...config });
493
- } else {
494
- response = await axiosInstance.get(finalUrl, { params: body, ...config });
495
- }
496
- return processResponse(response);
497
- } catch (error) {
498
- return processResponse(error);
499
- }
500
- }
501
-
502
211
  // src/services/actions.ts
503
212
  function createAction(axiosInstance, method, endpoint) {
504
213
  return async (payload, config) => {
@@ -509,9 +218,9 @@ function createAction(axiosInstance, method, endpoint) {
509
218
  ...method.toUpperCase() === "GET" ? { params: payload } : { data: payload },
510
219
  ...config
511
220
  });
512
- return processResponse(response);
221
+ return _chunkNCMDUWNOcjs.processResponse.call(void 0, response);
513
222
  } catch (error) {
514
- return processResponse(error);
223
+ return _chunkNCMDUWNOcjs.processResponse.call(void 0, error);
515
224
  }
516
225
  };
517
226
  }
@@ -526,119 +235,11 @@ function createApiActions(axiosInstance, actionsConfig) {
526
235
  return actions;
527
236
  }
528
237
 
529
- // src/core/globalStateManager.ts
530
- var createInitialState = () => ({
531
- data: null,
532
- links: void 0,
533
- meta: void 0,
534
- error: null,
535
- loading: false,
536
- success: false,
537
- called: false,
538
- isStale: false,
539
- message: void 0,
540
- validationErrors: [],
541
- rawResponse: null
542
- });
543
- var GlobalStateManager = class {
544
- constructor() {
545
- __publicField(this, "store", /* @__PURE__ */ new Map());
546
- }
547
- getSnapshot(key) {
548
- if (!this.store.has(key)) {
549
- const initialState = createInitialState();
550
- this.store.set(key, { state: initialState, listeners: /* @__PURE__ */ new Set() });
551
- }
552
- return this.store.get(key).state;
553
- }
554
- /**
555
- * يسجل دالة callback للاستماع إلى التغييرات على مفتاح معين.
556
- * @returns دالة لإلغاء الاشتراك.
557
- */
558
- subscribe(key, callback) {
559
- if (!this.store.has(key)) {
560
- this.store.set(key, { state: createInitialState(), listeners: /* @__PURE__ */ new Set() });
561
- }
562
- const item = this.store.get(key);
563
- item.listeners.add(callback);
564
- return () => {
565
- item.listeners.delete(callback);
566
- };
567
- }
568
- /**
569
- * يحدّث الحالة لمفتاح معين ويقوم بإعلام جميع المشتركين.
570
- */
571
- setState(key, updater) {
572
- const currentState = this.getSnapshot(key);
573
- const newState = updater(currentState);
574
- if (Object.is(currentState, newState)) {
575
- return;
576
- }
577
- const item = this.store.get(key);
578
- item.state = newState;
579
- item.listeners.forEach((listener) => listener());
580
- }
581
- /**
582
- * يجعل البيانات المرتبطة بمفتاح معين "قديمة" (stale).
583
- */
584
- invalidate(key) {
585
- const state = this.getSnapshot(key);
586
- if (state.called) {
587
- this.setState(key, (prev) => ({ ...prev, isStale: true }));
588
- }
589
- }
590
- /**
591
- * [نسخة محدثة وأكثر قوة]
592
- * يجعل كل البيانات التي تبدأ بمفتاح معين "قديمة" (stale).
593
- * @example invalidateByPrefix('myModule/list::') سيبطل كل صفحات القائمة.
594
- */
595
- invalidateByPrefix(prefix) {
596
- this.store.forEach((value, key) => {
597
- if (key.startsWith(prefix)) {
598
- const state = this.getSnapshot(key);
599
- if (state.called) {
600
- this.setState(key, (prev) => ({ ...prev, isStale: true }));
601
- }
602
- }
603
- });
604
- }
605
- /**
606
- * Serializes the current state of the query store into a JSON string.
607
- * This is used on the server to pass the initial state to the client.
608
- * @returns A JSON string representing the dehydrated state.
609
- */
610
- dehydrate() {
611
- const stateToPersist = {};
612
- this.store.forEach((value, key) => {
613
- if (value.state.called) {
614
- stateToPersist[key] = value.state;
615
- }
616
- });
617
- return JSON.stringify(stateToPersist);
618
- }
619
- /**
620
- * Merges a dehydrated state object into the current store.
621
- * This is used on the client to hydrate the state received from the server.
622
- * @param hydratedState - A JSON string from the `dehydrate` method.
623
- */
624
- rehydrate(hydratedState) {
625
- try {
626
- const parsedState = JSON.parse(hydratedState);
627
- for (const key in parsedState) {
628
- this.setState(key, () => parsedState[key]);
629
- }
630
- } catch (e) {
631
- console.error("[api-core-lib] Failed to rehydrate state:", e);
632
- }
633
- }
634
- };
635
- var globalStateManager = new GlobalStateManager();
636
-
637
238
  // src/core/cache.ts
638
239
  var CacheManager = class {
639
240
  constructor() {
640
- __publicField(this, "cache", /* @__PURE__ */ new Map());
641
- __publicField(this, "defaultDuration", 15 * 60 * 1e3);
241
+ _chunkQOOQGLEXcjs.__publicField.call(void 0, this, "cache", /* @__PURE__ */ new Map());
242
+ _chunkQOOQGLEXcjs.__publicField.call(void 0, this, "defaultDuration", 15 * 60 * 1e3);
642
243
  }
643
244
  // 15 minutes
644
245
  set(key, data, duration) {
@@ -691,25 +292,13 @@ var CacheManager = class {
691
292
  };
692
293
  var cacheManager = new CacheManager();
693
294
 
694
- // src/core/cacheKey.ts
695
- var generateCacheKey = (moduleName, actionName, input, callOptions = {}) => {
696
- const params = { path: callOptions.pathParams, body: input };
697
- try {
698
- return `${moduleName}/${actionName}::${JSON.stringify(params)}`;
699
- } catch (error) {
700
- console.warn("Could not stringify cache key params, falling back to timestamp.", { moduleName, actionName, error });
701
- return `${moduleName}/${actionName}::${Date.now()}`;
702
- }
703
- };
704
- // Annotate the CommonJS export names for ESM import in node:
705
- 0 && (module.exports = {
706
- buildPaginateQuery,
707
- cacheManager,
708
- callDynamicApi,
709
- createApiActions,
710
- createApiClient,
711
- createApiServices,
712
- generateCacheKey,
713
- globalStateManager,
714
- processResponse
715
- });
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+ exports.buildPaginateQuery = _chunkNCMDUWNOcjs.buildPaginateQuery; exports.cacheManager = cacheManager; exports.callDynamicApi = _chunkNCMDUWNOcjs.callDynamicApi; exports.createApiActions = createApiActions; exports.createApiClient = createApiClient; exports.createApiServices = _chunkNCMDUWNOcjs.createApiServices; exports.generateCacheKey = _chunkNCMDUWNOcjs.generateCacheKey; exports.globalStateManager = _chunkNCMDUWNOcjs.globalStateManager; exports.processResponse = _chunkNCMDUWNOcjs.processResponse;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
2
- import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, e as UseApiQuery, i as ApiError, L as LogLevel } from './apiModule.types-Bn0tJF7b.cjs';
3
- export { n as ActionConfig, s as ActionMethods, p as ActionState, r as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-Bn0tJF7b.cjs';
4
- export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-NZtPRga3.cjs';
2
+ import { h as ApiClientConfig, b as ActionConfigModule, S as StandardResponse, a as ActionOptions, R as RequestConfig, i as ActionStateModule, Q as QueryOptions, g as UseApiQuery, A as ApiError, L as LogLevel } from './apiModule.types-Bg7m0Xoy.cjs';
3
+ export { n as ActionConfig, s as ActionMethods, p as ActionState, r as ActionsWithQuery, c as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, f as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, d as UseApiModuleOptions, e as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-Bg7m0Xoy.cjs';
4
+ export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-CT4BDrvj.cjs';
5
5
  import 'react';
6
6
 
7
7
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse, AxiosError } from 'axios';
2
- import { f as ApiClientConfig, A as ActionConfigModule, S as StandardResponse, g as ActionOptions, R as RequestConfig, h as ActionStateModule, Q as QueryOptions, e as UseApiQuery, i as ApiError, L as LogLevel } from './apiModule.types-Bn0tJF7b.js';
3
- export { n as ActionConfig, s as ActionMethods, p as ActionState, r as ActionsWithQuery, a as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, d as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, b as UseApiModuleOptions, c as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-Bn0tJF7b.js';
4
- export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-CWhwCAB6.js';
2
+ import { h as ApiClientConfig, b as ActionConfigModule, S as StandardResponse, a as ActionOptions, R as RequestConfig, i as ActionStateModule, Q as QueryOptions, g as UseApiQuery, A as ApiError, L as LogLevel } from './apiModule.types-Bg7m0Xoy.js';
3
+ export { n as ActionConfig, s as ActionMethods, p as ActionState, r as ActionsWithQuery, c as ApiModuleConfig, E as ExecutableAction, q as ExecuteOptions, I as InputOf, l as Middleware, k as MiddlewareContext, f as ModuleActions, M as ModuleStates, O as OutputOf, P as PaginationMeta, m as RefreshTokenConfig, j as TokenManager, T as Tokens, U as UseApiConfig, d as UseApiModuleOptions, e as UseApiModuleReturn, o as UseApiState, V as ValidationError, t } from './apiModule.types-Bg7m0Xoy.js';
4
+ export { c as UseApiRecordActions, U as UseApiRecordConfig, a as UseApiRecordReturn, b as UseApiRecordState } from './useApiRecord.types-BsemqlQl.js';
5
5
  import 'react';
6
6
 
7
7
  declare function createApiClient(config: ApiClientConfig): AxiosInstance;