apify-client 3.0.0-beta.2 → 3.0.0-beta.21

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