@abtnode/core 1.8.8 → 1.8.11

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.
@@ -2716,6 +2716,9 @@ class BlockletManager extends BaseBlockletManager {
2716
2716
 
2717
2717
  await fs.writeFile(path.join(blocklet.env.dataDir, 'logo.svg'), createDidLogo(blocklet.meta.did));
2718
2718
 
2719
+ // Init db
2720
+ await this.teamManager.initTeam(blocklet.meta.did);
2721
+
2719
2722
  this.emit(BlockletEvents.installed, { blocklet, context });
2720
2723
 
2721
2724
  // Update dynamic component meta in blocklet settings
package/lib/event.js CHANGED
@@ -25,6 +25,7 @@ module.exports = ({
25
25
  handleRouting,
26
26
  domainStatus,
27
27
  teamAPI,
28
+ teamManager,
28
29
  certManager,
29
30
  node,
30
31
  }) => {
@@ -50,6 +51,11 @@ module.exports = ({
50
51
  // Subscribe events from eventHub and proxy to eventHandler
51
52
  [...Object.values(BlockletEvents), ...Object.values(EVENTS)].forEach((name) => {
52
53
  eventHub.on(name, (data) => {
54
+ if (name === BlockletEvents.removed) {
55
+ // Cleanup cache in teamManager for every node instance
56
+ teamManager.deleteTeam(data?.meta?.did, { closeDatabase: false });
57
+ }
58
+
53
59
  if (typeof eventHandler === 'function') {
54
60
  eventHandler({ name, data });
55
61
  }
package/lib/index.js CHANGED
@@ -400,6 +400,7 @@ function ABTNode(options) {
400
400
  handleRouting,
401
401
  domainStatus,
402
402
  teamAPI,
403
+ teamManager,
403
404
  certManager,
404
405
  node: instance,
405
406
  });
@@ -1284,12 +1284,6 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
1284
1284
  });
1285
1285
  };
1286
1286
 
1287
- const checkDomain = async (domain) => {
1288
- const matchedCert = await routerManager.getMatchedCert(domain);
1289
-
1290
- return { domain, isHttps: !!matchedCert, matchedCert };
1291
- };
1292
-
1293
1287
  return {
1294
1288
  ensureDashboardRouting,
1295
1289
  ensureBlockletRouting,
@@ -1305,7 +1299,6 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
1305
1299
  getSnapshotSites,
1306
1300
  getSitesFromSnapshot,
1307
1301
  getCertificates,
1308
- checkDomain,
1309
1302
  ensureWildcardCerts,
1310
1303
  addWellknownSite,
1311
1304
  upsertSiteRule,
@@ -104,7 +104,7 @@ class TeamManager extends EventEmitter {
104
104
 
105
105
  async getUserState(did) {
106
106
  // validate exist
107
- if (!this.isNodeTeam(did) && !(await this.states.blocklet.getBlocklet(did))) {
107
+ if (!this.isNodeTeam(did) && !(await this.states.blocklet.hasBlocklet(did))) {
108
108
  logger.error('Did does not exist', { action: 'getUserState', did });
109
109
  throw new Error(`Did does not exist: ${did}`);
110
110
  }
@@ -143,7 +143,7 @@ class TeamManager extends EventEmitter {
143
143
 
144
144
  async getSessionState(did) {
145
145
  // validate exist
146
- if (!this.isNodeTeam(did) && !(await this.states.blocklet.getBlocklet(did))) {
146
+ if (!this.isNodeTeam(did) && !(await this.states.blocklet.hasBlocklet(did))) {
147
147
  logger.error('Did does not exist', { action: 'getSessionState', did });
148
148
  throw new Error(`Did does not exist: ${did}`);
149
149
  }
@@ -182,7 +182,7 @@ class TeamManager extends EventEmitter {
182
182
  logger.info('get rbac', { did });
183
183
 
184
184
  // validate exist
185
- if (!this.isNodeTeam(did) && !(await this.states.blocklet.getBlocklet(did))) {
185
+ if (!this.isNodeTeam(did) && !(await this.states.blocklet.hasBlocklet(did))) {
186
186
  logger.error('Did does not exist', { action: 'getRBAC', did });
187
187
  throw new Error(`Did does not exist: ${did}`);
188
188
  }
@@ -288,8 +288,34 @@ class TeamManager extends EventEmitter {
288
288
  return owner;
289
289
  }
290
290
 
291
- async deleteTeam(did) {
292
- if (this.cache[did]) {
291
+ async initTeam(did) {
292
+ if (!did) {
293
+ logger.error('initTeam: did does not exist');
294
+ return;
295
+ }
296
+
297
+ logger.info('initTeam', { did });
298
+
299
+ const rbac = await this.getRBAC(did);
300
+ const user = await this.getUserState(did);
301
+ const session = await this.getSessionState(did);
302
+
303
+ this.cache[did] = {
304
+ rbac,
305
+ user,
306
+ session,
307
+ };
308
+ }
309
+
310
+ async deleteTeam(did, { closeDatabase: closeDB = true } = {}) {
311
+ if (!did) {
312
+ logger.error('deleteTeam: did does not exist');
313
+ return;
314
+ }
315
+
316
+ logger.info('deleteTeam', { did, closeDB });
317
+
318
+ if (closeDB && this.cache[did]) {
293
319
  try {
294
320
  if (this.cache[did].rbac) {
295
321
  await closeDatabase(this.cache[did].rbac.storage.db);
@@ -1,6 +1,7 @@
1
+ const https = require('https');
1
2
  const { EventEmitter } = require('events');
2
3
  const logger = require('@abtnode/logger')('@abtnode/domain-status');
3
- const { EVENTS } = require('@abtnode/constant');
4
+ const { EVENTS, WELLKNOWN_PING_PREFIX } = require('@abtnode/constant');
4
5
  const { checkDomainDNS } = require('./index');
5
6
 
6
7
  const dnsStatusStore = Object.create(null);
@@ -31,9 +32,51 @@ class DomainStatus extends EventEmitter {
31
32
  this.routerManager = routerManager;
32
33
  }
33
34
 
35
+ async getHttpsCert(domain) {
36
+ const matchedCert = await this.routerManager.getMatchedCert(domain);
37
+
38
+ if (matchedCert) {
39
+ return matchedCert;
40
+ }
41
+
42
+ return new Promise((resolve) => {
43
+ const req = https.request(
44
+ {
45
+ host: domain,
46
+ path: WELLKNOWN_PING_PREFIX,
47
+ method: 'GET',
48
+ timeout: 1000 * 10,
49
+ },
50
+ (res) => {
51
+ try {
52
+ const data = res.socket.getPeerCertificate();
53
+ const cert = {
54
+ issuer: {
55
+ countryName: data.issuer.C,
56
+ organizationName: data.issuer.O,
57
+ commonName: data.issuer.CN,
58
+ },
59
+ validFrom: data.valid_from,
60
+ validTo: data.valid_to,
61
+ };
62
+ resolve(cert);
63
+ } catch {
64
+ resolve(null);
65
+ }
66
+ }
67
+ );
68
+
69
+ req.on('error', () => {
70
+ resolve(null);
71
+ });
72
+
73
+ req.end();
74
+ });
75
+ }
76
+
34
77
  checkDomainsStatus({ domains } = {}) {
35
78
  (domains || []).forEach((domain) => {
36
- Promise.all([this.routerManager.getMatchedCert(domain), checkDomainDnsWrapper(domain)])
79
+ Promise.all([this.getHttpsCert(domain), checkDomainDnsWrapper(domain)])
37
80
  .then((data) => {
38
81
  const [matchedCert, dns] = data;
39
82
  this.emit(EVENTS.DOMAIN_STATUS, { domain, matchedCert, isHttps: !!matchedCert, dns });
@@ -128,7 +128,7 @@ const doUpgrade = async (session) => {
128
128
  if (session.stage === NODE_UPGRADE_PROGRESS.CLEANUP) {
129
129
  logger.info('cleanup for upgrading', { from, to, sessionId });
130
130
  await goNextState(NODE_UPGRADE_PROGRESS.COMPLETE);
131
- await sleep(5000);
131
+ await sleep(8000);
132
132
  await states.node.updateNodeInfo({ nextVersion: '', version: to, upgradeSessionId: '' });
133
133
  try {
134
134
  await states.node.exitMode(NODE_MODES.MAINTENANCE);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.8",
6
+ "version": "1.8.11",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,17 +19,17 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/certificate-manager": "1.8.8",
23
- "@abtnode/constant": "1.8.8",
24
- "@abtnode/cron": "1.8.8",
25
- "@abtnode/db": "1.8.8",
26
- "@abtnode/logger": "1.8.8",
27
- "@abtnode/queue": "1.8.8",
28
- "@abtnode/rbac": "1.8.8",
29
- "@abtnode/router-provider": "1.8.8",
30
- "@abtnode/static-server": "1.8.8",
31
- "@abtnode/timemachine": "1.8.8",
32
- "@abtnode/util": "1.8.8",
22
+ "@abtnode/certificate-manager": "1.8.11",
23
+ "@abtnode/constant": "1.8.11",
24
+ "@abtnode/cron": "1.8.11",
25
+ "@abtnode/db": "1.8.11",
26
+ "@abtnode/logger": "1.8.11",
27
+ "@abtnode/queue": "1.8.11",
28
+ "@abtnode/rbac": "1.8.11",
29
+ "@abtnode/router-provider": "1.8.11",
30
+ "@abtnode/static-server": "1.8.11",
31
+ "@abtnode/timemachine": "1.8.11",
32
+ "@abtnode/util": "1.8.11",
33
33
  "@arcblock/did": "1.17.11",
34
34
  "@arcblock/did-motif": "^1.1.10",
35
35
  "@arcblock/did-util": "1.17.11",
@@ -37,11 +37,11 @@
37
37
  "@arcblock/jwt": "^1.17.11",
38
38
  "@arcblock/pm2-events": "^0.0.5",
39
39
  "@arcblock/vc": "1.17.11",
40
- "@blocklet/meta": "1.8.8",
41
- "@blocklet/sdk": "1.8.8",
40
+ "@blocklet/meta": "1.8.11",
41
+ "@blocklet/sdk": "1.8.11",
42
42
  "@fidm/x509": "^1.2.1",
43
- "@nedb/core": "^1.3.2",
44
- "@nedb/multi": "^1.3.2",
43
+ "@nedb/core": "^1.3.4",
44
+ "@nedb/multi": "^1.3.4",
45
45
  "@ocap/mcrypto": "1.17.11",
46
46
  "@ocap/util": "1.17.11",
47
47
  "@ocap/wallet": "1.17.11",
@@ -82,5 +82,5 @@
82
82
  "express": "^4.18.1",
83
83
  "jest": "^27.5.1"
84
84
  },
85
- "gitHead": "8da61db2342d7c53f2b803e5193c03d82bce8f77"
85
+ "gitHead": "389148562de1ce5b45097e764bc9d1718009e527"
86
86
  }