@abtnode/core 1.16.0-beta-1d6c582e → 1.16.0-beta-99e016c7

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.
@@ -127,6 +127,8 @@ const getLogContent = async (action, args, context, result, info, node) => {
127
127
  return `updated following navigations for blocklet ${getBlockletInfo(result, info)}:\n${args.navigations.map(
128
128
  (x) => `- ${x.title}: ${x.link}\n`
129
129
  )}`;
130
+ case 'configOAuth':
131
+ return `updated following OAuth for blocklet ${getBlockletInfo(result, info)}:\n${args.oauth}`;
130
132
  case 'updateComponentTitle':
131
133
  return `update component title to **${args.title}** for blocklet ${getBlockletInfo(result, info)}`;
132
134
  case 'updateComponentMountPoint':
@@ -271,6 +273,7 @@ const getLogCategory = (action) => {
271
273
  case 'upgradeComponents':
272
274
  case 'configPublicToStore':
273
275
  case 'configNavigations':
276
+ case 'configOAuth':
274
277
  case 'updateComponentTitle':
275
278
  case 'updateComponentMountPoint':
276
279
  return 'blocklet';
@@ -9,6 +9,42 @@ const { validateOwner } = require('../util');
9
9
 
10
10
  const isNullOrUndefined = (x) => x === undefined || x === null;
11
11
 
12
+ /**
13
+ * UserPassport
14
+ * @typedef {Object} UserPassport
15
+ * @property {string} id - id
16
+ * @property {string[]} [type] - passport's type
17
+ * @property {string[]} [issuer] - passport's issuer
18
+ * @property {Date} [issuanceDate] - passport's issuanceDate
19
+ * @property {string} [specVersion] - passport's specVersion
20
+ * @property {string} name - passport's name
21
+ * @property {string} [title] - passport's title
22
+ * @property {string} [endpoint] - passport's endpoint
23
+ * @property {string} [status] - passport's status
24
+ * @property {string} role - passport's role
25
+ */
26
+
27
+ /**
28
+ * The Data structure of blocklet-service user
29
+ * @typedef {Object} BlockletUser - Blocklet Service User Table
30
+ * @property {string} _id - id
31
+ * @property {('profile')} type - type of user
32
+ * @property {string} fullName - user profile's name
33
+ * @property {string} avatar - url of user's avatar, eg: bn://avatar/7f8848569405f8cdf8b1b2788ebf7d0f.jpg
34
+ * @property {string} did - user's did
35
+ * @property {('owner'|'admin'|'member'|'guest'|string)} role - user's role
36
+ * @property {UserPassport[]} passports - user's passport list
37
+ * @property {string} pk - user's publicKey
38
+ * @property {boolean} approved - enable user to login
39
+ * @property {string} locale - locale
40
+ * @property {Object} extra - extra data of user
41
+ * @property {Date} firstLoginAt - firstLoginAt
42
+ * @property {Date} lastLoginAt - lastLoginAt
43
+ * @property {string} lastLoginIp - lastLoginIp
44
+ * @property {Date} createdAt - createdAt
45
+ * @property {Date} updatedAt - updatedAt
46
+ */
47
+
12
48
  class User extends BaseState {
13
49
  constructor(baseDir, config = {}) {
14
50
  super(baseDir, { filename: 'user.db', ...config });
@@ -22,6 +58,11 @@ class User extends BaseState {
22
58
  });
23
59
  }
24
60
 
61
+ /**
62
+ * Add a new user
63
+ * @param {BlockletUser} user - user data
64
+ * @returns {Promise<number>}
65
+ */
25
66
  async add(user) {
26
67
  if (!validateOwner(user)) {
27
68
  throw new Error('user is invalid');
@@ -33,7 +74,14 @@ class User extends BaseState {
33
74
  });
34
75
  }
35
76
 
77
+ /**
78
+ * Update a user
79
+ * @param {BlockletUser} user - user data
80
+ * @returns {BlockletUser}
81
+ */
36
82
  async update(user) {
83
+ // FIXME: @zhanghan 这里为什么要限制?
84
+ // 限制后也无法更新 lastLoginAt ?
37
85
  if (!validateOwner(user)) {
38
86
  throw new Error('user is invalid');
39
87
  }
@@ -59,6 +107,11 @@ class User extends BaseState {
59
107
  return this._setPassportStatusById({ did, id, status: PASSPORT_STATUS.VALID });
60
108
  }
61
109
 
110
+ /**
111
+ * remove a user by user's did
112
+ * @param {string} did - the did of user
113
+ * @returns {number} deleted count
114
+ */
62
115
  async remove({ did }) {
63
116
  const num = await super.remove({ did });
64
117
 
@@ -69,6 +122,12 @@ class User extends BaseState {
69
122
  return num;
70
123
  }
71
124
 
125
+ /**
126
+ * enable/disable user login
127
+ * @param {string} did user's did
128
+ * @param {boolean} approved enable/disable user login
129
+ * @returns {BlockletUser}
130
+ */
72
131
  async updateApproved({ did, approved }) {
73
132
  const [num, doc] = await super.update({ did }, { $set: { approved } });
74
133
 
@@ -79,6 +138,12 @@ class User extends BaseState {
79
138
  return doc;
80
139
  }
81
140
 
141
+ /**
142
+ * update user's role
143
+ * @param {string} did user's did
144
+ * @param {BlockletUser.role} role user's rolel
145
+ * @returns {BlockletUser}
146
+ */
82
147
  async updateRole({ did, role }) {
83
148
  const [num, doc] = await super.update({ did }, { $set: { role } });
84
149
 
@@ -89,8 +154,15 @@ class User extends BaseState {
89
154
  return doc;
90
155
  }
91
156
 
157
+ /**
158
+ * Get blocklet service user list
159
+ * @param {Object} query query params
160
+ * @param {('asc'|'desc')} sort query sort
161
+ * @param {any} paging query paging
162
+ * @returns {{list: BlockletUser[]; paging: any;}}
163
+ */
92
164
  async getUsers({ query, sort, paging: inputPaging } = {}) {
93
- const { approved, role, search } = query || {};
165
+ const { approved, role, search, derivedDid } = query || {};
94
166
 
95
167
  // make query param
96
168
  const queryParam = {};
@@ -121,6 +193,11 @@ class User extends BaseState {
121
193
  }
122
194
  }
123
195
 
196
+ // 根据 derivedDid 查询 user 信息(wallet 账户绑定 oauth 账户后,会有该字段)
197
+ if (derivedDid) {
198
+ queryParam['derivedAccount.did'] = derivedDid;
199
+ }
200
+
124
201
  const sortParam = pickBy(sort, (x) => !isNullOrUndefined(x));
125
202
 
126
203
  if (!Object.keys(sortParam).length) {
@@ -136,6 +213,11 @@ class User extends BaseState {
136
213
  };
137
214
  }
138
215
 
216
+ /**
217
+ * get user list by did list
218
+ * @param {string[]} dids user did list
219
+ * @returns {BlockletUser[]}
220
+ */
139
221
  async getUsersByDids({ dids, query } = {}) {
140
222
  const { approved } = query || {};
141
223
  const didList = dids || [];
@@ -152,6 +234,11 @@ class User extends BaseState {
152
234
  return this.find(queryParam);
153
235
  }
154
236
 
237
+ /**
238
+ * get user by did
239
+ * @param {string} did user's did
240
+ * @returns {BlockletUser}
241
+ */
155
242
  async getUser(did) {
156
243
  const doc = await this.findOne({ did });
157
244
  return doc;
@@ -72,6 +72,7 @@ const {
72
72
  getSharedConfigObj,
73
73
  getComponentName,
74
74
  isEnvShareable,
75
+ getBlockletAppIdList,
75
76
  } = require('@blocklet/meta/lib/util');
76
77
  const toBlockletDid = require('@blocklet/meta/lib/did');
77
78
  const { titleSchema, descriptionSchema, logoSchema } = require('@blocklet/meta/lib/schema');
@@ -429,6 +430,8 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
429
430
  ? getBlockletWallet(blocklet.meta.did, nodeEnvironments.ABT_NODE_SK, undefined, 1)
430
431
  : null;
431
432
 
433
+ const BLOCKLET_APP_IDS = getBlockletAppIdList(root).join(',');
434
+
432
435
  const env = {
433
436
  ...blocklet.configObj,
434
437
  ...getSharedConfigObj(blocklet, ancestors),
@@ -439,6 +442,7 @@ const getRuntimeEnvironments = (blocklet, nodeEnvironments, ancestors) => {
439
442
  BLOCKLET_MODE: blocklet.mode || BLOCKLET_MODES.PRODUCTION,
440
443
  BLOCKLET_APP_EK: tmp?.secretKey,
441
444
  BLOCKLET_APP_VERSION: root.meta.version,
445
+ BLOCKLET_APP_IDS,
442
446
  ...nodeEnvironments,
443
447
  ...safeNodeEnvironments,
444
448
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.0-beta-1d6c582e",
6
+ "version": "1.16.0-beta-99e016c7",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,34 +19,34 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.16.0-beta-1d6c582e",
23
- "@abtnode/certificate-manager": "1.16.0-beta-1d6c582e",
24
- "@abtnode/constant": "1.16.0-beta-1d6c582e",
25
- "@abtnode/cron": "1.16.0-beta-1d6c582e",
26
- "@abtnode/db": "1.16.0-beta-1d6c582e",
27
- "@abtnode/logger": "1.16.0-beta-1d6c582e",
28
- "@abtnode/queue": "1.16.0-beta-1d6c582e",
29
- "@abtnode/rbac": "1.16.0-beta-1d6c582e",
30
- "@abtnode/router-provider": "1.16.0-beta-1d6c582e",
31
- "@abtnode/static-server": "1.16.0-beta-1d6c582e",
32
- "@abtnode/timemachine": "1.16.0-beta-1d6c582e",
33
- "@abtnode/util": "1.16.0-beta-1d6c582e",
34
- "@arcblock/did": "1.18.62",
22
+ "@abtnode/auth": "1.16.0-beta-99e016c7",
23
+ "@abtnode/certificate-manager": "1.16.0-beta-99e016c7",
24
+ "@abtnode/constant": "1.16.0-beta-99e016c7",
25
+ "@abtnode/cron": "1.16.0-beta-99e016c7",
26
+ "@abtnode/db": "1.16.0-beta-99e016c7",
27
+ "@abtnode/logger": "1.16.0-beta-99e016c7",
28
+ "@abtnode/queue": "1.16.0-beta-99e016c7",
29
+ "@abtnode/rbac": "1.16.0-beta-99e016c7",
30
+ "@abtnode/router-provider": "1.16.0-beta-99e016c7",
31
+ "@abtnode/static-server": "1.16.0-beta-99e016c7",
32
+ "@abtnode/timemachine": "1.16.0-beta-99e016c7",
33
+ "@abtnode/util": "1.16.0-beta-99e016c7",
34
+ "@arcblock/did": "1.18.63",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
- "@arcblock/did-util": "1.18.62",
37
- "@arcblock/event-hub": "1.18.62",
38
- "@arcblock/jwt": "^1.18.62",
36
+ "@arcblock/did-util": "1.18.63",
37
+ "@arcblock/event-hub": "1.18.63",
38
+ "@arcblock/jwt": "^1.18.63",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
- "@arcblock/vc": "1.18.62",
41
- "@blocklet/constant": "1.16.0-beta-1d6c582e",
42
- "@blocklet/meta": "1.16.0-beta-1d6c582e",
43
- "@blocklet/sdk": "1.16.0-beta-1d6c582e",
40
+ "@arcblock/vc": "1.18.63",
41
+ "@blocklet/constant": "1.16.0-beta-99e016c7",
42
+ "@blocklet/meta": "1.16.0-beta-99e016c7",
43
+ "@blocklet/sdk": "1.16.0-beta-99e016c7",
44
44
  "@did-space/client": "^0.2.40",
45
45
  "@fidm/x509": "^1.2.1",
46
- "@ocap/client": "1.18.62",
47
- "@ocap/mcrypto": "1.18.62",
48
- "@ocap/util": "1.18.62",
49
- "@ocap/wallet": "1.18.62",
46
+ "@ocap/client": "1.18.63",
47
+ "@ocap/mcrypto": "1.18.63",
48
+ "@ocap/util": "1.18.63",
49
+ "@ocap/wallet": "1.18.63",
50
50
  "@slack/webhook": "^5.0.4",
51
51
  "archiver": "^5.3.1",
52
52
  "axios": "^0.27.2",
@@ -91,5 +91,5 @@
91
91
  "express": "^4.18.2",
92
92
  "jest": "^27.5.1"
93
93
  },
94
- "gitHead": "209fa1413ae05d8961942b2c21f2d83df66f4b68"
94
+ "gitHead": "6dcb70e4613c92752d7b5f2662ac4b0e3bc9050b"
95
95
  }