@abtnode/core 1.8.6 → 1.8.9
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 +1 -6
- package/lib/blocklet/extras.js +6 -1
- package/lib/blocklet/manager/disk.js +16 -16
- package/lib/blocklet/migration.js +6 -0
- package/lib/blocklet/registry.js +0 -88
- package/lib/event.js +6 -4
- package/lib/index.js +2 -3
- package/lib/states/audit-log.js +1 -1
- package/lib/states/node.js +0 -1
- package/lib/team/manager.js +31 -5
- package/lib/util/blocklet.js +14 -1
- package/lib/util/upgrade.js +1 -1
- package/package.json +37 -37
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
|
|
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
|
});
|
package/lib/blocklet/extras.js
CHANGED
|
@@ -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);
|
|
@@ -2713,6 +2716,9 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2713
2716
|
|
|
2714
2717
|
await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createDidLogo(blocklet.meta.did));
|
|
2715
2718
|
|
|
2719
|
+
// Init db
|
|
2720
|
+
await this.teamManager.initTeam(blocklet.meta.did);
|
|
2721
|
+
|
|
2716
2722
|
this.emit(BlockletEvents.installed, { blocklet, context });
|
|
2717
2723
|
|
|
2718
2724
|
// Update dynamic component meta in blocklet settings
|
|
@@ -2771,7 +2777,6 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2771
2777
|
// ids
|
|
2772
2778
|
context.skippedProcessIds = getSkippedProcessIds({ newBlocklet, oldBlocklet, context });
|
|
2773
2779
|
|
|
2774
|
-
const oldVersion = oldBlocklet.meta.version;
|
|
2775
2780
|
const action = semver.gt(oldBlocklet.meta.version, version) ? 'downgrade' : 'upgrade';
|
|
2776
2781
|
try {
|
|
2777
2782
|
// delete old process
|
|
@@ -2817,26 +2822,21 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2817
2822
|
});
|
|
2818
2823
|
await forEachBlocklet(blocklet, postInstall, { parallel: true });
|
|
2819
2824
|
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2825
|
+
logger.info('start migration');
|
|
2826
|
+
try {
|
|
2827
|
+
const oldVersions = {};
|
|
2828
|
+
forEachBlockletSync(oldBlocklet, (b, { id }) => {
|
|
2829
|
+
oldVersions[id] = b.meta.version;
|
|
2830
|
+
});
|
|
2831
|
+
const runMigration = (b, { id, ancestors }) => {
|
|
2824
2832
|
return runMigrationScripts({
|
|
2825
2833
|
blocklet: b,
|
|
2826
2834
|
appDir: b.env.appDir,
|
|
2827
2835
|
env: getRuntimeEnvironments(b, nodeEnvironments, ancestors),
|
|
2828
|
-
oldVersion,
|
|
2829
|
-
newVersion: version,
|
|
2830
|
-
did: b.meta.did,
|
|
2831
|
-
notification: states.notification,
|
|
2832
|
-
context,
|
|
2836
|
+
oldVersion: oldVersions[id],
|
|
2837
|
+
newVersion: b.meta.version,
|
|
2833
2838
|
});
|
|
2834
|
-
}
|
|
2835
|
-
return Promise.resolve();
|
|
2836
|
-
};
|
|
2837
|
-
logger.info('start migration');
|
|
2838
|
-
|
|
2839
|
-
try {
|
|
2839
|
+
};
|
|
2840
2840
|
await forEachBlocklet(blocklet, runMigration, { parallel: true });
|
|
2841
2841
|
} catch (error) {
|
|
2842
2842
|
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
|
};
|
package/lib/blocklet/registry.js
CHANGED
|
@@ -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,
|
|
@@ -26,6 +25,7 @@ module.exports = ({
|
|
|
26
25
|
handleRouting,
|
|
27
26
|
domainStatus,
|
|
28
27
|
teamAPI,
|
|
28
|
+
teamManager,
|
|
29
29
|
certManager,
|
|
30
30
|
node,
|
|
31
31
|
}) => {
|
|
@@ -51,6 +51,11 @@ module.exports = ({
|
|
|
51
51
|
// Subscribe events from eventHub and proxy to eventHandler
|
|
52
52
|
[...Object.values(BlockletEvents), ...Object.values(EVENTS)].forEach((name) => {
|
|
53
53
|
eventHub.on(name, (data) => {
|
|
54
|
+
if (name === BlockletEvents.removed) {
|
|
55
|
+
// Cleanup cache in teamManager for every node instance
|
|
56
|
+
teamManager.deleteTeam(data?.meta?.did, { closeDatabase: false });
|
|
57
|
+
}
|
|
58
|
+
|
|
54
59
|
if (typeof eventHandler === 'function') {
|
|
55
60
|
eventHandler({ name, data });
|
|
56
61
|
}
|
|
@@ -252,9 +257,6 @@ module.exports = ({
|
|
|
252
257
|
nodeState.once(EVENTS.NODE_ADDED_OWNER, () => downloadAddedBlocklet());
|
|
253
258
|
nodeState.on(EVENTS.NODE_UPDATED, (nodeInfo, oldInfo) => {
|
|
254
259
|
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
260
|
|
|
259
261
|
// We need update router on some fields change
|
|
260
262
|
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
|
|
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
|
|
|
@@ -401,6 +400,7 @@ function ABTNode(options) {
|
|
|
401
400
|
handleRouting,
|
|
402
401
|
domainStatus,
|
|
403
402
|
teamAPI,
|
|
403
|
+
teamManager,
|
|
404
404
|
certManager,
|
|
405
405
|
node: instance,
|
|
406
406
|
});
|
|
@@ -412,7 +412,6 @@ function ABTNode(options) {
|
|
|
412
412
|
context: { states, events, webhook },
|
|
413
413
|
jobs: [
|
|
414
414
|
IP.cron,
|
|
415
|
-
blockletRegistry.getCron(),
|
|
416
415
|
Upgrade.getCron(),
|
|
417
416
|
...getRoutingCrons(),
|
|
418
417
|
...blockletManager.getCrons(),
|
package/lib/states/audit-log.js
CHANGED
|
@@ -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.
|
|
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':
|
package/lib/states/node.js
CHANGED
|
@@ -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;
|
package/lib/team/manager.js
CHANGED
|
@@ -104,7 +104,7 @@ class TeamManager extends EventEmitter {
|
|
|
104
104
|
|
|
105
105
|
async getUserState(did) {
|
|
106
106
|
// validate exist
|
|
107
|
-
if (!this.isNodeTeam(did) && !(await this.states.blocklet.
|
|
107
|
+
if (!this.isNodeTeam(did) && !(await this.states.blocklet.hasBlocklet(did))) {
|
|
108
108
|
logger.error('Did does not exist', { action: 'getUserState', did });
|
|
109
109
|
throw new Error(`Did does not exist: ${did}`);
|
|
110
110
|
}
|
|
@@ -143,7 +143,7 @@ class TeamManager extends EventEmitter {
|
|
|
143
143
|
|
|
144
144
|
async getSessionState(did) {
|
|
145
145
|
// validate exist
|
|
146
|
-
if (!this.isNodeTeam(did) && !(await this.states.blocklet.
|
|
146
|
+
if (!this.isNodeTeam(did) && !(await this.states.blocklet.hasBlocklet(did))) {
|
|
147
147
|
logger.error('Did does not exist', { action: 'getSessionState', did });
|
|
148
148
|
throw new Error(`Did does not exist: ${did}`);
|
|
149
149
|
}
|
|
@@ -182,7 +182,7 @@ class TeamManager extends EventEmitter {
|
|
|
182
182
|
logger.info('get rbac', { did });
|
|
183
183
|
|
|
184
184
|
// validate exist
|
|
185
|
-
if (!this.isNodeTeam(did) && !(await this.states.blocklet.
|
|
185
|
+
if (!this.isNodeTeam(did) && !(await this.states.blocklet.hasBlocklet(did))) {
|
|
186
186
|
logger.error('Did does not exist', { action: 'getRBAC', did });
|
|
187
187
|
throw new Error(`Did does not exist: ${did}`);
|
|
188
188
|
}
|
|
@@ -288,8 +288,34 @@ class TeamManager extends EventEmitter {
|
|
|
288
288
|
return owner;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
async
|
|
292
|
-
if (
|
|
291
|
+
async initTeam(did) {
|
|
292
|
+
if (!did) {
|
|
293
|
+
logger.error('initTeam: did does not exist');
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
logger.info('initTeam', { did });
|
|
298
|
+
|
|
299
|
+
const rbac = await this.getRBAC(did);
|
|
300
|
+
const user = await this.getUserState(did);
|
|
301
|
+
const session = await this.getSessionState(did);
|
|
302
|
+
|
|
303
|
+
this.cache[did] = {
|
|
304
|
+
rbac,
|
|
305
|
+
user,
|
|
306
|
+
session,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async deleteTeam(did, { closeDatabase: closeDB = true } = {}) {
|
|
311
|
+
if (!did) {
|
|
312
|
+
logger.error('deleteTeam: did does not exist');
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
logger.info('deleteTeam', { did, closeDB });
|
|
317
|
+
|
|
318
|
+
if (closeDB && this.cache[did]) {
|
|
293
319
|
try {
|
|
294
320
|
if (this.cache[did].rbac) {
|
|
295
321
|
await closeDatabase(this.cache[did].rbac.storage.db);
|
package/lib/util/blocklet.js
CHANGED
|
@@ -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
|
|
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/lib/util/upgrade.js
CHANGED
|
@@ -128,7 +128,7 @@ const doUpgrade = async (session) => {
|
|
|
128
128
|
if (session.stage === NODE_UPGRADE_PROGRESS.CLEANUP) {
|
|
129
129
|
logger.info('cleanup for upgrading', { from, to, sessionId });
|
|
130
130
|
await goNextState(NODE_UPGRADE_PROGRESS.COMPLETE);
|
|
131
|
-
await sleep(
|
|
131
|
+
await sleep(8000);
|
|
132
132
|
await states.node.updateNodeInfo({ nextVersion: '', version: to, upgradeSessionId: '' });
|
|
133
133
|
try {
|
|
134
134
|
await states.node.exitMode(NODE_MODES.MAINTENANCE);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.9",
|
|
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.
|
|
23
|
-
"@abtnode/constant": "1.8.
|
|
24
|
-
"@abtnode/cron": "1.8.
|
|
25
|
-
"@abtnode/db": "1.8.
|
|
26
|
-
"@abtnode/logger": "1.8.
|
|
27
|
-
"@abtnode/queue": "1.8.
|
|
28
|
-
"@abtnode/rbac": "1.8.
|
|
29
|
-
"@abtnode/router-provider": "1.8.
|
|
30
|
-
"@abtnode/static-server": "1.8.
|
|
31
|
-
"@abtnode/timemachine": "1.8.
|
|
32
|
-
"@abtnode/util": "1.8.
|
|
33
|
-
"@arcblock/did": "1.17.
|
|
22
|
+
"@abtnode/certificate-manager": "1.8.9",
|
|
23
|
+
"@abtnode/constant": "1.8.9",
|
|
24
|
+
"@abtnode/cron": "1.8.9",
|
|
25
|
+
"@abtnode/db": "1.8.9",
|
|
26
|
+
"@abtnode/logger": "1.8.9",
|
|
27
|
+
"@abtnode/queue": "1.8.9",
|
|
28
|
+
"@abtnode/rbac": "1.8.9",
|
|
29
|
+
"@abtnode/router-provider": "1.8.9",
|
|
30
|
+
"@abtnode/static-server": "1.8.9",
|
|
31
|
+
"@abtnode/timemachine": "1.8.9",
|
|
32
|
+
"@abtnode/util": "1.8.9",
|
|
33
|
+
"@arcblock/did": "1.17.11",
|
|
34
34
|
"@arcblock/did-motif": "^1.1.10",
|
|
35
|
-
"@arcblock/did-util": "1.17.
|
|
36
|
-
"@arcblock/event-hub": "1.17.
|
|
37
|
-
"@arcblock/jwt": "^1.17.
|
|
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.
|
|
40
|
-
"@blocklet/meta": "1.8.
|
|
41
|
-
"@blocklet/sdk": "1.8.
|
|
39
|
+
"@arcblock/vc": "1.17.11",
|
|
40
|
+
"@blocklet/meta": "1.8.9",
|
|
41
|
+
"@blocklet/sdk": "1.8.9",
|
|
42
42
|
"@fidm/x509": "^1.2.1",
|
|
43
|
-
"@nedb/core": "^1.3.
|
|
44
|
-
"@nedb/multi": "^1.3.
|
|
45
|
-
"@ocap/mcrypto": "1.17.
|
|
46
|
-
"@ocap/util": "1.17.
|
|
47
|
-
"@ocap/wallet": "1.17.
|
|
48
|
-
"@slack/webhook": "^5.0.
|
|
43
|
+
"@nedb/core": "^1.3.4",
|
|
44
|
+
"@nedb/multi": "^1.3.4",
|
|
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.
|
|
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
|
|
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.
|
|
64
|
+
"pm2": "^5.2.0",
|
|
65
65
|
"promise.any": "^2.0.4",
|
|
66
|
-
"semver": "^7.3.
|
|
67
|
-
"shelljs": "^0.8.
|
|
68
|
-
"slugify": "^1.
|
|
69
|
-
"ssri": "^8.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.
|
|
73
|
-
"tar": "^6.1.
|
|
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.
|
|
83
|
-
"jest": "^27.
|
|
82
|
+
"express": "^4.18.1",
|
|
83
|
+
"jest": "^27.5.1"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "1846a1f0bae2f870f3fe635b1f17ed06867d370d"
|
|
86
86
|
}
|