apify-client 3.0.0-beta.0 → 3.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +5 -3
  2. package/dist/apify_api_error.d.ts +59 -3
  3. package/dist/apify_api_error.js +71 -11
  4. package/dist/apify_client.d.ts +27 -27
  5. package/dist/apify_client.js +86 -91
  6. package/dist/base/api_client.d.ts +3 -3
  7. package/dist/base/api_client.js +6 -10
  8. package/dist/base/resource_client.d.ts +5 -4
  9. package/dist/base/resource_client.js +17 -21
  10. package/dist/base/resource_collection_client.d.ts +7 -6
  11. package/dist/base/resource_collection_client.js +11 -15
  12. package/dist/body_parser.js +6 -11
  13. package/dist/bundle.js +38 -48
  14. package/dist/bundle.js.map +1 -1
  15. package/dist/generated/api.d.ts +20595 -0
  16. package/dist/generated/api.js +5 -0
  17. package/dist/generated/schemas.d.ts +6699 -0
  18. package/dist/generated/schemas.js +1521 -0
  19. package/dist/http_client.d.ts +2 -2
  20. package/dist/http_client.js +23 -28
  21. package/dist/index.d.ts +33 -32
  22. package/dist/index.js +32 -36
  23. package/dist/interceptors.d.ts +1 -1
  24. package/dist/interceptors.js +14 -19
  25. package/dist/lazy_schema.d.ts +8 -0
  26. package/dist/lazy_schema.js +11 -0
  27. package/dist/models.d.ts +1053 -0
  28. package/dist/models.js +86 -0
  29. package/dist/resource_clients/actor.d.ts +13 -459
  30. package/dist/resource_clients/actor.js +70 -73
  31. package/dist/resource_clients/actor_collection.d.ts +10 -15
  32. package/dist/resource_clients/actor_collection.js +19 -20
  33. package/dist/resource_clients/actor_env_var.d.ts +3 -3
  34. package/dist/resource_clients/actor_env_var.js +7 -10
  35. package/dist/resource_clients/actor_env_var_collection.d.ts +11 -20
  36. package/dist/resource_clients/actor_env_var_collection.js +15 -19
  37. package/dist/resource_clients/actor_version.d.ts +14 -43
  38. package/dist/resource_clients/actor_version.js +15 -24
  39. package/dist/resource_clients/actor_version_collection.d.ts +13 -19
  40. package/dist/resource_clients/actor_version_collection.js +17 -19
  41. package/dist/resource_clients/build.d.ts +5 -80
  42. package/dist/resource_clients/build.js +14 -17
  43. package/dist/resource_clients/build_collection.d.ts +5 -5
  44. package/dist/resource_clients/build_collection.js +10 -13
  45. package/dist/resource_clients/dataset.d.ts +6 -72
  46. package/dist/resource_clients/dataset.js +73 -76
  47. package/dist/resource_clients/dataset_collection.d.ts +4 -4
  48. package/dist/resource_clients/dataset_collection.js +18 -21
  49. package/dist/resource_clients/key_value_store.d.ts +16 -77
  50. package/dist/resource_clients/key_value_store.js +64 -66
  51. package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
  52. package/dist/resource_clients/key_value_store_collection.js +18 -21
  53. package/dist/resource_clients/log.d.ts +2 -2
  54. package/dist/resource_clients/log.js +15 -22
  55. package/dist/resource_clients/request_queue.d.ts +17 -183
  56. package/dist/resource_clients/request_queue.js +102 -108
  57. package/dist/resource_clients/request_queue_collection.d.ts +4 -4
  58. package/dist/resource_clients/request_queue_collection.js +16 -19
  59. package/dist/resource_clients/run.d.ts +8 -8
  60. package/dist/resource_clients/run.js +50 -53
  61. package/dist/resource_clients/run_collection.d.ts +4 -4
  62. package/dist/resource_clients/run_collection.js +15 -18
  63. package/dist/resource_clients/schedule.d.ts +8 -86
  64. package/dist/resource_clients/schedule.js +13 -21
  65. package/dist/resource_clients/schedule_collection.d.ts +4 -4
  66. package/dist/resource_clients/schedule_collection.js +13 -16
  67. package/dist/resource_clients/store_collection.d.ts +5 -33
  68. package/dist/resource_clients/store_collection.js +15 -18
  69. package/dist/resource_clients/task.d.ts +9 -79
  70. package/dist/resource_clients/task.js +47 -50
  71. package/dist/resource_clients/task_collection.d.ts +6 -5
  72. package/dist/resource_clients/task_collection.js +12 -15
  73. package/dist/resource_clients/user.d.ts +5 -181
  74. package/dist/resource_clients/user.js +11 -24
  75. package/dist/resource_clients/webhook.d.ts +6 -65
  76. package/dist/resource_clients/webhook.js +11 -14
  77. package/dist/resource_clients/webhook_collection.d.ts +4 -4
  78. package/dist/resource_clients/webhook_collection.js +13 -16
  79. package/dist/resource_clients/webhook_dispatch.d.ts +5 -38
  80. package/dist/resource_clients/webhook_dispatch.js +5 -13
  81. package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
  82. package/dist/resource_clients/webhook_dispatch_collection.js +10 -13
  83. package/dist/response_validation_error.d.ts +26 -0
  84. package/dist/response_validation_error.js +37 -0
  85. package/dist/schemas.d.ts +15 -0
  86. package/dist/schemas.js +15 -0
  87. package/dist/statistics.js +5 -9
  88. package/dist/timezones.js +1 -2
  89. package/dist/utils.d.ts +19 -24
  90. package/dist/utils.js +66 -96
  91. package/package.json +48 -40
  92. package/dist/argument_validation_error.d.ts +0 -17
  93. package/dist/argument_validation_error.js +0 -157
  94. package/dist/index.mjs +0 -42
package/dist/utils.js CHANGED
@@ -1,53 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mutuallyExclusive = exports.paginationOptionsShape = exports.RequestQueuePaginationIterator = exports.anyObjectSchema = void 0;
4
- exports.parseArgument = parseArgument;
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");
23
- const NOT_FOUND_STATUS_CODE = 404;
24
- const RECORD_NOT_FOUND_TYPE = 'record-not-found';
25
- const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
1
+ import { z } from 'zod';
2
+ import { NotFoundError } from './apify_api_error.js';
3
+ import { parseArgument } from '@apify/validations';
4
+ import { ResponseValidationError } from './response_validation_error.js';
5
+ // @ts-ignore if we enable `resolveJsonModule`, we end up with a `src` folder in `dist`
6
+ import packageJson from '../package.json' with { type: 'json' };
26
7
  const MIN_COMPRESS_BYTES = 1024;
27
- // Zod installs its English locale as a module-level side effect but ships `"sideEffects": false`, so
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
- }
8
+ export { parseArgument };
46
9
  /**
47
10
  * Accepts any non-null, non-array object as a predicate for `z.custom()`.
48
11
  * @internal
49
12
  */
50
- function isNonArrayObject(value) {
13
+ export function isNonArrayObject(value) {
51
14
  return typeof value === 'object' && value !== null && !Array.isArray(value);
52
15
  }
53
16
  /**
@@ -56,14 +19,37 @@ function isNonArrayObject(value) {
56
19
  * the value itself instead of a copy.
57
20
  * @internal
58
21
  */
59
- exports.anyObjectSchema = zod_1.z.custom(isNonArrayObject, {
22
+ export const anyObjectSchema = z.custom(isNonArrayObject, {
60
23
  error: 'Invalid input: expected an object',
61
24
  });
25
+ // Zod installs its English locale as a module-level side effect but ships `"sideEffects": false`, so
26
+ // any tree-shaking bundler drops it and every message degrades to a bare "Invalid input". Passing it
27
+ // in per parse keeps them intact without reaching into the zod config the whole process shares.
28
+ const { localeError } = z.locales.en();
29
+ /**
30
+ * Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope, converts the
31
+ * date fields and validates the result against `schema`, one of the schemas generated from the OpenAPI
32
+ * specification. The validated copy is what callers get, so it is the schema's output -- unknown fields and unknown
33
+ * enum values included, since the schemas let both through, and URL fields normalized, since `z.url()` hands back
34
+ * the parsed URL's serialization.
35
+ *
36
+ * Throws {@link ResponseValidationError} when the response does not match the specification.
37
+ * @internal
38
+ */
39
+ export function parseResponse(response, schema, shouldParseField = null) {
40
+ const data = parseDateFields(pluckData(response.data), shouldParseField);
41
+ const result = schema.safeParse(data, { error: localeError });
42
+ if (!result.success) {
43
+ const { method = 'GET', url = '' } = response.config;
44
+ throw new ResponseValidationError(result.error, data, { method, url });
45
+ }
46
+ return result.data;
47
+ }
62
48
  /**
63
49
  * Returns object's 'data' property or throws if parameter is not an object,
64
50
  * or an object without a 'data' property.
65
51
  */
66
- function pluckData(obj) {
52
+ export function pluckData(obj) {
67
53
  if (typeof obj === 'object' && obj) {
68
54
  if (typeof obj.data !== 'undefined')
69
55
  return obj.data;
@@ -71,14 +57,10 @@ function pluckData(obj) {
71
57
  throw new Error(`Expected response object with a "data" property, but received: ${obj}`);
72
58
  }
73
59
  /**
74
- * If given HTTP error has NOT_FOUND_STATUS_CODE status code then returns undefined.
75
- * Otherwise rethrows error.
60
+ * Swallows a 404 Not Found API error and rethrows anything else.
76
61
  */
77
- function catchNotFoundOrThrow(err) {
78
- const isNotFoundStatus = err.statusCode === NOT_FOUND_STATUS_CODE;
79
- const isNotFoundMessage = err.type === RECORD_NOT_FOUND_TYPE || err.type === RECORD_OR_TOKEN_NOT_FOUND_TYPE || err.httpMethod === 'head';
80
- const isNotFoundError = isNotFoundStatus && isNotFoundMessage;
81
- if (!isNotFoundError)
62
+ export function catchNotFoundOrThrow(err) {
63
+ if (!(err instanceof NotFoundError))
82
64
  throw err;
83
65
  }
84
66
  /**
@@ -91,11 +73,17 @@ function catchNotFoundOrThrow(err) {
91
73
  *
92
74
  * If the field cannot be converted to Date, it is left as is.
93
75
  */
94
- function parseDateFields(input, shouldParseField = null, depth = 0) {
95
- // Don't go too deep to avoid stack overflows (especially if there is a circular reference). The depth of 3
96
- // corresponds to obj.data.someArrayField.[x].field and should be generally enough.
76
+ export function parseDateFields(input, shouldParseField = null, depth = 0) {
77
+ // Don't go too deep to avoid stack overflows (especially if there is a circular reference). The depth of 4
78
+ // corresponds to obj.items.[x].someArrayField.[y].field, which is what a list response looks like: it
79
+ // nests one level deeper than the single resource it wraps, because both the item array and the nested
80
+ // array spend a level.
81
+ //
82
+ // In a list response it also reaches one level into caller-owned blobs the API stores verbatim, so a
83
+ // listed request's `userData.foo.somethingAt` comes back as a `Date` rather than the string it was
84
+ // written as.
97
85
  // TODO: Consider removing this limitation. It might came across as an annoying surprise as it's not communicated.
98
- if (depth > 3) {
86
+ if (depth > 4) {
99
87
  return input;
100
88
  }
101
89
  if (Array.isArray(input))
@@ -125,7 +113,7 @@ function parseDateFields(input, shouldParseField = null, depth = 0) {
125
113
  /**
126
114
  * Helper function that converts array of webhooks to base64 string
127
115
  */
128
- function stringifyWebhooksToBase64(webhooks) {
116
+ export function stringifyWebhooksToBase64(webhooks) {
129
117
  if (!webhooks)
130
118
  return;
131
119
  const webhooksJson = JSON.stringify(webhooks);
@@ -166,7 +154,7 @@ async function gzipValue(value) {
166
154
  * Compress the passed value using brotli, falling back to gzip. Returns undefined if the data is
167
155
  * too small / wrong type, or if neither algorithm is available.
168
156
  */
169
- async function maybeCompressValue(value) {
157
+ export async function maybeCompressValue(value) {
170
158
  if (!isNode())
171
159
  return undefined;
172
160
  // Request compression is not that important so let's
@@ -195,7 +183,7 @@ async function maybeCompressValue(value) {
195
183
  /**
196
184
  * Helper function slice the items from array to fit the max byte length.
197
185
  */
198
- function sliceArrayByByteLength(array, maxByteLength, startIndex) {
186
+ export function sliceArrayByByteLength(array, maxByteLength, startIndex) {
199
187
  const stringByteLength = (str) => (isNode() ? Buffer.byteLength(str) : new Blob([str]).size);
200
188
  const arrayByteLength = stringByteLength(JSON.stringify(array));
201
189
  if (arrayByteLength < maxByteLength)
@@ -216,12 +204,12 @@ function sliceArrayByByteLength(array, maxByteLength, startIndex) {
216
204
  }
217
205
  return slicedArray;
218
206
  }
219
- function isNode() {
207
+ export function isNode() {
220
208
  if (typeof BROWSER_BUILD !== 'undefined')
221
209
  return false;
222
210
  return !!(typeof process !== 'undefined' && process.versions && process.versions.node);
223
211
  }
224
- function isBuffer(value) {
212
+ export function isBuffer(value) {
225
213
  // Tag checks rather than `instanceof`, to also match buffers from another realm. `isView()`
226
214
  // additionally covers `DataView`, which is not raw binary content.
227
215
  if (ArrayBuffer.isView(value))
@@ -231,39 +219,34 @@ function isBuffer(value) {
231
219
  function isTagged(value, tag) {
232
220
  return Object.prototype.toString.call(value) === `[object ${tag}]`;
233
221
  }
234
- function isStream(value) {
222
+ export function isStream(value) {
235
223
  if (value === null || typeof value !== 'object')
236
224
  return false;
237
225
  const { on, pipe } = value;
238
226
  return typeof on === 'function' && typeof pipe === 'function';
239
227
  }
240
- function getVersionData() {
228
+ export function getVersionData() {
241
229
  if (typeof BROWSER_BUILD !== 'undefined') {
242
230
  return { version: VERSION };
243
231
  }
244
- // eslint-disable-next-line
245
- return require('../package.json');
232
+ return packageJson;
246
233
  }
247
234
  /**
248
- * Helper class to create async iterators from paginated list endpoints with exclusive start key.
235
+ * Helper class to create async iterators from paginated list endpoints.
249
236
  */
250
- class RequestQueuePaginationIterator {
237
+ export class RequestQueuePaginationIterator {
251
238
  maxPageLimit;
252
239
  getPage;
253
240
  limit;
254
- exclusiveStartId;
255
241
  cursor;
256
242
  constructor(options) {
257
243
  this.maxPageLimit = options.maxPageLimit;
258
244
  this.limit = options.limit;
259
- this.exclusiveStartId = options.exclusiveStartId;
260
245
  this.cursor = options.cursor;
261
246
  this.getPage = options.getPage;
262
247
  }
263
248
  async *[Symbol.asyncIterator]() {
264
249
  let nextCursor = this.cursor;
265
- // allow using exclusiveStartId for the first page, but then we'll delete it to avoid using it for any later page
266
- let nextExclusiveStartId = this.exclusiveStartId;
267
250
  let iterateItemCount = 0;
268
251
  while (true) {
269
252
  const pageLimit = this.limit
@@ -272,7 +255,6 @@ class RequestQueuePaginationIterator {
272
255
  const page = await this.getPage({
273
256
  limit: pageLimit,
274
257
  cursor: nextCursor,
275
- exclusiveStartId: nextExclusiveStartId,
276
258
  });
277
259
  // There are no more pages to iterate
278
260
  if (page.items.length === 0)
@@ -283,25 +265,23 @@ class RequestQueuePaginationIterator {
283
265
  if ((this.limit && iterateItemCount >= this.limit) || !page.nextCursor)
284
266
  return;
285
267
  nextCursor = page.nextCursor;
286
- nextExclusiveStartId = undefined; // see comment above - delete it for any page after the first one, and paginate with cursor
287
268
  }
288
269
  }
289
270
  }
290
- exports.RequestQueuePaginationIterator = RequestQueuePaginationIterator;
291
271
  /**
292
272
  * Schema shape of {@link PaginationOptions}, to spread into every paginating client's list schema. One
293
273
  * copy stops it drifting from the interface.
294
274
  * @internal
295
275
  */
296
- exports.paginationOptionsShape = {
297
- limit: zod_1.z.number().min(0).optional(),
298
- offset: zod_1.z.number().min(0).optional(),
299
- chunkSize: zod_1.z.number().positive().optional(),
276
+ export const paginationOptionsShape = {
277
+ limit: z.number().min(0).optional(),
278
+ offset: z.number().min(0).optional(),
279
+ chunkSize: z.number().positive().optional(),
300
280
  };
301
- function cast(input) {
281
+ export function cast(input) {
302
282
  return input;
303
283
  }
304
- function asArray(value) {
284
+ export function asArray(value) {
305
285
  if (Array.isArray(value)) {
306
286
  return value;
307
287
  }
@@ -310,7 +290,7 @@ function asArray(value) {
310
290
  /**
311
291
  * Adds query parameters to a given URL based on the provided options object.
312
292
  */
313
- function applyQueryParamsToUrl(url, options) {
293
+ export function applyQueryParamsToUrl(url, options) {
314
294
  for (const [key, value] of Object.entries(options ?? {})) {
315
295
  // skip undefined values
316
296
  if (value === undefined)
@@ -324,17 +304,7 @@ function applyQueryParamsToUrl(url, options) {
324
304
  }
325
305
  return url;
326
306
  }
327
- /**
328
- * Builds a `[check, message]` pair to spread into `.refine()`, asserting that at most one of `keys`
329
- * is present. Pass the options interface as `T`, so that a misspelled key is a type error.
330
- * @internal
331
- */
332
- const mutuallyExclusive = (...keys) => [
333
- (value) => keys.filter((key) => typeof value[key] !== 'undefined').length <= 1,
334
- `At most one of the following fields is allowed: ${keys.join(', ')}`,
335
- ];
336
- exports.mutuallyExclusive = mutuallyExclusive;
337
- const pathSegmentSchema = zod_1.z
307
+ const pathSegmentSchema = z
338
308
  .string()
339
309
  .nonempty()
340
310
  .refine((v) => v !== '.' && v !== '..', { error: 'URL path must not contain dot segments' });
@@ -344,7 +314,7 @@ const pathSegmentSchema = zod_1.z
344
314
  * Empty strings and dot segments are rejected instead of encoded, because URL parsers resolve
345
315
  * dot segments after decoding - `records/%2E%2E` collapses to the parent endpoint just like `records/..`.
346
316
  */
347
- function toPathSegment(value) {
317
+ export function toPathSegment(value) {
348
318
  const valueParsed = parseArgument(value, pathSegmentSchema);
349
319
  return encodeURIComponent(valueParsed);
350
320
  }
@@ -352,6 +322,6 @@ function toPathSegment(value) {
352
322
  * Builds a URL path from segments. A plain string is used as-is, so literal paths such as
353
323
  * `requests/batch` keep their separators; an array has each of its segments encoded individually.
354
324
  */
355
- function toPath(path) {
325
+ export function toPath(path) {
356
326
  return Array.isArray(path) ? path.map(toPathSegment).join('/') : path;
357
327
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.0",
3
+ "version": "3.0.0-beta.10",
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": [
@@ -49,51 +48,58 @@
49
48
  "homepage": "https://docs.apify.com/api/client/js/",
50
49
  "files": [
51
50
  "dist",
52
- "!dist/*.tsbuildinfo"
51
+ "!dist/*.tsbuildinfo",
52
+ "!dist/spec_guards.*"
53
53
  ],
54
+ "apify": {
55
+ "openapiSpec": {
56
+ "version": "v2-2026-08-31T125154Z"
57
+ }
58
+ },
54
59
  "dependencies": {
55
- "@apify/consts": "^2.50.0",
56
- "@apify/log": "^2.2.6",
57
- "@apify/utilities": "^2.23.2",
58
- "@crawlee/types": "^3.3.0",
59
- "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",
60
66
  "async-retry": "^1.3.3",
61
- "axios": "^1.16.0",
67
+ "axios": "^1.20.0",
62
68
  "content-type": "^1.0.5",
63
69
  "proxy-agent": "^6.5.0",
64
- "tslib": "^2.5.0",
65
- "type-fest": "^4.0.0",
66
- "zod": "^4.0.0"
70
+ "tslib": "^2.8.1",
71
+ "type-fest": "^4.41.0",
72
+ "zod": "^4.5.4"
67
73
  },
68
74
  "devDependencies": {
69
75
  "@apify/oxlint-config": "^0.3.0",
70
76
  "@apify/tsconfig": "^0.2.0",
71
- "@crawlee/puppeteer": "^3.2.2",
72
- "@rsbuild/core": "^2.0.0",
73
- "@rsbuild/plugin-node-polyfill": "^1.3.0",
74
- "@rspack/cli": "^2.0.0",
75
- "@rspack/core": "^2.0.0",
76
- "@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",
77
83
  "@types/compression": "^1.8.1",
78
- "@types/content-type": "^1.1.5",
79
- "@types/express": "^5.0.0",
80
- "@types/node": "^24.0.0",
81
- "ajv": "^8.17.1",
82
- "body-parser": "^2.0.0",
83
- "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",
84
90
  "esbuild": "0.28.2",
85
- "express": "^5.0.0",
86
- "gen-esm-wrapper": "^1.1.2",
87
- "oxfmt": "0.65.0",
88
- "oxlint": "1.79.0",
91
+ "express": "^5.2.1",
92
+ "openapi-typescript": "7.13.0",
93
+ "oxfmt": "0.66.0",
94
+ "oxlint": "1.81.0",
89
95
  "oxlint-tsgolint": "7.0.2001",
90
- "puppeteer": "^25.0.0",
91
- "rimraf": "^6.0.0",
92
- "rolldown": "^1.0.0-rc.4",
93
- "typescript": "^6.0.0",
94
- "vitest": "^4.0.16",
95
- "webpack": "^5.105.2",
96
- "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"
97
103
  },
98
104
  "devEngines": {
99
105
  "packageManager": {
@@ -104,7 +110,6 @@
104
110
  },
105
111
  "scripts": {
106
112
  "build": "pnpm clean && pnpm build:node && pnpm build:browser",
107
- "postbuild": "gen-esm-wrapper dist/index.js dist/index.mjs",
108
113
  "clean": "rimraf dist tsconfig.tsbuildinfo",
109
114
  "test": "pnpm build && vitest run --project unit",
110
115
  "test:integration": "vitest run --project integration",
@@ -113,11 +118,14 @@
113
118
  "lint": "oxlint --type-aware",
114
119
  "lint:fix": "oxlint --type-aware --fix",
115
120
  "tsc-check-tests": "tsc --noEmit --project test/tsconfig.json",
121
+ "tsc-check-scripts": "tsc --noEmit --project tsconfig.scripts.json",
116
122
  "format": "oxfmt",
117
123
  "format:check": "oxfmt --check",
118
124
  "api:extract": "pnpm build && pnpm dlx github:apify/api-extractor-report --packages=. --extract-command='pnpm api:extract'",
119
125
  "api:check": "pnpm dlx github:apify/api-extractor-report --packages=. --extract-command='pnpm api:extract' --verify",
120
126
  "build:node": "tsc",
121
- "build:browser": "rsbuild build"
127
+ "build:browser": "rsbuild build",
128
+ "spec:fetch": "node scripts/openapi_spec.mts fetch",
129
+ "generate:models": "node scripts/openapi_spec.mts fetch && node scripts/generate_types.mts && node scripts/generate_schemas.mts && node scripts/openapi_spec.mts record-version"
122
130
  }
123
131
  }
@@ -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;