apify-client 3.0.0-beta.6 → 3.0.0-beta.60

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 (116) hide show
  1. package/README.md +10 -2
  2. package/dist/apify_api_error.d.ts +11 -26
  3. package/dist/apify_api_error.js +31 -22
  4. package/dist/apify_client.d.ts +125 -10
  5. package/dist/apify_client.js +133 -48
  6. package/dist/base/api_client.d.ts +7 -7
  7. package/dist/base/api_client.js +36 -36
  8. package/dist/base/resource_client.d.ts +21 -8
  9. package/dist/base/resource_client.js +67 -33
  10. package/dist/base/resource_collection_client.d.ts +12 -4
  11. package/dist/base/resource_collection_client.js +34 -11
  12. package/dist/body_parser.d.ts +3 -4
  13. package/dist/body_parser.js +19 -26
  14. package/dist/bundle.js +27 -22
  15. package/dist/bundle.js.map +1 -1
  16. package/dist/generated/api.d.ts +785 -290
  17. package/dist/generated/schemas.d.ts +771 -798
  18. package/dist/generated/schemas.js +183 -179
  19. package/dist/http_clients/axios.d.ts +60 -0
  20. package/dist/http_clients/axios.js +117 -0
  21. package/dist/http_clients/base.d.ts +331 -0
  22. package/dist/http_clients/base.js +563 -0
  23. package/dist/http_clients/index.d.ts +4 -0
  24. package/dist/http_clients/index.js +2 -0
  25. package/dist/http_compressors/base.d.ts +40 -0
  26. package/dist/http_compressors/base.js +9 -0
  27. package/dist/http_compressors/brotli.d.ts +33 -0
  28. package/dist/http_compressors/brotli.js +39 -0
  29. package/dist/http_compressors/gzip.d.ts +33 -0
  30. package/dist/http_compressors/gzip.js +39 -0
  31. package/dist/http_compressors/index.d.ts +6 -0
  32. package/dist/http_compressors/index.js +2 -0
  33. package/dist/http_compressors/resolve.d.ts +23 -0
  34. package/dist/http_compressors/resolve.js +27 -0
  35. package/dist/index.d.ts +4 -1
  36. package/dist/index.js +3 -1
  37. package/dist/invalid_response_body_error.d.ts +13 -0
  38. package/dist/invalid_response_body_error.js +17 -0
  39. package/dist/models.d.ts +162 -194
  40. package/dist/models.js +6 -4
  41. package/dist/resource_clients/actor.d.ts +74 -34
  42. package/dist/resource_clients/actor.js +87 -56
  43. package/dist/resource_clients/actor_collection.d.ts +18 -14
  44. package/dist/resource_clients/actor_collection.js +11 -3
  45. package/dist/resource_clients/actor_env_var.d.ts +11 -4
  46. package/dist/resource_clients/actor_env_var.js +16 -6
  47. package/dist/resource_clients/actor_env_var_collection.d.ts +16 -20
  48. package/dist/resource_clients/actor_env_var_collection.js +17 -11
  49. package/dist/resource_clients/actor_version.d.ts +20 -5
  50. package/dist/resource_clients/actor_version.js +19 -9
  51. package/dist/resource_clients/actor_version_collection.d.ts +18 -19
  52. package/dist/resource_clients/actor_version_collection.js +19 -11
  53. package/dist/resource_clients/build.d.ts +20 -7
  54. package/dist/resource_clients/build.js +35 -15
  55. package/dist/resource_clients/build_collection.d.ts +7 -5
  56. package/dist/resource_clients/build_collection.js +4 -1
  57. package/dist/resource_clients/dataset.d.ts +53 -35
  58. package/dist/resource_clients/dataset.js +105 -80
  59. package/dist/resource_clients/dataset_collection.d.ts +10 -6
  60. package/dist/resource_clients/dataset_collection.js +13 -2
  61. package/dist/resource_clients/key_value_store.d.ts +73 -23
  62. package/dist/resource_clients/key_value_store.js +86 -43
  63. package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
  64. package/dist/resource_clients/key_value_store_collection.js +13 -2
  65. package/dist/resource_clients/log.d.ts +13 -20
  66. package/dist/resource_clients/log.js +141 -59
  67. package/dist/resource_clients/request_queue.d.ts +74 -36
  68. package/dist/resource_clients/request_queue.js +182 -106
  69. package/dist/resource_clients/request_queue_collection.d.ts +9 -5
  70. package/dist/resource_clients/request_queue_collection.js +9 -3
  71. package/dist/resource_clients/run.d.ts +119 -28
  72. package/dist/resource_clients/run.js +190 -49
  73. package/dist/resource_clients/run_collection.d.ts +5 -3
  74. package/dist/resource_clients/run_collection.js +4 -1
  75. package/dist/resource_clients/schedule.d.ts +16 -7
  76. package/dist/resource_clients/schedule.js +30 -22
  77. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  78. package/dist/resource_clients/schedule_collection.js +9 -3
  79. package/dist/resource_clients/store_collection.d.ts +6 -4
  80. package/dist/resource_clients/store_collection.js +4 -1
  81. package/dist/resource_clients/task.d.ts +36 -13
  82. package/dist/resource_clients/task.js +79 -46
  83. package/dist/resource_clients/task_collection.d.ts +9 -5
  84. package/dist/resource_clients/task_collection.js +9 -3
  85. package/dist/resource_clients/user.d.ts +19 -10
  86. package/dist/resource_clients/user.js +42 -38
  87. package/dist/resource_clients/webhook.d.ts +17 -8
  88. package/dist/resource_clients/webhook.js +30 -22
  89. package/dist/resource_clients/webhook_collection.d.ts +8 -4
  90. package/dist/resource_clients/webhook_collection.js +9 -3
  91. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  92. package/dist/resource_clients/webhook_dispatch.js +7 -2
  93. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  94. package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
  95. package/dist/runtime/node.d.ts +6 -0
  96. package/dist/runtime/node.js +49 -0
  97. package/dist/runtime/types.d.ts +52 -0
  98. package/dist/runtime/types.js +1 -0
  99. package/dist/runtime/web.d.ts +5 -0
  100. package/dist/runtime/web.js +18 -0
  101. package/dist/schemas.d.ts +1 -1
  102. package/dist/schemas.js +1 -1
  103. package/dist/statistics.d.ts +1 -6
  104. package/dist/statistics.js +2 -2
  105. package/dist/timeouts.d.ts +84 -0
  106. package/dist/timeouts.js +37 -0
  107. package/dist/timezones.d.ts +1 -1
  108. package/dist/utils.d.ts +89 -53
  109. package/dist/utils.js +214 -161
  110. package/dist/wait_for_resources.d.ts +8 -0
  111. package/dist/wait_for_resources.js +39 -0
  112. package/package.json +32 -29
  113. package/dist/http_client.d.ts +0 -88
  114. package/dist/http_client.js +0 -255
  115. package/dist/interceptors.d.ts +0 -19
  116. package/dist/interceptors.js +0 -105
@@ -1,24 +1,30 @@
1
1
  import { z } from 'zod';
2
2
  import log from '@apify/log';
3
3
  import { createHmacSignatureAsync, createStorageContentSignatureAsync } from '@apify/utilities';
4
- import { DEFAULT_TIMEOUT_MILLIS, MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS, } from '../base/resource_client.js';
4
+ import { ResourceClient } from '../base/resource_client.js';
5
5
  import * as schemas from '../schemas.js';
6
- import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isBuffer, isNode, isStream, parseArgument, parseResponse, } from '../utils.js';
6
+ import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
7
+ import { runtime } from '#runtime';
8
+ import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isBuffer, isStream, minForLimitParam, parseArgument, parseResponse, } from '../utils.js';
7
9
  const listKeysOptionsSchema = z.strictObject({
8
10
  limit: z.number().min(0).optional(),
11
+ chunkSize: z.number().positive().optional(),
9
12
  exclusiveStartKey: z.string().optional(),
10
13
  collection: z.string().optional(),
11
14
  prefix: z.string().optional(),
12
15
  signature: z.string().optional(),
16
+ ...timeoutOptionsShape,
13
17
  });
14
18
  const nonEmptyKeySchema = z.string().min(1);
15
- // `signature` is left out - this method produces one. The options type omits it to match.
19
+ // `chunkSize` (client-side only) and `signature` (which this method produces) are left out. The options type omits
20
+ // both to match.
16
21
  const createKeysPublicUrlOptionsSchema = z.strictObject({
17
22
  limit: z.number().min(0).optional(),
18
23
  exclusiveStartKey: z.string().optional(),
19
24
  collection: z.string().optional(),
20
25
  prefix: z.string().optional(),
21
26
  expiresInSecs: z.number().optional(),
27
+ ...timeoutOptionsShape,
22
28
  });
23
29
  const keySchema = z.string();
24
30
  const getRecordOptionsSchema = z.strictObject({
@@ -26,6 +32,7 @@ const getRecordOptionsSchema = z.strictObject({
26
32
  stream: z.boolean().optional(),
27
33
  disableRedirect: z.boolean().optional(),
28
34
  signature: z.string().optional(),
35
+ ...timeoutOptionsShape,
29
36
  });
30
37
  const recordSchema = z.strictObject({
31
38
  key: z.string(),
@@ -37,11 +44,11 @@ const recordSchema = z.strictObject({
37
44
  typeof value !== 'symbol' &&
38
45
  typeof value !== 'bigint' &&
39
46
  typeof value !== 'function' &&
40
- (typeof value !== 'number' || Number.isFinite(value)), 'Expected a defined, JSON-serializable value'),
47
+ (typeof value !== 'number' || Number.isFinite(value)), 'Expected a JSON-serializable value, binary data, or a stream'),
41
48
  contentType: z.string().min(1).optional(),
42
49
  });
43
50
  const recordOptionsSchema = z.strictObject({
44
- timeoutSecs: z.number().optional(),
51
+ ...timeoutOptionsShape,
45
52
  doNotRetryTimeouts: z.boolean().optional(),
46
53
  });
47
54
  /**
@@ -85,11 +92,14 @@ export class KeyValueStoreClient extends ResourceClient {
85
92
  /**
86
93
  * Gets the key-value store object from the Apify API.
87
94
  *
95
+ * @param options - Request options
96
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
88
97
  * @returns The KeyValueStore object, or `undefined` if it does not exist
89
98
  * @see https://docs.apify.com/api/v2/key-value-store-get
90
99
  */
91
- async get() {
92
- return this._get(schemas.KeyValueStore(), {}, SMALL_TIMEOUT_MILLIS);
100
+ async get(options = {}) {
101
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
102
+ return this.getResource(schemas.KeyValueStoreResource(), {}, timeoutSecs, signal);
93
103
  }
94
104
  /**
95
105
  * Updates the key-value store with specified fields.
@@ -98,20 +108,26 @@ export class KeyValueStoreClient extends ResourceClient {
98
108
  * @param newFields.name - New name for the store
99
109
  * @param newFields.title - New title for the store
100
110
  * @param newFields.generalAccess - General resource access level ('FOLLOW_USER_SETTING', 'ANYONE_WITH_ID_CAN_READ' or 'RESTRICTED')
111
+ * @param options - Request options
112
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
101
113
  * @returns The updated KeyValueStore object
102
114
  * @see https://docs.apify.com/api/v2/key-value-store-put
103
115
  */
104
- async update(newFields) {
116
+ async update(newFields, options = {}) {
105
117
  parseArgument(newFields, anyObjectSchema);
106
- return this._update(schemas.KeyValueStore(), newFields, DEFAULT_TIMEOUT_MILLIS);
118
+ const { timeoutSecs = 'long', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
119
+ return this.updateResource(schemas.KeyValueStoreResource(), newFields, timeoutSecs, signal);
107
120
  }
108
121
  /**
109
122
  * Deletes the key-value store.
110
123
  *
124
+ * @param options - Request options
125
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
111
126
  * @see https://docs.apify.com/api/v2/key-value-store-delete
112
127
  */
113
- async delete() {
114
- return this._delete(SMALL_TIMEOUT_MILLIS);
128
+ async delete(options = {}) {
129
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
130
+ return this.deleteResource(timeoutSecs, signal);
115
131
  }
116
132
  /**
117
133
  * Lists all keys in the key-value store.
@@ -121,9 +137,12 @@ export class KeyValueStoreClient extends ResourceClient {
121
137
  *
122
138
  * @param options - Listing options
123
139
  * @param options.limit - Maximum number of keys to return. Default is 1000.
140
+ * @param options.chunkSize - Maximum number of keys requested per API call when iterating across pages. `limit`
141
+ * then caps the total across all pages.
124
142
  * @param options.exclusiveStartKey - Key to start listing from (for pagination). The listing starts with the next key after this one.
125
143
  * @param options.collection - Filter keys by collection name.
126
144
  * @param options.prefix - Filter keys that start with this prefix.
145
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
127
146
  * @returns Object containing `items` array of key metadata, pagination info (`count`, `limit`, `isTruncated`, `nextExclusiveStartKey`)
128
147
  * @see https://docs.apify.com/api/v2/key-value-store-keys-get
129
148
  *
@@ -149,17 +168,19 @@ export class KeyValueStoreClient extends ResourceClient {
149
168
  * ```
150
169
  */
151
170
  listKeys(options = {}) {
152
- const parsed = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
171
+ // `chunkSize` only sizes the page requests; it is not an API parameter, so it must not reach the query string.
172
+ const { chunkSize, timeoutSecs = 'medium', signal, ...parsed } = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
153
173
  const getPaginatedList = async (kvsListOptions = {}) => {
154
174
  const response = await this.httpClient.call({
155
- url: this._url('keys'),
175
+ url: this.buildUrl('keys'),
156
176
  method: 'GET',
157
- params: this._params(kvsListOptions),
158
- timeout: MEDIUM_TIMEOUT_MILLIS,
177
+ params: this.buildParams(kvsListOptions),
178
+ timeoutSecs,
179
+ signal,
159
180
  });
160
181
  return parseResponse(response, schemas.ListOfKeys());
161
182
  };
162
- const paginatedListPromise = getPaginatedList(parsed);
183
+ const paginatedListPromise = getPaginatedList({ ...parsed, limit: minForLimitParam(parsed.limit, chunkSize) });
163
184
  async function* asyncGenerator() {
164
185
  let currentPage = await paginatedListPromise;
165
186
  yield* currentPage.items;
@@ -172,7 +193,7 @@ export class KeyValueStoreClient extends ResourceClient {
172
193
  ) {
173
194
  const newOptions = {
174
195
  ...parsed,
175
- limit: remainingItems,
196
+ limit: minForLimitParam(remainingItems, chunkSize),
176
197
  exclusiveStartKey: currentPage.nextExclusiveStartKey,
177
198
  };
178
199
  currentPage = await getPaginatedList(newOptions);
@@ -194,6 +215,8 @@ export class KeyValueStoreClient extends ResourceClient {
194
215
  * requiring an API token.
195
216
  *
196
217
  * @param key - The record key
218
+ * @param options - Request options
219
+ * @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
197
220
  * @returns A public URL string for accessing the record
198
221
  *
199
222
  * @example
@@ -204,10 +227,11 @@ export class KeyValueStoreClient extends ResourceClient {
204
227
  * ```
205
228
  * @since Added in 2.14.0
206
229
  */
207
- async getRecordPublicUrl(key) {
230
+ async getRecordPublicUrl(key, options = {}) {
208
231
  parseArgument(key, nonEmptyKeySchema);
209
- const store = await this.get();
210
- const recordPublicUrl = new URL(this._publicUrl(['records', key]));
232
+ const { timeoutSecs = 'long', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
233
+ const store = await this.get({ timeoutSecs, signal });
234
+ const recordPublicUrl = new URL(this.buildPublicUrl(['records', key]));
211
235
  if (store?.urlSigningSecretKey) {
212
236
  const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
213
237
  recordPublicUrl.searchParams.append('signature', signature);
@@ -224,6 +248,7 @@ export class KeyValueStoreClient extends ResourceClient {
224
248
  * @param options.expiresInSecs - Number of seconds until the signed URL expires. If omitted, the URL never expires.
225
249
  * @param options.limit - Maximum number of keys to return.
226
250
  * @param options.prefix - Filter keys by prefix.
251
+ * @param options.timeoutSecs - Timeout for the API request that fetches the store. Default is `'long'`.
227
252
  * @returns A public URL string for accessing the keys list
228
253
  *
229
254
  * @example
@@ -238,10 +263,9 @@ export class KeyValueStoreClient extends ResourceClient {
238
263
  * @since Added in 2.13.0
239
264
  */
240
265
  async createKeysPublicUrl(options = {}) {
241
- const parsed = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
242
- const store = await this.get();
243
- const { expiresInSecs, ...queryOptions } = parsed;
244
- let createdPublicKeysUrl = new URL(this._publicUrl('keys'));
266
+ const { timeoutSecs = 'long', signal, expiresInSecs, ...queryOptions } = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
267
+ const store = await this.get({ timeoutSecs, signal });
268
+ let createdPublicKeysUrl = new URL(this.buildPublicUrl('keys'));
245
269
  if (store?.urlSigningSecretKey) {
246
270
  const signature = await createStorageContentSignatureAsync({
247
271
  resourceId: store.id,
@@ -259,6 +283,8 @@ export class KeyValueStoreClient extends ResourceClient {
259
283
  * This is more efficient than {@link getRecord} when you only need to check for existence.
260
284
  *
261
285
  * @param key - The record key to check
286
+ * @param options - Request options
287
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
262
288
  * @returns `true` if the record exists, `false` if it does not
263
289
  * @see https://docs.apify.com/api/v2/key-value-store-record-get
264
290
  *
@@ -271,11 +297,14 @@ export class KeyValueStoreClient extends ResourceClient {
271
297
  * ```
272
298
  * @since Added in 2.9.0
273
299
  */
274
- async recordExists(key) {
300
+ async recordExists(key, options = {}) {
301
+ const { timeoutSecs = 'long', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
275
302
  const requestOpts = {
276
- url: this._url(['records', key]),
303
+ url: this.buildUrl(['records', key]),
277
304
  method: 'HEAD',
278
- params: this._params(),
305
+ params: this.buildParams(),
306
+ timeoutSecs,
307
+ signal,
279
308
  };
280
309
  try {
281
310
  await this.httpClient.call(requestOpts);
@@ -289,7 +318,7 @@ export class KeyValueStoreClient extends ResourceClient {
289
318
  async getRecord(key, options = {}) {
290
319
  parseArgument(key, keySchema);
291
320
  const parsed = parseArgument(options, getRecordOptionsSchema, 'KeyValueClientGetRecordOptions');
292
- if (parsed.stream && !isNode()) {
321
+ if (parsed.stream && !runtime.isNode) {
293
322
  throw new Error('The stream option can only be used in Node.js environment.');
294
323
  }
295
324
  if ('disableRedirect' in parsed) {
@@ -300,13 +329,14 @@ export class KeyValueStoreClient extends ResourceClient {
300
329
  if (parsed.signature)
301
330
  queryParams.signature = parsed.signature;
302
331
  const requestOpts = {
303
- url: this._url(['records', key]),
332
+ url: this.buildUrl(['records', key]),
304
333
  method: 'GET',
305
- params: this._params(queryParams),
306
- timeout: DEFAULT_TIMEOUT_MILLIS,
334
+ params: this.buildParams(queryParams),
335
+ timeoutSecs: parsed.timeoutSecs ?? 'long',
336
+ signal: parsed.signal,
307
337
  };
308
338
  if (parsed.buffer)
309
- requestOpts.forceBuffer = true;
339
+ requestOpts.responseType = 'buffer';
310
340
  if (parsed.stream)
311
341
  requestOpts.responseType = 'stream';
312
342
  try {
@@ -329,19 +359,27 @@ export class KeyValueStoreClient extends ResourceClient {
329
359
  * The content type is automatically determined based on the value type, but can be
330
360
  * overridden using the `contentType` property.
331
361
  *
362
+ * A string is sent as it is, even under `application/json`, so a string stored under a JSON content type has
363
+ * to be valid JSON already, or {@link getRecord} fails to parse it back.
364
+ *
332
365
  * **Note about streams:** If the value is a stream object (has `.pipe` and `.on` methods),
333
366
  * the upload cannot be retried on failure or follow redirects. For reliable uploads,
334
367
  * buffer the entire stream into memory first.
335
368
  *
336
369
  * @param record - The record to store
337
370
  * @param record.key - Record key (unique identifier)
338
- * @param record.value - Record value (object, string, Buffer, or Stream)
371
+ * @param record.value - Record value (a JSON-serializable value, Buffer, ArrayBuffer, typed array, or Readable)
339
372
  * @param record.contentType - Optional MIME type. Auto-detected if not provided:
340
373
  * - Objects: `'application/json; charset=utf-8'`
341
374
  * - Strings: `'text/plain; charset=utf-8'`
342
- * - Buffers/Streams: `'application/octet-stream'`
375
+ * - Binary values and streams: `'application/octet-stream'`
376
+ *
377
+ * Worth setting for media and archives: the client skips compressing a body
378
+ * whose content type already carries its own compression. The
379
+ * `'application/octet-stream'` fallback is treated as compressible, because
380
+ * it could hold any binary data.
343
381
  * @param options - Storage options
344
- * @param options.timeoutSecs - Timeout for the upload in seconds. Default varies by value size.
382
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
345
383
  * @param options.doNotRetryTimeouts - If `true`, don't retry on timeout errors. Default is `false`.
346
384
  * @see https://docs.apify.com/api/v2/key-value-store-record-put
347
385
  *
@@ -374,7 +412,7 @@ export class KeyValueStoreClient extends ResourceClient {
374
412
  const parsed = parseArgument(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
375
413
  const { key } = record;
376
414
  let { value, contentType } = record;
377
- const { timeoutSecs, doNotRetryTimeouts } = parsed;
415
+ const { timeoutSecs = 'long', signal, doNotRetryTimeouts } = parsed;
378
416
  const isValueStreamOrBuffer = isStream(value) || isBuffer(value);
379
417
  // To allow saving Objects to JSON without providing content type
380
418
  if (!contentType) {
@@ -396,13 +434,14 @@ export class KeyValueStoreClient extends ResourceClient {
396
434
  }
397
435
  }
398
436
  const uploadOpts = {
399
- url: this._url(['records', key]),
437
+ url: this.buildUrl(['records', key]),
400
438
  method: 'PUT',
401
- params: this._params(),
439
+ params: this.buildParams(),
402
440
  data: value,
403
441
  headers: contentType ? { 'content-type': contentType } : undefined,
404
442
  doNotRetryTimeouts,
405
- timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 : DEFAULT_TIMEOUT_MILLIS,
443
+ timeoutSecs,
444
+ signal,
406
445
  };
407
446
  await this.httpClient.call(uploadOpts);
408
447
  }
@@ -410,6 +449,8 @@ export class KeyValueStoreClient extends ResourceClient {
410
449
  * Deletes a record from the key-value store.
411
450
  *
412
451
  * @param key - The record key to delete
452
+ * @param options - Request options
453
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
413
454
  * @see https://docs.apify.com/api/v2/key-value-store-record-delete
414
455
  *
415
456
  * @example
@@ -417,13 +458,15 @@ export class KeyValueStoreClient extends ResourceClient {
417
458
  * await client.keyValueStore('my-store').deleteRecord('temp-data');
418
459
  * ```
419
460
  */
420
- async deleteRecord(key) {
461
+ async deleteRecord(key, options = {}) {
421
462
  parseArgument(key, keySchema);
463
+ const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
422
464
  await this.httpClient.call({
423
- url: this._url(['records', key]),
465
+ url: this.buildUrl(['records', key]),
424
466
  method: 'DELETE',
425
- params: this._params(),
426
- timeout: SMALL_TIMEOUT_MILLIS,
467
+ params: this.buildParams(),
468
+ timeoutSecs,
469
+ signal,
427
470
  });
428
471
  }
429
472
  }
@@ -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 { KeyValueStore } from './key_value_store.js';
6
+ import type { KeyValueStoreResource } from './key_value_store.js';
6
7
  /**
7
8
  * Client for managing the collection of Key-value stores in your account.
8
9
  *
@@ -45,21 +46,24 @@ 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
  */
51
- list(options?: KeyValueStoreCollectionClientListOptions): Promise<KeyValueStoreCollectionListResult> & AsyncIterable<KeyValueStore>;
53
+ list(options?: KeyValueStoreCollectionClientListOptions): Promise<KeyValueStoreCollectionListResult> & AsyncIterable<KeyValueStoreResource>;
52
54
  /**
53
55
  * Gets or creates a key-value store with the specified name.
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
- getOrCreate(name?: string, options?: KeyValueStoreCollectionClientGetOrCreateOptions): Promise<KeyValueStore>;
64
+ getOrCreate(name?: string, options?: KeyValueStoreCollectionClientGetOrCreateOptions): Promise<KeyValueStoreResource>;
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,9 +75,9 @@ 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
- export type KeyValueStoreCollectionListResult = PaginatedList<KeyValueStore> & {
81
+ export type KeyValueStoreCollectionListResult = PaginatedList<KeyValueStoreResource> & {
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 KeyValueStoreCollectionClient 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 Key-value stores.
62
65
  * @see https://docs.apify.com/api/v2/key-value-stores-get
63
66
  */
64
67
  list(options = {}) {
65
68
  const parsed = parseArgument(options, listOptionsSchema, 'KeyValueStoreCollectionClientListOptions');
66
- return this._listPaginated(schemas.ListOfKeyValueStores(), parsed);
69
+ return this.listResourcesPaginated(schemas.ListOfKeyValueStores(), parsed, 'medium');
67
70
  }
68
71
  /**
69
72
  * Gets or creates a key-value store with the specified name.
70
73
  *
71
74
  * @param name - Name of the key-value store. If not provided, a default store is used.
72
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'`.
73
78
  * @returns The key-value store object.
74
79
  * @see https://docs.apify.com/api/v2/key-value-stores-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.KeyValueStore(), 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.KeyValueStoreResource(), name, hasResource ? resource : undefined, timeoutSecs, signal);
80
91
  }
81
92
  }
@@ -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
- * @returns The log content as a string, or `undefined` if it does not exist.
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
- * @returns The log content as a Readable stream, or `undefined` if it does not exist.
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,31 +74,17 @@ export declare class LoggerActorRedirect extends Logger {
69
74
  * @since Added in 2.20.0
70
75
  */
71
76
  export declare class StreamedLog {
72
- private destinationLog;
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.
82
81
  */
83
82
  start(): void;
84
83
  /**
85
- * Stop log redirection.
84
+ * Stop log redirection. Waits up to one second for lines already in flight, then aborts the log stream request. If
85
+ * no stream has delivered anything yet, reads the whole log in one request instead.
86
86
  */
87
87
  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
88
  }
98
89
  /**
99
90
  * @since Added in 2.20.0
@@ -105,4 +96,6 @@ export interface StreamedLogOptions {
105
96
  toLog: Log;
106
97
  /** Whether to redirect all logs from Actor run start (even logs from the past). */
107
98
  fromStart?: boolean;
99
+ /** Ends the log stream once it aborts. */
100
+ signal?: AbortSignal;
108
101
  }