apify-client 3.0.0-beta.4 → 3.0.0-beta.41
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/README.md +13 -3
- package/dist/apify_api_error.d.ts +62 -21
- package/dist/apify_api_error.js +96 -23
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +24 -16
- package/dist/base/resource_client.d.ts +23 -9
- package/dist/base/resource_client.js +57 -29
- package/dist/base/resource_collection_client.d.ts +8 -4
- package/dist/base/resource_collection_client.js +26 -15
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +29 -22
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +887 -322
- package/dist/generated/schemas.d.ts +6717 -0
- package/dist/generated/schemas.js +1527 -0
- package/dist/http_clients/axios.d.ts +60 -0
- package/dist/http_clients/axios.js +117 -0
- package/dist/http_clients/base.d.ts +333 -0
- package/dist/http_clients/base.js +563 -0
- package/dist/http_clients/index.d.ts +4 -0
- package/dist/http_clients/index.js +2 -0
- package/dist/http_compressors/base.d.ts +40 -0
- package/dist/http_compressors/base.js +9 -0
- package/dist/http_compressors/brotli.d.ts +33 -0
- package/dist/http_compressors/brotli.js +39 -0
- package/dist/http_compressors/gzip.d.ts +33 -0
- package/dist/http_compressors/gzip.js +39 -0
- package/dist/http_compressors/index.d.ts +6 -0
- package/dist/http_compressors/index.js +2 -0
- package/dist/http_compressors/resolve.d.ts +23 -0
- package/dist/http_compressors/resolve.js +27 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -1
- package/dist/invalid_response_body_error.d.ts +13 -0
- package/dist/invalid_response_body_error.js +17 -0
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +33 -61
- package/dist/resource_clients/actor.d.ts +52 -31
- package/dist/resource_clients/actor.js +81 -58
- package/dist/resource_clients/actor_collection.d.ts +9 -5
- package/dist/resource_clients/actor_collection.js +12 -3
- package/dist/resource_clients/actor_env_var.d.ts +10 -3
- package/dist/resource_clients/actor_env_var.js +17 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
- package/dist/resource_clients/actor_env_var_collection.js +18 -11
- package/dist/resource_clients/actor_version.d.ts +18 -3
- package/dist/resource_clients/actor_version.js +20 -9
- package/dist/resource_clients/actor_version_collection.d.ts +16 -17
- package/dist/resource_clients/actor_version_collection.js +20 -11
- package/dist/resource_clients/build.d.ts +18 -6
- package/dist/resource_clients/build.js +37 -17
- package/dist/resource_clients/build_collection.d.ts +3 -1
- package/dist/resource_clients/build_collection.js +5 -1
- package/dist/resource_clients/dataset.d.ts +49 -31
- package/dist/resource_clients/dataset.js +102 -76
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +14 -2
- package/dist/resource_clients/key_value_store.d.ts +58 -16
- package/dist/resource_clients/key_value_store.js +80 -41
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +14 -2
- package/dist/resource_clients/log.d.ts +11 -19
- package/dist/resource_clients/log.js +64 -46
- package/dist/resource_clients/request_queue.d.ts +56 -26
- package/dist/resource_clients/request_queue.js +197 -116
- package/dist/resource_clients/request_queue_collection.d.ts +6 -2
- package/dist/resource_clients/request_queue_collection.js +10 -3
- package/dist/resource_clients/run.d.ts +53 -18
- package/dist/resource_clients/run.js +94 -47
- package/dist/resource_clients/run_collection.d.ts +3 -1
- package/dist/resource_clients/run_collection.js +5 -1
- package/dist/resource_clients/schedule.d.ts +16 -7
- package/dist/resource_clients/schedule.js +32 -21
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +10 -3
- package/dist/resource_clients/store_collection.d.ts +3 -1
- package/dist/resource_clients/store_collection.js +5 -1
- package/dist/resource_clients/task.d.ts +28 -10
- package/dist/resource_clients/task.js +71 -46
- package/dist/resource_clients/task_collection.d.ts +6 -2
- package/dist/resource_clients/task_collection.js +10 -3
- package/dist/resource_clients/user.d.ts +17 -8
- package/dist/resource_clients/user.js +43 -39
- package/dist/resource_clients/webhook.d.ts +14 -5
- package/dist/resource_clients/webhook.js +31 -22
- package/dist/resource_clients/webhook_collection.d.ts +6 -2
- package/dist/resource_clients/webhook_collection.js +10 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +8 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
- package/dist/response_validation_error.d.ts +26 -0
- package/dist/response_validation_error.js +37 -0
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +49 -0
- package/dist/runtime/types.d.ts +52 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +18 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.js +15 -0
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/utils.d.ts +86 -46
- package/dist/utils.js +218 -164
- package/package.json +32 -29
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -255
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -105
|
@@ -3,6 +3,8 @@ 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';
|
|
7
|
+
import type { Dictionary } from '../utils.js';
|
|
6
8
|
import { ActorVersionClient } from './actor_version.js';
|
|
7
9
|
import { ActorVersionCollectionClient } from './actor_version_collection.js';
|
|
8
10
|
import type { Build, BuildClientGetOptions } from './build.js';
|
|
@@ -42,24 +44,30 @@ export declare class ActorClient extends ResourceClient {
|
|
|
42
44
|
/**
|
|
43
45
|
* Gets the Actor object from the Apify API.
|
|
44
46
|
*
|
|
47
|
+
* @param options - Request options
|
|
48
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
45
49
|
* @returns The Actor object, or `undefined` if it does not exist
|
|
46
50
|
* @see https://docs.apify.com/api/v2/act-get
|
|
47
51
|
*/
|
|
48
|
-
get(): Promise<Actor | undefined>;
|
|
52
|
+
get(options?: TimeoutOptions): Promise<Actor | undefined>;
|
|
49
53
|
/**
|
|
50
54
|
* Updates the Actor with specified fields.
|
|
51
55
|
*
|
|
52
56
|
* @param newFields - Fields to update in the Actor
|
|
57
|
+
* @param options - Request options
|
|
58
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
53
59
|
* @returns The updated Actor object
|
|
54
60
|
* @see https://docs.apify.com/api/v2/act-put
|
|
55
61
|
*/
|
|
56
|
-
update(newFields: ActorUpdateOptions): Promise<Actor>;
|
|
62
|
+
update(newFields: ActorUpdateOptions, options?: TimeoutOptions): Promise<Actor>;
|
|
57
63
|
/**
|
|
58
64
|
* Deletes the Actor.
|
|
59
65
|
*
|
|
66
|
+
* @param options - Request options
|
|
67
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
60
68
|
* @see https://docs.apify.com/api/v2/act-delete
|
|
61
69
|
*/
|
|
62
|
-
delete(): Promise<void>;
|
|
70
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
63
71
|
/**
|
|
64
72
|
* Starts the Actor and immediately returns the Run object.
|
|
65
73
|
*
|
|
@@ -67,17 +75,18 @@ export declare class ActorClient extends ResourceClient {
|
|
|
67
75
|
* asynchronously and this method returns immediately without waiting for completion.
|
|
68
76
|
* Use the {@link call} method if you want to wait for the Actor to finish.
|
|
69
77
|
*
|
|
70
|
-
* @param input - Input for the Actor
|
|
71
|
-
*
|
|
78
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
79
|
+
* Omit it to run the Actor without input.
|
|
72
80
|
* @param options - Run configuration options
|
|
73
81
|
* @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.
|
|
74
82
|
* @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
|
|
75
|
-
* @param options.
|
|
83
|
+
* @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
|
|
76
84
|
* @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).
|
|
77
85
|
* @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
|
|
78
86
|
* @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
|
|
79
87
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
|
|
80
|
-
* @param options.
|
|
88
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
89
|
+
* when the API is asked to hold the response.
|
|
81
90
|
* @returns The Actor run object with status, usage, and storage IDs
|
|
82
91
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
83
92
|
*
|
|
@@ -90,11 +99,11 @@ export declare class ActorClient extends ResourceClient {
|
|
|
90
99
|
* // Start Actor with specific build and memory
|
|
91
100
|
* const run = await client.actor('my-actor').start(
|
|
92
101
|
* { url: 'https://example.com' },
|
|
93
|
-
* { build: '0.1.2', memory: 512,
|
|
102
|
+
* { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
|
|
94
103
|
* );
|
|
95
104
|
* ```
|
|
96
105
|
*/
|
|
97
|
-
start(input?:
|
|
106
|
+
start(input?: ActorInput, options?: ActorStartOptions): Promise<ActorRun>;
|
|
98
107
|
/**
|
|
99
108
|
* Starts the Actor and waits for it to finish before returning the Run object.
|
|
100
109
|
*
|
|
@@ -102,14 +111,15 @@ export declare class ActorClient extends ResourceClient {
|
|
|
102
111
|
* by polling the run status. It optionally streams logs to the console or a custom Log instance.
|
|
103
112
|
* By default, it waits indefinitely unless the `waitSecs` option is provided.
|
|
104
113
|
*
|
|
105
|
-
* @param input - Input for the Actor
|
|
106
|
-
*
|
|
114
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
115
|
+
* Omit it to run the Actor without input.
|
|
107
116
|
* @param options - Run configuration options (extends all options from {@link start})
|
|
108
117
|
* @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
|
|
109
118
|
* @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
|
|
110
119
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
|
|
111
120
|
* @param options.memory - Memory in megabytes allocated for the run.
|
|
112
|
-
* @param options.
|
|
121
|
+
* @param options.runTimeoutSecs - Maximum run duration in seconds.
|
|
122
|
+
* @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
|
|
113
123
|
* @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
|
|
114
124
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
115
125
|
*
|
|
@@ -132,7 +142,7 @@ export declare class ActorClient extends ResourceClient {
|
|
|
132
142
|
* const run = await client.actor('my-actor').call({ url: 'https://example.com' }, { log });
|
|
133
143
|
* ```
|
|
134
144
|
*/
|
|
135
|
-
call(input?:
|
|
145
|
+
call(input?: ActorInput, options?: ActorCallOptions): Promise<ActorRun>;
|
|
136
146
|
/**
|
|
137
147
|
* Validates the provided input for the Actor against its input schema.
|
|
138
148
|
*
|
|
@@ -141,13 +151,12 @@ export declare class ActorClient extends ResourceClient {
|
|
|
141
151
|
* invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
|
|
142
152
|
* validation problem.
|
|
143
153
|
*
|
|
144
|
-
* @param input - Input to validate against the Actor's input schema
|
|
145
|
-
*
|
|
146
|
-
* input should be a string or Buffer.
|
|
154
|
+
* @param input - Input to validate against the Actor's input schema: an object or array serialized to JSON, or
|
|
155
|
+
* raw bytes sent as they are.
|
|
147
156
|
* @param options - Validation options
|
|
148
157
|
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
149
158
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
150
|
-
* @param options.
|
|
159
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
151
160
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
152
161
|
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
153
162
|
*
|
|
@@ -164,7 +173,7 @@ export declare class ActorClient extends ResourceClient {
|
|
|
164
173
|
* ```
|
|
165
174
|
* @since Added in 2.24.0
|
|
166
175
|
*/
|
|
167
|
-
validateInput(input?:
|
|
176
|
+
validateInput(input?: ActorInput, options?: ActorValidateInputOptions): Promise<boolean>;
|
|
168
177
|
/**
|
|
169
178
|
* Builds the Actor.
|
|
170
179
|
*
|
|
@@ -177,6 +186,8 @@ export declare class ActorClient extends ResourceClient {
|
|
|
177
186
|
* @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
|
|
178
187
|
* @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
|
|
179
188
|
* @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).
|
|
189
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
190
|
+
* when the API is asked to hold the response.
|
|
180
191
|
* @returns The Build object with status and build details
|
|
181
192
|
* @see https://docs.apify.com/api/v2/act-builds-post
|
|
182
193
|
*
|
|
@@ -204,6 +215,8 @@ export declare class ActorClient extends ResourceClient {
|
|
|
204
215
|
*
|
|
205
216
|
* @param options - Options for getting the default build
|
|
206
217
|
* @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).
|
|
218
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
219
|
+
* when the API is asked to hold the response.
|
|
207
220
|
* @returns A client for the default build
|
|
208
221
|
* @see https://docs.apify.com/api/v2/act-build-default-get
|
|
209
222
|
*
|
|
@@ -280,17 +293,26 @@ export declare class ActorClient extends ResourceClient {
|
|
|
280
293
|
* Fields that can be updated when modifying an Actor.
|
|
281
294
|
*/
|
|
282
295
|
export type ActorUpdateOptions = Partial<Pick<Actor, 'name' | 'description' | 'isPublic' | 'isDeprecated' | 'seoTitle' | 'seoDescription' | 'title' | 'restartOnError' | 'versions' | 'categories' | 'defaultRunOptions' | 'actorStandby' | 'actorPermissionLevel' | 'taggedBuilds'>>;
|
|
283
|
-
|
|
296
|
+
/**
|
|
297
|
+
* Input for an Actor run, as taken by {@link ActorClient.start}, {@link ActorClient.call},
|
|
298
|
+
* {@link ActorClient.validateInput} and {@link RunClient.metamorph}.
|
|
299
|
+
*
|
|
300
|
+
* A plain object or an array of plain objects, serialized into the request body, or raw bytes
|
|
301
|
+
* (a `Uint8Array` such as a `Buffer`, or an `ArrayBuffer`) sent as they are, typically with a
|
|
302
|
+
* `contentType`. An input typed as an `interface` or a class needs a spread (`{ ...input }`), or for
|
|
303
|
+
* an interface a `type` alias, to compile.
|
|
304
|
+
*/
|
|
305
|
+
export type ActorInput = Dictionary | readonly Dictionary[] | Uint8Array | ArrayBuffer;
|
|
306
|
+
export interface ActorStartOptions extends TimeoutOptions {
|
|
284
307
|
/**
|
|
285
308
|
* Tag or number of the Actor build to run (e.g. `beta` or `1.2.345`).
|
|
286
309
|
* If not provided, the run uses build tag or number from the default Actor run configuration (typically `latest`).
|
|
287
310
|
*/
|
|
288
311
|
build?: string;
|
|
289
312
|
/**
|
|
290
|
-
* Content type
|
|
291
|
-
*
|
|
292
|
-
* `application/
|
|
293
|
-
* `String` or `Buffer`.
|
|
313
|
+
* Content type of the request body, which becomes the content type of the run's `INPUT` record.
|
|
314
|
+
* Without it, an input is serialized to JSON and sent as `application/json`. Pairing an object
|
|
315
|
+
* with `application/x-www-form-urlencoded` form-encodes it instead.
|
|
294
316
|
*/
|
|
295
317
|
contentType?: string;
|
|
296
318
|
/**
|
|
@@ -300,9 +322,9 @@ export interface ActorStartOptions {
|
|
|
300
322
|
memory?: number;
|
|
301
323
|
/**
|
|
302
324
|
* Timeout for the Actor run in seconds. Zero value means there is no timeout.
|
|
303
|
-
* If not provided, the run uses timeout of the default Actor run configuration.
|
|
325
|
+
* If not provided, the run uses the timeout of the default Actor run configuration.
|
|
304
326
|
*/
|
|
305
|
-
|
|
327
|
+
runTimeoutSecs?: number;
|
|
306
328
|
/**
|
|
307
329
|
* Maximum time to wait for the Actor run to finish, in seconds.
|
|
308
330
|
* If the limit is reached, the returned promise is resolved to a run object that will have
|
|
@@ -369,24 +391,23 @@ export interface ActorCallOptions extends Omit<ActorStartOptions, 'waitForFinish
|
|
|
369
391
|
* Options for validating an Actor input.
|
|
370
392
|
* @since Added in 2.24.0
|
|
371
393
|
*/
|
|
372
|
-
export interface ActorValidateInputOptions {
|
|
394
|
+
export interface ActorValidateInputOptions extends TimeoutOptions {
|
|
373
395
|
/**
|
|
374
396
|
* Tag or number of the Actor build whose input schema the input is validated against
|
|
375
397
|
* (e.g. `beta` or `1.2.345`). If not provided, the default build is used.
|
|
376
398
|
*/
|
|
377
399
|
build?: string;
|
|
378
400
|
/**
|
|
379
|
-
* Content type
|
|
380
|
-
*
|
|
381
|
-
* `application/
|
|
382
|
-
* `String` or `Buffer`.
|
|
401
|
+
* Content type of the request body carrying the input to validate. Without it, the input is
|
|
402
|
+
* serialized to JSON and sent as `application/json`. Pairing an object with
|
|
403
|
+
* `application/x-www-form-urlencoded` form-encodes it instead.
|
|
383
404
|
*/
|
|
384
405
|
contentType?: string;
|
|
385
406
|
}
|
|
386
407
|
/**
|
|
387
408
|
* Options for building an Actor.
|
|
388
409
|
*/
|
|
389
|
-
export interface ActorBuildOptions {
|
|
410
|
+
export interface ActorBuildOptions extends TimeoutOptions {
|
|
390
411
|
betaPackages?: boolean;
|
|
391
412
|
tag?: string;
|
|
392
413
|
useCache?: boolean;
|
|
@@ -2,7 +2,9 @@ import { z } from 'zod';
|
|
|
2
2
|
import { ACTOR_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify/consts';
|
|
3
3
|
import { Log } from '@apify/log';
|
|
4
4
|
import { ResourceClient } from '../base/resource_client.js';
|
|
5
|
-
import
|
|
5
|
+
import * as schemas from '../schemas.js';
|
|
6
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
7
|
+
import { anyObjectSchema, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
|
|
6
8
|
import { ActorVersionClient } from './actor_version.js';
|
|
7
9
|
import { ActorVersionCollectionClient } from './actor_version_collection.js';
|
|
8
10
|
import { BuildClient } from './build.js';
|
|
@@ -14,19 +16,20 @@ const startOptionsSchema = z.strictObject({
|
|
|
14
16
|
build: z.string().optional(),
|
|
15
17
|
contentType: z.string().optional(),
|
|
16
18
|
memory: z.number().optional(),
|
|
17
|
-
|
|
19
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
18
20
|
waitForFinish: z.number().optional(),
|
|
19
21
|
webhooks: z.array(anyObjectSchema).optional(),
|
|
20
22
|
maxItems: z.number().min(0).optional(),
|
|
21
23
|
maxTotalChargeUsd: z.number().min(0).optional(),
|
|
22
24
|
restartOnError: z.boolean().optional(),
|
|
23
25
|
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
26
|
+
...timeoutOptionsShape,
|
|
24
27
|
});
|
|
25
28
|
const callOptionsSchema = z.strictObject({
|
|
26
29
|
build: z.string().optional(),
|
|
27
30
|
contentType: z.string().optional(),
|
|
28
31
|
memory: z.number().optional(),
|
|
29
|
-
|
|
32
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
30
33
|
waitSecs: z.number().min(0).optional(),
|
|
31
34
|
webhooks: z.array(anyObjectSchema).optional(),
|
|
32
35
|
maxItems: z.number().min(0).optional(),
|
|
@@ -34,18 +37,22 @@ const callOptionsSchema = z.strictObject({
|
|
|
34
37
|
log: z.union([z.null(), z.instanceof(Log), z.literal('default')]).optional(),
|
|
35
38
|
restartOnError: z.boolean().optional(),
|
|
36
39
|
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
40
|
+
...timeoutOptionsShape,
|
|
37
41
|
});
|
|
38
42
|
const validateInputOptionsSchema = z.strictObject({
|
|
39
43
|
build: z.string().optional(),
|
|
40
44
|
contentType: z.string().optional(),
|
|
45
|
+
...timeoutOptionsShape,
|
|
41
46
|
});
|
|
42
|
-
const versionNumberSchema = z.string();
|
|
47
|
+
const versionNumberSchema = z.string().min(1);
|
|
43
48
|
const buildOptionsSchema = z.strictObject({
|
|
44
49
|
betaPackages: z.boolean().optional(),
|
|
45
50
|
tag: z.string().optional(),
|
|
46
51
|
useCache: z.boolean().optional(),
|
|
47
52
|
waitForFinish: z.number().optional(),
|
|
53
|
+
...timeoutOptionsShape,
|
|
48
54
|
});
|
|
55
|
+
const defaultBuildOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
|
|
49
56
|
const lastRunOptionsSchema = z.strictObject({
|
|
50
57
|
status: z.enum(ACTOR_JOB_STATUSES).optional(),
|
|
51
58
|
origin: z.enum(META_ORIGINS).optional(),
|
|
@@ -83,30 +90,39 @@ export class ActorClient extends ResourceClient {
|
|
|
83
90
|
/**
|
|
84
91
|
* Gets the Actor object from the Apify API.
|
|
85
92
|
*
|
|
93
|
+
* @param options - Request options
|
|
94
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
86
95
|
* @returns The Actor object, or `undefined` if it does not exist
|
|
87
96
|
* @see https://docs.apify.com/api/v2/act-get
|
|
88
97
|
*/
|
|
89
|
-
async get() {
|
|
90
|
-
|
|
98
|
+
async get(options = {}) {
|
|
99
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
100
|
+
return this.getResource(schemas.Actor(), {}, timeoutSecs, signal);
|
|
91
101
|
}
|
|
92
102
|
/**
|
|
93
103
|
* Updates the Actor with specified fields.
|
|
94
104
|
*
|
|
95
105
|
* @param newFields - Fields to update in the Actor
|
|
106
|
+
* @param options - Request options
|
|
107
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
96
108
|
* @returns The updated Actor object
|
|
97
109
|
* @see https://docs.apify.com/api/v2/act-put
|
|
98
110
|
*/
|
|
99
|
-
async update(newFields) {
|
|
111
|
+
async update(newFields, options = {}) {
|
|
100
112
|
parseArgument(newFields, anyObjectSchema);
|
|
101
|
-
|
|
113
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
|
+
return this.updateResource(schemas.Actor(), newFields, timeoutSecs, signal);
|
|
102
115
|
}
|
|
103
116
|
/**
|
|
104
117
|
* Deletes the Actor.
|
|
105
118
|
*
|
|
119
|
+
* @param options - Request options
|
|
120
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
106
121
|
* @see https://docs.apify.com/api/v2/act-delete
|
|
107
122
|
*/
|
|
108
|
-
async delete() {
|
|
109
|
-
|
|
123
|
+
async delete(options = {}) {
|
|
124
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
125
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
110
126
|
}
|
|
111
127
|
/**
|
|
112
128
|
* Starts the Actor and immediately returns the Run object.
|
|
@@ -115,17 +131,18 @@ export class ActorClient extends ResourceClient {
|
|
|
115
131
|
* asynchronously and this method returns immediately without waiting for completion.
|
|
116
132
|
* Use the {@link call} method if you want to wait for the Actor to finish.
|
|
117
133
|
*
|
|
118
|
-
* @param input - Input for the Actor
|
|
119
|
-
*
|
|
134
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
135
|
+
* Omit it to run the Actor without input.
|
|
120
136
|
* @param options - Run configuration options
|
|
121
137
|
* @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.
|
|
122
138
|
* @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
|
|
123
|
-
* @param options.
|
|
139
|
+
* @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
|
|
124
140
|
* @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).
|
|
125
141
|
* @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
|
|
126
142
|
* @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
|
|
127
143
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
|
|
128
|
-
* @param options.
|
|
144
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
145
|
+
* when the API is asked to hold the response.
|
|
129
146
|
* @returns The Actor run object with status, usage, and storage IDs
|
|
130
147
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
131
148
|
*
|
|
@@ -138,18 +155,17 @@ export class ActorClient extends ResourceClient {
|
|
|
138
155
|
* // Start Actor with specific build and memory
|
|
139
156
|
* const run = await client.actor('my-actor').start(
|
|
140
157
|
* { url: 'https://example.com' },
|
|
141
|
-
* { build: '0.1.2', memory: 512,
|
|
158
|
+
* { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
|
|
142
159
|
* );
|
|
143
160
|
* ```
|
|
144
161
|
*/
|
|
145
162
|
async start(input, options = {}) {
|
|
146
|
-
// input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
|
|
147
|
-
// then it will process input as a buffer.
|
|
148
163
|
const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
|
|
149
|
-
const { waitForFinish,
|
|
164
|
+
const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, timeoutSecs, signal, } = parsed;
|
|
165
|
+
// The API's `timeout` parameter bounds the run, not the request.
|
|
150
166
|
const params = {
|
|
151
167
|
waitForFinish,
|
|
152
|
-
timeout,
|
|
168
|
+
timeout: runTimeoutSecs,
|
|
153
169
|
memory,
|
|
154
170
|
build,
|
|
155
171
|
webhooks: stringifyWebhooksToBase64(parsed.webhooks),
|
|
@@ -159,13 +175,14 @@ export class ActorClient extends ResourceClient {
|
|
|
159
175
|
forcePermissionLevel,
|
|
160
176
|
};
|
|
161
177
|
const request = {
|
|
162
|
-
url: this.
|
|
178
|
+
url: this.buildUrl('runs'),
|
|
163
179
|
method: 'POST',
|
|
164
180
|
data: input,
|
|
165
|
-
params: this.
|
|
166
|
-
//
|
|
167
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
181
|
+
params: this.buildParams(params),
|
|
182
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
168
183
|
stringifyFunctions: true,
|
|
184
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
|
|
185
|
+
signal,
|
|
169
186
|
};
|
|
170
187
|
if (parsed.contentType) {
|
|
171
188
|
request.headers = {
|
|
@@ -173,7 +190,7 @@ export class ActorClient extends ResourceClient {
|
|
|
173
190
|
};
|
|
174
191
|
}
|
|
175
192
|
const response = await this.httpClient.call(request);
|
|
176
|
-
return
|
|
193
|
+
return parseResponse(response, schemas.Run());
|
|
177
194
|
}
|
|
178
195
|
/**
|
|
179
196
|
* Starts the Actor and waits for it to finish before returning the Run object.
|
|
@@ -182,14 +199,15 @@ export class ActorClient extends ResourceClient {
|
|
|
182
199
|
* by polling the run status. It optionally streams logs to the console or a custom Log instance.
|
|
183
200
|
* By default, it waits indefinitely unless the `waitSecs` option is provided.
|
|
184
201
|
*
|
|
185
|
-
* @param input - Input for the Actor
|
|
186
|
-
*
|
|
202
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
203
|
+
* Omit it to run the Actor without input.
|
|
187
204
|
* @param options - Run configuration options (extends all options from {@link start})
|
|
188
205
|
* @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
|
|
189
206
|
* @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
|
|
190
207
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
|
|
191
208
|
* @param options.memory - Memory in megabytes allocated for the run.
|
|
192
|
-
* @param options.
|
|
209
|
+
* @param options.runTimeoutSecs - Maximum run duration in seconds.
|
|
210
|
+
* @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
|
|
193
211
|
* @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
|
|
194
212
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
195
213
|
*
|
|
@@ -213,20 +231,18 @@ export class ActorClient extends ResourceClient {
|
|
|
213
231
|
* ```
|
|
214
232
|
*/
|
|
215
233
|
async call(input, options = {}) {
|
|
216
|
-
// input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
|
|
217
|
-
// then it will process input as a buffer.
|
|
218
234
|
const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
|
|
219
|
-
const { waitSecs, log, ...startOptions } = parsed;
|
|
220
|
-
const { id } = await this.start(input, startOptions);
|
|
235
|
+
const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
|
|
236
|
+
const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
|
|
221
237
|
// Calling root client because we need access to top level API.
|
|
222
238
|
// Creating a new instance of RunClient here would only allow
|
|
223
239
|
// setting it up as a nested route under actor API.
|
|
224
240
|
const newRunClient = this.apifyClient.run(id);
|
|
225
|
-
const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
|
|
241
|
+
const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
|
|
226
242
|
streamedLog?.start();
|
|
227
243
|
return this.apifyClient
|
|
228
244
|
.run(id)
|
|
229
|
-
.waitForFinish({ waitSecs })
|
|
245
|
+
.waitForFinish({ waitSecs, timeoutSecs, signal })
|
|
230
246
|
.finally(async () => {
|
|
231
247
|
await streamedLog?.stop();
|
|
232
248
|
});
|
|
@@ -239,13 +255,12 @@ export class ActorClient extends ResourceClient {
|
|
|
239
255
|
* invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
|
|
240
256
|
* validation problem.
|
|
241
257
|
*
|
|
242
|
-
* @param input - Input to validate against the Actor's input schema
|
|
243
|
-
*
|
|
244
|
-
* input should be a string or Buffer.
|
|
258
|
+
* @param input - Input to validate against the Actor's input schema: an object or array serialized to JSON, or
|
|
259
|
+
* raw bytes sent as they are.
|
|
245
260
|
* @param options - Validation options
|
|
246
261
|
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
247
262
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
248
|
-
* @param options.
|
|
263
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
249
264
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
250
265
|
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
251
266
|
*
|
|
@@ -263,17 +278,16 @@ export class ActorClient extends ResourceClient {
|
|
|
263
278
|
* @since Added in 2.24.0
|
|
264
279
|
*/
|
|
265
280
|
async validateInput(input, options = {}) {
|
|
266
|
-
// input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
|
|
267
|
-
// then it will process input as a buffer.
|
|
268
281
|
const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
|
|
269
282
|
const request = {
|
|
270
|
-
url: this.
|
|
283
|
+
url: this.buildUrl('validate-input'),
|
|
271
284
|
method: 'POST',
|
|
272
285
|
data: input,
|
|
273
|
-
params: this.
|
|
274
|
-
//
|
|
275
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
286
|
+
params: this.buildParams({ build: parsed.build }),
|
|
287
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
276
288
|
stringifyFunctions: true,
|
|
289
|
+
timeoutSecs: parsed.timeoutSecs ?? 'short',
|
|
290
|
+
signal: parsed.signal,
|
|
277
291
|
};
|
|
278
292
|
if (parsed.contentType) {
|
|
279
293
|
request.headers = {
|
|
@@ -295,6 +309,8 @@ export class ActorClient extends ResourceClient {
|
|
|
295
309
|
* @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
|
|
296
310
|
* @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
|
|
297
311
|
* @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).
|
|
312
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
313
|
+
* when the API is asked to hold the response.
|
|
298
314
|
* @returns The Build object with status and build details
|
|
299
315
|
* @see https://docs.apify.com/api/v2/act-builds-post
|
|
300
316
|
*
|
|
@@ -314,16 +330,18 @@ export class ActorClient extends ResourceClient {
|
|
|
314
330
|
*/
|
|
315
331
|
async build(versionNumber, options = {}) {
|
|
316
332
|
parseArgument(versionNumber, versionNumberSchema);
|
|
317
|
-
const
|
|
333
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
|
|
318
334
|
const response = await this.httpClient.call({
|
|
319
|
-
url: this.
|
|
335
|
+
url: this.buildUrl('builds'),
|
|
320
336
|
method: 'POST',
|
|
321
|
-
params: this.
|
|
337
|
+
params: this.buildParams({
|
|
322
338
|
version: versionNumber,
|
|
323
|
-
...
|
|
339
|
+
...params,
|
|
324
340
|
}),
|
|
341
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
|
|
342
|
+
signal,
|
|
325
343
|
});
|
|
326
|
-
return
|
|
344
|
+
return parseResponse(response, schemas.Build());
|
|
327
345
|
}
|
|
328
346
|
/**
|
|
329
347
|
* Returns a client for the default build of this Actor.
|
|
@@ -334,6 +352,8 @@ export class ActorClient extends ResourceClient {
|
|
|
334
352
|
*
|
|
335
353
|
* @param options - Options for getting the default build
|
|
336
354
|
* @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).
|
|
355
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
356
|
+
* when the API is asked to hold the response.
|
|
337
357
|
* @returns A client for the default build
|
|
338
358
|
* @see https://docs.apify.com/api/v2/act-build-default-get
|
|
339
359
|
*
|
|
@@ -351,12 +371,15 @@ export class ActorClient extends ResourceClient {
|
|
|
351
371
|
* @since Added in 2.12.2
|
|
352
372
|
*/
|
|
353
373
|
async defaultBuild(options = {}) {
|
|
374
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
|
|
354
375
|
const response = await this.httpClient.call({
|
|
355
|
-
url: this.
|
|
376
|
+
url: this.buildUrl('builds/default'),
|
|
356
377
|
method: 'GET',
|
|
357
|
-
params: this.
|
|
378
|
+
params: this.buildParams(params),
|
|
379
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
|
|
380
|
+
signal,
|
|
358
381
|
});
|
|
359
|
-
const { id } =
|
|
382
|
+
const { id } = parseResponse(response, schemas.Build());
|
|
360
383
|
return new BuildClient({
|
|
361
384
|
baseUrl: this.apifyClient.baseUrl,
|
|
362
385
|
publicBaseUrl: this.apifyClient.publicBaseUrl,
|
|
@@ -384,9 +407,9 @@ export class ActorClient extends ResourceClient {
|
|
|
384
407
|
*/
|
|
385
408
|
lastRun(options = {}) {
|
|
386
409
|
const parsed = parseArgument(options, lastRunOptionsSchema, 'ActorLastRunOptions');
|
|
387
|
-
return new RunClient(this.
|
|
410
|
+
return new RunClient(this.subResourceOptions({
|
|
388
411
|
id: 'last',
|
|
389
|
-
params: this.
|
|
412
|
+
params: this.buildParams(parsed),
|
|
390
413
|
resourcePath: 'runs',
|
|
391
414
|
}));
|
|
392
415
|
}
|
|
@@ -397,7 +420,7 @@ export class ActorClient extends ResourceClient {
|
|
|
397
420
|
* @see https://docs.apify.com/api/v2/act-builds-get
|
|
398
421
|
*/
|
|
399
422
|
builds() {
|
|
400
|
-
return new BuildCollectionClient(this.
|
|
423
|
+
return new BuildCollectionClient(this.subResourceOptions({
|
|
401
424
|
resourcePath: 'builds',
|
|
402
425
|
}));
|
|
403
426
|
}
|
|
@@ -408,7 +431,7 @@ export class ActorClient extends ResourceClient {
|
|
|
408
431
|
* @see https://docs.apify.com/api/v2/act-runs-get
|
|
409
432
|
*/
|
|
410
433
|
runs() {
|
|
411
|
-
return new RunCollectionClient(this.
|
|
434
|
+
return new RunCollectionClient(this.subResourceOptions({
|
|
412
435
|
resourcePath: 'runs',
|
|
413
436
|
}));
|
|
414
437
|
}
|
|
@@ -421,7 +444,7 @@ export class ActorClient extends ResourceClient {
|
|
|
421
444
|
*/
|
|
422
445
|
version(versionNumber) {
|
|
423
446
|
parseArgument(versionNumber, versionNumberSchema);
|
|
424
|
-
return new ActorVersionClient(this.
|
|
447
|
+
return new ActorVersionClient(this.subResourceOptions({
|
|
425
448
|
id: versionNumber,
|
|
426
449
|
}));
|
|
427
450
|
}
|
|
@@ -432,7 +455,7 @@ export class ActorClient extends ResourceClient {
|
|
|
432
455
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
433
456
|
*/
|
|
434
457
|
versions() {
|
|
435
|
-
return new ActorVersionCollectionClient(this.
|
|
458
|
+
return new ActorVersionCollectionClient(this.subResourceOptions());
|
|
436
459
|
}
|
|
437
460
|
/**
|
|
438
461
|
* Returns a client for managing webhooks associated with this Actor.
|
|
@@ -441,6 +464,6 @@ export class ActorClient extends ResourceClient {
|
|
|
441
464
|
* @see https://docs.apify.com/api/v2/act-webhooks-get
|
|
442
465
|
*/
|
|
443
466
|
webhooks() {
|
|
444
|
-
return new WebhookCollectionClient(this.
|
|
467
|
+
return new WebhookCollectionClient(this.subResourceOptions());
|
|
445
468
|
}
|
|
446
469
|
}
|