@abtnode/core 1.16.21-beta-46c675eb → 1.16.21-beta-e828f413

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
@@ -1332,6 +1332,26 @@ class TeamAPI extends EventEmitter {
1332
1332
  );
1333
1333
  }
1334
1334
 
1335
+ async createNotification({ teamDid, ...rest }) {
1336
+ const notificationState = await this.getNotificationState(teamDid);
1337
+ return notificationState.create({ teamDid, ...rest });
1338
+ }
1339
+
1340
+ async getNotification({ teamDid, ...rest }) {
1341
+ const notificationState = await this.getNotificationState(teamDid);
1342
+ return notificationState.findPaginated({ teamDid, ...rest });
1343
+ }
1344
+
1345
+ async readNotifications({ teamDid, ...rest }) {
1346
+ const notificationState = await this.getNotificationState(teamDid);
1347
+ return notificationState.read({ teamDid, ...rest });
1348
+ }
1349
+
1350
+ async unreadNotifications({ teamDid, ...rest }) {
1351
+ const notificationState = await this.getNotificationState(teamDid);
1352
+ return notificationState.unread({ teamDid, ...rest });
1353
+ }
1354
+
1335
1355
  // =======
1336
1356
  // Private
1337
1357
  // =======
@@ -1356,6 +1376,10 @@ class TeamAPI extends EventEmitter {
1356
1376
  return this.teamManager.getSessionState(did);
1357
1377
  }
1358
1378
 
1379
+ getNotificationState(did) {
1380
+ return this.teamManager.getNotification(did);
1381
+ }
1382
+
1359
1383
  // =============
1360
1384
  // Just for test
1361
1385
  // =============
@@ -57,6 +57,7 @@ const runUserHook = async (label, hookName, args) => {
57
57
  const preInstall = (label, ...args) => runUserHook(label, 'pre-install', ...args);
58
58
  const postInstall = (label, ...args) => runUserHook(label, 'post-install', ...args);
59
59
  const preConfig = (label, ...args) => runUserHook(label, 'pre-config', ...args);
60
+ const preFlight = (label, ...args) => runUserHook(get(label, 'meta.title') || label, 'pre-flight', ...args);
60
61
  const preStart = (blocklet, options) => {
61
62
  // check required environments
62
63
  let environments = get(blocklet, 'meta.environments', []);
@@ -76,4 +77,4 @@ const postStart = (blocklet, ...args) => runUserHook(blocklet.meta.title, 'post-
76
77
  const preUninstall = (label, ...args) => runUserHook(label, 'pre-uninstall', ...args);
77
78
  const preStop = (label, ...args) => runUserHook(label, 'pre-stop', ...args);
78
79
 
79
- module.exports = { preInstall, postInstall, preStart, postStart, preUninstall, preStop, preConfig };
80
+ module.exports = { preInstall, postInstall, preFlight, preStart, postStart, preUninstall, preStop, preConfig };
@@ -576,6 +576,7 @@ class DiskBlockletManager extends BaseBlockletManager {
576
576
 
577
577
  await startBlockletProcess(blocklet, {
578
578
  ...context,
579
+ preFlight: getHookFn('preFlight'),
579
580
  preStart: getHookFn('preStart'),
580
581
  postStart: getHookFn('postStart'),
581
582
  nodeEnvironments,
@@ -2827,14 +2828,17 @@ class DiskBlockletManager extends BaseBlockletManager {
2827
2828
  }
2828
2829
 
2829
2830
  // pre install
2830
- await this._runPreInstallHook(blocklet, context);
2831
+ await this._runUserHook('preInstall', blocklet, context);
2831
2832
 
2832
2833
  // Add environments
2833
2834
  await this._updateBlockletEnvironment(meta.did);
2834
2835
  blocklet = await this.getBlocklet(did);
2835
2836
 
2836
2837
  // post install
2837
- await this._runPostInstallHook(blocklet, context);
2838
+ await this._runUserHook('postInstall', blocklet, context);
2839
+
2840
+ // pre flight
2841
+ await this._runUserHook('preFlight', blocklet, context);
2838
2842
 
2839
2843
  await states.blocklet.setInstalledAt(did);
2840
2844
 
@@ -2951,14 +2955,17 @@ class DiskBlockletManager extends BaseBlockletManager {
2951
2955
  let blocklet = await this.ensureBlocklet(did);
2952
2956
 
2953
2957
  // pre install
2954
- await this._runPreInstallHook(blocklet, context);
2958
+ await this._runUserHook('preInstall', blocklet, context);
2955
2959
 
2956
2960
  // Add environments
2957
2961
  await this._updateBlockletEnvironment(did);
2958
2962
  blocklet = await this.getBlocklet(did);
2959
2963
 
2960
2964
  // post install
2961
- await this._runPostInstallHook(blocklet, context);
2965
+ await this._runUserHook('postInstall', blocklet, context);
2966
+
2967
+ // pre flight
2968
+ await this._runUserHook('preFlight', blocklet, context);
2962
2969
 
2963
2970
  logger.info('start migration on upgrading', { did, componentDids });
2964
2971
  {
@@ -3357,28 +3364,11 @@ class DiskBlockletManager extends BaseBlockletManager {
3357
3364
  return blocklet;
3358
3365
  }
3359
3366
 
3360
- async _runPreInstallHook(blocklet, context) {
3361
- const nodeEnvironments = await states.node.getEnvironments();
3362
-
3363
- const preInstall = (b) =>
3364
- hooks.preInstall(b.meta.title, {
3365
- hooks: Object.assign(b.meta.hooks || {}, b.meta.scripts || {}),
3366
- env: { ...nodeEnvironments },
3367
- appDir: b.env.appDir,
3368
- did: blocklet.meta.did, // root blocklet did
3369
- notification: states.notification,
3370
- context,
3371
- ...getHooksOutputFiles(b),
3372
- });
3373
-
3374
- await forEachBlocklet(blocklet, preInstall, { parallel: true, concurrencyLimit: 2 });
3375
- }
3376
-
3377
- async _runPostInstallHook(blocklet, context) {
3367
+ async _runUserHook(name, blocklet, context) {
3378
3368
  const nodeEnvironments = await states.node.getEnvironments();
3379
3369
 
3380
- const postInstall = (b, { ancestors }) =>
3381
- hooks.postInstall(b.meta.title, {
3370
+ const hookFn = (b, { ancestors }) =>
3371
+ hooks[name](b.meta.title, {
3382
3372
  hooks: Object.assign(b.meta.hooks || {}, b.meta.scripts || {}),
3383
3373
  env: getRuntimeEnvironments(b, nodeEnvironments, ancestors),
3384
3374
  appDir: b.env.appDir,
@@ -3388,7 +3378,7 @@ class DiskBlockletManager extends BaseBlockletManager {
3388
3378
  ...getHooksOutputFiles(b),
3389
3379
  });
3390
3380
 
3391
- await forEachBlocklet(blocklet, postInstall, { parallel: true, concurrencyLimit: 2 });
3381
+ await forEachBlocklet(blocklet, hookFn, { parallel: true, concurrencyLimit: 2 });
3392
3382
  }
3393
3383
 
3394
3384
  async _createNotification(did, notification) {
@@ -3419,6 +3409,8 @@ class DiskBlockletManager extends BaseBlockletManager {
3419
3409
  }
3420
3410
 
3421
3411
  await states.notification.create({ ...notification, blockletUrl });
3412
+ const notificationState = await Promise.resolve(this.teamManager.getNotification(did));
3413
+ await notificationState.create({ teamId: did, ...notification, blockletUrl });
3422
3414
  } catch (error) {
3423
3415
  logger.error('create notification failed', { error });
3424
3416
  }
@@ -98,14 +98,17 @@ const installComponentFromDev = async ({ folder, meta, rootDid, mountPoint, mana
98
98
  let blocklet = await manager.ensureBlocklet(rootDid);
99
99
 
100
100
  // pre install
101
- await manager._runPreInstallHook(blocklet);
101
+ await manager._runUserHook('preInstall', blocklet);
102
102
 
103
103
  // Add environments
104
104
  await manager._updateBlockletEnvironment(rootDid);
105
105
  blocklet = await manager.getBlocklet(rootDid);
106
106
 
107
107
  // post install
108
- await manager._runPostInstallHook(blocklet);
108
+ await manager._runUserHook('postInstall', blocklet);
109
+
110
+ // pre flight
111
+ await manager._runUserHook('preFlight', blocklet);
109
112
 
110
113
  logger.info('add blocklet component for dev', { did, version, meta });
111
114
 
@@ -332,14 +332,16 @@ module.exports = ({
332
332
  }
333
333
 
334
334
  if (payload?.progress !== 100) {
335
- await node.createNotification({
335
+ const param = {
336
336
  title: 'App Backup Failed',
337
337
  description: `Failed to backup ${getDisplayName(blocklet)} to ${args.url}, due to: ${args.errorMessage}`,
338
338
  entityType: 'blocklet',
339
339
  entityId: args.did,
340
340
  severity: 'error',
341
341
  sticky: true,
342
- });
342
+ };
343
+ await node.createNotification(param);
344
+ await node.createBlockeltNotification({ ...param });
343
345
  }
344
346
  } catch (error) {
345
347
  logger.error('Failed to createAuditLog for backupToSpaces failed', { error });
package/lib/index.js CHANGED
@@ -450,6 +450,12 @@ function ABTNode(options) {
450
450
  readNotifications: states.notification.read.bind(states.notification),
451
451
  unreadNotifications: states.notification.unread.bind(states.notification),
452
452
 
453
+ // Blocklet Notifications
454
+ createBlockletNotification: teamAPI.createNotification.bind(teamAPI),
455
+ getBlockletNotifications: teamAPI.getNotification.bind(teamAPI),
456
+ readBlockletNotifications: teamAPI.readNotifications.bind(teamAPI),
457
+ unreadBlockletNotifications: teamAPI.unreadNotifications.bind(teamAPI),
458
+
453
459
  // AuditLog
454
460
  createAuditLog: (params) => states.auditLog.create(params, instance),
455
461
  getAuditLogs: async (params) => {
@@ -493,6 +499,7 @@ function ABTNode(options) {
493
499
 
494
500
  addDomainAlias,
495
501
  deleteDomainAlias,
502
+ isDidDomain: routerManager.isDidDomain.bind(routerManager),
496
503
 
497
504
  getRoutingProviders: () => listProviders(dataDirs.router),
498
505
  checkDomains: domainStatus.checkDomainsStatus.bind(domainStatus),
@@ -6,6 +6,7 @@
6
6
  */
7
7
  const path = require('path');
8
8
  const os = require('os');
9
+ const dns = require('dns');
9
10
  const fse = require('fs-extra');
10
11
  const get = require('lodash/get');
11
12
  const toLower = require('lodash/toLower');
@@ -32,6 +33,7 @@ const {
32
33
  BlockletGroup,
33
34
  } = require('@blocklet/constant');
34
35
  const { forEachChildSync, hasStartEngine, isGatewayBlocklet } = require('@blocklet/meta/lib/util');
36
+ const { fromPublicKey } = require('@ocap/wallet');
35
37
 
36
38
  const {
37
39
  validateAddSite,
@@ -186,6 +188,46 @@ class RouterManager extends EventEmitter {
186
188
  return dbSite;
187
189
  }
188
190
 
191
+ /**
192
+ *
193
+ * @param {object} params
194
+ * @param {string} params.domain
195
+ * @returns
196
+ */
197
+ async isDidDomain({ domain } = {}) {
198
+ if (!domain) {
199
+ throw new Error('domain is required');
200
+ }
201
+
202
+ const tempArray = toLower(domain).split('.');
203
+ let domainTld = domain;
204
+ if (tempArray.length > 2) {
205
+ domainTld = tempArray.slice(tempArray.length - 2).join('.');
206
+ }
207
+
208
+ const results = await dns.promises.resolveTxt(domainTld).catch(() => []);
209
+
210
+ return !!results.find(
211
+ (x) =>
212
+ !!x.find((v) => {
213
+ try {
214
+ const [type, value] = v.split('=');
215
+ if (type === 'dv') {
216
+ const [sig, pk] = value.split('.');
217
+ const wallet = fromPublicKey(pk);
218
+
219
+ return wallet.verify(domainTld, sig);
220
+ }
221
+
222
+ return false;
223
+ } catch (error) {
224
+ // do nothing
225
+ return false;
226
+ }
227
+ })
228
+ );
229
+ }
230
+
189
231
  async addDomainAlias(
190
232
  { id, domainAlias: tmpAlias, force, type, nftDid, chainHost, inBlockletSetup = false },
191
233
  context = {}
@@ -196,6 +238,12 @@ class RouterManager extends EventEmitter {
196
238
  throw new Error(`site ${id} does not exist`);
197
239
  }
198
240
 
241
+ if (type !== 'nft-domain') {
242
+ if (await this.isDidDomain({ domain: domainAlias })) {
243
+ throw new Error(`domain ${domainAlias} is a did domain`);
244
+ }
245
+ }
246
+
199
247
  // check domain exists in site domain
200
248
  const mainDomainSiteCount = await states.site.count({
201
249
  domain: domainAlias,
@@ -44,12 +44,14 @@ class NotificationState extends BaseState {
44
44
  return doc;
45
45
  }
46
46
 
47
- findPaginated({ read, paging } = {}) {
47
+ findPaginated({ read, paging, teamDid } = {}) {
48
48
  const conditions = {};
49
49
  if (typeof read === 'boolean') {
50
50
  conditions.read = read;
51
51
  }
52
-
52
+ if (teamDid) {
53
+ conditions.entityId = teamDid;
54
+ }
53
55
  return this.paginate(conditions, { createdAt: -1 }, { ...paging, pageSize: 10 });
54
56
  }
55
57
 
@@ -35,6 +35,7 @@ const States = {
35
35
  Tag: require('../states/tag'),
36
36
  Project: require('../states/project'),
37
37
  Release: require('../states/release'),
38
+ Notification: require('../states/notification'),
38
39
  };
39
40
 
40
41
  const getDefaultTeamState = () => ({
@@ -46,6 +47,7 @@ const getDefaultTeamState = () => ({
46
47
  tag: null,
47
48
  project: null,
48
49
  release: null,
50
+ notification: null,
49
51
  });
50
52
 
51
53
  class TeamManager extends EventEmitter {
@@ -102,6 +104,7 @@ class TeamManager extends EventEmitter {
102
104
  passport: await this.createState(this.nodeDid, 'Passport'),
103
105
  connectedAccount: await this.createState(this.nodeDid, 'ConnectedAccount'),
104
106
  session: await this.createState(this.nodeDid, 'Session'),
107
+ notification: await this.createState(this.nodeDid, 'Notification'),
105
108
  };
106
109
  }
107
110
 
@@ -129,6 +132,10 @@ class TeamManager extends EventEmitter {
129
132
  return this.getState(teamDid, 'session');
130
133
  }
131
134
 
135
+ getNotification(teamDid) {
136
+ return this.getState(teamDid, 'notification');
137
+ }
138
+
132
139
  async getProjectState(teamDid) {
133
140
  return {
134
141
  projectState: await this.getState(teamDid, 'project'),
@@ -488,6 +488,7 @@ const getHealthyCheckTimeout = (blocklet, { checkHealthImmediately } = {}) => {
488
488
  const startBlockletProcess = async (
489
489
  blocklet,
490
490
  {
491
+ preFlight = noop,
491
492
  preStart = noop,
492
493
  postStart = noopAsync,
493
494
  nodeEnvironments,
@@ -541,6 +542,9 @@ const startBlockletProcess = async (
541
542
  const env = getRuntimeEnvironments(b, nodeEnvironments, ancestors);
542
543
  const startedAt = Date.now();
543
544
 
545
+ // run hook
546
+ await preFlight(b, { env });
547
+
544
548
  // run hook
545
549
  await preStart(b, { env });
546
550
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.21-beta-46c675eb",
6
+ "version": "1.16.21-beta-e828f413",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,39 +19,39 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/analytics": "1.16.21-beta-46c675eb",
23
- "@abtnode/auth": "1.16.21-beta-46c675eb",
24
- "@abtnode/certificate-manager": "1.16.21-beta-46c675eb",
25
- "@abtnode/constant": "1.16.21-beta-46c675eb",
26
- "@abtnode/cron": "1.16.21-beta-46c675eb",
27
- "@abtnode/logger": "1.16.21-beta-46c675eb",
28
- "@abtnode/models": "1.16.21-beta-46c675eb",
29
- "@abtnode/queue": "1.16.21-beta-46c675eb",
30
- "@abtnode/rbac": "1.16.21-beta-46c675eb",
31
- "@abtnode/router-provider": "1.16.21-beta-46c675eb",
32
- "@abtnode/static-server": "1.16.21-beta-46c675eb",
33
- "@abtnode/timemachine": "1.16.21-beta-46c675eb",
34
- "@abtnode/util": "1.16.21-beta-46c675eb",
35
- "@arcblock/did": "1.18.105",
36
- "@arcblock/did-auth": "1.18.105",
37
- "@arcblock/did-ext": "^1.18.105",
22
+ "@abtnode/analytics": "1.16.21-beta-e828f413",
23
+ "@abtnode/auth": "1.16.21-beta-e828f413",
24
+ "@abtnode/certificate-manager": "1.16.21-beta-e828f413",
25
+ "@abtnode/constant": "1.16.21-beta-e828f413",
26
+ "@abtnode/cron": "1.16.21-beta-e828f413",
27
+ "@abtnode/logger": "1.16.21-beta-e828f413",
28
+ "@abtnode/models": "1.16.21-beta-e828f413",
29
+ "@abtnode/queue": "1.16.21-beta-e828f413",
30
+ "@abtnode/rbac": "1.16.21-beta-e828f413",
31
+ "@abtnode/router-provider": "1.16.21-beta-e828f413",
32
+ "@abtnode/static-server": "1.16.21-beta-e828f413",
33
+ "@abtnode/timemachine": "1.16.21-beta-e828f413",
34
+ "@abtnode/util": "1.16.21-beta-e828f413",
35
+ "@arcblock/did": "1.18.107",
36
+ "@arcblock/did-auth": "1.18.107",
37
+ "@arcblock/did-ext": "^1.18.107",
38
38
  "@arcblock/did-motif": "^1.1.13",
39
- "@arcblock/did-util": "1.18.105",
40
- "@arcblock/event-hub": "1.18.105",
41
- "@arcblock/jwt": "^1.18.105",
39
+ "@arcblock/did-util": "1.18.107",
40
+ "@arcblock/event-hub": "1.18.107",
41
+ "@arcblock/jwt": "^1.18.107",
42
42
  "@arcblock/pm2-events": "^0.0.5",
43
- "@arcblock/validator": "^1.18.105",
44
- "@arcblock/vc": "1.18.105",
45
- "@blocklet/constant": "1.16.21-beta-46c675eb",
46
- "@blocklet/env": "1.16.21-beta-46c675eb",
47
- "@blocklet/meta": "1.16.21-beta-46c675eb",
48
- "@blocklet/resolver": "1.16.21-beta-46c675eb",
49
- "@blocklet/sdk": "1.16.21-beta-46c675eb",
50
- "@did-space/client": "^0.3.43",
43
+ "@arcblock/validator": "^1.18.107",
44
+ "@arcblock/vc": "1.18.107",
45
+ "@blocklet/constant": "1.16.21-beta-e828f413",
46
+ "@blocklet/env": "1.16.21-beta-e828f413",
47
+ "@blocklet/meta": "1.16.21-beta-e828f413",
48
+ "@blocklet/resolver": "1.16.21-beta-e828f413",
49
+ "@blocklet/sdk": "1.16.21-beta-e828f413",
50
+ "@did-space/client": "^0.3.44",
51
51
  "@fidm/x509": "^1.2.1",
52
- "@ocap/mcrypto": "1.18.105",
53
- "@ocap/util": "1.18.105",
54
- "@ocap/wallet": "1.18.105",
52
+ "@ocap/mcrypto": "1.18.107",
53
+ "@ocap/util": "1.18.107",
54
+ "@ocap/wallet": "1.18.107",
55
55
  "@slack/webhook": "^5.0.4",
56
56
  "archiver": "^5.3.1",
57
57
  "axios": "^0.27.2",
@@ -102,5 +102,5 @@
102
102
  "jest": "^27.5.1",
103
103
  "unzipper": "^0.10.11"
104
104
  },
105
- "gitHead": "a852c7930e8bc84c641579d8e4c009accf478078"
105
+ "gitHead": "936af9cb0549f341d3683ea63085b460bf6ddbf0"
106
106
  }