apify-client 3.0.0-beta.12 → 3.0.0-beta.121
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 +23 -2
- package/dist/apify_api_error.d.ts +14 -28
- package/dist/apify_api_error.js +33 -23
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/axios.d.ts +2 -0
- package/dist/axios.js +1 -0
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +36 -36
- package/dist/base/resource_client.d.ts +13 -8
- package/dist/base/resource_client.js +60 -34
- package/dist/base/resource_collection_client.d.ts +12 -4
- package/dist/base/resource_collection_client.js +34 -11
- package/dist/body_parser.d.ts +4 -5
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +41 -35
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +3266 -1103
- package/dist/generated/schemas.d.ts +2608 -1079
- package/dist/generated/schemas.js +600 -239
- package/dist/http_clients/axios.d.ts +80 -0
- package/dist/http_clients/axios.js +165 -0
- package/dist/http_clients/base.d.ts +402 -0
- package/dist/http_clients/base.js +680 -0
- package/dist/http_clients/fetch.d.ts +53 -0
- package/dist/http_clients/fetch.js +219 -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 +8 -0
- package/dist/http_compressors/index.js +3 -0
- package/dist/http_compressors/resolve.d.ts +24 -0
- package/dist/http_compressors/resolve.js +30 -0
- package/dist/http_compressors/zstd.d.ts +34 -0
- package/dist/http_compressors/zstd.js +43 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -1
- package/dist/invalid_response_body_error.d.ts +14 -0
- package/dist/invalid_response_body_error.js +18 -0
- package/dist/models.d.ts +177 -240
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +94 -23
- package/dist/resource_clients/actor.js +129 -43
- package/dist/resource_clients/actor_collection.d.ts +15 -11
- package/dist/resource_clients/actor_collection.js +9 -3
- package/dist/resource_clients/actor_env_var.d.ts +11 -4
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_server.d.ts +149 -0
- package/dist/resource_clients/actor_server.js +195 -0
- package/dist/resource_clients/actor_version.d.ts +19 -6
- package/dist/resource_clients/actor_version.js +19 -8
- package/dist/resource_clients/actor_version_collection.d.ts +10 -4
- package/dist/resource_clients/actor_version_collection.js +12 -4
- package/dist/resource_clients/build.d.ts +18 -7
- package/dist/resource_clients/build.js +33 -15
- package/dist/resource_clients/build_collection.d.ts +7 -5
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +83 -37
- package/dist/resource_clients/dataset.js +99 -109
- package/dist/resource_clients/dataset_collection.d.ts +10 -6
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +108 -33
- package/dist/resource_clients/key_value_store.js +134 -53
- package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +41 -25
- package/dist/resource_clients/log.js +142 -65
- package/dist/resource_clients/request_queue.d.ts +77 -31
- package/dist/resource_clients/request_queue.js +178 -93
- package/dist/resource_clients/request_queue_collection.d.ts +9 -5
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +119 -29
- package/dist/resource_clients/run.js +188 -49
- package/dist/resource_clients/run_collection.d.ts +5 -3
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +15 -6
- package/dist/resource_clients/schedule.js +25 -10
- 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 +10 -4
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +35 -12
- package/dist/resource_clients/task.js +75 -35
- package/dist/resource_clients/task_collection.d.ts +9 -5
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +16 -7
- package/dist/resource_clients/user.js +34 -16
- package/dist/resource_clients/webhook.d.ts +16 -7
- package/dist/resource_clients/webhook.js +25 -10
- package/dist/resource_clients/webhook_collection.d.ts +8 -4
- 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/response_validation_error.d.ts +2 -1
- package/dist/response_validation_error.js +2 -1
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +111 -0
- package/dist/runtime/types.d.ts +82 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +60 -0
- package/dist/schemas.d.ts +372 -4
- package/dist/schemas.js +26 -4
- 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 +115 -61
- package/dist/utils.js +220 -161
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +53 -38
- 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,7 +3,10 @@ import { ACTOR_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify
|
|
|
3
3
|
import { Log } from '@apify/log';
|
|
4
4
|
import { ResourceClient } from '../base/resource_client.js';
|
|
5
5
|
import * as schemas from '../schemas.js';
|
|
6
|
-
import {
|
|
6
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
7
|
+
import { anyObjectSchema, isAnyStream, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
|
|
8
|
+
import { startWaitingForResources } from '../wait_for_resources.js';
|
|
9
|
+
import { ActorServerClient } from './actor_server.js';
|
|
7
10
|
import { ActorVersionClient } from './actor_version.js';
|
|
8
11
|
import { ActorVersionCollectionClient } from './actor_version_collection.js';
|
|
9
12
|
import { BuildClient } from './build.js';
|
|
@@ -15,19 +18,21 @@ const startOptionsSchema = z.strictObject({
|
|
|
15
18
|
build: z.string().optional(),
|
|
16
19
|
contentType: z.string().optional(),
|
|
17
20
|
memory: z.number().optional(),
|
|
18
|
-
|
|
21
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
19
22
|
waitForFinish: z.number().optional(),
|
|
20
23
|
webhooks: z.array(anyObjectSchema).optional(),
|
|
21
24
|
maxItems: z.number().min(0).optional(),
|
|
22
25
|
maxTotalChargeUsd: z.number().min(0).optional(),
|
|
23
26
|
restartOnError: z.boolean().optional(),
|
|
24
27
|
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
28
|
+
waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
|
|
29
|
+
...timeoutOptionsShape,
|
|
25
30
|
});
|
|
26
31
|
const callOptionsSchema = z.strictObject({
|
|
27
32
|
build: z.string().optional(),
|
|
28
33
|
contentType: z.string().optional(),
|
|
29
34
|
memory: z.number().optional(),
|
|
30
|
-
|
|
35
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
31
36
|
waitSecs: z.number().min(0).optional(),
|
|
32
37
|
webhooks: z.array(anyObjectSchema).optional(),
|
|
33
38
|
maxItems: z.number().min(0).optional(),
|
|
@@ -35,10 +40,13 @@ const callOptionsSchema = z.strictObject({
|
|
|
35
40
|
log: z.union([z.null(), z.instanceof(Log), z.literal('default')]).optional(),
|
|
36
41
|
restartOnError: z.boolean().optional(),
|
|
37
42
|
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
43
|
+
waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
|
|
44
|
+
...timeoutOptionsShape,
|
|
38
45
|
});
|
|
39
46
|
const validateInputOptionsSchema = z.strictObject({
|
|
40
47
|
build: z.string().optional(),
|
|
41
48
|
contentType: z.string().optional(),
|
|
49
|
+
...timeoutOptionsShape,
|
|
42
50
|
});
|
|
43
51
|
const versionNumberSchema = z.string().min(1);
|
|
44
52
|
const buildOptionsSchema = z.strictObject({
|
|
@@ -46,7 +54,9 @@ const buildOptionsSchema = z.strictObject({
|
|
|
46
54
|
tag: z.string().optional(),
|
|
47
55
|
useCache: z.boolean().optional(),
|
|
48
56
|
waitForFinish: z.number().optional(),
|
|
57
|
+
...timeoutOptionsShape,
|
|
49
58
|
});
|
|
59
|
+
const defaultBuildOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
|
|
50
60
|
const lastRunOptionsSchema = z.strictObject({
|
|
51
61
|
status: z.enum(ACTOR_JOB_STATUSES).optional(),
|
|
52
62
|
origin: z.enum(META_ORIGINS).optional(),
|
|
@@ -72,6 +82,7 @@ const lastRunOptionsSchema = z.strictObject({
|
|
|
72
82
|
* @see https://docs.apify.com/platform/actors
|
|
73
83
|
*/
|
|
74
84
|
export class ActorClient extends ResourceClient {
|
|
85
|
+
#serverClient;
|
|
75
86
|
/**
|
|
76
87
|
* @hidden
|
|
77
88
|
*/
|
|
@@ -84,30 +95,39 @@ export class ActorClient extends ResourceClient {
|
|
|
84
95
|
/**
|
|
85
96
|
* Gets the Actor object from the Apify API.
|
|
86
97
|
*
|
|
98
|
+
* @param options - Request options
|
|
99
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
87
100
|
* @returns The Actor object, or `undefined` if it does not exist
|
|
88
101
|
* @see https://docs.apify.com/api/v2/act-get
|
|
89
102
|
*/
|
|
90
|
-
async get() {
|
|
91
|
-
|
|
103
|
+
async get(options = {}) {
|
|
104
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
105
|
+
return this.getResource(schemas.ActorResource(), {}, timeoutSecs, signal);
|
|
92
106
|
}
|
|
93
107
|
/**
|
|
94
108
|
* Updates the Actor with specified fields.
|
|
95
109
|
*
|
|
96
110
|
* @param newFields - Fields to update in the Actor
|
|
111
|
+
* @param options - Request options
|
|
112
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
97
113
|
* @returns The updated Actor object
|
|
98
114
|
* @see https://docs.apify.com/api/v2/act-put
|
|
99
115
|
*/
|
|
100
|
-
async update(newFields) {
|
|
116
|
+
async update(newFields, options = {}) {
|
|
101
117
|
parseArgument(newFields, anyObjectSchema);
|
|
102
|
-
|
|
118
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
119
|
+
return this.updateResource(schemas.ActorResource(), newFields, timeoutSecs, signal);
|
|
103
120
|
}
|
|
104
121
|
/**
|
|
105
122
|
* Deletes the Actor.
|
|
106
123
|
*
|
|
124
|
+
* @param options - Request options
|
|
125
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
107
126
|
* @see https://docs.apify.com/api/v2/act-delete
|
|
108
127
|
*/
|
|
109
|
-
async delete() {
|
|
110
|
-
|
|
128
|
+
async delete(options = {}) {
|
|
129
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
130
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
111
131
|
}
|
|
112
132
|
/**
|
|
113
133
|
* Starts the Actor and immediately returns the Run object.
|
|
@@ -116,15 +136,20 @@ export class ActorClient extends ResourceClient {
|
|
|
116
136
|
* asynchronously and this method returns immediately without waiting for completion.
|
|
117
137
|
* Use the {@link call} method if you want to wait for the Actor to finish.
|
|
118
138
|
*
|
|
119
|
-
* @param input - Input for the Actor
|
|
139
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
140
|
+
* Omit it to run the Actor without input.
|
|
120
141
|
* @param options - Run configuration options
|
|
121
142
|
* @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
143
|
* @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
|
|
123
|
-
* @param options.
|
|
144
|
+
* @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
|
|
124
145
|
* @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
146
|
* @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
|
|
126
147
|
* @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
|
|
127
148
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
|
|
149
|
+
* @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
|
|
150
|
+
* the run. `true` retries until the run starts, a number stops retrying after that many seconds.
|
|
151
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
152
|
+
* when the API is asked to hold the response.
|
|
128
153
|
* @returns The Actor run object with status, usage, and storage IDs
|
|
129
154
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
130
155
|
*
|
|
@@ -137,16 +162,17 @@ export class ActorClient extends ResourceClient {
|
|
|
137
162
|
* // Start Actor with specific build and memory
|
|
138
163
|
* const run = await client.actor('my-actor').start(
|
|
139
164
|
* { url: 'https://example.com' },
|
|
140
|
-
* { build: '0.1.2', memory: 512,
|
|
165
|
+
* { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
|
|
141
166
|
* );
|
|
142
167
|
* ```
|
|
143
168
|
*/
|
|
144
169
|
async start(input, options = {}) {
|
|
145
170
|
const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
|
|
146
|
-
const { waitForFinish,
|
|
171
|
+
const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, waitForResources, timeoutSecs, signal, } = parsed;
|
|
172
|
+
// The API's `timeout` parameter bounds the run, not the request.
|
|
147
173
|
const params = {
|
|
148
174
|
waitForFinish,
|
|
149
|
-
timeout,
|
|
175
|
+
timeout: runTimeoutSecs,
|
|
150
176
|
memory,
|
|
151
177
|
build,
|
|
152
178
|
webhooks: stringifyWebhooksToBase64(parsed.webhooks),
|
|
@@ -156,20 +182,22 @@ export class ActorClient extends ResourceClient {
|
|
|
156
182
|
forcePermissionLevel,
|
|
157
183
|
};
|
|
158
184
|
const request = {
|
|
159
|
-
url: this.
|
|
185
|
+
url: this.buildUrl('runs'),
|
|
160
186
|
method: 'POST',
|
|
161
187
|
data: input,
|
|
162
|
-
params: this.
|
|
163
|
-
//
|
|
164
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
188
|
+
params: this.buildParams(params),
|
|
189
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
165
190
|
stringifyFunctions: true,
|
|
191
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
|
|
192
|
+
signal,
|
|
166
193
|
};
|
|
167
194
|
if (parsed.contentType) {
|
|
168
195
|
request.headers = {
|
|
169
196
|
'content-type': parsed.contentType,
|
|
170
197
|
};
|
|
171
198
|
}
|
|
172
|
-
|
|
199
|
+
// A stream input is consumed by the first attempt, so a retry would start the run with an empty input.
|
|
200
|
+
const response = await startWaitingForResources(async () => this.httpClient.call(request), isAnyStream(input) ? false : waitForResources, this.httpClient.logger, signal);
|
|
173
201
|
return parseResponse(response, schemas.Run());
|
|
174
202
|
}
|
|
175
203
|
/**
|
|
@@ -179,13 +207,18 @@ export class ActorClient extends ResourceClient {
|
|
|
179
207
|
* by polling the run status. It optionally streams logs to the console or a custom Log instance.
|
|
180
208
|
* By default, it waits indefinitely unless the `waitSecs` option is provided.
|
|
181
209
|
*
|
|
182
|
-
* @param input - Input for the Actor
|
|
210
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
211
|
+
* Omit it to run the Actor without input.
|
|
183
212
|
* @param options - Run configuration options (extends all options from {@link start})
|
|
184
213
|
* @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
|
|
185
214
|
* @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
|
|
186
215
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
|
|
187
216
|
* @param options.memory - Memory in megabytes allocated for the run.
|
|
188
|
-
* @param options.
|
|
217
|
+
* @param options.runTimeoutSecs - Maximum run duration in seconds.
|
|
218
|
+
* @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
|
|
219
|
+
* the run. `true` retries until the run starts, a number stops retrying after that many seconds. The time spent
|
|
220
|
+
* retrying doesn't count toward `waitSecs`.
|
|
221
|
+
* @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
|
|
189
222
|
* @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
|
|
190
223
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
191
224
|
*
|
|
@@ -210,17 +243,17 @@ export class ActorClient extends ResourceClient {
|
|
|
210
243
|
*/
|
|
211
244
|
async call(input, options = {}) {
|
|
212
245
|
const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
|
|
213
|
-
const { waitSecs, log, ...startOptions } = parsed;
|
|
214
|
-
const { id } = await this.start(input, startOptions);
|
|
246
|
+
const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
|
|
247
|
+
const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
|
|
215
248
|
// Calling root client because we need access to top level API.
|
|
216
249
|
// Creating a new instance of RunClient here would only allow
|
|
217
250
|
// setting it up as a nested route under actor API.
|
|
218
251
|
const newRunClient = this.apifyClient.run(id);
|
|
219
|
-
const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
|
|
252
|
+
const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
|
|
220
253
|
streamedLog?.start();
|
|
221
254
|
return this.apifyClient
|
|
222
255
|
.run(id)
|
|
223
|
-
.waitForFinish({ waitSecs })
|
|
256
|
+
.waitForFinish({ waitSecs, timeoutSecs, signal })
|
|
224
257
|
.finally(async () => {
|
|
225
258
|
await streamedLog?.stop();
|
|
226
259
|
});
|
|
@@ -233,10 +266,12 @@ export class ActorClient extends ResourceClient {
|
|
|
233
266
|
* invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
|
|
234
267
|
* validation problem.
|
|
235
268
|
*
|
|
236
|
-
* @param input - Input to validate against the Actor's input schema
|
|
269
|
+
* @param input - Input to validate against the Actor's input schema: an object or array serialized to JSON, or
|
|
270
|
+
* raw bytes sent as they are.
|
|
237
271
|
* @param options - Validation options
|
|
238
272
|
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
239
273
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
274
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
240
275
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
241
276
|
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
242
277
|
*
|
|
@@ -256,13 +291,14 @@ export class ActorClient extends ResourceClient {
|
|
|
256
291
|
async validateInput(input, options = {}) {
|
|
257
292
|
const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
|
|
258
293
|
const request = {
|
|
259
|
-
url: this.
|
|
294
|
+
url: this.buildUrl('validate-input'),
|
|
260
295
|
method: 'POST',
|
|
261
296
|
data: input,
|
|
262
|
-
params: this.
|
|
263
|
-
//
|
|
264
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
297
|
+
params: this.buildParams({ build: parsed.build }),
|
|
298
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
265
299
|
stringifyFunctions: true,
|
|
300
|
+
timeoutSecs: parsed.timeoutSecs ?? 'short',
|
|
301
|
+
signal: parsed.signal,
|
|
266
302
|
};
|
|
267
303
|
if (parsed.contentType) {
|
|
268
304
|
request.headers = {
|
|
@@ -284,6 +320,8 @@ export class ActorClient extends ResourceClient {
|
|
|
284
320
|
* @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
|
|
285
321
|
* @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
|
|
286
322
|
* @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).
|
|
323
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
324
|
+
* when the API is asked to hold the response.
|
|
287
325
|
* @returns The Build object with status and build details
|
|
288
326
|
* @see https://docs.apify.com/api/v2/act-builds-post
|
|
289
327
|
*
|
|
@@ -303,14 +341,16 @@ export class ActorClient extends ResourceClient {
|
|
|
303
341
|
*/
|
|
304
342
|
async build(versionNumber, options = {}) {
|
|
305
343
|
parseArgument(versionNumber, versionNumberSchema);
|
|
306
|
-
const
|
|
344
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
|
|
307
345
|
const response = await this.httpClient.call({
|
|
308
|
-
url: this.
|
|
346
|
+
url: this.buildUrl('builds'),
|
|
309
347
|
method: 'POST',
|
|
310
|
-
params: this.
|
|
348
|
+
params: this.buildParams({
|
|
311
349
|
version: versionNumber,
|
|
312
|
-
...
|
|
350
|
+
...params,
|
|
313
351
|
}),
|
|
352
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
|
|
353
|
+
signal,
|
|
314
354
|
});
|
|
315
355
|
return parseResponse(response, schemas.Build());
|
|
316
356
|
}
|
|
@@ -323,6 +363,8 @@ export class ActorClient extends ResourceClient {
|
|
|
323
363
|
*
|
|
324
364
|
* @param options - Options for getting the default build
|
|
325
365
|
* @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).
|
|
366
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
367
|
+
* when the API is asked to hold the response.
|
|
326
368
|
* @returns A client for the default build
|
|
327
369
|
* @see https://docs.apify.com/api/v2/act-build-default-get
|
|
328
370
|
*
|
|
@@ -340,10 +382,13 @@ export class ActorClient extends ResourceClient {
|
|
|
340
382
|
* @since Added in 2.12.2
|
|
341
383
|
*/
|
|
342
384
|
async defaultBuild(options = {}) {
|
|
385
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
|
|
343
386
|
const response = await this.httpClient.call({
|
|
344
|
-
url: this.
|
|
387
|
+
url: this.buildUrl('builds/default'),
|
|
345
388
|
method: 'GET',
|
|
346
|
-
params: this.
|
|
389
|
+
params: this.buildParams(params),
|
|
390
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
|
|
391
|
+
signal,
|
|
347
392
|
});
|
|
348
393
|
const { id } = parseResponse(response, schemas.Build());
|
|
349
394
|
return new BuildClient({
|
|
@@ -373,9 +418,9 @@ export class ActorClient extends ResourceClient {
|
|
|
373
418
|
*/
|
|
374
419
|
lastRun(options = {}) {
|
|
375
420
|
const parsed = parseArgument(options, lastRunOptionsSchema, 'ActorLastRunOptions');
|
|
376
|
-
return new RunClient(this.
|
|
421
|
+
return new RunClient(this.subResourceOptions({
|
|
377
422
|
id: 'last',
|
|
378
|
-
params: this.
|
|
423
|
+
params: this.buildParams(parsed),
|
|
379
424
|
resourcePath: 'runs',
|
|
380
425
|
}));
|
|
381
426
|
}
|
|
@@ -386,7 +431,7 @@ export class ActorClient extends ResourceClient {
|
|
|
386
431
|
* @see https://docs.apify.com/api/v2/act-builds-get
|
|
387
432
|
*/
|
|
388
433
|
builds() {
|
|
389
|
-
return new BuildCollectionClient(this.
|
|
434
|
+
return new BuildCollectionClient(this.subResourceOptions({
|
|
390
435
|
resourcePath: 'builds',
|
|
391
436
|
}));
|
|
392
437
|
}
|
|
@@ -397,7 +442,7 @@ export class ActorClient extends ResourceClient {
|
|
|
397
442
|
* @see https://docs.apify.com/api/v2/act-runs-get
|
|
398
443
|
*/
|
|
399
444
|
runs() {
|
|
400
|
-
return new RunCollectionClient(this.
|
|
445
|
+
return new RunCollectionClient(this.subResourceOptions({
|
|
401
446
|
resourcePath: 'runs',
|
|
402
447
|
}));
|
|
403
448
|
}
|
|
@@ -410,7 +455,7 @@ export class ActorClient extends ResourceClient {
|
|
|
410
455
|
*/
|
|
411
456
|
version(versionNumber) {
|
|
412
457
|
parseArgument(versionNumber, versionNumberSchema);
|
|
413
|
-
return new ActorVersionClient(this.
|
|
458
|
+
return new ActorVersionClient(this.subResourceOptions({
|
|
414
459
|
id: versionNumber,
|
|
415
460
|
}));
|
|
416
461
|
}
|
|
@@ -421,7 +466,7 @@ export class ActorClient extends ResourceClient {
|
|
|
421
466
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
422
467
|
*/
|
|
423
468
|
versions() {
|
|
424
|
-
return new ActorVersionCollectionClient(this.
|
|
469
|
+
return new ActorVersionCollectionClient(this.subResourceOptions());
|
|
425
470
|
}
|
|
426
471
|
/**
|
|
427
472
|
* Returns a client for managing webhooks associated with this Actor.
|
|
@@ -430,6 +475,47 @@ export class ActorClient extends ResourceClient {
|
|
|
430
475
|
* @see https://docs.apify.com/api/v2/act-webhooks-get
|
|
431
476
|
*/
|
|
432
477
|
webhooks() {
|
|
433
|
-
return new WebhookCollectionClient(this.
|
|
478
|
+
return new WebhookCollectionClient(this.subResourceOptions());
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Returns a client for the server interface of this Actor.
|
|
482
|
+
*
|
|
483
|
+
* A Server Actor runs a web server, its server interface, that is called over HTTP without starting a run for
|
|
484
|
+
* each call. Server Actors were formerly called Actor Standby, and {@link standby} is a deprecated alias of this
|
|
485
|
+
* method. Every call returns the same client, so the server URL it fetches is reused.
|
|
486
|
+
*
|
|
487
|
+
* @returns The client for the server interface of this Actor
|
|
488
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```javascript
|
|
492
|
+
* const response = await client.actor('username/actor-name').server().request('/search', {
|
|
493
|
+
* params: { q: 'apify' },
|
|
494
|
+
* });
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
server() {
|
|
498
|
+
this.#serverClient ??= new ActorServerClient({
|
|
499
|
+
baseUrl: this.baseUrl,
|
|
500
|
+
publicBaseUrl: this.publicBaseUrl,
|
|
501
|
+
apifyClient: this.apifyClient,
|
|
502
|
+
httpClient: this.httpClient,
|
|
503
|
+
id: this.id,
|
|
504
|
+
params: this.params,
|
|
505
|
+
});
|
|
506
|
+
return this.#serverClient;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Returns a client for the server interface of this Actor in Standby mode.
|
|
510
|
+
*
|
|
511
|
+
* Named after Actor Standby, the former name of Server Actors.
|
|
512
|
+
*
|
|
513
|
+
* @deprecated Use {@link server} instead. Will be removed in v4.
|
|
514
|
+
* @returns The client for the server interface of this Actor
|
|
515
|
+
* @see https://docs.apify.com/platform/actors/running/standby
|
|
516
|
+
*/
|
|
517
|
+
standby() {
|
|
518
|
+
this.httpClient.logger.deprecated('`standby()` is deprecated and will be removed in v4. Use `server()` instead.');
|
|
519
|
+
return this.server();
|
|
434
520
|
}
|
|
435
521
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ACTOR_PERMISSION_LEVEL } from '@apify/consts';
|
|
2
2
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ActorListItem } from '../models.js';
|
|
5
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
5
6
|
import type { PaginatedIterator, PaginatedList, PaginationOptions } from '../utils.js';
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
export type {
|
|
7
|
+
import type { ActorResource, ActorStandby, DefaultRunOptions, ExampleRunInput } from './actor.js';
|
|
8
|
+
import type { Version } from './actor_version.js';
|
|
9
|
+
export type { ActorListItem } from '../models.js';
|
|
9
10
|
/**
|
|
10
11
|
* Client for managing the collection of Actors in your account.
|
|
11
12
|
*
|
|
@@ -51,18 +52,21 @@ export declare class ActorCollectionClient extends ResourceCollectionClient {
|
|
|
51
52
|
* ```
|
|
52
53
|
*
|
|
53
54
|
* @param options - Pagination options.
|
|
55
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
54
56
|
* @returns A paginated iterator of Actors.
|
|
55
57
|
* @see https://docs.apify.com/api/v2/acts-get
|
|
56
58
|
*/
|
|
57
|
-
list(options?: ActorCollectionListOptions): PaginatedIterator<
|
|
59
|
+
list(options?: ActorCollectionListOptions): PaginatedIterator<ActorListItem>;
|
|
58
60
|
/**
|
|
59
61
|
* Creates a new Actor.
|
|
60
62
|
*
|
|
61
63
|
* @param actor - The Actor data.
|
|
64
|
+
* @param options - Request options
|
|
65
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
62
66
|
* @returns The created Actor object.
|
|
63
67
|
* @see https://docs.apify.com/api/v2/acts-post
|
|
64
68
|
*/
|
|
65
|
-
create(actor: ActorCollectionCreateOptions): Promise<
|
|
69
|
+
create(actor: ActorCollectionCreateOptions, options?: TimeoutOptions): Promise<ActorResource>;
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
72
|
* Field to order a list of Actors by.
|
|
@@ -73,7 +77,7 @@ export declare enum ActorListSortBy {
|
|
|
73
77
|
CREATED_AT = "createdAt",
|
|
74
78
|
LAST_RUN_STARTED_AT = "stats.lastRunStartedAt"
|
|
75
79
|
}
|
|
76
|
-
export interface ActorCollectionListOptions extends PaginationOptions {
|
|
80
|
+
export interface ActorCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
77
81
|
my?: boolean;
|
|
78
82
|
desc?: boolean;
|
|
79
83
|
/**
|
|
@@ -81,7 +85,7 @@ export interface ActorCollectionListOptions extends PaginationOptions {
|
|
|
81
85
|
*/
|
|
82
86
|
sortBy?: `${ActorListSortBy}`;
|
|
83
87
|
}
|
|
84
|
-
export type ActorCollectionListResult = PaginatedList<
|
|
88
|
+
export type ActorCollectionListResult = PaginatedList<ActorListItem>;
|
|
85
89
|
export interface ActorCollectionCreateOptions {
|
|
86
90
|
/**
|
|
87
91
|
* @since Added in 2.8.6
|
|
@@ -90,12 +94,12 @@ export interface ActorCollectionCreateOptions {
|
|
|
90
94
|
/**
|
|
91
95
|
* @since Added in 2.8.6
|
|
92
96
|
*/
|
|
93
|
-
defaultRunOptions?:
|
|
97
|
+
defaultRunOptions?: DefaultRunOptions;
|
|
94
98
|
description?: string;
|
|
95
99
|
/**
|
|
96
100
|
* @since Added in 2.8.6
|
|
97
101
|
*/
|
|
98
|
-
exampleRunInput?:
|
|
102
|
+
exampleRunInput?: ExampleRunInput;
|
|
99
103
|
/**
|
|
100
104
|
* @since Added in 2.8.6
|
|
101
105
|
*/
|
|
@@ -111,7 +115,7 @@ export interface ActorCollectionCreateOptions {
|
|
|
111
115
|
*/
|
|
112
116
|
seoDescription?: string;
|
|
113
117
|
title?: string;
|
|
114
|
-
versions?:
|
|
118
|
+
versions?: Version[];
|
|
115
119
|
/**
|
|
116
120
|
* @since Added in 2.9.5
|
|
117
121
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
3
|
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
4
5
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
6
|
const actorCreateSchema = anyObjectSchema.optional();
|
|
6
7
|
/**
|
|
@@ -53,23 +54,27 @@ export class ActorCollectionClient extends ResourceCollectionClient {
|
|
|
53
54
|
* ```
|
|
54
55
|
*
|
|
55
56
|
* @param options - Pagination options.
|
|
57
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
56
58
|
* @returns A paginated iterator of Actors.
|
|
57
59
|
* @see https://docs.apify.com/api/v2/acts-get
|
|
58
60
|
*/
|
|
59
61
|
list(options = {}) {
|
|
60
62
|
const parsed = parseArgument(options, listOptionsSchema, 'ActorCollectionListOptions');
|
|
61
|
-
return this.
|
|
63
|
+
return this.listResourcesPaginated(schemas.ListOfActors(), parsed, 'medium');
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
66
|
* Creates a new Actor.
|
|
65
67
|
*
|
|
66
68
|
* @param actor - The Actor data.
|
|
69
|
+
* @param options - Request options
|
|
70
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
67
71
|
* @returns The created Actor object.
|
|
68
72
|
* @see https://docs.apify.com/api/v2/acts-post
|
|
69
73
|
*/
|
|
70
|
-
async create(actor) {
|
|
74
|
+
async create(actor, options = {}) {
|
|
71
75
|
parseArgument(actor, actorCreateSchema);
|
|
72
|
-
|
|
76
|
+
const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
77
|
+
return this.createResource(schemas.ActorResource(), actor, timeoutSecs, signal);
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
/**
|
|
@@ -88,4 +93,5 @@ const listOptionsSchema = z.strictObject({
|
|
|
88
93
|
...paginationOptionsShape,
|
|
89
94
|
desc: z.boolean().optional(),
|
|
90
95
|
sortBy: z.enum(ActorListSortBy).optional(),
|
|
96
|
+
...timeoutOptionsShape,
|
|
91
97
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
|
+
import type { EnvVar } from './actor_version.js';
|
|
4
5
|
/**
|
|
5
6
|
* Client for managing a specific Actor environment variable.
|
|
6
7
|
*
|
|
@@ -32,22 +33,28 @@ export declare class ActorEnvVarClient extends ResourceClient {
|
|
|
32
33
|
/**
|
|
33
34
|
* Retrieves the environment variable.
|
|
34
35
|
*
|
|
36
|
+
* @param options - Request options
|
|
37
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
35
38
|
* @returns The environment variable object, or `undefined` if it does not exist.
|
|
36
39
|
* @see https://docs.apify.com/api/v2/act-version-env-var-get
|
|
37
40
|
*/
|
|
38
|
-
get(): Promise<
|
|
41
|
+
get(options?: TimeoutOptions): Promise<EnvVar | undefined>;
|
|
39
42
|
/**
|
|
40
43
|
* Updates the environment variable.
|
|
41
44
|
*
|
|
42
45
|
* @param actorEnvVar - The updated environment variable data.
|
|
46
|
+
* @param options - Request options
|
|
47
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
43
48
|
* @returns The updated environment variable object.
|
|
44
49
|
* @see https://docs.apify.com/api/v2/act-version-env-var-put
|
|
45
50
|
*/
|
|
46
|
-
update(actorEnvVar:
|
|
51
|
+
update(actorEnvVar: EnvVar, options?: TimeoutOptions): Promise<EnvVar>;
|
|
47
52
|
/**
|
|
48
53
|
* Deletes the environment variable.
|
|
49
54
|
*
|
|
55
|
+
* @param options - Request options
|
|
56
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
50
57
|
* @see https://docs.apify.com/api/v2/act-version-env-var-delete
|
|
51
58
|
*/
|
|
52
|
-
delete(): Promise<void>;
|
|
59
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
53
60
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
2
|
import * as schemas from '../schemas.js';
|
|
3
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
3
4
|
import { anyObjectSchema, parseArgument } from '../utils.js';
|
|
4
5
|
/**
|
|
5
6
|
* Client for managing a specific Actor environment variable.
|
|
@@ -37,29 +38,38 @@ export class ActorEnvVarClient extends ResourceClient {
|
|
|
37
38
|
/**
|
|
38
39
|
* Retrieves the environment variable.
|
|
39
40
|
*
|
|
41
|
+
* @param options - Request options
|
|
42
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
40
43
|
* @returns The environment variable object, or `undefined` if it does not exist.
|
|
41
44
|
* @see https://docs.apify.com/api/v2/act-version-env-var-get
|
|
42
45
|
*/
|
|
43
|
-
async get() {
|
|
44
|
-
|
|
46
|
+
async get(options = {}) {
|
|
47
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
48
|
+
return this.getResource(schemas.EnvVar(), {}, timeoutSecs, signal);
|
|
45
49
|
}
|
|
46
50
|
/**
|
|
47
51
|
* Updates the environment variable.
|
|
48
52
|
*
|
|
49
53
|
* @param actorEnvVar - The updated environment variable data.
|
|
54
|
+
* @param options - Request options
|
|
55
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
50
56
|
* @returns The updated environment variable object.
|
|
51
57
|
* @see https://docs.apify.com/api/v2/act-version-env-var-put
|
|
52
58
|
*/
|
|
53
|
-
async update(actorEnvVar) {
|
|
59
|
+
async update(actorEnvVar, options = {}) {
|
|
54
60
|
parseArgument(actorEnvVar, anyObjectSchema);
|
|
55
|
-
|
|
61
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
62
|
+
return this.updateResource(schemas.EnvVar(), actorEnvVar, timeoutSecs, signal);
|
|
56
63
|
}
|
|
57
64
|
/**
|
|
58
65
|
* Deletes the environment variable.
|
|
59
66
|
*
|
|
67
|
+
* @param options - Request options
|
|
68
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
60
69
|
* @see https://docs.apify.com/api/v2/act-version-env-var-delete
|
|
61
70
|
*/
|
|
62
|
-
async delete() {
|
|
63
|
-
|
|
71
|
+
async delete(options = {}) {
|
|
72
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
73
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
64
74
|
}
|
|
65
75
|
}
|