@abtnode/blocklet-services 1.16.54-beta-20251029-055649-a9143beb → 1.16.54-beta-20251029-230008-54c9843b

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/api/index.js CHANGED
@@ -62,7 +62,6 @@ const states = require('./state/index');
62
62
  const { init: initNotification } = require('./services/notification');
63
63
  const { init: initKyc } = require('./services/kyc');
64
64
  const { init: initRelay } = require('./services/relay');
65
- // const BlockletEventsNotifier = require('./services/notification/blocklet-events-notifier');
66
65
  const notificationQueue = require('./services/notification/queue');
67
66
  const { init: initAuth } = require('./services/auth');
68
67
  const { init: initDashboard } = require('./services/dashboard');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.54-beta-20251029-055649-a9143beb",
6
+ "version": "1.16.54-beta-20251029-230008-54c9843b",
7
7
  "description": "Provide unified services for every blocklet",
8
8
  "main": "api/index.js",
9
9
  "files": [
@@ -34,17 +34,17 @@
34
34
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
35
35
  "license": "Apache-2.0",
36
36
  "dependencies": {
37
- "@abtnode/analytics": "1.16.54-beta-20251029-055649-a9143beb",
38
- "@abtnode/auth": "1.16.54-beta-20251029-055649-a9143beb",
39
- "@abtnode/connect-storage": "1.16.54-beta-20251029-055649-a9143beb",
40
- "@abtnode/constant": "1.16.54-beta-20251029-055649-a9143beb",
41
- "@abtnode/core": "1.16.54-beta-20251029-055649-a9143beb",
42
- "@abtnode/cron": "1.16.54-beta-20251029-055649-a9143beb",
43
- "@abtnode/db-cache": "1.16.54-beta-20251029-055649-a9143beb",
44
- "@abtnode/logger": "1.16.54-beta-20251029-055649-a9143beb",
45
- "@abtnode/models": "1.16.54-beta-20251029-055649-a9143beb",
46
- "@abtnode/router-templates": "1.16.54-beta-20251029-055649-a9143beb",
47
- "@abtnode/util": "1.16.54-beta-20251029-055649-a9143beb",
37
+ "@abtnode/analytics": "1.16.54-beta-20251029-230008-54c9843b",
38
+ "@abtnode/auth": "1.16.54-beta-20251029-230008-54c9843b",
39
+ "@abtnode/connect-storage": "1.16.54-beta-20251029-230008-54c9843b",
40
+ "@abtnode/constant": "1.16.54-beta-20251029-230008-54c9843b",
41
+ "@abtnode/core": "1.16.54-beta-20251029-230008-54c9843b",
42
+ "@abtnode/cron": "1.16.54-beta-20251029-230008-54c9843b",
43
+ "@abtnode/db-cache": "1.16.54-beta-20251029-230008-54c9843b",
44
+ "@abtnode/logger": "1.16.54-beta-20251029-230008-54c9843b",
45
+ "@abtnode/models": "1.16.54-beta-20251029-230008-54c9843b",
46
+ "@abtnode/router-templates": "1.16.54-beta-20251029-230008-54c9843b",
47
+ "@abtnode/util": "1.16.54-beta-20251029-230008-54c9843b",
48
48
  "@arcblock/did": "^1.26.3",
49
49
  "@arcblock/did-connect-js": "^1.26.3",
50
50
  "@arcblock/did-ext": "^1.26.3",
@@ -54,18 +54,18 @@
54
54
  "@arcblock/jwt": "^1.26.3",
55
55
  "@arcblock/validator": "^1.26.3",
56
56
  "@arcblock/ws": "^1.26.3",
57
- "@blocklet/constant": "1.16.54-beta-20251029-055649-a9143beb",
57
+ "@blocklet/constant": "1.16.54-beta-20251029-230008-54c9843b",
58
58
  "@blocklet/dbhub": "^0.2.9",
59
- "@blocklet/env": "1.16.54-beta-20251029-055649-a9143beb",
59
+ "@blocklet/env": "1.16.54-beta-20251029-230008-54c9843b",
60
60
  "@blocklet/error": "^0.2.5",
61
61
  "@blocklet/form-builder": "^0.1.12",
62
62
  "@blocklet/form-collector": "^0.1.8",
63
- "@blocklet/images": "1.16.54-beta-20251029-055649-a9143beb",
64
- "@blocklet/js-sdk": "1.16.54-beta-20251029-055649-a9143beb",
65
- "@blocklet/meta": "1.16.54-beta-20251029-055649-a9143beb",
66
- "@blocklet/rate-limit": "1.16.54-beta-20251029-055649-a9143beb",
67
- "@blocklet/sdk": "1.16.54-beta-20251029-055649-a9143beb",
68
- "@blocklet/server-js": "1.16.54-beta-20251029-055649-a9143beb",
63
+ "@blocklet/images": "1.16.54-beta-20251029-230008-54c9843b",
64
+ "@blocklet/js-sdk": "1.16.54-beta-20251029-230008-54c9843b",
65
+ "@blocklet/meta": "1.16.54-beta-20251029-230008-54c9843b",
66
+ "@blocklet/rate-limit": "1.16.54-beta-20251029-230008-54c9843b",
67
+ "@blocklet/sdk": "1.16.54-beta-20251029-230008-54c9843b",
68
+ "@blocklet/server-js": "1.16.54-beta-20251029-230008-54c9843b",
69
69
  "@blocklet/theme": "^3.1.53",
70
70
  "@blocklet/theme-builder": "0.4.7",
71
71
  "@blocklet/uploader-server": "^0.3.1",
@@ -125,7 +125,7 @@
125
125
  "whatwg-url": "14.0.0"
126
126
  },
127
127
  "devDependencies": {
128
- "@abtnode/ux": "1.16.54-beta-20251029-055649-a9143beb",
128
+ "@abtnode/ux": "1.16.54-beta-20251029-230008-54c9843b",
129
129
  "@arcblock/bridge": "^3.1.53",
130
130
  "@arcblock/did-connect-react": "^3.1.53",
131
131
  "@arcblock/icons": "^3.1.53",
@@ -135,7 +135,7 @@
135
135
  "@blocklet/did-space-react": "^1.1.35",
136
136
  "@blocklet/launcher-layout": "^3.1.53",
137
137
  "@blocklet/payment-react": "^1.22.0",
138
- "@blocklet/tracker": "1.16.54-beta-20251029-055649-a9143beb",
138
+ "@blocklet/tracker": "1.16.54-beta-20251029-230008-54c9843b",
139
139
  "@blocklet/ui-react": "^3.1.53",
140
140
  "@blocklet/uploader": "^0.3.1",
141
141
  "@emotion/react": "^11.14.0",
@@ -215,5 +215,5 @@
215
215
  "url": "https://github.com/ArcBlock/blocklet-server/issues",
216
216
  "email": "shijun@arcblock.io"
217
217
  },
218
- "gitHead": "4ac4eebb4ade000c0fca21b1d542054a9dafd776"
218
+ "gitHead": "21cf7881f5759a9b82e1a852286f048af112bafa"
219
219
  }
@@ -1,215 +0,0 @@
1
- const get = require('lodash/get');
2
- const uniqBy = require('lodash/uniqBy');
3
- const uniq = require('lodash/uniq');
4
- const { isInstanceWorker } = require('@abtnode/util/lib/pm2/is-instence-worker');
5
- const JWT = require('@arcblock/jwt');
6
-
7
- const { ROLES } = require('@abtnode/constant');
8
- const { BlockletEvents, TeamEvents } = require('@blocklet/constant');
9
-
10
- const eventHub =
11
- process.env.NODE_ENV === 'test' ? require('@arcblock/event-hub/single') : require('@arcblock/event-hub');
12
-
13
- const logger = require('../../libs/logger')('notification');
14
- const cache = require('../../cache');
15
-
16
- const getComponentNamesWithVersion = (app) => {
17
- const { componentDids = [], children = [] } = app;
18
-
19
- const componentNames = uniq(componentDids).map((x) => {
20
- const component = children.find((y) => y.meta.did === x);
21
- return `${component.meta.title}@${component.meta.version}`;
22
- });
23
-
24
- return `${componentNames}`;
25
- };
26
-
27
- const messages = {
28
- [BlockletEvents.componentInstalled]: ({ data }) => ({
29
- title: {
30
- en: 'Component Installed Success',
31
- zh: '组件安装成功',
32
- },
33
- body: {
34
- en: `Component ${getComponentNamesWithVersion(data)} is installed successfully for ${data.meta.title}.`,
35
- zh: `${data.meta.title} 中的组件 ${getComponentNamesWithVersion(data)} 安装成功`,
36
- },
37
- }),
38
- [BlockletEvents.componentInstallFailed]: ({ data }) => ({
39
- title: {
40
- en: 'Component Install Failed',
41
- zh: '组件安装失败',
42
- },
43
- body: {
44
- en: `${getComponentNamesWithVersion(data)} installed failed for ${data.meta.title}: ${data?.error?.message}`,
45
- zh: `${data.meta.title} 中的组件 ${getComponentNamesWithVersion(data)} 安装失败: ${data?.error?.message}`,
46
- },
47
- }),
48
- [BlockletEvents.componentUpgraded]: ({ data }) => ({
49
- title: {
50
- en: 'Component Upgrade Success',
51
- zh: '组件升级成功',
52
- },
53
- body: {
54
- en: `${getComponentNamesWithVersion(data)} is upgraded successfully for ${data.meta.title}.`,
55
- zh: `${data.meta.title} 中的组件 ${getComponentNamesWithVersion(data)} 升级成功`,
56
- },
57
- }),
58
- [BlockletEvents.componentUpgradeFailed]: ({ data }) => ({
59
- title: {
60
- en: 'Component Upgrade Failed',
61
- zh: '组件升级失败',
62
- },
63
- body: {
64
- en: `${getComponentNamesWithVersion(data)} upgraded failed for ${data.meta.title}: ${data?.error?.message}`,
65
- zh: `${data.meta.title} 中的组件 ${getComponentNamesWithVersion(data)} 升级失败: ${data?.error?.message}`,
66
- },
67
- }),
68
- [BlockletEvents.componentRemoved]: ({ data }) => ({
69
- title: {
70
- en: 'Component Removed Success',
71
- zh: '组件删除成功',
72
- },
73
- body: {
74
- en: `${getComponentNamesWithVersion(data)} is removed successfully for ${data.meta.title}.`,
75
- zh: `${data.meta.title} 中的组件 ${getComponentNamesWithVersion(data)} 删除成功`,
76
- },
77
- }),
78
- [BlockletEvents.started]: ({ data = {} }) => {
79
- return {
80
- title: {
81
- en: 'Component Start Success',
82
- zh: '组件启动成功',
83
- },
84
- body: {
85
- en: `${getComponentNamesWithVersion(data)} started successfully for ${data.meta.title}.`,
86
- zh: `${data.meta.title} 中的组件 ${getComponentNamesWithVersion(data)} 启动成功`,
87
- },
88
- };
89
- },
90
-
91
- [BlockletEvents.startFailed]: ({ data }) => ({
92
- title: {
93
- en: 'Component Start Failed',
94
- zh: 'Component 启动失败',
95
- },
96
- body: {
97
- en: `${getComponentNamesWithVersion(data)} started failed: ${data.error?.message}`,
98
- zh: `${data.meta.title} 中的组件 ${getComponentNamesWithVersion(data)} 启动失败: ${data.error?.message}`,
99
- },
100
- }),
101
- [BlockletEvents.stopped]: ({ data = {} }) => {
102
- return {
103
- title: {
104
- en: 'Component Stop Success',
105
- zh: '组件已停止运行',
106
- },
107
- body: {
108
- en: `${
109
- data?.componentDids?.length ? getComponentNamesWithVersion(data) : 'All components'
110
- } stopped successfully for ${data.meta.title}.`,
111
- zh: `${data.meta.title}${
112
- data?.componentDids?.length ? `中的组件 ${getComponentNamesWithVersion(data)}` : ''
113
- } 已停止运行`,
114
- },
115
- };
116
- },
117
- [TeamEvents.userAdded]: ({ data }) => ({
118
- title: {
119
- en: 'New member join',
120
- zh: '新成员加入',
121
- },
122
- body: {
123
- en: `Member with Name (${data.user?.fullName}) and DID (${data.user?.did}) has joined this Blocklet`,
124
- zh: `成员 ${data.user?.fullName} (DID: ${data.user?.did}) 已加入此 Blocklet`,
125
- },
126
- }),
127
- };
128
-
129
- const DEFAULT_LOCALE = 'en';
130
-
131
- // eslint-disable-next-line no-unused-vars
132
- const init = ({ node, notificationService }) => {
133
- [
134
- BlockletEvents.componentInstalled,
135
- BlockletEvents.componentInstallFailed,
136
- BlockletEvents.componentUpgraded,
137
- BlockletEvents.componentUpgradeFailed,
138
- BlockletEvents.componentRemoved,
139
- BlockletEvents.started,
140
- BlockletEvents.startFailed,
141
- BlockletEvents.stopped,
142
-
143
- TeamEvents.userAdded,
144
-
145
- // The blocklet owner does not need to receive removed events
146
- // BlockletEvents.removed,
147
- ].forEach((eventName) => {
148
- eventHub.on(eventName, async (data) => {
149
- // Only first worker process handle blocklet event
150
- if (isInstanceWorker()) {
151
- return;
152
- }
153
-
154
- try {
155
- const did = get(data, 'meta.did') || get(data, 'teamDid');
156
-
157
- const error = get(data, 'error');
158
-
159
- const blockletInfo = await cache.getBlockletInfo({ did, node });
160
- const { wallet } = blockletInfo;
161
-
162
- // FIXME: BLOCKLET ADMIN is more than 50
163
- const { users: adminUsers } = await node.getUsers({
164
- teamDid: did,
165
- query: { approved: true, role: ROLES.ADMIN },
166
- paging: { pageSize: 50 },
167
- });
168
-
169
- const { users: ownerUsers } = await node.getUsers({
170
- teamDid: did,
171
- query: { approved: true, role: ROLES.OWNER },
172
- });
173
-
174
- const users = uniqBy((adminUsers || []).concat(ownerUsers).filter(Boolean), 'did');
175
-
176
- if (!users.length) {
177
- return;
178
- }
179
-
180
- const token = await JWT.sign(wallet.address, wallet.secretKey);
181
- const sender = { token, appDid: wallet.address };
182
-
183
- const message = messages[eventName]({ data, blockletInfo, error });
184
-
185
- // send message to each user
186
- users.forEach(({ did: userDid, locale = 'en' }) => {
187
- // eslint-disable-next-line no-unused-vars
188
- const input = {
189
- sender,
190
- receiver: userDid,
191
- notification: {
192
- title: message.title[locale] || message.title[DEFAULT_LOCALE],
193
- body: message.body[locale] || message.body[DEFAULT_LOCALE],
194
- source: 'app',
195
- },
196
- };
197
- // 注释原因:
198
- // 1. 重复逻辑,
199
- // a. 这里的消息监听是通过 this.emit() 推送的。然后通过 sendToUser 发送给用户。
200
- // 调用 this.emit() 的地方都有 _createNotification() 方法,在 _createNotification 方法中又 重新调用 this.emit() 方法将消息发送给用户;
201
- // 在 _createNotification() 方法中推送的事件不同,但是结果都会向用户推送相同的消息
202
- // 2. 存在的问题
203
- // a. 缺少用户信息,基于 L163~L174 代码可以看出这里获取的用户信息只有 teamDid 对应的 service 用户,没有 server 用户
204
- // notificationService.sendToUser.exec(input).catch((notificationError) => {
205
- // logger.error('sendToUser error', { error: notificationError, input });
206
- // });
207
- });
208
- } catch (error) {
209
- logger.error('Handle event failed', { eventName, error });
210
- }
211
- });
212
- });
213
- };
214
-
215
- module.exports = { init };