apify-client 3.0.0-beta.107 → 3.0.0-beta.109
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/dist/bundle.js +8 -8
- package/dist/bundle.js.map +1 -1
- package/dist/http_clients/axios.d.ts +5 -3
- package/dist/http_clients/axios.js +16 -6
- package/dist/http_clients/base.d.ts +8 -2
- package/dist/http_clients/base.js +8 -2
- package/dist/resource_clients/actor_server.d.ts +4 -3
- package/package.json +10 -10
|
@@ -21,8 +21,9 @@ export interface AxiosHttpClientOptions extends HttpClientOptions {
|
|
|
21
21
|
*
|
|
22
22
|
* It inherits the request pipeline from {@link HttpClient} and adds the transport: in Node.js, keep-alive agents
|
|
23
23
|
* that honor the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables; in the browser, the XHR
|
|
24
|
-
* adapter of axios
|
|
25
|
-
* redirects, since the part of it already sent could
|
|
24
|
+
* adapter of axios, or its fetch adapter for a request that must not follow redirects. Network errors are retried,
|
|
25
|
+
* timeouts included, and a stream body is sent without following redirects, since the part of it already sent could
|
|
26
|
+
* not be replayed.
|
|
26
27
|
*/
|
|
27
28
|
export declare class AxiosHttpClient extends HttpClient {
|
|
28
29
|
#private;
|
|
@@ -55,7 +56,8 @@ export declare class AxiosHttpClient extends HttpClient {
|
|
|
55
56
|
/**
|
|
56
57
|
* Sends the request through axios and hands the raw response back. A stream body is sent without following
|
|
57
58
|
* redirects, since the part of it already sent could not be replayed, and so is a request with
|
|
58
|
-
* `followRedirects: false`.
|
|
59
|
+
* `followRedirects: false`. Outside Node.js, such a request goes through `fetch`, since the browser follows the
|
|
60
|
+
* redirects of an XHR itself, and a redirect response fails the request: `fetch` hides it from the page.
|
|
59
61
|
*/
|
|
60
62
|
sendRequest(request: HttpRequest): Promise<HttpResponse>;
|
|
61
63
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import axios, { AxiosError, AxiosHeaders } from 'axios';
|
|
2
2
|
import { runtime } from '#runtime';
|
|
3
|
+
import { ApifyClientError } from '../apify_client_error.js';
|
|
3
4
|
import { isStream } from '../utils.js';
|
|
4
5
|
import { HttpClient } from './base.js';
|
|
5
6
|
/**
|
|
@@ -7,8 +8,9 @@ import { HttpClient } from './base.js';
|
|
|
7
8
|
*
|
|
8
9
|
* It inherits the request pipeline from {@link HttpClient} and adds the transport: in Node.js, keep-alive agents
|
|
9
10
|
* that honor the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables; in the browser, the XHR
|
|
10
|
-
* adapter of axios
|
|
11
|
-
* redirects, since the part of it already sent could
|
|
11
|
+
* adapter of axios, or its fetch adapter for a request that must not follow redirects. Network errors are retried,
|
|
12
|
+
* timeouts included, and a stream body is sent without following redirects, since the part of it already sent could
|
|
13
|
+
* not be replayed.
|
|
12
14
|
*/
|
|
13
15
|
export class AxiosHttpClient extends HttpClient {
|
|
14
16
|
/** The axios instance the requests go through. */
|
|
@@ -79,24 +81,32 @@ export class AxiosHttpClient extends HttpClient {
|
|
|
79
81
|
/**
|
|
80
82
|
* Sends the request through axios and hands the raw response back. A stream body is sent without following
|
|
81
83
|
* redirects, since the part of it already sent could not be replayed, and so is a request with
|
|
82
|
-
* `followRedirects: false`.
|
|
84
|
+
* `followRedirects: false`. Outside Node.js, such a request goes through `fetch`, since the browser follows the
|
|
85
|
+
* redirects of an XHR itself, and a redirect response fails the request: `fetch` hides it from the page.
|
|
83
86
|
*/
|
|
84
87
|
async sendRequest(request) {
|
|
85
88
|
await this.#ensureHttpAgents();
|
|
86
89
|
const { method, url, headers, body, timeoutMillis, stream, followRedirects, signal } = request;
|
|
90
|
+
const useFetch = !followRedirects && !runtime.isNode;
|
|
87
91
|
const response = await this.axios.request({
|
|
88
92
|
method,
|
|
89
93
|
url,
|
|
90
|
-
|
|
94
|
+
// The fetch adapter adds a `User-Agent` of its own otherwise, which a browser lists in the CORS preflight.
|
|
95
|
+
headers: useFetch ? { 'User-Agent': null, ...headers } : headers,
|
|
91
96
|
data: body,
|
|
92
97
|
// Axios reads 0 as no timeout.
|
|
93
98
|
timeout: timeoutMillis ?? 0,
|
|
94
99
|
signal,
|
|
95
100
|
responseType: stream ? 'stream' : 'arraybuffer',
|
|
96
|
-
// See axios/axios#1045 for why axios must not buffer a stream body to follow redirects. The
|
|
97
|
-
//
|
|
101
|
+
// See axios/axios#1045 for why axios must not buffer a stream body to follow redirects. The fetch
|
|
102
|
+
// adapter turns this into `redirect: 'manual'`.
|
|
98
103
|
...(isStream(body) || !followRedirects ? { maxRedirects: 0 } : {}),
|
|
104
|
+
...(useFetch ? { adapter: 'fetch' } : {}),
|
|
99
105
|
});
|
|
106
|
+
// `redirect: 'manual'` resolves to an opaque response with status 0 instead of the redirect.
|
|
107
|
+
if (useFetch && response.status === 0) {
|
|
108
|
+
throw new ApifyClientError(`${method} ${url} responded with a redirect, which the client does not follow.`);
|
|
109
|
+
}
|
|
100
110
|
return {
|
|
101
111
|
status: response.status,
|
|
102
112
|
headers: AxiosHeaders.from(response.headers).toJSON(),
|
|
@@ -244,10 +244,16 @@ export interface HttpClientOptions {
|
|
|
244
244
|
* import { ApifyClient, HttpClient } from 'apify-client';
|
|
245
245
|
*
|
|
246
246
|
* class FetchHttpClient extends HttpClient {
|
|
247
|
-
* async sendRequest({ method, url, headers, body, timeoutMillis, signal }) {
|
|
247
|
+
* async sendRequest({ method, url, headers, body, timeoutMillis, followRedirects, signal }) {
|
|
248
248
|
* const signals = signal ? [signal] : [];
|
|
249
249
|
* if (timeoutMillis !== undefined) signals.push(AbortSignal.timeout(timeoutMillis));
|
|
250
|
-
* const response = await fetch(url, {
|
|
250
|
+
* const response = await fetch(url, {
|
|
251
|
+
* method,
|
|
252
|
+
* headers,
|
|
253
|
+
* body,
|
|
254
|
+
* redirect: followRedirects ? 'follow' : 'manual',
|
|
255
|
+
* signal: AbortSignal.any(signals),
|
|
256
|
+
* });
|
|
251
257
|
* return {
|
|
252
258
|
* status: response.status,
|
|
253
259
|
* headers: Object.fromEntries(response.headers),
|
|
@@ -55,10 +55,16 @@ const UNSERIALIZABLE_OBJECT_TAGS = new Set(['FormData', 'ReadableStream']);
|
|
|
55
55
|
* import { ApifyClient, HttpClient } from 'apify-client';
|
|
56
56
|
*
|
|
57
57
|
* class FetchHttpClient extends HttpClient {
|
|
58
|
-
* async sendRequest({ method, url, headers, body, timeoutMillis, signal }) {
|
|
58
|
+
* async sendRequest({ method, url, headers, body, timeoutMillis, followRedirects, signal }) {
|
|
59
59
|
* const signals = signal ? [signal] : [];
|
|
60
60
|
* if (timeoutMillis !== undefined) signals.push(AbortSignal.timeout(timeoutMillis));
|
|
61
|
-
* const response = await fetch(url, {
|
|
61
|
+
* const response = await fetch(url, {
|
|
62
|
+
* method,
|
|
63
|
+
* headers,
|
|
64
|
+
* body,
|
|
65
|
+
* redirect: followRedirects ? 'follow' : 'manual',
|
|
66
|
+
* signal: AbortSignal.any(signals),
|
|
67
|
+
* });
|
|
62
68
|
* return {
|
|
63
69
|
* status: response.status,
|
|
64
70
|
* headers: Object.fromEntries(response.headers),
|
|
@@ -71,9 +71,10 @@ export declare class ActorServerClient extends ResourceClient {
|
|
|
71
71
|
* The method resolves to any response of the server, error statuses included. A rate-limit (429) or Service
|
|
72
72
|
* Unavailable (503) response is retried with the client's retry settings, and the last one is returned once the
|
|
73
73
|
* retries run out. The Actor's code can return these statuses too, and then it gets the request again. A redirect
|
|
74
|
-
* is returned as it is, since following it would send the token to a host the Actor's code picked.
|
|
75
|
-
*
|
|
76
|
-
* unless `compression` is set, since the Actor's server may not decode a
|
|
74
|
+
* is returned as it is, since following it would send the token to a host the Actor's code picked. In a
|
|
75
|
+
* browser the redirect response can't be read, so the request fails with an {@link ApifyClientError} instead.
|
|
76
|
+
* Request bodies are sent uncompressed unless `compression` is set, since the Actor's server may not decode a
|
|
77
|
+
* compressed body.
|
|
77
78
|
*
|
|
78
79
|
* @template T - Type of the parsed response body.
|
|
79
80
|
* @param path - The path on the Actor's server, for example `/search`. It is always resolved against the server
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apify-client",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.109",
|
|
4
4
|
"description": "Apify API client for JavaScript",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.15.0"
|
|
@@ -70,19 +70,19 @@
|
|
|
70
70
|
"ansi-colors": "^4.1.3",
|
|
71
71
|
"axios": "^1.21.1",
|
|
72
72
|
"content-type": "^3.1.1",
|
|
73
|
-
"proxy-agent": "^8.0.
|
|
73
|
+
"proxy-agent": "^8.0.3",
|
|
74
74
|
"tslib": "^2.9.1",
|
|
75
75
|
"type-fest": "^5.10.0",
|
|
76
76
|
"zod": "^4.6.7"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@apify/oxlint-config": "^0.4.
|
|
79
|
+
"@apify/oxlint-config": "^0.4.1",
|
|
80
80
|
"@apify/tsconfig": "^0.2.0",
|
|
81
81
|
"@crawlee/puppeteer": "4.0.0-rc.2",
|
|
82
|
-
"@rsbuild/core": "^2.3.
|
|
82
|
+
"@rsbuild/core": "^2.3.3",
|
|
83
83
|
"@rsbuild/plugin-node-polyfill": "^1.4.6",
|
|
84
|
-
"@rspack/cli": "^2.3.
|
|
85
|
-
"@rspack/core": "^2.3.
|
|
84
|
+
"@rspack/cli": "^2.3.3",
|
|
85
|
+
"@rspack/core": "^2.3.3",
|
|
86
86
|
"@types/compression": "^1.8.1",
|
|
87
87
|
"@types/express": "^5.0.6",
|
|
88
88
|
"@types/node": "^26.6.6",
|
|
@@ -94,13 +94,13 @@
|
|
|
94
94
|
"oxfmt": "0.79.0",
|
|
95
95
|
"oxlint": "1.93.0",
|
|
96
96
|
"oxlint-tsgolint": "7.0.2007",
|
|
97
|
-
"puppeteer": "^25.
|
|
97
|
+
"puppeteer": "^25.18.1",
|
|
98
98
|
"rimraf": "^6.1.4",
|
|
99
|
-
"rolldown": "^1.
|
|
99
|
+
"rolldown": "^1.3.3",
|
|
100
100
|
"typescript": "^7.0.2",
|
|
101
101
|
"typescript-v6": "npm:typescript@^6.0.3",
|
|
102
|
-
"vitest": "^5.1.
|
|
103
|
-
"webpack": "^5.
|
|
102
|
+
"vitest": "^5.1.1",
|
|
103
|
+
"webpack": "^5.113.0",
|
|
104
104
|
"webpack-cli": "^7.3.1"
|
|
105
105
|
},
|
|
106
106
|
"devEngines": {
|