apify-client 3.0.0-beta.12 → 3.0.0-beta.121
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.
- package/README.md +23 -2
- package/dist/apify_api_error.d.ts +14 -28
- package/dist/apify_api_error.js +33 -23
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/axios.d.ts +2 -0
- package/dist/axios.js +1 -0
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +36 -36
- package/dist/base/resource_client.d.ts +13 -8
- package/dist/base/resource_client.js +60 -34
- package/dist/base/resource_collection_client.d.ts +12 -4
- package/dist/base/resource_collection_client.js +34 -11
- package/dist/body_parser.d.ts +4 -5
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +41 -35
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +3266 -1103
- package/dist/generated/schemas.d.ts +2608 -1079
- package/dist/generated/schemas.js +600 -239
- package/dist/http_clients/axios.d.ts +80 -0
- package/dist/http_clients/axios.js +165 -0
- package/dist/http_clients/base.d.ts +402 -0
- package/dist/http_clients/base.js +680 -0
- package/dist/http_clients/fetch.d.ts +53 -0
- package/dist/http_clients/fetch.js +219 -0
- package/dist/http_clients/index.d.ts +4 -0
- package/dist/http_clients/index.js +2 -0
- package/dist/http_compressors/base.d.ts +40 -0
- package/dist/http_compressors/base.js +9 -0
- package/dist/http_compressors/brotli.d.ts +33 -0
- package/dist/http_compressors/brotli.js +39 -0
- package/dist/http_compressors/gzip.d.ts +33 -0
- package/dist/http_compressors/gzip.js +39 -0
- package/dist/http_compressors/index.d.ts +8 -0
- package/dist/http_compressors/index.js +3 -0
- package/dist/http_compressors/resolve.d.ts +24 -0
- package/dist/http_compressors/resolve.js +30 -0
- package/dist/http_compressors/zstd.d.ts +34 -0
- package/dist/http_compressors/zstd.js +43 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +5 -1
- package/dist/invalid_response_body_error.d.ts +14 -0
- package/dist/invalid_response_body_error.js +18 -0
- package/dist/models.d.ts +177 -240
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +94 -23
- package/dist/resource_clients/actor.js +129 -43
- package/dist/resource_clients/actor_collection.d.ts +15 -11
- package/dist/resource_clients/actor_collection.js +9 -3
- package/dist/resource_clients/actor_env_var.d.ts +11 -4
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_server.d.ts +149 -0
- package/dist/resource_clients/actor_server.js +195 -0
- package/dist/resource_clients/actor_version.d.ts +19 -6
- package/dist/resource_clients/actor_version.js +19 -8
- package/dist/resource_clients/actor_version_collection.d.ts +10 -4
- package/dist/resource_clients/actor_version_collection.js +12 -4
- package/dist/resource_clients/build.d.ts +18 -7
- package/dist/resource_clients/build.js +33 -15
- package/dist/resource_clients/build_collection.d.ts +7 -5
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +83 -37
- package/dist/resource_clients/dataset.js +99 -109
- package/dist/resource_clients/dataset_collection.d.ts +10 -6
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +108 -33
- package/dist/resource_clients/key_value_store.js +134 -53
- package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +41 -25
- package/dist/resource_clients/log.js +142 -65
- package/dist/resource_clients/request_queue.d.ts +77 -31
- package/dist/resource_clients/request_queue.js +178 -93
- package/dist/resource_clients/request_queue_collection.d.ts +9 -5
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +119 -29
- package/dist/resource_clients/run.js +188 -49
- package/dist/resource_clients/run_collection.d.ts +5 -3
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +15 -6
- package/dist/resource_clients/schedule.js +25 -10
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +9 -3
- package/dist/resource_clients/store_collection.d.ts +10 -4
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +35 -12
- package/dist/resource_clients/task.js +75 -35
- package/dist/resource_clients/task_collection.d.ts +9 -5
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +16 -7
- package/dist/resource_clients/user.js +34 -16
- package/dist/resource_clients/webhook.d.ts +16 -7
- package/dist/resource_clients/webhook.js +25 -10
- package/dist/resource_clients/webhook_collection.d.ts +8 -4
- package/dist/resource_clients/webhook_collection.js +9 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +7 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
- package/dist/response_validation_error.d.ts +2 -1
- package/dist/response_validation_error.js +2 -1
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +111 -0
- package/dist/runtime/types.d.ts +82 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +60 -0
- package/dist/schemas.d.ts +372 -4
- package/dist/schemas.js +26 -4
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/utils.d.ts +115 -61
- package/dist/utils.js +220 -161
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +53 -38
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -255
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -105
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { createStorageContentSignatureAsync } from '@apify/utilities';
|
|
3
|
-
import {
|
|
3
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
4
4
|
import * as schemas from '../schemas.js';
|
|
5
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
5
6
|
import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, } 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.
|
|
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,33 @@ 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.
|
|
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
|
+
stream: z.boolean().optional(),
|
|
59
|
+
...timeoutOptionsShape,
|
|
42
60
|
});
|
|
43
|
-
const pushItemsSchema = z.union([itemSchema, z.string(), z.array(
|
|
44
|
-
//
|
|
45
|
-
// `signature` (which this method produces) are left out. The options type
|
|
61
|
+
const pushItemsSchema = z.union([itemSchema, z.string(), z.array(itemSchema)]);
|
|
62
|
+
// Apart from `timeoutSecs`, `signal` and `expiresInSecs`, every option becomes a query parameter of the generated
|
|
63
|
+
// URL, so `chunkSize` (client-side only) and `signature` (which this method produces) are left out. The options type
|
|
64
|
+
// omits both to match.
|
|
46
65
|
const createItemsPublicUrlOptionsSchema = z.strictObject({
|
|
47
66
|
clean: z.boolean().optional(),
|
|
48
67
|
desc: z.boolean().optional(),
|
|
49
68
|
flatten: z.array(z.string()).optional(),
|
|
50
69
|
fields: z.array(z.string()).optional(),
|
|
70
|
+
format: itemFormatSchema.optional(),
|
|
51
71
|
omit: z.array(z.string()).optional(),
|
|
52
72
|
limit: z.number().min(0).optional(),
|
|
53
73
|
offset: z.number().min(0).optional(),
|
|
54
74
|
skipEmpty: z.boolean().optional(),
|
|
55
75
|
skipHidden: z.boolean().optional(),
|
|
56
|
-
unwind: z.
|
|
76
|
+
unwind: z.array(z.string()).optional(),
|
|
57
77
|
view: z.string().optional(),
|
|
58
|
-
expiresInSecs: z.number().optional(),
|
|
78
|
+
expiresInSecs: z.number().positive().optional(),
|
|
79
|
+
...timeoutOptionsShape,
|
|
59
80
|
});
|
|
60
81
|
/**
|
|
61
82
|
* Client for managing a specific Dataset.
|
|
@@ -99,30 +120,39 @@ export class DatasetClient extends ResourceClient {
|
|
|
99
120
|
/**
|
|
100
121
|
* Gets the dataset object from the Apify API.
|
|
101
122
|
*
|
|
123
|
+
* @param options - Request options
|
|
124
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
102
125
|
* @returns The Dataset object, or `undefined` if it does not exist
|
|
103
126
|
* @see https://docs.apify.com/api/v2/dataset-get
|
|
104
127
|
*/
|
|
105
|
-
async get() {
|
|
106
|
-
|
|
128
|
+
async get(options = {}) {
|
|
129
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
130
|
+
return this.getResource(schemas.DatasetResource(), {}, timeoutSecs, signal);
|
|
107
131
|
}
|
|
108
132
|
/**
|
|
109
133
|
* Updates the dataset with specified fields.
|
|
110
134
|
*
|
|
111
135
|
* @param newFields - Fields to update in the dataset
|
|
136
|
+
* @param options - Request options
|
|
137
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
112
138
|
* @returns The updated Dataset object
|
|
113
139
|
* @see https://docs.apify.com/api/v2/dataset-put
|
|
114
140
|
*/
|
|
115
|
-
async update(newFields) {
|
|
141
|
+
async update(newFields, options = {}) {
|
|
116
142
|
parseArgument(newFields, anyObjectSchema);
|
|
117
|
-
|
|
143
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
144
|
+
return this.updateResource(schemas.DatasetResource(), newFields, timeoutSecs, signal);
|
|
118
145
|
}
|
|
119
146
|
/**
|
|
120
147
|
* Deletes the dataset.
|
|
121
148
|
*
|
|
149
|
+
* @param options - Request options
|
|
150
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
122
151
|
* @see https://docs.apify.com/api/v2/dataset-delete
|
|
123
152
|
*/
|
|
124
|
-
async delete() {
|
|
125
|
-
|
|
153
|
+
async delete(options = {}) {
|
|
154
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
155
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
126
156
|
}
|
|
127
157
|
/**
|
|
128
158
|
* Lists items in the dataset.
|
|
@@ -134,6 +164,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
134
164
|
* @param options - Options for listing items
|
|
135
165
|
* @param options.limit - Maximum number of items to return. Default is all items.
|
|
136
166
|
* @param options.chunkSize - Maximum number of items returned in one API response. Relevant in the context of asyncIterator.
|
|
167
|
+
* Without it, iteration loads the whole dataset, or all `limit` items, in one response.
|
|
137
168
|
* @param options.offset - Number of items to skip from the beginning. Default is 0.
|
|
138
169
|
* @param options.desc - If `true`, items are returned in descending order (newest first). Default is `false`.
|
|
139
170
|
* @param options.fields - Array of field names to include in the results. Omits all other fields.
|
|
@@ -142,8 +173,9 @@ export class DatasetClient extends ResourceClient {
|
|
|
142
173
|
* @param options.skipEmpty - If `true`, skips empty items. Default is `false`.
|
|
143
174
|
* @param options.skipHidden - If `true`, skips hidden fields (fields starting with `#`). Default is `false`.
|
|
144
175
|
* @param options.flatten - Array of field names to flatten. Nested objects are converted to dot notation (e.g., `obj.field`).
|
|
145
|
-
* @param options.unwind -
|
|
176
|
+
* @param options.unwind - Array of field names to unwind. Each array value creates a separate item.
|
|
146
177
|
* @param options.view - Name of a predefined view to use for field selection.
|
|
178
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'long'`.
|
|
147
179
|
* @returns A paginated list with `items`, `total` count, `offset`, `count`, and `limit`
|
|
148
180
|
* @see https://docs.apify.com/api/v2/dataset-items-get
|
|
149
181
|
*
|
|
@@ -169,83 +201,48 @@ export class DatasetClient extends ResourceClient {
|
|
|
169
201
|
* ```
|
|
170
202
|
*/
|
|
171
203
|
listItems(options = {}) {
|
|
172
|
-
const
|
|
204
|
+
const { timeoutSecs = 'long', signal, ...listOptions } = parseArgument(options, listItemsOptionsSchema, 'DatasetClientListItemOptions');
|
|
173
205
|
const fetchItems = async (datasetListOptions = {}) => {
|
|
174
206
|
const response = await this.httpClient.call({
|
|
175
|
-
url: this.
|
|
207
|
+
url: this.buildUrl('items'),
|
|
176
208
|
method: 'GET',
|
|
177
|
-
params: this.
|
|
178
|
-
|
|
209
|
+
params: this.buildParams(datasetListOptions),
|
|
210
|
+
timeoutSecs,
|
|
211
|
+
signal,
|
|
179
212
|
});
|
|
180
|
-
return this
|
|
213
|
+
return this.#createPaginationList(response, datasetListOptions.desc ?? false);
|
|
181
214
|
};
|
|
182
|
-
return this.
|
|
215
|
+
return this.listPaginatedFromCallback(fetchItems, listOptions);
|
|
183
216
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Downloads dataset items in a specific format.
|
|
186
|
-
*
|
|
187
|
-
* Unlike {@link listItems} which returns a {@link PaginatedList} with an array of individual
|
|
188
|
-
* dataset items, this method returns the items serialized to the provided format
|
|
189
|
-
* (JSON, CSV, Excel, etc.) as a Buffer. Useful for exporting data for further processing.
|
|
190
|
-
*
|
|
191
|
-
* @param format - Output format: `'json'`, `'jsonl'`, `'csv'`, `'xlsx'`, `'xml'`, `'rss'`, or `'html'`
|
|
192
|
-
* @param options - Download and formatting options (extends all options from {@link listItems})
|
|
193
|
-
* @param options.attachment - If `true`, the response will have `Content-Disposition: attachment` header.
|
|
194
|
-
* @param options.bom - If `true`, adds UTF-8 BOM to the beginning of the file (useful for Excel compatibility).
|
|
195
|
-
* @param options.delimiter - CSV delimiter character. Default is `,` (comma).
|
|
196
|
-
* @param options.skipHeaderRow - If `true`, CSV export will not include the header row with field names.
|
|
197
|
-
* @param options.xmlRoot - Name of the root XML element. Default is `'items'`.
|
|
198
|
-
* @param options.xmlRow - Name of the XML element for each item. Default is `'item'`.
|
|
199
|
-
* @param options.fields - Array of field names to include in the export.
|
|
200
|
-
* @param options.omit - Array of field names to exclude from the export.
|
|
201
|
-
* @returns Buffer containing the serialized data in the specified format
|
|
202
|
-
* @see https://docs.apify.com/api/v2/dataset-items-get
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```javascript
|
|
206
|
-
* // Download as CSV with BOM for Excel compatibility
|
|
207
|
-
* const csvBuffer = await client.dataset('my-dataset').downloadItems('csv', { bom: true });
|
|
208
|
-
* require('fs').writeFileSync('output.csv', csvBuffer);
|
|
209
|
-
*
|
|
210
|
-
* // Download as Excel with custom options
|
|
211
|
-
* const xlsxBuffer = await client.dataset('my-dataset').downloadItems('xlsx', {
|
|
212
|
-
* fields: ['url', 'title', 'price'],
|
|
213
|
-
* skipEmpty: true,
|
|
214
|
-
* limit: 1000
|
|
215
|
-
* });
|
|
216
|
-
*
|
|
217
|
-
* // Download as XML with custom element names
|
|
218
|
-
* const xmlBuffer = await client.dataset('my-dataset').downloadItems('xml', {
|
|
219
|
-
* xmlRoot: 'products',
|
|
220
|
-
* xmlRow: 'product'
|
|
221
|
-
* });
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
217
|
async downloadItems(format, options = {}) {
|
|
225
218
|
parseArgument(format, itemFormatSchema);
|
|
226
|
-
const
|
|
219
|
+
const { timeoutSecs = 'long', signal, stream, ...query } = parseArgument(options, downloadItemsOptionsSchema, 'DatasetClientDownloadItemsOptions');
|
|
227
220
|
const { data } = await this.httpClient.call({
|
|
228
|
-
url: this.
|
|
221
|
+
url: this.buildUrl('items'),
|
|
229
222
|
method: 'GET',
|
|
230
|
-
params: this.
|
|
223
|
+
params: this.buildParams({
|
|
231
224
|
format,
|
|
232
|
-
...
|
|
225
|
+
...query,
|
|
233
226
|
}),
|
|
234
|
-
|
|
235
|
-
|
|
227
|
+
responseType: stream ? 'stream' : 'buffer',
|
|
228
|
+
timeoutSecs,
|
|
229
|
+
signal,
|
|
236
230
|
});
|
|
237
231
|
return cast(data);
|
|
238
232
|
}
|
|
239
233
|
/**
|
|
240
234
|
* Stores one or more items into the dataset.
|
|
241
235
|
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
236
|
+
* Each item will be stored as a separate record in the dataset. Objects are automatically
|
|
237
|
+
* serialized to JSON. If you provide an array, all items will be stored in order. This method
|
|
238
|
+
* is idempotent - calling it multiple times with the same data will not create duplicates, but
|
|
239
|
+
* will append items each time.
|
|
246
240
|
*
|
|
247
|
-
* @param items - A single item
|
|
248
|
-
*
|
|
241
|
+
* @param items - A single item, an array of items, or a string that is the JSON serialization of
|
|
242
|
+
* either - the API only accepts an object or an array of objects, so a plain string
|
|
243
|
+
* is not a valid item on its own.
|
|
244
|
+
* @param options - Request options
|
|
245
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
249
246
|
* @see https://docs.apify.com/api/v2/dataset-items-post
|
|
250
247
|
*
|
|
251
248
|
* @example
|
|
@@ -263,23 +260,22 @@ export class DatasetClient extends ResourceClient {
|
|
|
263
260
|
* { url: 'https://test.com', title: 'Test' },
|
|
264
261
|
* { url: 'https://demo.com', title: 'Demo' }
|
|
265
262
|
* ]);
|
|
266
|
-
*
|
|
267
|
-
* // Store string items
|
|
268
|
-
* await client.dataset('my-dataset').pushItems(['item1', 'item2', 'item3']);
|
|
269
263
|
* ```
|
|
270
264
|
*/
|
|
271
|
-
async pushItems(items) {
|
|
265
|
+
async pushItems(items, options = {}) {
|
|
272
266
|
parseArgument(items, pushItemsSchema);
|
|
267
|
+
const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
273
268
|
await this.httpClient.call({
|
|
274
|
-
url: this.
|
|
269
|
+
url: this.buildUrl('items'),
|
|
275
270
|
method: 'POST',
|
|
276
271
|
headers: {
|
|
277
272
|
'content-type': 'application/json; charset=utf-8',
|
|
278
273
|
},
|
|
279
274
|
data: items,
|
|
280
|
-
params: this.
|
|
281
|
-
doNotRetryTimeouts: true,
|
|
282
|
-
|
|
275
|
+
params: this.buildParams(),
|
|
276
|
+
doNotRetryTimeouts: true,
|
|
277
|
+
timeoutSecs,
|
|
278
|
+
signal,
|
|
283
279
|
});
|
|
284
280
|
}
|
|
285
281
|
/**
|
|
@@ -288,16 +284,20 @@ export class DatasetClient extends ResourceClient {
|
|
|
288
284
|
* Returns statistics for each field in the dataset, including information about
|
|
289
285
|
* data types, null counts, and value ranges.
|
|
290
286
|
*
|
|
287
|
+
* @param options - Request options
|
|
288
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
291
289
|
* @returns Dataset statistics
|
|
292
290
|
* @see https://docs.apify.com/api/v2/dataset-statistics-get
|
|
293
291
|
* @since Added in 2.11.2
|
|
294
292
|
*/
|
|
295
|
-
async getStatistics() {
|
|
293
|
+
async getStatistics(options = {}) {
|
|
294
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
296
295
|
const response = await this.httpClient.call({
|
|
297
|
-
url: this.
|
|
296
|
+
url: this.buildUrl('statistics'),
|
|
298
297
|
method: 'GET',
|
|
299
|
-
params: this.
|
|
300
|
-
|
|
298
|
+
params: this.buildParams(),
|
|
299
|
+
timeoutSecs,
|
|
300
|
+
signal,
|
|
301
301
|
});
|
|
302
302
|
return parseResponse(response, schemas.DatasetStatistics());
|
|
303
303
|
}
|
|
@@ -309,10 +309,13 @@ export class DatasetClient extends ResourceClient {
|
|
|
309
309
|
* This is useful for sharing dataset results with external services or users.
|
|
310
310
|
*
|
|
311
311
|
* @param options - URL generation options (extends all options from {@link listItems})
|
|
312
|
-
* @param options.expiresInSecs - Number of seconds until the signed URL expires. If omitted, the URL
|
|
312
|
+
* @param options.expiresInSecs - Number of seconds until the signed URL expires. Must be positive. If omitted, the URL
|
|
313
|
+
* never expires.
|
|
313
314
|
* @param options.fields - Array of field names to include in the response.
|
|
315
|
+
* @param options.format - Format of the items served by the URL. Defaults to `json`.
|
|
314
316
|
* @param options.limit - Maximum number of items to return.
|
|
315
317
|
* @param options.offset - Number of items to skip.
|
|
318
|
+
* @param options.timeoutSecs - Timeout for the API request that fetches the dataset. Default is `'long'`.
|
|
316
319
|
* @returns A public URL string for accessing the dataset items
|
|
317
320
|
*
|
|
318
321
|
* @example
|
|
@@ -334,10 +337,9 @@ export class DatasetClient extends ResourceClient {
|
|
|
334
337
|
* @since Added in 2.13.0
|
|
335
338
|
*/
|
|
336
339
|
async createItemsPublicUrl(options = {}) {
|
|
337
|
-
const
|
|
338
|
-
const dataset = await this.get();
|
|
339
|
-
|
|
340
|
-
let createdItemsPublicUrl = new URL(this._publicUrl('items'));
|
|
340
|
+
const { timeoutSecs = 'long', signal, expiresInSecs, ...queryOptions } = parseArgument(options, createItemsPublicUrlOptionsSchema, 'DatasetClientCreateItemsUrlOptions');
|
|
341
|
+
const dataset = await this.get({ timeoutSecs, signal });
|
|
342
|
+
let createdItemsPublicUrl = new URL(this.buildPublicUrl('items'));
|
|
341
343
|
if (dataset?.urlSigningSecretKey) {
|
|
342
344
|
const signature = await createStorageContentSignatureAsync({
|
|
343
345
|
resourceId: dataset.id,
|
|
@@ -349,31 +351,19 @@ export class DatasetClient extends ResourceClient {
|
|
|
349
351
|
createdItemsPublicUrl = applyQueryParamsToUrl(createdItemsPublicUrl, queryOptions);
|
|
350
352
|
return createdItemsPublicUrl.toString();
|
|
351
353
|
}
|
|
352
|
-
|
|
354
|
+
#createPaginationList(response, userProvidedDesc) {
|
|
355
|
+
const descHeader = response.headers['x-apify-pagination-desc'];
|
|
353
356
|
return {
|
|
354
357
|
items: response.data,
|
|
355
358
|
total: Number(response.headers['x-apify-pagination-total']),
|
|
356
359
|
offset: Number(response.headers['x-apify-pagination-offset']),
|
|
357
|
-
|
|
360
|
+
// `x-apify-pagination-count` reports the rows scanned, which filters and `unwind` can leave above or below
|
|
361
|
+
// the items returned. It is derived from the dataset's item count, which lags a fresh push, so it can also
|
|
362
|
+
// fall below the items returned on an unfiltered page.
|
|
363
|
+
count: Math.max(Number(response.headers['x-apify-pagination-count'] ?? 0), response.data.length),
|
|
358
364
|
limit: Number(response.headers['x-apify-pagination-limit']), // API returns 999999999999 when no limit is used
|
|
359
365
|
// TODO: Replace this once https://github.com/apify/apify-core/issues/3503 is solved
|
|
360
|
-
desc: JSON.parse(
|
|
366
|
+
desc: typeof descHeader === 'string' ? JSON.parse(descHeader) : userProvidedDesc,
|
|
361
367
|
};
|
|
362
368
|
}
|
|
363
369
|
}
|
|
364
|
-
/**
|
|
365
|
-
* Supported formats for downloading dataset items.
|
|
366
|
-
*/
|
|
367
|
-
export var DownloadItemsFormat;
|
|
368
|
-
(function (DownloadItemsFormat) {
|
|
369
|
-
DownloadItemsFormat["JSON"] = "json";
|
|
370
|
-
DownloadItemsFormat["JSONL"] = "jsonl";
|
|
371
|
-
DownloadItemsFormat["XML"] = "xml";
|
|
372
|
-
DownloadItemsFormat["HTML"] = "html";
|
|
373
|
-
DownloadItemsFormat["CSV"] = "csv";
|
|
374
|
-
DownloadItemsFormat["XLSX"] = "xlsx";
|
|
375
|
-
DownloadItemsFormat["RSS"] = "rss";
|
|
376
|
-
})(DownloadItemsFormat || (DownloadItemsFormat = {}));
|
|
377
|
-
const validItemFormats = [...new Set(Object.values(DownloadItemsFormat).map((item) => item.toLowerCase()))];
|
|
378
|
-
// Declared below `validItemFormats` because it references it at module load time.
|
|
379
|
-
const itemFormatSchema = z.enum(validItemFormats);
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
-
import type {
|
|
6
|
+
import type { DatasetResource } from './dataset.js';
|
|
6
7
|
/**
|
|
7
8
|
* Client for managing the collection of datasets in your account.
|
|
8
9
|
*
|
|
@@ -45,21 +46,24 @@ 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
|
*/
|
|
51
|
-
list(options?: DatasetCollectionClientListOptions): Promise<DatasetCollectionClientListResult> & AsyncIterable<
|
|
53
|
+
list(options?: DatasetCollectionClientListOptions): Promise<DatasetCollectionClientListResult> & AsyncIterable<DatasetResource>;
|
|
52
54
|
/**
|
|
53
55
|
* Gets or creates a dataset with the specified name.
|
|
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
|
-
getOrCreate(name?: string, options?: DatasetCollectionClientGetOrCreateOptions): Promise<
|
|
64
|
+
getOrCreate(name?: string, options?: DatasetCollectionClientGetOrCreateOptions): Promise<DatasetResource>;
|
|
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,9 +75,9 @@ 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
|
-
export type DatasetCollectionClientListResult = PaginatedList<
|
|
81
|
+
export type DatasetCollectionClientListResult = PaginatedList<DatasetResource> & {
|
|
78
82
|
unnamed: boolean;
|
|
79
83
|
};
|
|
@@ -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.
|
|
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
|
-
|
|
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.DatasetResource(), name, hasResource ? resource : undefined, timeoutSecs, signal);
|
|
80
91
|
}
|
|
81
92
|
}
|