@abtnode/core 1.6.30 → 1.7.1

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
@@ -1,7 +1,7 @@
1
1
  const { EventEmitter } = require('events');
2
2
  const pick = require('lodash/pick');
3
3
  const logger = require('@abtnode/logger')('@abtnode/core:api:team');
4
- const { ROLES, genPermissionName, EVENTS } = require('@abtnode/constant');
4
+ const { ROLES, genPermissionName, EVENTS, WHO_CAN_ACCESS } = require('@abtnode/constant');
5
5
  const { isValid: isValidDid } = require('@arcblock/did');
6
6
  const { BlockletEvents } = require('@blocklet/meta/lib/constants');
7
7
  const { validateTrustedPassportIssuers } = require('../validators/trusted-passport');
@@ -454,6 +454,14 @@ class TeamAPI extends EventEmitter {
454
454
  }
455
455
  }
456
456
 
457
+ async configWhoCanAccess({ teamDid, value }) {
458
+ if (!Object.values(WHO_CAN_ACCESS).includes(value)) {
459
+ throw new Error('value is invalid');
460
+ }
461
+
462
+ await this.teamManager.configWhoCanAccess(teamDid, value);
463
+ }
464
+
457
465
  // Access Control
458
466
 
459
467
  async getRoles({ teamDid }) {
@@ -34,6 +34,7 @@ const validateBlockletEntry = require('@blocklet/meta/lib/entry');
34
34
  const toBlockletDid = require('@blocklet/meta/lib/did');
35
35
  const { validateMeta } = require('@blocklet/meta/lib/validate');
36
36
  const { update: updateMetaFile } = require('@blocklet/meta/lib/file');
37
+ const { titleSchema, descriptionSchema } = require('@blocklet/meta/lib/schema');
37
38
 
38
39
  const {
39
40
  BlockletStatus,
@@ -252,8 +253,9 @@ class BlockletManager extends BaseBlockletManager {
252
253
  }
253
254
 
254
255
  const blocklet = await states.blocklet.getBlocklet(meta.did);
256
+ const isRunning = blocklet?.status === BlockletStatus.running;
255
257
 
256
- return { meta, isFree, isInstalled: !!blocklet };
258
+ return { meta, isFree, isInstalled: !!blocklet, isRunning };
257
259
  }
258
260
 
259
261
  async installBlockletFromVc({ vcPresentation, challenge }, context) {
@@ -622,6 +624,14 @@ class BlockletManager extends BaseBlockletManager {
622
624
  }
623
625
  }
624
626
 
627
+ if (x.key === 'BLOCKLET_APP_NAME') {
628
+ x.value = await titleSchema.validateAsync(x.value);
629
+ }
630
+
631
+ if (x.key === 'BLOCKLET_APP_DESCRIPTION') {
632
+ x.value = await descriptionSchema.validateAsync(x.value);
633
+ }
634
+
625
635
  if (x.key === 'BLOCKLET_WALLET_TYPE') {
626
636
  if (['default', 'eth'].includes(x.value) === false) {
627
637
  throw new Error('Invalid blocklet wallet type, only "default" and "eth" are supported');
@@ -997,13 +1007,14 @@ class BlockletManager extends BaseBlockletManager {
997
1007
  }),
998
1008
  };
999
1009
 
1000
- const configs = await states.blockletExtras.getConfigs(did);
1010
+ const configs = await states.blockletExtras.getConfigs(blocklet.meta.did);
1001
1011
  fillBlockletConfigs(blocklet, configs);
1002
1012
 
1003
1013
  // merge settings to blocklet
1004
- const settings = await states.blockletExtras.getSettings(did);
1014
+ const settings = await states.blockletExtras.getSettings(blocklet.meta.did);
1005
1015
  blocklet.trustedPassports = get(settings, 'trustedPassports') || [];
1006
1016
  blocklet.enablePassportIssuance = get(settings, 'enablePassportIssuance', true);
1017
+ blocklet.settings = settings || {};
1007
1018
 
1008
1019
  // handle child env
1009
1020
  for (const child of blocklet.children) {
@@ -1026,13 +1037,25 @@ class BlockletManager extends BaseBlockletManager {
1026
1037
  }),
1027
1038
  };
1028
1039
 
1029
- const childConfigs = await states.blockletExtras.getChildConfigs(did, childDid);
1040
+ const childConfigs = await states.blockletExtras.getChildConfigs(blocklet.meta.did, childDid);
1030
1041
  fillBlockletConfigs(child, childConfigs, blocklet);
1031
1042
  }
1032
1043
 
1044
+ // site
1045
+ blocklet.site = await this.getSiteByDid(blocklet.meta.did);
1046
+
1033
1047
  return blocklet;
1034
1048
  }
1035
1049
 
1050
+ async setInitialized({ did }) {
1051
+ const blocklet = await states.blocklet.getBlocklet(did);
1052
+ await states.blockletExtras.setSettings(blocklet.meta.did, { initialized: true });
1053
+
1054
+ this.emit(BlockletEvents.updated, { meta: { did: blocklet.meta.did } });
1055
+
1056
+ return this.ensureBlocklet(did);
1057
+ }
1058
+
1036
1059
  async status(did, { forceSync = false } = {}) {
1037
1060
  const fastReturnOnForceSync = async (blocklet = {}) => {
1038
1061
  const { status } = blocklet;
@@ -1594,7 +1617,7 @@ class BlockletManager extends BaseBlockletManager {
1594
1617
  const newBlocklet = await states.blocklet.getBlocklet(did);
1595
1618
  newBlocklet.meta = meta;
1596
1619
  newBlocklet.source = BlockletSource.upload;
1597
- newBlocklet.deployedFrom = `Upload by ${context.user.did}`;
1620
+ newBlocklet.deployedFrom = `Upload by ${context.user.fullName}`;
1598
1621
  newBlocklet.children = await this._getChildren(meta);
1599
1622
  await validateBlocklet(newBlocklet);
1600
1623
  await this._downloadBlocklet(newBlocklet, oldBlocklet);
@@ -1620,7 +1643,7 @@ class BlockletManager extends BaseBlockletManager {
1620
1643
  const newBlocklet = await states.blocklet.getBlocklet(meta.did);
1621
1644
  newBlocklet.meta = meta;
1622
1645
  newBlocklet.source = BlockletSource.upload;
1623
- newBlocklet.deployedFrom = `Upload by ${context.user.did}`;
1646
+ newBlocklet.deployedFrom = `Upload by ${context.user.fullName}`;
1624
1647
  newBlocklet.children = await this._getChildren(meta);
1625
1648
 
1626
1649
  await validateBlocklet(newBlocklet);
@@ -1639,7 +1662,7 @@ class BlockletManager extends BaseBlockletManager {
1639
1662
  did: meta.did,
1640
1663
  meta,
1641
1664
  source: BlockletSource.upload,
1642
- deployedFrom: `Upload by ${context.user.did}`,
1665
+ deployedFrom: `Upload by ${context.user.fullName}`,
1643
1666
  children,
1644
1667
  });
1645
1668
 
package/lib/cert.js CHANGED
@@ -37,6 +37,14 @@ const onCertIssued = (cert) => {
37
37
  });
38
38
  };
39
39
 
40
+ const getDomainFromInput = (input) => {
41
+ if (Object.prototype.toString.call(input) === '[object Object]') {
42
+ return input.domain;
43
+ }
44
+
45
+ return input;
46
+ };
47
+
40
48
  class Cert extends EventEmitter {
41
49
  constructor({ maintainerEmail, dataDir }) {
42
50
  super();
@@ -74,7 +82,8 @@ class Cert extends EventEmitter {
74
82
  return this.manager.getNormalByDomain(domain);
75
83
  }
76
84
 
77
- getByDomain(domain) {
85
+ getByDomain(inputDomain) {
86
+ const domain = getDomainFromInput(inputDomain);
78
87
  return this.manager.getByDomain(domain);
79
88
  }
80
89
 
package/lib/index.js CHANGED
@@ -137,6 +137,7 @@ function ABTNode(options) {
137
137
  const {
138
138
  handleRouting,
139
139
  getRoutingRulesByDid,
140
+ getSiteByDid,
140
141
  updateNodeRouting,
141
142
  takeRoutingSnapshot,
142
143
  getRoutingSites,
@@ -157,6 +158,7 @@ function ABTNode(options) {
157
158
  const teamAPI = new TeamAPI({ states, teamManager });
158
159
 
159
160
  blockletManager.getRoutingRulesByDid = getRoutingRulesByDid;
161
+ blockletManager.getSiteByDid = getSiteByDid;
160
162
 
161
163
  // Generate an on node ready callback
162
164
  const onStatesReady = createStateReadyQueue({ states, options, dataDirs });
@@ -226,6 +228,7 @@ function ABTNode(options) {
226
228
  getBlocklet: blockletManager.detail.bind(blockletManager),
227
229
  getBlockletDiff: blockletManager.diff.bind(blockletManager),
228
230
  updateAllBlockletEnvironment: blockletManager.updateAllBlockletEnvironment.bind(blockletManager),
231
+ setBlockletInitialized: blockletManager.setInitialized.bind(blockletManager),
229
232
 
230
233
  // Registry
231
234
  listBlocklets: blockletRegistry.listBlocklets.bind(blockletRegistry),
@@ -295,6 +298,7 @@ function ABTNode(options) {
295
298
  processPassportIssuance: teamAPI.processPassportIssuance.bind(teamAPI),
296
299
  configTrustedPassports: teamAPI.configTrustedPassports.bind(teamAPI),
297
300
  configPassportIssuance: teamAPI.configPassportIssuance.bind(teamAPI),
301
+ configWhoCanAccess: teamAPI.configWhoCanAccess.bind(teamAPI),
298
302
 
299
303
  // Challenge
300
304
  generateChallenge: states.challenge.generate.bind(states.challenge),
@@ -0,0 +1,18 @@
1
+ /* eslint-disable no-continue */
2
+ /* eslint-disable no-await-in-loop */
3
+ /* eslint-disable no-underscore-dangle */
4
+
5
+ module.exports = async ({ states, printInfo }) => {
6
+ printInfo('Try to update blocklet to 1.7.1...');
7
+
8
+ const blockletExtras = await states.blockletExtras.find({});
9
+ for (const extra of blockletExtras) {
10
+ if (!extra) {
11
+ continue;
12
+ }
13
+
14
+ await states.blockletExtras.setSettings(extra.did, { initialized: true });
15
+
16
+ printInfo(`Set initialized: ${extra}`);
17
+ }
18
+ };
@@ -437,6 +437,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
437
437
  certificate,
438
438
  isProtected: true,
439
439
  });
440
+
440
441
  logger.info('dashboard certificate updated');
441
442
  } catch (error) {
442
443
  logger.error('update dashboard certificate failed', { error });
@@ -448,13 +449,14 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
448
449
 
449
450
  const updateCert = async (domain, url) => {
450
451
  try {
451
- const cert = await routerManager.findCertificateByDomain(domain);
452
+ const cert = await certManager.getByDomain(domain);
452
453
  if (!cert) {
453
454
  return;
454
455
  }
455
456
 
456
457
  const now = Date.now();
457
458
  const certInfo = getHttpsCertInfo(cert.certificate);
459
+
458
460
  if (certInfo.validTo - now >= CERTIFICATE_EXPIRES_OFFSET) {
459
461
  logger.info('skip dashboard certificate update before not expired', { domain, url });
460
462
  return;
@@ -1122,6 +1124,12 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
1122
1124
  return rules.filter((rule) => rule.to.did === did);
1123
1125
  }
1124
1126
 
1127
+ async function getSiteByDid(did) {
1128
+ const { sites } = await readRoutingSites();
1129
+ const domain = getBlockletDomainGroupName(did);
1130
+ return (sites || []).find((x) => x.domain === domain);
1131
+ }
1132
+
1125
1133
  const providers = {}; // we need to keep reference for different router instances
1126
1134
  const handleRouting = async (nodeInfo) => {
1127
1135
  const providerName = get(nodeInfo, 'routing.provider', null);
@@ -1372,6 +1380,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
1372
1380
  removeBlockletRouting,
1373
1381
  handleRouting,
1374
1382
  getRoutingRulesByDid,
1383
+ getSiteByDid,
1375
1384
  updateNodeRouting,
1376
1385
  takeRoutingSnapshot,
1377
1386
  getRoutingSites,
@@ -1,3 +1,4 @@
1
+ const get = require('lodash/get');
1
2
  const { fromRandom } = require('@ocap/wallet');
2
3
  const { toBase58 } = require('@ocap/util');
3
4
  const logger = require('@abtnode/logger')('@abtnode/core:access-key');
@@ -15,6 +16,8 @@ const validatePassport = (passport) => {
15
16
  }
16
17
  };
17
18
 
19
+ const getUserName = (context) => get(context, 'user.fullName', '');
20
+
18
21
  class AccessKeyState extends BaseState {
19
22
  constructor(baseDir, options = {}) {
20
23
  super(baseDir, { filename: 'access_key.db', ...options });
@@ -26,7 +29,6 @@ class AccessKeyState extends BaseState {
26
29
  });
27
30
  }
28
31
 
29
- // eslint-disable-next-line no-unused-vars
30
32
  async create(input = {}, context) {
31
33
  const { remark, passport } = input;
32
34
 
@@ -42,6 +44,10 @@ class AccessKeyState extends BaseState {
42
44
  if (remark) {
43
45
  data.remark = remark;
44
46
  }
47
+
48
+ data.createdBy = getUserName(context);
49
+ data.updatedBy = getUserName(context);
50
+
45
51
  const doc = await this.asyncDB.insert(data);
46
52
  return {
47
53
  ...doc,
@@ -84,6 +90,7 @@ class AccessKeyState extends BaseState {
84
90
  doc.remark = remark;
85
91
  }
86
92
  doc.passport = passport;
93
+ doc.updatedBy = getUserName(context);
87
94
 
88
95
  await this.asyncDB.update({ accessKeyId }, { $set: doc });
89
96
  return doc;
@@ -234,6 +234,14 @@ class TeamManager extends EventEmitter {
234
234
  return this.states.blockletExtras.setSettings(did, { trustedPassports });
235
235
  }
236
236
 
237
+ async configWhoCanAccess(did, value) {
238
+ if (this.isNodeTeam(did)) {
239
+ throw new Error('Cannot be node did');
240
+ }
241
+
242
+ return this.states.blockletExtras.setSettings(did, { whoCanAccess: value });
243
+ }
244
+
237
245
  async configPassportIssuance(did, enable) {
238
246
  const enablePassportIssuance = enable;
239
247
  if (this.isNodeTeam(did)) {
@@ -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, getDisplayName } = require('@blocklet/meta/lib/util');
45
+ const { forEachBlocklet, isFreeBlocklet, getDisplayName, findWebInterface } = require('@blocklet/meta/lib/util');
46
46
 
47
47
  const { validate: validateEngine, get: getEngine } = require('../blocklet/manager/engine');
48
48
 
@@ -338,7 +338,7 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, parent) => {
338
338
  const getSharedConfigs = (child, parent) => {
339
339
  const sharedConfigs = {};
340
340
  if (parent && Array.isArray(parent.configs) && child.meta.did !== parent.meta.did) {
341
- const parentKeys = parent.configs.filter((x) => x.secure === false).map((x) => x.key);
341
+ const parentKeys = parent.configs.filter((x) => x.secure === false && x.shared !== false).map((x) => x.key);
342
342
  const childKeys = child.configs.map((x) => x.key);
343
343
  const sharedKeys = intersection(parentKeys, childKeys);
344
344
  sharedKeys.forEach((key) => {
@@ -629,17 +629,6 @@ const reloadProcess = (appId) =>
629
629
  });
630
630
  });
631
631
 
632
- const findWebInterface = (blocklet) => {
633
- const meta = blocklet.meta || blocklet || {};
634
- const { interfaces = [] } = meta;
635
-
636
- if (!Array.isArray(interfaces)) {
637
- return null;
638
- }
639
-
640
- return interfaces.find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
641
- };
642
-
643
632
  /**
644
633
  * this function has side effect on children
645
634
  */
@@ -1,5 +1,5 @@
1
1
  const slugify = require('slugify');
2
- const { DEFAULT_IP_DNS_DOMAIN_SUFFIX } = require('@abtnode/constant');
2
+ const { DEFAULT_IP_DOMAIN_SUFFIX } = require('@abtnode/constant');
3
3
  const md5 = require('@abtnode/util/lib/md5');
4
4
 
5
5
  const SLOT_FOR_IP_DNS_SITE = '888-888-888-888';
@@ -14,7 +14,7 @@ const getIpDnsDomainForBlocklet = (blocklet, blockletInterface) => {
14
14
 
15
15
  return `${formatName(blocklet.meta.name)}-${nameSuffix}${
16
16
  iName ? '-' : ''
17
- }${iName}-${SLOT_FOR_IP_DNS_SITE}.${DEFAULT_IP_DNS_DOMAIN_SUFFIX}`;
17
+ }${iName}-${SLOT_FOR_IP_DNS_SITE}.${DEFAULT_IP_DOMAIN_SUFFIX}`;
18
18
  };
19
19
 
20
20
  const getDidDomainForBlocklet = ({ name, daemonDid, didDomain }) => {
package/lib/util/index.js CHANGED
@@ -26,7 +26,7 @@ const {
26
26
  DEFAULT_HTTPS_PORT,
27
27
  ROUTING_RULE_TYPES,
28
28
  SLOT_FOR_IP_DNS_SITE,
29
- DEFAULT_IP_DNS_DOMAIN_SUFFIX,
29
+ DEFAULT_IP_DOMAIN_SUFFIX,
30
30
  BLOCKLET_SITE_GROUP_SUFFIX,
31
31
  } = require('@abtnode/constant');
32
32
 
@@ -115,7 +115,7 @@ const getBlockletBaseUrls = ({ rules = [], context = {}, nodeIp }) => {
115
115
  const host = getBlockletHost({ domain: rule.from.domain, context, nodeIp });
116
116
  if (host) {
117
117
  let protocol = 'http'; // TODO: 这里固定为 http, 因为判断 url 是不是 https 和证书相关,这里实现的话比较复杂
118
- if (host.includes(DEFAULT_IP_DNS_DOMAIN_SUFFIX)) {
118
+ if (host.includes(DEFAULT_IP_DOMAIN_SUFFIX)) {
119
119
  protocol = 'https';
120
120
  }
121
121
 
@@ -28,7 +28,7 @@ const isSatisfied = (requirements, throwOnUnsatisfied = true) => {
28
28
  throw new Error(`Your blocklet is not supported on architecture ${actualCpu}`);
29
29
  }
30
30
  if (isVersionSatisfied === false) {
31
- throw new Error(`Your blocklet is not supported on abtnode version v${actualVersion}`);
31
+ throw new Error(`Your blocklet is not supported on server version v${actualVersion}`);
32
32
  }
33
33
  }
34
34
 
@@ -77,7 +77,7 @@ const resetUsers = async ({ teamManager }) => {
77
77
 
78
78
  let count = 0;
79
79
  for (const user of users) {
80
- if (nodeInfo.nodeOwner.did !== user.find) {
80
+ if (nodeInfo.nodeOwner.did !== user.did) {
81
81
  // eslint-disable-next-line no-await-in-loop
82
82
  await userState.remove({ did: user.did });
83
83
  count++;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.30",
6
+ "version": "1.7.1",
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.30",
23
- "@abtnode/constant": "1.6.30",
24
- "@abtnode/cron": "1.6.30",
25
- "@abtnode/db": "1.6.30",
26
- "@abtnode/logger": "1.6.30",
27
- "@abtnode/queue": "1.6.30",
28
- "@abtnode/rbac": "1.6.30",
29
- "@abtnode/router-provider": "1.6.30",
30
- "@abtnode/static-server": "1.6.30",
31
- "@abtnode/timemachine": "1.6.30",
32
- "@abtnode/util": "1.6.30",
33
- "@arcblock/did": "^1.14.20",
34
- "@arcblock/event-hub": "1.14.20",
22
+ "@abtnode/certificate-manager": "1.7.1",
23
+ "@abtnode/constant": "1.7.1",
24
+ "@abtnode/cron": "1.7.1",
25
+ "@abtnode/db": "1.7.1",
26
+ "@abtnode/logger": "1.7.1",
27
+ "@abtnode/queue": "1.7.1",
28
+ "@abtnode/rbac": "1.7.1",
29
+ "@abtnode/router-provider": "1.7.1",
30
+ "@abtnode/static-server": "1.7.1",
31
+ "@abtnode/timemachine": "1.7.1",
32
+ "@abtnode/util": "1.7.1",
33
+ "@arcblock/did": "^1.15.3",
34
+ "@arcblock/event-hub": "1.15.3",
35
35
  "@arcblock/pm2-events": "^0.0.5",
36
- "@arcblock/vc": "^1.14.20",
37
- "@blocklet/meta": "1.6.30",
36
+ "@arcblock/vc": "^1.15.3",
37
+ "@blocklet/meta": "1.7.1",
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.20",
42
- "@ocap/util": "^1.14.20",
43
- "@ocap/wallet": "^1.14.20",
41
+ "@ocap/mcrypto": "^1.15.3",
42
+ "@ocap/util": "^1.15.3",
43
+ "@ocap/wallet": "^1.15.3",
44
44
  "@slack/webhook": "^5.0.3",
45
45
  "ajv": "^7.0.3",
46
46
  "axios": "^0.25.0",
@@ -77,5 +77,5 @@
77
77
  "express": "^4.17.1",
78
78
  "jest": "^27.4.5"
79
79
  },
80
- "gitHead": "d8ea64b807f7852186cd4bf544193496fbb31e7c"
80
+ "gitHead": "5d7efb21dd09f90206251fb74601ca37b0ef84bf"
81
81
  }