@blocklet/launcher-util 2.0.38 → 2.0.40
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/notification/index.js +8 -34
- package/package.json +5 -5
- package/lib/notification/email.js +0 -43
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
const BlockletNotification = require('@blocklet/sdk/service/notification');
|
|
2
|
-
const AuthClient = require('@blocklet/sdk/service/auth');
|
|
3
|
-
|
|
4
|
-
const email = require('./email');
|
|
5
|
-
|
|
6
|
-
const authClient = new AuthClient();
|
|
7
2
|
|
|
8
3
|
class Notification {
|
|
9
4
|
constructor({ logger, auth }) {
|
|
@@ -12,22 +7,23 @@ class Notification {
|
|
|
12
7
|
this.logger = logger || { info: console.info, error: console.error };
|
|
13
8
|
}
|
|
14
9
|
|
|
15
|
-
async sendNotification({ to, title, message,
|
|
10
|
+
async sendNotification({ to, title, message, actions, attachments = [], assetAddress }) {
|
|
16
11
|
try {
|
|
17
|
-
const payload = { title, body: message, actions: actions || [] };
|
|
12
|
+
const payload = { title, body: message, actions: actions || [], attachments: [...attachments] };
|
|
13
|
+
|
|
18
14
|
if (typeof assetAddress !== 'undefined') {
|
|
19
|
-
|
|
20
|
-
{
|
|
15
|
+
if (assetAddress) {
|
|
16
|
+
payload.attachments.push({
|
|
21
17
|
type: 'asset',
|
|
22
18
|
data: {
|
|
23
19
|
chainHost: this.auth.chainHost,
|
|
24
20
|
did: assetAddress,
|
|
25
21
|
},
|
|
26
|
-
}
|
|
27
|
-
|
|
22
|
+
});
|
|
23
|
+
}
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
await
|
|
26
|
+
await BlockletNotification.sendToUser(to, payload);
|
|
31
27
|
|
|
32
28
|
this.logger.info('text message was sent', { to, payload: JSON.stringify(payload, null, 2) });
|
|
33
29
|
} catch (error) {
|
|
@@ -35,28 +31,6 @@ class Notification {
|
|
|
35
31
|
throw error;
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
|
-
|
|
39
|
-
async send(to, payload) {
|
|
40
|
-
const tasks = [BlockletNotification.sendToUser(to, payload)];
|
|
41
|
-
|
|
42
|
-
if (this.auth.email) {
|
|
43
|
-
const { user } = await authClient.getUser(to);
|
|
44
|
-
if (user && user.email) {
|
|
45
|
-
tasks.push(this.sendToEmail(user.email, email.getEmailMessage(payload), { auth: this.auth.email }));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await Promise.all(tasks);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async sendToEmail(to, payload, emailConfig) {
|
|
53
|
-
try {
|
|
54
|
-
await email.send(to, payload, emailConfig);
|
|
55
|
-
this.logger.info('send email message successfully', { to });
|
|
56
|
-
} catch (error) {
|
|
57
|
-
this.logger.error('send email message failed', { error, to });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
34
|
}
|
|
61
35
|
|
|
62
36
|
module.exports = Notification;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/launcher-util",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.40",
|
|
4
4
|
"description": "Common constants",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"constant"
|
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
"url": "https://github.com/blocklet/launcher/issues"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@blocklet/sdk": "^1.16.
|
|
35
|
-
"@ocap/util": "^1.18.
|
|
34
|
+
"@blocklet/sdk": "^1.16.7",
|
|
35
|
+
"@ocap/util": "^1.18.80",
|
|
36
36
|
"axios": "^0.26.1",
|
|
37
37
|
"flat": "^5.0.2",
|
|
38
38
|
"lodash.get": "^4.4.2",
|
|
39
39
|
"lodash.pick": "^4.4.0",
|
|
40
40
|
"moment": "^2.29.4",
|
|
41
41
|
"moment-timezone": "^0.5.43",
|
|
42
|
-
"nodemailer": "^6.9.
|
|
42
|
+
"nodemailer": "^6.9.2",
|
|
43
43
|
"url-join": "^4.0.1"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "afb153f2b5f798efa48def402a91798b2d3a7919"
|
|
46
46
|
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const nodemailer = require('nodemailer');
|
|
2
|
-
const get = require('lodash.get');
|
|
3
|
-
const { getExplorerUrl } = require('../util');
|
|
4
|
-
|
|
5
|
-
const send = (to, payload, { auth }) => {
|
|
6
|
-
const transporter = nodemailer.createTransport({
|
|
7
|
-
host: auth.host,
|
|
8
|
-
port: auth.port,
|
|
9
|
-
secure: false,
|
|
10
|
-
auth: { user: auth.user, pass: auth.pass },
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return transporter.sendMail({ from: auth.from, to, subject: payload.subject, html: payload.html });
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const getEmailMessage = ({ title, body, actions, attachments }) => {
|
|
17
|
-
let html = `<p>${body}</p>`;
|
|
18
|
-
if (Array.isArray(actions) && actions.length > 0) {
|
|
19
|
-
html += '<p>';
|
|
20
|
-
|
|
21
|
-
actions.forEach((action) => {
|
|
22
|
-
html += `<p>${action.name}: <a href="${action.link}">${action.link}</a></p>`;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
html += '</p>';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const asset = (attachments || []).find((item) => item.type === 'asset');
|
|
29
|
-
if (asset) {
|
|
30
|
-
html += `<p>NFT: ${getExplorerUrl({
|
|
31
|
-
address: get(asset, 'data.did'),
|
|
32
|
-
type: 'assets',
|
|
33
|
-
chainHost: get(asset, 'data.chainHost'),
|
|
34
|
-
})}</p>`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
subject: title,
|
|
39
|
-
html,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
module.exports = { send, getEmailMessage };
|