apify-client 3.0.0-beta.1 → 3.0.0-beta.11

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 +13 -4
  9. package/dist/base/resource_client.js +25 -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 +287 -214
  16. package/dist/generated/api.js +1 -2
  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 +33 -52
  28. package/dist/models.js +8 -11
  29. package/dist/resource_clients/actor.d.ts +13 -13
  30. package/dist/resource_clients/actor.js +70 -73
  31. package/dist/resource_clients/actor_collection.d.ts +10 -10
  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 +16 -8
  38. package/dist/resource_clients/actor_version.js +15 -19
  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 +7 -5
  42. package/dist/resource_clients/build.js +16 -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 +8 -8
  46. package/dist/resource_clients/dataset.js +75 -85
  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 -8
  50. package/dist/resource_clients/key_value_store.js +61 -65
  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 +6 -4
  54. package/dist/resource_clients/log.js +23 -28
  55. package/dist/resource_clients/request_queue.d.ts +4 -11
  56. package/dist/resource_clients/request_queue.js +100 -106
  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 +18 -8
  60. package/dist/resource_clients/run.js +62 -54
  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 -8
  64. package/dist/resource_clients/schedule.js +14 -23
  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 -5
  68. package/dist/resource_clients/store_collection.js +15 -18
  69. package/dist/resource_clients/task.d.ts +11 -11
  70. package/dist/resource_clients/task.js +49 -59
  71. package/dist/resource_clients/task_collection.d.ts +6 -6
  72. package/dist/resource_clients/task_collection.js +12 -15
  73. package/dist/resource_clients/user.d.ts +11 -11
  74. package/dist/resource_clients/user.js +16 -35
  75. package/dist/resource_clients/webhook.d.ts +8 -8
  76. package/dist/resource_clients/webhook.js +13 -23
  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 -5
  80. package/dist/resource_clients/webhook_dispatch.js +5 -9
  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 +27 -24
  90. package/dist/utils.js +69 -93
  91. package/package.json +38 -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
@@ -1,37 +1,35 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaskClient = void 0;
4
- const zod_1 = require("zod");
5
- const consts_1 = require("@apify/consts");
6
- const resource_client_1 = require("../base/resource_client");
7
- const utils_1 = require("../utils");
8
- const run_1 = require("./run");
9
- const run_collection_1 = require("./run_collection");
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(),
1
+ import { z } from 'zod';
2
+ import { ACT_JOB_STATUSES, META_ORIGINS } from '@apify/consts';
3
+ import { ResourceClient } from '../base/resource_client.js';
4
+ import * as schemas from '../schemas.js';
5
+ import { anyObjectSchema, cast, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
6
+ import { RunClient } from './run.js';
7
+ import { RunCollectionClient } from './run_collection.js';
8
+ import { WebhookCollectionClient } from './webhook_collection.js';
9
+ const inputSchema = anyObjectSchema.optional();
10
+ const startOptionsSchema = z.strictObject({
11
+ build: z.string().optional(),
12
+ memory: z.number().optional(),
13
+ timeout: z.number().optional(),
14
+ waitForFinish: z.number().optional(),
15
+ webhooks: z.array(anyObjectSchema).optional(),
16
+ maxItems: z.number().min(0).optional(),
17
+ maxTotalChargeUsd: z.number().min(0).optional(),
18
+ restartOnError: z.boolean().optional(),
21
19
  });
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(),
20
+ const callOptionsSchema = z.strictObject({
21
+ build: z.string().optional(),
22
+ memory: z.number().optional(),
23
+ timeout: z.number().min(0).optional(),
24
+ waitSecs: z.number().min(0).optional(),
25
+ webhooks: z.array(anyObjectSchema).optional(),
26
+ maxItems: z.number().min(0).optional(),
27
+ maxTotalChargeUsd: z.number().min(0).optional(),
28
+ restartOnError: z.boolean().optional(),
31
29
  });
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(),
30
+ const lastRunOptionsSchema = z.strictObject({
31
+ status: z.enum(ACT_JOB_STATUSES).optional(),
32
+ origin: z.enum(META_ORIGINS).optional(),
35
33
  });
36
34
  /**
37
35
  * Client for managing a specific Actor task.
@@ -53,7 +51,7 @@ const lastRunOptionsSchema = zod_1.z.strictObject({
53
51
  *
54
52
  * @see https://docs.apify.com/platform/actors/running/tasks
55
53
  */
56
- class TaskClient extends resource_client_1.ResourceClient {
54
+ export class TaskClient extends ResourceClient {
57
55
  /**
58
56
  * @hidden
59
57
  */
@@ -70,7 +68,7 @@ class TaskClient extends resource_client_1.ResourceClient {
70
68
  * @see https://docs.apify.com/api/v2/actor-task-get
71
69
  */
72
70
  async get() {
73
- return this._get();
71
+ return this._get(schemas.Task());
74
72
  }
75
73
  /**
76
74
  * Updates the task with the specified fields.
@@ -80,8 +78,8 @@ class TaskClient extends resource_client_1.ResourceClient {
80
78
  * @see https://docs.apify.com/api/v2/actor-task-put
81
79
  */
82
80
  async update(newFields) {
83
- (0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
84
- return this._update(newFields);
81
+ parseArgument(newFields, anyObjectSchema);
82
+ return this._update(schemas.Task(), newFields);
85
83
  }
86
84
  /**
87
85
  * Publishes the task on its public landing page, by setting `isPublic` through
@@ -138,15 +136,15 @@ class TaskClient extends resource_client_1.ResourceClient {
138
136
  * @see https://docs.apify.com/api/v2/actor-task-runs-post
139
137
  */
140
138
  async start(input, options = {}) {
141
- (0, utils_1.parseArgument)(input, inputSchema);
142
- const parsed = (0, utils_1.parseArgument)(options, startOptionsSchema, 'TaskStartOptions');
139
+ parseArgument(input, inputSchema);
140
+ const parsed = parseArgument(options, startOptionsSchema, 'TaskStartOptions');
143
141
  const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError } = parsed;
144
142
  const params = {
145
143
  waitForFinish,
146
144
  timeout,
147
145
  memory,
148
146
  build,
149
- webhooks: (0, utils_1.stringifyWebhooksToBase64)(parsed.webhooks),
147
+ webhooks: stringifyWebhooksToBase64(parsed.webhooks),
150
148
  maxItems,
151
149
  maxTotalChargeUsd,
152
150
  restartOnError,
@@ -164,7 +162,7 @@ class TaskClient extends resource_client_1.ResourceClient {
164
162
  },
165
163
  };
166
164
  const response = await this.httpClient.call(request);
167
- return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
165
+ return parseResponse(response, schemas.Run());
168
166
  }
169
167
  /**
170
168
  * Starts a task and waits for it to finish before returning the Run object.
@@ -184,8 +182,8 @@ class TaskClient extends resource_client_1.ResourceClient {
184
182
  * @see https://docs.apify.com/api/v2/actor-task-runs-post
185
183
  */
186
184
  async call(input, options = {}) {
187
- (0, utils_1.parseArgument)(input, inputSchema);
188
- const parsed = (0, utils_1.parseArgument)(options, callOptionsSchema, 'TaskCallOptions');
185
+ parseArgument(input, inputSchema);
186
+ const parsed = parseArgument(options, callOptionsSchema, 'TaskCallOptions');
189
187
  const { waitSecs, ...startOptions } = parsed;
190
188
  const { id } = await this.start(input, startOptions);
191
189
  // Calling root client because we need access to top level API.
@@ -196,23 +194,16 @@ class TaskClient extends resource_client_1.ResourceClient {
196
194
  /**
197
195
  * Retrieves the Actor task's input object.
198
196
  *
199
- * @returns The Task's input, or `undefined` if it does not exist.
197
+ * @returns The Task's input.
200
198
  * @see https://docs.apify.com/api/v2/actor-task-input-get
201
199
  */
202
200
  async getInput() {
203
- const requestOpts = {
201
+ const response = await this.httpClient.call({
204
202
  url: this._url('input'),
205
203
  method: 'GET',
206
204
  params: this._params(),
207
- };
208
- try {
209
- const response = await this.httpClient.call(requestOpts);
210
- return (0, utils_1.cast)(response.data);
211
- }
212
- catch (err) {
213
- (0, utils_1.catchNotFoundOrThrow)(err);
214
- }
215
- return undefined;
205
+ });
206
+ return cast(response.data);
216
207
  }
217
208
  /**
218
209
  * Updates the Actor task's input object.
@@ -228,7 +219,7 @@ class TaskClient extends resource_client_1.ResourceClient {
228
219
  params: this._params(),
229
220
  data: newFields,
230
221
  });
231
- return (0, utils_1.cast)(response.data);
222
+ return cast(response.data);
232
223
  }
233
224
  /**
234
225
  * Returns a client for the last run of this task.
@@ -240,8 +231,8 @@ class TaskClient extends resource_client_1.ResourceClient {
240
231
  * @see https://docs.apify.com/api/v2/actor-task-runs-last-get
241
232
  */
242
233
  lastRun(options = {}) {
243
- const parsed = (0, utils_1.parseArgument)(options, lastRunOptionsSchema, 'TaskLastRunOptions');
244
- return new run_1.RunClient(this._subResourceOptions({
234
+ const parsed = parseArgument(options, lastRunOptionsSchema, 'TaskLastRunOptions');
235
+ return new RunClient(this._subResourceOptions({
245
236
  id: 'last',
246
237
  params: this._params(parsed),
247
238
  resourcePath: 'runs',
@@ -254,7 +245,7 @@ class TaskClient extends resource_client_1.ResourceClient {
254
245
  * @see https://docs.apify.com/api/v2/actor-task-runs-get
255
246
  */
256
247
  runs() {
257
- return new run_collection_1.RunCollectionClient(this._subResourceOptions({
248
+ return new RunCollectionClient(this._subResourceOptions({
258
249
  resourcePath: 'runs',
259
250
  }));
260
251
  }
@@ -265,7 +256,6 @@ class TaskClient extends resource_client_1.ResourceClient {
265
256
  * @see https://docs.apify.com/api/v2/actor-task-webhooks-get
266
257
  */
267
258
  webhooks() {
268
- return new webhook_collection_1.WebhookCollectionClient(this._subResourceOptions());
259
+ return new WebhookCollectionClient(this._subResourceOptions());
269
260
  }
270
261
  }
271
- exports.TaskClient = TaskClient;
@@ -1,9 +1,9 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceCollectionClient } from '../base/resource_collection_client';
3
- import type { TaskList } from '../models';
4
- import type { PaginatedIterator, PaginationOptions } from '../utils';
5
- import type { Task, TaskUpdateData } from './task';
6
- export type { TaskList } from '../models';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import type { TaskList } from '../models.js';
4
+ import type { PaginatedIterator, PaginationOptions } from '../utils.js';
5
+ import type { Task, TaskUpdateData } from './task.js';
6
+ export type { TaskList } from '../models.js';
7
7
  /**
8
8
  * Client for managing the collection of Actor tasks in your account.
9
9
  *
@@ -1,12 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TaskCollectionClient = void 0;
4
- const zod_1 = require("zod");
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(),
1
+ import { z } from 'zod';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import * as schemas from '../schemas.js';
4
+ import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
5
+ const listOptionsSchema = z.strictObject({
6
+ ...paginationOptionsShape,
7
+ desc: z.boolean().optional(),
10
8
  });
11
9
  /**
12
10
  * Client for managing the collection of Actor tasks in your account.
@@ -32,7 +30,7 @@ const listOptionsSchema = zod_1.z.strictObject({
32
30
  *
33
31
  * @see https://docs.apify.com/platform/actors/running/tasks
34
32
  */
35
- class TaskCollectionClient extends resource_collection_client_1.ResourceCollectionClient {
33
+ export class TaskCollectionClient extends ResourceCollectionClient {
36
34
  /**
37
35
  * @hidden
38
36
  */
@@ -63,8 +61,8 @@ class TaskCollectionClient extends resource_collection_client_1.ResourceCollecti
63
61
  * @see https://docs.apify.com/api/v2/actor-tasks-get
64
62
  */
65
63
  list(options = {}) {
66
- const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'TaskCollectionListOptions');
67
- return this._listPaginated(parsed);
64
+ const parsed = parseArgument(options, listOptionsSchema, 'TaskCollectionListOptions');
65
+ return this._listPaginated(schemas.ListOfTasks(), parsed);
68
66
  }
69
67
  /**
70
68
  * Creates a new task.
@@ -74,8 +72,7 @@ class TaskCollectionClient extends resource_collection_client_1.ResourceCollecti
74
72
  * @see https://docs.apify.com/api/v2/actor-tasks-post
75
73
  */
76
74
  async create(task) {
77
- (0, utils_1.parseArgument)(task, utils_1.anyObjectSchema);
78
- return this._create(task);
75
+ parseArgument(task, anyObjectSchema);
76
+ return this._create(schemas.Task(), task);
79
77
  }
80
78
  }
81
- exports.TaskCollectionClient = TaskCollectionClient;
@@ -1,8 +1,8 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceClient } from '../base/resource_client';
3
- import type { AccountAndUsageLimits, MonthlyUsage, User } from '../models';
4
- export type { AccountAndUsageLimits, Current, DailyServiceUsage, EffectivePlatformFeature, EffectivePlatformFeatures, Limits, MonthlyUsage, MonthlyUsageCycle, PriceTier, ProxyGroup, ServiceUsage, UsageCycle, UsageItem, User, UserPlan, UserProfile, UserProxy, } from '../models';
5
- export { PlatformFeature } from '../models';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceClient } from '../base/resource_client.js';
3
+ import type { AccountAndUsageLimits, MonthlyUsage, User } from '../models.js';
4
+ export type { AccountAndUsageLimits, Current, DailyServiceUsage, EffectivePlatformFeature, EffectivePlatformFeatures, Limits, MonthlyUsage, MonthlyUsageCycle, PriceTier, ProxyGroup, ServiceUsage, UsageCycle, UsageItem, User, UserPlan, UserProfile, UserProxy, } from '../models.js';
5
+ export { PlatformFeature } from '../models.js';
6
6
  /**
7
7
  * Client for managing user account information.
8
8
  *
@@ -38,26 +38,26 @@ export declare class UserClient extends ResourceClient {
38
38
  * Depending on whether ApifyClient was created with a token,
39
39
  * the method will either return public or private user data.
40
40
  *
41
- * @returns The user object.
41
+ * @returns The user object, or `undefined` if it does not exist.
42
42
  * @see https://docs.apify.com/api/v2/user-get
43
43
  */
44
- get(): Promise<User>;
44
+ get(): Promise<User | undefined>;
45
45
  /**
46
46
  * Retrieves the user's monthly usage data.
47
47
  *
48
- * @returns The monthly usage object, or `undefined` if it does not exist.
48
+ * @returns The monthly usage object.
49
49
  * @see https://docs.apify.com/api/v2/users-me-usage-monthly-get
50
50
  * @since Added in 2.9.2
51
51
  */
52
- monthlyUsage(): Promise<MonthlyUsage | undefined>;
52
+ monthlyUsage(): Promise<MonthlyUsage>;
53
53
  /**
54
54
  * Retrieves the user's account and usage limits.
55
55
  *
56
- * @returns The account and usage limits object, or `undefined` if it does not exist.
56
+ * @returns The account and usage limits object.
57
57
  * @see https://docs.apify.com/api/v2/users-me-limits-get
58
58
  * @since Added in 2.9.2
59
59
  */
60
- limits(): Promise<AccountAndUsageLimits | undefined>;
60
+ limits(): Promise<AccountAndUsageLimits>;
61
61
  /**
62
62
  * Updates the user's account and usage limits.
63
63
  *
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UserClient = exports.PlatformFeature = void 0;
4
- const resource_client_1 = require("../base/resource_client");
5
- const utils_1 = require("../utils");
6
- var models_1 = require("../models");
7
- Object.defineProperty(exports, "PlatformFeature", { enumerable: true, get: function () { return models_1.PlatformFeature; } });
1
+ import { ResourceClient } from '../base/resource_client.js';
2
+ import * as schemas from '../schemas.js';
3
+ import { parseResponse } from '../utils.js';
4
+ export { PlatformFeature } from '../models.js';
8
5
  /**
9
6
  * Client for managing user account information.
10
7
  *
@@ -29,7 +26,7 @@ Object.defineProperty(exports, "PlatformFeature", { enumerable: true, get: funct
29
26
  *
30
27
  * @see https://docs.apify.com/platform/actors/running
31
28
  */
32
- class UserClient extends resource_client_1.ResourceClient {
29
+ export class UserClient extends ResourceClient {
33
30
  /**
34
31
  * @hidden
35
32
  */
@@ -45,57 +42,42 @@ class UserClient extends resource_client_1.ResourceClient {
45
42
  * Depending on whether ApifyClient was created with a token,
46
43
  * the method will either return public or private user data.
47
44
  *
48
- * @returns The user object.
45
+ * @returns The user object, or `undefined` if it does not exist.
49
46
  * @see https://docs.apify.com/api/v2/user-get
50
47
  */
51
48
  async get() {
52
- return this._get();
49
+ return this._get(schemas.UserPrivateInfo());
53
50
  }
54
51
  /**
55
52
  * Retrieves the user's monthly usage data.
56
53
  *
57
- * @returns The monthly usage object, or `undefined` if it does not exist.
54
+ * @returns The monthly usage object.
58
55
  * @see https://docs.apify.com/api/v2/users-me-usage-monthly-get
59
56
  * @since Added in 2.9.2
60
57
  */
61
58
  async monthlyUsage() {
62
- const requestOpts = {
59
+ const response = await this.httpClient.call({
63
60
  url: this._url('usage/monthly'),
64
61
  method: 'GET',
65
62
  params: this._params(),
66
- };
67
- try {
68
- const response = await this.httpClient.call(requestOpts);
69
- return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data),
70
- // Convert monthlyUsage.dailyServiceUsages[].date to Date (by default it's ignored by parseDateFields)
71
- /* shouldParseField = */ (key) => key === 'date'));
72
- }
73
- catch (err) {
74
- (0, utils_1.catchNotFoundOrThrow)(err);
75
- }
76
- return undefined;
63
+ });
64
+ // `dailyServiceUsages[].date` does not end in `At`, so it has to be named for `parseDateFields`.
65
+ return parseResponse(response, schemas.MonthlyUsage(), (key) => key === 'date');
77
66
  }
78
67
  /**
79
68
  * Retrieves the user's account and usage limits.
80
69
  *
81
- * @returns The account and usage limits object, or `undefined` if it does not exist.
70
+ * @returns The account and usage limits object.
82
71
  * @see https://docs.apify.com/api/v2/users-me-limits-get
83
72
  * @since Added in 2.9.2
84
73
  */
85
74
  async limits() {
86
- const requestOpts = {
75
+ const response = await this.httpClient.call({
87
76
  url: this._url('limits'),
88
77
  method: 'GET',
89
78
  params: this._params(),
90
- };
91
- try {
92
- const response = await this.httpClient.call(requestOpts);
93
- return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
94
- }
95
- catch (err) {
96
- (0, utils_1.catchNotFoundOrThrow)(err);
97
- }
98
- return undefined;
79
+ });
80
+ return parseResponse(response, schemas.AccountLimits());
99
81
  }
100
82
  /**
101
83
  * Updates the user's account and usage limits.
@@ -114,4 +96,3 @@ class UserClient extends resource_client_1.ResourceClient {
114
96
  await this.httpClient.call(requestOpts);
115
97
  }
116
98
  }
117
- exports.UserClient = UserClient;
@@ -1,9 +1,9 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceClient } from '../base/resource_client';
3
- import type { Webhook, WebhookEventType } from '../models';
4
- import type { WebhookDispatch } from './webhook_dispatch';
5
- import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection';
6
- export type { Webhook, WebhookAnyRunOfActorCondition, WebhookAnyRunOfActorTaskCondition, WebhookCertainRunCondition, WebhookCondition, WebhookEventType, WebhookLastDispatch, WebhookStats, } from '../models';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceClient } from '../base/resource_client.js';
3
+ import type { Webhook, WebhookEventType } from '../models.js';
4
+ import type { WebhookDispatch } from './webhook_dispatch.js';
5
+ import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
6
+ export type { Webhook, WebhookAnyRunOfActorCondition, WebhookAnyRunOfActorTaskCondition, WebhookCertainRunCondition, WebhookCondition, WebhookEventType, WebhookLastDispatch, WebhookStats, } from '../models.js';
7
7
  /**
8
8
  * Client for managing a specific webhook.
9
9
  *
@@ -61,10 +61,10 @@ export declare class WebhookClient extends ResourceClient {
61
61
  /**
62
62
  * Tests the webhook by dispatching a test event.
63
63
  *
64
- * @returns The webhook dispatch object, or `undefined` if the test fails.
64
+ * @returns The webhook dispatch object.
65
65
  * @see https://docs.apify.com/api/v2/webhook-test-post
66
66
  */
67
- test(): Promise<WebhookDispatch | undefined>;
67
+ test(): Promise<WebhookDispatch>;
68
68
  /**
69
69
  * Returns a client for the dispatches of this webhook.
70
70
  *
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookClient = void 0;
4
- const resource_client_1 = require("../base/resource_client");
5
- const utils_1 = require("../utils");
6
- const webhook_dispatch_collection_1 = require("./webhook_dispatch_collection");
1
+ import { ResourceClient } from '../base/resource_client.js';
2
+ import * as schemas from '../schemas.js';
3
+ import { anyObjectSchema, parseArgument, parseResponse } from '../utils.js';
4
+ import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
7
5
  /**
8
6
  * Client for managing a specific webhook.
9
7
  *
@@ -32,7 +30,7 @@ const webhook_dispatch_collection_1 = require("./webhook_dispatch_collection");
32
30
  *
33
31
  * @see https://docs.apify.com/platform/integrations/webhooks
34
32
  */
35
- class WebhookClient extends resource_client_1.ResourceClient {
33
+ export class WebhookClient extends ResourceClient {
36
34
  /**
37
35
  * @hidden
38
36
  */
@@ -49,7 +47,7 @@ class WebhookClient extends resource_client_1.ResourceClient {
49
47
  * @see https://docs.apify.com/api/v2/webhook-get
50
48
  */
51
49
  async get() {
52
- return this._get();
50
+ return this._get(schemas.Webhook());
53
51
  }
54
52
  /**
55
53
  * Updates the webhook with the specified fields.
@@ -59,8 +57,8 @@ class WebhookClient extends resource_client_1.ResourceClient {
59
57
  * @see https://docs.apify.com/api/v2/webhook-put
60
58
  */
61
59
  async update(newFields) {
62
- (0, utils_1.parseArgument)(newFields, utils_1.anyObjectSchema);
63
- return this._update(newFields);
60
+ parseArgument(newFields, anyObjectSchema);
61
+ return this._update(schemas.Webhook(), newFields);
64
62
  }
65
63
  /**
66
64
  * Deletes the webhook.
@@ -73,23 +71,16 @@ class WebhookClient extends resource_client_1.ResourceClient {
73
71
  /**
74
72
  * Tests the webhook by dispatching a test event.
75
73
  *
76
- * @returns The webhook dispatch object, or `undefined` if the test fails.
74
+ * @returns The webhook dispatch object.
77
75
  * @see https://docs.apify.com/api/v2/webhook-test-post
78
76
  */
79
77
  async test() {
80
- const request = {
78
+ const response = await this.httpClient.call({
81
79
  url: this._url('test'),
82
80
  method: 'POST',
83
81
  params: this._params(),
84
- };
85
- try {
86
- const response = await this.httpClient.call(request);
87
- return (0, utils_1.cast)((0, utils_1.parseDateFields)((0, utils_1.pluckData)(response.data)));
88
- }
89
- catch (err) {
90
- (0, utils_1.catchNotFoundOrThrow)(err);
91
- }
92
- return undefined;
82
+ });
83
+ return parseResponse(response, schemas.WebhookDispatch());
93
84
  }
94
85
  /**
95
86
  * Returns a client for the dispatches of this webhook.
@@ -98,9 +89,8 @@ class WebhookClient extends resource_client_1.ResourceClient {
98
89
  * @see https://docs.apify.com/api/v2/webhook-webhook-dispatches-get
99
90
  */
100
91
  dispatches() {
101
- return new webhook_dispatch_collection_1.WebhookDispatchCollectionClient(this._subResourceOptions({
92
+ return new WebhookDispatchCollectionClient(this._subResourceOptions({
102
93
  resourcePath: 'dispatches',
103
94
  }));
104
95
  }
105
96
  }
106
- exports.WebhookClient = WebhookClient;
@@ -1,7 +1,7 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceCollectionClient } from '../base/resource_collection_client';
3
- import type { PaginatedIterator, PaginationOptions } from '../utils';
4
- import type { Webhook, WebhookUpdateData } from './webhook';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import type { PaginatedIterator, PaginationOptions } from '../utils.js';
4
+ import type { Webhook, WebhookUpdateData } from './webhook.js';
5
5
  /**
6
6
  * Client for managing the collection of Webhooks.
7
7
  *
@@ -1,14 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookCollectionClient = void 0;
4
- const zod_1 = require("zod");
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(),
1
+ import { z } from 'zod';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import * as schemas from '../schemas.js';
4
+ import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
5
+ const listOptionsSchema = z.strictObject({
6
+ ...paginationOptionsShape,
7
+ desc: z.boolean().optional(),
10
8
  });
11
- const webhookCreateSchema = utils_1.anyObjectSchema.optional();
9
+ const webhookCreateSchema = anyObjectSchema.optional();
12
10
  /**
13
11
  * Client for managing the collection of Webhooks.
14
12
  *
@@ -32,7 +30,7 @@ const webhookCreateSchema = utils_1.anyObjectSchema.optional();
32
30
  *
33
31
  * @see https://docs.apify.com/platform/integrations/webhooks
34
32
  */
35
- class WebhookCollectionClient extends resource_collection_client_1.ResourceCollectionClient {
33
+ export class WebhookCollectionClient extends ResourceCollectionClient {
36
34
  /**
37
35
  * @hidden
38
36
  */
@@ -63,8 +61,8 @@ class WebhookCollectionClient extends resource_collection_client_1.ResourceColle
63
61
  * @see https://docs.apify.com/api/v2/webhooks-get
64
62
  */
65
63
  list(options = {}) {
66
- const parsed = (0, utils_1.parseArgument)(options, listOptionsSchema, 'WebhookCollectionListOptions');
67
- return this._listPaginated(parsed);
64
+ const parsed = parseArgument(options, listOptionsSchema, 'WebhookCollectionListOptions');
65
+ return this._listPaginated(schemas.ListOfWebhooks(), parsed);
68
66
  }
69
67
  /**
70
68
  * Creates a new webhook.
@@ -74,8 +72,7 @@ class WebhookCollectionClient extends resource_collection_client_1.ResourceColle
74
72
  * @see https://docs.apify.com/api/v2/webhooks-post
75
73
  */
76
74
  async create(webhook) {
77
- (0, utils_1.parseArgument)(webhook, webhookCreateSchema);
78
- return this._create(webhook);
75
+ parseArgument(webhook, webhookCreateSchema);
76
+ return this._create(schemas.Webhook(), webhook);
79
77
  }
80
78
  }
81
- exports.WebhookCollectionClient = WebhookCollectionClient;
@@ -1,8 +1,8 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceClient } from '../base/resource_client';
3
- import type { WebhookDispatch } from '../models';
4
- export type { WebhookDispatch, WebhookDispatchCall, WebhookDispatchEventData, WebhookDispatchWebhookSummary, } from '../models';
5
- export { WebhookDispatchStatus } from '../models';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceClient } from '../base/resource_client.js';
3
+ import type { WebhookDispatch } from '../models.js';
4
+ export type { WebhookDispatch, WebhookDispatchCall, WebhookDispatchEventData, WebhookDispatchWebhookSummary, } from '../models.js';
5
+ export { WebhookDispatchStatus } from '../models.js';
6
6
  /**
7
7
  * Client for managing a specific webhook dispatch.
8
8
  *
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookDispatchClient = exports.WebhookDispatchStatus = void 0;
4
- const resource_client_1 = require("../base/resource_client");
5
- var models_1 = require("../models");
6
- Object.defineProperty(exports, "WebhookDispatchStatus", { enumerable: true, get: function () { return models_1.WebhookDispatchStatus; } });
1
+ import { ResourceClient } from '../base/resource_client.js';
2
+ import * as schemas from '../schemas.js';
3
+ export { WebhookDispatchStatus } from '../models.js';
7
4
  /**
8
5
  * Client for managing a specific webhook dispatch.
9
6
  *
@@ -22,7 +19,7 @@ Object.defineProperty(exports, "WebhookDispatchStatus", { enumerable: true, get:
22
19
  *
23
20
  * @see https://docs.apify.com/platform/integrations/webhooks
24
21
  */
25
- class WebhookDispatchClient extends resource_client_1.ResourceClient {
22
+ export class WebhookDispatchClient extends ResourceClient {
26
23
  /**
27
24
  * @hidden
28
25
  */
@@ -39,7 +36,6 @@ class WebhookDispatchClient extends resource_client_1.ResourceClient {
39
36
  * @see https://docs.apify.com/api/v2/webhook-dispatch-get
40
37
  */
41
38
  async get() {
42
- return this._get();
39
+ return this._get(schemas.WebhookDispatch());
43
40
  }
44
41
  }
45
- exports.WebhookDispatchClient = WebhookDispatchClient;
@@ -1,7 +1,7 @@
1
- import type { ApiClientSubResourceOptions } from '../base/api_client';
2
- import { ResourceCollectionClient } from '../base/resource_collection_client';
3
- import type { PaginatedIterator, PaginationOptions } from '../utils';
4
- import type { WebhookDispatch } from './webhook_dispatch';
1
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
+ import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
+ import type { PaginatedIterator, PaginationOptions } from '../utils.js';
4
+ import type { WebhookDispatch } from './webhook_dispatch.js';
5
5
  /**
6
6
  * Client for managing the collection of webhook dispatches.
7
7
  *