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.
- package/README.md +3 -1
- package/dist/apify_api_error.d.ts +60 -19
- package/dist/apify_api_error.js +88 -21
- package/dist/apify_client.d.ts +22 -3
- package/dist/apify_client.js +35 -29
- package/dist/base/api_client.d.ts +6 -6
- package/dist/base/api_client.js +24 -16
- package/dist/base/resource_client.d.ts +23 -9
- package/dist/base/resource_client.js +49 -25
- package/dist/base/resource_collection_client.d.ts +7 -4
- package/dist/base/resource_collection_client.js +21 -15
- package/dist/bundle.js +38 -48
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/http_client.d.ts +18 -51
- package/dist/http_client.js +79 -42
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/interceptors.js +22 -4
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +32 -52
- package/dist/resource_clients/actor.d.ts +46 -31
- package/dist/resource_clients/actor.js +71 -53
- package/dist/resource_clients/actor_collection.d.ts +9 -5
- package/dist/resource_clients/actor_collection.js +12 -3
- package/dist/resource_clients/actor_env_var.d.ts +10 -3
- package/dist/resource_clients/actor_env_var.js +17 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
- package/dist/resource_clients/actor_env_var_collection.js +18 -11
- package/dist/resource_clients/actor_version.d.ts +18 -3
- package/dist/resource_clients/actor_version.js +20 -9
- package/dist/resource_clients/actor_version_collection.d.ts +16 -17
- package/dist/resource_clients/actor_version_collection.js +20 -11
- package/dist/resource_clients/build.d.ts +18 -6
- package/dist/resource_clients/build.js +35 -17
- package/dist/resource_clients/build_collection.d.ts +3 -1
- package/dist/resource_clients/build_collection.js +5 -1
- package/dist/resource_clients/dataset.d.ts +23 -9
- package/dist/resource_clients/dataset.js +70 -48
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +48 -15
- package/dist/resource_clients/key_value_store.js +69 -39
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +9 -19
- package/dist/resource_clients/log.js +55 -44
- package/dist/resource_clients/request_queue.d.ts +56 -26
- package/dist/resource_clients/request_queue.js +178 -113
- package/dist/resource_clients/request_queue_collection.d.ts +6 -2
- package/dist/resource_clients/request_queue_collection.js +10 -3
- package/dist/resource_clients/run.d.ts +51 -17
- package/dist/resource_clients/run.js +83 -43
- package/dist/resource_clients/run_collection.d.ts +3 -1
- package/dist/resource_clients/run_collection.js +5 -1
- package/dist/resource_clients/schedule.d.ts +16 -7
- package/dist/resource_clients/schedule.js +31 -21
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +10 -3
- package/dist/resource_clients/store_collection.d.ts +3 -1
- package/dist/resource_clients/store_collection.js +5 -1
- package/dist/resource_clients/task.d.ts +28 -10
- package/dist/resource_clients/task.js +67 -44
- package/dist/resource_clients/task_collection.d.ts +6 -2
- package/dist/resource_clients/task_collection.js +10 -3
- package/dist/resource_clients/user.d.ts +17 -8
- package/dist/resource_clients/user.js +40 -39
- package/dist/resource_clients/webhook.d.ts +14 -5
- package/dist/resource_clients/webhook.js +30 -22
- package/dist/resource_clients/webhook_collection.d.ts +6 -2
- package/dist/resource_clients/webhook_collection.js +10 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +8 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
- package/dist/response_validation_error.d.ts +26 -0
- package/dist/response_validation_error.js +37 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.js +15 -0
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +57 -41
- package/dist/utils.js +155 -121
- package/package.json +36 -35
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -153
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
|
-
import type { JsonValue } from 'type-fest';
|
|
2
|
+
import type { JsonValue, TypedArray } from 'type-fest';
|
|
3
3
|
import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
|
|
4
4
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
5
5
|
import { ResourceClient } from '../base/resource_client.js';
|
|
6
6
|
import type { KeyValueClientListKeysResult, KeyValueListItem, KeyValueStore } from '../models.js';
|
|
7
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
7
8
|
export type { KeyValueClientListKeysResult, KeyValueListItem, KeyValueStore, KeyValueStoreStats } from '../models.js';
|
|
8
9
|
/**
|
|
9
10
|
* Client for managing a specific key-value store.
|
|
@@ -41,10 +42,12 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
41
42
|
/**
|
|
42
43
|
* Gets the key-value store object from the Apify API.
|
|
43
44
|
*
|
|
45
|
+
* @param options - Request options
|
|
46
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
44
47
|
* @returns The KeyValueStore object, or `undefined` if it does not exist
|
|
45
48
|
* @see https://docs.apify.com/api/v2/key-value-store-get
|
|
46
49
|
*/
|
|
47
|
-
get(): Promise<KeyValueStore | undefined>;
|
|
50
|
+
get(options?: TimeoutOptions): Promise<KeyValueStore | undefined>;
|
|
48
51
|
/**
|
|
49
52
|
* Updates the key-value store with specified fields.
|
|
50
53
|
*
|
|
@@ -52,16 +55,20 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
52
55
|
* @param newFields.name - New name for the store
|
|
53
56
|
* @param newFields.title - New title for the store
|
|
54
57
|
* @param newFields.generalAccess - General resource access level ('FOLLOW_USER_SETTING', 'ANYONE_WITH_ID_CAN_READ' or 'RESTRICTED')
|
|
58
|
+
* @param options - Request options
|
|
59
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
55
60
|
* @returns The updated KeyValueStore object
|
|
56
61
|
* @see https://docs.apify.com/api/v2/key-value-store-put
|
|
57
62
|
*/
|
|
58
|
-
update(newFields: KeyValueClientUpdateOptions): Promise<KeyValueStore>;
|
|
63
|
+
update(newFields: KeyValueClientUpdateOptions, options?: TimeoutOptions): Promise<KeyValueStore>;
|
|
59
64
|
/**
|
|
60
65
|
* Deletes the key-value store.
|
|
61
66
|
*
|
|
67
|
+
* @param options - Request options
|
|
68
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
62
69
|
* @see https://docs.apify.com/api/v2/key-value-store-delete
|
|
63
70
|
*/
|
|
64
|
-
delete(): Promise<void>;
|
|
71
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
65
72
|
/**
|
|
66
73
|
* Lists all keys in the key-value store.
|
|
67
74
|
*
|
|
@@ -73,6 +80,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
73
80
|
* @param options.exclusiveStartKey - Key to start listing from (for pagination). The listing starts with the next key after this one.
|
|
74
81
|
* @param options.collection - Filter keys by collection name.
|
|
75
82
|
* @param options.prefix - Filter keys that start with this prefix.
|
|
83
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
76
84
|
* @returns Object containing `items` array of key metadata, pagination info (`count`, `limit`, `isTruncated`, `nextExclusiveStartKey`)
|
|
77
85
|
* @see https://docs.apify.com/api/v2/key-value-store-keys-get
|
|
78
86
|
*
|
|
@@ -106,6 +114,8 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
106
114
|
* requiring an API token.
|
|
107
115
|
*
|
|
108
116
|
* @param key - The record key
|
|
117
|
+
* @param options - Request options
|
|
118
|
+
* @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
|
|
109
119
|
* @returns A public URL string for accessing the record
|
|
110
120
|
*
|
|
111
121
|
* @example
|
|
@@ -116,7 +126,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
116
126
|
* ```
|
|
117
127
|
* @since Added in 2.14.0
|
|
118
128
|
*/
|
|
119
|
-
getRecordPublicUrl(key: string): Promise<string>;
|
|
129
|
+
getRecordPublicUrl(key: string, options?: TimeoutOptions): Promise<string>;
|
|
120
130
|
/**
|
|
121
131
|
* Generates a public URL for accessing the list of keys in the key-value store.
|
|
122
132
|
*
|
|
@@ -127,6 +137,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
127
137
|
* @param options.expiresInSecs - Number of seconds until the signed URL expires. If omitted, the URL never expires.
|
|
128
138
|
* @param options.limit - Maximum number of keys to return.
|
|
129
139
|
* @param options.prefix - Filter keys by prefix.
|
|
140
|
+
* @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
|
|
130
141
|
* @returns A public URL string for accessing the keys list
|
|
131
142
|
*
|
|
132
143
|
* @example
|
|
@@ -147,6 +158,8 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
147
158
|
* This is more efficient than {@link getRecord} when you only need to check for existence.
|
|
148
159
|
*
|
|
149
160
|
* @param key - The record key to check
|
|
161
|
+
* @param options - Request options
|
|
162
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
150
163
|
* @returns `true` if the record exists, `false` if it does not
|
|
151
164
|
* @see https://docs.apify.com/api/v2/key-value-store-record-get
|
|
152
165
|
*
|
|
@@ -159,7 +172,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
159
172
|
* ```
|
|
160
173
|
* @since Added in 2.9.0
|
|
161
174
|
*/
|
|
162
|
-
recordExists(key: string): Promise<boolean>;
|
|
175
|
+
recordExists(key: string, options?: TimeoutOptions): Promise<boolean>;
|
|
163
176
|
/**
|
|
164
177
|
* You can use the `buffer` option to get the value in a Buffer (Node.js)
|
|
165
178
|
* or ArrayBuffer (browser) format. In Node.js (not in browser) you can also
|
|
@@ -168,6 +181,12 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
168
181
|
* When the record does not exist, the function resolves to `undefined`. It does
|
|
169
182
|
* NOT resolve to a `KeyValueStore` record with an `undefined` value.
|
|
170
183
|
*
|
|
184
|
+
* @param key - The record key
|
|
185
|
+
* @param options - Retrieval options
|
|
186
|
+
* @param options.buffer - If `true`, the value is returned as a Buffer (Node.js) or ArrayBuffer (browser).
|
|
187
|
+
* @param options.stream - If `true`, the value is returned as a Readable stream. Node.js only.
|
|
188
|
+
* @param options.signature - Signature of a public URL, for reading a record without a token.
|
|
189
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
171
190
|
* @see https://docs.apify.com/api/v2/key-value-store-record-get
|
|
172
191
|
*/
|
|
173
192
|
getRecord(key: string): Promise<KeyValueStoreRecord<JsonValue> | undefined>;
|
|
@@ -185,13 +204,18 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
185
204
|
*
|
|
186
205
|
* @param record - The record to store
|
|
187
206
|
* @param record.key - Record key (unique identifier)
|
|
188
|
-
* @param record.value - Record value (
|
|
207
|
+
* @param record.value - Record value (a JSON-serializable value, Buffer, ArrayBuffer, typed array, or Readable)
|
|
189
208
|
* @param record.contentType - Optional MIME type. Auto-detected if not provided:
|
|
190
209
|
* - Objects: `'application/json; charset=utf-8'`
|
|
191
210
|
* - Strings: `'text/plain; charset=utf-8'`
|
|
192
|
-
* -
|
|
211
|
+
* - Binary values and streams: `'application/octet-stream'`
|
|
212
|
+
*
|
|
213
|
+
* Worth setting for media and archives: the client skips compressing a body
|
|
214
|
+
* whose content type already carries its own compression. The
|
|
215
|
+
* `'application/octet-stream'` fallback is treated as compressible, because
|
|
216
|
+
* it could hold any binary data.
|
|
193
217
|
* @param options - Storage options
|
|
194
|
-
* @param options.timeoutSecs - Timeout for the
|
|
218
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
195
219
|
* @param options.doNotRetryTimeouts - If `true`, don't retry on timeout errors. Default is `false`.
|
|
196
220
|
* @see https://docs.apify.com/api/v2/key-value-store-record-put
|
|
197
221
|
*
|
|
@@ -219,11 +243,13 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
219
243
|
* });
|
|
220
244
|
* ```
|
|
221
245
|
*/
|
|
222
|
-
setRecord(record: KeyValueStoreRecord<
|
|
246
|
+
setRecord(record: KeyValueStoreRecord<KeyValueStoreRecordValue>, options?: KeyValueStoreRecordOptions): Promise<void>;
|
|
223
247
|
/**
|
|
224
248
|
* Deletes a record from the key-value store.
|
|
225
249
|
*
|
|
226
250
|
* @param key - The record key to delete
|
|
251
|
+
* @param options - Request options
|
|
252
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
227
253
|
* @see https://docs.apify.com/api/v2/key-value-store-record-delete
|
|
228
254
|
*
|
|
229
255
|
* @example
|
|
@@ -231,7 +257,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
231
257
|
* await client.keyValueStore('my-store').deleteRecord('temp-data');
|
|
232
258
|
* ```
|
|
233
259
|
*/
|
|
234
|
-
deleteRecord(key: string): Promise<void>;
|
|
260
|
+
deleteRecord(key: string, options?: TimeoutOptions): Promise<void>;
|
|
235
261
|
}
|
|
236
262
|
/**
|
|
237
263
|
* Options for updating a Key-Value Store.
|
|
@@ -250,7 +276,7 @@ export interface KeyValueClientUpdateOptions {
|
|
|
250
276
|
/**
|
|
251
277
|
* Options for listing keys in a Key-Value Store.
|
|
252
278
|
*/
|
|
253
|
-
export interface KeyValueClientListKeysOptions {
|
|
279
|
+
export interface KeyValueClientListKeysOptions extends TimeoutOptions {
|
|
254
280
|
limit?: number;
|
|
255
281
|
exclusiveStartKey?: string;
|
|
256
282
|
collection?: string;
|
|
@@ -276,7 +302,7 @@ export interface KeyValueClientCreateKeysUrlOptions extends Omit<KeyValueClientL
|
|
|
276
302
|
/**
|
|
277
303
|
* Options for retrieving a record from a Key-Value Store.
|
|
278
304
|
*/
|
|
279
|
-
export interface KeyValueClientGetRecordOptions {
|
|
305
|
+
export interface KeyValueClientGetRecordOptions extends TimeoutOptions {
|
|
280
306
|
buffer?: boolean;
|
|
281
307
|
stream?: boolean;
|
|
282
308
|
/**
|
|
@@ -284,6 +310,14 @@ export interface KeyValueClientGetRecordOptions {
|
|
|
284
310
|
*/
|
|
285
311
|
signature?: string;
|
|
286
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* A value that `setRecord` accepts.
|
|
315
|
+
*
|
|
316
|
+
* Anything JSON-serializable, or binary content the client uploads as bytes instead of JSON-encoding
|
|
317
|
+
* it: a `Buffer`, an `ArrayBuffer`, a typed array, or a readable stream. `Buffer` is a `Uint8Array`, so
|
|
318
|
+
* `TypedArray` covers it.
|
|
319
|
+
*/
|
|
320
|
+
export type KeyValueStoreRecordValue = JsonValue | ArrayBuffer | TypedArray | Readable;
|
|
287
321
|
/**
|
|
288
322
|
* Represents a record (key-value pair) in a Key-Value Store.
|
|
289
323
|
*
|
|
@@ -298,8 +332,7 @@ export interface KeyValueStoreRecord<T> {
|
|
|
298
332
|
* Options for storing a record in a Key-Value Store.
|
|
299
333
|
* @since Added in 2.12.4
|
|
300
334
|
*/
|
|
301
|
-
export interface KeyValueStoreRecordOptions {
|
|
302
|
-
timeoutSecs?: number;
|
|
335
|
+
export interface KeyValueStoreRecordOptions extends TimeoutOptions {
|
|
303
336
|
doNotRetryTimeouts?: boolean;
|
|
304
337
|
}
|
|
305
338
|
/**
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import log from '@apify/log';
|
|
3
3
|
import { createHmacSignatureAsync, createStorageContentSignatureAsync } from '@apify/utilities';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
5
|
+
import * as schemas from '../schemas.js';
|
|
6
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
7
|
+
import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isBuffer, isNode, isStream, parseArgument, parseResponse, } from '../utils.js';
|
|
6
8
|
const listKeysOptionsSchema = z.strictObject({
|
|
7
9
|
limit: z.number().min(0).optional(),
|
|
8
10
|
exclusiveStartKey: z.string().optional(),
|
|
9
11
|
collection: z.string().optional(),
|
|
10
12
|
prefix: z.string().optional(),
|
|
11
13
|
signature: z.string().optional(),
|
|
14
|
+
...timeoutOptionsShape,
|
|
12
15
|
});
|
|
13
16
|
const nonEmptyKeySchema = z.string().min(1);
|
|
14
17
|
// `signature` is left out - this method produces one. The options type omits it to match.
|
|
@@ -18,6 +21,7 @@ const createKeysPublicUrlOptionsSchema = z.strictObject({
|
|
|
18
21
|
collection: z.string().optional(),
|
|
19
22
|
prefix: z.string().optional(),
|
|
20
23
|
expiresInSecs: z.number().optional(),
|
|
24
|
+
...timeoutOptionsShape,
|
|
21
25
|
});
|
|
22
26
|
const keySchema = z.string();
|
|
23
27
|
const getRecordOptionsSchema = z.strictObject({
|
|
@@ -25,6 +29,7 @@ const getRecordOptionsSchema = z.strictObject({
|
|
|
25
29
|
stream: z.boolean().optional(),
|
|
26
30
|
disableRedirect: z.boolean().optional(),
|
|
27
31
|
signature: z.string().optional(),
|
|
32
|
+
...timeoutOptionsShape,
|
|
28
33
|
});
|
|
29
34
|
const recordSchema = z.strictObject({
|
|
30
35
|
key: z.string(),
|
|
@@ -36,11 +41,11 @@ const recordSchema = z.strictObject({
|
|
|
36
41
|
typeof value !== 'symbol' &&
|
|
37
42
|
typeof value !== 'bigint' &&
|
|
38
43
|
typeof value !== 'function' &&
|
|
39
|
-
(typeof value !== 'number' || Number.isFinite(value)), 'Expected a
|
|
44
|
+
(typeof value !== 'number' || Number.isFinite(value)), 'Expected a JSON-serializable value, binary data, or a stream'),
|
|
40
45
|
contentType: z.string().min(1).optional(),
|
|
41
46
|
});
|
|
42
47
|
const recordOptionsSchema = z.strictObject({
|
|
43
|
-
|
|
48
|
+
...timeoutOptionsShape,
|
|
44
49
|
doNotRetryTimeouts: z.boolean().optional(),
|
|
45
50
|
});
|
|
46
51
|
/**
|
|
@@ -84,11 +89,14 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
84
89
|
/**
|
|
85
90
|
* Gets the key-value store object from the Apify API.
|
|
86
91
|
*
|
|
92
|
+
* @param options - Request options
|
|
93
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
87
94
|
* @returns The KeyValueStore object, or `undefined` if it does not exist
|
|
88
95
|
* @see https://docs.apify.com/api/v2/key-value-store-get
|
|
89
96
|
*/
|
|
90
|
-
async get() {
|
|
91
|
-
|
|
97
|
+
async get(options = {}) {
|
|
98
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
99
|
+
return this.getResource(schemas.KeyValueStore(), {}, timeoutSecs);
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
102
|
* Updates the key-value store with specified fields.
|
|
@@ -97,20 +105,26 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
97
105
|
* @param newFields.name - New name for the store
|
|
98
106
|
* @param newFields.title - New title for the store
|
|
99
107
|
* @param newFields.generalAccess - General resource access level ('FOLLOW_USER_SETTING', 'ANYONE_WITH_ID_CAN_READ' or 'RESTRICTED')
|
|
108
|
+
* @param options - Request options
|
|
109
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
100
110
|
* @returns The updated KeyValueStore object
|
|
101
111
|
* @see https://docs.apify.com/api/v2/key-value-store-put
|
|
102
112
|
*/
|
|
103
|
-
async update(newFields) {
|
|
113
|
+
async update(newFields, options = {}) {
|
|
104
114
|
parseArgument(newFields, anyObjectSchema);
|
|
105
|
-
|
|
115
|
+
const { timeoutSecs = 'long' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
116
|
+
return this.updateResource(schemas.KeyValueStore(), newFields, timeoutSecs);
|
|
106
117
|
}
|
|
107
118
|
/**
|
|
108
119
|
* Deletes the key-value store.
|
|
109
120
|
*
|
|
121
|
+
* @param options - Request options
|
|
122
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
110
123
|
* @see https://docs.apify.com/api/v2/key-value-store-delete
|
|
111
124
|
*/
|
|
112
|
-
async delete() {
|
|
113
|
-
|
|
125
|
+
async delete(options = {}) {
|
|
126
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
127
|
+
return this.deleteResource(timeoutSecs);
|
|
114
128
|
}
|
|
115
129
|
/**
|
|
116
130
|
* Lists all keys in the key-value store.
|
|
@@ -123,6 +137,7 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
123
137
|
* @param options.exclusiveStartKey - Key to start listing from (for pagination). The listing starts with the next key after this one.
|
|
124
138
|
* @param options.collection - Filter keys by collection name.
|
|
125
139
|
* @param options.prefix - Filter keys that start with this prefix.
|
|
140
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
126
141
|
* @returns Object containing `items` array of key metadata, pagination info (`count`, `limit`, `isTruncated`, `nextExclusiveStartKey`)
|
|
127
142
|
* @see https://docs.apify.com/api/v2/key-value-store-keys-get
|
|
128
143
|
*
|
|
@@ -148,15 +163,15 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
148
163
|
* ```
|
|
149
164
|
*/
|
|
150
165
|
listKeys(options = {}) {
|
|
151
|
-
const parsed = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
|
|
166
|
+
const { timeoutSecs = 'medium', ...parsed } = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
|
|
152
167
|
const getPaginatedList = async (kvsListOptions = {}) => {
|
|
153
168
|
const response = await this.httpClient.call({
|
|
154
|
-
url: this.
|
|
169
|
+
url: this.buildUrl('keys'),
|
|
155
170
|
method: 'GET',
|
|
156
|
-
params: this.
|
|
157
|
-
|
|
171
|
+
params: this.buildParams(kvsListOptions),
|
|
172
|
+
timeoutSecs,
|
|
158
173
|
});
|
|
159
|
-
return
|
|
174
|
+
return parseResponse(response, schemas.ListOfKeys());
|
|
160
175
|
};
|
|
161
176
|
const paginatedListPromise = getPaginatedList(parsed);
|
|
162
177
|
async function* asyncGenerator() {
|
|
@@ -193,6 +208,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
193
208
|
* requiring an API token.
|
|
194
209
|
*
|
|
195
210
|
* @param key - The record key
|
|
211
|
+
* @param options - Request options
|
|
212
|
+
* @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
|
|
196
213
|
* @returns A public URL string for accessing the record
|
|
197
214
|
*
|
|
198
215
|
* @example
|
|
@@ -203,10 +220,11 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
203
220
|
* ```
|
|
204
221
|
* @since Added in 2.14.0
|
|
205
222
|
*/
|
|
206
|
-
async getRecordPublicUrl(key) {
|
|
223
|
+
async getRecordPublicUrl(key, options = {}) {
|
|
207
224
|
parseArgument(key, nonEmptyKeySchema);
|
|
208
|
-
const
|
|
209
|
-
const
|
|
225
|
+
const { timeoutSecs = 'long' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
226
|
+
const store = await this.get({ timeoutSecs });
|
|
227
|
+
const recordPublicUrl = new URL(this.buildPublicUrl(['records', key]));
|
|
210
228
|
if (store?.urlSigningSecretKey) {
|
|
211
229
|
const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
|
|
212
230
|
recordPublicUrl.searchParams.append('signature', signature);
|
|
@@ -223,6 +241,7 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
223
241
|
* @param options.expiresInSecs - Number of seconds until the signed URL expires. If omitted, the URL never expires.
|
|
224
242
|
* @param options.limit - Maximum number of keys to return.
|
|
225
243
|
* @param options.prefix - Filter keys by prefix.
|
|
244
|
+
* @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
|
|
226
245
|
* @returns A public URL string for accessing the keys list
|
|
227
246
|
*
|
|
228
247
|
* @example
|
|
@@ -237,10 +256,9 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
237
256
|
* @since Added in 2.13.0
|
|
238
257
|
*/
|
|
239
258
|
async createKeysPublicUrl(options = {}) {
|
|
240
|
-
const
|
|
241
|
-
const store = await this.get();
|
|
242
|
-
|
|
243
|
-
let createdPublicKeysUrl = new URL(this._publicUrl('keys'));
|
|
259
|
+
const { timeoutSecs = 'long', expiresInSecs, ...queryOptions } = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
|
|
260
|
+
const store = await this.get({ timeoutSecs });
|
|
261
|
+
let createdPublicKeysUrl = new URL(this.buildPublicUrl('keys'));
|
|
244
262
|
if (store?.urlSigningSecretKey) {
|
|
245
263
|
const signature = await createStorageContentSignatureAsync({
|
|
246
264
|
resourceId: store.id,
|
|
@@ -258,6 +276,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
258
276
|
* This is more efficient than {@link getRecord} when you only need to check for existence.
|
|
259
277
|
*
|
|
260
278
|
* @param key - The record key to check
|
|
279
|
+
* @param options - Request options
|
|
280
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
261
281
|
* @returns `true` if the record exists, `false` if it does not
|
|
262
282
|
* @see https://docs.apify.com/api/v2/key-value-store-record-get
|
|
263
283
|
*
|
|
@@ -270,11 +290,13 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
270
290
|
* ```
|
|
271
291
|
* @since Added in 2.9.0
|
|
272
292
|
*/
|
|
273
|
-
async recordExists(key) {
|
|
293
|
+
async recordExists(key, options = {}) {
|
|
294
|
+
const { timeoutSecs = 'long' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
274
295
|
const requestOpts = {
|
|
275
|
-
url: this.
|
|
296
|
+
url: this.buildUrl(['records', key]),
|
|
276
297
|
method: 'HEAD',
|
|
277
|
-
params: this.
|
|
298
|
+
params: this.buildParams(),
|
|
299
|
+
timeoutSecs,
|
|
278
300
|
};
|
|
279
301
|
try {
|
|
280
302
|
await this.httpClient.call(requestOpts);
|
|
@@ -299,10 +321,10 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
299
321
|
if (parsed.signature)
|
|
300
322
|
queryParams.signature = parsed.signature;
|
|
301
323
|
const requestOpts = {
|
|
302
|
-
url: this.
|
|
324
|
+
url: this.buildUrl(['records', key]),
|
|
303
325
|
method: 'GET',
|
|
304
|
-
params: this.
|
|
305
|
-
|
|
326
|
+
params: this.buildParams(queryParams),
|
|
327
|
+
timeoutSecs: parsed.timeoutSecs ?? 'long',
|
|
306
328
|
};
|
|
307
329
|
if (parsed.buffer)
|
|
308
330
|
requestOpts.forceBuffer = true;
|
|
@@ -334,13 +356,18 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
334
356
|
*
|
|
335
357
|
* @param record - The record to store
|
|
336
358
|
* @param record.key - Record key (unique identifier)
|
|
337
|
-
* @param record.value - Record value (
|
|
359
|
+
* @param record.value - Record value (a JSON-serializable value, Buffer, ArrayBuffer, typed array, or Readable)
|
|
338
360
|
* @param record.contentType - Optional MIME type. Auto-detected if not provided:
|
|
339
361
|
* - Objects: `'application/json; charset=utf-8'`
|
|
340
362
|
* - Strings: `'text/plain; charset=utf-8'`
|
|
341
|
-
* -
|
|
363
|
+
* - Binary values and streams: `'application/octet-stream'`
|
|
364
|
+
*
|
|
365
|
+
* Worth setting for media and archives: the client skips compressing a body
|
|
366
|
+
* whose content type already carries its own compression. The
|
|
367
|
+
* `'application/octet-stream'` fallback is treated as compressible, because
|
|
368
|
+
* it could hold any binary data.
|
|
342
369
|
* @param options - Storage options
|
|
343
|
-
* @param options.timeoutSecs - Timeout for the
|
|
370
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
344
371
|
* @param options.doNotRetryTimeouts - If `true`, don't retry on timeout errors. Default is `false`.
|
|
345
372
|
* @see https://docs.apify.com/api/v2/key-value-store-record-put
|
|
346
373
|
*
|
|
@@ -373,7 +400,7 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
373
400
|
const parsed = parseArgument(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
|
|
374
401
|
const { key } = record;
|
|
375
402
|
let { value, contentType } = record;
|
|
376
|
-
const { timeoutSecs, doNotRetryTimeouts } = parsed;
|
|
403
|
+
const { timeoutSecs = 'long', doNotRetryTimeouts } = parsed;
|
|
377
404
|
const isValueStreamOrBuffer = isStream(value) || isBuffer(value);
|
|
378
405
|
// To allow saving Objects to JSON without providing content type
|
|
379
406
|
if (!contentType) {
|
|
@@ -395,13 +422,13 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
395
422
|
}
|
|
396
423
|
}
|
|
397
424
|
const uploadOpts = {
|
|
398
|
-
url: this.
|
|
425
|
+
url: this.buildUrl(['records', key]),
|
|
399
426
|
method: 'PUT',
|
|
400
|
-
params: this.
|
|
427
|
+
params: this.buildParams(),
|
|
401
428
|
data: value,
|
|
402
429
|
headers: contentType ? { 'content-type': contentType } : undefined,
|
|
403
430
|
doNotRetryTimeouts,
|
|
404
|
-
|
|
431
|
+
timeoutSecs,
|
|
405
432
|
};
|
|
406
433
|
await this.httpClient.call(uploadOpts);
|
|
407
434
|
}
|
|
@@ -409,6 +436,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
409
436
|
* Deletes a record from the key-value store.
|
|
410
437
|
*
|
|
411
438
|
* @param key - The record key to delete
|
|
439
|
+
* @param options - Request options
|
|
440
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
412
441
|
* @see https://docs.apify.com/api/v2/key-value-store-record-delete
|
|
413
442
|
*
|
|
414
443
|
* @example
|
|
@@ -416,13 +445,14 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
416
445
|
* await client.keyValueStore('my-store').deleteRecord('temp-data');
|
|
417
446
|
* ```
|
|
418
447
|
*/
|
|
419
|
-
async deleteRecord(key) {
|
|
448
|
+
async deleteRecord(key, options = {}) {
|
|
420
449
|
parseArgument(key, keySchema);
|
|
450
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
421
451
|
await this.httpClient.call({
|
|
422
|
-
url: this.
|
|
452
|
+
url: this.buildUrl(['records', key]),
|
|
423
453
|
method: 'DELETE',
|
|
424
|
-
params: this.
|
|
425
|
-
|
|
454
|
+
params: this.buildParams(),
|
|
455
|
+
timeoutSecs,
|
|
426
456
|
});
|
|
427
457
|
}
|
|
428
458
|
}
|
|
@@ -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 { KeyValueStore } from './key_value_store.js';
|
|
6
7
|
/**
|
|
@@ -45,6 +46,7 @@ export declare class KeyValueStoreCollectionClient extends ResourceCollectionCli
|
|
|
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 Key-value stores.
|
|
49
51
|
* @see https://docs.apify.com/api/v2/key-value-stores-get
|
|
50
52
|
*/
|
|
@@ -54,12 +56,14 @@ export declare class KeyValueStoreCollectionClient extends ResourceCollectionCli
|
|
|
54
56
|
*
|
|
55
57
|
* @param name - Name of the key-value store. If not provided, a default store is used.
|
|
56
58
|
* @param options - Additional options like schema.
|
|
59
|
+
* @param options.schema - Schema of the key-value store.
|
|
60
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
57
61
|
* @returns The key-value store object.
|
|
58
62
|
* @see https://docs.apify.com/api/v2/key-value-stores-post
|
|
59
63
|
*/
|
|
60
64
|
getOrCreate(name?: string, options?: KeyValueStoreCollectionClientGetOrCreateOptions): Promise<KeyValueStore>;
|
|
61
65
|
}
|
|
62
|
-
export interface KeyValueStoreCollectionClientListOptions extends PaginationOptions {
|
|
66
|
+
export interface KeyValueStoreCollectionClientListOptions extends PaginationOptions, TimeoutOptions {
|
|
63
67
|
unnamed?: boolean;
|
|
64
68
|
desc?: boolean;
|
|
65
69
|
/**
|
|
@@ -71,7 +75,7 @@ export interface KeyValueStoreCollectionClientListOptions extends PaginationOpti
|
|
|
71
75
|
/**
|
|
72
76
|
* @since Added in 2.3.0
|
|
73
77
|
*/
|
|
74
|
-
export interface KeyValueStoreCollectionClientGetOrCreateOptions {
|
|
78
|
+
export interface KeyValueStoreCollectionClientGetOrCreateOptions extends TimeoutOptions {
|
|
75
79
|
schema?: Record<string, unknown>;
|
|
76
80
|
}
|
|
77
81
|
export type KeyValueStoreCollectionListResult = PaginatedList<KeyValueStore> & {
|
|
@@ -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 { optionalTimeoutSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
4
6
|
import { anyObjectSchema, 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
|
const schemaSchema = anyObjectSchema.optional();
|
|
@@ -57,24 +60,32 @@ export class KeyValueStoreCollectionClient extends ResourceCollectionClient {
|
|
|
57
60
|
* ```
|
|
58
61
|
*
|
|
59
62
|
* @param options - Pagination options.
|
|
63
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
60
64
|
* @returns A paginated iterator of Key-value stores.
|
|
61
65
|
* @see https://docs.apify.com/api/v2/key-value-stores-get
|
|
62
66
|
*/
|
|
63
67
|
list(options = {}) {
|
|
64
68
|
const parsed = parseArgument(options, listOptionsSchema, 'KeyValueStoreCollectionClientListOptions');
|
|
65
|
-
return this.
|
|
69
|
+
return this.listResourcesPaginated(schemas.ListOfKeyValueStores(), parsed, 'medium');
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
72
|
* Gets or creates a key-value store with the specified name.
|
|
69
73
|
*
|
|
70
74
|
* @param name - Name of the key-value store. If not provided, a default store is used.
|
|
71
75
|
* @param options - Additional options like schema.
|
|
76
|
+
* @param options.schema - Schema of the key-value store.
|
|
77
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
72
78
|
* @returns The key-value store object.
|
|
73
79
|
* @see https://docs.apify.com/api/v2/key-value-stores-post
|
|
74
80
|
*/
|
|
75
81
|
async getOrCreate(name, options) {
|
|
76
82
|
parseArgument(name, nameSchema);
|
|
77
83
|
parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
|
|
78
|
-
|
|
84
|
+
parseArgument(options?.timeoutSecs, optionalTimeoutSchema);
|
|
85
|
+
// `timeoutSecs` is not part of the resource, so the body carries only the rest, and stays absent when
|
|
86
|
+
// there is nothing else to send.
|
|
87
|
+
const { timeoutSecs = 'short', ...resource } = options ?? {};
|
|
88
|
+
const hasResource = Object.keys(resource).length > 0;
|
|
89
|
+
return this.getOrCreateResource(schemas.KeyValueStore(), name, hasResource ? resource : undefined, timeoutSecs);
|
|
79
90
|
}
|
|
80
91
|
}
|
|
@@ -3,6 +3,7 @@ import type { Log } from '@apify/log';
|
|
|
3
3
|
import { Logger, LogLevel } from '@apify/log';
|
|
4
4
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
5
5
|
import { ResourceClient } from '../base/resource_client.js';
|
|
6
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
6
7
|
/**
|
|
7
8
|
* Client for accessing Actor run or build logs.
|
|
8
9
|
*
|
|
@@ -35,7 +36,9 @@ export declare class LogClient extends ResourceClient {
|
|
|
35
36
|
*
|
|
36
37
|
* @param options - Log retrieval options.
|
|
37
38
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
38
|
-
* @
|
|
39
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
40
|
+
* @returns The log content as a string, or `undefined` if it does not exist. A chained client such as
|
|
41
|
+
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
39
42
|
* @see https://docs.apify.com/api/v2/log-get
|
|
40
43
|
*/
|
|
41
44
|
get(options?: LogOptions): Promise<string | undefined>;
|
|
@@ -44,7 +47,9 @@ export declare class LogClient extends ResourceClient {
|
|
|
44
47
|
*
|
|
45
48
|
* @param options - Log retrieval options.
|
|
46
49
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
47
|
-
* @
|
|
50
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
|
|
51
|
+
* @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
|
|
52
|
+
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
48
53
|
* @see https://docs.apify.com/api/v2/log-get
|
|
49
54
|
*/
|
|
50
55
|
stream(options?: LogOptions): Promise<Readable | undefined>;
|
|
@@ -52,7 +57,7 @@ export declare class LogClient extends ResourceClient {
|
|
|
52
57
|
/**
|
|
53
58
|
* @since Added in 2.20.0
|
|
54
59
|
*/
|
|
55
|
-
export interface LogOptions {
|
|
60
|
+
export interface LogOptions extends TimeoutOptions {
|
|
56
61
|
/** @default false */
|
|
57
62
|
raw?: boolean;
|
|
58
63
|
}
|
|
@@ -69,13 +74,7 @@ export declare class LoggerActorRedirect extends Logger {
|
|
|
69
74
|
* @since Added in 2.20.0
|
|
70
75
|
*/
|
|
71
76
|
export declare class StreamedLog {
|
|
72
|
-
private
|
|
73
|
-
private streamBuffer;
|
|
74
|
-
private splitMarker;
|
|
75
|
-
private relevancyTimeLimit;
|
|
76
|
-
private logClient;
|
|
77
|
-
private streamingTask;
|
|
78
|
-
private stopLogging;
|
|
77
|
+
#private;
|
|
79
78
|
constructor(options: StreamedLogOptions);
|
|
80
79
|
/**
|
|
81
80
|
* Start log redirection.
|
|
@@ -85,15 +84,6 @@ export declare class StreamedLog {
|
|
|
85
84
|
* Stop log redirection.
|
|
86
85
|
*/
|
|
87
86
|
stop(): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* Get log stream from response and redirect it to another log.
|
|
90
|
-
*/
|
|
91
|
-
private streamLog;
|
|
92
|
-
private logStreamChunks;
|
|
93
|
-
/**
|
|
94
|
-
* Parse the buffer and log complete messages.
|
|
95
|
-
*/
|
|
96
|
-
private logBufferContent;
|
|
97
87
|
}
|
|
98
88
|
/**
|
|
99
89
|
* @since Added in 2.20.0
|