apify-client 3.0.0-beta.15 → 3.0.0-beta.17

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