apify-client 3.0.0-beta.5 → 3.0.0-beta.51

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 (115) 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 +36 -24
  8. package/dist/base/resource_client.d.ts +21 -8
  9. package/dist/base/resource_client.js +54 -26
  10. package/dist/base/resource_collection_client.d.ts +12 -4
  11. package/dist/base/resource_collection_client.js +34 -11
  12. package/dist/body_parser.d.ts +3 -4
  13. package/dist/body_parser.js +19 -26
  14. package/dist/bundle.js +27 -22
  15. package/dist/bundle.js.map +1 -1
  16. package/dist/generated/api.d.ts +610 -112
  17. package/dist/generated/schemas.d.ts +726 -703
  18. package/dist/generated/schemas.js +92 -85
  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 +4 -1
  36. package/dist/index.js +3 -1
  37. package/dist/invalid_response_body_error.d.ts +13 -0
  38. package/dist/invalid_response_body_error.js +17 -0
  39. package/dist/models.d.ts +19 -22
  40. package/dist/resource_clients/actor.d.ts +72 -32
  41. package/dist/resource_clients/actor.js +87 -56
  42. package/dist/resource_clients/actor_collection.d.ts +9 -5
  43. package/dist/resource_clients/actor_collection.js +11 -3
  44. package/dist/resource_clients/actor_env_var.d.ts +10 -3
  45. package/dist/resource_clients/actor_env_var.js +16 -6
  46. package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
  47. package/dist/resource_clients/actor_env_var_collection.js +17 -11
  48. package/dist/resource_clients/actor_version.d.ts +18 -3
  49. package/dist/resource_clients/actor_version.js +19 -9
  50. package/dist/resource_clients/actor_version_collection.d.ts +16 -17
  51. package/dist/resource_clients/actor_version_collection.js +19 -11
  52. package/dist/resource_clients/build.d.ts +18 -6
  53. package/dist/resource_clients/build.js +34 -15
  54. package/dist/resource_clients/build_collection.d.ts +3 -1
  55. package/dist/resource_clients/build_collection.js +4 -1
  56. package/dist/resource_clients/dataset.d.ts +51 -33
  57. package/dist/resource_clients/dataset.js +105 -80
  58. package/dist/resource_clients/dataset_collection.d.ts +6 -2
  59. package/dist/resource_clients/dataset_collection.js +13 -2
  60. package/dist/resource_clients/key_value_store.d.ts +58 -16
  61. package/dist/resource_clients/key_value_store.js +78 -40
  62. package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
  63. package/dist/resource_clients/key_value_store_collection.js +13 -2
  64. package/dist/resource_clients/log.d.ts +12 -20
  65. package/dist/resource_clients/log.js +93 -58
  66. package/dist/resource_clients/request_queue.d.ts +56 -26
  67. package/dist/resource_clients/request_queue.js +176 -103
  68. package/dist/resource_clients/request_queue_collection.d.ts +6 -2
  69. package/dist/resource_clients/request_queue_collection.js +9 -3
  70. package/dist/resource_clients/run.d.ts +108 -18
  71. package/dist/resource_clients/run.js +183 -43
  72. package/dist/resource_clients/run_collection.d.ts +3 -1
  73. package/dist/resource_clients/run_collection.js +4 -1
  74. package/dist/resource_clients/schedule.d.ts +14 -5
  75. package/dist/resource_clients/schedule.js +29 -21
  76. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  77. package/dist/resource_clients/schedule_collection.js +9 -3
  78. package/dist/resource_clients/store_collection.d.ts +3 -1
  79. package/dist/resource_clients/store_collection.js +4 -1
  80. package/dist/resource_clients/task.d.ts +33 -10
  81. package/dist/resource_clients/task.js +79 -46
  82. package/dist/resource_clients/task_collection.d.ts +6 -2
  83. package/dist/resource_clients/task_collection.js +9 -3
  84. package/dist/resource_clients/user.d.ts +17 -8
  85. package/dist/resource_clients/user.js +42 -38
  86. package/dist/resource_clients/webhook.d.ts +14 -5
  87. package/dist/resource_clients/webhook.js +30 -22
  88. package/dist/resource_clients/webhook_collection.d.ts +6 -2
  89. package/dist/resource_clients/webhook_collection.js +9 -3
  90. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  91. package/dist/resource_clients/webhook_dispatch.js +7 -2
  92. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  93. package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
  94. package/dist/runtime/node.d.ts +6 -0
  95. package/dist/runtime/node.js +49 -0
  96. package/dist/runtime/types.d.ts +52 -0
  97. package/dist/runtime/types.js +1 -0
  98. package/dist/runtime/web.d.ts +5 -0
  99. package/dist/runtime/web.js +18 -0
  100. package/dist/schemas.d.ts +1 -1
  101. package/dist/schemas.js +1 -1
  102. package/dist/statistics.d.ts +1 -6
  103. package/dist/statistics.js +2 -2
  104. package/dist/timeouts.d.ts +84 -0
  105. package/dist/timeouts.js +37 -0
  106. package/dist/timezones.d.ts +1 -1
  107. package/dist/utils.d.ts +81 -52
  108. package/dist/utils.js +201 -170
  109. package/dist/wait_for_resources.d.ts +8 -0
  110. package/dist/wait_for_resources.js +39 -0
  111. package/package.json +32 -29
  112. package/dist/http_client.d.ts +0 -88
  113. package/dist/http_client.js +0 -255
  114. package/dist/interceptors.d.ts +0 -19
  115. package/dist/interceptors.js +0 -105
@@ -2,7 +2,20 @@ import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
2
2
  import type { ApiClientSubResourceOptions } from '../base/api_client.js';
3
3
  import { ResourceClient } from '../base/resource_client.js';
4
4
  import type { Dataset, DatasetStatistics } from '../models.js';
5
+ import type { TimeoutOptions } from '../timeouts.js';
5
6
  import type { PaginatedIterator, PaginationOptions } from '../utils.js';
7
+ /**
8
+ * Supported formats for downloading dataset items.
9
+ */
10
+ export declare enum DownloadItemsFormat {
11
+ JSON = "json",
12
+ JSONL = "jsonl",
13
+ XML = "xml",
14
+ HTML = "html",
15
+ CSV = "csv",
16
+ XLSX = "xlsx",
17
+ RSS = "rss"
18
+ }
6
19
  export type { Dataset, DatasetStatistics, DatasetStats, FieldStatistics } from '../models.js';
7
20
  /**
8
21
  * Client for managing a specific Dataset.
@@ -34,6 +47,7 @@ export type { Dataset, DatasetStatistics, DatasetStats, FieldStatistics } from '
34
47
  * @see https://docs.apify.com/platform/storage/dataset
35
48
  */
36
49
  export declare class DatasetClient<Data extends Record<string | number, any> = Record<string | number, unknown>> extends ResourceClient {
50
+ #private;
37
51
  /**
38
52
  * @hidden
39
53
  */
@@ -41,24 +55,30 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
41
55
  /**
42
56
  * Gets the dataset object from the Apify API.
43
57
  *
58
+ * @param options - Request options
59
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
44
60
  * @returns The Dataset object, or `undefined` if it does not exist
45
61
  * @see https://docs.apify.com/api/v2/dataset-get
46
62
  */
47
- get(): Promise<Dataset | undefined>;
63
+ get(options?: TimeoutOptions): Promise<Dataset | undefined>;
48
64
  /**
49
65
  * Updates the dataset with specified fields.
50
66
  *
51
67
  * @param newFields - Fields to update in the dataset
68
+ * @param options - Request options
69
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
52
70
  * @returns The updated Dataset object
53
71
  * @see https://docs.apify.com/api/v2/dataset-put
54
72
  */
55
- update(newFields: DatasetClientUpdateOptions): Promise<Dataset>;
73
+ update(newFields: DatasetClientUpdateOptions, options?: TimeoutOptions): Promise<Dataset>;
56
74
  /**
57
75
  * Deletes the dataset.
58
76
  *
77
+ * @param options - Request options
78
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
59
79
  * @see https://docs.apify.com/api/v2/dataset-delete
60
80
  */
61
- delete(): Promise<void>;
81
+ delete(options?: TimeoutOptions): Promise<void>;
62
82
  /**
63
83
  * Lists items in the dataset.
64
84
  *
@@ -77,8 +97,9 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
77
97
  * @param options.skipEmpty - If `true`, skips empty items. Default is `false`.
78
98
  * @param options.skipHidden - If `true`, skips hidden fields (fields starting with `#`). Default is `false`.
79
99
  * @param options.flatten - Array of field names to flatten. Nested objects are converted to dot notation (e.g., `obj.field`).
80
- * @param options.unwind - Field name or array of field names to unwind. Each array value creates a separate item.
100
+ * @param options.unwind - Array of field names to unwind. Each array value creates a separate item.
81
101
  * @param options.view - Name of a predefined view to use for field selection.
102
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'long'`.
82
103
  * @returns A paginated list with `items`, `total` count, `offset`, `count`, and `limit`
83
104
  * @see https://docs.apify.com/api/v2/dataset-items-get
84
105
  *
@@ -121,6 +142,7 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
121
142
  * @param options.xmlRow - Name of the XML element for each item. Default is `'item'`.
122
143
  * @param options.fields - Array of field names to include in the export.
123
144
  * @param options.omit - Array of field names to exclude from the export.
145
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
124
146
  * @returns Buffer containing the serialized data in the specified format
125
147
  * @see https://docs.apify.com/api/v2/dataset-items-get
126
148
  *
@@ -144,17 +166,20 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
144
166
  * });
145
167
  * ```
146
168
  */
147
- downloadItems(format: DownloadItemsFormat, options?: DatasetClientDownloadItemsOptions): Promise<Buffer>;
169
+ downloadItems(format: `${DownloadItemsFormat}`, options?: DatasetClientDownloadItemsOptions): Promise<Buffer>;
148
170
  /**
149
171
  * Stores one or more items into the dataset.
150
172
  *
151
- * Items can be objects, strings, or arrays thereof. Each item will be stored as a separate
152
- * record in the dataset. Objects are automatically serialized to JSON. If you provide an array,
153
- * all items will be stored in order. This method is idempotent - calling it multiple times
154
- * with the same data will not create duplicates, but will append items each time.
173
+ * Each item will be stored as a separate record in the dataset. Objects are automatically
174
+ * serialized to JSON. If you provide an array, all items will be stored in order. This method
175
+ * is idempotent - calling it multiple times with the same data will not create duplicates, but
176
+ * will append items each time.
155
177
  *
156
- * @param items - A single item (object or string) or an array of items to store.
157
- * Objects are automatically stringified to JSON. Strings are stored as-is.
178
+ * @param items - A single item, an array of items, or a string that is the JSON serialization of
179
+ * either - the API only accepts an object or an array of objects, so a plain string
180
+ * is not a valid item on its own.
181
+ * @param options - Request options
182
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
158
183
  * @see https://docs.apify.com/api/v2/dataset-items-post
159
184
  *
160
185
  * @example
@@ -172,23 +197,22 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
172
197
  * { url: 'https://test.com', title: 'Test' },
173
198
  * { url: 'https://demo.com', title: 'Demo' }
174
199
  * ]);
175
- *
176
- * // Store string items
177
- * await client.dataset('my-dataset').pushItems(['item1', 'item2', 'item3']);
178
200
  * ```
179
201
  */
180
- pushItems(items: Data | Data[] | string | string[]): Promise<void>;
202
+ pushItems(items: Data | Data[] | string, options?: TimeoutOptions): Promise<void>;
181
203
  /**
182
204
  * Gets statistical information about the dataset.
183
205
  *
184
206
  * Returns statistics for each field in the dataset, including information about
185
207
  * data types, null counts, and value ranges.
186
208
  *
187
- * @returns Dataset statistics, or `undefined` if not available
209
+ * @param options - Request options
210
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
211
+ * @returns Dataset statistics
188
212
  * @see https://docs.apify.com/api/v2/dataset-statistics-get
189
213
  * @since Added in 2.11.2
190
214
  */
191
- getStatistics(): Promise<DatasetStatistics | undefined>;
215
+ getStatistics(options?: TimeoutOptions): Promise<DatasetStatistics>;
192
216
  /**
193
217
  * Generates a public URL for accessing dataset items.
194
218
  *
@@ -199,8 +223,10 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
199
223
  * @param options - URL generation options (extends all options from {@link listItems})
200
224
  * @param options.expiresInSecs - Number of seconds until the signed URL expires. If omitted, the URL never expires.
201
225
  * @param options.fields - Array of field names to include in the response.
226
+ * @param options.format - Format of the items served by the URL. Defaults to `json`.
202
227
  * @param options.limit - Maximum number of items to return.
203
228
  * @param options.offset - Number of items to skip.
229
+ * @param options.timeoutSecs - Timeout for the API request that fetches the dataset. Default is `'long'`.
204
230
  * @returns A public URL string for accessing the dataset items
205
231
  *
206
232
  * @example
@@ -222,7 +248,6 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
222
248
  * @since Added in 2.13.0
223
249
  */
224
250
  createItemsPublicUrl(options?: DatasetClientCreateItemsUrlOptions): Promise<string>;
225
- private _createPaginationList;
226
251
  }
227
252
  /**
228
253
  * Options for updating a dataset.
@@ -244,7 +269,7 @@ export interface DatasetClientUpdateOptions {
244
269
  * Provides various filtering, pagination, and transformation options to customize
245
270
  * the output format and content of retrieved items.
246
271
  */
247
- export interface DatasetClientListItemOptions extends PaginationOptions {
272
+ export interface DatasetClientListItemOptions extends PaginationOptions, TimeoutOptions {
248
273
  clean?: boolean;
249
274
  desc?: boolean;
250
275
  /**
@@ -255,7 +280,7 @@ export interface DatasetClientListItemOptions extends PaginationOptions {
255
280
  omit?: string[];
256
281
  skipEmpty?: boolean;
257
282
  skipHidden?: boolean;
258
- unwind?: string | string[];
283
+ unwind?: string[];
259
284
  /**
260
285
  * @since Added in 2.2.0
261
286
  */
@@ -268,25 +293,18 @@ export interface DatasetClientListItemOptions extends PaginationOptions {
268
293
  /**
269
294
  * Options for creating a public URL to access dataset items.
270
295
  *
271
- * Extends {@link DatasetClientListItemOptions} with URL expiration control, minus `chunkSize` (it only
296
+ * Extends {@link DatasetClientListItemOptions} with output format and URL expiration control, minus `chunkSize` (it only
272
297
  * sizes a client-side iteration) and `signature` (this method produces one).
273
298
  * @since Added in 2.16.0
274
299
  */
275
300
  export interface DatasetClientCreateItemsUrlOptions extends Omit<DatasetClientListItemOptions, 'chunkSize' | 'signature'> {
301
+ /**
302
+ * Format of the items served by the URL. Defaults to `json`.
303
+ * @since Added in 2.26.0
304
+ */
305
+ format?: `${DownloadItemsFormat}`;
276
306
  expiresInSecs?: number;
277
307
  }
278
- /**
279
- * Supported formats for downloading dataset items.
280
- */
281
- export declare enum DownloadItemsFormat {
282
- JSON = "json",
283
- JSONL = "jsonl",
284
- XML = "xml",
285
- HTML = "html",
286
- CSV = "csv",
287
- XLSX = "xlsx",
288
- RSS = "rss"
289
- }
290
308
  /**
291
309
  * Options for downloading dataset items in a specific format.
292
310
  *
@@ -1,8 +1,23 @@
1
1
  import { z } from 'zod';
2
2
  import { createStorageContentSignatureAsync } from '@apify/utilities';
3
- import { DEFAULT_TIMEOUT_MILLIS, MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS, } from '../base/resource_client.js';
3
+ import { ResourceClient } from '../base/resource_client.js';
4
4
  import * as schemas from '../schemas.js';
5
- import { anyObjectSchema, applyQueryParamsToUrl, cast, catchNotFoundOrThrow, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, } from '../utils.js';
5
+ import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
6
+ import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, SCANNED_COUNT, } from '../utils.js';
7
+ /**
8
+ * Supported formats for downloading dataset items.
9
+ */
10
+ export var DownloadItemsFormat;
11
+ (function (DownloadItemsFormat) {
12
+ DownloadItemsFormat["JSON"] = "json";
13
+ DownloadItemsFormat["JSONL"] = "jsonl";
14
+ DownloadItemsFormat["XML"] = "xml";
15
+ DownloadItemsFormat["HTML"] = "html";
16
+ DownloadItemsFormat["CSV"] = "csv";
17
+ DownloadItemsFormat["XLSX"] = "xlsx";
18
+ DownloadItemsFormat["RSS"] = "rss";
19
+ })(DownloadItemsFormat || (DownloadItemsFormat = {}));
20
+ const itemFormatSchema = z.enum(DownloadItemsFormat);
6
21
  // A predicate, not a `z.object()` arm, which would walk and copy every key of every pushed item.
7
22
  const itemSchema = z.custom(isNonArrayObject, 'Expected an object');
8
23
  const listItemsOptionsSchema = z.strictObject({
@@ -14,9 +29,10 @@ const listItemsOptionsSchema = z.strictObject({
14
29
  ...paginationOptionsShape,
15
30
  skipEmpty: z.boolean().optional(),
16
31
  skipHidden: z.boolean().optional(),
17
- unwind: z.union([z.string(), z.array(z.string())]).optional(),
32
+ unwind: z.array(z.string()).optional(),
18
33
  view: z.string().optional(),
19
34
  signature: z.string().optional(),
35
+ ...timeoutOptionsShape,
20
36
  });
21
37
  // Spells out `limit` / `offset` instead of spreading `paginationOptionsShape`: a download is one
22
38
  // request, so `chunkSize` has nothing to size. The options type omits it to match.
@@ -34,28 +50,32 @@ const downloadItemsOptionsSchema = z.strictObject({
34
50
  skipEmpty: z.boolean().optional(),
35
51
  skipHeaderRow: z.boolean().optional(),
36
52
  skipHidden: z.boolean().optional(),
37
- unwind: z.union([z.string(), z.array(z.string())]).optional(),
53
+ unwind: z.array(z.string()).optional(),
38
54
  view: z.string().optional(),
39
55
  xmlRoot: z.string().optional(),
40
56
  xmlRow: z.string().optional(),
41
57
  signature: z.string().optional(),
58
+ ...timeoutOptionsShape,
42
59
  });
43
- const pushItemsSchema = z.union([itemSchema, z.string(), z.array(z.union([itemSchema, z.string()]))]);
44
- // Every option becomes a query parameter of the generated URL, so `chunkSize` (client-side only) and
45
- // `signature` (which this method produces) are left out. The options type omits both to match.
60
+ const pushItemsSchema = z.union([itemSchema, z.string(), z.array(itemSchema)]);
61
+ // Apart from `timeoutSecs`, `signal` and `expiresInSecs`, every option becomes a query parameter of the generated
62
+ // URL, so `chunkSize` (client-side only) and `signature` (which this method produces) are left out. The options type
63
+ // omits both to match.
46
64
  const createItemsPublicUrlOptionsSchema = z.strictObject({
47
65
  clean: z.boolean().optional(),
48
66
  desc: z.boolean().optional(),
49
67
  flatten: z.array(z.string()).optional(),
50
68
  fields: z.array(z.string()).optional(),
69
+ format: itemFormatSchema.optional(),
51
70
  omit: z.array(z.string()).optional(),
52
71
  limit: z.number().min(0).optional(),
53
72
  offset: z.number().min(0).optional(),
54
73
  skipEmpty: z.boolean().optional(),
55
74
  skipHidden: z.boolean().optional(),
56
- unwind: z.union([z.string(), z.array(z.string())]).optional(),
75
+ unwind: z.array(z.string()).optional(),
57
76
  view: z.string().optional(),
58
77
  expiresInSecs: z.number().optional(),
78
+ ...timeoutOptionsShape,
59
79
  });
60
80
  /**
61
81
  * Client for managing a specific Dataset.
@@ -99,30 +119,39 @@ export class DatasetClient extends ResourceClient {
99
119
  /**
100
120
  * Gets the dataset object from the Apify API.
101
121
  *
122
+ * @param options - Request options
123
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
102
124
  * @returns The Dataset object, or `undefined` if it does not exist
103
125
  * @see https://docs.apify.com/api/v2/dataset-get
104
126
  */
105
- async get() {
106
- return this._get(schemas.Dataset(), {}, SMALL_TIMEOUT_MILLIS);
127
+ async get(options = {}) {
128
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
129
+ return this.getResource(schemas.Dataset(), {}, timeoutSecs, signal);
107
130
  }
108
131
  /**
109
132
  * Updates the dataset with specified fields.
110
133
  *
111
134
  * @param newFields - Fields to update in the dataset
135
+ * @param options - Request options
136
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
112
137
  * @returns The updated Dataset object
113
138
  * @see https://docs.apify.com/api/v2/dataset-put
114
139
  */
115
- async update(newFields) {
140
+ async update(newFields, options = {}) {
116
141
  parseArgument(newFields, anyObjectSchema);
117
- return this._update(schemas.Dataset(), newFields, SMALL_TIMEOUT_MILLIS);
142
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
143
+ return this.updateResource(schemas.Dataset(), newFields, timeoutSecs, signal);
118
144
  }
119
145
  /**
120
146
  * Deletes the dataset.
121
147
  *
148
+ * @param options - Request options
149
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
122
150
  * @see https://docs.apify.com/api/v2/dataset-delete
123
151
  */
124
- async delete() {
125
- return this._delete(SMALL_TIMEOUT_MILLIS);
152
+ async delete(options = {}) {
153
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
154
+ return this.deleteResource(timeoutSecs, signal);
126
155
  }
127
156
  /**
128
157
  * Lists items in the dataset.
@@ -142,8 +171,9 @@ export class DatasetClient extends ResourceClient {
142
171
  * @param options.skipEmpty - If `true`, skips empty items. Default is `false`.
143
172
  * @param options.skipHidden - If `true`, skips hidden fields (fields starting with `#`). Default is `false`.
144
173
  * @param options.flatten - Array of field names to flatten. Nested objects are converted to dot notation (e.g., `obj.field`).
145
- * @param options.unwind - Field name or array of field names to unwind. Each array value creates a separate item.
174
+ * @param options.unwind - Array of field names to unwind. Each array value creates a separate item.
146
175
  * @param options.view - Name of a predefined view to use for field selection.
176
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'long'`.
147
177
  * @returns A paginated list with `items`, `total` count, `offset`, `count`, and `limit`
148
178
  * @see https://docs.apify.com/api/v2/dataset-items-get
149
179
  *
@@ -169,17 +199,18 @@ export class DatasetClient extends ResourceClient {
169
199
  * ```
170
200
  */
171
201
  listItems(options = {}) {
172
- const parsed = parseArgument(options, listItemsOptionsSchema, 'DatasetClientListItemOptions');
202
+ const { timeoutSecs = 'long', signal, ...listOptions } = parseArgument(options, listItemsOptionsSchema, 'DatasetClientListItemOptions');
173
203
  const fetchItems = async (datasetListOptions = {}) => {
174
204
  const response = await this.httpClient.call({
175
- url: this._url('items'),
205
+ url: this.buildUrl('items'),
176
206
  method: 'GET',
177
- params: this._params(datasetListOptions),
178
- timeout: DEFAULT_TIMEOUT_MILLIS,
207
+ params: this.buildParams(datasetListOptions),
208
+ timeoutSecs,
209
+ signal,
179
210
  });
180
- return this._createPaginationList(response, datasetListOptions.desc ?? false);
211
+ return this.#createPaginationList(response, datasetListOptions.desc ?? false);
181
212
  };
182
- return this._listPaginatedFromCallback(fetchItems, parsed);
213
+ return this.listPaginatedFromCallback(fetchItems, listOptions);
183
214
  }
184
215
  /**
185
216
  * Downloads dataset items in a specific format.
@@ -198,6 +229,7 @@ export class DatasetClient extends ResourceClient {
198
229
  * @param options.xmlRow - Name of the XML element for each item. Default is `'item'`.
199
230
  * @param options.fields - Array of field names to include in the export.
200
231
  * @param options.omit - Array of field names to exclude from the export.
232
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
201
233
  * @returns Buffer containing the serialized data in the specified format
202
234
  * @see https://docs.apify.com/api/v2/dataset-items-get
203
235
  *
@@ -223,29 +255,33 @@ export class DatasetClient extends ResourceClient {
223
255
  */
224
256
  async downloadItems(format, options = {}) {
225
257
  parseArgument(format, itemFormatSchema);
226
- const parsed = parseArgument(options, downloadItemsOptionsSchema, 'DatasetClientDownloadItemsOptions');
258
+ const { timeoutSecs = 'long', signal, ...query } = parseArgument(options, downloadItemsOptionsSchema, 'DatasetClientDownloadItemsOptions');
227
259
  const { data } = await this.httpClient.call({
228
- url: this._url('items'),
260
+ url: this.buildUrl('items'),
229
261
  method: 'GET',
230
- params: this._params({
262
+ params: this.buildParams({
231
263
  format,
232
- ...parsed,
264
+ ...query,
233
265
  }),
234
- forceBuffer: true,
235
- timeout: DEFAULT_TIMEOUT_MILLIS,
266
+ responseType: 'buffer',
267
+ timeoutSecs,
268
+ signal,
236
269
  });
237
270
  return cast(data);
238
271
  }
239
272
  /**
240
273
  * Stores one or more items into the dataset.
241
274
  *
242
- * Items can be objects, strings, or arrays thereof. Each item will be stored as a separate
243
- * record in the dataset. Objects are automatically serialized to JSON. If you provide an array,
244
- * all items will be stored in order. This method is idempotent - calling it multiple times
245
- * with the same data will not create duplicates, but will append items each time.
275
+ * Each item will be stored as a separate record in the dataset. Objects are automatically
276
+ * serialized to JSON. If you provide an array, all items will be stored in order. This method
277
+ * is idempotent - calling it multiple times with the same data will not create duplicates, but
278
+ * will append items each time.
246
279
  *
247
- * @param items - A single item (object or string) or an array of items to store.
248
- * Objects are automatically stringified to JSON. Strings are stored as-is.
280
+ * @param items - A single item, an array of items, or a string that is the JSON serialization of
281
+ * either - the API only accepts an object or an array of objects, so a plain string
282
+ * is not a valid item on its own.
283
+ * @param options - Request options
284
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
249
285
  * @see https://docs.apify.com/api/v2/dataset-items-post
250
286
  *
251
287
  * @example
@@ -263,23 +299,22 @@ export class DatasetClient extends ResourceClient {
263
299
  * { url: 'https://test.com', title: 'Test' },
264
300
  * { url: 'https://demo.com', title: 'Demo' }
265
301
  * ]);
266
- *
267
- * // Store string items
268
- * await client.dataset('my-dataset').pushItems(['item1', 'item2', 'item3']);
269
302
  * ```
270
303
  */
271
- async pushItems(items) {
304
+ async pushItems(items, options = {}) {
272
305
  parseArgument(items, pushItemsSchema);
306
+ const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
273
307
  await this.httpClient.call({
274
- url: this._url('items'),
308
+ url: this.buildUrl('items'),
275
309
  method: 'POST',
276
310
  headers: {
277
311
  'content-type': 'application/json; charset=utf-8',
278
312
  },
279
313
  data: items,
280
- params: this._params(),
281
- doNotRetryTimeouts: true, // see timeout handling in http-client
282
- timeout: MEDIUM_TIMEOUT_MILLIS,
314
+ params: this.buildParams(),
315
+ doNotRetryTimeouts: true,
316
+ timeoutSecs,
317
+ signal,
283
318
  });
284
319
  }
285
320
  /**
@@ -288,25 +323,22 @@ export class DatasetClient extends ResourceClient {
288
323
  * Returns statistics for each field in the dataset, including information about
289
324
  * data types, null counts, and value ranges.
290
325
  *
291
- * @returns Dataset statistics, or `undefined` if not available
326
+ * @param options - Request options
327
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
328
+ * @returns Dataset statistics
292
329
  * @see https://docs.apify.com/api/v2/dataset-statistics-get
293
330
  * @since Added in 2.11.2
294
331
  */
295
- async getStatistics() {
296
- const requestOpts = {
297
- url: this._url('statistics'),
332
+ async getStatistics(options = {}) {
333
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
334
+ const response = await this.httpClient.call({
335
+ url: this.buildUrl('statistics'),
298
336
  method: 'GET',
299
- params: this._params(),
300
- timeout: SMALL_TIMEOUT_MILLIS,
301
- };
302
- try {
303
- const response = await this.httpClient.call(requestOpts);
304
- return parseResponse(response, schemas.DatasetStatistics());
305
- }
306
- catch (err) {
307
- catchNotFoundOrThrow(err);
308
- }
309
- return undefined;
337
+ params: this.buildParams(),
338
+ timeoutSecs,
339
+ signal,
340
+ });
341
+ return parseResponse(response, schemas.DatasetStatistics());
310
342
  }
311
343
  /**
312
344
  * Generates a public URL for accessing dataset items.
@@ -318,8 +350,10 @@ export class DatasetClient extends ResourceClient {
318
350
  * @param options - URL generation options (extends all options from {@link listItems})
319
351
  * @param options.expiresInSecs - Number of seconds until the signed URL expires. If omitted, the URL never expires.
320
352
  * @param options.fields - Array of field names to include in the response.
353
+ * @param options.format - Format of the items served by the URL. Defaults to `json`.
321
354
  * @param options.limit - Maximum number of items to return.
322
355
  * @param options.offset - Number of items to skip.
356
+ * @param options.timeoutSecs - Timeout for the API request that fetches the dataset. Default is `'long'`.
323
357
  * @returns A public URL string for accessing the dataset items
324
358
  *
325
359
  * @example
@@ -341,10 +375,9 @@ export class DatasetClient extends ResourceClient {
341
375
  * @since Added in 2.13.0
342
376
  */
343
377
  async createItemsPublicUrl(options = {}) {
344
- const parsed = parseArgument(options, createItemsPublicUrlOptionsSchema, 'DatasetClientCreateItemsUrlOptions');
345
- const dataset = await this.get();
346
- const { expiresInSecs, ...queryOptions } = parsed;
347
- let createdItemsPublicUrl = new URL(this._publicUrl('items'));
378
+ const { timeoutSecs = 'long', signal, expiresInSecs, ...queryOptions } = parseArgument(options, createItemsPublicUrlOptionsSchema, 'DatasetClientCreateItemsUrlOptions');
379
+ const dataset = await this.get({ timeoutSecs, signal });
380
+ let createdItemsPublicUrl = new URL(this.buildPublicUrl('items'));
348
381
  if (dataset?.urlSigningSecretKey) {
349
382
  const signature = await createStorageContentSignatureAsync({
350
383
  resourceId: dataset.id,
@@ -356,31 +389,23 @@ export class DatasetClient extends ResourceClient {
356
389
  createdItemsPublicUrl = applyQueryParamsToUrl(createdItemsPublicUrl, queryOptions);
357
390
  return createdItemsPublicUrl.toString();
358
391
  }
359
- _createPaginationList(response, userProvidedDesc) {
360
- return {
392
+ #createPaginationList(response, userProvidedDesc) {
393
+ const descHeader = response.headers['x-apify-pagination-desc'];
394
+ const page = {
361
395
  items: response.data,
362
396
  total: Number(response.headers['x-apify-pagination-total']),
363
397
  offset: Number(response.headers['x-apify-pagination-offset']),
364
- count: response.data.length, // because x-apify-pagination-count returns invalid values when hidden/empty items are skipped
398
+ // `x-apify-pagination-count` reports the rows scanned, which filters and `unwind` can leave above or below
399
+ // the items returned.
400
+ count: response.data.length,
365
401
  limit: Number(response.headers['x-apify-pagination-limit']), // API returns 999999999999 when no limit is used
366
402
  // TODO: Replace this once https://github.com/apify/apify-core/issues/3503 is solved
367
- desc: JSON.parse(response.headers['x-apify-pagination-desc'] ?? userProvidedDesc),
403
+ desc: typeof descHeader === 'string' ? JSON.parse(descHeader) : userProvidedDesc,
368
404
  };
405
+ const scannedCount = response.headers['x-apify-pagination-count'];
406
+ if (scannedCount === undefined)
407
+ return page;
408
+ // The offset iterator paginates by the scanned number, so it travels with the page outside its public shape.
409
+ return Object.defineProperty(page, SCANNED_COUNT, { value: Number(scannedCount) });
369
410
  }
370
411
  }
371
- /**
372
- * Supported formats for downloading dataset items.
373
- */
374
- export var DownloadItemsFormat;
375
- (function (DownloadItemsFormat) {
376
- DownloadItemsFormat["JSON"] = "json";
377
- DownloadItemsFormat["JSONL"] = "jsonl";
378
- DownloadItemsFormat["XML"] = "xml";
379
- DownloadItemsFormat["HTML"] = "html";
380
- DownloadItemsFormat["CSV"] = "csv";
381
- DownloadItemsFormat["XLSX"] = "xlsx";
382
- DownloadItemsFormat["RSS"] = "rss";
383
- })(DownloadItemsFormat || (DownloadItemsFormat = {}));
384
- const validItemFormats = [...new Set(Object.values(DownloadItemsFormat).map((item) => item.toLowerCase()))];
385
- // Declared below `validItemFormats` because it references it at module load time.
386
- const itemFormatSchema = z.enum(validItemFormats);
@@ -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 { Dataset } from './dataset.js';
6
7
  /**
@@ -45,6 +46,7 @@ export declare class DatasetCollectionClient extends ResourceCollectionClient {
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 Datasets.
49
51
  * @see https://docs.apify.com/api/v2/datasets-get
50
52
  */
@@ -54,12 +56,14 @@ export declare class DatasetCollectionClient extends ResourceCollectionClient {
54
56
  *
55
57
  * @param name - Name of the dataset. If not provided, a default dataset is used.
56
58
  * @param options - Additional options like schema.
59
+ * @param options.schema - Schema of the dataset.
60
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
57
61
  * @returns The dataset object.
58
62
  * @see https://docs.apify.com/api/v2/datasets-post
59
63
  */
60
64
  getOrCreate(name?: string, options?: DatasetCollectionClientGetOrCreateOptions): Promise<Dataset>;
61
65
  }
62
- export interface DatasetCollectionClientListOptions extends PaginationOptions {
66
+ export interface DatasetCollectionClientListOptions extends PaginationOptions, TimeoutOptions {
63
67
  unnamed?: boolean;
64
68
  desc?: boolean;
65
69
  /**
@@ -71,7 +75,7 @@ export interface DatasetCollectionClientListOptions extends PaginationOptions {
71
75
  /**
72
76
  * @since Added in 2.3.0
73
77
  */
74
- export interface DatasetCollectionClientGetOrCreateOptions {
78
+ export interface DatasetCollectionClientGetOrCreateOptions extends TimeoutOptions {
75
79
  schema?: Record<string, unknown>;
76
80
  }
77
81
  export type DatasetCollectionClientListResult = PaginatedList<Dataset> & {
@@ -2,12 +2,14 @@ import { z } from 'zod';
2
2
  import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
3
3
  import { ResourceCollectionClient } from '../base/resource_collection_client.js';
4
4
  import * as schemas from '../schemas.js';
5
+ import { optionalSignalSchema, optionalTimeoutSchema, timeoutOptionsShape } from '../timeouts.js';
5
6
  import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
6
7
  const listOptionsSchema = z.strictObject({
7
8
  unnamed: z.boolean().optional(),
8
9
  ...paginationOptionsShape,
9
10
  desc: z.boolean().optional(),
10
11
  ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
12
+ ...timeoutOptionsShape,
11
13
  });
12
14
  const nameSchema = z.string().optional();
13
15
  const schemaSchema = anyObjectSchema.optional();
@@ -58,24 +60,33 @@ export class DatasetCollectionClient extends ResourceCollectionClient {
58
60
  * ```
59
61
  *
60
62
  * @param options - Pagination options.
63
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
61
64
  * @returns A paginated iterator of Datasets.
62
65
  * @see https://docs.apify.com/api/v2/datasets-get
63
66
  */
64
67
  list(options = {}) {
65
68
  const parsed = parseArgument(options, listOptionsSchema, 'DatasetCollectionClientListOptions');
66
- return this._listPaginated(schemas.ListOfDatasets(), parsed);
69
+ return this.listResourcesPaginated(schemas.ListOfDatasets(), parsed, 'medium');
67
70
  }
68
71
  /**
69
72
  * Gets or creates a dataset with the specified name.
70
73
  *
71
74
  * @param name - Name of the dataset. If not provided, a default dataset is used.
72
75
  * @param options - Additional options like schema.
76
+ * @param options.schema - Schema of the dataset.
77
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
73
78
  * @returns The dataset object.
74
79
  * @see https://docs.apify.com/api/v2/datasets-post
75
80
  */
76
81
  async getOrCreate(name, options) {
77
82
  parseArgument(name, nameSchema);
78
83
  parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
79
- return this._getOrCreate(schemas.Dataset(), name, options);
84
+ parseArgument(options?.timeoutSecs, optionalTimeoutSchema);
85
+ parseArgument(options?.signal, optionalSignalSchema);
86
+ // `timeoutSecs` and `signal` are not part of the resource, so the body carries only the rest, and stays
87
+ // absent when there is nothing else to send.
88
+ const { timeoutSecs = 'short', signal, ...resource } = options ?? {};
89
+ const hasResource = Object.keys(resource).length > 0;
90
+ return this.getOrCreateResource(schemas.Dataset(), name, hasResource ? resource : undefined, timeoutSecs, signal);
80
91
  }
81
92
  }