@abtnode/core 1.8.4 → 1.8.7

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;
@@ -2771,7 +2771,6 @@ class BlockletManager extends BaseBlockletManager {
2771
2771
  // ids
2772
2772
  context.skippedProcessIds = getSkippedProcessIds({ newBlocklet, oldBlocklet, context });
2773
2773
 
2774
- const oldVersion = oldBlocklet.meta.version;
2775
2774
  const action = semver.gt(oldBlocklet.meta.version, version) ? 'downgrade' : 'upgrade';
2776
2775
  try {
2777
2776
  // delete old process
@@ -2817,26 +2816,21 @@ class BlockletManager extends BaseBlockletManager {
2817
2816
  });
2818
2817
  await forEachBlocklet(blocklet, postInstall, { parallel: true });
2819
2818
 
2820
- // run migrations
2821
- const runMigration = (b, { ancestors }) => {
2822
- // BUG: 本身的定义是在执行 upgrade 操作时进行 migration,但是父 blocklet upgrade 时,子 blocklet 可能不需要 upgrade,就会导致子 blocklet 多走了一遍 migration 流程
2823
- if (b.meta.did === did) {
2819
+ logger.info('start migration');
2820
+ try {
2821
+ const oldVersions = {};
2822
+ forEachBlockletSync(oldBlocklet, (b, { id }) => {
2823
+ oldVersions[id] = b.meta.version;
2824
+ });
2825
+ const runMigration = (b, { id, ancestors }) => {
2824
2826
  return runMigrationScripts({
2825
2827
  blocklet: b,
2826
2828
  appDir: b.env.appDir,
2827
2829
  env: getRuntimeEnvironments(b, nodeEnvironments, ancestors),
2828
- oldVersion,
2829
- newVersion: version,
2830
- did: b.meta.did,
2831
- notification: states.notification,
2832
- context,
2830
+ oldVersion: oldVersions[id],
2831
+ newVersion: b.meta.version,
2833
2832
  });
2834
- }
2835
- return Promise.resolve();
2836
- };
2837
- logger.info('start migration');
2838
-
2839
- try {
2833
+ };
2840
2834
  await forEachBlocklet(blocklet, runMigration, { parallel: true });
2841
2835
  } catch (error) {
2842
2836
  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':
@@ -231,6 +231,8 @@ const getLogContent = async (action, args, context, result, info, node) => {
231
231
 
232
232
  return message;
233
233
  }
234
+ case 'createTransferInvitation':
235
+ return `created a transfer node invitation(${result.inviteId})`;
234
236
 
235
237
  default:
236
238
  return action;
@@ -282,6 +284,7 @@ const getLogCategory = (action) => {
282
284
  case 'updatePermissionsForRole':
283
285
  case 'configTrustedPassports':
284
286
  case 'delegateTransferNFT':
287
+ case 'createTransferInvitation':
285
288
  return 'team';
286
289
 
287
290
  // accessKeys
@@ -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;
@@ -339,6 +339,7 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
339
339
  : {};
340
340
 
341
341
  const root = (ancestors || [])[0] || blocklet;
342
+
342
343
  const ports = {};
343
344
  forEachBlockletSync(root, (x) => {
344
345
  const webInterface = findWebInterface(x);
@@ -347,12 +348,23 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
347
348
  }
348
349
  });
349
350
 
351
+ const mountPoints = [];
352
+ for (const x of root.children || []) {
353
+ mountPoints.push({
354
+ title: x.meta.title,
355
+ did: x.meta.did,
356
+ name: x.meta.name,
357
+ mountPoint: x.mountPoint || '',
358
+ });
359
+ }
360
+
350
361
  return {
351
362
  ...blocklet.configObj,
352
363
  ...getSharedConfigObj(blocklet, ancestors),
353
364
  ...blocklet.environmentObj,
354
365
  ...devEnvironments,
355
366
  BLOCKLET_WEB_PORTS: JSON.stringify(ports),
367
+ BLOCKLET_MOUNT_POINTS: JSON.stringify(mountPoints),
356
368
  ...nodeEnvironments,
357
369
  ...safeNodeEnvironments,
358
370
  };
@@ -740,7 +752,7 @@ const parseChildrenFromMeta = async (src, context = {}) => {
740
752
  try {
741
753
  m = await getBlockletMetaFromUrls(urls);
742
754
  } catch {
743
- throw new Error('Failed get component meta');
755
+ throw new Error(`Failed get component meta: ${config.title || config.name}`);
744
756
  }
745
757
 
746
758
  validateBlockletMeta(m, { ensureDist: true });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.4",
6
+ "version": "1.8.7",
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.4",
23
- "@abtnode/constant": "1.8.4",
24
- "@abtnode/cron": "1.8.4",
25
- "@abtnode/db": "1.8.4",
26
- "@abtnode/logger": "1.8.4",
27
- "@abtnode/queue": "1.8.4",
28
- "@abtnode/rbac": "1.8.4",
29
- "@abtnode/router-provider": "1.8.4",
30
- "@abtnode/static-server": "1.8.4",
31
- "@abtnode/timemachine": "1.8.4",
32
- "@abtnode/util": "1.8.4",
33
- "@arcblock/did": "1.17.5",
22
+ "@abtnode/certificate-manager": "1.8.7",
23
+ "@abtnode/constant": "1.8.7",
24
+ "@abtnode/cron": "1.8.7",
25
+ "@abtnode/db": "1.8.7",
26
+ "@abtnode/logger": "1.8.7",
27
+ "@abtnode/queue": "1.8.7",
28
+ "@abtnode/rbac": "1.8.7",
29
+ "@abtnode/router-provider": "1.8.7",
30
+ "@abtnode/static-server": "1.8.7",
31
+ "@abtnode/timemachine": "1.8.7",
32
+ "@abtnode/util": "1.8.7",
33
+ "@arcblock/did": "1.17.10",
34
34
  "@arcblock/did-motif": "^1.1.10",
35
- "@arcblock/did-util": "1.17.5",
36
- "@arcblock/event-hub": "1.17.5",
37
- "@arcblock/jwt": "^1.17.5",
35
+ "@arcblock/did-util": "1.17.10",
36
+ "@arcblock/event-hub": "1.17.10",
37
+ "@arcblock/jwt": "^1.17.10",
38
38
  "@arcblock/pm2-events": "^0.0.5",
39
- "@arcblock/vc": "1.17.5",
40
- "@blocklet/meta": "1.8.4",
41
- "@blocklet/sdk": "1.8.4",
39
+ "@arcblock/vc": "1.17.10",
40
+ "@blocklet/meta": "1.8.7",
41
+ "@blocklet/sdk": "1.8.7",
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.5",
46
- "@ocap/util": "1.17.5",
47
- "@ocap/wallet": "1.17.5",
48
- "@slack/webhook": "^5.0.3",
45
+ "@ocap/mcrypto": "1.17.10",
46
+ "@ocap/util": "1.17.10",
47
+ "@ocap/wallet": "1.17.10",
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": "c42fb1bb84c5eef0f753fd5397d8007c7a6eee19"
85
+ "gitHead": "9807ea28b3ae634f5806c875774ac3b7e38502a1"
86
86
  }