@abtnode/core 1.8.10 → 1.8.13

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.
@@ -533,7 +533,7 @@ class BlockletManager extends BaseBlockletManager {
533
533
  logger.info('blocklet reload successfully', { did });
534
534
 
535
535
  const res = await this.status(did);
536
- this.emit(BlockletEvents.statusUpdated, res);
536
+ this.emit(BlockletEvents.statusChange, res);
537
537
  return res;
538
538
  }
539
539
 
@@ -1370,7 +1370,9 @@ class BlockletManager extends BaseBlockletManager {
1370
1370
  return blocklet;
1371
1371
  }
1372
1372
 
1373
- return states.blocklet.setBlockletStatus(did, BlockletStatus.stopped);
1373
+ const res = await states.blocklet.setBlockletStatus(did, BlockletStatus.stopped);
1374
+ this.emit(BlockletEvents.statusChange, res);
1375
+ return res;
1374
1376
  };
1375
1377
 
1376
1378
  const blocklet = await this.ensureBlocklet(did);
@@ -1384,22 +1386,22 @@ class BlockletManager extends BaseBlockletManager {
1384
1386
  }
1385
1387
  }
1386
1388
 
1389
+ if (!shouldUpdateStatus) {
1390
+ return blocklet;
1391
+ }
1392
+
1387
1393
  try {
1388
1394
  const status = await getBlockletStatusFromProcess(blocklet);
1389
- if (shouldUpdateStatus) {
1390
- if (status === BlockletStatus.stopped) {
1391
- await states.blocklet.stopBlocklet(did);
1392
- }
1393
- return states.blocklet.setBlockletStatus(did, status);
1395
+ if (blocklet.status !== status) {
1396
+ const res = await states.blocklet.setBlockletStatus(did, status);
1397
+ this.emit(BlockletEvents.statusChange, res);
1398
+ return res;
1394
1399
  }
1400
+
1401
+ return blocklet;
1395
1402
  } catch (err) {
1396
- if (shouldUpdateStatus) {
1397
- return fastReturnOnForceSync(blocklet);
1398
- }
1399
- throw err;
1403
+ return fastReturnOnForceSync(blocklet);
1400
1404
  }
1401
-
1402
- return blocklet;
1403
1405
  }
1404
1406
 
1405
1407
  async getBlockletInterfaces({ blocklet, nodeInfo, context }) {
@@ -2301,7 +2303,7 @@ class BlockletManager extends BaseBlockletManager {
2301
2303
  async _syncBlockletStatus() {
2302
2304
  const run = async (blocklet) => {
2303
2305
  try {
2304
- await this.status(blocklet.meta.did, { forceSync: true });
2306
+ await this.status(blocklet.meta.did);
2305
2307
  } catch (err) {
2306
2308
  logger.error('sync blocklet status failed', { error: err });
2307
2309
  }
@@ -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,
@@ -8,7 +8,7 @@ class WebhookState extends BaseState {
8
8
  super(baseDir, { filename: 'webhook.db', ...options });
9
9
  }
10
10
 
11
- async create(info) {
11
+ async create(info, { mock } = {}) {
12
12
  const { type, params } = info;
13
13
  const filterParams = params.map((item) => {
14
14
  const data = {
@@ -26,6 +26,10 @@ class WebhookState extends BaseState {
26
26
 
27
27
  await validateWebhook(data);
28
28
 
29
+ if (mock) {
30
+ return data;
31
+ }
32
+
29
33
  const webhook = await this.asyncDB.insert(data);
30
34
  return webhook;
31
35
  }
@@ -353,8 +353,8 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
353
353
  for (const x of root.children || []) {
354
354
  mountPoints.push({
355
355
  title: x.meta.title,
356
- did: x.meta.did,
357
- name: x.meta.name,
356
+ did: x.meta.bundleDid,
357
+ name: x.meta.bundleName,
358
358
  mountPoint: x.mountPoint || '',
359
359
  });
360
360
  }
@@ -366,6 +366,7 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
366
366
  ...devEnvironments,
367
367
  BLOCKLET_WEB_PORTS: JSON.stringify(ports),
368
368
  BLOCKLET_MOUNT_POINTS: JSON.stringify(mountPoints),
369
+ BLOCKLET_MODE: blocklet.mode || BLOCKLET_MODES.PRODUCTION,
369
370
  ...nodeEnvironments,
370
371
  ...safeNodeEnvironments,
371
372
  };
@@ -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 });
@@ -134,13 +134,14 @@ module.exports = ({ events, dataDirs, instance }) => {
134
134
 
135
135
  const createWebhook = async (webhook) => {
136
136
  try {
137
- const createRes = await webhookState.create(webhook);
138
- await sentTextMessage(createRes, `A ${createRes.type} integration is now *successfully added*`);
137
+ const mockCreateRes = await webhookState.create(webhook, { mock: true });
138
+ await sentTextMessage(mockCreateRes, `A ${mockCreateRes.type} integration is now *successfully added*`);
139
139
 
140
+ const createRes = await webhookState.create(webhook);
140
141
  return createRes;
141
142
  } catch (err) {
142
- logger.error('create webhook error', { err });
143
- throw new Error(err.message);
143
+ logger.error('Failed to create webhook', { err });
144
+ throw new Error(`Failed to create webhook: ${err.message}`);
144
145
  }
145
146
  };
146
147
 
@@ -29,7 +29,7 @@ class SlackSender extends BaseSender {
29
29
  type: 'section',
30
30
  text: {
31
31
  type: 'mrkdwn',
32
- text: `*${nodeInfo.name}*`,
32
+ text: `*${nodeInfo?.name}*`,
33
33
  },
34
34
  },
35
35
  {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.10",
6
+ "version": "1.8.13",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,32 +19,32 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/certificate-manager": "1.8.10",
23
- "@abtnode/constant": "1.8.10",
24
- "@abtnode/cron": "1.8.10",
25
- "@abtnode/db": "1.8.10",
26
- "@abtnode/logger": "1.8.10",
27
- "@abtnode/queue": "1.8.10",
28
- "@abtnode/rbac": "1.8.10",
29
- "@abtnode/router-provider": "1.8.10",
30
- "@abtnode/static-server": "1.8.10",
31
- "@abtnode/timemachine": "1.8.10",
32
- "@abtnode/util": "1.8.10",
33
- "@arcblock/did": "1.17.11",
22
+ "@abtnode/certificate-manager": "1.8.13",
23
+ "@abtnode/constant": "1.8.13",
24
+ "@abtnode/cron": "1.8.13",
25
+ "@abtnode/db": "1.8.13",
26
+ "@abtnode/logger": "1.8.13",
27
+ "@abtnode/queue": "1.8.13",
28
+ "@abtnode/rbac": "1.8.13",
29
+ "@abtnode/router-provider": "1.8.13",
30
+ "@abtnode/static-server": "1.8.13",
31
+ "@abtnode/timemachine": "1.8.13",
32
+ "@abtnode/util": "1.8.13",
33
+ "@arcblock/did": "1.17.15",
34
34
  "@arcblock/did-motif": "^1.1.10",
35
- "@arcblock/did-util": "1.17.11",
36
- "@arcblock/event-hub": "1.17.11",
37
- "@arcblock/jwt": "^1.17.11",
35
+ "@arcblock/did-util": "1.17.15",
36
+ "@arcblock/event-hub": "1.17.15",
37
+ "@arcblock/jwt": "^1.17.15",
38
38
  "@arcblock/pm2-events": "^0.0.5",
39
- "@arcblock/vc": "1.17.11",
40
- "@blocklet/meta": "1.8.10",
41
- "@blocklet/sdk": "1.8.10",
39
+ "@arcblock/vc": "1.17.15",
40
+ "@blocklet/meta": "1.8.13",
41
+ "@blocklet/sdk": "1.8.13",
42
42
  "@fidm/x509": "^1.2.1",
43
43
  "@nedb/core": "^1.3.4",
44
44
  "@nedb/multi": "^1.3.4",
45
- "@ocap/mcrypto": "1.17.11",
46
- "@ocap/util": "1.17.11",
47
- "@ocap/wallet": "1.17.11",
45
+ "@ocap/mcrypto": "1.17.15",
46
+ "@ocap/util": "1.17.15",
47
+ "@ocap/wallet": "1.17.15",
48
48
  "@slack/webhook": "^5.0.4",
49
49
  "axios": "^0.27.2",
50
50
  "axon": "^2.0.3",
@@ -82,5 +82,5 @@
82
82
  "express": "^4.18.1",
83
83
  "jest": "^27.5.1"
84
84
  },
85
- "gitHead": "84f655bd7b8d55fde2656fac8671faad3c3bde28"
85
+ "gitHead": "028f33d8a3a4f999456bfe8e7bd2e1a53b664b47"
86
86
  }