apify-client 3.0.0-beta.8 → 3.0.0-rc.0

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 -24
  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 +720 -747
  18. package/dist/generated/schemas.js +166 -162
  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 -12
  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 +9 -4
  48. package/dist/resource_clients/actor_env_var_collection.js +11 -4
  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 +11 -4
  52. package/dist/resource_clients/actor_version_collection.js +13 -4
  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 +62 -20
  62. package/dist/resource_clients/key_value_store.js +78 -40
  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 +68 -31
  68. package/dist/resource_clients/request_queue.js +173 -91
  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 +82 -45
  109. package/dist/utils.js +197 -146
  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
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ import { runtime } from '#runtime';
3
+ import { parseArgument } from '../utils.js';
4
+ /** Lowest valid brotli quality, the fastest with the least compression. */
5
+ const MIN_QUALITY = 0;
6
+ /** Highest valid brotli quality, the slowest with the best compression. */
7
+ const MAX_QUALITY = 11;
8
+ /** Middle of the range, where brotli already beats gzip at a comparable CPU cost. */
9
+ const DEFAULT_QUALITY = 6;
10
+ const optionsSchema = z.strictObject({
11
+ quality: z.int().min(MIN_QUALITY).max(MAX_QUALITY).default(DEFAULT_QUALITY),
12
+ });
13
+ /**
14
+ * Compresses request bodies using brotli.
15
+ *
16
+ * Built on the `node:zlib` module, so it works wherever the client runs on Node.js.
17
+ *
18
+ * @example
19
+ * ```javascript
20
+ * import { ApifyClient, BrotliHttpCompressor } from 'apify-client';
21
+ *
22
+ * const client = new ApifyClient({ token: 'my-token', compression: new BrotliHttpCompressor({ quality: 11 }) });
23
+ * ```
24
+ */
25
+ export class BrotliHttpCompressor {
26
+ contentEncoding = 'br';
27
+ #quality;
28
+ /**
29
+ * @param options - Compressor options.
30
+ * @throws {ArgumentValidationError} If `quality` is out of the valid range.
31
+ */
32
+ constructor(options = {}) {
33
+ const { quality } = parseArgument(options, optionsSchema, 'BrotliHttpCompressorOptions');
34
+ this.#quality = quality;
35
+ }
36
+ async compress(data) {
37
+ return runtime.compress(data, { algorithm: 'br', quality: this.#quality });
38
+ }
39
+ }
@@ -0,0 +1,33 @@
1
+ import type { HttpCompressor } from './base.js';
2
+ /**
3
+ * Compresses request bodies using gzip.
4
+ *
5
+ * Built on the `node:zlib` module, so it works wherever the client runs on Node.js.
6
+ *
7
+ * @example
8
+ * ```javascript
9
+ * import { ApifyClient, GzipHttpCompressor } from 'apify-client';
10
+ *
11
+ * const client = new ApifyClient({ token: 'my-token', compression: new GzipHttpCompressor({ quality: 1 }) });
12
+ * ```
13
+ */
14
+ export declare class GzipHttpCompressor implements HttpCompressor {
15
+ #private;
16
+ readonly contentEncoding = "gzip";
17
+ /**
18
+ * @param options - Compressor options.
19
+ * @throws {ArgumentValidationError} If `quality` is out of the valid range.
20
+ */
21
+ constructor(options?: GzipHttpCompressorOptions);
22
+ compress(data: Buffer): Promise<Buffer>;
23
+ }
24
+ /**
25
+ * Options for {@link GzipHttpCompressor}.
26
+ */
27
+ export interface GzipHttpCompressorOptions {
28
+ /**
29
+ * Compression level, from `1` (the fastest) to `9` (the best compression).
30
+ * @default 6
31
+ */
32
+ quality?: number;
33
+ }
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ import { runtime } from '#runtime';
3
+ import { parseArgument } from '../utils.js';
4
+ /** Lowest valid gzip quality, the fastest with the least compression. */
5
+ const MIN_QUALITY = 1;
6
+ /** Highest valid gzip quality, the slowest with the best compression. */
7
+ const MAX_QUALITY = 9;
8
+ /** zlib's own default. The levels above it roughly double the CPU cost for about a percent fewer bytes. */
9
+ const DEFAULT_QUALITY = 6;
10
+ const optionsSchema = z.strictObject({
11
+ quality: z.int().min(MIN_QUALITY).max(MAX_QUALITY).default(DEFAULT_QUALITY),
12
+ });
13
+ /**
14
+ * Compresses request bodies using gzip.
15
+ *
16
+ * Built on the `node:zlib` module, so it works wherever the client runs on Node.js.
17
+ *
18
+ * @example
19
+ * ```javascript
20
+ * import { ApifyClient, GzipHttpCompressor } from 'apify-client';
21
+ *
22
+ * const client = new ApifyClient({ token: 'my-token', compression: new GzipHttpCompressor({ quality: 1 }) });
23
+ * ```
24
+ */
25
+ export class GzipHttpCompressor {
26
+ contentEncoding = 'gzip';
27
+ #quality;
28
+ /**
29
+ * @param options - Compressor options.
30
+ * @throws {ArgumentValidationError} If `quality` is out of the valid range.
31
+ */
32
+ constructor(options = {}) {
33
+ const { quality } = parseArgument(options, optionsSchema, 'GzipHttpCompressorOptions');
34
+ this.#quality = quality;
35
+ }
36
+ async compress(data) {
37
+ return runtime.compress(data, { algorithm: 'gzip', quality: this.#quality });
38
+ }
39
+ }
@@ -0,0 +1,6 @@
1
+ export type { HttpCompressor } from './base.js';
2
+ export { BrotliHttpCompressor } from './brotli.js';
3
+ export type { BrotliHttpCompressorOptions } from './brotli.js';
4
+ export { GzipHttpCompressor } from './gzip.js';
5
+ export type { GzipHttpCompressorOptions } from './gzip.js';
6
+ export type { HttpCompressionAlgorithm } from './resolve.js';
@@ -0,0 +1,2 @@
1
+ export { BrotliHttpCompressor } from './brotli.js';
2
+ export { GzipHttpCompressor } from './gzip.js';
@@ -0,0 +1,23 @@
1
+ import { z } from 'zod';
2
+ import type { HttpCompressor } from './base.js';
3
+ /**
4
+ * Compression algorithms the `compression` option of {@link ApifyClient} accepts by name. Each name selects the
5
+ * matching built-in compressor with its default quality: `'brotli'` a {@link BrotliHttpCompressor}, `'gzip'` a
6
+ * {@link GzipHttpCompressor}. The Apify API also accepts `deflate` and `identity`, which a custom
7
+ * {@link HttpCompressor} covers.
8
+ */
9
+ export type HttpCompressionAlgorithm = 'brotli' | 'gzip';
10
+ /**
11
+ * Schema of the `compression` option: an algorithm name or an {@link HttpCompressor}.
12
+ * @internal
13
+ */
14
+ export declare const compressionSchema: z.ZodUnion<readonly [z.ZodEnum<{
15
+ brotli: "brotli";
16
+ gzip: "gzip";
17
+ }>, z.ZodCustom<HttpCompressor, HttpCompressor>]>;
18
+ /**
19
+ * Turns the `compression` option into a ready-to-use {@link HttpCompressor}: a name into the matching built-in
20
+ * compressor with its default quality, a compressor into itself.
21
+ * @internal
22
+ */
23
+ export declare function resolveCompressor(compression: HttpCompressionAlgorithm | HttpCompressor): HttpCompressor;
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import { httpCompressorSchema } from './base.js';
3
+ import { BrotliHttpCompressor } from './brotli.js';
4
+ import { GzipHttpCompressor } from './gzip.js';
5
+ /**
6
+ * Schema of the `compression` option: an algorithm name or an {@link HttpCompressor}.
7
+ * @internal
8
+ */
9
+ export const compressionSchema = z.union([
10
+ z.enum(['brotli', 'gzip']),
11
+ httpCompressorSchema,
12
+ ]);
13
+ /**
14
+ * Turns the `compression` option into a ready-to-use {@link HttpCompressor}: a name into the matching built-in
15
+ * compressor with its default quality, a compressor into itself.
16
+ * @internal
17
+ */
18
+ export function resolveCompressor(compression) {
19
+ if (typeof compression !== 'string')
20
+ return compression;
21
+ switch (compression) {
22
+ case 'gzip':
23
+ return new GzipHttpCompressor();
24
+ case 'brotli':
25
+ return new BrotliHttpCompressor();
26
+ }
27
+ }
package/dist/index.d.ts CHANGED
@@ -29,5 +29,8 @@ export * from './resource_clients/webhook_dispatch_collection.js';
29
29
  export * from './apify_api_error.js';
30
30
  export { ArgumentValidationError } from '@apify/validations';
31
31
  export * from './response_validation_error.js';
32
- export { InvalidResponseBodyError } from './interceptors.js';
32
+ export * from './invalid_response_body_error.js';
33
+ export * from './http_clients/index.js';
34
+ export * from './http_compressors/index.js';
33
35
  export type { PaginatedList, Dictionary } from './utils.js';
36
+ export type { Timeout, TimeoutOptions, TimeoutTier } from './timeouts.js';
package/dist/index.js CHANGED
@@ -29,4 +29,6 @@ export * from './resource_clients/webhook_dispatch_collection.js';
29
29
  export * from './apify_api_error.js';
30
30
  export { ArgumentValidationError } from '@apify/validations';
31
31
  export * from './response_validation_error.js';
32
- export { InvalidResponseBodyError } from './interceptors.js';
32
+ export * from './invalid_response_body_error.js';
33
+ export * from './http_clients/index.js';
34
+ export * from './http_compressors/index.js';
@@ -0,0 +1,13 @@
1
+ import type { HttpResponse } from './http_clients/base.js';
2
+ /**
3
+ * Thrown when a response body does not parse as its content type claims, typically a JSON document cut short by a
4
+ * connection dropped mid-response. The client retries such requests, so the error surfaces once the retries are
5
+ * exhausted.
6
+ */
7
+ export declare class InvalidResponseBodyError extends Error {
8
+ code: string;
9
+ /** The response whose body did not parse, with the body as the transport returned it. */
10
+ response: HttpResponse;
11
+ cause: Error;
12
+ constructor(response: HttpResponse, cause: Error);
13
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Thrown when a response body does not parse as its content type claims, typically a JSON document cut short by a
3
+ * connection dropped mid-response. The client retries such requests, so the error surfaces once the retries are
4
+ * exhausted.
5
+ */
6
+ export class InvalidResponseBodyError extends Error {
7
+ code;
8
+ /** The response whose body did not parse, with the body as the transport returned it. */
9
+ response;
10
+ constructor(response, cause) {
11
+ super(`Response body could not be parsed.\nCause:${cause.message}`);
12
+ this.name = this.constructor.name;
13
+ this.code = 'invalid-response-body';
14
+ this.response = response;
15
+ this.cause = cause;
16
+ }
17
+ }