apify-client 3.0.0-beta.4 → 3.0.0-beta.40

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