apify-client 3.0.0-beta.14 → 3.0.0-beta.16
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.js +23 -7
- 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 +24 -16
- 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 +13 -13
- package/dist/bundle.js.map +1 -1
- package/dist/http_client.d.ts +34 -13
- package/dist/http_client.js +58 -28
- 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 +65 -37
- 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 +4 -1
- package/dist/resource_clients/log.js +15 -6
- package/dist/resource_clients/request_queue.d.ts +52 -18
- package/dist/resource_clients/request_queue.js +114 -60
- 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/timeouts.d.ts +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +10 -0
- package/package.json +1 -1
package/dist/http_client.d.ts
CHANGED
|
@@ -4,13 +4,17 @@ 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 {
|
|
8
9
|
stats: Statistics;
|
|
9
10
|
maxRetries: number;
|
|
10
11
|
minDelayBetweenRetriesMillis: number;
|
|
11
12
|
userProvidedRequestInterceptors: RequestInterceptorFunction[];
|
|
12
13
|
logger: Log;
|
|
13
|
-
|
|
14
|
+
/** Duration of each timeout tier, in milliseconds. */
|
|
15
|
+
timeoutMillis: Record<TimeoutTier, number>;
|
|
16
|
+
/** Cap on the timeout of a single request attempt, in milliseconds. */
|
|
17
|
+
timeoutMaxMillis: number;
|
|
14
18
|
httpAgent?: http.Agent;
|
|
15
19
|
httpsAgent?: https.Agent;
|
|
16
20
|
axios: AxiosInstance;
|
|
@@ -21,55 +25,69 @@ export declare class HttpClient {
|
|
|
21
25
|
private ensureNodeInit;
|
|
22
26
|
private initNode;
|
|
23
27
|
call<T = any>(config: ApifyRequestConfig): Promise<ApifyResponse<T>>;
|
|
24
|
-
private
|
|
28
|
+
private informAboutStreamNoRetry;
|
|
25
29
|
/**
|
|
26
30
|
* Successful responses are returned, errors and unsuccessful
|
|
27
31
|
* status codes are retried. See the following functions for the
|
|
28
32
|
* retrying logic.
|
|
29
33
|
*/
|
|
30
|
-
private
|
|
31
|
-
private
|
|
34
|
+
private createRequestHandler;
|
|
35
|
+
private isStatusOk;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves `timeoutSecs` to the number of milliseconds the given attempt gets. A tier name resolves to
|
|
38
|
+
* its configured duration, a number is taken as seconds, and `'noTimeout'` becomes `0`, which axios reads
|
|
39
|
+
* as no timeout. The result doubles with each attempt and is capped at `timeoutMaxMillis`. A requested
|
|
40
|
+
* value above the cap is capped too, which warns once, since it does not take effect in full.
|
|
41
|
+
*/
|
|
42
|
+
private computeTimeoutMillis;
|
|
32
43
|
/**
|
|
33
44
|
* Handles all unexpected errors that can happen, but are not
|
|
34
45
|
* Apify API typed errors. E.g. network errors, timeouts and so on.
|
|
35
46
|
*/
|
|
36
|
-
private
|
|
47
|
+
private handleRequestError;
|
|
37
48
|
/**
|
|
38
49
|
* Axios calls req.abort() on timeouts so timeout errors will
|
|
39
50
|
* have a code ECONNABORTED.
|
|
40
51
|
*/
|
|
41
|
-
private
|
|
52
|
+
private isTimeoutError;
|
|
42
53
|
/**
|
|
43
54
|
* We don't want to retry every exception thrown from Axios.
|
|
44
55
|
* The common denominator for retryable errors are network issues.
|
|
45
56
|
* @param {Error} err
|
|
46
57
|
* @private
|
|
47
58
|
*/
|
|
48
|
-
private
|
|
59
|
+
private isRetryableError;
|
|
49
60
|
/**
|
|
50
61
|
* When a network connection to our API is interrupted in the middle of streaming
|
|
51
62
|
* a response, the request often does not fail, but simply contains
|
|
52
63
|
* an incomplete response. This can often be fixed by retrying.
|
|
53
64
|
*/
|
|
54
|
-
private
|
|
65
|
+
private isResponseBodyInvalid;
|
|
55
66
|
/**
|
|
56
67
|
* When a network request is attempted by axios and fails,
|
|
57
68
|
* it throws an AxiosError, which will have the request
|
|
58
69
|
* and config (and other) properties.
|
|
59
70
|
*/
|
|
60
|
-
private
|
|
71
|
+
private isNetworkError;
|
|
61
72
|
/**
|
|
62
73
|
* We retry 429 (rate limit) and 500+.
|
|
63
74
|
* For status codes 300-499 (except 429) we do not retry the request,
|
|
64
75
|
* because it's probably caused by invalid url (redirect 3xx) or invalid user input (4xx).
|
|
65
76
|
*/
|
|
66
|
-
private
|
|
67
|
-
private
|
|
77
|
+
private isStatusCodeRetryable;
|
|
78
|
+
private onRequestRetry;
|
|
68
79
|
}
|
|
69
|
-
export interface ApifyRequestConfig extends AxiosRequestConfig {
|
|
80
|
+
export interface ApifyRequestConfig extends Omit<AxiosRequestConfig, 'timeout'> {
|
|
70
81
|
stringifyFunctions?: boolean;
|
|
71
82
|
forceBuffer?: boolean;
|
|
72
83
|
doNotRetryTimeouts?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Timeout of the request: a tier name, a number of seconds, or `'noTimeout'`. The client resolves it to
|
|
86
|
+
* the axios `timeout` in milliseconds for each attempt, before axios runs its interceptors, so a request
|
|
87
|
+
* interceptor already sees a number of milliseconds.
|
|
88
|
+
* @default 'medium'
|
|
89
|
+
*/
|
|
90
|
+
timeoutSecs?: Timeout;
|
|
73
91
|
}
|
|
74
92
|
export interface ApifyResponse<T = any> extends AxiosResponse<T> {
|
|
75
93
|
config: ApifyRequestConfig & InternalAxiosRequestConfig;
|
|
@@ -79,7 +97,10 @@ export interface HttpClientOptions {
|
|
|
79
97
|
maxRetries: number;
|
|
80
98
|
minDelayBetweenRetriesMillis: number;
|
|
81
99
|
requestInterceptors: RequestInterceptorFunction[];
|
|
82
|
-
|
|
100
|
+
timeoutShortSecs: number;
|
|
101
|
+
timeoutMediumSecs: number;
|
|
102
|
+
timeoutLongSecs: number;
|
|
103
|
+
timeoutMaxSecs: number;
|
|
83
104
|
logger: Log;
|
|
84
105
|
token?: string;
|
|
85
106
|
workflowKey?: string;
|
package/dist/http_client.js
CHANGED
|
@@ -12,7 +12,10 @@ 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;
|
|
@@ -25,11 +28,16 @@ export class HttpClient {
|
|
|
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
39
|
this.userAgentSuffix = options.userAgentSuffix;
|
|
32
|
-
this.
|
|
40
|
+
this.onRequestRetry = this.onRequestRetry.bind(this);
|
|
33
41
|
this.axios = axios.create({
|
|
34
42
|
// Disable axios's built-in proxy handling since we're using custom agents
|
|
35
43
|
proxy: false,
|
|
@@ -50,7 +58,9 @@ export class HttpClient {
|
|
|
50
58
|
transformRequest: undefined,
|
|
51
59
|
transformResponse: undefined,
|
|
52
60
|
responseType: 'arraybuffer',
|
|
53
|
-
timeout
|
|
61
|
+
// Every request sets its own timeout in `createRequestHandler`, so the default only backs a raw
|
|
62
|
+
// `axios.request()` call.
|
|
63
|
+
timeout: this.timeoutMaxMillis,
|
|
54
64
|
// maxBodyLength needs to be Infinity, because -1 falls back to a 10 MB default
|
|
55
65
|
// from an axios subdependency - 'follow-redirects'
|
|
56
66
|
maxBodyLength: Infinity,
|
|
@@ -92,7 +102,7 @@ export class HttpClient {
|
|
|
92
102
|
keepAlive: true,
|
|
93
103
|
// Timeout for inactive sockets
|
|
94
104
|
// Prevents socket leaks from idle connections
|
|
95
|
-
timeout: this.
|
|
105
|
+
timeout: this.timeoutMaxMillis,
|
|
96
106
|
// Keep alive timeout for free sockets (15 seconds)
|
|
97
107
|
// Node.js will close unused sockets after this period
|
|
98
108
|
keepAliveMsecs: 15_000,
|
|
@@ -127,14 +137,14 @@ export class HttpClient {
|
|
|
127
137
|
async call(config) {
|
|
128
138
|
await this.ensureNodeInit();
|
|
129
139
|
this.stats.calls++;
|
|
130
|
-
const makeRequest = this.
|
|
140
|
+
const makeRequest = this.createRequestHandler(config);
|
|
131
141
|
return retry(makeRequest, {
|
|
132
142
|
retries: this.maxRetries,
|
|
133
143
|
minTimeout: this.minDelayBetweenRetriesMillis,
|
|
134
|
-
onRetry: this.
|
|
144
|
+
onRetry: this.onRequestRetry,
|
|
135
145
|
});
|
|
136
146
|
}
|
|
137
|
-
|
|
147
|
+
informAboutStreamNoRetry() {
|
|
138
148
|
this.logger.warningOnce('Request body was a stream - retrying will not work, as part of it was already consumed.');
|
|
139
149
|
this.logger.warningOnce('If you want Apify client to handle retries for you, collect the stream into a buffer before sending it.');
|
|
140
150
|
}
|
|
@@ -143,7 +153,8 @@ export class HttpClient {
|
|
|
143
153
|
* status codes are retried. See the following functions for the
|
|
144
154
|
* retrying logic.
|
|
145
155
|
*/
|
|
146
|
-
|
|
156
|
+
createRequestHandler(config) {
|
|
157
|
+
const { timeoutSecs = 'medium', ...axiosConfig } = config;
|
|
147
158
|
const makeRequest = async (stopTrying, attempt) => {
|
|
148
159
|
this.stats.requests++;
|
|
149
160
|
let response;
|
|
@@ -153,24 +164,25 @@ export class HttpClient {
|
|
|
153
164
|
// Handling redirects is not possible without buffering - part of the stream has already been sent and can't be recovered
|
|
154
165
|
// when server sends the redirect. Therefore we need to override this in Axios config to prevent it from buffering the body.
|
|
155
166
|
// see also axios/axios#1045
|
|
156
|
-
|
|
167
|
+
axiosConfig.maxRedirects = 0;
|
|
157
168
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
169
|
+
response = await this.axios.request({
|
|
170
|
+
...axiosConfig,
|
|
171
|
+
timeout: this.computeTimeoutMillis(timeoutSecs, attempt),
|
|
172
|
+
});
|
|
173
|
+
if (this.isStatusOk(response.status))
|
|
162
174
|
return response;
|
|
163
175
|
}
|
|
164
176
|
catch (err) {
|
|
165
|
-
return cast(this.
|
|
177
|
+
return cast(this.handleRequestError(err, config, stopTrying));
|
|
166
178
|
}
|
|
167
179
|
if (response.status === RATE_LIMIT_EXCEEDED_STATUS_CODE) {
|
|
168
180
|
this.stats.addRateLimitError(attempt);
|
|
169
181
|
}
|
|
170
182
|
const apiError = ApifyApiError.fromResponse(response, attempt);
|
|
171
|
-
if (this.
|
|
183
|
+
if (this.isStatusCodeRetryable(response.status)) {
|
|
172
184
|
if (requestIsStream) {
|
|
173
|
-
this.
|
|
185
|
+
this.informAboutStreamNoRetry();
|
|
174
186
|
}
|
|
175
187
|
else {
|
|
176
188
|
// allow a retry
|
|
@@ -182,20 +194,38 @@ export class HttpClient {
|
|
|
182
194
|
};
|
|
183
195
|
return makeRequest;
|
|
184
196
|
}
|
|
185
|
-
|
|
197
|
+
isStatusOk(statusCode) {
|
|
186
198
|
return statusCode < 300;
|
|
187
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Resolves `timeoutSecs` to the number of milliseconds the given attempt gets. A tier name resolves to
|
|
202
|
+
* its configured duration, a number is taken as seconds, and `'noTimeout'` becomes `0`, which axios reads
|
|
203
|
+
* as no timeout. The result doubles with each attempt and is capped at `timeoutMaxMillis`. A requested
|
|
204
|
+
* value above the cap is capped too, which warns once, since it does not take effect in full.
|
|
205
|
+
*/
|
|
206
|
+
computeTimeoutMillis(timeoutSecs, attempt) {
|
|
207
|
+
if (timeoutSecs === 'noTimeout')
|
|
208
|
+
return 0;
|
|
209
|
+
const requestedMillis = typeof timeoutSecs === 'number' ? timeoutSecs * 1000 : this.timeoutMillis[timeoutSecs];
|
|
210
|
+
if (requestedMillis > this.timeoutMaxMillis) {
|
|
211
|
+
// `warningOnce` keys by message, so each requested value warns once.
|
|
212
|
+
this.logger.warningOnce(`The requested timeout of ${requestedMillis / 1000}s exceeds timeoutMaxSecs ` +
|
|
213
|
+
`(${this.timeoutMaxMillis / 1000}s) and is capped at it. ` +
|
|
214
|
+
'Raise timeoutMaxSecs on the client to allow longer request timeouts.');
|
|
215
|
+
}
|
|
216
|
+
return Math.min(requestedMillis * 2 ** (attempt - 1), this.timeoutMaxMillis);
|
|
217
|
+
}
|
|
188
218
|
/**
|
|
189
219
|
* Handles all unexpected errors that can happen, but are not
|
|
190
220
|
* Apify API typed errors. E.g. network errors, timeouts and so on.
|
|
191
221
|
*/
|
|
192
|
-
|
|
193
|
-
if (this.
|
|
222
|
+
handleRequestError(err, config, stopTrying) {
|
|
223
|
+
if (this.isTimeoutError(err) && config.doNotRetryTimeouts) {
|
|
194
224
|
return stopTrying(err);
|
|
195
225
|
}
|
|
196
|
-
if (this.
|
|
226
|
+
if (this.isRetryableError(err)) {
|
|
197
227
|
if (isStream(config.data)) {
|
|
198
|
-
this.
|
|
228
|
+
this.informAboutStreamNoRetry();
|
|
199
229
|
}
|
|
200
230
|
else {
|
|
201
231
|
throw err;
|
|
@@ -207,7 +237,7 @@ export class HttpClient {
|
|
|
207
237
|
* Axios calls req.abort() on timeouts so timeout errors will
|
|
208
238
|
* have a code ECONNABORTED.
|
|
209
239
|
*/
|
|
210
|
-
|
|
240
|
+
isTimeoutError(err) {
|
|
211
241
|
return err.code === 'ECONNABORTED';
|
|
212
242
|
}
|
|
213
243
|
/**
|
|
@@ -216,15 +246,15 @@ export class HttpClient {
|
|
|
216
246
|
* @param {Error} err
|
|
217
247
|
* @private
|
|
218
248
|
*/
|
|
219
|
-
|
|
220
|
-
return this.
|
|
249
|
+
isRetryableError(err) {
|
|
250
|
+
return this.isNetworkError(err) || this.isResponseBodyInvalid(err);
|
|
221
251
|
}
|
|
222
252
|
/**
|
|
223
253
|
* When a network connection to our API is interrupted in the middle of streaming
|
|
224
254
|
* a response, the request often does not fail, but simply contains
|
|
225
255
|
* an incomplete response. This can often be fixed by retrying.
|
|
226
256
|
*/
|
|
227
|
-
|
|
257
|
+
isResponseBodyInvalid(err) {
|
|
228
258
|
return err instanceof InvalidResponseBodyError;
|
|
229
259
|
}
|
|
230
260
|
/**
|
|
@@ -232,7 +262,7 @@ export class HttpClient {
|
|
|
232
262
|
* it throws an AxiosError, which will have the request
|
|
233
263
|
* and config (and other) properties.
|
|
234
264
|
*/
|
|
235
|
-
|
|
265
|
+
isNetworkError(err) {
|
|
236
266
|
const hasRequest = err.request && typeof err.request === 'object';
|
|
237
267
|
const hasConfig = err.config && typeof err.config === 'object';
|
|
238
268
|
return hasRequest && hasConfig;
|
|
@@ -242,12 +272,12 @@ export class HttpClient {
|
|
|
242
272
|
* For status codes 300-499 (except 429) we do not retry the request,
|
|
243
273
|
* because it's probably caused by invalid url (redirect 3xx) or invalid user input (4xx).
|
|
244
274
|
*/
|
|
245
|
-
|
|
275
|
+
isStatusCodeRetryable(statusCode) {
|
|
246
276
|
const isRateLimitError = statusCode === RATE_LIMIT_EXCEEDED_STATUS_CODE;
|
|
247
277
|
const isInternalError = statusCode >= 500;
|
|
248
278
|
return isRateLimitError || isInternalError;
|
|
249
279
|
}
|
|
250
|
-
|
|
280
|
+
onRequestRetry(error, attempt) {
|
|
251
281
|
if (attempt === Math.round(this.maxRetries / 2)) {
|
|
252
282
|
this.logger.warning(`API request failed ${attempt} times. Max attempts: ${this.maxRetries + 1}.\nCause:${error.stack}`);
|
|
253
283
|
}
|
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;
|