@blocklet/sdk 1.8.65 → 1.8.66-beta-7f4224af
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/service/notification.d.ts +3 -0
- package/lib/service/notification.js +7 -1
- package/lib/util/send-notification.d.ts +3 -2
- package/lib/util/send-notification.js +34 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/wallet-handler.d.ts +7 -5
- package/lib/wallet-handler.js +11 -10
- package/package.json +14 -13
|
@@ -11,6 +11,7 @@ type $TSFixMe = any;
|
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
declare const doSendToUser: (receiver: string | string[], notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
|
|
14
|
+
declare const doSendToRelay: (topic: string, event: string, data: any) => Promise<any>;
|
|
14
15
|
/**
|
|
15
16
|
*
|
|
16
17
|
* @param {Notification} notification
|
|
@@ -30,9 +31,11 @@ export declare const _message: {
|
|
|
30
31
|
off: any;
|
|
31
32
|
};
|
|
32
33
|
export { doSendToUser as sendToUser };
|
|
34
|
+
export { doSendToRelay as sendToRelay };
|
|
33
35
|
export { broadcast };
|
|
34
36
|
declare const _default: {
|
|
35
37
|
sendToUser: (receiver: string | string[], notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
|
|
38
|
+
sendToRelay: (topic: string, event: string, data: any) => Promise<any>;
|
|
36
39
|
broadcast: (notification: TNotificationInput, options?: TSendOptions) => Promise<any>;
|
|
37
40
|
on: (event: string, cb?: any) => EventEmitter;
|
|
38
41
|
off: any;
|
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.broadcast = exports.sendToUser = exports._message = exports.off = exports.on = void 0;
|
|
38
|
+
exports.broadcast = exports.sendToRelay = exports.sendToUser = exports._message = exports.off = exports.on = void 0;
|
|
39
39
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
40
40
|
const Jwt = __importStar(require("@arcblock/jwt"));
|
|
41
41
|
const events_1 = __importDefault(require("events"));
|
|
@@ -63,6 +63,11 @@ const doSendToUser = (receiver, notification, options) => __awaiter(void 0, void
|
|
|
63
63
|
return (0, send_notification_1.sendToUser)(receiver, notification, getSender(), process.env.ABT_NODE_SERVICE_PORT, options);
|
|
64
64
|
});
|
|
65
65
|
exports.sendToUser = doSendToUser;
|
|
66
|
+
const doSendToRelay = (topic, event, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
(0, check_blocklet_env_1.default)();
|
|
68
|
+
return (0, send_notification_1.sendToRelay)(topic, event, data, getSender(), process.env.ABT_NODE_SERVICE_PORT);
|
|
69
|
+
});
|
|
70
|
+
exports.sendToRelay = doSendToRelay;
|
|
66
71
|
/**
|
|
67
72
|
*
|
|
68
73
|
* @param {Notification} notification
|
|
@@ -178,6 +183,7 @@ exports._message = {
|
|
|
178
183
|
};
|
|
179
184
|
exports.default = {
|
|
180
185
|
sendToUser: doSendToUser,
|
|
186
|
+
sendToRelay: doSendToRelay,
|
|
181
187
|
broadcast,
|
|
182
188
|
on: exports.on,
|
|
183
189
|
off: exports.off,
|
|
@@ -16,10 +16,11 @@ export type TNotificationSender = {
|
|
|
16
16
|
*/
|
|
17
17
|
declare const sendToUser: (receiver: string | string[], notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}) => Promise<any>;
|
|
18
18
|
declare const sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: TSendOptions) => Promise<any>;
|
|
19
|
-
|
|
20
|
-
export { sendToAppChannel };
|
|
19
|
+
declare const sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
20
|
+
export { sendToUser, sendToAppChannel, sendToRelay };
|
|
21
21
|
declare const _default: {
|
|
22
22
|
sendToUser: (receiver: string | string[], notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: {}) => Promise<any>;
|
|
23
23
|
sendToAppChannel: (channel: string, event: string, notification: TNotificationInput, { appDid, appSk }: TNotificationSender, port?: string, options?: TSendOptions) => Promise<any>;
|
|
24
|
+
sendToRelay: (topic: string, event: string, data: any, { appDid, appSk }: TNotificationSender, port?: string) => Promise<any>;
|
|
24
25
|
};
|
|
25
26
|
export default _default;
|
|
@@ -35,11 +35,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.sendToAppChannel = exports.sendToUser = void 0;
|
|
38
|
+
exports.sendToRelay = exports.sendToAppChannel = exports.sendToUser = void 0;
|
|
39
39
|
const axios_1 = __importDefault(require("axios"));
|
|
40
40
|
const pick_1 = __importDefault(require("lodash/pick"));
|
|
41
41
|
const JWT = __importStar(require("@arcblock/jwt"));
|
|
42
42
|
const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
43
|
+
const channel_1 = require("@blocklet/meta/lib/channel");
|
|
43
44
|
const index_1 = require("../validators/index");
|
|
44
45
|
const constants_1 = require("./constants");
|
|
45
46
|
const version_1 = require("../version");
|
|
@@ -126,7 +127,39 @@ const sendToAppChannel = (channel, event, notification, { appDid, appSk }, port
|
|
|
126
127
|
}
|
|
127
128
|
});
|
|
128
129
|
exports.sendToAppChannel = sendToAppChannel;
|
|
130
|
+
const sendToRelay = (topic, event, data, { appDid, appSk }, port = process.env.ABT_NODE_SERVICE_PORT) => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
if (!topic) {
|
|
132
|
+
throw new Error('topic is required');
|
|
133
|
+
}
|
|
134
|
+
if (!event) {
|
|
135
|
+
throw new Error('event is required');
|
|
136
|
+
}
|
|
137
|
+
if (!data) {
|
|
138
|
+
throw new Error('data is required');
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const { data: res } = yield axios.post(`http://127.0.0.1:${port}${constants_1.SERVICE_PREFIX}/relay/api/send-to-relay-channel`, {
|
|
142
|
+
apiVersion: VERSION,
|
|
143
|
+
data: {
|
|
144
|
+
sender: { appDid, token: JWT.sign(appDid, appSk) },
|
|
145
|
+
channel: (0, channel_1.getRelayChannel)(appDid, topic),
|
|
146
|
+
event,
|
|
147
|
+
data,
|
|
148
|
+
},
|
|
149
|
+
}, {
|
|
150
|
+
timeout: 60 * 1000,
|
|
151
|
+
headers: getRequestHeaders(),
|
|
152
|
+
});
|
|
153
|
+
return res;
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
console.error(err.response ? err.response.data : err);
|
|
157
|
+
throw new Error(err.response ? err.response.data : err.message);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
exports.sendToRelay = sendToRelay;
|
|
129
161
|
exports.default = {
|
|
130
162
|
sendToUser,
|
|
131
163
|
sendToAppChannel,
|
|
164
|
+
sendToRelay,
|
|
132
165
|
};
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
package/lib/wallet-handler.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { WalletHandlers as Handler } from '@arcblock/did-auth';
|
|
2
2
|
declare class WalletHandlers extends Handler {
|
|
3
3
|
enableConnect: boolean;
|
|
4
|
-
sendNotificationFn:
|
|
4
|
+
sendNotificationFn: Function;
|
|
5
|
+
sendToRelayFn: Function;
|
|
5
6
|
/**
|
|
6
|
-
* @param {boolean} autoConnect enable auto connect to wallet (wallet does not need to scan qr code)
|
|
7
|
-
* @param {boolean} connectedDidOnly only current login did or connected did can connect
|
|
8
|
-
* @param {function} sendNotificationFn use in a non-blocklet environment
|
|
7
|
+
* @param {boolean} params.autoConnect enable auto connect to wallet (wallet does not need to scan qr code)
|
|
8
|
+
* @param {boolean} params.connectedDidOnly only current login did or connected did can connect
|
|
9
|
+
* @param {function} [params.sendNotificationFn] use in a non-blocklet environment
|
|
10
|
+
* @param {function} [params.sendToRelayFn]
|
|
9
11
|
*/
|
|
10
|
-
constructor({ autoConnect, connectedDidOnly, sendNotificationFn, options, ...opts }:
|
|
12
|
+
constructor({ autoConnect, connectedDidOnly, sendNotificationFn, sendToRelayFn, options, ...opts }: any);
|
|
11
13
|
getConnectedDid: ({ req, didwallet, extraParams }: $TSFixMe) => any;
|
|
12
14
|
attach({ onStart, ...opts }: {
|
|
13
15
|
[x: string]: any;
|
package/lib/wallet-handler.js
CHANGED
|
@@ -56,16 +56,13 @@ const inMobileWallet = (didwallet) => {
|
|
|
56
56
|
};
|
|
57
57
|
class WalletHandlers extends did_auth_1.WalletHandlers {
|
|
58
58
|
/**
|
|
59
|
-
* @param {boolean} autoConnect enable auto connect to wallet (wallet does not need to scan qr code)
|
|
60
|
-
* @param {boolean} connectedDidOnly only current login did or connected did can connect
|
|
61
|
-
* @param {function} sendNotificationFn use in a non-blocklet environment
|
|
59
|
+
* @param {boolean} params.autoConnect enable auto connect to wallet (wallet does not need to scan qr code)
|
|
60
|
+
* @param {boolean} params.connectedDidOnly only current login did or connected did can connect
|
|
61
|
+
* @param {function} [params.sendNotificationFn] use in a non-blocklet environment
|
|
62
|
+
* @param {function} [params.sendToRelayFn]
|
|
62
63
|
*/
|
|
63
64
|
constructor(_a) {
|
|
64
|
-
var { autoConnect = true, connectedDidOnly = false, sendNotificationFn, options = {} } = _a, opts = __rest(_a, ["autoConnect", "connectedDidOnly", "sendNotificationFn", "options"]);
|
|
65
|
-
// FIXME: wait check
|
|
66
|
-
// if (autoConnect && connectedDidOnly) {
|
|
67
|
-
// options.sessionDidKey = CONNECTED_DID_KEY;
|
|
68
|
-
// }
|
|
65
|
+
var { autoConnect = true, connectedDidOnly = false, sendNotificationFn = null, sendToRelayFn = null, options = {} } = _a, opts = __rest(_a, ["autoConnect", "connectedDidOnly", "sendNotificationFn", "sendToRelayFn", "options"]);
|
|
69
66
|
super(Object.assign({ options: Object.assign(Object.assign({}, options), {
|
|
70
67
|
sessionDidKey: autoConnect && connectedDidOnly ? CONNECTED_DID_KEY : options === null || options === void 0 ? void 0 : options.sessionDidKey,
|
|
71
68
|
}) }, opts));
|
|
@@ -83,6 +80,11 @@ class WalletHandlers extends did_auth_1.WalletHandlers {
|
|
|
83
80
|
};
|
|
84
81
|
this.enableConnect = !!autoConnect;
|
|
85
82
|
this.sendNotificationFn = sendNotificationFn || notification_1.sendToUser.bind(notification_1.default);
|
|
83
|
+
this.sendToRelayFn = sendToRelayFn || notification_1.sendToRelay.bind(notification_1.default);
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
this.on('updated', (session) => {
|
|
86
|
+
this.sendToRelayFn({ topic: session.token, event: 'updated', data: session }).catch(console.error);
|
|
87
|
+
});
|
|
86
88
|
}
|
|
87
89
|
attach(_a) {
|
|
88
90
|
var { onStart = noop } = _a, opts = __rest(_a, ["onStart"]);
|
|
@@ -96,9 +98,8 @@ class WalletHandlers extends did_auth_1.WalletHandlers {
|
|
|
96
98
|
// send notification to wallet to trigger wallet to auto connect
|
|
97
99
|
if (connectedDid) {
|
|
98
100
|
// wallet use check url to check status of the session
|
|
99
|
-
let checkUrl
|
|
101
|
+
let checkUrl;
|
|
100
102
|
try {
|
|
101
|
-
// @ts-expect-error TS(2322) FIXME: Type 'URL' is not assignable to type 'string'.
|
|
102
103
|
checkUrl = new URL(decodeURIComponent(new URL(params.deepLink).searchParams.get('url')));
|
|
103
104
|
checkUrl.pathname = checkUrl.pathname.replace(/auth$/, 'status');
|
|
104
105
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.66-beta-7f4224af",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -26,18 +26,19 @@
|
|
|
26
26
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@abtnode/client": "1.8.
|
|
30
|
-
"@abtnode/constant": "1.8.
|
|
31
|
-
"@
|
|
32
|
-
"@arcblock/
|
|
33
|
-
"@arcblock/
|
|
34
|
-
"@
|
|
35
|
-
"@blocklet/
|
|
36
|
-
"@
|
|
37
|
-
"@did-connect/
|
|
29
|
+
"@abtnode/client": "1.8.66-beta-7f4224af",
|
|
30
|
+
"@abtnode/constant": "1.8.66-beta-7f4224af",
|
|
31
|
+
"@abtnode/util": "1.8.66-beta-7f4224af",
|
|
32
|
+
"@arcblock/did-auth": "1.18.47",
|
|
33
|
+
"@arcblock/jwt": "1.18.47",
|
|
34
|
+
"@arcblock/ws": "1.18.47",
|
|
35
|
+
"@blocklet/constant": "1.8.66-beta-7f4224af",
|
|
36
|
+
"@blocklet/meta": "1.8.66-beta-7f4224af",
|
|
37
|
+
"@did-connect/authenticator": "^2.1.35",
|
|
38
|
+
"@did-connect/handler": "^2.1.35",
|
|
38
39
|
"@nedb/core": "^2.1.5",
|
|
39
|
-
"@ocap/mcrypto": "1.18.
|
|
40
|
-
"@ocap/wallet": "1.18.
|
|
40
|
+
"@ocap/mcrypto": "1.18.47",
|
|
41
|
+
"@ocap/wallet": "1.18.47",
|
|
41
42
|
"axios": "^0.27.2",
|
|
42
43
|
"fs-extra": "^10.1.0",
|
|
43
44
|
"joi": "17.7.0",
|
|
@@ -68,5 +69,5 @@
|
|
|
68
69
|
"ts-node": "^10.9.1",
|
|
69
70
|
"typescript": "^4.8.4"
|
|
70
71
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "72d418f63ecb76b1d5d62edbcc5f336cb62bf308"
|
|
72
73
|
}
|