unprint 0.13.2 → 0.14.0

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.2",
3
+ "version": "0.14.0",
4
4
  "description": "Simplify common web scraping tasks while staying in control of the data.",
5
5
  "main": "src/app.js",
6
6
  "scripts": {
@@ -28,6 +28,7 @@
28
28
  "eslint": "^8.17.0",
29
29
  "eslint-config-airbnb": "^19.0.4",
30
30
  "eslint-config-airbnb-base": "^15.0.0",
31
+ "https-proxy-agent": "^7.0.5",
31
32
  "jsdom": "^17.0.0",
32
33
  "moment-timezone": "^0.5.34"
33
34
  },
package/src/app.js CHANGED
@@ -5,6 +5,7 @@ const EventEmitter = require('events');
5
5
  const http = require('http');
6
6
  const https = require('https');
7
7
  const axios = require('axios').default;
8
+ const { HttpsProxyAgent } = require('https-proxy-agent');
8
9
  const Bottleneck = require('bottleneck');
9
10
  const moment = require('moment-timezone');
10
11
  const merge = require('deepmerge');
@@ -803,7 +804,6 @@ function initQueryFns(fns, context) {
803
804
  events.emit('query', {
804
805
  key,
805
806
  args,
806
- origin: context.options.origin,
807
807
  });
808
808
 
809
809
  return fn(...args);
@@ -816,7 +816,6 @@ function initQueryFns(fns, context) {
816
816
  events.emit('query', {
817
817
  key,
818
818
  args,
819
- origin: context.options.origin,
820
819
  });
821
820
 
822
821
  return fn({
@@ -950,17 +949,31 @@ async function request(url, body, customOptions = {}, method = 'GET') {
950
949
 
951
950
  events.emit('requestInit', feedbackBase);
952
951
 
953
- const res = await limiter.schedule(async () => axios({
954
- url,
955
- method,
952
+ const instance = axios.create({
956
953
  data: body,
957
954
  validateStatus: null,
958
- ...options,
955
+ headers: options.headers,
959
956
  timeout: options.timeout,
960
957
  signal: options.abortSignal,
961
- httpAgent: options.httpAgent || new http.Agent({ ...options.agent }),
962
- httpsAgent: options.httpsAgent || new https.Agent({ ...options.agent }),
963
- }));
958
+ // ...options,
959
+ // httpAgent: options.httpAgent || new http.Agent({ ...options.agent }),
960
+ });
961
+
962
+ if (options.proxy) {
963
+ // instance.defaults.httpAgent = new HttpsProxyAgent(`http://${options.proxy.host}:${options.proxy.port}`, { ...options.agent });
964
+ instance.defaults.httpsAgent = options.httpsAgent || new HttpsProxyAgent(`http://${options.proxy.host}:${options.proxy.port}`, { ...options.agent });
965
+
966
+ instance.defaults.proxy = {
967
+ protocol: 'http',
968
+ host: options.proxy.host,
969
+ port: options.proxy.port,
970
+ };
971
+ } else {
972
+ instance.defaults.httpAgent = options.httpsAgent || new http.Agent({ ...options.agent });
973
+ instance.defaults.httpsAgent = options.httpsAgent || new https.Agent({ ...options.agent });
974
+ }
975
+
976
+ const res = await limiter.schedule(async () => instance.get(url));
964
977
 
965
978
  if (!(res.status >= 200 && res.status < 300)) {
966
979
  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));