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

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 (99) hide show
  1. package/README.md +7 -3
  2. package/dist/apify_api_error.d.ts +60 -19
  3. package/dist/apify_api_error.js +88 -22
  4. package/dist/apify_client.d.ts +22 -3
  5. package/dist/apify_client.js +37 -31
  6. package/dist/base/api_client.d.ts +6 -6
  7. package/dist/base/api_client.js +24 -16
  8. package/dist/base/resource_client.d.ts +23 -9
  9. package/dist/base/resource_client.js +49 -25
  10. package/dist/base/resource_collection_client.d.ts +7 -4
  11. package/dist/base/resource_collection_client.js +21 -15
  12. package/dist/body_parser.d.ts +3 -4
  13. package/dist/body_parser.js +17 -24
  14. package/dist/bundle.js +38 -48
  15. package/dist/bundle.js.map +1 -1
  16. package/dist/generated/api.d.ts +287 -214
  17. package/dist/generated/schemas.d.ts +6699 -0
  18. package/dist/generated/schemas.js +1521 -0
  19. package/dist/http_client.d.ts +18 -51
  20. package/dist/http_client.js +90 -85
  21. package/dist/index.d.ts +3 -1
  22. package/dist/index.js +2 -1
  23. package/dist/interceptors.js +24 -6
  24. package/dist/lazy_schema.d.ts +8 -0
  25. package/dist/lazy_schema.js +11 -0
  26. package/dist/models.d.ts +32 -52
  27. package/dist/resource_clients/actor.d.ts +46 -31
  28. package/dist/resource_clients/actor.js +71 -53
  29. package/dist/resource_clients/actor_collection.d.ts +9 -5
  30. package/dist/resource_clients/actor_collection.js +12 -3
  31. package/dist/resource_clients/actor_env_var.d.ts +10 -3
  32. package/dist/resource_clients/actor_env_var.js +17 -6
  33. package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
  34. package/dist/resource_clients/actor_env_var_collection.js +18 -11
  35. package/dist/resource_clients/actor_version.d.ts +18 -3
  36. package/dist/resource_clients/actor_version.js +20 -9
  37. package/dist/resource_clients/actor_version_collection.d.ts +16 -17
  38. package/dist/resource_clients/actor_version_collection.js +20 -11
  39. package/dist/resource_clients/build.d.ts +18 -6
  40. package/dist/resource_clients/build.js +35 -17
  41. package/dist/resource_clients/build_collection.d.ts +3 -1
  42. package/dist/resource_clients/build_collection.js +5 -1
  43. package/dist/resource_clients/dataset.d.ts +23 -9
  44. package/dist/resource_clients/dataset.js +70 -48
  45. package/dist/resource_clients/dataset_collection.d.ts +6 -2
  46. package/dist/resource_clients/dataset_collection.js +13 -2
  47. package/dist/resource_clients/key_value_store.d.ts +48 -15
  48. package/dist/resource_clients/key_value_store.js +71 -40
  49. package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
  50. package/dist/resource_clients/key_value_store_collection.js +13 -2
  51. package/dist/resource_clients/log.d.ts +9 -19
  52. package/dist/resource_clients/log.js +57 -45
  53. package/dist/resource_clients/request_queue.d.ts +56 -26
  54. package/dist/resource_clients/request_queue.js +178 -113
  55. package/dist/resource_clients/request_queue_collection.d.ts +6 -2
  56. package/dist/resource_clients/request_queue_collection.js +10 -3
  57. package/dist/resource_clients/run.d.ts +51 -17
  58. package/dist/resource_clients/run.js +85 -44
  59. package/dist/resource_clients/run_collection.d.ts +3 -1
  60. package/dist/resource_clients/run_collection.js +5 -1
  61. package/dist/resource_clients/schedule.d.ts +16 -7
  62. package/dist/resource_clients/schedule.js +31 -21
  63. package/dist/resource_clients/schedule_collection.d.ts +6 -2
  64. package/dist/resource_clients/schedule_collection.js +10 -3
  65. package/dist/resource_clients/store_collection.d.ts +3 -1
  66. package/dist/resource_clients/store_collection.js +5 -1
  67. package/dist/resource_clients/task.d.ts +28 -10
  68. package/dist/resource_clients/task.js +67 -44
  69. package/dist/resource_clients/task_collection.d.ts +6 -2
  70. package/dist/resource_clients/task_collection.js +10 -3
  71. package/dist/resource_clients/user.d.ts +17 -8
  72. package/dist/resource_clients/user.js +40 -39
  73. package/dist/resource_clients/webhook.d.ts +14 -5
  74. package/dist/resource_clients/webhook.js +30 -22
  75. package/dist/resource_clients/webhook_collection.d.ts +6 -2
  76. package/dist/resource_clients/webhook_collection.js +10 -3
  77. package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
  78. package/dist/resource_clients/webhook_dispatch.js +8 -2
  79. package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
  80. package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
  81. package/dist/response_validation_error.d.ts +26 -0
  82. package/dist/response_validation_error.js +37 -0
  83. package/dist/runtime/node.d.ts +6 -0
  84. package/dist/runtime/node.js +58 -0
  85. package/dist/runtime/types.d.ts +50 -0
  86. package/dist/runtime/types.js +1 -0
  87. package/dist/runtime/web.d.ts +5 -0
  88. package/dist/runtime/web.js +17 -0
  89. package/dist/schemas.d.ts +15 -0
  90. package/dist/schemas.js +15 -0
  91. package/dist/statistics.d.ts +1 -6
  92. package/dist/statistics.js +2 -2
  93. package/dist/timeouts.d.ts +72 -0
  94. package/dist/timeouts.js +31 -0
  95. package/dist/utils.d.ts +75 -55
  96. package/dist/utils.js +201 -180
  97. package/package.json +42 -35
  98. package/dist/argument_validation_error.d.ts +0 -17
  99. package/dist/argument_validation_error.js +0 -153
@@ -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
- }