@abtnode/util 1.16.44-beta-20250513-030435-c2d99062 → 1.16.44-beta-20250516-225119-c0b5ec8d
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/lib/get-pm2-process-info.js +2 -1
- package/lib/security.js +2 -2
- package/package.json +11 -10
- package/lib/custom-error.js +0 -65
- package/lib/format-error.js +0 -36
package/lib/security.js
CHANGED
|
@@ -7,7 +7,7 @@ const { dirname, join, sep } = require('path');
|
|
|
7
7
|
const resolve = require('resolve/sync');
|
|
8
8
|
const { tmpdir, homedir } = require('os');
|
|
9
9
|
const which = require('which');
|
|
10
|
-
const {
|
|
10
|
+
const { withHttps, withHttp } = require('ufo');
|
|
11
11
|
|
|
12
12
|
const cloneDeep = require('./deep-clone');
|
|
13
13
|
|
|
@@ -286,7 +286,7 @@ async function patchCors(rawConfig, { node, blocklet }) {
|
|
|
286
286
|
const sites = (federated?.sites || []).filter((x) => x?.isMaster !== false || x.status === 'approved');
|
|
287
287
|
const siteAlias = [];
|
|
288
288
|
for (const site of sites) {
|
|
289
|
-
siteAlias.push(
|
|
289
|
+
siteAlias.push(new URL(site.appUrl).hostname);
|
|
290
290
|
siteAlias.push(...(site.aliasDomain || []));
|
|
291
291
|
}
|
|
292
292
|
result.push(...siteAlias.map((x) => withHttps(x)), ...siteAlias.map((x) => withHttp(x)));
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.44-beta-
|
|
6
|
+
"version": "1.16.44-beta-20250516-225119-c0b5ec8d",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,15 +18,16 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.16.44-beta-
|
|
22
|
-
"@arcblock/did": "1.20.
|
|
21
|
+
"@abtnode/constant": "1.16.44-beta-20250516-225119-c0b5ec8d",
|
|
22
|
+
"@arcblock/did": "1.20.11",
|
|
23
23
|
"@arcblock/pm2": "^5.4.0",
|
|
24
|
-
"@blocklet/constant": "1.16.44-beta-
|
|
25
|
-
"@blocklet/
|
|
26
|
-
"@
|
|
27
|
-
"@ocap/
|
|
28
|
-
"@ocap/
|
|
29
|
-
"@ocap/
|
|
24
|
+
"@blocklet/constant": "1.16.44-beta-20250516-225119-c0b5ec8d",
|
|
25
|
+
"@blocklet/error": "^0.2.4",
|
|
26
|
+
"@blocklet/meta": "1.16.44-beta-20250516-225119-c0b5ec8d",
|
|
27
|
+
"@ocap/client": "1.20.11",
|
|
28
|
+
"@ocap/mcrypto": "1.20.11",
|
|
29
|
+
"@ocap/util": "1.20.11",
|
|
30
|
+
"@ocap/wallet": "1.20.11",
|
|
30
31
|
"archiver": "^7.0.1",
|
|
31
32
|
"axios": "^1.7.9",
|
|
32
33
|
"axios-mock-adapter": "^2.1.0",
|
|
@@ -86,5 +87,5 @@
|
|
|
86
87
|
"fs-extra": "^11.2.0",
|
|
87
88
|
"jest": "^29.7.0"
|
|
88
89
|
},
|
|
89
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "eb15dee761c0ea273981c848992e5f29b94a69dc"
|
|
90
91
|
}
|
package/lib/custom-error.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @extends Error
|
|
3
|
-
*/
|
|
4
|
-
class CustomError extends Error {
|
|
5
|
-
/**
|
|
6
|
-
* @param {number|string} code - Error code
|
|
7
|
-
* @param {...any} params - Additional error parameters
|
|
8
|
-
*/
|
|
9
|
-
constructor(code = 'GENERIC', ...params) {
|
|
10
|
-
super(...params);
|
|
11
|
-
|
|
12
|
-
if (Error.captureStackTrace) {
|
|
13
|
-
Error.captureStackTrace(this, CustomError);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.code = code;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const getStatusFromError = (err) => {
|
|
21
|
-
if (!err) {
|
|
22
|
-
return 200;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Handle Axios errors
|
|
26
|
-
if (err?.isAxiosError) {
|
|
27
|
-
return err.response?.status || 500;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Handle Fetch errors (including TypeError for network errors)
|
|
31
|
-
if (err instanceof TypeError && err.message.includes('fetch')) {
|
|
32
|
-
return 503; // Service Unavailable
|
|
33
|
-
}
|
|
34
|
-
if (err?.name === 'FetchError' && err?.response) {
|
|
35
|
-
return err.response?.status || 500;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Check for common validation library errors
|
|
39
|
-
if (
|
|
40
|
-
// Zod validation error
|
|
41
|
-
err?.name === 'ZodError' ||
|
|
42
|
-
// Joi validation error
|
|
43
|
-
err?.name === 'ValidationError' ||
|
|
44
|
-
// Express-validator error
|
|
45
|
-
Array.isArray(err?.errors) ||
|
|
46
|
-
// Yup validation error
|
|
47
|
-
err?.name === 'ValidationError' ||
|
|
48
|
-
// Class-validator error
|
|
49
|
-
Array.isArray(err?.constraints) ||
|
|
50
|
-
// Ajv validation error
|
|
51
|
-
err?.keyword === 'validation'
|
|
52
|
-
) {
|
|
53
|
-
return 400;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// infer status code from error code
|
|
57
|
-
const status =
|
|
58
|
-
['status', 'statusCode', 'code']
|
|
59
|
-
.map((key) => err[key])
|
|
60
|
-
.find((code) => typeof code === 'number' && code >= 400 && code < 600) || 500;
|
|
61
|
-
return status;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
module.exports = CustomError;
|
|
65
|
-
module.exports.getStatusFromError = getStatusFromError;
|
package/lib/format-error.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
const formatError = (err) => {
|
|
2
|
-
const { details, errors, response } = err;
|
|
3
|
-
|
|
4
|
-
// graphql error
|
|
5
|
-
if (Array.isArray(errors)) {
|
|
6
|
-
return errors.map((x) => x.message).join('\n');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// joi validate error
|
|
10
|
-
if (Array.isArray(details)) {
|
|
11
|
-
const formatted = details.map((e) => {
|
|
12
|
-
const errorMessage = e.message.replace(/["]/g, "'");
|
|
13
|
-
const errorPath = e.path.join('.');
|
|
14
|
-
return `${errorPath}: ${errorMessage}`;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return `Validate failed: ${formatted.join(';')}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// axios error
|
|
21
|
-
if (response) {
|
|
22
|
-
if (response.data.message) {
|
|
23
|
-
return response.data.message;
|
|
24
|
-
}
|
|
25
|
-
if (response.data.error) {
|
|
26
|
-
return response.data.error;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const data = typeof response.data === 'string' ? response.data.slice(0, 200) : JSON.stringify(response.data);
|
|
30
|
-
return `Request failed: ${response.status} ${response.statusText}: ${data}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return err.message;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
module.exports = formatError;
|