@autofleet/network 1.2.9-alpha-4 → 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 -34
- 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,37 +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
|
-
|
|
53
|
-
const keepaliveHttpsAgent = new HttpsAgent({
|
|
54
|
-
maxSockets: 100,
|
|
55
|
-
maxFreeSockets: 10,
|
|
56
|
-
timeout: 60000, // active socket keepalive for 60 seconds
|
|
57
|
-
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
|
|
58
|
-
});
|
|
59
|
-
this.settings.httpAgent = keepaliveAgent;
|
|
60
|
-
this.settings.httpsAgent = keepaliveHttpsAgent;
|
|
61
|
-
delete this.settings.keepAlive;
|
|
62
|
-
}
|
|
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
|
+
// }
|
|
63
53
|
this.createBaseUrl();
|
|
64
54
|
|
|
65
|
-
if(settings.cache) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
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
|
+
// }
|
|
75
65
|
|
|
76
|
-
this.axios = axios.create(this.settings);
|
|
66
|
+
// this.axios = axios.create(this.settings);
|
|
77
67
|
// this.addRetry(settings);
|
|
78
68
|
this.buildClassHttpMethods();
|
|
79
69
|
// this.addLogs();
|
|
@@ -109,7 +99,20 @@ module.exports = class Network {
|
|
|
109
99
|
*/
|
|
110
100
|
buildClassHttpMethods() {
|
|
111
101
|
HTTPMethods.forEach((method) => {
|
|
112
|
-
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
|
+
}
|
|
113
116
|
});
|
|
114
117
|
}
|
|
115
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",
|