@abtnode/auth 1.16.23-beta-47ca27f8 → 1.16.23-beta-f25d8f54

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/auth.js CHANGED
@@ -799,9 +799,13 @@ const handleIssuePassportResponse = async ({
799
799
  await updateSession({ passportId: vc.id });
800
800
 
801
801
  return {
802
- disposition: 'attachment',
803
- type: 'VerifiableCredential',
804
- data: vc,
802
+ response: {
803
+ disposition: 'attachment',
804
+ type: 'VerifiableCredential',
805
+ data: vc,
806
+ },
807
+ role,
808
+ passport,
805
809
  };
806
810
  };
807
811
 
package/lib/invitation.js CHANGED
@@ -7,10 +7,120 @@ const { getDisplayName } = require('@blocklet/meta/lib/util');
7
7
  const logger = require('@abtnode/logger')(require('../package.json').name);
8
8
  const { getUserAvatarUrl } = require('@abtnode/util/lib/user');
9
9
 
10
+ /**
11
+ * @typedef {Object} InvitationInfo
12
+ * @property {string} inviteId
13
+ * @property {string} teamDid
14
+ * @property {number} expireDate
15
+ * @property {Object} info
16
+ * @property {Object} inviter
17
+ * @property {Object} receiver
18
+ * @property {Object} role
19
+ * @property {string} remark
20
+ */
21
+ /**
22
+ * @typedef {Object} InvitationData
23
+ * @property {string} inviteId
24
+ * @property {string} teamDid
25
+ * @property {Date} expireDate
26
+ * @property {Object} inviter
27
+ * @property {Object} role
28
+ * @property {string} remark
29
+ */
30
+
31
+ /**
32
+ * @typedef {Object} IssuePassportData
33
+ * @property {string} id
34
+ * @property {'passport-issuance'} type
35
+ * @property {string} key - 实际上是颁发者的 userDid
36
+ * @property {string} name
37
+ * @property {string} title
38
+ * @property {string} ownerDid
39
+ * @property {string} teamDid
40
+ * @property {number} expireDate
41
+ * @property {Date} createdAt
42
+ * @property {Date} updatedAt
43
+ */
44
+
45
+ /**
46
+ * @typedef {Object} Role
47
+ * @property {string} name
48
+ * @property {string} title
49
+ * @property {string} description
50
+ * @property {Arrary} permissions
51
+ * @property {Arrary} grants
52
+ */
53
+
54
+ async function getInvitation({ node, teamDid, inviteId, roles }) {
55
+ /**
56
+ * @type {InvitationData}
57
+ */
58
+ const invitationData = await node.getInvitation({ teamDid, inviteId });
59
+ if (invitationData) {
60
+ /**
61
+ * @type {Role}
62
+ */
63
+ const role = roles.find((v) => v.name === invitationData.role);
64
+ const invitation = {
65
+ ...invitationData,
66
+ expireDate: new Date(invitationData.expireDate).getTime(),
67
+ receiver: null,
68
+ };
69
+
70
+ return {
71
+ invitation,
72
+ role,
73
+ };
74
+ }
75
+ return {
76
+ invitation: null,
77
+ role: null,
78
+ };
79
+ }
80
+
81
+ /**
82
+ * 通过指定用户颁发通行证获得 invitation 数据结构
83
+ * @returns {Promise<{invitation: InvitationInfo, role: Role}>}
84
+ */
85
+ async function getInvitationByIssuePassport({ node, teamDid, inviteId, roles }) {
86
+ /**
87
+ * @type {IssuePassportData}
88
+ */
89
+ const passportIssuance = await node.getPassportIssuance({ teamDid, sessionId: inviteId });
90
+ if (passportIssuance) {
91
+ const role = roles.find((v) => v.name === passportIssuance.name);
92
+
93
+ const invitation = {
94
+ inviteId: passportIssuance.id,
95
+ teamDid,
96
+ expireDate: new Date(passportIssuance.expireDate).getTime(),
97
+ inviter: {
98
+ did: passportIssuance.key,
99
+ },
100
+ remark: '',
101
+ role: {
102
+ name: passportIssuance.name,
103
+ title: passportIssuance.title,
104
+ },
105
+ receiver: {
106
+ did: passportIssuance.ownerDid,
107
+ },
108
+ };
109
+ return {
110
+ invitation,
111
+ role,
112
+ };
113
+ }
114
+ return {
115
+ invitation: null,
116
+ role: null,
117
+ };
118
+ }
119
+
10
120
  module.exports = {
11
121
  init(server, node, { prefix, type } = {}) {
12
122
  server.get(`${prefix}/invitation`, async (req, res) => {
13
- const { inviteId } = req.query;
123
+ const { inviteId, mode = 'invite' } = req.query;
14
124
  const groupPathPrefix = req.headers['x-group-path-prefix'] || '/';
15
125
 
16
126
  const nodeInfo = await node.getNodeInfo();
@@ -43,15 +153,28 @@ module.exports = {
43
153
  }
44
154
 
45
155
  const teamDid = info.did;
46
- const invitations = await node.getInvitations({ teamDid, filter: () => true });
47
- const invitation = invitations.find((v) => v.inviteId === inviteId);
156
+ const roles = await node.getRoles({ teamDid });
157
+ let invitation;
158
+ let role;
159
+ if (mode === 'invite') {
160
+ ({ invitation, role } = await getInvitation({
161
+ node,
162
+ inviteId,
163
+ teamDid,
164
+ roles,
165
+ }));
166
+ } else if (mode === 'issue-passport') {
167
+ ({ invitation, role } = await getInvitationByIssuePassport({ node, inviteId, teamDid, roles }));
168
+ } else {
169
+ res.status(400).send('Invitation mode is invalid');
170
+ return;
171
+ }
172
+
48
173
  if (!invitation || Date.now() > new Date(invitation.expireDate).getTime()) {
49
174
  res.status(404).send('Invitation not found or invitation has been used');
50
175
  return;
51
176
  }
52
177
 
53
- const roles = await node.getRoles({ teamDid });
54
- const role = roles.find((v) => v.name === invitation.role);
55
178
  try {
56
179
  role.permissions = await node.getPermissionsByRole({ teamDid, role: { name: role.name } });
57
180
  } catch (err) {
@@ -71,10 +194,10 @@ module.exports = {
71
194
  }
72
195
 
73
196
  const inviter = {
74
- did: invitation.inviter.did,
75
- email: invitation.inviter.email,
76
- fullName: invitation.inviter.fullName || user?.fullName,
77
- role: invitation.inviter.role,
197
+ did: user.did,
198
+ email: user.email,
199
+ fullName: user.fullName,
200
+ role: user.role,
78
201
  avatar: getUserAvatarUrl(baseUrl, user.avatar, nodeInfo, isServer),
79
202
  };
80
203
 
@@ -82,7 +205,6 @@ module.exports = {
82
205
  ...invitation,
83
206
  info: omit(info, 'dataDir'),
84
207
  inviter,
85
- inviterRaw: invitation.inviter,
86
208
  role: role || {},
87
209
  });
88
210
  } catch (err) {
@@ -9,7 +9,7 @@ const getNodeWallet = require('@abtnode/util/lib/get-app-wallet');
9
9
  const { getDisplayName, getBlockletAppIdList } = require('@blocklet/meta/lib/util');
10
10
  const { VC_TYPE_NODE_PASSPORT, PASSPORT_STATUS, NODE_DATA_DIR_NAME } = require('@abtnode/constant');
11
11
  const get = require('lodash/get');
12
- const { getUserAvatarUrl, getAppAvatarUrl, getServerAvatarUrl } = require('@abtnode/util/lib/user');
12
+ const { getUserAvatarUrl, getAppAvatarUrl, getServerAvatarUrl, extractUserAvatar } = require('@abtnode/util/lib/user');
13
13
  const { getWalletDid } = require('@blocklet/meta/lib/did-utils');
14
14
 
15
15
  const logger = require('./logger');
@@ -176,7 +176,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
176
176
  const { locale, passportName, receiverDid } = extraParams;
177
177
  checkWalletVersion({ didwallet, locale });
178
178
 
179
- const { teamDid, issuerDid, issuerName, issuerLogo, passportColor, info } = await getApplicationInfo({
179
+ const { teamDid, issuerDid, issuerName, issuerLogo, passportColor, info, dataDir } = await getApplicationInfo({
180
180
  node,
181
181
  req: request,
182
182
  type,
@@ -185,6 +185,8 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
185
185
  const user = await getUser(node, teamDid, receiverDid, { enableConnectedAccount: true });
186
186
  const passport = await createPassport({ name: passportName, node, teamDid, locale });
187
187
 
188
+ const avatar = await extractUserAvatar(user.avatar, { dataDir });
189
+
188
190
  return {
189
191
  description: messages.receivePassport[locale],
190
192
  data: getRandomMessage(),
@@ -198,7 +200,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
198
200
  issuerAvatarUrl: issuerLogo,
199
201
  ownerDid: receiverDid,
200
202
  ownerName: user.fullName || '',
201
- ownerAvatarUrl: getUserAvatarUrl(baseUrl, user.avatar, info, info.did === teamDid),
203
+ ownerAvatarUrl: getUserAvatarUrl(baseUrl, avatar, info, info.did === teamDid),
202
204
  preferredColor: passportColor,
203
205
  }),
204
206
  }),
@@ -210,7 +212,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
210
212
  onAuth: async ({ claims, userDid, userPk, extraParams, updateSession, baseUrl, req }) => {
211
213
  const { locale = 'en', receiverDid, passportName } = extraParams;
212
214
 
213
- const { teamDid, issuerDidList, issuerName, issuerLogo, issuerWallet, passportColor, info } =
215
+ const { teamDid, issuerDidList, issuerName, issuerLogo, issuerWallet, passportColor, info, dataDir } =
214
216
  await getApplicationInfo({ node, req, type, baseUrl });
215
217
  const statusEndpointBaseUrl = getStatusEndpointBaseUrl(type, baseUrl, authServicePrefix);
216
218
 
@@ -261,6 +263,8 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
261
263
  );
262
264
  }
263
265
 
266
+ const avatar = await extractUserAvatar(user.avatar, { dataDir });
267
+
264
268
  const vcParams = {
265
269
  issuerName,
266
270
  issuerWallet,
@@ -279,7 +283,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
279
283
  teamDid,
280
284
  }),
281
285
  types: [],
282
- ownerProfile: { ...user, avatar: getUserAvatarUrl(baseUrl, user.avatar, info, info.did === teamDid) },
286
+ ownerProfile: { ...user, avatar: getUserAvatarUrl(baseUrl, avatar, info, info.did === teamDid) },
283
287
  preferredColor: passportColor,
284
288
  };
285
289
 
package/locales/ar.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'غير مسموح بنقل الخادم إلى نفسك',
65
65
  tagRequired: 'العلامة مطلوبة',
66
66
  appIsInProgress: 'التطبيق قيد التقدم، يرجى الانتظار حتى الانتهاء.',
67
+ requestDidSpace: 'يرجى تفويض مساحة DID للاستمرار',
67
68
  };
package/locales/de.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'Nicht erlaubt, den Server an sich selbst zu übertragen',
65
65
  tagRequired: 'Es ist ein Pflichtfeld',
66
66
  appIsInProgress: 'Die Anwendung befindet sich in Bearbeitung. Bitte warten Sie, bis sie abgeschlossen ist.',
67
+ requestDidSpace: 'Bitte autorisieren Sie DID Space, um fortzufahren',
67
68
  };
package/locales/es.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'No se permite transferir el servidor a ti mismo',
65
65
  tagRequired: 'La etiqueta es requerida',
66
66
  appIsInProgress: 'La aplicación está en progreso, por favor espere a que termine',
67
+ requestDidSpace: 'Por favor, autoriza a DID Space para continuar',
67
68
  };
package/locales/fr.js CHANGED
@@ -65,4 +65,5 @@ module.exports = {
65
65
  notAllowedTransferToSelf: 'Interdiction de transférer le serveur vers vous-même',
66
66
  tagRequired: 'Les balises sont obligatoires',
67
67
  appIsInProgress: "L'application est en cours, veuillez attendre qu'elle se termine.",
68
+ requestDidSpace: 'Veuillez autoriser DID Space à continuer',
68
69
  };
package/locales/hi.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'सर्वर को खुद को स्थानांतरित करने की अनुमति नहीं है',
65
65
  tagRequired: 'टैग आवश्यक है',
66
66
  appIsInProgress: 'ऐप्लीकेशन प्रगति में है, कृपया पूरा होने तक प्रतीक्षा करें।',
67
+ requestDidSpace: 'कृपया DID स्थान की प्राधिकरणदिये जारी रखें',
67
68
  };
package/locales/i18n.db CHANGED
Binary file
package/locales/id.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'Dilarang mentransfer Server ke diri sendiri',
65
65
  tagRequired: 'Tag diperlukan',
66
66
  appIsInProgress: 'Aplikasi ini sedang berjalan, mohon tunggu hingga selesai',
67
+ requestDidSpace: 'Silakan otorisasi DID Space untuk melanjutkan',
67
68
  };
package/locales/ja.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'サーバーを自分に移動することは許可されていません',
65
65
  tagRequired: 'タグは必須です',
66
66
  appIsInProgress: 'アプリケーションは進行中です。完了するまでお待ちください',
67
+ requestDidSpace: '続行するためにDID Spaceへの承認をお願いします',
67
68
  };
package/locales/ko.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: '서버를 자신에게 전송할 수 없습니다',
65
65
  tagRequired: '태그가 필요합니다',
66
66
  appIsInProgress: '애플리케이션 진행 중입니다. 완료될 때까지 기다려주세요',
67
+ requestDidSpace: '계속하려면 DID Space를 인증해주세요',
67
68
  };
package/locales/pt.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'Não é permitido transferir o servidor para você mesmo',
65
65
  tagRequired: 'A tag é necessária',
66
66
  appIsInProgress: 'O aplicativo está em progresso, por favor, aguarde até que ele termine',
67
+ requestDidSpace: 'Por favor, autorize o DID Space a continuar',
67
68
  };
package/locales/ru.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'Запрещено передавать сервер себе',
65
65
  tagRequired: 'Требуется тег',
66
66
  appIsInProgress: 'Приложение находится в процессе, пожалуйста, подождите, пока оно закончится.',
67
+ requestDidSpace: 'Пожалуйста, авторизуйте DID Space для продолжения',
67
68
  };
package/locales/th.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'ไม่อนุญาตให้โอนเซิร์ฟเวอร์ให้ตัวเอง',
65
65
  tagRequired: 'ต้องใส่แท็ก',
66
66
  appIsInProgress: 'แอปพลิเคชันกำลังดำเนินการ โปรดรอให้เสร็จสิ้น',
67
+ requestDidSpace: 'โปรดอนุญาตให้ DID Space ดำเนินการต่อ',
67
68
  };
package/locales/vi.js CHANGED
@@ -64,4 +64,5 @@ module.exports = {
64
64
  notAllowedTransferToSelf: 'Không được phép chuyển máy chủ cho chính bạn',
65
65
  tagRequired: 'Tag là bắt buộc',
66
66
  appIsInProgress: 'Ứng dụng đang tiến hành, vui lòng đợi cho đến khi nó hoàn thành',
67
+ requestDidSpace: 'Vui lòng cho phép DID Space tiếp tục',
67
68
  };
package/locales/zh-tw.js CHANGED
@@ -62,4 +62,5 @@ module.exports = {
62
62
  notAllowedTransferToSelf: '不允許將伺服器轉移到您自己',
63
63
  tagRequired: '需要標籤',
64
64
  appIsInProgress: '應用程式正在進行中,請等待完成',
65
+ requestDidSpace: '請授權DID Space繼續',
65
66
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.23-beta-47ca27f8",
6
+ "version": "1.16.23-beta-f25d8f54",
7
7
  "description": "Simple lib to manage auth in ABT Node",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -20,15 +20,15 @@
20
20
  "author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
- "@abtnode/constant": "1.16.23-beta-47ca27f8",
24
- "@abtnode/logger": "1.16.23-beta-47ca27f8",
25
- "@abtnode/util": "1.16.23-beta-47ca27f8",
23
+ "@abtnode/constant": "1.16.23-beta-f25d8f54",
24
+ "@abtnode/logger": "1.16.23-beta-f25d8f54",
25
+ "@abtnode/util": "1.16.23-beta-f25d8f54",
26
26
  "@arcblock/did": "1.18.110",
27
- "@arcblock/nft-display": "2.9.24",
27
+ "@arcblock/nft-display": "2.9.28",
28
28
  "@arcblock/validator": "^1.18.110",
29
29
  "@arcblock/vc": "1.18.110",
30
- "@blocklet/constant": "1.16.23-beta-47ca27f8",
31
- "@blocklet/meta": "1.16.23-beta-47ca27f8",
30
+ "@blocklet/constant": "1.16.23-beta-f25d8f54",
31
+ "@blocklet/meta": "1.16.23-beta-f25d8f54",
32
32
  "@ocap/client": "^1.18.110",
33
33
  "@ocap/mcrypto": "1.18.110",
34
34
  "@ocap/util": "1.18.110",
@@ -49,5 +49,5 @@
49
49
  "devDependencies": {
50
50
  "jest": "^29.7.0"
51
51
  },
52
- "gitHead": "d0a1e85532a1826150275067f55e0f3873ea39d6"
52
+ "gitHead": "0c6357195f3e28095234bc05cfb4f3b051474377"
53
53
  }