@codebit-programando-solucoes/codebit-web 1.1.21 → 1.1.24
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 +37 -14
- package/package.json +48 -17
package/dist/index.cjs
CHANGED
|
@@ -156,14 +156,19 @@ function setupRequestControl(url, externalSignal, timeout = API_CONFIG.timeout)
|
|
|
156
156
|
fullUrl
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
+
function isNativeBodyType(body) {
|
|
160
|
+
return 'string' == typeof body || body instanceof URLSearchParams || body instanceof Blob || body instanceof ArrayBuffer || ArrayBuffer.isView(body);
|
|
161
|
+
}
|
|
159
162
|
function prepareBodyAndContentType(config) {
|
|
160
|
-
if (config.body)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
if (!config.body) return;
|
|
164
|
+
if (config.body instanceof FormData) {
|
|
165
|
+
if (config.headers['Content-Type']) delete config.headers['Content-Type'];
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (isNativeBodyType(config.body)) return;
|
|
169
|
+
if ('object' == typeof config.body) {
|
|
170
|
+
config.body = JSON.stringify(config.body);
|
|
171
|
+
config.headers['Content-Type'] = 'application/json';
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
function isBinaryContent(contentType) {
|
|
@@ -234,7 +239,12 @@ async function makeRequest(url, options = {}) {
|
|
|
234
239
|
inferredResponseType = contentType?.includes('application/json') ? 'json' : isBinaryContent(contentType) ? 'blob' : 'text';
|
|
235
240
|
const finalResponseType = responseType || inferredResponseType;
|
|
236
241
|
let data;
|
|
237
|
-
|
|
242
|
+
try {
|
|
243
|
+
data = 'json' === finalResponseType ? await response.json() : 'blob' === finalResponseType ? await response.blob() : 'arraybuffer' === finalResponseType ? await response.arrayBuffer() : 'stream' === finalResponseType ? response.body : await response.text();
|
|
244
|
+
} catch (e) {
|
|
245
|
+
if (timeoutController.signal.aborted) throw new ApiNetworkError(e);
|
|
246
|
+
throw e;
|
|
247
|
+
}
|
|
238
248
|
return {
|
|
239
249
|
data,
|
|
240
250
|
status: response.status,
|
|
@@ -249,24 +259,24 @@ function makeRequestWithProgress(url, options) {
|
|
|
249
259
|
if ('blob' === responseType || 'arraybuffer' === responseType) xhr.responseType = responseType;
|
|
250
260
|
else if ('stream' === responseType) console.warn('Stream responseType is not supported with XMLHttpRequest');
|
|
251
261
|
const { timeoutController, timer } = setupRequestControl(fullUrl, externalSignal, timeout);
|
|
262
|
+
let abortReason = null;
|
|
252
263
|
const originalAbort = timeoutController.abort;
|
|
253
264
|
timeoutController.abort = function(reason) {
|
|
265
|
+
abortReason = reason;
|
|
254
266
|
originalAbort.call(this, reason);
|
|
255
267
|
xhr.abort();
|
|
256
268
|
};
|
|
257
269
|
xhr.open(method, fullUrl, true);
|
|
258
270
|
xhr.withCredentials = true;
|
|
259
|
-
const finalHeaders = buildHeaders(headers);
|
|
260
|
-
Object.keys(finalHeaders).forEach((key)=>{
|
|
261
|
-
if ('content-type' === key.toLowerCase() && body instanceof FormData) return;
|
|
262
|
-
xhr.setRequestHeader(key, finalHeaders[key]);
|
|
263
|
-
});
|
|
264
271
|
const config = {
|
|
265
|
-
headers:
|
|
272
|
+
headers: buildHeaders(headers),
|
|
266
273
|
body
|
|
267
274
|
};
|
|
268
275
|
prepareBodyAndContentType(config);
|
|
269
276
|
const requestBody = config.body;
|
|
277
|
+
Object.keys(config.headers).forEach((key)=>{
|
|
278
|
+
xhr.setRequestHeader(key, config.headers[key]);
|
|
279
|
+
});
|
|
270
280
|
if (onUploadProgress) xhr.upload.addEventListener('progress', onUploadProgress);
|
|
271
281
|
xhr.onload = function() {
|
|
272
282
|
if (timer) clearTimeout(timer);
|
|
@@ -298,6 +308,12 @@ function makeRequestWithProgress(url, options) {
|
|
|
298
308
|
apiNetworkError.errorCode = errorCode;
|
|
299
309
|
reject(apiNetworkError);
|
|
300
310
|
};
|
|
311
|
+
xhr.onabort = function() {
|
|
312
|
+
if (timer) clearTimeout(timer);
|
|
313
|
+
const abortError = new Error('TIMEOUT' === abortReason ? 'timeout exceeded' : 'The operation was aborted');
|
|
314
|
+
abortError.name = 'TIMEOUT' === abortReason ? 'TimeoutError' : 'AbortError';
|
|
315
|
+
reject(new ApiNetworkError(abortError));
|
|
316
|
+
};
|
|
301
317
|
xhr.ontimeout = function() {
|
|
302
318
|
if (timer) clearTimeout(timer);
|
|
303
319
|
const timeoutError = new ApiError({
|
|
@@ -309,6 +325,13 @@ function makeRequestWithProgress(url, options) {
|
|
|
309
325
|
timeoutError.code = ErrorCode.ERR_TIMEOUT;
|
|
310
326
|
reject(timeoutError);
|
|
311
327
|
};
|
|
328
|
+
if (timeoutController.signal.aborted) {
|
|
329
|
+
if (timer) clearTimeout(timer);
|
|
330
|
+
const abortError = new Error('The operation was aborted');
|
|
331
|
+
abortError.name = 'AbortError';
|
|
332
|
+
reject(new ApiNetworkError(abortError));
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
312
335
|
xhr.send(requestBody);
|
|
313
336
|
});
|
|
314
337
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebit-programando-solucoes/codebit-web",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.24",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -19,32 +19,60 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
+
"markdown-it": "^14.3.3",
|
|
22
23
|
"prop-types": ">=15.8.1",
|
|
23
24
|
"react": ">=19.2.0",
|
|
24
25
|
"react-dom": ">=19.2.0",
|
|
25
|
-
"react-router": ">=7.
|
|
26
|
-
"sass": ">=1.89.0"
|
|
27
|
-
"markdown-it": "^14.1.1"
|
|
26
|
+
"react-router": ">=7.18.2",
|
|
27
|
+
"sass": ">=1.89.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@
|
|
30
|
+
"@babel/core": "^7.29.13",
|
|
31
|
+
"@babel/preset-env": "^7.29.14",
|
|
32
|
+
"@eslint/js": "^9.39.5",
|
|
31
33
|
"@rsbuild/plugin-react": "1.4.3",
|
|
32
34
|
"@rsbuild/plugin-sass": "1.4.1",
|
|
33
|
-
"@rslib/core": "^0.18.
|
|
34
|
-
"@swc/core": "^1.
|
|
35
|
-
"
|
|
35
|
+
"@rslib/core": "^0.18.6",
|
|
36
|
+
"@swc/core": "^1.16.22",
|
|
37
|
+
"@types/jest": "^29.5.14",
|
|
38
|
+
"babel-jest": "^29.7.0",
|
|
39
|
+
"cross-env": "^10.1.0",
|
|
36
40
|
"del-cli": "^6.0.0",
|
|
37
|
-
"dotenv": "^17.
|
|
38
|
-
"eslint": "^9.
|
|
39
|
-
"eslint-plugin-jsdoc": "^54.
|
|
41
|
+
"dotenv": "^17.4.2",
|
|
42
|
+
"eslint": "^9.39.5",
|
|
43
|
+
"eslint-plugin-jsdoc": "^54.7.0",
|
|
40
44
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
41
45
|
"eslint-plugin-react": "^7.37.5",
|
|
42
46
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
43
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
44
|
-
"glob": "
|
|
45
|
-
"globals": "^16.
|
|
46
|
-
"
|
|
47
|
-
"
|
|
47
|
+
"eslint-plugin-react-refresh": "^0.4.26",
|
|
48
|
+
"glob": "^14.0.6",
|
|
49
|
+
"globals": "^16.5.0",
|
|
50
|
+
"jest": "^29.7.0",
|
|
51
|
+
"jsdom": "^22.1.0",
|
|
52
|
+
"prettier": "^3.10.1",
|
|
53
|
+
"prettier-plugin-jsdoc": "^1.8.1",
|
|
54
|
+
"react-router": "^7.18.6"
|
|
55
|
+
},
|
|
56
|
+
"jest": {
|
|
57
|
+
"moduleFileExtensions": [
|
|
58
|
+
"js",
|
|
59
|
+
"json",
|
|
60
|
+
"mjs"
|
|
61
|
+
],
|
|
62
|
+
"roots": [
|
|
63
|
+
"<rootDir>/src"
|
|
64
|
+
],
|
|
65
|
+
"testEnvironment": "node",
|
|
66
|
+
"testRegex": ".*\\.spec\\.js$",
|
|
67
|
+
"transform": {
|
|
68
|
+
".+\\.m?js$": "babel-jest"
|
|
69
|
+
},
|
|
70
|
+
"collectCoverageFrom": [
|
|
71
|
+
"src/**/*.js",
|
|
72
|
+
"!src/**/*.spec.js",
|
|
73
|
+
"!src/**/*.test-helper.js"
|
|
74
|
+
],
|
|
75
|
+
"coverageDirectory": "coverage"
|
|
48
76
|
},
|
|
49
77
|
"scripts": {
|
|
50
78
|
"format:write": "prettier --write \"src/**/*.{js,jsx,mjs}\"",
|
|
@@ -52,6 +80,9 @@
|
|
|
52
80
|
"lint:check": "eslint \"{src,apps,libs,test}/**/*.{js,jsx,mjs}\"",
|
|
53
81
|
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.{js,jsx,mjs}\" --fix",
|
|
54
82
|
"build": "rslib build",
|
|
55
|
-
"minify": "node scripts/minify.cjs"
|
|
83
|
+
"minify": "node scripts/minify.cjs",
|
|
84
|
+
"test": "jest",
|
|
85
|
+
"test:watch": "jest --watch",
|
|
86
|
+
"test:cov": "jest --coverage"
|
|
56
87
|
}
|
|
57
88
|
}
|