apify-client 3.0.0-beta.97 → 3.0.0-beta.99

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.
@@ -911,6 +911,7 @@ export interface paths {
911
911
  *
912
912
  * * Brotli: `Content-Encoding: br`
913
913
  * * Gzip: `Content-Encoding: gzip`
914
+ * * Zstandard: `Content-Encoding: zstd`
914
915
  * * Deflate: `Content-Encoding: deflate`
915
916
  */
916
917
  post: operations["actor_runs_last_dataset_items_post"];
@@ -2072,6 +2073,7 @@ export interface paths {
2072
2073
  *
2073
2074
  * * Brotli: `Content-Encoding: br`
2074
2075
  * * Gzip: `Content-Encoding: gzip`
2076
+ * * Zstandard: `Content-Encoding: zstd`
2075
2077
  * * Deflate: `Content-Encoding: deflate`
2076
2078
  */
2077
2079
  post: operations["actorTask_runs_last_dataset_items_post"];
@@ -2765,6 +2767,7 @@ export interface paths {
2765
2767
  *
2766
2768
  * * Brotli: `Content-Encoding: br`
2767
2769
  * * Gzip: `Content-Encoding: gzip`
2770
+ * * Zstandard: `Content-Encoding: zstd`
2768
2771
  * * Deflate: `Content-Encoding: deflate`
2769
2772
  */
2770
2773
  post: operations["actorRun_dataset_items_post"];
@@ -3537,6 +3540,7 @@ export interface paths {
3537
3540
  *
3538
3541
  * * Brotli compression: `Content-Encoding: br`
3539
3542
  * * Gzip compression: `Content-Encoding: gzip`
3543
+ * * Zstandard compression: `Content-Encoding: zstd`
3540
3544
  * * Deflate compression: `Content-Encoding: deflate`
3541
3545
  */
3542
3546
  put: operations["keyValueStore_record_put"];
@@ -3814,6 +3818,7 @@ export interface paths {
3814
3818
  *
3815
3819
  * * Brotli: `Content-Encoding: br`
3816
3820
  * * Gzip: `Content-Encoding: gzip`
3821
+ * * Zstandard: `Content-Encoding: zstd`
3817
3822
  * * Deflate: `Content-Encoding: deflate`
3818
3823
  */
3819
3824
  post: operations["dataset_items_post"];
@@ -10301,7 +10306,7 @@ export interface components {
10301
10306
  /** @description Signature used for the access. */
10302
10307
  signature: string;
10303
10308
  /** @description Compression encoding of the request body. */
10304
- "Content-Encoding": "br" | "gzip" | "deflate" | "identity";
10309
+ "Content-Encoding": "br" | "gzip" | "zstd" | "deflate" | "identity";
10305
10310
  /** @description All keys up to this one (including) are skipped from the result. */
10306
10311
  exclusiveStartKey: string;
10307
10312
  /** @description Number of keys to be returned. */
@@ -4,3 +4,5 @@ export type { BrotliHttpCompressorOptions } from './brotli.js';
4
4
  export { GzipHttpCompressor } from './gzip.js';
5
5
  export type { GzipHttpCompressorOptions } from './gzip.js';
6
6
  export type { HttpCompressionAlgorithm } from './resolve.js';
7
+ export { ZstdHttpCompressor } from './zstd.js';
8
+ export type { ZstdHttpCompressorOptions } from './zstd.js';
@@ -1,2 +1,3 @@
1
1
  export { BrotliHttpCompressor } from './brotli.js';
2
2
  export { GzipHttpCompressor } from './gzip.js';
3
+ export { ZstdHttpCompressor } from './zstd.js';
@@ -3,10 +3,10 @@ import type { HttpCompressor } from './base.js';
3
3
  /**
4
4
  * Compression algorithms the `compression` option of {@link ApifyClient} accepts by name. Each name selects the
5
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.
6
+ * {@link GzipHttpCompressor}, `'zstd'` a {@link ZstdHttpCompressor}. The Apify API also accepts `deflate` and
7
+ * `identity`, which a custom {@link HttpCompressor} covers.
8
8
  */
9
- export type HttpCompressionAlgorithm = 'brotli' | 'gzip';
9
+ export type HttpCompressionAlgorithm = 'brotli' | 'gzip' | 'zstd';
10
10
  /**
11
11
  * Schema of the `compression` option: an algorithm name or an {@link HttpCompressor}.
12
12
  * @internal
@@ -14,6 +14,7 @@ export type HttpCompressionAlgorithm = 'brotli' | 'gzip';
14
14
  export declare const compressionSchema: z.ZodUnion<readonly [z.ZodEnum<{
15
15
  brotli: "brotli";
16
16
  gzip: "gzip";
17
+ zstd: "zstd";
17
18
  }>, z.ZodCustom<HttpCompressor, HttpCompressor>]>;
18
19
  /**
19
20
  * Turns the `compression` option into a ready-to-use {@link HttpCompressor}: a name into the matching built-in
@@ -2,12 +2,13 @@ import { z } from 'zod';
2
2
  import { httpCompressorSchema } from './base.js';
3
3
  import { BrotliHttpCompressor } from './brotli.js';
4
4
  import { GzipHttpCompressor } from './gzip.js';
5
+ import { ZstdHttpCompressor } from './zstd.js';
5
6
  /**
6
7
  * Schema of the `compression` option: an algorithm name or an {@link HttpCompressor}.
7
8
  * @internal
8
9
  */
9
10
  export const compressionSchema = z.union([
10
- z.enum(['brotli', 'gzip']),
11
+ z.enum(['brotli', 'gzip', 'zstd']),
11
12
  httpCompressorSchema,
12
13
  ]);
13
14
  /**
@@ -23,5 +24,7 @@ export function resolveCompressor(compression) {
23
24
  return new GzipHttpCompressor();
24
25
  case 'brotli':
25
26
  return new BrotliHttpCompressor();
27
+ case 'zstd':
28
+ return new ZstdHttpCompressor();
26
29
  }
27
30
  }
@@ -0,0 +1,34 @@
1
+ import type { HttpCompressor } from './base.js';
2
+ /**
3
+ * Compresses request bodies using zstd.
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, ZstdHttpCompressor } from 'apify-client';
10
+ *
11
+ * const client = new ApifyClient({ token: 'my-token', compression: new ZstdHttpCompressor({ quality: 19 }) });
12
+ * ```
13
+ */
14
+ export declare class ZstdHttpCompressor implements HttpCompressor {
15
+ #private;
16
+ readonly contentEncoding = "zstd";
17
+ /**
18
+ * @param options - Compressor options.
19
+ * @throws {ArgumentValidationError} If `quality` is out of the valid range.
20
+ */
21
+ constructor(options?: ZstdHttpCompressorOptions);
22
+ compress(data: Buffer): Promise<Buffer>;
23
+ }
24
+ /**
25
+ * Options for {@link ZstdHttpCompressor}.
26
+ */
27
+ export interface ZstdHttpCompressorOptions {
28
+ /**
29
+ * Compression level, from `1` (the fastest) to `19` (the best compression). zstd's levels 20 to 22 are not
30
+ * accepted: their window exceeds the 8 MB that HTTP decoders are required to support.
31
+ * @default 3
32
+ */
33
+ quality?: number;
34
+ }
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ import { runtime } from '#runtime';
3
+ import { parseArgument } from '../utils.js';
4
+ /** Lowest valid zstd quality, the fastest with the least compression. */
5
+ const MIN_QUALITY = 1;
6
+ /**
7
+ * Highest quality the compressor accepts. zstd itself goes up to 22, but levels 20 to 22 use a window above the 8 MB
8
+ * that RFC 9659 requires HTTP decoders to support, so a record stored at those levels could fail to decode in a
9
+ * browser that accepts zstd. Level 19 is the last one within the limit.
10
+ */
11
+ const MAX_QUALITY = 19;
12
+ /** zstd's own default. Fast, with a ratio close to gzip at its best level. */
13
+ const DEFAULT_QUALITY = 3;
14
+ const optionsSchema = z.strictObject({
15
+ quality: z.int().min(MIN_QUALITY).max(MAX_QUALITY).default(DEFAULT_QUALITY),
16
+ });
17
+ /**
18
+ * Compresses request bodies using zstd.
19
+ *
20
+ * Built on the `node:zlib` module, so it works wherever the client runs on Node.js.
21
+ *
22
+ * @example
23
+ * ```javascript
24
+ * import { ApifyClient, ZstdHttpCompressor } from 'apify-client';
25
+ *
26
+ * const client = new ApifyClient({ token: 'my-token', compression: new ZstdHttpCompressor({ quality: 19 }) });
27
+ * ```
28
+ */
29
+ export class ZstdHttpCompressor {
30
+ contentEncoding = 'zstd';
31
+ #quality;
32
+ /**
33
+ * @param options - Compressor options.
34
+ * @throws {ArgumentValidationError} If `quality` is out of the valid range.
35
+ */
36
+ constructor(options = {}) {
37
+ const { quality } = parseArgument(options, optionsSchema, 'ZstdHttpCompressorOptions');
38
+ this.#quality = quality;
39
+ }
40
+ async compress(data) {
41
+ return runtime.compress(data, { algorithm: 'zstd', quality: this.#quality });
42
+ }
43
+ }
@@ -232,12 +232,12 @@ export declare class KeyValueStoreClient extends ResourceClient {
232
232
  * @param record.contentEncoding - Optional encoding already applied to `value`, sent as the `Content-Encoding`
233
233
  * header. Set it to upload a pre-compressed value: the client then sends the
234
234
  * bytes as they are and does not compress them again. The API accepts `gzip`,
235
- * `br`, `deflate`, and `identity`, and stores the record exactly as uploaded, so
236
- * this is also the encoding the record is served with. Only binary values and
237
- * streams can carry a compression, so any encoding other than `identity` throws
238
- * a `TypeError` when `value` is a string, or a plain object, array, or other
239
- * value that the client serializes to JSON. Node.js only, since browsers cannot
240
- * send the header to the API.
235
+ * `br`, `zstd`, `deflate`, and `identity`, and stores the record exactly as
236
+ * uploaded, so this is also the encoding the record is served with. Only binary
237
+ * values and streams can carry a compression, so any encoding other than
238
+ * `identity` throws a `TypeError` when `value` is a string, or a plain object,
239
+ * array, or other value that the client serializes to JSON. Node.js only, since
240
+ * browsers cannot send the header to the API.
241
241
  * @param options - Storage options
242
242
  * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
243
243
  * @param options.doNotRetryTimeouts - If `true`, don't retry on timeout errors. Default is `false`.
@@ -386,12 +386,12 @@ export class KeyValueStoreClient extends ResourceClient {
386
386
  * @param record.contentEncoding - Optional encoding already applied to `value`, sent as the `Content-Encoding`
387
387
  * header. Set it to upload a pre-compressed value: the client then sends the
388
388
  * bytes as they are and does not compress them again. The API accepts `gzip`,
389
- * `br`, `deflate`, and `identity`, and stores the record exactly as uploaded, so
390
- * this is also the encoding the record is served with. Only binary values and
391
- * streams can carry a compression, so any encoding other than `identity` throws
392
- * a `TypeError` when `value` is a string, or a plain object, array, or other
393
- * value that the client serializes to JSON. Node.js only, since browsers cannot
394
- * send the header to the API.
389
+ * `br`, `zstd`, `deflate`, and `identity`, and stores the record exactly as
390
+ * uploaded, so this is also the encoding the record is served with. Only binary
391
+ * values and streams can carry a compression, so any encoding other than
392
+ * `identity` throws a `TypeError` when `value` is a string, or a plain object,
393
+ * array, or other value that the client serializes to JSON. Node.js only, since
394
+ * browsers cannot send the header to the API.
395
395
  * @param options - Storage options
396
396
  * @param options.timeoutSecs - Timeout for the API request. Default is `'long'`.
397
397
  * @param options.doNotRetryTimeouts - If `true`, don't retry on timeout errors. Default is `false`.
@@ -1,6 +1,6 @@
1
1
  import os from 'node:os';
2
2
  import { Readable } from 'node:stream';
3
- import { brotliCompress, constants, gzip } from 'node:zlib';
3
+ import { brotliCompress, constants, gzip, zstdCompress } from 'node:zlib';
4
4
  /**
5
5
  * The Node.js implementation of {@link Runtime}. Deno and Bun resolve the `node` condition too and
6
6
  * provide the built-ins it uses.
@@ -11,11 +11,18 @@ export const runtime = {
11
11
  async compress(data, { algorithm, quality }) {
12
12
  return new Promise((resolve, reject) => {
13
13
  const done = (error, result) => (error ? reject(error) : resolve(result));
14
- if (algorithm === 'br') {
15
- brotliCompress(data, { params: { [constants.BROTLI_PARAM_QUALITY]: quality } }, done);
16
- }
17
- else {
18
- gzip(data, { level: quality }, done);
14
+ switch (algorithm) {
15
+ case 'br':
16
+ brotliCompress(data, { params: { [constants.BROTLI_PARAM_QUALITY]: quality } }, done);
17
+ break;
18
+ case 'gzip':
19
+ gzip(data, { level: quality }, done);
20
+ break;
21
+ case 'zstd':
22
+ zstdCompress(data, { params: { [constants.ZSTD_c_compressionLevel]: quality } }, done);
23
+ break;
24
+ default:
25
+ reject(new Error(`Unrecognized compression algorithm: ${String(algorithm)}`));
19
26
  }
20
27
  });
21
28
  },
@@ -7,7 +7,7 @@ import type { Readable } from 'node:stream';
7
7
  */
8
8
  export interface CompressionOptions {
9
9
  /** Algorithm to compress with, named by the `Content-Encoding` value it produces. */
10
- algorithm: 'br' | 'gzip';
10
+ algorithm: 'br' | 'gzip' | 'zstd';
11
11
  /** Compression level, in the range the algorithm defines. */
12
12
  quality: number;
13
13
  }
@@ -5,7 +5,7 @@ export const runtime = {
5
5
  isNode: false,
6
6
  // Browsers do not let a page set the `User-Agent` header.
7
7
  platform: undefined,
8
- // No request compression: brotli and gzip have no Web API, and a `content-encoding` request header is not
8
+ // No request compression: brotli, gzip and zstd have no Web API, and a `content-encoding` request header is not
9
9
  // on the list of headers the Apify API allows in a cross-origin request, so a browser would fail the
10
10
  // preflight. The client compresses in Node.js alone, so nothing reaches this.
11
11
  async compress() {
package/dist/utils.d.ts CHANGED
@@ -73,8 +73,8 @@ export declare function toBytes(value: unknown): Uint8Array | undefined;
73
73
  /**
74
74
  * Decides whether a request body with the given content type is worth compressing.
75
75
  *
76
- * Images, audio, video and archives already carry their own compression. Running them through brotli or gzip
77
- * burns CPU, holds a second full copy of the body in memory, and usually produces output slightly larger than
76
+ * Images, audio, video and archives already carry their own compression. Running them through brotli, gzip or
77
+ * zstd burns CPU, holds a second full copy of the body in memory, and usually produces output slightly larger than
78
78
  * the input. Formats that are raw despite such a media type, for example `image/bmp` or `audio/wav`, are still
79
79
  * compressed. A body with no content type is assumed to be compressible.
80
80
  * @internal
package/dist/utils.js CHANGED
@@ -173,8 +173,8 @@ export function toBytes(value) {
173
173
  /**
174
174
  * Decides whether a request body with the given content type is worth compressing.
175
175
  *
176
- * Images, audio, video and archives already carry their own compression. Running them through brotli or gzip
177
- * burns CPU, holds a second full copy of the body in memory, and usually produces output slightly larger than
176
+ * Images, audio, video and archives already carry their own compression. Running them through brotli, gzip or
177
+ * zstd burns CPU, holds a second full copy of the body in memory, and usually produces output slightly larger than
178
178
  * the input. Formats that are raw despite such a media type, for example `image/bmp` or `audio/wav`, are still
179
179
  * compressed. A body with no content type is assumed to be compressible.
180
180
  * @internal
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.97",
3
+ "version": "3.0.0-beta.99",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
- "node": ">=22.13.0"
6
+ "node": ">=22.15.0"
7
7
  },
8
8
  "type": "module",
9
9
  "main": "dist/index.js",
@@ -59,7 +59,7 @@
59
59
  ],
60
60
  "apify": {
61
61
  "openapiSpec": {
62
- "version": "v2-2026-11-04T151257Z"
62
+ "version": "v2-2026-11-09T143926Z"
63
63
  }
64
64
  },
65
65
  "dependencies": {