@autofleet/network 1.2.9-alpha-6 → 1.2.9-alpha-7

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.
Files changed (2) hide show
  1. package/index.js +26 -39
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,13 +1,13 @@
1
- const undici = require('undici');
1
+ const axios = require('axios');
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,30 +43,30 @@ 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
- // 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
- // }
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
- // 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
- // }
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);
67
- // this.addRetry(settings);
66
+ this.axios = axios.create(this.settings);
67
+ this.addRetry(settings);
68
68
  this.buildClassHttpMethods();
69
- // this.addLogs();
69
+ this.addLogs();
70
70
  }
71
71
 
72
72
  addRetry(settings) {
@@ -99,20 +99,7 @@ module.exports = class Network {
99
99
  */
100
100
  buildClassHttpMethods() {
101
101
  HTTPMethods.forEach((method) => {
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
- }
102
+ this[method] = (...args) => this.axios[method](...args);
116
103
  });
117
104
  }
118
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/network",
3
- "version": "1.2.9-alpha-6",
3
+ "version": "1.2.9-alpha-7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "undici": "^4.4.4"
23
23
  },
24
24
  "devDependencies": {
25
- "jest": "22.4.3",
25
+ "jest": "^27.0.6",
26
26
  "nock": "^10.0.0"
27
27
  }
28
28
  }