@abtnode/core 1.16.14-beta-a90ba909 → 1.16.14-beta-c2843ec5
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 +4 -1
- package/lib/blocklet/manager/base.js +0 -7
- package/lib/blocklet/manager/disk.js +48 -21
- package/lib/blocklet/manager/helper/install-application-from-dev.js +12 -34
- package/lib/blocklet/manager/helper/install-component-from-dev.js +35 -12
- package/lib/event.js +12 -2
- package/lib/index.js +2 -1
- package/lib/router/helper.js +12 -2
- package/lib/router/index.js +1 -0
- package/lib/util/index.js +0 -5
- package/lib/util/log.js +3 -2
- package/package.json +19 -19
package/lib/api/node.js
CHANGED
|
@@ -24,7 +24,8 @@ class NodeAPI {
|
|
|
24
24
|
* @param {object} states StateDB
|
|
25
25
|
* @param {string} nodeDid
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
// eslint-disable-next-line no-unused-vars
|
|
28
|
+
constructor(states, nodeDid, getRouterCapabilities = (_) => ({})) {
|
|
28
29
|
assert.notStrictEqual(states, undefined, 'argument states can not be undefined');
|
|
29
30
|
assert.notStrictEqual(states, null, 'argument states can not be null');
|
|
30
31
|
|
|
@@ -39,6 +40,7 @@ class NodeAPI {
|
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
this.state = states.node;
|
|
43
|
+
this.getRouterCapabilities = getRouterCapabilities;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
async updateNodeInfo(entity = {}, context) {
|
|
@@ -73,6 +75,7 @@ class NodeAPI {
|
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
info.uptime = process.uptime() * 1000;
|
|
78
|
+
info.capabilities = this.getRouterCapabilities(info);
|
|
76
79
|
|
|
77
80
|
return info;
|
|
78
81
|
}
|
|
@@ -2,18 +2,11 @@
|
|
|
2
2
|
const { EventEmitter } = require('events');
|
|
3
3
|
const logger = require('@abtnode/logger')('@abtnode/core:manager');
|
|
4
4
|
|
|
5
|
-
const { isCLI } = require('../../util');
|
|
6
|
-
|
|
7
5
|
class BaseBlockletManager extends EventEmitter {
|
|
8
6
|
constructor() {
|
|
9
7
|
super();
|
|
10
8
|
|
|
11
9
|
this.setMaxListeners(100);
|
|
12
|
-
|
|
13
|
-
// HACK: do not emit any events from CLI
|
|
14
|
-
if (isCLI() && process.env.NODE_ENV !== 'test') {
|
|
15
|
-
this.emit = (name) => logger.debug('stopped blocklet manager event in CLI', name);
|
|
16
|
-
}
|
|
17
10
|
}
|
|
18
11
|
|
|
19
12
|
install() {
|
|
@@ -32,7 +32,7 @@ const {
|
|
|
32
32
|
const getBlockletEngine = require('@blocklet/meta/lib/engine');
|
|
33
33
|
const {
|
|
34
34
|
isDeletableBlocklet,
|
|
35
|
-
|
|
35
|
+
getComponentMissingConfigs,
|
|
36
36
|
hasRunnableComponent,
|
|
37
37
|
forEachBlockletSync,
|
|
38
38
|
forEachChildSync,
|
|
@@ -165,8 +165,8 @@ const statusLock = new Lock('blocklet-status-lock');
|
|
|
165
165
|
const limitSync = pLimit(1);
|
|
166
166
|
|
|
167
167
|
const getHooksOutputFiles = (blocklet) => ({
|
|
168
|
-
output: path.join(blocklet.env.logsDir, 'output.log'),
|
|
169
|
-
error: path.join(blocklet.env.logsDir, 'error.log'),
|
|
168
|
+
output: blocklet.mode === BLOCKLET_MODES.DEVELOPMENT ? '' : path.join(blocklet.env.logsDir, 'output.log'),
|
|
169
|
+
error: blocklet.mode === BLOCKLET_MODES.DEVELOPMENT ? '' : path.join(blocklet.env.logsDir, 'error.log'),
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
const pm2StatusMap = {
|
|
@@ -379,7 +379,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
379
379
|
* After the dev function finished, the caller should send a BlockletEvents.installed event to the daemon
|
|
380
380
|
* @returns {Object} blocklet
|
|
381
381
|
*/
|
|
382
|
-
dev(folder, { rootDid, mountPoint, defaultStoreUrl } = {}) {
|
|
382
|
+
dev(folder, { rootDid, mountPoint, defaultStoreUrl, skipParseDependents } = {}) {
|
|
383
383
|
logger.info('dev component', { folder, rootDid, mountPoint });
|
|
384
384
|
|
|
385
385
|
const meta = getBlockletMeta(folder, { defaultStoreUrl });
|
|
@@ -391,7 +391,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
391
391
|
return installApplicationFromDev({ folder, meta, manager: this, states });
|
|
392
392
|
}
|
|
393
393
|
|
|
394
|
-
return installComponentFromDev({ folder, meta, rootDid, mountPoint, manager: this, states });
|
|
394
|
+
return installComponentFromDev({ folder, meta, rootDid, mountPoint, skipParseDependents, manager: this, states });
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
checkComponentsForUpdates({ did }) {
|
|
@@ -460,15 +460,21 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
460
460
|
throw new Error('No runnable component found');
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
-
// check required config
|
|
464
|
-
const missingProps = getAppMissingConfigs(blocklet1);
|
|
465
|
-
if (missingProps.length) {
|
|
466
|
-
throw new Error(
|
|
467
|
-
`Missing required configuration to start the blocklet: ${missingProps.map((x) => x.key).join(',')}`
|
|
468
|
-
);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
463
|
try {
|
|
464
|
+
// check required config
|
|
465
|
+
for (const component of blocklet1.children) {
|
|
466
|
+
if (!shouldSkipComponent(component.meta.did, componentDids)) {
|
|
467
|
+
const missingProps = getComponentMissingConfigs(component, [blocklet1]);
|
|
468
|
+
if (missingProps.length) {
|
|
469
|
+
throw new Error(
|
|
470
|
+
`Missing required configuration to start ${component.meta.title}: ${missingProps
|
|
471
|
+
.map((x) => x.key)
|
|
472
|
+
.join(',')}`
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
472
478
|
// blocklet may be manually stopped durning starting
|
|
473
479
|
// so error message would not be sent if blocklet is stopped
|
|
474
480
|
// so we need update status first
|
|
@@ -493,6 +499,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
493
499
|
|
|
494
500
|
// start process
|
|
495
501
|
const nodeEnvironments = await states.node.getEnvironments();
|
|
502
|
+
|
|
496
503
|
await startBlockletProcess(blocklet, {
|
|
497
504
|
...context,
|
|
498
505
|
preStart: getHookFn('preStart'),
|
|
@@ -1220,6 +1227,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1220
1227
|
// handleInstanceInStore 中会校验修改 publicToStore字段 的条件,不符合则会抛错,就不会执行下面更新 publicToStore 的逻辑
|
|
1221
1228
|
await handleInstanceInStore(blocklet, { publicToStore });
|
|
1222
1229
|
await states.blockletExtras.setSettings(did, { publicToStore });
|
|
1230
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1223
1231
|
|
|
1224
1232
|
const newState = await this.getBlocklet(did);
|
|
1225
1233
|
return newState;
|
|
@@ -1232,6 +1240,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1232
1240
|
await states.blockletExtras.setSettings(did, { navigations });
|
|
1233
1241
|
|
|
1234
1242
|
const newState = await this.getBlocklet(did);
|
|
1243
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1235
1244
|
this.emit(BlockletEvents.updated, newState);
|
|
1236
1245
|
return newState;
|
|
1237
1246
|
}
|
|
@@ -1284,7 +1293,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1284
1293
|
}
|
|
1285
1294
|
|
|
1286
1295
|
const blocklet = await this.getBlocklet(rootDid);
|
|
1287
|
-
|
|
1296
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1288
1297
|
this.emit(BlockletEvents.updated, { meta: { did: blocklet.meta.did } });
|
|
1289
1298
|
|
|
1290
1299
|
return blocklet;
|
|
@@ -1295,6 +1304,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1295
1304
|
const mergeConfig = { ...oldOAuth, ...JSON.parse(oauth) };
|
|
1296
1305
|
await states.blockletExtras.setSettings(did, { oauth: mergeConfig });
|
|
1297
1306
|
const newState = await this.getBlocklet(did);
|
|
1307
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1298
1308
|
this.emit(BlockletEvents.updated, newState);
|
|
1299
1309
|
return newState;
|
|
1300
1310
|
}
|
|
@@ -1322,6 +1332,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1322
1332
|
const mergeConfig = { ...oldConfig, ...newConfig };
|
|
1323
1333
|
await states.blockletExtras.setSettings(did, { notification: mergeConfig });
|
|
1324
1334
|
const newState = await this.getBlocklet(did);
|
|
1335
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1325
1336
|
this.emit(BlockletEvents.updated, newState);
|
|
1326
1337
|
return newState;
|
|
1327
1338
|
}
|
|
@@ -1415,6 +1426,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1415
1426
|
}
|
|
1416
1427
|
|
|
1417
1428
|
await states.blockletExtras.setSettings(blocklet.meta.did, { session: sessionConfig });
|
|
1429
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1418
1430
|
|
|
1419
1431
|
const newState = await this.getBlocklet(did);
|
|
1420
1432
|
this.emit(BlockletEvents.updated, newState);
|
|
@@ -1685,6 +1697,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1685
1697
|
spaceGateways.push(value);
|
|
1686
1698
|
|
|
1687
1699
|
await states.blockletExtras.setSettings(did, { spaceGateways });
|
|
1700
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1688
1701
|
}
|
|
1689
1702
|
|
|
1690
1703
|
/**
|
|
@@ -1705,6 +1718,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1705
1718
|
});
|
|
1706
1719
|
|
|
1707
1720
|
await states.blockletExtras.setSettings(did, { spaceGateways: latestSpaceGateways });
|
|
1721
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1708
1722
|
}
|
|
1709
1723
|
|
|
1710
1724
|
/**
|
|
@@ -1737,6 +1751,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1737
1751
|
}
|
|
1738
1752
|
|
|
1739
1753
|
await states.blockletExtras.setSettings(did, { spaceGateways });
|
|
1754
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
1740
1755
|
}
|
|
1741
1756
|
|
|
1742
1757
|
/**
|
|
@@ -2380,7 +2395,12 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
2380
2395
|
},
|
|
2381
2396
|
};
|
|
2382
2397
|
|
|
2383
|
-
|
|
2398
|
+
let children;
|
|
2399
|
+
if (mode === BLOCKLET_MODES.DEVELOPMENT) {
|
|
2400
|
+
children = [component];
|
|
2401
|
+
} else {
|
|
2402
|
+
children = component ? await this._getChildrenForInstallation(component) : [];
|
|
2403
|
+
}
|
|
2384
2404
|
|
|
2385
2405
|
// FIXME @linchen
|
|
2386
2406
|
// 当应用本身是容器时, 下载这个容器, 因为容器可能除 blocklet.yml 额外的文件
|
|
@@ -2617,8 +2637,12 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
2617
2637
|
|
|
2618
2638
|
if (oldBlocklet.status === BlockletStatus.running) {
|
|
2619
2639
|
// start new process
|
|
2620
|
-
|
|
2621
|
-
|
|
2640
|
+
try {
|
|
2641
|
+
await this.start({ did, componentDids }, context);
|
|
2642
|
+
logger.info('started blocklet for upgrading', { did, version, componentDids });
|
|
2643
|
+
} catch (error) {
|
|
2644
|
+
logger.error('failed to start blocklet for upgrading', { did, version, componentDids, error });
|
|
2645
|
+
}
|
|
2622
2646
|
} else {
|
|
2623
2647
|
const status =
|
|
2624
2648
|
oldBlocklet.status === BlockletStatus.installed ? BlockletStatus.installed : BlockletStatus.stopped;
|
|
@@ -3493,9 +3517,8 @@ class FederatedBlockletManager extends DiskBlockletManager {
|
|
|
3493
3517
|
});
|
|
3494
3518
|
|
|
3495
3519
|
const newState = await this.getBlocklet(did);
|
|
3496
|
-
this.emit(
|
|
3497
|
-
|
|
3498
|
-
});
|
|
3520
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
3521
|
+
this.emit(BlockletEvents.updated, { masterAppUrl: appUrl });
|
|
3499
3522
|
return newState;
|
|
3500
3523
|
}
|
|
3501
3524
|
|
|
@@ -3539,6 +3562,7 @@ class FederatedBlockletManager extends DiskBlockletManager {
|
|
|
3539
3562
|
federated: null,
|
|
3540
3563
|
});
|
|
3541
3564
|
const newState = await this.getBlocklet(did);
|
|
3565
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
3542
3566
|
this.emit(BlockletEvents.updated, newState);
|
|
3543
3567
|
return newState;
|
|
3544
3568
|
}
|
|
@@ -3554,6 +3578,7 @@ class FederatedBlockletManager extends DiskBlockletManager {
|
|
|
3554
3578
|
await states.blockletExtras.setSettings(did, { federated: config });
|
|
3555
3579
|
|
|
3556
3580
|
const newState = await this.getBlocklet(did);
|
|
3581
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
3557
3582
|
this.emit(BlockletEvents.updated, newState);
|
|
3558
3583
|
return newState;
|
|
3559
3584
|
}
|
|
@@ -3572,6 +3597,7 @@ class FederatedBlockletManager extends DiskBlockletManager {
|
|
|
3572
3597
|
await states.blockletExtras.setSettings(did, { federated });
|
|
3573
3598
|
|
|
3574
3599
|
const newState = await this.getBlocklet(did);
|
|
3600
|
+
this.emit(BlockletInternalEvents.appSettingChanged, { appDid: did });
|
|
3575
3601
|
this.emit(BlockletEvents.updated, newState);
|
|
3576
3602
|
return newState;
|
|
3577
3603
|
}
|
|
@@ -3616,7 +3642,8 @@ class FederatedBlockletManager extends DiskBlockletManager {
|
|
|
3616
3642
|
let roles = [];
|
|
3617
3643
|
if (status === 'approved') {
|
|
3618
3644
|
delegation = signV2(permanentWallet.address, permanentWallet.secretKey, {
|
|
3619
|
-
|
|
3645
|
+
// HACK: 钱包签名使用的始终是最新的,这里的 dalegation 也保持 agentDid 就是当前应用最新的 did(appId)
|
|
3646
|
+
agentDid: `did:abt:${memberSite.appId}`,
|
|
3620
3647
|
permissions: [
|
|
3621
3648
|
{
|
|
3622
3649
|
role: 'DIDConnectAgent',
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs-extra');
|
|
3
|
+
const { BlockletStatus, BLOCKLET_MODES, BlockletSource } = require('@blocklet/constant');
|
|
2
4
|
|
|
3
5
|
const logger = require('@abtnode/logger')('@abtnode/core:install-app-dev');
|
|
4
|
-
const { ensureMeta, updateBlockletFallbackLogo,
|
|
6
|
+
const { ensureMeta, updateBlockletFallbackLogo, getBundleDir } = require('../../../util/blocklet');
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
*
|
|
@@ -16,28 +18,7 @@ const installApplicationFromDev = async ({ folder, meta, states, manager } = {})
|
|
|
16
18
|
|
|
17
19
|
const exist = await states.blocklet.getBlocklet(did);
|
|
18
20
|
if (exist) {
|
|
19
|
-
|
|
20
|
-
throw new Error('The blocklet of production mode already exists, please remove it before developing');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const status = fromBlockletStatus(exist.status);
|
|
24
|
-
if (['starting', 'running'].includes(status)) {
|
|
25
|
-
throw new Error(`The blocklet is already on ${status}, please stop it before developing`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
logger.info('remove blocklet for dev', { did, version });
|
|
29
|
-
|
|
30
|
-
await manager.delete({ did, keepLogsDir: false });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// delete process
|
|
34
|
-
try {
|
|
35
|
-
await manager.deleteProcess({ did });
|
|
36
|
-
logger.info('delete blocklet precess for dev', { did, version });
|
|
37
|
-
} catch (err) {
|
|
38
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
39
|
-
logger.error('failed to delete blocklet process for dev', { error: err });
|
|
40
|
-
}
|
|
21
|
+
throw new Error(`The application ${exist.meta.title} already exists`);
|
|
41
22
|
}
|
|
42
23
|
|
|
43
24
|
// create component
|
|
@@ -51,7 +32,7 @@ const installApplicationFromDev = async ({ folder, meta, states, manager } = {})
|
|
|
51
32
|
};
|
|
52
33
|
|
|
53
34
|
// create app
|
|
54
|
-
|
|
35
|
+
await manager._addBlocklet({
|
|
55
36
|
component,
|
|
56
37
|
name,
|
|
57
38
|
did,
|
|
@@ -59,28 +40,25 @@ const installApplicationFromDev = async ({ folder, meta, states, manager } = {})
|
|
|
59
40
|
});
|
|
60
41
|
logger.info('add blocklet for dev', { did, version, meta });
|
|
61
42
|
|
|
62
|
-
await manager._downloadBlocklet(added);
|
|
63
|
-
|
|
64
43
|
// Add Config
|
|
65
44
|
await manager._setConfigsFromMeta(did);
|
|
66
45
|
|
|
67
46
|
// should ensure blocklet integrity
|
|
68
47
|
let blocklet = await manager.ensureBlocklet(did);
|
|
69
48
|
|
|
70
|
-
// pre install
|
|
71
|
-
await manager._runPreInstallHook(blocklet);
|
|
72
|
-
|
|
73
49
|
// Add environments
|
|
74
50
|
await manager._updateBlockletEnvironment(did);
|
|
75
51
|
blocklet = await manager.getBlocklet(did);
|
|
76
52
|
|
|
77
|
-
// post install
|
|
78
|
-
await manager._runPostInstallHook(blocklet);
|
|
79
|
-
|
|
80
53
|
await states.blocklet.setBlockletStatus(did, BlockletStatus.installed);
|
|
81
54
|
|
|
82
55
|
// logo
|
|
83
|
-
|
|
56
|
+
if (fs.existsSync(path.join(folder, component.meta.logo))) {
|
|
57
|
+
await fs.copy(
|
|
58
|
+
path.join(folder, component.meta.logo),
|
|
59
|
+
path.join(getBundleDir(manager.installDir, blocklet.meta), component.meta.logo)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
84
62
|
await updateBlockletFallbackLogo(blocklet);
|
|
85
63
|
|
|
86
64
|
blocklet = await manager.getBlocklet(did);
|
|
@@ -11,7 +11,12 @@ const {
|
|
|
11
11
|
} = require('../../../util/blocklet');
|
|
12
12
|
const { formatName } = require('../../../util/get-domain-for-blocklet');
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const needParseDependents = (meta, app) => {
|
|
15
|
+
const dependents = (meta.components || []).map((x) => x.source.name);
|
|
16
|
+
return !dependents.every((name) => app.children.some((x) => x.meta.name === name));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const installComponentFromDev = async ({ folder, meta, rootDid, mountPoint, manager, states, skipParseDependents }) => {
|
|
15
20
|
const { did, version } = meta;
|
|
16
21
|
|
|
17
22
|
const existRoot = await states.blocklet.getBlocklet(rootDid);
|
|
@@ -26,7 +31,7 @@ const installComponentFromDev = async ({ folder, meta, rootDid, mountPoint, mana
|
|
|
26
31
|
throw new Error(`The blocklet component is on ${status}, please stop it before developing`);
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
logger.info('remove blocklet component for dev', { did, version });
|
|
34
|
+
logger.info('remove blocklet component for dev', { did, rootDid, version });
|
|
30
35
|
|
|
31
36
|
await manager.deleteComponent({ did, rootDid });
|
|
32
37
|
}
|
|
@@ -44,24 +49,40 @@ const installComponentFromDev = async ({ folder, meta, rootDid, mountPoint, mana
|
|
|
44
49
|
status: BlockletStatus.installed,
|
|
45
50
|
mode: BLOCKLET_MODES.DEVELOPMENT,
|
|
46
51
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
|
|
53
|
+
const needParse = !skipParseDependents && needParseDependents(component.meta, existRoot);
|
|
54
|
+
let children = [];
|
|
55
|
+
if (needParse) {
|
|
56
|
+
const { dynamicComponents } = await parseComponents(component);
|
|
57
|
+
children = filterDuplicateComponents(
|
|
58
|
+
dynamicComponents,
|
|
59
|
+
existRoot.children.filter((x) => x.meta.did !== component.meta.did)
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
children.unshift(component);
|
|
53
63
|
checkVersionCompatibility([...children, ...existRoot.children]);
|
|
64
|
+
|
|
65
|
+
const componentDids = children.map((x) => x.meta.did);
|
|
66
|
+
|
|
54
67
|
await states.blocklet.addChildren(rootDid, children);
|
|
55
68
|
|
|
56
69
|
const newBlocklet = await states.blocklet.getBlocklet(rootDid);
|
|
57
70
|
await validateBlocklet(newBlocklet);
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
componentDids
|
|
71
|
+
|
|
72
|
+
if (needParse) {
|
|
73
|
+
const childrenToDownload = (newBlocklet.children || []).filter((x) => {
|
|
74
|
+
return componentDids.includes(x.meta.did);
|
|
75
|
+
});
|
|
76
|
+
await manager._downloadBlocklet({
|
|
77
|
+
...newBlocklet,
|
|
78
|
+
childrenToDownload,
|
|
62
79
|
});
|
|
63
80
|
}
|
|
64
81
|
|
|
82
|
+
await states.blocklet.setBlockletStatus(rootDid, BlockletStatus.installed, {
|
|
83
|
+
componentDids,
|
|
84
|
+
});
|
|
85
|
+
|
|
65
86
|
// Add Config
|
|
66
87
|
await manager._setConfigsFromMeta(rootDid);
|
|
67
88
|
|
|
@@ -82,6 +103,8 @@ const installComponentFromDev = async ({ folder, meta, rootDid, mountPoint, mana
|
|
|
82
103
|
|
|
83
104
|
blocklet = await manager.getBlocklet(rootDid);
|
|
84
105
|
|
|
106
|
+
blocklet.componentDids = componentDids;
|
|
107
|
+
|
|
85
108
|
return blocklet;
|
|
86
109
|
};
|
|
87
110
|
|
package/lib/event.js
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
const { EVENTS } = require('@abtnode/constant');
|
|
14
14
|
const { NodeMonitSender } = require('./monitor/node-monit-sender');
|
|
15
15
|
const handleInstanceInStore = require('./util/public-to-store');
|
|
16
|
+
const { isCLI } = require('./util');
|
|
16
17
|
|
|
17
18
|
const eventHub =
|
|
18
19
|
process.env.NODE_ENV === 'test' ? require('@arcblock/event-hub/single') : require('@arcblock/event-hub');
|
|
@@ -218,6 +219,15 @@ module.exports = ({
|
|
|
218
219
|
const handleBlockletEvent = async (eventName, payload) => {
|
|
219
220
|
const blocklet = payload.blocklet || payload;
|
|
220
221
|
|
|
222
|
+
if (isCLI() && process.env.NODE_ENV !== 'test') {
|
|
223
|
+
if (payload.blocklet && !payload.meta) {
|
|
224
|
+
onEvent(eventName, payload.blocklet);
|
|
225
|
+
} else {
|
|
226
|
+
onEvent(eventName, payload);
|
|
227
|
+
}
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
221
231
|
if ([BlockletEvents.installed].includes(eventName)) {
|
|
222
232
|
await handleBlockletInstall(eventName, payload);
|
|
223
233
|
|
|
@@ -382,8 +392,8 @@ module.exports = ({
|
|
|
382
392
|
listen(blockletManager, eventName, handleBlockletEvent);
|
|
383
393
|
});
|
|
384
394
|
|
|
385
|
-
|
|
386
|
-
listen(blockletManager,
|
|
395
|
+
Object.keys(BlockletInternalEvents).forEach((key) => {
|
|
396
|
+
listen(blockletManager, BlockletInternalEvents[key], onEvent);
|
|
387
397
|
});
|
|
388
398
|
|
|
389
399
|
listen(notificationState, EVENTS.NOTIFICATION_CREATE, onEvent);
|
package/lib/index.js
CHANGED
|
@@ -206,9 +206,10 @@ function ABTNode(options) {
|
|
|
206
206
|
deleteRoutingRule,
|
|
207
207
|
addDomainAlias,
|
|
208
208
|
deleteDomainAlias,
|
|
209
|
+
getRouterCapabilities,
|
|
209
210
|
} = getRouterHelpers({ dataDirs, routingSnapshot, routerManager, blockletManager, certManager });
|
|
210
211
|
|
|
211
|
-
const nodeAPI = new NodeAPI(states, options.nodeDid);
|
|
212
|
+
const nodeAPI = new NodeAPI(states, options.nodeDid, getRouterCapabilities);
|
|
212
213
|
const teamAPI = new TeamAPI({ states, teamManager, dataDirs });
|
|
213
214
|
|
|
214
215
|
blockletManager.resetSiteByDid = resetSiteByDid;
|
package/lib/router/helper.js
CHANGED
|
@@ -7,6 +7,7 @@ const UUID = require('uuid');
|
|
|
7
7
|
const dayjs = require('@abtnode/util/lib/dayjs');
|
|
8
8
|
const isUrl = require('is-url');
|
|
9
9
|
const get = require('lodash/get');
|
|
10
|
+
const pick = require('lodash/pick');
|
|
10
11
|
const cloneDeep = require('lodash/cloneDeep');
|
|
11
12
|
const groupBy = require('lodash/groupBy');
|
|
12
13
|
const isEqual = require('lodash/isEqual');
|
|
@@ -676,8 +677,6 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
676
677
|
const notification = states.notification;
|
|
677
678
|
const trafficInsight = states.trafficInsight;
|
|
678
679
|
|
|
679
|
-
// site level duplication detection
|
|
680
|
-
|
|
681
680
|
const downloadCert = async ({ domain, url }) => {
|
|
682
681
|
const destFolder = getTmpDir(path.join(`certificate-${Date.now()}`));
|
|
683
682
|
try {
|
|
@@ -1283,6 +1282,16 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
1283
1282
|
}
|
|
1284
1283
|
};
|
|
1285
1284
|
|
|
1285
|
+
const getRouterCapabilities = (info) => {
|
|
1286
|
+
const providerName = get(info, 'routing.provider', null);
|
|
1287
|
+
|
|
1288
|
+
if (providerName && providers[providerName]) {
|
|
1289
|
+
return pick(providers[providerName].capabilities || {}, ['httpImageFilter']);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
return {};
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1286
1295
|
const analyzeRouterLog = async () => {
|
|
1287
1296
|
const info = await nodeState.read();
|
|
1288
1297
|
const sites = await getRoutingSites({});
|
|
@@ -1593,6 +1602,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
1593
1602
|
deleteDomainAlias,
|
|
1594
1603
|
|
|
1595
1604
|
isGatewayCacheEnabled,
|
|
1605
|
+
getRouterCapabilities,
|
|
1596
1606
|
};
|
|
1597
1607
|
};
|
|
1598
1608
|
|
package/lib/router/index.js
CHANGED
package/lib/util/index.js
CHANGED
|
@@ -28,7 +28,6 @@ const {
|
|
|
28
28
|
DEFAULT_HTTPS_PORT,
|
|
29
29
|
SLOT_FOR_IP_DNS_SITE,
|
|
30
30
|
BLOCKLET_SITE_GROUP_SUFFIX,
|
|
31
|
-
NODE_MODES,
|
|
32
31
|
} = require('@abtnode/constant');
|
|
33
32
|
|
|
34
33
|
const DEFAULT_WELLKNOWN_PORT = 8088;
|
|
@@ -452,10 +451,6 @@ const templateReplace = (str, vars = {}) => {
|
|
|
452
451
|
};
|
|
453
452
|
|
|
454
453
|
const isGatewayCacheEnabled = (info) => {
|
|
455
|
-
if (info.mode === NODE_MODES.DEBUG) {
|
|
456
|
-
return false;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
454
|
const cacheEnabled = get(info, 'routing.cacheEnabled');
|
|
460
455
|
if (typeof cacheEnabled === 'boolean') {
|
|
461
456
|
return cacheEnabled;
|
package/lib/util/log.js
CHANGED
|
@@ -149,8 +149,9 @@ const getLogFiles = async ({ name, node }) => {
|
|
|
149
149
|
const blocklet = await node.getBlocklet({ did: appId, useCache: true });
|
|
150
150
|
let { name: blockletName } = blocklet.meta;
|
|
151
151
|
|
|
152
|
+
let component;
|
|
152
153
|
if (componentId) {
|
|
153
|
-
|
|
154
|
+
component = findComponentByIdV2(blocklet, componentId);
|
|
154
155
|
if (component) {
|
|
155
156
|
blockletName = path.join(blockletName, component.meta.name);
|
|
156
157
|
}
|
|
@@ -177,7 +178,7 @@ const getLogFiles = async ({ name, node }) => {
|
|
|
177
178
|
access,
|
|
178
179
|
stdout,
|
|
179
180
|
stderr,
|
|
180
|
-
recent:
|
|
181
|
+
recent: component?.mode === BLOCKLET_MODES.DEVELOPMENT ? 0 : 100,
|
|
181
182
|
};
|
|
182
183
|
}
|
|
183
184
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.14-beta-
|
|
6
|
+
"version": "1.16.14-beta-c2843ec5",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/analytics": "1.16.14-beta-
|
|
23
|
-
"@abtnode/auth": "1.16.14-beta-
|
|
24
|
-
"@abtnode/certificate-manager": "1.16.14-beta-
|
|
25
|
-
"@abtnode/constant": "1.16.14-beta-
|
|
26
|
-
"@abtnode/cron": "1.16.14-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.14-beta-
|
|
28
|
-
"@abtnode/models": "1.16.14-beta-
|
|
29
|
-
"@abtnode/queue": "1.16.14-beta-
|
|
30
|
-
"@abtnode/rbac": "1.16.14-beta-
|
|
31
|
-
"@abtnode/router-provider": "1.16.14-beta-
|
|
32
|
-
"@abtnode/static-server": "1.16.14-beta-
|
|
33
|
-
"@abtnode/timemachine": "1.16.14-beta-
|
|
34
|
-
"@abtnode/util": "1.16.14-beta-
|
|
22
|
+
"@abtnode/analytics": "1.16.14-beta-c2843ec5",
|
|
23
|
+
"@abtnode/auth": "1.16.14-beta-c2843ec5",
|
|
24
|
+
"@abtnode/certificate-manager": "1.16.14-beta-c2843ec5",
|
|
25
|
+
"@abtnode/constant": "1.16.14-beta-c2843ec5",
|
|
26
|
+
"@abtnode/cron": "1.16.14-beta-c2843ec5",
|
|
27
|
+
"@abtnode/logger": "1.16.14-beta-c2843ec5",
|
|
28
|
+
"@abtnode/models": "1.16.14-beta-c2843ec5",
|
|
29
|
+
"@abtnode/queue": "1.16.14-beta-c2843ec5",
|
|
30
|
+
"@abtnode/rbac": "1.16.14-beta-c2843ec5",
|
|
31
|
+
"@abtnode/router-provider": "1.16.14-beta-c2843ec5",
|
|
32
|
+
"@abtnode/static-server": "1.16.14-beta-c2843ec5",
|
|
33
|
+
"@abtnode/timemachine": "1.16.14-beta-c2843ec5",
|
|
34
|
+
"@abtnode/util": "1.16.14-beta-c2843ec5",
|
|
35
35
|
"@arcblock/did": "1.18.87",
|
|
36
36
|
"@arcblock/did-auth": "1.18.87",
|
|
37
37
|
"@arcblock/did-ext": "^1.18.87",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@arcblock/pm2-events": "^0.0.5",
|
|
43
43
|
"@arcblock/validator": "^1.18.87",
|
|
44
44
|
"@arcblock/vc": "1.18.87",
|
|
45
|
-
"@blocklet/constant": "1.16.14-beta-
|
|
46
|
-
"@blocklet/meta": "1.16.14-beta-
|
|
47
|
-
"@blocklet/resolver": "1.16.14-beta-
|
|
48
|
-
"@blocklet/sdk": "1.16.14-beta-
|
|
45
|
+
"@blocklet/constant": "1.16.14-beta-c2843ec5",
|
|
46
|
+
"@blocklet/meta": "1.16.14-beta-c2843ec5",
|
|
47
|
+
"@blocklet/resolver": "1.16.14-beta-c2843ec5",
|
|
48
|
+
"@blocklet/sdk": "1.16.14-beta-c2843ec5",
|
|
49
49
|
"@did-space/client": "^0.2.141",
|
|
50
50
|
"@fidm/x509": "^1.2.1",
|
|
51
51
|
"@ocap/mcrypto": "1.18.87",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"jest": "^27.5.1",
|
|
100
100
|
"unzipper": "^0.10.11"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "968bfad93779a21dd1374eede3ac7d4d6d40822b"
|
|
103
103
|
}
|