unprint 0.13.3 → 0.14.1

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/README.md CHANGED
@@ -207,6 +207,14 @@ Returns
207
207
  }
208
208
  ```
209
209
 
210
+ ### Proxy
211
+ ```javascript
212
+ unprint.get({ // or unprint.options();
213
+ host: '127.0.0.1',
214
+ port: 8888,
215
+ });
216
+ ```
217
+
210
218
  ### Feedback events
211
219
  Usage:
212
220
  * `unprint.on('trigger', callbackFn)`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unprint",
3
- "version": "0.13.3",
3
+ "version": "0.14.1",
4
4
  "description": "Simplify common web scraping tasks while staying in control of the data.",
5
5
  "main": "src/app.js",
6
6
  "scripts": {
@@ -29,7 +29,8 @@
29
29
  "eslint-config-airbnb": "^19.0.4",
30
30
  "eslint-config-airbnb-base": "^15.0.0",
31
31
  "jsdom": "^17.0.0",
32
- "moment-timezone": "^0.5.34"
32
+ "moment-timezone": "^0.5.34",
33
+ "tunnel": "^0.0.6"
33
34
  },
34
35
  "devDependencies": {
35
36
  "express": "^4.18.1"
package/src/app.js CHANGED
@@ -4,6 +4,7 @@ const { JSDOM, VirtualConsole } = require('jsdom');
4
4
  const EventEmitter = require('events');
5
5
  const http = require('http');
6
6
  const https = require('https');
7
+ const tunnel = require('tunnel');
7
8
  const axios = require('axios').default;
8
9
  const Bottleneck = require('bottleneck');
9
10
  const moment = require('moment-timezone');
@@ -948,17 +949,32 @@ async function request(url, body, customOptions = {}, method = 'GET') {
948
949
 
949
950
  events.emit('requestInit', feedbackBase);
950
951
 
951
- const res = await limiter.schedule(async () => axios({
952
- url,
953
- method,
952
+ const instance = axios.create({
954
953
  data: body,
955
954
  validateStatus: null,
956
- ...options,
955
+ headers: options.headers,
957
956
  timeout: options.timeout,
958
957
  signal: options.abortSignal,
959
- httpAgent: options.httpAgent || new http.Agent({ ...options.agent }),
960
- httpsAgent: options.httpsAgent || new https.Agent({ ...options.agent }),
961
- }));
958
+ // ...options,
959
+ // httpAgent: options.httpAgent || new http.Agent({ ...options.agent }),
960
+ });
961
+
962
+ if (options.proxy) {
963
+ const proxyAgent = tunnel.httpsOverHttp({
964
+ proxy: {
965
+ host: options.proxy.host,
966
+ port: options.proxy.port,
967
+ },
968
+ });
969
+
970
+ instance.defaults.httpAgent = proxyAgent;
971
+ instance.defaults.httpsAgent = proxyAgent;
972
+ } else {
973
+ instance.defaults.httpAgent = options.httpsAgent || new http.Agent({ ...options.agent });
974
+ instance.defaults.httpsAgent = options.httpsAgent || new https.Agent({ ...options.agent });
975
+ }
976
+
977
+ const res = await limiter.schedule(async () => instance.get(url));
962
978
 
963
979
  if (!(res.status >= 200 && res.status < 300)) {
964
980
  handleError(new Error(`HTTP response from ${url} not OK (${res.status} ${res.statusText}): ${res.data}`), 'HTTP_NOT_OK');
package/tests/init.js CHANGED
@@ -18,6 +18,12 @@ async function initTest() {
18
18
  interval: 100,
19
19
  },
20
20
  },
21
+ /*
22
+ proxy: {
23
+ host: '192.168.178.25',
24
+ port: 8888,
25
+ },
26
+ */
21
27
  });
22
28
 
23
29
  unprint.on('requestInit', (initData) => console.log('init', initData));