@abtnode/core 1.6.22 → 1.6.23

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.
@@ -92,6 +92,7 @@ const {
92
92
  needBlockletDownload,
93
93
  verifyPurchase,
94
94
  } = require('../../util/blocklet');
95
+ const { parseSourceUrl } = require('../../util/registry');
95
96
  const states = require('../../states');
96
97
  const BlockletRegistry = require('../registry');
97
98
  const BaseBlockletManager = require('./base');
@@ -673,7 +674,7 @@ class BlockletManager extends BaseBlockletManager {
673
674
  /**
674
675
  * upgrade blocklet from registry
675
676
  */
676
- async upgrade({ did, registryUrl }, context) {
677
+ async upgrade({ did, registryUrl, sync }, context) {
677
678
  const blocklet = await states.blocklet.getBlocklet(did);
678
679
 
679
680
  // TODO: 查看了下目前页面中的升级按钮,都是会传 registryUrl 过来的,这个函数里的逻辑感觉需要在以后做一个简化
@@ -740,6 +741,7 @@ class BlockletManager extends BaseBlockletManager {
740
741
  source: BlockletSource.registry,
741
742
  deployedFrom: upgradeFromRegistry,
742
743
  context,
744
+ sync,
743
745
  });
744
746
  }
745
747
 
@@ -920,7 +922,6 @@ class BlockletManager extends BaseBlockletManager {
920
922
  }
921
923
 
922
924
  const { did, version } = meta;
923
- meta.title = `[DEV] ${meta.title || meta.name}`;
924
925
 
925
926
  const exist = await states.blocklet.getBlocklet(did);
926
927
  if (exist) {
@@ -1379,7 +1380,7 @@ class BlockletManager extends BaseBlockletManager {
1379
1380
  }
1380
1381
  }
1381
1382
 
1382
- async _installFromStore({ did, registry }, context) {
1383
+ async _installFromStore({ did, registry, sync }, context) {
1383
1384
  logger.debug('start install blocklet', { did });
1384
1385
  if (!isValidDid(did)) {
1385
1386
  throw new Error('Blocklet did is invalid');
@@ -1404,6 +1405,7 @@ class BlockletManager extends BaseBlockletManager {
1404
1405
  meta,
1405
1406
  source: BlockletSource.registry,
1406
1407
  deployedFrom: info.cdnUrl || registryUrl,
1408
+ sync,
1407
1409
  context,
1408
1410
  });
1409
1411
  }
@@ -1411,6 +1413,16 @@ class BlockletManager extends BaseBlockletManager {
1411
1413
  async _installFromUrl({ url, sync }, context) {
1412
1414
  logger.debug('start install blocklet', { url });
1413
1415
 
1416
+ const { inStore, registryUrl, blockletDid } = await parseSourceUrl(url);
1417
+ if (inStore) {
1418
+ const exist = await states.blocklet.getBlocklet(blockletDid);
1419
+ if (exist) {
1420
+ return this.upgrade({ did: blockletDid, registryUrl }, context);
1421
+ }
1422
+
1423
+ return this._installFromStore({ did: blockletDid, registry: registryUrl }, context);
1424
+ }
1425
+
1414
1426
  const meta = await getBlockletMetaFromUrl(url);
1415
1427
 
1416
1428
  if (!meta) {
@@ -1,9 +1,7 @@
1
- const isBase64 = require('is-base64');
2
1
  const { BlockletGroup } = require('@blocklet/meta/lib/constants');
3
2
  const joinURL = require('url-join');
4
3
  const get = require('lodash/get');
5
- const pick = require('lodash/pick');
6
- const { BLOCKLET_STORE_API_PREFIX, BLOCKLET_STORE_META_PATH } = require('@abtnode/constant');
4
+ const { BLOCKLET_STORE_API_PREFIX } = require('@abtnode/constant');
7
5
 
8
6
  const { name } = require('../../package.json');
9
7
 
@@ -15,6 +13,7 @@ const states = require('../states');
15
13
  const isRequirementsSatisfied = require('../util/requirement');
16
14
  const { fixAndVerifyBlockletMeta } = require('../util/blocklet');
17
15
  const { translate } = require('../locales');
16
+ const { validateRegistryURL, getRegistryMeta } = require('../util/registry');
18
17
 
19
18
  const DEFAULT_REFRESH_INTERVAL = 1 * 60 * 1000;
20
19
  const MAX_REFRESH_INTERVAL = 1 * 60 * 1000;
@@ -152,54 +151,8 @@ class BlockletRegistry {
152
151
  }
153
152
  }
154
153
 
155
- BlockletRegistry.validateRegistryURL = async (registry) => {
156
- const url = joinURL(registry, BLOCKLET_STORE_API_PREFIX, `/blocklets.json?__t__=${Date.now()}`);
157
- try {
158
- const res = await request.get(url);
159
- if (Array.isArray(res.data)) {
160
- return res.data;
161
- }
162
-
163
- logger.error('Blocklet list fetch failed ', { url, data: res.data });
164
- throw new Error('blocklet list fetch failed');
165
- } catch (error) {
166
- logger.error('Blocklet registry refresh failed', { url, error });
167
- throw new Error(`Invalid Blocklet Registry URL ${registry}: ${error.message}`);
168
- }
169
- };
170
-
171
- BlockletRegistry.getRegistryMeta = async (registry) => {
172
- try {
173
- const url = joinURL(registry, BLOCKLET_STORE_META_PATH, `?__t__=${Date.now()}`);
174
- const { data } = await request.get(url);
175
-
176
- if (!data) {
177
- return {};
178
- }
154
+ BlockletRegistry.validateRegistryURL = validateRegistryURL;
179
155
 
180
- const requiredFields = ['name', 'description', 'maintainer'];
181
-
182
- const missingFields = requiredFields.filter((x) => !data[x]);
183
- if (missingFields.length > 0) {
184
- throw new Error(`the registry missing required information: ${missingFields.join(', ')}`);
185
- }
186
-
187
- const result = pick(data, ['id', 'name', 'description', 'maintainer', 'cdnUrl', 'chainHost']);
188
- const { logoUrl } = data;
189
- if (logoUrl) {
190
- if (logoUrl.startsWith('http') === true) {
191
- result.logoUrl = logoUrl;
192
- } else if (isBase64(logoUrl, { allowMime: true })) {
193
- result.logoUrl = logoUrl;
194
- } else {
195
- result.logoUrl = joinURL(registry, logoUrl);
196
- }
197
- }
198
-
199
- return result;
200
- } catch (err) {
201
- throw new Error(`Can not get meta info for registry [${registry}]: ${err.message}`);
202
- }
203
- };
156
+ BlockletRegistry.getRegistryMeta = getRegistryMeta;
204
157
 
205
158
  module.exports = BlockletRegistry;
@@ -9,6 +9,7 @@ const detectPort = require('detect-port');
9
9
  const Lock = require('@abtnode/util/lib/lock');
10
10
  const security = require('@abtnode/util/lib/security');
11
11
  const { fixPerson, fixInterfaces } = require('@blocklet/meta/lib/fix');
12
+ const { getDisplayName } = require('@blocklet/meta/lib/util');
12
13
  const {
13
14
  BlockletStatus,
14
15
  BlockletSource,
@@ -25,6 +26,7 @@ const { validateBlockletMeta } = require('../util');
25
26
 
26
27
  const lock = new Lock('blocklet-port-assign-lock');
27
28
 
29
+ const isHex = (str) => /^0x[0-9a-f]+$/i.test(str);
28
30
  const getMaxPort = (ports = {}) => Math.max(Object.values(ports).map(Number));
29
31
 
30
32
  const getExternalPortsFromMeta = (meta) =>
@@ -50,10 +52,10 @@ const formatBlocklet = (blocklet, phase, dek) => {
50
52
  if (!env) {
51
53
  return;
52
54
  }
53
- if (phase === 'onUpdate' && env.value.indexOf('0x') === 0) {
55
+ if (phase === 'onUpdate' && isHex(env.value) === true) {
54
56
  env.value = security.encrypt(env.value, b.meta.did, dek);
55
57
  }
56
- if (phase === 'onRead' && env.value.indexOf('0x') === -1) {
58
+ if (phase === 'onRead' && isHex(env.value) === false) {
57
59
  env.value = security.decrypt(env.value, b.meta.did, dek);
58
60
  }
59
61
  });
@@ -243,20 +245,17 @@ class BlockletState extends BaseState {
243
245
  await this.fillChildrenPorts(children, { oldChildren: doc.children, defaultPort: getMaxPort(ports) });
244
246
 
245
247
  // add to db
246
- const newDoc = await this.updateById(doc._id, {
247
- $set: {
248
- meta: omit(sanitized, ['htmlAst']),
249
- source,
250
- deployedFrom,
251
- children,
252
- ports,
253
- },
248
+ const newDoc = await this.updateBlocklet(meta.did, {
249
+ meta: omit(sanitized, ['htmlAst']),
250
+ source,
251
+ deployedFrom,
252
+ children,
253
+ ports,
254
254
  });
255
255
  lock.release();
256
256
 
257
- const formatted = formatBlocklet(newDoc, 'onRead', this.options.dek);
258
- this.emit('upgrade', formatted);
259
- resolve(formatted);
257
+ this.emit('upgrade', newDoc);
258
+ resolve(newDoc);
260
259
  } catch (err) {
261
260
  lock.release();
262
261
  reject(err);
@@ -446,8 +445,7 @@ class BlockletState extends BaseState {
446
445
  return child;
447
446
  });
448
447
 
449
- await this.update(doc._id, { $set: updates });
450
- return formatBlocklet({ ...doc, ...updates }, 'onRead', this.options.dek);
448
+ return this.updateBlocklet(did, updates);
451
449
  }
452
450
 
453
451
  async fillChildrenPorts(children, { defaultPort = 0, oldChildren } = {}) {
@@ -511,7 +509,7 @@ class BlockletState extends BaseState {
511
509
  const { meta, mountPoint, sourceUrl = '', source = '', deployedFrom = '' } = child;
512
510
 
513
511
  if (!mountPoint) {
514
- throw new Error(`mountPoint is required when adding component ${meta.title || meta.name}`);
512
+ throw new Error(`mountPoint is required when adding component ${getDisplayName(child, true)}`);
515
513
  }
516
514
 
517
515
  if (meta.did === parent.meta.did) {
@@ -542,5 +540,6 @@ class BlockletState extends BaseState {
542
540
  }
543
541
 
544
542
  BlockletState.BlockletStatus = BlockletStatus;
543
+ BlockletState.formatBlocklet = formatBlocklet;
545
544
 
546
545
  module.exports = BlockletState;
@@ -42,7 +42,7 @@ const validateBlockletEntry = require('@blocklet/meta/lib/entry');
42
42
  const getBlockletEngine = require('@blocklet/meta/lib/engine');
43
43
  const getBlockletInfo = require('@blocklet/meta/lib/info');
44
44
  const { validateMeta, fixAndValidateService } = require('@blocklet/meta/lib/validate');
45
- const { forEachBlocklet, isFreeBlocklet } = require('@blocklet/meta/lib/util');
45
+ const { forEachBlocklet, isFreeBlocklet, getDisplayName } = require('@blocklet/meta/lib/util');
46
46
 
47
47
  const { validate: validateEngine, get: getEngine } = require('../blocklet/manager/engine');
48
48
 
@@ -1069,7 +1069,7 @@ const checkDuplicateComponents = (dynamicComponents, staticComponents) => {
1069
1069
  if (duplicates.length) {
1070
1070
  throw new Error(
1071
1071
  `Cannot add duplicate component${duplicates.length > 1 ? 's' : ''}: ${duplicates
1072
- .map((x) => x.meta.title || x.meta.name)
1072
+ .map((x) => getDisplayName(x, true))
1073
1073
  .join(', ')}`
1074
1074
  );
1075
1075
  }
@@ -1,5 +1,6 @@
1
1
  const slugify = require('slugify');
2
2
  const { DEFAULT_IP_DNS_DOMAIN_SUFFIX } = require('@abtnode/constant');
3
+ const md5 = require('@abtnode/util/lib/md5');
3
4
 
4
5
  const SLOT_FOR_IP_DNS_SITE = '888-888-888-888';
5
6
 
@@ -17,7 +18,9 @@ const getIpDnsDomainForBlocklet = (blocklet, blockletInterface) => {
17
18
  };
18
19
 
19
20
  const getDidDomainForBlocklet = ({ name, daemonDid, didDomain }) => {
20
- return `${formatName(name)}-${daemonDid.toLowerCase()}.${didDomain}`;
21
+ const prefix = md5(name).substring(0, 8);
22
+
23
+ return `${prefix}-${daemonDid.toLowerCase()}.${didDomain}`;
21
24
  };
22
25
 
23
26
  module.exports = { getIpDnsDomainForBlocklet, getDidDomainForBlocklet };
@@ -0,0 +1,90 @@
1
+ const joinURL = require('url-join');
2
+ const pick = require('lodash/pick');
3
+ const isBase64 = require('is-base64');
4
+
5
+ const { BLOCKLET_STORE_API_PREFIX, BLOCKLET_STORE_META_PATH } = require('@abtnode/constant');
6
+
7
+ const { name } = require('../../package.json');
8
+ const logger = require('@abtnode/logger')(`${name}:util:registry`); // eslint-disable-line
9
+
10
+ const request = require('./request');
11
+
12
+ const validateRegistryURL = async (registry) => {
13
+ const url = joinURL(registry, BLOCKLET_STORE_API_PREFIX, `/blocklets.json?__t__=${Date.now()}`);
14
+ try {
15
+ const res = await request.get(url);
16
+ if (Array.isArray(res.data)) {
17
+ return res.data;
18
+ }
19
+
20
+ logger.error('Blocklet list fetch failed ', { url, data: res.data });
21
+ throw new Error('blocklet list fetch failed');
22
+ } catch (error) {
23
+ logger.error('Blocklet registry refresh failed', { url, error });
24
+ throw new Error(`Invalid Blocklet Registry URL ${registry}: ${error.message}`);
25
+ }
26
+ };
27
+
28
+ const getRegistryMeta = async (registry) => {
29
+ try {
30
+ const url = joinURL(registry, BLOCKLET_STORE_META_PATH, `?__t__=${Date.now()}`);
31
+ const { data } = await request.get(url);
32
+
33
+ if (!data) {
34
+ return {};
35
+ }
36
+
37
+ const requiredFields = ['name', 'description', 'maintainer'];
38
+
39
+ const missingFields = requiredFields.filter((x) => !data[x]);
40
+ if (missingFields.length > 0) {
41
+ throw new Error(`the registry missing required information: ${missingFields.join(', ')}`);
42
+ }
43
+
44
+ const result = pick(data, ['id', 'name', 'description', 'maintainer', 'cdnUrl', 'chainHost']);
45
+ const { logoUrl } = data;
46
+ if (logoUrl) {
47
+ if (logoUrl.startsWith('http') === true) {
48
+ result.logoUrl = logoUrl;
49
+ } else if (isBase64(logoUrl, { allowMime: true })) {
50
+ result.logoUrl = logoUrl;
51
+ } else {
52
+ result.logoUrl = joinURL(registry, logoUrl);
53
+ }
54
+ }
55
+
56
+ return result;
57
+ } catch (err) {
58
+ throw new Error(`Can not get meta info for registry [${registry}]: ${err.message}`);
59
+ }
60
+ };
61
+
62
+ const parseSourceUrl = async (url) => {
63
+ const { origin, pathname } = new URL(url);
64
+
65
+ const match = pathname.match(/^\/api\/blocklets\/(\w*)\/blocklet\.json/);
66
+ if (match) {
67
+ try {
68
+ const m = await getRegistryMeta(origin);
69
+ if (m && m.id) {
70
+ return {
71
+ inStore: true,
72
+ registryUrl: origin,
73
+ blockletDid: match[1],
74
+ };
75
+ }
76
+ } catch {
77
+ // meat is not in store, do nothing
78
+ }
79
+ }
80
+
81
+ return {
82
+ inStore: false,
83
+ };
84
+ };
85
+
86
+ module.exports = {
87
+ validateRegistryURL,
88
+ getRegistryMeta,
89
+ parseSourceUrl,
90
+ };
@@ -1,30 +1,15 @@
1
1
  const fs = require('fs-extra');
2
- const { NODE_SERVICES } = require('@abtnode/constant');
3
-
4
- const servicesNames = Object.values(NODE_SERVICES);
5
2
 
6
3
  const getServices = ({ stringifySchema = false } = {}) =>
7
- servicesNames
4
+ ['auth']
8
5
  .map((x) => {
9
- const service = {};
10
-
11
- // Read service meta
12
- try {
13
- const packageFile = require.resolve(`${x}/package.json`);
14
- const { name, description, version } = fs.readJSONSync(packageFile);
15
- service.name = name;
16
- service.description = description || name;
17
- service.version = version;
18
- } catch (err) {
19
- return null;
20
- }
6
+ let service;
21
7
 
22
- // Read service config: optional
23
8
  try {
24
- const schemaFile = require.resolve(`${x}/api/schema.json`);
25
- service.schema = fs.readJSONSync(schemaFile);
9
+ const metaFile = require.resolve(`@abtnode/blocklet-services/services/${x}/meta.json`);
10
+ service = fs.readJSONSync(metaFile);
26
11
  } catch (err) {
27
- service.schema = {};
12
+ service = {};
28
13
  }
29
14
 
30
15
  if (stringifySchema) {
@@ -64,7 +64,7 @@ module.exports = ({ events, dataDirs, instance }) => {
64
64
  const webhookList = await webhookState.list();
65
65
  const nodeInfo = await nodeState.read();
66
66
  const { internal, external } = await IP.get();
67
- const baseUrls = await getBaseUrls(instance, [internal, external]);
67
+ const baseUrls = await getBaseUrls(instance, [external, internal]);
68
68
  const senderFns = {};
69
69
 
70
70
  if (webhookList.length) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.22",
6
+ "version": "1.6.23",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,28 +19,28 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/certificate-manager": "1.6.22",
23
- "@abtnode/constant": "1.6.22",
24
- "@abtnode/cron": "1.6.22",
25
- "@abtnode/db": "1.6.22",
26
- "@abtnode/logger": "1.6.22",
27
- "@abtnode/queue": "1.6.22",
28
- "@abtnode/rbac": "1.6.22",
29
- "@abtnode/router-provider": "1.6.22",
30
- "@abtnode/static-server": "1.6.22",
31
- "@abtnode/timemachine": "1.6.22",
32
- "@abtnode/util": "1.6.22",
33
- "@arcblock/did": "^1.14.16",
34
- "@arcblock/event-hub": "1.14.16",
22
+ "@abtnode/certificate-manager": "1.6.23",
23
+ "@abtnode/constant": "1.6.23",
24
+ "@abtnode/cron": "1.6.23",
25
+ "@abtnode/db": "1.6.23",
26
+ "@abtnode/logger": "1.6.23",
27
+ "@abtnode/queue": "1.6.23",
28
+ "@abtnode/rbac": "1.6.23",
29
+ "@abtnode/router-provider": "1.6.23",
30
+ "@abtnode/static-server": "1.6.23",
31
+ "@abtnode/timemachine": "1.6.23",
32
+ "@abtnode/util": "1.6.23",
33
+ "@arcblock/did": "^1.14.19",
34
+ "@arcblock/event-hub": "1.14.19",
35
35
  "@arcblock/pm2-events": "^0.0.5",
36
- "@arcblock/vc": "^1.14.16",
37
- "@blocklet/meta": "1.6.22",
36
+ "@arcblock/vc": "^1.14.19",
37
+ "@blocklet/meta": "1.6.23",
38
38
  "@fidm/x509": "^1.2.1",
39
39
  "@nedb/core": "^1.2.2",
40
40
  "@nedb/multi": "^1.2.2",
41
- "@ocap/mcrypto": "^1.14.16",
42
- "@ocap/util": "^1.14.16",
43
- "@ocap/wallet": "^1.14.16",
41
+ "@ocap/mcrypto": "^1.14.19",
42
+ "@ocap/util": "^1.14.19",
43
+ "@ocap/wallet": "^1.14.19",
44
44
  "@slack/webhook": "^5.0.3",
45
45
  "axios": "^0.25.0",
46
46
  "axon": "^2.0.3",
@@ -75,5 +75,5 @@
75
75
  "express": "^4.17.1",
76
76
  "jest": "^27.4.5"
77
77
  },
78
- "gitHead": "18ac52a439dbd04e4ace98d796b6de517503fb14"
78
+ "gitHead": "6c478fb7e2a30b302981b5339f349c69134e022e"
79
79
  }