@abtnode/core 1.6.31 → 1.7.2

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,
@@ -623,6 +624,14 @@ class BlockletManager extends BaseBlockletManager {
623
624
  }
624
625
  }
625
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
+
626
635
  if (x.key === 'BLOCKLET_WALLET_TYPE') {
627
636
  if (['default', 'eth'].includes(x.value) === false) {
628
637
  throw new Error('Invalid blocklet wallet type, only "default" and "eth" are supported');
@@ -998,13 +1007,14 @@ class BlockletManager extends BaseBlockletManager {
998
1007
  }),
999
1008
  };
1000
1009
 
1001
- const configs = await states.blockletExtras.getConfigs(did);
1010
+ const configs = await states.blockletExtras.getConfigs(blocklet.meta.did);
1002
1011
  fillBlockletConfigs(blocklet, configs);
1003
1012
 
1004
1013
  // merge settings to blocklet
1005
- const settings = await states.blockletExtras.getSettings(did);
1014
+ const settings = await states.blockletExtras.getSettings(blocklet.meta.did);
1006
1015
  blocklet.trustedPassports = get(settings, 'trustedPassports') || [];
1007
1016
  blocklet.enablePassportIssuance = get(settings, 'enablePassportIssuance', true);
1017
+ blocklet.settings = settings || {};
1008
1018
 
1009
1019
  // handle child env
1010
1020
  for (const child of blocklet.children) {
@@ -1027,13 +1037,25 @@ class BlockletManager extends BaseBlockletManager {
1027
1037
  }),
1028
1038
  };
1029
1039
 
1030
- const childConfigs = await states.blockletExtras.getChildConfigs(did, childDid);
1040
+ const childConfigs = await states.blockletExtras.getChildConfigs(blocklet.meta.did, childDid);
1031
1041
  fillBlockletConfigs(child, childConfigs, blocklet);
1032
1042
  }
1033
1043
 
1044
+ // site
1045
+ blocklet.site = await this.getSiteByDid(blocklet.meta.did);
1046
+
1034
1047
  return blocklet;
1035
1048
  }
1036
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
+
1037
1059
  async status(did, { forceSync = false } = {}) {
1038
1060
  const fastReturnOnForceSync = async (blocklet = {}) => {
1039
1061
  const { status } = blocklet;
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,
@@ -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
  */
@@ -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.31",
6
+ "version": "1.7.2",
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.31",
23
- "@abtnode/constant": "1.6.31",
24
- "@abtnode/cron": "1.6.31",
25
- "@abtnode/db": "1.6.31",
26
- "@abtnode/logger": "1.6.31",
27
- "@abtnode/queue": "1.6.31",
28
- "@abtnode/rbac": "1.6.31",
29
- "@abtnode/router-provider": "1.6.31",
30
- "@abtnode/static-server": "1.6.31",
31
- "@abtnode/timemachine": "1.6.31",
32
- "@abtnode/util": "1.6.31",
33
- "@arcblock/did": "^1.14.24",
34
- "@arcblock/event-hub": "1.14.24",
22
+ "@abtnode/certificate-manager": "1.7.2",
23
+ "@abtnode/constant": "1.7.2",
24
+ "@abtnode/cron": "1.7.2",
25
+ "@abtnode/db": "1.7.2",
26
+ "@abtnode/logger": "1.7.2",
27
+ "@abtnode/queue": "1.7.2",
28
+ "@abtnode/rbac": "1.7.2",
29
+ "@abtnode/router-provider": "1.7.2",
30
+ "@abtnode/static-server": "1.7.2",
31
+ "@abtnode/timemachine": "1.7.2",
32
+ "@abtnode/util": "1.7.2",
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.24",
37
- "@blocklet/meta": "1.6.31",
36
+ "@arcblock/vc": "^1.15.3",
37
+ "@blocklet/meta": "1.7.2",
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.24",
42
- "@ocap/util": "^1.14.24",
43
- "@ocap/wallet": "^1.14.24",
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": "ccda31a16ac6b606d34336fcc6db0b2aff15c32e"
80
+ "gitHead": "b84e7406d84fb9c3be5bf7ce968cb7b6b661d550"
81
81
  }