@abtnode/util 1.16.44-beta-20250513-030435-c2d99062 → 1.16.44-beta-20250518-020443-77ba168f

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.
@@ -1,5 +1,6 @@
1
+ const { CustomError } = require('@blocklet/error');
2
+
1
3
  const pm2 = require('./async-pm2');
2
- const CustomError = require('./custom-error');
3
4
 
4
5
  const noop = () => {};
5
6
 
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 { parseURL, withHttps, withHttp } = require('ufo');
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(parseURL(site.appUrl).host);
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-20250513-030435-c2d99062",
6
+ "version": "1.16.44-beta-20250518-020443-77ba168f",
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-20250513-030435-c2d99062",
22
- "@arcblock/did": "1.20.8",
21
+ "@abtnode/constant": "1.16.44-beta-20250518-020443-77ba168f",
22
+ "@arcblock/did": "1.20.11",
23
23
  "@arcblock/pm2": "^5.4.0",
24
- "@blocklet/constant": "1.16.44-beta-20250513-030435-c2d99062",
25
- "@blocklet/meta": "1.16.44-beta-20250513-030435-c2d99062",
26
- "@ocap/client": "1.20.8",
27
- "@ocap/mcrypto": "1.20.8",
28
- "@ocap/util": "1.20.8",
29
- "@ocap/wallet": "1.20.8",
24
+ "@blocklet/constant": "1.16.44-beta-20250518-020443-77ba168f",
25
+ "@blocklet/error": "^0.2.4",
26
+ "@blocklet/meta": "1.16.44-beta-20250518-020443-77ba168f",
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": "c3a3efef44ccf08705abb47875edba6169e76faa"
90
+ "gitHead": "8464d53e8d44b255afa6032e37d8d4ab7be76e67"
90
91
  }
@@ -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;
@@ -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;