@abtnode/core 1.16.8-next-d1e52353 → 1.16.8-next-c66e39c7
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/api/team.js +20 -0
- package/lib/index.js +3 -0
- package/lib/states/blocklet.js +16 -1
- package/lib/states/user.js +54 -76
- package/package.json +17 -17
package/lib/api/team.js
CHANGED
|
@@ -261,6 +261,26 @@ class TeamAPI extends EventEmitter {
|
|
|
261
261
|
return state.getUser(user.did, options);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
async getUserByDid({ teamDid, userDid }) {
|
|
265
|
+
const state = await this.getUserState(teamDid);
|
|
266
|
+
return state.getUserByDid(userDid);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async isUserValid({ teamDid, userDid }) {
|
|
270
|
+
const state = await this.getUserState(teamDid);
|
|
271
|
+
return state.isUserValid(userDid);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async isPassportValid({ teamDid, passportId }) {
|
|
275
|
+
const state = await this.getUserState(teamDid);
|
|
276
|
+
return state.isPassportValid(passportId);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
async isConnectedAccount({ teamDid, did }) {
|
|
280
|
+
const state = await this.getUserState(teamDid);
|
|
281
|
+
return state.isConnectedAccount(did);
|
|
282
|
+
}
|
|
283
|
+
|
|
264
284
|
async getOwner({ teamDid }) {
|
|
265
285
|
const owner = await this.teamManager.getOwner(teamDid);
|
|
266
286
|
|
package/lib/index.js
CHANGED
|
@@ -342,6 +342,9 @@ function ABTNode(options) {
|
|
|
342
342
|
updateUser: teamAPI.updateUser.bind(teamAPI),
|
|
343
343
|
updateUserApproval: teamAPI.updateUserApproval.bind(teamAPI),
|
|
344
344
|
updateUserRole: teamAPI.updateUserRole.bind(teamAPI),
|
|
345
|
+
getUserByDid: teamAPI.getUserByDid.bind(teamAPI),
|
|
346
|
+
isPassportValid: teamAPI.isPassportValid.bind(teamAPI),
|
|
347
|
+
isConnectedAccount: teamAPI.isConnectedAccount.bind(teamAPI),
|
|
345
348
|
|
|
346
349
|
// Access Control
|
|
347
350
|
getRBAC: (did = options.nodeDid) => teamManager.getRBAC(did),
|
package/lib/states/blocklet.js
CHANGED
|
@@ -140,6 +140,8 @@ class BlockletState extends BaseState {
|
|
|
140
140
|
constructor(model, config = {}) {
|
|
141
141
|
super(model, config);
|
|
142
142
|
this.defaultPort = config.blockletPort || 5555;
|
|
143
|
+
// @didMap: { [did: string]: metaDid: string }
|
|
144
|
+
this.didMap = new Map();
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
async getBlocklet(did, { decryptSk = true } = {}) {
|
|
@@ -152,8 +154,17 @@ class BlockletState extends BaseState {
|
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
async getBlockletMetaDid(did) {
|
|
157
|
+
if (this.didMap.has(did)) {
|
|
158
|
+
return this.didMap.get(did);
|
|
159
|
+
}
|
|
160
|
+
|
|
155
161
|
const doc = await this.getBlocklet(did);
|
|
156
|
-
|
|
162
|
+
if (doc?.meta?.did) {
|
|
163
|
+
this.didMap.set(did, doc.meta.did);
|
|
164
|
+
return doc.meta.did;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return null;
|
|
157
168
|
}
|
|
158
169
|
|
|
159
170
|
async getBlockletStatus(did) {
|
|
@@ -182,6 +193,10 @@ class BlockletState extends BaseState {
|
|
|
182
193
|
}
|
|
183
194
|
|
|
184
195
|
await this.remove({ id: doc.id });
|
|
196
|
+
|
|
197
|
+
this.didMap.delete(doc.meta?.did);
|
|
198
|
+
this.didMap.delete(doc.appDid);
|
|
199
|
+
|
|
185
200
|
this.emit('remove', doc);
|
|
186
201
|
return formatBlocklet(doc, 'onRead', this.config.dek);
|
|
187
202
|
}
|
package/lib/states/user.js
CHANGED
|
@@ -159,19 +159,8 @@ class User extends ExtendBase {
|
|
|
159
159
|
* Get blocklet service user list
|
|
160
160
|
*/
|
|
161
161
|
async getUsers({ query, sort, paging } = {}) {
|
|
162
|
-
const { approved, role, search, connectedDid } = query || {};
|
|
163
|
-
|
|
164
162
|
const where = {};
|
|
165
|
-
const
|
|
166
|
-
{
|
|
167
|
-
model: this.models.Passport,
|
|
168
|
-
as: 'passports',
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
model: this.models.ConnectedAccount,
|
|
172
|
-
as: 'connectedAccounts',
|
|
173
|
-
},
|
|
174
|
-
];
|
|
163
|
+
const { approved, role, search } = query || {};
|
|
175
164
|
|
|
176
165
|
if (isNullOrUndefined(approved) === false) {
|
|
177
166
|
where.approved = approved;
|
|
@@ -188,29 +177,26 @@ class User extends ExtendBase {
|
|
|
188
177
|
}
|
|
189
178
|
}
|
|
190
179
|
|
|
191
|
-
if (role && role !== '$all') {
|
|
180
|
+
if (role && role !== '$all' && !where.did) {
|
|
192
181
|
if (role === '$none') {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
[Op.or]: [{ name: null }, { id: null }],
|
|
182
|
+
where.did = {
|
|
183
|
+
[Op.notIn]: Sequelize.literal('(SELECT DISTINCT userDid FROM passports)'),
|
|
196
184
|
};
|
|
197
185
|
} else {
|
|
198
|
-
|
|
199
|
-
|
|
186
|
+
where.did = {
|
|
187
|
+
[Op.in]: Sequelize.literal(
|
|
188
|
+
`(SELECT DISTINCT userDid FROM passports WHERE name = '${role}' AND status = '${PASSPORT_STATUS.VALID}')`
|
|
189
|
+
),
|
|
190
|
+
};
|
|
200
191
|
}
|
|
201
192
|
}
|
|
202
193
|
|
|
203
|
-
if (connectedDid) {
|
|
204
|
-
include[1].where = { did: connectedDid };
|
|
205
|
-
include[1].required = true;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
194
|
const sorting = pickBy(sort, (x) => !isNullOrUndefined(x));
|
|
209
195
|
if (!Object.keys(sorting).length) {
|
|
210
196
|
sorting.createdAt = -1;
|
|
211
197
|
}
|
|
212
198
|
|
|
213
|
-
return this.paginate({ where
|
|
199
|
+
return this.paginate({ where }, sorting, paging);
|
|
214
200
|
}
|
|
215
201
|
|
|
216
202
|
async getUsersByDids({ dids, query }) {
|
|
@@ -220,19 +206,7 @@ class User extends ExtendBase {
|
|
|
220
206
|
condition.approved = !!approved;
|
|
221
207
|
}
|
|
222
208
|
|
|
223
|
-
return this.find({
|
|
224
|
-
where: condition,
|
|
225
|
-
include: [
|
|
226
|
-
{
|
|
227
|
-
model: this.models.ConnectedAccount,
|
|
228
|
-
as: 'connectedAccounts',
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
model: this.models.Passport,
|
|
232
|
-
as: 'passports',
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
});
|
|
209
|
+
return this.find({ where: condition });
|
|
236
210
|
}
|
|
237
211
|
|
|
238
212
|
async countByPassport({ name, status = PASSPORT_STATUS.VALID }) {
|
|
@@ -253,14 +227,13 @@ class User extends ExtendBase {
|
|
|
253
227
|
return this.count({
|
|
254
228
|
distinct: true,
|
|
255
229
|
col: 'did',
|
|
256
|
-
|
|
257
|
-
{
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
where: { name, status },
|
|
230
|
+
where: {
|
|
231
|
+
did: {
|
|
232
|
+
[Op.in]: Sequelize.literal(
|
|
233
|
+
`(SELECT DISTINCT userDid FROM passports WHERE name = '${name}' AND status = '${status}')`
|
|
234
|
+
),
|
|
262
235
|
},
|
|
263
|
-
|
|
236
|
+
},
|
|
264
237
|
});
|
|
265
238
|
}
|
|
266
239
|
|
|
@@ -269,40 +242,26 @@ class User extends ExtendBase {
|
|
|
269
242
|
* @param {string} did user's did
|
|
270
243
|
*/
|
|
271
244
|
async getUser(did, { enableConnectedAccount = false } = {}) {
|
|
272
|
-
let user = await this.findOne({
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
},
|
|
283
|
-
],
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
if (enableConnectedAccount && !user) {
|
|
287
|
-
user = await this.findOne({
|
|
288
|
-
include: [
|
|
289
|
-
{
|
|
290
|
-
model: this.models.ConnectedAccount,
|
|
291
|
-
as: 'connectedAccounts',
|
|
292
|
-
where: { did },
|
|
293
|
-
required: true,
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
model: this.models.Passport,
|
|
297
|
-
as: 'passports',
|
|
298
|
-
},
|
|
299
|
-
],
|
|
300
|
-
});
|
|
245
|
+
let user = await this.findOne({ did });
|
|
246
|
+
let connectedAccounts = [];
|
|
247
|
+
let passports = [];
|
|
248
|
+
|
|
249
|
+
// search in connected accounts
|
|
250
|
+
if (!user && enableConnectedAccount) {
|
|
251
|
+
const connectedAccount = await this.connectedAccount.findOne({ did });
|
|
252
|
+
if (connectedAccount) {
|
|
253
|
+
user = await this.findOne({ did: connectedAccount.userDid });
|
|
254
|
+
}
|
|
301
255
|
}
|
|
302
256
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
257
|
+
if (user) {
|
|
258
|
+
[connectedAccounts, passports] = await Promise.all([
|
|
259
|
+
this.connectedAccount.find({ userDid: user.did }),
|
|
260
|
+
this.passport.find({ userDid: user.did }),
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
user.connectedAccounts = connectedAccounts;
|
|
264
|
+
user.passports = passports;
|
|
306
265
|
}
|
|
307
266
|
|
|
308
267
|
return user;
|
|
@@ -376,6 +335,25 @@ class User extends ExtendBase {
|
|
|
376
335
|
|
|
377
336
|
return { ...updated, _action: exist ? 'update' : 'add' };
|
|
378
337
|
}
|
|
338
|
+
|
|
339
|
+
async getUserByDid(did) {
|
|
340
|
+
return this.findOne({ did }, { did: 1, pk: 1, fullName: 1, email: 1, role: 1, approved: 1 });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async isUserValid(did) {
|
|
344
|
+
const count = await super.count({ did, approved: true });
|
|
345
|
+
return count > 0;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async isConnectedAccount(did) {
|
|
349
|
+
const count = await this.connectedAccount.count({ did });
|
|
350
|
+
return count > 0;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async isPassportValid(passportId) {
|
|
354
|
+
const count = await this.passport.count({ id: passportId, status: PASSPORT_STATUS.VALID });
|
|
355
|
+
return count > 0;
|
|
356
|
+
}
|
|
379
357
|
}
|
|
380
358
|
|
|
381
359
|
module.exports = User;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.8-next-
|
|
6
|
+
"version": "1.16.8-next-c66e39c7",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.16.8-next-
|
|
23
|
-
"@abtnode/certificate-manager": "1.16.8-next-
|
|
24
|
-
"@abtnode/constant": "1.16.8-next-
|
|
25
|
-
"@abtnode/cron": "1.16.8-next-
|
|
26
|
-
"@abtnode/logger": "1.16.8-next-
|
|
27
|
-
"@abtnode/models": "1.16.8-next-
|
|
28
|
-
"@abtnode/queue": "1.16.8-next-
|
|
29
|
-
"@abtnode/rbac": "1.16.8-next-
|
|
30
|
-
"@abtnode/router-provider": "1.16.8-next-
|
|
31
|
-
"@abtnode/static-server": "1.16.8-next-
|
|
32
|
-
"@abtnode/timemachine": "1.16.8-next-
|
|
33
|
-
"@abtnode/util": "1.16.8-next-
|
|
22
|
+
"@abtnode/auth": "1.16.8-next-c66e39c7",
|
|
23
|
+
"@abtnode/certificate-manager": "1.16.8-next-c66e39c7",
|
|
24
|
+
"@abtnode/constant": "1.16.8-next-c66e39c7",
|
|
25
|
+
"@abtnode/cron": "1.16.8-next-c66e39c7",
|
|
26
|
+
"@abtnode/logger": "1.16.8-next-c66e39c7",
|
|
27
|
+
"@abtnode/models": "1.16.8-next-c66e39c7",
|
|
28
|
+
"@abtnode/queue": "1.16.8-next-c66e39c7",
|
|
29
|
+
"@abtnode/rbac": "1.16.8-next-c66e39c7",
|
|
30
|
+
"@abtnode/router-provider": "1.16.8-next-c66e39c7",
|
|
31
|
+
"@abtnode/static-server": "1.16.8-next-c66e39c7",
|
|
32
|
+
"@abtnode/timemachine": "1.16.8-next-c66e39c7",
|
|
33
|
+
"@abtnode/util": "1.16.8-next-c66e39c7",
|
|
34
34
|
"@arcblock/did": "1.18.78",
|
|
35
35
|
"@arcblock/did-auth": "1.18.78",
|
|
36
36
|
"@arcblock/did-ext": "^1.18.78",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"@arcblock/pm2-events": "^0.0.5",
|
|
42
42
|
"@arcblock/validator": "^1.18.78",
|
|
43
43
|
"@arcblock/vc": "1.18.78",
|
|
44
|
-
"@blocklet/constant": "1.16.8-next-
|
|
45
|
-
"@blocklet/meta": "1.16.8-next-
|
|
46
|
-
"@blocklet/sdk": "1.16.8-next-
|
|
44
|
+
"@blocklet/constant": "1.16.8-next-c66e39c7",
|
|
45
|
+
"@blocklet/meta": "1.16.8-next-c66e39c7",
|
|
46
|
+
"@blocklet/sdk": "1.16.8-next-c66e39c7",
|
|
47
47
|
"@did-space/client": "^0.2.91",
|
|
48
48
|
"@fidm/x509": "^1.2.1",
|
|
49
49
|
"@ocap/mcrypto": "1.18.78",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"express": "^4.18.2",
|
|
97
97
|
"jest": "^27.5.1"
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "d769d1ab5bd56d258d4d1061e2c0f201dcef5676"
|
|
100
100
|
}
|