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

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/dist/index.d.ts CHANGED
@@ -27,6 +27,6 @@ export * from './resource_clients/webhook_collection.js';
27
27
  export * from './resource_clients/webhook_dispatch.js';
28
28
  export * from './resource_clients/webhook_dispatch_collection.js';
29
29
  export * from './apify_api_error.js';
30
- export * from './argument_validation_error.js';
30
+ export { ArgumentValidationError } from '@apify/validations';
31
31
  export { InvalidResponseBodyError } from './interceptors.js';
32
32
  export type { PaginatedList, Dictionary } from './utils.js';
package/dist/index.js CHANGED
@@ -27,5 +27,5 @@ export * from './resource_clients/webhook_collection.js';
27
27
  export * from './resource_clients/webhook_dispatch.js';
28
28
  export * from './resource_clients/webhook_dispatch_collection.js';
29
29
  export * from './apify_api_error.js';
30
- export * from './argument_validation_error.js';
30
+ export { ArgumentValidationError } from '@apify/validations';
31
31
  export { InvalidResponseBodyError } from './interceptors.js';
package/dist/utils.d.ts CHANGED
@@ -2,17 +2,10 @@ import type { Readable } from 'node:stream';
2
2
  import type { JsonValue, TypedArray } from 'type-fest';
3
3
  import { z } from 'zod';
4
4
  import type { ApifyApiError } from './apify_api_error.js';
5
+ import { parseArgument } from '@apify/validations';
5
6
  import type { RequestQueueClientListRequestsOptions, RequestQueueClientListRequestsResult } from './resource_clients/request_queue.js';
6
7
  import type { WebhookUpdateData } from './resource_clients/webhook.js';
7
- /**
8
- * Parses `value` with `schema`, returning the typed result (with schema defaults applied).
9
- * Throws {@link ArgumentValidationError} on failure.
10
- *
11
- * The optional `label` names the interface being validated and is appended to every error line
12
- * (e.g. ``... at `memory` in `ActorStartOptions` ``).
13
- * @internal
14
- */
15
- export declare function parseArgument<TValue, TSchema extends z.ZodType>(value: TValue, schema: TSchema, label?: string): TValue & z.output<TSchema>;
8
+ export { parseArgument };
16
9
  /**
17
10
  * Accepts any non-null, non-array object as a predicate for `z.custom()`.
18
11
  * @internal
@@ -210,4 +203,3 @@ export declare function toPathSegment(value: string): string;
210
203
  * `requests/batch` keep their separators; an array has each of its segments encoded individually.
211
204
  */
212
205
  export declare function toPath(path: string | string[]): string;
213
- export {};
package/dist/utils.js CHANGED
@@ -1,30 +1,12 @@
1
1
  import { z } from 'zod';
2
- import { ArgumentValidationError } from './argument_validation_error.js';
2
+ import { parseArgument } from '@apify/validations';
3
3
  // @ts-ignore if we enable `resolveJsonModule`, we end up with a `src` folder in `dist`
4
4
  import packageJson from '../package.json' with { type: 'json' };
5
5
  const NOT_FOUND_STATUS_CODE = 404;
6
6
  const RECORD_NOT_FOUND_TYPE = 'record-not-found';
7
7
  const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
8
8
  const MIN_COMPRESS_BYTES = 1024;
9
- // Zod installs its English locale as a module-level side effect but ships `"sideEffects": false`, so
10
- // any tree-shaking bundler drops it and every message degrades to a bare "Invalid input". Passing it
11
- // in per parse keeps them intact without reaching into the zod config the whole process shares.
12
- const { localeError } = z.locales.en();
13
- /**
14
- * Parses `value` with `schema`, returning the typed result (with schema defaults applied).
15
- * Throws {@link ArgumentValidationError} on failure.
16
- *
17
- * The optional `label` names the interface being validated and is appended to every error line
18
- * (e.g. ``... at `memory` in `ActorStartOptions` ``).
19
- * @internal
20
- */
21
- export function parseArgument(value, schema, label) {
22
- const result = schema.safeParse(value, { error: localeError });
23
- if (!result.success) {
24
- throw new ArgumentValidationError(result.error, value, label);
25
- }
26
- return result.data;
27
- }
9
+ export { parseArgument };
28
10
  /**
29
11
  * Accepts any non-null, non-array object as a predicate for `z.custom()`.
30
12
  * @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.4",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -57,48 +57,49 @@
57
57
  }
58
58
  },
59
59
  "dependencies": {
60
- "@apify/consts": "^2.50.0",
61
- "@apify/log": "^2.2.6",
62
- "@apify/utilities": "^2.23.2",
63
- "@crawlee/types": "^3.3.0",
64
- "ansi-colors": "^4.1.1",
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
+ "@crawlee/types": "^3.18.1",
65
+ "ansi-colors": "^4.1.3",
65
66
  "async-retry": "^1.3.3",
66
- "axios": "^1.16.0",
67
+ "axios": "^1.20.0",
67
68
  "content-type": "^1.0.5",
68
69
  "proxy-agent": "^6.5.0",
69
- "tslib": "^2.5.0",
70
- "type-fest": "^4.0.0",
71
- "zod": "^4.0.0"
70
+ "tslib": "^2.8.1",
71
+ "type-fest": "^4.41.0",
72
+ "zod": "^4.5.4"
72
73
  },
73
74
  "devDependencies": {
74
75
  "@apify/oxlint-config": "^0.3.0",
75
76
  "@apify/tsconfig": "^0.2.0",
76
- "@crawlee/puppeteer": "^3.2.2",
77
- "@rsbuild/core": "^2.0.0",
78
- "@rsbuild/plugin-node-polyfill": "^1.3.0",
79
- "@rspack/cli": "^2.0.0",
80
- "@rspack/core": "^2.0.0",
81
- "@types/async-retry": "^1.4.5",
77
+ "@crawlee/puppeteer": "4.0.0-beta.165",
78
+ "@rsbuild/core": "^2.2.3",
79
+ "@rsbuild/plugin-node-polyfill": "^1.4.6",
80
+ "@rspack/cli": "^2.2.2",
81
+ "@rspack/core": "^2.2.2",
82
+ "@types/async-retry": "^1.4.9",
82
83
  "@types/compression": "^1.8.1",
83
- "@types/content-type": "^1.1.5",
84
- "@types/express": "^5.0.0",
85
- "@types/node": "^24.0.0",
86
- "ajv": "^8.17.1",
87
- "body-parser": "^2.0.0",
88
- "compression": "^1.7.4",
84
+ "@types/content-type": "^1.1.9",
85
+ "@types/express": "^5.0.6",
86
+ "@types/node": "^24.13.3",
87
+ "ajv": "^8.20.0",
88
+ "body-parser": "^2.3.0",
89
+ "compression": "^1.8.1",
89
90
  "esbuild": "0.28.2",
90
- "express": "^5.0.0",
91
+ "express": "^5.2.1",
91
92
  "openapi-typescript": "7.13.0",
92
- "oxfmt": "0.65.0",
93
- "oxlint": "1.79.0",
93
+ "oxfmt": "0.66.0",
94
+ "oxlint": "1.81.0",
94
95
  "oxlint-tsgolint": "7.0.2001",
95
- "puppeteer": "^25.0.0",
96
- "rimraf": "^6.0.0",
97
- "rolldown": "^1.0.0-rc.4",
98
- "typescript": "^6.0.0",
99
- "vitest": "^4.0.16",
100
- "webpack": "^5.105.2",
101
- "webpack-cli": "^7.0.0"
96
+ "puppeteer": "^25.10.0",
97
+ "rimraf": "^6.1.3",
98
+ "rolldown": "^1.2.7",
99
+ "typescript": "^6.0.3",
100
+ "vitest": "^5.0.0",
101
+ "webpack": "^5.110.3",
102
+ "webpack-cli": "^7.2.3"
102
103
  },
103
104
  "devEngines": {
104
105
  "packageManager": {
@@ -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,153 +0,0 @@
1
- /** Formats a zod issue path like `groups[0]` or `countryCode`. */
2
- function formatIssuePath(path) {
3
- let out = '';
4
- for (const key of path) {
5
- if (typeof key === 'number')
6
- out += `[${key}]`;
7
- else
8
- out += out ? `.${String(key)}` : String(key);
9
- }
10
- return out;
11
- }
12
- /** Reads the value at `path` from the validated input, to include in the error. */
13
- function valueAtPath(root, path) {
14
- let current = root;
15
- for (const key of path) {
16
- if (current === null || typeof current !== 'object')
17
- return undefined;
18
- current = current[key];
19
- }
20
- return current;
21
- }
22
- /**
23
- * How much of a received string the message renders. A rejected argument can be arbitrarily large - a
24
- * whole JSON payload passed where an object was expected - and its full text would swamp the message.
25
- */
26
- const MAX_RECEIVED_STRING_LENGTH = 80;
27
- /** Renders a primitive received value for an error; skips objects/Dates (noisy). */
28
- function describeReceived(value) {
29
- switch (typeof value) {
30
- case 'string':
31
- // An empty string would render as bare backticks - make it visible.
32
- if (value === '')
33
- return "''";
34
- return value.length > MAX_RECEIVED_STRING_LENGTH
35
- ? `${value.slice(0, MAX_RECEIVED_STRING_LENGTH)}...`
36
- : value;
37
- case 'number':
38
- case 'boolean':
39
- return String(value);
40
- case 'bigint':
41
- // Keep the `n` suffix, so a rejected bigint is not mistaken for a number.
42
- return `${value}n`;
43
- default:
44
- return undefined;
45
- }
46
- }
47
- /**
48
- * Renders the issue's own sentence, except where zod's contradicts itself: a value of the expected type
49
- * that fails that type's implicit constraint is still reported as the wrong *type*, giving "expected
50
- * number, received number" for `Infinity` / `NaN` and "expected date, received Date" for an invalid
51
- * `Date`. Name the constraint that actually failed instead.
52
- */
53
- function describeIssue(issue, value) {
54
- if (issue.code === 'invalid_type') {
55
- if (issue.expected === 'number' && typeof value === 'number') {
56
- return 'Invalid input: expected a finite number';
57
- }
58
- // A tag check, not `instanceof`, so a `Date` from another realm is named too.
59
- if (issue.expected === 'date' && Object.prototype.toString.call(value) === '[object Date]') {
60
- return 'Invalid input: expected a valid date';
61
- }
62
- }
63
- return issue.message;
64
- }
65
- /**
66
- * How many issue lines the message renders, before a closing "... and N more" line. Validating a
67
- * large array - a dataset push, a request batch - can fail on every element, and rendering all of
68
- * them would make the message megabytes long. The full set stays on `issues` either way.
69
- */
70
- const MAX_RENDERED_LINES = 10;
71
- /**
72
- * How deep into the value the lines for `issue` would sit, as a path length. Computed without
73
- * rendering anything, so a union can weigh its arms before any string is built.
74
- */
75
- function deepestIssueDepth(issue, baseDepth) {
76
- const depth = baseDepth + issue.path.length;
77
- if (issue.code === 'invalid_union') {
78
- let deepest = -1;
79
- for (const arm of issue.errors) {
80
- for (const nested of arm)
81
- deepest = Math.max(deepest, deepestIssueDepth(nested, depth));
82
- }
83
- return deepest;
84
- }
85
- return depth;
86
- }
87
- /** Collects one line per issue into `lines`; a union expands into a line per deepest-failing arm. */
88
- function collectIssueLines(issue, root, basePath, lines, counter) {
89
- const path = [...basePath, ...issue.path];
90
- // A union's own message is a bare "Invalid input" - the useful part is in `errors`,
91
- // whose paths are relative to the union, hence passing `path` down as the base.
92
- if (issue.code === 'invalid_union') {
93
- // Only the arms that reached deepest are reported. An arm that failed nearer the root rejected a
94
- // shape the value never had - for `[{ ok: 1 }, 2]` against `object | string | array`, the object
95
- // and string arms fail on the whole array, and only the array arm can point at `[1]`. When every
96
- // arm fails at the same depth, as for an argument of an outright wrong type, they are all kept.
97
- const armDepths = issue.errors.map((arm) => arm.reduce((deepest, nested) => Math.max(deepest, deepestIssueDepth(nested, path.length)), -1));
98
- const deepest = Math.max(...armDepths);
99
- for (const [index, arm] of issue.errors.entries()) {
100
- if (armDepths[index] !== deepest)
101
- continue;
102
- for (const nested of arm)
103
- collectIssueLines(nested, root, path, lines, counter);
104
- }
105
- return;
106
- }
107
- counter.total += 1;
108
- if (lines.length >= MAX_RENDERED_LINES)
109
- return;
110
- const location = path.length ? ` at \`${formatIssuePath(path)}\`` : '';
111
- const value = valueAtPath(root, path);
112
- const received = describeReceived(value);
113
- const got = received === undefined ? '' : `, got \`${received}\``;
114
- lines.push(`${describeIssue(issue, value)}${location}${got}`);
115
- }
116
- /**
117
- * Formats a `ZodError` as a plain, human-readable message that names the
118
- * offending field *and* the value it received (e.g. ``must match pattern
119
- * /^[A-Z]{2}$/ at `countryCode`, got `CZE` ``) - closer to the old `ow` errors
120
- * than zod's default, which omits the received value.
121
- */
122
- function formatZodError(error, root, label) {
123
- const lines = [];
124
- const counter = { total: 0 };
125
- for (const issue of error.issues)
126
- collectIssueLines(issue, root, [], lines, counter);
127
- // The label names the validated interface, the way ow's errors ended with "in object `X`".
128
- const rendered = label ? lines.map((line) => `${line} in \`${label}\``) : [...lines];
129
- const hidden = counter.total - lines.length;
130
- if (hidden > 0)
131
- rendered.push(`... and ${hidden} more problem${hidden === 1 ? '' : 's'}`);
132
- return rendered.join('\n');
133
- }
134
- /**
135
- * Thrown when an argument fails schema validation.
136
- *
137
- * Its `message` is a human-readable sentence naming the offending field and the
138
- * value it received (rather than a raw JSON dump). The structured
139
- * {@link https://zod.dev | zod} issues are available on `issues`, and the
140
- * original `ZodError` on `cause`, for programmatic inspection.
141
- *
142
- * `apify-client` sits below `@crawlee/core` and the Apify SDK in the dependency
143
- * graph, so it defines its own error type rather than importing one from them.
144
- */
145
- export class ArgumentValidationError extends Error {
146
- /** Structured issues from the underlying schema check. */
147
- issues;
148
- constructor(error, value, label) {
149
- super(formatZodError(error, value, label), { cause: error });
150
- this.name = 'ArgumentValidationError';
151
- this.issues = error.issues;
152
- }
153
- }