@abtnode/core 1.6.16 → 1.6.17
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/manager/disk.js +373 -93
- package/lib/index.js +2 -0
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/router/helper.js +1 -1
- package/lib/router/manager.js +41 -37
- package/lib/states/blocklet-extras.js +39 -3
- package/lib/states/blocklet.js +4 -8
- package/lib/states/node.js +17 -2
- package/lib/util/blocklet.js +266 -67
- package/package.json +21 -21
package/lib/index.js
CHANGED
|
@@ -197,11 +197,13 @@ function ABTNode(options) {
|
|
|
197
197
|
// Blocklet manager
|
|
198
198
|
installBlocklet: blockletManager.install.bind(blockletManager),
|
|
199
199
|
installBlockletFromVc: blockletManager.installBlockletFromVc.bind(blockletManager),
|
|
200
|
+
installComponent: blockletManager.installComponent.bind(blockletManager),
|
|
200
201
|
startBlocklet: blockletManager.start.bind(blockletManager),
|
|
201
202
|
stopBlocklet: blockletManager.stop.bind(blockletManager),
|
|
202
203
|
reloadBlocklet: blockletManager.reload.bind(blockletManager),
|
|
203
204
|
restartBlocklet: blockletManager.restart.bind(blockletManager),
|
|
204
205
|
deleteBlocklet: blockletManager.delete.bind(blockletManager),
|
|
206
|
+
deleteComponent: blockletManager.deleteComponent.bind(blockletManager),
|
|
205
207
|
cancelDownloadBlocklet: blockletManager.cancelDownload.bind(blockletManager),
|
|
206
208
|
upgradeBlocklet: blockletManager.upgrade.bind(blockletManager),
|
|
207
209
|
configBlocklet: blockletManager.config.bind(blockletManager),
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
/* eslint-disable no-await-in-loop */
|
|
3
|
+
/* eslint-disable no-underscore-dangle */
|
|
4
|
+
|
|
5
|
+
module.exports = async ({ states, printInfo }) => {
|
|
6
|
+
printInfo('Try to update blocklet to 1.6.17...');
|
|
7
|
+
const blockletState = states.blocklet;
|
|
8
|
+
|
|
9
|
+
const blocklets = await blockletState.getBlocklets();
|
|
10
|
+
for (const blocklet of blocklets) {
|
|
11
|
+
if (!blocklet) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!blocklet.children || !blocklet.children.length) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const meta = blocklet.meta || {};
|
|
20
|
+
const { did } = meta;
|
|
21
|
+
if (!did) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const children = (blocklet.children || []).map((child) => {
|
|
26
|
+
if (child.mountPoint) {
|
|
27
|
+
return child;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const config = (meta.children || []).find((x) => x.name === child.meta.name);
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
config &&
|
|
34
|
+
config.mountPoints &&
|
|
35
|
+
config.mountPoints[0] &&
|
|
36
|
+
config.mountPoints[0].root &&
|
|
37
|
+
config.mountPoints[0].root.prefix
|
|
38
|
+
) {
|
|
39
|
+
child.mountPoint = config.mountPoints[0].root.prefix;
|
|
40
|
+
}
|
|
41
|
+
printInfo(`Set mountPoint: ${child.mountPoint} to child ${child.meta.name} in ${blocklet.meta.name}`);
|
|
42
|
+
|
|
43
|
+
return child;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await blockletState.update(blocklet._id, { $set: { children } });
|
|
47
|
+
}
|
|
48
|
+
};
|
package/lib/router/helper.js
CHANGED
|
@@ -317,7 +317,7 @@ const ensureWellknownRule = async (sites) => {
|
|
|
317
317
|
rules.forEach((rule) => {
|
|
318
318
|
if (
|
|
319
319
|
rule.to.type !== ROUTING_RULE_TYPES.BLOCKLET || // is not blocklet
|
|
320
|
-
rule.to.did !== rule.to.realDid // is a component endpoint
|
|
320
|
+
(rule.to.did !== rule.to.realDid && rule.from.pathPrefix !== '/') // is a component endpoint in sub path
|
|
321
321
|
) {
|
|
322
322
|
return;
|
|
323
323
|
}
|
package/lib/router/manager.js
CHANGED
|
@@ -27,6 +27,7 @@ const {
|
|
|
27
27
|
BLOCKLET_BUNDLE_FOLDER,
|
|
28
28
|
BLOCKLET_DYNAMIC_PATH_PREFIX,
|
|
29
29
|
BLOCKLET_INTERFACE_TYPE_WEB,
|
|
30
|
+
BlockletGroup,
|
|
30
31
|
} = require('@blocklet/meta/lib/constants');
|
|
31
32
|
|
|
32
33
|
const {
|
|
@@ -37,6 +38,7 @@ const {
|
|
|
37
38
|
validateUpdateSite,
|
|
38
39
|
} = require('../validators/router');
|
|
39
40
|
const { getProviderFromNodeInfo, findInterfaceByName, isCLI, findInterfacePortByName } = require('../util');
|
|
41
|
+
const { findWebInterface } = require('../util/blocklet');
|
|
40
42
|
const { attachInterfaceUrls, ensureLatestInfo } = require('./helper');
|
|
41
43
|
const Router = require('./index');
|
|
42
44
|
const states = require('../states');
|
|
@@ -679,49 +681,51 @@ class RouterManager extends EventEmitter {
|
|
|
679
681
|
|
|
680
682
|
// get child rules
|
|
681
683
|
const blocklet = await states.blocklet.getBlocklet(rule.to.did);
|
|
682
|
-
for (const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
continue;
|
|
690
|
-
}
|
|
684
|
+
for (const child of blocklet.children || []) {
|
|
685
|
+
const { mountPoint } = child;
|
|
686
|
+
if (!mountPoint) {
|
|
687
|
+
logger.error(`mountPoint of child ${child.meta.name} does not exist`);
|
|
688
|
+
// eslint-disable-next-line no-continue
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
691
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
692
|
+
const childWebInterface = findWebInterface(child);
|
|
693
|
+
if (!childWebInterface) {
|
|
694
|
+
logger.error(`web interface of child ${child.meta.name} does not exist`);
|
|
695
|
+
// eslint-disable-next-line no-continue
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
698
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
from: {
|
|
704
|
-
pathPrefix: normalizePathPrefix(pathPrefix),
|
|
705
|
-
groupPathPrefix: rule.from.pathPrefix,
|
|
706
|
-
},
|
|
707
|
-
to: {
|
|
708
|
-
type: ROUTING_RULE_TYPES.BLOCKLET,
|
|
709
|
-
port: findInterfacePortByName(child, mountPoint.child.interfaceName),
|
|
710
|
-
did: rule.to.did, // root blocklet did
|
|
711
|
-
interfaceName: rule.to.interfaceName, // root blocklet interface
|
|
712
|
-
realDid: child.meta.did, // child blocklet did
|
|
713
|
-
realInterfaceName: mountPoint.child.interfaceName,
|
|
714
|
-
},
|
|
715
|
-
isProtected: isRootPath ? rule.isProtected : true,
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
rules.push(childRule);
|
|
719
|
-
}
|
|
699
|
+
const pathPrefix = path.join(rule.from.pathPrefix, mountPoint);
|
|
700
|
+
const isRootPath = pathPrefix === rule.from.pathPrefix;
|
|
701
|
+
if (isRootPath) {
|
|
702
|
+
occupied = true;
|
|
720
703
|
}
|
|
704
|
+
|
|
705
|
+
// if is root path, child rule become root rule
|
|
706
|
+
const childRule = {
|
|
707
|
+
id: isRootPath ? rule.id : uuid.v4(),
|
|
708
|
+
groupId: rule.id,
|
|
709
|
+
from: {
|
|
710
|
+
pathPrefix: normalizePathPrefix(pathPrefix),
|
|
711
|
+
groupPathPrefix: rule.from.pathPrefix,
|
|
712
|
+
},
|
|
713
|
+
to: {
|
|
714
|
+
type: ROUTING_RULE_TYPES.BLOCKLET,
|
|
715
|
+
port: findInterfacePortByName(child, childWebInterface.name),
|
|
716
|
+
did: rule.to.did, // root blocklet did
|
|
717
|
+
interfaceName: rule.to.interfaceName, // root blocklet interface
|
|
718
|
+
realDid: child.meta.did, // child blocklet did
|
|
719
|
+
realInterfaceName: childWebInterface.name,
|
|
720
|
+
},
|
|
721
|
+
isProtected: isRootPath ? rule.isProtected : true,
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
rules.push(childRule);
|
|
721
725
|
}
|
|
722
726
|
|
|
723
727
|
// get root rule
|
|
724
|
-
if (!occupied) {
|
|
728
|
+
if (!occupied && blocklet.meta.group !== BlockletGroup.gateway) {
|
|
725
729
|
rules.push(rule);
|
|
726
730
|
}
|
|
727
731
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
/* eslint-disable consistent-return */
|
|
4
4
|
const logger = require('@abtnode/logger')('state-blocklet-extras');
|
|
5
5
|
const camelCase = require('lodash/camelCase');
|
|
6
|
+
const get = require('lodash/get');
|
|
6
7
|
|
|
7
8
|
const BaseState = require('./base');
|
|
8
9
|
|
|
@@ -36,16 +37,28 @@ class BlockletExtrasState extends BaseState {
|
|
|
36
37
|
},
|
|
37
38
|
},
|
|
38
39
|
];
|
|
40
|
+
|
|
41
|
+
this.childExtras = this.extras.filter((x) => ['configs'].includes(x.name));
|
|
42
|
+
|
|
39
43
|
this.generateExtraFns();
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
delete(did) {
|
|
47
|
+
return this.remove({ did });
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
generateExtraFns() {
|
|
43
|
-
const methods = ['get', 'set', 'del'];
|
|
51
|
+
const methods = ['get', 'set', 'del', 'list'];
|
|
44
52
|
methods.forEach((method) => {
|
|
45
53
|
this.extras.forEach((extra) => {
|
|
46
54
|
const fn = camelCase(`${method} ${extra.name}`); // getConfigs, getRules
|
|
47
55
|
this[fn] = this.generateExtraFn(method, extra);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
48
58
|
|
|
59
|
+
const childMethods = ['get', 'set', 'del'];
|
|
60
|
+
childMethods.forEach((method) => {
|
|
61
|
+
this.childExtras.forEach((extra) => {
|
|
49
62
|
const childFn = camelCase(`${method} child ${extra.name}`); // getChildConfigs, getChildRules
|
|
50
63
|
this[childFn] = this.generateExtraChildFn(method, extra);
|
|
51
64
|
});
|
|
@@ -66,14 +79,22 @@ class BlockletExtrasState extends BaseState {
|
|
|
66
79
|
if (method === 'del') {
|
|
67
80
|
return this.generateDelFn(extra);
|
|
68
81
|
}
|
|
82
|
+
|
|
83
|
+
if (method === 'list') {
|
|
84
|
+
return this.generateListFn(extra);
|
|
85
|
+
}
|
|
69
86
|
}
|
|
70
87
|
|
|
71
88
|
generateGetFn(extra) {
|
|
72
|
-
return async (did) => {
|
|
89
|
+
return async (did, path, defaultValue) => {
|
|
73
90
|
const { dek } = this.options;
|
|
74
91
|
const { name, afterGet = noop('data') } = extra;
|
|
75
92
|
const item = await this.asyncDB.findOne({ did });
|
|
76
|
-
|
|
93
|
+
const data = afterGet({ data: item ? item[name] : item, did, dek });
|
|
94
|
+
if (!path) {
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
97
|
+
return get(data, path, defaultValue);
|
|
77
98
|
};
|
|
78
99
|
}
|
|
79
100
|
|
|
@@ -118,6 +139,21 @@ class BlockletExtrasState extends BaseState {
|
|
|
118
139
|
};
|
|
119
140
|
}
|
|
120
141
|
|
|
142
|
+
generateListFn(extra) {
|
|
143
|
+
return async () => {
|
|
144
|
+
const { dek } = this.options;
|
|
145
|
+
const { name, afterGet = noop('data') } = extra;
|
|
146
|
+
const docs = await this.asyncDB.find({});
|
|
147
|
+
const list = docs
|
|
148
|
+
.filter((x) => x[name])
|
|
149
|
+
.map((x) => ({
|
|
150
|
+
did: x.did,
|
|
151
|
+
[name]: afterGet({ data: x[name], did: x.did, dek }),
|
|
152
|
+
}));
|
|
153
|
+
return list;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
121
157
|
// generate extra child functions
|
|
122
158
|
|
|
123
159
|
generateExtraChildFn(method, extra) {
|
package/lib/states/blocklet.js
CHANGED
|
@@ -131,9 +131,9 @@ class BlockletState extends BaseState {
|
|
|
131
131
|
meta,
|
|
132
132
|
source = BlockletSource.registry,
|
|
133
133
|
status = BlockletStatus.added,
|
|
134
|
-
deployedFrom,
|
|
134
|
+
deployedFrom = '',
|
|
135
135
|
mode = BLOCKLET_MODES.PRODUCTION,
|
|
136
|
-
|
|
136
|
+
children: rawChildren = [],
|
|
137
137
|
} = {}) {
|
|
138
138
|
return this.getBlocklet(did).then(
|
|
139
139
|
(doc) =>
|
|
@@ -153,7 +153,7 @@ class BlockletState extends BaseState {
|
|
|
153
153
|
|
|
154
154
|
const ports = await this.getBlockletPorts({ interfaces: sanitized.interfaces || [] });
|
|
155
155
|
|
|
156
|
-
const children = await this.fillChildrenPorts(
|
|
156
|
+
const children = await this.fillChildrenPorts(rawChildren, {
|
|
157
157
|
defaultPort: getMaxPort(ports),
|
|
158
158
|
});
|
|
159
159
|
|
|
@@ -207,7 +207,7 @@ class BlockletState extends BaseState {
|
|
|
207
207
|
);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
upgradeBlocklet({ meta, source, deployedFrom, children } = {}) {
|
|
210
|
+
upgradeBlocklet({ meta, source, deployedFrom = '', children } = {}) {
|
|
211
211
|
return this.getBlocklet(meta.did).then(
|
|
212
212
|
(doc) =>
|
|
213
213
|
// eslint-disable-next-line no-async-promise-executor
|
|
@@ -416,10 +416,6 @@ class BlockletState extends BaseState {
|
|
|
416
416
|
return formatBlocklet({ ...doc, ...updates }, 'onRead', this.options.dek);
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
-
getChildrenFromMetas(childrenMeta) {
|
|
420
|
-
return childrenMeta.map((x) => ({ meta: x }));
|
|
421
|
-
}
|
|
422
|
-
|
|
423
419
|
async fillChildrenPorts(children, { defaultPort = 0, oldChildren } = {}) {
|
|
424
420
|
let _maxPort = defaultPort;
|
|
425
421
|
for (const child of children || []) {
|
package/lib/states/node.js
CHANGED
|
@@ -49,7 +49,10 @@ class NodeState extends BaseState {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
isInitialized(doc) {
|
|
52
|
-
|
|
52
|
+
const isOwnerConnected = !!doc.nodeOwner;
|
|
53
|
+
const isControlledBy3rdParty =
|
|
54
|
+
!doc.enablePassportIssuance && Array.isArray(doc.trustedPassports) && doc.trustedPassports.length > 0;
|
|
55
|
+
return isOwnerConnected || isControlledBy3rdParty;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
/**
|
|
@@ -92,13 +95,15 @@ class NodeState extends BaseState {
|
|
|
92
95
|
launcherInfo,
|
|
93
96
|
didRegistry,
|
|
94
97
|
didDomain,
|
|
98
|
+
enablePassportIssuance = true,
|
|
99
|
+
trustedPassports = [],
|
|
95
100
|
} = this.options;
|
|
96
101
|
|
|
97
102
|
if (nodeOwner && !validateOwner(nodeOwner)) {
|
|
98
103
|
return reject(new Error('Node owner is invalid'));
|
|
99
104
|
}
|
|
100
105
|
|
|
101
|
-
const initialized = this.isInitialized({ nodeOwner });
|
|
106
|
+
const initialized = this.isInitialized({ nodeOwner, enablePassportIssuance, trustedPassports });
|
|
102
107
|
|
|
103
108
|
return getDefaultConfigs()
|
|
104
109
|
.then((defaultConfigs) =>
|
|
@@ -126,6 +131,9 @@ class NodeState extends BaseState {
|
|
|
126
131
|
launcherInfo: launcherInfo || undefined,
|
|
127
132
|
didRegistry,
|
|
128
133
|
didDomain,
|
|
134
|
+
enablePassportIssuance,
|
|
135
|
+
trustedPassports,
|
|
136
|
+
customBlockletNumber: 0,
|
|
129
137
|
},
|
|
130
138
|
async (e, data) => {
|
|
131
139
|
if (e) {
|
|
@@ -262,6 +270,13 @@ class NodeState extends BaseState {
|
|
|
262
270
|
getBlockletRegistry() {
|
|
263
271
|
return this.read().then((info) => info.blockletRegistryList.find((item) => item.selected).url);
|
|
264
272
|
}
|
|
273
|
+
|
|
274
|
+
async increaseCustomBlockletNumber() {
|
|
275
|
+
const { _id, customBlockletNumber = 0 } = await this.read();
|
|
276
|
+
const num = customBlockletNumber + 1;
|
|
277
|
+
await this.update(_id, { $set: { customBlockletNumber: num } });
|
|
278
|
+
return num;
|
|
279
|
+
}
|
|
265
280
|
}
|
|
266
281
|
|
|
267
282
|
module.exports = NodeState;
|