apify-client 3.0.0-beta.2 → 3.0.0-beta.20
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 +3 -1
- package/dist/apify_api_error.d.ts +60 -19
- package/dist/apify_api_error.js +88 -21
- package/dist/apify_client.d.ts +22 -3
- package/dist/apify_client.js +35 -29
- package/dist/base/api_client.d.ts +6 -6
- package/dist/base/api_client.js +24 -16
- package/dist/base/resource_client.d.ts +23 -9
- package/dist/base/resource_client.js +49 -25
- package/dist/base/resource_collection_client.d.ts +7 -4
- package/dist/base/resource_collection_client.js +21 -15
- package/dist/bundle.js +38 -48
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/http_client.d.ts +18 -51
- package/dist/http_client.js +79 -42
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/interceptors.js +22 -4
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +32 -52
- package/dist/resource_clients/actor.d.ts +46 -31
- package/dist/resource_clients/actor.js +71 -53
- 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 +35 -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 +23 -9
- package/dist/resource_clients/dataset.js +70 -48
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +48 -15
- package/dist/resource_clients/key_value_store.js +69 -39
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +9 -19
- package/dist/resource_clients/log.js +55 -44
- package/dist/resource_clients/request_queue.d.ts +56 -26
- package/dist/resource_clients/request_queue.js +178 -113
- 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 +51 -17
- package/dist/resource_clients/run.js +83 -43
- 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 +31 -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 +67 -44
- 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 +40 -39
- package/dist/resource_clients/webhook.d.ts +14 -5
- package/dist/resource_clients/webhook.js +30 -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/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 +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +57 -41
- package/dist/utils.js +155 -121
- package/package.json +36 -35
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -153
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { LEVELS, Log } from '@apify/log';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
-
import
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { optionalTimeoutSchema, timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
6
|
+
import { anyObjectSchema, isNode, parseArgument, parseResponse } from '../utils.js';
|
|
5
7
|
import { DatasetClient } from './dataset.js';
|
|
6
8
|
import { KeyValueStoreClient } from './key_value_store.js';
|
|
7
9
|
import { LogClient, LoggerActorRedirect, StreamedLog } from './log.js';
|
|
8
10
|
import { RequestQueueClient } from './request_queue.js';
|
|
9
11
|
const RUN_CHARGE_IDEMPOTENCY_HEADER = 'idempotency-key';
|
|
10
|
-
const getOptionsSchema = z.strictObject({ waitForFinish: z.number().optional() });
|
|
11
|
-
const abortOptionsSchema = z.strictObject({ gracefully: z.boolean().optional() });
|
|
12
|
+
const getOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
|
|
13
|
+
const abortOptionsSchema = z.strictObject({ gracefully: z.boolean().optional(), ...timeoutOptionsShape });
|
|
12
14
|
const targetActorIdSchema = z.string();
|
|
13
15
|
const metamorphOptionsSchema = z.strictObject({
|
|
14
16
|
contentType: z.string().optional(),
|
|
15
17
|
build: z.string().optional(),
|
|
18
|
+
...timeoutOptionsShape,
|
|
16
19
|
});
|
|
17
20
|
const resurrectOptionsSchema = z.strictObject({
|
|
18
21
|
build: z.string().optional(),
|
|
19
22
|
memory: z.number().optional(),
|
|
20
|
-
|
|
23
|
+
runTimeoutSecs: z.number().optional(),
|
|
21
24
|
maxItems: z.number().optional(),
|
|
22
25
|
maxTotalChargeUsd: z.number().optional(),
|
|
23
26
|
restartOnError: z.boolean().optional(),
|
|
27
|
+
...timeoutOptionsShape,
|
|
24
28
|
});
|
|
25
29
|
const chargeOptionsSchema = z.strictObject({
|
|
26
30
|
eventName: z.string(),
|
|
27
31
|
count: z.number().default(1),
|
|
28
32
|
idempotencyKey: z.string().optional(),
|
|
33
|
+
...timeoutOptionsShape,
|
|
29
34
|
});
|
|
30
|
-
const waitForFinishOptionsSchema = z.strictObject({ waitSecs: z.number().optional() });
|
|
35
|
+
const waitForFinishOptionsSchema = z.strictObject({ waitSecs: z.number().optional(), ...timeoutOptionsShape });
|
|
31
36
|
/**
|
|
32
37
|
* Client for managing a specific Actor run.
|
|
33
38
|
*
|
|
@@ -66,6 +71,8 @@ export class RunClient extends ResourceClient {
|
|
|
66
71
|
*
|
|
67
72
|
* @param options - Get options
|
|
68
73
|
* @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).
|
|
74
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
|
|
75
|
+
* when the API is asked to hold the response.
|
|
69
76
|
* @returns The ActorRun object, or `undefined` if it does not exist
|
|
70
77
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
71
78
|
*
|
|
@@ -80,14 +87,15 @@ export class RunClient extends ResourceClient {
|
|
|
80
87
|
* ```
|
|
81
88
|
*/
|
|
82
89
|
async get(options = {}) {
|
|
83
|
-
const
|
|
84
|
-
return this.
|
|
90
|
+
const { timeoutSecs, ...params } = parseArgument(options, getOptionsSchema, 'RunGetOptions');
|
|
91
|
+
return this.getResource(schemas.Run(), params, this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish));
|
|
85
92
|
}
|
|
86
93
|
/**
|
|
87
94
|
* Aborts the Actor run.
|
|
88
95
|
*
|
|
89
96
|
* @param options - Abort options
|
|
90
97
|
* @param options.gracefully - If `true`, the Actor run will abort gracefully - it can send status messages and perform cleanup. Default is `false` (immediate abort).
|
|
98
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
91
99
|
* @returns The updated ActorRun object with `ABORTING` or `ABORTED` status
|
|
92
100
|
* @see https://docs.apify.com/api/v2/actor-run-abort-post
|
|
93
101
|
*
|
|
@@ -101,22 +109,26 @@ export class RunClient extends ResourceClient {
|
|
|
101
109
|
* ```
|
|
102
110
|
*/
|
|
103
111
|
async abort(options = {}) {
|
|
104
|
-
const
|
|
112
|
+
const { timeoutSecs = 'medium', ...params } = parseArgument(options, abortOptionsSchema, 'RunAbortOptions');
|
|
105
113
|
const response = await this.httpClient.call({
|
|
106
|
-
url: this.
|
|
114
|
+
url: this.buildUrl('abort'),
|
|
107
115
|
method: 'POST',
|
|
108
|
-
params: this.
|
|
116
|
+
params: this.buildParams(params),
|
|
117
|
+
timeoutSecs,
|
|
109
118
|
});
|
|
110
|
-
return
|
|
119
|
+
return parseResponse(response, schemas.Run());
|
|
111
120
|
}
|
|
112
121
|
/**
|
|
113
122
|
* Deletes the Actor run.
|
|
114
123
|
*
|
|
124
|
+
* @param options - Request options
|
|
125
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
115
126
|
* @see https://docs.apify.com/api/v2/actor-run-delete
|
|
116
127
|
* @since Added in 2.8.1
|
|
117
128
|
*/
|
|
118
|
-
async delete() {
|
|
119
|
-
|
|
129
|
+
async delete(options = {}) {
|
|
130
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
131
|
+
return this.deleteResource(timeoutSecs);
|
|
120
132
|
}
|
|
121
133
|
/**
|
|
122
134
|
* Transforms the Actor run into a run of another Actor (metamorph).
|
|
@@ -126,10 +138,10 @@ export class RunClient extends ResourceClient {
|
|
|
126
138
|
* This is useful for chaining Actor executions or implementing complex workflows.
|
|
127
139
|
*
|
|
128
140
|
* @param targetActorId - ID or username/name of the target Actor
|
|
129
|
-
* @param input - Input for the target Actor.
|
|
141
|
+
* @param input - Input for the target Actor, serialized to JSON. Omit it to metamorph without input.
|
|
130
142
|
* @param options - Metamorph options
|
|
131
143
|
* @param options.build - Tag or number of the target Actor's build to run. Default is the target Actor's default build.
|
|
132
|
-
* @param options.
|
|
144
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
133
145
|
* @returns The metamorphed ActorRun object (same ID, but now running the target Actor)
|
|
134
146
|
* @see https://docs.apify.com/api/v2/actor-run-metamorph-post
|
|
135
147
|
*
|
|
@@ -145,23 +157,21 @@ export class RunClient extends ResourceClient {
|
|
|
145
157
|
*/
|
|
146
158
|
async metamorph(targetActorId, input, options = {}) {
|
|
147
159
|
parseArgument(targetActorId, targetActorIdSchema);
|
|
148
|
-
// input can be anything, pointless to validate
|
|
149
160
|
const parsed = parseArgument(options, metamorphOptionsSchema, 'RunMetamorphOptions');
|
|
150
|
-
const safeTargetActorId = this.
|
|
161
|
+
const safeTargetActorId = this.toSafeId(targetActorId);
|
|
151
162
|
const params = {
|
|
152
163
|
targetActorId: safeTargetActorId,
|
|
153
164
|
build: parsed.build,
|
|
154
165
|
};
|
|
155
166
|
const request = {
|
|
156
|
-
url: this.
|
|
167
|
+
url: this.buildUrl('metamorph'),
|
|
157
168
|
method: 'POST',
|
|
158
169
|
data: input,
|
|
159
|
-
params: this.
|
|
170
|
+
params: this.buildParams(params),
|
|
160
171
|
// Apify internal property. Tells the request serialization interceptor
|
|
161
172
|
// to stringify functions to JSON, instead of omitting them.
|
|
162
|
-
// TODO: remove this ts-expect-error once we have defined custom Apify axios configs
|
|
163
|
-
// @ts-expect-error Custom Apify property
|
|
164
173
|
stringifyFunctions: true,
|
|
174
|
+
timeoutSecs: parsed.timeoutSecs ?? 'medium',
|
|
165
175
|
};
|
|
166
176
|
if (parsed.contentType) {
|
|
167
177
|
request.headers = {
|
|
@@ -169,7 +179,7 @@ export class RunClient extends ResourceClient {
|
|
|
169
179
|
};
|
|
170
180
|
}
|
|
171
181
|
const response = await this.httpClient.call(request);
|
|
172
|
-
return
|
|
182
|
+
return parseResponse(response, schemas.Run());
|
|
173
183
|
}
|
|
174
184
|
/**
|
|
175
185
|
* Reboots the Actor run.
|
|
@@ -178,6 +188,8 @@ export class RunClient extends ResourceClient {
|
|
|
178
188
|
* This can be useful to recover from certain errors or to force the Actor to restart
|
|
179
189
|
* with a fresh environment.
|
|
180
190
|
*
|
|
191
|
+
* @param options - Request options
|
|
192
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
181
193
|
* @returns The updated ActorRun object
|
|
182
194
|
* @see https://docs.apify.com/api/v2/actor-run-reboot-post
|
|
183
195
|
*
|
|
@@ -187,13 +199,15 @@ export class RunClient extends ResourceClient {
|
|
|
187
199
|
* ```
|
|
188
200
|
* @since Added in 2.8.0
|
|
189
201
|
*/
|
|
190
|
-
async reboot() {
|
|
202
|
+
async reboot(options = {}) {
|
|
203
|
+
const { timeoutSecs = 'medium' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
191
204
|
const request = {
|
|
192
|
-
url: this.
|
|
205
|
+
url: this.buildUrl('reboot'),
|
|
193
206
|
method: 'POST',
|
|
207
|
+
timeoutSecs,
|
|
194
208
|
};
|
|
195
209
|
const response = await this.httpClient.call(request);
|
|
196
|
-
return
|
|
210
|
+
return parseResponse(response, schemas.Run());
|
|
197
211
|
}
|
|
198
212
|
/**
|
|
199
213
|
* Updates the Actor run with specified fields.
|
|
@@ -202,6 +216,8 @@ export class RunClient extends ResourceClient {
|
|
|
202
216
|
* @param newFields.statusMessage - Custom status message to display (e.g., "Processing page 10/100")
|
|
203
217
|
* @param newFields.isStatusMessageTerminal - If `true`, the status message is final and won't be overwritten. Default is `false`.
|
|
204
218
|
* @param newFields.generalAccess - General resource access level ('FOLLOW_USER_SETTING', 'ANYONE_WITH_ID_CAN_READ' or 'RESTRICTED')
|
|
219
|
+
* @param options - Request options
|
|
220
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
205
221
|
* @returns The updated ActorRun object
|
|
206
222
|
*
|
|
207
223
|
* @example
|
|
@@ -213,9 +229,10 @@ export class RunClient extends ResourceClient {
|
|
|
213
229
|
* ```
|
|
214
230
|
* @since Added in 2.6.0
|
|
215
231
|
*/
|
|
216
|
-
async update(newFields) {
|
|
232
|
+
async update(newFields, options = {}) {
|
|
217
233
|
parseArgument(newFields, anyObjectSchema);
|
|
218
|
-
|
|
234
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
235
|
+
return this.updateResource(schemas.Run(), newFields, timeoutSecs);
|
|
219
236
|
}
|
|
220
237
|
/**
|
|
221
238
|
* Resurrects a finished Actor run, starting it again with the same settings.
|
|
@@ -226,10 +243,11 @@ export class RunClient extends ResourceClient {
|
|
|
226
243
|
* @param options - Resurrection options (override original run settings)
|
|
227
244
|
* @param options.build - Tag or number of the build to use. If not provided, uses the original run's build.
|
|
228
245
|
* @param options.memory - Memory in megabytes. If not provided, uses the original run's memory.
|
|
229
|
-
* @param options.
|
|
246
|
+
* @param options.runTimeoutSecs - Timeout for the resurrected run in seconds. If not provided, uses the original run's timeout.
|
|
230
247
|
* @param options.maxItems - Maximum number of dataset items (pay-per-result Actors).
|
|
231
248
|
* @param options.maxTotalChargeUsd - Maximum cost in USD (pay-per-event Actors).
|
|
232
249
|
* @param options.restartOnError - Whether to restart on error.
|
|
250
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
233
251
|
* @returns The new (resurrected) ActorRun object
|
|
234
252
|
* @see https://docs.apify.com/api/v2/post-resurrect-run
|
|
235
253
|
*
|
|
@@ -241,13 +259,15 @@ export class RunClient extends ResourceClient {
|
|
|
241
259
|
* ```
|
|
242
260
|
*/
|
|
243
261
|
async resurrect(options = {}) {
|
|
244
|
-
const
|
|
262
|
+
const { timeoutSecs = 'medium', runTimeoutSecs, ...params } = parseArgument(options, resurrectOptionsSchema, 'RunResurrectOptions');
|
|
245
263
|
const response = await this.httpClient.call({
|
|
246
|
-
url: this.
|
|
264
|
+
url: this.buildUrl('resurrect'),
|
|
247
265
|
method: 'POST',
|
|
248
|
-
|
|
266
|
+
// The API's `timeout` parameter bounds the run, not the request.
|
|
267
|
+
params: this.buildParams({ ...params, timeout: runTimeoutSecs }),
|
|
268
|
+
timeoutSecs,
|
|
249
269
|
});
|
|
250
|
-
return
|
|
270
|
+
return parseResponse(response, schemas.Run());
|
|
251
271
|
}
|
|
252
272
|
/**
|
|
253
273
|
* Charges the Actor run for a specific event.
|
|
@@ -256,17 +276,18 @@ export class RunClient extends ResourceClient {
|
|
|
256
276
|
* @param options.eventName - **Required.** Name of the event to charge for.
|
|
257
277
|
* @param options.count - Number of times to charge the event. Default is 1.
|
|
258
278
|
* @param options.idempotencyKey - Optional key to ensure the charge is not duplicated. If not provided, one is auto-generated.
|
|
279
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
259
280
|
* @returns Empty response object.
|
|
260
281
|
* @see https://docs.apify.com/api/v2/post-charge-run
|
|
261
282
|
* @since Added in 2.11.0
|
|
262
283
|
*/
|
|
263
284
|
async charge(options) {
|
|
264
|
-
const { eventName, count, idempotencyKey: providedIdempotencyKey, } = parseArgument(options, chargeOptionsSchema, 'RunChargeOptions');
|
|
285
|
+
const { eventName, count, idempotencyKey: providedIdempotencyKey, timeoutSecs = 'short', } = parseArgument(options, chargeOptionsSchema, 'RunChargeOptions');
|
|
265
286
|
/** To avoid duplicates during the same milisecond, doesn't need to by crypto-secure. */
|
|
266
287
|
const randomSuffix = (Math.random() + 1).toString(36).slice(3, 8);
|
|
267
288
|
const idempotencyKey = providedIdempotencyKey ?? `${this.id}-${eventName}-${Date.now()}-${randomSuffix}`;
|
|
268
289
|
const request = {
|
|
269
|
-
url: this.
|
|
290
|
+
url: this.buildUrl('charge'),
|
|
270
291
|
method: 'POST',
|
|
271
292
|
data: {
|
|
272
293
|
eventName,
|
|
@@ -275,6 +296,7 @@ export class RunClient extends ResourceClient {
|
|
|
275
296
|
headers: {
|
|
276
297
|
[RUN_CHARGE_IDEMPOTENCY_HEADER]: idempotencyKey,
|
|
277
298
|
},
|
|
299
|
+
timeoutSecs,
|
|
278
300
|
};
|
|
279
301
|
const response = await this.httpClient.call(request);
|
|
280
302
|
return response;
|
|
@@ -292,7 +314,8 @@ export class RunClient extends ResourceClient {
|
|
|
292
314
|
*
|
|
293
315
|
* @param options - Wait options
|
|
294
316
|
* @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If the limit is reached, the returned promise resolves to a run object that will have status `READY` or `RUNNING`. If omitted, waits indefinitely.
|
|
295
|
-
* @
|
|
317
|
+
* @param options.timeoutSecs - Timeout for each polling API request. Default is `'noTimeout'`.
|
|
318
|
+
* @returns The ActorRun object (finished or still running if the timeout was reached)
|
|
296
319
|
*
|
|
297
320
|
* @example
|
|
298
321
|
* ```javascript
|
|
@@ -309,11 +332,13 @@ export class RunClient extends ResourceClient {
|
|
|
309
332
|
*/
|
|
310
333
|
async waitForFinish(options = {}) {
|
|
311
334
|
const parsed = parseArgument(options, waitForFinishOptionsSchema, 'RunWaitForFinishOptions');
|
|
312
|
-
return this.
|
|
335
|
+
return this.waitForJobFinish(schemas.Run(), parsed);
|
|
313
336
|
}
|
|
314
337
|
/**
|
|
315
338
|
* Returns a client for the default dataset of this Actor run.
|
|
316
339
|
*
|
|
340
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
341
|
+
*
|
|
317
342
|
* @returns A client for accessing the run's default dataset
|
|
318
343
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
319
344
|
*
|
|
@@ -324,13 +349,16 @@ export class RunClient extends ResourceClient {
|
|
|
324
349
|
* ```
|
|
325
350
|
*/
|
|
326
351
|
dataset() {
|
|
327
|
-
return new DatasetClient(this.
|
|
352
|
+
return new DatasetClient(this.subResourceOptions({
|
|
328
353
|
resourcePath: 'dataset',
|
|
329
354
|
}));
|
|
330
355
|
}
|
|
331
356
|
/**
|
|
332
357
|
* Returns a client for the default key-value store of this Actor run.
|
|
333
358
|
*
|
|
359
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
|
|
360
|
+
* lookups such as `getRecord()` read a 404 as a missing record.
|
|
361
|
+
*
|
|
334
362
|
* @returns A client for accessing the run's default key-value store
|
|
335
363
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
336
364
|
*
|
|
@@ -341,13 +369,16 @@ export class RunClient extends ResourceClient {
|
|
|
341
369
|
* ```
|
|
342
370
|
*/
|
|
343
371
|
keyValueStore() {
|
|
344
|
-
return new KeyValueStoreClient(this.
|
|
372
|
+
return new KeyValueStoreClient(this.subResourceOptions({
|
|
345
373
|
resourcePath: 'key-value-store',
|
|
346
374
|
}));
|
|
347
375
|
}
|
|
348
376
|
/**
|
|
349
377
|
* Returns a client for the default Request queue of this Actor run.
|
|
350
378
|
*
|
|
379
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
380
|
+
* `getRequest()` reads a 404 as a missing request.
|
|
381
|
+
*
|
|
351
382
|
* @returns A client for accessing the run's default Request queue
|
|
352
383
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
353
384
|
*
|
|
@@ -358,13 +389,15 @@ export class RunClient extends ResourceClient {
|
|
|
358
389
|
* ```
|
|
359
390
|
*/
|
|
360
391
|
requestQueue() {
|
|
361
|
-
return new RequestQueueClient(this.
|
|
392
|
+
return new RequestQueueClient(this.subResourceOptions({
|
|
362
393
|
resourcePath: 'request-queue',
|
|
363
394
|
}));
|
|
364
395
|
}
|
|
365
396
|
/**
|
|
366
397
|
* Returns a client for accessing the log of this Actor run.
|
|
367
398
|
*
|
|
399
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
400
|
+
*
|
|
368
401
|
* @returns A client for accessing the run's log
|
|
369
402
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
370
403
|
*
|
|
@@ -376,16 +409,22 @@ export class RunClient extends ResourceClient {
|
|
|
376
409
|
* ```
|
|
377
410
|
*/
|
|
378
411
|
log() {
|
|
379
|
-
return new LogClient(this.
|
|
412
|
+
return new LogClient(this.subResourceOptions({
|
|
380
413
|
resourcePath: 'log',
|
|
381
414
|
}));
|
|
382
415
|
}
|
|
383
416
|
/**
|
|
384
417
|
* Get StreamedLog for convenient streaming of the run log and their redirection.
|
|
418
|
+
*
|
|
419
|
+
* @param options - Streaming options
|
|
420
|
+
* @param options.toLog - Log instance to redirect the run log to. Use `'default'` for a preconfigured one, or `null` to disable the redirection.
|
|
421
|
+
* @param options.fromStart - If `true`, the log is streamed from its beginning. Default is `true`.
|
|
422
|
+
* @param options.timeoutSecs - Timeout for the API requests that fetch the run and its Actor. Default is `'long'`.
|
|
385
423
|
* @since Added in 2.20.0
|
|
386
424
|
*/
|
|
387
425
|
async getStreamedLog(options = {}) {
|
|
388
|
-
|
|
426
|
+
parseArgument(options.timeoutSecs, optionalTimeoutSchema);
|
|
427
|
+
const { fromStart = true, timeoutSecs = 'long' } = options;
|
|
389
428
|
let { toLog } = options;
|
|
390
429
|
if (toLog === null || !isNode()) {
|
|
391
430
|
// Explicitly no logging or not in Node.js
|
|
@@ -394,10 +433,11 @@ export class RunClient extends ResourceClient {
|
|
|
394
433
|
if (toLog === undefined || toLog === 'default') {
|
|
395
434
|
// Create default StreamedLog
|
|
396
435
|
// Get actor name and run id
|
|
397
|
-
const runData = await this.get();
|
|
436
|
+
const runData = await this.get({ timeoutSecs });
|
|
398
437
|
const runId = runData?.id ?? '';
|
|
399
438
|
const actorId = runData?.actId ?? '';
|
|
400
|
-
|
|
439
|
+
// `apifyClient.actor()` rejects an empty ID, which is what a run that could not be read leaves here.
|
|
440
|
+
const actorData = actorId ? await this.apifyClient.actor(actorId).get({ timeoutSecs }) : undefined;
|
|
401
441
|
const actorName = actorData?.name ?? '';
|
|
402
442
|
const name = [actorName, `runId:${runId}`].filter(Boolean).join(' ');
|
|
403
443
|
toLog = new Log({ level: LEVELS.DEBUG, prefix: `${name} -> `, logger: new LoggerActorRedirect() });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ACTOR_JOB_STATUSES } from '@apify/consts';
|
|
2
2
|
import type { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client.js';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
import type { PaginatedIterator, PaginationOptions } from '../utils.js';
|
|
5
6
|
import type { ActorRunListItem } from './actor.js';
|
|
6
7
|
/**
|
|
@@ -46,12 +47,13 @@ export declare class RunCollectionClient extends ResourceCollectionClient {
|
|
|
46
47
|
* ```
|
|
47
48
|
*
|
|
48
49
|
* @param options - Pagination and filtering options.
|
|
50
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
49
51
|
* @returns A paginated iterator of Actor runs.
|
|
50
52
|
* @see https://docs.apify.com/api/v2/actor-runs-get
|
|
51
53
|
*/
|
|
52
54
|
list(options?: RunCollectionListOptions): PaginatedIterator<ActorRunListItem>;
|
|
53
55
|
}
|
|
54
|
-
export interface RunCollectionListOptions extends PaginationOptions {
|
|
56
|
+
export interface RunCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
55
57
|
desc?: boolean;
|
|
56
58
|
status?: (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES] | (typeof ACTOR_JOB_STATUSES)[keyof typeof ACTOR_JOB_STATUSES][];
|
|
57
59
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ACTOR_JOB_STATUSES } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { timeoutOptionsShape } from '../timeouts.js';
|
|
4
6
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
7
|
const jobStatusSchema = z.enum(ACTOR_JOB_STATUSES);
|
|
6
8
|
const listOptionsSchema = z.strictObject({
|
|
@@ -9,6 +11,7 @@ const listOptionsSchema = z.strictObject({
|
|
|
9
11
|
status: z.union([jobStatusSchema, z.array(jobStatusSchema)]).optional(),
|
|
10
12
|
startedBefore: z.union([z.date(), z.string()]).optional(),
|
|
11
13
|
startedAfter: z.union([z.date(), z.string()]).optional(),
|
|
14
|
+
...timeoutOptionsShape,
|
|
12
15
|
});
|
|
13
16
|
/**
|
|
14
17
|
* Client for managing the collection of Actor runs.
|
|
@@ -58,11 +61,12 @@ export class RunCollectionClient extends ResourceCollectionClient {
|
|
|
58
61
|
* ```
|
|
59
62
|
*
|
|
60
63
|
* @param options - Pagination and filtering options.
|
|
64
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
61
65
|
* @returns A paginated iterator of Actor runs.
|
|
62
66
|
* @see https://docs.apify.com/api/v2/actor-runs-get
|
|
63
67
|
*/
|
|
64
68
|
list(options = {}) {
|
|
65
69
|
const parsed = parseArgument(options, listOptionsSchema, 'RunCollectionListOptions');
|
|
66
|
-
return this.
|
|
70
|
+
return this.listResourcesPaginated(schemas.ListOfRuns(), parsed, 'medium');
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
3
|
-
import type { Schedule, ScheduleAction } from '../models.js';
|
|
3
|
+
import type { Schedule, ScheduleAction, ScheduleInvoked } from '../models.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
import type { DistributiveOptional } from '../utils.js';
|
|
5
|
-
export type { Schedule, ScheduleAction, ScheduleActionRunActor, ScheduleActionRunActorTask, ScheduledActorRunInput, ScheduledActorRunOptions, } from '../models.js';
|
|
6
|
+
export type { Schedule, ScheduleAction, ScheduleActionRunActor, ScheduleActionRunActorTask, ScheduledActorRunInput, ScheduledActorRunOptions, ScheduleInvoked, } from '../models.js';
|
|
6
7
|
export { ScheduleActions } from '../models.js';
|
|
7
8
|
/**
|
|
8
9
|
* Client for managing a specific Schedule.
|
|
@@ -35,31 +36,39 @@ export declare class ScheduleClient extends ResourceClient {
|
|
|
35
36
|
/**
|
|
36
37
|
* Retrieves the schedule.
|
|
37
38
|
*
|
|
39
|
+
* @param options - Request options
|
|
40
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
38
41
|
* @returns The schedule object, or `undefined` if it does not exist.
|
|
39
42
|
* @see https://docs.apify.com/api/v2/schedule-get
|
|
40
43
|
*/
|
|
41
|
-
get(): Promise<Schedule | undefined>;
|
|
44
|
+
get(options?: TimeoutOptions): Promise<Schedule | undefined>;
|
|
42
45
|
/**
|
|
43
46
|
* Updates the schedule with the specified fields.
|
|
44
47
|
*
|
|
45
48
|
* @param newFields - Fields to update.
|
|
49
|
+
* @param options - Request options
|
|
50
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
46
51
|
* @returns The updated schedule object.
|
|
47
52
|
* @see https://docs.apify.com/api/v2/schedule-put
|
|
48
53
|
*/
|
|
49
|
-
update(newFields: ScheduleCreateOrUpdateData): Promise<Schedule>;
|
|
54
|
+
update(newFields: ScheduleCreateOrUpdateData, options?: TimeoutOptions): Promise<Schedule>;
|
|
50
55
|
/**
|
|
51
56
|
* Deletes the schedule.
|
|
52
57
|
*
|
|
58
|
+
* @param options - Request options
|
|
59
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
53
60
|
* @see https://docs.apify.com/api/v2/schedule-delete
|
|
54
61
|
*/
|
|
55
|
-
delete(): Promise<void>;
|
|
62
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
56
63
|
/**
|
|
57
64
|
* Retrieves the schedule's log.
|
|
58
65
|
*
|
|
59
|
-
* @
|
|
66
|
+
* @param options - Request options
|
|
67
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
68
|
+
* @returns The schedule log, one entry per invocation.
|
|
60
69
|
* @see https://docs.apify.com/api/v2/schedule-log-get
|
|
61
70
|
*/
|
|
62
|
-
getLog(): Promise<
|
|
71
|
+
getLog(options?: TimeoutOptions): Promise<ScheduleInvoked[]>;
|
|
63
72
|
}
|
|
64
73
|
/**
|
|
65
74
|
* Data for creating or updating a Schedule.
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
-
import
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
5
|
+
import { anyObjectSchema, parseArgument, parseResponse } from '../utils.js';
|
|
3
6
|
export { ScheduleActions } from '../models.js';
|
|
7
|
+
const scheduleLogSchema = z.array(schemas.ScheduleInvoked());
|
|
4
8
|
/**
|
|
5
9
|
* Client for managing a specific Schedule.
|
|
6
10
|
*
|
|
@@ -37,50 +41,56 @@ export class ScheduleClient extends ResourceClient {
|
|
|
37
41
|
/**
|
|
38
42
|
* Retrieves the schedule.
|
|
39
43
|
*
|
|
44
|
+
* @param options - Request options
|
|
45
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
40
46
|
* @returns The schedule object, or `undefined` if it does not exist.
|
|
41
47
|
* @see https://docs.apify.com/api/v2/schedule-get
|
|
42
48
|
*/
|
|
43
|
-
async get() {
|
|
44
|
-
|
|
49
|
+
async get(options = {}) {
|
|
50
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
51
|
+
return this.getResource(schemas.Schedule(), {}, timeoutSecs);
|
|
45
52
|
}
|
|
46
53
|
/**
|
|
47
54
|
* Updates the schedule with the specified fields.
|
|
48
55
|
*
|
|
49
56
|
* @param newFields - Fields to update.
|
|
57
|
+
* @param options - Request options
|
|
58
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
50
59
|
* @returns The updated schedule object.
|
|
51
60
|
* @see https://docs.apify.com/api/v2/schedule-put
|
|
52
61
|
*/
|
|
53
|
-
async update(newFields) {
|
|
62
|
+
async update(newFields, options = {}) {
|
|
54
63
|
parseArgument(newFields, anyObjectSchema);
|
|
55
|
-
|
|
64
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
65
|
+
return this.updateResource(schemas.Schedule(), newFields, timeoutSecs);
|
|
56
66
|
}
|
|
57
67
|
/**
|
|
58
68
|
* Deletes the schedule.
|
|
59
69
|
*
|
|
70
|
+
* @param options - Request options
|
|
71
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
60
72
|
* @see https://docs.apify.com/api/v2/schedule-delete
|
|
61
73
|
*/
|
|
62
|
-
async delete() {
|
|
63
|
-
|
|
74
|
+
async delete(options = {}) {
|
|
75
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
76
|
+
return this.deleteResource(timeoutSecs);
|
|
64
77
|
}
|
|
65
78
|
/**
|
|
66
79
|
* Retrieves the schedule's log.
|
|
67
80
|
*
|
|
68
|
-
* @
|
|
81
|
+
* @param options - Request options
|
|
82
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
83
|
+
* @returns The schedule log, one entry per invocation.
|
|
69
84
|
* @see https://docs.apify.com/api/v2/schedule-log-get
|
|
70
85
|
*/
|
|
71
|
-
async getLog() {
|
|
72
|
-
const
|
|
73
|
-
|
|
86
|
+
async getLog(options = {}) {
|
|
87
|
+
const { timeoutSecs = 'medium' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
88
|
+
const response = await this.httpClient.call({
|
|
89
|
+
url: this.buildUrl('log'),
|
|
74
90
|
method: 'GET',
|
|
75
|
-
params: this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return cast(parseDateFields(pluckData(response.data)));
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
catchNotFoundOrThrow(err);
|
|
83
|
-
}
|
|
84
|
-
return undefined;
|
|
91
|
+
params: this.buildParams(),
|
|
92
|
+
timeoutSecs,
|
|
93
|
+
});
|
|
94
|
+
return parseResponse(response, scheduleLogSchema);
|
|
85
95
|
}
|
|
86
96
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
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 { PaginatedIterator, PaginationOptions } from '../utils.js';
|
|
4
5
|
import type { Schedule, ScheduleCreateOrUpdateData } from './schedule.js';
|
|
5
6
|
/**
|
|
@@ -48,6 +49,7 @@ export declare class ScheduleCollectionClient extends ResourceCollectionClient {
|
|
|
48
49
|
* ```
|
|
49
50
|
*
|
|
50
51
|
* @param options - Pagination and sorting options.
|
|
52
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
51
53
|
* @returns A paginated iterator of schedules.
|
|
52
54
|
* @see https://docs.apify.com/api/v2/schedules-get
|
|
53
55
|
*/
|
|
@@ -56,11 +58,13 @@ export declare class ScheduleCollectionClient extends ResourceCollectionClient {
|
|
|
56
58
|
* Creates a new schedule.
|
|
57
59
|
*
|
|
58
60
|
* @param schedule - The schedule data.
|
|
61
|
+
* @param options - Request options
|
|
62
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
59
63
|
* @returns The created schedule object.
|
|
60
64
|
* @see https://docs.apify.com/api/v2/schedules-post
|
|
61
65
|
*/
|
|
62
|
-
create(schedule?: ScheduleCreateOrUpdateData): Promise<Schedule>;
|
|
66
|
+
create(schedule?: ScheduleCreateOrUpdateData, options?: TimeoutOptions): Promise<Schedule>;
|
|
63
67
|
}
|
|
64
|
-
export interface ScheduleCollectionListOptions extends PaginationOptions {
|
|
68
|
+
export interface ScheduleCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
65
69
|
desc?: boolean;
|
|
66
70
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
3
5
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
6
|
const listOptionsSchema = z.strictObject({
|
|
5
7
|
...paginationOptionsShape,
|
|
6
8
|
desc: z.boolean().optional(),
|
|
9
|
+
...timeoutOptionsShape,
|
|
7
10
|
});
|
|
8
11
|
const scheduleCreateSchema = anyObjectSchema.optional();
|
|
9
12
|
/**
|
|
@@ -57,22 +60,26 @@ export class ScheduleCollectionClient extends ResourceCollectionClient {
|
|
|
57
60
|
* ```
|
|
58
61
|
*
|
|
59
62
|
* @param options - Pagination and sorting options.
|
|
63
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
60
64
|
* @returns A paginated iterator of schedules.
|
|
61
65
|
* @see https://docs.apify.com/api/v2/schedules-get
|
|
62
66
|
*/
|
|
63
67
|
list(options = {}) {
|
|
64
68
|
const parsed = parseArgument(options, listOptionsSchema, 'ScheduleCollectionListOptions');
|
|
65
|
-
return this.
|
|
69
|
+
return this.listResourcesPaginated(schemas.ListOfSchedules(), parsed, 'medium');
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
72
|
* Creates a new schedule.
|
|
69
73
|
*
|
|
70
74
|
* @param schedule - The schedule data.
|
|
75
|
+
* @param options - Request options
|
|
76
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
71
77
|
* @returns The created schedule object.
|
|
72
78
|
* @see https://docs.apify.com/api/v2/schedules-post
|
|
73
79
|
*/
|
|
74
|
-
async create(schedule) {
|
|
80
|
+
async create(schedule, options = {}) {
|
|
75
81
|
parseArgument(schedule, scheduleCreateSchema);
|
|
76
|
-
|
|
82
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
83
|
+
return this.createResource(schemas.Schedule(), schedule, timeoutSecs);
|
|
77
84
|
}
|
|
78
85
|
}
|