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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +13 -3
  2. package/dist/apify_api_error.d.ts +62 -21
  3. package/dist/apify_api_error.js +96 -23
  4. package/dist/apify_client.d.ts +125 -10
  5. package/dist/apify_client.js +133 -48
  6. package/dist/base/api_client.d.ts +7 -7
  7. package/dist/base/api_client.js +24 -16
  8. package/dist/base/resource_client.d.ts +23 -9
  9. package/dist/base/resource_client.js +57 -29
  10. package/dist/base/resource_collection_client.d.ts +8 -4
  11. package/dist/base/resource_collection_client.js +26 -15
  12. package/dist/body_parser.d.ts +3 -4
  13. package/dist/body_parser.js +19 -26
  14. package/dist/bundle.js +29 -22
  15. package/dist/bundle.js.map +1 -1
  16. package/dist/generated/api.d.ts +887 -322
  17. package/dist/generated/schemas.d.ts +6717 -0
  18. package/dist/generated/schemas.js +1527 -0
  19. package/dist/http_clients/axios.d.ts +60 -0
  20. package/dist/http_clients/axios.js +117 -0
  21. package/dist/http_clients/base.d.ts +333 -0
  22. package/dist/http_clients/base.js +563 -0
  23. package/dist/http_clients/index.d.ts +4 -0
  24. package/dist/http_clients/index.js +2 -0
  25. package/dist/http_compressors/base.d.ts +40 -0
  26. package/dist/http_compressors/base.js +9 -0
  27. package/dist/http_compressors/brotli.d.ts +33 -0
  28. package/dist/http_compressors/brotli.js +39 -0
  29. package/dist/http_compressors/gzip.d.ts +33 -0
  30. package/dist/http_compressors/gzip.js +39 -0
  31. package/dist/http_compressors/index.d.ts +6 -0
  32. package/dist/http_compressors/index.js +2 -0
  33. package/dist/http_compressors/resolve.d.ts +23 -0
  34. package/dist/http_compressors/resolve.js +27 -0
  35. package/dist/index.d.ts +5 -1
  36. package/dist/index.js +4 -1
  37. package/dist/invalid_response_body_error.d.ts +13 -0
  38. package/dist/invalid_response_body_error.js +17 -0
  39. package/dist/lazy_schema.d.ts +8 -0
  40. package/dist/lazy_schema.js +11 -0
  41. package/dist/models.d.ts +33 -61
  42. package/dist/resource_clients/actor.d.ts +46 -31
  43. package/dist/resource_clients/actor.js +78 -58
  44. package/dist/resource_clients/actor_collection.d.ts +9 -5
  45. package/dist/resource_clients/actor_collection.js +12 -3
  46. package/dist/resource_clients/actor_env_var.d.ts +10 -3
  47. package/dist/resource_clients/actor_env_var.js +17 -6
  48. package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
  49. package/dist/resource_clients/actor_env_var_collection.js +18 -11
  50. package/dist/resource_clients/actor_version.d.ts +18 -3
  51. package/dist/resource_clients/actor_version.js +20 -9
  52. package/dist/resource_clients/actor_version_collection.d.ts +16 -17
  53. package/dist/resource_clients/actor_version_collection.js +20 -11
  54. package/dist/resource_clients/build.d.ts +18 -6
  55. package/dist/resource_clients/build.js +37 -17
  56. package/dist/resource_clients/build_collection.d.ts +3 -1
  57. package/dist/resource_clients/build_collection.js +5 -1
  58. package/dist/resource_clients/dataset.d.ts +49 -31
  59. package/dist/resource_clients/dataset.js +102 -76
  60. package/dist/resource_clients/dataset_collection.d.ts +6 -2
  61. package/dist/resource_clients/dataset_collection.js +14 -2
  62. package/dist/resource_clients/key_value_store.d.ts +58 -16
  63. package/dist/resource_clients/key_value_store.js +80 -41
  64. package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
  65. package/dist/resource_clients/key_value_store_collection.js +14 -2
  66. package/dist/resource_clients/log.d.ts +11 -19
  67. package/dist/resource_clients/log.js +64 -46
  68. package/dist/resource_clients/request_queue.d.ts +56 -26
  69. package/dist/resource_clients/request_queue.js +197 -116
  70. package/dist/resource_clients/request_queue_collection.d.ts +6 -2
  71. package/dist/resource_clients/request_queue_collection.js +10 -3
  72. package/dist/resource_clients/run.d.ts +52 -18
  73. package/dist/resource_clients/run.js +93 -47
  74. package/dist/resource_clients/run_collection.d.ts +3 -1
  75. package/dist/resource_clients/run_collection.js +5 -1
  76. package/dist/resource_clients/schedule.d.ts +16 -7
  77. package/dist/resource_clients/schedule.js +32 -21
  78. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  79. package/dist/resource_clients/schedule_collection.js +10 -3
  80. package/dist/resource_clients/store_collection.d.ts +3 -1
  81. package/dist/resource_clients/store_collection.js +5 -1
  82. package/dist/resource_clients/task.d.ts +28 -10
  83. package/dist/resource_clients/task.js +71 -46
  84. package/dist/resource_clients/task_collection.d.ts +6 -2
  85. package/dist/resource_clients/task_collection.js +10 -3
  86. package/dist/resource_clients/user.d.ts +17 -8
  87. package/dist/resource_clients/user.js +43 -39
  88. package/dist/resource_clients/webhook.d.ts +14 -5
  89. package/dist/resource_clients/webhook.js +31 -22
  90. package/dist/resource_clients/webhook_collection.d.ts +6 -2
  91. package/dist/resource_clients/webhook_collection.js +10 -3
  92. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  93. package/dist/resource_clients/webhook_dispatch.js +8 -2
  94. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  95. package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
  96. package/dist/response_validation_error.d.ts +26 -0
  97. package/dist/response_validation_error.js +37 -0
  98. package/dist/runtime/node.d.ts +6 -0
  99. package/dist/runtime/node.js +49 -0
  100. package/dist/runtime/types.d.ts +52 -0
  101. package/dist/runtime/types.js +1 -0
  102. package/dist/runtime/web.d.ts +5 -0
  103. package/dist/runtime/web.js +18 -0
  104. package/dist/schemas.d.ts +15 -0
  105. package/dist/schemas.js +15 -0
  106. package/dist/statistics.d.ts +1 -6
  107. package/dist/statistics.js +2 -2
  108. package/dist/timeouts.d.ts +84 -0
  109. package/dist/timeouts.js +37 -0
  110. package/dist/timezones.d.ts +1 -1
  111. package/dist/utils.d.ts +86 -46
  112. package/dist/utils.js +218 -164
  113. package/package.json +32 -29
  114. package/dist/http_client.d.ts +0 -88
  115. package/dist/http_client.js +0 -255
  116. package/dist/interceptors.d.ts +0 -19
  117. package/dist/interceptors.js +0 -105
@@ -3,6 +3,7 @@ import { Log } from '@apify/log';
3
3
  import type { ApiClientSubResourceOptions } from '../base/api_client.js';
4
4
  import { ResourceClient } from '../base/resource_client.js';
5
5
  import type { Actor, ActorRun } from '../models.js';
6
+ import type { TimeoutOptions } from '../timeouts.js';
6
7
  import { ActorVersionClient } from './actor_version.js';
7
8
  import { ActorVersionCollectionClient } from './actor_version_collection.js';
8
9
  import type { Build, BuildClientGetOptions } from './build.js';
@@ -42,24 +43,30 @@ export declare class ActorClient extends ResourceClient {
42
43
  /**
43
44
  * Gets the Actor object from the Apify API.
44
45
  *
46
+ * @param options - Request options
47
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
45
48
  * @returns The Actor object, or `undefined` if it does not exist
46
49
  * @see https://docs.apify.com/api/v2/act-get
47
50
  */
48
- get(): Promise<Actor | undefined>;
51
+ get(options?: TimeoutOptions): Promise<Actor | undefined>;
49
52
  /**
50
53
  * Updates the Actor with specified fields.
51
54
  *
52
55
  * @param newFields - Fields to update in the Actor
56
+ * @param options - Request options
57
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
53
58
  * @returns The updated Actor object
54
59
  * @see https://docs.apify.com/api/v2/act-put
55
60
  */
56
- update(newFields: ActorUpdateOptions): Promise<Actor>;
61
+ update(newFields: ActorUpdateOptions, options?: TimeoutOptions): Promise<Actor>;
57
62
  /**
58
63
  * Deletes the Actor.
59
64
  *
65
+ * @param options - Request options
66
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
60
67
  * @see https://docs.apify.com/api/v2/act-delete
61
68
  */
62
- delete(): Promise<void>;
69
+ delete(options?: TimeoutOptions): Promise<void>;
63
70
  /**
64
71
  * Starts the Actor and immediately returns the Run object.
65
72
  *
@@ -67,17 +74,17 @@ export declare class ActorClient extends ResourceClient {
67
74
  * asynchronously and this method returns immediately without waiting for completion.
68
75
  * Use the {@link call} method if you want to wait for the Actor to finish.
69
76
  *
70
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
71
- * If `contentType` is specified in options, input should be a string or Buffer.
77
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
72
78
  * @param options - Run configuration options
73
79
  * @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.
74
80
  * @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
75
- * @param options.timeout - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
81
+ * @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
76
82
  * @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).
77
83
  * @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
78
84
  * @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
79
85
  * @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
80
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
86
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
87
+ * when the API is asked to hold the response.
81
88
  * @returns The Actor run object with status, usage, and storage IDs
82
89
  * @see https://docs.apify.com/api/v2/act-runs-post
83
90
  *
@@ -90,11 +97,11 @@ export declare class ActorClient extends ResourceClient {
90
97
  * // Start Actor with specific build and memory
91
98
  * const run = await client.actor('my-actor').start(
92
99
  * { url: 'https://example.com' },
93
- * { build: '0.1.2', memory: 512, timeout: 300 }
100
+ * { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
94
101
  * );
95
102
  * ```
96
103
  */
97
- start(input?: unknown, options?: ActorStartOptions): Promise<ActorRun>;
104
+ start(input?: ActorInput, options?: ActorStartOptions): Promise<ActorRun>;
98
105
  /**
99
106
  * Starts the Actor and waits for it to finish before returning the Run object.
100
107
  *
@@ -102,14 +109,14 @@ export declare class ActorClient extends ResourceClient {
102
109
  * by polling the run status. It optionally streams logs to the console or a custom Log instance.
103
110
  * By default, it waits indefinitely unless the `waitSecs` option is provided.
104
111
  *
105
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
106
- * If `contentType` is specified in options, input should be a string or Buffer.
112
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
107
113
  * @param options - Run configuration options (extends all options from {@link start})
108
114
  * @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
109
115
  * @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
110
116
  * @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
111
117
  * @param options.memory - Memory in megabytes allocated for the run.
112
- * @param options.timeout - Maximum run duration in seconds.
118
+ * @param options.runTimeoutSecs - Maximum run duration in seconds.
119
+ * @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
113
120
  * @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
114
121
  * @see https://docs.apify.com/api/v2/act-runs-post
115
122
  *
@@ -132,7 +139,7 @@ export declare class ActorClient extends ResourceClient {
132
139
  * const run = await client.actor('my-actor').call({ url: 'https://example.com' }, { log });
133
140
  * ```
134
141
  */
135
- call(input?: unknown, options?: ActorCallOptions): Promise<ActorRun>;
142
+ call(input?: ActorInput, options?: ActorCallOptions): Promise<ActorRun>;
136
143
  /**
137
144
  * Validates the provided input for the Actor against its input schema.
138
145
  *
@@ -141,13 +148,11 @@ export declare class ActorClient extends ResourceClient {
141
148
  * invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
142
149
  * validation problem.
143
150
  *
144
- * @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
145
- * value (object, array, string, number). If `contentType` is specified in options,
146
- * input should be a string or Buffer.
151
+ * @param input - Input to validate against the Actor's input schema, serialized to JSON.
147
152
  * @param options - Validation options
148
153
  * @param options.build - Tag or number of the build whose input schema the input is validated against
149
154
  * (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
150
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
155
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
151
156
  * @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
152
157
  * @see https://docs.apify.com/api/v2/act-validate-input-post
153
158
  *
@@ -164,7 +169,7 @@ export declare class ActorClient extends ResourceClient {
164
169
  * ```
165
170
  * @since Added in 2.24.0
166
171
  */
167
- validateInput(input?: unknown, options?: ActorValidateInputOptions): Promise<boolean>;
172
+ validateInput(input?: ActorInput, options?: ActorValidateInputOptions): Promise<boolean>;
168
173
  /**
169
174
  * Builds the Actor.
170
175
  *
@@ -177,6 +182,8 @@ export declare class ActorClient extends ResourceClient {
177
182
  * @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
178
183
  * @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
179
184
  * @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).
185
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
186
+ * when the API is asked to hold the response.
180
187
  * @returns The Build object with status and build details
181
188
  * @see https://docs.apify.com/api/v2/act-builds-post
182
189
  *
@@ -204,6 +211,8 @@ export declare class ActorClient extends ResourceClient {
204
211
  *
205
212
  * @param options - Options for getting the default build
206
213
  * @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).
214
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
215
+ * when the API is asked to hold the response.
207
216
  * @returns A client for the default build
208
217
  * @see https://docs.apify.com/api/v2/act-build-default-get
209
218
  *
@@ -280,17 +289,24 @@ export declare class ActorClient extends ResourceClient {
280
289
  * Fields that can be updated when modifying an Actor.
281
290
  */
282
291
  export type ActorUpdateOptions = Partial<Pick<Actor, 'name' | 'description' | 'isPublic' | 'isDeprecated' | 'seoTitle' | 'seoDescription' | 'title' | 'restartOnError' | 'versions' | 'categories' | 'defaultRunOptions' | 'actorStandby' | 'actorPermissionLevel' | 'taggedBuilds'>>;
283
- export interface ActorStartOptions {
292
+ /**
293
+ * Input for an Actor run, as taken by {@link ActorClient.start}, {@link ActorClient.call},
294
+ * {@link ActorClient.validateInput} and {@link RunClient.metamorph}.
295
+ *
296
+ * An object or an array. Declared as `object` rather than an index-signature type such as
297
+ * `Dictionary`, which would reject a caller's own `interface`.
298
+ */
299
+ export type ActorInput = object;
300
+ export interface ActorStartOptions extends TimeoutOptions {
284
301
  /**
285
302
  * Tag or number of the Actor build to run (e.g. `beta` or `1.2.345`).
286
303
  * If not provided, the run uses build tag or number from the default Actor run configuration (typically `latest`).
287
304
  */
288
305
  build?: string;
289
306
  /**
290
- * Content type for the `input`. If not specified,
291
- * `input` is expected to be an object that will be stringified to JSON and content type set to
292
- * `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
293
- * `String` or `Buffer`.
307
+ * Content type of the request body, which becomes the content type of the run's `INPUT` record.
308
+ * Without it, an input is serialized to JSON and sent as `application/json`. Pairing an object
309
+ * with `application/x-www-form-urlencoded` form-encodes it instead.
294
310
  */
295
311
  contentType?: string;
296
312
  /**
@@ -300,9 +316,9 @@ export interface ActorStartOptions {
300
316
  memory?: number;
301
317
  /**
302
318
  * Timeout for the Actor run in seconds. Zero value means there is no timeout.
303
- * If not provided, the run uses timeout of the default Actor run configuration.
319
+ * If not provided, the run uses the timeout of the default Actor run configuration.
304
320
  */
305
- timeout?: number;
321
+ runTimeoutSecs?: number;
306
322
  /**
307
323
  * Maximum time to wait for the Actor run to finish, in seconds.
308
324
  * If the limit is reached, the returned promise is resolved to a run object that will have
@@ -369,24 +385,23 @@ export interface ActorCallOptions extends Omit<ActorStartOptions, 'waitForFinish
369
385
  * Options for validating an Actor input.
370
386
  * @since Added in 2.24.0
371
387
  */
372
- export interface ActorValidateInputOptions {
388
+ export interface ActorValidateInputOptions extends TimeoutOptions {
373
389
  /**
374
390
  * Tag or number of the Actor build whose input schema the input is validated against
375
391
  * (e.g. `beta` or `1.2.345`). If not provided, the default build is used.
376
392
  */
377
393
  build?: string;
378
394
  /**
379
- * Content type for the `input`. If not specified,
380
- * `input` is expected to be an object that will be stringified to JSON and content type set to
381
- * `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
382
- * `String` or `Buffer`.
395
+ * Content type of the request body carrying the input to validate. Without it, the input is
396
+ * serialized to JSON and sent as `application/json`. Pairing an object with
397
+ * `application/x-www-form-urlencoded` form-encodes it instead.
383
398
  */
384
399
  contentType?: string;
385
400
  }
386
401
  /**
387
402
  * Options for building an Actor.
388
403
  */
389
- export interface ActorBuildOptions {
404
+ export interface ActorBuildOptions extends TimeoutOptions {
390
405
  betaPackages?: boolean;
391
406
  tag?: string;
392
407
  useCache?: boolean;
@@ -2,7 +2,9 @@ import { z } from 'zod';
2
2
  import { ACTOR_JOB_STATUSES, ACTOR_PERMISSION_LEVEL, META_ORIGINS } from '@apify/consts';
3
3
  import { Log } from '@apify/log';
4
4
  import { ResourceClient } from '../base/resource_client.js';
5
- import { anyObjectSchema, cast, parseArgument, parseDateFields, pluckData, stringifyWebhooksToBase64, } from '../utils.js';
5
+ import * as schemas from '../schemas.js';
6
+ import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
7
+ import { anyObjectSchema, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
6
8
  import { ActorVersionClient } from './actor_version.js';
7
9
  import { ActorVersionCollectionClient } from './actor_version_collection.js';
8
10
  import { BuildClient } from './build.js';
@@ -14,19 +16,20 @@ const startOptionsSchema = z.strictObject({
14
16
  build: z.string().optional(),
15
17
  contentType: z.string().optional(),
16
18
  memory: z.number().optional(),
17
- timeout: z.number().optional(),
19
+ runTimeoutSecs: z.number().min(0).optional(),
18
20
  waitForFinish: z.number().optional(),
19
21
  webhooks: z.array(anyObjectSchema).optional(),
20
22
  maxItems: z.number().min(0).optional(),
21
23
  maxTotalChargeUsd: z.number().min(0).optional(),
22
24
  restartOnError: z.boolean().optional(),
23
25
  forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
26
+ ...timeoutOptionsShape,
24
27
  });
25
28
  const callOptionsSchema = z.strictObject({
26
29
  build: z.string().optional(),
27
30
  contentType: z.string().optional(),
28
31
  memory: z.number().optional(),
29
- timeout: z.number().min(0).optional(),
32
+ runTimeoutSecs: z.number().min(0).optional(),
30
33
  waitSecs: z.number().min(0).optional(),
31
34
  webhooks: z.array(anyObjectSchema).optional(),
32
35
  maxItems: z.number().min(0).optional(),
@@ -34,18 +37,22 @@ const callOptionsSchema = z.strictObject({
34
37
  log: z.union([z.null(), z.instanceof(Log), z.literal('default')]).optional(),
35
38
  restartOnError: z.boolean().optional(),
36
39
  forcePermissionLevel: z.enum(ACTOR_PERMISSION_LEVEL).optional(),
40
+ ...timeoutOptionsShape,
37
41
  });
38
42
  const validateInputOptionsSchema = z.strictObject({
39
43
  build: z.string().optional(),
40
44
  contentType: z.string().optional(),
45
+ ...timeoutOptionsShape,
41
46
  });
42
- const versionNumberSchema = z.string();
47
+ const versionNumberSchema = z.string().min(1);
43
48
  const buildOptionsSchema = z.strictObject({
44
49
  betaPackages: z.boolean().optional(),
45
50
  tag: z.string().optional(),
46
51
  useCache: z.boolean().optional(),
47
52
  waitForFinish: z.number().optional(),
53
+ ...timeoutOptionsShape,
48
54
  });
55
+ const defaultBuildOptionsSchema = z.strictObject({ waitForFinish: z.number().optional(), ...timeoutOptionsShape });
49
56
  const lastRunOptionsSchema = z.strictObject({
50
57
  status: z.enum(ACTOR_JOB_STATUSES).optional(),
51
58
  origin: z.enum(META_ORIGINS).optional(),
@@ -83,30 +90,39 @@ export class ActorClient extends ResourceClient {
83
90
  /**
84
91
  * Gets the Actor object from the Apify API.
85
92
  *
93
+ * @param options - Request options
94
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
86
95
  * @returns The Actor object, or `undefined` if it does not exist
87
96
  * @see https://docs.apify.com/api/v2/act-get
88
97
  */
89
- async get() {
90
- return this._get();
98
+ async get(options = {}) {
99
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
100
+ return this.getResource(schemas.Actor(), {}, timeoutSecs, signal);
91
101
  }
92
102
  /**
93
103
  * Updates the Actor with specified fields.
94
104
  *
95
105
  * @param newFields - Fields to update in the Actor
106
+ * @param options - Request options
107
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
96
108
  * @returns The updated Actor object
97
109
  * @see https://docs.apify.com/api/v2/act-put
98
110
  */
99
- async update(newFields) {
111
+ async update(newFields, options = {}) {
100
112
  parseArgument(newFields, anyObjectSchema);
101
- return this._update(newFields);
113
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
114
+ return this.updateResource(schemas.Actor(), newFields, timeoutSecs, signal);
102
115
  }
103
116
  /**
104
117
  * Deletes the Actor.
105
118
  *
119
+ * @param options - Request options
120
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
106
121
  * @see https://docs.apify.com/api/v2/act-delete
107
122
  */
108
- async delete() {
109
- return this._delete();
123
+ async delete(options = {}) {
124
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
125
+ return this.deleteResource(timeoutSecs, signal);
110
126
  }
111
127
  /**
112
128
  * Starts the Actor and immediately returns the Run object.
@@ -115,17 +131,17 @@ export class ActorClient extends ResourceClient {
115
131
  * asynchronously and this method returns immediately without waiting for completion.
116
132
  * Use the {@link call} method if you want to wait for the Actor to finish.
117
133
  *
118
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
119
- * If `contentType` is specified in options, input should be a string or Buffer.
134
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
120
135
  * @param options - Run configuration options
121
136
  * @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.
122
137
  * @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
123
- * @param options.timeout - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
138
+ * @param options.runTimeoutSecs - Timeout for the run in seconds. Zero means no timeout. If not provided, uses the Actor's default timeout.
124
139
  * @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).
125
140
  * @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
126
141
  * @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
127
142
  * @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
128
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
143
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
144
+ * when the API is asked to hold the response.
129
145
  * @returns The Actor run object with status, usage, and storage IDs
130
146
  * @see https://docs.apify.com/api/v2/act-runs-post
131
147
  *
@@ -138,18 +154,17 @@ export class ActorClient extends ResourceClient {
138
154
  * // Start Actor with specific build and memory
139
155
  * const run = await client.actor('my-actor').start(
140
156
  * { url: 'https://example.com' },
141
- * { build: '0.1.2', memory: 512, timeout: 300 }
157
+ * { build: '0.1.2', memory: 512, runTimeoutSecs: 300 }
142
158
  * );
143
159
  * ```
144
160
  */
145
161
  async start(input, options = {}) {
146
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
147
- // then it will process input as a buffer.
148
162
  const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
149
- const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, } = parsed;
163
+ const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, timeoutSecs, signal, } = parsed;
164
+ // The API's `timeout` parameter bounds the run, not the request.
150
165
  const params = {
151
166
  waitForFinish,
152
- timeout,
167
+ timeout: runTimeoutSecs,
153
168
  memory,
154
169
  build,
155
170
  webhooks: stringifyWebhooksToBase64(parsed.webhooks),
@@ -159,13 +174,14 @@ export class ActorClient extends ResourceClient {
159
174
  forcePermissionLevel,
160
175
  };
161
176
  const request = {
162
- url: this._url('runs'),
177
+ url: this.buildUrl('runs'),
163
178
  method: 'POST',
164
179
  data: input,
165
- params: this._params(params),
166
- // Apify internal property. Tells the request serialization interceptor
167
- // to stringify functions to JSON, instead of omitting them.
180
+ params: this.buildParams(params),
181
+ // Actor input may carry page functions, which plain JSON serialization would drop.
168
182
  stringifyFunctions: true,
183
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
184
+ signal,
169
185
  };
170
186
  if (parsed.contentType) {
171
187
  request.headers = {
@@ -173,7 +189,7 @@ export class ActorClient extends ResourceClient {
173
189
  };
174
190
  }
175
191
  const response = await this.httpClient.call(request);
176
- return cast(parseDateFields(pluckData(response.data)));
192
+ return parseResponse(response, schemas.Run());
177
193
  }
178
194
  /**
179
195
  * Starts the Actor and waits for it to finish before returning the Run object.
@@ -182,14 +198,14 @@ export class ActorClient extends ResourceClient {
182
198
  * by polling the run status. It optionally streams logs to the console or a custom Log instance.
183
199
  * By default, it waits indefinitely unless the `waitSecs` option is provided.
184
200
  *
185
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
186
- * If `contentType` is specified in options, input should be a string or Buffer.
201
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
187
202
  * @param options - Run configuration options (extends all options from {@link start})
188
203
  * @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
189
204
  * @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
190
205
  * @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`).
191
206
  * @param options.memory - Memory in megabytes allocated for the run.
192
- * @param options.timeout - Maximum run duration in seconds.
207
+ * @param options.runTimeoutSecs - Maximum run duration in seconds.
208
+ * @param options.timeoutSecs - Timeout for each API request, the start and every poll alike. Default is `'noTimeout'`.
193
209
  * @returns The finished Actor run object with final status (`SUCCEEDED`, `FAILED`, `ABORTED`, or `TIMED-OUT`)
194
210
  * @see https://docs.apify.com/api/v2/act-runs-post
195
211
  *
@@ -213,20 +229,18 @@ export class ActorClient extends ResourceClient {
213
229
  * ```
214
230
  */
215
231
  async call(input, options = {}) {
216
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
217
- // then it will process input as a buffer.
218
232
  const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
219
- const { waitSecs, log, ...startOptions } = parsed;
220
- const { id } = await this.start(input, startOptions);
233
+ const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
234
+ const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
221
235
  // Calling root client because we need access to top level API.
222
236
  // Creating a new instance of RunClient here would only allow
223
237
  // setting it up as a nested route under actor API.
224
238
  const newRunClient = this.apifyClient.run(id);
225
- const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
239
+ const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
226
240
  streamedLog?.start();
227
241
  return this.apifyClient
228
242
  .run(id)
229
- .waitForFinish({ waitSecs })
243
+ .waitForFinish({ waitSecs, timeoutSecs, signal })
230
244
  .finally(async () => {
231
245
  await streamedLog?.stop();
232
246
  });
@@ -239,13 +253,11 @@ export class ActorClient extends ResourceClient {
239
253
  * invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
240
254
  * validation problem.
241
255
  *
242
- * @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
243
- * value (object, array, string, number). If `contentType` is specified in options,
244
- * input should be a string or Buffer.
256
+ * @param input - Input to validate against the Actor's input schema, serialized to JSON.
245
257
  * @param options - Validation options
246
258
  * @param options.build - Tag or number of the build whose input schema the input is validated against
247
259
  * (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
248
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
260
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
249
261
  * @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
250
262
  * @see https://docs.apify.com/api/v2/act-validate-input-post
251
263
  *
@@ -263,17 +275,16 @@ export class ActorClient extends ResourceClient {
263
275
  * @since Added in 2.24.0
264
276
  */
265
277
  async validateInput(input, options = {}) {
266
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
267
- // then it will process input as a buffer.
268
278
  const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
269
279
  const request = {
270
- url: this._url('validate-input'),
280
+ url: this.buildUrl('validate-input'),
271
281
  method: 'POST',
272
282
  data: input,
273
- params: this._params({ build: parsed.build }),
274
- // Apify internal property. Tells the request serialization interceptor
275
- // to stringify functions to JSON, instead of omitting them.
283
+ params: this.buildParams({ build: parsed.build }),
284
+ // Actor input may carry page functions, which plain JSON serialization would drop.
276
285
  stringifyFunctions: true,
286
+ timeoutSecs: parsed.timeoutSecs ?? 'short',
287
+ signal: parsed.signal,
277
288
  };
278
289
  if (parsed.contentType) {
279
290
  request.headers = {
@@ -295,6 +306,8 @@ export class ActorClient extends ResourceClient {
295
306
  * @param options.tag - Tag to be applied to the build (e.g., `'latest'`, `'beta'`). Existing tag with the same name will be replaced.
296
307
  * @param options.useCache - If `false`, Docker build cache will be ignored. Default is `true`.
297
308
  * @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).
309
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`, extended to cover `waitForFinish`
310
+ * when the API is asked to hold the response.
298
311
  * @returns The Build object with status and build details
299
312
  * @see https://docs.apify.com/api/v2/act-builds-post
300
313
  *
@@ -314,16 +327,18 @@ export class ActorClient extends ResourceClient {
314
327
  */
315
328
  async build(versionNumber, options = {}) {
316
329
  parseArgument(versionNumber, versionNumberSchema);
317
- const parsed = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
330
+ const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
318
331
  const response = await this.httpClient.call({
319
- url: this._url('builds'),
332
+ url: this.buildUrl('builds'),
320
333
  method: 'POST',
321
- params: this._params({
334
+ params: this.buildParams({
322
335
  version: versionNumber,
323
- ...parsed,
336
+ ...params,
324
337
  }),
338
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
339
+ signal,
325
340
  });
326
- return cast(parseDateFields(pluckData(response.data)));
341
+ return parseResponse(response, schemas.Build());
327
342
  }
328
343
  /**
329
344
  * Returns a client for the default build of this Actor.
@@ -334,6 +349,8 @@ export class ActorClient extends ResourceClient {
334
349
  *
335
350
  * @param options - Options for getting the default build
336
351
  * @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).
352
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
353
+ * when the API is asked to hold the response.
337
354
  * @returns A client for the default build
338
355
  * @see https://docs.apify.com/api/v2/act-build-default-get
339
356
  *
@@ -351,12 +368,15 @@ export class ActorClient extends ResourceClient {
351
368
  * @since Added in 2.12.2
352
369
  */
353
370
  async defaultBuild(options = {}) {
371
+ const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
354
372
  const response = await this.httpClient.call({
355
- url: this._url('builds/default'),
373
+ url: this.buildUrl('builds/default'),
356
374
  method: 'GET',
357
- params: this._params(options),
375
+ params: this.buildParams(params),
376
+ timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
377
+ signal,
358
378
  });
359
- const { id } = pluckData(response.data);
379
+ const { id } = parseResponse(response, schemas.Build());
360
380
  return new BuildClient({
361
381
  baseUrl: this.apifyClient.baseUrl,
362
382
  publicBaseUrl: this.apifyClient.publicBaseUrl,
@@ -384,9 +404,9 @@ export class ActorClient extends ResourceClient {
384
404
  */
385
405
  lastRun(options = {}) {
386
406
  const parsed = parseArgument(options, lastRunOptionsSchema, 'ActorLastRunOptions');
387
- return new RunClient(this._subResourceOptions({
407
+ return new RunClient(this.subResourceOptions({
388
408
  id: 'last',
389
- params: this._params(parsed),
409
+ params: this.buildParams(parsed),
390
410
  resourcePath: 'runs',
391
411
  }));
392
412
  }
@@ -397,7 +417,7 @@ export class ActorClient extends ResourceClient {
397
417
  * @see https://docs.apify.com/api/v2/act-builds-get
398
418
  */
399
419
  builds() {
400
- return new BuildCollectionClient(this._subResourceOptions({
420
+ return new BuildCollectionClient(this.subResourceOptions({
401
421
  resourcePath: 'builds',
402
422
  }));
403
423
  }
@@ -408,7 +428,7 @@ export class ActorClient extends ResourceClient {
408
428
  * @see https://docs.apify.com/api/v2/act-runs-get
409
429
  */
410
430
  runs() {
411
- return new RunCollectionClient(this._subResourceOptions({
431
+ return new RunCollectionClient(this.subResourceOptions({
412
432
  resourcePath: 'runs',
413
433
  }));
414
434
  }
@@ -421,7 +441,7 @@ export class ActorClient extends ResourceClient {
421
441
  */
422
442
  version(versionNumber) {
423
443
  parseArgument(versionNumber, versionNumberSchema);
424
- return new ActorVersionClient(this._subResourceOptions({
444
+ return new ActorVersionClient(this.subResourceOptions({
425
445
  id: versionNumber,
426
446
  }));
427
447
  }
@@ -432,7 +452,7 @@ export class ActorClient extends ResourceClient {
432
452
  * @see https://docs.apify.com/api/v2/act-versions-get
433
453
  */
434
454
  versions() {
435
- return new ActorVersionCollectionClient(this._subResourceOptions());
455
+ return new ActorVersionCollectionClient(this.subResourceOptions());
436
456
  }
437
457
  /**
438
458
  * Returns a client for managing webhooks associated with this Actor.
@@ -441,6 +461,6 @@ export class ActorClient extends ResourceClient {
441
461
  * @see https://docs.apify.com/api/v2/act-webhooks-get
442
462
  */
443
463
  webhooks() {
444
- return new WebhookCollectionClient(this._subResourceOptions());
464
+ return new WebhookCollectionClient(this.subResourceOptions());
445
465
  }
446
466
  }
@@ -2,6 +2,7 @@ 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
4
  import type { ActorCollectionListItem } from '../models.js';
5
+ import type { TimeoutOptions } from '../timeouts.js';
5
6
  import type { PaginatedIterator, PaginatedList, PaginationOptions } from '../utils.js';
6
7
  import type { Actor, ActorDefaultRunOptions, ActorExampleRunInput, ActorStandby } from './actor.js';
7
8
  import type { ActorVersion } from './actor_version.js';
@@ -51,6 +52,7 @@ 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
  */
@@ -59,25 +61,29 @@ export declare class ActorCollectionClient extends ResourceCollectionClient {
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<Actor>;
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
88
  export type ActorCollectionListResult = PaginatedList<ActorCollectionListItem>;
83
89
  export interface ActorCollectionCreateOptions {
@@ -100,8 +106,6 @@ export interface ActorCollectionCreateOptions {
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
  */