apify-client 3.0.0-beta.4 → 3.0.0-beta.40

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