react-js-plugins 3.4.0 → 3.6.0
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/README.md +1 -2
- package/dist/chunkautils/chunk83454.d.ts +10 -2
- package/dist/chunkautils/chunk83454.js +73 -46
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,11 +34,10 @@ It supports automatic date formatting, optional data encryption/decryption, seam
|
|
|
34
34
|
|
|
35
35
|
```ts
|
|
36
36
|
const apiPrivate = createAxiosInstance({
|
|
37
|
-
baseURL:
|
|
37
|
+
baseURL: 'https://jsonplaceholder.typicode.com',
|
|
38
38
|
timeout: 30000,
|
|
39
39
|
withCredentials: true,
|
|
40
40
|
enableDateTransform: true,
|
|
41
|
-
enableEncryptDecrypt: true,
|
|
42
41
|
transformRequest: (data) => transform(data),
|
|
43
42
|
transformResponse: (data) => transform(data),
|
|
44
43
|
handleAuthError: async (instance, originalRequest, error) => {
|
|
@@ -14,8 +14,16 @@ interface AxiosConfigProps {
|
|
|
14
14
|
enablePrivateMode?: boolean;
|
|
15
15
|
getToken?: () => string | null;
|
|
16
16
|
handleAuthError?: (axiosInstance: AxiosInstance, originalRequest: AxiosRequestConfig, err: AxiosError) => Promise<AxiosResponse>;
|
|
17
|
-
transformRequest?: (
|
|
18
|
-
|
|
17
|
+
transformRequest?: (params: {
|
|
18
|
+
data: any;
|
|
19
|
+
config: AxiosRequestConfig;
|
|
20
|
+
}) => any;
|
|
21
|
+
transformResponse?: (params: {
|
|
22
|
+
data: any;
|
|
23
|
+
config: AxiosRequestConfig;
|
|
24
|
+
status: number;
|
|
25
|
+
headers: any;
|
|
26
|
+
}) => any;
|
|
19
27
|
defaultHeaders?: Record<string, string>;
|
|
20
28
|
onError?: (error: AxiosError) => void;
|
|
21
29
|
}
|
|
@@ -58,7 +58,7 @@ import axios from 'axios';
|
|
|
58
58
|
import moment from 'moment';
|
|
59
59
|
var dateTransformer = function (data, depth) {
|
|
60
60
|
if (depth === void 0) { depth = 0; }
|
|
61
|
-
if (depth
|
|
61
|
+
if (depth >= 20)
|
|
62
62
|
return data;
|
|
63
63
|
if (data instanceof Date) {
|
|
64
64
|
return moment(data).format('YYYY-MM-DDTHH:mm:ss');
|
|
@@ -89,52 +89,82 @@ export var createAxiosInstance = function (_a) {
|
|
|
89
89
|
], axios.defaults.transformRequest, true) : axios.defaults.transformRequest,
|
|
90
90
|
});
|
|
91
91
|
axiosInstance.defaults.headers.common = __assign(__assign({}, axiosInstance.defaults.headers.common), defaultHeaders);
|
|
92
|
-
axiosInstance.interceptors.request.use(function (config) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
92
|
+
axiosInstance.interceptors.request.use(function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
93
|
+
var token, transformed, _a, error_1;
|
|
94
|
+
var _b, _c;
|
|
95
|
+
return __generator(this, function (_d) {
|
|
96
|
+
switch (_d.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
_d.trys.push([0, 5, , 6]);
|
|
99
|
+
if ((_b = config.enablePrivateMode) !== null && _b !== void 0 ? _b : enablePrivateMode) {
|
|
100
|
+
token = getToken === null || getToken === void 0 ? void 0 : getToken();
|
|
101
|
+
if (token) {
|
|
102
|
+
config.headers = config.headers || {};
|
|
103
|
+
config.headers.Authorization = "Bearer ".concat(token);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
console.warn('⚠️ No access token found in localStorage.');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!(config === null || config === void 0 ? void 0 : config.data)) return [3 /*break*/, 4];
|
|
110
|
+
if (!(typeof transformRequest === 'function')) return [3 /*break*/, 2];
|
|
111
|
+
return [4 /*yield*/, Promise.resolve(transformRequest({ data: config.data, config: config }))];
|
|
112
|
+
case 1:
|
|
113
|
+
_a = (_c = (_d.sent())) !== null && _c !== void 0 ? _c : config.data;
|
|
114
|
+
return [3 /*break*/, 3];
|
|
115
|
+
case 2:
|
|
116
|
+
_a = config.data;
|
|
117
|
+
_d.label = 3;
|
|
118
|
+
case 3:
|
|
119
|
+
transformed = _a;
|
|
120
|
+
config.data = transformed;
|
|
121
|
+
_d.label = 4;
|
|
122
|
+
case 4: return [2 /*return*/, config];
|
|
123
|
+
case 5:
|
|
124
|
+
error_1 = _d.sent();
|
|
125
|
+
console.error('❌ Request Interceptor Error:', error_1);
|
|
126
|
+
return [2 /*return*/, Promise.reject(error_1)];
|
|
127
|
+
case 6: return [2 /*return*/];
|
|
108
128
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
catch (error) {
|
|
112
|
-
console.error('❌ Request Interceptor Error:', error);
|
|
113
|
-
return Promise.reject(error);
|
|
114
|
-
}
|
|
115
|
-
}, function (error) {
|
|
129
|
+
});
|
|
130
|
+
}); }, function (error) {
|
|
116
131
|
console.error('❌ Axios Request Error:', error);
|
|
117
132
|
return Promise.reject(error);
|
|
118
133
|
});
|
|
119
|
-
axiosInstance.interceptors.response.use(function (response) {
|
|
120
|
-
var _a;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
134
|
+
axiosInstance.interceptors.response.use(function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
135
|
+
var result, _a, _b, error_2;
|
|
136
|
+
return __generator(this, function (_c) {
|
|
137
|
+
switch (_c.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
_c.trys.push([0, 5, , 6]);
|
|
140
|
+
if (!(typeof transformResponse === 'function')) return [3 /*break*/, 4];
|
|
141
|
+
result = transformResponse({
|
|
142
|
+
data: response.data,
|
|
143
|
+
config: response.config,
|
|
144
|
+
status: response.status,
|
|
145
|
+
headers: response.headers,
|
|
146
|
+
});
|
|
147
|
+
_a = response;
|
|
148
|
+
if (!(result instanceof Promise)) return [3 /*break*/, 2];
|
|
149
|
+
return [4 /*yield*/, result];
|
|
150
|
+
case 1:
|
|
151
|
+
_b = _c.sent();
|
|
152
|
+
return [3 /*break*/, 3];
|
|
153
|
+
case 2:
|
|
154
|
+
_b = result !== null && result !== void 0 ? result : response.data;
|
|
155
|
+
_c.label = 3;
|
|
156
|
+
case 3:
|
|
157
|
+
_a.data = _b;
|
|
158
|
+
_c.label = 4;
|
|
159
|
+
case 4: return [2 /*return*/, response];
|
|
160
|
+
case 5:
|
|
161
|
+
error_2 = _c.sent();
|
|
162
|
+
console.error('❌ Response Transform Error:', error_2);
|
|
163
|
+
return [2 /*return*/, Promise.reject(error_2)];
|
|
164
|
+
case 6: return [2 /*return*/];
|
|
130
165
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
catch (error) {
|
|
134
|
-
console.error('❌ Response Transform Error:', error);
|
|
135
|
-
return Promise.reject(error);
|
|
136
|
-
}
|
|
137
|
-
}, function (err) { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
});
|
|
167
|
+
}); }, function (err) { return __awaiter(void 0, void 0, void 0, function () {
|
|
138
168
|
var originalRequest, status, authError_1;
|
|
139
169
|
var _a, _b, _c, _d, _e;
|
|
140
170
|
return __generator(this, function (_f) {
|
|
@@ -176,10 +206,7 @@ export var createAxiosInstance = function (_a) {
|
|
|
176
206
|
return [2 /*return*/, Promise.reject(authError_1)];
|
|
177
207
|
case 4:
|
|
178
208
|
if (status === 500) {
|
|
179
|
-
return [2 /*return*/, Promise.reject((_c = (_b = err.response) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : {
|
|
180
|
-
title: 'Internal Server Error',
|
|
181
|
-
status: status,
|
|
182
|
-
})];
|
|
209
|
+
return [2 /*return*/, Promise.reject((_c = (_b = err.response) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : { title: 'Internal Server Error', status: status })];
|
|
183
210
|
}
|
|
184
211
|
return [2 /*return*/, Promise.reject((_e = (_d = err.response) === null || _d === void 0 ? void 0 : _d.data) !== null && _e !== void 0 ? _e : {
|
|
185
212
|
title: 'Something went wrong',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-js-plugins",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "A powerful and efficient React utility library designed to enhance application performance by streamlining and simplifying the management of complex asynchronous operations.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|