@abtnode/blocklet-services 1.16.15 → 1.16.16-beta-e038cde7

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 (121) hide show
  1. package/api/index.js +1 -19
  2. package/api/libs/auth/utils.js +82 -36
  3. package/api/libs/connect/session.js +9 -1
  4. package/api/libs/connect/shared.js +2 -2
  5. package/api/libs/connect/v1.js +3 -3
  6. package/api/routes/oauth.js +22 -4
  7. package/api/util/blocklet-utils.js +7 -4
  8. package/api/util/federated.js +0 -13
  9. package/build/asset-manifest.json +109 -113
  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/css/{1562.1b34375e.chunk.css → 4706.7a92e9f9.chunk.css} +1 -1
  14. package/build/static/js/1013.48b6d77d.chunk.js +3 -0
  15. package/build/static/js/1480.30b94380.chunk.js +2 -0
  16. package/build/static/js/1565.f0321c52.chunk.js +2 -0
  17. package/build/static/js/1660.5c8ade93.chunk.js +2 -0
  18. package/build/static/js/1760.95d0c320.chunk.js +2 -0
  19. package/build/static/js/2291.4b1a6a86.chunk.js +2 -0
  20. package/build/static/js/2307.2e451912.chunk.js +2 -0
  21. package/build/static/js/2393.c5bbedfd.chunk.js +2 -0
  22. package/build/static/js/2653.11a1ad57.chunk.js +2 -0
  23. package/build/static/js/2686.07687254.chunk.js +2 -0
  24. package/build/static/js/3593.c1eddcd6.chunk.js +2 -0
  25. package/build/static/js/{3595.a4e8bebd.chunk.js → 3595.cbf763c8.chunk.js} +3 -3
  26. package/build/static/js/3688.9bb1c7a8.chunk.js +2 -0
  27. package/build/static/js/{4023.7553cbda.chunk.js → 4023.0f348986.chunk.js} +2 -2
  28. package/build/static/js/4042.3c8e0025.chunk.js +3 -0
  29. package/build/static/js/4355.68364e13.chunk.js +2 -0
  30. package/build/static/js/4420.55971847.chunk.js +2 -0
  31. package/build/static/js/{4682.867b00fa.chunk.js → 4682.8e18351a.chunk.js} +2 -2
  32. package/build/static/js/4706.df5b600d.chunk.js +3 -0
  33. package/build/static/js/4716.47aa133c.chunk.js +2 -0
  34. package/build/static/js/476.1f6135d6.chunk.js +2 -0
  35. package/build/static/js/4802.63425dd4.chunk.js +2 -0
  36. package/build/static/js/5176.42904a22.chunk.js +2 -0
  37. package/build/static/js/5628.773a32da.chunk.js +2 -0
  38. package/build/static/js/{5683.7e2e9b58.chunk.js → 5683.3bdd2338.chunk.js} +2 -2
  39. package/build/static/js/5982.89bdb419.chunk.js +2 -0
  40. package/build/static/js/6186.61596c22.chunk.js +2 -0
  41. package/build/static/js/6380.2b96be29.chunk.js +2 -0
  42. package/build/static/js/6452.b1899621.chunk.js +2 -0
  43. package/build/static/js/6465.e704f56b.chunk.js +3 -0
  44. package/build/static/js/6576.f78daf32.chunk.js +2 -0
  45. package/build/static/js/6606.9f17eaa6.chunk.js +3 -0
  46. package/build/static/js/{445.4e1c7d75.chunk.js → 6629.36e61c26.chunk.js} +3 -3
  47. package/build/static/js/6640.53cdcb95.chunk.js +2 -0
  48. package/build/static/js/6700.5dfd9c70.chunk.js +2 -0
  49. package/build/static/js/{6711.93590b67.chunk.js → 6711.9a173439.chunk.js} +2 -2
  50. package/build/static/js/6737.5f735a29.chunk.js +2 -0
  51. package/build/static/js/{6771.b78869b6.chunk.js → 6771.735ebd3f.chunk.js} +3 -3
  52. package/build/static/js/{6856.46480e82.chunk.js → 6856.e5c166e6.chunk.js} +2 -2
  53. package/build/static/js/{6868.71135b70.chunk.js → 6868.f2fd5c29.chunk.js} +2 -2
  54. package/build/static/js/{7006.6838f9f0.chunk.js → 7006.9a53f7ed.chunk.js} +2 -2
  55. package/build/static/js/7465.ba1027a7.chunk.js +3 -0
  56. package/build/static/js/{8437.fd5a5ad5.chunk.js → 8437.994560bd.chunk.js} +2 -2
  57. package/build/static/js/8497.0cf2247d.chunk.js +2 -0
  58. package/build/static/js/8604.ad77a749.chunk.js +3 -0
  59. package/build/static/js/8706.3d16907a.chunk.js +2 -0
  60. package/build/static/js/9102.828066ce.chunk.js +2 -0
  61. package/build/static/js/9409.befe72b4.chunk.js +2 -0
  62. package/build/static/js/941.6a4ed4dd.chunk.js +2 -0
  63. package/build/static/js/9620.59bc85b8.chunk.js +2 -0
  64. package/build/static/js/{9657.e974d577.chunk.js → 9657.b03b88e5.chunk.js} +2 -2
  65. package/build/static/js/9899.c8ff588e.chunk.js +2 -0
  66. package/build/static/js/main.2ea1070b.js +3 -0
  67. package/build/static/js/{main.706d9331.js.LICENSE.txt → main.2ea1070b.js.LICENSE.txt} +1 -1
  68. package/package.json +23 -23
  69. package/build/static/js/1013.3fea2f42.chunk.js +0 -3
  70. package/build/static/js/1480.76f3aa40.chunk.js +0 -2
  71. package/build/static/js/1562.73f77a34.chunk.js +0 -3
  72. package/build/static/js/1565.fb9d063a.chunk.js +0 -2
  73. package/build/static/js/1614.80ddb35a.chunk.js +0 -2
  74. package/build/static/js/1660.a921a29a.chunk.js +0 -2
  75. package/build/static/js/1760.1d682c10.chunk.js +0 -2
  76. package/build/static/js/1980.5fbdb67a.chunk.js +0 -2
  77. package/build/static/js/2100.d46217bd.chunk.js +0 -2
  78. package/build/static/js/2291.80adfd96.chunk.js +0 -2
  79. package/build/static/js/2393.f7bbb9ef.chunk.js +0 -2
  80. package/build/static/js/252.27d0e320.chunk.js +0 -3
  81. package/build/static/js/2653.99c8d3c0.chunk.js +0 -2
  82. package/build/static/js/2686.04a60159.chunk.js +0 -2
  83. package/build/static/js/3593.36ff635b.chunk.js +0 -2
  84. package/build/static/js/3620.da2326b7.chunk.js +0 -2
  85. package/build/static/js/3688.6ec4bb5c.chunk.js +0 -2
  86. package/build/static/js/4212.cc2c8542.chunk.js +0 -2
  87. package/build/static/js/4461.d7dcfc2f.chunk.js +0 -2
  88. package/build/static/js/4716.55a4daab.chunk.js +0 -2
  89. package/build/static/js/4802.fbb3d2f1.chunk.js +0 -2
  90. package/build/static/js/5176.fdc05077.chunk.js +0 -2
  91. package/build/static/js/5628.701509d2.chunk.js +0 -2
  92. package/build/static/js/5848.d8a944a2.chunk.js +0 -2
  93. package/build/static/js/5859.b1852fc0.chunk.js +0 -2
  94. package/build/static/js/5982.5c6bdd6b.chunk.js +0 -2
  95. package/build/static/js/617.ecc73170.chunk.js +0 -3
  96. package/build/static/js/6186.a5c56653.chunk.js +0 -2
  97. package/build/static/js/6452.b7040943.chunk.js +0 -2
  98. package/build/static/js/6640.34287d69.chunk.js +0 -2
  99. package/build/static/js/6700.6c404ac2.chunk.js +0 -2
  100. package/build/static/js/6737.0af19630.chunk.js +0 -2
  101. package/build/static/js/6921.3ab94bf5.chunk.js +0 -2
  102. package/build/static/js/7310.1163692a.chunk.js +0 -2
  103. package/build/static/js/7465.30cccc16.chunk.js +0 -3
  104. package/build/static/js/8128.d1e32d23.chunk.js +0 -3
  105. package/build/static/js/861.889f9199.chunk.js +0 -2
  106. package/build/static/js/9102.1c2ca825.chunk.js +0 -2
  107. package/build/static/js/9260.78822a10.chunk.js +0 -3
  108. package/build/static/js/9409.1148b9cc.chunk.js +0 -2
  109. package/build/static/js/9620.f05f3e72.chunk.js +0 -2
  110. package/build/static/js/9899.52da4ed3.chunk.js +0 -2
  111. package/build/static/js/main.706d9331.js +0 -3
  112. /package/build/static/js/{1013.3fea2f42.chunk.js.LICENSE.txt → 1013.48b6d77d.chunk.js.LICENSE.txt} +0 -0
  113. /package/build/static/js/{3595.a4e8bebd.chunk.js.LICENSE.txt → 3595.cbf763c8.chunk.js.LICENSE.txt} +0 -0
  114. /package/build/static/js/{9260.78822a10.chunk.js.LICENSE.txt → 4042.3c8e0025.chunk.js.LICENSE.txt} +0 -0
  115. /package/build/static/js/{1562.73f77a34.chunk.js.LICENSE.txt → 4706.df5b600d.chunk.js.LICENSE.txt} +0 -0
  116. /package/build/static/js/{617.ecc73170.chunk.js.LICENSE.txt → 6465.e704f56b.chunk.js.LICENSE.txt} +0 -0
  117. /package/build/static/js/{8128.d1e32d23.chunk.js.LICENSE.txt → 6606.9f17eaa6.chunk.js.LICENSE.txt} +0 -0
  118. /package/build/static/js/{445.4e1c7d75.chunk.js.LICENSE.txt → 6629.36e61c26.chunk.js.LICENSE.txt} +0 -0
  119. /package/build/static/js/{6771.b78869b6.chunk.js.LICENSE.txt → 6771.735ebd3f.chunk.js.LICENSE.txt} +0 -0
  120. /package/build/static/js/{7465.30cccc16.chunk.js.LICENSE.txt → 7465.ba1027a7.chunk.js.LICENSE.txt} +0 -0
  121. /package/build/static/js/{252.27d0e320.chunk.js.LICENSE.txt → 8604.ad77a749.chunk.js.LICENSE.txt} +0 -0
package/api/index.js CHANGED
@@ -7,7 +7,6 @@ const cors = require('cors');
7
7
  const cookieParser = require('cookie-parser');
8
8
  const bodyParser = require('body-parser');
9
9
  const httpProxy = require('@arcblock/http-proxy');
10
- const dayjs = require('@abtnode/util/lib/dayjs');
11
10
  const minimatch = require('minimatch');
12
11
 
13
12
  const { getAccessLogStream } = require('@abtnode/logger');
@@ -49,20 +48,6 @@ const checkBlocklet = require('./middlewares/check-blocklet');
49
48
  const proxyToDaemon = require('./middlewares/proxy-to-daemon');
50
49
  const attachSharedUtils = require('./util/attach-shared-utils');
51
50
 
52
- const logFileGenerator = (time, index) => {
53
- if (!time) {
54
- return 'service.log';
55
- }
56
-
57
- let filename = `service-${dayjs(time).subtract(1, 'day').format('YYYY-MM-DD')}`; // prev date
58
-
59
- if (index > 1) {
60
- filename = `${filename}-${index}`;
61
- }
62
-
63
- return `${filename}.log.gz`;
64
- };
65
-
66
51
  const agent = new http.Agent({ maxSockets: Number.MAX_VALUE });
67
52
 
68
53
  module.exports = function createServer(node, serverOptions = {}) {
@@ -222,8 +207,7 @@ module.exports = function createServer(node, serverOptions = {}) {
222
207
 
223
208
  /* istanbul ignore if */
224
209
  if (isProduction) {
225
- // TODO: 这里没有修改原来的文件名,不过我觉得这里叫 service-access.log 会更好, 或者单独放一个目录
226
- server.use(morgan('combined', { stream: getAccessLogStream(process.env.ABT_NODE_LOG_DIR, 'service.log') }));
210
+ server.use(morgan('combined', { stream: getAccessLogStream(process.env.ABT_NODE_LOG_DIR, 'service.access.log') }));
227
211
  /* istanbul ignore else */
228
212
  } else {
229
213
  server.use(
@@ -473,5 +457,3 @@ module.exports = function createServer(node, serverOptions = {}) {
473
457
 
474
458
  return server;
475
459
  };
476
-
477
- module.exports.logFileGenerator = logFileGenerator;
@@ -1,5 +1,5 @@
1
1
  const { getPassportStatusEndpoint, getApplicationInfo } = require('@abtnode/auth/lib/auth');
2
- const { createPassportVC } = require('@abtnode/auth/lib/passport');
2
+ const { createPassportVC, upsertToPassports, createUserPassport } = require('@abtnode/auth/lib/passport');
3
3
  const { VC_TYPE_NODE_PASSPORT, PASSPORT_STATUS } = require('@abtnode/constant');
4
4
  const { getAvatarByEmail, getAvatarByUrl, getUserAvatarUrl } = require('@abtnode/util/lib/user');
5
5
  const { getBlockletAppIdList } = require('@blocklet/meta/lib/util');
@@ -9,8 +9,7 @@ const uniqBy = require('lodash/uniqBy');
9
9
 
10
10
  const { sendToUser } = require('../notification');
11
11
 
12
- // FIXME: @zhanghan 转移通行证目前只能颁发新的,会导致用户数据中产生多余的通行证
13
- async function transferPassport(fromUser, toUser, { req, teamDid, node, nodeInfo }) {
12
+ async function transferPassport(fromUser, toUser, { req, teamDid, node, nodeInfo, revokePassport = false }) {
14
13
  if (!fromUser || !toUser) {
15
14
  return;
16
15
  }
@@ -20,9 +19,9 @@ async function transferPassport(fromUser, toUser, { req, teamDid, node, nodeInfo
20
19
  passportColor,
21
20
  } = await getApplicationInfo({ node, nodeInfo, teamDid });
22
21
 
23
- const blocklet = await req.getBlockletInfo();
24
- const { wallet: blockletWallet } = blocklet;
25
- const issuerDidList = uniq([blockletWallet.address, ...getBlockletAppIdList(blocklet)]);
22
+ const blockletInfo = await req.getBlockletInfo();
23
+ const { wallet: blockletWallet } = blockletInfo;
24
+ const issuerDidList = uniq([blockletWallet.address, ...getBlockletAppIdList(blockletInfo)]);
26
25
  const waitPassportList = uniqBy(
27
26
  (fromUser.passports || []).filter((x) => {
28
27
  if (x.status !== PASSPORT_STATUS.VALID) {
@@ -41,37 +40,42 @@ async function transferPassport(fromUser, toUser, { req, teamDid, node, nodeInfo
41
40
  return;
42
41
  }
43
42
 
44
- const attachments = await Promise.all(
45
- waitPassportList.map((x) => {
46
- const vcParams = {
47
- issuerName,
48
- issuerWallet,
49
- ownerDid: toUser.did,
50
- passport: pick(x, ['name', 'title', 'endpoint', 'specVersion']),
51
- endpoint: getPassportStatusEndpoint({
52
- baseUrl: x.endpoint,
53
- userDid: toUser.did,
54
- teamDid,
55
- }),
56
- types: teamDid === nodeInfo.did ? [VC_TYPE_NODE_PASSPORT] : [],
57
- ownerProfile: {
58
- email: toUser.email,
59
- fullName: toUser.fullName,
60
- avatar: getUserAvatarUrl(x.endpoint, toUser.avatar),
61
- },
62
- preferredColor: passportColor,
63
- };
43
+ const attachments = waitPassportList.map((x) => {
44
+ const vcParams = {
45
+ issuerName,
46
+ issuerWallet,
47
+ ownerDid: toUser.did,
48
+ passport: { ...pick(x, ['name', 'title', 'specVersion']), endpoint: x.endpoint || blockletInfo.appUrl },
49
+ endpoint: getPassportStatusEndpoint({
50
+ baseUrl: x.endpoint || blockletInfo.appUrl,
51
+ userDid: toUser.did,
52
+ teamDid,
53
+ }),
54
+ types: teamDid === nodeInfo.did ? [VC_TYPE_NODE_PASSPORT] : [],
55
+ ownerProfile: {
56
+ email: toUser.email,
57
+ fullName: toUser.fullName,
58
+ avatar: getUserAvatarUrl(x.endpoint || blockletInfo.appUrl, toUser.avatar),
59
+ },
60
+ preferredColor: passportColor,
61
+ };
64
62
 
65
- const vc = createPassportVC(vcParams);
66
- return {
67
- type: 'vc',
68
- data: {
69
- credential: vc,
70
- tag: x.name,
71
- },
72
- };
73
- })
74
- );
63
+ const vc = createPassportVC(vcParams);
64
+ return {
65
+ type: 'vc',
66
+ data: {
67
+ credential: vc,
68
+ tag: x.name,
69
+ },
70
+ };
71
+ });
72
+ const insertPassportList = attachments.map((item, index) => {
73
+ return {
74
+ ...createUserPassport(item.data.credential, { role: item.data.tag }),
75
+ ...pick(waitPassportList[index], ['firstLoginAt', 'lastLoginAt', 'lastLoginIp']),
76
+ userDid: toUser.did,
77
+ };
78
+ });
75
79
 
76
80
  const passportNameList = attachments.map((x) => x.data.credential.name);
77
81
 
@@ -86,6 +90,48 @@ async function transferPassport(fromUser, toUser, { req, teamDid, node, nodeInfo
86
90
  },
87
91
  { req }
88
92
  );
93
+
94
+ const passports = insertPassportList.reduce((acc, item) => {
95
+ return upsertToPassports(acc, item);
96
+ }, fromUser.passports || []);
97
+ const toUserExsit = await node.getUser({
98
+ teamDid,
99
+ user: { did: toUser.did },
100
+ options: {
101
+ enableConnectedAccount: false,
102
+ },
103
+ });
104
+ // HACK: 默认情况下,应该将新 passport 添加到 toUser,但某些情况下,toUser 是绑定到 fromUser 的 connectAccount,所以需要将新通行证添加到 fromUser
105
+ if (toUserExsit) {
106
+ await node.updateUser({
107
+ teamDid,
108
+ user: {
109
+ did: toUser.did,
110
+ pk: toUser.pk,
111
+ passports,
112
+ },
113
+ });
114
+ } else {
115
+ await node.updateUser({
116
+ teamDid,
117
+ user: {
118
+ did: fromUser.did,
119
+ pk: fromUser.pk,
120
+ passports,
121
+ },
122
+ });
123
+ }
124
+ if (revokePassport) {
125
+ const revokePendingList = waitPassportList
126
+ .filter((item) => item.id)
127
+ .map((item) => {
128
+ if (fromUser.sourceProvider === 'auth0') {
129
+ return node.removeUserPassport({ teamDid, userDid: fromUser.did, passportId: item.id });
130
+ }
131
+ return node.revokeUserPassport({ teamDid, userDid: fromUser.did, passportId: item.id });
132
+ });
133
+ await Promise.all(revokePendingList);
134
+ }
89
135
  }
90
136
 
91
137
  module.exports = {
@@ -885,7 +885,14 @@ module.exports = {
885
885
  };
886
886
  }
887
887
 
888
- await transferPassport(oauthUser, bindUser, { req: request, node, nodeInfo, teamDid, baseUrl });
888
+ await transferPassport(oauthUser, bindUser, {
889
+ req: request,
890
+ node,
891
+ nodeInfo,
892
+ teamDid,
893
+ baseUrl,
894
+ revokePassport: true,
895
+ });
889
896
 
890
897
  const connectedAccounts = oauthUser?.connectedAccounts || [];
891
898
  const sourceProvider = oauthUser?.sourceProvider;
@@ -893,6 +900,7 @@ module.exports = {
893
900
  const userWallet = fromAppDid(oauthAccount.id, blockletWallet.secretKey);
894
901
  await declareAccount({ wallet: userWallet, blocklet });
895
902
  await migrateAccount({ wallet: userWallet, blocklet, user: bindUser });
903
+
896
904
  await node.createAuditLog(
897
905
  {
898
906
  action: 'connectAccount',
@@ -3,7 +3,7 @@ const joinUrl = require('url-join');
3
3
  const { getConnectAppUrl, getChainInfo } = require('@blocklet/meta/lib/util');
4
4
  const { WELLKNOWN_SERVICE_PATH_PREFIX } = require('@abtnode/constant');
5
5
  const { LOGIN_PROVIDER } = require('@blocklet/constant');
6
- const { getProvider } = require('../../util/federated');
6
+ const { getLoginProvider } = require('@blocklet/sdk/lib/util/login');
7
7
 
8
8
  module.exports = {
9
9
  appInfo: async ({ request, baseUrl, extraParams }) => {
@@ -16,7 +16,7 @@ module.exports = {
16
16
  ]);
17
17
  // 对于 ux 来说, 要展示的始终是 pid,所以这个给 agentDid 的赋值也需要是 pid
18
18
  let agentDid;
19
- const provider = getProvider(request, extraParams);
19
+ const provider = getLoginProvider(request, extraParams);
20
20
  // federated 登录模式下,需要告知原有的 blocklet-did
21
21
  if (provider === LOGIN_PROVIDER.FEDERATED) {
22
22
  agentDid = blocklet.appPid;
@@ -11,10 +11,10 @@ const { WELLKNOWN_SERVICE_PATH_PREFIX, NODE_SERVICES_PREFIX } = require('@abtnod
11
11
  const DynamicStorage = require('@abtnode/connect-storage');
12
12
  const { fromPublicKey } = require('@ocap/wallet');
13
13
  const { LOGIN_PROVIDER } = require('@blocklet/constant');
14
+ const { getLoginProvider } = require('@blocklet/sdk/lib/util/login');
14
15
 
15
16
  const cache = require('../../cache');
16
17
  const { appInfo, chainInfo } = require('./shared');
17
- const { getProvider } = require('../../util/federated');
18
18
 
19
19
  module.exports = (node, opts) => {
20
20
  const authenticator = new WalletAuthenticator({
@@ -25,7 +25,7 @@ module.exports = (node, opts) => {
25
25
  return wallet.toJSON();
26
26
  },
27
27
  delegator: async ({ request, extraParams }) => {
28
- const provider = getProvider(request, extraParams);
28
+ const provider = getLoginProvider(request, extraParams);
29
29
 
30
30
  const blocklet = await request.getBlocklet();
31
31
  if (provider === LOGIN_PROVIDER.FEDERATED) {
@@ -51,7 +51,7 @@ module.exports = (node, opts) => {
51
51
  },
52
52
  delegation: async ({ request, extraParams }) => {
53
53
  const { wallet: delegatee, permanentWallet: delegator } = await request.getBlockletInfo();
54
- const provider = getProvider(request, extraParams);
54
+ const provider = getLoginProvider(request, extraParams);
55
55
  if (provider === LOGIN_PROVIDER.FEDERATED) {
56
56
  const blocklet = await request.getBlocklet();
57
57
  const delegation = get(blocklet, 'settings.federated.config.delegation');
@@ -376,7 +376,7 @@ async function bind(req, node, options) {
376
376
  };
377
377
  }
378
378
  const nodeInfo = await req.getNodeInfo();
379
- await transferPassport(oauthUser, bindUser, { req, node, teamDid, nodeInfo });
379
+ await transferPassport(oauthUser, bindUser, { req, node, teamDid, nodeInfo, revokePassport: true });
380
380
  await node.createAuditLog(
381
381
  {
382
382
  action: 'connectAccount',
@@ -407,7 +407,25 @@ module.exports = {
407
407
  const issuerDidList = uniq([blockletWallet.address, ...getBlockletAppIdList(blocklet)]);
408
408
  // NOTICE: 这里获取的 did 是当前登录用户的永久 did,无需查询 connectedAccount
409
409
  const user = await node.getUser({ teamDid, user: { did: userDid } });
410
- const ownerAvatarUrl = getUserAvatarUrl(appUrl, user.avatar);
410
+ let ownerAvatarUrl = getUserAvatarUrl(appUrl, user.avatar);
411
+ try {
412
+ // FIXME: @zhanghan 暂时将 imageFilter 等 queryString 参数移除
413
+ const ownerAvatarUrlInstance = new URL(ownerAvatarUrl);
414
+ ownerAvatarUrlInstance.search = '';
415
+ ownerAvatarUrl = ownerAvatarUrlInstance.href;
416
+ } catch {
417
+ /* empty */
418
+ }
419
+ let issuerAvatarUrl = getAppAvatarUrl(appUrl);
420
+ try {
421
+ // FIXME: @zhanghan 暂时将 imageFilter 等 queryString 参数移除
422
+ const issuerAvatarUrlInstance = new URL(issuerAvatarUrl);
423
+ issuerAvatarUrlInstance.search = '';
424
+ issuerAvatarUrl = issuerAvatarUrlInstance.href;
425
+ } catch {
426
+ /* empty */
427
+ }
428
+
411
429
  const { passports = [] } = user || {};
412
430
  // NOTICE: 保持每一种 role 的 passport 只有一个即可
413
431
  const passportTypes = uniqBy(
@@ -429,7 +447,7 @@ module.exports = {
429
447
  title: x.title,
430
448
  issuer: x.issuer.name,
431
449
  issuerDid: x.issuer.id,
432
- issuerAvatarUrl: getAppAvatarUrl(appUrl),
450
+ issuerAvatarUrl,
433
451
  ownerName: user?.fullName,
434
452
  ownerDid: userDid,
435
453
  ownerAvatarUrl,
@@ -463,7 +481,7 @@ module.exports = {
463
481
  // NOTICE: 这里获取的 did 是当前登录用户的永久 did,无需查询 connectedAccount
464
482
  const user = await node.getUser({ teamDid, user: { did: userDid } });
465
483
  const { passports = [] } = user || {};
466
- const passport = passports.find((item) => item.id === passportId);
484
+ const passport = passportId ? passports.find((item) => item.id === passportId) : { name: 'Guest', role: 'guest' };
467
485
  await node.createAuditLog(
468
486
  {
469
487
  action: 'switchPassport',
@@ -33,14 +33,17 @@ async function getFederatedTrustedIssuers(blocklet) {
33
33
  }
34
34
 
35
35
  async function getTrustedIssuers(blocklet, { provider = LOGIN_PROVIDER.WALLET } = {}) {
36
+ let federatedTrustedIssuers = [];
36
37
  if (provider === LOGIN_PROVIDER.FEDERATED) {
37
- const federatedTrustedIssuers = await getFederatedTrustedIssuers(blocklet);
38
-
39
- return federatedTrustedIssuers;
38
+ federatedTrustedIssuers = await getFederatedTrustedIssuers(blocklet);
40
39
  }
41
40
 
42
41
  const trustedPassports = (blocklet.trustedPassports || []).map((x) => x.issuerDid);
43
- const trustedIssuers = [...getBlockletAppIdList(blocklet), ...trustedPassports].filter(Boolean);
42
+ // NOTICE: 在某个应用的页面登录时,需要将该应用自身颁发的通行证页放入 trustedIssuers,这样才能登录应用独立颁发的 Passport
43
+ // 使用该通行证登录后,其他应用均会展示为 guest
44
+ const trustedIssuers = [...getBlockletAppIdList(blocklet), ...trustedPassports, ...federatedTrustedIssuers].filter(
45
+ Boolean
46
+ );
44
47
  return trustedIssuers;
45
48
  }
46
49
 
@@ -1,6 +1,5 @@
1
1
  const joinUrl = require('url-join');
2
2
  const { USER_AVATAR_URL_PREFIX, WELLKNOWN_SERVICE_PATH_PREFIX, USER_AVATAR_PATH_PREFIX } = require('@abtnode/constant');
3
- const { LOGIN_PROVIDER } = require('@blocklet/constant');
4
3
 
5
4
  function getFederatedMaster(blocklet) {
6
5
  const { sites } = blocklet?.settings?.federated || {};
@@ -23,20 +22,8 @@ function getUserAvatarUrl(avatar, blocklet) {
23
22
  return avatarUrl;
24
23
  }
25
24
 
26
- function getProvider(request, extraParams = {}) {
27
- let provider = LOGIN_PROVIDER.WALLET;
28
- // 1. 优先读取当前登录用户的 provider
29
- ({ provider } = request.user || {});
30
- if (!provider) {
31
- // 读取在 extraParams 中指定的 provider
32
- ({ provider } = extraParams);
33
- }
34
- return provider;
35
- }
36
-
37
25
  module.exports = {
38
26
  isMaster,
39
27
  getFederatedMaster,
40
28
  getUserAvatarUrl,
41
- getProvider,
42
29
  };