apify-client 3.0.0-beta.8 → 3.0.0-rc.0
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 +10 -2
- package/dist/apify_api_error.d.ts +11 -26
- package/dist/apify_api_error.js +31 -22
- 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 +36 -24
- package/dist/base/resource_client.d.ts +21 -8
- package/dist/base/resource_client.js +67 -33
- 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 +3 -4
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +27 -22
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +785 -290
- package/dist/generated/schemas.d.ts +720 -747
- package/dist/generated/schemas.js +166 -162
- package/dist/http_clients/axios.d.ts +60 -0
- package/dist/http_clients/axios.js +117 -0
- package/dist/http_clients/base.d.ts +331 -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 +4 -1
- package/dist/index.js +3 -1
- package/dist/invalid_response_body_error.d.ts +13 -0
- package/dist/invalid_response_body_error.js +17 -0
- package/dist/models.d.ts +162 -194
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +74 -34
- package/dist/resource_clients/actor.js +87 -56
- package/dist/resource_clients/actor_collection.d.ts +18 -12
- package/dist/resource_clients/actor_collection.js +11 -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_version.d.ts +20 -5
- package/dist/resource_clients/actor_version.js +19 -9
- package/dist/resource_clients/actor_version_collection.d.ts +11 -4
- package/dist/resource_clients/actor_version_collection.js +13 -4
- package/dist/resource_clients/build.d.ts +20 -7
- package/dist/resource_clients/build.js +35 -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 +53 -35
- package/dist/resource_clients/dataset.js +105 -80
- 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 +62 -20
- package/dist/resource_clients/key_value_store.js +78 -40
- 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 +13 -20
- package/dist/resource_clients/log.js +141 -59
- package/dist/resource_clients/request_queue.d.ts +68 -31
- package/dist/resource_clients/request_queue.js +173 -91
- 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 -28
- package/dist/resource_clients/run.js +190 -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 +16 -7
- package/dist/resource_clients/schedule.js +30 -22
- 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 +6 -4
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +36 -13
- package/dist/resource_clients/task.js +79 -46
- 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 +19 -10
- package/dist/resource_clients/user.js +42 -38
- package/dist/resource_clients/webhook.d.ts +17 -8
- package/dist/resource_clients/webhook.js +30 -22
- 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/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 +1 -1
- package/dist/schemas.js +1 -1
- 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 +82 -45
- package/dist/utils.js +197 -146
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- 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,7 +3,9 @@ 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, isStream, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
|
|
8
|
+
import { startWaitingForResources } from '../wait_for_resources.js';
|
|
7
9
|
import { ActorVersionClient } from './actor_version.js';
|
|
8
10
|
import { ActorVersionCollectionClient } from './actor_version_collection.js';
|
|
9
11
|
import { BuildClient } from './build.js';
|
|
@@ -15,19 +17,21 @@ const startOptionsSchema = z.strictObject({
|
|
|
15
17
|
build: z.string().optional(),
|
|
16
18
|
contentType: z.string().optional(),
|
|
17
19
|
memory: z.number().optional(),
|
|
18
|
-
|
|
20
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
19
21
|
waitForFinish: z.number().optional(),
|
|
20
22
|
webhooks: z.array(anyObjectSchema).optional(),
|
|
21
23
|
maxItems: z.number().min(0).optional(),
|
|
22
24
|
maxTotalChargeUsd: z.number().min(0).optional(),
|
|
23
25
|
restartOnError: z.boolean().optional(),
|
|
24
26
|
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
27
|
+
waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
|
|
28
|
+
...timeoutOptionsShape,
|
|
25
29
|
});
|
|
26
30
|
const callOptionsSchema = z.strictObject({
|
|
27
31
|
build: z.string().optional(),
|
|
28
32
|
contentType: z.string().optional(),
|
|
29
33
|
memory: z.number().optional(),
|
|
30
|
-
|
|
34
|
+
runTimeoutSecs: z.number().min(0).optional(),
|
|
31
35
|
waitSecs: z.number().min(0).optional(),
|
|
32
36
|
webhooks: z.array(anyObjectSchema).optional(),
|
|
33
37
|
maxItems: z.number().min(0).optional(),
|
|
@@ -35,18 +39,23 @@ const callOptionsSchema = z.strictObject({
|
|
|
35
39
|
log: z.union([z.null(), z.instanceof(Log), z.literal('default')]).optional(),
|
|
36
40
|
restartOnError: z.boolean().optional(),
|
|
37
41
|
forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
|
|
42
|
+
waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
|
|
43
|
+
...timeoutOptionsShape,
|
|
38
44
|
});
|
|
39
45
|
const validateInputOptionsSchema = z.strictObject({
|
|
40
46
|
build: z.string().optional(),
|
|
41
47
|
contentType: z.string().optional(),
|
|
48
|
+
...timeoutOptionsShape,
|
|
42
49
|
});
|
|
43
|
-
const versionNumberSchema = z.string();
|
|
50
|
+
const versionNumberSchema = z.string().min(1);
|
|
44
51
|
const buildOptionsSchema = z.strictObject({
|
|
45
52
|
betaPackages: z.boolean().optional(),
|
|
46
53
|
tag: z.string().optional(),
|
|
47
54
|
useCache: z.boolean().optional(),
|
|
48
55
|
waitForFinish: z.number().optional(),
|
|
56
|
+
...timeoutOptionsShape,
|
|
49
57
|
});
|
|
58
|
+
const defaultBuildOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
|
|
50
59
|
const lastRunOptionsSchema = z.strictObject({
|
|
51
60
|
status: z.enum(ACTOR_JOB_STATUSES).optional(),
|
|
52
61
|
origin: z.enum(META_ORIGINS).optional(),
|
|
@@ -84,30 +93,39 @@ export class ActorClient extends ResourceClient {
|
|
|
84
93
|
/**
|
|
85
94
|
* Gets the Actor object from the Apify API.
|
|
86
95
|
*
|
|
96
|
+
* @param options - Request options
|
|
97
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
87
98
|
* @returns The Actor object, or `undefined` if it does not exist
|
|
88
99
|
* @see https://docs.apify.com/api/v2/act-get
|
|
89
100
|
*/
|
|
90
|
-
async get() {
|
|
91
|
-
|
|
101
|
+
async get(options = {}) {
|
|
102
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
103
|
+
return this.getResource(schemas.ActorResource(), {}, timeoutSecs, signal);
|
|
92
104
|
}
|
|
93
105
|
/**
|
|
94
106
|
* Updates the Actor with specified fields.
|
|
95
107
|
*
|
|
96
108
|
* @param newFields - Fields to update in the Actor
|
|
109
|
+
* @param options - Request options
|
|
110
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
97
111
|
* @returns The updated Actor object
|
|
98
112
|
* @see https://docs.apify.com/api/v2/act-put
|
|
99
113
|
*/
|
|
100
|
-
async update(newFields) {
|
|
114
|
+
async update(newFields, options = {}) {
|
|
101
115
|
parseArgument(newFields, anyObjectSchema);
|
|
102
|
-
|
|
116
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
117
|
+
return this.updateResource(schemas.ActorResource(), newFields, timeoutSecs, signal);
|
|
103
118
|
}
|
|
104
119
|
/**
|
|
105
120
|
* Deletes the Actor.
|
|
106
121
|
*
|
|
122
|
+
* @param options - Request options
|
|
123
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
107
124
|
* @see https://docs.apify.com/api/v2/act-delete
|
|
108
125
|
*/
|
|
109
|
-
async delete() {
|
|
110
|
-
|
|
126
|
+
async delete(options = {}) {
|
|
127
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
128
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
111
129
|
}
|
|
112
130
|
/**
|
|
113
131
|
* Starts the Actor and immediately returns the Run object.
|
|
@@ -116,17 +134,20 @@ export class ActorClient extends ResourceClient {
|
|
|
116
134
|
* asynchronously and this method returns immediately without waiting for completion.
|
|
117
135
|
* Use the {@link call} method if you want to wait for the Actor to finish.
|
|
118
136
|
*
|
|
119
|
-
* @param input - Input for the Actor
|
|
120
|
-
*
|
|
137
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
138
|
+
* Omit it to run the Actor without input.
|
|
121
139
|
* @param options - Run configuration options
|
|
122
140
|
* @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.
|
|
123
141
|
* @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
|
|
124
|
-
* @param options.
|
|
142
|
+
* @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
|
|
125
143
|
* @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).
|
|
126
144
|
* @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
|
|
127
145
|
* @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
|
|
128
146
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
|
|
129
|
-
* @param options.
|
|
147
|
+
* @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
|
|
148
|
+
* the run. `true` retries until the run starts, a number stops retrying after that many seconds.
|
|
149
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
150
|
+
* when the API is asked to hold the response.
|
|
130
151
|
* @returns The Actor run object with status, usage, and storage IDs
|
|
131
152
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
132
153
|
*
|
|
@@ -139,18 +160,17 @@ export class ActorClient extends ResourceClient {
|
|
|
139
160
|
* // Start Actor with specific build and memory
|
|
140
161
|
* const run = await client.actor('my-actor').start(
|
|
141
162
|
* { url: 'https://example.com' },
|
|
142
|
-
* { build: '0.1.2', memory: 512,
|
|
163
|
+
* { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
|
|
143
164
|
* );
|
|
144
165
|
* ```
|
|
145
166
|
*/
|
|
146
167
|
async start(input, options = {}) {
|
|
147
|
-
// input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
|
|
148
|
-
// then it will process input as a buffer.
|
|
149
168
|
const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
|
|
150
|
-
const { waitForFinish,
|
|
169
|
+
const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, waitForResources, timeoutSecs, signal, } = parsed;
|
|
170
|
+
// The API's `timeout` parameter bounds the run, not the request.
|
|
151
171
|
const params = {
|
|
152
172
|
waitForFinish,
|
|
153
|
-
timeout,
|
|
173
|
+
timeout: runTimeoutSecs,
|
|
154
174
|
memory,
|
|
155
175
|
build,
|
|
156
176
|
webhooks: stringifyWebhooksToBase64(parsed.webhooks),
|
|
@@ -160,20 +180,22 @@ export class ActorClient extends ResourceClient {
|
|
|
160
180
|
forcePermissionLevel,
|
|
161
181
|
};
|
|
162
182
|
const request = {
|
|
163
|
-
url: this.
|
|
183
|
+
url: this.buildUrl('runs'),
|
|
164
184
|
method: 'POST',
|
|
165
185
|
data: input,
|
|
166
|
-
params: this.
|
|
167
|
-
//
|
|
168
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
186
|
+
params: this.buildParams(params),
|
|
187
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
169
188
|
stringifyFunctions: true,
|
|
189
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
|
|
190
|
+
signal,
|
|
170
191
|
};
|
|
171
192
|
if (parsed.contentType) {
|
|
172
193
|
request.headers = {
|
|
173
194
|
'content-type': parsed.contentType,
|
|
174
195
|
};
|
|
175
196
|
}
|
|
176
|
-
|
|
197
|
+
// A `Readable` input is consumed by the first attempt, so a retry would start the run with an empty input.
|
|
198
|
+
const response = await startWaitingForResources(async () => this.httpClient.call(request), isStream(input) ? false : waitForResources, this.httpClient.logger, signal);
|
|
177
199
|
return parseResponse(response, schemas.Run());
|
|
178
200
|
}
|
|
179
201
|
/**
|
|
@@ -183,14 +205,18 @@ export class ActorClient extends ResourceClient {
|
|
|
183
205
|
* by polling the run status. It optionally streams logs to the console or a custom Log instance.
|
|
184
206
|
* By default, it waits indefinitely unless the `waitSecs` option is provided.
|
|
185
207
|
*
|
|
186
|
-
* @param input - Input for the Actor
|
|
187
|
-
*
|
|
208
|
+
* @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
|
|
209
|
+
* Omit it to run the Actor without input.
|
|
188
210
|
* @param options - Run configuration options (extends all options from {@link start})
|
|
189
211
|
* @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
|
|
190
212
|
* @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
|
|
191
213
|
* @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
|
|
192
214
|
* @param options.memory - Memory in megabytes allocated for the run.
|
|
193
|
-
* @param options.
|
|
215
|
+
* @param options.runTimeoutSecs - Maximum run duration in seconds.
|
|
216
|
+
* @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
|
|
217
|
+
* the run. `true` retries until the run starts, a number stops retrying after that many seconds. The time spent
|
|
218
|
+
* retrying doesn't count toward `waitSecs`.
|
|
219
|
+
* @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
|
|
194
220
|
* @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
|
|
195
221
|
* @see https://docs.apify.com/api/v2/act-runs-post
|
|
196
222
|
*
|
|
@@ -214,20 +240,18 @@ export class ActorClient extends ResourceClient {
|
|
|
214
240
|
* ```
|
|
215
241
|
*/
|
|
216
242
|
async call(input, options = {}) {
|
|
217
|
-
// input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
|
|
218
|
-
// then it will process input as a buffer.
|
|
219
243
|
const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
|
|
220
|
-
const { waitSecs, log, ...startOptions } = parsed;
|
|
221
|
-
const { id } = await this.start(input, startOptions);
|
|
244
|
+
const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
|
|
245
|
+
const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
|
|
222
246
|
// Calling root client because we need access to top level API.
|
|
223
247
|
// Creating a new instance of RunClient here would only allow
|
|
224
248
|
// setting it up as a nested route under actor API.
|
|
225
249
|
const newRunClient = this.apifyClient.run(id);
|
|
226
|
-
const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
|
|
250
|
+
const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
|
|
227
251
|
streamedLog?.start();
|
|
228
252
|
return this.apifyClient
|
|
229
253
|
.run(id)
|
|
230
|
-
.waitForFinish({ waitSecs })
|
|
254
|
+
.waitForFinish({ waitSecs, timeoutSecs, signal })
|
|
231
255
|
.finally(async () => {
|
|
232
256
|
await streamedLog?.stop();
|
|
233
257
|
});
|
|
@@ -240,13 +264,12 @@ export class ActorClient extends ResourceClient {
|
|
|
240
264
|
* invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
|
|
241
265
|
* validation problem.
|
|
242
266
|
*
|
|
243
|
-
* @param input - Input to validate against the Actor's input schema
|
|
244
|
-
*
|
|
245
|
-
* input should be a string or Buffer.
|
|
267
|
+
* @param input - Input to validate against the Actor's input schema: an object or array serialized to JSON, or
|
|
268
|
+
* raw bytes sent as they are.
|
|
246
269
|
* @param options - Validation options
|
|
247
270
|
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
248
271
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
249
|
-
* @param options.
|
|
272
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
250
273
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
251
274
|
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
252
275
|
*
|
|
@@ -264,17 +287,16 @@ export class ActorClient extends ResourceClient {
|
|
|
264
287
|
* @since Added in 2.24.0
|
|
265
288
|
*/
|
|
266
289
|
async validateInput(input, options = {}) {
|
|
267
|
-
// input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
|
|
268
|
-
// then it will process input as a buffer.
|
|
269
290
|
const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
|
|
270
291
|
const request = {
|
|
271
|
-
url: this.
|
|
292
|
+
url: this.buildUrl('validate-input'),
|
|
272
293
|
method: 'POST',
|
|
273
294
|
data: input,
|
|
274
|
-
params: this.
|
|
275
|
-
//
|
|
276
|
-
// to stringify functions to JSON, instead of omitting them.
|
|
295
|
+
params: this.buildParams({ build: parsed.build }),
|
|
296
|
+
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
277
297
|
stringifyFunctions: true,
|
|
298
|
+
timeoutSecs: parsed.timeoutSecs ?? 'short',
|
|
299
|
+
signal: parsed.signal,
|
|
278
300
|
};
|
|
279
301
|
if (parsed.contentType) {
|
|
280
302
|
request.headers = {
|
|
@@ -296,6 +318,8 @@ export class ActorClient extends ResourceClient {
|
|
|
296
318
|
* @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
|
|
297
319
|
* @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
|
|
298
320
|
* @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).
|
|
321
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
|
|
322
|
+
* when the API is asked to hold the response.
|
|
299
323
|
* @returns The Build object with status and build details
|
|
300
324
|
* @see https://docs.apify.com/api/v2/act-builds-post
|
|
301
325
|
*
|
|
@@ -315,14 +339,16 @@ export class ActorClient extends ResourceClient {
|
|
|
315
339
|
*/
|
|
316
340
|
async build(versionNumber, options = {}) {
|
|
317
341
|
parseArgument(versionNumber, versionNumberSchema);
|
|
318
|
-
const
|
|
342
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
|
|
319
343
|
const response = await this.httpClient.call({
|
|
320
|
-
url: this.
|
|
344
|
+
url: this.buildUrl('builds'),
|
|
321
345
|
method: 'POST',
|
|
322
|
-
params: this.
|
|
346
|
+
params: this.buildParams({
|
|
323
347
|
version: versionNumber,
|
|
324
|
-
...
|
|
348
|
+
...params,
|
|
325
349
|
}),
|
|
350
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
|
|
351
|
+
signal,
|
|
326
352
|
});
|
|
327
353
|
return parseResponse(response, schemas.Build());
|
|
328
354
|
}
|
|
@@ -335,6 +361,8 @@ export class ActorClient extends ResourceClient {
|
|
|
335
361
|
*
|
|
336
362
|
* @param options - Options for getting the default build
|
|
337
363
|
* @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).
|
|
364
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
365
|
+
* when the API is asked to hold the response.
|
|
338
366
|
* @returns A client for the default build
|
|
339
367
|
* @see https://docs.apify.com/api/v2/act-build-default-get
|
|
340
368
|
*
|
|
@@ -352,10 +380,13 @@ export class ActorClient extends ResourceClient {
|
|
|
352
380
|
* @since Added in 2.12.2
|
|
353
381
|
*/
|
|
354
382
|
async defaultBuild(options = {}) {
|
|
383
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
|
|
355
384
|
const response = await this.httpClient.call({
|
|
356
|
-
url: this.
|
|
385
|
+
url: this.buildUrl('builds/default'),
|
|
357
386
|
method: 'GET',
|
|
358
|
-
params: this.
|
|
387
|
+
params: this.buildParams(params),
|
|
388
|
+
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
|
|
389
|
+
signal,
|
|
359
390
|
});
|
|
360
391
|
const { id } = parseResponse(response, schemas.Build());
|
|
361
392
|
return new BuildClient({
|
|
@@ -385,9 +416,9 @@ export class ActorClient extends ResourceClient {
|
|
|
385
416
|
*/
|
|
386
417
|
lastRun(options = {}) {
|
|
387
418
|
const parsed = parseArgument(options, lastRunOptionsSchema, 'ActorLastRunOptions');
|
|
388
|
-
return new RunClient(this.
|
|
419
|
+
return new RunClient(this.subResourceOptions({
|
|
389
420
|
id: 'last',
|
|
390
|
-
params: this.
|
|
421
|
+
params: this.buildParams(parsed),
|
|
391
422
|
resourcePath: 'runs',
|
|
392
423
|
}));
|
|
393
424
|
}
|
|
@@ -398,7 +429,7 @@ export class ActorClient extends ResourceClient {
|
|
|
398
429
|
* @see https://docs.apify.com/api/v2/act-builds-get
|
|
399
430
|
*/
|
|
400
431
|
builds() {
|
|
401
|
-
return new BuildCollectionClient(this.
|
|
432
|
+
return new BuildCollectionClient(this.subResourceOptions({
|
|
402
433
|
resourcePath: 'builds',
|
|
403
434
|
}));
|
|
404
435
|
}
|
|
@@ -409,7 +440,7 @@ export class ActorClient extends ResourceClient {
|
|
|
409
440
|
* @see https://docs.apify.com/api/v2/act-runs-get
|
|
410
441
|
*/
|
|
411
442
|
runs() {
|
|
412
|
-
return new RunCollectionClient(this.
|
|
443
|
+
return new RunCollectionClient(this.subResourceOptions({
|
|
413
444
|
resourcePath: 'runs',
|
|
414
445
|
}));
|
|
415
446
|
}
|
|
@@ -422,7 +453,7 @@ export class ActorClient extends ResourceClient {
|
|
|
422
453
|
*/
|
|
423
454
|
version(versionNumber) {
|
|
424
455
|
parseArgument(versionNumber, versionNumberSchema);
|
|
425
|
-
return new ActorVersionClient(this.
|
|
456
|
+
return new ActorVersionClient(this.subResourceOptions({
|
|
426
457
|
id: versionNumber,
|
|
427
458
|
}));
|
|
428
459
|
}
|
|
@@ -433,7 +464,7 @@ export class ActorClient extends ResourceClient {
|
|
|
433
464
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
434
465
|
*/
|
|
435
466
|
versions() {
|
|
436
|
-
return new ActorVersionCollectionClient(this.
|
|
467
|
+
return new ActorVersionCollectionClient(this.subResourceOptions());
|
|
437
468
|
}
|
|
438
469
|
/**
|
|
439
470
|
* Returns a client for managing webhooks associated with this Actor.
|
|
@@ -442,6 +473,6 @@ export class ActorClient extends ResourceClient {
|
|
|
442
473
|
* @see https://docs.apify.com/api/v2/act-webhooks-get
|
|
443
474
|
*/
|
|
444
475
|
webhooks() {
|
|
445
|
-
return new WebhookCollectionClient(this.
|
|
476
|
+
return new WebhookCollectionClient(this.subResourceOptions());
|
|
446
477
|
}
|
|
447
478
|
}
|
|
@@ -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,35 +52,40 @@ 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
|
/**
|
|
72
|
+
* Field to order a list of Actors by.
|
|
73
|
+
*
|
|
68
74
|
* @since Added in 2.12.6
|
|
69
75
|
*/
|
|
70
76
|
export declare enum ActorListSortBy {
|
|
71
77
|
CREATED_AT = "createdAt",
|
|
72
78
|
LAST_RUN_STARTED_AT = "stats.lastRunStartedAt"
|
|
73
79
|
}
|
|
74
|
-
export interface ActorCollectionListOptions extends PaginationOptions {
|
|
80
|
+
export interface ActorCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
75
81
|
my?: boolean;
|
|
76
82
|
desc?: boolean;
|
|
77
83
|
/**
|
|
78
84
|
* @since Added in 2.12.6
|
|
79
85
|
*/
|
|
80
|
-
sortBy?: ActorListSortBy
|
|
86
|
+
sortBy?: `${ActorListSortBy}`;
|
|
81
87
|
}
|
|
82
|
-
export type ActorCollectionListResult = PaginatedList<
|
|
88
|
+
export type ActorCollectionListResult = PaginatedList<ActorListItem>;
|
|
83
89
|
export interface ActorCollectionCreateOptions {
|
|
84
90
|
/**
|
|
85
91
|
* @since Added in 2.8.6
|
|
@@ -88,12 +94,12 @@ export interface ActorCollectionCreateOptions {
|
|
|
88
94
|
/**
|
|
89
95
|
* @since Added in 2.8.6
|
|
90
96
|
*/
|
|
91
|
-
defaultRunOptions?:
|
|
97
|
+
defaultRunOptions?: DefaultRunOptions;
|
|
92
98
|
description?: string;
|
|
93
99
|
/**
|
|
94
100
|
* @since Added in 2.8.6
|
|
95
101
|
*/
|
|
96
|
-
exampleRunInput?:
|
|
102
|
+
exampleRunInput?: ExampleRunInput;
|
|
97
103
|
/**
|
|
98
104
|
* @since Added in 2.8.6
|
|
99
105
|
*/
|
|
@@ -109,7 +115,7 @@ export interface ActorCollectionCreateOptions {
|
|
|
109
115
|
*/
|
|
110
116
|
seoDescription?: string;
|
|
111
117
|
title?: string;
|
|
112
|
-
versions?:
|
|
118
|
+
versions?: Version[];
|
|
113
119
|
/**
|
|
114
120
|
* @since Added in 2.9.5
|
|
115
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,26 +54,32 @@ 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
|
/**
|
|
81
|
+
* Field to order a list of Actors by.
|
|
82
|
+
*
|
|
76
83
|
* @since Added in 2.12.6
|
|
77
84
|
*/
|
|
78
85
|
export var ActorListSortBy;
|
|
@@ -86,4 +93,5 @@ const listOptionsSchema = z.strictObject({
|
|
|
86
93
|
...paginationOptionsShape,
|
|
87
94
|
desc: z.boolean().optional(),
|
|
88
95
|
sortBy: z.enum(ActorListSortBy).optional(),
|
|
96
|
+
...timeoutOptionsShape,
|
|
89
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
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
3
4
|
import type { PaginatedList } from '../utils.js';
|
|
4
|
-
import type {
|
|
5
|
+
import type { EnvVar } from './actor_version.js';
|
|
5
6
|
/**
|
|
6
7
|
* Client for managing the collection of environment variables for an Actor version.
|
|
7
8
|
*
|
|
@@ -49,20 +50,24 @@ export declare class ActorEnvVarCollectionClient extends ResourceCollectionClien
|
|
|
49
50
|
* for await (const singleItem of client.list()) {...}
|
|
50
51
|
* ```
|
|
51
52
|
*
|
|
53
|
+
* @param options - Request options
|
|
54
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
52
55
|
* @returns The environment variables, awaitable as a whole list or iterable one by one.
|
|
53
56
|
* @see https://docs.apify.com/api/v2/act-version-env-vars-get
|
|
54
57
|
*/
|
|
55
|
-
list(): Promise<ActorEnvVarListResult> & AsyncIterable<
|
|
58
|
+
list(options?: TimeoutOptions): Promise<ActorEnvVarListResult> & AsyncIterable<EnvVar>;
|
|
56
59
|
/**
|
|
57
60
|
* Creates a new environment variable for this Actor version.
|
|
58
61
|
*
|
|
59
62
|
* @param actorEnvVar - The environment variable data.
|
|
63
|
+
* @param options - Request options
|
|
64
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
60
65
|
* @returns The created environment variable object.
|
|
61
66
|
* @see https://docs.apify.com/api/v2/act-version-env-vars-post
|
|
62
67
|
*/
|
|
63
|
-
create(actorEnvVar:
|
|
68
|
+
create(actorEnvVar: EnvVar, options?: TimeoutOptions): Promise<EnvVar>;
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
66
71
|
* @since Added in 2.1.0
|
|
67
72
|
*/
|
|
68
|
-
export type ActorEnvVarListResult = Pick<PaginatedList<
|
|
73
|
+
export type ActorEnvVarListResult = Pick<PaginatedList<EnvVar>, 'total' | 'items'>;
|