apify-client 3.0.0-beta.2 → 3.0.0-beta.20

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 (91) hide show
  1. package/README.md +3 -1
  2. package/dist/apify_api_error.d.ts +60 -19
  3. package/dist/apify_api_error.js +88 -21
  4. package/dist/apify_client.d.ts +22 -3
  5. package/dist/apify_client.js +35 -29
  6. package/dist/base/api_client.d.ts +6 -6
  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 +49 -25
  10. package/dist/base/resource_collection_client.d.ts +7 -4
  11. package/dist/base/resource_collection_client.js +21 -15
  12. package/dist/bundle.js +38 -48
  13. package/dist/bundle.js.map +1 -1
  14. package/dist/generated/api.d.ts +287 -214
  15. package/dist/generated/schemas.d.ts +6699 -0
  16. package/dist/generated/schemas.js +1521 -0
  17. package/dist/http_client.d.ts +18 -51
  18. package/dist/http_client.js +79 -42
  19. package/dist/index.d.ts +3 -1
  20. package/dist/index.js +2 -1
  21. package/dist/interceptors.js +22 -4
  22. package/dist/lazy_schema.d.ts +8 -0
  23. package/dist/lazy_schema.js +11 -0
  24. package/dist/models.d.ts +32 -52
  25. package/dist/resource_clients/actor.d.ts +46 -31
  26. package/dist/resource_clients/actor.js +71 -53
  27. package/dist/resource_clients/actor_collection.d.ts +9 -5
  28. package/dist/resource_clients/actor_collection.js +12 -3
  29. package/dist/resource_clients/actor_env_var.d.ts +10 -3
  30. package/dist/resource_clients/actor_env_var.js +17 -6
  31. package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
  32. package/dist/resource_clients/actor_env_var_collection.js +18 -11
  33. package/dist/resource_clients/actor_version.d.ts +18 -3
  34. package/dist/resource_clients/actor_version.js +20 -9
  35. package/dist/resource_clients/actor_version_collection.d.ts +16 -17
  36. package/dist/resource_clients/actor_version_collection.js +20 -11
  37. package/dist/resource_clients/build.d.ts +18 -6
  38. package/dist/resource_clients/build.js +35 -17
  39. package/dist/resource_clients/build_collection.d.ts +3 -1
  40. package/dist/resource_clients/build_collection.js +5 -1
  41. package/dist/resource_clients/dataset.d.ts +23 -9
  42. package/dist/resource_clients/dataset.js +70 -48
  43. package/dist/resource_clients/dataset_collection.d.ts +6 -2
  44. package/dist/resource_clients/dataset_collection.js +13 -2
  45. package/dist/resource_clients/key_value_store.d.ts +48 -15
  46. package/dist/resource_clients/key_value_store.js +69 -39
  47. package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
  48. package/dist/resource_clients/key_value_store_collection.js +13 -2
  49. package/dist/resource_clients/log.d.ts +9 -19
  50. package/dist/resource_clients/log.js +55 -44
  51. package/dist/resource_clients/request_queue.d.ts +56 -26
  52. package/dist/resource_clients/request_queue.js +178 -113
  53. package/dist/resource_clients/request_queue_collection.d.ts +6 -2
  54. package/dist/resource_clients/request_queue_collection.js +10 -3
  55. package/dist/resource_clients/run.d.ts +51 -17
  56. package/dist/resource_clients/run.js +83 -43
  57. package/dist/resource_clients/run_collection.d.ts +3 -1
  58. package/dist/resource_clients/run_collection.js +5 -1
  59. package/dist/resource_clients/schedule.d.ts +16 -7
  60. package/dist/resource_clients/schedule.js +31 -21
  61. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  62. package/dist/resource_clients/schedule_collection.js +10 -3
  63. package/dist/resource_clients/store_collection.d.ts +3 -1
  64. package/dist/resource_clients/store_collection.js +5 -1
  65. package/dist/resource_clients/task.d.ts +28 -10
  66. package/dist/resource_clients/task.js +67 -44
  67. package/dist/resource_clients/task_collection.d.ts +6 -2
  68. package/dist/resource_clients/task_collection.js +10 -3
  69. package/dist/resource_clients/user.d.ts +17 -8
  70. package/dist/resource_clients/user.js +40 -39
  71. package/dist/resource_clients/webhook.d.ts +14 -5
  72. package/dist/resource_clients/webhook.js +30 -22
  73. package/dist/resource_clients/webhook_collection.d.ts +6 -2
  74. package/dist/resource_clients/webhook_collection.js +10 -3
  75. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  76. package/dist/resource_clients/webhook_dispatch.js +8 -2
  77. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  78. package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
  79. package/dist/response_validation_error.d.ts +26 -0
  80. package/dist/response_validation_error.js +37 -0
  81. package/dist/schemas.d.ts +15 -0
  82. package/dist/schemas.js +15 -0
  83. package/dist/statistics.d.ts +1 -6
  84. package/dist/statistics.js +2 -2
  85. package/dist/timeouts.d.ts +72 -0
  86. package/dist/timeouts.js +31 -0
  87. package/dist/utils.d.ts +57 -41
  88. package/dist/utils.js +155 -121
  89. package/package.json +36 -35
  90. package/dist/argument_validation_error.d.ts +0 -17
  91. package/dist/argument_validation_error.js +0 -153
@@ -1,6 +1,7 @@
1
1
  import { STORAGE_OWNERSHIP_FILTER } 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 { TimeoutOptions } from '../timeouts.js';
4
5
  import type { PaginatedList, PaginationOptions } from '../utils.js';
5
6
  import type { RequestQueue } from './request_queue.js';
6
7
  /**
@@ -45,6 +46,7 @@ export declare class RequestQueueCollectionClient extends ResourceCollectionClie
45
46
  * ```
46
47
  *
47
48
  * @param options - Pagination options.
49
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
48
50
  * @returns A paginated iterator of Request queues.
49
51
  * @see https://docs.apify.com/api/v2/request-queues-get
50
52
  */
@@ -53,12 +55,14 @@ export declare class RequestQueueCollectionClient extends ResourceCollectionClie
53
55
  * Gets or creates a Request queue with the specified name.
54
56
  *
55
57
  * @param name - Name of the Request queue. If not provided, a default queue is used.
58
+ * @param options - Request options
59
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
56
60
  * @returns The Request queue object.
57
61
  * @see https://docs.apify.com/api/v2/request-queues-post
58
62
  */
59
- getOrCreate(name?: string): Promise<RequestQueue>;
63
+ getOrCreate(name?: string, options?: TimeoutOptions): Promise<RequestQueue>;
60
64
  }
61
- export interface RequestQueueCollectionListOptions extends PaginationOptions {
65
+ export interface RequestQueueCollectionListOptions extends PaginationOptions, TimeoutOptions {
62
66
  unnamed?: boolean;
63
67
  desc?: boolean;
64
68
  /**
@@ -1,12 +1,15 @@
1
1
  import { z } from 'zod';
2
2
  import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
3
3
  import { ResourceCollectionClient } from '../base/resource_collection_client.js';
4
+ import * as schemas from '../schemas.js';
5
+ import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
4
6
  import { paginationOptionsShape, parseArgument } from '../utils.js';
5
7
  const listOptionsSchema = z.strictObject({
6
8
  unnamed: z.boolean().optional(),
7
9
  ...paginationOptionsShape,
8
10
  desc: z.boolean().optional(),
9
11
  ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
12
+ ...timeoutOptionsShape,
10
13
  });
11
14
  const nameSchema = z.string().optional();
12
15
  /**
@@ -56,22 +59,26 @@ export class RequestQueueCollectionClient extends ResourceCollectionClient {
56
59
  * ```
57
60
  *
58
61
  * @param options - Pagination options.
62
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
59
63
  * @returns A paginated iterator of Request queues.
60
64
  * @see https://docs.apify.com/api/v2/request-queues-get
61
65
  */
62
66
  list(options = {}) {
63
67
  const parsed = parseArgument(options, listOptionsSchema, 'RequestQueueCollectionListOptions');
64
- return this._listPaginated(parsed);
68
+ return this.listResourcesPaginated(schemas.ListOfRequestQueues(), parsed, 'medium');
65
69
  }
66
70
  /**
67
71
  * Gets or creates a Request queue with the specified name.
68
72
  *
69
73
  * @param name - Name of the Request queue. If not provided, a default queue is used.
74
+ * @param options - Request options
75
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
70
76
  * @returns The Request queue object.
71
77
  * @see https://docs.apify.com/api/v2/request-queues-post
72
78
  */
73
- async getOrCreate(name) {
79
+ async getOrCreate(name, options = {}) {
74
80
  parseArgument(name, nameSchema);
75
- return this._getOrCreate(name);
81
+ const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
82
+ return this.getOrCreateResource(schemas.RequestQueue(), name, undefined, timeoutSecs);
76
83
  }
77
84
  }
@@ -3,7 +3,8 @@ import { Log } from '@apify/log';
3
3
  import type { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client.js';
4
4
  import { ResourceClient } from '../base/resource_client.js';
5
5
  import type { ApifyResponse } from '../http_client.js';
6
- import type { ActorRun } from './actor.js';
6
+ import type { TimeoutOptions } from '../timeouts.js';
7
+ import type { ActorInput, ActorRun } from './actor.js';
7
8
  import { DatasetClient } from './dataset.js';
8
9
  import { KeyValueStoreClient } from './key_value_store.js';
9
10
  import { LogClient, StreamedLog } from './log.js';
@@ -41,6 +42,8 @@ export declare class RunClient extends ResourceClient {
41
42
  *
42
43
  * @param options - Get options
43
44
  * @param options.waitForFinish - Maximum time to wait (in seconds, max 60s) for the run to finish on the API side before returning. Default is 0 (returns immediately).
45
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`, extended to cover `waitForFinish`
46
+ * when the API is asked to hold the response.
44
47
  * @returns The ActorRun object, or `undefined` if it does not exist
45
48
  * @see https://docs.apify.com/api/v2/actor-run-get
46
49
  *
@@ -60,6 +63,7 @@ export declare class RunClient extends ResourceClient {
60
63
  *
61
64
  * @param options - Abort options
62
65
  * @param options.gracefully - If `true`, the Actor run will abort gracefully - it can send status messages and perform cleanup. Default is `false` (immediate abort).
66
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
63
67
  * @returns The updated ActorRun object with `ABORTING` or `ABORTED` status
64
68
  * @see https://docs.apify.com/api/v2/actor-run-abort-post
65
69
  *
@@ -76,10 +80,12 @@ export declare class RunClient extends ResourceClient {
76
80
  /**
77
81
  * Deletes the Actor run.
78
82
  *
83
+ * @param options - Request options
84
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
79
85
  * @see https://docs.apify.com/api/v2/actor-run-delete
80
86
  * @since Added in 2.8.1
81
87
  */
82
- delete(): Promise<void>;
88
+ delete(options?: TimeoutOptions): Promise<void>;
83
89
  /**
84
90
  * Transforms the Actor run into a run of another Actor (metamorph).
85
91
  *
@@ -88,10 +94,10 @@ export declare class RunClient extends ResourceClient {
88
94
  * This is useful for chaining Actor executions or implementing complex workflows.
89
95
  *
90
96
  * @param targetActorId - ID or username/name of the target Actor
91
- * @param input - Input for the target Actor. Can be any JSON-serializable value.
97
+ * @param input - Input for the target Actor, serialized to JSON. Omit it to metamorph without input.
92
98
  * @param options - Metamorph options
93
99
  * @param options.build - Tag or number of the target Actor's build to run. Default is the target Actor's default build.
94
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
100
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
95
101
  * @returns The metamorphed ActorRun object (same ID, but now running the target Actor)
96
102
  * @see https://docs.apify.com/api/v2/actor-run-metamorph-post
97
103
  *
@@ -105,7 +111,7 @@ export declare class RunClient extends ResourceClient {
105
111
  * console.log(`Run ${metamorphedRun.id} is now running ${metamorphedRun.actId}`);
106
112
  * ```
107
113
  */
108
- metamorph(targetActorId: string, input: unknown, options?: RunMetamorphOptions): Promise<ActorRun>;
114
+ metamorph(targetActorId: string, input?: ActorInput, options?: RunMetamorphOptions): Promise<ActorRun>;
109
115
  /**
110
116
  * Reboots the Actor run.
111
117
  *
@@ -113,6 +119,8 @@ export declare class RunClient extends ResourceClient {
113
119
  * This can be useful to recover from certain errors or to force the Actor to restart
114
120
  * with a fresh environment.
115
121
  *
122
+ * @param options - Request options
123
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
116
124
  * @returns The updated ActorRun object
117
125
  * @see https://docs.apify.com/api/v2/actor-run-reboot-post
118
126
  *
@@ -122,7 +130,7 @@ export declare class RunClient extends ResourceClient {
122
130
  * ```
123
131
  * @since Added in 2.8.0
124
132
  */
125
- reboot(): Promise<ActorRun>;
133
+ reboot(options?: TimeoutOptions): Promise<ActorRun>;
126
134
  /**
127
135
  * Updates the Actor run with specified fields.
128
136
  *
@@ -130,6 +138,8 @@ export declare class RunClient extends ResourceClient {
130
138
  * @param newFields.statusMessage - Custom status message to display (e.g., "Processing page 10/100")
131
139
  * @param newFields.isStatusMessageTerminal - If `true`, the status message is final and won't be overwritten. Default is `false`.
132
140
  * @param newFields.generalAccess - General resource access level ('FOLLOW_USER_SETTING', 'ANYONE_WITH_ID_CAN_READ' or 'RESTRICTED')
141
+ * @param options - Request options
142
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
133
143
  * @returns The updated ActorRun object
134
144
  *
135
145
  * @example
@@ -141,7 +151,7 @@ export declare class RunClient extends ResourceClient {
141
151
  * ```
142
152
  * @since Added in 2.6.0
143
153
  */
144
- update(newFields: RunUpdateOptions): Promise<ActorRun>;
154
+ update(newFields: RunUpdateOptions, options?: TimeoutOptions): Promise<ActorRun>;
145
155
  /**
146
156
  * Resurrects a finished Actor run, starting it again with the same settings.
147
157
  *
@@ -151,10 +161,11 @@ export declare class RunClient extends ResourceClient {
151
161
  * @param options - Resurrection options (override original run settings)
152
162
  * @param options.build - Tag or number of the build to use. If not provided, uses the original run's build.
153
163
  * @param options.memory - Memory in megabytes. If not provided, uses the original run's memory.
154
- * @param options.timeout - Timeout in seconds. If not provided, uses the original run's timeout.
164
+ * @param options.runTimeoutSecs - Timeout for the resurrected run in seconds. If not provided, uses the original run's timeout.
155
165
  * @param options.maxItems - Maximum number of dataset items (pay-per-result Actors).
156
166
  * @param options.maxTotalChargeUsd - Maximum cost in USD (pay-per-event Actors).
157
167
  * @param options.restartOnError - Whether to restart on error.
168
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
158
169
  * @returns The new (resurrected) ActorRun object
159
170
  * @see https://docs.apify.com/api/v2/post-resurrect-run
160
171
  *
@@ -173,6 +184,7 @@ export declare class RunClient extends ResourceClient {
173
184
  * @param options.eventName - **Required.** Name of the event to charge for.
174
185
  * @param options.count - Number of times to charge the event. Default is 1.
175
186
  * @param options.idempotencyKey - Optional key to ensure the charge is not duplicated. If not provided, one is auto-generated.
187
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
176
188
  * @returns Empty response object.
177
189
  * @see https://docs.apify.com/api/v2/post-charge-run
178
190
  * @since Added in 2.11.0
@@ -191,7 +203,8 @@ export declare class RunClient extends ResourceClient {
191
203
  *
192
204
  * @param options - Wait options
193
205
  * @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If the limit is reached, the returned promise resolves to a run object that will have status `READY` or `RUNNING`. If omitted, waits indefinitely.
194
- * @returns The ActorRun object (finished or still running if timeout was reached)
206
+ * @param options.timeoutSecs - Timeout for each polling API request. Default is `'noTimeout'`.
207
+ * @returns The ActorRun object (finished or still running if the timeout was reached)
195
208
  *
196
209
  * @example
197
210
  * ```javascript
@@ -210,6 +223,8 @@ export declare class RunClient extends ResourceClient {
210
223
  /**
211
224
  * Returns a client for the default dataset of this Actor run.
212
225
  *
226
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
227
+ *
213
228
  * @returns A client for accessing the run's default dataset
214
229
  * @see https://docs.apify.com/api/v2/actor-run-get
215
230
  *
@@ -223,6 +238,9 @@ export declare class RunClient extends ResourceClient {
223
238
  /**
224
239
  * Returns a client for the default key-value store of this Actor run.
225
240
  *
241
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
242
+ * lookups such as `getRecord()` read a 404 as a missing record.
243
+ *
226
244
  * @returns A client for accessing the run's default key-value store
227
245
  * @see https://docs.apify.com/api/v2/actor-run-get
228
246
  *
@@ -236,6 +254,9 @@ export declare class RunClient extends ResourceClient {
236
254
  /**
237
255
  * Returns a client for the default Request queue of this Actor run.
238
256
  *
257
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
258
+ * `getRequest()` reads a 404 as a missing request.
259
+ *
239
260
  * @returns A client for accessing the run's default Request queue
240
261
  * @see https://docs.apify.com/api/v2/actor-run-get
241
262
  *
@@ -249,6 +270,8 @@ export declare class RunClient extends ResourceClient {
249
270
  /**
250
271
  * Returns a client for accessing the log of this Actor run.
251
272
  *
273
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
274
+ *
252
275
  * @returns A client for accessing the run's log
253
276
  * @see https://docs.apify.com/api/v2/actor-run-get
254
277
  *
@@ -262,6 +285,11 @@ export declare class RunClient extends ResourceClient {
262
285
  log(): LogClient;
263
286
  /**
264
287
  * Get StreamedLog for convenient streaming of the run log and their redirection.
288
+ *
289
+ * @param options - Streaming options
290
+ * @param options.toLog - Log instance to redirect the run log to. Use `'default'` for a preconfigured one, or `null` to disable the redirection.
291
+ * @param options.fromStart - If `true`, the log is streamed from its beginning. Default is `true`.
292
+ * @param options.timeoutSecs - Timeout for the API requests that fetch the run and its Actor. Default is `'long'`.
265
293
  * @since Added in 2.20.0
266
294
  */
267
295
  getStreamedLog(options?: GetStreamedLogOptions): Promise<StreamedLog | undefined>;
@@ -270,26 +298,31 @@ export declare class RunClient extends ResourceClient {
270
298
  * Options for getting a streamed log.
271
299
  * @since Added in 2.20.0
272
300
  */
273
- export interface GetStreamedLogOptions {
301
+ export interface GetStreamedLogOptions extends TimeoutOptions {
274
302
  toLog?: Log | null | 'default';
275
303
  fromStart?: boolean;
276
304
  }
277
305
  /**
278
306
  * Options for getting a Run.
279
307
  */
280
- export interface RunGetOptions {
308
+ export interface RunGetOptions extends TimeoutOptions {
281
309
  waitForFinish?: number;
282
310
  }
283
311
  /**
284
312
  * Options for aborting a Run.
285
313
  */
286
- export interface RunAbortOptions {
314
+ export interface RunAbortOptions extends TimeoutOptions {
287
315
  gracefully?: boolean;
288
316
  }
289
317
  /**
290
318
  * Options for metamorphing a Run into another Actor.
291
319
  */
292
- export interface RunMetamorphOptions {
320
+ export interface RunMetamorphOptions extends TimeoutOptions {
321
+ /**
322
+ * Content type of the request body, which becomes the content type of the run's `INPUT` record.
323
+ * Without it, an input is serialized to JSON and sent as `application/json`. Pairing an object
324
+ * with `application/x-www-form-urlencoded` form-encodes it instead.
325
+ */
293
326
  contentType?: string;
294
327
  build?: string;
295
328
  }
@@ -311,10 +344,11 @@ export interface RunUpdateOptions {
311
344
  /**
312
345
  * Options for resurrecting a finished Run.
313
346
  */
314
- export interface RunResurrectOptions {
347
+ export interface RunResurrectOptions extends TimeoutOptions {
315
348
  build?: string;
316
349
  memory?: number;
317
- timeout?: number;
350
+ /** Timeout for the resurrected run in seconds. If not provided, the run keeps its original timeout. */
351
+ runTimeoutSecs?: number;
318
352
  /**
319
353
  * @since Added in 2.12.1
320
354
  */
@@ -332,7 +366,7 @@ export interface RunResurrectOptions {
332
366
  * Options for charging events in a pay-per-event Actor run.
333
367
  * @since Added in 2.11.0
334
368
  */
335
- export interface RunChargeOptions {
369
+ export interface RunChargeOptions extends TimeoutOptions {
336
370
  /** Name of the event to charge. Must be defined in the Actor's pricing info else the API will throw. */
337
371
  eventName: string;
338
372
  /** Defaults to 1 */
@@ -343,7 +377,7 @@ export interface RunChargeOptions {
343
377
  /**
344
378
  * Options for waiting for a Run to finish.
345
379
  */
346
- export interface RunWaitForFinishOptions {
380
+ export interface RunWaitForFinishOptions extends TimeoutOptions {
347
381
  /**
348
382
  * Maximum time to wait for the run to finish, in seconds.
349
383
  * If the limit is reached, the returned promise is resolved to a run object that will have