@injectivelabs/utils 1.20.62 → 1.20.63

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,4 +1,4 @@
1
- import { t as _defineProperty } from "./defineProperty-Zp25b8Cm.js";
1
+ import { t as _defineProperty } from "./defineProperty-DiY4Kzl4.js";
2
2
  import store from "store2";
3
3
 
4
4
  //#region src/classes/LocalStorage.ts
@@ -1,4 +1,4 @@
1
- import { t as _defineProperty } from "./defineProperty-Zp25b8Cm.js";
1
+ import { t as _defineProperty } from "./defineProperty-DiY4Kzl4.js";
2
2
 
3
3
  //#region src/enum.ts
4
4
  const StatusType = {
@@ -1,2 +1,2 @@
1
- import { n as HttpClient, t as HttpRestClient } from "./HttpRestClient-B-UvB9KB.js";
1
+ import { p as HttpClient, t as HttpRestClient } from "./HttpRestClient-00SidMhA.js";
2
2
  export { HttpClient, HttpRestClient };
package/dist/esm/http.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./defineProperty-Zp25b8Cm.js";
2
- import { n as HttpClient, t as HttpRestClient } from "./HttpRestClient-CsKkn8lo.js";
1
+ import { n as HttpClient, t as HttpRestClient } from "./HttpRestClient-CWyiACSA.js";
2
+ import "./defineProperty-DiY4Kzl4.js";
3
3
 
4
4
  export { HttpClient, HttpRestClient };
@@ -3,9 +3,9 @@ import { n as BigNumberInBase, t as BigNumberInWei } from "./BigNumberInWei-JtQu
3
3
  import { _ as INJ_DENOM, a as DEFAULT_BRIDGE_FEE_PRICE, c as DEFAULT_GAS_LIMIT, d as DEFAULT_STD_FEE_BY_DENOM, f as DEFAULT_TIMESTAMP_TIMEOUT_MS, g as INJECTIVE_DENOM, h as DEFAULT_TX_POLL_INTERVAL_MS, i as DEFAULT_BRIDGE_FEE_DENOM, l as DEFAULT_GAS_PRICE, m as DEFAULT_TX_POLL_CALL_TIMEOUT_MS, n as DEFAULT_BLOCK_TIME_IN_SECONDS, o as DEFAULT_EXCHANGE_LIMIT, p as DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, r as DEFAULT_BRIDGE_FEE_AMOUNT, s as DEFAULT_FEE_DENOM, t as DEFAULT_BLOCK_TIMEOUT_HEIGHT, u as DEFAULT_IBC_GAS_LIMIT, v as ZERO_ADDRESS, y as getDefaultStdFee } from "./constants-BPYHMKzA.js";
4
4
  import { i as toPascalCase, n as formatWalletAddress, r as snakeToPascal, t as capitalize } from "./formatters-v2reo54H.js";
5
5
  import { a as getStdFeeFromObject, c as splitArrayToChunks, i as getStdFeeForToken, l as splitArrayToChunksThrow, n as awaitForAll, o as getStdFeeFromString, r as getStdFee, s as sleep, t as awaitAll } from "./helpers-BZ1LFB-6.js";
6
- import { n as HttpClient, t as HttpRestClient } from "./HttpRestClient-B-UvB9KB.js";
6
+ import { a as AbortErrorLike, c as combineAbortSignals, d as raceWithAbort, f as throwIfAborted, i as AbortError, l as createAbortError, n as RetryRequestConfig, o as RequestOptions, p as HttpClient, r as RetryOptions, s as abortableSleep, t as HttpRestClient, u as isAbortError } from "./HttpRestClient-00SidMhA.js";
7
7
  import { a as past24Hours, c as tomorrow, i as getUTCDateFromTimestamp, n as getEndDateStringFromTimeInSeconds, o as pastDays, r as getSecondsInDay, s as todayInSeconds, t as convertTimestampToMilliseconds } from "./time-DJirA2PE.js";
8
8
  import { n as getExactDecimalsFromNumber, r as getSignificantDecimalsFromNumber, t as getBigNumberWithRounding } from "./numbers-Bnbd75cb.js";
9
9
  import { n as StatusType, t as Status } from "./Status-C6A6ZtpL.js";
10
10
  import { t as LocalStorage } from "./LocalStorage-CyTj3H1T.js";
11
- export { BigNumber, BigNumberInBase, BigNumberInWei, DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_BRIDGE_FEE_AMOUNT, DEFAULT_BRIDGE_FEE_DENOM, DEFAULT_BRIDGE_FEE_PRICE, DEFAULT_EXCHANGE_LIMIT, DEFAULT_FEE_DENOM, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, DEFAULT_IBC_GAS_LIMIT, DEFAULT_STD_FEE_BY_DENOM, DEFAULT_TIMESTAMP_TIMEOUT_MS, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, DEFAULT_TX_POLL_CALL_TIMEOUT_MS, DEFAULT_TX_POLL_INTERVAL_MS, HttpClient, HttpRestClient, INJECTIVE_DENOM, INJ_DENOM, LocalStorage, Status, StatusType, ZERO_ADDRESS, awaitAll, awaitForAll, capitalize, convertTimestampToMilliseconds, formatWalletAddress, getBigNumberWithRounding, getDefaultStdFee, getEndDateStringFromTimeInSeconds, getExactDecimalsFromNumber, getSecondsInDay, getSignificantDecimalsFromNumber, getStdFee, getStdFeeForToken, getStdFeeFromObject, getStdFeeFromString, getUTCDateFromTimestamp, past24Hours, pastDays, sleep, snakeToPascal, splitArrayToChunks, splitArrayToChunksThrow, toBigNumber, toChainFormat, toHumanReadable, toPascalCase, todayInSeconds, tomorrow };
11
+ export { AbortError, AbortErrorLike, BigNumber, BigNumberInBase, BigNumberInWei, DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_BRIDGE_FEE_AMOUNT, DEFAULT_BRIDGE_FEE_DENOM, DEFAULT_BRIDGE_FEE_PRICE, DEFAULT_EXCHANGE_LIMIT, DEFAULT_FEE_DENOM, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, DEFAULT_IBC_GAS_LIMIT, DEFAULT_STD_FEE_BY_DENOM, DEFAULT_TIMESTAMP_TIMEOUT_MS, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, DEFAULT_TX_POLL_CALL_TIMEOUT_MS, DEFAULT_TX_POLL_INTERVAL_MS, HttpClient, HttpRestClient, INJECTIVE_DENOM, INJ_DENOM, LocalStorage, RequestOptions, RetryOptions, type RetryRequestConfig, Status, StatusType, ZERO_ADDRESS, abortableSleep, awaitAll, awaitForAll, capitalize, combineAbortSignals, convertTimestampToMilliseconds, createAbortError, formatWalletAddress, getBigNumberWithRounding, getDefaultStdFee, getEndDateStringFromTimeInSeconds, getExactDecimalsFromNumber, getSecondsInDay, getSignificantDecimalsFromNumber, getStdFee, getStdFeeForToken, getStdFeeFromObject, getStdFeeFromString, getUTCDateFromTimestamp, isAbortError, past24Hours, pastDays, raceWithAbort, sleep, snakeToPascal, splitArrayToChunks, splitArrayToChunksThrow, throwIfAborted, toBigNumber, toChainFormat, toHumanReadable, toPascalCase, todayInSeconds, tomorrow };
package/dist/esm/index.js CHANGED
@@ -1,13 +1,13 @@
1
- import "./defineProperty-Zp25b8Cm.js";
2
- import { n as HttpClient, t as HttpRestClient } from "./HttpRestClient-CsKkn8lo.js";
1
+ import { a as combineAbortSignals, c as raceWithAbort, i as abortableSleep, l as throwIfAborted, n as HttpClient, o as createAbortError, r as AbortError, s as isAbortError, t as HttpRestClient } from "./HttpRestClient-CWyiACSA.js";
2
+ import "./defineProperty-DiY4Kzl4.js";
3
3
  import { i as toHumanReadable, n as toBigNumber, r as toChainFormat, t as BigNumber_default } from "./BigNumber-DUr2WQBK.js";
4
4
  import { a as past24Hours, c as tomorrow, i as getUTCDateFromTimestamp, n as getEndDateStringFromTimeInSeconds, o as pastDays, r as getSecondsInDay, s as todayInSeconds, t as convertTimestampToMilliseconds } from "./time-BBEhFnvo.js";
5
5
  import { _ as INJ_DENOM, a as DEFAULT_BRIDGE_FEE_PRICE, c as DEFAULT_GAS_LIMIT, d as DEFAULT_STD_FEE_BY_DENOM, f as DEFAULT_TIMESTAMP_TIMEOUT_MS, g as INJECTIVE_DENOM, h as DEFAULT_TX_POLL_INTERVAL_MS, i as DEFAULT_BRIDGE_FEE_DENOM, l as DEFAULT_GAS_PRICE, m as DEFAULT_TX_POLL_CALL_TIMEOUT_MS, n as DEFAULT_BLOCK_TIME_IN_SECONDS, o as DEFAULT_EXCHANGE_LIMIT, p as DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, r as DEFAULT_BRIDGE_FEE_AMOUNT, s as DEFAULT_FEE_DENOM, t as DEFAULT_BLOCK_TIMEOUT_HEIGHT, u as DEFAULT_IBC_GAS_LIMIT, v as ZERO_ADDRESS, y as getDefaultStdFee } from "./constants-0w1sGXWU.js";
6
6
  import { a as getStdFeeFromObject, c as splitArrayToChunks, i as getStdFeeForToken, l as splitArrayToChunksThrow, n as awaitForAll, o as getStdFeeFromString, r as getStdFee, s as sleep, t as awaitAll } from "./helpers-BsGkkq54.js";
7
7
  import { n as getExactDecimalsFromNumber, r as getSignificantDecimalsFromNumber, t as getBigNumberWithRounding } from "./numbers-Dh5x3_mA.js";
8
8
  import { i as toPascalCase, n as formatWalletAddress, r as snakeToPascal, t as capitalize } from "./formatters-QUaa2UZY.js";
9
- import { n as StatusType, t as Status } from "./Status-eHtiFREA.js";
10
- import { t as LocalStorage } from "./LocalStorage-Cpe5wG8z.js";
9
+ import { n as StatusType, t as Status } from "./Status-BhM2hdSA.js";
10
+ import { t as LocalStorage } from "./LocalStorage-CVCXt4aX.js";
11
11
  import { n as BigNumberInWei, t as BigNumberInBase } from "./BigNumberInBase-Dcx5wyxY.js";
12
12
 
13
- export { BigNumber_default as BigNumber, BigNumberInBase, BigNumberInWei, DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_BRIDGE_FEE_AMOUNT, DEFAULT_BRIDGE_FEE_DENOM, DEFAULT_BRIDGE_FEE_PRICE, DEFAULT_EXCHANGE_LIMIT, DEFAULT_FEE_DENOM, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, DEFAULT_IBC_GAS_LIMIT, DEFAULT_STD_FEE_BY_DENOM, DEFAULT_TIMESTAMP_TIMEOUT_MS, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, DEFAULT_TX_POLL_CALL_TIMEOUT_MS, DEFAULT_TX_POLL_INTERVAL_MS, HttpClient, HttpRestClient, INJECTIVE_DENOM, INJ_DENOM, LocalStorage, Status, StatusType, ZERO_ADDRESS, awaitAll, awaitForAll, capitalize, convertTimestampToMilliseconds, formatWalletAddress, getBigNumberWithRounding, getDefaultStdFee, getEndDateStringFromTimeInSeconds, getExactDecimalsFromNumber, getSecondsInDay, getSignificantDecimalsFromNumber, getStdFee, getStdFeeForToken, getStdFeeFromObject, getStdFeeFromString, getUTCDateFromTimestamp, past24Hours, pastDays, sleep, snakeToPascal, splitArrayToChunks, splitArrayToChunksThrow, toBigNumber, toChainFormat, toHumanReadable, toPascalCase, todayInSeconds, tomorrow };
13
+ export { AbortError, BigNumber_default as BigNumber, BigNumberInBase, BigNumberInWei, DEFAULT_BLOCK_TIMEOUT_HEIGHT, DEFAULT_BLOCK_TIME_IN_SECONDS, DEFAULT_BRIDGE_FEE_AMOUNT, DEFAULT_BRIDGE_FEE_DENOM, DEFAULT_BRIDGE_FEE_PRICE, DEFAULT_EXCHANGE_LIMIT, DEFAULT_FEE_DENOM, DEFAULT_GAS_LIMIT, DEFAULT_GAS_PRICE, DEFAULT_IBC_GAS_LIMIT, DEFAULT_STD_FEE_BY_DENOM, DEFAULT_TIMESTAMP_TIMEOUT_MS, DEFAULT_TX_BLOCK_INCLUSION_TIMEOUT_IN_MS, DEFAULT_TX_POLL_CALL_TIMEOUT_MS, DEFAULT_TX_POLL_INTERVAL_MS, HttpClient, HttpRestClient, INJECTIVE_DENOM, INJ_DENOM, LocalStorage, Status, StatusType, ZERO_ADDRESS, abortableSleep, awaitAll, awaitForAll, capitalize, combineAbortSignals, convertTimestampToMilliseconds, createAbortError, formatWalletAddress, getBigNumberWithRounding, getDefaultStdFee, getEndDateStringFromTimeInSeconds, getExactDecimalsFromNumber, getSecondsInDay, getSignificantDecimalsFromNumber, getStdFee, getStdFeeForToken, getStdFeeFromObject, getStdFeeFromString, getUTCDateFromTimestamp, isAbortError, past24Hours, pastDays, raceWithAbort, sleep, snakeToPascal, splitArrayToChunks, splitArrayToChunksThrow, throwIfAborted, toBigNumber, toChainFormat, toHumanReadable, toPascalCase, todayInSeconds, tomorrow };
package/dist/esm/light.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as _defineProperty } from "./defineProperty-Zp25b8Cm.js";
1
+ import { t as _defineProperty } from "./defineProperty-DiY4Kzl4.js";
2
2
 
3
3
  //#region src/light.ts
4
4
  const StatusType = {
@@ -1,4 +1,4 @@
1
- import "./defineProperty-Zp25b8Cm.js";
2
- import { n as StatusType, t as Status } from "./Status-eHtiFREA.js";
1
+ import "./defineProperty-DiY4Kzl4.js";
2
+ import { n as StatusType, t as Status } from "./Status-BhM2hdSA.js";
3
3
 
4
4
  export { Status, StatusType };
@@ -1,4 +1,4 @@
1
- import "./defineProperty-Zp25b8Cm.js";
2
- import { t as LocalStorage } from "./LocalStorage-Cpe5wG8z.js";
1
+ import "./defineProperty-DiY4Kzl4.js";
2
+ import { t as LocalStorage } from "./LocalStorage-CVCXt4aX.js";
3
3
 
4
4
  export { LocalStorage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@injectivelabs/utils",
3
- "version": "1.20.62",
3
+ "version": "1.20.63",
4
4
  "description": "List of utils and helper functions that can be reused throughout Injective's projects.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -266,9 +266,9 @@
266
266
  "bignumber.js": "^9.3.1",
267
267
  "http-status-codes": "^2.3.0",
268
268
  "store2": "^2.14.4",
269
- "@injectivelabs/exceptions": "1.20.62",
270
- "@injectivelabs/ts-types": "1.20.62",
271
- "@injectivelabs/networks": "1.20.62"
269
+ "@injectivelabs/networks": "1.20.63",
270
+ "@injectivelabs/ts-types": "1.20.63",
271
+ "@injectivelabs/exceptions": "1.20.63"
272
272
  },
273
273
  "publishConfig": {
274
274
  "access": "public"
@@ -1,29 +0,0 @@
1
- import { AxiosRequestConfig } from "axios";
2
-
3
- //#region src/classes/HttpClient.d.ts
4
- declare class HttpClient {
5
- private readonly client;
6
- private config;
7
- constructor(endpoint: string, options?: Record<string, any>);
8
- setConfig(config: AxiosRequestConfig): HttpClient;
9
- get<T, P>(endpoint: string, params?: T): Promise<P>;
10
- post<T, P>(endpoint: string, data?: T): Promise<P>;
11
- put<T, P>(endpoint: string, data?: T): Promise<P>;
12
- delete<T, P>(endpoint: string, params?: T): Promise<P>;
13
- }
14
- //#endregion
15
- //#region src/classes/HttpRestClient.d.ts
16
- /**
17
- * @hidden
18
- */
19
- declare class HttpRestClient {
20
- protected client: HttpClient;
21
- protected endpoint: string;
22
- constructor(endpoint: string, options?: Record<string, any>);
23
- setConfig(config: AxiosRequestConfig): HttpRestClient;
24
- get<T>(endpoint: string, params?: Record<string, any>): Promise<T>;
25
- retry<TResponse>(httpCall: Function, retries?: number, delay?: number): Promise<TResponse>;
26
- post<T>(endpoint: string, params?: Record<string, any>): Promise<T>;
27
- }
28
- //#endregion
29
- export { HttpClient as n, HttpRestClient as t };
@@ -1,138 +0,0 @@
1
- const require_chunk = require('./chunk-CbDLau6x.cjs');
2
- const require_defineProperty = require('./defineProperty-CImP5zIM.cjs');
3
- let axios = require("axios");
4
- axios = require_chunk.__toESM(axios);
5
- let http_status_codes = require("http-status-codes");
6
- let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
7
-
8
- //#region src/classes/HttpClient.ts
9
- var HttpClient = class {
10
- constructor(endpoint, options = { headers: { "Content-Type": "application/json" } }) {
11
- require_defineProperty._defineProperty(this, "client", void 0);
12
- require_defineProperty._defineProperty(this, "config", {});
13
- this.client = axios.default.create({
14
- baseURL: endpoint,
15
- timeout: 15e3,
16
- ...options
17
- });
18
- this.config = {};
19
- }
20
- setConfig(config) {
21
- this.config = config;
22
- return this;
23
- }
24
- get(endpoint, params = {}) {
25
- return this.client.get(endpoint, {
26
- params,
27
- ...this.config
28
- });
29
- }
30
- post(endpoint, data = {}) {
31
- return this.client.post(endpoint, data, this.config);
32
- }
33
- put(endpoint, data = {}) {
34
- return this.client.put(endpoint, data, this.config);
35
- }
36
- delete(endpoint, params = {}) {
37
- return this.client.delete(endpoint, {
38
- params,
39
- ...this.config
40
- });
41
- }
42
- };
43
-
44
- //#endregion
45
- //#region src/classes/HttpRestClient.ts
46
- const getErrorMessage = (error, endpoint) => {
47
- if (!error.response) return `The request to ${endpoint} has failed.`;
48
- return error.response.data ? error.response.data.message || error.response.data.statusMessage || error.response.data : error.response.statusText;
49
- };
50
- /**
51
- * @hidden
52
- */
53
- var HttpRestClient = class {
54
- constructor(endpoint, options = {}) {
55
- require_defineProperty._defineProperty(this, "client", void 0);
56
- require_defineProperty._defineProperty(this, "endpoint", void 0);
57
- this.client = new HttpClient(endpoint, options);
58
- this.endpoint = endpoint;
59
- }
60
- setConfig(config) {
61
- this.client.setConfig(config);
62
- return this;
63
- }
64
- async get(endpoint, params = {}) {
65
- try {
66
- return await this.client.get(endpoint, params);
67
- } catch (e) {
68
- const error = e;
69
- if (axios.default.isAxiosError(error)) {
70
- if (error.code === "ECONNABORTED") throw new __injectivelabs_exceptions.HttpRequestException(new Error(error.message), {
71
- code: http_status_codes.StatusCodes.REQUEST_TOO_LONG,
72
- context: endpoint
73
- });
74
- const message = getErrorMessage(error, endpoint);
75
- throw new __injectivelabs_exceptions.HttpRequestException(new Error(message), {
76
- context: endpoint,
77
- code: error.response ? error.response.status : http_status_codes.StatusCodes.BAD_REQUEST
78
- });
79
- }
80
- throw new __injectivelabs_exceptions.HttpRequestException(new Error(error.message), {
81
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
82
- context: endpoint
83
- });
84
- }
85
- }
86
- async retry(httpCall, retries = 3, delay = 1e3) {
87
- const retryHttpCall = async (attempt = 1) => {
88
- try {
89
- return await httpCall();
90
- } catch (e) {
91
- if (e instanceof __injectivelabs_exceptions.HttpRequestException) {
92
- if (e.code === http_status_codes.StatusCodes.REQUEST_TOO_LONG) throw e;
93
- }
94
- if (attempt >= retries) throw e;
95
- return new Promise((resolve) => setTimeout(() => resolve(retryHttpCall(attempt + 1)), delay * attempt));
96
- }
97
- };
98
- return retryHttpCall();
99
- }
100
- async post(endpoint, params = {}) {
101
- try {
102
- return await this.client.post(endpoint, params);
103
- } catch (e) {
104
- const error = e;
105
- if (axios.default.isAxiosError(error)) {
106
- if (error.code === "ECONNABORTED") throw new __injectivelabs_exceptions.HttpRequestException(new Error(error.message), {
107
- code: http_status_codes.StatusCodes.REQUEST_TOO_LONG,
108
- method: __injectivelabs_exceptions.HttpRequestMethod.Post
109
- });
110
- const message = getErrorMessage(error, endpoint);
111
- throw new __injectivelabs_exceptions.HttpRequestException(new Error(message), {
112
- code: error.response ? error.response.status : http_status_codes.StatusCodes.BAD_REQUEST,
113
- context: endpoint,
114
- contextModule: __injectivelabs_exceptions.HttpRequestMethod.Post
115
- });
116
- }
117
- throw new __injectivelabs_exceptions.HttpRequestException(new Error(error.message), {
118
- code: __injectivelabs_exceptions.UnspecifiedErrorCode,
119
- context: endpoint,
120
- contextModule: __injectivelabs_exceptions.HttpRequestMethod.Post
121
- });
122
- }
123
- }
124
- };
125
-
126
- //#endregion
127
- Object.defineProperty(exports, 'HttpClient', {
128
- enumerable: true,
129
- get: function () {
130
- return HttpClient;
131
- }
132
- });
133
- Object.defineProperty(exports, 'HttpRestClient', {
134
- enumerable: true,
135
- get: function () {
136
- return HttpRestClient;
137
- }
138
- });
@@ -1,29 +0,0 @@
1
- import { AxiosRequestConfig } from "axios";
2
-
3
- //#region src/classes/HttpClient.d.ts
4
- declare class HttpClient {
5
- private readonly client;
6
- private config;
7
- constructor(endpoint: string, options?: Record<string, any>);
8
- setConfig(config: AxiosRequestConfig): HttpClient;
9
- get<T, P>(endpoint: string, params?: T): Promise<P>;
10
- post<T, P>(endpoint: string, data?: T): Promise<P>;
11
- put<T, P>(endpoint: string, data?: T): Promise<P>;
12
- delete<T, P>(endpoint: string, params?: T): Promise<P>;
13
- }
14
- //#endregion
15
- //#region src/classes/HttpRestClient.d.ts
16
- /**
17
- * @hidden
18
- */
19
- declare class HttpRestClient {
20
- protected client: HttpClient;
21
- protected endpoint: string;
22
- constructor(endpoint: string, options?: Record<string, any>);
23
- setConfig(config: AxiosRequestConfig): HttpRestClient;
24
- get<T>(endpoint: string, params?: Record<string, any>): Promise<T>;
25
- retry<TResponse>(httpCall: Function, retries?: number, delay?: number): Promise<TResponse>;
26
- post<T>(endpoint: string, params?: Record<string, any>): Promise<T>;
27
- }
28
- //#endregion
29
- export { HttpClient as n, HttpRestClient as t };
@@ -1,125 +0,0 @@
1
- import { t as _defineProperty } from "./defineProperty-Zp25b8Cm.js";
2
- import axios from "axios";
3
- import { StatusCodes } from "http-status-codes";
4
- import { HttpRequestException, HttpRequestMethod, UnspecifiedErrorCode } from "@injectivelabs/exceptions";
5
-
6
- //#region src/classes/HttpClient.ts
7
- var HttpClient = class {
8
- constructor(endpoint, options = { headers: { "Content-Type": "application/json" } }) {
9
- _defineProperty(this, "client", void 0);
10
- _defineProperty(this, "config", {});
11
- this.client = axios.create({
12
- baseURL: endpoint,
13
- timeout: 15e3,
14
- ...options
15
- });
16
- this.config = {};
17
- }
18
- setConfig(config) {
19
- this.config = config;
20
- return this;
21
- }
22
- get(endpoint, params = {}) {
23
- return this.client.get(endpoint, {
24
- params,
25
- ...this.config
26
- });
27
- }
28
- post(endpoint, data = {}) {
29
- return this.client.post(endpoint, data, this.config);
30
- }
31
- put(endpoint, data = {}) {
32
- return this.client.put(endpoint, data, this.config);
33
- }
34
- delete(endpoint, params = {}) {
35
- return this.client.delete(endpoint, {
36
- params,
37
- ...this.config
38
- });
39
- }
40
- };
41
-
42
- //#endregion
43
- //#region src/classes/HttpRestClient.ts
44
- const getErrorMessage = (error, endpoint) => {
45
- if (!error.response) return `The request to ${endpoint} has failed.`;
46
- return error.response.data ? error.response.data.message || error.response.data.statusMessage || error.response.data : error.response.statusText;
47
- };
48
- /**
49
- * @hidden
50
- */
51
- var HttpRestClient = class {
52
- constructor(endpoint, options = {}) {
53
- _defineProperty(this, "client", void 0);
54
- _defineProperty(this, "endpoint", void 0);
55
- this.client = new HttpClient(endpoint, options);
56
- this.endpoint = endpoint;
57
- }
58
- setConfig(config) {
59
- this.client.setConfig(config);
60
- return this;
61
- }
62
- async get(endpoint, params = {}) {
63
- try {
64
- return await this.client.get(endpoint, params);
65
- } catch (e) {
66
- const error = e;
67
- if (axios.isAxiosError(error)) {
68
- if (error.code === "ECONNABORTED") throw new HttpRequestException(new Error(error.message), {
69
- code: StatusCodes.REQUEST_TOO_LONG,
70
- context: endpoint
71
- });
72
- const message = getErrorMessage(error, endpoint);
73
- throw new HttpRequestException(new Error(message), {
74
- context: endpoint,
75
- code: error.response ? error.response.status : StatusCodes.BAD_REQUEST
76
- });
77
- }
78
- throw new HttpRequestException(new Error(error.message), {
79
- code: UnspecifiedErrorCode,
80
- context: endpoint
81
- });
82
- }
83
- }
84
- async retry(httpCall, retries = 3, delay = 1e3) {
85
- const retryHttpCall = async (attempt = 1) => {
86
- try {
87
- return await httpCall();
88
- } catch (e) {
89
- if (e instanceof HttpRequestException) {
90
- if (e.code === StatusCodes.REQUEST_TOO_LONG) throw e;
91
- }
92
- if (attempt >= retries) throw e;
93
- return new Promise((resolve) => setTimeout(() => resolve(retryHttpCall(attempt + 1)), delay * attempt));
94
- }
95
- };
96
- return retryHttpCall();
97
- }
98
- async post(endpoint, params = {}) {
99
- try {
100
- return await this.client.post(endpoint, params);
101
- } catch (e) {
102
- const error = e;
103
- if (axios.isAxiosError(error)) {
104
- if (error.code === "ECONNABORTED") throw new HttpRequestException(new Error(error.message), {
105
- code: StatusCodes.REQUEST_TOO_LONG,
106
- method: HttpRequestMethod.Post
107
- });
108
- const message = getErrorMessage(error, endpoint);
109
- throw new HttpRequestException(new Error(message), {
110
- code: error.response ? error.response.status : StatusCodes.BAD_REQUEST,
111
- context: endpoint,
112
- contextModule: HttpRequestMethod.Post
113
- });
114
- }
115
- throw new HttpRequestException(new Error(error.message), {
116
- code: UnspecifiedErrorCode,
117
- context: endpoint,
118
- contextModule: HttpRequestMethod.Post
119
- });
120
- }
121
- }
122
- };
123
-
124
- //#endregion
125
- export { HttpClient as n, HttpRestClient as t };