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

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 +52 -31
  43. package/dist/resource_clients/actor.js +81 -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 +53 -18
  73. package/dist/resource_clients/run.js +94 -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,11 @@ 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: an object or array serialized to JSON, or raw bytes sent as they
144
+ * are. Omit it to metamorph without input.
130
145
  * @param options - Metamorph options
131
146
  * @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.
147
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
133
148
  * @returns The metamorphed ActorRun object (same ID, but now running the target Actor)
134
149
  * @see https://docs.apify.com/api/v2/actor-run-metamorph-post
135
150
  *
@@ -145,23 +160,21 @@ export class RunClient extends ResourceClient {
145
160
  */
146
161
  async metamorph(targetActorId, input, options = {}) {
147
162
  parseArgument(targetActorId, targetActorIdSchema);
148
- // input can be anything, pointless to validate
149
163
  const parsed = parseArgument(options, metamorphOptionsSchema, 'RunMetamorphOptions');
150
- const safeTargetActorId = this._toSafeId(targetActorId);
164
+ const safeTargetActorId = this.toSafeId(targetActorId);
151
165
  const params = {
152
166
  targetActorId: safeTargetActorId,
153
167
  build: parsed.build,
154
168
  };
155
169
  const request = {
156
- url: this._url('metamorph'),
170
+ url: this.buildUrl('metamorph'),
157
171
  method: 'POST',
158
172
  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
173
+ params: this.buildParams(params),
174
+ // Actor input may carry page functions, which plain JSON serialization would drop.
164
175
  stringifyFunctions: true,
176
+ timeoutSecs: parsed.timeoutSecs ?? 'medium',
177
+ signal: parsed.signal,
165
178
  };
166
179
  if (parsed.contentType) {
167
180
  request.headers = {
@@ -169,7 +182,7 @@ export class RunClient extends ResourceClient {
169
182
  };
170
183
  }
171
184
  const response = await this.httpClient.call(request);
172
- return cast(parseDateFields(pluckData(response.data)));
185
+ return parseResponse(response, schemas.Run());
173
186
  }
174
187
  /**
175
188
  * Reboots the Actor run.
@@ -178,6 +191,8 @@ export class RunClient extends ResourceClient {
178
191
  * This can be useful to recover from certain errors or to force the Actor to restart
179
192
  * with a fresh environment.
180
193
  *
194
+ * @param options - Request options
195
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
181
196
  * @returns The updated ActorRun object
182
197
  * @see https://docs.apify.com/api/v2/actor-run-reboot-post
183
198
  *
@@ -187,13 +202,16 @@ export class RunClient extends ResourceClient {
187
202
  * ```
188
203
  * @since Added in 2.8.0
189
204
  */
190
- async reboot() {
205
+ async reboot(options = {}) {
206
+ const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
191
207
  const request = {
192
- url: this._url('reboot'),
208
+ url: this.buildUrl('reboot'),
193
209
  method: 'POST',
210
+ timeoutSecs,
211
+ signal,
194
212
  };
195
213
  const response = await this.httpClient.call(request);
196
- return cast(parseDateFields(pluckData(response.data)));
214
+ return parseResponse(response, schemas.Run());
197
215
  }
198
216
  /**
199
217
  * Updates the Actor run with specified fields.
@@ -202,6 +220,8 @@ export class RunClient extends ResourceClient {
202
220
  * @param newFields.statusMessage - Custom status message to display (e.g., "Processing page 10/100")
203
221
  * @param newFields.isStatusMessageTerminal - If `true`, the status message is final and won't be overwritten. Default is `false`.
204
222
  * @param newFields.generalAccess - General resource access level ('FOLLOW_USER_SETTING', 'ANYONE_WITH_ID_CAN_READ' or 'RESTRICTED')
223
+ * @param options - Request options
224
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
205
225
  * @returns The updated ActorRun object
206
226
  *
207
227
  * @example
@@ -213,9 +233,10 @@ export class RunClient extends ResourceClient {
213
233
  * ```
214
234
  * @since Added in 2.6.0
215
235
  */
216
- async update(newFields) {
236
+ async update(newFields, options = {}) {
217
237
  parseArgument(newFields, anyObjectSchema);
218
- return this._update(newFields);
238
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
239
+ return this.updateResource(schemas.Run(), newFields, timeoutSecs, signal);
219
240
  }
220
241
  /**
221
242
  * Resurrects a finished Actor run, starting it again with the same settings.
@@ -226,10 +247,11 @@ export class RunClient extends ResourceClient {
226
247
  * @param options - Resurrection options (override original run settings)
227
248
  * @param options.build - Tag or number of the build to use. If not provided, uses the original run's build.
228
249
  * @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.
250
+ * @param options.runTimeoutSecs - Timeout for the resurrected run in seconds. If not provided, uses the original run's timeout.
230
251
  * @param options.maxItems - Maximum number of dataset items (pay-per-result Actors).
231
252
  * @param options.maxTotalChargeUsd - Maximum cost in USD (pay-per-event Actors).
232
253
  * @param options.restartOnError - Whether to restart on error.
254
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
233
255
  * @returns The new (resurrected) ActorRun object
234
256
  * @see https://docs.apify.com/api/v2/post-resurrect-run
235
257
  *
@@ -241,13 +263,16 @@ export class RunClient extends ResourceClient {
241
263
  * ```
242
264
  */
243
265
  async resurrect(options = {}) {
244
- const parsed = parseArgument(options, resurrectOptionsSchema, 'RunResurrectOptions');
266
+ const { timeoutSecs = 'medium', signal, runTimeoutSecs, ...params } = parseArgument(options, resurrectOptionsSchema, 'RunResurrectOptions');
245
267
  const response = await this.httpClient.call({
246
- url: this._url('resurrect'),
268
+ url: this.buildUrl('resurrect'),
247
269
  method: 'POST',
248
- params: this._params(parsed),
270
+ // The API's `timeout` parameter bounds the run, not the request.
271
+ params: this.buildParams({ ...params, timeout: runTimeoutSecs }),
272
+ timeoutSecs,
273
+ signal,
249
274
  });
250
- return cast(parseDateFields(pluckData(response.data)));
275
+ return parseResponse(response, schemas.Run());
251
276
  }
252
277
  /**
253
278
  * Charges the Actor run for a specific event.
@@ -256,17 +281,18 @@ export class RunClient extends ResourceClient {
256
281
  * @param options.eventName - **Required.** Name of the event to charge for.
257
282
  * @param options.count - Number of times to charge the event. Default is 1.
258
283
  * @param options.idempotencyKey - Optional key to ensure the charge is not duplicated. If not provided, one is auto-generated.
284
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
259
285
  * @returns Empty response object.
260
286
  * @see https://docs.apify.com/api/v2/post-charge-run
261
287
  * @since Added in 2.11.0
262
288
  */
263
289
  async charge(options) {
264
- const { eventName, count, idempotencyKey: providedIdempotencyKey, } = parseArgument(options, chargeOptionsSchema, 'RunChargeOptions');
290
+ const { eventName, count, idempotencyKey: providedIdempotencyKey, timeoutSecs = 'short', signal, } = parseArgument(options, chargeOptionsSchema, 'RunChargeOptions');
265
291
  /** To avoid duplicates during the same milisecond, doesn't need to by crypto-secure. */
266
292
  const randomSuffix = (Math.random() + 1).toString(36).slice(3, 8);
267
293
  const idempotencyKey = providedIdempotencyKey ?? `${this.id}-${eventName}-${Date.now()}-${randomSuffix}`;
268
294
  const request = {
269
- url: this._url('charge'),
295
+ url: this.buildUrl('charge'),
270
296
  method: 'POST',
271
297
  data: {
272
298
  eventName,
@@ -275,6 +301,8 @@ export class RunClient extends ResourceClient {
275
301
  headers: {
276
302
  [RUN_CHARGE_IDEMPOTENCY_HEADER]: idempotencyKey,
277
303
  },
304
+ timeoutSecs,
305
+ signal,
278
306
  };
279
307
  const response = await this.httpClient.call(request);
280
308
  return response;
@@ -292,7 +320,8 @@ export class RunClient extends ResourceClient {
292
320
  *
293
321
  * @param options - Wait options
294
322
  * @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)
323
+ * @param options.timeoutSecs - Timeout for each polling API request. Default is `'noTimeout'`.
324
+ * @returns The ActorRun object (finished or still running if the timeout was reached)
296
325
  *
297
326
  * @example
298
327
  * ```javascript
@@ -309,11 +338,13 @@ export class RunClient extends ResourceClient {
309
338
  */
310
339
  async waitForFinish(options = {}) {
311
340
  const parsed = parseArgument(options, waitForFinishOptionsSchema, 'RunWaitForFinishOptions');
312
- return this._waitForFinish(parsed);
341
+ return this.waitForJobFinish(schemas.Run(), parsed);
313
342
  }
314
343
  /**
315
344
  * Returns a client for the default dataset of this Actor run.
316
345
  *
346
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
347
+ *
317
348
  * @returns A client for accessing the run's default dataset
318
349
  * @see https://docs.apify.com/api/v2/actor-run-get
319
350
  *
@@ -324,13 +355,16 @@ export class RunClient extends ResourceClient {
324
355
  * ```
325
356
  */
326
357
  dataset() {
327
- return new DatasetClient(this._subResourceOptions({
358
+ return new DatasetClient(this.subResourceOptions({
328
359
  resourcePath: 'dataset',
329
360
  }));
330
361
  }
331
362
  /**
332
363
  * Returns a client for the default key-value store of this Actor run.
333
364
  *
365
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
366
+ * lookups such as `getRecord()` read a 404 as a missing record.
367
+ *
334
368
  * @returns A client for accessing the run's default key-value store
335
369
  * @see https://docs.apify.com/api/v2/actor-run-get
336
370
  *
@@ -341,13 +375,16 @@ export class RunClient extends ResourceClient {
341
375
  * ```
342
376
  */
343
377
  keyValueStore() {
344
- return new KeyValueStoreClient(this._subResourceOptions({
378
+ return new KeyValueStoreClient(this.subResourceOptions({
345
379
  resourcePath: 'key-value-store',
346
380
  }));
347
381
  }
348
382
  /**
349
383
  * Returns a client for the default Request queue of this Actor run.
350
384
  *
385
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
386
+ * `getRequest()` reads a 404 as a missing request.
387
+ *
351
388
  * @returns A client for accessing the run's default Request queue
352
389
  * @see https://docs.apify.com/api/v2/actor-run-get
353
390
  *
@@ -358,13 +395,15 @@ export class RunClient extends ResourceClient {
358
395
  * ```
359
396
  */
360
397
  requestQueue() {
361
- return new RequestQueueClient(this._subResourceOptions({
398
+ return new RequestQueueClient(this.subResourceOptions({
362
399
  resourcePath: 'request-queue',
363
400
  }));
364
401
  }
365
402
  /**
366
403
  * Returns a client for accessing the log of this Actor run.
367
404
  *
405
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
406
+ *
368
407
  * @returns A client for accessing the run's log
369
408
  * @see https://docs.apify.com/api/v2/actor-run-get
370
409
  *
@@ -376,32 +415,40 @@ export class RunClient extends ResourceClient {
376
415
  * ```
377
416
  */
378
417
  log() {
379
- return new LogClient(this._subResourceOptions({
418
+ return new LogClient(this.subResourceOptions({
380
419
  resourcePath: 'log',
381
420
  }));
382
421
  }
383
422
  /**
384
423
  * Get StreamedLog for convenient streaming of the run log and their redirection.
424
+ *
425
+ * @param options - Streaming options
426
+ * @param options.toLog - Log instance to redirect the run log to. Use `'default'` for a preconfigured one, or `null` to disable the redirection.
427
+ * @param options.fromStart - If `true`, the log is streamed from its beginning. Default is `true`.
428
+ * @param options.timeoutSecs - Timeout for the API requests that fetch the run and its Actor. Default is `'long'`.
385
429
  * @since Added in 2.20.0
386
430
  */
387
431
  async getStreamedLog(options = {}) {
388
- const { fromStart = true } = options;
432
+ parseArgument(options.timeoutSecs, optionalTimeoutSchema);
433
+ parseArgument(options.signal, optionalSignalSchema);
434
+ const { fromStart = true, timeoutSecs = 'long', signal } = options;
389
435
  let { toLog } = options;
390
- if (toLog === null || !isNode()) {
436
+ if (toLog === null || !runtime.isNode) {
391
437
  // Explicitly no logging or not in Node.js
392
438
  return undefined;
393
439
  }
394
440
  if (toLog === undefined || toLog === 'default') {
395
441
  // Create default StreamedLog
396
442
  // Get actor name and run id
397
- const runData = await this.get();
443
+ const runData = await this.get({ timeoutSecs, signal });
398
444
  const runId = runData?.id ?? '';
399
445
  const actorId = runData?.actId ?? '';
400
- const actorData = (await this.apifyClient.actor(actorId).get()) || { name: '' };
446
+ // `apifyClient.actor()` rejects an empty ID, which is what a run that could not be read leaves here.
447
+ const actorData = actorId ? await this.apifyClient.actor(actorId).get({ timeoutSecs, signal }) : undefined;
401
448
  const actorName = actorData?.name ?? '';
402
449
  const name = [actorName, `runId:${runId}`].filter(Boolean).join(' ');
403
450
  toLog = new Log({ level: LEVELS.DEBUG, prefix: `${name} -> `, logger: new LoggerActorRedirect() });
404
451
  }
405
- return new StreamedLog({ logClient: this.log(), toLog, fromStart });
452
+ return new StreamedLog({ logClient: this.log(), toLog, fromStart, signal });
406
453
  }
407
454
  }
@@ -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
  }