@injectivelabs/utils 1.0.51 → 1.0.52
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.
|
@@ -11,7 +11,11 @@ class HttpClient {
|
|
|
11
11
|
},
|
|
12
12
|
}) {
|
|
13
13
|
this.config = {};
|
|
14
|
-
this.client = axios_1.default.create(
|
|
14
|
+
this.client = axios_1.default.create({
|
|
15
|
+
baseURL: endpoint,
|
|
16
|
+
timeout: 15000,
|
|
17
|
+
...options,
|
|
18
|
+
});
|
|
15
19
|
this.config = {};
|
|
16
20
|
}
|
|
17
21
|
setConfig(config) {
|
|
@@ -19,13 +23,13 @@ class HttpClient {
|
|
|
19
23
|
return this;
|
|
20
24
|
}
|
|
21
25
|
get(endpoint, params = {}) {
|
|
22
|
-
return this.client.get(endpoint,
|
|
26
|
+
return this.client.get(endpoint, { params, ...this.config });
|
|
23
27
|
}
|
|
24
28
|
post(endpoint, data = {}) {
|
|
25
29
|
return this.client.post(endpoint, data, this.config);
|
|
26
30
|
}
|
|
27
31
|
delete(endpoint, params = {}) {
|
|
28
|
-
return this.client.delete(endpoint,
|
|
32
|
+
return this.client.delete(endpoint, { params, ...this.config });
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
exports.default = HttpClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/classes/HttpClient.ts"],"names":[],"mappings":";;;;;AAAA,kDAAgE;AAEhE,MAAqB,UAAU;IAK7B,YACE,QAAgB,EAChB,UAA+B;QAC7B,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF;QARK,WAAM,GAAuB,EAAE,CAAA;QAUrC,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"HttpClient.js","sourceRoot":"","sources":["../../src/classes/HttpClient.ts"],"names":[],"mappings":";;;;;AAAA,kDAAgE;AAEhE,MAAqB,UAAU;IAK7B,YACE,QAAgB,EAChB,UAA+B;QAC7B,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF;QARK,WAAM,GAAuB,EAAE,CAAA;QAUrC,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,QAAQ;YACjB,OAAO,EAAE,KAAK;YACd,GAAG,OAAO;SACX,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,GAAG,EAAE,CAAA;IAClB,CAAC;IAED,SAAS,CAAC,MAA0B;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,GAAG,CAAO,QAAgB,EAAE,SAAY,EAAO;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IAC9D,CAAC;IAED,IAAI,CAAO,QAAgB,EAAE,OAAU,EAAO;QAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACtD,CAAC;IAED,MAAM,CAAO,QAAgB,EAAE,SAAY,EAAO;QAChD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACjE,CAAC;CACF;AAvCD,6BAuCC"}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -35,63 +26,59 @@ class HttpRestClient {
|
|
|
35
26
|
this.client.setConfig(config);
|
|
36
27
|
return this;
|
|
37
28
|
}
|
|
38
|
-
get(endpoint, params = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG,
|
|
49
|
-
method: exceptions_1.HttpRequestMethod.Get,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
const message = getErrorMessage(error, endpoint);
|
|
53
|
-
throw new exceptions_1.HttpRequestException(new Error(message), {
|
|
54
|
-
code: error.response
|
|
55
|
-
? error.response.status
|
|
56
|
-
: http_status_codes_1.StatusCodes.BAD_REQUEST,
|
|
29
|
+
async get(endpoint, params = {}) {
|
|
30
|
+
try {
|
|
31
|
+
return await this.client.get(endpoint, params);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
const error = e;
|
|
35
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
36
|
+
if (error.code === 'ECONNABORTED') {
|
|
37
|
+
throw new exceptions_1.HttpRequestException(new Error(error.message), {
|
|
38
|
+
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG,
|
|
57
39
|
method: exceptions_1.HttpRequestMethod.Get,
|
|
58
40
|
});
|
|
59
41
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
const message = getErrorMessage(error, endpoint);
|
|
43
|
+
throw new exceptions_1.HttpRequestException(new Error(message), {
|
|
44
|
+
code: error.response
|
|
45
|
+
? error.response.status
|
|
46
|
+
: http_status_codes_1.StatusCodes.BAD_REQUEST,
|
|
47
|
+
method: exceptions_1.HttpRequestMethod.Get,
|
|
63
48
|
});
|
|
64
49
|
}
|
|
65
|
-
|
|
50
|
+
throw new exceptions_1.HttpRequestException(new Error(error.message), {
|
|
51
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
52
|
+
contextModule: exceptions_1.HttpRequestMethod.Get,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
66
55
|
}
|
|
67
|
-
post(endpoint, params = {}) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
method: exceptions_1.HttpRequestMethod.Post,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
const message = getErrorMessage(error, endpoint);
|
|
82
|
-
throw new exceptions_1.HttpRequestException(new Error(message), {
|
|
83
|
-
code: error.response
|
|
84
|
-
? error.response.status
|
|
85
|
-
: http_status_codes_1.StatusCodes.BAD_REQUEST,
|
|
86
|
-
contextModule: exceptions_1.HttpRequestMethod.Post,
|
|
56
|
+
async post(endpoint, params = {}) {
|
|
57
|
+
try {
|
|
58
|
+
return await this.client.post(endpoint, params);
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
const error = e;
|
|
62
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
63
|
+
if (error.code === 'ECONNABORTED') {
|
|
64
|
+
throw new exceptions_1.HttpRequestException(new Error(error.message), {
|
|
65
|
+
code: http_status_codes_1.StatusCodes.REQUEST_TOO_LONG,
|
|
66
|
+
method: exceptions_1.HttpRequestMethod.Post,
|
|
87
67
|
});
|
|
88
68
|
}
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
const message = getErrorMessage(error, endpoint);
|
|
70
|
+
throw new exceptions_1.HttpRequestException(new Error(message), {
|
|
71
|
+
code: error.response
|
|
72
|
+
? error.response.status
|
|
73
|
+
: http_status_codes_1.StatusCodes.BAD_REQUEST,
|
|
91
74
|
contextModule: exceptions_1.HttpRequestMethod.Post,
|
|
92
75
|
});
|
|
93
76
|
}
|
|
94
|
-
|
|
77
|
+
throw new exceptions_1.HttpRequestException(new Error(error.message), {
|
|
78
|
+
code: exceptions_1.UnspecifiedErrorCode,
|
|
79
|
+
contextModule: exceptions_1.HttpRequestMethod.Post,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
95
82
|
}
|
|
96
83
|
}
|
|
97
84
|
exports.default = HttpRestClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpRestClient.js","sourceRoot":"","sources":["../../src/classes/HttpRestClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpRestClient.js","sourceRoot":"","sources":["../../src/classes/HttpRestClient.ts"],"names":[],"mappings":";;;;;AAAA,kDAA6D;AAC7D,0DAIkC;AAClC,yDAA+C;AAC/C,8DAAqC;AAErC,MAAM,eAAe,GAAG,CAAC,KAAU,EAAE,QAAgB,EAAU,EAAE;IAC/D,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;QACnB,OAAO,kBAAkB,QAAQ,cAAc,CAAA;KAChD;IAED,OAAO,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ;QAC5C,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI;QACrB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAA;AAC/B,CAAC,CAAA;AAED;;GAEG;AACH,MAAqB,cAAc;IAGjC,YAAY,QAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,oBAAU,CAAC,QAAQ,CAAC,CAAA;IACxC,CAAC;IAED,SAAS,CAAC,MAA0B;QAClC,IAAI,CAAC,MAAM,CAAC,SAAS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AAC,CAAA;SAChD;QAAC,OAAO,CAAU,EAAE;YACnB,MAAM,KAAK,GAAG,CAAuB,CAAA;YAErC,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;gBAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE;oBACjC,MAAM,IAAI,iCAAoB,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;wBACvD,IAAI,EAAE,+BAAW,CAAC,gBAAgB;wBAClC,MAAM,EAAE,8BAAiB,CAAC,IAAI;qBAC/B,CAAC,CAAA;iBACH;gBAED,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;gBAEhD,MAAM,IAAI,iCAAoB,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE;oBACjD,IAAI,EAAE,KAAK,CAAC,QAAQ;wBAClB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM;wBACvB,CAAC,CAAC,+BAAW,CAAC,WAAW;oBAC3B,aAAa,EAAE,8BAAiB,CAAC,IAAI;iBACtC,CAAC,CAAA;aACH;YAED,MAAM,IAAI,iCAAoB,CAAC,IAAI,KAAK,CAAE,KAAa,CAAC,OAAO,CAAC,EAAE;gBAChE,IAAI,EAAE,iCAAoB;gBAC1B,aAAa,EAAE,8BAAiB,CAAC,IAAI;aACtC,CAAC,CAAA;SACH;IACH,CAAC;CACF;AAhFD,iCAgFC"}
|
package/dist/time.js
CHANGED
|
@@ -12,7 +12,7 @@ const convertTimestampToMilliseconds = (timestamp) => {
|
|
|
12
12
|
}
|
|
13
13
|
if (timestamp.toString().length < 13) {
|
|
14
14
|
const trailingZeros = 13 - timestamp.toString().length;
|
|
15
|
-
return timestampInBigNumber.times(
|
|
15
|
+
return timestampInBigNumber.times(10 ** trailingZeros).toNumber();
|
|
16
16
|
}
|
|
17
17
|
return timestampInBigNumber.toNumber();
|
|
18
18
|
};
|
package/dist/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,uCAAsD;AAEzC,QAAA,gBAAgB,GAAc,IAAI,mBAAS,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAA;AAE/D,MAAM,8BAA8B,GAAG,CAC5C,SAA0B,EAClB,EAAE;IACV,MAAM,oBAAoB,GAAG,IAAI,yBAAe,CAAC,SAAS,CAAC,CAAA;IAE3D,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE;QACpC,OAAO,oBAAoB;aACxB,SAAS,CAAC,EAAE,EAAE,mBAAS,CAAC,aAAa,CAAC;aACtC,QAAQ,EAAE,CAAA;KACd;IAED,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE;QACpC,MAAM,aAAa,GAAG,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAA;QAEtD,OAAO,oBAAoB,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,uCAAsD;AAEzC,QAAA,gBAAgB,GAAc,IAAI,mBAAS,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAA;AAE/D,MAAM,8BAA8B,GAAG,CAC5C,SAA0B,EAClB,EAAE;IACV,MAAM,oBAAoB,GAAG,IAAI,yBAAe,CAAC,SAAS,CAAC,CAAA;IAE3D,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE;QACpC,OAAO,oBAAoB;aACxB,SAAS,CAAC,EAAE,EAAE,mBAAS,CAAC,aAAa,CAAC;aACtC,QAAQ,EAAE,CAAA;KACd;IAED,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,GAAG,EAAE,EAAE;QACpC,MAAM,aAAa,GAAG,EAAE,GA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AAC,CAAC;KAClC,QAAQ,EAAE,CAAA;AAHF,QAAA,QAAQ,YAGN;AAER,MAAM,iCAAiC,GAAG,CAC/C,aAA8B,EACtB,EAAE;IACV,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAA;IAE7D,OAAO,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAA;AAC5C,CAAC,CAAA;AANY,QAAA,iCAAiC,qCAM7C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/utils",
|
|
3
3
|
"description": "List of utils and helper functions that can be reused throughout Injective's projects.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.52",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bojan Angjelkoski",
|
|
7
7
|
"email": "bojan@injectivelabs.org"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"start": "node dist/index.js"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@injectivelabs/exceptions": "^1.0.
|
|
35
|
-
"@injectivelabs/ts-types": "^1.0.
|
|
34
|
+
"@injectivelabs/exceptions": "^1.0.36",
|
|
35
|
+
"@injectivelabs/ts-types": "^1.0.21",
|
|
36
36
|
"axios": "^0.21.1",
|
|
37
37
|
"bignumber.js": "^9.0.1",
|
|
38
38
|
"http-status-codes": "^2.2.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"snakecase-keys": "^5.1.2",
|
|
42
42
|
"store2": "^2.12.0"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "9c5c63534dd63a09be137644b4ca41fbdc8c5781"
|
|
45
45
|
}
|