@rabby-wallet/rabby-api 0.9.45 → 0.9.47

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/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ import { AddrDescResponse, BridgeAggregator, ApprovalStatus, AssetItem, BasicDap
5
5
  interface OpenApiStore {
6
6
  host: string;
7
7
  testnetHost?: string;
8
+ apiKey: string | null;
9
+ apiTime: number | null;
8
10
  }
9
11
  interface Options {
10
12
  store: OpenApiStore | Promise<OpenApiStore>;
@@ -28,6 +30,9 @@ export declare class OpenApiService {
28
30
  constructor({ store, plugin, adapter, clientName, clientVersion, }: Options);
29
31
  setHost: (host: string) => Promise<void>;
30
32
  setHostSync: (host: string) => void;
33
+ setAPIKey: (apiKey: string) => Promise<void>;
34
+ setAPITime: (apiTime: number) => Promise<void>;
35
+ removeAPIKey: () => Promise<void>;
31
36
  getHost: () => string;
32
37
  setTestnetHost: (host: string) => Promise<void>;
33
38
  getTestnetHost: () => string | undefined;
package/dist/index.js CHANGED
@@ -58,6 +58,19 @@ export class OpenApiService {
58
58
  this.store.host = host;
59
59
  this.initSync();
60
60
  };
61
+ this.setAPIKey = (apiKey) => __awaiter(this, void 0, void 0, function* () {
62
+ this.store.apiKey = apiKey;
63
+ yield this.init();
64
+ });
65
+ this.setAPITime = (apiTime) => __awaiter(this, void 0, void 0, function* () {
66
+ this.store.apiTime = apiTime;
67
+ yield this.init();
68
+ });
69
+ this.removeAPIKey = () => __awaiter(this, void 0, void 0, function* () {
70
+ this.store.apiKey = null;
71
+ this.store.apiTime = null;
72
+ yield this.init();
73
+ });
61
74
  this.getHost = () => {
62
75
  return this.store.host;
63
76
  };
@@ -1780,13 +1793,18 @@ export class OpenApiService {
1780
1793
  initSync(options) {
1781
1794
  var _a, _b;
1782
1795
  (_b = (_a = __classPrivateFieldGet(this, _OpenApiService_plugin, "f")).onInitiate) === null || _b === void 0 ? void 0 : _b.call(_a, Object.assign({}, options));
1796
+ const headers = {
1797
+ 'X-Client': __classPrivateFieldGet(this, _OpenApiService_clientName, "f"),
1798
+ 'X-Version': __classPrivateFieldGet(this, _OpenApiService_clientVersion, "f"),
1799
+ };
1800
+ if (this.store.apiKey && this.store.apiTime) {
1801
+ headers['X-API-Key'] = this.store.apiKey;
1802
+ headers['X-API-Time'] = this.store.apiTime;
1803
+ }
1783
1804
  const request = axios.create({
1784
1805
  baseURL: this.store.host,
1785
1806
  adapter: __classPrivateFieldGet(this, _OpenApiService_adapter, "f"),
1786
- headers: {
1787
- 'X-Client': __classPrivateFieldGet(this, _OpenApiService_clientName, "f"),
1788
- 'X-Version': __classPrivateFieldGet(this, _OpenApiService_clientVersion, "f"),
1789
- },
1807
+ headers,
1790
1808
  });
1791
1809
  // sign after rateLimit, timestamp is the latest
1792
1810
  request.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () {
@@ -1799,9 +1817,13 @@ export class OpenApiService {
1799
1817
  }));
1800
1818
  this.request = rateLimit(request, { maxRPS });
1801
1819
  this.request.interceptors.response.use((response) => {
1802
- var _a, _b, _c, _d;
1803
- const code = ((_a = response.data) === null || _a === void 0 ? void 0 : _a.err_code) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.error_code);
1804
- const msg = ((_c = response.data) === null || _c === void 0 ? void 0 : _c.err_msg) || ((_d = response.data) === null || _d === void 0 ? void 0 : _d.error_msg);
1820
+ var _a, _b, _c, _d, _e;
1821
+ const newAPIKey = (_a = response.headers) === null || _a === void 0 ? void 0 : _a['x-set-api-key'];
1822
+ if (newAPIKey) {
1823
+ this.setAPIKey(newAPIKey);
1824
+ }
1825
+ const code = ((_b = response.data) === null || _b === void 0 ? void 0 : _b.err_code) || ((_c = response.data) === null || _c === void 0 ? void 0 : _c.error_code);
1826
+ const msg = ((_d = response.data) === null || _d === void 0 ? void 0 : _d.err_msg) || ((_e = response.data) === null || _e === void 0 ? void 0 : _e.error_msg);
1805
1827
  if (code && code !== 200) {
1806
1828
  if (msg) {
1807
1829
  let err;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-api",
3
- "version": "0.9.45",
3
+ "version": "0.9.47",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [