@blocklet/sdk 1.16.34-beta-20241216-230644-e9ec07d8 → 1.16.34-beta-20241218-045149-150af879
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 +10 -2
- package/lib/component/index.js +20 -6
- package/package.json +15 -14
package/lib/component/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { AxiosResponse, Method } from 'axios';
|
|
2
2
|
import { IncomingMessage } from 'http';
|
|
3
3
|
import type { Resource } from './util';
|
|
4
|
+
type RetryOptions = {
|
|
5
|
+
retries?: number;
|
|
6
|
+
factor?: number;
|
|
7
|
+
randomize?: boolean;
|
|
8
|
+
minTimeout?: number;
|
|
9
|
+
maxTimeout?: number;
|
|
10
|
+
onFailedAttempt?: (error: any) => void | Promise<void>;
|
|
11
|
+
};
|
|
4
12
|
declare const getComponentWebEndpoint: (keyword: string) => string;
|
|
5
13
|
type CallComponentOptions<D = any, P = any> = {
|
|
6
14
|
name?: string;
|
|
@@ -15,8 +23,8 @@ type CallComponentOptions<D = any, P = any> = {
|
|
|
15
23
|
type CallComponent = {
|
|
16
24
|
(options: CallComponentOptions & {
|
|
17
25
|
responseType: 'stream';
|
|
18
|
-
}): Promise<AxiosResponse<IncomingMessage>>;
|
|
19
|
-
<T = any, D = any, P = any>(options: CallComponentOptions<D, P
|
|
26
|
+
}, retryOptions?: RetryOptions): Promise<AxiosResponse<IncomingMessage>>;
|
|
27
|
+
<T = any, D = any, P = any>(options: CallComponentOptions<D, P>, retryOptions?: RetryOptions): Promise<AxiosResponse<T, D>>;
|
|
20
28
|
};
|
|
21
29
|
declare const call: CallComponent;
|
|
22
30
|
declare const getComponentMountPoint: (keyword: string) => string;
|
package/lib/component/index.js
CHANGED
|
@@ -39,23 +39,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.getPackResources = exports.getResources = exports.getReleaseExportDir = exports.getResourceExportDir = exports.waitForComponentRunning = exports.getComponentWebEndpoint = exports.getComponentMountPoint = exports.getRelativeUrl = exports.getUrl = exports.call = void 0;
|
|
40
40
|
const path_1 = require("path");
|
|
41
41
|
const get_1 = __importDefault(require("lodash/get"));
|
|
42
|
+
const noop_1 = __importDefault(require("lodash/noop"));
|
|
42
43
|
const ufo_1 = require("ufo");
|
|
44
|
+
const p_retry_1 = __importDefault(require("p-retry"));
|
|
43
45
|
const wait_port_1 = __importDefault(require("wait-port"));
|
|
44
46
|
const constant_1 = require("@blocklet/constant");
|
|
45
47
|
const config_1 = require("../config");
|
|
46
48
|
const Util = __importStar(require("./util"));
|
|
47
49
|
const component_api_1 = __importDefault(require("../util/component-api"));
|
|
48
50
|
const parse_docker_endpoint_1 = require("../util/parse-docker-endpoint");
|
|
49
|
-
|
|
51
|
+
// eslint-disable-next-line require-await
|
|
52
|
+
const doCall = async ({ url, headers = {}, ...options }, retryOptions = {}) => (0, p_retry_1.default)(async () => {
|
|
50
53
|
try {
|
|
51
|
-
const
|
|
54
|
+
const res = await (0, component_api_1.default)({
|
|
52
55
|
url,
|
|
53
56
|
timeout: 60 * 1000,
|
|
54
57
|
...options,
|
|
55
58
|
headers,
|
|
56
59
|
});
|
|
57
60
|
config_1.logger.info(`call ${url} api success`);
|
|
58
|
-
return
|
|
61
|
+
return res;
|
|
59
62
|
}
|
|
60
63
|
catch (error) {
|
|
61
64
|
config_1.logger.error(`call ${url} api failed`, {
|
|
@@ -64,9 +67,20 @@ const doCall = async ({ url, headers = {}, ...options }) => {
|
|
|
64
67
|
responseData: (0, get_1.default)(error, 'response.data'),
|
|
65
68
|
error: (0, get_1.default)(error, 'message'),
|
|
66
69
|
});
|
|
70
|
+
// Do not retry if the response status indicates a client error
|
|
71
|
+
if (error.response && error.response.status < 500 && error.response.status >= 400) {
|
|
72
|
+
throw new p_retry_1.default.AbortError(error);
|
|
73
|
+
}
|
|
67
74
|
throw error;
|
|
68
75
|
}
|
|
69
|
-
}
|
|
76
|
+
}, {
|
|
77
|
+
retries: typeof retryOptions.retries === 'undefined' ? 3 : retryOptions.retries,
|
|
78
|
+
factor: retryOptions.factor || 2,
|
|
79
|
+
randomize: retryOptions.randomize || true,
|
|
80
|
+
minTimeout: retryOptions.minTimeout || 500,
|
|
81
|
+
maxTimeout: retryOptions.maxTimeout || 5000,
|
|
82
|
+
onFailedAttempt: retryOptions.onFailedAttempt || noop_1.default,
|
|
83
|
+
});
|
|
70
84
|
const getComponent = (name) => {
|
|
71
85
|
const item = config_1.components.find((x) => [x.title, x.name, x.did].includes(name));
|
|
72
86
|
return item;
|
|
@@ -77,7 +91,7 @@ const getComponentWebEndpoint = (keyword) => {
|
|
|
77
91
|
return (0, parse_docker_endpoint_1.parseDockerComponentEndpoint)(endpoint, item);
|
|
78
92
|
};
|
|
79
93
|
exports.getComponentWebEndpoint = getComponentWebEndpoint;
|
|
80
|
-
const call = async ({ name, method = 'POST', path: _path, ...options }) => {
|
|
94
|
+
const call = async ({ name, method = 'POST', path: _path, ...options }, retryOptions = {}) => {
|
|
81
95
|
if (!name) {
|
|
82
96
|
throw new Error('component.call: name is required');
|
|
83
97
|
}
|
|
@@ -91,7 +105,7 @@ const call = async ({ name, method = 'POST', path: _path, ...options }) => {
|
|
|
91
105
|
}
|
|
92
106
|
const url = (0, ufo_1.joinURL)(baseURL, _path);
|
|
93
107
|
try {
|
|
94
|
-
const resp = await doCall({ url, method, ...options });
|
|
108
|
+
const resp = await doCall({ url, method, ...options }, retryOptions);
|
|
95
109
|
return resp;
|
|
96
110
|
}
|
|
97
111
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.34-beta-
|
|
6
|
+
"version": "1.16.34-beta-20241218-045149-150af879",
|
|
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",
|
|
@@ -27,21 +27,21 @@
|
|
|
27
27
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@abtnode/client": "1.16.34-beta-
|
|
31
|
-
"@abtnode/constant": "1.16.34-beta-
|
|
32
|
-
"@abtnode/util": "1.16.34-beta-
|
|
33
|
-
"@arcblock/did": "1.18.
|
|
34
|
-
"@arcblock/did-auth": "1.18.
|
|
35
|
-
"@arcblock/jwt": "1.18.
|
|
36
|
-
"@arcblock/ws": "1.18.
|
|
37
|
-
"@blocklet/constant": "1.16.34-beta-
|
|
38
|
-
"@blocklet/env": "1.16.34-beta-
|
|
39
|
-
"@blocklet/meta": "1.16.34-beta-
|
|
30
|
+
"@abtnode/client": "1.16.34-beta-20241218-045149-150af879",
|
|
31
|
+
"@abtnode/constant": "1.16.34-beta-20241218-045149-150af879",
|
|
32
|
+
"@abtnode/util": "1.16.34-beta-20241218-045149-150af879",
|
|
33
|
+
"@arcblock/did": "1.18.162",
|
|
34
|
+
"@arcblock/did-auth": "1.18.162",
|
|
35
|
+
"@arcblock/jwt": "1.18.162",
|
|
36
|
+
"@arcblock/ws": "1.18.162",
|
|
37
|
+
"@blocklet/constant": "1.16.34-beta-20241218-045149-150af879",
|
|
38
|
+
"@blocklet/env": "1.16.34-beta-20241218-045149-150af879",
|
|
39
|
+
"@blocklet/meta": "1.16.34-beta-20241218-045149-150af879",
|
|
40
40
|
"@did-connect/authenticator": "^2.2.4",
|
|
41
41
|
"@did-connect/handler": "^2.2.4",
|
|
42
42
|
"@nedb/core": "^2.1.5",
|
|
43
|
-
"@ocap/mcrypto": "1.18.
|
|
44
|
-
"@ocap/wallet": "1.18.
|
|
43
|
+
"@ocap/mcrypto": "1.18.162",
|
|
44
|
+
"@ocap/wallet": "1.18.162",
|
|
45
45
|
"axios": "^1.7.5",
|
|
46
46
|
"cheerio": "1.0.0-rc.12",
|
|
47
47
|
"debug": "^4.3.7",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"jsonwebtoken": "^9.0.0",
|
|
52
52
|
"lodash": "^4.17.21",
|
|
53
53
|
"lru-cache": "^11.0.2",
|
|
54
|
+
"p-retry": "^4.6.2",
|
|
54
55
|
"qs": "^6.13.0",
|
|
55
56
|
"semver": "^7.6.3",
|
|
56
57
|
"sitemap": "^8.0.0",
|
|
@@ -80,5 +81,5 @@
|
|
|
80
81
|
"ts-node": "^10.9.1",
|
|
81
82
|
"typescript": "^5.6.3"
|
|
82
83
|
},
|
|
83
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "91907df23611fc7d41194669bc0831af1909114c"
|
|
84
85
|
}
|