zenrows 2.0.0 → 2.0.2

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.
@@ -0,0 +1,20 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ check:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: pnpm/action-setup@v4
14
+ - uses: actions/setup-node@v4
15
+ with:
16
+ node-version: 20
17
+ cache: pnpm
18
+ - run: pnpm install --frozen-lockfile
19
+ - run: pnpm check
20
+ - run: pnpm test -- --run
@@ -0,0 +1,38 @@
1
+ name: Release
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: pnpm/action-setup@v4
18
+ - uses: actions/setup-node@v4
19
+ with:
20
+ node-version: 24
21
+ registry-url: https://registry.npmjs.org
22
+ cache: pnpm
23
+ - run: pnpm install --frozen-lockfile
24
+ - name: Verify tag matches package.json version
25
+ if: github.event_name == 'release'
26
+ run: |
27
+ TAG="${GITHUB_REF_NAME#v}"
28
+ PKG=$(node -p "require('./package.json').version")
29
+ if [ "$TAG" != "$PKG" ]; then
30
+ echo "tag $GITHUB_REF_NAME ($TAG) does not match package.json version $PKG"
31
+ exit 1
32
+ fi
33
+ - run: pnpm check
34
+ - run: pnpm test -- --run
35
+ - run: pnpm build
36
+ - run: npm publish --provenance --access public
37
+ env:
38
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/dist/index.cjs CHANGED
@@ -28,18 +28,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  ZenRows: () => ZenRows
34
34
  });
35
- module.exports = __toCommonJS(src_exports);
35
+ module.exports = __toCommonJS(index_exports);
36
36
  var import_fastq = __toESM(require("fastq"), 1);
37
37
  var import_fetch_retry = __toESM(require("fetch-retry"), 1);
38
38
 
39
39
  // package.json
40
40
  var package_default = {
41
41
  name: "zenrows",
42
- version: "1.3.2",
42
+ version: "2.0.2",
43
43
  description: "ZenRows Node SDK",
44
44
  main: "./dist/index.cjs",
45
45
  module: "./dist/index.js",
@@ -57,7 +57,9 @@ var package_default = {
57
57
  },
58
58
  scripts: {
59
59
  build: "tsup src/index.ts --dts --format cjs,esm --clean",
60
- test: "vitest"
60
+ test: "vitest",
61
+ format: "biome format --write .",
62
+ check: "biome check ."
61
63
  },
62
64
  keywords: ["sdk", "zenrows", "scraping"],
63
65
  author: "ZenRows",
@@ -71,15 +73,15 @@ var package_default = {
71
73
  license: "MIT",
72
74
  devDependencies: {
73
75
  "@biomejs/biome": "1.8.1",
74
- "@types/async-retry": "^1.4.8",
75
- "@types/node": "^20.14.2",
76
- msw: "^2.3.1",
77
- tsup: "^8.1.0",
78
- typescript: "^5.4.5",
79
- vitest: "^1.6.0"
76
+ "@types/async-retry": "^1.4.9",
77
+ "@types/node": "^20.19.39",
78
+ msw: "^2.13.4",
79
+ tsup: "^8.5.1",
80
+ typescript: "^5.9.3",
81
+ vitest: "^1.6.1"
80
82
  },
81
83
  dependencies: {
82
- fastq: "^1.17.1",
84
+ fastq: "^1.20.1",
83
85
  "fetch-retry": "^6.0.0"
84
86
  }
85
87
  };
@@ -95,16 +97,12 @@ var ZenRows = class {
95
97
  this.apiKey = apiKey;
96
98
  this.clientConfig = clientConfig;
97
99
  const retries = this.clientConfig.retries ?? 0;
98
- this.queue = import_fastq.default.promise(
99
- this,
100
- this.worker,
101
- this.clientConfig.concurrency ?? 5
102
- );
100
+ this.queue = import_fastq.default.promise(this, this.worker, this.clientConfig.concurrency ?? 5);
103
101
  this.fetchWithRetry = (0, import_fetch_retry.default)(fetch, {
104
102
  retryDelay: (attempt) => 2 ** attempt * 1e3,
105
103
  // retryOn: [422, 503, 504],
106
104
  retryOn: (attempt, error, response) => {
107
- if (attempt > retries) {
105
+ if (attempt >= retries) {
108
106
  return false;
109
107
  }
110
108
  if (error !== null || response?.status === 422 || response?.status === 503 || response?.status === 504) {
@@ -120,13 +118,27 @@ var ZenRows = class {
120
118
  post(url, config, { headers = {}, data = {} } = {
121
119
  headers: { "Content-Type": "application/x-www-form-urlencoded" }
122
120
  }) {
121
+ const normalizedHeaders = Object.keys(headers).reduce(
122
+ (acc, key) => {
123
+ const value = headers[key];
124
+ if (value !== void 0) {
125
+ if (key.toLowerCase() === "content-type") {
126
+ acc["Content-Type"] = value;
127
+ } else {
128
+ acc[key] = value;
129
+ }
130
+ }
131
+ return acc;
132
+ },
133
+ {}
134
+ );
123
135
  return this.queue.push({
124
136
  url,
125
137
  method: "POST",
126
138
  config,
127
139
  headers: {
128
140
  "Content-Type": "application/x-www-form-urlencoded",
129
- ...headers
141
+ ...normalizedHeaders
130
142
  },
131
143
  data
132
144
  });
@@ -167,10 +179,7 @@ var ZenRows = class {
167
179
  fetchOptions.body = String(data);
168
180
  }
169
181
  }
170
- const response = await this.fetchWithRetry(
171
- `${API_URL}?${params.toString()}`,
172
- fetchOptions
173
- );
182
+ const response = await this.fetchWithRetry(`${API_URL}?${params.toString()}`, fetchOptions);
174
183
  return response;
175
184
  }
176
185
  };
package/dist/index.d.cts CHANGED
@@ -30,8 +30,8 @@ declare class ZenRows {
30
30
  readonly clientConfig: ClientConfig;
31
31
  readonly queue: fastq.queueAsPromised<{
32
32
  url: string;
33
- method?: HttpMethods | undefined;
34
- config?: ZenRowsConfig | undefined;
33
+ method?: HttpMethods;
34
+ config?: ZenRowsConfig;
35
35
  headers: Headers;
36
36
  data?: unknown;
37
37
  }, Response>;
package/dist/index.d.ts CHANGED
@@ -30,8 +30,8 @@ declare class ZenRows {
30
30
  readonly clientConfig: ClientConfig;
31
31
  readonly queue: fastq.queueAsPromised<{
32
32
  url: string;
33
- method?: HttpMethods | undefined;
34
- config?: ZenRowsConfig | undefined;
33
+ method?: HttpMethods;
34
+ config?: ZenRowsConfig;
35
35
  headers: Headers;
36
36
  data?: unknown;
37
37
  }, Response>;
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import fetchRetry from "fetch-retry";
5
5
  // package.json
6
6
  var package_default = {
7
7
  name: "zenrows",
8
- version: "1.3.2",
8
+ version: "2.0.2",
9
9
  description: "ZenRows Node SDK",
10
10
  main: "./dist/index.cjs",
11
11
  module: "./dist/index.js",
@@ -23,7 +23,9 @@ var package_default = {
23
23
  },
24
24
  scripts: {
25
25
  build: "tsup src/index.ts --dts --format cjs,esm --clean",
26
- test: "vitest"
26
+ test: "vitest",
27
+ format: "biome format --write .",
28
+ check: "biome check ."
27
29
  },
28
30
  keywords: ["sdk", "zenrows", "scraping"],
29
31
  author: "ZenRows",
@@ -37,15 +39,15 @@ var package_default = {
37
39
  license: "MIT",
38
40
  devDependencies: {
39
41
  "@biomejs/biome": "1.8.1",
40
- "@types/async-retry": "^1.4.8",
41
- "@types/node": "^20.14.2",
42
- msw: "^2.3.1",
43
- tsup: "^8.1.0",
44
- typescript: "^5.4.5",
45
- vitest: "^1.6.0"
42
+ "@types/async-retry": "^1.4.9",
43
+ "@types/node": "^20.19.39",
44
+ msw: "^2.13.4",
45
+ tsup: "^8.5.1",
46
+ typescript: "^5.9.3",
47
+ vitest: "^1.6.1"
46
48
  },
47
49
  dependencies: {
48
- fastq: "^1.17.1",
50
+ fastq: "^1.20.1",
49
51
  "fetch-retry": "^6.0.0"
50
52
  }
51
53
  };
@@ -61,16 +63,12 @@ var ZenRows = class {
61
63
  this.apiKey = apiKey;
62
64
  this.clientConfig = clientConfig;
63
65
  const retries = this.clientConfig.retries ?? 0;
64
- this.queue = fastq.promise(
65
- this,
66
- this.worker,
67
- this.clientConfig.concurrency ?? 5
68
- );
66
+ this.queue = fastq.promise(this, this.worker, this.clientConfig.concurrency ?? 5);
69
67
  this.fetchWithRetry = fetchRetry(fetch, {
70
68
  retryDelay: (attempt) => 2 ** attempt * 1e3,
71
69
  // retryOn: [422, 503, 504],
72
70
  retryOn: (attempt, error, response) => {
73
- if (attempt > retries) {
71
+ if (attempt >= retries) {
74
72
  return false;
75
73
  }
76
74
  if (error !== null || response?.status === 422 || response?.status === 503 || response?.status === 504) {
@@ -86,13 +84,27 @@ var ZenRows = class {
86
84
  post(url, config, { headers = {}, data = {} } = {
87
85
  headers: { "Content-Type": "application/x-www-form-urlencoded" }
88
86
  }) {
87
+ const normalizedHeaders = Object.keys(headers).reduce(
88
+ (acc, key) => {
89
+ const value = headers[key];
90
+ if (value !== void 0) {
91
+ if (key.toLowerCase() === "content-type") {
92
+ acc["Content-Type"] = value;
93
+ } else {
94
+ acc[key] = value;
95
+ }
96
+ }
97
+ return acc;
98
+ },
99
+ {}
100
+ );
89
101
  return this.queue.push({
90
102
  url,
91
103
  method: "POST",
92
104
  config,
93
105
  headers: {
94
106
  "Content-Type": "application/x-www-form-urlencoded",
95
- ...headers
107
+ ...normalizedHeaders
96
108
  },
97
109
  data
98
110
  });
@@ -133,10 +145,7 @@ var ZenRows = class {
133
145
  fetchOptions.body = String(data);
134
146
  }
135
147
  }
136
- const response = await this.fetchWithRetry(
137
- `${API_URL}?${params.toString()}`,
138
- fetchOptions
139
- );
148
+ const response = await this.fetchWithRetry(`${API_URL}?${params.toString()}`, fetchOptions);
140
149
  return response;
141
150
  }
142
151
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zenrows",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "ZenRows Node SDK",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -18,7 +18,9 @@
18
18
  },
19
19
  "scripts": {
20
20
  "build": "tsup src/index.ts --dts --format cjs,esm --clean",
21
- "test": "vitest"
21
+ "test": "vitest",
22
+ "format": "biome format --write .",
23
+ "check": "biome check ."
22
24
  },
23
25
  "keywords": ["sdk", "zenrows", "scraping"],
24
26
  "author": "ZenRows",
@@ -32,15 +34,15 @@
32
34
  "license": "MIT",
33
35
  "devDependencies": {
34
36
  "@biomejs/biome": "1.8.1",
35
- "@types/async-retry": "^1.4.8",
36
- "@types/node": "^20.14.2",
37
- "msw": "^2.3.1",
38
- "tsup": "^8.1.0",
39
- "typescript": "^5.4.5",
40
- "vitest": "^1.6.0"
37
+ "@types/async-retry": "^1.4.9",
38
+ "@types/node": "^20.19.39",
39
+ "msw": "^2.13.4",
40
+ "tsup": "^8.5.1",
41
+ "typescript": "^5.9.3",
42
+ "vitest": "^1.6.1"
41
43
  },
42
44
  "dependencies": {
43
- "fastq": "^1.17.1",
45
+ "fastq": "^1.20.1",
44
46
  "fetch-retry": "^6.0.0"
45
47
  }
46
48
  }