apify-client 3.0.0-beta.0 → 3.0.0-beta.2

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 (84) hide show
  1. package/README.md +2 -2
  2. package/dist/apify_api_error.js +5 -9
  3. package/dist/apify_client.d.ts +27 -27
  4. package/dist/apify_client.js +86 -91
  5. package/dist/argument_validation_error.js +1 -5
  6. package/dist/base/api_client.d.ts +3 -3
  7. package/dist/base/api_client.js +6 -10
  8. package/dist/base/resource_client.d.ts +1 -1
  9. package/dist/base/resource_client.js +14 -18
  10. package/dist/base/resource_collection_client.d.ts +2 -2
  11. package/dist/base/resource_collection_client.js +6 -10
  12. package/dist/body_parser.js +6 -11
  13. package/dist/bundle.js +8 -8
  14. package/dist/bundle.js.map +1 -1
  15. package/dist/generated/api.d.ts +20522 -0
  16. package/dist/generated/api.js +5 -0
  17. package/dist/http_client.d.ts +2 -2
  18. package/dist/http_client.js +23 -28
  19. package/dist/index.d.ts +32 -32
  20. package/dist/index.js +31 -36
  21. package/dist/interceptors.d.ts +1 -1
  22. package/dist/interceptors.js +14 -19
  23. package/dist/models.d.ts +1072 -0
  24. package/dist/models.js +86 -0
  25. package/dist/resource_clients/actor.d.ts +13 -459
  26. package/dist/resource_clients/actor.js +67 -71
  27. package/dist/resource_clients/actor_collection.d.ts +7 -12
  28. package/dist/resource_clients/actor_collection.js +14 -18
  29. package/dist/resource_clients/actor_env_var.d.ts +3 -3
  30. package/dist/resource_clients/actor_env_var.js +4 -8
  31. package/dist/resource_clients/actor_env_var_collection.d.ts +4 -4
  32. package/dist/resource_clients/actor_env_var_collection.js +5 -9
  33. package/dist/resource_clients/actor_version.d.ts +7 -44
  34. package/dist/resource_clients/actor_version.js +12 -22
  35. package/dist/resource_clients/actor_version_collection.d.ts +4 -4
  36. package/dist/resource_clients/actor_version_collection.js +5 -9
  37. package/dist/resource_clients/build.d.ts +5 -80
  38. package/dist/resource_clients/build.js +11 -15
  39. package/dist/resource_clients/build_collection.d.ts +5 -5
  40. package/dist/resource_clients/build_collection.js +8 -12
  41. package/dist/resource_clients/dataset.d.ts +5 -71
  42. package/dist/resource_clients/dataset.js +72 -76
  43. package/dist/resource_clients/dataset_collection.d.ts +4 -4
  44. package/dist/resource_clients/dataset_collection.js +15 -19
  45. package/dist/resource_clients/key_value_store.d.ts +4 -73
  46. package/dist/resource_clients/key_value_store.js +60 -63
  47. package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
  48. package/dist/resource_clients/key_value_store_collection.js +15 -19
  49. package/dist/resource_clients/log.d.ts +2 -2
  50. package/dist/resource_clients/log.js +15 -22
  51. package/dist/resource_clients/request_queue.d.ts +17 -176
  52. package/dist/resource_clients/request_queue.js +93 -98
  53. package/dist/resource_clients/request_queue_collection.d.ts +4 -4
  54. package/dist/resource_clients/request_queue_collection.js +13 -17
  55. package/dist/resource_clients/run.d.ts +8 -8
  56. package/dist/resource_clients/run.js +46 -50
  57. package/dist/resource_clients/run_collection.d.ts +4 -4
  58. package/dist/resource_clients/run_collection.js +13 -17
  59. package/dist/resource_clients/schedule.d.ts +6 -84
  60. package/dist/resource_clients/schedule.js +7 -18
  61. package/dist/resource_clients/schedule_collection.d.ts +4 -4
  62. package/dist/resource_clients/schedule_collection.js +10 -14
  63. package/dist/resource_clients/store_collection.d.ts +5 -33
  64. package/dist/resource_clients/store_collection.js +13 -17
  65. package/dist/resource_clients/task.d.ts +9 -79
  66. package/dist/resource_clients/task.js +44 -48
  67. package/dist/resource_clients/task_collection.d.ts +6 -5
  68. package/dist/resource_clients/task_collection.js +9 -13
  69. package/dist/resource_clients/user.d.ts +5 -181
  70. package/dist/resource_clients/user.js +8 -21
  71. package/dist/resource_clients/webhook.d.ts +6 -65
  72. package/dist/resource_clients/webhook.js +8 -12
  73. package/dist/resource_clients/webhook_collection.d.ts +4 -4
  74. package/dist/resource_clients/webhook_collection.js +10 -14
  75. package/dist/resource_clients/webhook_dispatch.d.ts +5 -38
  76. package/dist/resource_clients/webhook_dispatch.js +3 -12
  77. package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
  78. package/dist/resource_clients/webhook_dispatch_collection.js +8 -12
  79. package/dist/statistics.js +5 -9
  80. package/dist/timezones.js +1 -2
  81. package/dist/utils.d.ts +3 -3
  82. package/dist/utils.js +41 -56
  83. package/package.json +16 -9
  84. package/dist/index.mjs +0 -42
@@ -1,8 +1,10 @@
1
1
  import type { Readable } from 'node:stream';
2
2
  import type { JsonValue } from 'type-fest';
3
3
  import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
4
- import type { ApiClientSubResourceOptions } from '../base/api_client';
5
- import { ResourceClient } from '../base/resource_client';
4
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
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
8
  /**
7
9
  * Client for managing a specific key-value store.
8
10
  *
@@ -231,53 +233,6 @@ export declare class KeyValueStoreClient extends ResourceClient {
231
233
  */
232
234
  deleteRecord(key: string): Promise<void>;
233
235
  }
234
- /**
235
- * Represents a Key-Value Store storage on the Apify platform.
236
- *
237
- * Key-value stores are used to store arbitrary data records or files. Each record is identified
238
- * by a unique key and can contain any data - JSON objects, strings, binary files, etc.
239
- */
240
- export interface KeyValueStore {
241
- id: string;
242
- name?: string;
243
- /**
244
- * @since Added in 2.6.1
245
- */
246
- title?: string;
247
- userId: string;
248
- /**
249
- * @since Added in 2.21.0
250
- */
251
- username?: string;
252
- createdAt: Date;
253
- modifiedAt: Date;
254
- accessedAt: Date;
255
- actId?: string;
256
- actRunId?: string;
257
- stats?: KeyValueStoreStats;
258
- /**
259
- * @since Added in 2.12.2
260
- */
261
- generalAccess?: STORAGE_GENERAL_ACCESS | null;
262
- /**
263
- * @since Added in 2.13.0
264
- */
265
- urlSigningSecretKey?: string | null;
266
- /**
267
- * @since Added in 2.13.0
268
- */
269
- keysPublicUrl: string;
270
- }
271
- /**
272
- * Statistics about Key-Value Store usage and storage.
273
- */
274
- export interface KeyValueStoreStats {
275
- readCount?: number;
276
- writeCount?: number;
277
- deleteCount?: number;
278
- listCount?: number;
279
- storageBytes?: number;
280
- }
281
236
  /**
282
237
  * Options for updating a Key-Value Store.
283
238
  */
@@ -318,30 +273,6 @@ export interface KeyValueClientListKeysOptions {
318
273
  export interface KeyValueClientCreateKeysUrlOptions extends Omit<KeyValueClientListKeysOptions, 'signature'> {
319
274
  expiresInSecs?: number;
320
275
  }
321
- /**
322
- * Result of listing keys in a Key-Value Store.
323
- *
324
- * Contains paginated list of keys with metadata and pagination information.
325
- */
326
- export interface KeyValueClientListKeysResult {
327
- count: number;
328
- limit: number;
329
- exclusiveStartKey: string;
330
- isTruncated: boolean;
331
- nextExclusiveStartKey: string;
332
- items: KeyValueListItem[];
333
- }
334
- /**
335
- * Metadata about a single key in a Key-Value Store.
336
- */
337
- export interface KeyValueListItem {
338
- key: string;
339
- size: number;
340
- /**
341
- * @since Added in 2.15.1
342
- */
343
- recordPublicUrl: string;
344
- }
345
276
  /**
346
277
  * Options for retrieving a record from a Key-Value Store.
347
278
  */
@@ -1,51 +1,47 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeyValueStoreClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const zod_1 = require("zod");
6
- const log_1 = tslib_1.__importDefault(require("@apify/log"));
7
- const utilities_1 = require("@apify/utilities");
8
- const resource_client_1 = require("../base/resource_client");
9
- const utils_1 = require("../utils");
10
- const listKeysOptionsSchema = zod_1.z.strictObject({
11
- limit: zod_1.z.number().min(0).optional(),
12
- exclusiveStartKey: zod_1.z.string().optional(),
13
- collection: zod_1.z.string().optional(),
14
- prefix: zod_1.z.string().optional(),
15
- signature: zod_1.z.string().optional(),
1
+ import { z } from 'zod';
2
+ import log from '@apify/log';
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';
6
+ const listKeysOptionsSchema = z.strictObject({
7
+ limit: z.number().min(0).optional(),
8
+ exclusiveStartKey: z.string().optional(),
9
+ collection: z.string().optional(),
10
+ prefix: z.string().optional(),
11
+ signature: z.string().optional(),
16
12
  });
17
- const nonEmptyKeySchema = zod_1.z.string().min(1);
13
+ const nonEmptyKeySchema = z.string().min(1);
18
14
  // `signature` is left out - this method produces one. The options type omits it to match.
19
- const createKeysPublicUrlOptionsSchema = zod_1.z.strictObject({
20
- limit: zod_1.z.number().min(0).optional(),
21
- exclusiveStartKey: zod_1.z.string().optional(),
22
- collection: zod_1.z.string().optional(),
23
- prefix: zod_1.z.string().optional(),
24
- expiresInSecs: zod_1.z.number().optional(),
15
+ const createKeysPublicUrlOptionsSchema = z.strictObject({
16
+ limit: z.number().min(0).optional(),
17
+ exclusiveStartKey: z.string().optional(),
18
+ collection: z.string().optional(),
19
+ prefix: z.string().optional(),
20
+ expiresInSecs: z.number().optional(),
25
21
  });
26
- const keySchema = zod_1.z.string();
27
- const getRecordOptionsSchema = zod_1.z.strictObject({
28
- buffer: zod_1.z.boolean().optional(),
29
- stream: zod_1.z.boolean().optional(),
30
- disableRedirect: zod_1.z.boolean().optional(),
31
- signature: zod_1.z.string().optional(),
22
+ const keySchema = z.string();
23
+ const getRecordOptionsSchema = z.strictObject({
24
+ buffer: z.boolean().optional(),
25
+ stream: z.boolean().optional(),
26
+ disableRedirect: z.boolean().optional(),
27
+ signature: z.string().optional(),
32
28
  });
33
- const recordSchema = zod_1.z.strictObject({
34
- key: zod_1.z.string(),
29
+ const recordSchema = z.strictObject({
30
+ key: z.string(),
35
31
  // Values are arbitrary, and a `z.object()` arm would walk every key of a large buffer.
36
32
  // Symbols, bigints, functions and non-finite numbers are rejected because they cannot be serialized
37
33
  // to JSON - symbols and bigints throw, functions stringify to `undefined` (an empty request body),
38
34
  // and `NaN` / `Infinity` would silently become `null`.
39
- value: zod_1.z.custom((value) => value !== undefined &&
35
+ value: z.custom((value) => value !== undefined &&
40
36
  typeof value !== 'symbol' &&
41
37
  typeof value !== 'bigint' &&
42
38
  typeof value !== 'function' &&
43
39
  (typeof value !== 'number' || Number.isFinite(value)), 'Expected a defined, JSON-serializable value'),
44
- contentType: zod_1.z.string().min(1).optional(),
40
+ contentType: z.string().min(1).optional(),
45
41
  });
46
- const recordOptionsSchema = zod_1.z.strictObject({
47
- timeoutSecs: zod_1.z.number().optional(),
48
- doNotRetryTimeouts: zod_1.z.boolean().optional(),
42
+ const recordOptionsSchema = z.strictObject({
43
+ timeoutSecs: z.number().optional(),
44
+ doNotRetryTimeouts: z.boolean().optional(),
49
45
  });
50
46
  /**
51
47
  * Client for managing a specific key-value store.
@@ -75,7 +71,7 @@ const recordOptionsSchema = zod_1.z.strictObject({
75
71
  *
76
72
  * @see https://docs.apify.com/platform/storage/key-value-store
77
73
  */
78
- class KeyValueStoreClient extends resource_client_1.ResourceClient {
74
+ export class KeyValueStoreClient extends ResourceClient {
79
75
  /**
80
76
  * @hidden
81
77
  */
@@ -92,7 +88,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
92
88
  * @see https://docs.apify.com/api/v2/key-value-store-get
93
89
  */
94
90
  async get() {
95
- return this._get({}, resource_client_1.SMALL_TIMEOUT_MILLIS);
91
+ return this._get({}, SMALL_TIMEOUT_MILLIS);
96
92
  }
97
93
  /**
98
94
  * Updates the key-value store with specified fields.
@@ -105,8 +101,8 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
105
101
  * @see https://docs.apify.com/api/v2/key-value-store-put
106
102
  */
107
103
  async update(newFields) {
108
- (0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
109
- return this._update(newFields, resource_client_1.DEFAULT_TIMEOUT_MILLIS);
104
+ parseArgument(newFields, anyObjectSchema);
105
+ return this._update(newFields, DEFAULT_TIMEOUT_MILLIS);
110
106
  }
111
107
  /**
112
108
  * Deletes the key-value store.
@@ -114,7 +110,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
114
110
  * @see https://docs.apify.com/api/v2/key-value-store-delete
115
111
  */
116
112
  async delete() {
117
- return this._delete(resource_client_1.SMALL_TIMEOUT_MILLIS);
113
+ return this._delete(SMALL_TIMEOUT_MILLIS);
118
114
  }
119
115
  /**
120
116
  * Lists all keys in the key-value store.
@@ -152,15 +148,15 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
152
148
  * ```
153
149
  */
154
150
  listKeys(options = {}) {
155
- const parsed = (0, utils_1.parseArgument)(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
151
+ const parsed = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
156
152
  const getPaginatedList = async (kvsListOptions = {}) => {
157
153
  const response = await this.httpClient.call({
158
154
  url: this._url('keys'),
159
155
  method: 'GET',
160
156
  params: this._params(kvsListOptions),
161
- timeout: resource_client_1.MEDIUM_TIMEOUT_MILLIS,
157
+ timeout: MEDIUM_TIMEOUT_MILLIS,
162
158
  });
163
- return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
159
+ return cast(parseDateFields(pluckData(response.data)));
164
160
  };
165
161
  const paginatedListPromise = getPaginatedList(parsed);
166
162
  async function* asyncGenerator() {
@@ -168,7 +164,9 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
168
164
  yield* currentPage.items;
169
165
  let remainingItems = parsed.limit ? parsed.limit - currentPage.items.length : undefined;
170
166
  while (currentPage.items.length > 0 && // Continue only if at least some items were returned in the last page.
171
- currentPage.nextExclusiveStartKey !== null && // Continue only if there is some next key.
167
+ // Continue only if there is some next key. The API answers with `null` on the last page and
168
+ // omits the field entirely for a listing that was not truncated.
169
+ currentPage.nextExclusiveStartKey != null &&
172
170
  (remainingItems === undefined || remainingItems > 0) // Continue only if the limit was not exceeded.
173
171
  ) {
174
172
  const newOptions = {
@@ -206,11 +204,11 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
206
204
  * @since Added in 2.14.0
207
205
  */
208
206
  async getRecordPublicUrl(key) {
209
- (0, utils_1.parseArgument)(key, nonEmptyKeySchema);
207
+ parseArgument(key, nonEmptyKeySchema);
210
208
  const store = await this.get();
211
209
  const recordPublicUrl = new URL(this._publicUrl(['records', key]));
212
210
  if (store?.urlSigningSecretKey) {
213
- const signature = await (0, utilities_1.createHmacSignatureAsync)(store.urlSigningSecretKey, key);
211
+ const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
214
212
  recordPublicUrl.searchParams.append('signature', signature);
215
213
  }
216
214
  return recordPublicUrl.toString();
@@ -239,19 +237,19 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
239
237
  * @since Added in 2.13.0
240
238
  */
241
239
  async createKeysPublicUrl(options = {}) {
242
- const parsed = (0, utils_1.parseArgument)(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
240
+ const parsed = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
243
241
  const store = await this.get();
244
242
  const { expiresInSecs, ...queryOptions } = parsed;
245
243
  let createdPublicKeysUrl = new URL(this._publicUrl('keys'));
246
244
  if (store?.urlSigningSecretKey) {
247
- const signature = await (0, utilities_1.createStorageContentSignatureAsync)({
245
+ const signature = await createStorageContentSignatureAsync({
248
246
  resourceId: store.id,
249
247
  urlSigningSecretKey: store.urlSigningSecretKey,
250
248
  expiresInMillis: expiresInSecs ? expiresInSecs * 1000 : undefined,
251
249
  });
252
250
  createdPublicKeysUrl.searchParams.set('signature', signature);
253
251
  }
254
- createdPublicKeysUrl = (0, utils_1.applyQueryParamsToUrl)(createdPublicKeysUrl, queryOptions);
252
+ createdPublicKeysUrl = applyQueryParamsToUrl(createdPublicKeysUrl, queryOptions);
255
253
  return createdPublicKeysUrl.toString();
256
254
  }
257
255
  /**
@@ -283,18 +281,18 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
283
281
  return true;
284
282
  }
285
283
  catch (err) {
286
- (0, utils_1.catchNotFoundOrThrow)(err);
284
+ catchNotFoundOrThrow(err);
287
285
  }
288
286
  return false;
289
287
  }
290
288
  async getRecord(key, options = {}) {
291
- (0, utils_1.parseArgument)(key, keySchema);
292
- const parsed = (0, utils_1.parseArgument)(options, getRecordOptionsSchema, 'KeyValueClientGetRecordOptions');
293
- if (parsed.stream && !(0, utils_1.isNode)()) {
289
+ parseArgument(key, keySchema);
290
+ const parsed = parseArgument(options, getRecordOptionsSchema, 'KeyValueClientGetRecordOptions');
291
+ if (parsed.stream && !isNode()) {
294
292
  throw new Error('The stream option can only be used in Node.js environment.');
295
293
  }
296
294
  if ('disableRedirect' in parsed) {
297
- log_1.default.deprecated('The disableRedirect option for getRecord() is deprecated. ' +
295
+ log.deprecated('The disableRedirect option for getRecord() is deprecated. ' +
298
296
  'It has no effect and will be removed in the following major release.');
299
297
  }
300
298
  const queryParams = { attachment: 'true' };
@@ -304,7 +302,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
304
302
  url: this._url(['records', key]),
305
303
  method: 'GET',
306
304
  params: this._params(queryParams),
307
- timeout: resource_client_1.DEFAULT_TIMEOUT_MILLIS,
305
+ timeout: DEFAULT_TIMEOUT_MILLIS,
308
306
  };
309
307
  if (parsed.buffer)
310
308
  requestOpts.forceBuffer = true;
@@ -319,7 +317,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
319
317
  };
320
318
  }
321
319
  catch (err) {
322
- (0, utils_1.catchNotFoundOrThrow)(err);
320
+ catchNotFoundOrThrow(err);
323
321
  }
324
322
  return undefined;
325
323
  }
@@ -371,12 +369,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
371
369
  * ```
372
370
  */
373
371
  async setRecord(record, options = {}) {
374
- (0, utils_1.parseArgument)(record, recordSchema);
375
- const parsed = (0, utils_1.parseArgument)(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
372
+ parseArgument(record, recordSchema);
373
+ const parsed = parseArgument(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
376
374
  const { key } = record;
377
375
  let { value, contentType } = record;
378
376
  const { timeoutSecs, doNotRetryTimeouts } = parsed;
379
- const isValueStreamOrBuffer = (0, utils_1.isStream)(value) || (0, utils_1.isBuffer)(value);
377
+ const isValueStreamOrBuffer = isStream(value) || isBuffer(value);
380
378
  // To allow saving Objects to JSON without providing content type
381
379
  if (!contentType) {
382
380
  if (isValueStreamOrBuffer)
@@ -403,7 +401,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
403
401
  data: value,
404
402
  headers: contentType ? { 'content-type': contentType } : undefined,
405
403
  doNotRetryTimeouts,
406
- timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 : resource_client_1.DEFAULT_TIMEOUT_MILLIS,
404
+ timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 : DEFAULT_TIMEOUT_MILLIS,
407
405
  };
408
406
  await this.httpClient.call(uploadOpts);
409
407
  }
@@ -419,13 +417,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
419
417
  * ```
420
418
  */
421
419
  async deleteRecord(key) {
422
- (0, utils_1.parseArgument)(key, keySchema);
420
+ parseArgument(key, keySchema);
423
421
  await this.httpClient.call({
424
422
  url: this._url(['records', key]),
425
423
  method: 'DELETE',
426
424
  params: this._params(),
427
- timeout: resource_client_1.SMALL_TIMEOUT_MILLIS,
425
+ timeout: SMALL_TIMEOUT_MILLIS,
428
426
  });
429
427
  }
430
428
  }
431
- exports.KeyValueStoreClient = KeyValueStoreClient;
@@ -1,8 +1,8 @@
1
1
  import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
2
- import type { ApiClientSubResourceOptions } from '../base/api_client';
3
- import { ResourceCollectionClient } from '../base/resource_collection_client';
4
- import type { PaginatedList, PaginationOptions } from '../utils';
5
- import type { KeyValueStore } from './key_value_store';
2
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
3
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
4
+ import type { PaginatedList, PaginationOptions } from '../utils.js';
5
+ import type { KeyValueStore } from './key_value_store.js';
6
6
  /**
7
7
  * Client for managing the collection of Key-value stores in your account.
8
8
  *
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeyValueStoreCollectionClient = void 0;
4
- const zod_1 = require("zod");
5
- const consts_1 = require("@apify/consts");
6
- const resource_collection_client_1 = require("../base/resource_collection_client");
7
- const utils_1 = require("../utils");
8
- const listOptionsSchema = zod_1.z.strictObject({
9
- unnamed: zod_1.z.boolean().optional(),
10
- ...utils_1.paginationOptionsShape,
11
- desc: zod_1.z.boolean().optional(),
12
- ownership: zod_1.z.enum(consts_1.STORAGE_OWNERSHIP_FILTER).optional(),
1
+ import { z } from 'zod';
2
+ import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
3
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
4
+ import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
5
+ const listOptionsSchema = z.strictObject({
6
+ unnamed: z.boolean().optional(),
7
+ ...paginationOptionsShape,
8
+ desc: z.boolean().optional(),
9
+ ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
13
10
  });
14
- const nameSchema = zod_1.z.string().optional();
15
- const schemaSchema = utils_1.anyObjectSchema.optional();
11
+ const nameSchema = z.string().optional();
12
+ const schemaSchema = anyObjectSchema.optional();
16
13
  /**
17
14
  * Client for managing the collection of Key-value stores in your account.
18
15
  *
@@ -33,7 +30,7 @@ const schemaSchema = utils_1.anyObjectSchema.optional();
33
30
  *
34
31
  * @see https://docs.apify.com/platform/storage/key-value-store
35
32
  */
36
- class KeyValueStoreCollectionClient extends resource_collection_client_1.ResourceCollectionClient {
33
+ export class KeyValueStoreCollectionClient extends ResourceCollectionClient {
37
34
  /**
38
35
  * @hidden
39
36
  */
@@ -64,7 +61,7 @@ class KeyValueStoreCollectionClient extends resource_collection_client_1.Resourc
64
61
  * @see https://docs.apify.com/api/v2/key-value-stores-get
65
62
  */
66
63
  list(options = {}) {
67
- const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'KeyValueStoreCollectionClientListOptions');
64
+ const parsed = parseArgument(options, listOptionsSchema, 'KeyValueStoreCollectionClientListOptions');
68
65
  return this._listPaginated(parsed);
69
66
  }
70
67
  /**
@@ -76,9 +73,8 @@ class KeyValueStoreCollectionClient extends resource_collection_client_1.Resourc
76
73
  * @see https://docs.apify.com/api/v2/key-value-stores-post
77
74
  */
78
75
  async getOrCreate(name, options) {
79
- (0, utils_1.parseArgument)(name, nameSchema);
80
- (0, utils_1.parseArgument)(options?.schema, schemaSchema); // TODO: Add schema validation
76
+ parseArgument(name, nameSchema);
77
+ parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
81
78
  return this._getOrCreate(name, options);
82
79
  }
83
80
  }
84
- exports.KeyValueStoreCollectionClient = KeyValueStoreCollectionClient;
@@ -1,8 +1,8 @@
1
1
  import type { Readable } from 'node:stream';
2
2
  import type { Log } from '@apify/log';
3
3
  import { Logger, LogLevel } from '@apify/log';
4
- import type { ApiClientSubResourceOptions } from '../base/api_client';
5
- import { ResourceClient } from '../base/resource_client';
4
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
5
+ import { ResourceClient } from '../base/resource_client.js';
6
6
  /**
7
7
  * Client for accessing Actor run or build logs.
8
8
  *
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamedLog = exports.LoggerActorRedirect = exports.LogClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
6
- const log_1 = tslib_1.__importStar(require("@apify/log"));
7
- const resource_client_1 = require("../base/resource_client");
8
- const utils_1 = require("../utils");
1
+ import c from 'ansi-colors';
2
+ import log, { Logger, LogLevel } from '@apify/log';
3
+ import { ResourceClient } from '../base/resource_client.js';
4
+ import { cast, catchNotFoundOrThrow } from '../utils.js';
9
5
  /**
10
6
  * Client for accessing Actor run or build logs.
11
7
  *
@@ -28,7 +24,7 @@ const utils_1 = require("../utils");
28
24
  *
29
25
  * @see https://docs.apify.com/platform/actors/running/runs-and-builds#logging
30
26
  */
31
- class LogClient extends resource_client_1.ResourceClient {
27
+ export class LogClient extends ResourceClient {
32
28
  /**
33
29
  * @hidden
34
30
  */
@@ -54,10 +50,10 @@ class LogClient extends resource_client_1.ResourceClient {
54
50
  };
55
51
  try {
56
52
  const response = await this.httpClient.call(requestOpts);
57
- return (0, utils_1.cast)(response.data);
53
+ return cast(response.data);
58
54
  }
59
55
  catch (err) {
60
- (0, utils_1.catchNotFoundOrThrow)(err);
56
+ catchNotFoundOrThrow(err);
61
57
  }
62
58
  return undefined;
63
59
  }
@@ -82,22 +78,21 @@ class LogClient extends resource_client_1.ResourceClient {
82
78
  };
83
79
  try {
84
80
  const response = await this.httpClient.call(requestOpts);
85
- return (0, utils_1.cast)(response.data);
81
+ return cast(response.data);
86
82
  }
87
83
  catch (err) {
88
- (0, utils_1.catchNotFoundOrThrow)(err);
84
+ catchNotFoundOrThrow(err);
89
85
  }
90
86
  return undefined;
91
87
  }
92
88
  }
93
- exports.LogClient = LogClient;
94
89
  /**
95
90
  * Logger for redirected actor logs.
96
91
  * @since Added in 2.20.0
97
92
  */
98
- class LoggerActorRedirect extends log_1.Logger {
93
+ export class LoggerActorRedirect extends Logger {
99
94
  constructor(options = {}) {
100
- super({ skipTime: true, level: log_1.LogLevel.DEBUG, ...options });
95
+ super({ skipTime: true, level: LogLevel.DEBUG, ...options });
101
96
  }
102
97
  _log(level, message, data, exception, opts = {}) {
103
98
  if (level > this.options.level) {
@@ -112,19 +107,18 @@ class LoggerActorRedirect extends log_1.Logger {
112
107
  if (!this.options.skipTime) {
113
108
  maybeDate = `${new Date().toISOString().replace('Z', '').replace('T', ' ')} `;
114
109
  }
115
- const line = `${ansi_colors_1.default.gray(maybeDate)}${ansi_colors_1.default.cyan(prefix)}${message || ''}`;
110
+ const line = `${c.gray(maybeDate)}${c.cyan(prefix)}${message || ''}`;
116
111
  // All redirected logs are logged at info level to avid any console specific formating for non-info levels,
117
112
  // which have already been applied once to the original log. (For example error stack traces etc.)
118
- this._outputWithConsole(log_1.LogLevel.INFO, line);
113
+ this._outputWithConsole(LogLevel.INFO, line);
119
114
  return line;
120
115
  }
121
116
  }
122
- exports.LoggerActorRedirect = LoggerActorRedirect;
123
117
  /**
124
118
  * Helper class for redirecting streamed Actor logs to another log.
125
119
  * @since Added in 2.20.0
126
120
  */
127
- class StreamedLog {
121
+ export class StreamedLog {
128
122
  destinationLog;
129
123
  streamBuffer = [];
130
124
  splitMarker = /(?:\n|^)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/g;
@@ -185,7 +179,7 @@ class StreamedLog {
185
179
  }
186
180
  }
187
181
  catch (err) {
188
- log_1.default.warning(`Log redirection stopped due to error`, err);
182
+ log.warning(`Log redirection stopped due to error`, err);
189
183
  }
190
184
  }
191
185
  async logStreamChunks(logStream) {
@@ -235,4 +229,3 @@ class StreamedLog {
235
229
  });
236
230
  }
237
231
  }
238
- exports.StreamedLog = StreamedLog;