zenrows 1.2.2 → 1.3.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
@@ -86,6 +86,37 @@ You can also pass optional parameters and headers; the list above is a reference
86
86
 
87
87
  Sending headers to the target URL will overwrite our defaults. Be careful when doing it and contact us if there is any problem.
88
88
 
89
+ ### POST Requests
90
+
91
+ The SDK also offers POST requests by calling the `client.post` method. It can receive a new parameter `data` that represents the data sent in, for example, a form.
92
+
93
+ ```javascript
94
+ const { ZenRows } = require('zenrows', { retries: 1 });
95
+
96
+ const apiKey = 'YOUR-API-KEY';
97
+ const url = 'https://httpbin.org/anything';
98
+
99
+ (async () => {
100
+ const client = new ZenRows(apiKey);
101
+
102
+ const { data } = await client.post(url, {
103
+ // The same params as in GET requests
104
+ }, {
105
+ data: new URLSearchParams({
106
+ 'key1': 'value1',
107
+ 'key2': 'value2',
108
+ }).toString(),
109
+ });
110
+
111
+ console.log(data);
112
+ /*
113
+ ...
114
+ form: { key1: 'value1', key2: 'value2' },
115
+ ...
116
+ */
117
+ })();
118
+ ```
119
+
89
120
  ### Concurrency
90
121
 
91
122
  To limit the concurrency, it uses [fastq](https://github.com/mcollina/fastq), which will simultaneously send a maximum of requests. The concurrency is determined by the plan you are in, so take a look at the [pricing](https://www.zenrows.com/pricing) and set it accordingly. Take into account that each client instance will have its own limit, meaning that two different scripts will not share it, and 429 (Too Many Requests) errors might arise.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AxiosPromise } from 'axios';
1
+ import { AxiosPromise, Method } from 'axios';
2
2
  import * as fastq from 'fastq';
3
3
  interface ClientConfig {
4
4
  concurrency?: number;
@@ -28,13 +28,19 @@ declare class ZenRows {
28
28
  readonly clientConfig: ClientConfig;
29
29
  readonly queue: fastq.queueAsPromised<{
30
30
  url: string;
31
+ method?: Method | undefined;
31
32
  config?: Config | undefined;
32
33
  headers: Headers;
34
+ data?: any;
33
35
  }, import("axios").AxiosResponse<any>>;
34
36
  constructor(apiKey: string, clientConfig?: ClientConfig);
35
37
  get(url: string, config?: Config, { headers }?: {
36
38
  headers?: Headers;
37
39
  }): AxiosPromise;
40
+ post(url: string, config?: Config, { headers, data }?: {
41
+ headers?: Headers;
42
+ data?: any;
43
+ }): AxiosPromise;
38
44
  private worker;
39
45
  private applyRetries;
40
46
  }
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZenRows = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
5
  const axios_1 = require("axios");
5
6
  const axios_retry_1 = require("axios-retry");
6
7
  const fastq = require("fastq");
@@ -17,13 +18,18 @@ class ZenRows {
17
18
  get(url, config, { headers = {} } = {}) {
18
19
  return this.queue.push({ url, config, headers });
19
20
  }
20
- worker({ url, config, headers }) {
21
+ post(url, config, { headers = {}, data = {} } = {}) {
22
+ return this.queue.push({ url, method: 'POST', config, headers, data });
23
+ }
24
+ worker({ url, method = 'GET', config, headers, data }) {
21
25
  const params = Object.assign(Object.assign({}, config), { url, apikey: this.apiKey });
22
26
  const finalHeaders = Object.assign({ 'User-Agent': `zenrows/${version_1.VERSION} node` }, headers);
23
27
  const axiosRequestConfig = {
24
28
  baseURL: API_URL,
29
+ method,
25
30
  params,
26
31
  headers: finalHeaders,
32
+ data,
27
33
  };
28
34
  if (headers && Object.keys(headers).length) {
29
35
  params.custom_headers = true;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.2.2";
1
+ export declare const VERSION = "1.3.1";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '1.2.2';
4
+ exports.VERSION = '1.3.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenrows",
3
- "version": "1.2.2",
3
+ "version": "1.3.1",
4
4
  "description": "ZenRows Node SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",