apify-client 3.0.0-beta.15 → 3.0.0-beta.17
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/apify_api_error.d.ts +4 -19
- package/dist/apify_api_error.js +16 -15
- package/dist/apify_client.d.ts +22 -3
- package/dist/apify_client.js +35 -29
- package/dist/base/api_client.d.ts +6 -6
- package/dist/base/api_client.js +11 -10
- package/dist/base/resource_client.d.ts +13 -8
- package/dist/base/resource_client.js +35 -19
- package/dist/base/resource_collection_client.d.ts +6 -4
- package/dist/base/resource_collection_client.js +17 -11
- package/dist/bundle.js +12 -12
- package/dist/bundle.js.map +1 -1
- package/dist/http_client.d.ts +18 -51
- package/dist/http_client.js +67 -38
- package/dist/index.d.ts +1 -0
- package/dist/resource_clients/actor.d.ts +26 -11
- package/dist/resource_clients/actor.js +62 -33
- package/dist/resource_clients/actor_collection.d.ts +6 -2
- package/dist/resource_clients/actor_collection.js +9 -3
- package/dist/resource_clients/actor_env_var.d.ts +10 -3
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +7 -2
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_version.d.ts +10 -3
- package/dist/resource_clients/actor_version.js +18 -8
- package/dist/resource_clients/actor_version_collection.d.ts +7 -2
- package/dist/resource_clients/actor_version_collection.js +11 -4
- package/dist/resource_clients/build.d.ts +16 -6
- package/dist/resource_clients/build.js +30 -15
- package/dist/resource_clients/build_collection.d.ts +3 -1
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +21 -7
- package/dist/resource_clients/dataset.js +56 -34
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +12 -2
- package/dist/resource_clients/key_value_store.d.ts +31 -11
- package/dist/resource_clients/key_value_store.js +58 -34
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +12 -2
- package/dist/resource_clients/log.d.ts +5 -17
- package/dist/resource_clients/log.js +46 -37
- package/dist/resource_clients/request_queue.d.ts +47 -19
- package/dist/resource_clients/request_queue.js +127 -73
- package/dist/resource_clients/request_queue_collection.d.ts +6 -2
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +33 -13
- package/dist/resource_clients/run.js +65 -35
- package/dist/resource_clients/run_collection.d.ts +3 -1
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +13 -4
- package/dist/resource_clients/schedule.js +23 -9
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +9 -3
- package/dist/resource_clients/store_collection.d.ts +3 -1
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +27 -9
- package/dist/resource_clients/task.js +60 -31
- package/dist/resource_clients/task_collection.d.ts +6 -2
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +14 -5
- package/dist/resource_clients/user.js +30 -14
- package/dist/resource_clients/webhook.d.ts +13 -4
- package/dist/resource_clients/webhook.js +24 -10
- package/dist/resource_clients/webhook_collection.d.ts +6 -2
- package/dist/resource_clients/webhook_collection.js +9 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +7 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +1 -4
- package/dist/utils.js +14 -14
- package/package.json +1 -1
package/dist/http_client.d.ts
CHANGED
|
@@ -4,72 +4,36 @@ import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosReq
|
|
|
4
4
|
import type { Log } from '@apify/log';
|
|
5
5
|
import type { RequestInterceptorFunction } from './interceptors.js';
|
|
6
6
|
import type { Statistics } from './statistics.js';
|
|
7
|
+
import type { Timeout, TimeoutTier } from './timeouts.js';
|
|
7
8
|
export declare class HttpClient {
|
|
9
|
+
#private;
|
|
8
10
|
stats: Statistics;
|
|
9
11
|
maxRetries: number;
|
|
10
12
|
minDelayBetweenRetriesMillis: number;
|
|
11
13
|
userProvidedRequestInterceptors: RequestInterceptorFunction[];
|
|
12
14
|
logger: Log;
|
|
13
|
-
|
|
15
|
+
/** Duration of each timeout tier, in milliseconds. */
|
|
16
|
+
timeoutMillis: Record<TimeoutTier, number>;
|
|
17
|
+
/** Cap on the timeout of a single request attempt, in milliseconds. */
|
|
18
|
+
timeoutMaxMillis: number;
|
|
14
19
|
httpAgent?: http.Agent;
|
|
15
20
|
httpsAgent?: https.Agent;
|
|
16
21
|
axios: AxiosInstance;
|
|
17
22
|
workflowKey?: string;
|
|
18
|
-
private nodeInitPromise?;
|
|
19
|
-
private userAgentSuffix?;
|
|
20
23
|
constructor(options: HttpClientOptions);
|
|
21
|
-
private ensureNodeInit;
|
|
22
|
-
private initNode;
|
|
23
24
|
call<T = any>(config: ApifyRequestConfig): Promise<ApifyResponse<T>>;
|
|
24
|
-
private _informAboutStreamNoRetry;
|
|
25
|
-
/**
|
|
26
|
-
* Successful responses are returned, errors and unsuccessful
|
|
27
|
-
* status codes are retried. See the following functions for the
|
|
28
|
-
* retrying logic.
|
|
29
|
-
*/
|
|
30
|
-
private _createRequestHandler;
|
|
31
|
-
private _isStatusOk;
|
|
32
|
-
/**
|
|
33
|
-
* Handles all unexpected errors that can happen, but are not
|
|
34
|
-
* Apify API typed errors. E.g. network errors, timeouts and so on.
|
|
35
|
-
*/
|
|
36
|
-
private _handleRequestError;
|
|
37
|
-
/**
|
|
38
|
-
* Axios calls req.abort() on timeouts so timeout errors will
|
|
39
|
-
* have a code ECONNABORTED.
|
|
40
|
-
*/
|
|
41
|
-
private _isTimeoutError;
|
|
42
|
-
/**
|
|
43
|
-
* We don't want to retry every exception thrown from Axios.
|
|
44
|
-
* The common denominator for retryable errors are network issues.
|
|
45
|
-
* @param {Error} err
|
|
46
|
-
* @private
|
|
47
|
-
*/
|
|
48
|
-
private _isRetryableError;
|
|
49
|
-
/**
|
|
50
|
-
* When a network connection to our API is interrupted in the middle of streaming
|
|
51
|
-
* a response, the request often does not fail, but simply contains
|
|
52
|
-
* an incomplete response. This can often be fixed by retrying.
|
|
53
|
-
*/
|
|
54
|
-
private _isResponseBodyInvalid;
|
|
55
|
-
/**
|
|
56
|
-
* When a network request is attempted by axios and fails,
|
|
57
|
-
* it throws an AxiosError, which will have the request
|
|
58
|
-
* and config (and other) properties.
|
|
59
|
-
*/
|
|
60
|
-
private _isNetworkError;
|
|
61
|
-
/**
|
|
62
|
-
* We retry 429 (rate limit) and 500+.
|
|
63
|
-
* For status codes 300-499 (except 429) we do not retry the request,
|
|
64
|
-
* because it's probably caused by invalid url (redirect 3xx) or invalid user input (4xx).
|
|
65
|
-
*/
|
|
66
|
-
private _isStatusCodeRetryable;
|
|
67
|
-
private _onRequestRetry;
|
|
68
25
|
}
|
|
69
|
-
export interface ApifyRequestConfig extends AxiosRequestConfig {
|
|
26
|
+
export interface ApifyRequestConfig extends Omit<AxiosRequestConfig, 'timeout'> {
|
|
70
27
|
stringifyFunctions?: boolean;
|
|
71
28
|
forceBuffer?: boolean;
|
|
72
29
|
doNotRetryTimeouts?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Timeout of the request: a tier name, a number of seconds, or `'noTimeout'`. The client resolves it to
|
|
32
|
+
* the axios `timeout` in milliseconds for each attempt, before axios runs its interceptors, so a request
|
|
33
|
+
* interceptor already sees a number of milliseconds.
|
|
34
|
+
* @default 'medium'
|
|
35
|
+
*/
|
|
36
|
+
timeoutSecs?: Timeout;
|
|
73
37
|
}
|
|
74
38
|
export interface ApifyResponse<T = any> extends AxiosResponse<T> {
|
|
75
39
|
config: ApifyRequestConfig & InternalAxiosRequestConfig;
|
|
@@ -79,7 +43,10 @@ export interface HttpClientOptions {
|
|
|
79
43
|
maxRetries: number;
|
|
80
44
|
minDelayBetweenRetriesMillis: number;
|
|
81
45
|
requestInterceptors: RequestInterceptorFunction[];
|
|
82
|
-
|
|
46
|
+
timeoutShortSecs: number;
|
|
47
|
+
timeoutMediumSecs: number;
|
|
48
|
+
timeoutLongSecs: number;
|
|
49
|
+
timeoutMaxSecs: number;
|
|
83
50
|
logger: Log;
|
|
84
51
|
token?: string;
|
|
85
52
|
workflowKey?: string;
|
package/dist/http_client.js
CHANGED
|
@@ -12,24 +12,31 @@ export class HttpClient {
|
|
|
12
12
|
minDelayBetweenRetriesMillis;
|
|
13
13
|
userProvidedRequestInterceptors;
|
|
14
14
|
logger;
|
|
15
|
+
/** Duration of each timeout tier, in milliseconds. */
|
|
15
16
|
timeoutMillis;
|
|
17
|
+
/** Cap on the timeout of a single request attempt, in milliseconds. */
|
|
18
|
+
timeoutMaxMillis;
|
|
16
19
|
httpAgent;
|
|
17
20
|
httpsAgent;
|
|
18
21
|
axios;
|
|
19
22
|
workflowKey;
|
|
20
|
-
nodeInitPromise;
|
|
21
|
-
userAgentSuffix;
|
|
23
|
+
#nodeInitPromise;
|
|
24
|
+
#userAgentSuffix;
|
|
22
25
|
constructor(options) {
|
|
23
26
|
const { token } = options;
|
|
24
27
|
this.stats = options.apifyClientStats;
|
|
25
28
|
this.maxRetries = options.maxRetries;
|
|
26
29
|
this.minDelayBetweenRetriesMillis = options.minDelayBetweenRetriesMillis;
|
|
27
30
|
this.userProvidedRequestInterceptors = options.requestInterceptors;
|
|
28
|
-
this.timeoutMillis =
|
|
31
|
+
this.timeoutMillis = {
|
|
32
|
+
short: options.timeoutShortSecs * 1000,
|
|
33
|
+
medium: options.timeoutMediumSecs * 1000,
|
|
34
|
+
long: options.timeoutLongSecs * 1000,
|
|
35
|
+
};
|
|
36
|
+
this.timeoutMaxMillis = options.timeoutMaxSecs * 1000;
|
|
29
37
|
this.logger = options.logger;
|
|
30
38
|
this.workflowKey = options.workflowKey || process.env[APIFY_ENV_VARS.WORKFLOW_KEY];
|
|
31
|
-
this
|
|
32
|
-
this._onRequestRetry = this._onRequestRetry.bind(this);
|
|
39
|
+
this.#userAgentSuffix = options.userAgentSuffix;
|
|
33
40
|
this.axios = axios.create({
|
|
34
41
|
// Disable axios's built-in proxy handling since we're using custom agents
|
|
35
42
|
proxy: false,
|
|
@@ -50,7 +57,9 @@ export class HttpClient {
|
|
|
50
57
|
transformRequest: undefined,
|
|
51
58
|
transformResponse: undefined,
|
|
52
59
|
responseType: 'arraybuffer',
|
|
53
|
-
timeout
|
|
60
|
+
// Every request sets its own timeout in `createRequestHandler`, so the default only backs a raw
|
|
61
|
+
// `axios.request()` call.
|
|
62
|
+
timeout: this.timeoutMaxMillis,
|
|
54
63
|
// maxBodyLength needs to be Infinity, because -1 falls back to a 10 MB default
|
|
55
64
|
// from an axios subdependency - 'follow-redirects'
|
|
56
65
|
maxBodyLength: Infinity,
|
|
@@ -72,13 +81,13 @@ export class HttpClient {
|
|
|
72
81
|
this.userProvidedRequestInterceptors.forEach((i) => this.axios.interceptors.request.use(i));
|
|
73
82
|
responseInterceptors.forEach((i) => this.axios.interceptors.response.use(i));
|
|
74
83
|
}
|
|
75
|
-
async ensureNodeInit() {
|
|
84
|
+
async #ensureNodeInit() {
|
|
76
85
|
if (!isNode())
|
|
77
86
|
return;
|
|
78
|
-
this
|
|
79
|
-
return this
|
|
87
|
+
this.#nodeInitPromise ??= this.#initNode();
|
|
88
|
+
return this.#nodeInitPromise;
|
|
80
89
|
}
|
|
81
|
-
async initNode() {
|
|
90
|
+
async #initNode() {
|
|
82
91
|
if (!isNode())
|
|
83
92
|
return;
|
|
84
93
|
const [{ ProxyAgent }, os] = await Promise.all([import('proxy-agent'), import('node:os')]);
|
|
@@ -92,7 +101,7 @@ export class HttpClient {
|
|
|
92
101
|
keepAlive: true,
|
|
93
102
|
// Timeout for inactive sockets
|
|
94
103
|
// Prevents socket leaks from idle connections
|
|
95
|
-
timeout: this.
|
|
104
|
+
timeout: this.timeoutMaxMillis,
|
|
96
105
|
// Keep alive timeout for free sockets (15 seconds)
|
|
97
106
|
// Node.js will close unused sockets after this period
|
|
98
107
|
keepAliveMsecs: 15_000,
|
|
@@ -119,22 +128,22 @@ export class HttpClient {
|
|
|
119
128
|
// Works only in Node. Cannot be set in browser
|
|
120
129
|
const isAtHome = !!process.env[APIFY_ENV_VARS.IS_AT_HOME];
|
|
121
130
|
let userAgent = `ApifyClient/${version} (${os.platform()}; Node/${process.version}); isAtHome/${isAtHome}`;
|
|
122
|
-
if (this
|
|
123
|
-
userAgent += `; ${asArray(this
|
|
131
|
+
if (this.#userAgentSuffix) {
|
|
132
|
+
userAgent += `; ${asArray(this.#userAgentSuffix).join('; ')}`;
|
|
124
133
|
}
|
|
125
134
|
this.axios.defaults.headers['User-Agent'] = userAgent;
|
|
126
135
|
}
|
|
127
136
|
async call(config) {
|
|
128
|
-
await this
|
|
137
|
+
await this.#ensureNodeInit();
|
|
129
138
|
this.stats.calls++;
|
|
130
|
-
const makeRequest = this
|
|
139
|
+
const makeRequest = this.#createRequestHandler(config);
|
|
131
140
|
return retry(makeRequest, {
|
|
132
141
|
retries: this.maxRetries,
|
|
133
142
|
minTimeout: this.minDelayBetweenRetriesMillis,
|
|
134
|
-
onRetry: this
|
|
143
|
+
onRetry: (error, attempt) => this.#onRequestRetry(error, attempt),
|
|
135
144
|
});
|
|
136
145
|
}
|
|
137
|
-
|
|
146
|
+
#informAboutStreamNoRetry() {
|
|
138
147
|
this.logger.warningOnce('Request body was a stream - retrying will not work, as part of it was already consumed.');
|
|
139
148
|
this.logger.warningOnce('If you want Apify client to handle retries for you, collect the stream into a buffer before sending it.');
|
|
140
149
|
}
|
|
@@ -143,7 +152,8 @@ export class HttpClient {
|
|
|
143
152
|
* status codes are retried. See the following functions for the
|
|
144
153
|
* retrying logic.
|
|
145
154
|
*/
|
|
146
|
-
|
|
155
|
+
#createRequestHandler(config) {
|
|
156
|
+
const { timeoutSecs = 'medium', ...axiosConfig } = config;
|
|
147
157
|
const makeRequest = async (stopTrying, attempt) => {
|
|
148
158
|
this.stats.requests++;
|
|
149
159
|
let response;
|
|
@@ -153,24 +163,25 @@ export class HttpClient {
|
|
|
153
163
|
// Handling redirects is not possible without buffering - part of the stream has already been sent and can't be recovered
|
|
154
164
|
// when server sends the redirect. Therefore we need to override this in Axios config to prevent it from buffering the body.
|
|
155
165
|
// see also axios/axios#1045
|
|
156
|
-
|
|
166
|
+
axiosConfig.maxRedirects = 0;
|
|
157
167
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
response = await this.axios.request({
|
|
169
|
+
...axiosConfig,
|
|
170
|
+
timeout: this.#computeTimeoutMillis(timeoutSecs, attempt),
|
|
171
|
+
});
|
|
172
|
+
if (this.#isStatusOk(response.status))
|
|
162
173
|
return response;
|
|
163
174
|
}
|
|
164
175
|
catch (err) {
|
|
165
|
-
return cast(this
|
|
176
|
+
return cast(this.#handleRequestError(err, config, stopTrying));
|
|
166
177
|
}
|
|
167
178
|
if (response.status === RATE_LIMIT_EXCEEDED_STATUS_CODE) {
|
|
168
179
|
this.stats.addRateLimitError(attempt);
|
|
169
180
|
}
|
|
170
181
|
const apiError = ApifyApiError.fromResponse(response, attempt);
|
|
171
|
-
if (this
|
|
182
|
+
if (this.#isStatusCodeRetryable(response.status)) {
|
|
172
183
|
if (requestIsStream) {
|
|
173
|
-
this
|
|
184
|
+
this.#informAboutStreamNoRetry();
|
|
174
185
|
}
|
|
175
186
|
else {
|
|
176
187
|
// allow a retry
|
|
@@ -182,20 +193,38 @@ export class HttpClient {
|
|
|
182
193
|
};
|
|
183
194
|
return makeRequest;
|
|
184
195
|
}
|
|
185
|
-
|
|
196
|
+
#isStatusOk(statusCode) {
|
|
186
197
|
return statusCode < 300;
|
|
187
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Resolves `timeoutSecs` to the number of milliseconds the given attempt gets. A tier name resolves to
|
|
201
|
+
* its configured duration, a number is taken as seconds, and `'noTimeout'` becomes `0`, which axios reads
|
|
202
|
+
* as no timeout. The result doubles with each attempt and is capped at `timeoutMaxMillis`. A requested
|
|
203
|
+
* value above the cap is capped too, which warns once, since it does not take effect in full.
|
|
204
|
+
*/
|
|
205
|
+
#computeTimeoutMillis(timeoutSecs, attempt) {
|
|
206
|
+
if (timeoutSecs === 'noTimeout')
|
|
207
|
+
return 0;
|
|
208
|
+
const requestedMillis = typeof timeoutSecs === 'number' ? timeoutSecs * 1000 : this.timeoutMillis[timeoutSecs];
|
|
209
|
+
if (requestedMillis > this.timeoutMaxMillis) {
|
|
210
|
+
// `warningOnce` keys by message, so each requested value warns once.
|
|
211
|
+
this.logger.warningOnce(`The requested timeout of ${requestedMillis / 1000}s exceeds timeoutMaxSecs ` +
|
|
212
|
+
`(${this.timeoutMaxMillis / 1000}s) and is capped at it. ` +
|
|
213
|
+
'Raise timeoutMaxSecs on the client to allow longer request timeouts.');
|
|
214
|
+
}
|
|
215
|
+
return Math.min(requestedMillis * 2 ** (attempt - 1), this.timeoutMaxMillis);
|
|
216
|
+
}
|
|
188
217
|
/**
|
|
189
218
|
* Handles all unexpected errors that can happen, but are not
|
|
190
219
|
* Apify API typed errors. E.g. network errors, timeouts and so on.
|
|
191
220
|
*/
|
|
192
|
-
|
|
193
|
-
if (this
|
|
221
|
+
#handleRequestError(err, config, stopTrying) {
|
|
222
|
+
if (this.#isTimeoutError(err) && config.doNotRetryTimeouts) {
|
|
194
223
|
return stopTrying(err);
|
|
195
224
|
}
|
|
196
|
-
if (this
|
|
225
|
+
if (this.#isRetryableError(err)) {
|
|
197
226
|
if (isStream(config.data)) {
|
|
198
|
-
this
|
|
227
|
+
this.#informAboutStreamNoRetry();
|
|
199
228
|
}
|
|
200
229
|
else {
|
|
201
230
|
throw err;
|
|
@@ -207,7 +236,7 @@ export class HttpClient {
|
|
|
207
236
|
* Axios calls req.abort() on timeouts so timeout errors will
|
|
208
237
|
* have a code ECONNABORTED.
|
|
209
238
|
*/
|
|
210
|
-
|
|
239
|
+
#isTimeoutError(err) {
|
|
211
240
|
return err.code === 'ECONNABORTED';
|
|
212
241
|
}
|
|
213
242
|
/**
|
|
@@ -216,15 +245,15 @@ export class HttpClient {
|
|
|
216
245
|
* @param {Error} err
|
|
217
246
|
* @private
|
|
218
247
|
*/
|
|
219
|
-
|
|
220
|
-
return this
|
|
248
|
+
#isRetryableError(err) {
|
|
249
|
+
return this.#isNetworkError(err) || this.#isResponseBodyInvalid(err);
|
|
221
250
|
}
|
|
222
251
|
/**
|
|
223
252
|
* When a network connection to our API is interrupted in the middle of streaming
|
|
224
253
|
* a response, the request often does not fail, but simply contains
|
|
225
254
|
* an incomplete response. This can often be fixed by retrying.
|
|
226
255
|
*/
|
|
227
|
-
|
|
256
|
+
#isResponseBodyInvalid(err) {
|
|
228
257
|
return err instanceof InvalidResponseBodyError;
|
|
229
258
|
}
|
|
230
259
|
/**
|
|
@@ -232,7 +261,7 @@ export class HttpClient {
|
|
|
232
261
|
* it throws an AxiosError, which will have the request
|
|
233
262
|
* and config (and other) properties.
|
|
234
263
|
*/
|
|
235
|
-
|
|
264
|
+
#isNetworkError(err) {
|
|
236
265
|
const hasRequest = err.request && typeof err.request === 'object';
|
|
237
266
|
const hasConfig = err.config && typeof err.config === 'object';
|
|
238
267
|
return hasRequest && hasConfig;
|
|
@@ -242,12 +271,12 @@ export class HttpClient {
|
|
|
242
271
|
* For status codes 300-499 (except 429) we do not retry the request,
|
|
243
272
|
* because it's probably caused by invalid url (redirect 3xx) or invalid user input (4xx).
|
|
244
273
|
*/
|
|
245
|
-
|
|
274
|
+
#isStatusCodeRetryable(statusCode) {
|
|
246
275
|
const isRateLimitError = statusCode === RATE_LIMIT_EXCEEDED_STATUS_CODE;
|
|
247
276
|
const isInternalError = statusCode >= 500;
|
|
248
277
|
return isRateLimitError || isInternalError;
|
|
249
278
|
}
|
|
250
|
-
|
|
279
|
+
#onRequestRetry(error, attempt) {
|
|
251
280
|
if (attempt === Math.round(this.maxRetries / 2)) {
|
|
252
281
|
this.logger.warning(`API request failed ${attempt} times. Max attempts: ${this.maxRetries + 1}.\nCause:${error.stack}`);
|
|
253
282
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -31,3 +31,4 @@ export { ArgumentValidationError } from '@apify/validations';
|
|
|
31
31
|
export * from './response_validation_error.js';
|
|
32
32
|
export { InvalidResponseBodyError } from './interceptors.js';
|
|
33
33
|
export type { PaginatedList, Dictionary } from './utils.js';
|
|
34
|
+
export type { Timeout, TimeoutOptions, TimeoutTier } from './timeouts.js';
|
|
@@ -3,6 +3,7 @@ import { Log } from '@apify/log';
|
|
|
3
3
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
4
4
|
import { ResourceClient } from '../base/resource_client.js';
|
|
5
5
|
import type { Actor, ActorRun } from '../models.js';
|
|
6
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
6
7
|
import { ActorVersionClient } from './actor_version.js';
|
|
7
8
|
import { ActorVersionCollectionClient } from './actor_version_collection.js';
|
|
8
9
|
import type { Build, BuildClientGetOptions } from './build.js';
|
|
@@ -42,24 +43,30 @@ export declare class ActorClient extends ResourceClient {
|
|
|
42
43
|
/**
|
|
43
44
|
* Gets the Actor object from the Apify API.
|
|
44
45
|
*
|
|
46
|
+
* @param options - Request options
|
|
47
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
45
48
|
* @returns The Actor object, or `undefined` if it does not exist
|
|
46
49
|
* @see https://docs.apify.com/api/v2/act-get
|
|
47
50
|
*/
|
|
48
|
-
get(): Promise<Actor | undefined>;
|
|
51
|
+
get(options?: TimeoutOptions): Promise<Actor | undefined>;
|
|
49
52
|
/**
|
|
50
53
|
* Updates the Actor with specified fields.
|
|
51
54
|
*
|
|
52
55
|
* @param newFields - Fields to update in the Actor
|
|
56
|
+
* @param options - Request options
|
|
57
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
53
58
|
* @returns The updated Actor object
|
|
54
59
|
* @see https://docs.apify.com/api/v2/act-put
|
|
55
60
|
*/
|
|
56
|
-
update(newFields: ActorUpdateOptions): Promise<Actor>;
|
|
61
|
+
update(newFields: ActorUpdateOptions, options?: TimeoutOptions): Promise<Actor>;
|
|
57
62
|
/**
|
|
58
63
|
* Deletes the Actor.
|
|
59
64
|
*
|
|
65
|
+
* @param options - Request options
|
|
66
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
60
67
|
* @see https://docs.apify.com/api/v2/act-delete
|
|
61
68
|
*/
|
|
62
|
-
delete(): Promise<void>;
|
|
69
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
63
70
|
/**
|
|
64
71
|
* Starts the Actor and immediately returns the Run object.
|
|
65
72
|
*
|
|
@@ -71,11 +78,13 @@ export declare class ActorClient extends ResourceClient {
|
|
|
71
78
|
* @param options - Run configuration options
|
|
72
79
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`). If not provided, uses the default build.
|
|
73
80
|
* @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
|
|
74
|
-
* @param options.
|
|
81
|
+
* @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
|
|
75
82
|
* @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the run to finish on the API side before returning. Default is 0 (returns immediately).
|
|
76
83
|
* @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
|
|
77
84
|
* @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
|
|
78
85
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
|
|
86
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
87
|
+
* when the API is asked to hold the response.
|
|
79
88
|
* @returns The Actor run object with status, usage, and storage IDs
|
|
80
89
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
81
90
|
*
|
|
@@ -88,7 +97,7 @@ export declare class ActorClient extends ResourceClient {
|
|
|
88
97
|
* // Start Actor with specific build and memory
|
|
89
98
|
* const run = await client.actor('my-actor').start(
|
|
90
99
|
* { url: 'https://example.com' },
|
|
91
|
-
* { build: '0.1.2', memory: 512,
|
|
100
|
+
* { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
|
|
92
101
|
* );
|
|
93
102
|
* ```
|
|
94
103
|
*/
|
|
@@ -106,7 +115,8 @@ export declare class ActorClient extends ResourceClient {
|
|
|
106
115
|
* @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
|
|
107
116
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
|
|
108
117
|
* @param options.memory - Memory in megabytes allocated for the run.
|
|
109
|
-
* @param options.
|
|
118
|
+
* @param options.runTimeoutSecs - Maximum run duration in seconds.
|
|
119
|
+
* @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
|
|
110
120
|
* @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
|
|
111
121
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
112
122
|
*
|
|
@@ -142,6 +152,7 @@ export declare class ActorClient extends ResourceClient {
|
|
|
142
152
|
* @param options - Validation options
|
|
143
153
|
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
144
154
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
155
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
145
156
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
146
157
|
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
147
158
|
*
|
|
@@ -171,6 +182,8 @@ export declare class ActorClient extends ResourceClient {
|
|
|
171
182
|
* @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
|
|
172
183
|
* @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
|
|
173
184
|
* @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the build to finish on the API side before returning. Default is 0 (returns immediately).
|
|
185
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
186
|
+
* when the API is asked to hold the response.
|
|
174
187
|
* @returns The Build object with status and build details
|
|
175
188
|
* @see https://docs.apify.com/api/v2/act-builds-post
|
|
176
189
|
*
|
|
@@ -198,6 +211,8 @@ export declare class ActorClient extends ResourceClient {
|
|
|
198
211
|
*
|
|
199
212
|
* @param options - Options for getting the default build
|
|
200
213
|
* @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the build to finish on the API side before returning. Default is 0 (returns immediately).
|
|
214
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
215
|
+
* when the API is asked to hold the response.
|
|
201
216
|
* @returns A client for the default build
|
|
202
217
|
* @see https://docs.apify.com/api/v2/act-build-default-get
|
|
203
218
|
*
|
|
@@ -282,7 +297,7 @@ export type ActorUpdateOptions = Partial<Pick<Actor, 'name' | 'description' | 'i
|
|
|
282
297
|
* `Dictionary`, which would reject a caller's own `interface`.
|
|
283
298
|
*/
|
|
284
299
|
export type ActorInput = object;
|
|
285
|
-
export interface ActorStartOptions {
|
|
300
|
+
export interface ActorStartOptions extends TimeoutOptions {
|
|
286
301
|
/**
|
|
287
302
|
* Tag or number of the Actor build to run (e.g. `beta` or `1.2.345`).
|
|
288
303
|
* If not provided, the run uses build tag or number from the default Actor run configuration (typically `latest`).
|
|
@@ -301,9 +316,9 @@ export interface ActorStartOptions {
|
|
|
301
316
|
memory?: number;
|
|
302
317
|
/**
|
|
303
318
|
* Timeout for the Actor run in seconds. Zero value means there is no timeout.
|
|
304
|
-
* If not provided, the run uses timeout of the default Actor run configuration.
|
|
319
|
+
* If not provided, the run uses the timeout of the default Actor run configuration.
|
|
305
320
|
*/
|
|
306
|
-
|
|
321
|
+
runTimeoutSecs?: number;
|
|
307
322
|
/**
|
|
308
323
|
* Maximum time to wait for the Actor run to finish, in seconds.
|
|
309
324
|
* If the limit is reached, the returned promise is resolved to a run object that will have
|
|
@@ -370,7 +385,7 @@ export interface ActorCallOptions extends Omit<ActorStartOptions, 'waitForFinish
|
|
|
370
385
|
* Options for validating an Actor input.
|
|
371
386
|
* @since Added in 2.24.0
|
|
372
387
|
*/
|
|
373
|
-
export interface ActorValidateInputOptions {
|
|
388
|
+
export interface ActorValidateInputOptions extends TimeoutOptions {
|
|
374
389
|
/**
|
|
375
390
|
* Tag or number of the Actor build whose input schema the input is validated against
|
|
376
391
|
* (e.g. `beta` or `1.2.345`). If not provided, the default build is used.
|
|
@@ -386,7 +401,7 @@ export interface ActorValidateInputOptions {
|
|
|
386
401
|
/**
|
|
387
402
|
* Options for building an Actor.
|
|
388
403
|
*/
|
|
389
|
-
export interface ActorBuildOptions {
|
|
404
|
+
export interface ActorBuildOptions extends TimeoutOptions {
|
|
390
405
|
betaPackages?: boolean;
|
|
391
406
|
tag?: string;
|
|
392
407
|
useCache?: boolean;
|