apify-client 3.0.0-rc.1 → 3.0.0-rc.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.
Files changed (46) hide show
  1. package/README.md +4 -2
  2. package/dist/apify_api_error.d.ts +2 -2
  3. package/dist/apify_client.d.ts +8 -8
  4. package/dist/apify_client.js +10 -10
  5. package/dist/axios.d.ts +2 -0
  6. package/dist/axios.js +1 -0
  7. package/dist/body_parser.d.ts +1 -1
  8. package/dist/bundle.js +31 -30
  9. package/dist/bundle.js.map +1 -1
  10. package/dist/generated/api.d.ts +124 -32
  11. package/dist/generated/schemas.d.ts +178 -58
  12. package/dist/generated/schemas.js +23 -6
  13. package/dist/http_clients/axios.d.ts +34 -15
  14. package/dist/http_clients/axios.js +79 -33
  15. package/dist/http_clients/base.d.ts +34 -23
  16. package/dist/http_clients/base.js +50 -20
  17. package/dist/http_clients/fetch.d.ts +53 -0
  18. package/dist/http_clients/fetch.js +219 -0
  19. package/dist/http_clients/index.d.ts +2 -2
  20. package/dist/http_clients/index.js +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/resource_clients/actor.d.ts +3 -2
  23. package/dist/resource_clients/actor.js +3 -3
  24. package/dist/resource_clients/actor_server.d.ts +11 -11
  25. package/dist/resource_clients/actor_server.js +0 -4
  26. package/dist/resource_clients/actor_version.d.ts +2 -1
  27. package/dist/resource_clients/actor_version.js +3 -2
  28. package/dist/resource_clients/actor_version_collection.d.ts +2 -1
  29. package/dist/resource_clients/actor_version_collection.js +3 -2
  30. package/dist/resource_clients/dataset.d.ts +14 -15
  31. package/dist/resource_clients/dataset.js +0 -4
  32. package/dist/resource_clients/key_value_store.d.ts +20 -19
  33. package/dist/resource_clients/key_value_store.js +10 -11
  34. package/dist/resource_clients/log.d.ts +10 -11
  35. package/dist/resource_clients/log.js +4 -3
  36. package/dist/resource_clients/run.d.ts +6 -2
  37. package/dist/resource_clients/run.js +6 -2
  38. package/dist/resource_clients/store_collection.d.ts +4 -0
  39. package/dist/resource_clients/task.js +3 -3
  40. package/dist/runtime/node.js +35 -11
  41. package/dist/runtime/types.d.ts +26 -4
  42. package/dist/runtime/web.js +39 -0
  43. package/dist/schemas.d.ts +4 -4
  44. package/dist/utils.d.ts +29 -1
  45. package/dist/utils.js +13 -0
  46. package/package.json +33 -21
@@ -5,7 +5,7 @@ import { ResourceClient } from '../base/resource_client.js';
5
5
  import * as schemas from '../schemas.js';
6
6
  import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
7
7
  import { runtime } from '#runtime';
8
- import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isBlob, isBuffer, isStream, minForLimitParam, parseArgument, parseResponse, } from '../utils.js';
8
+ import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isAnyStream, isBlob, isBuffer, minForLimitParam, parseArgument, parseResponse, } from '../utils.js';
9
9
  const listKeysOptionsSchema = z.strictObject({
10
10
  limit: z.number().min(0).optional(),
11
11
  chunkSize: z.number().positive().optional(),
@@ -320,9 +320,6 @@ export class KeyValueStoreClient extends ResourceClient {
320
320
  async getRecord(key, options = {}) {
321
321
  parseArgument(key, keySchema);
322
322
  const parsed = parseArgument(options, getRecordOptionsSchema, 'KeyValueClientGetRecordOptions');
323
- if (parsed.stream && !runtime.isNode) {
324
- throw new Error('The stream option can only be used in Node.js environment.');
325
- }
326
323
  if ('disableRedirect' in parsed) {
327
324
  log.deprecated('The disableRedirect option for getRecord() is deprecated. ' +
328
325
  'It has no effect and will be removed in the following major release.');
@@ -364,15 +361,17 @@ export class KeyValueStoreClient extends ResourceClient {
364
361
  * A string is sent as it is, even under `application/json`, so a string stored under a JSON content type has
365
362
  * to be valid JSON already, or {@link getRecord} fails to parse it back.
366
363
  *
367
- * **Note about streams:** If the value is a stream object (has `.pipe` and `.on` methods),
368
- * the upload cannot be retried on failure or follow redirects. For reliable uploads of a file,
369
- * pass a `Blob` from `fs.openAsBlob()` instead: it is read again for every attempt and never held
370
- * in memory whole.
364
+ * **Note about streams:** If the value is a stream, either a Node.js `Readable` or a web `ReadableStream`
365
+ * such as the `value` that {@link getRecord} returns with the `stream` option, the upload cannot be retried
366
+ * on failure or follow redirects. For reliable uploads of a file, pass a `Blob` from `fs.openAsBlob()`
367
+ * instead: it is read again for every attempt and never held in memory whole. A browser sends a web
368
+ * `ReadableStream` only over HTTP/2 or later, and only if it supports streaming request bodies at all:
369
+ * where it doesn't, the call throws a `TypeError`.
371
370
  *
372
371
  * @param record - The record to store
373
372
  * @param record.key - Record key (unique identifier)
374
- * @param record.value - Record value (a JSON-serializable value, Buffer, ArrayBuffer, typed array, Blob, or
375
- * Readable)
373
+ * @param record.value - Record value (a JSON-serializable value, Buffer, ArrayBuffer, typed array, Blob,
374
+ * Readable, or web ReadableStream)
376
375
  * @param record.contentType - Optional MIME type. Auto-detected if not provided:
377
376
  * - Objects: `'application/json; charset=utf-8'`
378
377
  * - Strings: `'text/plain; charset=utf-8'`
@@ -439,7 +438,7 @@ export class KeyValueStoreClient extends ResourceClient {
439
438
  if (contentEncoding !== undefined && !runtime.isNode) {
440
439
  throw new Error('The contentEncoding option can only be used in Node.js environment.');
441
440
  }
442
- const isBinaryValue = isStream(value) || isBuffer(value) || isBlob(value);
441
+ const isBinaryValue = isAnyStream(value) || isBuffer(value) || isBlob(value);
443
442
  // The client forwards the header without inspecting the body, so a string or a value serialized to JSON, which
444
443
  // cannot hold compressed bytes, would be stored under an encoding that misdescribes it.
445
444
  const declaresCompression = contentEncoding !== undefined && contentEncoding.trim().toLowerCase() !== 'identity';
@@ -1,4 +1,3 @@
1
- import type { Readable } from 'node:stream';
2
1
  import type { Log } from '@apify/log';
3
2
  import { Logger, LogLevel } from '@apify/log';
4
3
  import type { ApiClientSubResourceOptions } from '../base/api_client.js';
@@ -37,13 +36,13 @@ export declare class LogClient extends ResourceClient {
37
36
  /**
38
37
  * Retrieves the log as a string.
39
38
  *
40
- * The `buffer` option only selects the return type: the bytes come back as a Buffer (Node.js) or ArrayBuffer
41
- * (browser), not decoded to a string. Either way the whole log is downloaded in one response; to read it
42
- * incrementally, use {@link LogClient.stream}.
39
+ * The `buffer` option only selects the return type: the bytes come back as a Uint8Array, not decoded to a
40
+ * string. Either way the whole log is downloaded in one response; to read it incrementally, use
41
+ * {@link LogClient.stream}.
43
42
  *
44
43
  * @param options - Log retrieval options.
45
44
  * @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
46
- * @param options.buffer - If `true`, the log is returned as a Buffer (Node.js) or ArrayBuffer (browser) instead of a
45
+ * @param options.buffer - If `true`, the log is returned as a Uint8Array instead of a
47
46
  * string. It does not change how the log is fetched.
48
47
  * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
49
48
  * @returns The log content, or `undefined` if it does not exist. A chained client such as `run.log()` throws an
@@ -55,19 +54,19 @@ export declare class LogClient extends ResourceClient {
55
54
  }): Promise<string | undefined>;
56
55
  get(options: LogGetOptions & {
57
56
  buffer: true;
58
- }): Promise<Buffer | undefined>;
59
- get(options?: LogGetOptions): Promise<string | Buffer | undefined>;
57
+ }): Promise<Uint8Array | undefined>;
58
+ get(options?: LogGetOptions): Promise<string | Uint8Array | undefined>;
60
59
  /**
61
- * Retrieves the log as a Readable stream. Only works in Node.js.
60
+ * Retrieves the log as a web ReadableStream of Uint8Array chunks.
62
61
  *
63
62
  * @param options - Log retrieval options.
64
63
  * @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
65
64
  * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
66
- * @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
65
+ * @returns The log content as a web ReadableStream, or `undefined` if it does not exist. A chained client such as
67
66
  * `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
68
67
  * @see https://docs.apify.com/api/v2/log-get
69
68
  */
70
- stream(options?: LogOptions): Promise<Readable | undefined>;
69
+ stream(options?: LogOptions): Promise<ReadableStream<Uint8Array> | undefined>;
71
70
  }
72
71
  /**
73
72
  * @since Added in 2.20.0
@@ -81,7 +80,7 @@ export interface LogOptions extends TimeoutOptions {
81
80
  */
82
81
  export interface LogGetOptions extends LogOptions {
83
82
  /**
84
- * If `true`, the log is returned as a Buffer (Node.js) or ArrayBuffer (browser) instead of a string. It only selects
83
+ * If `true`, the log is returned as a Uint8Array instead of a string. It only selects
85
84
  * the return type; to read the log incrementally, use {@link LogClient.stream}.
86
85
  * @default false
87
86
  */
@@ -72,12 +72,12 @@ export class LogClient extends ResourceClient {
72
72
  return undefined;
73
73
  }
74
74
  /**
75
- * Retrieves the log as a Readable stream. Only works in Node.js.
75
+ * Retrieves the log as a web ReadableStream of Uint8Array chunks.
76
76
  *
77
77
  * @param options - Log retrieval options.
78
78
  * @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
79
79
  * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
80
- * @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
80
+ * @returns The log content as a web ReadableStream, or `undefined` if it does not exist. A chained client such as
81
81
  * `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
82
82
  * @see https://docs.apify.com/api/v2/log-get
83
83
  */
@@ -227,7 +227,8 @@ export class StreamedLog {
227
227
  }
228
228
  // A stream opened during stop() would be cut after its first chunk, so read the log in one request.
229
229
  if (this.#stopLogging) {
230
- logStream.destroy();
230
+ // Cancelling a stream that has already failed rejects with its error.
231
+ await logStream.cancel().catch(() => { });
231
232
  continue;
232
233
  }
233
234
  lastChunkRemainder = await this.#logStreamChunks(logStream, signal);
@@ -94,6 +94,9 @@ export declare class RunClient extends ResourceClient {
94
94
  * and resource allocation. The run effectively becomes a run of the target Actor with new input.
95
95
  * This is useful for chaining Actor executions or implementing complex workflows.
96
96
  *
97
+ * Only the run itself can metamorph: the client must use the run's own API token, which the run gets
98
+ * in the `APIFY_TOKEN` environment variable. With any other token, the API rejects the request.
99
+ *
97
100
  * @param targetActorId - ID or username/name of the target Actor
98
101
  * @param input - Input for the target Actor: an object or array serialized to JSON, or raw bytes sent as they
99
102
  * are. Omit it to metamorph without input.
@@ -105,8 +108,9 @@ export declare class RunClient extends ResourceClient {
105
108
  *
106
109
  * @example
107
110
  * ```javascript
108
- * // Transform current run into another Actor
109
- * const metamorphedRun = await client.run('original-run-id').metamorph(
111
+ * // Inside the run: transform it into another Actor
112
+ * const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
113
+ * const metamorphedRun = await client.run(process.env.ACTOR_RUN_ID).metamorph(
110
114
  * 'target-actor-id',
111
115
  * { url: 'https://example.com' }
112
116
  * );
@@ -153,6 +153,9 @@ export class RunClient extends ResourceClient {
153
153
  * and resource allocation. The run effectively becomes a run of the target Actor with new input.
154
154
  * This is useful for chaining Actor executions or implementing complex workflows.
155
155
  *
156
+ * Only the run itself can metamorph: the client must use the run's own API token, which the run gets
157
+ * in the `APIFY_TOKEN` environment variable. With any other token, the API rejects the request.
158
+ *
156
159
  * @param targetActorId - ID or username/name of the target Actor
157
160
  * @param input - Input for the target Actor: an object or array serialized to JSON, or raw bytes sent as they
158
161
  * are. Omit it to metamorph without input.
@@ -164,8 +167,9 @@ export class RunClient extends ResourceClient {
164
167
  *
165
168
  * @example
166
169
  * ```javascript
167
- * // Transform current run into another Actor
168
- * const metamorphedRun = await client.run('original-run-id').metamorph(
170
+ * // Inside the run: transform it into another Actor
171
+ * const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
172
+ * const metamorphedRun = await client.run(process.env.ACTOR_RUN_ID).metamorph(
169
173
  * 'target-actor-id',
170
174
  * { url: 'https://example.com' }
171
175
  * );
@@ -58,6 +58,10 @@ export declare class StoreCollectionClient extends ResourceCollectionClient {
58
58
  */
59
59
  export interface StoreCollectionListOptions extends PaginationOptions, TimeoutOptions {
60
60
  search?: string;
61
+ /**
62
+ * @deprecated The API ignores this option. Results are ordered by relevance when `search` is used, and by Store
63
+ * position otherwise. Sort the results on the client if you need a different order.
64
+ */
61
65
  sortBy?: string;
62
66
  category?: string;
63
67
  username?: string;
@@ -3,7 +3,7 @@ import { ACT_JOB_STATUSES, META_ORIGINS } from '@apify/consts';
3
3
  import { ResourceClient } from '../base/resource_client.js';
4
4
  import * as schemas from '../schemas.js';
5
5
  import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
6
- import { anyObjectSchema, cast, isStream, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
6
+ import { anyObjectSchema, cast, isAnyStream, parseArgument, parseResponse, stringifyWebhooksToBase64, } from '../utils.js';
7
7
  import { startWaitingForResources } from '../wait_for_resources.js';
8
8
  import { RunClient } from './run.js';
9
9
  import { RunCollectionClient } from './run_collection.js';
@@ -186,8 +186,8 @@ export class TaskClient extends ResourceClient {
186
186
  timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
187
187
  signal,
188
188
  };
189
- // A `Readable` input is consumed by the first attempt, so a retry would start the run with an empty input.
190
- const response = await startWaitingForResources(async () => this.httpClient.call(request), isStream(input) ? false : waitForResources, this.httpClient.logger, signal);
189
+ // A stream input is consumed by the first attempt, so a retry would start the run with an empty input.
190
+ const response = await startWaitingForResources(async () => this.httpClient.call(request), isAnyStream(input) ? false : waitForResources, this.httpClient.logger, signal);
191
191
  return parseResponse(response, schemas.Run());
192
192
  }
193
193
  /**
@@ -1,12 +1,16 @@
1
+ import http from 'node:http';
2
+ import https from 'node:https';
1
3
  import os from 'node:os';
2
4
  import { Readable } from 'node:stream';
3
5
  import { brotliCompress, constants, gzip, zstdCompress } from 'node:zlib';
6
+ const isBunOrDeno = Boolean(process.versions.bun || process.versions.deno);
4
7
  /**
5
8
  * The Node.js implementation of {@link Runtime}. Deno and Bun resolve the `node` condition too and
6
9
  * provide the built-ins it uses.
7
10
  */
8
11
  export const runtime = {
9
12
  isNode: true,
13
+ fetchFailsWithCause: !isBunOrDeno,
10
14
  platform: `${os.platform()}; Node/${process.version}`,
11
15
  async compress(data, { algorithm, quality }) {
12
16
  return new Promise((resolve, reject) => {
@@ -27,9 +31,6 @@ export const runtime = {
27
31
  });
28
32
  },
29
33
  async createHttpAgents({ timeoutMillis }) {
30
- // Loaded on the first request rather than with the client: the proxy support pulls in a sizeable
31
- // dependency tree that a client which never sends a request should not pay for.
32
- const { ProxyAgent } = await import('proxy-agent');
33
34
  // We want to keep sockets alive for better performance.
34
35
  const agentOptions = {
35
36
  keepAlive: true,
@@ -44,19 +45,42 @@ export const runtime = {
44
45
  maxFreeSockets: 256,
45
46
  // LIFO scheduling - reuse most recently used sockets for better performance
46
47
  scheduling: 'lifo',
48
+ // Disable Nagle's algorithm for lower latency. The agent hands the option to `net.createConnection()`.
49
+ noDelay: true,
47
50
  };
48
- // ProxyAgent picks the proxy up from the environment variables and supports CONNECT tunneling.
49
- const agent = new ProxyAgent(agentOptions);
50
- // Disable Nagle's algorithm for lower latency
51
- // This sends data immediately instead of buffering small packets
52
- agent.on('socket', (socket) => {
53
- socket.setNoDelay(true);
54
- });
55
- return { httpAgent: agent, httpsAgent: agent };
51
+ return { httpAgent: new http.Agent(agentOptions), httpsAgent: new https.Agent(agentOptions) };
52
+ },
53
+ streamToWeb(stream) {
54
+ return Readable.toWeb(stream);
55
+ },
56
+ unusedProxyHint() {
57
+ const names = ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy'].filter((name) => process.env[name]);
58
+ if (names.length === 0)
59
+ return undefined;
60
+ // The `fetch` of Bun and Deno reads these variables on its own.
61
+ if (isBunOrDeno)
62
+ return undefined;
63
+ const [major, minor] = process.versions.node.split('.').map(Number);
64
+ const supported = major >= 24 || (major === 22 && minor >= 21);
65
+ const flags = [...process.execArgv, ...(process.env.NODE_OPTIONS ?? '').split(/\s+/)];
66
+ const enabled = process.env.NODE_USE_ENV_PROXY === '1' || flags.includes('--use-env-proxy');
67
+ // An older Node.js ignores the switch, so the proxy stays unused there even with it set.
68
+ if (supported && enabled)
69
+ return undefined;
70
+ const fix = supported
71
+ ? 'Start Node.js with NODE_USE_ENV_PROXY=1 to send the requests through it.'
72
+ : `Node.js ${process.versions.node} cannot route fetch() through it: upgrade to Node.js 22.21 or 24, ` +
73
+ 'then start it with NODE_USE_ENV_PROXY=1.';
74
+ return (`The request failed, and the proxy set in ${names[0]} was not used, since fetch() in Node.js ignores the ` +
75
+ `proxy environment variables by default. ${fix} ` +
76
+ 'See https://docs.apify.com/api/client/js/docs/concepts/custom-http-clients#proxies for the other options.');
56
77
  },
57
78
  openBlobBody(blob, onSourceError) {
58
79
  return Readable.from(readBlob(blob, onSourceError), { objectMode: false });
59
80
  },
81
+ openStreamBody(stream) {
82
+ return Readable.fromWeb(stream);
83
+ },
60
84
  };
61
85
  /**
62
86
  * Yields the bytes of a blob. Ending the iteration early, which destroying the `Readable` around it does, cancels
@@ -12,7 +12,7 @@ export interface CompressionOptions {
12
12
  quality: number;
13
13
  }
14
14
  /**
15
- * The agents axios's Node.js adapter sends requests through.
15
+ * The agents the Node.js adapter of axios sends requests through.
16
16
  * @internal
17
17
  */
18
18
  export interface HttpAgents {
@@ -29,9 +29,14 @@ export interface Runtime {
29
29
  /**
30
30
  * Whether the Node.js implementation was selected, which the `node` condition settles when `#runtime` is
31
31
  * resolved - so a Node.js application bundled for a browser or a neutral target reports `false`. Log
32
- * streaming, the `stream` record option and request body compression are gated on it.
32
+ * redirection and request body compression are gated on it.
33
33
  */
34
34
  isNode: boolean;
35
+ /**
36
+ * Whether a failed `fetch` rejects with a `TypeError` that names the network error as its `cause`, which is
37
+ * what Node.js does. Bun and Deno resolve the `node` condition too, and their `fetch` does not.
38
+ */
39
+ fetchFailsWithCause: boolean;
35
40
  /**
36
41
  * The platform part of the `User-Agent` header, or `undefined` where the runtime does not let a client
37
42
  * set that header (browsers).
@@ -44,12 +49,22 @@ export interface Runtime {
44
49
  */
45
50
  compress(data: Uint8Array, options: CompressionOptions): Promise<Buffer>;
46
51
  /**
47
- * Creates the agents axios's Node.js adapter sends requests through, or resolves to `undefined` where
48
- * axios does not use agents.
52
+ * Creates the keep-alive agents the Node.js adapter of axios sends requests through, or resolves to `undefined`
53
+ * where axios does not use agents.
49
54
  */
50
55
  createHttpAgents(options: {
51
56
  timeoutMillis: number;
52
57
  }): Promise<HttpAgents | undefined>;
58
+ /**
59
+ * Turns the `Readable` a transport returned for a streamed response into the web stream the callers get.
60
+ * Throws where the runtime has no `Readable`, since no transport can return one there.
61
+ */
62
+ streamToWeb(stream: Readable): ReadableStream<Uint8Array>;
63
+ /**
64
+ * Explains how to make `fetch` use the proxy named in the environment variables, or returns `undefined` when
65
+ * none is set, the runtime already honors them, or it has no environment to read.
66
+ */
67
+ unusedProxyHint(): string | undefined;
53
68
  /**
54
69
  * Opens a `Blob` request body for one attempt. The Node.js implementation reads the blob into a `Readable` and
55
70
  * reports an error the blob raises while it is read to `onSourceError` before the stream fails with it, so the
@@ -57,4 +72,11 @@ export interface Runtime {
57
72
  * which `fetch` and `XMLHttpRequest` read on their own, and never calls `onSourceError`.
58
73
  */
59
74
  openBlobBody(blob: Blob, onSourceError: (error: unknown) => void): Readable | Blob;
75
+ /**
76
+ * Opens a web `ReadableStream` request body. The Node.js implementation wraps it in a `Readable`, the one
77
+ * stream type every Node.js transport sends. The Web API one returns the stream itself, and throws a
78
+ * `TypeError` where `fetch` cannot send a stream body: such a browser would send the text
79
+ * `[object ReadableStream]` instead.
80
+ */
81
+ openStreamBody(stream: ReadableStream<Uint8Array>): Readable | ReadableStream<Uint8Array>;
60
82
  }
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export const runtime = {
5
5
  isNode: false,
6
+ fetchFailsWithCause: false,
6
7
  // Browsers do not let a page set the `User-Agent` header.
7
8
  platform: undefined,
8
9
  // No request compression: brotli, gzip and zstd have no Web API, and a `content-encoding` request header is not
@@ -15,7 +16,45 @@ export const runtime = {
15
16
  async createHttpAgents() {
16
17
  return undefined;
17
18
  },
19
+ streamToWeb() {
20
+ throw new Error('A Readable stream is only available in Node.js.');
21
+ },
22
+ // A browser applies the proxy settings of the system on its own.
23
+ unusedProxyHint() {
24
+ return undefined;
25
+ },
18
26
  openBlobBody(blob) {
19
27
  return blob;
20
28
  },
29
+ openStreamBody(stream) {
30
+ if (!canSendStreamBody()) {
31
+ throw new TypeError('This runtime cannot send a ReadableStream as a request body. ' +
32
+ 'Read it into a Blob or bytes first, for example with `await new Response(stream).blob()`.');
33
+ }
34
+ return stream;
35
+ },
21
36
  };
37
+ /**
38
+ * Whether `fetch` sends a `ReadableStream` body as a stream. A runtime that does not, such as Firefox and Safari,
39
+ * never reads the `duplex` option and sends the stream converted to a string, under a text content type.
40
+ */
41
+ function canSendStreamBody() {
42
+ // Cloudflare Workers, Deno and Bun stream such a body too, without ever reading `duplex`.
43
+ if (/^(Cloudflare-Workers$|Deno\/|Bun\/)/.test(globalThis.navigator?.userAgent ?? ''))
44
+ return true;
45
+ let duplexRead = false;
46
+ try {
47
+ const request = new Request('https://api.apify.com', {
48
+ method: 'POST',
49
+ body: new ReadableStream(),
50
+ get duplex() {
51
+ duplexRead = true;
52
+ return 'half';
53
+ },
54
+ });
55
+ return duplexRead && !request.headers.has('content-type');
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
package/dist/schemas.d.ts CHANGED
@@ -311,13 +311,13 @@ export declare const Schedule: () => z.ZodObject<{
311
311
  actorTaskId: z.ZodString;
312
312
  input: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
313
313
  }, z.core.$loose>], "type">>;
314
- uiState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
314
+ uiState: z.ZodOptional<z.ZodNullable<z.ZodNullable<z.ZodObject<{
315
315
  version: z.ZodOptional<z.ZodInt>;
316
316
  data: z.ZodOptional<z.ZodObject<{
317
317
  cronExpression: z.ZodOptional<z.ZodString>;
318
318
  timezone: z.ZodOptional<z.ZodString>;
319
319
  }, z.core.$loose>>;
320
- }, z.core.$loose>>>;
320
+ }, z.core.$loose>>>>;
321
321
  }, z.core.$loose>;
322
322
  /** Response containing schedule data. */
323
323
  export declare const ScheduleResponse: () => z.ZodObject<{
@@ -370,12 +370,12 @@ export declare const ScheduleResponse: () => z.ZodObject<{
370
370
  actorTaskId: z.ZodString;
371
371
  input: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
372
372
  }, z.core.$loose>], "type">>;
373
- uiState: z.ZodOptional<z.ZodNullable<z.ZodObject<{
373
+ uiState: z.ZodOptional<z.ZodNullable<z.ZodNullable<z.ZodObject<{
374
374
  version: z.ZodOptional<z.ZodInt>;
375
375
  data: z.ZodOptional<z.ZodObject<{
376
376
  cronExpression: z.ZodOptional<z.ZodString>;
377
377
  timezone: z.ZodOptional<z.ZodString>;
378
378
  }, z.core.$loose>>;
379
- }, z.core.$loose>>>;
379
+ }, z.core.$loose>>>>;
380
380
  }, z.core.$loose>;
381
381
  }, z.core.$loose>;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import type { Readable } from 'node:stream';
2
- import type { TypedArray } from 'type-fest';
3
2
  import { z } from 'zod';
4
3
  import type { ApifyApiError } from './apify_api_error.js';
5
4
  import { parseArgument } from '@apify/validations';
@@ -106,7 +105,16 @@ export declare function isBuffer(value: unknown): value is Buffer | ArrayBuffer
106
105
  * request, so a request with a blob body can be retried.
107
106
  */
108
107
  export declare function isBlob(value: unknown): value is Blob;
108
+ /**
109
+ * Whether a value is a web `ReadableStream`, which is what the callers get for a streamed response and may pass
110
+ * on as a request body.
111
+ */
112
+ export declare function isWebStream(value: unknown): value is ReadableStream<Uint8Array>;
109
113
  export declare function isStream(value: unknown): value is Readable;
114
+ /**
115
+ * Whether a value is a stream of either kind, which a request can send only once.
116
+ */
117
+ export declare function isAnyStream(value: unknown): value is Readable | ReadableStream<Uint8Array>;
110
118
  /**
111
119
  * Helper class to create async iterators from paginated list endpoints.
112
120
  */
@@ -240,3 +248,23 @@ export declare function toPath(path: string | string[]): string;
240
248
  * @internal
241
249
  */
242
250
  export declare function sleep(millis: number, signal?: AbortSignal): Promise<void>;
251
+ /** Any string, written so that a union with string literals keeps suggesting the literals. */
252
+ export type AnyString = string & {};
253
+ /** Any valid JSON value. */
254
+ export type JsonValue = string | number | boolean | null | {
255
+ [Key in string]: JsonValue;
256
+ } | JsonValue[] | readonly JsonValue[];
257
+ /**
258
+ * Any JSON object.
259
+ * @internal
260
+ */
261
+ export type JsonObject = {
262
+ [Key in string]: JsonValue;
263
+ };
264
+ /**
265
+ * Any JSON array.
266
+ * @internal
267
+ */
268
+ export type JsonArray = JsonValue[] | readonly JsonValue[];
269
+ /** Any typed array, such as `Uint8Array` or `Float64Array`. */
270
+ export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
package/dist/utils.js CHANGED
@@ -246,12 +246,25 @@ export function isBlob(value) {
246
246
  function isTagged(value, tag) {
247
247
  return Object.prototype.toString.call(value) === `[object ${tag}]`;
248
248
  }
249
+ /**
250
+ * Whether a value is a web `ReadableStream`, which is what the callers get for a streamed response and may pass
251
+ * on as a request body.
252
+ */
253
+ export function isWebStream(value) {
254
+ return isTagged(value, 'ReadableStream');
255
+ }
249
256
  export function isStream(value) {
250
257
  if (value === null || typeof value !== 'object')
251
258
  return false;
252
259
  const { on, pipe } = value;
253
260
  return typeof on === 'function' && typeof pipe === 'function';
254
261
  }
262
+ /**
263
+ * Whether a value is a stream of either kind, which a request can send only once.
264
+ */
265
+ export function isAnyStream(value) {
266
+ return isStream(value) || isWebStream(value);
267
+ }
255
268
  /**
256
269
  * Helper class to create async iterators from paginated list endpoints.
257
270
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-rc.1",
3
+ "version": "3.0.0-rc.2",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.15.0"
@@ -19,6 +19,10 @@
19
19
  "exports": {
20
20
  "./package.json": "./package.json",
21
21
  "./browser": "./dist/bundle.js",
22
+ "./axios": {
23
+ "types": "./dist/axios.d.ts",
24
+ "default": "./dist/axios.js"
25
+ },
22
26
  ".": {
23
27
  "types": "./dist/index.d.ts",
24
28
  "browser": "./dist/bundle.js",
@@ -59,48 +63,55 @@
59
63
  ],
60
64
  "apify": {
61
65
  "openapiSpec": {
62
- "version": "v2-2026-11-09T143926Z"
66
+ "version": "v2-2026-11-18T151559Z"
63
67
  }
64
68
  },
65
69
  "dependencies": {
66
- "@apify/consts": "^3.0.1",
67
- "@apify/log": "^3.0.1",
68
- "@apify/utilities": "^3.1.0",
69
- "@apify/validations": "^1.1.2",
70
+ "@apify/consts": "^3.1.0",
71
+ "@apify/log": "^3.0.2",
72
+ "@apify/utilities": "^3.1.1",
73
+ "@apify/validations": "^1.1.4",
70
74
  "ansi-colors": "^4.1.3",
71
- "axios": "^1.21.0",
72
75
  "content-type": "^3.1.1",
73
- "proxy-agent": "^8.0.2",
74
76
  "tslib": "^2.9.1",
75
- "type-fest": "^5.10.0",
76
77
  "zod": "^4.6.7"
77
78
  },
79
+ "peerDependencies": {
80
+ "axios": "^1.21.1"
81
+ },
82
+ "peerDependenciesMeta": {
83
+ "axios": {
84
+ "optional": true
85
+ }
86
+ },
78
87
  "devDependencies": {
79
- "@apify/oxlint-config": "^0.3.0",
88
+ "@apify/oxlint-config": "^0.4.1",
80
89
  "@apify/tsconfig": "^0.2.0",
81
- "@crawlee/puppeteer": "4.0.0-rc.1",
82
- "@rsbuild/core": "^2.3.1",
90
+ "@crawlee/puppeteer": "4.0.0-rc.2",
91
+ "@rsbuild/core": "^2.3.3",
83
92
  "@rsbuild/plugin-node-polyfill": "^1.4.6",
84
- "@rspack/cli": "^2.3.1",
85
- "@rspack/core": "^2.3.1",
93
+ "@rspack/cli": "^2.3.3",
94
+ "@rspack/core": "^2.3.3",
86
95
  "@types/compression": "^1.8.1",
87
96
  "@types/express": "^5.0.6",
88
97
  "@types/node": "^26.6.6",
89
98
  "ajv": "^8.20.0",
99
+ "axios": "^1.21.1",
90
100
  "body-parser": "^2.4.0",
91
101
  "compression": "^1.8.2",
92
102
  "esbuild": "0.28.2",
93
103
  "express": "^5.3.0",
94
- "oxfmt": "0.77.0",
95
- "oxlint": "1.92.0",
96
- "oxlint-tsgolint": "7.0.2006",
97
- "puppeteer": "^25.16.0",
104
+ "miniflare": "4.20260730.0",
105
+ "oxfmt": "0.80.0",
106
+ "oxlint": "1.93.0",
107
+ "oxlint-tsgolint": "7.0.2007",
108
+ "puppeteer": "^25.18.1",
98
109
  "rimraf": "^6.1.4",
99
- "rolldown": "^1.2.16",
110
+ "rolldown": "^1.3.3",
100
111
  "typescript": "^7.0.2",
101
112
  "typescript-v6": "npm:typescript@^6.0.3",
102
- "vitest": "^5.1.0",
103
- "webpack": "^5.112.2",
113
+ "vitest": "^5.1.1",
114
+ "webpack": "^5.113.0",
104
115
  "webpack-cli": "^7.3.1"
105
116
  },
106
117
  "devEngines": {
@@ -114,6 +125,7 @@
114
125
  "build": "pnpm clean && pnpm build:node && pnpm build:browser",
115
126
  "clean": "rimraf dist tsconfig.tsbuildinfo",
116
127
  "test": "pnpm build && vitest run --project unit",
128
+ "test:axios": "pnpm build && vitest run --project unit-axios",
117
129
  "test:integration": "vitest run --project integration",
118
130
  "test:all": "pnpm build && vitest run",
119
131
  "test:bundling": "pnpm build && pnpm --prefix=./test/bundling run bundle:all",