@blocklet/sdk 1.7.7 → 1.7.10

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/README.md CHANGED
@@ -28,7 +28,7 @@ const userDid = 'xxxxxxxx';
28
28
  const { user } = await client.getUser(userDid);
29
29
  ```
30
30
 
31
- ### Api
31
+ ### API
32
32
 
33
33
  #### client.getUser(did)
34
34
 
@@ -37,9 +37,16 @@ Get user by user did
37
37
  - _@param_ **did** `string`
38
38
  - _@return_ `{ code, user }`
39
39
 
40
+ #### client.getOwner()
41
+
42
+ Get owner of the app
43
+
44
+ - _@param_ **did** `string`
45
+ - _@return_ `{ code, user }`
46
+
40
47
  #### client.getUsers()
41
48
 
42
- Get all users of the team
49
+ Get all users of the app
43
50
 
44
51
  - _@return_ `{ code, users }`
45
52
 
@@ -52,7 +59,7 @@ Get all permissions of a role
52
59
 
53
60
  #### client.getRoles()
54
61
 
55
- Get all roles of the team
62
+ Get all roles of the app
56
63
 
57
64
  - _@return_ `{ code, roles }`
58
65
 
@@ -104,7 +111,7 @@ Full update permissions of a role
104
111
 
105
112
  #### client.getPermissions()
106
113
 
107
- Get all permissions of the team
114
+ Get all permissions of the app
108
115
 
109
116
  - _@return_ `{ code, permissions }`
110
117
 
@@ -167,7 +174,7 @@ await Notification.sendToUser([userDid, anotherUserDid], notification);
167
174
  await Notification.sendToUser([userDid, anotherUserDid], [notification, anotherNotification]);
168
175
  ```
169
176
 
170
- ### Api
177
+ ### API
171
178
 
172
179
  #### notification.sendToUser(receiver, notification)
173
180
 
@@ -268,6 +275,26 @@ const { Database } = require('@blocklet/sdk');
268
275
  })();
269
276
  ```
270
277
 
278
+ ## Log SDK
279
+
280
+ For Blocklet to write business logs, provides a consistent write format.
281
+
282
+ ### Usage
283
+
284
+ ```javascript
285
+ const { logger } = require('@blocklet/sdk');
286
+
287
+ // log
288
+ log = logger('demo');
289
+ log.info('this is demo', { id: 'test-id' });
290
+ log.warn('this is demo', { id: 'test-id' });
291
+ log.error('this is demo', { id: 'test-id' });
292
+ log.debug('this is demo', { id: 'test-id' });
293
+
294
+ // access log
295
+ app.use(morgan('combined', { stream: logger.getAccessLogStream() }));
296
+ ```
297
+
271
298
  ## getWallet
272
299
 
273
300
  ### Usage
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ const Database = require('./database');
6
6
  const env = require('./env');
7
7
  const middlewares = require('./middlewares');
8
8
  const getWallet = require('./wallet');
9
+ const logger = require('./logger');
9
10
 
10
11
  module.exports = {
11
12
  AuthService,
@@ -16,4 +17,5 @@ module.exports = {
16
17
  getWallet,
17
18
  env,
18
19
  middlewares,
20
+ logger,
19
21
  };
package/lib/logger.js ADDED
@@ -0,0 +1,8 @@
1
+ const logger = require('@abtnode/logger');
2
+
3
+ if (!process.env.BLOCKLET_LOG_DIR) {
4
+ throw new Error('valid BLOCKLET_LOG_DIR env is required by logger');
5
+ }
6
+
7
+ module.exports = (label) => logger(label, { logDir: process.env.BLOCKLET_LOG_DIR, filename: 'info' });
8
+ module.exports.getAccessLogStream = () => logger.getAccessLogStream(process.env.BLOCKLET_LOG_DIR);
@@ -37,6 +37,7 @@ class AuthService extends Client {
37
37
  // user
38
38
  'getUsers',
39
39
  'getUser',
40
+ 'getOwner',
40
41
  // 'removeUser',
41
42
  'updateUserRole', // deprecated
42
43
  // 'updateUserApproval',
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable global-require */
2
2
  const axios = require('axios').create({ proxy: false });
3
+ const pick = require('lodash/pick');
3
4
 
4
5
  const JWT = require('@arcblock/jwt');
5
6
  const { NODE_MODES } = require('@abtnode/constant');
@@ -29,7 +30,8 @@ module.exports = async (
29
30
  options = {}
30
31
  ) => {
31
32
  await validateReceiver(receiver);
32
- await validateOption(options);
33
+ const opt = pick(options, ['keepForOfflineUser']);
34
+ await validateOption(opt);
33
35
 
34
36
  if (SERVER_MODE !== NODE_MODES.DEBUG) {
35
37
  await validateNotification(notification);
@@ -44,7 +46,7 @@ module.exports = async (
44
46
  sender: { did, token, appDid: appId },
45
47
  receiver,
46
48
  notification,
47
- options,
49
+ options: opt,
48
50
  },
49
51
  });
50
52
 
@@ -75,7 +75,8 @@ class WalletHandlers extends Handler {
75
75
  message.checkUrl = checkUrl.href;
76
76
  }
77
77
 
78
- this.sendNotificationFn(connectedDid, message).catch((err) => {
78
+ // sendNotificationFn maybe custom function so we need params
79
+ this.sendNotificationFn(connectedDid, message, params).catch((err) => {
79
80
  console.error(err);
80
81
  if (typeof opts.onError === 'function') {
81
82
  opts.onError(err);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.7.7",
6
+ "version": "1.7.10",
7
7
  "description": "graphql client to read/write data on abt node",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,16 +19,17 @@
19
19
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/client": "1.7.7",
23
- "@abtnode/constant": "1.7.7",
24
- "@arcblock/did-auth": "^1.16.0",
25
- "@arcblock/jwt": "^1.16.0",
26
- "@arcblock/ws": "^1.16.0",
27
- "@blocklet/meta": "1.7.7",
22
+ "@abtnode/client": "1.7.10",
23
+ "@abtnode/constant": "1.7.10",
24
+ "@abtnode/logger": "1.7.10",
25
+ "@arcblock/did-auth": "^1.16.5",
26
+ "@arcblock/jwt": "^1.16.5",
27
+ "@arcblock/ws": "^1.16.5",
28
+ "@blocklet/meta": "1.7.10",
28
29
  "@nedb/core": "^1.2.2",
29
- "@ocap/mcrypto": "^1.16.0",
30
- "@ocap/wallet": "^1.16.0",
31
- "axios": "^0.25.0",
30
+ "@ocap/mcrypto": "^1.16.5",
31
+ "@ocap/wallet": "^1.16.5",
32
+ "axios": "^0.26.1",
32
33
  "fs-extra": "^10.0.1",
33
34
  "joi": "^17.6.0",
34
35
  "lodash": "^4.17.21",
@@ -39,5 +40,5 @@
39
40
  "detect-port": "^1.3.0",
40
41
  "jest": "^27.4.5"
41
42
  },
42
- "gitHead": "619db37ea7a91c64a9bf30836a55c70d55325e73"
43
+ "gitHead": "8eab10fd39b6183a2fa4d2706f52e8b2ecaa059a"
43
44
  }