apify-client 2.25.1-beta.7 → 3.0.0-beta.0

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 (41) hide show
  1. package/dist/apify_client.js +34 -30
  2. package/dist/argument_validation_error.d.ts +17 -0
  3. package/dist/argument_validation_error.js +157 -0
  4. package/dist/base/api_client.d.ts +2 -2
  5. package/dist/base/api_client.js +13 -10
  6. package/dist/bundle.js +66 -28147
  7. package/dist/bundle.js.LICENSE.txt +33 -0
  8. package/dist/bundle.js.map +1 -1
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +1 -0
  11. package/dist/index.mjs +1 -0
  12. package/dist/resource_clients/actor.js +60 -55
  13. package/dist/resource_clients/actor_collection.js +13 -11
  14. package/dist/resource_clients/actor_env_var.js +2 -3
  15. package/dist/resource_clients/actor_env_var_collection.js +3 -3
  16. package/dist/resource_clients/actor_version.js +5 -4
  17. package/dist/resource_clients/actor_version_collection.js +3 -3
  18. package/dist/resource_clients/build.js +7 -10
  19. package/dist/resource_clients/build_collection.js +8 -8
  20. package/dist/resource_clients/dataset.d.ts +6 -4
  21. package/dist/resource_clients/dataset.js +66 -57
  22. package/dist/resource_clients/dataset_collection.js +14 -12
  23. package/dist/resource_clients/key_value_store.d.ts +3 -2
  24. package/dist/resource_clients/key_value_store.js +66 -50
  25. package/dist/resource_clients/key_value_store_collection.js +14 -12
  26. package/dist/resource_clients/request_queue.js +83 -89
  27. package/dist/resource_clients/request_queue_collection.js +12 -11
  28. package/dist/resource_clients/run.js +39 -40
  29. package/dist/resource_clients/run_collection.js +12 -11
  30. package/dist/resource_clients/schedule.js +1 -3
  31. package/dist/resource_clients/schedule_collection.js +10 -9
  32. package/dist/resource_clients/store_collection.js +13 -13
  33. package/dist/resource_clients/task.js +36 -33
  34. package/dist/resource_clients/task_collection.js +9 -9
  35. package/dist/resource_clients/webhook.js +1 -3
  36. package/dist/resource_clients/webhook_collection.js +10 -9
  37. package/dist/resource_clients/webhook_dispatch_collection.js +8 -8
  38. package/dist/statistics.js +4 -3
  39. package/dist/utils.d.ts +51 -5
  40. package/dist/utils.js +94 -12
  41. package/package.json +9 -4
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StoreCollectionClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const ow_1 = tslib_1.__importDefault(require("ow"));
4
+ const zod_1 = require("zod");
6
5
  const resource_collection_client_1 = require("../base/resource_collection_client");
6
+ const utils_1 = require("../utils");
7
+ const listOptionsSchema = zod_1.z.strictObject({
8
+ ...utils_1.paginationOptionsShape,
9
+ search: zod_1.z.string().optional(),
10
+ sortBy: zod_1.z.string().optional(),
11
+ category: zod_1.z.string().optional(),
12
+ username: zod_1.z.string().optional(),
13
+ pricingModel: zod_1.z.string().optional(),
14
+ includeUnrunnableActors: zod_1.z.boolean().optional(),
15
+ });
7
16
  /**
8
17
  * Client for browsing Actors in the Apify Store.
9
18
  *
@@ -56,17 +65,8 @@ class StoreCollectionClient extends resource_collection_client_1.ResourceCollect
56
65
  * @see https://docs.apify.com/api/v2/store-get
57
66
  */
58
67
  list(options = {}) {
59
- (0, ow_1.default)(options, ow_1.default.object.exactShape({
60
- limit: ow_1.default.optional.number.not.negative,
61
- offset: ow_1.default.optional.number.not.negative,
62
- search: ow_1.default.optional.string,
63
- sortBy: ow_1.default.optional.string,
64
- category: ow_1.default.optional.string,
65
- username: ow_1.default.optional.string,
66
- pricingModel: ow_1.default.optional.string,
67
- includeUnrunnableActors: ow_1.default.optional.boolean,
68
- }));
69
- return this._listPaginated(options);
68
+ const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'StoreCollectionListOptions');
69
+ return this._listPaginated(parsed);
70
70
  }
71
71
  }
72
72
  exports.StoreCollectionClient = StoreCollectionClient;
@@ -1,14 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TaskClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const ow_1 = tslib_1.__importDefault(require("ow"));
4
+ const zod_1 = require("zod");
6
5
  const consts_1 = require("@apify/consts");
7
6
  const resource_client_1 = require("../base/resource_client");
8
7
  const utils_1 = require("../utils");
9
8
  const run_1 = require("./run");
10
9
  const run_collection_1 = require("./run_collection");
11
10
  const webhook_collection_1 = require("./webhook_collection");
11
+ const inputSchema = utils_1.anyObjectSchema.optional();
12
+ const startOptionsSchema = zod_1.z.strictObject({
13
+ build: zod_1.z.string().optional(),
14
+ memory: zod_1.z.number().optional(),
15
+ timeout: zod_1.z.number().optional(),
16
+ waitForFinish: zod_1.z.number().optional(),
17
+ webhooks: zod_1.z.array(utils_1.anyObjectSchema).optional(),
18
+ maxItems: zod_1.z.number().min(0).optional(),
19
+ maxTotalChargeUsd: zod_1.z.number().min(0).optional(),
20
+ restartOnError: zod_1.z.boolean().optional(),
21
+ });
22
+ const callOptionsSchema = zod_1.z.strictObject({
23
+ build: zod_1.z.string().optional(),
24
+ memory: zod_1.z.number().optional(),
25
+ timeout: zod_1.z.number().min(0).optional(),
26
+ waitSecs: zod_1.z.number().min(0).optional(),
27
+ webhooks: zod_1.z.array(utils_1.anyObjectSchema).optional(),
28
+ maxItems: zod_1.z.number().min(0).optional(),
29
+ maxTotalChargeUsd: zod_1.z.number().min(0).optional(),
30
+ restartOnError: zod_1.z.boolean().optional(),
31
+ });
32
+ const lastRunOptionsSchema = zod_1.z.strictObject({
33
+ status: zod_1.z.enum(consts_1.ACT_JOB_STATUSES).optional(),
34
+ origin: zod_1.z.enum(consts_1.META_ORIGINS).optional(),
35
+ });
12
36
  /**
13
37
  * Client for managing a specific Actor task.
14
38
  *
@@ -56,7 +80,7 @@ class TaskClient extends resource_client_1.ResourceClient {
56
80
  * @see https://docs.apify.com/api/v2/actor-task-put
57
81
  */
58
82
  async update(newFields) {
59
- (0, ow_1.default)(newFields, ow_1.default.object);
83
+ (0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
60
84
  return this._update(newFields);
61
85
  }
62
86
  /**
@@ -114,24 +138,15 @@ class TaskClient extends resource_client_1.ResourceClient {
114
138
  * @see https://docs.apify.com/api/v2/actor-task-runs-post
115
139
  */
116
140
  async start(input, options = {}) {
117
- (0, ow_1.default)(input, ow_1.default.optional.object);
118
- (0, ow_1.default)(options, ow_1.default.object.exactShape({
119
- build: ow_1.default.optional.string,
120
- memory: ow_1.default.optional.number,
121
- timeout: ow_1.default.optional.number,
122
- waitForFinish: ow_1.default.optional.number,
123
- webhooks: ow_1.default.optional.array.ofType(ow_1.default.object),
124
- maxItems: ow_1.default.optional.number.not.negative,
125
- maxTotalChargeUsd: ow_1.default.optional.number.not.negative,
126
- restartOnError: ow_1.default.optional.boolean,
127
- }));
128
- const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError } = options;
141
+ (0, utils_1.parseArgument)(input, inputSchema);
142
+ const parsed = (0, utils_1.parseArgument)(options, startOptionsSchema, 'TaskStartOptions');
143
+ const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError } = parsed;
129
144
  const params = {
130
145
  waitForFinish,
131
146
  timeout,
132
147
  memory,
133
148
  build,
134
- webhooks: (0, utils_1.stringifyWebhooksToBase64)(options.webhooks),
149
+ webhooks: (0, utils_1.stringifyWebhooksToBase64)(parsed.webhooks),
135
150
  maxItems,
136
151
  maxTotalChargeUsd,
137
152
  restartOnError,
@@ -169,18 +184,9 @@ class TaskClient extends resource_client_1.ResourceClient {
169
184
  * @see https://docs.apify.com/api/v2/actor-task-runs-post
170
185
  */
171
186
  async call(input, options = {}) {
172
- (0, ow_1.default)(input, ow_1.default.optional.object);
173
- (0, ow_1.default)(options, ow_1.default.object.exactShape({
174
- build: ow_1.default.optional.string,
175
- memory: ow_1.default.optional.number,
176
- timeout: ow_1.default.optional.number.not.negative,
177
- waitSecs: ow_1.default.optional.number.not.negative,
178
- webhooks: ow_1.default.optional.array.ofType(ow_1.default.object),
179
- maxItems: ow_1.default.optional.number.not.negative,
180
- maxTotalChargeUsd: ow_1.default.optional.number.not.negative,
181
- restartOnError: ow_1.default.optional.boolean,
182
- }));
183
- const { waitSecs, ...startOptions } = options;
187
+ (0, utils_1.parseArgument)(input, inputSchema);
188
+ const parsed = (0, utils_1.parseArgument)(options, callOptionsSchema, 'TaskCallOptions');
189
+ const { waitSecs, ...startOptions } = parsed;
184
190
  const { id } = await this.start(input, startOptions);
185
191
  // Calling root client because we need access to top level API.
186
192
  // Creating a new instance of RunClient here would only allow
@@ -234,13 +240,10 @@ class TaskClient extends resource_client_1.ResourceClient {
234
240
  * @see https://docs.apify.com/api/v2/actor-task-runs-last-get
235
241
  */
236
242
  lastRun(options = {}) {
237
- (0, ow_1.default)(options, ow_1.default.object.exactShape({
238
- status: ow_1.default.optional.string.oneOf(Object.values(consts_1.ACT_JOB_STATUSES)),
239
- origin: ow_1.default.optional.string.oneOf(Object.values(consts_1.META_ORIGINS)),
240
- }));
243
+ const parsed = (0, utils_1.parseArgument)(options, lastRunOptionsSchema, 'TaskLastRunOptions');
241
244
  return new run_1.RunClient(this._subResourceOptions({
242
245
  id: 'last',
243
- params: this._params(options),
246
+ params: this._params(parsed),
244
247
  resourcePath: 'runs',
245
248
  }));
246
249
  }
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TaskCollectionClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const ow_1 = tslib_1.__importDefault(require("ow"));
4
+ const zod_1 = require("zod");
6
5
  const resource_collection_client_1 = require("../base/resource_collection_client");
6
+ const utils_1 = require("../utils");
7
+ const listOptionsSchema = zod_1.z.strictObject({
8
+ ...utils_1.paginationOptionsShape,
9
+ desc: zod_1.z.boolean().optional(),
10
+ });
7
11
  /**
8
12
  * Client for managing the collection of Actor tasks in your account.
9
13
  *
@@ -59,12 +63,8 @@ class TaskCollectionClient extends resource_collection_client_1.ResourceCollecti
59
63
  * @see https://docs.apify.com/api/v2/actor-tasks-get
60
64
  */
61
65
  list(options = {}) {
62
- (0, ow_1.default)(options, ow_1.default.object.exactShape({
63
- limit: ow_1.default.optional.number.not.negative,
64
- offset: ow_1.default.optional.number.not.negative,
65
- desc: ow_1.default.optional.boolean,
66
- }));
67
- return this._listPaginated(options);
66
+ const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'TaskCollectionListOptions');
67
+ return this._listPaginated(parsed);
68
68
  }
69
69
  /**
70
70
  * Creates a new task.
@@ -74,7 +74,7 @@ class TaskCollectionClient extends resource_collection_client_1.ResourceCollecti
74
74
  * @see https://docs.apify.com/api/v2/actor-tasks-post
75
75
  */
76
76
  async create(task) {
77
- (0, ow_1.default)(task, ow_1.default.object);
77
+ (0, utils_1.parseArgument)(task, utils_1.anyObjectSchema);
78
78
  return this._create(task);
79
79
  }
80
80
  }
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebhookClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const ow_1 = tslib_1.__importDefault(require("ow"));
6
4
  const resource_client_1 = require("../base/resource_client");
7
5
  const utils_1 = require("../utils");
8
6
  const webhook_dispatch_collection_1 = require("./webhook_dispatch_collection");
@@ -61,7 +59,7 @@ class WebhookClient extends resource_client_1.ResourceClient {
61
59
  * @see https://docs.apify.com/api/v2/webhook-put
62
60
  */
63
61
  async update(newFields) {
64
- (0, ow_1.default)(newFields, ow_1.default.object);
62
+ (0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
65
63
  return this._update(newFields);
66
64
  }
67
65
  /**
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebhookCollectionClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const ow_1 = tslib_1.__importDefault(require("ow"));
4
+ const zod_1 = require("zod");
6
5
  const resource_collection_client_1 = require("../base/resource_collection_client");
6
+ const utils_1 = require("../utils");
7
+ const listOptionsSchema = zod_1.z.strictObject({
8
+ ...utils_1.paginationOptionsShape,
9
+ desc: zod_1.z.boolean().optional(),
10
+ });
11
+ const webhookCreateSchema = utils_1.anyObjectSchema.optional();
7
12
  /**
8
13
  * Client for managing the collection of Webhooks.
9
14
  *
@@ -58,12 +63,8 @@ class WebhookCollectionClient extends resource_collection_client_1.ResourceColle
58
63
  * @see https://docs.apify.com/api/v2/webhooks-get
59
64
  */
60
65
  list(options = {}) {
61
- (0, ow_1.default)(options, ow_1.default.object.exactShape({
62
- limit: ow_1.default.optional.number.not.negative,
63
- offset: ow_1.default.optional.number.not.negative,
64
- desc: ow_1.default.optional.boolean,
65
- }));
66
- return this._listPaginated(options);
66
+ const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'WebhookCollectionListOptions');
67
+ return this._listPaginated(parsed);
67
68
  }
68
69
  /**
69
70
  * Creates a new webhook.
@@ -73,7 +74,7 @@ class WebhookCollectionClient extends resource_collection_client_1.ResourceColle
73
74
  * @see https://docs.apify.com/api/v2/webhooks-post
74
75
  */
75
76
  async create(webhook) {
76
- (0, ow_1.default)(webhook, ow_1.default.optional.object);
77
+ (0, utils_1.parseArgument)(webhook, webhookCreateSchema);
77
78
  return this._create(webhook);
78
79
  }
79
80
  }
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebhookDispatchCollectionClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const ow_1 = tslib_1.__importDefault(require("ow"));
4
+ const zod_1 = require("zod");
6
5
  const resource_collection_client_1 = require("../base/resource_collection_client");
6
+ const utils_1 = require("../utils");
7
+ const listOptionsSchema = zod_1.z.strictObject({
8
+ ...utils_1.paginationOptionsShape,
9
+ desc: zod_1.z.boolean().optional(),
10
+ });
7
11
  /**
8
12
  * Client for managing the collection of webhook dispatches.
9
13
  *
@@ -53,12 +57,8 @@ class WebhookDispatchCollectionClient extends resource_collection_client_1.Resou
53
57
  * @see https://docs.apify.com/api/v2/webhook-dispatches-get
54
58
  */
55
59
  list(options = {}) {
56
- (0, ow_1.default)(options, ow_1.default.object.exactShape({
57
- limit: ow_1.default.optional.number.not.negative,
58
- offset: ow_1.default.optional.number.not.negative,
59
- desc: ow_1.default.optional.boolean,
60
- }));
61
- return this._listPaginated(options);
60
+ const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'WebhookDispatchCollectionListOptions');
61
+ return this._listPaginated(parsed);
62
62
  }
63
63
  }
64
64
  exports.WebhookDispatchCollectionClient = WebhookDispatchCollectionClient;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Statistics = void 0;
4
- const tslib_1 = require("tslib");
5
- const ow_1 = tslib_1.__importDefault(require("ow"));
4
+ const zod_1 = require("zod");
5
+ const utils_1 = require("./utils");
6
+ const attemptSchema = zod_1.z.number().gt(0);
6
7
  class Statistics {
7
8
  /**
8
9
  * Number of Apify client function calls
@@ -18,7 +19,7 @@ class Statistics {
18
19
  */
19
20
  rateLimitErrors = [];
20
21
  addRateLimitError(attempt) {
21
- (0, ow_1.default)(attempt, ow_1.default.number.greaterThan(0));
22
+ (0, utils_1.parseArgument)(attempt, attemptSchema);
22
23
  // attempt is never 0,
23
24
  // but we don't want index 0 empty
24
25
  const index = attempt - 1;
package/dist/utils.d.ts CHANGED
@@ -1,8 +1,30 @@
1
1
  import type { Readable } from 'node:stream';
2
2
  import type { JsonValue, TypedArray } from 'type-fest';
3
+ import { z } from 'zod';
3
4
  import type { ApifyApiError } from './apify_api_error';
4
5
  import type { RequestQueueClientListRequestsOptions, RequestQueueClientListRequestsResult } from './resource_clients/request_queue';
5
6
  import type { WebhookUpdateData } from './resource_clients/webhook';
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>;
16
+ /**
17
+ * Accepts any non-null, non-array object as a predicate for `z.custom()`.
18
+ * @internal
19
+ */
20
+ export declare function isNonArrayObject(value: unknown): value is Record<string, unknown>;
21
+ /**
22
+ * Matches any plain object, letting unknown keys through - for payloads whose shape the API
23
+ * validates itself. A `z.custom()` predicate rather than an object schema, so parsing returns
24
+ * the value itself instead of a copy.
25
+ * @internal
26
+ */
27
+ export declare const anyObjectSchema: z.ZodCustom<Record<string, unknown>, Record<string, unknown>>;
6
28
  /**
7
29
  * Generic interface for objects that may contain a data property.
8
30
  *
@@ -40,7 +62,7 @@ export declare function parseDateFields(input: JsonValue, shouldParseField?: ((k
40
62
  /**
41
63
  * Helper function that converts array of webhooks to base64 string
42
64
  */
43
- export declare function stringifyWebhooksToBase64(webhooks: WebhookUpdateData[]): string | undefined;
65
+ export declare function stringifyWebhooksToBase64(webhooks?: readonly WebhookUpdateData[]): string | undefined;
44
66
  export interface CompressedValue {
45
67
  data: Buffer;
46
68
  encoding: 'br' | 'gzip';
@@ -103,6 +125,16 @@ export interface PaginationOptions {
103
125
  * */
104
126
  chunkSize?: number;
105
127
  }
128
+ /**
129
+ * Schema shape of {@link PaginationOptions}, to spread into every paginating client's list schema. One
130
+ * copy stops it drifting from the interface.
131
+ * @internal
132
+ */
133
+ export declare const paginationOptionsShape: {
134
+ limit: z.ZodOptional<z.ZodNumber>;
135
+ offset: z.ZodOptional<z.ZodNumber>;
136
+ chunkSize: z.ZodOptional<z.ZodNumber>;
137
+ };
106
138
  /**
107
139
  * Standard paginated response format.
108
140
  *
@@ -160,8 +192,22 @@ export type DistributiveOptional<T, K extends keyof T> = T extends any ? Omit<T,
160
192
  * Adds query parameters to a given URL based on the provided options object.
161
193
  */
162
194
  export declare function applyQueryParamsToUrl(url: URL, options?: Record<string, string | number | boolean | string[] | undefined>): URL;
163
- export declare const mutuallyExclusive: <T, K extends keyof T>(...keys: K[]) => (value: T) => {
164
- validator: boolean;
165
- message: string;
166
- };
195
+ /**
196
+ * Builds a `[check, message]` pair to spread into `.refine()`, asserting that at most one of `keys`
197
+ * is present. Pass the options interface as `T`, so that a misspelled key is a type error.
198
+ * @internal
199
+ */
200
+ export declare const mutuallyExclusive: <T extends object>(...keys: (keyof T & string)[]) => [(value: T) => boolean, string];
201
+ /**
202
+ * Percent-encodes a caller-supplied URL path segment so it cannot restructure the request path.
203
+ *
204
+ * Empty strings and dot segments are rejected instead of encoded, because URL parsers resolve
205
+ * dot segments after decoding - `records/%2E%2E` collapses to the parent endpoint just like `records/..`.
206
+ */
207
+ export declare function toPathSegment(value: string): string;
208
+ /**
209
+ * Builds a URL path from segments. A plain string is used as-is, so literal paths such as
210
+ * `requests/batch` keep their separators; an array has each of its segments encoded individually.
211
+ */
212
+ export declare function toPath(path: string | string[]): string;
167
213
  export {};
package/dist/utils.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mutuallyExclusive = exports.RequestQueuePaginationIterator = void 0;
3
+ exports.mutuallyExclusive = exports.paginationOptionsShape = exports.RequestQueuePaginationIterator = exports.anyObjectSchema = void 0;
4
+ exports.parseArgument = parseArgument;
5
+ exports.isNonArrayObject = isNonArrayObject;
4
6
  exports.pluckData = pluckData;
5
7
  exports.catchNotFoundOrThrow = catchNotFoundOrThrow;
6
8
  exports.parseDateFields = parseDateFields;
@@ -14,12 +16,49 @@ exports.getVersionData = getVersionData;
14
16
  exports.cast = cast;
15
17
  exports.asArray = asArray;
16
18
  exports.applyQueryParamsToUrl = applyQueryParamsToUrl;
17
- const tslib_1 = require("tslib");
18
- const ow_1 = tslib_1.__importDefault(require("ow"));
19
+ exports.toPathSegment = toPathSegment;
20
+ exports.toPath = toPath;
21
+ const zod_1 = require("zod");
22
+ const argument_validation_error_1 = require("./argument_validation_error");
19
23
  const NOT_FOUND_STATUS_CODE = 404;
20
24
  const RECORD_NOT_FOUND_TYPE = 'record-not-found';
21
25
  const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
22
26
  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
+ }
46
+ /**
47
+ * Accepts any non-null, non-array object as a predicate for `z.custom()`.
48
+ * @internal
49
+ */
50
+ function isNonArrayObject(value) {
51
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
52
+ }
53
+ /**
54
+ * Matches any plain object, letting unknown keys through - for payloads whose shape the API
55
+ * validates itself. A `z.custom()` predicate rather than an object schema, so parsing returns
56
+ * the value itself instead of a copy.
57
+ * @internal
58
+ */
59
+ exports.anyObjectSchema = zod_1.z.custom(isNonArrayObject, {
60
+ error: 'Invalid input: expected an object',
61
+ });
23
62
  /**
24
63
  * Returns object's 'data' property or throws if parameter is not an object,
25
64
  * or an object without a 'data' property.
@@ -183,10 +222,20 @@ function isNode() {
183
222
  return !!(typeof process !== 'undefined' && process.versions && process.versions.node);
184
223
  }
185
224
  function isBuffer(value) {
186
- return ow_1.default.isValid(value, ow_1.default.any(ow_1.default.buffer, ow_1.default.arrayBuffer, ow_1.default.typedArray));
225
+ // Tag checks rather than `instanceof`, to also match buffers from another realm. `isView()`
226
+ // additionally covers `DataView`, which is not raw binary content.
227
+ if (ArrayBuffer.isView(value))
228
+ return !isTagged(value, 'DataView');
229
+ return isTagged(value, 'ArrayBuffer');
230
+ }
231
+ function isTagged(value, tag) {
232
+ return Object.prototype.toString.call(value) === `[object ${tag}]`;
187
233
  }
188
234
  function isStream(value) {
189
- return ow_1.default.isValid(value, ow_1.default.object.hasKeys('on', 'pipe'));
235
+ if (value === null || typeof value !== 'object')
236
+ return false;
237
+ const { on, pipe } = value;
238
+ return typeof on === 'function' && typeof pipe === 'function';
190
239
  }
191
240
  function getVersionData() {
192
241
  if (typeof BROWSER_BUILD !== 'undefined') {
@@ -239,6 +288,16 @@ class RequestQueuePaginationIterator {
239
288
  }
240
289
  }
241
290
  exports.RequestQueuePaginationIterator = RequestQueuePaginationIterator;
291
+ /**
292
+ * Schema shape of {@link PaginationOptions}, to spread into every paginating client's list schema. One
293
+ * copy stops it drifting from the interface.
294
+ * @internal
295
+ */
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(),
300
+ };
242
301
  function cast(input) {
243
302
  return input;
244
303
  }
@@ -265,11 +324,34 @@ function applyQueryParamsToUrl(url, options) {
265
324
  }
266
325
  return url;
267
326
  }
268
- const mutuallyExclusive = (...keys) => (value) => {
269
- const presentKeys = keys.filter((key) => typeof value[key] !== 'undefined');
270
- return {
271
- validator: presentKeys.length <= 1,
272
- message: `At most one of the following fields is allowed: ${keys.join(', ')}`,
273
- };
274
- };
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
+ ];
275
336
  exports.mutuallyExclusive = mutuallyExclusive;
337
+ const pathSegmentSchema = zod_1.z
338
+ .string()
339
+ .nonempty()
340
+ .refine((v) => v !== '.' && v !== '..', { error: 'URL path must not contain dot segments' });
341
+ /**
342
+ * Percent-encodes a caller-supplied URL path segment so it cannot restructure the request path.
343
+ *
344
+ * Empty strings and dot segments are rejected instead of encoded, because URL parsers resolve
345
+ * dot segments after decoding - `records/%2E%2E` collapses to the parent endpoint just like `records/..`.
346
+ */
347
+ function toPathSegment(value) {
348
+ const valueParsed = parseArgument(value, pathSegmentSchema);
349
+ return encodeURIComponent(valueParsed);
350
+ }
351
+ /**
352
+ * Builds a URL path from segments. A plain string is used as-is, so literal paths such as
353
+ * `requests/batch` keep their separators; an array has each of its segments encoded individually.
354
+ */
355
+ function toPath(path) {
356
+ return Array.isArray(path) ? path.map(toPathSegment).join('/') : path;
357
+ }
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "2.25.1-beta.7",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "Apify API client for JavaScript",
5
+ "engines": {
6
+ "node": ">=22.0.0"
7
+ },
5
8
  "main": "dist/index.js",
6
9
  "module": "dist/index.mjs",
7
10
  "types": "dist/index.d.ts",
@@ -57,10 +60,10 @@
57
60
  "async-retry": "^1.3.3",
58
61
  "axios": "^1.16.0",
59
62
  "content-type": "^1.0.5",
60
- "ow": "^0.28.2",
61
63
  "proxy-agent": "^6.5.0",
62
64
  "tslib": "^2.5.0",
63
- "type-fest": "^4.0.0"
65
+ "type-fest": "^4.0.0",
66
+ "zod": "^4.0.0"
64
67
  },
65
68
  "devDependencies": {
66
69
  "@apify/oxlint-config": "^0.3.0",
@@ -103,7 +106,9 @@
103
106
  "build": "pnpm clean && pnpm build:node && pnpm build:browser",
104
107
  "postbuild": "gen-esm-wrapper dist/index.js dist/index.mjs",
105
108
  "clean": "rimraf dist tsconfig.tsbuildinfo",
106
- "test": "pnpm build && vitest run",
109
+ "test": "pnpm build && vitest run --project unit",
110
+ "test:integration": "vitest run --project integration",
111
+ "test:all": "pnpm build && vitest run",
107
112
  "test:bundling": "pnpm build && pnpm --prefix=./test/bundling run bundle:all",
108
113
  "lint": "oxlint --type-aware",
109
114
  "lint:fix": "oxlint --type-aware --fix",