apify-client 3.0.0-beta.6 → 3.0.0-beta.60

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 (116) hide show
  1. package/README.md +10 -2
  2. package/dist/apify_api_error.d.ts +11 -26
  3. package/dist/apify_api_error.js +31 -22
  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 +36 -36
  8. package/dist/base/resource_client.d.ts +21 -8
  9. package/dist/base/resource_client.js +67 -33
  10. package/dist/base/resource_collection_client.d.ts +12 -4
  11. package/dist/base/resource_collection_client.js +34 -11
  12. package/dist/body_parser.d.ts +3 -4
  13. package/dist/body_parser.js +19 -26
  14. package/dist/bundle.js +27 -22
  15. package/dist/bundle.js.map +1 -1
  16. package/dist/generated/api.d.ts +785 -290
  17. package/dist/generated/schemas.d.ts +771 -798
  18. package/dist/generated/schemas.js +183 -179
  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 +331 -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 +4 -1
  36. package/dist/index.js +3 -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/models.d.ts +162 -194
  40. package/dist/models.js +6 -4
  41. package/dist/resource_clients/actor.d.ts +74 -34
  42. package/dist/resource_clients/actor.js +87 -56
  43. package/dist/resource_clients/actor_collection.d.ts +18 -14
  44. package/dist/resource_clients/actor_collection.js +11 -3
  45. package/dist/resource_clients/actor_env_var.d.ts +11 -4
  46. package/dist/resource_clients/actor_env_var.js +16 -6
  47. package/dist/resource_clients/actor_env_var_collection.d.ts +16 -20
  48. package/dist/resource_clients/actor_env_var_collection.js +17 -11
  49. package/dist/resource_clients/actor_version.d.ts +20 -5
  50. package/dist/resource_clients/actor_version.js +19 -9
  51. package/dist/resource_clients/actor_version_collection.d.ts +18 -19
  52. package/dist/resource_clients/actor_version_collection.js +19 -11
  53. package/dist/resource_clients/build.d.ts +20 -7
  54. package/dist/resource_clients/build.js +35 -15
  55. package/dist/resource_clients/build_collection.d.ts +7 -5
  56. package/dist/resource_clients/build_collection.js +4 -1
  57. package/dist/resource_clients/dataset.d.ts +53 -35
  58. package/dist/resource_clients/dataset.js +105 -80
  59. package/dist/resource_clients/dataset_collection.d.ts +10 -6
  60. package/dist/resource_clients/dataset_collection.js +13 -2
  61. package/dist/resource_clients/key_value_store.d.ts +73 -23
  62. package/dist/resource_clients/key_value_store.js +86 -43
  63. package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
  64. package/dist/resource_clients/key_value_store_collection.js +13 -2
  65. package/dist/resource_clients/log.d.ts +13 -20
  66. package/dist/resource_clients/log.js +141 -59
  67. package/dist/resource_clients/request_queue.d.ts +74 -36
  68. package/dist/resource_clients/request_queue.js +182 -106
  69. package/dist/resource_clients/request_queue_collection.d.ts +9 -5
  70. package/dist/resource_clients/request_queue_collection.js +9 -3
  71. package/dist/resource_clients/run.d.ts +119 -28
  72. package/dist/resource_clients/run.js +190 -49
  73. package/dist/resource_clients/run_collection.d.ts +5 -3
  74. package/dist/resource_clients/run_collection.js +4 -1
  75. package/dist/resource_clients/schedule.d.ts +16 -7
  76. package/dist/resource_clients/schedule.js +30 -22
  77. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  78. package/dist/resource_clients/schedule_collection.js +9 -3
  79. package/dist/resource_clients/store_collection.d.ts +6 -4
  80. package/dist/resource_clients/store_collection.js +4 -1
  81. package/dist/resource_clients/task.d.ts +36 -13
  82. package/dist/resource_clients/task.js +79 -46
  83. package/dist/resource_clients/task_collection.d.ts +9 -5
  84. package/dist/resource_clients/task_collection.js +9 -3
  85. package/dist/resource_clients/user.d.ts +19 -10
  86. package/dist/resource_clients/user.js +42 -38
  87. package/dist/resource_clients/webhook.d.ts +17 -8
  88. package/dist/resource_clients/webhook.js +30 -22
  89. package/dist/resource_clients/webhook_collection.d.ts +8 -4
  90. package/dist/resource_clients/webhook_collection.js +9 -3
  91. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  92. package/dist/resource_clients/webhook_dispatch.js +7 -2
  93. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  94. package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
  95. package/dist/runtime/node.d.ts +6 -0
  96. package/dist/runtime/node.js +49 -0
  97. package/dist/runtime/types.d.ts +52 -0
  98. package/dist/runtime/types.js +1 -0
  99. package/dist/runtime/web.d.ts +5 -0
  100. package/dist/runtime/web.js +18 -0
  101. package/dist/schemas.d.ts +1 -1
  102. package/dist/schemas.js +1 -1
  103. package/dist/statistics.d.ts +1 -6
  104. package/dist/statistics.js +2 -2
  105. package/dist/timeouts.d.ts +84 -0
  106. package/dist/timeouts.js +37 -0
  107. package/dist/timezones.d.ts +1 -1
  108. package/dist/utils.d.ts +89 -53
  109. package/dist/utils.js +214 -161
  110. package/dist/wait_for_resources.d.ts +8 -0
  111. package/dist/wait_for_resources.js +39 -0
  112. package/package.json +32 -29
  113. package/dist/http_client.d.ts +0 -88
  114. package/dist/http_client.js +0 -255
  115. package/dist/interceptors.d.ts +0 -19
  116. package/dist/interceptors.js +0 -105
@@ -3,7 +3,9 @@ import { ACTOR_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify
3
3
  import { Log } from '@apify/log';
4
4
  import { ResourceClient } from '../base/resource_client.js';
5
5
  import * as schemas from '../schemas.js';
6
- import { anyObjectSchema, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
6
+ import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
7
+ import { anyObjectSchema, isStream, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
8
+ import { startWaitingForResources } from '../wait_for_resources.js';
7
9
  import { ActorVersionClient } from './actor_version.js';
8
10
  import { ActorVersionCollectionClient } from './actor_version_collection.js';
9
11
  import { BuildClient } from './build.js';
@@ -15,19 +17,21 @@ const startOptionsSchema = z.strictObject({
15
17
  build: z.string().optional(),
16
18
  contentType: z.string().optional(),
17
19
  memory: z.number().optional(),
18
- timeout: z.number().optional(),
20
+ runTimeoutSecs: z.number().min(0).optional(),
19
21
  waitForFinish: z.number().optional(),
20
22
  webhooks: z.array(anyObjectSchema).optional(),
21
23
  maxItems: z.number().min(0).optional(),
22
24
  maxTotalChargeUsd: z.number().min(0).optional(),
23
25
  restartOnError: z.boolean().optional(),
24
26
  forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
27
+ waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
28
+ ...timeoutOptionsShape,
25
29
  });
26
30
  const callOptionsSchema = z.strictObject({
27
31
  build: z.string().optional(),
28
32
  contentType: z.string().optional(),
29
33
  memory: z.number().optional(),
30
- timeout: z.number().min(0).optional(),
34
+ runTimeoutSecs: z.number().min(0).optional(),
31
35
  waitSecs: z.number().min(0).optional(),
32
36
  webhooks: z.array(anyObjectSchema).optional(),
33
37
  maxItems: z.number().min(0).optional(),
@@ -35,18 +39,23 @@ const callOptionsSchema = z.strictObject({
35
39
  log: z.union([z.null(), z.instanceof(Log), z.literal('default')]).optional(),
36
40
  restartOnError: z.boolean().optional(),
37
41
  forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
42
+ waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
43
+ ...timeoutOptionsShape,
38
44
  });
39
45
  const validateInputOptionsSchema = z.strictObject({
40
46
  build: z.string().optional(),
41
47
  contentType: z.string().optional(),
48
+ ...timeoutOptionsShape,
42
49
  });
43
- const versionNumberSchema = z.string();
50
+ const versionNumberSchema = z.string().min(1);
44
51
  const buildOptionsSchema = z.strictObject({
45
52
  betaPackages: z.boolean().optional(),
46
53
  tag: z.string().optional(),
47
54
  useCache: z.boolean().optional(),
48
55
  waitForFinish: z.number().optional(),
56
+ ...timeoutOptionsShape,
49
57
  });
58
+ const defaultBuildOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
50
59
  const lastRunOptionsSchema = z.strictObject({
51
60
  status: z.enum(ACTOR_JOB_STATUSES).optional(),
52
61
  origin: z.enum(META_ORIGINS).optional(),
@@ -84,30 +93,39 @@ export class ActorClient extends ResourceClient {
84
93
  /**
85
94
  * Gets the Actor object from the Apify API.
86
95
  *
96
+ * @param options - Request options
97
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
87
98
  * @returns The Actor object, or `undefined` if it does not exist
88
99
  * @see https://docs.apify.com/api/v2/act-get
89
100
  */
90
- async get() {
91
- return this._get(schemas.Actor());
101
+ async get(options = {}) {
102
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
103
+ return this.getResource(schemas.ActorResource(), {}, timeoutSecs, signal);
92
104
  }
93
105
  /**
94
106
  * Updates the Actor with specified fields.
95
107
  *
96
108
  * @param newFields - Fields to update in the Actor
109
+ * @param options - Request options
110
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
97
111
  * @returns The updated Actor object
98
112
  * @see https://docs.apify.com/api/v2/act-put
99
113
  */
100
- async update(newFields) {
114
+ async update(newFields, options = {}) {
101
115
  parseArgument(newFields, anyObjectSchema);
102
- return this._update(schemas.Actor(), newFields);
116
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
117
+ return this.updateResource(schemas.ActorResource(), newFields, timeoutSecs, signal);
103
118
  }
104
119
  /**
105
120
  * Deletes the Actor.
106
121
  *
122
+ * @param options - Request options
123
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
107
124
  * @see https://docs.apify.com/api/v2/act-delete
108
125
  */
109
- async delete() {
110
- return this._delete();
126
+ async delete(options = {}) {
127
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
128
+ return this.deleteResource(timeoutSecs, signal);
111
129
  }
112
130
  /**
113
131
  * Starts the Actor and immediately returns the Run object.
@@ -116,17 +134,20 @@ export class ActorClient extends ResourceClient {
116
134
  * asynchronously and this method returns immediately without waiting for completion.
117
135
  * Use the {@link call} method if you want to wait for the Actor to finish.
118
136
  *
119
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
120
- * If `contentType` is specified in options, input should be a string or Buffer.
137
+ * @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
138
+ * Omit it to run the Actor without input.
121
139
  * @param options - Run configuration options
122
140
  * @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`). If not provided, uses the default build.
123
141
  * @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
124
- * @param options.timeout - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
142
+ * @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
125
143
  * @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).
126
144
  * @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
127
145
  * @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
128
146
  * @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
129
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
147
+ * @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
148
+ * the run. `true` retries until the run starts, a number stops retrying after that many seconds.
149
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
150
+ * when the API is asked to hold the response.
130
151
  * @returns The Actor run object with status, usage, and storage IDs
131
152
  * @see https://docs.apify.com/api/v2/act-runs-post
132
153
  *
@@ -139,18 +160,17 @@ export class ActorClient extends ResourceClient {
139
160
  * // Start Actor with specific build and memory
140
161
  * const run = await client.actor('my-actor').start(
141
162
  * { url: 'https://example.com' },
142
- * { build: '0.1.2', memory: 512, timeout: 300 }
163
+ * { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
143
164
  * );
144
165
  * ```
145
166
  */
146
167
  async start(input, options = {}) {
147
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
148
- // then it will process input as a buffer.
149
168
  const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
150
- const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, } = parsed;
169
+ const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, waitForResources, timeoutSecs, signal, } = parsed;
170
+ // The API's `timeout` parameter bounds the run, not the request.
151
171
  const params = {
152
172
  waitForFinish,
153
- timeout,
173
+ timeout: runTimeoutSecs,
154
174
  memory,
155
175
  build,
156
176
  webhooks: stringifyWebhooksToBase64(parsed.webhooks),
@@ -160,20 +180,22 @@ export class ActorClient extends ResourceClient {
160
180
  forcePermissionLevel,
161
181
  };
162
182
  const request = {
163
- url: this._url('runs'),
183
+ url: this.buildUrl('runs'),
164
184
  method: 'POST',
165
185
  data: input,
166
- params: this._params(params),
167
- // Apify internal property. Tells the request serialization interceptor
168
- // to stringify functions to JSON, instead of omitting them.
186
+ params: this.buildParams(params),
187
+ // Actor input may carry page functions, which plain JSON serialization would drop.
169
188
  stringifyFunctions: true,
189
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
190
+ signal,
170
191
  };
171
192
  if (parsed.contentType) {
172
193
  request.headers = {
173
194
  'content-type': parsed.contentType,
174
195
  };
175
196
  }
176
- const response = await this.httpClient.call(request);
197
+ // A `Readable` input is consumed by the first attempt, so a retry would start the run with an empty input.
198
+ const response = await startWaitingForResources(async () => this.httpClient.call(request), isStream(input) ? false : waitForResources, this.httpClient.logger, signal);
177
199
  return parseResponse(response, schemas.Run());
178
200
  }
179
201
  /**
@@ -183,14 +205,18 @@ export class ActorClient extends ResourceClient {
183
205
  * by polling the run status. It optionally streams logs to the console or a custom Log instance.
184
206
  * By default, it waits indefinitely unless the `waitSecs` option is provided.
185
207
  *
186
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
187
- * If `contentType` is specified in options, input should be a string or Buffer.
208
+ * @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
209
+ * Omit it to run the Actor without input.
188
210
  * @param options - Run configuration options (extends all options from {@link start})
189
211
  * @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
190
212
  * @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
191
213
  * @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
192
214
  * @param options.memory - Memory in megabytes allocated for the run.
193
- * @param options.timeout - Maximum run duration in seconds.
215
+ * @param options.runTimeoutSecs - Maximum run duration in seconds.
216
+ * @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
217
+ * the run. `true` retries until the run starts, a number stops retrying after that many seconds. The time spent
218
+ * retrying doesn't count toward `waitSecs`.
219
+ * @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
194
220
  * @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
195
221
  * @see https://docs.apify.com/api/v2/act-runs-post
196
222
  *
@@ -214,20 +240,18 @@ export class ActorClient extends ResourceClient {
214
240
  * ```
215
241
  */
216
242
  async call(input, options = {}) {
217
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
218
- // then it will process input as a buffer.
219
243
  const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
220
- const { waitSecs, log, ...startOptions } = parsed;
221
- const { id } = await this.start(input, startOptions);
244
+ const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
245
+ const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
222
246
  // Calling root client because we need access to top level API.
223
247
  // Creating a new instance of RunClient here would only allow
224
248
  // setting it up as a nested route under actor API.
225
249
  const newRunClient = this.apifyClient.run(id);
226
- const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
250
+ const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
227
251
  streamedLog?.start();
228
252
  return this.apifyClient
229
253
  .run(id)
230
- .waitForFinish({ waitSecs })
254
+ .waitForFinish({ waitSecs, timeoutSecs, signal })
231
255
  .finally(async () => {
232
256
  await streamedLog?.stop();
233
257
  });
@@ -240,13 +264,12 @@ export class ActorClient extends ResourceClient {
240
264
  * invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
241
265
  * validation problem.
242
266
  *
243
- * @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
244
- * value (object, array, string, number). If `contentType` is specified in options,
245
- * input should be a string or Buffer.
267
+ * @param input - Input to validate against the Actor's input schema: an object or array serialized to JSON, or
268
+ * raw bytes sent as they are.
246
269
  * @param options - Validation options
247
270
  * @param options.build - Tag or number of the build whose input schema the input is validated against
248
271
  * (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
249
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
272
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
250
273
  * @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
251
274
  * @see https://docs.apify.com/api/v2/act-validate-input-post
252
275
  *
@@ -264,17 +287,16 @@ export class ActorClient extends ResourceClient {
264
287
  * @since Added in 2.24.0
265
288
  */
266
289
  async validateInput(input, options = {}) {
267
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
268
- // then it will process input as a buffer.
269
290
  const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
270
291
  const request = {
271
- url: this._url('validate-input'),
292
+ url: this.buildUrl('validate-input'),
272
293
  method: 'POST',
273
294
  data: input,
274
- params: this._params({ build: parsed.build }),
275
- // Apify internal property. Tells the request serialization interceptor
276
- // to stringify functions to JSON, instead of omitting them.
295
+ params: this.buildParams({ build: parsed.build }),
296
+ // Actor input may carry page functions, which plain JSON serialization would drop.
277
297
  stringifyFunctions: true,
298
+ timeoutSecs: parsed.timeoutSecs ?? 'short',
299
+ signal: parsed.signal,
278
300
  };
279
301
  if (parsed.contentType) {
280
302
  request.headers = {
@@ -296,6 +318,8 @@ export class ActorClient extends ResourceClient {
296
318
  * @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
297
319
  * @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
298
320
  * @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the build to finish on the API side before returning. Default is 0 (returns immediately).
321
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
322
+ * when the API is asked to hold the response.
299
323
  * @returns The Build object with status and build details
300
324
  * @see https://docs.apify.com/api/v2/act-builds-post
301
325
  *
@@ -315,14 +339,16 @@ export class ActorClient extends ResourceClient {
315
339
  */
316
340
  async build(versionNumber, options = {}) {
317
341
  parseArgument(versionNumber, versionNumberSchema);
318
- const parsed = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
342
+ const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
319
343
  const response = await this.httpClient.call({
320
- url: this._url('builds'),
344
+ url: this.buildUrl('builds'),
321
345
  method: 'POST',
322
- params: this._params({
346
+ params: this.buildParams({
323
347
  version: versionNumber,
324
- ...parsed,
348
+ ...params,
325
349
  }),
350
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
351
+ signal,
326
352
  });
327
353
  return parseResponse(response, schemas.Build());
328
354
  }
@@ -335,6 +361,8 @@ export class ActorClient extends ResourceClient {
335
361
  *
336
362
  * @param options - Options for getting the default build
337
363
  * @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the build to finish on the API side before returning. Default is 0 (returns immediately).
364
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
365
+ * when the API is asked to hold the response.
338
366
  * @returns A client for the default build
339
367
  * @see https://docs.apify.com/api/v2/act-build-default-get
340
368
  *
@@ -352,10 +380,13 @@ export class ActorClient extends ResourceClient {
352
380
  * @since Added in 2.12.2
353
381
  */
354
382
  async defaultBuild(options = {}) {
383
+ const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
355
384
  const response = await this.httpClient.call({
356
- url: this._url('builds/default'),
385
+ url: this.buildUrl('builds/default'),
357
386
  method: 'GET',
358
- params: this._params(options),
387
+ params: this.buildParams(params),
388
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
389
+ signal,
359
390
  });
360
391
  const { id } = parseResponse(response, schemas.Build());
361
392
  return new BuildClient({
@@ -385,9 +416,9 @@ export class ActorClient extends ResourceClient {
385
416
  */
386
417
  lastRun(options = {}) {
387
418
  const parsed = parseArgument(options, lastRunOptionsSchema, 'ActorLastRunOptions');
388
- return new RunClient(this._subResourceOptions({
419
+ return new RunClient(this.subResourceOptions({
389
420
  id: 'last',
390
- params: this._params(parsed),
421
+ params: this.buildParams(parsed),
391
422
  resourcePath: 'runs',
392
423
  }));
393
424
  }
@@ -398,7 +429,7 @@ export class ActorClient extends ResourceClient {
398
429
  * @see https://docs.apify.com/api/v2/act-builds-get
399
430
  */
400
431
  builds() {
401
- return new BuildCollectionClient(this._subResourceOptions({
432
+ return new BuildCollectionClient(this.subResourceOptions({
402
433
  resourcePath: 'builds',
403
434
  }));
404
435
  }
@@ -409,7 +440,7 @@ export class ActorClient extends ResourceClient {
409
440
  * @see https://docs.apify.com/api/v2/act-runs-get
410
441
  */
411
442
  runs() {
412
- return new RunCollectionClient(this._subResourceOptions({
443
+ return new RunCollectionClient(this.subResourceOptions({
413
444
  resourcePath: 'runs',
414
445
  }));
415
446
  }
@@ -422,7 +453,7 @@ export class ActorClient extends ResourceClient {
422
453
  */
423
454
  version(versionNumber) {
424
455
  parseArgument(versionNumber, versionNumberSchema);
425
- return new ActorVersionClient(this._subResourceOptions({
456
+ return new ActorVersionClient(this.subResourceOptions({
426
457
  id: versionNumber,
427
458
  }));
428
459
  }
@@ -433,7 +464,7 @@ export class ActorClient extends ResourceClient {
433
464
  * @see https://docs.apify.com/api/v2/act-versions-get
434
465
  */
435
466
  versions() {
436
- return new ActorVersionCollectionClient(this._subResourceOptions());
467
+ return new ActorVersionCollectionClient(this.subResourceOptions());
437
468
  }
438
469
  /**
439
470
  * Returns a client for managing webhooks associated with this Actor.
@@ -442,6 +473,6 @@ export class ActorClient extends ResourceClient {
442
473
  * @see https://docs.apify.com/api/v2/act-webhooks-get
443
474
  */
444
475
  webhooks() {
445
- return new WebhookCollectionClient(this._subResourceOptions());
476
+ return new WebhookCollectionClient(this.subResourceOptions());
446
477
  }
447
478
  }
@@ -1,11 +1,12 @@
1
1
  import type { ACTOR_PERMISSION_LEVEL } from '@apify/consts';
2
2
  import type { ApiClientSubResourceOptions } from '../base/api_client.js';
3
3
  import { ResourceCollectionClient } from '../base/resource_collection_client.js';
4
- import type { ActorCollectionListItem } from '../models.js';
4
+ import type { ActorListItem } from '../models.js';
5
+ import type { TimeoutOptions } from '../timeouts.js';
5
6
  import type { PaginatedIterator, PaginatedList, PaginationOptions } from '../utils.js';
6
- import type { Actor, ActorDefaultRunOptions, ActorExampleRunInput, ActorStandby } from './actor.js';
7
- import type { ActorVersion } from './actor_version.js';
8
- export type { ActorCollectionListItem } from '../models.js';
7
+ import type { ActorResource, ActorStandby, DefaultRunOptions, ExampleRunInput } from './actor.js';
8
+ import type { Version } from './actor_version.js';
9
+ export type { ActorListItem } from '../models.js';
9
10
  /**
10
11
  * Client for managing the collection of Actors in your account.
11
12
  *
@@ -51,35 +52,40 @@ export declare class ActorCollectionClient extends ResourceCollectionClient {
51
52
  * ```
52
53
  *
53
54
  * @param options - Pagination options.
55
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
54
56
  * @returns A paginated iterator of Actors.
55
57
  * @see https://docs.apify.com/api/v2/acts-get
56
58
  */
57
- list(options?: ActorCollectionListOptions): PaginatedIterator<ActorCollectionListItem>;
59
+ list(options?: ActorCollectionListOptions): PaginatedIterator<ActorListItem>;
58
60
  /**
59
61
  * Creates a new Actor.
60
62
  *
61
63
  * @param actor - The Actor data.
64
+ * @param options - Request options
65
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
62
66
  * @returns The created Actor object.
63
67
  * @see https://docs.apify.com/api/v2/acts-post
64
68
  */
65
- create(actor: ActorCollectionCreateOptions): Promise<Actor>;
69
+ create(actor: ActorCollectionCreateOptions, options?: TimeoutOptions): Promise<ActorResource>;
66
70
  }
67
71
  /**
72
+ * Field to order a list of Actors by.
73
+ *
68
74
  * @since Added in 2.12.6
69
75
  */
70
76
  export declare enum ActorListSortBy {
71
77
  CREATED_AT = "createdAt",
72
78
  LAST_RUN_STARTED_AT = "stats.lastRunStartedAt"
73
79
  }
74
- export interface ActorCollectionListOptions extends PaginationOptions {
80
+ export interface ActorCollectionListOptions extends PaginationOptions, TimeoutOptions {
75
81
  my?: boolean;
76
82
  desc?: boolean;
77
83
  /**
78
84
  * @since Added in 2.12.6
79
85
  */
80
- sortBy?: ActorListSortBy;
86
+ sortBy?: `${ActorListSortBy}`;
81
87
  }
82
- export type ActorCollectionListResult = PaginatedList<ActorCollectionListItem>;
88
+ export type ActorCollectionListResult = PaginatedList<ActorListItem>;
83
89
  export interface ActorCollectionCreateOptions {
84
90
  /**
85
91
  * @since Added in 2.8.6
@@ -88,20 +94,18 @@ export interface ActorCollectionCreateOptions {
88
94
  /**
89
95
  * @since Added in 2.8.6
90
96
  */
91
- defaultRunOptions?: ActorDefaultRunOptions;
97
+ defaultRunOptions?: DefaultRunOptions;
92
98
  description?: string;
93
99
  /**
94
100
  * @since Added in 2.8.6
95
101
  */
96
- exampleRunInput?: ActorExampleRunInput;
102
+ exampleRunInput?: ExampleRunInput;
97
103
  /**
98
104
  * @since Added in 2.8.6
99
105
  */
100
106
  isDeprecated?: boolean;
101
107
  isPublic?: boolean;
102
108
  name?: string;
103
- /** @deprecated Use defaultRunOptions.restartOnError instead */
104
- restartOnError?: boolean;
105
109
  /**
106
110
  * @since Added in 2.8.6
107
111
  */
@@ -111,7 +115,7 @@ export interface ActorCollectionCreateOptions {
111
115
  */
112
116
  seoDescription?: string;
113
117
  title?: string;
114
- versions?: ActorVersion[];
118
+ versions?: Version[];
115
119
  /**
116
120
  * @since Added in 2.9.5
117
121
  */
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
3
  import * as schemas from '../schemas.js';
4
+ import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
4
5
  import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
5
6
  const actorCreateSchema = anyObjectSchema.optional();
6
7
  /**
@@ -53,26 +54,32 @@ export class ActorCollectionClient extends ResourceCollectionClient {
53
54
  * ```
54
55
  *
55
56
  * @param options - Pagination options.
57
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
56
58
  * @returns A paginated iterator of Actors.
57
59
  * @see https://docs.apify.com/api/v2/acts-get
58
60
  */
59
61
  list(options = {}) {
60
62
  const parsed = parseArgument(options, listOptionsSchema, 'ActorCollectionListOptions');
61
- return this._listPaginated(schemas.ListOfActors(), parsed);
63
+ return this.listResourcesPaginated(schemas.ListOfActors(), parsed, 'medium');
62
64
  }
63
65
  /**
64
66
  * Creates a new Actor.
65
67
  *
66
68
  * @param actor - The Actor data.
69
+ * @param options - Request options
70
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
67
71
  * @returns The created Actor object.
68
72
  * @see https://docs.apify.com/api/v2/acts-post
69
73
  */
70
- async create(actor) {
74
+ async create(actor, options = {}) {
71
75
  parseArgument(actor, actorCreateSchema);
72
- return this._create(schemas.Actor(), actor);
76
+ const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
77
+ return this.createResource(schemas.ActorResource(), actor, timeoutSecs, signal);
73
78
  }
74
79
  }
75
80
  /**
81
+ * Field to order a list of Actors by.
82
+ *
76
83
  * @since Added in 2.12.6
77
84
  */
78
85
  export var ActorListSortBy;
@@ -86,4 +93,5 @@ const listOptionsSchema = z.strictObject({
86
93
  ...paginationOptionsShape,
87
94
  desc: z.boolean().optional(),
88
95
  sortBy: z.enum(ActorListSortBy).optional(),
96
+ ...timeoutOptionsShape,
89
97
  });
@@ -1,6 +1,7 @@
1
1
  import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
2
  import { ResourceClient } from '../base/resource_client.js';
3
- import type { ActorEnvironmentVariable } from './actor_version.js';
3
+ import type { TimeoutOptions } from '../timeouts.js';
4
+ import type { EnvVar } from './actor_version.js';
4
5
  /**
5
6
  * Client for managing a specific Actor environment variable.
6
7
  *
@@ -32,22 +33,28 @@ export declare class ActorEnvVarClient extends ResourceClient {
32
33
  /**
33
34
  * Retrieves the environment variable.
34
35
  *
36
+ * @param options - Request options
37
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
35
38
  * @returns The environment variable object, or `undefined` if it does not exist.
36
39
  * @see https://docs.apify.com/api/v2/act-version-env-var-get
37
40
  */
38
- get(): Promise<ActorEnvironmentVariable | undefined>;
41
+ get(options?: TimeoutOptions): Promise<EnvVar | undefined>;
39
42
  /**
40
43
  * Updates the environment variable.
41
44
  *
42
45
  * @param actorEnvVar - The updated environment variable data.
46
+ * @param options - Request options
47
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
43
48
  * @returns The updated environment variable object.
44
49
  * @see https://docs.apify.com/api/v2/act-version-env-var-put
45
50
  */
46
- update(actorEnvVar: ActorEnvironmentVariable): Promise<ActorEnvironmentVariable>;
51
+ update(actorEnvVar: EnvVar, options?: TimeoutOptions): Promise<EnvVar>;
47
52
  /**
48
53
  * Deletes the environment variable.
49
54
  *
55
+ * @param options - Request options
56
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
50
57
  * @see https://docs.apify.com/api/v2/act-version-env-var-delete
51
58
  */
52
- delete(): Promise<void>;
59
+ delete(options?: TimeoutOptions): Promise<void>;
53
60
  }
@@ -1,5 +1,6 @@
1
1
  import { ResourceClient } from '../base/resource_client.js';
2
2
  import * as schemas from '../schemas.js';
3
+ import { timeoutOptionsSchema } from '../timeouts.js';
3
4
  import { anyObjectSchema, parseArgument } from '../utils.js';
4
5
  /**
5
6
  * Client for managing a specific Actor environment variable.
@@ -37,29 +38,38 @@ export class ActorEnvVarClient extends ResourceClient {
37
38
  /**
38
39
  * Retrieves the environment variable.
39
40
  *
41
+ * @param options - Request options
42
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
40
43
  * @returns The environment variable object, or `undefined` if it does not exist.
41
44
  * @see https://docs.apify.com/api/v2/act-version-env-var-get
42
45
  */
43
- async get() {
44
- return this._get(schemas.EnvVar());
46
+ async get(options = {}) {
47
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
48
+ return this.getResource(schemas.EnvVar(), {}, timeoutSecs, signal);
45
49
  }
46
50
  /**
47
51
  * Updates the environment variable.
48
52
  *
49
53
  * @param actorEnvVar - The updated environment variable data.
54
+ * @param options - Request options
55
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
50
56
  * @returns The updated environment variable object.
51
57
  * @see https://docs.apify.com/api/v2/act-version-env-var-put
52
58
  */
53
- async update(actorEnvVar) {
59
+ async update(actorEnvVar, options = {}) {
54
60
  parseArgument(actorEnvVar, anyObjectSchema);
55
- return this._update(schemas.EnvVar(), actorEnvVar);
61
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
62
+ return this.updateResource(schemas.EnvVar(), actorEnvVar, timeoutSecs, signal);
56
63
  }
57
64
  /**
58
65
  * Deletes the environment variable.
59
66
  *
67
+ * @param options - Request options
68
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
60
69
  * @see https://docs.apify.com/api/v2/act-version-env-var-delete
61
70
  */
62
- async delete() {
63
- return this._delete();
71
+ async delete(options = {}) {
72
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
73
+ return this.deleteResource(timeoutSecs, signal);
64
74
  }
65
75
  }