apify-client 3.0.0-beta.1 → 3.0.0-beta.3
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 +2 -2
- package/dist/apify_api_error.js +5 -9
- package/dist/apify_client.d.ts +27 -27
- package/dist/apify_client.js +86 -91
- package/dist/base/api_client.d.ts +3 -3
- package/dist/base/api_client.js +6 -10
- package/dist/base/resource_client.d.ts +1 -1
- package/dist/base/resource_client.js +14 -18
- package/dist/base/resource_collection_client.d.ts +2 -2
- package/dist/base/resource_collection_client.js +6 -10
- package/dist/body_parser.js +6 -11
- package/dist/bundle.js +35 -47
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.js +1 -2
- package/dist/http_client.d.ts +2 -2
- package/dist/http_client.js +23 -28
- package/dist/index.d.ts +32 -32
- package/dist/index.js +31 -36
- package/dist/interceptors.d.ts +1 -1
- package/dist/interceptors.js +14 -19
- package/dist/models.d.ts +3 -3
- package/dist/models.js +8 -11
- package/dist/resource_clients/actor.d.ts +13 -13
- package/dist/resource_clients/actor.js +67 -71
- package/dist/resource_clients/actor_collection.d.ts +7 -7
- package/dist/resource_clients/actor_collection.js +14 -18
- package/dist/resource_clients/actor_env_var.d.ts +3 -3
- package/dist/resource_clients/actor_env_var.js +4 -8
- package/dist/resource_clients/actor_env_var_collection.d.ts +4 -4
- package/dist/resource_clients/actor_env_var_collection.js +5 -9
- package/dist/resource_clients/actor_version.d.ts +7 -7
- package/dist/resource_clients/actor_version.js +12 -17
- package/dist/resource_clients/actor_version_collection.d.ts +4 -4
- package/dist/resource_clients/actor_version_collection.js +5 -9
- package/dist/resource_clients/build.d.ts +5 -5
- package/dist/resource_clients/build.js +11 -15
- package/dist/resource_clients/build_collection.d.ts +5 -5
- package/dist/resource_clients/build_collection.js +8 -12
- package/dist/resource_clients/dataset.d.ts +5 -5
- package/dist/resource_clients/dataset.js +72 -76
- package/dist/resource_clients/dataset_collection.d.ts +4 -4
- package/dist/resource_clients/dataset_collection.js +15 -19
- package/dist/resource_clients/key_value_store.d.ts +4 -4
- package/dist/resource_clients/key_value_store.js +57 -62
- package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
- package/dist/resource_clients/key_value_store_collection.js +15 -19
- package/dist/resource_clients/log.d.ts +2 -2
- package/dist/resource_clients/log.js +15 -22
- package/dist/resource_clients/request_queue.d.ts +4 -4
- package/dist/resource_clients/request_queue.js +91 -96
- package/dist/resource_clients/request_queue_collection.d.ts +4 -4
- package/dist/resource_clients/request_queue_collection.js +13 -17
- package/dist/resource_clients/run.d.ts +8 -8
- package/dist/resource_clients/run.js +46 -50
- package/dist/resource_clients/run_collection.d.ts +4 -4
- package/dist/resource_clients/run_collection.js +13 -17
- package/dist/resource_clients/schedule.d.ts +6 -6
- package/dist/resource_clients/schedule.js +7 -12
- package/dist/resource_clients/schedule_collection.d.ts +4 -4
- package/dist/resource_clients/schedule_collection.js +10 -14
- package/dist/resource_clients/store_collection.d.ts +5 -5
- package/dist/resource_clients/store_collection.js +13 -17
- package/dist/resource_clients/task.d.ts +9 -9
- package/dist/resource_clients/task.js +44 -48
- package/dist/resource_clients/task_collection.d.ts +6 -6
- package/dist/resource_clients/task_collection.js +9 -13
- package/dist/resource_clients/user.d.ts +5 -5
- package/dist/resource_clients/user.js +8 -13
- package/dist/resource_clients/webhook.d.ts +6 -6
- package/dist/resource_clients/webhook.js +8 -12
- package/dist/resource_clients/webhook_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_collection.js +10 -14
- package/dist/resource_clients/webhook_dispatch.d.ts +5 -5
- package/dist/resource_clients/webhook_dispatch.js +3 -8
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_dispatch_collection.js +8 -12
- package/dist/statistics.js +5 -9
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +5 -13
- package/dist/utils.js +30 -69
- package/package.json +10 -12
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -157
- package/dist/index.mjs +0 -42
package/dist/utils.js
CHANGED
|
@@ -1,53 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.isNonArrayObject = isNonArrayObject;
|
|
6
|
-
exports.pluckData = pluckData;
|
|
7
|
-
exports.catchNotFoundOrThrow = catchNotFoundOrThrow;
|
|
8
|
-
exports.parseDateFields = parseDateFields;
|
|
9
|
-
exports.stringifyWebhooksToBase64 = stringifyWebhooksToBase64;
|
|
10
|
-
exports.maybeCompressValue = maybeCompressValue;
|
|
11
|
-
exports.sliceArrayByByteLength = sliceArrayByByteLength;
|
|
12
|
-
exports.isNode = isNode;
|
|
13
|
-
exports.isBuffer = isBuffer;
|
|
14
|
-
exports.isStream = isStream;
|
|
15
|
-
exports.getVersionData = getVersionData;
|
|
16
|
-
exports.cast = cast;
|
|
17
|
-
exports.asArray = asArray;
|
|
18
|
-
exports.applyQueryParamsToUrl = applyQueryParamsToUrl;
|
|
19
|
-
exports.toPathSegment = toPathSegment;
|
|
20
|
-
exports.toPath = toPath;
|
|
21
|
-
const zod_1 = require("zod");
|
|
22
|
-
const argument_validation_error_1 = require("./argument_validation_error");
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { parseArgument } from '@apify/validations';
|
|
3
|
+
// @ts-ignore if we enable `resolveJsonModule`, we end up with a `src` folder in `dist`
|
|
4
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
23
5
|
const NOT_FOUND_STATUS_CODE = 404;
|
|
24
6
|
const RECORD_NOT_FOUND_TYPE = 'record-not-found';
|
|
25
7
|
const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
|
|
26
8
|
const MIN_COMPRESS_BYTES = 1024;
|
|
27
|
-
|
|
28
|
-
// any tree-shaking bundler drops it and every message degrades to a bare "Invalid input". Passing it
|
|
29
|
-
// in per parse keeps them intact without reaching into the zod config the whole process shares.
|
|
30
|
-
const { localeError } = zod_1.z.locales.en();
|
|
31
|
-
/**
|
|
32
|
-
* Parses `value` with `schema`, returning the typed result (with schema defaults applied).
|
|
33
|
-
* Throws {@link ArgumentValidationError} on failure.
|
|
34
|
-
*
|
|
35
|
-
* The optional `label` names the interface being validated and is appended to every error line
|
|
36
|
-
* (e.g. ``... at `memory` in `ActorStartOptions` ``).
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
function parseArgument(value, schema, label) {
|
|
40
|
-
const result = schema.safeParse(value, { error: localeError });
|
|
41
|
-
if (!result.success) {
|
|
42
|
-
throw new argument_validation_error_1.ArgumentValidationError(result.error, value, label);
|
|
43
|
-
}
|
|
44
|
-
return result.data;
|
|
45
|
-
}
|
|
9
|
+
export { parseArgument };
|
|
46
10
|
/**
|
|
47
11
|
* Accepts any non-null, non-array object as a predicate for `z.custom()`.
|
|
48
12
|
* @internal
|
|
49
13
|
*/
|
|
50
|
-
function isNonArrayObject(value) {
|
|
14
|
+
export function isNonArrayObject(value) {
|
|
51
15
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
52
16
|
}
|
|
53
17
|
/**
|
|
@@ -56,14 +20,14 @@ function isNonArrayObject(value) {
|
|
|
56
20
|
* the value itself instead of a copy.
|
|
57
21
|
* @internal
|
|
58
22
|
*/
|
|
59
|
-
|
|
23
|
+
export const anyObjectSchema = z.custom(isNonArrayObject, {
|
|
60
24
|
error: 'Invalid input: expected an object',
|
|
61
25
|
});
|
|
62
26
|
/**
|
|
63
27
|
* Returns object's 'data' property or throws if parameter is not an object,
|
|
64
28
|
* or an object without a 'data' property.
|
|
65
29
|
*/
|
|
66
|
-
function pluckData(obj) {
|
|
30
|
+
export function pluckData(obj) {
|
|
67
31
|
if (typeof obj === 'object' && obj) {
|
|
68
32
|
if (typeof obj.data !== 'undefined')
|
|
69
33
|
return obj.data;
|
|
@@ -74,7 +38,7 @@ function pluckData(obj) {
|
|
|
74
38
|
* If given HTTP error has NOT_FOUND_STATUS_CODE status code then returns undefined.
|
|
75
39
|
* Otherwise rethrows error.
|
|
76
40
|
*/
|
|
77
|
-
function catchNotFoundOrThrow(err) {
|
|
41
|
+
export function catchNotFoundOrThrow(err) {
|
|
78
42
|
const isNotFoundStatus = err.statusCode === NOT_FOUND_STATUS_CODE;
|
|
79
43
|
const isNotFoundMessage = err.type === RECORD_NOT_FOUND_TYPE || err.type === RECORD_OR_TOKEN_NOT_FOUND_TYPE || err.httpMethod === 'head';
|
|
80
44
|
const isNotFoundError = isNotFoundStatus && isNotFoundMessage;
|
|
@@ -91,7 +55,7 @@ function catchNotFoundOrThrow(err) {
|
|
|
91
55
|
*
|
|
92
56
|
* If the field cannot be converted to Date, it is left as is.
|
|
93
57
|
*/
|
|
94
|
-
function parseDateFields(input, shouldParseField = null, depth = 0) {
|
|
58
|
+
export function parseDateFields(input, shouldParseField = null, depth = 0) {
|
|
95
59
|
// Don't go too deep to avoid stack overflows (especially if there is a circular reference). The depth of 4
|
|
96
60
|
// corresponds to obj.items.[x].someArrayField.[y].field, which is what a list response looks like: it
|
|
97
61
|
// nests one level deeper than the single resource it wraps, because both the item array and the nested
|
|
@@ -131,7 +95,7 @@ function parseDateFields(input, shouldParseField = null, depth = 0) {
|
|
|
131
95
|
/**
|
|
132
96
|
* Helper function that converts array of webhooks to base64 string
|
|
133
97
|
*/
|
|
134
|
-
function stringifyWebhooksToBase64(webhooks) {
|
|
98
|
+
export function stringifyWebhooksToBase64(webhooks) {
|
|
135
99
|
if (!webhooks)
|
|
136
100
|
return;
|
|
137
101
|
const webhooksJson = JSON.stringify(webhooks);
|
|
@@ -172,7 +136,7 @@ async function gzipValue(value) {
|
|
|
172
136
|
* Compress the passed value using brotli, falling back to gzip. Returns undefined if the data is
|
|
173
137
|
* too small / wrong type, or if neither algorithm is available.
|
|
174
138
|
*/
|
|
175
|
-
async function maybeCompressValue(value) {
|
|
139
|
+
export async function maybeCompressValue(value) {
|
|
176
140
|
if (!isNode())
|
|
177
141
|
return undefined;
|
|
178
142
|
// Request compression is not that important so let's
|
|
@@ -201,7 +165,7 @@ async function maybeCompressValue(value) {
|
|
|
201
165
|
/**
|
|
202
166
|
* Helper function slice the items from array to fit the max byte length.
|
|
203
167
|
*/
|
|
204
|
-
function sliceArrayByByteLength(array, maxByteLength, startIndex) {
|
|
168
|
+
export function sliceArrayByByteLength(array, maxByteLength, startIndex) {
|
|
205
169
|
const stringByteLength = (str) => (isNode() ? Buffer.byteLength(str) : new Blob([str]).size);
|
|
206
170
|
const arrayByteLength = stringByteLength(JSON.stringify(array));
|
|
207
171
|
if (arrayByteLength < maxByteLength)
|
|
@@ -222,12 +186,12 @@ function sliceArrayByByteLength(array, maxByteLength, startIndex) {
|
|
|
222
186
|
}
|
|
223
187
|
return slicedArray;
|
|
224
188
|
}
|
|
225
|
-
function isNode() {
|
|
189
|
+
export function isNode() {
|
|
226
190
|
if (typeof BROWSER_BUILD !== 'undefined')
|
|
227
191
|
return false;
|
|
228
192
|
return !!(typeof process !== 'undefined' && process.versions && process.versions.node);
|
|
229
193
|
}
|
|
230
|
-
function isBuffer(value) {
|
|
194
|
+
export function isBuffer(value) {
|
|
231
195
|
// Tag checks rather than `instanceof`, to also match buffers from another realm. `isView()`
|
|
232
196
|
// additionally covers `DataView`, which is not raw binary content.
|
|
233
197
|
if (ArrayBuffer.isView(value))
|
|
@@ -237,23 +201,22 @@ function isBuffer(value) {
|
|
|
237
201
|
function isTagged(value, tag) {
|
|
238
202
|
return Object.prototype.toString.call(value) === `[object ${tag}]`;
|
|
239
203
|
}
|
|
240
|
-
function isStream(value) {
|
|
204
|
+
export function isStream(value) {
|
|
241
205
|
if (value === null || typeof value !== 'object')
|
|
242
206
|
return false;
|
|
243
207
|
const { on, pipe } = value;
|
|
244
208
|
return typeof on === 'function' && typeof pipe === 'function';
|
|
245
209
|
}
|
|
246
|
-
function getVersionData() {
|
|
210
|
+
export function getVersionData() {
|
|
247
211
|
if (typeof BROWSER_BUILD !== 'undefined') {
|
|
248
212
|
return { version: VERSION };
|
|
249
213
|
}
|
|
250
|
-
|
|
251
|
-
return require('../package.json');
|
|
214
|
+
return packageJson;
|
|
252
215
|
}
|
|
253
216
|
/**
|
|
254
217
|
* Helper class to create async iterators from paginated list endpoints with exclusive start key.
|
|
255
218
|
*/
|
|
256
|
-
class RequestQueuePaginationIterator {
|
|
219
|
+
export class RequestQueuePaginationIterator {
|
|
257
220
|
maxPageLimit;
|
|
258
221
|
getPage;
|
|
259
222
|
limit;
|
|
@@ -293,21 +256,20 @@ class RequestQueuePaginationIterator {
|
|
|
293
256
|
}
|
|
294
257
|
}
|
|
295
258
|
}
|
|
296
|
-
exports.RequestQueuePaginationIterator = RequestQueuePaginationIterator;
|
|
297
259
|
/**
|
|
298
260
|
* Schema shape of {@link PaginationOptions}, to spread into every paginating client's list schema. One
|
|
299
261
|
* copy stops it drifting from the interface.
|
|
300
262
|
* @internal
|
|
301
263
|
*/
|
|
302
|
-
|
|
303
|
-
limit:
|
|
304
|
-
offset:
|
|
305
|
-
chunkSize:
|
|
264
|
+
export const paginationOptionsShape = {
|
|
265
|
+
limit: z.number().min(0).optional(),
|
|
266
|
+
offset: z.number().min(0).optional(),
|
|
267
|
+
chunkSize: z.number().positive().optional(),
|
|
306
268
|
};
|
|
307
|
-
function cast(input) {
|
|
269
|
+
export function cast(input) {
|
|
308
270
|
return input;
|
|
309
271
|
}
|
|
310
|
-
function asArray(value) {
|
|
272
|
+
export function asArray(value) {
|
|
311
273
|
if (Array.isArray(value)) {
|
|
312
274
|
return value;
|
|
313
275
|
}
|
|
@@ -316,7 +278,7 @@ function asArray(value) {
|
|
|
316
278
|
/**
|
|
317
279
|
* Adds query parameters to a given URL based on the provided options object.
|
|
318
280
|
*/
|
|
319
|
-
function applyQueryParamsToUrl(url, options) {
|
|
281
|
+
export function applyQueryParamsToUrl(url, options) {
|
|
320
282
|
for (const [key, value] of Object.entries(options ?? {})) {
|
|
321
283
|
// skip undefined values
|
|
322
284
|
if (value === undefined)
|
|
@@ -335,12 +297,11 @@ function applyQueryParamsToUrl(url, options) {
|
|
|
335
297
|
* is present. Pass the options interface as `T`, so that a misspelled key is a type error.
|
|
336
298
|
* @internal
|
|
337
299
|
*/
|
|
338
|
-
const mutuallyExclusive = (...keys) => [
|
|
300
|
+
export const mutuallyExclusive = (...keys) => [
|
|
339
301
|
(value) => keys.filter((key) => typeof value[key] !== 'undefined').length <= 1,
|
|
340
302
|
`At most one of the following fields is allowed: ${keys.join(', ')}`,
|
|
341
303
|
];
|
|
342
|
-
|
|
343
|
-
const pathSegmentSchema = zod_1.z
|
|
304
|
+
const pathSegmentSchema = z
|
|
344
305
|
.string()
|
|
345
306
|
.nonempty()
|
|
346
307
|
.refine((v) => v !== '.' && v !== '..', { error: 'URL path must not contain dot segments' });
|
|
@@ -350,7 +311,7 @@ const pathSegmentSchema = zod_1.z
|
|
|
350
311
|
* Empty strings and dot segments are rejected instead of encoded, because URL parsers resolve
|
|
351
312
|
* dot segments after decoding - `records/%2E%2E` collapses to the parent endpoint just like `records/..`.
|
|
352
313
|
*/
|
|
353
|
-
function toPathSegment(value) {
|
|
314
|
+
export function toPathSegment(value) {
|
|
354
315
|
const valueParsed = parseArgument(value, pathSegmentSchema);
|
|
355
316
|
return encodeURIComponent(valueParsed);
|
|
356
317
|
}
|
|
@@ -358,6 +319,6 @@ function toPathSegment(value) {
|
|
|
358
319
|
* Builds a URL path from segments. A plain string is used as-is, so literal paths such as
|
|
359
320
|
* `requests/batch` keep their separators; an array has each of its segments encoded individually.
|
|
360
321
|
*/
|
|
361
|
-
function toPath(path) {
|
|
322
|
+
export function toPath(path) {
|
|
362
323
|
return Array.isArray(path) ? path.map(toPathSegment).join('/') : path;
|
|
363
324
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apify-client",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.3",
|
|
4
4
|
"description": "Apify API client for JavaScript",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
7
7
|
},
|
|
8
|
+
"type": "module",
|
|
8
9
|
"main": "dist/index.js",
|
|
9
|
-
"module": "dist/index.mjs",
|
|
10
10
|
"types": "dist/index.d.ts",
|
|
11
11
|
"browser": "dist/bundle.js",
|
|
12
12
|
"unpkg": "dist/bundle.js",
|
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
"./package.json": "./package.json",
|
|
15
15
|
"./browser": "./dist/bundle.js",
|
|
16
16
|
".": {
|
|
17
|
-
"import": "./dist/index.mjs",
|
|
18
|
-
"require": "./dist/index.js",
|
|
19
17
|
"types": "./dist/index.d.ts",
|
|
20
|
-
"browser": "./dist/bundle.js"
|
|
18
|
+
"browser": "./dist/bundle.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
21
20
|
}
|
|
22
21
|
},
|
|
23
22
|
"keywords": [
|
|
@@ -58,9 +57,10 @@
|
|
|
58
57
|
}
|
|
59
58
|
},
|
|
60
59
|
"dependencies": {
|
|
61
|
-
"@apify/consts": "^
|
|
62
|
-
"@apify/log": "^
|
|
63
|
-
"@apify/utilities": "^
|
|
60
|
+
"@apify/consts": "^3.0.1",
|
|
61
|
+
"@apify/log": "^3.0.1",
|
|
62
|
+
"@apify/utilities": "^3.0.1",
|
|
63
|
+
"@apify/validations": "^1.1.0",
|
|
64
64
|
"@crawlee/types": "^3.3.0",
|
|
65
65
|
"ansi-colors": "^4.1.1",
|
|
66
66
|
"async-retry": "^1.3.3",
|
|
@@ -69,12 +69,12 @@
|
|
|
69
69
|
"proxy-agent": "^6.5.0",
|
|
70
70
|
"tslib": "^2.5.0",
|
|
71
71
|
"type-fest": "^4.0.0",
|
|
72
|
-
"zod": "^4.
|
|
72
|
+
"zod": "^4.5.4"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@apify/oxlint-config": "^0.3.0",
|
|
76
76
|
"@apify/tsconfig": "^0.2.0",
|
|
77
|
-
"@crawlee/puppeteer": "
|
|
77
|
+
"@crawlee/puppeteer": "4.0.0-beta.165",
|
|
78
78
|
"@rsbuild/core": "^2.0.0",
|
|
79
79
|
"@rsbuild/plugin-node-polyfill": "^1.3.0",
|
|
80
80
|
"@rspack/cli": "^2.0.0",
|
|
@@ -89,7 +89,6 @@
|
|
|
89
89
|
"compression": "^1.7.4",
|
|
90
90
|
"esbuild": "0.28.2",
|
|
91
91
|
"express": "^5.0.0",
|
|
92
|
-
"gen-esm-wrapper": "^1.1.2",
|
|
93
92
|
"openapi-typescript": "7.13.0",
|
|
94
93
|
"oxfmt": "0.65.0",
|
|
95
94
|
"oxlint": "1.79.0",
|
|
@@ -111,7 +110,6 @@
|
|
|
111
110
|
},
|
|
112
111
|
"scripts": {
|
|
113
112
|
"build": "pnpm clean && pnpm build:node && pnpm build:browser",
|
|
114
|
-
"postbuild": "gen-esm-wrapper dist/index.js dist/index.mjs",
|
|
115
113
|
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
116
114
|
"test": "pnpm build && vitest run --project unit",
|
|
117
115
|
"test:integration": "vitest run --project integration",
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
/**
|
|
3
|
-
* Thrown when an argument fails schema validation.
|
|
4
|
-
*
|
|
5
|
-
* Its `message` is a human-readable sentence naming the offending field and the
|
|
6
|
-
* value it received (rather than a raw JSON dump). The structured
|
|
7
|
-
* {@link https://zod.dev | zod} issues are available on `issues`, and the
|
|
8
|
-
* original `ZodError` on `cause`, for programmatic inspection.
|
|
9
|
-
*
|
|
10
|
-
* `apify-client` sits below `@crawlee/core` and the Apify SDK in the dependency
|
|
11
|
-
* graph, so it defines its own error type rather than importing one from them.
|
|
12
|
-
*/
|
|
13
|
-
export declare class ArgumentValidationError extends Error {
|
|
14
|
-
/** Structured issues from the underlying schema check. */
|
|
15
|
-
readonly issues: z.ZodError['issues'];
|
|
16
|
-
constructor(error: z.ZodError, value: unknown, label?: string);
|
|
17
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArgumentValidationError = void 0;
|
|
4
|
-
/** Formats a zod issue path like `groups[0]` or `countryCode`. */
|
|
5
|
-
function formatIssuePath(path) {
|
|
6
|
-
let out = '';
|
|
7
|
-
for (const key of path) {
|
|
8
|
-
if (typeof key === 'number')
|
|
9
|
-
out += `[${key}]`;
|
|
10
|
-
else
|
|
11
|
-
out += out ? `.${String(key)}` : String(key);
|
|
12
|
-
}
|
|
13
|
-
return out;
|
|
14
|
-
}
|
|
15
|
-
/** Reads the value at `path` from the validated input, to include in the error. */
|
|
16
|
-
function valueAtPath(root, path) {
|
|
17
|
-
let current = root;
|
|
18
|
-
for (const key of path) {
|
|
19
|
-
if (current === null || typeof current !== 'object')
|
|
20
|
-
return undefined;
|
|
21
|
-
current = current[key];
|
|
22
|
-
}
|
|
23
|
-
return current;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* How much of a received string the message renders. A rejected argument can be arbitrarily large - a
|
|
27
|
-
* whole JSON payload passed where an object was expected - and its full text would swamp the message.
|
|
28
|
-
*/
|
|
29
|
-
const MAX_RECEIVED_STRING_LENGTH = 80;
|
|
30
|
-
/** Renders a primitive received value for an error; skips objects/Dates (noisy). */
|
|
31
|
-
function describeReceived(value) {
|
|
32
|
-
switch (typeof value) {
|
|
33
|
-
case 'string':
|
|
34
|
-
// An empty string would render as bare backticks - make it visible.
|
|
35
|
-
if (value === '')
|
|
36
|
-
return "''";
|
|
37
|
-
return value.length > MAX_RECEIVED_STRING_LENGTH
|
|
38
|
-
? `${value.slice(0, MAX_RECEIVED_STRING_LENGTH)}...`
|
|
39
|
-
: value;
|
|
40
|
-
case 'number':
|
|
41
|
-
case 'boolean':
|
|
42
|
-
return String(value);
|
|
43
|
-
case 'bigint':
|
|
44
|
-
// Keep the `n` suffix, so a rejected bigint is not mistaken for a number.
|
|
45
|
-
return `${value}n`;
|
|
46
|
-
default:
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Renders the issue's own sentence, except where zod's contradicts itself: a value of the expected type
|
|
52
|
-
* that fails that type's implicit constraint is still reported as the wrong *type*, giving "expected
|
|
53
|
-
* number, received number" for `Infinity` / `NaN` and "expected date, received Date" for an invalid
|
|
54
|
-
* `Date`. Name the constraint that actually failed instead.
|
|
55
|
-
*/
|
|
56
|
-
function describeIssue(issue, value) {
|
|
57
|
-
if (issue.code === 'invalid_type') {
|
|
58
|
-
if (issue.expected === 'number' && typeof value === 'number') {
|
|
59
|
-
return 'Invalid input: expected a finite number';
|
|
60
|
-
}
|
|
61
|
-
// A tag check, not `instanceof`, so a `Date` from another realm is named too.
|
|
62
|
-
if (issue.expected === 'date' && Object.prototype.toString.call(value) === '[object Date]') {
|
|
63
|
-
return 'Invalid input: expected a valid date';
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return issue.message;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* How many issue lines the message renders, before a closing "... and N more" line. Validating a
|
|
70
|
-
* large array - a dataset push, a request batch - can fail on every element, and rendering all of
|
|
71
|
-
* them would make the message megabytes long. The full set stays on `issues` either way.
|
|
72
|
-
*/
|
|
73
|
-
const MAX_RENDERED_LINES = 10;
|
|
74
|
-
/**
|
|
75
|
-
* How deep into the value the lines for `issue` would sit, as a path length. Computed without
|
|
76
|
-
* rendering anything, so a union can weigh its arms before any string is built.
|
|
77
|
-
*/
|
|
78
|
-
function deepestIssueDepth(issue, baseDepth) {
|
|
79
|
-
const depth = baseDepth + issue.path.length;
|
|
80
|
-
if (issue.code === 'invalid_union') {
|
|
81
|
-
let deepest = -1;
|
|
82
|
-
for (const arm of issue.errors) {
|
|
83
|
-
for (const nested of arm)
|
|
84
|
-
deepest = Math.max(deepest, deepestIssueDepth(nested, depth));
|
|
85
|
-
}
|
|
86
|
-
return deepest;
|
|
87
|
-
}
|
|
88
|
-
return depth;
|
|
89
|
-
}
|
|
90
|
-
/** Collects one line per issue into `lines`; a union expands into a line per deepest-failing arm. */
|
|
91
|
-
function collectIssueLines(issue, root, basePath, lines, counter) {
|
|
92
|
-
const path = [...basePath, ...issue.path];
|
|
93
|
-
// A union's own message is a bare "Invalid input" - the useful part is in `errors`,
|
|
94
|
-
// whose paths are relative to the union, hence passing `path` down as the base.
|
|
95
|
-
if (issue.code === 'invalid_union') {
|
|
96
|
-
// Only the arms that reached deepest are reported. An arm that failed nearer the root rejected a
|
|
97
|
-
// shape the value never had - for `[{ ok: 1 }, 2]` against `object | string | array`, the object
|
|
98
|
-
// and string arms fail on the whole array, and only the array arm can point at `[1]`. When every
|
|
99
|
-
// arm fails at the same depth, as for an argument of an outright wrong type, they are all kept.
|
|
100
|
-
const armDepths = issue.errors.map((arm) => arm.reduce((deepest, nested) => Math.max(deepest, deepestIssueDepth(nested, path.length)), -1));
|
|
101
|
-
const deepest = Math.max(...armDepths);
|
|
102
|
-
for (const [index, arm] of issue.errors.entries()) {
|
|
103
|
-
if (armDepths[index] !== deepest)
|
|
104
|
-
continue;
|
|
105
|
-
for (const nested of arm)
|
|
106
|
-
collectIssueLines(nested, root, path, lines, counter);
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
counter.total += 1;
|
|
111
|
-
if (lines.length >= MAX_RENDERED_LINES)
|
|
112
|
-
return;
|
|
113
|
-
const location = path.length ? ` at \`${formatIssuePath(path)}\`` : '';
|
|
114
|
-
const value = valueAtPath(root, path);
|
|
115
|
-
const received = describeReceived(value);
|
|
116
|
-
const got = received === undefined ? '' : `, got \`${received}\``;
|
|
117
|
-
lines.push(`${describeIssue(issue, value)}${location}${got}`);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Formats a `ZodError` as a plain, human-readable message that names the
|
|
121
|
-
* offending field *and* the value it received (e.g. ``must match pattern
|
|
122
|
-
* /^[A-Z]{2}$/ at `countryCode`, got `CZE` ``) - closer to the old `ow` errors
|
|
123
|
-
* than zod's default, which omits the received value.
|
|
124
|
-
*/
|
|
125
|
-
function formatZodError(error, root, label) {
|
|
126
|
-
const lines = [];
|
|
127
|
-
const counter = { total: 0 };
|
|
128
|
-
for (const issue of error.issues)
|
|
129
|
-
collectIssueLines(issue, root, [], lines, counter);
|
|
130
|
-
// The label names the validated interface, the way ow's errors ended with "in object `X`".
|
|
131
|
-
const rendered = label ? lines.map((line) => `${line} in \`${label}\``) : [...lines];
|
|
132
|
-
const hidden = counter.total - lines.length;
|
|
133
|
-
if (hidden > 0)
|
|
134
|
-
rendered.push(`... and ${hidden} more problem${hidden === 1 ? '' : 's'}`);
|
|
135
|
-
return rendered.join('\n');
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Thrown when an argument fails schema validation.
|
|
139
|
-
*
|
|
140
|
-
* Its `message` is a human-readable sentence naming the offending field and the
|
|
141
|
-
* value it received (rather than a raw JSON dump). The structured
|
|
142
|
-
* {@link https://zod.dev | zod} issues are available on `issues`, and the
|
|
143
|
-
* original `ZodError` on `cause`, for programmatic inspection.
|
|
144
|
-
*
|
|
145
|
-
* `apify-client` sits below `@crawlee/core` and the Apify SDK in the dependency
|
|
146
|
-
* graph, so it defines its own error type rather than importing one from them.
|
|
147
|
-
*/
|
|
148
|
-
class ArgumentValidationError extends Error {
|
|
149
|
-
/** Structured issues from the underlying schema check. */
|
|
150
|
-
issues;
|
|
151
|
-
constructor(error, value, label) {
|
|
152
|
-
super(formatZodError(error, value, label), { cause: error });
|
|
153
|
-
this.name = 'ArgumentValidationError';
|
|
154
|
-
this.issues = error.issues;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.ArgumentValidationError = ArgumentValidationError;
|
package/dist/index.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import mod from "./index.js";
|
|
2
|
-
|
|
3
|
-
export default mod;
|
|
4
|
-
export const ActorClient = mod.ActorClient;
|
|
5
|
-
export const ActorCollectionClient = mod.ActorCollectionClient;
|
|
6
|
-
export const ActorEnvVarClient = mod.ActorEnvVarClient;
|
|
7
|
-
export const ActorEnvVarCollectionClient = mod.ActorEnvVarCollectionClient;
|
|
8
|
-
export const ActorListSortBy = mod.ActorListSortBy;
|
|
9
|
-
export const ActorSourceType = mod.ActorSourceType;
|
|
10
|
-
export const ActorVersionClient = mod.ActorVersionClient;
|
|
11
|
-
export const ActorVersionCollectionClient = mod.ActorVersionCollectionClient;
|
|
12
|
-
export const ApifyApiError = mod.ApifyApiError;
|
|
13
|
-
export const ApifyClient = mod.ApifyClient;
|
|
14
|
-
export const ArgumentValidationError = mod.ArgumentValidationError;
|
|
15
|
-
export const BuildClient = mod.BuildClient;
|
|
16
|
-
export const BuildCollectionClient = mod.BuildCollectionClient;
|
|
17
|
-
export const DatasetClient = mod.DatasetClient;
|
|
18
|
-
export const DatasetCollectionClient = mod.DatasetCollectionClient;
|
|
19
|
-
export const DownloadItemsFormat = mod.DownloadItemsFormat;
|
|
20
|
-
export const InvalidResponseBodyError = mod.InvalidResponseBodyError;
|
|
21
|
-
export const KeyValueStoreClient = mod.KeyValueStoreClient;
|
|
22
|
-
export const KeyValueStoreCollectionClient = mod.KeyValueStoreCollectionClient;
|
|
23
|
-
export const LogClient = mod.LogClient;
|
|
24
|
-
export const LoggerActorRedirect = mod.LoggerActorRedirect;
|
|
25
|
-
export const PlatformFeature = mod.PlatformFeature;
|
|
26
|
-
export const RequestQueueClient = mod.RequestQueueClient;
|
|
27
|
-
export const RequestQueueCollectionClient = mod.RequestQueueCollectionClient;
|
|
28
|
-
export const RunClient = mod.RunClient;
|
|
29
|
-
export const RunCollectionClient = mod.RunCollectionClient;
|
|
30
|
-
export const ScheduleActions = mod.ScheduleActions;
|
|
31
|
-
export const ScheduleClient = mod.ScheduleClient;
|
|
32
|
-
export const ScheduleCollectionClient = mod.ScheduleCollectionClient;
|
|
33
|
-
export const StoreCollectionClient = mod.StoreCollectionClient;
|
|
34
|
-
export const StreamedLog = mod.StreamedLog;
|
|
35
|
-
export const TaskClient = mod.TaskClient;
|
|
36
|
-
export const TaskCollectionClient = mod.TaskCollectionClient;
|
|
37
|
-
export const UserClient = mod.UserClient;
|
|
38
|
-
export const WebhookClient = mod.WebhookClient;
|
|
39
|
-
export const WebhookCollectionClient = mod.WebhookCollectionClient;
|
|
40
|
-
export const WebhookDispatchClient = mod.WebhookDispatchClient;
|
|
41
|
-
export const WebhookDispatchCollectionClient = mod.WebhookDispatchCollectionClient;
|
|
42
|
-
export const WebhookDispatchStatus = mod.WebhookDispatchStatus;
|