@abtnode/core 1.8.22 → 1.8.24
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/blocklet/extras.js +35 -24
- package/lib/blocklet/manager/disk.js +76 -2
- package/lib/event.js +16 -14
- package/lib/index.js +6 -2
- package/lib/states/audit-log.js +11 -5
- package/lib/states/blocklet-extras.js +3 -1
- package/package.json +16 -16
package/lib/blocklet/extras.js
CHANGED
|
@@ -12,6 +12,8 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
|
|
|
12
12
|
const isUpdatingCustomConfig = newConfigs.every((x) => x.key);
|
|
13
13
|
const configs = isUpdatingCustomConfig ? metaConfigs : metaConfigsToKeep;
|
|
14
14
|
|
|
15
|
+
const enableSecurity = dek && did;
|
|
16
|
+
|
|
15
17
|
// oldConfig 表示从数据库中可以用的字段
|
|
16
18
|
const oldConfig = [...configs, ...customConfigs].reduce((acc, x) => {
|
|
17
19
|
acc[x.key] = {
|
|
@@ -26,8 +28,28 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
|
|
|
26
28
|
return acc;
|
|
27
29
|
}, {});
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
// newConfig 为用户传的,也可以是从环境变量中去读的
|
|
32
|
+
const uniqConfigs = uniqBy(newConfigs, (x) => x.key || x.name);
|
|
33
|
+
|
|
34
|
+
// `BLOCKLET_*` and `ABT_NODE_*` vars can only be set by Blocklet Server Daemon with only a few exceptions.
|
|
35
|
+
const newConfig = cloneDeep(
|
|
36
|
+
uniqConfigs.filter((x) => {
|
|
37
|
+
const key = x.key || x.name;
|
|
38
|
+
|
|
39
|
+
if (!key) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (BLOCKLET_CONFIGURABLE_KEY[key]) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return !(key.toString().startsWith('ABT_NODE_') || key.toString().startsWith('BLOCKLET_'));
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
if (enableSecurity) {
|
|
52
|
+
newConfig.forEach((x) => {
|
|
31
53
|
if (x.secure) {
|
|
32
54
|
x.value = security.encrypt(x.value, did, dek);
|
|
33
55
|
if (x.default) {
|
|
@@ -37,24 +59,6 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
|
|
|
37
59
|
});
|
|
38
60
|
}
|
|
39
61
|
|
|
40
|
-
// newConfig 为用户传的,也可以是从环境变量中去读的
|
|
41
|
-
const uniqConfigs = uniqBy(newConfigs, (x) => x.key || x.name);
|
|
42
|
-
|
|
43
|
-
// `BLOCKLET_*` and `ABT_NODE_*` vars can only be set by Blocklet Server Daemon with only a few exceptions.
|
|
44
|
-
const newConfig = uniqConfigs.filter((x) => {
|
|
45
|
-
const key = x.key || x.name;
|
|
46
|
-
|
|
47
|
-
if (!key) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (BLOCKLET_CONFIGURABLE_KEY[key]) {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return !(key.toString().startsWith('ABT_NODE_') || key.toString().startsWith('BLOCKLET_'));
|
|
56
|
-
});
|
|
57
|
-
|
|
58
62
|
newConfig.forEach((config) => {
|
|
59
63
|
const { name, key, value, default: defaultVal, required, description, secure, validation, custom, shared } = config;
|
|
60
64
|
// 新增、更新或者删除
|
|
@@ -76,16 +80,21 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
|
|
|
76
80
|
if (name) {
|
|
77
81
|
// 重装时 name 和 value不覆盖
|
|
78
82
|
if (oldConfig[name]) {
|
|
83
|
+
const oldSecure = oldConfig[name].secure;
|
|
84
|
+
const oldValue =
|
|
85
|
+
enableSecurity && oldSecure ? security.decrypt(oldConfig[name].value, did, dek) : oldConfig[name].value;
|
|
86
|
+
|
|
87
|
+
const newSecure = secure === undefined ? false : secure;
|
|
88
|
+
|
|
79
89
|
oldConfig[name] = {
|
|
80
|
-
value:
|
|
90
|
+
value: enableSecurity && newSecure ? security.encrypt(oldValue, did, dek) : oldValue,
|
|
81
91
|
required: required === undefined ? false : required,
|
|
82
92
|
description: description || '',
|
|
83
93
|
validation: validation || '',
|
|
84
|
-
secure:
|
|
94
|
+
secure: newSecure,
|
|
85
95
|
custom: custom === undefined ? false : custom,
|
|
86
96
|
shared,
|
|
87
97
|
};
|
|
88
|
-
|
|
89
98
|
return;
|
|
90
99
|
}
|
|
91
100
|
|
|
@@ -120,7 +129,9 @@ const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '
|
|
|
120
129
|
};
|
|
121
130
|
|
|
122
131
|
const parseConfigs = ({ data, did, dek }) => {
|
|
123
|
-
|
|
132
|
+
const enableSecurity = dek && did;
|
|
133
|
+
|
|
134
|
+
if (enableSecurity && Array.isArray(data)) {
|
|
124
135
|
return cloneDeep(data).map((x) => {
|
|
125
136
|
if (x.secure) {
|
|
126
137
|
x.value = security.decrypt(x.value, did, dek);
|
|
@@ -43,7 +43,7 @@ const validateBlockletEntry = require('@blocklet/meta/lib/entry');
|
|
|
43
43
|
const toBlockletDid = require('@blocklet/meta/lib/did');
|
|
44
44
|
const { validateMeta } = require('@blocklet/meta/lib/validate');
|
|
45
45
|
const { update: updateMetaFile } = require('@blocklet/meta/lib/file');
|
|
46
|
-
const { titleSchema, descriptionSchema } = require('@blocklet/meta/lib/schema');
|
|
46
|
+
const { titleSchema, descriptionSchema, mountPointSchema } = require('@blocklet/meta/lib/schema');
|
|
47
47
|
const hasReservedKey = require('@blocklet/meta/lib/has-reserved-key');
|
|
48
48
|
|
|
49
49
|
const {
|
|
@@ -698,7 +698,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
698
698
|
}
|
|
699
699
|
|
|
700
700
|
const newBlocklet = await this.ensureBlocklet(rootDid);
|
|
701
|
-
this.emit(BlockletEvents.upgraded, { blocklet: newBlocklet, context }); // trigger router refresh
|
|
701
|
+
this.emit(BlockletEvents.upgraded, { blocklet: newBlocklet, context: { ...context, createAuditLog: false } }); // trigger router refresh
|
|
702
702
|
|
|
703
703
|
states.notification.create({
|
|
704
704
|
title: 'Component Deleted',
|
|
@@ -946,6 +946,80 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
946
946
|
return blocklet;
|
|
947
947
|
}
|
|
948
948
|
|
|
949
|
+
async updateComponentTitle({ did, rootDid: inputRootDid, title }) {
|
|
950
|
+
await titleSchema.validateAsync(title);
|
|
951
|
+
|
|
952
|
+
const blocklet = await states.blocklet.getBlocklet(inputRootDid);
|
|
953
|
+
|
|
954
|
+
if (!blocklet) {
|
|
955
|
+
throw new Error('blocklet does not exist');
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
const rootDid = blocklet.meta.did;
|
|
959
|
+
|
|
960
|
+
const { children } = blocklet;
|
|
961
|
+
const component = children.find((x) => x.meta.did === did);
|
|
962
|
+
|
|
963
|
+
if (!component) {
|
|
964
|
+
throw new Error('component does not exist');
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (!component.dynamic) {
|
|
968
|
+
throw new Error('cannot update title of non-dynamic component');
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
component.meta.title = title;
|
|
972
|
+
|
|
973
|
+
const navigation = await states.blockletExtras.getSettings(rootDid, 'navigation', []);
|
|
974
|
+
const nav = navigation.find((x) => x.child === component.meta.name);
|
|
975
|
+
|
|
976
|
+
if (nav) {
|
|
977
|
+
nav.title = title;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// update db
|
|
981
|
+
if (nav) {
|
|
982
|
+
await states.blockletExtras.setSettings(rootDid, { navigation });
|
|
983
|
+
}
|
|
984
|
+
await states.blocklet.updateBlocklet(rootDid, { children });
|
|
985
|
+
|
|
986
|
+
// trigger meta.js refresh
|
|
987
|
+
// trigger dashboard frontend refresh
|
|
988
|
+
this.emit(BlockletEvents.updated, blocklet);
|
|
989
|
+
|
|
990
|
+
return this.ensureBlocklet(rootDid);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
async updateComponentMountPoint({ did, rootDid: inputRootDid, mountPoint }, context) {
|
|
994
|
+
await mountPointSchema.validateAsync(mountPoint);
|
|
995
|
+
|
|
996
|
+
const blocklet = await states.blocklet.getBlocklet(inputRootDid);
|
|
997
|
+
|
|
998
|
+
if (!blocklet) {
|
|
999
|
+
throw new Error('blocklet does not exist');
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
const rootDid = blocklet.meta.did;
|
|
1003
|
+
|
|
1004
|
+
const { children } = blocklet;
|
|
1005
|
+
const component = children.find((x) => x.meta.did === did);
|
|
1006
|
+
|
|
1007
|
+
if (!component) {
|
|
1008
|
+
throw new Error('component does not exist');
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
if (!component.dynamic) {
|
|
1012
|
+
throw new Error('cannot update mountPoint of non-dynamic component');
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
component.mountPoint = mountPoint;
|
|
1016
|
+
await states.blocklet.updateBlocklet(rootDid, { children });
|
|
1017
|
+
|
|
1018
|
+
this.emit(BlockletEvents.upgraded, { blocklet, context: { ...context, createAuditLog: false } }); // trigger router refresh
|
|
1019
|
+
|
|
1020
|
+
return this.ensureBlocklet(rootDid);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
949
1023
|
/**
|
|
950
1024
|
* upgrade blocklet from registry
|
|
951
1025
|
*/
|
package/lib/event.js
CHANGED
|
@@ -181,17 +181,19 @@ module.exports = ({
|
|
|
181
181
|
} else if ([BlockletEvents.upgraded, BlockletEvents.downgraded].includes(eventName)) {
|
|
182
182
|
await handleBlockletUpgrade(eventName, payload);
|
|
183
183
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
184
|
+
if (payload?.context?.createAuditLog !== false) {
|
|
185
|
+
try {
|
|
186
|
+
await node.createAuditLog({
|
|
187
|
+
action: 'upgradeBlocklet',
|
|
188
|
+
args: {
|
|
189
|
+
did: blocklet.meta.did,
|
|
190
|
+
},
|
|
191
|
+
context: payload.context || {},
|
|
192
|
+
result: blocklet,
|
|
193
|
+
});
|
|
194
|
+
} catch (error) {
|
|
195
|
+
logger.error('Failed to createAuditLog for upgradeBlocklet', { error });
|
|
196
|
+
}
|
|
195
197
|
}
|
|
196
198
|
} else if ([BlockletEvents.removed].includes(eventName)) {
|
|
197
199
|
await handleBlockletRemove(eventName, payload);
|
|
@@ -285,6 +287,9 @@ module.exports = ({
|
|
|
285
287
|
teamAPI.on(EVENTS.USER_UPDATED, (data) => onEvent(EVENTS.USER_UPDATED, data));
|
|
286
288
|
teamAPI.on(BlockletEvents.updated, (data) => onEvent(BlockletEvents.updated, data));
|
|
287
289
|
|
|
290
|
+
certManager.on('cert.issued', (data) => onEvent(EVENTS.CERT_ISSUED, data));
|
|
291
|
+
certManager.on('cert.error', (data) => onEvent(EVENTS.CERT_ERROR, data));
|
|
292
|
+
|
|
288
293
|
events.setEventHandler = (handler) => {
|
|
289
294
|
if (typeof handler === 'function') {
|
|
290
295
|
eventHandler = handler;
|
|
@@ -294,8 +299,5 @@ module.exports = ({
|
|
|
294
299
|
events.handleServerEvent = handleServerEvent;
|
|
295
300
|
events.handleBlockletEvent = handleBlockletEvent;
|
|
296
301
|
|
|
297
|
-
certManager.on('cert.issued', (data) => onEvent(EVENTS.CERT_ISSUED, data));
|
|
298
|
-
certManager.on('cert.error', (data) => onEvent(EVENTS.CERT_ERROR, data));
|
|
299
|
-
|
|
300
302
|
return events;
|
|
301
303
|
};
|
package/lib/index.js
CHANGED
|
@@ -209,13 +209,15 @@ function ABTNode(options) {
|
|
|
209
209
|
configBlocklet: blockletManager.config.bind(blockletManager),
|
|
210
210
|
devBlocklet: blockletManager.dev.bind(blockletManager),
|
|
211
211
|
checkChildBlockletsForUpdates: blockletManager.checkChildrenForUpdates.bind(blockletManager),
|
|
212
|
-
|
|
212
|
+
upgradeChildBlocklets: blockletManager.updateChildren.bind(blockletManager),
|
|
213
213
|
getLatestBlockletVersion: blockletManager.getLatestBlockletVersion.bind(blockletManager),
|
|
214
214
|
getBlockletMetaFromUrl: blockletManager.getMetaFromUrl.bind(blockletManager),
|
|
215
215
|
resetBlocklet: blockletManager.reset.bind(blockletManager),
|
|
216
216
|
deleteBlockletProcess: blockletManager.deleteProcess.bind(blockletManager),
|
|
217
217
|
configPublicToStore: blockletManager.configPublicToStore.bind(blockletManager),
|
|
218
218
|
updateWhoCanAccess: blockletManager.updateWhoCanAccess.bind(blockletManager),
|
|
219
|
+
updateComponentTitle: blockletManager.updateComponentTitle.bind(blockletManager),
|
|
220
|
+
updateComponentMountPoint: blockletManager.updateComponentMountPoint.bind(blockletManager),
|
|
219
221
|
|
|
220
222
|
// For diagnose purpose
|
|
221
223
|
syncBlockletStatus: blockletManager.status.bind(blockletManager),
|
|
@@ -456,7 +458,9 @@ function ABTNode(options) {
|
|
|
456
458
|
.catch((error) => logger.error('start certificate manager service failed', { error }));
|
|
457
459
|
|
|
458
460
|
if (process.env.NODE_ENV === 'development') {
|
|
459
|
-
|
|
461
|
+
setTimeout(() => {
|
|
462
|
+
initCron();
|
|
463
|
+
}, 1000);
|
|
460
464
|
} else {
|
|
461
465
|
// We should only respond to pm2 events when node is alive
|
|
462
466
|
events.on(EVENTS.NODE_STARTED, () => {
|
package/lib/states/audit-log.js
CHANGED
|
@@ -122,6 +122,10 @@ const getLogContent = async (action, args, context, result, info, node) => {
|
|
|
122
122
|
return `set publicToStore to true for blocklet ${getBlockletInfo(result, info)}`;
|
|
123
123
|
}
|
|
124
124
|
return `set publicToStore to false for blocklet ${getBlockletInfo(result, info)}`;
|
|
125
|
+
case 'updateComponentTitle':
|
|
126
|
+
return `update component title to **${args.title}** for blocklet ${getBlockletInfo(result, info)}`;
|
|
127
|
+
case 'updateComponentMountPoint':
|
|
128
|
+
return `update component mount point to **${args.mountPoint}** for blocklet ${getBlockletInfo(result, info)}`;
|
|
125
129
|
// store
|
|
126
130
|
case 'addBlockletStore':
|
|
127
131
|
return `added blocklet store ${args.url}`;
|
|
@@ -257,6 +261,8 @@ const getLogCategory = (action) => {
|
|
|
257
261
|
case 'upgradeBlocklet':
|
|
258
262
|
case 'updateChildBlocklets':
|
|
259
263
|
case 'configPublicToStore':
|
|
264
|
+
case 'updateComponentTitle':
|
|
265
|
+
case 'updateComponentMountPoint':
|
|
260
266
|
return 'blocklet';
|
|
261
267
|
|
|
262
268
|
// store
|
|
@@ -328,6 +334,11 @@ const getScope = (args = {}) => {
|
|
|
328
334
|
return args.teamDid;
|
|
329
335
|
}
|
|
330
336
|
|
|
337
|
+
// this param usually means mutating a child component
|
|
338
|
+
if (args.rootDid) {
|
|
339
|
+
return args.rootDid;
|
|
340
|
+
}
|
|
341
|
+
|
|
331
342
|
// this param usually means mutating an blockle application
|
|
332
343
|
if (args.did) {
|
|
333
344
|
// this param usually means mutating a nested child component
|
|
@@ -338,11 +349,6 @@ const getScope = (args = {}) => {
|
|
|
338
349
|
return args.did;
|
|
339
350
|
}
|
|
340
351
|
|
|
341
|
-
// this param usually means mutating a child component
|
|
342
|
-
if (args.rootDid) {
|
|
343
|
-
return args.rootDid;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
352
|
return null;
|
|
347
353
|
};
|
|
348
354
|
|
|
@@ -133,7 +133,9 @@ class BlockletExtrasState extends BaseState {
|
|
|
133
133
|
logger.info('update extra success', { name, dids });
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
return
|
|
136
|
+
// re get data because should return decrypted secure value
|
|
137
|
+
const getFn = this[camelCase(`get ${extra.name}`)].bind(this);
|
|
138
|
+
return getFn(dids);
|
|
137
139
|
};
|
|
138
140
|
}
|
|
139
141
|
|
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.24",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.8.
|
|
23
|
-
"@abtnode/certificate-manager": "1.8.
|
|
24
|
-
"@abtnode/constant": "1.8.
|
|
25
|
-
"@abtnode/cron": "1.8.
|
|
26
|
-
"@abtnode/db": "1.8.
|
|
27
|
-
"@abtnode/logger": "1.8.
|
|
28
|
-
"@abtnode/queue": "1.8.
|
|
29
|
-
"@abtnode/rbac": "1.8.
|
|
30
|
-
"@abtnode/router-provider": "1.8.
|
|
31
|
-
"@abtnode/static-server": "1.8.
|
|
32
|
-
"@abtnode/timemachine": "1.8.
|
|
33
|
-
"@abtnode/util": "1.8.
|
|
22
|
+
"@abtnode/auth": "1.8.24",
|
|
23
|
+
"@abtnode/certificate-manager": "1.8.24",
|
|
24
|
+
"@abtnode/constant": "1.8.24",
|
|
25
|
+
"@abtnode/cron": "1.8.24",
|
|
26
|
+
"@abtnode/db": "1.8.24",
|
|
27
|
+
"@abtnode/logger": "1.8.24",
|
|
28
|
+
"@abtnode/queue": "1.8.24",
|
|
29
|
+
"@abtnode/rbac": "1.8.24",
|
|
30
|
+
"@abtnode/router-provider": "1.8.24",
|
|
31
|
+
"@abtnode/static-server": "1.8.24",
|
|
32
|
+
"@abtnode/timemachine": "1.8.24",
|
|
33
|
+
"@abtnode/util": "1.8.24",
|
|
34
34
|
"@arcblock/did": "1.17.19",
|
|
35
35
|
"@arcblock/did-motif": "^1.1.10",
|
|
36
36
|
"@arcblock/did-util": "1.17.19",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@arcblock/jwt": "^1.17.19",
|
|
39
39
|
"@arcblock/pm2-events": "^0.0.5",
|
|
40
40
|
"@arcblock/vc": "1.17.19",
|
|
41
|
-
"@blocklet/meta": "1.8.
|
|
42
|
-
"@blocklet/sdk": "1.8.
|
|
41
|
+
"@blocklet/meta": "1.8.24",
|
|
42
|
+
"@blocklet/sdk": "1.8.24",
|
|
43
43
|
"@fidm/x509": "^1.2.1",
|
|
44
44
|
"@ocap/mcrypto": "1.17.19",
|
|
45
45
|
"@ocap/util": "1.17.19",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"express": "^4.18.1",
|
|
81
81
|
"jest": "^27.5.1"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "2b955a638ca6177c04f3a722cc326770fba276f0"
|
|
84
84
|
}
|