@abtnode/util 1.16.28-next-5a717317 → 1.16.28

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/async-pm2.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // You must install pm2 as project dependency
2
- const pm2 = require('pm2'); // eslint-disable-line import/no-extraneous-dependencies
2
+ const pm2 = require('@arcblock/pm2'); // eslint-disable-line import/no-extraneous-dependencies
3
3
  const { promisify } = require('util');
4
4
 
5
5
  const api = [
package/lib/blocklet.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const path = require('path');
2
2
  const { createHash } = require('crypto');
3
3
  const isUrl = require('is-url');
4
- const joinURL = require('url-join');
4
+ const { joinURL } = require('ufo');
5
5
  const { WELLKNOWN_SERVICE_PATH_PREFIX } = require('@abtnode/constant');
6
6
  const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/constant');
7
7
 
@@ -1,6 +1,6 @@
1
1
  const stringify = require('json-stable-stringify');
2
2
  const { toBase64, toBase58, toDid } = require('@ocap/util');
3
- const joinUrl = require('url-join');
3
+ const { joinURL } = require('ufo');
4
4
  const pRetry = require('p-retry');
5
5
  const debug = require('debug')('@abtnode/util:did-document');
6
6
  const axios = require('./axios');
@@ -52,7 +52,7 @@ const update = ({ id, services, didRegistryUrl, wallet, alsoKnownAs = [], blockl
52
52
 
53
53
  document.proof = proof;
54
54
 
55
- return axios.post(joinUrl(didRegistryUrl, '/.well-known/did-resolver/registries'), document, {
55
+ return axios.post(joinURL(didRegistryUrl, '/.well-known/did-resolver/registries'), document, {
56
56
  timeout: 10 * 1000,
57
57
  headers: { 'X-Blocklet-Server-Version': blockletServerVersion },
58
58
  });
package/lib/did-domain.js CHANGED
@@ -1,4 +1,4 @@
1
- const joinURL = require('url-join');
1
+ const { joinURL } = require('ufo');
2
2
 
3
3
  const axios = require('./axios');
4
4
 
@@ -1,4 +1,4 @@
1
- const joinUrl = require('url-join');
1
+ const { joinURL } = require('ufo');
2
2
  const Client = require('@ocap/client');
3
3
 
4
4
  // cache ocap clients for smaller memory consumption
@@ -11,7 +11,7 @@ const clients = new Map();
11
11
  * @return {import('@ocap/client')}
12
12
  */
13
13
  const getChainClient = (chainHost) => {
14
- const endpoint = joinUrl(chainHost, '/');
14
+ const endpoint = joinURL(chainHost, '/');
15
15
  if (!clients.has(endpoint)) {
16
16
  const client = new Client(endpoint);
17
17
  clients.set(endpoint, client);
package/lib/security.js CHANGED
@@ -1,5 +1,12 @@
1
+ const { BLOCKLET_MODES } = require('@blocklet/constant');
1
2
  const crypto = require('crypto');
2
3
  const AES = require('@ocap/mcrypto/lib/crypter/aes-legacy').default;
4
+ const semver = require('semver');
5
+ const uniq = require('lodash/uniq');
6
+ const { dirname, join, sep } = require('path');
7
+ const resolve = require('resolve/sync');
8
+ const { tmpdir, homedir } = require('os');
9
+ const which = require('which');
3
10
 
4
11
  const encrypt = (m, s, i) => AES.encrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, 'sha512').toString('hex'));
5
12
  const decrypt = (m, s, i) => AES.decrypt(m, crypto.pbkdf2Sync(i, s, 256, 32, 'sha512').toString('hex'));
@@ -36,10 +43,105 @@ const encodeEncryptionKey = (key) => escape(Buffer.from(key).toString('base64'))
36
43
  const unescape = (str) => (str + '==='.slice((str.length + 3) % 4)).replace(/-/g, '+').replace(/_/g, '/');
37
44
  const decodeEncryptionKey = (str) => new Uint8Array(Buffer.from(unescape(str), 'base64'));
38
45
 
46
+ const SAFE_NODE_VERSION = 'v21.6.0';
47
+ const canUseFileSystemIsolateApi = () => semver.gte(process.version, SAFE_NODE_VERSION);
48
+
49
+ const getPm2Path = () => {
50
+ try {
51
+ return resolve('@arcblock/pm2', { basedir: __dirname });
52
+ } catch (error) {
53
+ return null;
54
+ }
55
+ };
56
+
57
+ /**
58
+ *
59
+ * @param {string} executable
60
+ * @returns
61
+ */
62
+ function findExecutable(executable) {
63
+ try {
64
+ const fullPath = which.sync(executable);
65
+ return fullPath;
66
+ } catch (error) {
67
+ return null;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * @description
73
+ * @param {import('@abtnode/client').BlockletState & { environmentObj: [key: string]: string } } blocklet
74
+ * @param {true | false} enableFileSystemIsolation
75
+ * @return {string}
76
+ */
77
+ const getSecurityNodeOptions = (blocklet, enableFileSystemIsolation = true) => {
78
+ const options = [];
79
+
80
+ if (!canUseFileSystemIsolateApi() || !enableFileSystemIsolation) {
81
+ return options.join(' ').trim();
82
+ }
83
+
84
+ if (!blocklet) {
85
+ throw new Error('blocklet is not defined');
86
+ }
87
+
88
+ const pm2Path = getPm2Path();
89
+ const meiliSearchPath = findExecutable('meilisearch');
90
+ const blockletCliPath = findExecutable('blocklet');
91
+
92
+ options.push(
93
+ '--experimental-permission',
94
+ ...[
95
+ blocklet.environmentObj.BLOCKLET_DATA_DIR, // allow each component to write it's own data
96
+ blocklet.environmentObj.BLOCKLET_APP_DIR, // allow each component to write it's own source code: for example, to install dependencies
97
+ blocklet.environmentObj.BLOCKLET_LOG_DIR,
98
+ blocklet.environmentObj.BLOCKLET_CACHE_DIR,
99
+ join(blocklet.environmentObj.BLOCKLET_APP_DATA_DIR, '.projects'), // allow all components to access blocklet studio
100
+ tmpdir(),
101
+ ].map((dir) => `--allow-fs-write=${dir}`),
102
+ // @note: sqlite3 需要这个
103
+ '--allow-addons',
104
+ // FIXME: 目前我们非常多的应用都依赖使用 child_process 安装 sqlite,所以暂时放行。等 @blocklet/db ready 了,我们把限制再加上,@jianchao
105
+ '--allow-child-process'
106
+ );
107
+
108
+ // @note: 在正式环境下,用户不应该可以改变运行模式
109
+ if (
110
+ blocklet.mode === BLOCKLET_MODES.DEVELOPMENT ||
111
+ blocklet.environmentObj.BLOCKLET_MODE === BLOCKLET_MODES.DEVELOPMENT
112
+ ) {
113
+ options.push('--allow-worker', '--allow-fs-read=*');
114
+ options.push(`--allow-fs-write=${join(homedir(), '.npm', '_logs')}`);
115
+ } else {
116
+ options.push(
117
+ ...[
118
+ blocklet.environmentObj.BLOCKLET_LOG_DIR,
119
+ blocklet.environmentObj.BLOCKLET_CACHE_DIR,
120
+ blocklet.environmentObj.BLOCKLET_APP_DATA_DIR, // allow all components to read blocklet data
121
+ dirname(dirname(blocklet.environmentObj.BLOCKLET_APP_DIR)), // allow all components to read source code
122
+ pm2Path && dirname(dirname(dirname(dirname(pm2Path)))),
123
+ meiliSearchPath && dirname(dirname(meiliSearchPath)),
124
+ blockletCliPath && dirname(blockletCliPath),
125
+ dirname(dirname(process.execPath)),
126
+ process.cwd(),
127
+ tmpdir(),
128
+ ]
129
+ .filter(Boolean)
130
+ .filter((x) => x !== sep)
131
+ .map((dir) => `--allow-fs-read=${dir}`)
132
+ );
133
+ }
134
+
135
+ return uniq(options).join(' ').trim();
136
+ };
137
+
39
138
  module.exports = {
40
139
  encrypt,
41
140
  decrypt,
42
141
  formatEnv,
43
142
  encodeEncryptionKey,
44
143
  decodeEncryptionKey,
144
+ canUseFileSystemIsolateApi,
145
+ getSecurityNodeOptions,
146
+ SAFE_NODE_VERSION,
45
147
  };
@@ -1,4 +1,4 @@
1
- const axios = require('axios');
1
+ const { default: axios } = require('axios');
2
2
  const http = require('http');
3
3
  const https = require('https');
4
4
  const dns = require('dns');
@@ -1,4 +1,4 @@
1
- const axios = require('axios');
1
+ const { default: axios } = require('axios');
2
2
 
3
3
  module.exports = async (url, timeout = 5000) => {
4
4
  try {
package/lib/user.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const path = require('path');
2
2
  const fs = require('fs-extra');
3
- const joinUrl = require('url-join');
3
+ const { joinURL } = require('ufo');
4
4
  const cloneDeep = require('lodash/cloneDeep');
5
5
 
6
6
  const {
@@ -30,7 +30,7 @@ const getServerAvatarUrl = (baseUrl, info) => {
30
30
  // Do nothing;
31
31
  }
32
32
 
33
- return joinUrl(
33
+ return joinURL(
34
34
  origin,
35
35
  process.env.NODE_ENV === 'production' ? info.routing.adminPath : '',
36
36
  `/images/node.png?v=${info.version}`
@@ -49,7 +49,7 @@ const getAppAvatarUrl = (baseUrl, size = 80) => {
49
49
  // Do nothing;
50
50
  }
51
51
 
52
- return joinUrl(origin, WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?imageFilter=convert&f=png&h=${size}`);
52
+ return joinURL(origin, WELLKNOWN_SERVICE_PATH_PREFIX, `/blocklet/logo?imageFilter=convert&f=png&h=${size}`);
53
53
  };
54
54
 
55
55
  const getUserAvatarUrl = (baseUrl, avatar, info = {}, isServer = false) => {
@@ -76,10 +76,10 @@ const getUserAvatarUrl = (baseUrl, avatar, info = {}, isServer = false) => {
76
76
 
77
77
  if (isServer) {
78
78
  const prefix = process.env.NODE_ENV !== 'development' ? info.routing.adminPath : '';
79
- return joinUrl(origin, prefix, USER_AVATAR_PATH_PREFIX, info.did, filename);
79
+ return joinURL(origin, prefix, USER_AVATAR_PATH_PREFIX, info.did, filename);
80
80
  }
81
81
 
82
- return joinUrl(
82
+ return joinURL(
83
83
  origin,
84
84
  WELLKNOWN_SERVICE_PATH_PREFIX,
85
85
  USER_AVATAR_PATH_PREFIX,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.28-next-5a717317",
6
+ "version": "1.16.28",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,16 +18,17 @@
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.28-next-5a717317",
22
- "@abtnode/logger": "1.16.28-next-5a717317",
23
- "@blocklet/constant": "1.16.28-next-5a717317",
24
- "@blocklet/meta": "1.16.28-next-5a717317",
21
+ "@abtnode/constant": "1.16.28",
22
+ "@abtnode/logger": "1.16.28",
23
+ "@arcblock/pm2": "^5.4.0",
24
+ "@blocklet/constant": "1.16.28",
25
+ "@blocklet/meta": "1.16.28",
25
26
  "@ocap/client": "1.18.123",
26
27
  "@ocap/mcrypto": "1.18.123",
27
28
  "@ocap/util": "1.18.123",
28
29
  "@ocap/wallet": "1.18.123",
29
30
  "archiver": "^7.0.1",
30
- "axios": "^0.27.2",
31
+ "axios": "^1.7.2",
31
32
  "axios-mock-adapter": "^1.21.2",
32
33
  "axon": "^2.0.3",
33
34
  "chalk": "^4.1.2",
@@ -53,9 +54,10 @@
53
54
  "npm-packlist": "^7.0.4",
54
55
  "p-retry": "4.6.1",
55
56
  "parallel-transform": "^1.2.0",
56
- "pm2": "^5.3.1",
57
57
  "public-ip": "^4.0.4",
58
58
  "pump": "^3.0.0",
59
+ "resolve": "^1.22.8",
60
+ "semver": "^7.6.2",
59
61
  "semver-sort": "^1.0.0",
60
62
  "shelljs": "^0.8.5",
61
63
  "slugify": "^1.6.5",
@@ -66,15 +68,16 @@
66
68
  "through2-map": "^3.0.0",
67
69
  "to-semver": "^3.0.0",
68
70
  "transliteration": "^2.3.5",
69
- "url-join": "^4.0.1",
71
+ "ufo": "^1.5.3",
70
72
  "which": "^2.0.2"
71
73
  },
72
74
  "devDependencies": {
75
+ "@types/resolve": "^1.20.6",
73
76
  "cookie-signature": "^1.0.6",
74
77
  "detect-port": "^1.5.1",
75
78
  "express": "^4.18.2",
76
79
  "fs-extra": "^11.2.0",
77
80
  "jest": "^29.7.0"
78
81
  },
79
- "gitHead": "3624967f9549de3a25a87ed6b20f82519ddb4757"
82
+ "gitHead": "54db076a7e520bbc260f8cbf0af31dd50b86aef1"
80
83
  }