@abtnode/core 1.16.24 → 1.16.25-beta-4f765cf3

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 CHANGED
@@ -26,6 +26,7 @@ const {
26
26
  createUserPassport,
27
27
  } = require('@abtnode/auth/lib/passport');
28
28
  const { getPassportStatusEndpoint } = require('@abtnode/auth/lib/auth');
29
+ const { callFederated, getFederatedMaster, findFederatedSite } = require('@abtnode/auth/lib/util/federated');
29
30
  const { hasActiveOwnerPassport } = require('@abtnode/util/lib/passport');
30
31
  const getBlockletInfo = require('@blocklet/meta/lib/info');
31
32
  const { getUserAvatarUrl, getAppAvatarUrl, extractUserAvatar, getAvatarByUrl } = require('@abtnode/util/lib/user');
@@ -41,7 +42,6 @@ const { validateCreatePermission, validateUpdatePermission } = require('../valid
41
42
  const { getBlocklet } = require('../util/blocklet');
42
43
  const StoreUtil = require('../util/store');
43
44
  const { profileSchema } = require('../validators/user');
44
- const { callFederated, getFederatedMaster, findFederatedSite } = require('../util/federated');
45
45
 
46
46
  const sanitizeUrl = (url) => {
47
47
  if (!url) {
@@ -54,6 +54,7 @@ const {
54
54
  getDisplayName,
55
55
  } = require('@blocklet/meta/lib/util');
56
56
  const { getComponentsInternalInfo } = require('@blocklet/meta/lib/blocklet');
57
+ const { getRequiredComponentsLayers } = require('@blocklet/meta/lib/get-required-components-layers');
57
58
  const { update: updateMetaFile } = require('@blocklet/meta/lib/file');
58
59
  const { titleSchema, updateMountPointSchema, environmentNameSchema } = require('@blocklet/meta/lib/schema');
59
60
  const { emailConfigSchema } = require('@blocklet/sdk/lib/validators/email');
@@ -99,6 +100,8 @@ const isFunction = require('lodash/isFunction');
99
100
  const { encode } = require('@abtnode/util/lib/base32');
100
101
  const formatContext = require('@abtnode/util/lib/format-context');
101
102
  const md5 = require('@abtnode/util/lib/md5');
103
+ const { callFederated } = require('@abtnode/auth/lib/util/federated');
104
+ const pAll = require('p-all');
102
105
  const { consumeServerlessNFT, consumeLauncherSession } = require('../../util/launcher');
103
106
  const util = require('../../util');
104
107
  const {
@@ -197,7 +200,6 @@ const {
197
200
  getSelectedResources,
198
201
  updateSelectedResources,
199
202
  } = require('../project');
200
- const { callFederated } = require('../../util/federated');
201
203
 
202
204
  const { formatEnvironments, getBlockletMeta, validateOwner, isCLI } = util;
203
205
 
@@ -603,13 +605,68 @@ class DiskBlockletManager extends BaseBlockletManager {
603
605
  return migrateApplicationToStructV2({ did, appSk, context, manager: this, states });
604
606
  }
605
607
 
608
+ async startRequiredComponents({
609
+ componentDids,
610
+ inputComponentDids,
611
+ blocklet,
612
+ throwOnError,
613
+ checkHealthImmediately,
614
+ e2eMode,
615
+ context,
616
+ atomic,
617
+ }) {
618
+ if (!blocklet.children) {
619
+ return componentDids;
620
+ }
621
+
622
+ const targetDid = !inputComponentDids?.length ? componentDids[0] : inputComponentDids[0];
623
+
624
+ const canStartStatus = {
625
+ [BlockletStatus.installed]: true,
626
+ [BlockletStatus.error]: true,
627
+ [BlockletStatus.stopped]: true,
628
+ };
629
+
630
+ const requiredDidsLayers = getRequiredComponentsLayers({
631
+ targetDid,
632
+ children: blocklet.children,
633
+ filter: (child) => atomic || canStartStatus[child.status],
634
+ });
635
+
636
+ // 让当前的组件的状态提前变成 starting, 不然用户会很奇怪, 明明点了启动, 但是当前组件没变化.
637
+ const targetChild = blocklet.children.find((x) => x.meta.did === targetDid);
638
+ const doc = await states.blocklet.setBlockletStatus(blocklet.meta?.did, BlockletStatus.starting, {
639
+ componentDids: [targetDid],
640
+ });
641
+ targetChild.status = BlockletStatus.starting;
642
+ this.emit(BlockletEvents.statusChange, doc);
643
+
644
+ // start by dependency
645
+ for (const dids of requiredDidsLayers) {
646
+ if (atomic) {
647
+ await this._start({ blocklet, throwOnError, checkHealthImmediately, e2eMode, componentDids: dids }, context);
648
+ } else {
649
+ const tasks = dids.map(
650
+ (x) => () =>
651
+ this._start({ blocklet, throwOnError, checkHealthImmediately, e2eMode, componentDids: [x] }, context)
652
+ );
653
+ await pAll(tasks, { concurrency: 4 }).catch((err) => {
654
+ throw new Error(err.errors.join(', '));
655
+ });
656
+ }
657
+ }
658
+
659
+ // remove the components that have just been started
660
+ const startedDids = new Set(requiredDidsLayers.flat());
661
+ return componentDids.filter((x) => !startedDids.has(x));
662
+ }
663
+
606
664
  async start(
607
665
  { did, throwOnError, checkHealthImmediately = false, e2eMode = false, componentDids: inputComponentDids, atomic },
608
666
  context
609
667
  ) {
610
668
  const blocklet = await this.ensureBlocklet(did, { e2eMode });
611
-
612
- const componentDids = inputComponentDids?.length ? inputComponentDids : blocklet.children.map((x) => x.meta.did);
669
+ let componentDids = inputComponentDids?.length ? inputComponentDids : blocklet.children.map((x) => x.meta.did);
613
670
 
614
671
  // sync component config before at first to ensure resource component config is ready
615
672
  const serverSk = (await states.node.read()).sk;
@@ -619,20 +676,29 @@ class DiskBlockletManager extends BaseBlockletManager {
619
676
  )
620
677
  );
621
678
 
679
+ componentDids = await this.startRequiredComponents({
680
+ componentDids,
681
+ inputComponentDids,
682
+ blocklet,
683
+ throwOnError,
684
+ checkHealthImmediately,
685
+ e2eMode,
686
+ context,
687
+ atomic,
688
+ });
689
+
622
690
  if (atomic || !blocklet.structVersion) {
623
- return this._start(
624
- { did, throwOnError, checkHealthImmediately, e2eMode, componentDids: inputComponentDids },
625
- context
626
- );
691
+ return this._start({ blocklet, throwOnError, checkHealthImmediately, e2eMode, componentDids }, context);
627
692
  }
628
693
 
629
- const tasks = componentDids.map((componentDid) =>
630
- this._start({ blocklet, throwOnError, checkHealthImmediately, e2eMode, componentDids: [componentDid] }, context)
694
+ const tasks = componentDids.map(
695
+ (componentDid) => () =>
696
+ this._start({ blocklet, throwOnError, checkHealthImmediately, e2eMode, componentDids: [componentDid] }, context)
631
697
  );
632
698
 
633
- return Promise.any(tasks).catch((err) => {
634
- throw new Error(err.errors.join(', '));
635
- });
699
+ const rest = await pAll(tasks, { concurrency: 4 });
700
+
701
+ return rest[0];
636
702
  }
637
703
 
638
704
  async _start(
@@ -1257,7 +1323,7 @@ class DiskBlockletManager extends BaseBlockletManager {
1257
1323
  }
1258
1324
 
1259
1325
  // Get blocklet by blockletDid or appDid
1260
- async detail({ did, attachConfig = true, attachRuntimeInfo, useCache }, context) {
1326
+ async detail({ did, attachConfig = true, attachRuntimeInfo, useCache, getOptionalComponents }, context) {
1261
1327
  if (!did) {
1262
1328
  throw new Error('did should not be empty');
1263
1329
  }
@@ -1267,7 +1333,7 @@ class DiskBlockletManager extends BaseBlockletManager {
1267
1333
  }
1268
1334
 
1269
1335
  if (attachRuntimeInfo) {
1270
- return this._attachRuntimeInfo({ did, diskInfo: true, context });
1336
+ return this._attachRuntimeInfo({ did, diskInfo: true, context, getOptionalComponents });
1271
1337
  }
1272
1338
 
1273
1339
  if (useCache && this.cachedBlocklets.has(did)) {
@@ -1275,7 +1341,7 @@ class DiskBlockletManager extends BaseBlockletManager {
1275
1341
  }
1276
1342
 
1277
1343
  try {
1278
- const blocklet = await this.getBlocklet(did, { throwOnNotExist: false });
1344
+ const blocklet = await this.getBlocklet(did, { throwOnNotExist: false, getOptionalComponents });
1279
1345
 
1280
1346
  if (blocklet) {
1281
1347
  if (blocklet.appDid) {
@@ -3026,13 +3092,13 @@ class DiskBlockletManager extends BaseBlockletManager {
3026
3092
  return [];
3027
3093
  }
3028
3094
 
3029
- async _attachRuntimeInfo({ did, diskInfo = true, context }) {
3095
+ async _attachRuntimeInfo({ did, diskInfo = true, context, getOptionalComponents }) {
3030
3096
  if (!did) {
3031
3097
  throw new Error('did should not be empty');
3032
3098
  }
3033
3099
 
3034
3100
  try {
3035
- const blocklet = await this.getBlocklet(did, { throwOnNotExist: false });
3101
+ const blocklet = await this.getBlocklet(did, { throwOnNotExist: false, getOptionalComponents });
3036
3102
 
3037
3103
  if (!blocklet) {
3038
3104
  return null;
@@ -209,7 +209,9 @@ class User extends ExtendBase {
209
209
  if (role && role !== '$all' && !where.did) {
210
210
  if (role === '$none') {
211
211
  where.did = {
212
- [Op.notIn]: Sequelize.literal('(SELECT DISTINCT userDid FROM passports)'),
212
+ [Op.notIn]: Sequelize.literal(
213
+ `(SELECT DISTINCT userDid FROM passports WHERE status = '${PASSPORT_STATUS.VALID}')`
214
+ ),
213
215
  };
214
216
  } else {
215
217
  where.did = {
@@ -265,7 +267,9 @@ class User extends ExtendBase {
265
267
  return this.count({
266
268
  where: {
267
269
  did: {
268
- [Op.notIn]: Sequelize.literal('(SELECT DISTINCT userDid FROM passports)'),
270
+ [Op.notIn]: Sequelize.literal(
271
+ `(SELECT DISTINCT userDid FROM passports WHERE status = '${PASSPORT_STATUS.VALID}')`
272
+ ),
269
273
  },
270
274
  },
271
275
  });
@@ -1255,6 +1255,7 @@ const getBlocklet = async ({
1255
1255
  e2eMode = false,
1256
1256
  throwOnNotExist = true,
1257
1257
  ensureIntegrity = false,
1258
+ getOptionalComponents = false,
1258
1259
  } = {}) => {
1259
1260
  if (!did) {
1260
1261
  throw new Error('Blocklet did does not exist');
@@ -1333,8 +1334,12 @@ const getBlocklet = async ({
1333
1334
  fillBlockletConfigs(component, configs);
1334
1335
  });
1335
1336
 
1336
- const optionalComponents = await parseOptionalComponents(blocklet.children);
1337
- blocklet.optionalComponents = optionalComponents;
1337
+ if (getOptionalComponents) {
1338
+ const optionalComponents = await parseOptionalComponents(blocklet);
1339
+ blocklet.optionalComponents = optionalComponents;
1340
+ } else {
1341
+ blocklet.optionalComponents = [];
1342
+ }
1338
1343
 
1339
1344
  return blocklet;
1340
1345
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.24",
6
+ "version": "1.16.25-beta-4f765cf3",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,39 +19,39 @@
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.24",
23
- "@abtnode/auth": "1.16.24",
24
- "@abtnode/certificate-manager": "1.16.24",
25
- "@abtnode/constant": "1.16.24",
26
- "@abtnode/cron": "1.16.24",
27
- "@abtnode/logger": "1.16.24",
28
- "@abtnode/models": "1.16.24",
29
- "@abtnode/queue": "1.16.24",
30
- "@abtnode/rbac": "1.16.24",
31
- "@abtnode/router-provider": "1.16.24",
32
- "@abtnode/static-server": "1.16.24",
33
- "@abtnode/timemachine": "1.16.24",
34
- "@abtnode/util": "1.16.24",
35
- "@arcblock/did": "1.18.110",
36
- "@arcblock/did-auth": "1.18.110",
37
- "@arcblock/did-ext": "^1.18.110",
22
+ "@abtnode/analytics": "1.16.25-beta-4f765cf3",
23
+ "@abtnode/auth": "1.16.25-beta-4f765cf3",
24
+ "@abtnode/certificate-manager": "1.16.25-beta-4f765cf3",
25
+ "@abtnode/constant": "1.16.25-beta-4f765cf3",
26
+ "@abtnode/cron": "1.16.25-beta-4f765cf3",
27
+ "@abtnode/logger": "1.16.25-beta-4f765cf3",
28
+ "@abtnode/models": "1.16.25-beta-4f765cf3",
29
+ "@abtnode/queue": "1.16.25-beta-4f765cf3",
30
+ "@abtnode/rbac": "1.16.25-beta-4f765cf3",
31
+ "@abtnode/router-provider": "1.16.25-beta-4f765cf3",
32
+ "@abtnode/static-server": "1.16.25-beta-4f765cf3",
33
+ "@abtnode/timemachine": "1.16.25-beta-4f765cf3",
34
+ "@abtnode/util": "1.16.25-beta-4f765cf3",
35
+ "@arcblock/did": "1.18.113",
36
+ "@arcblock/did-auth": "1.18.113",
37
+ "@arcblock/did-ext": "^1.18.113",
38
38
  "@arcblock/did-motif": "^1.1.13",
39
- "@arcblock/did-util": "1.18.110",
40
- "@arcblock/event-hub": "1.18.110",
41
- "@arcblock/jwt": "^1.18.110",
39
+ "@arcblock/did-util": "1.18.113",
40
+ "@arcblock/event-hub": "1.18.113",
41
+ "@arcblock/jwt": "^1.18.113",
42
42
  "@arcblock/pm2-events": "^0.0.5",
43
- "@arcblock/validator": "^1.18.110",
44
- "@arcblock/vc": "1.18.110",
45
- "@blocklet/constant": "1.16.24",
46
- "@blocklet/env": "1.16.24",
47
- "@blocklet/meta": "1.16.24",
48
- "@blocklet/resolver": "1.16.24",
49
- "@blocklet/sdk": "1.16.24",
43
+ "@arcblock/validator": "^1.18.113",
44
+ "@arcblock/vc": "1.18.113",
45
+ "@blocklet/constant": "1.16.25-beta-4f765cf3",
46
+ "@blocklet/env": "1.16.25-beta-4f765cf3",
47
+ "@blocklet/meta": "1.16.25-beta-4f765cf3",
48
+ "@blocklet/resolver": "1.16.25-beta-4f765cf3",
49
+ "@blocklet/sdk": "1.16.25-beta-4f765cf3",
50
50
  "@did-space/client": "^0.3.67",
51
51
  "@fidm/x509": "^1.2.1",
52
- "@ocap/mcrypto": "1.18.110",
53
- "@ocap/util": "1.18.110",
54
- "@ocap/wallet": "1.18.110",
52
+ "@ocap/mcrypto": "1.18.113",
53
+ "@ocap/util": "1.18.113",
54
+ "@ocap/wallet": "1.18.113",
55
55
  "@slack/webhook": "^5.0.4",
56
56
  "archiver": "^5.3.1",
57
57
  "axios": "^0.27.2",
@@ -102,5 +102,5 @@
102
102
  "jest": "^29.7.0",
103
103
  "unzipper": "^0.10.11"
104
104
  },
105
- "gitHead": "6cd6669cb3569f96433e18b1dac346432741a1a7"
105
+ "gitHead": "7783a4bf883bb44b4266651b04008ef65bf6c2ce"
106
106
  }
@@ -1,43 +0,0 @@
1
- const { WELLKNOWN_SERVICE_PATH_PREFIX } = require('@abtnode/constant');
2
- const pRetry = require('p-retry');
3
- const { signV2 } = require('@arcblock/jwt');
4
- const joinUrl = require('url-join');
5
-
6
- const request = require('./request');
7
-
8
- function isMaster(site) {
9
- return site?.isMaster !== false;
10
- }
11
-
12
- function getFederatedMaster(blocklet) {
13
- const { sites } = blocklet?.settings?.federated || {};
14
- const masterSite = (sites || []).find((item) => isMaster(item));
15
- return masterSite || null;
16
- }
17
-
18
- function findFederatedSite(blocklet, targetAppPid) {
19
- const { sites } = blocklet?.settings?.federated || {};
20
- const targetSite = (sites || []).find((item) => item.appPid === targetAppPid);
21
- return targetSite || null;
22
- }
23
-
24
- async function callFederated({ site, permanentWallet, data, action }) {
25
- const url = new URL(site.appUrl);
26
- url.pathname = joinUrl(WELLKNOWN_SERVICE_PATH_PREFIX, `/api/federated/${action}`);
27
- const result = await pRetry(
28
- () =>
29
- request.post(url.href, {
30
- signer: permanentWallet.address,
31
- data: signV2(permanentWallet.address, permanentWallet.secretKey, data),
32
- }),
33
- { retries: 3 }
34
- );
35
- return result.data;
36
- }
37
-
38
- module.exports = {
39
- callFederated,
40
- getFederatedMaster,
41
- findFederatedSite,
42
- isMaster,
43
- };