apify-client 3.0.0-rc.0 → 3.0.0-rc.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.
- package/README.md +10 -2
- package/dist/apify_api_error.d.ts +4 -3
- package/dist/apify_api_error.js +2 -1
- package/dist/apify_client.d.ts +8 -8
- package/dist/apify_client.js +10 -10
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/axios.d.ts +2 -0
- package/dist/axios.js +1 -0
- package/dist/base/api_client.js +8 -20
- package/dist/base/resource_client.js +8 -8
- package/dist/body_parser.d.ts +1 -1
- package/dist/bundle.js +31 -30
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +2427 -725
- package/dist/generated/schemas.d.ts +1868 -274
- package/dist/generated/schemas.js +437 -79
- package/dist/http_clients/axios.d.ts +35 -15
- package/dist/http_clients/axios.js +80 -32
- package/dist/http_clients/base.d.ts +105 -34
- package/dist/http_clients/base.js +169 -52
- package/dist/http_clients/fetch.d.ts +53 -0
- package/dist/http_clients/fetch.js +219 -0
- package/dist/http_clients/index.d.ts +2 -2
- package/dist/http_clients/index.js +1 -1
- package/dist/http_compressors/index.d.ts +2 -0
- package/dist/http_compressors/index.js +1 -0
- package/dist/http_compressors/resolve.d.ts +4 -3
- package/dist/http_compressors/resolve.js +4 -1
- package/dist/http_compressors/zstd.d.ts +34 -0
- package/dist/http_compressors/zstd.js +43 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/invalid_response_body_error.d.ts +5 -4
- package/dist/invalid_response_body_error.js +5 -4
- package/dist/models.d.ts +30 -61
- package/dist/resource_clients/actor.d.ts +33 -2
- package/dist/resource_clients/actor.js +46 -3
- package/dist/resource_clients/actor_server.d.ts +149 -0
- package/dist/resource_clients/actor_server.js +195 -0
- package/dist/resource_clients/actor_version.d.ts +7 -1
- package/dist/resource_clients/actor_version.js +3 -2
- package/dist/resource_clients/actor_version_collection.d.ts +2 -1
- package/dist/resource_clients/actor_version_collection.js +3 -2
- package/dist/resource_clients/dataset.d.ts +33 -5
- package/dist/resource_clients/dataset.js +12 -54
- package/dist/resource_clients/key_value_store.d.ts +63 -22
- package/dist/resource_clients/key_value_store.js +62 -19
- package/dist/resource_clients/log.d.ts +32 -7
- package/dist/resource_clients/log.js +11 -14
- package/dist/resource_clients/request_queue.d.ts +9 -0
- package/dist/resource_clients/request_queue.js +9 -6
- package/dist/resource_clients/run.d.ts +15 -2
- package/dist/resource_clients/run.js +12 -5
- package/dist/resource_clients/store_collection.d.ts +4 -0
- package/dist/resource_clients/task.js +3 -3
- package/dist/response_validation_error.d.ts +2 -1
- package/dist/response_validation_error.js +2 -1
- package/dist/runtime/node.js +79 -17
- package/dist/runtime/types.d.ts +35 -5
- package/dist/runtime/web.js +43 -1
- package/dist/schemas.d.ts +369 -3
- package/dist/schemas.js +25 -3
- package/dist/utils.d.ts +52 -27
- package/dist/utils.js +45 -25
- package/package.json +42 -30
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { runtime } from '#runtime';
|
|
2
|
+
import { ApifyClientError } from '../apify_client_error.js';
|
|
3
|
+
import { isAnyStream, isStream, isWebStream } from '../utils.js';
|
|
4
|
+
import { HttpClient } from './base.js';
|
|
5
|
+
/** Error codes of the timeouts that Node.js reports as the `cause` of a failed `fetch`. */
|
|
6
|
+
const TIMEOUT_ERROR_CODES = new Set([
|
|
7
|
+
'ETIMEDOUT',
|
|
8
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
9
|
+
'UND_ERR_HEADERS_TIMEOUT',
|
|
10
|
+
'UND_ERR_BODY_TIMEOUT',
|
|
11
|
+
]);
|
|
12
|
+
/** Error codes of a request that Node.js or Bun refused to send, so sending it again fails the same way. */
|
|
13
|
+
const INVALID_REQUEST_ERROR_CODES = new Set([
|
|
14
|
+
'ERR_INVALID_URL',
|
|
15
|
+
'ERR_INVALID_ARG_TYPE',
|
|
16
|
+
'ERR_INVALID_ARG_VALUE',
|
|
17
|
+
'UND_ERR_INVALID_ARG',
|
|
18
|
+
'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH',
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* The default HTTP client of {@link ApifyClient}, built on the `fetch` of the runtime, so it works the same way in
|
|
22
|
+
* Node.js, browsers and edge runtimes and brings no dependency of its own.
|
|
23
|
+
*
|
|
24
|
+
* It inherits the request pipeline from {@link HttpClient} and adds the transport. Network errors are retried,
|
|
25
|
+
* timeouts included, and a stream body is sent without following redirects, since the part of it already sent could
|
|
26
|
+
* not be replayed. The timeout of a request runs until the response headers arrive and starts over with every chunk
|
|
27
|
+
* of the response body and of a stream body, so a large download or upload does not time out while it makes progress.
|
|
28
|
+
*
|
|
29
|
+
* In Node.js, `fetch` keeps connections alive on its own, and goes through a proxy only when Node.js is told to
|
|
30
|
+
* read the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables: start it with `NODE_USE_ENV_PROXY=1`
|
|
31
|
+
* (Node.js 22.21 and 24.0) or `--use-env-proxy` (Node.js 22.21 and 24.5).
|
|
32
|
+
*/
|
|
33
|
+
export class FetchHttpClient extends HttpClient {
|
|
34
|
+
#fetch;
|
|
35
|
+
constructor(options = {}) {
|
|
36
|
+
super(options);
|
|
37
|
+
this.#fetch = options.fetch;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A timeout is the `TimeoutError` this client aborts a late request with, or a `fetch` failure caused by one of
|
|
41
|
+
* the connection, headers and body timeouts of Node.js.
|
|
42
|
+
*/
|
|
43
|
+
isTimeoutError(error) {
|
|
44
|
+
if (super.isTimeoutError(error))
|
|
45
|
+
return true;
|
|
46
|
+
const code = causeCode(error);
|
|
47
|
+
return code !== undefined && TIMEOUT_ERROR_CODES.has(code);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A network failure is the `TypeError` that `fetch` rejects with: a connection that could not be made, dropped
|
|
51
|
+
* mid-way or timed out. In Node.js it carries the failure as its `cause`, which tells it apart from a request
|
|
52
|
+
* that was never sent, such as one with an invalid URL. Bun rejects with an `Error` that has a `code` instead.
|
|
53
|
+
*/
|
|
54
|
+
isRetryableTransportError(error) {
|
|
55
|
+
if (this.isTimeoutError(error))
|
|
56
|
+
return true;
|
|
57
|
+
const code = causeCode(error) ?? errorCode(error);
|
|
58
|
+
if (code !== undefined && INVALID_REQUEST_ERROR_CODES.has(code))
|
|
59
|
+
return false;
|
|
60
|
+
if (runtime.fetchFailsWithCause)
|
|
61
|
+
return error instanceof TypeError && error.cause !== undefined;
|
|
62
|
+
// Browsers and Deno fail with a bare `TypeError` whatever the reason, and Bun with an error that has a `code`.
|
|
63
|
+
return error instanceof TypeError || code !== undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sends the request through `fetch` and hands the raw response back. A stream body is sent without following
|
|
67
|
+
* redirects, and so is a request with `followRedirects: false`. A browser hides such a redirect response from
|
|
68
|
+
* the page, so there it fails the request.
|
|
69
|
+
*/
|
|
70
|
+
async sendRequest(request) {
|
|
71
|
+
const { method, url, headers, body, timeoutMillis, stream, followRedirects, signal } = request;
|
|
72
|
+
// `AbortSignal.timeout()` could neither be restarted nor called off.
|
|
73
|
+
const timeout = new AbortController();
|
|
74
|
+
let timer;
|
|
75
|
+
let settled = false;
|
|
76
|
+
const restartTimeout = () => {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
// The transport may still read a stream body after the response arrived.
|
|
79
|
+
if (timeoutMillis === undefined || settled)
|
|
80
|
+
return;
|
|
81
|
+
timer = setTimeout(() => timeout.abort(new DOMException(`timeout of ${timeoutMillis}ms exceeded`, 'TimeoutError')), timeoutMillis);
|
|
82
|
+
};
|
|
83
|
+
restartTimeout();
|
|
84
|
+
let sentBody;
|
|
85
|
+
try {
|
|
86
|
+
// Browsers and Deno reject an invalid URL with the same bare `TypeError` as a network failure.
|
|
87
|
+
const baseUrl = globalThis.location?.href;
|
|
88
|
+
if (!runtime.fetchFailsWithCause && !URL.canParse(url, baseUrl)) {
|
|
89
|
+
throw Object.assign(new TypeError(`Invalid URL: ${url}`), { code: 'ERR_INVALID_URL' });
|
|
90
|
+
}
|
|
91
|
+
sentBody = trackProgress(body, restartTimeout);
|
|
92
|
+
const response = await (this.#fetch ?? globalThis.fetch)(url, {
|
|
93
|
+
method,
|
|
94
|
+
headers,
|
|
95
|
+
body: sentBody,
|
|
96
|
+
redirect: followRedirects && !isAnyStream(body) ? 'follow' : 'manual',
|
|
97
|
+
signal: signal ? AbortSignal.any([signal, timeout.signal]) : timeout.signal,
|
|
98
|
+
// Required for a stream body, and ignored for any other.
|
|
99
|
+
...(isAnyStream(body) ? { duplex: 'half' } : {}),
|
|
100
|
+
});
|
|
101
|
+
// `redirect: 'manual'` resolves to an opaque response with status 0 in a browser.
|
|
102
|
+
if (response.type === 'opaqueredirect') {
|
|
103
|
+
throw new ApifyClientError(`${method} ${url} responded with a redirect, which the client does not follow.`);
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
status: response.status,
|
|
107
|
+
headers: toResponseHeaders(response.headers),
|
|
108
|
+
// The timeout covers a streamed response only until its headers, and the caller's signal throughout.
|
|
109
|
+
body: stream ? (response.body ?? new Blob([]).stream()) : await readBody(response, restartTimeout),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// A `fetch` that refused the request never took the body over, which keeps the caller's stream locked.
|
|
114
|
+
if (isWebStream(sentBody) && !sentBody.locked)
|
|
115
|
+
sentBody.cancel(error).catch(() => { });
|
|
116
|
+
if (!this.#fetch && this.isRetryableTransportError(error))
|
|
117
|
+
this.#warnAboutUnusedProxy();
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
settled = true;
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/** A proxy the environment names and Node.js ignores is the likeliest reason for a connection to fail. */
|
|
126
|
+
#warnAboutUnusedProxy() {
|
|
127
|
+
const hint = runtime.unusedProxyHint();
|
|
128
|
+
if (hint)
|
|
129
|
+
this.logger.warningOnce(hint);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Bun reads a stream body ahead of sending it, so reading it there says nothing about the progress. */
|
|
133
|
+
const isBun = 'Bun' in globalThis;
|
|
134
|
+
/** A larger chunk of a stream body is passed on in pieces, since a `Blob` held in memory arrives as a single one. */
|
|
135
|
+
const MAX_BODY_CHUNK_BYTES = 64 * 1024;
|
|
136
|
+
/** Makes a stream body report every chunk that `fetch` reads from it, and leaves any other body as it is. */
|
|
137
|
+
function trackProgress(body, onChunk) {
|
|
138
|
+
if (isWebStream(body))
|
|
139
|
+
return withWebProgress(body, onChunk);
|
|
140
|
+
// Node.js reads an async iterable, which the DOM types do not know about.
|
|
141
|
+
if (isStream(body) && !isBun)
|
|
142
|
+
return withProgress(body, onChunk);
|
|
143
|
+
return body;
|
|
144
|
+
}
|
|
145
|
+
/** Passes a stream body on piece by piece, so that a large upload counts as alive for as long as it is being read. */
|
|
146
|
+
async function* withProgress(body, onChunk) {
|
|
147
|
+
for await (const chunk of body) {
|
|
148
|
+
// Deno refuses the string chunks of a stream with an encoding.
|
|
149
|
+
const bytes = typeof chunk === 'string' ? new TextEncoder().encode(chunk) : chunk;
|
|
150
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength <= MAX_BODY_CHUNK_BYTES) {
|
|
151
|
+
onChunk();
|
|
152
|
+
yield bytes;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
for (let offset = 0; offset < bytes.byteLength; offset += MAX_BODY_CHUNK_BYTES) {
|
|
156
|
+
onChunk();
|
|
157
|
+
yield bytes.subarray(offset, offset + MAX_BODY_CHUNK_BYTES);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Does for a web stream body what {@link withProgress} does for an async iterable. */
|
|
162
|
+
function withWebProgress(body, onChunk) {
|
|
163
|
+
const reader = body.getReader();
|
|
164
|
+
let rest;
|
|
165
|
+
return new ReadableStream({
|
|
166
|
+
async pull(controller) {
|
|
167
|
+
if (!rest?.byteLength) {
|
|
168
|
+
const { done, value } = await reader.read();
|
|
169
|
+
if (done)
|
|
170
|
+
return controller.close();
|
|
171
|
+
rest = value;
|
|
172
|
+
}
|
|
173
|
+
onChunk();
|
|
174
|
+
controller.enqueue(rest.subarray(0, MAX_BODY_CHUNK_BYTES));
|
|
175
|
+
rest = rest.subarray(MAX_BODY_CHUNK_BYTES);
|
|
176
|
+
},
|
|
177
|
+
async cancel(reason) {
|
|
178
|
+
await reader.cancel(reason);
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
// Reads a piece only once `fetch` asks for it.
|
|
182
|
+
{ highWaterMark: 0 });
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Reads the response body chunk by chunk, so that a large download counts as alive for as long as bytes arrive.
|
|
186
|
+
*/
|
|
187
|
+
async function readBody(response, onChunk) {
|
|
188
|
+
const chunks = [];
|
|
189
|
+
let length = 0;
|
|
190
|
+
const reader = response.body?.getReader();
|
|
191
|
+
for (let chunk = await reader?.read(); chunk && !chunk.done; chunk = await reader?.read()) {
|
|
192
|
+
onChunk();
|
|
193
|
+
chunks.push(chunk.value);
|
|
194
|
+
length += chunk.value.byteLength;
|
|
195
|
+
}
|
|
196
|
+
const bytes = new Uint8Array(length);
|
|
197
|
+
let offset = 0;
|
|
198
|
+
for (const chunk of chunks) {
|
|
199
|
+
bytes.set(chunk, offset);
|
|
200
|
+
offset += chunk.byteLength;
|
|
201
|
+
}
|
|
202
|
+
return bytes;
|
|
203
|
+
}
|
|
204
|
+
function toResponseHeaders(headers) {
|
|
205
|
+
const result = Object.fromEntries(headers);
|
|
206
|
+
// `fetch` joins repeated headers with a comma, which a cookie's `Expires` date makes ambiguous.
|
|
207
|
+
const cookies = headers.getSetCookie?.() ?? [];
|
|
208
|
+
if (cookies.length > 0)
|
|
209
|
+
result['set-cookie'] = cookies;
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
/** Reads the `code` of the error that caused a `fetch` failure, which is where Node.js puts the network error. */
|
|
213
|
+
function causeCode(error) {
|
|
214
|
+
return errorCode(error instanceof Error ? error.cause : undefined);
|
|
215
|
+
}
|
|
216
|
+
function errorCode(error) {
|
|
217
|
+
const code = error?.code;
|
|
218
|
+
return typeof code === 'string' ? code : undefined;
|
|
219
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AxiosHttpClientOptions, RequestInterceptorFunction } from './axios.js';
|
|
2
|
-
export { AxiosHttpClient } from './axios.js';
|
|
3
1
|
export type { ApifyRequestConfig, ApifyResponse, ApifyResponseType, HttpClientOptions, HttpMethod, HttpRequest, HttpRequestBody, HttpResponse, HttpResponseBody, HttpResponseHeaders, } from './base.js';
|
|
4
2
|
export { HttpClient } from './base.js';
|
|
3
|
+
export type { FetchFunction, FetchHttpClientOptions } from './fetch.js';
|
|
4
|
+
export { FetchHttpClient } from './fetch.js';
|
|
@@ -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';
|
|
@@ -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
|
|
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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './resource_clients/actor.js';
|
|
|
3
3
|
export * from './resource_clients/actor_collection.js';
|
|
4
4
|
export * from './resource_clients/actor_env_var.js';
|
|
5
5
|
export * from './resource_clients/actor_env_var_collection.js';
|
|
6
|
+
export * from './resource_clients/actor_server.js';
|
|
6
7
|
export * from './resource_clients/actor_version.js';
|
|
7
8
|
export * from './resource_clients/actor_version_collection.js';
|
|
8
9
|
export * from './resource_clients/build.js';
|
|
@@ -26,11 +27,12 @@ export * from './resource_clients/webhook.js';
|
|
|
26
27
|
export * from './resource_clients/webhook_collection.js';
|
|
27
28
|
export * from './resource_clients/webhook_dispatch.js';
|
|
28
29
|
export * from './resource_clients/webhook_dispatch_collection.js';
|
|
30
|
+
export * from './apify_client_error.js';
|
|
29
31
|
export * from './apify_api_error.js';
|
|
30
32
|
export { ArgumentValidationError } from '@apify/validations';
|
|
31
33
|
export * from './response_validation_error.js';
|
|
32
34
|
export * from './invalid_response_body_error.js';
|
|
33
35
|
export * from './http_clients/index.js';
|
|
34
36
|
export * from './http_compressors/index.js';
|
|
35
|
-
export type { PaginatedList, Dictionary } from './utils.js';
|
|
37
|
+
export type { AnyString, PaginatedList, Dictionary, JsonValue, TypedArray } from './utils.js';
|
|
36
38
|
export type { Timeout, TimeoutOptions, TimeoutTier } from './timeouts.js';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './resource_clients/actor.js';
|
|
|
3
3
|
export * from './resource_clients/actor_collection.js';
|
|
4
4
|
export * from './resource_clients/actor_env_var.js';
|
|
5
5
|
export * from './resource_clients/actor_env_var_collection.js';
|
|
6
|
+
export * from './resource_clients/actor_server.js';
|
|
6
7
|
export * from './resource_clients/actor_version.js';
|
|
7
8
|
export * from './resource_clients/actor_version_collection.js';
|
|
8
9
|
export * from './resource_clients/build.js';
|
|
@@ -26,6 +27,7 @@ export * from './resource_clients/webhook.js';
|
|
|
26
27
|
export * from './resource_clients/webhook_collection.js';
|
|
27
28
|
export * from './resource_clients/webhook_dispatch.js';
|
|
28
29
|
export * from './resource_clients/webhook_dispatch_collection.js';
|
|
30
|
+
export * from './apify_client_error.js';
|
|
29
31
|
export * from './apify_api_error.js';
|
|
30
32
|
export { ArgumentValidationError } from '@apify/validations';
|
|
31
33
|
export * from './response_validation_error.js';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { ApifyClientError } from './apify_client_error.js';
|
|
1
2
|
import type { HttpResponse } from './http_clients/base.js';
|
|
2
3
|
/**
|
|
3
|
-
* Thrown when a response
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Thrown when the body of a successful response does not parse as its content type claims, for example a non-JSON
|
|
5
|
+
* value stored under `application/json`. The response arrived in full, so the request is not retried. An error
|
|
6
|
+
* status with an unparsable body throws {@link ApifyApiError} for its status code.
|
|
6
7
|
*/
|
|
7
|
-
export declare class InvalidResponseBodyError extends
|
|
8
|
+
export declare class InvalidResponseBodyError extends ApifyClientError {
|
|
8
9
|
code: string;
|
|
9
10
|
/** The response whose body did not parse, with the body as the transport returned it. */
|
|
10
11
|
response: HttpResponse;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { ApifyClientError } from './apify_client_error.js';
|
|
1
2
|
/**
|
|
2
|
-
* Thrown when a response
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Thrown when the body of a successful response does not parse as its content type claims, for example a non-JSON
|
|
4
|
+
* value stored under `application/json`. The response arrived in full, so the request is not retried. An error
|
|
5
|
+
* status with an unparsable body throws {@link ApifyApiError} for its status code.
|
|
5
6
|
*/
|
|
6
|
-
export class InvalidResponseBodyError extends
|
|
7
|
+
export class InvalidResponseBodyError extends ApifyClientError {
|
|
7
8
|
code;
|
|
8
9
|
/** The response whose body did not parse, with the body as the transport returned it. */
|
|
9
10
|
response;
|
package/dist/models.d.ts
CHANGED
|
@@ -62,7 +62,6 @@ export type ErrorType = Schemas['ErrorType'];
|
|
|
62
62
|
* TODO: Remove once the spec covers them.
|
|
63
63
|
*/
|
|
64
64
|
export interface DatasetResourceSpecGaps {
|
|
65
|
-
title?: string;
|
|
66
65
|
username?: string;
|
|
67
66
|
}
|
|
68
67
|
export interface DatasetResourceRePointed {
|
|
@@ -143,14 +142,6 @@ export interface WebhookDispatchEventData extends GeneratedWebhookDispatchEventD
|
|
|
143
142
|
}
|
|
144
143
|
type GeneratedKeyValueStoreStats = Schemas['KeyValueStoreStats'];
|
|
145
144
|
type GeneratedKeyValueStoreKey = Schemas['KeyValueStoreKey'];
|
|
146
|
-
/**
|
|
147
|
-
* Fields the API returns on a key-value store that the OpenAPI spec does not describe yet.
|
|
148
|
-
*
|
|
149
|
-
* TODO: Remove once the spec covers them.
|
|
150
|
-
*/
|
|
151
|
-
export interface KeyValueStoreResourceSpecGaps {
|
|
152
|
-
title?: string;
|
|
153
|
-
}
|
|
154
145
|
export interface KeyValueStoreResourceRePointed {
|
|
155
146
|
stats?: KeyValueStoreStats;
|
|
156
147
|
generalAccess?: STORAGE_GENERAL_ACCESS | null;
|
|
@@ -161,7 +152,7 @@ export interface KeyValueStoreResourceRePointed {
|
|
|
161
152
|
* Key-value stores are used to store arbitrary data records or files. Each record is identified
|
|
162
153
|
* by a unique key and can contain any data - JSON objects, strings, binary files, etc.
|
|
163
154
|
*/
|
|
164
|
-
export interface KeyValueStoreResource extends Omit<Schemas['KeyValueStoreResource'], keyof KeyValueStoreResourceRePointed>, KeyValueStoreResourceRePointed
|
|
155
|
+
export interface KeyValueStoreResource extends Omit<Schemas['KeyValueStoreResource'], keyof KeyValueStoreResourceRePointed>, KeyValueStoreResourceRePointed {
|
|
165
156
|
}
|
|
166
157
|
/** Statistics about Key-Value Store usage and storage. */
|
|
167
158
|
export interface KeyValueStoreStats extends GeneratedKeyValueStoreStats {
|
|
@@ -222,6 +213,7 @@ export interface VersionRePointed {
|
|
|
222
213
|
}
|
|
223
214
|
export interface VersionClientNarrowings {
|
|
224
215
|
sourceType: `${ActorSourceType}`;
|
|
216
|
+
actorPath?: GeneratedVersion['actorPath'];
|
|
225
217
|
}
|
|
226
218
|
/**
|
|
227
219
|
* Fields every Actor version carries, whatever its source type.
|
|
@@ -229,6 +221,7 @@ export interface VersionClientNarrowings {
|
|
|
229
221
|
* The spec models a version as one flat object with all four source locations optional. This client
|
|
230
222
|
* keeps a union discriminated on `sourceType` instead, because that narrows the source location down
|
|
231
223
|
* to the single field which applies -- so the four are dropped here and reinstated per variant.
|
|
224
|
+
* `actorPath` is dropped as well, and only the `SOURCE_FILES` and `TARBALL` variants reinstate it.
|
|
232
225
|
*/
|
|
233
226
|
export interface BaseVersion<SourceType extends `${ActorSourceType}`> extends Omit<GeneratedVersion, keyof VersionClientNarrowings | keyof VersionRePointed | VersionSourceLocation>, VersionRePointed {
|
|
234
227
|
sourceType: SourceType;
|
|
@@ -239,6 +232,12 @@ export interface BaseVersion<SourceType extends `${ActorSourceType}`> extends Om
|
|
|
239
232
|
*/
|
|
240
233
|
export interface VersionSourceFiles extends BaseVersion<`${ActorSourceType.SourceFiles}`> {
|
|
241
234
|
sourceFiles: (SourceCodeFile | SourceCodeFolder)[];
|
|
235
|
+
/**
|
|
236
|
+
* The Actor's folder inside the uploaded source, as a POSIX path relative to the upload root, such as
|
|
237
|
+
* `actors/typescript-actor`. When absent or `null`, the upload root is the Actor's folder. It has 1 to 255
|
|
238
|
+
* characters, with no leading, trailing, or repeated `/` and no `.` or `..` segment.
|
|
239
|
+
*/
|
|
240
|
+
actorPath?: GeneratedVersion['actorPath'];
|
|
242
241
|
}
|
|
243
242
|
/** An Actor version built from a Git repository. */
|
|
244
243
|
export interface VersionGitRepo extends BaseVersion<`${ActorSourceType.GitRepo}`> {
|
|
@@ -247,6 +246,12 @@ export interface VersionGitRepo extends BaseVersion<`${ActorSourceType.GitRepo}`
|
|
|
247
246
|
/** An Actor version built from a downloadable tarball or ZIP archive. */
|
|
248
247
|
export interface VersionTarball extends BaseVersion<`${ActorSourceType.Tarball}`> {
|
|
249
248
|
tarballUrl: NonNullable<GeneratedVersion['tarballUrl']>;
|
|
249
|
+
/**
|
|
250
|
+
* The Actor's folder inside the archive, as a POSIX path relative to the archive root, such as
|
|
251
|
+
* `actors/typescript-actor`. When absent or `null`, the archive root is the Actor's folder. It has 1 to 255
|
|
252
|
+
* characters, with no leading, trailing, or repeated `/` and no `.` or `..` segment.
|
|
253
|
+
*/
|
|
254
|
+
actorPath?: GeneratedVersion['actorPath'];
|
|
250
255
|
}
|
|
251
256
|
/** An Actor version built from a GitHub Gist. */
|
|
252
257
|
export interface VersionGitHubGist extends BaseVersion<`${ActorSourceType.GitHubGist}`> {
|
|
@@ -303,19 +308,6 @@ export interface DefaultRunOptionsRePointed {
|
|
|
303
308
|
/** Default configuration options for Actor runs. */
|
|
304
309
|
export interface DefaultRunOptions extends Omit<Schemas['DefaultRunOptions'], keyof DefaultRunOptionsRePointed>, DefaultRunOptionsRePointed {
|
|
305
310
|
}
|
|
306
|
-
/**
|
|
307
|
-
* Fields of an Actor definition that the OpenAPI spec does not describe yet.
|
|
308
|
-
*
|
|
309
|
-
* TODO: Remove once the spec covers them.
|
|
310
|
-
*/
|
|
311
|
-
export interface ActorDefinitionSpecGaps {
|
|
312
|
-
/**
|
|
313
|
-
* Output schema for the Actor.
|
|
314
|
-
*
|
|
315
|
-
* @see https://docs.apify.com/platform/actors/development/actor-definition/output-schema
|
|
316
|
-
*/
|
|
317
|
-
output?: object | null;
|
|
318
|
-
}
|
|
319
311
|
type GeneratedActorDefinition = Schemas['ActorDefinition'];
|
|
320
312
|
/**
|
|
321
313
|
* Actor definition from the `.actor/actor.json` file.
|
|
@@ -324,7 +316,7 @@ type GeneratedActorDefinition = Schemas['ActorDefinition'];
|
|
|
324
316
|
* @see https://docs.apify.com/platform/actors/development/actor-definition/actor-json
|
|
325
317
|
* @since Added in 2.11.0
|
|
326
318
|
*/
|
|
327
|
-
export interface ActorDefinition extends GeneratedActorDefinition
|
|
319
|
+
export interface ActorDefinition extends GeneratedActorDefinition {
|
|
328
320
|
}
|
|
329
321
|
export interface ActorChargeEventRePointed {
|
|
330
322
|
eventTieredPricingUsd?: TieredPricingPerEvent;
|
|
@@ -437,6 +429,7 @@ export interface ActorListItem extends Omit<Schemas['ActorListItem'], keyof Acto
|
|
|
437
429
|
type GeneratedBuildUsage = Schemas['BuildUsage'];
|
|
438
430
|
type GeneratedBuildStats = Schemas['BuildStats'];
|
|
439
431
|
type GeneratedBuildOptions = Schemas['BuildOptions'];
|
|
432
|
+
type GeneratedBuildActVersion = NonNullable<Schemas['Build']['actVersion']>;
|
|
440
433
|
/**
|
|
441
434
|
* Resource usage for an Actor build.
|
|
442
435
|
* @since Added in 2.7.2
|
|
@@ -463,6 +456,10 @@ export interface BuildRePointed {
|
|
|
463
456
|
usageUsd?: BuildUsage | null;
|
|
464
457
|
actorDefinition?: ActorDefinition | null;
|
|
465
458
|
status: ValueOf<typeof ACTOR_JOB_STATUSES>;
|
|
459
|
+
/** The API returns `buildTag` as `null` for some builds, which the specification types as a string. */
|
|
460
|
+
actVersion?: Omit<GeneratedBuildActVersion, 'buildTag'> & {
|
|
461
|
+
buildTag?: string | null;
|
|
462
|
+
};
|
|
466
463
|
}
|
|
467
464
|
/**
|
|
468
465
|
* Represents an Actor build.
|
|
@@ -519,20 +516,12 @@ export interface RunMetaRePointed {
|
|
|
519
516
|
/** Metadata about how an Actor run was initiated. */
|
|
520
517
|
export interface RunMeta extends Omit<Schemas['RunMeta'], keyof RunMetaRePointed>, RunMetaRePointed {
|
|
521
518
|
}
|
|
522
|
-
/**
|
|
523
|
-
* Fields the API returns in an Actor run's options that the OpenAPI spec does not describe yet.
|
|
524
|
-
*
|
|
525
|
-
* TODO: Remove once the spec covers it.
|
|
526
|
-
*/
|
|
527
|
-
export interface RunOptionsSpecGaps {
|
|
528
|
-
restartOnError?: boolean;
|
|
529
|
-
}
|
|
530
519
|
/**
|
|
531
520
|
* Configuration options used for an Actor run.
|
|
532
521
|
*
|
|
533
522
|
* These are the actual options that were applied to the run (may differ from requested options).
|
|
534
523
|
*/
|
|
535
|
-
export interface RunOptions extends GeneratedRunOptions
|
|
524
|
+
export interface RunOptions extends GeneratedRunOptions {
|
|
536
525
|
}
|
|
537
526
|
export interface RunListItemRePointed {
|
|
538
527
|
meta: RunMeta;
|
|
@@ -604,19 +593,8 @@ export interface Task extends Omit<Schemas['Task'], keyof TaskRePointed>, TaskRe
|
|
|
604
593
|
export interface TaskListItemRePointed {
|
|
605
594
|
stats?: TaskStats | null;
|
|
606
595
|
}
|
|
607
|
-
/**
|
|
608
|
-
* Fields the API returns on a listed task that the OpenAPI spec does not describe yet.
|
|
609
|
-
*
|
|
610
|
-
* `description` is deliberately not here, although the spec has it on the full `Task` resource: the
|
|
611
|
-
* list endpoint publishes a smaller set of fields, and that is one of the fields it leaves out.
|
|
612
|
-
*
|
|
613
|
-
* TODO: Remove once the spec covers it.
|
|
614
|
-
*/
|
|
615
|
-
export interface TaskListItemSpecGaps {
|
|
616
|
-
title?: string | null;
|
|
617
|
-
}
|
|
618
596
|
/** A task as it appears in a listing, which carries fewer fields than the full resource. */
|
|
619
|
-
export interface TaskListItem extends Omit<Schemas['TaskListItem'], keyof TaskListItemRePointed>, TaskListItemRePointed
|
|
597
|
+
export interface TaskListItem extends Omit<Schemas['TaskListItem'], keyof TaskListItemRePointed>, TaskListItemRePointed {
|
|
620
598
|
}
|
|
621
599
|
export interface StoreActorRePointed {
|
|
622
600
|
stats: ActorStats;
|
|
@@ -675,17 +653,6 @@ export interface WebhookLastDispatchRePointed {
|
|
|
675
653
|
/** The summary of a webhook's most recent dispatch that the webhook resource carries. */
|
|
676
654
|
export interface WebhookLastDispatch extends Omit<Schemas['WebhookLastDispatch'], keyof WebhookLastDispatchRePointed>, WebhookLastDispatchRePointed {
|
|
677
655
|
}
|
|
678
|
-
/**
|
|
679
|
-
* Fields the API returns on a webhook that the OpenAPI spec does not describe yet.
|
|
680
|
-
*
|
|
681
|
-
* The spec does carry `isApifyIntegration` on `WebhookListItem`, the listing shape, and simply omits it
|
|
682
|
-
* from the full `WebhookResource` schema.
|
|
683
|
-
*
|
|
684
|
-
* TODO: Remove once the spec covers it.
|
|
685
|
-
*/
|
|
686
|
-
export interface WebhookResourceSpecGaps {
|
|
687
|
-
isApifyIntegration?: boolean;
|
|
688
|
-
}
|
|
689
656
|
export interface WebhookResourceRePointed {
|
|
690
657
|
condition: WebhookCondition;
|
|
691
658
|
stats?: WebhookStats | null;
|
|
@@ -698,7 +665,7 @@ export interface WebhookResourceRePointed {
|
|
|
698
665
|
* Webhooks send HTTP POST requests to specified URLs when certain events occur
|
|
699
666
|
* (e.g., Actor run succeeds, fails, or times out).
|
|
700
667
|
*/
|
|
701
|
-
export interface WebhookResource extends Omit<Schemas['WebhookResource'], keyof WebhookResourceRePointed>, WebhookResourceRePointed
|
|
668
|
+
export interface WebhookResource extends Omit<Schemas['WebhookResource'], keyof WebhookResourceRePointed>, WebhookResourceRePointed {
|
|
702
669
|
}
|
|
703
670
|
type GeneratedScheduleActionRunInput = Schemas['ScheduleActionRunInput'];
|
|
704
671
|
/**
|
|
@@ -741,12 +708,15 @@ export interface ScheduleRePointed {
|
|
|
741
708
|
export interface ScheduleClientNarrowings {
|
|
742
709
|
timezone: Timezone;
|
|
743
710
|
}
|
|
711
|
+
export interface ScheduleSpecNarrowings {
|
|
712
|
+
uiState?: NonNullable<Schemas['Schedule']['uiState']> | null;
|
|
713
|
+
}
|
|
744
714
|
/**
|
|
745
715
|
* Represents a schedule for automated Actor or Task runs.
|
|
746
716
|
*
|
|
747
717
|
* Schedules use cron expressions to define when Actors or Tasks should run automatically.
|
|
748
718
|
*/
|
|
749
|
-
export interface Schedule extends Omit<Schemas['Schedule'], keyof ScheduleRePointed | keyof ScheduleClientNarrowings>, ScheduleRePointed, ScheduleClientNarrowings {
|
|
719
|
+
export interface Schedule extends Omit<Schemas['Schedule'], keyof ScheduleRePointed | keyof ScheduleClientNarrowings | keyof ScheduleSpecNarrowings>, ScheduleRePointed, ScheduleClientNarrowings, ScheduleSpecNarrowings {
|
|
750
720
|
}
|
|
751
721
|
type GeneratedUserProfile = Schemas['UserProfile'];
|
|
752
722
|
type GeneratedProxyGroup = Schemas['ProxyGroup'];
|
|
@@ -907,12 +877,11 @@ export interface RequestQueueStats extends GeneratedRequestQueueStats {
|
|
|
907
877
|
* Fields the API returns on a request queue that the OpenAPI spec does not describe yet.
|
|
908
878
|
*
|
|
909
879
|
* The spec does carry `username` on `RequestQueueListItem`, the listing shape, and simply omits it from the
|
|
910
|
-
* full `RequestQueueResource` schema.
|
|
880
|
+
* full `RequestQueueResource` schema.
|
|
911
881
|
*
|
|
912
|
-
* TODO: Remove once the spec covers
|
|
882
|
+
* TODO: Remove once the spec covers it.
|
|
913
883
|
*/
|
|
914
884
|
export interface RequestQueueResourceSpecGaps {
|
|
915
|
-
title?: string;
|
|
916
885
|
username?: string;
|
|
917
886
|
}
|
|
918
887
|
export interface RequestQueueResourceRePointed {
|