@abtnode/blocklet-services 1.16.20 → 1.16.21-beta-46c675eb

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.
@@ -9,17 +9,23 @@ const components_1 = require("@react-email/components");
9
9
  // @ts-ignore
10
10
  const constant_1 = require("@abtnode/constant");
11
11
  const copyright_1 = __importDefault(require("./copyright"));
12
- function Footer({ showLogo = false, showCopyright = false, showBlocklet = true, appInfo, locale = 'en', allowUnsubscribe = true, unsubscribeToken, receiverEmail, }) {
12
+ function Footer({ showLogo = false, showCopyright = false, showBlocklet = true, appInfo, locale = 'en', unsubscribeToken, userInfo, }) {
13
+ const userInfoName = (userInfo === null || userInfo === void 0 ? void 0 : userInfo.fullName) || (userInfo === null || userInfo === void 0 ? void 0 : userInfo.email);
14
+ const userInfoDescription = userInfo === null || userInfo === void 0 ? void 0 : userInfo.did;
15
+ let userInfoContent = userInfoName;
16
+ if (userInfoDescription) {
17
+ userInfoContent += ` <${userInfoDescription}>`;
18
+ }
13
19
  function UnsubscribeContent() {
14
- if (!unsubscribeToken) {
20
+ if (!userInfoContent) {
15
21
  return null;
16
22
  }
17
23
  if (locale === 'zh') {
18
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("br", {}), "\u8FD9\u5C01\u90AE\u4EF6\u7531\u7CFB\u7EDF\u53D1\u9001\u7ED9 ", receiverEmail, ". \u5982\u679C\u60A8\u4E0D\u60F3\u518D\u6536\u5230\u6B64\u7C7B\u90AE\u4EF6\uFF0C\u60A8\u53EF\u4EE5", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, Object.assign({ href: (0, url_join_1.default)(appInfo.url, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/user/unsubscribe?token=${unsubscribeToken}`), style: Object.assign(Object.assign({}, link), { color: '#898989', fontSize: '12px' }), target: "_blank" }, { children: "\u9000\u8BA2" }))] }));
24
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("br", {}), "\u8FD9\u5C01\u90AE\u4EF6\u7531\u7CFB\u7EDF\u53D1\u9001\u7ED9 ", userInfoContent, "\u3002", unsubscribeToken ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["\u5982\u679C\u60A8\u4E0D\u60F3\u518D\u6536\u5230\u6B64\u7C7B\u90AE\u4EF6\uFF0C\u60A8\u53EF\u4EE5", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, Object.assign({ href: (0, url_join_1.default)(appInfo.url, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/user/unsubscribe?token=${unsubscribeToken}`), style: Object.assign(Object.assign({}, link), { color: '#898989', fontSize: '12px' }), target: "_blank" }, { children: "\u9000\u8BA2" }))] })) : null] }));
19
25
  }
20
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("br", {}), "This email was sent to ", receiverEmail, " . If you'd rather not receive this kind of email, you can", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, Object.assign({ href: (0, url_join_1.default)(appInfo.url, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/user/unsubscribe?token=${unsubscribeToken}`), style: Object.assign(Object.assign({}, link), { color: '#898989', fontSize: '12px' }), target: "_blank" }, { children: "unsubscribe" }))] }));
26
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("br", {}), "This email was sent to ", userInfoContent, " .", ' ', unsubscribeToken ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["If you'd rather not receive this kind of email, you can", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, Object.assign({ href: (0, url_join_1.default)(appInfo.url, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/user/unsubscribe?token=${unsubscribeToken}`), style: Object.assign(Object.assign({}, link), { color: '#898989', fontSize: '12px' }), target: "_blank" }, { children: "unsubscribe" }))] })) : null] }));
21
27
  }
22
- return ((0, jsx_runtime_1.jsxs)(components_1.Section, { children: [showLogo && (0, jsx_runtime_1.jsx)(components_1.Img, { src: appInfo.logo, width: "32", height: "32", alt: appInfo.title }), showBlocklet && ((0, jsx_runtime_1.jsxs)(components_1.Text, Object.assign({ style: footer }, { children: [(0, jsx_runtime_1.jsx)(components_1.Link, Object.assign({ href: appInfo.url, target: "_blank", style: Object.assign(Object.assign({}, link), { color: '#898989' }) }, { children: appInfo.title })), allowUnsubscribe && (0, jsx_runtime_1.jsx)(UnsubscribeContent, {})] }))), showCopyright && (0, jsx_runtime_1.jsx)(copyright_1.default, {})] }));
28
+ return ((0, jsx_runtime_1.jsxs)(components_1.Section, { children: [showLogo && (0, jsx_runtime_1.jsx)(components_1.Img, { src: appInfo.logo, width: "32", height: "32", alt: appInfo.title }), showBlocklet && ((0, jsx_runtime_1.jsxs)(components_1.Text, Object.assign({ style: footer }, { children: [(0, jsx_runtime_1.jsx)(components_1.Link, Object.assign({ href: appInfo.url, target: "_blank", style: Object.assign(Object.assign({}, link), { color: '#898989' }) }, { children: appInfo.title })), (0, jsx_runtime_1.jsx)(UnsubscribeContent, {})] }))), showCopyright && (0, jsx_runtime_1.jsx)(copyright_1.default, {})] }));
23
29
  }
24
30
  exports.default = Footer;
25
31
  const footer = {
@@ -10,8 +10,8 @@ const footer_1 = __importDefault(require("../components/footer"));
10
10
  const content_1 = __importDefault(require("../components/content"));
11
11
  const layout_1 = __importDefault(require("../components/layout"));
12
12
  const header_1 = __importDefault(require("../components/header"));
13
- const NotificationEmail = ({ title, body = '', subject, attachments = [], actions = [], appInfo, locale = 'en', allowUnsubscribe = true, severity = 'normal', unsubscribeToken, receiverEmail, }) => {
14
- return ((0, jsx_runtime_1.jsxs)(layout_1.default, Object.assign({ mainStyle: main, subject: subject }, { children: [(0, jsx_runtime_1.jsx)(components_1.Preview, { children: subject }), (0, jsx_runtime_1.jsx)(header_1.default, { appInfo: appInfo }), (0, jsx_runtime_1.jsx)(content_1.default, { style: container, title: title, content: body, attachments: attachments, actions: actions, locale: locale, severity: severity }), (0, jsx_runtime_1.jsx)(footer_1.default, { showCopyright: false, showBlocklet: true, appInfo: appInfo, locale: locale, allowUnsubscribe: allowUnsubscribe, unsubscribeToken: unsubscribeToken, receiverEmail: receiverEmail })] })));
13
+ const NotificationEmail = ({ title, body = '', subject, attachments = [], actions = [], appInfo, locale = 'en', severity = 'normal', unsubscribeToken, userInfo, }) => {
14
+ return ((0, jsx_runtime_1.jsxs)(layout_1.default, Object.assign({ mainStyle: main, subject: subject }, { children: [(0, jsx_runtime_1.jsx)(components_1.Preview, { children: subject }), (0, jsx_runtime_1.jsx)(header_1.default, { appInfo: appInfo }), (0, jsx_runtime_1.jsx)(content_1.default, { style: container, title: title, content: body, attachments: attachments, actions: actions, locale: locale, severity: severity }), (0, jsx_runtime_1.jsx)(footer_1.default, { showCopyright: false, showBlocklet: true, appInfo: appInfo, locale: locale, unsubscribeToken: unsubscribeToken, userInfo: userInfo })] })));
15
15
  };
16
16
  exports.NotificationEmail = NotificationEmail;
17
17
  exports.default = exports.NotificationEmail;
package/api/libs/email.js CHANGED
@@ -12,7 +12,7 @@ const schemaEmail = Joi.string().email().required();
12
12
 
13
13
  const validateEmail = schemaEmail.validateAsync.bind(schemaEmail);
14
14
 
15
- async function sendEmail(receiver, notification, { teamDid, node, locale, allowUnsubscribe = true, unsubscribeToken }) {
15
+ async function sendEmail(receiver, notification, { teamDid, node, locale, unsubscribeToken, userInfo = {} }) {
16
16
  if (!receiver) {
17
17
  throw new Error('receiver is required');
18
18
  }
@@ -60,9 +60,11 @@ async function sendEmail(receiver, notification, { teamDid, node, locale, allowU
60
60
  ...notification,
61
61
  appInfo,
62
62
  locale,
63
- allowUnsubscribe,
64
63
  unsubscribeToken,
65
- receiverEmail: receiver,
64
+ userInfo: {
65
+ ...userInfo,
66
+ email: receiver,
67
+ },
66
68
  })
67
69
  );
68
70
  const emailData = {
@@ -20,6 +20,7 @@ const { ensureSenderApp, getSenderServer, parseNotification, broadcast, EVENTS }
20
20
  const states = require('../../state');
21
21
  const { validateEmail, sendEmail } = require('../../libs/email');
22
22
  const { getBlockletInfo } = require('../../cache');
23
+ const { getUserAvatarUrl } = require('../../util/federated');
23
24
 
24
25
  /**
25
26
  * app send notification to user
@@ -48,6 +49,7 @@ const sendToUserDid = async ({ sender, receiver: rawDid, notification, options,
48
49
 
49
50
  // sender.appDid 就是当前 blockletDid,通知的发送方就是这个 blocklet 本身
50
51
  const teamDid = sender.appDid;
52
+ const blocklet = await node.getBlocklet({ did: teamDid });
51
53
  const blockletInfo = await getBlockletInfo({ did: teamDid, node });
52
54
  const { wallet } = blockletInfo;
53
55
 
@@ -74,7 +76,9 @@ const sendToUserDid = async ({ sender, receiver: rawDid, notification, options,
74
76
  receiverEmailList.push({
75
77
  email: receiverEmail,
76
78
  locale: user?.locale || 'en',
77
- userDid: receiverDid,
79
+ did: receiverDid,
80
+ fullName: user?.fullName,
81
+ avatar: user?.avatar,
78
82
  });
79
83
  } catch (error) {
80
84
  logger.error(`Skip invalid email receiver: ${receiverEmail}`, { error });
@@ -123,11 +127,11 @@ const sendToUserDid = async ({ sender, receiver: rawDid, notification, options,
123
127
  // NOTICE: 目前只有 notification 的通知能够发送邮件,并且 type 可能为 undefined
124
128
  if ([undefined, NOTIFICATION_TYPES.NOTIFICATION].includes(data.type)) {
125
129
  const limit = pLimit(10);
126
- const sendEmailList = receiverEmailList.map((receiverEmail) => {
130
+ const sendEmailList = receiverEmailList.map((receiverItem) => {
127
131
  return limit(async () => {
128
132
  try {
129
133
  const now = Math.floor(Date.now() / 1000);
130
- const userDid = receiverEmail?.userDid;
134
+ const userDid = receiverItem?.did;
131
135
  const unsubscribeToken = userDid
132
136
  ? JWT.signV2(wallet.address, wallet.secretKey, {
133
137
  userDid,
@@ -136,11 +140,16 @@ const sendToUserDid = async ({ sender, receiver: rawDid, notification, options,
136
140
  exp: String(now + 30 * 24 * 60 * 60),
137
141
  })
138
142
  : null;
139
- await sendEmail(receiverEmail.email, data, {
143
+ await sendEmail(receiverItem.email, data, {
140
144
  teamDid,
141
145
  node,
142
- locale: receiverEmail.locale,
146
+ locale: receiverItem.locale,
143
147
  unsubscribeToken,
148
+ userInfo: {
149
+ did: userDid,
150
+ fullName: receiverItem.fullName,
151
+ avatar: getUserAvatarUrl(receiverItem.avatar, blocklet),
152
+ },
144
153
  });
145
154
  } catch (error) {
146
155
  logger.error('Failed to send email', { error });
@@ -301,7 +310,6 @@ const sendToMail = async ({ sender, receiver, notification, options, node }) =>
301
310
  teamDid: sender.appDid,
302
311
  node,
303
312
  locale,
304
- allowUnsubscribe: false,
305
313
  });
306
314
  })
307
315
  );
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.20",
6
+ "version": "1.16.21-beta-46c675eb",
7
7
  "description": "Provide unified services for every blocklet",
8
8
  "main": "api/index.js",
9
9
  "files": [
@@ -32,17 +32,17 @@
32
32
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
33
33
  "license": "Apache-2.0",
34
34
  "dependencies": {
35
- "@abtnode/analytics": "1.16.20",
36
- "@abtnode/auth": "1.16.20",
37
- "@abtnode/client": "1.16.20",
38
- "@abtnode/connect-storage": "1.16.20",
39
- "@abtnode/constant": "1.16.20",
40
- "@abtnode/core": "1.16.20",
41
- "@abtnode/cron": "1.16.20",
42
- "@abtnode/logger": "1.16.20",
43
- "@abtnode/models": "1.16.20",
44
- "@abtnode/router-templates": "1.16.20",
45
- "@abtnode/util": "1.16.20",
35
+ "@abtnode/analytics": "1.16.21-beta-46c675eb",
36
+ "@abtnode/auth": "1.16.21-beta-46c675eb",
37
+ "@abtnode/client": "1.16.21-beta-46c675eb",
38
+ "@abtnode/connect-storage": "1.16.21-beta-46c675eb",
39
+ "@abtnode/constant": "1.16.21-beta-46c675eb",
40
+ "@abtnode/core": "1.16.21-beta-46c675eb",
41
+ "@abtnode/cron": "1.16.21-beta-46c675eb",
42
+ "@abtnode/logger": "1.16.21-beta-46c675eb",
43
+ "@abtnode/models": "1.16.21-beta-46c675eb",
44
+ "@abtnode/router-templates": "1.16.21-beta-46c675eb",
45
+ "@abtnode/util": "1.16.21-beta-46c675eb",
46
46
  "@arcblock/did": "^1.18.105",
47
47
  "@arcblock/did-auth": "1.18.105",
48
48
  "@arcblock/did-ext": "^1.18.105",
@@ -51,11 +51,11 @@
51
51
  "@arcblock/jwt": "1.18.105",
52
52
  "@arcblock/validator": "^1.18.105",
53
53
  "@arcblock/ws": "1.18.105",
54
- "@blocklet/constant": "1.16.20",
54
+ "@blocklet/constant": "1.16.21-beta-46c675eb",
55
55
  "@blocklet/form-builder": "^0.1.11",
56
56
  "@blocklet/form-collector": "^0.1.6",
57
- "@blocklet/meta": "1.16.20",
58
- "@blocklet/sdk": "1.16.20",
57
+ "@blocklet/meta": "1.16.21-beta-46c675eb",
58
+ "@blocklet/sdk": "1.16.21-beta-46c675eb",
59
59
  "@did-connect/authenticator": "^2.2.1",
60
60
  "@did-connect/relay-adapter-express": "^2.2.1",
61
61
  "@ocap/client": "1.18.105",
@@ -94,12 +94,12 @@
94
94
  },
95
95
  "resolutions": {},
96
96
  "devDependencies": {
97
- "@abtnode/ux": "1.16.20",
97
+ "@abtnode/ux": "1.16.21-beta-46c675eb",
98
98
  "@arcblock/did-connect": "^2.8.22",
99
99
  "@arcblock/icons": "^2.8.22",
100
100
  "@arcblock/ux": "^2.8.22",
101
101
  "@blocklet/launcher-layout": "2.2.48",
102
- "@blocklet/tracker": "1.16.20",
102
+ "@blocklet/tracker": "1.16.21-beta-46c675eb",
103
103
  "@blocklet/ui-react": "^2.8.22",
104
104
  "@emotion/react": "^11.10.4",
105
105
  "@emotion/styled": "^11.10.4",
@@ -171,5 +171,5 @@
171
171
  "url": "https://github.com/ArcBlock/blocklet-server/issues",
172
172
  "email": "shijun@arcblock.io"
173
173
  },
174
- "gitHead": "715efa6465e9143c23b152b5ef639266ea834843"
174
+ "gitHead": "a852c7930e8bc84c641579d8e4c009accf478078"
175
175
  }