apify-client 3.0.0-beta.7 → 3.0.0-beta.70

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 (120) hide show
  1. package/README.md +10 -2
  2. package/dist/apify_api_error.d.ts +13 -27
  3. package/dist/apify_api_error.js +33 -23
  4. package/dist/apify_client.d.ts +125 -10
  5. package/dist/apify_client.js +133 -48
  6. package/dist/apify_client_error.d.ts +10 -0
  7. package/dist/apify_client_error.js +10 -0
  8. package/dist/base/api_client.d.ts +7 -7
  9. package/dist/base/api_client.js +36 -36
  10. package/dist/base/resource_client.d.ts +21 -8
  11. package/dist/base/resource_client.js +67 -33
  12. package/dist/base/resource_collection_client.d.ts +12 -4
  13. package/dist/base/resource_collection_client.js +34 -11
  14. package/dist/body_parser.d.ts +3 -4
  15. package/dist/body_parser.js +19 -26
  16. package/dist/bundle.js +27 -22
  17. package/dist/bundle.js.map +1 -1
  18. package/dist/generated/api.d.ts +785 -290
  19. package/dist/generated/schemas.d.ts +771 -798
  20. package/dist/generated/schemas.js +183 -179
  21. package/dist/http_clients/axios.d.ts +60 -0
  22. package/dist/http_clients/axios.js +117 -0
  23. package/dist/http_clients/base.d.ts +331 -0
  24. package/dist/http_clients/base.js +563 -0
  25. package/dist/http_clients/index.d.ts +4 -0
  26. package/dist/http_clients/index.js +2 -0
  27. package/dist/http_compressors/base.d.ts +40 -0
  28. package/dist/http_compressors/base.js +9 -0
  29. package/dist/http_compressors/brotli.d.ts +33 -0
  30. package/dist/http_compressors/brotli.js +39 -0
  31. package/dist/http_compressors/gzip.d.ts +33 -0
  32. package/dist/http_compressors/gzip.js +39 -0
  33. package/dist/http_compressors/index.d.ts +6 -0
  34. package/dist/http_compressors/index.js +2 -0
  35. package/dist/http_compressors/resolve.d.ts +23 -0
  36. package/dist/http_compressors/resolve.js +27 -0
  37. package/dist/index.d.ts +5 -1
  38. package/dist/index.js +4 -1
  39. package/dist/invalid_response_body_error.d.ts +14 -0
  40. package/dist/invalid_response_body_error.js +18 -0
  41. package/dist/models.d.ts +162 -194
  42. package/dist/models.js +6 -4
  43. package/dist/resource_clients/actor.d.ts +74 -34
  44. package/dist/resource_clients/actor.js +87 -56
  45. package/dist/resource_clients/actor_collection.d.ts +18 -12
  46. package/dist/resource_clients/actor_collection.js +11 -3
  47. package/dist/resource_clients/actor_env_var.d.ts +11 -4
  48. package/dist/resource_clients/actor_env_var.js +16 -6
  49. package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
  50. package/dist/resource_clients/actor_env_var_collection.js +11 -4
  51. package/dist/resource_clients/actor_version.d.ts +20 -5
  52. package/dist/resource_clients/actor_version.js +19 -9
  53. package/dist/resource_clients/actor_version_collection.d.ts +11 -4
  54. package/dist/resource_clients/actor_version_collection.js +13 -4
  55. package/dist/resource_clients/build.d.ts +20 -7
  56. package/dist/resource_clients/build.js +35 -15
  57. package/dist/resource_clients/build_collection.d.ts +7 -5
  58. package/dist/resource_clients/build_collection.js +4 -1
  59. package/dist/resource_clients/dataset.d.ts +81 -36
  60. package/dist/resource_clients/dataset.js +109 -120
  61. package/dist/resource_clients/dataset_collection.d.ts +10 -6
  62. package/dist/resource_clients/dataset_collection.js +13 -2
  63. package/dist/resource_clients/key_value_store.d.ts +101 -23
  64. package/dist/resource_clients/key_value_store.js +121 -45
  65. package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
  66. package/dist/resource_clients/key_value_store_collection.js +13 -2
  67. package/dist/resource_clients/log.d.ts +40 -21
  68. package/dist/resource_clients/log.js +144 -66
  69. package/dist/resource_clients/request_queue.d.ts +76 -31
  70. package/dist/resource_clients/request_queue.js +178 -93
  71. package/dist/resource_clients/request_queue_collection.d.ts +9 -5
  72. package/dist/resource_clients/request_queue_collection.js +9 -3
  73. package/dist/resource_clients/run.d.ts +119 -28
  74. package/dist/resource_clients/run.js +190 -49
  75. package/dist/resource_clients/run_collection.d.ts +5 -3
  76. package/dist/resource_clients/run_collection.js +4 -1
  77. package/dist/resource_clients/schedule.d.ts +16 -7
  78. package/dist/resource_clients/schedule.js +30 -22
  79. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  80. package/dist/resource_clients/schedule_collection.js +9 -3
  81. package/dist/resource_clients/store_collection.d.ts +6 -4
  82. package/dist/resource_clients/store_collection.js +4 -1
  83. package/dist/resource_clients/task.d.ts +36 -13
  84. package/dist/resource_clients/task.js +79 -46
  85. package/dist/resource_clients/task_collection.d.ts +9 -5
  86. package/dist/resource_clients/task_collection.js +9 -3
  87. package/dist/resource_clients/user.d.ts +19 -10
  88. package/dist/resource_clients/user.js +42 -38
  89. package/dist/resource_clients/webhook.d.ts +17 -8
  90. package/dist/resource_clients/webhook.js +30 -22
  91. package/dist/resource_clients/webhook_collection.d.ts +8 -4
  92. package/dist/resource_clients/webhook_collection.js +9 -3
  93. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  94. package/dist/resource_clients/webhook_dispatch.js +7 -2
  95. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  96. package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
  97. package/dist/response_validation_error.d.ts +2 -1
  98. package/dist/response_validation_error.js +2 -1
  99. package/dist/runtime/node.d.ts +6 -0
  100. package/dist/runtime/node.js +49 -0
  101. package/dist/runtime/types.d.ts +52 -0
  102. package/dist/runtime/types.js +1 -0
  103. package/dist/runtime/web.d.ts +5 -0
  104. package/dist/runtime/web.js +18 -0
  105. package/dist/schemas.d.ts +1 -1
  106. package/dist/schemas.js +1 -1
  107. package/dist/statistics.d.ts +1 -6
  108. package/dist/statistics.js +2 -2
  109. package/dist/timeouts.d.ts +84 -0
  110. package/dist/timeouts.js +37 -0
  111. package/dist/timezones.d.ts +1 -1
  112. package/dist/utils.d.ts +88 -57
  113. package/dist/utils.js +219 -157
  114. package/dist/wait_for_resources.d.ts +8 -0
  115. package/dist/wait_for_resources.js +39 -0
  116. package/package.json +32 -29
  117. package/dist/http_client.d.ts +0 -88
  118. package/dist/http_client.js +0 -255
  119. package/dist/interceptors.d.ts +0 -19
  120. package/dist/interceptors.js +0 -105
@@ -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 { Dataset } from './dataset.js';
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<Dataset>;
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<Dataset>;
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<Dataset> & {
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._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.DatasetResource(), name, hasResource ? resource : undefined, timeoutSecs, signal);
80
91
  }
81
92
  }
@@ -1,10 +1,11 @@
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
- import type { KeyValueClientListKeysResult, KeyValueListItem, KeyValueStore } from '../models.js';
7
- export type { KeyValueClientListKeysResult, KeyValueListItem, KeyValueStore, KeyValueStoreStats } from '../models.js';
6
+ import type { KeyValueStoreResource, KeyValueStoreKey, ListOfKeys } from '../models.js';
7
+ import type { TimeoutOptions } from '../timeouts.js';
8
+ export type { KeyValueStoreResource, KeyValueStoreKey, KeyValueStoreStats, ListOfKeys } from '../models.js';
8
9
  /**
9
10
  * Client for managing a specific key-value store.
10
11
  *
@@ -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<KeyValueStoreResource | 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<KeyValueStoreResource>;
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
  *
@@ -70,9 +77,12 @@ export declare class KeyValueStoreClient extends ResourceClient {
70
77
  *
71
78
  * @param options - Listing options
72
79
  * @param options.limit - Maximum number of keys to return. Default is 1000.
80
+ * @param options.chunkSize - Maximum number of keys requested per API call when iterating across pages. `limit`
81
+ * then caps the total across all pages.
73
82
  * @param options.exclusiveStartKey - Key to start listing from (for pagination). The listing starts with the next key after this one.
74
83
  * @param options.collection - Filter keys by collection name.
75
84
  * @param options.prefix - Filter keys that start with this prefix.
85
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
76
86
  * @returns Object containing `items` array of key metadata, pagination info (`count`, `limit`, `isTruncated`, `nextExclusiveStartKey`)
77
87
  * @see https://docs.apify.com/api/v2/key-value-store-keys-get
78
88
  *
@@ -97,7 +107,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
97
107
  * } while (result.isTruncated);
98
108
  * ```
99
109
  */
100
- listKeys(options?: KeyValueClientListKeysOptions): Promise<KeyValueClientListKeysResult> & AsyncIterable<KeyValueListItem>;
110
+ listKeys(options?: KeyValueClientListKeysOptions): Promise<ListOfKeys> & AsyncIterable<KeyValueStoreKey>;
101
111
  /**
102
112
  * Generates a public URL for accessing a specific record in the key-value store.
103
113
  *
@@ -106,6 +116,8 @@ export declare class KeyValueStoreClient extends ResourceClient {
106
116
  * requiring an API token.
107
117
  *
108
118
  * @param key - The record key
119
+ * @param options - Request options
120
+ * @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
109
121
  * @returns A public URL string for accessing the record
110
122
  *
111
123
  * @example
@@ -116,7 +128,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
116
128
  * ```
117
129
  * @since Added in 2.14.0
118
130
  */
119
- getRecordPublicUrl(key: string): Promise<string>;
131
+ getRecordPublicUrl(key: string, options?: TimeoutOptions): Promise<string>;
120
132
  /**
121
133
  * Generates a public URL for accessing the list of keys in the key-value store.
122
134
  *
@@ -127,6 +139,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
127
139
  * @param options.expiresInSecs - Number of seconds until the signed URL expires. If omitted, the URL never expires.
128
140
  * @param options.limit - Maximum number of keys to return.
129
141
  * @param options.prefix - Filter keys by prefix.
142
+ * @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
130
143
  * @returns A public URL string for accessing the keys list
131
144
  *
132
145
  * @example
@@ -147,6 +160,8 @@ export declare class KeyValueStoreClient extends ResourceClient {
147
160
  * This is more efficient than {@link getRecord} when you only need to check for existence.
148
161
  *
149
162
  * @param key - The record key to check
163
+ * @param options - Request options
164
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
150
165
  * @returns `true` if the record exists, `false` if it does not
151
166
  * @see https://docs.apify.com/api/v2/key-value-store-record-get
152
167
  *
@@ -159,15 +174,27 @@ export declare class KeyValueStoreClient extends ResourceClient {
159
174
  * ```
160
175
  * @since Added in 2.9.0
161
176
  */
162
- recordExists(key: string): Promise<boolean>;
177
+ recordExists(key: string, options?: TimeoutOptions): Promise<boolean>;
163
178
  /**
179
+ * By default, the value is parsed by the record's content type: `application/json` is parsed into a value,
180
+ * `text/*` and `application/*xml` are decoded to a string, and anything else is returned as a Buffer (Node.js)
181
+ * or ArrayBuffer (browser). A record whose body does not parse as its content type claims, such as a non-JSON
182
+ * string stored under `application/json`, makes the call throw an {@link InvalidResponseBodyError}, which
183
+ * carries the raw body in `error.response`.
184
+ *
164
185
  * You can use the `buffer` option to get the value in a Buffer (Node.js)
165
- * or ArrayBuffer (browser) format. In Node.js (not in browser) you can also
186
+ * or ArrayBuffer (browser) format, which skips the parsing. In Node.js (not in browser) you can also
166
187
  * use the `stream` option to get a Readable stream.
167
188
  *
168
189
  * When the record does not exist, the function resolves to `undefined`. It does
169
- * NOT resolve to a `KeyValueStore` record with an `undefined` value.
190
+ * NOT resolve to a `KeyValueStoreRecord` with an `undefined` value.
170
191
  *
192
+ * @param key - The record key
193
+ * @param options - Retrieval options
194
+ * @param options.buffer - If `true`, the value is returned as a Buffer (Node.js) or ArrayBuffer (browser).
195
+ * @param options.stream - If `true`, the value is returned as a Readable stream. Node.js only.
196
+ * @param options.signature - Signature of a public URL, for reading a record without a token.
197
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
171
198
  * @see https://docs.apify.com/api/v2/key-value-store-record-get
172
199
  */
173
200
  getRecord(key: string): Promise<KeyValueStoreRecord<JsonValue> | undefined>;
@@ -179,19 +206,36 @@ export declare class KeyValueStoreClient extends ResourceClient {
179
206
  * The content type is automatically determined based on the value type, but can be
180
207
  * overridden using the `contentType` property.
181
208
  *
209
+ * A string is sent as it is, even under `application/json`, so a string stored under a JSON content type has
210
+ * to be valid JSON already, or {@link getRecord} fails to parse it back.
211
+ *
182
212
  * **Note about streams:** If the value is a stream object (has `.pipe` and `.on` methods),
183
213
  * the upload cannot be retried on failure or follow redirects. For reliable uploads,
184
214
  * buffer the entire stream into memory first.
185
215
  *
186
216
  * @param record - The record to store
187
217
  * @param record.key - Record key (unique identifier)
188
- * @param record.value - Record value (object, string, Buffer, or Stream)
218
+ * @param record.value - Record value (a JSON-serializable value, Buffer, ArrayBuffer, typed array, or Readable)
189
219
  * @param record.contentType - Optional MIME type. Auto-detected if not provided:
190
220
  * - Objects: `'application/json; charset=utf-8'`
191
221
  * - Strings: `'text/plain; charset=utf-8'`
192
- * - Buffers/Streams: `'application/octet-stream'`
222
+ * - Binary values and streams: `'application/octet-stream'`
223
+ *
224
+ * Worth setting for media and archives: the client skips compressing a body
225
+ * whose content type already carries its own compression. The
226
+ * `'application/octet-stream'` fallback is treated as compressible, because
227
+ * it could hold any binary data.
228
+ * @param record.contentEncoding - Optional encoding already applied to `value`, sent as the `Content-Encoding`
229
+ * header. Set it to upload a pre-compressed value: the client then sends the
230
+ * bytes as they are and does not compress them again. The API accepts `gzip`,
231
+ * `br`, `deflate`, and `identity`, and stores the record exactly as uploaded, so
232
+ * this is also the encoding the record is served with. Only binary values and
233
+ * streams can carry a compression, so any encoding other than `identity` throws
234
+ * a `TypeError` when `value` is a string, or a plain object, array, or other
235
+ * value that the client serializes to JSON. Node.js only, since browsers cannot
236
+ * send the header to the API.
193
237
  * @param options - Storage options
194
- * @param options.timeoutSecs - Timeout for the upload in seconds. Default varies by value size.
238
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
195
239
  * @param options.doNotRetryTimeouts - If `true`, don't retry on timeout errors. Default is `false`.
196
240
  * @see https://docs.apify.com/api/v2/key-value-store-record-put
197
241
  *
@@ -217,13 +261,24 @@ export declare class KeyValueStoreClient extends ResourceClient {
217
261
  * value: imageBuffer,
218
262
  * contentType: 'image/png'
219
263
  * });
264
+ *
265
+ * // Store a gzipped file without compressing it again
266
+ * const gzippedReport = await readFile('report.json.gz');
267
+ * await client.keyValueStore('my-store').setRecord({
268
+ * key: 'report.json',
269
+ * value: gzippedReport,
270
+ * contentType: 'application/json',
271
+ * contentEncoding: 'gzip'
272
+ * });
220
273
  * ```
221
274
  */
222
- setRecord(record: KeyValueStoreRecord<JsonValue>, options?: KeyValueStoreRecordOptions): Promise<void>;
275
+ setRecord(record: KeyValueStoreRecordInput, options?: KeyValueStoreRecordOptions): Promise<void>;
223
276
  /**
224
277
  * Deletes a record from the key-value store.
225
278
  *
226
279
  * @param key - The record key to delete
280
+ * @param options - Request options
281
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
227
282
  * @see https://docs.apify.com/api/v2/key-value-store-record-delete
228
283
  *
229
284
  * @example
@@ -231,7 +286,7 @@ export declare class KeyValueStoreClient extends ResourceClient {
231
286
  * await client.keyValueStore('my-store').deleteRecord('temp-data');
232
287
  * ```
233
288
  */
234
- deleteRecord(key: string): Promise<void>;
289
+ deleteRecord(key: string, options?: TimeoutOptions): Promise<void>;
235
290
  }
236
291
  /**
237
292
  * Options for updating a Key-Value Store.
@@ -250,8 +305,14 @@ export interface KeyValueClientUpdateOptions {
250
305
  /**
251
306
  * Options for listing keys in a Key-Value Store.
252
307
  */
253
- export interface KeyValueClientListKeysOptions {
308
+ export interface KeyValueClientListKeysOptions extends TimeoutOptions {
254
309
  limit?: number;
310
+ /**
311
+ * Maximum number of keys returned in one API response. When the call is iterated with `for await`, the iterator
312
+ * fetches keys in chunks of this size and yields them one by one, until `limit` is reached or the store has no
313
+ * more keys. Awaiting the call returns only the first chunk.
314
+ */
315
+ chunkSize?: number;
255
316
  exclusiveStartKey?: string;
256
317
  collection?: string;
257
318
  /**
@@ -266,17 +327,17 @@ export interface KeyValueClientListKeysOptions {
266
327
  /**
267
328
  * Options for creating a public URL to list keys in a Key-Value Store.
268
329
  *
269
- * Extends {@link KeyValueClientListKeysOptions} with URL expiration control, minus `signature` (this
270
- * method produces one).
330
+ * Extends {@link KeyValueClientListKeysOptions} with URL expiration control, minus `chunkSize` (it only sizes a
331
+ * client-side iteration) and `signature` (this method produces one).
271
332
  * @since Added in 2.16.0
272
333
  */
273
- export interface KeyValueClientCreateKeysUrlOptions extends Omit<KeyValueClientListKeysOptions, 'signature'> {
334
+ export interface KeyValueClientCreateKeysUrlOptions extends Omit<KeyValueClientListKeysOptions, 'chunkSize' | 'signature'> {
274
335
  expiresInSecs?: number;
275
336
  }
276
337
  /**
277
338
  * Options for retrieving a record from a Key-Value Store.
278
339
  */
279
- export interface KeyValueClientGetRecordOptions {
340
+ export interface KeyValueClientGetRecordOptions extends TimeoutOptions {
280
341
  buffer?: boolean;
281
342
  stream?: boolean;
282
343
  /**
@@ -284,6 +345,14 @@ export interface KeyValueClientGetRecordOptions {
284
345
  */
285
346
  signature?: string;
286
347
  }
348
+ /**
349
+ * A value that `setRecord` accepts.
350
+ *
351
+ * Anything JSON-serializable, or binary content the client uploads as bytes instead of JSON-encoding
352
+ * it: a `Buffer`, an `ArrayBuffer`, a typed array, or a readable stream. `Buffer` is a `Uint8Array`, so
353
+ * `TypedArray` covers it.
354
+ */
355
+ export type KeyValueStoreRecordValue = JsonValue | ArrayBuffer | TypedArray | Readable;
287
356
  /**
288
357
  * Represents a record (key-value pair) in a Key-Value Store.
289
358
  *
@@ -294,12 +363,21 @@ export interface KeyValueStoreRecord<T> {
294
363
  value: T;
295
364
  contentType?: string;
296
365
  }
366
+ /**
367
+ * A record to store with {@link KeyValueStoreClient.setRecord}.
368
+ */
369
+ export interface KeyValueStoreRecordInput extends KeyValueStoreRecord<KeyValueStoreRecordValue> {
370
+ /**
371
+ * Encoding already applied to `value`, sent as the `Content-Encoding` header. See
372
+ * {@link KeyValueStoreClient.setRecord}.
373
+ */
374
+ contentEncoding?: string;
375
+ }
297
376
  /**
298
377
  * Options for storing a record in a Key-Value Store.
299
378
  * @since Added in 2.12.4
300
379
  */
301
- export interface KeyValueStoreRecordOptions {
302
- timeoutSecs?: number;
380
+ export interface KeyValueStoreRecordOptions extends TimeoutOptions {
303
381
  doNotRetryTimeouts?: boolean;
304
382
  }
305
383
  /**