apify-client 3.0.0-beta.9 → 3.0.0-beta.90

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 (122) hide show
  1. package/README.md +16 -2
  2. package/dist/apify_api_error.d.ts +13 -27
  3. package/dist/apify_api_error.js +33 -23
  4. package/dist/apify_client.d.ts +125 -10
  5. package/dist/apify_client.js +133 -48
  6. package/dist/apify_client_error.d.ts +10 -0
  7. package/dist/apify_client_error.js +10 -0
  8. package/dist/base/api_client.d.ts +7 -7
  9. package/dist/base/api_client.js +36 -36
  10. package/dist/base/resource_client.d.ts +21 -8
  11. package/dist/base/resource_client.js +70 -36
  12. package/dist/base/resource_collection_client.d.ts +12 -4
  13. package/dist/base/resource_collection_client.js +34 -11
  14. package/dist/body_parser.d.ts +3 -4
  15. package/dist/body_parser.js +19 -26
  16. package/dist/bundle.js +27 -22
  17. package/dist/bundle.js.map +1 -1
  18. package/dist/generated/api.d.ts +3040 -971
  19. package/dist/generated/schemas.d.ts +2369 -934
  20. package/dist/generated/schemas.js +570 -229
  21. package/dist/http_clients/axios.d.ts +61 -0
  22. package/dist/http_clients/axios.js +119 -0
  23. package/dist/http_clients/base.d.ts +386 -0
  24. package/dist/http_clients/base.js +650 -0
  25. package/dist/http_clients/index.d.ts +4 -0
  26. package/dist/http_clients/index.js +2 -0
  27. package/dist/http_compressors/base.d.ts +40 -0
  28. package/dist/http_compressors/base.js +9 -0
  29. package/dist/http_compressors/brotli.d.ts +33 -0
  30. package/dist/http_compressors/brotli.js +39 -0
  31. package/dist/http_compressors/gzip.d.ts +33 -0
  32. package/dist/http_compressors/gzip.js +39 -0
  33. package/dist/http_compressors/index.d.ts +6 -0
  34. package/dist/http_compressors/index.js +2 -0
  35. package/dist/http_compressors/resolve.d.ts +23 -0
  36. package/dist/http_compressors/resolve.js +27 -0
  37. package/dist/index.d.ts +6 -1
  38. package/dist/index.js +5 -1
  39. package/dist/invalid_response_body_error.d.ts +14 -0
  40. package/dist/invalid_response_body_error.js +18 -0
  41. package/dist/models.d.ts +166 -243
  42. package/dist/models.js +6 -4
  43. package/dist/resource_clients/actor.d.ts +104 -34
  44. package/dist/resource_clients/actor.js +130 -56
  45. package/dist/resource_clients/actor_collection.d.ts +18 -12
  46. package/dist/resource_clients/actor_collection.js +11 -3
  47. package/dist/resource_clients/actor_env_var.d.ts +11 -4
  48. package/dist/resource_clients/actor_env_var.js +16 -6
  49. package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
  50. package/dist/resource_clients/actor_env_var_collection.js +11 -4
  51. package/dist/resource_clients/actor_server.d.ts +141 -0
  52. package/dist/resource_clients/actor_server.js +195 -0
  53. package/dist/resource_clients/actor_version.d.ts +20 -5
  54. package/dist/resource_clients/actor_version.js +19 -9
  55. package/dist/resource_clients/actor_version_collection.d.ts +11 -4
  56. package/dist/resource_clients/actor_version_collection.js +13 -4
  57. package/dist/resource_clients/build.d.ts +20 -7
  58. package/dist/resource_clients/build.js +35 -15
  59. package/dist/resource_clients/build_collection.d.ts +7 -5
  60. package/dist/resource_clients/build_collection.js +4 -1
  61. package/dist/resource_clients/dataset.d.ts +83 -37
  62. package/dist/resource_clients/dataset.js +107 -121
  63. package/dist/resource_clients/dataset_collection.d.ts +10 -6
  64. package/dist/resource_clients/dataset_collection.js +13 -2
  65. package/dist/resource_clients/key_value_store.d.ts +108 -26
  66. package/dist/resource_clients/key_value_store.js +134 -52
  67. package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
  68. package/dist/resource_clients/key_value_store_collection.js +13 -2
  69. package/dist/resource_clients/log.d.ts +40 -21
  70. package/dist/resource_clients/log.js +144 -66
  71. package/dist/resource_clients/request_queue.d.ts +76 -31
  72. package/dist/resource_clients/request_queue.js +178 -93
  73. package/dist/resource_clients/request_queue_collection.d.ts +9 -5
  74. package/dist/resource_clients/request_queue_collection.js +9 -3
  75. package/dist/resource_clients/run.d.ts +126 -28
  76. package/dist/resource_clients/run.js +193 -49
  77. package/dist/resource_clients/run_collection.d.ts +5 -3
  78. package/dist/resource_clients/run_collection.js +4 -1
  79. package/dist/resource_clients/schedule.d.ts +16 -7
  80. package/dist/resource_clients/schedule.js +30 -22
  81. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  82. package/dist/resource_clients/schedule_collection.js +9 -3
  83. package/dist/resource_clients/store_collection.d.ts +6 -4
  84. package/dist/resource_clients/store_collection.js +4 -1
  85. package/dist/resource_clients/task.d.ts +36 -13
  86. package/dist/resource_clients/task.js +79 -46
  87. package/dist/resource_clients/task_collection.d.ts +9 -5
  88. package/dist/resource_clients/task_collection.js +9 -3
  89. package/dist/resource_clients/user.d.ts +19 -10
  90. package/dist/resource_clients/user.js +42 -38
  91. package/dist/resource_clients/webhook.d.ts +17 -8
  92. package/dist/resource_clients/webhook.js +30 -22
  93. package/dist/resource_clients/webhook_collection.d.ts +8 -4
  94. package/dist/resource_clients/webhook_collection.js +9 -3
  95. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  96. package/dist/resource_clients/webhook_dispatch.js +7 -2
  97. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  98. package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
  99. package/dist/response_validation_error.d.ts +2 -1
  100. package/dist/response_validation_error.js +2 -1
  101. package/dist/runtime/node.d.ts +6 -0
  102. package/dist/runtime/node.js +80 -0
  103. package/dist/runtime/types.d.ts +60 -0
  104. package/dist/runtime/types.js +1 -0
  105. package/dist/runtime/web.d.ts +5 -0
  106. package/dist/runtime/web.js +21 -0
  107. package/dist/schemas.d.ts +368 -4
  108. package/dist/schemas.js +26 -4
  109. package/dist/statistics.d.ts +1 -6
  110. package/dist/statistics.js +2 -2
  111. package/dist/timeouts.d.ts +84 -0
  112. package/dist/timeouts.js +37 -0
  113. package/dist/timezones.d.ts +1 -1
  114. package/dist/utils.d.ts +89 -59
  115. package/dist/utils.js +216 -158
  116. package/dist/wait_for_resources.d.ts +8 -0
  117. package/dist/wait_for_resources.js +39 -0
  118. package/package.json +37 -34
  119. package/dist/http_client.d.ts +0 -88
  120. package/dist/http_client.js +0 -255
  121. package/dist/interceptors.d.ts +0 -19
  122. package/dist/interceptors.js +0 -105
@@ -3,7 +3,10 @@ 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';
9
+ import { ActorServerClient } from './actor_server.js';
7
10
  import { ActorVersionClient } from './actor_version.js';
8
11
  import { ActorVersionCollectionClient } from './actor_version_collection.js';
9
12
  import { BuildClient } from './build.js';
@@ -15,19 +18,21 @@ const startOptionsSchema = z.strictObject({
15
18
  build: z.string().optional(),
16
19
  contentType: z.string().optional(),
17
20
  memory: z.number().optional(),
18
- timeout: z.number().optional(),
21
+ runTimeoutSecs: z.number().min(0).optional(),
19
22
  waitForFinish: z.number().optional(),
20
23
  webhooks: z.array(anyObjectSchema).optional(),
21
24
  maxItems: z.number().min(0).optional(),
22
25
  maxTotalChargeUsd: z.number().min(0).optional(),
23
26
  restartOnError: z.boolean().optional(),
24
27
  forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
28
+ waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
29
+ ...timeoutOptionsShape,
25
30
  });
26
31
  const callOptionsSchema = z.strictObject({
27
32
  build: z.string().optional(),
28
33
  contentType: z.string().optional(),
29
34
  memory: z.number().optional(),
30
- timeout: z.number().min(0).optional(),
35
+ runTimeoutSecs: z.number().min(0).optional(),
31
36
  waitSecs: z.number().min(0).optional(),
32
37
  webhooks: z.array(anyObjectSchema).optional(),
33
38
  maxItems: z.number().min(0).optional(),
@@ -35,18 +40,23 @@ const callOptionsSchema = z.strictObject({
35
40
  log: z.union([z.null(), z.instanceof(Log), z.literal('default')]).optional(),
36
41
  restartOnError: z.boolean().optional(),
37
42
  forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
43
+ waitForResources: z.union([z.boolean(), z.number().min(0)]).optional(),
44
+ ...timeoutOptionsShape,
38
45
  });
39
46
  const validateInputOptionsSchema = z.strictObject({
40
47
  build: z.string().optional(),
41
48
  contentType: z.string().optional(),
49
+ ...timeoutOptionsShape,
42
50
  });
43
- const versionNumberSchema = z.string();
51
+ const versionNumberSchema = z.string().min(1);
44
52
  const buildOptionsSchema = z.strictObject({
45
53
  betaPackages: z.boolean().optional(),
46
54
  tag: z.string().optional(),
47
55
  useCache: z.boolean().optional(),
48
56
  waitForFinish: z.number().optional(),
57
+ ...timeoutOptionsShape,
49
58
  });
59
+ const defaultBuildOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
50
60
  const lastRunOptionsSchema = z.strictObject({
51
61
  status: z.enum(ACTOR_JOB_STATUSES).optional(),
52
62
  origin: z.enum(META_ORIGINS).optional(),
@@ -72,6 +82,7 @@ const lastRunOptionsSchema = z.strictObject({
72
82
  * @see https://docs.apify.com/platform/actors
73
83
  */
74
84
  export class ActorClient extends ResourceClient {
85
+ #serverClient;
75
86
  /**
76
87
  * @hidden
77
88
  */
@@ -84,30 +95,39 @@ export class ActorClient extends ResourceClient {
84
95
  /**
85
96
  * Gets the Actor object from the Apify API.
86
97
  *
98
+ * @param options - Request options
99
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
87
100
  * @returns The Actor object, or `undefined` if it does not exist
88
101
  * @see https://docs.apify.com/api/v2/act-get
89
102
  */
90
- async get() {
91
- return this._get(schemas.Actor());
103
+ async get(options = {}) {
104
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
105
+ return this.getResource(schemas.ActorResource(), {}, timeoutSecs, signal);
92
106
  }
93
107
  /**
94
108
  * Updates the Actor with specified fields.
95
109
  *
96
110
  * @param newFields - Fields to update in the Actor
111
+ * @param options - Request options
112
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
97
113
  * @returns The updated Actor object
98
114
  * @see https://docs.apify.com/api/v2/act-put
99
115
  */
100
- async update(newFields) {
116
+ async update(newFields, options = {}) {
101
117
  parseArgument(newFields, anyObjectSchema);
102
- return this._update(schemas.Actor(), newFields);
118
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
119
+ return this.updateResource(schemas.ActorResource(), newFields, timeoutSecs, signal);
103
120
  }
104
121
  /**
105
122
  * Deletes the Actor.
106
123
  *
124
+ * @param options - Request options
125
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
107
126
  * @see https://docs.apify.com/api/v2/act-delete
108
127
  */
109
- async delete() {
110
- return this._delete();
128
+ async delete(options = {}) {
129
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
130
+ return this.deleteResource(timeoutSecs, signal);
111
131
  }
112
132
  /**
113
133
  * Starts the Actor and immediately returns the Run object.
@@ -116,17 +136,20 @@ export class ActorClient extends ResourceClient {
116
136
  * asynchronously and this method returns immediately without waiting for completion.
117
137
  * Use the {@link call} method if you want to wait for the Actor to finish.
118
138
  *
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.
139
+ * @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
140
+ * Omit it to run the Actor without input.
121
141
  * @param options - Run configuration options
122
142
  * @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
143
  * @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.
144
+ * @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
125
145
  * @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
146
  * @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
127
147
  * @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
128
148
  * @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.
149
+ * @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
150
+ * the run. `true` retries until the run starts, a number stops retrying after that many seconds.
151
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
152
+ * when the API is asked to hold the response.
130
153
  * @returns The Actor run object with status, usage, and storage IDs
131
154
  * @see https://docs.apify.com/api/v2/act-runs-post
132
155
  *
@@ -139,18 +162,17 @@ export class ActorClient extends ResourceClient {
139
162
  * // Start Actor with specific build and memory
140
163
  * const run = await client.actor('my-actor').start(
141
164
  * { url: 'https://example.com' },
142
- * { build: '0.1.2', memory: 512, timeout: 300 }
165
+ * { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
143
166
  * );
144
167
  * ```
145
168
  */
146
169
  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
170
  const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
150
- const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, } = parsed;
171
+ const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, waitForResources, timeoutSecs, signal, } = parsed;
172
+ // The API's `timeout` parameter bounds the run, not the request.
151
173
  const params = {
152
174
  waitForFinish,
153
- timeout,
175
+ timeout: runTimeoutSecs,
154
176
  memory,
155
177
  build,
156
178
  webhooks: stringifyWebhooksToBase64(parsed.webhooks),
@@ -160,20 +182,22 @@ export class ActorClient extends ResourceClient {
160
182
  forcePermissionLevel,
161
183
  };
162
184
  const request = {
163
- url: this._url('runs'),
185
+ url: this.buildUrl('runs'),
164
186
  method: 'POST',
165
187
  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.
188
+ params: this.buildParams(params),
189
+ // Actor input may carry page functions, which plain JSON serialization would drop.
169
190
  stringifyFunctions: true,
191
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
192
+ signal,
170
193
  };
171
194
  if (parsed.contentType) {
172
195
  request.headers = {
173
196
  'content-type': parsed.contentType,
174
197
  };
175
198
  }
176
- const response = await this.httpClient.call(request);
199
+ // A `Readable` input is consumed by the first attempt, so a retry would start the run with an empty input.
200
+ const response = await startWaitingForResources(async () => this.httpClient.call(request), isStream(input) ? false : waitForResources, this.httpClient.logger, signal);
177
201
  return parseResponse(response, schemas.Run());
178
202
  }
179
203
  /**
@@ -183,14 +207,18 @@ export class ActorClient extends ResourceClient {
183
207
  * by polling the run status. It optionally streams logs to the console or a custom Log instance.
184
208
  * By default, it waits indefinitely unless the `waitSecs` option is provided.
185
209
  *
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.
210
+ * @param input - Input for the Actor: an object or array serialized to JSON, or raw bytes sent as they are.
211
+ * Omit it to run the Actor without input.
188
212
  * @param options - Run configuration options (extends all options from {@link start})
189
213
  * @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
190
214
  * @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
215
  * @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
192
216
  * @param options.memory - Memory in megabytes allocated for the run.
193
- * @param options.timeout - Maximum run duration in seconds.
217
+ * @param options.runTimeoutSecs - Maximum run duration in seconds.
218
+ * @param options.waitForResources - Retry the start while the account lacks the memory or a concurrent-run slot for
219
+ * the run. `true` retries until the run starts, a number stops retrying after that many seconds. The time spent
220
+ * retrying doesn't count toward `waitSecs`.
221
+ * @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
194
222
  * @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
195
223
  * @see https://docs.apify.com/api/v2/act-runs-post
196
224
  *
@@ -214,20 +242,18 @@ export class ActorClient extends ResourceClient {
214
242
  * ```
215
243
  */
216
244
  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
245
  const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
220
- const { waitSecs, log, ...startOptions } = parsed;
221
- const { id } = await this.start(input, startOptions);
246
+ const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
247
+ const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
222
248
  // Calling root client because we need access to top level API.
223
249
  // Creating a new instance of RunClient here would only allow
224
250
  // setting it up as a nested route under actor API.
225
251
  const newRunClient = this.apifyClient.run(id);
226
- const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
252
+ const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
227
253
  streamedLog?.start();
228
254
  return this.apifyClient
229
255
  .run(id)
230
- .waitForFinish({ waitSecs })
256
+ .waitForFinish({ waitSecs, timeoutSecs, signal })
231
257
  .finally(async () => {
232
258
  await streamedLog?.stop();
233
259
  });
@@ -240,13 +266,12 @@ export class ActorClient extends ResourceClient {
240
266
  * invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
241
267
  * validation problem.
242
268
  *
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.
269
+ * @param input - Input to validate against the Actor's input schema: an object or array serialized to JSON, or
270
+ * raw bytes sent as they are.
246
271
  * @param options - Validation options
247
272
  * @param options.build - Tag or number of the build whose input schema the input is validated against
248
273
  * (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.
274
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
250
275
  * @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
251
276
  * @see https://docs.apify.com/api/v2/act-validate-input-post
252
277
  *
@@ -264,17 +289,16 @@ export class ActorClient extends ResourceClient {
264
289
  * @since Added in 2.24.0
265
290
  */
266
291
  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
292
  const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
270
293
  const request = {
271
- url: this._url('validate-input'),
294
+ url: this.buildUrl('validate-input'),
272
295
  method: 'POST',
273
296
  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.
297
+ params: this.buildParams({ build: parsed.build }),
298
+ // Actor input may carry page functions, which plain JSON serialization would drop.
277
299
  stringifyFunctions: true,
300
+ timeoutSecs: parsed.timeoutSecs ?? 'short',
301
+ signal: parsed.signal,
278
302
  };
279
303
  if (parsed.contentType) {
280
304
  request.headers = {
@@ -296,6 +320,8 @@ export class ActorClient extends ResourceClient {
296
320
  * @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
297
321
  * @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
298
322
  * @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).
323
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
324
+ * when the API is asked to hold the response.
299
325
  * @returns The Build object with status and build details
300
326
  * @see https://docs.apify.com/api/v2/act-builds-post
301
327
  *
@@ -315,14 +341,16 @@ export class ActorClient extends ResourceClient {
315
341
  */
316
342
  async build(versionNumber, options = {}) {
317
343
  parseArgument(versionNumber, versionNumberSchema);
318
- const parsed = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
344
+ const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
319
345
  const response = await this.httpClient.call({
320
- url: this._url('builds'),
346
+ url: this.buildUrl('builds'),
321
347
  method: 'POST',
322
- params: this._params({
348
+ params: this.buildParams({
323
349
  version: versionNumber,
324
- ...parsed,
350
+ ...params,
325
351
  }),
352
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
353
+ signal,
326
354
  });
327
355
  return parseResponse(response, schemas.Build());
328
356
  }
@@ -335,6 +363,8 @@ export class ActorClient extends ResourceClient {
335
363
  *
336
364
  * @param options - Options for getting the default build
337
365
  * @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).
366
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
367
+ * when the API is asked to hold the response.
338
368
  * @returns A client for the default build
339
369
  * @see https://docs.apify.com/api/v2/act-build-default-get
340
370
  *
@@ -352,10 +382,13 @@ export class ActorClient extends ResourceClient {
352
382
  * @since Added in 2.12.2
353
383
  */
354
384
  async defaultBuild(options = {}) {
385
+ const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
355
386
  const response = await this.httpClient.call({
356
- url: this._url('builds/default'),
387
+ url: this.buildUrl('builds/default'),
357
388
  method: 'GET',
358
- params: this._params(options),
389
+ params: this.buildParams(params),
390
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
391
+ signal,
359
392
  });
360
393
  const { id } = parseResponse(response, schemas.Build());
361
394
  return new BuildClient({
@@ -385,9 +418,9 @@ export class ActorClient extends ResourceClient {
385
418
  */
386
419
  lastRun(options = {}) {
387
420
  const parsed = parseArgument(options, lastRunOptionsSchema, 'ActorLastRunOptions');
388
- return new RunClient(this._subResourceOptions({
421
+ return new RunClient(this.subResourceOptions({
389
422
  id: 'last',
390
- params: this._params(parsed),
423
+ params: this.buildParams(parsed),
391
424
  resourcePath: 'runs',
392
425
  }));
393
426
  }
@@ -398,7 +431,7 @@ export class ActorClient extends ResourceClient {
398
431
  * @see https://docs.apify.com/api/v2/act-builds-get
399
432
  */
400
433
  builds() {
401
- return new BuildCollectionClient(this._subResourceOptions({
434
+ return new BuildCollectionClient(this.subResourceOptions({
402
435
  resourcePath: 'builds',
403
436
  }));
404
437
  }
@@ -409,7 +442,7 @@ export class ActorClient extends ResourceClient {
409
442
  * @see https://docs.apify.com/api/v2/act-runs-get
410
443
  */
411
444
  runs() {
412
- return new RunCollectionClient(this._subResourceOptions({
445
+ return new RunCollectionClient(this.subResourceOptions({
413
446
  resourcePath: 'runs',
414
447
  }));
415
448
  }
@@ -422,7 +455,7 @@ export class ActorClient extends ResourceClient {
422
455
  */
423
456
  version(versionNumber) {
424
457
  parseArgument(versionNumber, versionNumberSchema);
425
- return new ActorVersionClient(this._subResourceOptions({
458
+ return new ActorVersionClient(this.subResourceOptions({
426
459
  id: versionNumber,
427
460
  }));
428
461
  }
@@ -433,7 +466,7 @@ export class ActorClient extends ResourceClient {
433
466
  * @see https://docs.apify.com/api/v2/act-versions-get
434
467
  */
435
468
  versions() {
436
- return new ActorVersionCollectionClient(this._subResourceOptions());
469
+ return new ActorVersionCollectionClient(this.subResourceOptions());
437
470
  }
438
471
  /**
439
472
  * Returns a client for managing webhooks associated with this Actor.
@@ -442,6 +475,47 @@ export class ActorClient extends ResourceClient {
442
475
  * @see https://docs.apify.com/api/v2/act-webhooks-get
443
476
  */
444
477
  webhooks() {
445
- return new WebhookCollectionClient(this._subResourceOptions());
478
+ return new WebhookCollectionClient(this.subResourceOptions());
479
+ }
480
+ /**
481
+ * Returns a client for the server interface of this Actor.
482
+ *
483
+ * A Server Actor runs a web server, its server interface, that is called over HTTP without starting a run for
484
+ * each call. Server Actors were formerly called Actor Standby, and {@link standby} is a deprecated alias of this
485
+ * method. Every call returns the same client, so the server URL it fetches is reused.
486
+ *
487
+ * @returns The client for the server interface of this Actor
488
+ * @see https://docs.apify.com/platform/actors/running/standby
489
+ *
490
+ * @example
491
+ * ```javascript
492
+ * const response = await client.actor('username/actor-name').server().request('/search', {
493
+ * params: { q: 'apify' },
494
+ * });
495
+ * ```
496
+ */
497
+ server() {
498
+ this.#serverClient ??= new ActorServerClient({
499
+ baseUrl: this.baseUrl,
500
+ publicBaseUrl: this.publicBaseUrl,
501
+ apifyClient: this.apifyClient,
502
+ httpClient: this.httpClient,
503
+ id: this.id,
504
+ params: this.params,
505
+ });
506
+ return this.#serverClient;
507
+ }
508
+ /**
509
+ * Returns a client for the server interface of this Actor in Standby mode.
510
+ *
511
+ * Named after Actor Standby, the former name of Server Actors.
512
+ *
513
+ * @deprecated Use {@link server} instead. Will be removed in v4.
514
+ * @returns The client for the server interface of this Actor
515
+ * @see https://docs.apify.com/platform/actors/running/standby
516
+ */
517
+ standby() {
518
+ this.httpClient.logger.deprecated('`standby()` is deprecated and will be removed in v4. Use `server()` instead.');
519
+ return this.server();
446
520
  }
447
521
  }
@@ -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,12 +94,12 @@ 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
  */
@@ -109,7 +115,7 @@ export interface ActorCollectionCreateOptions {
109
115
  */
110
116
  seoDescription?: string;
111
117
  title?: string;
112
- versions?: ActorVersion[];
118
+ versions?: Version[];
113
119
  /**
114
120
  * @since Added in 2.9.5
115
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
  }