api-core-lib 3.3.3 → 4.4.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/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +17 -4
- package/dist/index.mjs +17 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -61,6 +61,7 @@ interface RequestConfig extends AxiosRequestConfig {
|
|
61
61
|
cancelTokenKey?: string;
|
62
62
|
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
63
63
|
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
64
|
+
isPublic?: boolean;
|
64
65
|
}
|
65
66
|
/**
|
66
67
|
* يمثل خيارات الاستعلام للترقيم والبحث والفرز.
|
@@ -203,6 +204,11 @@ interface UseApiConfig<T> {
|
|
203
204
|
refetchAfterChange?: boolean;
|
204
205
|
onSuccess?: (message: string, data?: T) => void;
|
205
206
|
onError?: (message: string, error?: ApiError) => void;
|
207
|
+
/**
|
208
|
+
* إعدادات Axios/Request افتراضية يتم تطبيقها على جميع طلبات الجلب (GET).
|
209
|
+
* مفيدة لتمرير إعدادات مثل isPublic.
|
210
|
+
*/
|
211
|
+
requestConfig?: RequestConfig;
|
206
212
|
}
|
207
213
|
|
208
214
|
/**
|
package/dist/index.d.ts
CHANGED
@@ -61,6 +61,7 @@ interface RequestConfig extends AxiosRequestConfig {
|
|
61
61
|
cancelTokenKey?: string;
|
62
62
|
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
63
63
|
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
64
|
+
isPublic?: boolean;
|
64
65
|
}
|
65
66
|
/**
|
66
67
|
* يمثل خيارات الاستعلام للترقيم والبحث والفرز.
|
@@ -203,6 +204,11 @@ interface UseApiConfig<T> {
|
|
203
204
|
refetchAfterChange?: boolean;
|
204
205
|
onSuccess?: (message: string, data?: T) => void;
|
205
206
|
onError?: (message: string, error?: ApiError) => void;
|
207
|
+
/**
|
208
|
+
* إعدادات Axios/Request افتراضية يتم تطبيقها على جميع طلبات الجلب (GET).
|
209
|
+
* مفيدة لتمرير إعدادات مثل isPublic.
|
210
|
+
*/
|
211
|
+
requestConfig?: RequestConfig;
|
206
212
|
}
|
207
213
|
|
208
214
|
/**
|
package/dist/index.js
CHANGED
@@ -96,6 +96,9 @@ function createApiClient(config) {
|
|
96
96
|
timeout = 15e3,
|
97
97
|
headers = {},
|
98
98
|
withCredentials = false
|
99
|
+
// onRefreshError = () => {},
|
100
|
+
// responseType = 'json',
|
101
|
+
// refreshTokenConfig,
|
99
102
|
} = config;
|
100
103
|
const axiosInstance = import_axios.default.create({
|
101
104
|
baseURL,
|
@@ -106,7 +109,10 @@ function createApiClient(config) {
|
|
106
109
|
let tokenRefreshPromise = null;
|
107
110
|
axiosInstance.interceptors.request.use(async (req) => {
|
108
111
|
req.headers["X-Request-ID"] = (0, import_uuid.v4)();
|
109
|
-
if (req.
|
112
|
+
if (req.isPublic) {
|
113
|
+
console.log(`[API Core] Skipping token for public request: ${req.url}`);
|
114
|
+
return req;
|
115
|
+
}
|
110
116
|
if (tokenRefreshPromise) {
|
111
117
|
await tokenRefreshPromise;
|
112
118
|
}
|
@@ -125,6 +131,9 @@ function createApiClient(config) {
|
|
125
131
|
if (tokens.accessToken && !tokenManager.isHttpOnly()) {
|
126
132
|
const tokenType = tokens.tokenType || "Bearer";
|
127
133
|
req.headers.Authorization = `${tokenType} ${tokens.accessToken}`;
|
134
|
+
console.log(`[API Core] Token attached to request: ${req.url}`);
|
135
|
+
} else {
|
136
|
+
console.warn(`[API Core] No token attached for request: ${req.url}`);
|
128
137
|
}
|
129
138
|
return req;
|
130
139
|
}, (error) => Promise.reject(error));
|
@@ -350,7 +359,7 @@ function useApi(axiosInstance, config) {
|
|
350
359
|
initialQuery = { limit: 10 },
|
351
360
|
enabled = true,
|
352
361
|
refetchAfterChange = true,
|
353
|
-
|
362
|
+
requestConfig,
|
354
363
|
onSuccess,
|
355
364
|
onError
|
356
365
|
} = config;
|
@@ -367,12 +376,16 @@ function useApi(axiosInstance, config) {
|
|
367
376
|
const currentQuery = options || queryOptions;
|
368
377
|
setState((prev) => ({ ...prev, data: null, loading: true, error: null }));
|
369
378
|
const queryString = buildPaginateQuery(currentQuery);
|
370
|
-
const result = await apiServices.getWithQuery(queryString, {
|
379
|
+
const result = await apiServices.getWithQuery(queryString, {
|
380
|
+
cancelTokenKey: endpoint,
|
381
|
+
...requestConfig
|
382
|
+
// <-- هنا نمرر الإعدادات الافتراضية
|
383
|
+
});
|
371
384
|
setState(result);
|
372
385
|
if (!result.success && onError) {
|
373
386
|
onError(result.message || "Fetch failed", result.error || void 0);
|
374
387
|
}
|
375
|
-
}, [apiServices, queryOptions, endpoint, onError]);
|
388
|
+
}, [apiServices, queryOptions, endpoint, onError, requestConfig]);
|
376
389
|
(0, import_react.useEffect)(() => {
|
377
390
|
if (enabled) {
|
378
391
|
fetchData();
|
package/dist/index.mjs
CHANGED
@@ -54,6 +54,9 @@ function createApiClient(config) {
|
|
54
54
|
timeout = 15e3,
|
55
55
|
headers = {},
|
56
56
|
withCredentials = false
|
57
|
+
// onRefreshError = () => {},
|
58
|
+
// responseType = 'json',
|
59
|
+
// refreshTokenConfig,
|
57
60
|
} = config;
|
58
61
|
const axiosInstance = axios.create({
|
59
62
|
baseURL,
|
@@ -64,7 +67,10 @@ function createApiClient(config) {
|
|
64
67
|
let tokenRefreshPromise = null;
|
65
68
|
axiosInstance.interceptors.request.use(async (req) => {
|
66
69
|
req.headers["X-Request-ID"] = uuidv4();
|
67
|
-
if (req.
|
70
|
+
if (req.isPublic) {
|
71
|
+
console.log(`[API Core] Skipping token for public request: ${req.url}`);
|
72
|
+
return req;
|
73
|
+
}
|
68
74
|
if (tokenRefreshPromise) {
|
69
75
|
await tokenRefreshPromise;
|
70
76
|
}
|
@@ -83,6 +89,9 @@ function createApiClient(config) {
|
|
83
89
|
if (tokens.accessToken && !tokenManager.isHttpOnly()) {
|
84
90
|
const tokenType = tokens.tokenType || "Bearer";
|
85
91
|
req.headers.Authorization = `${tokenType} ${tokens.accessToken}`;
|
92
|
+
console.log(`[API Core] Token attached to request: ${req.url}`);
|
93
|
+
} else {
|
94
|
+
console.warn(`[API Core] No token attached for request: ${req.url}`);
|
86
95
|
}
|
87
96
|
return req;
|
88
97
|
}, (error) => Promise.reject(error));
|
@@ -308,7 +317,7 @@ function useApi(axiosInstance, config) {
|
|
308
317
|
initialQuery = { limit: 10 },
|
309
318
|
enabled = true,
|
310
319
|
refetchAfterChange = true,
|
311
|
-
|
320
|
+
requestConfig,
|
312
321
|
onSuccess,
|
313
322
|
onError
|
314
323
|
} = config;
|
@@ -325,12 +334,16 @@ function useApi(axiosInstance, config) {
|
|
325
334
|
const currentQuery = options || queryOptions;
|
326
335
|
setState((prev) => ({ ...prev, data: null, loading: true, error: null }));
|
327
336
|
const queryString = buildPaginateQuery(currentQuery);
|
328
|
-
const result = await apiServices.getWithQuery(queryString, {
|
337
|
+
const result = await apiServices.getWithQuery(queryString, {
|
338
|
+
cancelTokenKey: endpoint,
|
339
|
+
...requestConfig
|
340
|
+
// <-- هنا نمرر الإعدادات الافتراضية
|
341
|
+
});
|
329
342
|
setState(result);
|
330
343
|
if (!result.success && onError) {
|
331
344
|
onError(result.message || "Fetch failed", result.error || void 0);
|
332
345
|
}
|
333
|
-
}, [apiServices, queryOptions, endpoint, onError]);
|
346
|
+
}, [apiServices, queryOptions, endpoint, onError, requestConfig]);
|
334
347
|
useEffect(() => {
|
335
348
|
if (enabled) {
|
336
349
|
fetchData();
|