@abtnode/core 1.8.5 → 1.8.8

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/api/node.js CHANGED
@@ -30,12 +30,11 @@ class NodeAPI {
30
30
  *
31
31
  * @param {object} state Node StateDB
32
32
  */
33
- constructor(state, blockletRegistry) {
33
+ constructor(state) {
34
34
  assert.notStrictEqual(state, undefined, 'argument state can not be undefined');
35
35
  assert.notStrictEqual(state, null, 'argument state can not be null');
36
36
 
37
37
  this.state = state;
38
- this.blockletRegistry = blockletRegistry;
39
38
  }
40
39
 
41
40
  // eslint-disable-next-line no-unused-vars
@@ -66,7 +65,6 @@ class NodeAPI {
66
65
  const newBlockletRegistryList = info.blockletRegistryList.map((x) => ({ ...x, selected: false }));
67
66
  newBlockletRegistryList.push({ ...newBlockletRegistry, url: sanitized, selected: true, protected: false });
68
67
 
69
- this.blockletRegistry.clearCache();
70
68
  return this.state.updateNodeInfo({ blockletRegistryList: newBlockletRegistryList });
71
69
  }
72
70
 
@@ -80,8 +78,6 @@ class NodeAPI {
80
78
  throw new Error(`Blocklet registry does not exist: ${sanitized}`);
81
79
  }
82
80
 
83
- this.blockletRegistry.clearCache();
84
-
85
81
  const blockletRegistryList = info.blockletRegistryList.filter((x) => x.url !== sanitized);
86
82
  if (!blockletRegistryList.find((x) => x.selected)) {
87
83
  blockletRegistryList[0].selected = true;
@@ -99,7 +95,6 @@ class NodeAPI {
99
95
  throw new Error(`Blocklet registry does not exist: ${sanitized}`);
100
96
  }
101
97
 
102
- this.blockletRegistry.clearCache();
103
98
  return this.state.updateNodeInfo({
104
99
  blockletRegistryList: info.blockletRegistryList.map((x) => ({ ...x, selected: x.url === sanitized })),
105
100
  });
@@ -21,6 +21,7 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
21
21
  secure: x.secure || false,
22
22
  validation: x.validation || '',
23
23
  custom: x.custom,
24
+ shared: x.shared,
24
25
  };
25
26
  return acc;
26
27
  }, {});
@@ -55,7 +56,7 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
55
56
  });
56
57
 
57
58
  newConfig.forEach((config) => {
58
- const { name, key, value, default: defaultVal, required, description, secure, validation, custom } = config;
59
+ const { name, key, value, default: defaultVal, required, description, secure, validation, custom, shared } = config;
59
60
  // 新增、更新或者删除
60
61
  if (key) {
61
62
  const originalVal = oldConfig[key] || {};
@@ -67,6 +68,7 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
67
68
  validation: validation || '',
68
69
  secure: secure === undefined ? false : secure,
69
70
  custom: custom === undefined ? false : custom,
71
+ shared,
70
72
  };
71
73
  return;
72
74
  }
@@ -81,6 +83,7 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
81
83
  validation: validation || '',
82
84
  secure: secure === undefined ? false : secure,
83
85
  custom: custom === undefined ? false : custom,
86
+ shared,
84
87
  };
85
88
 
86
89
  return;
@@ -94,6 +97,7 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
94
97
  validation: validation || '',
95
98
  secure: secure === undefined ? false : secure,
96
99
  custom: custom === undefined ? false : custom,
100
+ shared,
97
101
  };
98
102
  }
99
103
  });
@@ -109,6 +113,7 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
109
113
  secure: mergedObj[key].secure,
110
114
  validation: mergedObj[key].validation,
111
115
  custom: mergedObj[key].custom,
116
+ shared: mergedObj[key].shared,
112
117
  }));
113
118
 
114
119
  return mergedConfig;
@@ -2211,6 +2211,9 @@ class BlockletManager extends BaseBlockletManager {
2211
2211
  } else {
2212
2212
  newBlocklet.children.push(newChild);
2213
2213
  }
2214
+
2215
+ checkDuplicateComponents(newBlocklet.children);
2216
+
2214
2217
  await this._upsertDynamicNavigation(newBlocklet.meta.did, newChild);
2215
2218
 
2216
2219
  await this._downloadBlocklet(newBlocklet, oldBlocklet);
@@ -2771,7 +2774,6 @@ class BlockletManager extends BaseBlockletManager {
2771
2774
  // ids
2772
2775
  context.skippedProcessIds = getSkippedProcessIds({ newBlocklet, oldBlocklet, context });
2773
2776
 
2774
- const oldVersion = oldBlocklet.meta.version;
2775
2777
  const action = semver.gt(oldBlocklet.meta.version, version) ? 'downgrade' : 'upgrade';
2776
2778
  try {
2777
2779
  // delete old process
@@ -2817,26 +2819,21 @@ class BlockletManager extends BaseBlockletManager {
2817
2819
  });
2818
2820
  await forEachBlocklet(blocklet, postInstall, { parallel: true });
2819
2821
 
2820
- // run migrations
2821
- const runMigration = (b, { ancestors }) => {
2822
- // BUG: 本身的定义是在执行 upgrade 操作时进行 migration,但是父 blocklet upgrade 时,子 blocklet 可能不需要 upgrade,就会导致子 blocklet 多走了一遍 migration 流程
2823
- if (b.meta.did === did) {
2822
+ logger.info('start migration');
2823
+ try {
2824
+ const oldVersions = {};
2825
+ forEachBlockletSync(oldBlocklet, (b, { id }) => {
2826
+ oldVersions[id] = b.meta.version;
2827
+ });
2828
+ const runMigration = (b, { id, ancestors }) => {
2824
2829
  return runMigrationScripts({
2825
2830
  blocklet: b,
2826
2831
  appDir: b.env.appDir,
2827
2832
  env: getRuntimeEnvironments(b, nodeEnvironments, ancestors),
2828
- oldVersion,
2829
- newVersion: version,
2830
- did: b.meta.did,
2831
- notification: states.notification,
2832
- context,
2833
+ oldVersion: oldVersions[id],
2834
+ newVersion: b.meta.version,
2833
2835
  });
2834
- }
2835
- return Promise.resolve();
2836
- };
2837
- logger.info('start migration');
2838
-
2839
- try {
2836
+ };
2840
2837
  await forEachBlocklet(blocklet, runMigration, { parallel: true });
2841
2838
  } catch (error) {
2842
2839
  logger.error('Failed to migrate blocklet', { did, error });
@@ -102,6 +102,10 @@ module.exports = async ({
102
102
  printSuccess = logger.info,
103
103
  printError = logger.error,
104
104
  }) => {
105
+ if (!oldVersion) {
106
+ return;
107
+ }
108
+
105
109
  const baseDir = env.BLOCKLET_DATA_DIR;
106
110
 
107
111
  const scriptsDir = path.join(appDir, 'migration');
@@ -125,4 +129,6 @@ module.exports = async ({
125
129
  printInfo,
126
130
  printSuccess,
127
131
  });
132
+
133
+ fs.removeSync(backupDir);
128
134
  };
@@ -1,6 +1,4 @@
1
- const { BlockletGroup } = require('@blocklet/meta/lib/constants');
2
1
  const joinURL = require('url-join');
3
- const get = require('lodash/get');
4
2
  const { BLOCKLET_STORE_API_PREFIX } = require('@abtnode/constant');
5
3
 
6
4
  const { name } = require('../../package.json');
@@ -10,48 +8,15 @@ const logger = require('@abtnode/logger')(`${name}:blocklet:registry`); // eslin
10
8
  const request = require('../util/request');
11
9
 
12
10
  const states = require('../states');
13
- const isRequirementsSatisfied = require('../util/requirement');
14
11
  const { fixAndVerifyMetaFromStore } = require('../util/blocklet');
15
- const { translate } = require('../locales');
16
12
  const { validateRegistryURL, getRegistryMeta } = require('../util/registry');
17
13
 
18
- const DEFAULT_REFRESH_INTERVAL = 1 * 60 * 1000;
19
- const MAX_REFRESH_INTERVAL = 1 * 60 * 1000;
20
-
21
14
  class BlockletRegistry {
22
15
  constructor() {
23
16
  this.blocklets = [];
24
17
  this.cacheId = '';
25
18
  }
26
19
 
27
- getCron(refreshInterval = DEFAULT_REFRESH_INTERVAL) {
28
- const interval = Math.min(Math.max(Number(refreshInterval), DEFAULT_REFRESH_INTERVAL), MAX_REFRESH_INTERVAL); // Should between 20 ~ 60 seconds
29
- return {
30
- name: 'refetch-blocklet-registry',
31
- time: `*/${Math.round(interval / 1000)} * * * * *`,
32
- fn: this._init.bind(this),
33
- };
34
- }
35
-
36
- async listBlocklets(input, context) {
37
- const registryUrl = await states.node.getBlockletRegistry();
38
-
39
- if (input && input.registryUrl && registryUrl !== input.registryUrl) {
40
- this.blocklets = [];
41
- this.cacheId = '';
42
- }
43
-
44
- if (this.blocklets.length > 0) {
45
- return this.blocklets.filter((x) => isRequirementsSatisfied(x.requirements, false));
46
- }
47
- return this.refreshBlocklets(context);
48
- }
49
-
50
- async hasBlocklet(id) {
51
- const list = await this.listBlocklets();
52
- return list.some((x) => x.did === id || x.name === id);
53
- }
54
-
55
20
  getBlocklet(id, registryUrl) {
56
21
  return this.getBlockletMeta({ did: id, registryUrl });
57
22
  }
@@ -100,59 +65,6 @@ class BlockletRegistry {
100
65
  this.cacheId = '';
101
66
  this.blocklets = [];
102
67
  }
103
-
104
- async _init() {
105
- states.node.onReady(async () => {
106
- this.refreshBlocklets().catch(
107
- (error) => logger.error('refresh blocklets failed on initialize the registry', { error })
108
- // eslint-disable-next-line function-paren-newline
109
- );
110
- });
111
- }
112
-
113
- async refreshBlocklets(context) {
114
- const registryUrl = await states.node.getBlockletRegistry();
115
- const url = joinURL(registryUrl, BLOCKLET_STORE_API_PREFIX, '/blocklets.json');
116
- try {
117
- let res = await request.get(url, {
118
- validateStatus: (status) => (status >= 200 && status < 300) || status === 304,
119
- headers: {
120
- 'If-None-Match': this.cacheId,
121
- },
122
- });
123
-
124
- if (res.status === 304 && this.blocklets.length > 0) {
125
- logger.debug('use cached data', { etag: res.headers.etag, registryUrl });
126
- return this.blocklets.filter((x) => isRequirementsSatisfied(x.requirements, false));
127
- }
128
-
129
- if (res.status === 304) {
130
- res = await request.get(url, {
131
- headers: {
132
- 'Cache-Control': 'no-store',
133
- },
134
- });
135
-
136
- logger.debug('re-fetch from registry', { status: res.status });
137
- }
138
-
139
- if (!Array.isArray(res.data)) {
140
- logger.error('Blocklet list fetch failed, response data is not a list', { url, data: res.data });
141
- throw new Error('Blocklet list fetch failed');
142
- }
143
-
144
- const blocklets = res.data.filter((x) => BlockletGroup[x.group]);
145
- logger.debug('blocklets loaded', { url, blocklets: blocklets.map((x) => ({ did: x.did, name: x.name })) });
146
- this.cacheId = res.headers.etag;
147
- this.blocklets = blocklets.filter((x) => isRequirementsSatisfied(x.requirements, false));
148
- } catch (error) {
149
- logger.error('refresh blocklet registry failed', { error, registryUrl });
150
- this.cacheId = '';
151
- throw new Error(translate(get(context, 'query.locale', 'en'), 'registry.getListError', { registryUrl }));
152
- }
153
-
154
- return this.blocklets;
155
- }
156
68
  }
157
69
 
158
70
  BlockletRegistry.validateRegistryURL = validateRegistryURL;
package/lib/event.js CHANGED
@@ -18,7 +18,6 @@ const routingSnapshotPrefix = (blocklet) => (blocklet.mode === BLOCKLET_MODES.DE
18
18
  // Initialize the event queue: this will make events across process
19
19
  module.exports = ({
20
20
  blockletManager,
21
- blockletRegistry,
22
21
  ensureBlockletRouting,
23
22
  ensureBlockletRoutingForUpgrade,
24
23
  removeBlockletRouting,
@@ -252,9 +251,6 @@ module.exports = ({
252
251
  nodeState.once(EVENTS.NODE_ADDED_OWNER, () => downloadAddedBlocklet());
253
252
  nodeState.on(EVENTS.NODE_UPDATED, (nodeInfo, oldInfo) => {
254
253
  onEvent(EVENTS.NODE_UPDATED, { did: nodeInfo.did });
255
- blockletRegistry
256
- .refreshBlocklets()
257
- .catch((error) => logger.error('refresh blocklets failed on initialize the registry', { error }));
258
254
 
259
255
  // We need update router on some fields change
260
256
  const fields = ['enableWelcomePage', 'webWalletUrl', 'registerUrl'];
package/lib/index.js CHANGED
@@ -162,7 +162,7 @@ function ABTNode(options) {
162
162
  getRouterProvider,
163
163
  } = getRouterHelpers({ dataDirs, routingSnapshot, routerManager, blockletManager, certManager });
164
164
 
165
- const nodeAPI = new NodeAPI(states.node, blockletRegistry);
165
+ const nodeAPI = new NodeAPI(states.node);
166
166
  const teamAPI = new TeamAPI({ states, teamManager });
167
167
 
168
168
  blockletManager.getRoutingRulesByDid = getRoutingRulesByDid;
@@ -230,7 +230,6 @@ function ABTNode(options) {
230
230
  setBlockletInitialized: blockletManager.setInitialized.bind(blockletManager),
231
231
 
232
232
  // Registry
233
- listBlocklets: blockletRegistry.listBlocklets.bind(blockletRegistry),
234
233
  getBlockletMeta: blockletRegistry.getBlockletMeta.bind(blockletRegistry),
235
234
  getRegistryMeta: BlockletRegistry.getRegistryMeta,
236
235
 
@@ -412,7 +411,6 @@ function ABTNode(options) {
412
411
  context: { states, events, webhook },
413
412
  jobs: [
414
413
  IP.cron,
415
- blockletRegistry.getCron(),
416
414
  Upgrade.getCron(),
417
415
  ...getRoutingCrons(),
418
416
  ...blockletManager.getCrons(),
@@ -145,7 +145,7 @@ const getLogContent = async (action, args, context, result, info, node) => {
145
145
  case 'login':
146
146
  return `${user} logged in to ${team} with passport ${args.passport.name}`;
147
147
  case 'updateWhoCanAccess':
148
- return `updated access control policy to **${args.value}** for ${team} when ${args.reason}`;
148
+ return `updated access control policy to **${args.whoCanAccess}**`;
149
149
  case 'configPassportIssuance':
150
150
  return `${args.enabled ? 'enabled' : 'disabled'} passport issuance for ${team}`;
151
151
  case 'createPassportIssuance':
@@ -163,7 +163,6 @@ class NodeState extends BaseState {
163
163
  // FIXME: 这个接口比较危险,可能会修改一些本不应该修改的字段,后续需要考虑改进
164
164
  async updateNodeInfo(entity = {}) {
165
165
  const record = await this.read();
166
-
167
166
  const updateResult = await this.update(record._id, { $set: omit(entity, ['ownerNft', 'sk']) });
168
167
  this.emit(EVENTS.NODE_UPDATED, updateResult, record);
169
168
  return updateResult;
@@ -21,6 +21,7 @@ const CustomError = require('@abtnode/util/lib/custom-error');
21
21
  const getFolderSize = require('@abtnode/util/lib/get-folder-size');
22
22
  const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
23
23
  const hashFiles = require('@abtnode/util/lib/hash-files');
24
+ const isPathPrefixEqual = require('@abtnode/util/lib/is-path-prefix-equal');
24
25
  const { BLOCKLET_MAX_MEM_LIMIT_IN_MB, BLOCKLET_STORE_API_BLOCKLET_PREFIX } = require('@abtnode/constant');
25
26
 
26
27
  const {
@@ -339,6 +340,7 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
339
340
  : {};
340
341
 
341
342
  const root = (ancestors || [])[0] || blocklet;
343
+
342
344
  const ports = {};
343
345
  forEachBlockletSync(root, (x) => {
344
346
  const webInterface = findWebInterface(x);
@@ -347,12 +349,23 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
347
349
  }
348
350
  });
349
351
 
352
+ const mountPoints = [];
353
+ for (const x of root.children || []) {
354
+ mountPoints.push({
355
+ title: x.meta.title,
356
+ did: x.meta.did,
357
+ name: x.meta.name,
358
+ mountPoint: x.mountPoint || '',
359
+ });
360
+ }
361
+
350
362
  return {
351
363
  ...blocklet.configObj,
352
364
  ...getSharedConfigObj(blocklet, ancestors),
353
365
  ...blocklet.environmentObj,
354
366
  ...devEnvironments,
355
367
  BLOCKLET_WEB_PORTS: JSON.stringify(ports),
368
+ BLOCKLET_MOUNT_POINTS: JSON.stringify(mountPoints),
356
369
  ...nodeEnvironments,
357
370
  ...safeNodeEnvironments,
358
371
  };
@@ -1179,7 +1192,7 @@ const checkDuplicateComponents = (components = []) => {
1179
1192
  }
1180
1193
 
1181
1194
  const duplicateMountPoints = components.filter(
1182
- (item, index) => components.findIndex((x) => x.mountPoint === item.mountPoint) !== index
1195
+ (item, index) => components.findIndex((x) => isPathPrefixEqual(x.mountPoint, item.mountPoint)) !== index
1183
1196
  );
1184
1197
  if (duplicateMountPoints.length) {
1185
1198
  throw new Error(`mount point must be unique: ${duplicateMountPoints.map((x) => x.mountPoint).join(', ')}`);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.5",
6
+ "version": "1.8.8",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,40 +19,40 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/certificate-manager": "1.8.5",
23
- "@abtnode/constant": "1.8.5",
24
- "@abtnode/cron": "1.8.5",
25
- "@abtnode/db": "1.8.5",
26
- "@abtnode/logger": "1.8.5",
27
- "@abtnode/queue": "1.8.5",
28
- "@abtnode/rbac": "1.8.5",
29
- "@abtnode/router-provider": "1.8.5",
30
- "@abtnode/static-server": "1.8.5",
31
- "@abtnode/timemachine": "1.8.5",
32
- "@abtnode/util": "1.8.5",
33
- "@arcblock/did": "1.17.6",
22
+ "@abtnode/certificate-manager": "1.8.8",
23
+ "@abtnode/constant": "1.8.8",
24
+ "@abtnode/cron": "1.8.8",
25
+ "@abtnode/db": "1.8.8",
26
+ "@abtnode/logger": "1.8.8",
27
+ "@abtnode/queue": "1.8.8",
28
+ "@abtnode/rbac": "1.8.8",
29
+ "@abtnode/router-provider": "1.8.8",
30
+ "@abtnode/static-server": "1.8.8",
31
+ "@abtnode/timemachine": "1.8.8",
32
+ "@abtnode/util": "1.8.8",
33
+ "@arcblock/did": "1.17.11",
34
34
  "@arcblock/did-motif": "^1.1.10",
35
- "@arcblock/did-util": "1.17.6",
36
- "@arcblock/event-hub": "1.17.6",
37
- "@arcblock/jwt": "^1.17.6",
35
+ "@arcblock/did-util": "1.17.11",
36
+ "@arcblock/event-hub": "1.17.11",
37
+ "@arcblock/jwt": "^1.17.11",
38
38
  "@arcblock/pm2-events": "^0.0.5",
39
- "@arcblock/vc": "1.17.6",
40
- "@blocklet/meta": "1.8.5",
41
- "@blocklet/sdk": "1.8.5",
39
+ "@arcblock/vc": "1.17.11",
40
+ "@blocklet/meta": "1.8.8",
41
+ "@blocklet/sdk": "1.8.8",
42
42
  "@fidm/x509": "^1.2.1",
43
43
  "@nedb/core": "^1.3.2",
44
44
  "@nedb/multi": "^1.3.2",
45
- "@ocap/mcrypto": "1.17.6",
46
- "@ocap/util": "1.17.6",
47
- "@ocap/wallet": "1.17.6",
48
- "@slack/webhook": "^5.0.3",
45
+ "@ocap/mcrypto": "1.17.11",
46
+ "@ocap/util": "1.17.11",
47
+ "@ocap/wallet": "1.17.11",
48
+ "@slack/webhook": "^5.0.4",
49
49
  "axios": "^0.27.2",
50
50
  "axon": "^2.0.3",
51
- "chalk": "^4.0.0",
51
+ "chalk": "^4.1.2",
52
52
  "deep-diff": "^1.0.2",
53
53
  "detect-port": "^1.3.0",
54
54
  "flat": "^5.0.2",
55
- "fs-extra": "^10.0.1",
55
+ "fs-extra": "^10.1.0",
56
56
  "get-port": "^5.1.1",
57
57
  "is-base64": "^1.1.0",
58
58
  "is-ip": "^3.1.0",
@@ -61,16 +61,16 @@
61
61
  "js-yaml": "^4.1.0",
62
62
  "lodash": "^4.17.21",
63
63
  "lru-cache": "^6.0.0",
64
- "pm2": "^5.1.2",
64
+ "pm2": "^5.2.0",
65
65
  "promise.any": "^2.0.4",
66
- "semver": "^7.3.2",
67
- "shelljs": "^0.8.4",
68
- "slugify": "^1.4.6",
69
- "ssri": "^8.0.0",
66
+ "semver": "^7.3.7",
67
+ "shelljs": "^0.8.5",
68
+ "slugify": "^1.6.5",
69
+ "ssri": "^8.0.1",
70
70
  "stream-throttle": "^0.1.3",
71
71
  "stream-to-promise": "^3.0.0",
72
- "systeminformation": "^5.11.5",
73
- "tar": "^6.1.0",
72
+ "systeminformation": "^5.12.4",
73
+ "tar": "^6.1.11",
74
74
  "ua-parser-js": "^1.0.2",
75
75
  "unzipper": "^0.10.11",
76
76
  "url-join": "^4.0.1",
@@ -79,8 +79,8 @@
79
79
  "devDependencies": {
80
80
  "compression": "^1.7.4",
81
81
  "expand-tilde": "^2.0.2",
82
- "express": "^4.17.1",
83
- "jest": "^27.4.5"
82
+ "express": "^4.18.1",
83
+ "jest": "^27.5.1"
84
84
  },
85
- "gitHead": "58da88581cdf1dd45fd50e56db08a055be82626e"
85
+ "gitHead": "8da61db2342d7c53f2b803e5193c03d82bce8f77"
86
86
  }