@abtnode/blocklet-services 1.16.16-beta-2e5e3db7 → 1.16.16-beta-cfa95fa6

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.
Files changed (93) hide show
  1. package/api/emails/components/copyright.js +3 -1
  2. package/api/index.js +2 -2
  3. package/api/middlewares/verify-federated-call.js +1 -0
  4. package/api/routes/federated.js +147 -18
  5. package/api/services/auth/index.js +2 -3
  6. package/api/services/notification/index.js +2 -1
  7. package/api/socket/channel/component.js +26 -18
  8. package/api/util/index.js +19 -0
  9. package/build/asset-manifest.json +97 -97
  10. package/build/index.html +1 -1
  11. package/build/service-worker.js +1 -1
  12. package/build/service-worker.js.map +1 -1
  13. package/build/static/js/{1013.48b6d77d.chunk.js → 1013.7b9f0d1c.chunk.js} +3 -3
  14. package/build/static/js/{1480.88c590c2.chunk.js → 1480.4d4dda1b.chunk.js} +2 -2
  15. package/build/static/js/1565.ba7ad6c9.chunk.js +2 -0
  16. package/build/static/js/2291.1627e4db.chunk.js +2 -0
  17. package/build/static/js/{2393.c5bbedfd.chunk.js → 2393.29558f48.chunk.js} +2 -2
  18. package/build/static/js/{2631.54f86f84.chunk.js → 2631.58f5f3bd.chunk.js} +2 -2
  19. package/build/static/js/2653.e7392aa1.chunk.js +2 -0
  20. package/build/static/js/{2686.7ae70bfd.chunk.js → 2686.890b32ed.chunk.js} +2 -2
  21. package/build/static/js/{2838.6fa46760.chunk.js → 2838.777de983.chunk.js} +3 -3
  22. package/build/static/js/{3038.8cbed218.chunk.js → 3038.40d611d1.chunk.js} +2 -2
  23. package/build/static/js/3593.4d68c718.chunk.js +2 -0
  24. package/build/static/js/3595.e2b52a55.chunk.js +3 -0
  25. package/build/static/js/3688.a821d97e.chunk.js +2 -0
  26. package/build/static/js/4023.c145cf94.chunk.js +2 -0
  27. package/build/static/js/{4355.42023420.chunk.js → 4355.7ff96d41.chunk.js} +2 -2
  28. package/build/static/js/4420.8b69d6e7.chunk.js +2 -0
  29. package/build/static/js/4706.d0c07efb.chunk.js +3 -0
  30. package/build/static/js/4716.bd8bed1b.chunk.js +2 -0
  31. package/build/static/js/{476.1f6135d6.chunk.js → 476.f196e88a.chunk.js} +2 -2
  32. package/build/static/js/4802.c534aa74.chunk.js +2 -0
  33. package/build/static/js/{5465.e0965b1d.chunk.js → 5465.19cd4b1f.chunk.js} +2 -2
  34. package/build/static/js/5628.8e4d578c.chunk.js +2 -0
  35. package/build/static/js/{5673.ab67c509.chunk.js → 5673.24aec022.chunk.js} +2 -2
  36. package/build/static/js/{5683.7e5d47f1.chunk.js → 5683.19dfa1f2.chunk.js} +2 -2
  37. package/build/static/js/{5960.adcd2848.chunk.js → 5960.e6da30ae.chunk.js} +2 -2
  38. package/build/static/js/{5982.89bdb419.chunk.js → 5982.27671e0b.chunk.js} +2 -2
  39. package/build/static/js/6186.99068c82.chunk.js +2 -0
  40. package/build/static/js/6452.8510e39f.chunk.js +2 -0
  41. package/build/static/js/{6498.bd96fa39.chunk.js → 6498.698608f8.chunk.js} +2 -2
  42. package/build/static/js/6576.2afa44eb.chunk.js +2 -0
  43. package/build/static/js/6737.16a327aa.chunk.js +2 -0
  44. package/build/static/js/{6771.1e778542.chunk.js → 6771.fae30b2e.chunk.js} +3 -3
  45. package/build/static/js/6856.2eb98754.chunk.js +2 -0
  46. package/build/static/js/{6868.f2fd5c29.chunk.js → 6868.b4a7c4d1.chunk.js} +2 -2
  47. package/build/static/js/{6640.f40cecbd.chunk.js → 6919.aa19f009.chunk.js} +2 -2
  48. package/build/static/js/{7465.babf76bb.chunk.js → 6974.9fe85473.chunk.js} +3 -3
  49. package/build/static/js/{7006.b72aff66.chunk.js → 7006.8f0645e5.chunk.js} +2 -2
  50. package/build/static/js/{7367.60cb10e0.chunk.js → 7367.c5adfbb1.chunk.js} +2 -2
  51. package/build/static/js/7516.eb541f26.chunk.js +2 -0
  52. package/build/static/js/{8143.e1c8ca20.chunk.js → 8143.34374ce2.chunk.js} +2 -2
  53. package/build/static/js/{8497.0cf2247d.chunk.js → 8497.e83aa0c8.chunk.js} +2 -2
  54. package/build/static/js/{8604.ad77a749.chunk.js → 8604.ad426a4a.chunk.js} +3 -3
  55. package/build/static/js/9088.4313ac38.chunk.js +3 -0
  56. package/build/static/js/9102.ff87def5.chunk.js +2 -0
  57. package/build/static/js/9409.c853d69d.chunk.js +2 -0
  58. package/build/static/js/941.94668382.chunk.js +2 -0
  59. package/build/static/js/{9899.af2e4f43.chunk.js → 9899.277d673f.chunk.js} +2 -2
  60. package/build/static/js/main.adbd79ef.js +3 -0
  61. package/package.json +26 -26
  62. package/build/static/js/1565.6df974b9.chunk.js +0 -2
  63. package/build/static/js/2291.4b1a6a86.chunk.js +0 -2
  64. package/build/static/js/2653.5dc29ed5.chunk.js +0 -2
  65. package/build/static/js/3593.c1eddcd6.chunk.js +0 -2
  66. package/build/static/js/3595.cbf763c8.chunk.js +0 -3
  67. package/build/static/js/3688.9bb1c7a8.chunk.js +0 -2
  68. package/build/static/js/4023.a8b23be1.chunk.js +0 -2
  69. package/build/static/js/4420.55971847.chunk.js +0 -2
  70. package/build/static/js/4706.212c92c8.chunk.js +0 -3
  71. package/build/static/js/4716.88f32cf2.chunk.js +0 -2
  72. package/build/static/js/4802.3b60e453.chunk.js +0 -2
  73. package/build/static/js/50.cbaa5a4e.chunk.js +0 -3
  74. package/build/static/js/5628.e46ecc79.chunk.js +0 -2
  75. package/build/static/js/6186.6c16ec07.chunk.js +0 -2
  76. package/build/static/js/6452.143af37a.chunk.js +0 -2
  77. package/build/static/js/6576.f78daf32.chunk.js +0 -2
  78. package/build/static/js/6700.5dfd9c70.chunk.js +0 -2
  79. package/build/static/js/6737.7d135225.chunk.js +0 -2
  80. package/build/static/js/6856.e185e317.chunk.js +0 -2
  81. package/build/static/js/9102.828066ce.chunk.js +0 -2
  82. package/build/static/js/9409.62a2aee0.chunk.js +0 -2
  83. package/build/static/js/941.6a4ed4dd.chunk.js +0 -2
  84. package/build/static/js/main.88f8260e.js +0 -3
  85. /package/build/static/js/{1013.48b6d77d.chunk.js.LICENSE.txt → 1013.7b9f0d1c.chunk.js.LICENSE.txt} +0 -0
  86. /package/build/static/js/{2838.6fa46760.chunk.js.LICENSE.txt → 2838.777de983.chunk.js.LICENSE.txt} +0 -0
  87. /package/build/static/js/{3595.cbf763c8.chunk.js.LICENSE.txt → 3595.e2b52a55.chunk.js.LICENSE.txt} +0 -0
  88. /package/build/static/js/{4706.212c92c8.chunk.js.LICENSE.txt → 4706.d0c07efb.chunk.js.LICENSE.txt} +0 -0
  89. /package/build/static/js/{6771.1e778542.chunk.js.LICENSE.txt → 6771.fae30b2e.chunk.js.LICENSE.txt} +0 -0
  90. /package/build/static/js/{7465.babf76bb.chunk.js.LICENSE.txt → 6974.9fe85473.chunk.js.LICENSE.txt} +0 -0
  91. /package/build/static/js/{8604.ad77a749.chunk.js.LICENSE.txt → 8604.ad426a4a.chunk.js.LICENSE.txt} +0 -0
  92. /package/build/static/js/{50.cbaa5a4e.chunk.js.LICENSE.txt → 9088.4313ac38.chunk.js.LICENSE.txt} +0 -0
  93. /package/build/static/js/{main.88f8260e.js.LICENSE.txt → main.adbd79ef.js.LICENSE.txt} +0 -0
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const jsx_runtime_1 = require("react/jsx-runtime");
4
4
  const components_1 = require("@react-email/components");
5
+ // @ts-ignore
6
+ const constant_1 = require("@abtnode/constant");
5
7
  const startYear = 2017;
6
8
  const endYear = new Date().getFullYear();
7
9
  function Copyright() {
@@ -9,6 +11,6 @@ function Copyright() {
9
11
  textAlign: 'center',
10
12
  color: '#898989',
11
13
  fontSize: 12,
12
- } }, { children: ["\u00A9 ", startYear, "-", endYear, " ArcBlock, Inc. All Rights Reserved."] })));
14
+ } }, { children: ["\u00A9 ", startYear, "-", endYear, " ", constant_1.COPYRIGHT_OWNER, " All Rights Reserved."] })));
13
15
  }
14
16
  exports.default = Copyright;
package/api/index.js CHANGED
@@ -143,7 +143,7 @@ module.exports = function createServer(node, serverOptions = {}) {
143
143
  Object.keys(BlockletInternalEvents).forEach((key) => {
144
144
  const event = BlockletInternalEvents[key];
145
145
  eventHub.on(event, (data) => {
146
- const { appDid } = data;
146
+ const { appDid, componentDid } = data;
147
147
 
148
148
  // Let first worker process do something as master
149
149
  if (process.env.NODE_ENV === 'test' || process.env.NODE_APP_INSTANCE === '0') {
@@ -151,7 +151,7 @@ module.exports = function createServer(node, serverOptions = {}) {
151
151
  return;
152
152
  }
153
153
 
154
- notificationService.sendToAppComponents.exec({ event, appDid, data }).catch((error) => {
154
+ notificationService.sendToAppComponents.exec({ event, appDid, componentDid, data }).catch((error) => {
155
155
  logger.error('send to component error', { error });
156
156
  });
157
157
  }
@@ -28,6 +28,7 @@ function verifyFederatedCall({ isMaster = false } = { isMaster: false }) {
28
28
  }
29
29
 
30
30
  req.body.verifyData = decode(data);
31
+ req.body.verifySite = validSite;
31
32
  next();
32
33
  };
33
34
  }
@@ -33,6 +33,14 @@ const PREFIX = WELLKNOWN_SERVICE_PATH_PREFIX;
33
33
  const prefix = `${PREFIX}/api/federated`;
34
34
  const limitSync = pLimit(1);
35
35
 
36
+ function getAuditLogActorByFederatedSite(blocklet) {
37
+ return {
38
+ did: blocklet.appPid,
39
+ fullName: blocklet.appName,
40
+ role: 'blocklet',
41
+ };
42
+ }
43
+
36
44
  async function syncSwitchProfile(user, { node, teamDid, dataDir }) {
37
45
  const tempUser = pick(user, ['did', 'pk', 'avatar', 'fullName', 'email']);
38
46
 
@@ -89,11 +97,12 @@ module.exports = {
89
97
  // master blocklet
90
98
  const { blocklet } = req;
91
99
  const { site } = req.body;
100
+ const teamDid = blocklet.appPid;
92
101
 
93
102
  const federated = defaults(cloneDeep(blocklet.settings.federated || {}), {
94
103
  config: {
95
104
  appId: blocklet.appDid,
96
- appPid: blocklet.appPid,
105
+ appPid: teamDid,
97
106
  },
98
107
  sites: [],
99
108
  });
@@ -103,7 +112,7 @@ module.exports = {
103
112
  const domainAliases = await node.getBlockletDomainAliases(blocklet);
104
113
  const masterSite = {
105
114
  appId: blocklet.appDid,
106
- appPid: blocklet.appPid,
115
+ appPid: teamDid,
107
116
  aliasDid: (blocklet.migratedFrom || []).map((item) => item.appDid),
108
117
  appName: blockletInfo.name,
109
118
  appDescription: blockletInfo.description,
@@ -133,11 +142,23 @@ module.exports = {
133
142
  }
134
143
  // member 申请后,将 member 展示在列表中
135
144
  // 更新的是自己
136
- await node.setFederated({
137
- did: blocklet.appPid,
145
+ const newState = await node.setFederated({
146
+ did: teamDid,
138
147
  config: federated,
139
148
  });
140
149
 
150
+ await node.createAuditLog(
151
+ {
152
+ action: 'requestJoinFederated',
153
+ args: { teamDid, memberSite: site },
154
+ context: {
155
+ user: getAuditLogActorByFederatedSite(site),
156
+ },
157
+ result: newState,
158
+ },
159
+ node
160
+ );
161
+
141
162
  // 将新增的数据返回给 member
142
163
  res.json({
143
164
  sites: federated.sites,
@@ -148,16 +169,17 @@ module.exports = {
148
169
  server.post(`${prefix}/quit`, ensureBlocklet(), verifyFederatedCall(), async (req, res) => {
149
170
  const { blocklet } = req;
150
171
  const { memberPid } = req.body.verifyData;
172
+ const teamDid = blocklet.appPid;
151
173
 
152
174
  const federated = defaults(cloneDeep(blocklet.settings.federated || {}), {
153
175
  config: {
154
176
  appId: blocklet.appDid,
155
- appPid: blocklet.appPid,
177
+ appPid: teamDid,
156
178
  },
157
179
  sites: [],
158
180
  });
159
181
 
160
- remove(federated.sites, (item) => item.appPid === memberPid);
182
+ const removedSites = remove(federated.sites, (item) => item.appPid === memberPid);
161
183
 
162
184
  const { permanentWallet } = await req.getBlockletInfo();
163
185
  const postData = {
@@ -182,22 +204,47 @@ module.exports = {
182
204
  });
183
205
  await Promise.all(waitingList);
184
206
 
185
- await node.setFederated({
186
- did: blocklet.appPid,
207
+ const newState = await node.setFederated({
208
+ did: teamDid,
187
209
  config: federated,
188
210
  });
189
211
 
212
+ await node.createAuditLog(
213
+ {
214
+ action: 'quitFederated',
215
+ args: { memberSite: removedSites[0], teamDid },
216
+ context: {
217
+ user: getAuditLogActorByFederatedSite(removedSites[0]),
218
+ },
219
+ result: newState,
220
+ },
221
+ node
222
+ );
223
+
190
224
  res.json({});
191
225
  });
192
226
 
193
227
  // master 通知 member 当前统一登录要解散
194
228
  server.post(`${prefix}/disband`, ensureBlocklet(), verifyFederatedCall(), async (req, res) => {
195
229
  const { blocklet } = req;
230
+ const { verifySite } = req.body;
231
+ const teamDid = blocklet.appPid;
196
232
 
197
- await node.setFederated({
198
- did: blocklet.appPid,
233
+ const newState = await node.setFederated({
234
+ did: teamDid,
199
235
  config: null,
200
236
  });
237
+ await node.createAuditLog(
238
+ {
239
+ action: 'disbandFederated',
240
+ args: { blocklet, masterSite: verifySite, teamDid },
241
+ context: {
242
+ user: getAuditLogActorByFederatedSite(verifySite),
243
+ },
244
+ result: newState,
245
+ },
246
+ node
247
+ );
201
248
  res.json({});
202
249
  });
203
250
 
@@ -207,10 +254,12 @@ module.exports = {
207
254
  server.post(`${prefix}/audit-res`, ensureBlocklet(), verifyFederatedCall(), async (req, res) => {
208
255
  const { blocklet } = req;
209
256
  const { delegation, roles, masterPid, status } = req.body.verifyData;
257
+ const { verifySite } = req.body;
258
+ const teamDid = blocklet.appPid;
210
259
  const federated = defaults(cloneDeep(blocklet.settings.federated || {}), {
211
260
  config: {
212
261
  appId: blocklet.appDid,
213
- appPid: blocklet.appPid,
262
+ appPid: teamDid,
214
263
  isMaster: false,
215
264
  },
216
265
  sites: [],
@@ -221,7 +270,7 @@ module.exports = {
221
270
  const hasTrustedPassport = trustedPassports.find((item) => item.issuerDid === masterPid);
222
271
  if (!hasTrustedPassport) {
223
272
  await node.configTrustedPassports({
224
- teamDid: blocklet.appPid,
273
+ teamDid,
225
274
  trustedPassports: [
226
275
  ...trustedPassports,
227
276
  {
@@ -239,10 +288,21 @@ module.exports = {
239
288
  }
240
289
  }
241
290
 
242
- await node.setFederated({
243
- did: blocklet.appPid,
291
+ const newState = await node.setFederated({
292
+ did: teamDid,
244
293
  config: federated,
245
294
  });
295
+ await node.createAuditLog(
296
+ {
297
+ action: 'auditFederated',
298
+ args: { masterSite: verifySite, status, teamDid },
299
+ context: {
300
+ user: getAuditLogActorByFederatedSite(verifySite),
301
+ },
302
+ result: newState,
303
+ },
304
+ node
305
+ );
246
306
  res.json(federated);
247
307
  });
248
308
 
@@ -250,6 +310,7 @@ module.exports = {
250
310
  // 该路由为 member 接受响应的 api(只允许 master 调用)
251
311
  server.post(`${prefix}/sync`, ensureBlocklet(), verifyFederatedCall(), async (req, res) => {
252
312
  const { blocklet } = req;
313
+ const { verifySite } = req.body;
253
314
  const teamDid = blocklet.appPid;
254
315
  const { users = null, sites = null } = req.body.verifyData;
255
316
 
@@ -261,7 +322,7 @@ module.exports = {
261
322
  pendingList.push(
262
323
  limitSync(async () => {
263
324
  await node.setFederated({
264
- did: blocklet.appPid,
325
+ did: teamDid,
265
326
  config: federated,
266
327
  });
267
328
  })
@@ -286,6 +347,16 @@ module.exports = {
286
347
  }
287
348
 
288
349
  await Promise.all(pendingList);
350
+ await node.createAuditLog(
351
+ {
352
+ action: 'syncFederated',
353
+ args: { users, sites, callerSite: verifySite, teamDid },
354
+ context: {
355
+ user: getAuditLogActorByFederatedSite(verifySite),
356
+ },
357
+ },
358
+ node
359
+ );
289
360
  res.json({});
290
361
  });
291
362
 
@@ -316,7 +387,7 @@ module.exports = {
316
387
  const blockletInfo = await req.getBlockletInfo();
317
388
  const site = {
318
389
  appId: blocklet.appDid,
319
- appPid: blocklet.appPid,
390
+ appPid: teamDid,
320
391
  appName: blockletInfo.name,
321
392
  appDescription: blockletInfo.description,
322
393
  appUrl: blockletInfo.appUrl,
@@ -330,7 +401,7 @@ module.exports = {
330
401
  }
331
402
  );
332
403
 
333
- // step 5 完成自动登录(member 向 master 请求)
404
+ // step 5 完成 member 的自动登录(member 向 master 请求)
334
405
  server.post(
335
406
  `${prefix}/login`,
336
407
  cors({ credentials: true, origin: true }),
@@ -345,9 +416,9 @@ module.exports = {
345
416
  const { onlyWriteCookie = false } = req.body;
346
417
 
347
418
  const { blocklet } = req;
419
+ const teamDid = blocklet.appPid;
348
420
  if (!onlyWriteCookie) {
349
421
  const { permanentWallet } = await req.getBlockletInfo();
350
- const teamDid = blocklet.appPid;
351
422
  const federatedSites = blocklet.settings?.federated?.sites || [];
352
423
  const loginSite = federatedSites.find((item) => {
353
424
  const siteHost = new URL(item.appUrl).host;
@@ -391,6 +462,16 @@ module.exports = {
391
462
  res.status(500).send('Generate token error');
392
463
  return;
393
464
  }
465
+ await node.createAuditLog(
466
+ {
467
+ action: 'loginFederated',
468
+ args: { blocklet, memberSite: loginSite, teamDid },
469
+ context: {
470
+ user: req.user,
471
+ },
472
+ },
473
+ node
474
+ );
394
475
  }
395
476
 
396
477
  const cacheTtl = blocklet.settings?.session?.cacheTtl || 60 * 60;
@@ -400,6 +481,7 @@ module.exports = {
400
481
  sameSite: 'none',
401
482
  secure: true,
402
483
  });
484
+
403
485
  res.json(data);
404
486
  }
405
487
  );
@@ -407,6 +489,7 @@ module.exports = {
407
489
  // step 6 发放自动登录 token(master 向 member 发起生成 token 请求)
408
490
  server.post(`${prefix}/token`, ensureBlocklet(), verifyFederatedCall(), async (req, res) => {
409
491
  const { user, masterPid, role, passport, walletOS, provider } = req.body.verifyData;
492
+ const { verifySite } = req.body;
410
493
  const { createSessionToken } = initJwt(node, options);
411
494
  const createToken = createTokenFn(createSessionToken);
412
495
  const { secret } = await req.getBlockletInfo();
@@ -468,6 +551,16 @@ module.exports = {
468
551
  didConnectVersion: getDidConnectVersion(req),
469
552
  }
470
553
  );
554
+ await node.createAuditLog(
555
+ {
556
+ action: 'loginByMaster',
557
+ args: { masterSite: verifySite, teamDid, blocklet },
558
+ context: {
559
+ user: doc,
560
+ },
561
+ },
562
+ node
563
+ );
471
564
 
472
565
  res.json({ sessionToken, refreshToken });
473
566
  });
@@ -492,6 +585,7 @@ module.exports = {
492
585
  // member 传递过来的 user.did 和 user.pk 均为 master-site 与钱包生成的
493
586
 
494
587
  server.post(`${prefix}/loginByMember`, ensureBlocklet(), verifyFederatedCall(), async (req, res) => {
588
+ const { verifySite } = req.body;
495
589
  const { user, passport, walletOS, provider } = req.body.verifyData;
496
590
  const { createSessionToken } = initJwt(node, options);
497
591
  const createToken = createTokenFn(createSessionToken);
@@ -553,11 +647,24 @@ module.exports = {
553
647
  }
554
648
  );
555
649
 
650
+ await node.createAuditLog(
651
+ {
652
+ action: 'loginByMember',
653
+ args: { memberSite: verifySite, teamDid, blocklet },
654
+ context: {
655
+ user: newUser,
656
+ },
657
+ },
658
+ node
659
+ );
660
+
556
661
  res.json({ sessionToken, refreshToken });
557
662
  });
558
663
 
664
+ // member 向 master 申请 auth0 账号的 migrate
559
665
  server.post(`${prefix}/migrateAuth0`, ensureBlocklet(), verifyFederatedCall(), async (req, res) => {
560
666
  const { blocklet } = req;
667
+ const { verifySite } = req.body;
561
668
  const { did: teamDid, wallet: blockletWallet } = await req.getBlockletInfo();
562
669
  const { fromUserDid, toUserDid, toUserPk } = req.body.verifyData;
563
670
  const oauthUser = await node.getUser({ teamDid, user: { did: fromUserDid } });
@@ -572,9 +679,21 @@ module.exports = {
572
679
  };
573
680
  await declareAccount({ wallet: userWallet, blocklet });
574
681
  await migrateAccount({ wallet: userWallet, blocklet, user: bindUser });
682
+ await node.createAuditLog(
683
+ {
684
+ action: 'migrateFederatedAuth0',
685
+ args: { fromUserDid, toUserDid, callerSite: verifySite, teamDid },
686
+ context: {
687
+ user: getAuditLogActorByFederatedSite(verifySite),
688
+ },
689
+ },
690
+ node
691
+ );
575
692
  res.json({});
576
693
  });
577
694
 
695
+ // member 去登录 master
696
+ // 该监听是由 member 站点来做的,member 向自己的后端来申请要登录 master,member 的后端组装加密数据,由 Master 来接收并执行相应操作
578
697
  server.post(`${prefix}/loginMaster`, ensureBlocklet(), async (req, res) => {
579
698
  if (!req.user) {
580
699
  res.status(401).send('Unauthorized');
@@ -597,6 +716,16 @@ module.exports = {
597
716
  };
598
717
 
599
718
  const { data } = await api.post(url, postData);
719
+ await node.createAuditLog(
720
+ {
721
+ action: 'loginFederatedMaster',
722
+ args: { blocklet, masterSite, teamDid },
723
+ context: {
724
+ user,
725
+ },
726
+ },
727
+ node
728
+ );
600
729
  res.json(data);
601
730
  });
602
731
  },
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable arrow-parens */
2
2
  const get = require('lodash/get');
3
3
  const cookie = require('cookie');
4
- const minimatch = require('minimatch');
5
4
  const bearerToken = require('@abtnode/util/lib/express-bearer-token');
6
5
 
7
6
  const validators = require('@blocklet/sdk/lib/validators');
@@ -37,7 +36,7 @@ const createTransferAppOwnerRoutes = require('./connect/transfer-app-owner');
37
36
  const createReceiveTransferAppOwnerRoutes = require('./connect/receive-transfer-app-owner');
38
37
  const createSessionRoutes = require('./session');
39
38
  const createPassportRoutes = require('./passport');
40
- const { getRedirectUrl } = require('../../util');
39
+ const { getRedirectUrl, shouldIgnoreUrl } = require('../../util');
41
40
  const { sessionCacheDisabledUser } = require('../../cache');
42
41
 
43
42
  const getTokenFromWsConnect = (req, options) => {
@@ -98,7 +97,7 @@ const init = ({ node, options }) => {
98
97
  // developers need not config the following urls in blocklet.yml
99
98
  ignoreUrls.push('/api/public/**');
100
99
 
101
- const shouldIgnore = ignoreUrls.some((s) => minimatch(req.url, s));
100
+ const shouldIgnore = shouldIgnoreUrl(req.url, ignoreUrls);
102
101
  if (shouldIgnore) {
103
102
  return {};
104
103
  }
@@ -153,7 +153,8 @@ const init = ({ node }) => {
153
153
  },
154
154
 
155
155
  sendToAppComponents: {
156
- exec: ({ event, appDid, data }) => sendToAppComponents({ event, appDid, data, node, wsServer }),
156
+ exec: ({ event, appDid, componentDid, data }) =>
157
+ sendToAppComponents({ event, appDid, componentDid, data, node, wsServer }),
157
158
  },
158
159
 
159
160
  sendToAppChannel: {
@@ -34,8 +34,14 @@ const onAuthenticate = async ({ channel, payload, node }) => {
34
34
 
35
35
  const nodeInfo = await node.getNodeInfo({ useCache: true });
36
36
 
37
- if (getComponentApiKey({ serverSk: nodeInfo.sk, app, component }) !== apiKey) {
38
- throw new Error(`Invalid API key. app: ${appDid}, component: ${componentDid}`);
37
+ const expectedApiKey = getComponentApiKey({ serverSk: nodeInfo.sk, app, component }) || '';
38
+ if (expectedApiKey !== apiKey) {
39
+ throw new Error(
40
+ `Invalid API key. app: ${appDid}, component: ${componentDid}, expected: ${String(expectedApiKey).slice(
41
+ 0,
42
+ 4
43
+ )}***, actual: ${String(apiKey).slice(0, 4)}***, installedAt: ${component.installedAt}`
44
+ );
39
45
  }
40
46
  };
41
47
 
@@ -92,24 +98,26 @@ const sendToAppComponents = async ({ event, appDid, componentDid: inputComponent
92
98
 
93
99
  for (const component of app.children || []) {
94
100
  const componentDid = component.meta.did;
95
- if (inputComponentDid && componentDid !== inputComponentDid) {
96
- return;
97
- }
98
101
 
99
- // eslint-disable-next-line no-loop-func
100
- broadcast(wsServer, getComponentChannel(appDid, componentDid), event, notification, async (count) => {
101
- // FIXME @linchen 组件以 cluster 模式启动时, 是否确保所有组件实例都收到消息?
102
- if (count <= 0) {
103
- logger.info('Online component client was not found', { appDid, componentDid });
104
- await lock.acquire();
105
- try {
106
- await states.message.insert({ did: getCacheId(appDid, componentDid), event, data: notification });
107
- lock.release();
108
- } catch (error) {
109
- lock.release();
102
+ if (!inputComponentDid || componentDid === inputComponentDid) {
103
+ // realAppDid is diff with appDid when app development mode
104
+ const realAppDid = app.appDid || appDid;
105
+
106
+ // eslint-disable-next-line no-loop-func
107
+ broadcast(wsServer, getComponentChannel(realAppDid, componentDid), event, notification, async (count) => {
108
+ // FIXME @linchen 组件以 cluster 模式启动时, 是否确保所有组件实例都收到消息?
109
+ if (count <= 0) {
110
+ logger.info('Online component client was not found', { realAppDid, componentDid });
111
+ await lock.acquire();
112
+ try {
113
+ await states.message.insert({ did: getCacheId(realAppDid, componentDid), event, data: notification });
114
+ lock.release();
115
+ } catch (error) {
116
+ lock.release();
117
+ }
110
118
  }
111
- }
112
- });
119
+ });
120
+ }
113
121
  }
114
122
  };
115
123
 
package/api/util/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const joinUrl = require('url-join');
2
2
  const get = require('lodash/get');
3
+ const minimatch = require('minimatch');
3
4
  const { ROLES, WHO_CAN_ACCESS } = require('@abtnode/constant');
4
5
  const { BlockletSource, BLOCKLET_MODES, BlockletGroup } = require('@blocklet/constant');
5
6
  const { findWebInterface, findWebInterfacePort, findComponentByIdV2 } = require('@blocklet/meta/lib/util');
@@ -241,6 +242,23 @@ const getDidConnectVersion = (req) => {
241
242
 
242
243
  const nanoid = (length = 16) => [...Array(length)].map(() => Math.random().toString(36)[2]).join('');
243
244
 
245
+ const shouldIgnoreUrl = (url, urls) => {
246
+ let { length } = url;
247
+ for (let i = 0; i < url.length; i++) {
248
+ if (url[i] === '?' || url[i] === '#') {
249
+ length = i;
250
+ break;
251
+ }
252
+ }
253
+ const _url = url.slice(0, length);
254
+ for (let i = 0; i < urls.length; i++) {
255
+ if (minimatch(_url, urls[i])) {
256
+ return true;
257
+ }
258
+ }
259
+ return false;
260
+ };
261
+
244
262
  module.exports = {
245
263
  getBlockletLogo,
246
264
  shouldGotoStartPage,
@@ -251,4 +269,5 @@ module.exports = {
251
269
  createTokenFn,
252
270
  getDidConnectVersion,
253
271
  nanoid,
272
+ shouldIgnoreUrl,
254
273
  };