@abtnode/core 1.16.24-beta-3d2e25fd → 1.16.24-beta-08e03567
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/blocklet/downloader/resolve-download.js +5 -0
- package/lib/blocklet/manager/disk.js +107 -23
- package/lib/blocklet/manager/helper/install-component-from-url.js +1 -1
- package/lib/blocklet/manager/helper/upgrade-components.js +1 -1
- package/lib/event/index.js +3 -1
- package/lib/monitor/blocklet-runtime-monitor.js +1 -1
- package/lib/monitor/node-runtime-monitor.js +1 -1
- package/lib/team/manager.js +2 -2
- package/lib/util/blocklet.js +0 -4
- package/lib/util/install-external-dependencies.js +18 -7
- package/lib/webhook/index.js +10 -6
- package/lib/webhook/sender/wallet/index.js +27 -18
- package/package.json +21 -21
|
@@ -9,6 +9,7 @@ const defaultLogger = require('@abtnode/logger')('@abtnode/core:resolve-download
|
|
|
9
9
|
const { getBlockletMeta } = require('../../util');
|
|
10
10
|
|
|
11
11
|
const { ensureBlockletExpanded, expandTarball, getBundleDir } = require('../../util/blocklet');
|
|
12
|
+
const { installExternalDependencies } = require('../../util/install-external-dependencies');
|
|
12
13
|
|
|
13
14
|
const asyncFs = fs.promises;
|
|
14
15
|
|
|
@@ -76,6 +77,8 @@ const resolveDownload = async (tarFile, dist, { removeTarFile = true, logger = d
|
|
|
76
77
|
fs.mkdirSync(installDir, { recursive: true });
|
|
77
78
|
|
|
78
79
|
await fs.move(downloadDir, installDir, { overwrite: true });
|
|
80
|
+
|
|
81
|
+
installExternalDependencies(installDir);
|
|
79
82
|
} catch (error) {
|
|
80
83
|
fs.removeSync(downloadDir);
|
|
81
84
|
fs.removeSync(tmp);
|
|
@@ -142,6 +145,8 @@ const resolveDiffDownload = async (
|
|
|
142
145
|
logger.info('Move downloadDir to installDir', { downloadDir, bundleDir });
|
|
143
146
|
await fs.move(downloadDir, bundleDir, { overwrite: true });
|
|
144
147
|
|
|
148
|
+
installExternalDependencies(bundleDir);
|
|
149
|
+
|
|
145
150
|
return { meta, installDir: bundleDir };
|
|
146
151
|
} catch (error) {
|
|
147
152
|
fs.removeSync(downloadDir);
|
|
@@ -220,6 +220,40 @@ const pm2StatusMap = {
|
|
|
220
220
|
*/
|
|
221
221
|
const getBlockletEngineNameByPlatform = (blockletMeta) => getBlockletEngine(blockletMeta).interpreter;
|
|
222
222
|
|
|
223
|
+
const getWalletAppNotification = async (blocklet, tempBlockletInfo) => {
|
|
224
|
+
let blockletInfo = tempBlockletInfo;
|
|
225
|
+
if (!blockletInfo) {
|
|
226
|
+
const nodeInfo = await states.node.read();
|
|
227
|
+
blockletInfo = getBlockletInfo(blocklet, nodeInfo.sk);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
actions: [
|
|
232
|
+
{
|
|
233
|
+
name: 'Visit',
|
|
234
|
+
link: blockletInfo.appUrl,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
attachments: [
|
|
238
|
+
{
|
|
239
|
+
type: 'dapp',
|
|
240
|
+
data: {
|
|
241
|
+
url: blockletInfo.appUrl,
|
|
242
|
+
appDID: blocklet.appPid,
|
|
243
|
+
logo:
|
|
244
|
+
blocklet.environmentObj.BLOCKLET_APP_LOGO ||
|
|
245
|
+
joinUrl(
|
|
246
|
+
blockletInfo.appUrl,
|
|
247
|
+
normalizePathPrefix(joinUrl(WELLKNOWN_SERVICE_PATH_PREFIX, '/blocklet/logo')) || '/'
|
|
248
|
+
),
|
|
249
|
+
title: blockletInfo.name,
|
|
250
|
+
desc: blockletInfo.description,
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
|
|
223
257
|
class DiskBlockletManager extends BaseBlockletManager {
|
|
224
258
|
constructor({
|
|
225
259
|
dataDirs,
|
|
@@ -711,7 +745,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
711
745
|
blocklet1.meta.title
|
|
712
746
|
}: ${error.message}`;
|
|
713
747
|
this._createNotification(did, {
|
|
714
|
-
title: '',
|
|
748
|
+
title: 'Component start failed',
|
|
715
749
|
description,
|
|
716
750
|
entityType: 'blocklet',
|
|
717
751
|
entityId: did,
|
|
@@ -793,7 +827,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
793
827
|
this.configSynchronizer.throttledSyncAppConfig(blocklet.meta.did);
|
|
794
828
|
|
|
795
829
|
this._createNotification(did, {
|
|
796
|
-
title: '',
|
|
830
|
+
title: 'Component stop succeed',
|
|
797
831
|
description: `${
|
|
798
832
|
componentDids?.length ? getComponentNamesWithVersion(blocklet, componentDids) : 'All components'
|
|
799
833
|
} is successfully stopped for ${blocklet.meta.title}.`,
|
|
@@ -891,7 +925,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
891
925
|
result.meta.title
|
|
892
926
|
}: ${err.message || 'queue exception'}`;
|
|
893
927
|
this._createNotification(did, {
|
|
894
|
-
title: '',
|
|
928
|
+
title: 'Component restart failed',
|
|
895
929
|
description,
|
|
896
930
|
entityType: 'blocklet',
|
|
897
931
|
entityId: did,
|
|
@@ -1106,7 +1140,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1106
1140
|
this.emit(BlockletEvents.upgraded, { blocklet: newBlocklet, context: { ...context, createAuditLog: false } }); // trigger router refresh
|
|
1107
1141
|
|
|
1108
1142
|
this._createNotification(newBlocklet.meta.did, {
|
|
1109
|
-
title: '',
|
|
1143
|
+
title: 'Component delete succeed',
|
|
1110
1144
|
description: `${child.meta.title} is successfully deleted for ${newBlocklet.meta.title}.`,
|
|
1111
1145
|
entityType: 'blocklet',
|
|
1112
1146
|
entityId: newBlocklet.meta.did,
|
|
@@ -1434,6 +1468,45 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
1434
1468
|
|
|
1435
1469
|
this.configSynchronizer.syncComponentConfig(childDid, rootDid, { serverSk });
|
|
1436
1470
|
}
|
|
1471
|
+
|
|
1472
|
+
try {
|
|
1473
|
+
const observableConfigs = [
|
|
1474
|
+
BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_URL,
|
|
1475
|
+
BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_NAME,
|
|
1476
|
+
BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_DESCRIPTION,
|
|
1477
|
+
BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO,
|
|
1478
|
+
BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO_SQUARE,
|
|
1479
|
+
BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO_RECT,
|
|
1480
|
+
BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_LOGO_FAVICON,
|
|
1481
|
+
];
|
|
1482
|
+
|
|
1483
|
+
const shouldSendWalletNotification = observableConfigs.some((x) => newConfigs.some((y) => y.key === x));
|
|
1484
|
+
const receiverUsers = await this.teamManager.getOwnerAndAdminUsers(newState.appPid, 1);
|
|
1485
|
+
const receiver = receiverUsers.map((x) => x.did);
|
|
1486
|
+
|
|
1487
|
+
if (shouldSendWalletNotification && receiver) {
|
|
1488
|
+
const nodeInfo = await states.node.read();
|
|
1489
|
+
const blockletInfo = getBlockletInfo(newState, nodeInfo.sk);
|
|
1490
|
+
const walletExtra = await getWalletAppNotification(newState, blockletInfo);
|
|
1491
|
+
|
|
1492
|
+
const notification = {
|
|
1493
|
+
receiver,
|
|
1494
|
+
teamDid: newState.appPid,
|
|
1495
|
+
title: 'Blocklet Config Changed',
|
|
1496
|
+
description: `Blocklet ${blockletInfo.name} config changed`,
|
|
1497
|
+
action: `/blocklets/${did}/overview`,
|
|
1498
|
+
entityType: 'blocklet',
|
|
1499
|
+
entityId: newState.appPid,
|
|
1500
|
+
severity: 'success',
|
|
1501
|
+
blockletUrl: blockletInfo.appUrl,
|
|
1502
|
+
extra: { wallet: walletExtra },
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
await this.teamManager.createNotification(notification);
|
|
1506
|
+
}
|
|
1507
|
+
} catch (error) {
|
|
1508
|
+
logger.error('Failed to send wallet notification after updated config', { did, error });
|
|
1509
|
+
}
|
|
1437
1510
|
}
|
|
1438
1511
|
|
|
1439
1512
|
return newState;
|
|
@@ -2302,7 +2375,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
2302
2375
|
},
|
|
2303
2376
|
});
|
|
2304
2377
|
this._createNotification(did, {
|
|
2305
|
-
title: '',
|
|
2378
|
+
title: 'Component download failed',
|
|
2306
2379
|
description: `${childrenToDownload
|
|
2307
2380
|
.map((x) => `${x.meta.title}@${x.meta.version}`)
|
|
2308
2381
|
.join(', ')} download failed for ${title}: ${err.message}`,
|
|
@@ -2466,7 +2539,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
2466
2539
|
? `${getComponentNamesWithVersion(blocklet, componentDids)} is successfully started for ${blocklet.meta.title}.`
|
|
2467
2540
|
: `${blocklet.meta.title} is successfully started`;
|
|
2468
2541
|
this._createNotification(did, {
|
|
2469
|
-
title: '',
|
|
2542
|
+
title: 'Component start succeed',
|
|
2470
2543
|
description,
|
|
2471
2544
|
entityType: 'blocklet',
|
|
2472
2545
|
entityId: did,
|
|
@@ -2492,7 +2565,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
2492
2565
|
: `${blocklet.meta.title} start failed: ${error.message}`;
|
|
2493
2566
|
|
|
2494
2567
|
this._createNotification(did, {
|
|
2495
|
-
title: '',
|
|
2568
|
+
title: 'Component start failed',
|
|
2496
2569
|
description,
|
|
2497
2570
|
entityType: 'blocklet',
|
|
2498
2571
|
entityId: did,
|
|
@@ -2814,7 +2887,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
2814
2887
|
users,
|
|
2815
2888
|
}) {
|
|
2816
2889
|
this._createNotification(did, {
|
|
2817
|
-
title:
|
|
2890
|
+
title: title.en,
|
|
2818
2891
|
description: description.en,
|
|
2819
2892
|
entityType: 'blocklet',
|
|
2820
2893
|
entityId: did,
|
|
@@ -3221,16 +3294,25 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
3221
3294
|
}
|
|
3222
3295
|
|
|
3223
3296
|
if (createNotification) {
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3297
|
+
// 发送通知不阻塞后续安装流程
|
|
3298
|
+
try {
|
|
3299
|
+
const walletExtra = await getWalletAppNotification(blocklet);
|
|
3300
|
+
|
|
3301
|
+
this._createNotification(did, {
|
|
3302
|
+
title: 'Blocklet Installed',
|
|
3303
|
+
description: `Blocklet ${meta.title} is installed successfully. (Source: ${
|
|
3304
|
+
deployedFrom || fromBlockletSource(source)
|
|
3305
|
+
})`,
|
|
3306
|
+
action: `/blocklets/${did}/overview`,
|
|
3307
|
+
entityType: 'blocklet',
|
|
3308
|
+
entityId: did,
|
|
3309
|
+
severity: 'success',
|
|
3310
|
+
receiver: blocklet?.controller?.nftOwner,
|
|
3311
|
+
extra: { wallet: walletExtra },
|
|
3312
|
+
});
|
|
3313
|
+
} catch (error) {
|
|
3314
|
+
logger.error('create installed notification failed', { error, did });
|
|
3315
|
+
}
|
|
3234
3316
|
}
|
|
3235
3317
|
|
|
3236
3318
|
await this._rollbackCache.remove({ did: blocklet.meta.did });
|
|
@@ -3384,7 +3466,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
3384
3466
|
this.emit(notificationEvent, { ...blocklet, componentDids, context });
|
|
3385
3467
|
|
|
3386
3468
|
this._createNotification(did, {
|
|
3387
|
-
title:
|
|
3469
|
+
title: `Component ${actionName} succeed`,
|
|
3388
3470
|
description: `${getComponentNamesWithVersion(
|
|
3389
3471
|
newBlocklet,
|
|
3390
3472
|
componentDids
|
|
@@ -3440,7 +3522,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
3440
3522
|
});
|
|
3441
3523
|
|
|
3442
3524
|
this._createNotification(did, {
|
|
3443
|
-
title:
|
|
3525
|
+
title: `Component ${actionName} failed`,
|
|
3444
3526
|
description: `${getComponentNamesWithVersion(newBlocklet, componentDids)} ${actionName} failed for ${title}: ${
|
|
3445
3527
|
err.message
|
|
3446
3528
|
}.`,
|
|
@@ -3730,13 +3812,15 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
3730
3812
|
}${WELLKNOWN_BLOCKLET_ADMIN_PATH}`;
|
|
3731
3813
|
}
|
|
3732
3814
|
} catch (error) {
|
|
3733
|
-
logger.error('[_createNotification] get blocklet url failed', { error });
|
|
3815
|
+
logger.error('[_createNotification] get blocklet url failed', { did, error });
|
|
3734
3816
|
}
|
|
3735
3817
|
|
|
3736
3818
|
// if blocklet is external, no need to create notification in server
|
|
3737
3819
|
const extra = await states.blockletExtras.getMeta(did);
|
|
3738
3820
|
const isExternal = !!extra?.controller;
|
|
3739
|
-
|
|
3821
|
+
|
|
3822
|
+
// 如果指定了 receiver, 或者是内部 blocklet, 则创建 notification
|
|
3823
|
+
if (notification.receiver || !isExternal) {
|
|
3740
3824
|
await states.notification.create({ ...notification, blockletUrl });
|
|
3741
3825
|
}
|
|
3742
3826
|
await this.teamManager.createNotification({
|
|
@@ -3746,7 +3830,7 @@ class DiskBlockletManager extends BaseBlockletManager {
|
|
|
3746
3830
|
blockletUrl,
|
|
3747
3831
|
});
|
|
3748
3832
|
} catch (error) {
|
|
3749
|
-
logger.error('create notification failed', { error });
|
|
3833
|
+
logger.error('create notification failed', { did, error });
|
|
3750
3834
|
}
|
|
3751
3835
|
}
|
|
3752
3836
|
|
|
@@ -196,7 +196,7 @@ const installComponentFromUrl = async ({
|
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
manager._createNotification(rootDid, {
|
|
199
|
-
title:
|
|
199
|
+
title: `Component ${actionName} failed`,
|
|
200
200
|
description: `${getComponentNamesWithVersion(newBlocklet, componentDids)} ${actionName} failed for ${
|
|
201
201
|
newBlocklet.meta.title
|
|
202
202
|
}: ${err.message || 'queue exception'}.`,
|
|
@@ -151,7 +151,7 @@ const upgrade = async ({ updateId, componentDids, context, states, manager }) =>
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
manager._createNotification(did, {
|
|
154
|
-
title: '',
|
|
154
|
+
title: 'Component upgrade failed',
|
|
155
155
|
description: `${getComponentNamesWithVersion(oldBlocklet, componentDids)} upgrade failed for ${
|
|
156
156
|
oldBlocklet.meta.title
|
|
157
157
|
}: ${err.message || 'queue exception'}.`,
|
package/lib/event/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
BLOCKLET_CONFIGURABLE_KEY,
|
|
14
14
|
} = require('@blocklet/constant');
|
|
15
15
|
const { EVENTS, BACKUPS } = require('@abtnode/constant');
|
|
16
|
+
|
|
16
17
|
const { NodeMonitSender } = require('../monitor/node-monit-sender');
|
|
17
18
|
const handleInstanceInStore = require('../util/public-to-store');
|
|
18
19
|
const { isCLI } = require('../util');
|
|
@@ -66,7 +67,7 @@ module.exports = ({
|
|
|
66
67
|
};
|
|
67
68
|
|
|
68
69
|
// Listen events from eventHub and call eventHandler
|
|
69
|
-
[...Object.values(BlockletEvents), ...Object.values(EVENTS)].forEach((name) => {
|
|
70
|
+
[...Object.values(BlockletEvents), ...Object.values(TeamEvents), ...Object.values(EVENTS)].forEach((name) => {
|
|
70
71
|
eventHub.on(name, (data) => {
|
|
71
72
|
if (name === BlockletEvents.removed) {
|
|
72
73
|
// Cleanup cache in teamManager for every node instance
|
|
@@ -145,6 +146,7 @@ module.exports = ({
|
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
await teamAPI.refreshBlockletInterfacePermissions(blocklet.meta);
|
|
149
|
+
logger.info('refreshed blocklet interface permissions after installed', { did: blocklet.meta.did });
|
|
148
150
|
} catch (error) {
|
|
149
151
|
logger.error('create.url.mapping.error', { event: name, error });
|
|
150
152
|
notificationState.create({
|
package/lib/team/manager.js
CHANGED
|
@@ -137,11 +137,11 @@ class TeamManager extends EventEmitter {
|
|
|
137
137
|
return this.getState(teamDid, 'notification');
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
async createNotification({ teamDid, ...payload }) {
|
|
140
|
+
async createNotification({ teamDid, receiver, ...payload }) {
|
|
141
141
|
const notification = await this.getState(teamDid, 'notification');
|
|
142
142
|
const doc = await notification.create({ ...payload, teamDid });
|
|
143
143
|
const metaDid = await this.states.blocklet.getBlockletMetaDid(teamDid);
|
|
144
|
-
this.emit(EVENTS.NOTIFICATION_BLOCKLET_CREATE, { meta: { did: metaDid }, ...payload, ...doc, teamDid });
|
|
144
|
+
this.emit(EVENTS.NOTIFICATION_BLOCKLET_CREATE, { meta: { did: metaDid }, ...payload, ...doc, teamDid, receiver });
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
async getProjectState(teamDid) {
|
package/lib/util/blocklet.js
CHANGED
|
@@ -106,7 +106,6 @@ const { validate: validateEngine, get: getEngine } = require('../blocklet/manage
|
|
|
106
106
|
const isRequirementsSatisfied = require('./requirement');
|
|
107
107
|
const { getDidDomainForBlocklet } = require('./get-domain-for-blocklet');
|
|
108
108
|
const { expandBundle, findInterfacePortByName, prettyURL, templateReplace, getServerDidDomain } = require('./index');
|
|
109
|
-
const { installExternalDependencies } = require('./install-external-dependencies');
|
|
110
109
|
|
|
111
110
|
/**
|
|
112
111
|
* get blocklet engine info, default is node
|
|
@@ -565,9 +564,6 @@ const startBlockletProcess = async (
|
|
|
565
564
|
const env = getRuntimeEnvironments(b, nodeEnvironments, ancestors);
|
|
566
565
|
const startedAt = Date.now();
|
|
567
566
|
|
|
568
|
-
// install external dependencies
|
|
569
|
-
await Promise.resolve(installExternalDependencies(b, { env }));
|
|
570
|
-
|
|
571
567
|
// run hook
|
|
572
568
|
await preFlight(b, { env });
|
|
573
569
|
|
|
@@ -2,27 +2,38 @@ const { spawnSync } = require('child_process');
|
|
|
2
2
|
const fs = require('fs-extra');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
|
-
function installExternalDependencies(
|
|
6
|
-
if (!
|
|
7
|
-
throw new Error('
|
|
5
|
+
function installExternalDependencies(appDir) {
|
|
6
|
+
if (!appDir) {
|
|
7
|
+
throw new Error('appDir is required');
|
|
8
|
+
}
|
|
9
|
+
if (!fs.existsSync(appDir)) {
|
|
10
|
+
throw new Error(`not a correct appDir directory: ${appDir}`);
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
// 读取 BLOCKLET_APP_DIR 的 package.json
|
|
11
|
-
const packageJsonPath = path.resolve(
|
|
14
|
+
const packageJsonPath = path.resolve(appDir, 'package.json');
|
|
15
|
+
|
|
12
16
|
if (!fs.existsSync(packageJsonPath)) {
|
|
13
17
|
return;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
const packageJson = fs.readJsonSync(packageJsonPath);
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
// FIXME: 梁柱, 等未来所有的 blocklet 使用了正式版, 废弃 singleExternals
|
|
23
|
+
const { singleExternals, blockletExternalDependencies } = packageJson;
|
|
24
|
+
const externals = singleExternals || blockletExternalDependencies;
|
|
25
|
+
if (!externals || !externals?.length) {
|
|
19
26
|
return;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
const result = spawnSync(
|
|
23
|
-
cwd:
|
|
29
|
+
const result = spawnSync('npm', ['install'], {
|
|
30
|
+
cwd: appDir,
|
|
24
31
|
stdio: 'pipe',
|
|
25
32
|
shell: true,
|
|
33
|
+
env: {
|
|
34
|
+
...process.env,
|
|
35
|
+
NODE_ENV: 'production',
|
|
36
|
+
},
|
|
26
37
|
});
|
|
27
38
|
|
|
28
39
|
if (result.status !== 0 && result.stderr && result.stderr.toString().trim()) {
|
package/lib/webhook/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const logger = require('@abtnode/logger')('@abtnode/core:webhook:index');
|
|
2
|
-
|
|
3
2
|
const { evaluateURLs } = require('@abtnode/util/lib/url-evaluation');
|
|
4
3
|
const checkURLAccessible = require('@abtnode/util/lib/url-evaluation/check-accessible-node');
|
|
5
4
|
const { EVENTS } = require('@abtnode/constant');
|
|
5
|
+
const isEmpty = require('lodash/isEmpty');
|
|
6
|
+
|
|
6
7
|
const WebHookSender = require('./sender');
|
|
7
8
|
const WalletSender = require('./sender/wallet');
|
|
8
9
|
const createQueue = require('../util/queue');
|
|
@@ -78,7 +79,7 @@ module.exports = ({ events, dataDirs, instance }) => {
|
|
|
78
79
|
const webhookState = states.webhook;
|
|
79
80
|
const notification = states.notification; // eslint-disable-line
|
|
80
81
|
|
|
81
|
-
const sendMessage = async (message) => {
|
|
82
|
+
const sendMessage = async ({ extra, ...message } = {}) => {
|
|
82
83
|
try {
|
|
83
84
|
const webhookList = await webhookState.list();
|
|
84
85
|
const nodeInfo = await nodeState.read();
|
|
@@ -98,7 +99,7 @@ module.exports = ({ events, dataDirs, instance }) => {
|
|
|
98
99
|
const senderInstance = WebHookSender.getMessageSender(item.type);
|
|
99
100
|
senderFns[item.type] = senderInstance.send.bind(senderInstance);
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
+
let options = { ...message, nodeInfo, node: instance };
|
|
102
103
|
if (item.type === 'slack') {
|
|
103
104
|
// eslint-disable-next-line
|
|
104
105
|
options.urlInfo = await getSlackUrlInfo({
|
|
@@ -106,7 +107,10 @@ module.exports = ({ events, dataDirs, instance }) => {
|
|
|
106
107
|
path: message.action,
|
|
107
108
|
serverUrls: baseUrls,
|
|
108
109
|
});
|
|
110
|
+
} else if (item.type === WalletSender.type && !isEmpty(extra?.wallet)) {
|
|
111
|
+
options = { ...options, ...extra.wallet };
|
|
109
112
|
}
|
|
113
|
+
|
|
110
114
|
try {
|
|
111
115
|
// eslint-disable-next-line
|
|
112
116
|
await senderFns[item.type](item.params, options);
|
|
@@ -135,9 +139,9 @@ module.exports = ({ events, dataDirs, instance }) => {
|
|
|
135
139
|
|
|
136
140
|
[EVENTS.NOTIFICATION_CREATE, EVENTS.NOTIFICATION_BLOCKLET_CREATE].forEach((event) => {
|
|
137
141
|
events.on(event, (data) => {
|
|
138
|
-
const { title, description, severity, action, entityType, blockletUrl, entityId } = data;
|
|
139
|
-
if (!reduceQueue({ title, description, entityType, entityId, severity })) {
|
|
140
|
-
queue.push({ title, description, status: severity, action, entityType, blockletUrl });
|
|
142
|
+
const { title, description, severity, action, entityType, blockletUrl, entityId, extra, receiver } = data;
|
|
143
|
+
if (!reduceQueue({ title, description, entityType, entityId, severity, extra })) {
|
|
144
|
+
queue.push({ title, description, status: severity, action, entityType, blockletUrl, extra, receiver });
|
|
141
145
|
}
|
|
142
146
|
});
|
|
143
147
|
});
|
|
@@ -5,7 +5,7 @@ const BaseSender = require('../base');
|
|
|
5
5
|
|
|
6
6
|
class WalletSender extends BaseSender {
|
|
7
7
|
async send(params, data = {}) {
|
|
8
|
-
const { title, description, nodeInfo, node } = data;
|
|
8
|
+
const { title, description, nodeInfo, node, receiver, actions, attachments } = data;
|
|
9
9
|
|
|
10
10
|
try {
|
|
11
11
|
const sender = {
|
|
@@ -17,28 +17,37 @@ class WalletSender extends BaseSender {
|
|
|
17
17
|
const message = {
|
|
18
18
|
title,
|
|
19
19
|
body: description,
|
|
20
|
+
actions,
|
|
21
|
+
attachments,
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
let to = [];
|
|
25
|
+
|
|
26
|
+
if (receiver) {
|
|
27
|
+
to = Array.isArray(receiver) ? receiver : [receiver];
|
|
28
|
+
} else {
|
|
29
|
+
const { users } = await node.getUsers({
|
|
30
|
+
teamDid: nodeInfo.did,
|
|
31
|
+
paging: { pageSize: 100 },
|
|
32
|
+
query: { includePassports: true },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
to = users
|
|
36
|
+
.filter(
|
|
37
|
+
(x) =>
|
|
38
|
+
x.approved &&
|
|
39
|
+
(x.passports || []).some(
|
|
40
|
+
(y) => [ROLES.OWNER, ROLES.ADMIN].includes(y.name) && y.status === PASSPORT_STATUS.VALID
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
.map((x) => x.did);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!to.length) {
|
|
38
47
|
return;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
await sendToUser(
|
|
50
|
+
await sendToUser(to, message, sender, process.env.ABT_NODE_SERVICE_PORT);
|
|
42
51
|
} catch (error) {
|
|
43
52
|
delete error.request;
|
|
44
53
|
delete error.response;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.24-beta-
|
|
6
|
+
"version": "1.16.24-beta-08e03567",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,19 +19,19 @@
|
|
|
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.24-beta-
|
|
23
|
-
"@abtnode/auth": "1.16.24-beta-
|
|
24
|
-
"@abtnode/certificate-manager": "1.16.24-beta-
|
|
25
|
-
"@abtnode/constant": "1.16.24-beta-
|
|
26
|
-
"@abtnode/cron": "1.16.24-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.24-beta-
|
|
28
|
-
"@abtnode/models": "1.16.24-beta-
|
|
29
|
-
"@abtnode/queue": "1.16.24-beta-
|
|
30
|
-
"@abtnode/rbac": "1.16.24-beta-
|
|
31
|
-
"@abtnode/router-provider": "1.16.24-beta-
|
|
32
|
-
"@abtnode/static-server": "1.16.24-beta-
|
|
33
|
-
"@abtnode/timemachine": "1.16.24-beta-
|
|
34
|
-
"@abtnode/util": "1.16.24-beta-
|
|
22
|
+
"@abtnode/analytics": "1.16.24-beta-08e03567",
|
|
23
|
+
"@abtnode/auth": "1.16.24-beta-08e03567",
|
|
24
|
+
"@abtnode/certificate-manager": "1.16.24-beta-08e03567",
|
|
25
|
+
"@abtnode/constant": "1.16.24-beta-08e03567",
|
|
26
|
+
"@abtnode/cron": "1.16.24-beta-08e03567",
|
|
27
|
+
"@abtnode/logger": "1.16.24-beta-08e03567",
|
|
28
|
+
"@abtnode/models": "1.16.24-beta-08e03567",
|
|
29
|
+
"@abtnode/queue": "1.16.24-beta-08e03567",
|
|
30
|
+
"@abtnode/rbac": "1.16.24-beta-08e03567",
|
|
31
|
+
"@abtnode/router-provider": "1.16.24-beta-08e03567",
|
|
32
|
+
"@abtnode/static-server": "1.16.24-beta-08e03567",
|
|
33
|
+
"@abtnode/timemachine": "1.16.24-beta-08e03567",
|
|
34
|
+
"@abtnode/util": "1.16.24-beta-08e03567",
|
|
35
35
|
"@arcblock/did": "1.18.110",
|
|
36
36
|
"@arcblock/did-auth": "1.18.110",
|
|
37
37
|
"@arcblock/did-ext": "^1.18.110",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"@arcblock/pm2-events": "^0.0.5",
|
|
43
43
|
"@arcblock/validator": "^1.18.110",
|
|
44
44
|
"@arcblock/vc": "1.18.110",
|
|
45
|
-
"@blocklet/constant": "1.16.24-beta-
|
|
46
|
-
"@blocklet/env": "1.16.24-beta-
|
|
47
|
-
"@blocklet/meta": "1.16.24-beta-
|
|
48
|
-
"@blocklet/resolver": "1.16.24-beta-
|
|
49
|
-
"@blocklet/sdk": "1.16.24-beta-
|
|
50
|
-
"@did-space/client": "^0.3.
|
|
45
|
+
"@blocklet/constant": "1.16.24-beta-08e03567",
|
|
46
|
+
"@blocklet/env": "1.16.24-beta-08e03567",
|
|
47
|
+
"@blocklet/meta": "1.16.24-beta-08e03567",
|
|
48
|
+
"@blocklet/resolver": "1.16.24-beta-08e03567",
|
|
49
|
+
"@blocklet/sdk": "1.16.24-beta-08e03567",
|
|
50
|
+
"@did-space/client": "^0.3.66",
|
|
51
51
|
"@fidm/x509": "^1.2.1",
|
|
52
52
|
"@ocap/mcrypto": "1.18.110",
|
|
53
53
|
"@ocap/util": "1.18.110",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"jest": "^29.7.0",
|
|
103
103
|
"unzipper": "^0.10.11"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "464a7b3b6dd7f205d828e6e4f48f37e80741f762"
|
|
106
106
|
}
|