apify-client 3.0.0-beta.6 → 3.0.0-beta.60

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 (116) hide show
  1. package/README.md +10 -2
  2. package/dist/apify_api_error.d.ts +11 -26
  3. package/dist/apify_api_error.js +31 -22
  4. package/dist/apify_client.d.ts +125 -10
  5. package/dist/apify_client.js +133 -48
  6. package/dist/base/api_client.d.ts +7 -7
  7. package/dist/base/api_client.js +36 -36
  8. package/dist/base/resource_client.d.ts +21 -8
  9. package/dist/base/resource_client.js +67 -33
  10. package/dist/base/resource_collection_client.d.ts +12 -4
  11. package/dist/base/resource_collection_client.js +34 -11
  12. package/dist/body_parser.d.ts +3 -4
  13. package/dist/body_parser.js +19 -26
  14. package/dist/bundle.js +27 -22
  15. package/dist/bundle.js.map +1 -1
  16. package/dist/generated/api.d.ts +785 -290
  17. package/dist/generated/schemas.d.ts +771 -798
  18. package/dist/generated/schemas.js +183 -179
  19. package/dist/http_clients/axios.d.ts +60 -0
  20. package/dist/http_clients/axios.js +117 -0
  21. package/dist/http_clients/base.d.ts +331 -0
  22. package/dist/http_clients/base.js +563 -0
  23. package/dist/http_clients/index.d.ts +4 -0
  24. package/dist/http_clients/index.js +2 -0
  25. package/dist/http_compressors/base.d.ts +40 -0
  26. package/dist/http_compressors/base.js +9 -0
  27. package/dist/http_compressors/brotli.d.ts +33 -0
  28. package/dist/http_compressors/brotli.js +39 -0
  29. package/dist/http_compressors/gzip.d.ts +33 -0
  30. package/dist/http_compressors/gzip.js +39 -0
  31. package/dist/http_compressors/index.d.ts +6 -0
  32. package/dist/http_compressors/index.js +2 -0
  33. package/dist/http_compressors/resolve.d.ts +23 -0
  34. package/dist/http_compressors/resolve.js +27 -0
  35. package/dist/index.d.ts +4 -1
  36. package/dist/index.js +3 -1
  37. package/dist/invalid_response_body_error.d.ts +13 -0
  38. package/dist/invalid_response_body_error.js +17 -0
  39. package/dist/models.d.ts +162 -194
  40. package/dist/models.js +6 -4
  41. package/dist/resource_clients/actor.d.ts +74 -34
  42. package/dist/resource_clients/actor.js +87 -56
  43. package/dist/resource_clients/actor_collection.d.ts +18 -14
  44. package/dist/resource_clients/actor_collection.js +11 -3
  45. package/dist/resource_clients/actor_env_var.d.ts +11 -4
  46. package/dist/resource_clients/actor_env_var.js +16 -6
  47. package/dist/resource_clients/actor_env_var_collection.d.ts +16 -20
  48. package/dist/resource_clients/actor_env_var_collection.js +17 -11
  49. package/dist/resource_clients/actor_version.d.ts +20 -5
  50. package/dist/resource_clients/actor_version.js +19 -9
  51. package/dist/resource_clients/actor_version_collection.d.ts +18 -19
  52. package/dist/resource_clients/actor_version_collection.js +19 -11
  53. package/dist/resource_clients/build.d.ts +20 -7
  54. package/dist/resource_clients/build.js +35 -15
  55. package/dist/resource_clients/build_collection.d.ts +7 -5
  56. package/dist/resource_clients/build_collection.js +4 -1
  57. package/dist/resource_clients/dataset.d.ts +53 -35
  58. package/dist/resource_clients/dataset.js +105 -80
  59. package/dist/resource_clients/dataset_collection.d.ts +10 -6
  60. package/dist/resource_clients/dataset_collection.js +13 -2
  61. package/dist/resource_clients/key_value_store.d.ts +73 -23
  62. package/dist/resource_clients/key_value_store.js +86 -43
  63. package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
  64. package/dist/resource_clients/key_value_store_collection.js +13 -2
  65. package/dist/resource_clients/log.d.ts +13 -20
  66. package/dist/resource_clients/log.js +141 -59
  67. package/dist/resource_clients/request_queue.d.ts +74 -36
  68. package/dist/resource_clients/request_queue.js +182 -106
  69. package/dist/resource_clients/request_queue_collection.d.ts +9 -5
  70. package/dist/resource_clients/request_queue_collection.js +9 -3
  71. package/dist/resource_clients/run.d.ts +119 -28
  72. package/dist/resource_clients/run.js +190 -49
  73. package/dist/resource_clients/run_collection.d.ts +5 -3
  74. package/dist/resource_clients/run_collection.js +4 -1
  75. package/dist/resource_clients/schedule.d.ts +16 -7
  76. package/dist/resource_clients/schedule.js +30 -22
  77. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  78. package/dist/resource_clients/schedule_collection.js +9 -3
  79. package/dist/resource_clients/store_collection.d.ts +6 -4
  80. package/dist/resource_clients/store_collection.js +4 -1
  81. package/dist/resource_clients/task.d.ts +36 -13
  82. package/dist/resource_clients/task.js +79 -46
  83. package/dist/resource_clients/task_collection.d.ts +9 -5
  84. package/dist/resource_clients/task_collection.js +9 -3
  85. package/dist/resource_clients/user.d.ts +19 -10
  86. package/dist/resource_clients/user.js +42 -38
  87. package/dist/resource_clients/webhook.d.ts +17 -8
  88. package/dist/resource_clients/webhook.js +30 -22
  89. package/dist/resource_clients/webhook_collection.d.ts +8 -4
  90. package/dist/resource_clients/webhook_collection.js +9 -3
  91. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  92. package/dist/resource_clients/webhook_dispatch.js +7 -2
  93. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  94. package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
  95. package/dist/runtime/node.d.ts +6 -0
  96. package/dist/runtime/node.js +49 -0
  97. package/dist/runtime/types.d.ts +52 -0
  98. package/dist/runtime/types.js +1 -0
  99. package/dist/runtime/web.d.ts +5 -0
  100. package/dist/runtime/web.js +18 -0
  101. package/dist/schemas.d.ts +1 -1
  102. package/dist/schemas.js +1 -1
  103. package/dist/statistics.d.ts +1 -6
  104. package/dist/statistics.js +2 -2
  105. package/dist/timeouts.d.ts +84 -0
  106. package/dist/timeouts.js +37 -0
  107. package/dist/timezones.d.ts +1 -1
  108. package/dist/utils.d.ts +89 -53
  109. package/dist/utils.js +214 -161
  110. package/dist/wait_for_resources.d.ts +8 -0
  111. package/dist/wait_for_resources.js +39 -0
  112. package/package.json +32 -29
  113. package/dist/http_client.d.ts +0 -88
  114. package/dist/http_client.js +0 -255
  115. package/dist/interceptors.d.ts +0 -19
  116. package/dist/interceptors.js +0 -105
package/README.md CHANGED
@@ -59,6 +59,12 @@ By default, it will retry up to 8 times. First retry will be attempted after ~50
59
59
  and so on. You can configure those parameters using the `maxRetries` and `minDelayBetweenRetriesMillis`
60
60
  options of the `ApifyClient` constructor.
61
61
 
62
+ ### Pluggable HTTP client
63
+
64
+ The client ships with an axios-based HTTP client and accepts a custom one. Extend `HttpClient`, implement
65
+ `sendRequest()` over the HTTP library of your choice and plug it in with `ApifyClient.withCustomHttpClient()`. The
66
+ custom client inherits the retries, timeouts, compression and error handling of the built-in one.
67
+
62
68
  ### Convenience functions and options
63
69
 
64
70
  Some actions can't be performed by the API itself, such as indefinite waiting for an actor run to finish
@@ -145,13 +151,15 @@ property to get only a subset of results. Other props are also available, depend
145
151
 
146
152
  ## Bundled environments
147
153
 
148
- The package includes a pre-built browser bundle that is automatically resolved by bundlers targeting browser environments. You can also import it explicitly via
154
+ The package includes a pre-built browser bundle that bundlers targeting browsers resolve automatically. You can also import it explicitly:
149
155
 
150
156
  ```typescript
151
157
  import { ApifyClient } from 'apify-client/browser';
152
158
  ```
153
159
 
154
- For edge runtimes like Cloudflare Workers, you may need to enable Node compatibility (e.g. `node_compat = true` in `wrangler.toml`). Note that some Node-specific features (streaming, proxy support) are not available in the bundle.
160
+ Only two parts of the client need Node.js built-ins: the HTTP agents and request compression. The `node` condition selects the Node.js implementation of those, and every other target gets one built on Web APIs. Log streaming, proxy support, and request compression are only available in Node.js.
161
+
162
+ For details, see [Bundled environments](https://docs.apify.com/api/client/js/docs/concepts/bundled-environments).
155
163
 
156
164
  ## API Reference
157
165
 
@@ -1,7 +1,7 @@
1
- import type { AxiosResponse } from 'axios';
2
1
  import type { LiteralUnion } from 'type-fest';
3
- import type { ApifyApiErrorType } from './models.js';
4
- export type { ApifyApiErrorType } from './models.js';
2
+ import type { ApifyResponse } from './http_clients/base.js';
3
+ import type { ErrorType } from './models.js';
4
+ export type { ErrorType } from './models.js';
5
5
  /**
6
6
  * An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
7
7
  * but the API responds with an error response. Typically, those are rate limit
@@ -17,10 +17,12 @@ export type { ApifyApiErrorType } from './models.js';
17
17
  * share a status code are told apart by their `type`.
18
18
  */
19
19
  export declare class ApifyApiError extends Error {
20
+ #private;
20
21
  name: string;
21
22
  /**
22
- * The invoked resource client and the method. Known issue: Sometimes it displays
23
- * as `unknown` because it can't be parsed from a stack trace.
23
+ * The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
24
+ * method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
25
+ * when the stack trace cannot be parsed.
24
26
  */
25
27
  clientMethod: string;
26
28
  /**
@@ -28,10 +30,10 @@ export declare class ApifyApiError extends Error {
28
30
  */
29
31
  statusCode: number;
30
32
  /**
31
- * The type of the error, as returned by the API. Typed as the known {@link ApifyApiErrorType}
33
+ * The type of the error, as returned by the API. Typed as the known {@link ErrorType}
32
34
  * values for autocompletion, while still accepting any string the API may return.
33
35
  */
34
- type?: LiteralUnion<ApifyApiErrorType, string>;
36
+ type?: LiteralUnion<ErrorType, string>;
35
37
  /**
36
38
  * Number of the API call attempt.
37
39
  */
@@ -56,29 +58,12 @@ export declare class ApifyApiError extends Error {
56
58
  /**
57
59
  * @hidden
58
60
  */
59
- constructor(response: AxiosResponse, attempt: number);
61
+ constructor(response: ApifyResponse, attempt: number);
60
62
  /**
61
63
  * Creates the error for a failed response as an instance of the subclass matching its HTTP status code.
62
64
  * @hidden
63
65
  */
64
- static fromResponse(response: AxiosResponse, attempt: number): ApifyApiError;
65
- private _safelyParsePathFromResponse;
66
- private _extractClientAndMethodFromStack;
67
- /**
68
- * Creates a better looking and more informative stack that will be printed
69
- * out when API errors are thrown.
70
- *
71
- * Example:
72
- *
73
- * NotFoundError: Actor task was not found
74
- * clientMethod: TaskClient.start
75
- * statusCode: 404
76
- * type: record-not-found
77
- * attempt: 1
78
- * httpMethod: post
79
- * path: /v2/actor-tasks/user~my-task/runs
80
- */
81
- private _createApiStack;
66
+ static fromResponse(response: ApifyResponse, attempt: number): ApifyApiError;
82
67
  }
83
68
  /**
84
69
  * Thrown when the Apify API responds with HTTP 400 Bad Request, typically because the request
@@ -1,15 +1,21 @@
1
- import { isomorphicBufferToString } from './body_parser.js';
2
1
  import { isBuffer } from './utils.js';
3
2
  /**
4
- * Examples of capturing groups for "...at ActorCollectionClient._list (/Users/..."
5
- * 0: "at ActorCollectionClient._list ("
3
+ * Examples of capturing groups for "...at ActorCollectionClient.listResources (/Users/..."
4
+ * 0: "at ActorCollectionClient.listResources ("
6
5
  * 1: undefined
7
6
  * 2: "ActorCollectionClient"
8
7
  * 3: undefined
9
- * 4: "list"
8
+ * 4: "listResources"
9
+ *
10
+ * The error is created inside the HTTP client's pipeline, whose frames sit above the resource client's. The
11
+ * pipeline's own methods are private, so V8 prints them with a `#` that no method name can match. Its public
12
+ * `call()` prints under the name of the transport's class, which can be anything, so the lookaheads skip a class
13
+ * named after `HttpClient` and the method `call`. A transport named `SomethingClient` whose `call()` override
14
+ * awaits a helper of its own is reported under that helper. `ActorClient.call()` and `TaskClient.call()` reach the
15
+ * pipeline through `start()`, whose frame sits closer to the error and matches first.
10
16
  * @private
11
17
  */
12
- const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\._?([A-Za-z]+) \(/;
18
+ const CLIENT_METHOD_REGEX = /at( async)? (?![A-Za-z]*HttpClient\.)([A-Za-z]+(Collection)?Client)\.(?!call \()([A-Za-z]+) \(/;
13
19
  /**
14
20
  * An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
15
21
  * but the API responds with an error response. Typically, those are rate limit
@@ -27,8 +33,9 @@ const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\._?([A-Z
27
33
  export class ApifyApiError extends Error {
28
34
  name;
29
35
  /**
30
- * The invoked resource client and the method. Known issue: Sometimes it displays
31
- * as `unknown` because it can't be parsed from a stack trace.
36
+ * The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
37
+ * method that delegates to a shared helper of its class is reported under the helper. The value is `unknown`
38
+ * when the stack trace cannot be parsed.
32
39
  */
33
40
  clientMethod;
34
41
  /**
@@ -36,7 +43,7 @@ export class ApifyApiError extends Error {
36
43
  */
37
44
  statusCode;
38
45
  /**
39
- * The type of the error, as returned by the API. Typed as the known {@link ApifyApiErrorType}
46
+ * The type of the error, as returned by the API. Typed as the known {@link ErrorType}
40
47
  * values for autocompletion, while still accepting any string the API may return.
41
48
  */
42
49
  type;
@@ -69,14 +76,16 @@ export class ApifyApiError extends Error {
69
76
  let type;
70
77
  let responseData = response.data;
71
78
  let errorData;
72
- // Some methods (e.g. downloadItems) set up forceBuffer on request response. If this request failed
73
- // the body buffer needs to parse to get the correct error.
79
+ // A `responseType: 'buffer'` request (e.g. `downloadItems()`) and a failed streaming request, whose body
80
+ // `HttpClient` has read into a buffer, both arrive unparsed. Parse the body here to get at the error.
74
81
  if (isBuffer(responseData)) {
82
+ const body = new TextDecoder().decode(response.data);
75
83
  try {
76
- responseData = JSON.parse(isomorphicBufferToString(response.data, 'utf-8'));
84
+ responseData = JSON.parse(body);
77
85
  }
78
86
  catch {
79
- // This can happen. The data in the response body are malformed.
87
+ // A body that is not JSON at all, such as an HTML error page from a proxy, is kept as text.
88
+ responseData = body;
80
89
  }
81
90
  }
82
91
  if (responseData && responseData.error) {
@@ -97,15 +106,15 @@ export class ApifyApiError extends Error {
97
106
  }
98
107
  super(message);
99
108
  this.name = this.constructor.name;
100
- this.clientMethod = this._extractClientAndMethodFromStack();
109
+ this.clientMethod = this.#extractClientAndMethodFromStack();
101
110
  this.statusCode = response.status;
102
111
  this.type = type;
103
112
  this.attempt = attempt;
104
113
  this.httpMethod = response.config?.method;
105
- this.path = this._safelyParsePathFromResponse(response);
114
+ this.path = this.#safelyParsePathFromResponse(response);
106
115
  const stack = this.stack;
107
116
  this.originalStack = stack.slice(stack.indexOf('\n'));
108
- this.stack = this._createApiStack();
117
+ this.stack = this.#createApiStack();
109
118
  this.data = errorData;
110
119
  }
111
120
  /**
@@ -116,7 +125,7 @@ export class ApifyApiError extends Error {
116
125
  const ErrorClass = ERROR_CLASS_BY_STATUS[response.status] ?? (response.status >= 500 ? ServerError : ApifyApiError);
117
126
  return new ErrorClass(response, attempt);
118
127
  }
119
- _safelyParsePathFromResponse(response) {
128
+ #safelyParsePathFromResponse(response) {
120
129
  const urlString = response.config?.url;
121
130
  let url;
122
131
  try {
@@ -127,11 +136,11 @@ export class ApifyApiError extends Error {
127
136
  }
128
137
  return url.pathname + url.search;
129
138
  }
130
- _extractClientAndMethodFromStack() {
139
+ #extractClientAndMethodFromStack() {
131
140
  const match = this.stack.match(CLIENT_METHOD_REGEX);
132
- if (match)
133
- return `${match[2]}.${match[4]}`;
134
- return 'unknown';
141
+ if (!match)
142
+ return 'unknown';
143
+ return `${match[2]}.${match[4]}`;
135
144
  }
136
145
  /**
137
146
  * Creates a better looking and more informative stack that will be printed
@@ -144,10 +153,10 @@ export class ApifyApiError extends Error {
144
153
  * statusCode: 404
145
154
  * type: record-not-found
146
155
  * attempt: 1
147
- * httpMethod: post
156
+ * httpMethod: POST
148
157
  * path: /v2/actor-tasks/user~my-task/runs
149
158
  */
150
- _createApiStack() {
159
+ #createApiStack() {
151
160
  const { name, ...props } = this;
152
161
  const stack = Object.entries(props)
153
162
  .map(([k, v]) => {
@@ -1,7 +1,7 @@
1
- import type { SetStatusMessageOptions } from '@crawlee/types';
2
1
  import type { Log } from '@apify/log';
3
- import { HttpClient } from './http_client.js';
4
- import type { RequestInterceptorFunction } from './interceptors.js';
2
+ import { HttpClient } from './http_clients/base.js';
3
+ import type { HttpCompressor } from './http_compressors/base.js';
4
+ import type { HttpCompressionAlgorithm } from './http_compressors/resolve.js';
5
5
  import { ActorClient } from './resource_clients/actor.js';
6
6
  import { ActorCollectionClient } from './resource_clients/actor_collection.js';
7
7
  import { BuildClient } from './resource_clients/build.js';
@@ -49,17 +49,66 @@ import { Statistics } from './statistics.js';
49
49
  * @see https://docs.apify.com/api/v2
50
50
  */
51
51
  export declare class ApifyClient {
52
+ #private;
52
53
  baseUrl: string;
53
54
  /**
54
55
  * @since Added in 2.17.0
55
56
  */
56
57
  publicBaseUrl: string;
57
58
  token?: string;
59
+ /**
60
+ * Statistics of the API calls made through the client. With a custom HTTP client, this is the client's own
61
+ * `stats` object, so it only reflects what that client records.
62
+ */
58
63
  stats: Statistics;
59
64
  logger: Log;
60
- httpClient: HttpClient;
65
+ /**
66
+ * Creates a client that sends its requests through the built-in {@link AxiosHttpClient}, configured from
67
+ * `options`: the API token, retries, the timeout tiers, request compression and default headers. The HTTP
68
+ * client itself is created when {@link httpClient} is first read. To send the requests through a custom HTTP
69
+ * client, use {@link ApifyClient.withCustomHttpClient} instead.
70
+ *
71
+ * @param options - Configuration of the client and of its HTTP client.
72
+ * @throws {ArgumentValidationError} When an option is unknown or has an invalid value.
73
+ */
61
74
  constructor(options?: ApifyClientOptions);
62
- private _options;
75
+ /**
76
+ * Creates an `ApifyClient` that sends its requests through a custom HTTP client.
77
+ *
78
+ * The custom client owns its transport configuration: retries, timeouts, default headers and whatever its
79
+ * transport needs are set on the client itself. This is also how the built-in {@link AxiosHttpClient} is
80
+ * configured beyond what the constructor options offer, for example with axios request interceptors. The
81
+ * token is set as the client's `Authorization` header, unless the client already has one configured.
82
+ *
83
+ * @param options - The token, the API URLs and the HTTP client to use.
84
+ * @returns A client whose {@link httpClient} is the given one.
85
+ *
86
+ * @example
87
+ * ```javascript
88
+ * import { ApifyClient, HttpClient } from 'apify-client';
89
+ *
90
+ * class MyHttpClient extends HttpClient {
91
+ * async sendRequest({ method, url, headers, body, timeoutMillis, stream, signal }) {
92
+ * // Send the request with the HTTP library of your choice and return { status, headers, body }.
93
+ * }
94
+ * }
95
+ *
96
+ * const client = ApifyClient.withCustomHttpClient({ token: 'my-token', httpClient: new MyHttpClient() });
97
+ * ```
98
+ */
99
+ static withCustomHttpClient(options: ApifyClientCustomHttpClientOptions): ApifyClient;
100
+ /**
101
+ * The HTTP client the requests go through: the custom one when set through
102
+ * {@link ApifyClient.withCustomHttpClient}, and otherwise an {@link AxiosHttpClient} configured from the
103
+ * constructor options, created on first access. Assigning a client applies {@link token} to it through
104
+ * {@link HttpClient.setDefaultAuthorization} and points {@link stats} at its statistics, so the counters keep
105
+ * tracking the calls the client actually makes. Resource clients hold on to the HTTP client they were created
106
+ * with, so assign before reaching for them. Assigning does not close the client it replaces. A default client
107
+ * that already sent a request keeps its keep-alive agents open until {@link HttpClient.close} is called on it,
108
+ * so close it yourself, or assign before the first request.
109
+ */
110
+ get httpClient(): HttpClient;
111
+ set httpClient(httpClient: HttpClient);
63
112
  /**
64
113
  * Returns a client for managing Actors in your account.
65
114
  *
@@ -347,13 +396,41 @@ export declare class ApifyClient {
347
396
  */
348
397
  setStatusMessage(message: string, options?: SetStatusMessageOptions): Promise<void>;
349
398
  }
399
+ /**
400
+ * Options for {@apilink ApifyClient.setStatusMessage}. Structurally identical to crawlee's
401
+ * `SetStatusMessageOptions`, so the client stays a drop-in `StorageClient` implementation
402
+ * without a dependency on the crawlee packages.
403
+ */
404
+ export interface SetStatusMessageOptions {
405
+ /** If true, the status message is marked as the final one for the run. */
406
+ isStatusMessageTerminal?: boolean;
407
+ /** The log level for the status message. */
408
+ level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
409
+ }
350
410
  /**
351
411
  * Configuration options for ApifyClient.
352
412
  */
353
413
  export interface ApifyClientOptions {
354
- /** @default https://api.apify.com */
414
+ /**
415
+ * URL of the Apify API, with or without the `/v2` version path, which is appended when missing.
416
+ * @default https://api.apify.com
417
+ */
355
418
  baseUrl?: string;
356
419
  /**
420
+ * Compression of request bodies: the name of a built-in algorithm, or an {@link HttpCompressor} for a custom
421
+ * quality or algorithm. Bodies are compressed only in Node.js, and only when they are large enough to benefit
422
+ * and their content type does not already carry its own compression.
423
+ * @default 'brotli'
424
+ */
425
+ compression?: HttpCompressionAlgorithm | HttpCompressor;
426
+ /**
427
+ * Additional headers sent with every request, such as an integration platform marker. They win over the
428
+ * built-in defaults, and a header set on a single call wins over them.
429
+ */
430
+ headers?: Record<string, string>;
431
+ /**
432
+ * Publicly accessible URL of the Apify API, used in the URLs the client generates. Like `baseUrl`, with or
433
+ * without the `/v2` version path.
357
434
  * @default https://api.apify.com
358
435
  * @since Added in 2.17.0
359
436
  */
@@ -362,13 +439,51 @@ export interface ApifyClientOptions {
362
439
  maxRetries?: number;
363
440
  /** @default 500 */
364
441
  minDelayBetweenRetriesMillis?: number;
365
- /** @default [] */
366
- requestInterceptors?: RequestInterceptorFunction[];
367
- /** @default 360 */
368
- timeoutSecs?: number;
442
+ /**
443
+ * Duration of the `short` timeout tier, in seconds: simple metadata reads and writes.
444
+ * @default 5
445
+ */
446
+ timeoutShortSecs?: number;
447
+ /**
448
+ * Duration of the `medium` timeout tier, in seconds: listing, batch and trigger operations.
449
+ * @default 30
450
+ */
451
+ timeoutMediumSecs?: number;
452
+ /**
453
+ * Duration of the `long` timeout tier, in seconds: downloads, uploads and streaming.
454
+ * @default 360
455
+ */
456
+ timeoutLongSecs?: number;
457
+ /**
458
+ * Cap on the timeout of a single request attempt, in seconds. It bounds the doubling of the timeout across
459
+ * retries, and caps tier and per-call timeouts alike, so raise it to allow a request timeout above 360 s.
460
+ * @default 360
461
+ */
462
+ timeoutMaxSecs?: number;
369
463
  token?: string;
370
464
  /**
371
465
  * @since Added in 2.10.0
372
466
  */
373
467
  userAgentSuffix?: string | string[];
374
468
  }
469
+ /**
470
+ * Configuration options for {@link ApifyClient.withCustomHttpClient}. Retries, timeouts and headers are configured
471
+ * on the HTTP client itself.
472
+ */
473
+ export interface ApifyClientCustomHttpClientOptions {
474
+ /**
475
+ * URL of the Apify API, with or without the `/v2` version path, which is appended when missing.
476
+ * @default https://api.apify.com
477
+ */
478
+ baseUrl?: string;
479
+ /**
480
+ * Publicly accessible URL of the Apify API, used in the URLs the client generates. Like `baseUrl`, with or
481
+ * without the `/v2` version path.
482
+ * @default https://api.apify.com
483
+ */
484
+ publicBaseUrl?: string;
485
+ /** Set as the HTTP client's `Authorization` header, unless it already has one. */
486
+ token?: string;
487
+ /** The HTTP client to send the requests through. */
488
+ httpClient: HttpClient;
489
+ }