@abtnode/core 1.8.61 → 1.8.62

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
@@ -595,7 +595,13 @@ class TeamAPI extends EventEmitter {
595
595
  async getPassportIssuances({ teamDid, ownerDid }) {
596
596
  const state = await this.getSessionState(teamDid);
597
597
 
598
- const list = await state.find({ type: 'passport-issuance', ownerDid });
598
+ const query = { type: 'passport-issuance' };
599
+
600
+ if (ownerDid) {
601
+ query.ownerDid = ownerDid;
602
+ }
603
+
604
+ const list = await state.find(query);
599
605
 
600
606
  return list.map((d) => ({
601
607
  // eslint-disable-next-line no-underscore-dangle
@@ -118,6 +118,7 @@ const {
118
118
  consumeServerlessNFT,
119
119
  validateAppConfig,
120
120
  checkDuplicateAppSk,
121
+ checkDuplicateMountPoint,
121
122
  } = require('../../util/blocklet');
122
123
  const StoreUtil = require('../../util/store');
123
124
  const states = require('../../states');
@@ -1144,20 +1145,26 @@ class BlockletManager extends BaseBlockletManager {
1144
1145
  }
1145
1146
 
1146
1147
  const rootDid = blocklet.meta.did;
1148
+ const isRootComponent = !did;
1147
1149
 
1148
- const { children } = blocklet;
1149
- const component = children.find((x) => x.meta.did === did);
1150
-
1150
+ const component = isRootComponent ? blocklet : blocklet.children.find((x) => x.meta.did === did);
1151
1151
  if (!component) {
1152
1152
  throw new Error('component does not exist');
1153
1153
  }
1154
1154
 
1155
- if (!component.dynamic) {
1155
+ if (!isRootComponent && !component.dynamic) {
1156
1156
  throw new Error('cannot update mountPoint of non-dynamic component');
1157
1157
  }
1158
1158
 
1159
+ if (isRootComponent && component.group === BlockletGroup.gateway) {
1160
+ throw new Error('cannot update mountPoint of gateway blocklet');
1161
+ }
1162
+
1163
+ checkDuplicateMountPoint(blocklet, mountPoint);
1164
+
1159
1165
  component.mountPoint = mountPoint;
1160
- await states.blocklet.updateBlocklet(rootDid, { children });
1166
+
1167
+ await states.blocklet.updateBlocklet(rootDid, { mountPoint: blocklet.mountPoint, children: blocklet.children });
1161
1168
 
1162
1169
  this.emit(BlockletEvents.upgraded, { blocklet, context: { ...context, createAuditLog: false } }); // trigger router refresh
1163
1170
 
@@ -258,13 +258,19 @@ const ensureWellknownRule = async (sites) => {
258
258
  if (blockletRules.length) {
259
259
  // get pathPrefix for blocklet-service
260
260
  const rootBlockletRule = blockletRules.find((x) => x.to.did === x.to.componentId);
261
- const pathPrefix = joinUrl(rootBlockletRule?.from?.pathPrefix || '/', WELLKNOWN_SERVICE_PATH_PREFIX);
261
+
262
+ const servicePathPrefix = joinUrl(
263
+ // rootBlockletRule?.from?.pathPrefix is for backwards compatibility
264
+ // rootBlockletRule?.from?.groupPathPrefix 在旧的场景中可能不为 '/' (blocklet 只能挂载在 relative prefix 下)
265
+ rootBlockletRule?.from?.groupPathPrefix || rootBlockletRule?.from?.pathPrefix || '/',
266
+ WELLKNOWN_SERVICE_PATH_PREFIX
267
+ );
262
268
 
263
269
  // requests for /.well-known/service will stay in blocklet-service and never proxy back to blocklet
264
270
  // so any rule is ok to be cloned
265
- if (!site.rules.some((x) => x.from.pathPrefix === pathPrefix)) {
271
+ if (!site.rules.some((x) => x.from.pathPrefix === servicePathPrefix)) {
266
272
  const rule = cloneDeep(rootBlockletRule || blockletRules[0]);
267
- rule.from.pathPrefix = pathPrefix;
273
+ rule.from.pathPrefix = servicePathPrefix;
268
274
  rule.isProtected = true;
269
275
  site.rules.push(rule);
270
276
  }
@@ -11,6 +11,7 @@ const get = require('lodash/get');
11
11
  const { EventEmitter } = require('events');
12
12
  const uuid = require('uuid');
13
13
  const isUrl = require('is-url');
14
+ const joinUrl = require('url-join');
14
15
  const cloneDeep = require('lodash/cloneDeep');
15
16
  const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
16
17
  const logger = require('@abtnode/logger')('@abtnode/core:router:manager');
@@ -570,7 +571,8 @@ class RouterManager extends EventEmitter {
570
571
  rule.groupId = rule.id;
571
572
  rule.from.pathPrefix = normalizePathPrefix(rule.from.pathPrefix);
572
573
  if (rule.to.type === ROUTING_RULE_TYPES.BLOCKLET) {
573
- rule.from.groupPathPrefix = rule.from.pathPrefix;
574
+ // pathPrefix of root blocklet maybe changed to another prefix than '/', so use old groupPathPrefix first
575
+ rule.from.groupPathPrefix = rule.from.groupPathPrefix || rule.from.pathPrefix;
574
576
  rule.to.componentId = rule.to.did;
575
577
  }
576
578
  if (rule.to.url) {
@@ -580,18 +582,32 @@ class RouterManager extends EventEmitter {
580
582
 
581
583
  /**
582
584
  * get all rules to be add or update to site from root rule
583
- * @param {*} rule
585
+ * @param {*} rootRule
584
586
  */
585
- async getRulesForMutation(rule) {
586
- if (rule.to.type !== ROUTING_RULE_TYPES.BLOCKLET) {
587
- return [rule];
587
+ async getRulesForMutation(rootRule) {
588
+ if (rootRule.to.type !== ROUTING_RULE_TYPES.BLOCKLET) {
589
+ return [rootRule];
588
590
  }
589
591
 
590
592
  const rules = [];
591
- let occupied = false;
592
593
 
593
594
  // get child rules
594
- const blocklet = await states.blocklet.getBlocklet(rule.to.did);
595
+ const blocklet = await states.blocklet.getBlocklet(rootRule.to.did);
596
+
597
+ // blocklet may be mounted in relative prefix (for old usage), so blockletPrefix may not be '/'
598
+ // blocklet prefix is the origin pathPrefix in rootRule
599
+ const blockletPrefix = normalizePathPrefix(rootRule.from.pathPrefix);
600
+
601
+ // root component's mountPoint may not be '/'
602
+ const rootComponentPrefix = joinUrl(blockletPrefix, blocklet.mountPoint || '/');
603
+ rootRule.from.pathPrefix = normalizePathPrefix(rootComponentPrefix);
604
+
605
+ const isOccupiable = blocklet.meta.group === BlockletGroup.gateway;
606
+
607
+ if (!isOccupiable) {
608
+ rules.push(rootRule);
609
+ }
610
+
595
611
  forEachChildSync(blocklet, (component, { id, ancestors }) => {
596
612
  if (component.meta.group === BlockletGroup.gateway) {
597
613
  return;
@@ -611,38 +627,40 @@ class RouterManager extends EventEmitter {
611
627
  return;
612
628
  }
613
629
 
614
- const pathPrefix = path.join(rule.from.pathPrefix, ...ancestors.map((x) => x.mountPoint || ''), mountPoint);
615
- const isRootPath = normalizePathPrefix(pathPrefix) === normalizePathPrefix(rule.from.pathPrefix);
616
- if (isRootPath) {
617
- occupied = true;
630
+ const pathPrefix = path.join(
631
+ blockletPrefix,
632
+ // level 1 component should be independent with root component
633
+ ...ancestors.slice(1).map((x) => x.mountPoint || ''),
634
+ mountPoint
635
+ );
636
+
637
+ const occupied = normalizePathPrefix(pathPrefix) === normalizePathPrefix(rootRule.from.pathPrefix);
638
+
639
+ if (occupied && !isOccupiable) {
640
+ return;
618
641
  }
619
642
 
620
643
  // if is root path, child rule become root rule
621
644
  const childRule = {
622
- id: isRootPath ? rule.id : uuid.v4(),
623
- groupId: rule.id,
645
+ id: occupied ? rootRule.id : uuid.v4(),
646
+ groupId: rootRule.id,
624
647
  from: {
625
648
  pathPrefix: normalizePathPrefix(pathPrefix),
626
- groupPathPrefix: rule.from.pathPrefix,
649
+ groupPathPrefix: blockletPrefix,
627
650
  },
628
651
  to: {
629
652
  type: ROUTING_RULE_TYPES.BLOCKLET,
630
653
  port: findInterfacePortByName(component, childWebInterface.name),
631
- did: rule.to.did, // root component did
632
- interfaceName: rule.to.interfaceName, // root component interface
654
+ did: rootRule.to.did, // root component did
655
+ interfaceName: rootRule.to.interfaceName, // root component interface
633
656
  componentId: id,
634
657
  },
635
- isProtected: isRootPath ? rule.isProtected : true,
658
+ isProtected: occupied ? rootRule.isProtected : true,
636
659
  };
637
660
 
638
661
  rules.push(childRule);
639
662
  });
640
663
 
641
- // get root rule
642
- if (!occupied && blocklet.meta.group !== BlockletGroup.gateway) {
643
- rules.push(rule);
644
- }
645
-
646
664
  return rules;
647
665
  }
648
666
  }
@@ -1625,6 +1625,19 @@ const checkDuplicateAppSk = async ({ did, states }) => {
1625
1625
  }
1626
1626
  };
1627
1627
 
1628
+ const checkDuplicateMountPoint = (blocklet, mountPoint) => {
1629
+ const err = new Error(`cannot add duplicate mount point, ${mountPoint || '/'} already exist`);
1630
+ if (normalizePathPrefix(blocklet.mountPoint) === normalizePathPrefix(mountPoint)) {
1631
+ throw err;
1632
+ }
1633
+
1634
+ for (const component of blocklet.children || []) {
1635
+ if (normalizePathPrefix(component.mountPoint) === normalizePathPrefix(mountPoint)) {
1636
+ throw err;
1637
+ }
1638
+ }
1639
+ };
1640
+
1628
1641
  module.exports = {
1629
1642
  consumeServerlessNFT,
1630
1643
  forEachBlocklet,
@@ -1670,4 +1683,5 @@ module.exports = {
1670
1683
  createDataArchive,
1671
1684
  validateAppConfig,
1672
1685
  checkDuplicateAppSk,
1686
+ checkDuplicateMountPoint,
1673
1687
  };
@@ -47,7 +47,7 @@ const ruleSchema = {
47
47
  port: Joi.number().label('port').port().when('type', { is: ROUTING_RULE_TYPES.BLOCKLET, then: Joi.required() }),
48
48
  url: Joi.string().label('url').when('type', { is: ROUTING_RULE_TYPES.REDIRECT, then: Joi.required() }),
49
49
  redirectCode: Joi.alternatives()
50
- .try(301, 302)
50
+ .try(301, 302, 307, 308)
51
51
  .label('redirect code')
52
52
  .when('type', { is: ROUTING_RULE_TYPES.REDIRECT, then: Joi.required() }),
53
53
  interfaceName: Joi.string() // root interface
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.61",
6
+ "version": "1.8.62",
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": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.8.61",
23
- "@abtnode/certificate-manager": "1.8.61",
24
- "@abtnode/constant": "1.8.61",
25
- "@abtnode/cron": "1.8.61",
26
- "@abtnode/db": "1.8.61",
27
- "@abtnode/logger": "1.8.61",
28
- "@abtnode/queue": "1.8.61",
29
- "@abtnode/rbac": "1.8.61",
30
- "@abtnode/router-provider": "1.8.61",
31
- "@abtnode/static-server": "1.8.61",
32
- "@abtnode/timemachine": "1.8.61",
33
- "@abtnode/util": "1.8.61",
22
+ "@abtnode/auth": "1.8.62",
23
+ "@abtnode/certificate-manager": "1.8.62",
24
+ "@abtnode/constant": "1.8.62",
25
+ "@abtnode/cron": "1.8.62",
26
+ "@abtnode/db": "1.8.62",
27
+ "@abtnode/logger": "1.8.62",
28
+ "@abtnode/queue": "1.8.62",
29
+ "@abtnode/rbac": "1.8.62",
30
+ "@abtnode/router-provider": "1.8.62",
31
+ "@abtnode/static-server": "1.8.62",
32
+ "@abtnode/timemachine": "1.8.62",
33
+ "@abtnode/util": "1.8.62",
34
34
  "@arcblock/did": "1.18.36",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
36
  "@arcblock/did-util": "1.18.36",
@@ -38,9 +38,9 @@
38
38
  "@arcblock/jwt": "^1.18.36",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
40
  "@arcblock/vc": "1.18.36",
41
- "@blocklet/constant": "1.8.61",
42
- "@blocklet/meta": "1.8.61",
43
- "@blocklet/sdk": "1.8.61",
41
+ "@blocklet/constant": "1.8.62",
42
+ "@blocklet/meta": "1.8.62",
43
+ "@blocklet/sdk": "1.8.62",
44
44
  "@fidm/x509": "^1.2.1",
45
45
  "@ocap/mcrypto": "1.18.36",
46
46
  "@ocap/util": "1.18.36",
@@ -85,5 +85,5 @@
85
85
  "express": "^4.18.2",
86
86
  "jest": "^27.5.1"
87
87
  },
88
- "gitHead": "f68ac14c2074400d392e2171d328f12dbd2e64cb"
88
+ "gitHead": "ea6ab48149eb9e1157ef37ab1505fa36a9ce598f"
89
89
  }