@abtnode/core 1.8.63 → 1.8.64-beta-b3d407e0

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/event.js CHANGED
@@ -238,7 +238,11 @@ module.exports = ({
238
238
  logger.info('take snapshot after updated blocklet app', { event: eventName, did: blocklet.meta.did, hash });
239
239
  }
240
240
 
241
- if (blocklet.status && !isBeforeInstalled(blocklet.status)) {
241
+ if (
242
+ ![BlockletEvents.removed, BlockletEvents.dataCleaned].includes(eventName) &&
243
+ blocklet.status &&
244
+ !isBeforeInstalled(blocklet.status)
245
+ ) {
242
246
  try {
243
247
  await blockletManager.runtimeMonitor.monit(blocklet.meta.did);
244
248
  } catch (error) {
@@ -14,6 +14,7 @@ const getTmpDir = require('@abtnode/util/lib/get-tmp-directory');
14
14
  const downloadFile = require('@abtnode/util/lib/download-file');
15
15
  const { updateBlockletDocument } = require('@abtnode/util/lib/did-document');
16
16
  const getBlockletInfo = require('@blocklet/meta/lib/info');
17
+ const { forEachBlocklet } = require('@blocklet/meta/lib/util');
17
18
  const {
18
19
  DOMAIN_FOR_DEFAULT_SITE,
19
20
  DOMAIN_FOR_IP_SITE_REGEXP,
@@ -768,47 +769,77 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
768
769
  return false;
769
770
  }
770
771
 
771
- const tasks = (blocklet.meta.interfaces || [])
772
- .filter((x) => x.type === BLOCKLET_INTERFACE_TYPE_WELLKNOWN)
773
- .map(async (x) => {
774
- const pathPrefix = normalizePathPrefix(x.prefix);
775
- if (!pathPrefix.startsWith(WELLKNOWN_PATH_PREFIX)) {
776
- throw new Error(`Wellknown path prefix must start with: ${WELLKNOWN_PATH_PREFIX}`);
777
- }
772
+ /**
773
+ * 1. component blocklet 不允许有相同多的 wellknown
774
+ * 1. wellknown 可以访问的路由:
775
+ * /.well-known/xxx
776
+ * /{wellknown owner blocklet}/.well-known/xxx
777
+ */
778
778
 
779
- const port = findInterfacePortByName(blocklet, x.name);
780
- const existedRule = hasRuleByPrefix(wellknownSite, pathPrefix);
779
+ const isWellknownInterface = (x) => x.type === BLOCKLET_INTERFACE_TYPE_WELLKNOWN;
781
780
 
782
- const rule = {
783
- from: { pathPrefix },
784
- to: {
785
- did: blocklet.meta.did,
786
- port,
787
- type: ROUTING_RULE_TYPES.GENERAL_PROXY,
788
- interfaceName: x.name,
789
- },
790
- isProtected: true,
791
- };
781
+ const handler = async (tmpBlocklet, tmpInterface, mountPoint) => {
782
+ let pathPrefix = normalizePathPrefix(tmpInterface.prefix);
783
+ if (!pathPrefix.startsWith(WELLKNOWN_PATH_PREFIX)) {
784
+ throw new Error(`Wellknown path prefix must start with: ${WELLKNOWN_PATH_PREFIX}`);
785
+ }
792
786
 
793
- if (!existedRule) {
794
- await routerManager.addRoutingRule({ id: wellknownSite.id, rule, skipCheckDynamicBlacklist: true }, context);
795
- return true;
796
- }
787
+ const tmpMountPoint = mountPoint || tmpBlocklet.mountPoint;
788
+ if (tmpMountPoint) {
789
+ pathPrefix = joinUrl(tmpMountPoint, pathPrefix);
790
+ }
797
791
 
798
- // 兼容代码,旧的 rule 没有 to.did 字段
799
- if (port !== existedRule.to.port || existedRule.to.did !== blocklet.meta.did) {
800
- existedRule.to = rule.to;
792
+ const port = findInterfacePortByName(tmpBlocklet, tmpInterface.name);
793
+ const existedRule = hasRuleByPrefix(wellknownSite, pathPrefix);
801
794
 
802
- await routerManager.updateRoutingRule(
803
- { id: wellknownSite.id, rule: existedRule, skipProtectedRuleChecking: true },
804
- context
805
- );
795
+ const rule = {
796
+ from: { pathPrefix },
797
+ to: {
798
+ did: tmpBlocklet.meta.did,
799
+ port,
800
+ type: ROUTING_RULE_TYPES.GENERAL_PROXY,
801
+ interfaceName: tmpInterface.name,
802
+ },
803
+ isProtected: true,
804
+ };
806
805
 
807
- return true;
808
- }
806
+ if (!existedRule) {
807
+ await routerManager.addRoutingRule({ id: wellknownSite.id, rule, skipCheckDynamicBlacklist: true }, context);
808
+ return true;
809
+ }
809
810
 
810
- return false;
811
- });
811
+ // 兼容代码,旧的 rule 没有 to.did 字段
812
+ if (port !== existedRule.to.port || existedRule.to.did !== tmpBlocklet.meta.did) {
813
+ existedRule.to = rule.to;
814
+
815
+ await routerManager.updateRoutingRule(
816
+ { id: wellknownSite.id, rule: existedRule, skipProtectedRuleChecking: true },
817
+ context
818
+ );
819
+
820
+ return true;
821
+ }
822
+
823
+ return false;
824
+ };
825
+
826
+ const tasks = [];
827
+
828
+ forEachBlocklet(
829
+ blocklet,
830
+ (b) => {
831
+ (b.meta.interfaces || []).forEach((item) => {
832
+ if (isWellknownInterface(item)) {
833
+ tasks.push(handler(b, item));
834
+
835
+ if (!b.mountPoint || b.mountPoint !== '/') {
836
+ tasks.push(handler(b, item, '/')); // 在站点的根路由下挂载一个
837
+ }
838
+ }
839
+ });
840
+ },
841
+ { sync: true }
842
+ );
812
843
 
813
844
  const changes = await Promise.all(tasks);
814
845
  return changes.some(Boolean);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.63",
6
+ "version": "1.8.64-beta-b3d407e0",
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.63",
23
- "@abtnode/certificate-manager": "1.8.63",
24
- "@abtnode/constant": "1.8.63",
25
- "@abtnode/cron": "1.8.63",
26
- "@abtnode/db": "1.8.63",
27
- "@abtnode/logger": "1.8.63",
28
- "@abtnode/queue": "1.8.63",
29
- "@abtnode/rbac": "1.8.63",
30
- "@abtnode/router-provider": "1.8.63",
31
- "@abtnode/static-server": "1.8.63",
32
- "@abtnode/timemachine": "1.8.63",
33
- "@abtnode/util": "1.8.63",
22
+ "@abtnode/auth": "1.8.64-beta-b3d407e0",
23
+ "@abtnode/certificate-manager": "1.8.64-beta-b3d407e0",
24
+ "@abtnode/constant": "1.8.64-beta-b3d407e0",
25
+ "@abtnode/cron": "1.8.64-beta-b3d407e0",
26
+ "@abtnode/db": "1.8.64-beta-b3d407e0",
27
+ "@abtnode/logger": "1.8.64-beta-b3d407e0",
28
+ "@abtnode/queue": "1.8.64-beta-b3d407e0",
29
+ "@abtnode/rbac": "1.8.64-beta-b3d407e0",
30
+ "@abtnode/router-provider": "1.8.64-beta-b3d407e0",
31
+ "@abtnode/static-server": "1.8.64-beta-b3d407e0",
32
+ "@abtnode/timemachine": "1.8.64-beta-b3d407e0",
33
+ "@abtnode/util": "1.8.64-beta-b3d407e0",
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.63",
42
- "@blocklet/meta": "1.8.63",
43
- "@blocklet/sdk": "1.8.63",
41
+ "@blocklet/constant": "1.8.64-beta-b3d407e0",
42
+ "@blocklet/meta": "1.8.64-beta-b3d407e0",
43
+ "@blocklet/sdk": "1.8.64-beta-b3d407e0",
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": "69c7bf7f79fbabc8718d8ec0c6fb36ce9477cfd8"
88
+ "gitHead": "e076a9cab4c15cfafb82d0aef9a66dd1b825ec75"
89
89
  }