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

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 (52) hide show
  1. package/README.md +3 -1
  2. package/dist/apify_api_error.d.ts +59 -3
  3. package/dist/apify_api_error.js +66 -2
  4. package/dist/base/resource_client.d.ts +4 -3
  5. package/dist/base/resource_client.js +7 -7
  6. package/dist/base/resource_collection_client.d.ts +5 -4
  7. package/dist/base/resource_collection_client.js +9 -9
  8. package/dist/bundle.js +16 -14
  9. package/dist/bundle.js.map +1 -1
  10. package/dist/generated/api.d.ts +287 -214
  11. package/dist/generated/schemas.d.ts +6699 -0
  12. package/dist/generated/schemas.js +1521 -0
  13. package/dist/http_client.js +1 -1
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +1 -0
  16. package/dist/lazy_schema.d.ts +8 -0
  17. package/dist/lazy_schema.js +11 -0
  18. package/dist/models.d.ts +21 -40
  19. package/dist/resource_clients/actor.js +7 -6
  20. package/dist/resource_clients/actor_collection.js +3 -2
  21. package/dist/resource_clients/actor_env_var.js +3 -2
  22. package/dist/resource_clients/actor_env_var_collection.js +3 -2
  23. package/dist/resource_clients/actor_version.js +3 -2
  24. package/dist/resource_clients/actor_version_collection.js +3 -2
  25. package/dist/resource_clients/build.js +5 -4
  26. package/dist/resource_clients/build_collection.js +2 -1
  27. package/dist/resource_clients/dataset.js +5 -4
  28. package/dist/resource_clients/dataset_collection.js +3 -2
  29. package/dist/resource_clients/key_value_store.js +5 -4
  30. package/dist/resource_clients/key_value_store_collection.js +3 -2
  31. package/dist/resource_clients/request_queue.js +24 -16
  32. package/dist/resource_clients/request_queue_collection.js +3 -2
  33. package/dist/resource_clients/run.js +9 -8
  34. package/dist/resource_clients/run_collection.js +2 -1
  35. package/dist/resource_clients/schedule.d.ts +4 -4
  36. package/dist/resource_clients/schedule.js +8 -5
  37. package/dist/resource_clients/schedule_collection.js +3 -2
  38. package/dist/resource_clients/store_collection.js +2 -1
  39. package/dist/resource_clients/task.js +5 -4
  40. package/dist/resource_clients/task_collection.js +3 -2
  41. package/dist/resource_clients/user.js +6 -6
  42. package/dist/resource_clients/webhook.js +5 -4
  43. package/dist/resource_clients/webhook_collection.js +3 -2
  44. package/dist/resource_clients/webhook_dispatch.js +2 -1
  45. package/dist/resource_clients/webhook_dispatch_collection.js +2 -1
  46. package/dist/response_validation_error.d.ts +26 -0
  47. package/dist/response_validation_error.js +37 -0
  48. package/dist/schemas.d.ts +15 -0
  49. package/dist/schemas.js +15 -0
  50. package/dist/utils.d.ts +12 -2
  51. package/dist/utils.js +26 -9
  52. package/package.json +3 -3
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The schemas the resource clients validate API responses with.
3
+ *
4
+ * Today these are exactly the generated ones. The module still exists as the one place where a generated
5
+ * schema is widened when the API is known to return something the specification does not describe, so a
6
+ * documented deviation never sends a resource client reaching into `./generated` directly. An override
7
+ * declared here shadows the generated export of the same name and takes the same form, a `lazySchema()` thunk
8
+ * built on the generated schema it replaces. Every schema that embeds an overridden one has to be rebuilt on
9
+ * top of it, and `spec_guards.ts` checks that each override still accepts what the specification describes,
10
+ * so one cannot narrow by accident.
11
+ *
12
+ * Spec gaps need no override: the generated objects are loose, so a field the specification omits passes
13
+ * through. Neither do client narrowings: a schema only ever accepts more than the published type.
14
+ */
15
+ export * from './generated/schemas.js';
package/dist/utils.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { JsonValue, TypedArray } from 'type-fest';
3
3
  import { z } from 'zod';
4
4
  import type { ApifyApiError } from './apify_api_error.js';
5
5
  import { parseArgument } from '@apify/validations';
6
+ import type { ApifyResponse } from './http_client.js';
6
7
  import type { RequestQueueClientListRequestsOptions, RequestQueueClientListRequestsResult } from './resource_clients/request_queue.js';
7
8
  import type { WebhookUpdateData } from './resource_clients/webhook.js';
8
9
  export { parseArgument };
@@ -26,14 +27,23 @@ export declare const anyObjectSchema: z.ZodCustom<Record<string, unknown>, Recor
26
27
  export interface MaybeData<R> {
27
28
  data?: R;
28
29
  }
30
+ /**
31
+ * Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope, converts the
32
+ * date fields and validates the result against `schema`, one of the schemas generated from the OpenAPI
33
+ * specification. The validated copy is what callers get, so it is exactly what the schema accepted -- unknown
34
+ * fields and unknown enum values included, since the schemas let both through.
35
+ *
36
+ * Throws {@link ResponseValidationError} when the response does not match the specification.
37
+ * @internal
38
+ */
39
+ export declare function parseResponse<R>(response: ApifyResponse, schema: z.ZodType, shouldParseField?: ((key: string) => boolean) | null): R;
29
40
  /**
30
41
  * Returns object's 'data' property or throws if parameter is not an object,
31
42
  * or an object without a 'data' property.
32
43
  */
33
44
  export declare function pluckData<R>(obj: MaybeData<R>): R;
34
45
  /**
35
- * If given HTTP error has NOT_FOUND_STATUS_CODE status code then returns undefined.
36
- * Otherwise rethrows error.
46
+ * Swallows a 404 Not Found API error and rethrows anything else.
37
47
  */
38
48
  export declare function catchNotFoundOrThrow(err: ApifyApiError): void;
39
49
  type ReturnJsonValue = string | number | boolean | null | Date | ReturnJsonObject | ReturnJsonArray;
package/dist/utils.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { z } from 'zod';
2
+ import { NotFoundError } from './apify_api_error.js';
2
3
  import { parseArgument } from '@apify/validations';
4
+ import { ResponseValidationError } from './response_validation_error.js';
3
5
  // @ts-ignore if we enable `resolveJsonModule`, we end up with a `src` folder in `dist`
4
6
  import packageJson from '../package.json' with { type: 'json' };
5
- const NOT_FOUND_STATUS_CODE = 404;
6
- const RECORD_NOT_FOUND_TYPE = 'record-not-found';
7
- const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
8
7
  const MIN_COMPRESS_BYTES = 1024;
9
8
  export { parseArgument };
10
9
  /**
@@ -23,6 +22,28 @@ export function isNonArrayObject(value) {
23
22
  export const anyObjectSchema = z.custom(isNonArrayObject, {
24
23
  error: 'Invalid input: expected an object',
25
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 exactly what the schema accepted -- unknown
33
+ * fields and unknown enum values included, since the schemas let both through.
34
+ *
35
+ * Throws {@link ResponseValidationError} when the response does not match the specification.
36
+ * @internal
37
+ */
38
+ export function parseResponse(response, schema, shouldParseField = null) {
39
+ const data = parseDateFields(pluckData(response.data), shouldParseField);
40
+ const result = schema.safeParse(data, { error: localeError });
41
+ if (!result.success) {
42
+ const { method = 'GET', url = '' } = response.config;
43
+ throw new ResponseValidationError(result.error, data, { method, url });
44
+ }
45
+ return result.data;
46
+ }
26
47
  /**
27
48
  * Returns object's 'data' property or throws if parameter is not an object,
28
49
  * or an object without a 'data' property.
@@ -35,14 +56,10 @@ export function pluckData(obj) {
35
56
  throw new Error(`Expected response object with a "data" property, but received: ${obj}`);
36
57
  }
37
58
  /**
38
- * If given HTTP error has NOT_FOUND_STATUS_CODE status code then returns undefined.
39
- * Otherwise rethrows error.
59
+ * Swallows a 404 Not Found API error and rethrows anything else.
40
60
  */
41
61
  export function catchNotFoundOrThrow(err) {
42
- const isNotFoundStatus = err.statusCode === NOT_FOUND_STATUS_CODE;
43
- const isNotFoundMessage = err.type === RECORD_NOT_FOUND_TYPE || err.type === RECORD_OR_TOKEN_NOT_FOUND_TYPE || err.httpMethod === 'head';
44
- const isNotFoundError = isNotFoundStatus && isNotFoundMessage;
45
- if (!isNotFoundError)
62
+ if (!(err instanceof NotFoundError))
46
63
  throw err;
47
64
  }
48
65
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.4",
3
+ "version": "3.0.0-beta.6",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "apify": {
55
55
  "openapiSpec": {
56
- "version": "v2-2026-08-03T111309Z"
56
+ "version": "v2-2026-08-31T125154Z"
57
57
  }
58
58
  },
59
59
  "dependencies": {
@@ -126,6 +126,6 @@
126
126
  "build:node": "tsc",
127
127
  "build:browser": "rsbuild build",
128
128
  "spec:fetch": "node scripts/openapi_spec.mts fetch",
129
- "generate:types": "node scripts/openapi_spec.mts fetch && node scripts/generate_types.mts && node scripts/openapi_spec.mts record-version"
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"
130
130
  }
131
131
  }