@dashevo/dapi-client 0.24.0-dev.11 → 0.24.0-dev.12

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/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ require('../polyfills/fetch-polyfill');
2
+
1
3
  const DAPIClient = require('./DAPIClient');
2
4
 
3
5
  const NotFoundError = require('./transport/GrpcTransport/errors/NotFoundError');
@@ -1,3 +1,5 @@
1
+ require('../../polyfills/fetch-polyfill');
2
+
1
3
  const { expect, use } = require('chai');
2
4
  const sinon = require('sinon');
3
5
  const sinonChai = require('sinon-chai');
@@ -1,6 +1,4 @@
1
- const axios = require('axios');
2
1
  const https = require('https');
3
-
4
2
  const JsonRpcError = require('./errors/JsonRpcError');
5
3
  const WrongHttpCodeError = require('./errors/WrongHttpCodeError');
6
4
 
@@ -25,11 +23,6 @@ async function requestJsonRpc(protocol, host, port, selfSigned, method, params,
25
23
  id: 1,
26
24
  };
27
25
 
28
- const postOptions = {};
29
- if (options.timeout !== undefined) {
30
- postOptions.timeout = options.timeout;
31
- }
32
-
33
26
  const requestInfo = {
34
27
  protocol,
35
28
  host,
@@ -40,40 +33,44 @@ async function requestJsonRpc(protocol, host, port, selfSigned, method, params,
40
33
  options,
41
34
  };
42
35
 
43
- let response;
36
+ const requestOptions = {
37
+ method: 'POST',
38
+ body: JSON.stringify(payload),
39
+ headers: {
40
+ 'Content-Type': 'application/json',
41
+ },
42
+ };
43
+
44
+ let requestTimeoutId;
45
+ if (options.timeout) {
46
+ const controller = new AbortController();
47
+ requestTimeoutId = setTimeout(() => controller.abort(), options.timeout);
48
+ Object.assign(requestOptions, { signal: controller.signal });
49
+ }
44
50
 
45
- const config = { timeout: options.timeout };
46
51
  // For NodeJS Client
47
52
  if (typeof process !== 'undefined'
48
53
  && process.versions != null
49
54
  && process.versions.node != null
50
55
  && protocol === 'https'
51
56
  && selfSigned) {
52
- config.httpsAgent = new https.Agent({
57
+ requestOptions.agent = new https.Agent({
53
58
  rejectUnauthorized: false,
54
59
  });
55
60
  }
56
61
 
57
- try {
58
- response = await axios.post(
59
- url,
60
- payload,
61
- config,
62
- );
63
- } catch (error) {
64
- if (error.response && error.response.status >= 500) {
65
- throw new WrongHttpCodeError(requestInfo, error.response.status, error.response.statusText);
66
- }
62
+ // eslint-disable-next-line
63
+ const response = await fetch(url, requestOptions);
67
64
 
68
- throw error;
65
+ if (typeof requestTimeoutId !== 'undefined') {
66
+ clearTimeout(requestTimeoutId);
69
67
  }
68
+ const data = await response.json();
70
69
 
71
- if (response.status !== 200) {
72
- throw new WrongHttpCodeError(requestInfo, response.status, response.statusMessage);
70
+ if (!response.ok) {
71
+ throw new WrongHttpCodeError(requestInfo, response.status, response.statusText);
73
72
  }
74
73
 
75
- const { data } = response;
76
-
77
74
  if (data.error) {
78
75
  throw new JsonRpcError(requestInfo, data.error);
79
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "0.24.0-dev.11",
3
+ "version": "0.24.0-dev.12",
4
4
  "description": "Client library used to access Dash DAPI endpoints",
5
5
  "main": "lib/index.js",
6
6
  "contributors": [
@@ -26,15 +26,15 @@
26
26
  }
27
27
  ],
28
28
  "dependencies": {
29
- "@dashevo/dapi-grpc": "0.24.0-dev.11",
30
- "@dashevo/dash-spv": "0.24.0-dev.11",
29
+ "@dashevo/dapi-grpc": "0.24.0-dev.12",
30
+ "@dashevo/dash-spv": "0.24.0-dev.12",
31
31
  "@dashevo/dashcore-lib": "~0.19.44",
32
- "@dashevo/dpp": "0.24.0-dev.11",
33
- "@dashevo/grpc-common": "0.24.0-dev.11",
34
- "axios": "^0.27.2",
32
+ "@dashevo/dpp": "0.24.0-dev.12",
33
+ "@dashevo/grpc-common": "0.24.0-dev.12",
35
34
  "bs58": "^4.0.1",
36
35
  "cbor": "^8.0.0",
37
36
  "lodash": "^4.17.21",
37
+ "node-fetch": "^2.6.7",
38
38
  "node-inspect-extracted": "^1.0.8",
39
39
  "wasm-x11-hash": "~0.0.2"
40
40
  },