@blocklet/sdk 1.6.30 → 1.7.1
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.
|
@@ -8,7 +8,7 @@ const sendNotification = require('../util/send-notification');
|
|
|
8
8
|
const { SERVICE_PREFIX } = require('../util/constants');
|
|
9
9
|
const getWallet = require('../wallet');
|
|
10
10
|
|
|
11
|
-
const sendToUser = async (receiver, notification) => {
|
|
11
|
+
const sendToUser = async (receiver, notification, options) => {
|
|
12
12
|
checkBlockletEnv();
|
|
13
13
|
|
|
14
14
|
const sender = {
|
|
@@ -17,7 +17,7 @@ const sendToUser = async (receiver, notification) => {
|
|
|
17
17
|
did: process.env.BLOCKLET_DID,
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
return sendNotification(receiver, notification, sender, process.env.ABT_NODE_SERVICE_PORT);
|
|
20
|
+
return sendNotification(receiver, notification, sender, process.env.ABT_NODE_SERVICE_PORT, options);
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const emitter = new EventEmitter();
|
|
@@ -29,19 +29,19 @@ const initClient = () => {
|
|
|
29
29
|
const wallet = getWallet();
|
|
30
30
|
const { address: did, publicKey: pk, secretKey: sk } = wallet;
|
|
31
31
|
const url = `ws://127.0.0.1:${process.env.ABT_NODE_SERVICE_PORT}${SERVICE_PREFIX}`;
|
|
32
|
-
const token = Jwt.sign(did, sk, {});
|
|
32
|
+
const token = () => Jwt.sign(did, sk, {});
|
|
33
33
|
|
|
34
34
|
client = new WsClient(url, {
|
|
35
35
|
heartbeatIntervalMs: 10 * 1000,
|
|
36
36
|
params: () => ({
|
|
37
|
-
token,
|
|
37
|
+
token: token(),
|
|
38
38
|
pk,
|
|
39
39
|
}),
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
client.connect();
|
|
43
43
|
|
|
44
|
-
const channel = client.channel(wallet.address, { token, pk });
|
|
44
|
+
const channel = client.channel(wallet.address, () => ({ token: token(), pk }));
|
|
45
45
|
|
|
46
46
|
channel
|
|
47
47
|
.join()
|
|
@@ -9,7 +9,7 @@ const { SERVICE_PREFIX } = require('./constants');
|
|
|
9
9
|
|
|
10
10
|
const VERSION = require('../../package.json').version; // version of notification sdk
|
|
11
11
|
|
|
12
|
-
const { validateNotification, validateReceiver } = validators;
|
|
12
|
+
const { validateNotification, validateReceiver, validateOption } = validators;
|
|
13
13
|
|
|
14
14
|
const SERVER_MODE = process.env.ABT_NODE_MODE;
|
|
15
15
|
|
|
@@ -18,15 +18,18 @@ const SERVER_MODE = process.env.ABT_NODE_MODE;
|
|
|
18
18
|
* @param {Object} notification
|
|
19
19
|
* @param {Object} sender
|
|
20
20
|
* @param {String|Number} port port of abtnode service endpoint
|
|
21
|
+
* @param {Object} options
|
|
21
22
|
* @returns
|
|
22
23
|
*/
|
|
23
24
|
module.exports = async (
|
|
24
25
|
receiver,
|
|
25
26
|
notification,
|
|
26
27
|
{ appId, appSk, did } = {},
|
|
27
|
-
port = process.env.ABT_NODE_SERVICE_PORT
|
|
28
|
+
port = process.env.ABT_NODE_SERVICE_PORT,
|
|
29
|
+
options = {}
|
|
28
30
|
) => {
|
|
29
31
|
await validateReceiver(receiver);
|
|
32
|
+
await validateOption(options);
|
|
30
33
|
|
|
31
34
|
if (SERVER_MODE !== NODE_MODES.DEBUG) {
|
|
32
35
|
await validateNotification(notification);
|
|
@@ -41,6 +44,7 @@ module.exports = async (
|
|
|
41
44
|
sender: { did, token, appDid: appId },
|
|
42
45
|
receiver,
|
|
43
46
|
notification,
|
|
47
|
+
options,
|
|
44
48
|
},
|
|
45
49
|
});
|
|
46
50
|
|
package/lib/validators/index.js
CHANGED
|
@@ -87,10 +87,15 @@ const inputNotificationSchema = Joi.alternatives()
|
|
|
87
87
|
|
|
88
88
|
const inputReceiverSchema = Joi.alternatives().try(Joi.array().items(receiverSchema), receiverSchema).required();
|
|
89
89
|
|
|
90
|
+
const optionSchema = Joi.object({
|
|
91
|
+
keepForOfflineUser: Joi.boolean(),
|
|
92
|
+
});
|
|
93
|
+
|
|
90
94
|
module.exports = {
|
|
91
95
|
validateReceiver: inputReceiverSchema.validateAsync.bind(inputReceiverSchema),
|
|
92
96
|
validateNotification: inputNotificationSchema.validateAsync.bind(inputNotificationSchema),
|
|
93
97
|
validateMessage: messageSchema.validateAsync.bind(messageSchema),
|
|
98
|
+
validateOption: optionSchema.validateAsync.bind(optionSchema),
|
|
94
99
|
tokenSchema,
|
|
95
100
|
actionSchema,
|
|
96
101
|
assetSchema,
|
|
@@ -98,4 +103,5 @@ module.exports = {
|
|
|
98
103
|
attachmentSchema,
|
|
99
104
|
notificationSchema,
|
|
100
105
|
messageSchema,
|
|
106
|
+
optionSchema,
|
|
101
107
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.7.1",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/client": "1.
|
|
23
|
-
"@abtnode/constant": "1.
|
|
24
|
-
"@arcblock/did-auth": "^1.
|
|
25
|
-
"@arcblock/jwt": "^1.
|
|
26
|
-
"@arcblock/ws": "^1.
|
|
27
|
-
"@blocklet/meta": "1.
|
|
22
|
+
"@abtnode/client": "1.7.1",
|
|
23
|
+
"@abtnode/constant": "1.7.1",
|
|
24
|
+
"@arcblock/did-auth": "^1.15.3",
|
|
25
|
+
"@arcblock/jwt": "^1.15.3",
|
|
26
|
+
"@arcblock/ws": "^1.15.3",
|
|
27
|
+
"@blocklet/meta": "1.7.1",
|
|
28
28
|
"@nedb/core": "^1.2.2",
|
|
29
|
-
"@ocap/mcrypto": "^1.
|
|
30
|
-
"@ocap/wallet": "^1.
|
|
29
|
+
"@ocap/mcrypto": "^1.15.3",
|
|
30
|
+
"@ocap/wallet": "^1.15.3",
|
|
31
31
|
"axios": "^0.25.0",
|
|
32
32
|
"fs-extra": "^10.0.0",
|
|
33
33
|
"joi": "^17.6.0",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"detect-port": "^1.3.0",
|
|
40
40
|
"jest": "^27.4.5"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "5d7efb21dd09f90206251fb74601ca37b0ef84bf"
|
|
43
43
|
}
|