@blocklet/sdk 1.16.34-beta-20241214-102147-410be539 → 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.
@@ -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>): Promise<AxiosResponse<T, D>>;
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;
@@ -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
- const doCall = async ({ url, headers = {}, ...options }) => {
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 resp = await (0, component_api_1.default)({
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 resp;
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) {
@@ -2,10 +2,10 @@
2
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
- const lru_cache_1 = __importDefault(require("lru-cache"));
5
+ const lru_cache_1 = require("lru-cache");
6
6
  const auth_1 = __importDefault(require("../service/auth"));
7
7
  const login_1 = require("../util/login");
8
- const cache = new lru_cache_1.default({ max: 10, maxAge: 60 * 1000 });
8
+ const cache = new lru_cache_1.LRUCache({ max: 10, ttl: 60 * 1000 });
9
9
  const clients = {};
10
10
  const getServiceClient = () => {
11
11
  const appId = process.env.BLOCKLET_APP_ID;
package/lib/wallet.js CHANGED
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  const wallet_1 = require("@ocap/wallet");
6
3
  const mcrypto_1 = require("@ocap/mcrypto");
7
4
  const did_1 = require("@arcblock/did");
8
- const lru_cache_1 = __importDefault(require("lru-cache"));
5
+ const lru_cache_1 = require("lru-cache");
9
6
  // NOTICE: 1 个应用的 sdk 运行时最多 4 个钱包
10
7
  // 此处 cache 只是优化性能的手段,即使 miss 也不会造成任何错误,最终决定设置 size 为 4
11
- const cacheWallet = new lru_cache_1.default({ max: 4, maxAge: 60 * 1000 });
8
+ const cacheWallet = new lru_cache_1.LRUCache({ max: 4, ttl: 60 * 1000 });
12
9
  /**
13
10
  * @param {string} [type=process.env.CHAIN_TYPE] can only be 'eth|ethereum' or 'default|arcblock'
14
11
  * @param {string} [appSk=process.env.BLOCKLET_APP_SK] must be hex
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.34-beta-20241214-102147-410be539",
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-20241214-102147-410be539",
31
- "@abtnode/constant": "1.16.34-beta-20241214-102147-410be539",
32
- "@abtnode/util": "1.16.34-beta-20241214-102147-410be539",
33
- "@arcblock/did": "1.18.161",
34
- "@arcblock/did-auth": "1.18.161",
35
- "@arcblock/jwt": "1.18.161",
36
- "@arcblock/ws": "1.18.161",
37
- "@blocklet/constant": "1.16.34-beta-20241214-102147-410be539",
38
- "@blocklet/env": "1.16.34-beta-20241214-102147-410be539",
39
- "@blocklet/meta": "1.16.34-beta-20241214-102147-410be539",
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.161",
44
- "@ocap/wallet": "1.18.161",
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",
@@ -50,7 +50,8 @@
50
50
  "json-stable-stringify": "^1.0.1",
51
51
  "jsonwebtoken": "^9.0.0",
52
52
  "lodash": "^4.17.21",
53
- "lru-cache": "^6.0.0",
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": "7f14bf890cebd9294f3953a7adc64608c078771b"
84
+ "gitHead": "91907df23611fc7d41194669bc0831af1909114c"
84
85
  }