@blocklet/sdk 1.16.0-beta-8ee536d7 → 1.16.0-beta-62b42401
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/component/index.d.ts +16 -9
- package/lib/component/index.js +12 -7
- package/lib/env.d.ts +1 -0
- package/lib/util/env.d.ts +1 -0
- package/lib/util/env.js +1 -0
- package/lib/wallet.d.ts +5 -1
- package/lib/wallet.js +4 -0
- package/package.json +12 -12
package/lib/component/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AxiosResponse, Method } from 'axios';
|
|
3
|
+
import { IncomingMessage } from 'http';
|
|
2
4
|
export type MountPoint = {
|
|
3
5
|
did: string;
|
|
4
6
|
name: string;
|
|
@@ -10,11 +12,20 @@ export type MountPoint = {
|
|
|
10
12
|
declare const getChildWebEndpoint: (name: string) => string;
|
|
11
13
|
declare const getParentWebEndpoint: () => string;
|
|
12
14
|
declare const getComponentWebEndpoint: (keyword: string) => string;
|
|
13
|
-
|
|
15
|
+
type CallComponentOptions<D = any, P = any> = {
|
|
14
16
|
name?: string;
|
|
17
|
+
method?: Method;
|
|
15
18
|
path: string;
|
|
16
|
-
data
|
|
17
|
-
|
|
19
|
+
data?: D;
|
|
20
|
+
params?: P;
|
|
21
|
+
};
|
|
22
|
+
type CallComponent = {
|
|
23
|
+
(options: CallComponentOptions & {
|
|
24
|
+
responseType: 'stream';
|
|
25
|
+
}): Promise<AxiosResponse<IncomingMessage>>;
|
|
26
|
+
<T = any, D = any, P = any>(options: CallComponentOptions<D, P>): Promise<AxiosResponse<T, D>>;
|
|
27
|
+
};
|
|
28
|
+
declare const call: CallComponent;
|
|
18
29
|
declare const getComponentMountPoint: (keyword: string) => string;
|
|
19
30
|
export { call };
|
|
20
31
|
export { getComponentMountPoint };
|
|
@@ -22,11 +33,7 @@ export { getComponentWebEndpoint };
|
|
|
22
33
|
export { getChildWebEndpoint };
|
|
23
34
|
export { getParentWebEndpoint };
|
|
24
35
|
declare const _default: {
|
|
25
|
-
call:
|
|
26
|
-
name?: string;
|
|
27
|
-
path: string;
|
|
28
|
-
data: any;
|
|
29
|
-
}) => Promise<AxiosResponse<any, any>>;
|
|
36
|
+
call: CallComponent;
|
|
30
37
|
getComponentMountPoint: (keyword: string) => string;
|
|
31
38
|
getComponentWebEndpoint: (keyword: string) => string;
|
|
32
39
|
getChildWebEndpoint: (name: string) => string;
|
package/lib/component/index.js
CHANGED
|
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getParentWebEndpoint = exports.getChildWebEndpoint = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.call = void 0;
|
|
7
|
+
const util_1 = require("@blocklet/meta/lib/util");
|
|
7
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
8
10
|
const get_1 = __importDefault(require("lodash/get"));
|
|
9
11
|
const url_join_1 = __importDefault(require("url-join"));
|
|
10
|
-
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
11
|
-
const util_1 = require("@blocklet/meta/lib/util");
|
|
12
|
-
const wallet_1 = __importDefault(require("../wallet"));
|
|
13
12
|
const config_1 = require("../config");
|
|
13
|
+
const wallet_1 = __importDefault(require("../wallet"));
|
|
14
14
|
const parseMountPoints = () => {
|
|
15
15
|
const mountPoints = JSON.parse(process.env.BLOCKLET_MOUNT_POINTS) || [];
|
|
16
16
|
mountPoints.forEach((x) => {
|
|
@@ -25,9 +25,14 @@ const sign = (data) => {
|
|
|
25
25
|
const signData = typeof data === 'undefined' ? {} : data;
|
|
26
26
|
return { 'x-component-sig': wallet.sign((0, json_stable_stringify_1.default)(signData)) };
|
|
27
27
|
};
|
|
28
|
-
const doCall = async ({ url,
|
|
28
|
+
const doCall = async ({ url, ...options }) => {
|
|
29
29
|
try {
|
|
30
|
-
const resp = await axios_1.default
|
|
30
|
+
const resp = await (0, axios_1.default)({
|
|
31
|
+
url,
|
|
32
|
+
...options,
|
|
33
|
+
headers: { ...sign(options.data ?? {}) },
|
|
34
|
+
timeout: 60000,
|
|
35
|
+
});
|
|
31
36
|
config_1.logger.info(`call ${url} api success`);
|
|
32
37
|
return resp;
|
|
33
38
|
}
|
|
@@ -65,7 +70,7 @@ const getComponentWebEndpoint = (keyword) => {
|
|
|
65
70
|
return item ? item.webEndpoint : '';
|
|
66
71
|
};
|
|
67
72
|
exports.getComponentWebEndpoint = getComponentWebEndpoint;
|
|
68
|
-
const call = async ({ name, path: _path,
|
|
73
|
+
const call = async ({ name, method = 'POST', path: _path, ...options }) => {
|
|
69
74
|
let baseURL;
|
|
70
75
|
if (name) {
|
|
71
76
|
baseURL = getComponentWebEndpoint(name) || getChildWebEndpoint(name);
|
|
@@ -77,7 +82,7 @@ const call = async ({ name, path: _path, data }) => {
|
|
|
77
82
|
throw new Error(`can not find web endpoint for ${name}`);
|
|
78
83
|
}
|
|
79
84
|
const url = (0, url_join_1.default)(baseURL, _path);
|
|
80
|
-
return doCall({ url,
|
|
85
|
+
return doCall({ url, method, ...options });
|
|
81
86
|
};
|
|
82
87
|
exports.call = call;
|
|
83
88
|
const getComponentMountPoint = (keyword) => {
|
package/lib/env.d.ts
CHANGED
package/lib/util/env.d.ts
CHANGED
package/lib/util/env.js
CHANGED
|
@@ -18,6 +18,7 @@ function parseEnv(env = process.env) {
|
|
|
18
18
|
return Object.freeze({
|
|
19
19
|
appId: env.BLOCKLET_APP_ID,
|
|
20
20
|
appPid: env.BLOCKLET_APP_PID,
|
|
21
|
+
appIds: (env.BLOCKLET_APP_IDS || '').split(','),
|
|
21
22
|
appName: env.BLOCKLET_APP_NAME,
|
|
22
23
|
appDescription: env.BLOCKLET_APP_DESCRIPTION,
|
|
23
24
|
appUrl: env.BLOCKLET_APP_URL,
|
package/lib/wallet.d.ts
CHANGED
|
@@ -5,5 +5,9 @@ import { DIDTypeShortcut } from '@arcblock/did';
|
|
|
5
5
|
* @param {string} [appSk=process.env.BLOCKLET_APP_SK] must be hex
|
|
6
6
|
* @return {WalletObject} {WalletObject}
|
|
7
7
|
*/
|
|
8
|
-
declare const getWallet:
|
|
8
|
+
declare const getWallet: {
|
|
9
|
+
(type?: DIDTypeShortcut, appSk?: string): WalletObject;
|
|
10
|
+
getPermanentWallet: () => WalletObject<string>;
|
|
11
|
+
getEthereumWallet: (permanent?: boolean) => WalletObject<string>;
|
|
12
|
+
};
|
|
9
13
|
export = getWallet;
|
package/lib/wallet.js
CHANGED
|
@@ -20,4 +20,8 @@ const getWallet = (type = process.env.BLOCKLET_WALLET_TYPE, appSk = process.env.
|
|
|
20
20
|
}
|
|
21
21
|
return (0, wallet_1.fromSecretKey)(sk, t);
|
|
22
22
|
};
|
|
23
|
+
const getPermanentWallet = () => getWallet(process.env.BLOCKLET_WALLET_TYPE, process.env.BLOCKLET_APP_PSK);
|
|
24
|
+
const getEthereumWallet = (permanent = false) => getWallet('ethereum', permanent ? process.env.BLOCKLET_APP_PSK : process.env.BLOCKLET_APP_SK);
|
|
25
|
+
getWallet.getPermanentWallet = getPermanentWallet;
|
|
26
|
+
getWallet.getEthereumWallet = getEthereumWallet;
|
|
23
27
|
module.exports = getWallet;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.0-beta-
|
|
6
|
+
"version": "1.16.0-beta-62b42401",
|
|
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,19 +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.16.0-beta-
|
|
30
|
-
"@abtnode/constant": "1.16.0-beta-
|
|
31
|
-
"@arcblock/did": "1.18.
|
|
32
|
-
"@arcblock/did-auth": "1.18.
|
|
33
|
-
"@arcblock/jwt": "1.18.
|
|
34
|
-
"@arcblock/ws": "1.18.
|
|
35
|
-
"@blocklet/constant": "1.16.0-beta-
|
|
36
|
-
"@blocklet/meta": "1.16.0-beta-
|
|
29
|
+
"@abtnode/client": "1.16.0-beta-62b42401",
|
|
30
|
+
"@abtnode/constant": "1.16.0-beta-62b42401",
|
|
31
|
+
"@arcblock/did": "1.18.63",
|
|
32
|
+
"@arcblock/did-auth": "1.18.63",
|
|
33
|
+
"@arcblock/jwt": "1.18.63",
|
|
34
|
+
"@arcblock/ws": "1.18.63",
|
|
35
|
+
"@blocklet/constant": "1.16.0-beta-62b42401",
|
|
36
|
+
"@blocklet/meta": "1.16.0-beta-62b42401",
|
|
37
37
|
"@did-connect/authenticator": "^2.1.44",
|
|
38
38
|
"@did-connect/handler": "^2.1.44",
|
|
39
39
|
"@nedb/core": "^2.1.5",
|
|
40
|
-
"@ocap/mcrypto": "1.18.
|
|
41
|
-
"@ocap/wallet": "1.18.
|
|
40
|
+
"@ocap/mcrypto": "1.18.63",
|
|
41
|
+
"@ocap/wallet": "1.18.63",
|
|
42
42
|
"axios": "^0.27.2",
|
|
43
43
|
"cheerio": "^1.0.0-rc.12",
|
|
44
44
|
"fs-extra": "^10.1.0",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"ts-node": "^10.9.1",
|
|
72
72
|
"typescript": "^4.8.4"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "6ef1c3601d0cfdcf5da0b55b4c54ef1fa9fce7d2"
|
|
75
75
|
}
|