@autofleet/network 1.2.9-alpha-5 → 1.2.9-alpha-6
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/index.js +37 -24
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const undici = require('undici');
|
|
2
2
|
const http = require('http');
|
|
3
3
|
const https = require('https');
|
|
4
|
-
const axiosRetry = require('axios-retry');
|
|
4
|
+
// const axiosRetry = require('axios-retry');
|
|
5
5
|
const qs = require('qs');
|
|
6
|
-
const httpAdapter = require('axios/lib/adapters/http');
|
|
6
|
+
// const httpAdapter = require('axios/lib/adapters/http');
|
|
7
7
|
const merge = require('deepmerge');
|
|
8
8
|
const { setup } = require('axios-cache-adapter');
|
|
9
|
-
const Agent = require('agentkeepalive');
|
|
10
|
-
const HttpsAgent = require('agentkeepalive').HttpsAgent;
|
|
9
|
+
// const Agent = require('agentkeepalive');
|
|
10
|
+
// const HttpsAgent = require('agentkeepalive').HttpsAgent;
|
|
11
11
|
|
|
12
12
|
require('dotenv').config();
|
|
13
13
|
/**
|
|
@@ -43,27 +43,27 @@ const defaultSettings = {
|
|
|
43
43
|
module.exports = class Network {
|
|
44
44
|
constructor(settings = {}) {
|
|
45
45
|
this.settings = merge(defaultSettings, settings);
|
|
46
|
-
if (this.settings.keepAlive) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
46
|
+
// if (this.settings.keepAlive) {
|
|
47
|
+
// const keepaliveAgent = new Agent();
|
|
48
|
+
// const keepaliveHttpsAgent = new HttpsAgent();
|
|
49
|
+
// this.settings.httpAgent = keepaliveAgent;
|
|
50
|
+
// this.settings.httpsAgent = keepaliveHttpsAgent;
|
|
51
|
+
// delete this.settings.keepAlive;
|
|
52
|
+
// }
|
|
53
53
|
this.createBaseUrl();
|
|
54
54
|
|
|
55
|
-
if(settings.cache) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
55
|
+
// if(settings.cache) {
|
|
56
|
+
// this.settings.cache = {
|
|
57
|
+
// maxAge: 15 * 60 * 1000,
|
|
58
|
+
// exclude: {
|
|
59
|
+
// // Store responses from requests with query parameters in cache
|
|
60
|
+
// query: false
|
|
61
|
+
// },
|
|
62
|
+
// ...settings.cache,
|
|
63
|
+
// }
|
|
64
|
+
// }
|
|
65
65
|
|
|
66
|
-
this.axios = axios.create(this.settings);
|
|
66
|
+
// this.axios = axios.create(this.settings);
|
|
67
67
|
// this.addRetry(settings);
|
|
68
68
|
this.buildClassHttpMethods();
|
|
69
69
|
// this.addLogs();
|
|
@@ -99,7 +99,20 @@ module.exports = class Network {
|
|
|
99
99
|
*/
|
|
100
100
|
buildClassHttpMethods() {
|
|
101
101
|
HTTPMethods.forEach((method) => {
|
|
102
|
-
this[method] = (...args) =>
|
|
102
|
+
this[method] = async (...args) => {
|
|
103
|
+
const {
|
|
104
|
+
statusCode,
|
|
105
|
+
headers,
|
|
106
|
+
trailers,
|
|
107
|
+
body
|
|
108
|
+
} = await request(`${settings.baseURL}${args[0]}`, {
|
|
109
|
+
body: args[1]
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
data: await body.json(),
|
|
114
|
+
}
|
|
115
|
+
}
|
|
103
116
|
});
|
|
104
117
|
}
|
|
105
118
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/network",
|
|
3
|
-
"version": "1.2.9-alpha-
|
|
3
|
+
"version": "1.2.9-alpha-6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"axios-retry": "^3.1.1",
|
|
19
19
|
"deepmerge": "^3.0.0",
|
|
20
20
|
"dotenv": "^6.0.0",
|
|
21
|
-
"qs": "^6.5.2"
|
|
21
|
+
"qs": "^6.5.2",
|
|
22
|
+
"undici": "^4.4.4"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"jest": "22.4.3",
|