@abtnode/core 1.16.11-next-61882496 → 1.16.11-next-b5795b3a
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/team.js +5 -5
- package/lib/blocklet/downloader/blocklet-downloader.js +2 -2
- package/lib/blocklet/downloader/bundle-downloader.js +2 -2
- package/lib/blocklet/hooks.js +1 -1
- package/lib/blocklet/manager/base.js +9 -9
- package/lib/blocklet/manager/disk.js +24 -19
- package/lib/blocklet/manager/helper/install-application-from-backup.js +1 -1
- package/lib/blocklet/migration.js +2 -2
- package/lib/blocklet/storage/backup/base.js +1 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +1 -1
- package/lib/blocklet/storage/backup/blocklet.js +1 -1
- package/lib/blocklet/storage/backup/disk.js +1 -0
- package/lib/blocklet/storage/restore/blocklet-extras.js +1 -1
- package/lib/blocklet/storage/restore/blocklet.js +1 -1
- package/lib/blocklet/storage/restore/disk.js +1 -1
- package/lib/blocklet/storage/restore/spaces.js +1 -1
- package/lib/cert.js +5 -5
- package/lib/crons/rotate-pm2-logs/index.js +1 -1
- package/lib/migrations/index.js +3 -3
- package/lib/processes/updater.js +1 -1
- package/lib/router/helper.js +5 -5
- package/lib/states/audit-log.js +1 -1
- package/lib/states/backup.js +5 -4
- package/lib/states/blocklet-extras.js +1 -1
- package/lib/states/blocklet.js +2 -2
- package/lib/states/cache.js +1 -1
- package/lib/states/node.js +5 -2
- package/lib/states/notification.js +1 -1
- package/lib/states/routing-snapshot.js +1 -1
- package/lib/states/site.js +1 -1
- package/lib/states/user.js +6 -2
- package/lib/team/manager.js +6 -6
- package/lib/util/blocklet.js +5 -5
- package/lib/util/rpc.js +1 -1
- package/lib/util/store.js +1 -1
- package/lib/webhook/sender/api/index.js +1 -1
- package/lib/webhook/sender/slack/index.js +1 -1
- package/package.json +17 -17
package/lib/api/team.js
CHANGED
|
@@ -642,7 +642,7 @@ class TeamAPI extends EventEmitter {
|
|
|
642
642
|
/**
|
|
643
643
|
* this function is only used to create server owner transfer invitation
|
|
644
644
|
*/
|
|
645
|
-
|
|
645
|
+
createTransferInvitation({ teamDid, remark }, context = {}) {
|
|
646
646
|
return this.createMemberInvitation(
|
|
647
647
|
{ teamDid, expireTime: this.transferOwnerExpireTime, remark, role: 'owner' },
|
|
648
648
|
context
|
|
@@ -956,7 +956,7 @@ class TeamAPI extends EventEmitter {
|
|
|
956
956
|
|
|
957
957
|
// Access Control
|
|
958
958
|
|
|
959
|
-
|
|
959
|
+
getRoles({ teamDid }) {
|
|
960
960
|
return this.teamManager.getRoles(teamDid);
|
|
961
961
|
}
|
|
962
962
|
|
|
@@ -1171,15 +1171,15 @@ class TeamAPI extends EventEmitter {
|
|
|
1171
1171
|
// Private
|
|
1172
1172
|
// =======
|
|
1173
1173
|
|
|
1174
|
-
|
|
1174
|
+
getRBAC(did) {
|
|
1175
1175
|
return this.teamManager.getRBAC(did);
|
|
1176
1176
|
}
|
|
1177
1177
|
|
|
1178
|
-
|
|
1178
|
+
getUserState(did) {
|
|
1179
1179
|
return this.teamManager.getUserState(did);
|
|
1180
1180
|
}
|
|
1181
1181
|
|
|
1182
|
-
|
|
1182
|
+
getSessionState(did) {
|
|
1183
1183
|
return this.teamManager.getSessionState(did);
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
@@ -161,7 +161,7 @@ class BlockletDownloader extends EventEmitter {
|
|
|
161
161
|
});
|
|
162
162
|
|
|
163
163
|
const results = await Promise.all(
|
|
164
|
-
downloadList.map(
|
|
164
|
+
downloadList.map((meta) => {
|
|
165
165
|
const url = meta.dist.tarball;
|
|
166
166
|
return this.bundleDownloader.download(meta, did, url, {
|
|
167
167
|
...options,
|
|
@@ -188,7 +188,7 @@ class BlockletDownloader extends EventEmitter {
|
|
|
188
188
|
return { isCancelled: false };
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
cancelDownload(did) {
|
|
192
192
|
return this.bundleDownloader.cancelDownload(did);
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -121,7 +121,7 @@ class BundleDownloader extends EventEmitter {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// eslint-disable-next-line no-unused-vars
|
|
124
|
-
|
|
124
|
+
cancelDownload(rootDid) {
|
|
125
125
|
if (this.downloadCtrls[rootDid]) {
|
|
126
126
|
for (const cancelCtrl of this.downloadCtrls[rootDid].values()) {
|
|
127
127
|
cancelCtrl.cancel();
|
|
@@ -294,7 +294,7 @@ class BundleDownloader extends EventEmitter {
|
|
|
294
294
|
await this.cache.set(CACHE_KEY, cacheList);
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
|
|
297
|
+
_getCachedTarFile(integrity) {
|
|
298
298
|
// eslint-disable-next-line no-param-reassign
|
|
299
299
|
integrity = toBase58(integrity);
|
|
300
300
|
|
package/lib/blocklet/hooks.js
CHANGED
|
@@ -57,7 +57,7 @@ const runUserHook = async (label, hookName, args) => {
|
|
|
57
57
|
const preInstall = (label, ...args) => runUserHook(label, 'pre-install', ...args);
|
|
58
58
|
const postInstall = (label, ...args) => runUserHook(label, 'post-install', ...args);
|
|
59
59
|
const preConfig = (label, ...args) => runUserHook(label, 'pre-config', ...args);
|
|
60
|
-
const preStart =
|
|
60
|
+
const preStart = (blocklet, options) => {
|
|
61
61
|
// check required environments
|
|
62
62
|
let environments = get(blocklet, 'meta.environments', []);
|
|
63
63
|
if (!Array.isArray(environments)) {
|
|
@@ -16,39 +16,39 @@ class BaseBlockletManager extends EventEmitter {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
install() {
|
|
20
20
|
throw new Error('Install must be implemented in sub class');
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
start() {
|
|
24
24
|
throw new Error('Install must be implemented in sub class');
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
stop() {
|
|
28
28
|
throw new Error('Stop must be implemented in sub class');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
restart() {
|
|
32
32
|
throw new Error('Restart must be implemented in sub class');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
reload() {
|
|
36
36
|
throw new Error('Reload must be implemented in sub class');
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
delete() {
|
|
40
40
|
throw new Error('Delete must be implemented in sub class');
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
detail() {
|
|
44
44
|
throw new Error('Detail must be implemented in sub class');
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
list() {
|
|
48
48
|
throw new Error('List must be implemented in sub class');
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
config() {
|
|
52
52
|
throw new Error('Config must be implemented in sub class');
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -410,7 +410,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
410
410
|
throw new Error('Unknown source');
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
|
|
413
|
+
diff({ did, hashFiles, rootDid }) {
|
|
414
414
|
return diff({ did, hashFiles, rootDid, states, manager: this });
|
|
415
415
|
}
|
|
416
416
|
|
|
@@ -418,7 +418,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
418
418
|
* After the dev function finished, the caller should send a BlockletEvents.installed event to the daemon
|
|
419
419
|
* @returns {Object} blocklet
|
|
420
420
|
*/
|
|
421
|
-
|
|
421
|
+
dev(folder, { rootDid, mountPoint, defaultStoreUrl } = {}) {
|
|
422
422
|
logger.info('dev component', { folder, rootDid, mountPoint });
|
|
423
423
|
|
|
424
424
|
const meta = getBlockletMeta(folder, { defaultStoreUrl });
|
|
@@ -433,15 +433,15 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
433
433
|
return installComponentFromDev({ folder, meta, rootDid, mountPoint, manager: this, states });
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
|
|
436
|
+
checkComponentsForUpdates({ did }) {
|
|
437
437
|
return UpgradeComponents.check({ did, states });
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
-
|
|
440
|
+
upgradeComponents({ updateId, selectedComponents: componentDids }, context = {}) {
|
|
441
441
|
return UpgradeComponents.upgrade({ updateId, componentDids, context, states, manager: this });
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
|
|
444
|
+
migrateApplicationToStructV2({ did, appSk, context = {} }) {
|
|
445
445
|
return migrateApplicationToStructV2({ did, appSk, context, manager: this, states });
|
|
446
446
|
}
|
|
447
447
|
|
|
@@ -660,7 +660,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
660
660
|
* @memberof BlockletManager
|
|
661
661
|
*/
|
|
662
662
|
// eslint-disable-next-line no-unused-vars
|
|
663
|
-
|
|
663
|
+
restoreBlocklet(input, context) {
|
|
664
664
|
const { from, ...param } = input;
|
|
665
665
|
if (from === 'spaces') {
|
|
666
666
|
return this._restoreFromSpaces(param, context);
|
|
@@ -1060,7 +1060,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1060
1060
|
return blocklets;
|
|
1061
1061
|
}
|
|
1062
1062
|
|
|
1063
|
-
|
|
1063
|
+
listBackups() {
|
|
1064
1064
|
return getBackupList(this.dataDirs.data);
|
|
1065
1065
|
}
|
|
1066
1066
|
|
|
@@ -1390,15 +1390,15 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1390
1390
|
});
|
|
1391
1391
|
}
|
|
1392
1392
|
|
|
1393
|
-
|
|
1393
|
+
ensureBlocklet(did, opts = {}) {
|
|
1394
1394
|
return getBlocklet({ ...opts, states, dataDirs: this.dataDirs, did, ensureIntegrity: true });
|
|
1395
1395
|
}
|
|
1396
1396
|
|
|
1397
|
-
|
|
1397
|
+
getBlocklet(did, opts = {}) {
|
|
1398
1398
|
return getBlocklet({ ...opts, states, dataDirs: this.dataDirs, did, ensureIntegrity: false });
|
|
1399
1399
|
}
|
|
1400
1400
|
|
|
1401
|
-
|
|
1401
|
+
hasBlocklet({ did }) {
|
|
1402
1402
|
return states.blocklet.hasBlocklet(did);
|
|
1403
1403
|
}
|
|
1404
1404
|
|
|
@@ -1461,9 +1461,11 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1461
1461
|
|
|
1462
1462
|
try {
|
|
1463
1463
|
const status = await getProcessState(component.env.processId);
|
|
1464
|
+
const oldStatus = component.status;
|
|
1464
1465
|
if (component.status !== status) {
|
|
1465
1466
|
component.status = status;
|
|
1466
1467
|
addToUpdates(component.meta.did, status);
|
|
1468
|
+
logger.info('will sync status from pm2', { did, status, oldStatus, componentDid: component.meta.did });
|
|
1467
1469
|
}
|
|
1468
1470
|
} catch {
|
|
1469
1471
|
if (
|
|
@@ -1488,6 +1490,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1488
1490
|
// iterate updates
|
|
1489
1491
|
if (updates.size > 0) {
|
|
1490
1492
|
for (const [status, dids] of updates) {
|
|
1493
|
+
logger.info('sync status from pm2', { did, status, componentDids: dids });
|
|
1491
1494
|
await states.blocklet.setBlockletStatus(did, status, { componentDids: dids });
|
|
1492
1495
|
}
|
|
1493
1496
|
}
|
|
@@ -1497,7 +1500,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1497
1500
|
return blocklet;
|
|
1498
1501
|
}
|
|
1499
1502
|
|
|
1500
|
-
|
|
1503
|
+
refreshListCache() {
|
|
1501
1504
|
this.list({ useCache: false }).catch((err) => {
|
|
1502
1505
|
logger.error('refresh blocklet list failed', { error: err });
|
|
1503
1506
|
});
|
|
@@ -1699,7 +1702,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1699
1702
|
* @return {Promise<Array<import('@abtnode/client').Backup>>}
|
|
1700
1703
|
* @memberof BlockletManager
|
|
1701
1704
|
*/
|
|
1702
|
-
|
|
1705
|
+
getBlockletBackups({ did }) {
|
|
1703
1706
|
return states.backup.getBlockletBackups({ did });
|
|
1704
1707
|
}
|
|
1705
1708
|
|
|
@@ -2493,6 +2496,8 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2493
2496
|
|
|
2494
2497
|
// update state
|
|
2495
2498
|
await states.blocklet.upgradeBlocklet({ meta, source, deployedFrom, children });
|
|
2499
|
+
// ensure component status is upgrading
|
|
2500
|
+
await states.blocklet.setBlockletStatus(did, BlockletStatus.upgrading, { componentDids });
|
|
2496
2501
|
await this._setConfigsFromMeta(did);
|
|
2497
2502
|
|
|
2498
2503
|
// should ensure blocklet integrity
|
|
@@ -2533,14 +2538,14 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2533
2538
|
|
|
2534
2539
|
logger.info('updated blocklet for upgrading', { did, version, source, name });
|
|
2535
2540
|
|
|
2536
|
-
const status =
|
|
2537
|
-
oldBlocklet.status === BlockletStatus.installed ? BlockletStatus.installed : BlockletStatus.stopped;
|
|
2538
|
-
await states.blocklet.setBlockletStatus(did, status, { componentDids });
|
|
2539
|
-
|
|
2540
|
-
// start new process
|
|
2541
2541
|
if (oldBlocklet.status === BlockletStatus.running) {
|
|
2542
|
+
// start new process
|
|
2542
2543
|
await this.start({ did, componentDids }, context);
|
|
2543
2544
|
logger.info('started blocklet for upgrading', { did, version });
|
|
2545
|
+
} else {
|
|
2546
|
+
const status =
|
|
2547
|
+
oldBlocklet.status === BlockletStatus.installed ? BlockletStatus.installed : BlockletStatus.stopped;
|
|
2548
|
+
await states.blocklet.setBlockletStatus(did, status, { componentDids });
|
|
2544
2549
|
}
|
|
2545
2550
|
|
|
2546
2551
|
blocklet = await this.getBlocklet(did, context);
|
|
@@ -2621,7 +2626,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2621
2626
|
* @return {*}
|
|
2622
2627
|
* @memberof BlockletManager
|
|
2623
2628
|
*/
|
|
2624
|
-
|
|
2629
|
+
_downloadBlocklet(blocklet, context = {}) {
|
|
2625
2630
|
const {
|
|
2626
2631
|
appDid,
|
|
2627
2632
|
meta: { did },
|
|
@@ -2638,7 +2643,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2638
2643
|
this.emit(BlockletEvents.statusChange, blocklet1);
|
|
2639
2644
|
}
|
|
2640
2645
|
},
|
|
2641
|
-
onProgress:
|
|
2646
|
+
onProgress: (data) => {
|
|
2642
2647
|
this.emit(BlockletEvents.downloadBundleProgress, { appDid: appDid || did, meta: { did }, ...data });
|
|
2643
2648
|
},
|
|
2644
2649
|
postDownload: async ({ isCancelled }) => {
|
|
@@ -203,7 +203,7 @@ const installApplicationFromBackup = async ({
|
|
|
203
203
|
// 从 store 下载 blocklet
|
|
204
204
|
await manager.blockletDownloader.download(blockletState, {
|
|
205
205
|
skipCheckIntegrity: true,
|
|
206
|
-
onProgress:
|
|
206
|
+
onProgress: (data) => {
|
|
207
207
|
manager.emit(BlockletEvents.downloadBundleProgress, { appDid: wallet.address, meta: { did }, ...data });
|
|
208
208
|
},
|
|
209
209
|
});
|
|
@@ -78,14 +78,14 @@ async function runScripts({
|
|
|
78
78
|
return true;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
function doBackup({ dbDir, backupDir, printInfo, printSuccess }) {
|
|
82
82
|
printInfo('Backing up before migration...');
|
|
83
83
|
fs.emptyDirSync(backupDir);
|
|
84
84
|
fs.copySync(dbDir, backupDir);
|
|
85
85
|
printSuccess('Backup success');
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
function doRestore({ dbDir, backupDir, printInfo, printSuccess }) {
|
|
89
89
|
printInfo('Restoring when migration failed...');
|
|
90
90
|
fs.emptyDirSync(dbDir);
|
|
91
91
|
fs.copySync(backupDir, dbDir);
|
|
@@ -28,7 +28,7 @@ class BlockletBackup extends BaseBackup {
|
|
|
28
28
|
* @return {Promise<import('@abtnode/client').BlockletState>}
|
|
29
29
|
* @memberof BlockletBackup
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
cleanData() {
|
|
32
32
|
const clone = cloneDeep(this.blocklet);
|
|
33
33
|
|
|
34
34
|
/** @type {import('@abtnode/client').ComponentState[]} */
|
|
@@ -8,7 +8,7 @@ const { BaseRestore } = require('./base');
|
|
|
8
8
|
class BlockletExtrasRestore extends BaseRestore {
|
|
9
9
|
filename = 'blocklet-extras.json';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
import(params) {
|
|
12
12
|
const extras = this.cleanExtras(this.getExtras(), params);
|
|
13
13
|
removeSync(join(this.restoreDir, this.filename));
|
|
14
14
|
outputJsonSync(join(this.restoreDir, this.filename), extras);
|
|
@@ -8,7 +8,7 @@ const { BaseRestore } = require('./base');
|
|
|
8
8
|
class BlockletRestore extends BaseRestore {
|
|
9
9
|
filename = 'blocklet.json';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
import(params) {
|
|
12
12
|
const blocklet = this.decrypt(this.getBlocklet(), params);
|
|
13
13
|
removeSync(join(this.restoreDir, this.filename));
|
|
14
14
|
outputJsonSync(join(this.restoreDir, this.filename), blocklet);
|
|
@@ -61,7 +61,7 @@ class DiskRestore extends BaseRestore {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
initialize() {
|
|
65
65
|
this.serverDir = process.env.ABT_NODE_DATA_DIR;
|
|
66
66
|
this.restoreDir = getBackupDirs(this.serverDir, this.input.appDid).restoreDir;
|
|
67
67
|
if (existsSync(this.restoreDir)) {
|
|
@@ -82,7 +82,7 @@ class SpacesRestore extends BaseRestore {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
initialize() {
|
|
86
86
|
this.serverDir = process.env.ABT_NODE_DATA_DIR;
|
|
87
87
|
this.restoreDir = join(this.serverDir, 'tmp/restore', this.input.appDid);
|
|
88
88
|
if (existsSync(this.restoreDir)) {
|
package/lib/cert.js
CHANGED
|
@@ -4,7 +4,7 @@ const logger = require('@abtnode/logger')('@abtnode/core:cert');
|
|
|
4
4
|
const { EVENTS } = require('@abtnode/constant');
|
|
5
5
|
const { BlockletEvents } = require('@blocklet/constant');
|
|
6
6
|
|
|
7
|
-
const onCertExpired =
|
|
7
|
+
const onCertExpired = (cert, states) => {
|
|
8
8
|
logger.info('send certificate expire notification', { domain: cert.domain });
|
|
9
9
|
states.notification.create({
|
|
10
10
|
title: 'SSL Certificate Expired',
|
|
@@ -120,7 +120,7 @@ class Cert extends EventEmitter {
|
|
|
120
120
|
* did?:string // blocklet.meta.did
|
|
121
121
|
* }}
|
|
122
122
|
*/
|
|
123
|
-
|
|
123
|
+
issue({ domain, did }) {
|
|
124
124
|
logger.info(`generate certificate for ${domain}`);
|
|
125
125
|
|
|
126
126
|
if (did) {
|
|
@@ -137,7 +137,7 @@ class Cert extends EventEmitter {
|
|
|
137
137
|
return result;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
update(data) {
|
|
141
141
|
return this.manager.update(data.id, { name: data.name, public: data.public });
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -149,11 +149,11 @@ class Cert extends EventEmitter {
|
|
|
149
149
|
return {};
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
addWithoutValidations(data) {
|
|
153
153
|
return this.manager.addWithoutValidations(data);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
updateWithoutValidations(id, data) {
|
|
157
157
|
return this.manager.updateWithoutValidations(id, data);
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -7,7 +7,7 @@ const getCron = () => ({
|
|
|
7
7
|
name: 'rotate-pm2-logs',
|
|
8
8
|
time: '0 0 * * *', // default : every day at midnight
|
|
9
9
|
options: { runOnInit: false },
|
|
10
|
-
fn:
|
|
10
|
+
fn: () => {
|
|
11
11
|
console.info(`Log rotator started on ${new Date().toISOString()}`);
|
|
12
12
|
const child = spawn('node', [path.join(__dirname, './script.js')], {
|
|
13
13
|
detached: true,
|
package/lib/migrations/index.js
CHANGED
|
@@ -78,7 +78,7 @@ const getMigrationScripts = (scriptsDir) => {
|
|
|
78
78
|
return sorted;
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
const doBackup =
|
|
81
|
+
const doBackup = ({ dataDir, configFile, printInfo, printSuccess }) => {
|
|
82
82
|
printInfo('Backing up state db and config before migration...');
|
|
83
83
|
|
|
84
84
|
const backupDir = path.join(dataDir, 'migration', Date.now().toString());
|
|
@@ -96,7 +96,7 @@ const doBackup = async ({ dataDir, configFile, printInfo, printSuccess }) => {
|
|
|
96
96
|
return backupDir;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
|
-
const doRestore =
|
|
99
|
+
const doRestore = ({ dataDir, configFile, backupPath, printInfo, printSuccess }) => {
|
|
100
100
|
printInfo('Restoring when migration failed...');
|
|
101
101
|
|
|
102
102
|
const dbBackup = path.join(backupPath, BACKUP_FILE_DB);
|
|
@@ -309,7 +309,7 @@ const runDataMigrations = async ({
|
|
|
309
309
|
}
|
|
310
310
|
};
|
|
311
311
|
|
|
312
|
-
const closeDatabaseConnections =
|
|
312
|
+
const closeDatabaseConnections = ({
|
|
313
313
|
dataDir,
|
|
314
314
|
blocklets = [],
|
|
315
315
|
printInfo = console.info, // eslint-disable-line
|
package/lib/processes/updater.js
CHANGED
|
@@ -109,7 +109,7 @@ const verifyBlockletServer = async (version) => {
|
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
// Restart Blocklet Server
|
|
112
|
-
const restartBlockletServer =
|
|
112
|
+
const restartBlockletServer = (dataDir) => {
|
|
113
113
|
// We put this in the event loop because it will terminate the current node process
|
|
114
114
|
// But we need to wait for the session state to transition from restarting to cleanup
|
|
115
115
|
process.nextTick(async () => {
|
package/lib/router/helper.js
CHANGED
|
@@ -168,7 +168,7 @@ const ensureServiceRule = async (sites) => {
|
|
|
168
168
|
return site;
|
|
169
169
|
});
|
|
170
170
|
};
|
|
171
|
-
const ensureRootRule =
|
|
171
|
+
const ensureRootRule = (sites) => {
|
|
172
172
|
return sites.map((site) => {
|
|
173
173
|
if (!isBasicSite(site.domain) && !site.rules.some((x) => x.from.pathPrefix === '/')) {
|
|
174
174
|
site.rules.push({
|
|
@@ -388,7 +388,7 @@ const ensureCorsForWebWallet = async (sites) => {
|
|
|
388
388
|
* @param {Array<import('@abtnode/client').BlockletState>} blocklets
|
|
389
389
|
* @return {Promise<any>}
|
|
390
390
|
*/
|
|
391
|
-
const ensureCorsForDidSpace =
|
|
391
|
+
const ensureCorsForDidSpace = (sites = [], blocklets) => {
|
|
392
392
|
return sites.map((site) => {
|
|
393
393
|
const blocklet = blocklets.find((x) => x.meta.did === site.blockletDid);
|
|
394
394
|
if (blocklet) {
|
|
@@ -404,7 +404,7 @@ const ensureCorsForDidSpace = async (sites = [], blocklets) => {
|
|
|
404
404
|
});
|
|
405
405
|
};
|
|
406
406
|
|
|
407
|
-
const filterSitesForRemovedBlocklets =
|
|
407
|
+
const filterSitesForRemovedBlocklets = (sites = [], blocklets) => {
|
|
408
408
|
return sites.filter((site) => {
|
|
409
409
|
if (!site.domain.endsWith(BLOCKLET_SITE_GROUP_SUFFIX)) {
|
|
410
410
|
return true;
|
|
@@ -420,7 +420,7 @@ const filterSitesForRemovedBlocklets = async (sites = [], blocklets) => {
|
|
|
420
420
|
*
|
|
421
421
|
* @returns {boolean} if routing changed
|
|
422
422
|
*/
|
|
423
|
-
const ensureBlockletWellknownRules =
|
|
423
|
+
const ensureBlockletWellknownRules = (sites, blocklets) => {
|
|
424
424
|
/**
|
|
425
425
|
* 1. component blocklet 不允许有相同多的 wellknown
|
|
426
426
|
* 1. wellknown 可以访问的路由:
|
|
@@ -488,7 +488,7 @@ const ensureBlockletWellknownRules = async (sites, blocklets) => {
|
|
|
488
488
|
.filter(Boolean);
|
|
489
489
|
};
|
|
490
490
|
|
|
491
|
-
const ensureBlockletCache =
|
|
491
|
+
const ensureBlockletCache = (sites = [], blocklets) => {
|
|
492
492
|
return sites
|
|
493
493
|
.map((site) => {
|
|
494
494
|
if (!site.domain.endsWith(BLOCKLET_SITE_GROUP_SUFFIX)) {
|
package/lib/states/audit-log.js
CHANGED
package/lib/states/backup.js
CHANGED
|
@@ -35,7 +35,7 @@ class BackupState extends BaseState {
|
|
|
35
35
|
/**
|
|
36
36
|
* @param {Pick<import('@abtnode/models').BackupState, 'appPid' | 'userDid' | 'strategy' | 'sourceUrl' | 'target'>} backup
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
start(backup) {
|
|
39
39
|
const { error, value } = validateBackupStart.validate(backup, {
|
|
40
40
|
stripUnknown: true,
|
|
41
41
|
allowUnknown: true,
|
|
@@ -52,7 +52,7 @@ class BackupState extends BaseState {
|
|
|
52
52
|
* @param {string} id
|
|
53
53
|
* @param {Pick<import('@abtnode/models').BackupState, 'targetUrl'>} successBackupInfo
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
success(id, successBackupInfo) {
|
|
56
56
|
const { error, value } = validateBackupSuccess.validate(successBackupInfo, {
|
|
57
57
|
stripUnknown: true,
|
|
58
58
|
allowUnknown: true,
|
|
@@ -78,7 +78,7 @@ class BackupState extends BaseState {
|
|
|
78
78
|
* @param {string} id
|
|
79
79
|
* @param {Pick<import('@abtnode/models').BackupState, 'message'>} errorBackupInfo
|
|
80
80
|
*/
|
|
81
|
-
|
|
81
|
+
fail(id, errorBackupInfo) {
|
|
82
82
|
const { error, value } = validateBackupFail.validate(errorBackupInfo, {
|
|
83
83
|
stripUnknown: true,
|
|
84
84
|
allowUnknown: true,
|
|
@@ -104,6 +104,7 @@ class BackupState extends BaseState {
|
|
|
104
104
|
* @param {import('@abtnode/models').BackupState} backup
|
|
105
105
|
* @return {Promise<import('@abtnode/models').BackupState>}
|
|
106
106
|
*/
|
|
107
|
+
// eslint-disable-next-line require-await
|
|
107
108
|
async create(backup) {
|
|
108
109
|
const { error, value } = validateBackup.validate(backup, {
|
|
109
110
|
allowUnknown: true,
|
|
@@ -121,7 +122,7 @@ class BackupState extends BaseState {
|
|
|
121
122
|
* @param {{ did: string }} { did }
|
|
122
123
|
* @return {Promise<Array<import('@abtnode/models').BackupState>>}
|
|
123
124
|
*/
|
|
124
|
-
|
|
125
|
+
getBlockletBackups({ did }) {
|
|
125
126
|
return this.find({ appPid: did }, {}, { updatedAt: -1 });
|
|
126
127
|
}
|
|
127
128
|
}
|
package/lib/states/blocklet.js
CHANGED
|
@@ -540,7 +540,7 @@ class BlockletState extends BaseState {
|
|
|
540
540
|
return this.updateBlocklet(did, pick(doc, ['status', 'children']));
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
-
|
|
543
|
+
setInstalledAt(did) {
|
|
544
544
|
logger.info('setInstalledAt', { did });
|
|
545
545
|
return this.updateBlocklet(did, { installedAt: new Date() });
|
|
546
546
|
}
|
|
@@ -638,7 +638,7 @@ class BlockletState extends BaseState {
|
|
|
638
638
|
});
|
|
639
639
|
}
|
|
640
640
|
|
|
641
|
-
|
|
641
|
+
updateStructV1Did(did, v1Did) {
|
|
642
642
|
return this.updateBlocklet(did, { structV1Did: v1Did });
|
|
643
643
|
}
|
|
644
644
|
}
|
package/lib/states/cache.js
CHANGED
package/lib/states/node.js
CHANGED
|
@@ -204,7 +204,7 @@ class NodeState extends BaseState {
|
|
|
204
204
|
return updated;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
updateNftHolder(holder) {
|
|
208
208
|
if (!holder) {
|
|
209
209
|
throw new Error('NFT holder can not be empty');
|
|
210
210
|
}
|
|
@@ -242,6 +242,7 @@ class NodeState extends BaseState {
|
|
|
242
242
|
return this.updateNodeInfo({ previousMode: '', mode: info.previousMode });
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
// eslint-disable-next-line require-await
|
|
245
246
|
async setMode(mode) {
|
|
246
247
|
if (Object.values(NODE_MODES).includes(mode) === false) {
|
|
247
248
|
throw new Error(`Can not update server to unsupported mode: ${mode}`);
|
|
@@ -250,7 +251,7 @@ class NodeState extends BaseState {
|
|
|
250
251
|
return this.updateNodeInfo({ previousMode: '', mode });
|
|
251
252
|
}
|
|
252
253
|
|
|
253
|
-
|
|
254
|
+
getEnvironments() {
|
|
254
255
|
return this.read().then((info) => ({
|
|
255
256
|
ABT_NODE: info.version,
|
|
256
257
|
ABT_NODE_VERSION: info.version,
|
|
@@ -280,6 +281,7 @@ class NodeState extends BaseState {
|
|
|
280
281
|
return doc.routing;
|
|
281
282
|
}
|
|
282
283
|
|
|
284
|
+
// eslint-disable-next-line require-await
|
|
283
285
|
async updateStatus(status) {
|
|
284
286
|
if (!Object.values(SERVER_STATUS).includes(status)) {
|
|
285
287
|
throw new Error('status is invalid');
|
|
@@ -288,6 +290,7 @@ class NodeState extends BaseState {
|
|
|
288
290
|
return this.update({ $set: { status } });
|
|
289
291
|
}
|
|
290
292
|
|
|
293
|
+
// eslint-disable-next-line require-await
|
|
291
294
|
async resetStatus() {
|
|
292
295
|
return this.updateStatus(SERVER_STATUS.RUNNING);
|
|
293
296
|
}
|
package/lib/states/site.js
CHANGED
|
@@ -80,7 +80,7 @@ class SiteState extends BaseState {
|
|
|
80
80
|
return sites.find((x) => x.domainAliases.some((y) => y.value === domain));
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
findOneByBlocklet(did) {
|
|
84
84
|
return this.findOne({ domain: getBlockletDomainGroupName(did) });
|
|
85
85
|
}
|
|
86
86
|
|
package/lib/states/user.js
CHANGED
|
@@ -105,11 +105,11 @@ class User extends ExtendBase {
|
|
|
105
105
|
return this.getUser(did);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
revokePassportById({ did, id }) {
|
|
109
109
|
return this._setPassportStatusById({ did, id, status: PASSPORT_STATUS.REVOKED });
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
enablePassportById({ did, id }) {
|
|
113
113
|
return this._setPassportStatusById({ did, id, status: PASSPORT_STATUS.VALID });
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -160,6 +160,7 @@ class User extends ExtendBase {
|
|
|
160
160
|
/**
|
|
161
161
|
* Get blocklet service user list
|
|
162
162
|
*/
|
|
163
|
+
// eslint-disable-next-line require-await
|
|
163
164
|
async getUsers({ query, sort, paging } = {}) {
|
|
164
165
|
const where = {};
|
|
165
166
|
const { approved, role, search } = query || {};
|
|
@@ -201,6 +202,7 @@ class User extends ExtendBase {
|
|
|
201
202
|
return this.paginate({ where }, sorting, paging);
|
|
202
203
|
}
|
|
203
204
|
|
|
205
|
+
// eslint-disable-next-line require-await
|
|
204
206
|
async getUsersByDids({ dids, query }) {
|
|
205
207
|
const { approved } = query || {};
|
|
206
208
|
const condition = { did: dids };
|
|
@@ -211,6 +213,7 @@ class User extends ExtendBase {
|
|
|
211
213
|
return this.find({ where: condition });
|
|
212
214
|
}
|
|
213
215
|
|
|
216
|
+
// eslint-disable-next-line require-await
|
|
214
217
|
async countByPassport({ name, status = PASSPORT_STATUS.VALID }) {
|
|
215
218
|
if (name === '$none') {
|
|
216
219
|
return this.count({
|
|
@@ -338,6 +341,7 @@ class User extends ExtendBase {
|
|
|
338
341
|
return { ...updated, _action: exist ? 'update' : 'add' };
|
|
339
342
|
}
|
|
340
343
|
|
|
344
|
+
// eslint-disable-next-line require-await
|
|
341
345
|
async getUserByDid(did) {
|
|
342
346
|
return this.findOne({ did }, { did: 1, pk: 1, fullName: 1, email: 1, role: 1, approved: 1 });
|
|
343
347
|
}
|
package/lib/team/manager.js
CHANGED
|
@@ -96,19 +96,19 @@ class TeamManager extends EventEmitter {
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
getUserState(teamDid) {
|
|
100
100
|
return this.getState(teamDid, 'user');
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
getPassportState(teamDid) {
|
|
104
104
|
return this.getState(teamDid, 'passport');
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
getConnectedAccountState(teamDid) {
|
|
108
108
|
return this.getState(teamDid, 'connectedAccount');
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
getSessionState(teamDid) {
|
|
112
112
|
return this.getState(teamDid, 'session');
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -207,7 +207,7 @@ class TeamManager extends EventEmitter {
|
|
|
207
207
|
return this.states.blockletExtras.setSettings(metaDid, { trustedPassports });
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
|
|
210
|
+
configTrustedFactories(did, trustedFactories) {
|
|
211
211
|
if (this.isNodeTeam(did)) {
|
|
212
212
|
return this.states.node.updateNodeInfo({ trustedFactories });
|
|
213
213
|
}
|
|
@@ -408,7 +408,7 @@ class TeamManager extends EventEmitter {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
getPid(did) {
|
|
412
412
|
return this.isNodeTeam(did) ? did : this.states.blocklet.getBlockletMetaDid(did);
|
|
413
413
|
}
|
|
414
414
|
}
|
package/lib/util/blocklet.js
CHANGED
|
@@ -635,7 +635,7 @@ const startBlockletProcess = async (
|
|
|
635
635
|
* Stop all precesses of a blocklet
|
|
636
636
|
* @param {*} blocklet should contain env props
|
|
637
637
|
*/
|
|
638
|
-
const stopBlockletProcess =
|
|
638
|
+
const stopBlockletProcess = (blocklet, { preStop = noop, skippedProcessIds = [], componentDids } = {}) => {
|
|
639
639
|
return deleteBlockletProcess(blocklet, { preDelete: preStop, skippedProcessIds, componentDids });
|
|
640
640
|
};
|
|
641
641
|
|
|
@@ -673,7 +673,7 @@ const deleteBlockletProcess = async (blocklet, { preDelete = noop, skippedProces
|
|
|
673
673
|
* Reload all precesses of a blocklet
|
|
674
674
|
* @param {*} blocklet should contain env props
|
|
675
675
|
*/
|
|
676
|
-
const reloadBlockletProcess =
|
|
676
|
+
const reloadBlockletProcess = (blocklet, { componentDids } = {}) =>
|
|
677
677
|
forEachBlocklet(
|
|
678
678
|
blocklet,
|
|
679
679
|
async (b) => {
|
|
@@ -714,7 +714,7 @@ const getProcessInfo = (processId, { throwOnNotExist = true } = {}) =>
|
|
|
714
714
|
|
|
715
715
|
const deleteProcess = (processId) =>
|
|
716
716
|
new Promise((resolve, reject) => {
|
|
717
|
-
pm2.delete(processId,
|
|
717
|
+
pm2.delete(processId, (err) => {
|
|
718
718
|
if (isUsefulError(err)) {
|
|
719
719
|
logger.error('blocklet process delete failed', { error: err });
|
|
720
720
|
return reject(err);
|
|
@@ -725,7 +725,7 @@ const deleteProcess = (processId) =>
|
|
|
725
725
|
|
|
726
726
|
const reloadProcess = (processId) =>
|
|
727
727
|
new Promise((resolve, reject) => {
|
|
728
|
-
pm2.reload(processId,
|
|
728
|
+
pm2.reload(processId, (err) => {
|
|
729
729
|
if (err) {
|
|
730
730
|
if (isUsefulError(err)) {
|
|
731
731
|
logger.error('blocklet reload failed', { error: err });
|
|
@@ -859,7 +859,7 @@ const parseComponents = async (component, context = {}) => {
|
|
|
859
859
|
};
|
|
860
860
|
|
|
861
861
|
const validateBlocklet = (blocklet) =>
|
|
862
|
-
forEachBlocklet(blocklet,
|
|
862
|
+
forEachBlocklet(blocklet, (b) => {
|
|
863
863
|
isRequirementsSatisfied(b.meta.requirements);
|
|
864
864
|
validateEngine(getBlockletEngineNameByPlatform(b.meta));
|
|
865
865
|
});
|
package/lib/util/rpc.js
CHANGED
|
@@ -9,7 +9,7 @@ const logger = require('@abtnode/logger')('@abtnode/core:rpc');
|
|
|
9
9
|
const host = '127.0.0.1';
|
|
10
10
|
const port = Number(process.env.ABT_NODE_UPDATER_PORT || 40405);
|
|
11
11
|
|
|
12
|
-
const doRpcCall =
|
|
12
|
+
const doRpcCall = (message) =>
|
|
13
13
|
new Promise((resolve) => {
|
|
14
14
|
logger.info('try send rpc request', message);
|
|
15
15
|
const sock = axon.socket('req');
|
package/lib/util/store.js
CHANGED
|
@@ -120,7 +120,7 @@ const parseSourceUrl = async (url) => {
|
|
|
120
120
|
};
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
const resolveTarballURL =
|
|
123
|
+
const resolveTarballURL = ({ did, tarball = '', storeUrl = '' }) => {
|
|
124
124
|
if (!tarball) {
|
|
125
125
|
return '';
|
|
126
126
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.11-next-
|
|
6
|
+
"version": "1.16.11-next-b5795b3a",
|
|
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": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.16.11-next-
|
|
23
|
-
"@abtnode/certificate-manager": "1.16.11-next-
|
|
24
|
-
"@abtnode/constant": "1.16.11-next-
|
|
25
|
-
"@abtnode/cron": "1.16.11-next-
|
|
26
|
-
"@abtnode/logger": "1.16.11-next-
|
|
27
|
-
"@abtnode/models": "1.16.11-next-
|
|
28
|
-
"@abtnode/queue": "1.16.11-next-
|
|
29
|
-
"@abtnode/rbac": "1.16.11-next-
|
|
30
|
-
"@abtnode/router-provider": "1.16.11-next-
|
|
31
|
-
"@abtnode/static-server": "1.16.11-next-
|
|
32
|
-
"@abtnode/timemachine": "1.16.11-next-
|
|
33
|
-
"@abtnode/util": "1.16.11-next-
|
|
22
|
+
"@abtnode/auth": "1.16.11-next-b5795b3a",
|
|
23
|
+
"@abtnode/certificate-manager": "1.16.11-next-b5795b3a",
|
|
24
|
+
"@abtnode/constant": "1.16.11-next-b5795b3a",
|
|
25
|
+
"@abtnode/cron": "1.16.11-next-b5795b3a",
|
|
26
|
+
"@abtnode/logger": "1.16.11-next-b5795b3a",
|
|
27
|
+
"@abtnode/models": "1.16.11-next-b5795b3a",
|
|
28
|
+
"@abtnode/queue": "1.16.11-next-b5795b3a",
|
|
29
|
+
"@abtnode/rbac": "1.16.11-next-b5795b3a",
|
|
30
|
+
"@abtnode/router-provider": "1.16.11-next-b5795b3a",
|
|
31
|
+
"@abtnode/static-server": "1.16.11-next-b5795b3a",
|
|
32
|
+
"@abtnode/timemachine": "1.16.11-next-b5795b3a",
|
|
33
|
+
"@abtnode/util": "1.16.11-next-b5795b3a",
|
|
34
34
|
"@arcblock/did": "1.18.80",
|
|
35
35
|
"@arcblock/did-auth": "1.18.80",
|
|
36
36
|
"@arcblock/did-ext": "^1.18.80",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"@arcblock/pm2-events": "^0.0.5",
|
|
42
42
|
"@arcblock/validator": "^1.18.80",
|
|
43
43
|
"@arcblock/vc": "1.18.80",
|
|
44
|
-
"@blocklet/constant": "1.16.11-next-
|
|
45
|
-
"@blocklet/meta": "1.16.11-next-
|
|
46
|
-
"@blocklet/sdk": "1.16.11-next-
|
|
44
|
+
"@blocklet/constant": "1.16.11-next-b5795b3a",
|
|
45
|
+
"@blocklet/meta": "1.16.11-next-b5795b3a",
|
|
46
|
+
"@blocklet/sdk": "1.16.11-next-b5795b3a",
|
|
47
47
|
"@did-space/client": "^0.2.113",
|
|
48
48
|
"@fidm/x509": "^1.2.1",
|
|
49
49
|
"@ocap/mcrypto": "1.18.80",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"express": "^4.18.2",
|
|
97
97
|
"jest": "^27.5.1"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "3a3586bb115318b2149e72ab99e441684122b3e3"
|
|
100
100
|
}
|