@abtnode/core 1.16.11-beta-0ae58a71 → 1.16.11-beta-f74663ac
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/node.js +1 -1
- package/lib/api/team.js +5 -5
- package/lib/blocklet/downloader/blocklet-downloader.js +34 -19
- 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 +286 -172
- package/lib/blocklet/manager/helper/install-application-from-backup.js +1 -1
- package/lib/blocklet/manager/helper/install-application-from-general.js +18 -3
- package/lib/blocklet/manager/helper/install-component-from-dev.js +0 -1
- package/lib/blocklet/manager/helper/install-component-from-upload.js +8 -4
- package/lib/blocklet/manager/helper/install-component-from-url.js +4 -2
- package/lib/blocklet/manager/helper/upgrade-components.js +7 -7
- package/lib/blocklet/manager/pm2-events.js +3 -3
- 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/event.js +11 -1
- package/lib/index.js +8 -2
- package/lib/migrations/1.16.11-component-status.js +22 -0
- package/lib/migrations/index.js +3 -3
- package/lib/monitor/blocklet-runtime-monitor.js +7 -2
- 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 +11 -1
- package/lib/states/blocklet.js +46 -39
- package/lib/states/cache.js +1 -1
- package/lib/states/node.js +6 -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 +12 -6
- package/lib/team/manager.js +6 -6
- package/lib/util/blocklet.js +130 -118
- package/lib/util/launcher.js +238 -0
- package/lib/util/reset-node.js +19 -16
- package/lib/util/rpc.js +1 -1
- package/lib/util/store.js +1 -1
- package/lib/validators/space-gateway.js +3 -0
- package/lib/validators/util.js +3 -0
- 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/states/blocklet.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/* eslint-disable no-await-in-loop */
|
|
3
3
|
/* eslint-disable function-paren-newline */
|
|
4
4
|
/* eslint-disable no-underscore-dangle */
|
|
5
|
+
const pick = require('lodash/pick');
|
|
5
6
|
const omit = require('lodash/omit');
|
|
6
7
|
const uniq = require('lodash/uniq');
|
|
7
8
|
const cloneDeep = require('lodash/cloneDeep');
|
|
@@ -13,17 +14,23 @@ const {
|
|
|
13
14
|
getDisplayName,
|
|
14
15
|
forEachBlocklet,
|
|
15
16
|
forEachBlockletSync,
|
|
16
|
-
|
|
17
|
+
forEachComponentV2Sync,
|
|
17
18
|
getBlockletServices,
|
|
18
19
|
} = require('@blocklet/meta/lib/util');
|
|
19
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
BlockletStatus,
|
|
22
|
+
BlockletSource,
|
|
23
|
+
BLOCKLET_MODES,
|
|
24
|
+
BLOCKLET_DEFAULT_PORT_NAME,
|
|
25
|
+
BlockletGroup,
|
|
26
|
+
} = require('@blocklet/constant');
|
|
20
27
|
const { APP_STRUCT_VERSION } = require('@abtnode/constant');
|
|
21
28
|
|
|
22
29
|
const logger = require('@abtnode/logger')('@abtnode/core:states:blocklet');
|
|
23
30
|
|
|
24
31
|
const BaseState = require('./base');
|
|
25
32
|
const { checkDuplicateComponents, ensureMeta } = require('../util/blocklet');
|
|
26
|
-
const { validateBlockletMeta } = require('../util/blocklet');
|
|
33
|
+
const { validateBlockletMeta, getBlockletStatus, shouldSkipComponent } = require('../util/blocklet');
|
|
27
34
|
|
|
28
35
|
const lock = new Lock('blocklet-port-assign-lock');
|
|
29
36
|
|
|
@@ -37,6 +44,10 @@ const getExternalPortsFromMeta = (meta) =>
|
|
|
37
44
|
(meta.interfaces || []).map((x) => x.port && x.port.external).filter(Boolean);
|
|
38
45
|
|
|
39
46
|
const formatBlocklet = (blocklet, phase, dek) => {
|
|
47
|
+
if (phase === 'onRead') {
|
|
48
|
+
blocklet.status = getBlockletStatus(blocklet);
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
forEachBlockletSync(blocklet, (b) => {
|
|
41
52
|
if (b.meta) {
|
|
42
53
|
fixPerson(b.meta);
|
|
@@ -273,6 +284,9 @@ class BlockletState extends BaseState {
|
|
|
273
284
|
|
|
274
285
|
const formatted = formatBlocklet(cloneDeep(updates), 'onUpdate', this.config.dek);
|
|
275
286
|
const [, [updated]] = await this.update({ id: doc.id }, { $set: formatted });
|
|
287
|
+
|
|
288
|
+
updated.status = getBlockletStatus(updated);
|
|
289
|
+
|
|
276
290
|
return updated;
|
|
277
291
|
}
|
|
278
292
|
|
|
@@ -480,62 +494,55 @@ class BlockletState extends BaseState {
|
|
|
480
494
|
}
|
|
481
495
|
|
|
482
496
|
/**
|
|
483
|
-
* @param {
|
|
497
|
+
* @param {Did} did blocklet did
|
|
484
498
|
* @param {BlockletStatus} status blocklet status
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
499
|
+
* @param {{
|
|
500
|
+
* componentDids?: Array<Did>
|
|
501
|
+
* }}
|
|
488
502
|
*/
|
|
489
|
-
async setBlockletStatus(did, status, {
|
|
503
|
+
async setBlockletStatus(did, status, { componentDids } = {}) {
|
|
490
504
|
if (typeof status === 'undefined') {
|
|
491
505
|
throw new Error('Unsupported blocklet status');
|
|
492
506
|
}
|
|
493
507
|
|
|
494
508
|
const doc = await this.getBlocklet(did);
|
|
495
|
-
if (doc.status === status && !children) {
|
|
496
|
-
return formatBlocklet(doc, 'onRead', this.config.dek);
|
|
497
|
-
}
|
|
498
509
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
updates.startedAt = new Date();
|
|
502
|
-
}
|
|
503
|
-
if (status === BlockletStatus.installed) {
|
|
504
|
-
updates.installedAt = new Date();
|
|
510
|
+
if (doc.meta?.group === BlockletGroup.gateway && !doc.children?.length) {
|
|
511
|
+
return this.updateBlocklet(did, { status });
|
|
505
512
|
}
|
|
506
|
-
|
|
507
|
-
|
|
513
|
+
|
|
514
|
+
// for backward compatibility
|
|
515
|
+
if (!doc.structVersion && !doc.children?.length) {
|
|
516
|
+
return this.updateBlocklet(did, { status });
|
|
508
517
|
}
|
|
509
518
|
|
|
510
519
|
// update children status
|
|
511
|
-
|
|
512
|
-
if (
|
|
513
|
-
child.status = status;
|
|
520
|
+
forEachComponentV2Sync(doc, (component) => {
|
|
521
|
+
if (component.meta.group === BlockletGroup.gateway) {
|
|
514
522
|
return;
|
|
515
523
|
}
|
|
516
524
|
|
|
517
|
-
if (
|
|
518
|
-
if (
|
|
519
|
-
![
|
|
520
|
-
BlockletStatus.waiting,
|
|
521
|
-
BlockletStatus.upgrading,
|
|
522
|
-
BlockletStatus.installing,
|
|
523
|
-
BlockletStatus.starting,
|
|
524
|
-
].includes(status)
|
|
525
|
-
) {
|
|
526
|
-
child.status = status;
|
|
527
|
-
}
|
|
528
|
-
|
|
525
|
+
if (shouldSkipComponent(component.meta.did, componentDids)) {
|
|
529
526
|
return;
|
|
530
527
|
}
|
|
531
528
|
|
|
532
|
-
|
|
533
|
-
|
|
529
|
+
component.status = status;
|
|
530
|
+
if (status === BlockletStatus.running) {
|
|
531
|
+
component.startedAt = new Date();
|
|
532
|
+
component.stoppedAt = null;
|
|
533
|
+
}
|
|
534
|
+
if (status === BlockletStatus.stopped) {
|
|
535
|
+
component.startedAt = null;
|
|
536
|
+
component.stoppedAt = new Date();
|
|
534
537
|
}
|
|
535
538
|
});
|
|
536
539
|
|
|
537
|
-
|
|
538
|
-
|
|
540
|
+
return this.updateBlocklet(did, pick(doc, ['status', 'children']));
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
setInstalledAt(did) {
|
|
544
|
+
logger.info('setInstalledAt', { did });
|
|
545
|
+
return this.updateBlocklet(did, { installedAt: new Date() });
|
|
539
546
|
}
|
|
540
547
|
|
|
541
548
|
async fillChildrenPorts(children, { defaultPort = 0, oldChildren, returnMaxPort } = {}) {
|
|
@@ -631,7 +638,7 @@ class BlockletState extends BaseState {
|
|
|
631
638
|
});
|
|
632
639
|
}
|
|
633
640
|
|
|
634
|
-
|
|
641
|
+
updateStructV1Did(did, v1Did) {
|
|
635
642
|
return this.updateBlocklet(did, { structV1Did: v1Did });
|
|
636
643
|
}
|
|
637
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,9 +251,10 @@ 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,
|
|
257
|
+
ABT_NODE_VERSION: info.version,
|
|
256
258
|
ABT_NODE_DID: info.did,
|
|
257
259
|
ABT_NODE_SK: info.sk,
|
|
258
260
|
ABT_NODE_PK: info.pk,
|
|
@@ -279,6 +281,7 @@ class NodeState extends BaseState {
|
|
|
279
281
|
return doc.routing;
|
|
280
282
|
}
|
|
281
283
|
|
|
284
|
+
// eslint-disable-next-line require-await
|
|
282
285
|
async updateStatus(status) {
|
|
283
286
|
if (!Object.values(SERVER_STATUS).includes(status)) {
|
|
284
287
|
throw new Error('status is invalid');
|
|
@@ -287,6 +290,7 @@ class NodeState extends BaseState {
|
|
|
287
290
|
return this.update({ $set: { status } });
|
|
288
291
|
}
|
|
289
292
|
|
|
293
|
+
// eslint-disable-next-line require-await
|
|
290
294
|
async resetStatus() {
|
|
291
295
|
return this.updateStatus(SERVER_STATUS.RUNNING);
|
|
292
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
|
@@ -92,22 +92,24 @@ class User extends ExtendBase {
|
|
|
92
92
|
|
|
93
93
|
await super.update({ did }, { $set: updates });
|
|
94
94
|
await Promise.all(
|
|
95
|
-
(get(updates, 'passports') || [])
|
|
95
|
+
(get(updates, 'passports') || [])
|
|
96
|
+
.filter((x) => x.id)
|
|
97
|
+
.map((x) => this.passport.upsert({ id: x.id }, { ...x, userDid: did }))
|
|
96
98
|
);
|
|
97
99
|
await Promise.all(
|
|
98
|
-
(get(updates, 'connectedAccounts') || [])
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
(get(updates, 'connectedAccounts') || [])
|
|
101
|
+
.filter((x) => x.did)
|
|
102
|
+
.map((x) => this.connectedAccount.upsert({ did: x.did }, { ...x, userDid: did }))
|
|
101
103
|
);
|
|
102
104
|
|
|
103
105
|
return this.getUser(did);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
revokePassportById({ did, id }) {
|
|
107
109
|
return this._setPassportStatusById({ did, id, status: PASSPORT_STATUS.REVOKED });
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
enablePassportById({ did, id }) {
|
|
111
113
|
return this._setPassportStatusById({ did, id, status: PASSPORT_STATUS.VALID });
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -158,6 +160,7 @@ class User extends ExtendBase {
|
|
|
158
160
|
/**
|
|
159
161
|
* Get blocklet service user list
|
|
160
162
|
*/
|
|
163
|
+
// eslint-disable-next-line require-await
|
|
161
164
|
async getUsers({ query, sort, paging } = {}) {
|
|
162
165
|
const where = {};
|
|
163
166
|
const { approved, role, search } = query || {};
|
|
@@ -199,6 +202,7 @@ class User extends ExtendBase {
|
|
|
199
202
|
return this.paginate({ where }, sorting, paging);
|
|
200
203
|
}
|
|
201
204
|
|
|
205
|
+
// eslint-disable-next-line require-await
|
|
202
206
|
async getUsersByDids({ dids, query }) {
|
|
203
207
|
const { approved } = query || {};
|
|
204
208
|
const condition = { did: dids };
|
|
@@ -209,6 +213,7 @@ class User extends ExtendBase {
|
|
|
209
213
|
return this.find({ where: condition });
|
|
210
214
|
}
|
|
211
215
|
|
|
216
|
+
// eslint-disable-next-line require-await
|
|
212
217
|
async countByPassport({ name, status = PASSPORT_STATUS.VALID }) {
|
|
213
218
|
if (name === '$none') {
|
|
214
219
|
return this.count({
|
|
@@ -336,6 +341,7 @@ class User extends ExtendBase {
|
|
|
336
341
|
return { ...updated, _action: exist ? 'update' : 'add' };
|
|
337
342
|
}
|
|
338
343
|
|
|
344
|
+
// eslint-disable-next-line require-await
|
|
339
345
|
async getUserByDid(did) {
|
|
340
346
|
return this.findOne({ did }, { did: 1, pk: 1, fullName: 1, email: 1, role: 1, approved: 1 });
|
|
341
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
|
}
|