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.
- package/README.md +7 -3
- package/dist/apify_api_error.d.ts +60 -19
- package/dist/apify_api_error.js +88 -22
- package/dist/apify_client.d.ts +22 -3
- package/dist/apify_client.js +37 -31
- package/dist/base/api_client.d.ts +6 -6
- package/dist/base/api_client.js +24 -16
- package/dist/base/resource_client.d.ts +23 -9
- package/dist/base/resource_client.js +49 -25
- package/dist/base/resource_collection_client.d.ts +7 -4
- package/dist/base/resource_collection_client.js +21 -15
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +17 -24
- package/dist/bundle.js +38 -48
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/http_client.d.ts +18 -51
- package/dist/http_client.js +90 -85
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/interceptors.js +24 -6
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +32 -52
- package/dist/resource_clients/actor.d.ts +46 -31
- package/dist/resource_clients/actor.js +71 -53
- package/dist/resource_clients/actor_collection.d.ts +9 -5
- package/dist/resource_clients/actor_collection.js +12 -3
- package/dist/resource_clients/actor_env_var.d.ts +10 -3
- package/dist/resource_clients/actor_env_var.js +17 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +14 -18
- package/dist/resource_clients/actor_env_var_collection.js +18 -11
- package/dist/resource_clients/actor_version.d.ts +18 -3
- package/dist/resource_clients/actor_version.js +20 -9
- package/dist/resource_clients/actor_version_collection.d.ts +16 -17
- package/dist/resource_clients/actor_version_collection.js +20 -11
- package/dist/resource_clients/build.d.ts +18 -6
- package/dist/resource_clients/build.js +35 -17
- package/dist/resource_clients/build_collection.d.ts +3 -1
- package/dist/resource_clients/build_collection.js +5 -1
- package/dist/resource_clients/dataset.d.ts +23 -9
- package/dist/resource_clients/dataset.js +70 -48
- package/dist/resource_clients/dataset_collection.d.ts +6 -2
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +48 -15
- package/dist/resource_clients/key_value_store.js +71 -40
- package/dist/resource_clients/key_value_store_collection.d.ts +6 -2
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +9 -19
- package/dist/resource_clients/log.js +57 -45
- package/dist/resource_clients/request_queue.d.ts +56 -26
- package/dist/resource_clients/request_queue.js +178 -113
- package/dist/resource_clients/request_queue_collection.d.ts +6 -2
- package/dist/resource_clients/request_queue_collection.js +10 -3
- package/dist/resource_clients/run.d.ts +51 -17
- package/dist/resource_clients/run.js +85 -44
- package/dist/resource_clients/run_collection.d.ts +3 -1
- package/dist/resource_clients/run_collection.js +5 -1
- package/dist/resource_clients/schedule.d.ts +16 -7
- package/dist/resource_clients/schedule.js +31 -21
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +10 -3
- package/dist/resource_clients/store_collection.d.ts +3 -1
- package/dist/resource_clients/store_collection.js +5 -1
- package/dist/resource_clients/task.d.ts +28 -10
- package/dist/resource_clients/task.js +67 -44
- package/dist/resource_clients/task_collection.d.ts +6 -2
- package/dist/resource_clients/task_collection.js +10 -3
- package/dist/resource_clients/user.d.ts +17 -8
- package/dist/resource_clients/user.js +40 -39
- package/dist/resource_clients/webhook.d.ts +14 -5
- package/dist/resource_clients/webhook.js +30 -22
- package/dist/resource_clients/webhook_collection.d.ts +6 -2
- package/dist/resource_clients/webhook_collection.js +10 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +8 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +5 -1
- package/dist/response_validation_error.d.ts +26 -0
- package/dist/response_validation_error.js +37 -0
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +58 -0
- package/dist/runtime/types.d.ts +50 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +17 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.js +15 -0
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +72 -0
- package/dist/timeouts.js +31 -0
- package/dist/utils.d.ts +75 -55
- package/dist/utils.js +201 -180
- package/package.json +42 -35
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -153
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
-
import
|
|
2
|
+
import * as schemas from '../schemas.js';
|
|
3
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
4
|
+
import { parseArgument, parseResponse } from '../utils.js';
|
|
3
5
|
export { PlatformFeature } from '../models.js';
|
|
4
6
|
/**
|
|
5
7
|
* Client for managing user account information.
|
|
@@ -41,71 +43,70 @@ export class UserClient extends ResourceClient {
|
|
|
41
43
|
* Depending on whether ApifyClient was created with a token,
|
|
42
44
|
* the method will either return public or private user data.
|
|
43
45
|
*
|
|
44
|
-
* @
|
|
46
|
+
* @param options - Request options
|
|
47
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
48
|
+
* @returns The user object, or `undefined` if it does not exist.
|
|
45
49
|
* @see https://docs.apify.com/api/v2/user-get
|
|
46
50
|
*/
|
|
47
|
-
async get() {
|
|
48
|
-
|
|
51
|
+
async get(options = {}) {
|
|
52
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
53
|
+
return this.getResource(schemas.UserPrivateInfo(), {}, timeoutSecs);
|
|
49
54
|
}
|
|
50
55
|
/**
|
|
51
56
|
* Retrieves the user's monthly usage data.
|
|
52
57
|
*
|
|
53
|
-
* @
|
|
58
|
+
* @param options - Request options
|
|
59
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
60
|
+
* @returns The monthly usage object.
|
|
54
61
|
* @see https://docs.apify.com/api/v2/users-me-usage-monthly-get
|
|
55
62
|
* @since Added in 2.9.2
|
|
56
63
|
*/
|
|
57
|
-
async monthlyUsage() {
|
|
58
|
-
const
|
|
59
|
-
|
|
64
|
+
async monthlyUsage(options = {}) {
|
|
65
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
66
|
+
const response = await this.httpClient.call({
|
|
67
|
+
url: this.buildUrl('usage/monthly'),
|
|
60
68
|
method: 'GET',
|
|
61
|
-
params: this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return cast(parseDateFields(pluckData(response.data),
|
|
66
|
-
// Convert monthlyUsage.dailyServiceUsages[].date to Date (by default it's ignored by parseDateFields)
|
|
67
|
-
/* shouldParseField = */ (key) => key === 'date'));
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
catchNotFoundOrThrow(err);
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
69
|
+
params: this.buildParams(),
|
|
70
|
+
timeoutSecs,
|
|
71
|
+
});
|
|
72
|
+
return parseResponse(response, schemas.MonthlyUsage());
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Retrieves the user's account and usage limits.
|
|
76
76
|
*
|
|
77
|
-
* @
|
|
77
|
+
* @param options - Request options
|
|
78
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
79
|
+
* @returns The account and usage limits object.
|
|
78
80
|
* @see https://docs.apify.com/api/v2/users-me-limits-get
|
|
79
81
|
* @since Added in 2.9.2
|
|
80
82
|
*/
|
|
81
|
-
async limits() {
|
|
82
|
-
const
|
|
83
|
-
|
|
83
|
+
async limits(options = {}) {
|
|
84
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
85
|
+
const response = await this.httpClient.call({
|
|
86
|
+
url: this.buildUrl('limits'),
|
|
84
87
|
method: 'GET',
|
|
85
|
-
params: this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return cast(parseDateFields(pluckData(response.data)));
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
catchNotFoundOrThrow(err);
|
|
93
|
-
}
|
|
94
|
-
return undefined;
|
|
88
|
+
params: this.buildParams(),
|
|
89
|
+
timeoutSecs,
|
|
90
|
+
});
|
|
91
|
+
return parseResponse(response, schemas.AccountLimits());
|
|
95
92
|
}
|
|
96
93
|
/**
|
|
97
94
|
* Updates the user's account and usage limits.
|
|
98
95
|
*
|
|
99
|
-
* @param
|
|
96
|
+
* @param newLimits - The new limits to set.
|
|
97
|
+
* @param options - Request options
|
|
98
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
100
99
|
* @see https://docs.apify.com/api/v2/users-me-limits-put
|
|
101
100
|
* @since Added in 2.10.0
|
|
102
101
|
*/
|
|
103
|
-
async updateLimits(options) {
|
|
102
|
+
async updateLimits(newLimits, options = {}) {
|
|
103
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
104
104
|
const requestOpts = {
|
|
105
|
-
url: this.
|
|
105
|
+
url: this.buildUrl('limits'),
|
|
106
106
|
method: 'PUT',
|
|
107
|
-
params: this.
|
|
108
|
-
data:
|
|
107
|
+
params: this.buildParams(),
|
|
108
|
+
data: newLimits,
|
|
109
|
+
timeoutSecs,
|
|
109
110
|
};
|
|
110
111
|
await this.httpClient.call(requestOpts);
|
|
111
112
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
3
3
|
import type { Webhook, WebhookEventType } from '../models.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
import type { WebhookDispatch } from './webhook_dispatch.js';
|
|
5
6
|
import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
|
|
6
7
|
export type { Webhook, WebhookAnyRunOfActorCondition, WebhookAnyRunOfActorTaskCondition, WebhookCertainRunCondition, WebhookCondition, WebhookEventType, WebhookLastDispatch, WebhookStats, } from '../models.js';
|
|
@@ -40,31 +41,39 @@ export declare class WebhookClient extends ResourceClient {
|
|
|
40
41
|
/**
|
|
41
42
|
* Retrieves the webhook.
|
|
42
43
|
*
|
|
44
|
+
* @param options - Request options
|
|
45
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
43
46
|
* @returns The webhook object, or `undefined` if it does not exist.
|
|
44
47
|
* @see https://docs.apify.com/api/v2/webhook-get
|
|
45
48
|
*/
|
|
46
|
-
get(): Promise<Webhook | undefined>;
|
|
49
|
+
get(options?: TimeoutOptions): Promise<Webhook | undefined>;
|
|
47
50
|
/**
|
|
48
51
|
* Updates the webhook with the specified fields.
|
|
49
52
|
*
|
|
50
53
|
* @param newFields - Fields to update.
|
|
54
|
+
* @param options - Request options
|
|
55
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
51
56
|
* @returns The updated webhook object.
|
|
52
57
|
* @see https://docs.apify.com/api/v2/webhook-put
|
|
53
58
|
*/
|
|
54
|
-
update(newFields: WebhookUpdateData): Promise<Webhook>;
|
|
59
|
+
update(newFields: WebhookUpdateData, options?: TimeoutOptions): Promise<Webhook>;
|
|
55
60
|
/**
|
|
56
61
|
* Deletes the webhook.
|
|
57
62
|
*
|
|
63
|
+
* @param options - Request options
|
|
64
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
58
65
|
* @see https://docs.apify.com/api/v2/webhook-delete
|
|
59
66
|
*/
|
|
60
|
-
delete(): Promise<void>;
|
|
67
|
+
delete(options?: TimeoutOptions): Promise<void>;
|
|
61
68
|
/**
|
|
62
69
|
* Tests the webhook by dispatching a test event.
|
|
63
70
|
*
|
|
64
|
-
* @
|
|
71
|
+
* @param options - Request options
|
|
72
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
73
|
+
* @returns The webhook dispatch object.
|
|
65
74
|
* @see https://docs.apify.com/api/v2/webhook-test-post
|
|
66
75
|
*/
|
|
67
|
-
test(): Promise<WebhookDispatch
|
|
76
|
+
test(options?: TimeoutOptions): Promise<WebhookDispatch>;
|
|
68
77
|
/**
|
|
69
78
|
* Returns a client for the dispatches of this webhook.
|
|
70
79
|
*
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
-
import
|
|
2
|
+
import * as schemas from '../schemas.js';
|
|
3
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
4
|
+
import { anyObjectSchema, parseArgument, parseResponse } from '../utils.js';
|
|
3
5
|
import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
|
|
4
6
|
/**
|
|
5
7
|
* Client for managing a specific webhook.
|
|
@@ -42,51 +44,57 @@ export class WebhookClient extends ResourceClient {
|
|
|
42
44
|
/**
|
|
43
45
|
* Retrieves the webhook.
|
|
44
46
|
*
|
|
47
|
+
* @param options - Request options
|
|
48
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
45
49
|
* @returns The webhook object, or `undefined` if it does not exist.
|
|
46
50
|
* @see https://docs.apify.com/api/v2/webhook-get
|
|
47
51
|
*/
|
|
48
|
-
async get() {
|
|
49
|
-
|
|
52
|
+
async get(options = {}) {
|
|
53
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
54
|
+
return this.getResource(schemas.Webhook(), {}, timeoutSecs);
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
52
57
|
* Updates the webhook with the specified fields.
|
|
53
58
|
*
|
|
54
59
|
* @param newFields - Fields to update.
|
|
60
|
+
* @param options - Request options
|
|
61
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
55
62
|
* @returns The updated webhook object.
|
|
56
63
|
* @see https://docs.apify.com/api/v2/webhook-put
|
|
57
64
|
*/
|
|
58
|
-
async update(newFields) {
|
|
65
|
+
async update(newFields, options = {}) {
|
|
59
66
|
parseArgument(newFields, anyObjectSchema);
|
|
60
|
-
|
|
67
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
68
|
+
return this.updateResource(schemas.Webhook(), newFields, timeoutSecs);
|
|
61
69
|
}
|
|
62
70
|
/**
|
|
63
71
|
* Deletes the webhook.
|
|
64
72
|
*
|
|
73
|
+
* @param options - Request options
|
|
74
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
65
75
|
* @see https://docs.apify.com/api/v2/webhook-delete
|
|
66
76
|
*/
|
|
67
|
-
async delete() {
|
|
68
|
-
|
|
77
|
+
async delete(options = {}) {
|
|
78
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
79
|
+
return this.deleteResource(timeoutSecs);
|
|
69
80
|
}
|
|
70
81
|
/**
|
|
71
82
|
* Tests the webhook by dispatching a test event.
|
|
72
83
|
*
|
|
73
|
-
* @
|
|
84
|
+
* @param options - Request options
|
|
85
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
86
|
+
* @returns The webhook dispatch object.
|
|
74
87
|
* @see https://docs.apify.com/api/v2/webhook-test-post
|
|
75
88
|
*/
|
|
76
|
-
async test() {
|
|
77
|
-
const
|
|
78
|
-
|
|
89
|
+
async test(options = {}) {
|
|
90
|
+
const { timeoutSecs = 'medium' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
91
|
+
const response = await this.httpClient.call({
|
|
92
|
+
url: this.buildUrl('test'),
|
|
79
93
|
method: 'POST',
|
|
80
|
-
params: this.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return cast(parseDateFields(pluckData(response.data)));
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
catchNotFoundOrThrow(err);
|
|
88
|
-
}
|
|
89
|
-
return undefined;
|
|
94
|
+
params: this.buildParams(),
|
|
95
|
+
timeoutSecs,
|
|
96
|
+
});
|
|
97
|
+
return parseResponse(response, schemas.WebhookDispatch());
|
|
90
98
|
}
|
|
91
99
|
/**
|
|
92
100
|
* Returns a client for the dispatches of this webhook.
|
|
@@ -95,7 +103,7 @@ export class WebhookClient extends ResourceClient {
|
|
|
95
103
|
* @see https://docs.apify.com/api/v2/webhook-webhook-dispatches-get
|
|
96
104
|
*/
|
|
97
105
|
dispatches() {
|
|
98
|
-
return new WebhookDispatchCollectionClient(this.
|
|
106
|
+
return new WebhookDispatchCollectionClient(this.subResourceOptions({
|
|
99
107
|
resourcePath: 'dispatches',
|
|
100
108
|
}));
|
|
101
109
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
3
4
|
import type { PaginatedIterator, PaginationOptions } from '../utils.js';
|
|
4
5
|
import type { Webhook, WebhookUpdateData } from './webhook.js';
|
|
5
6
|
/**
|
|
@@ -47,6 +48,7 @@ export declare class WebhookCollectionClient extends ResourceCollectionClient {
|
|
|
47
48
|
* ```
|
|
48
49
|
*
|
|
49
50
|
* @param options - Pagination and sorting options.
|
|
51
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
50
52
|
* @returns A paginated iterator of webhooks.
|
|
51
53
|
* @see https://docs.apify.com/api/v2/webhooks-get
|
|
52
54
|
*/
|
|
@@ -55,11 +57,13 @@ export declare class WebhookCollectionClient extends ResourceCollectionClient {
|
|
|
55
57
|
* Creates a new webhook.
|
|
56
58
|
*
|
|
57
59
|
* @param webhook - The webhook data.
|
|
60
|
+
* @param options - Request options
|
|
61
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
58
62
|
* @returns The created webhook object.
|
|
59
63
|
* @see https://docs.apify.com/api/v2/webhooks-post
|
|
60
64
|
*/
|
|
61
|
-
create(webhook?: WebhookUpdateData): Promise<Webhook>;
|
|
65
|
+
create(webhook?: WebhookUpdateData, options?: TimeoutOptions): Promise<Webhook>;
|
|
62
66
|
}
|
|
63
|
-
export interface WebhookCollectionListOptions extends PaginationOptions {
|
|
67
|
+
export interface WebhookCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
64
68
|
desc?: boolean;
|
|
65
69
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
3
5
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
6
|
const listOptionsSchema = z.strictObject({
|
|
5
7
|
...paginationOptionsShape,
|
|
6
8
|
desc: z.boolean().optional(),
|
|
9
|
+
...timeoutOptionsShape,
|
|
7
10
|
});
|
|
8
11
|
const webhookCreateSchema = anyObjectSchema.optional();
|
|
9
12
|
/**
|
|
@@ -56,22 +59,26 @@ export class WebhookCollectionClient extends ResourceCollectionClient {
|
|
|
56
59
|
* ```
|
|
57
60
|
*
|
|
58
61
|
* @param options - Pagination and sorting options.
|
|
62
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
59
63
|
* @returns A paginated iterator of webhooks.
|
|
60
64
|
* @see https://docs.apify.com/api/v2/webhooks-get
|
|
61
65
|
*/
|
|
62
66
|
list(options = {}) {
|
|
63
67
|
const parsed = parseArgument(options, listOptionsSchema, 'WebhookCollectionListOptions');
|
|
64
|
-
return this.
|
|
68
|
+
return this.listResourcesPaginated(schemas.ListOfWebhooks(), parsed, 'medium');
|
|
65
69
|
}
|
|
66
70
|
/**
|
|
67
71
|
* Creates a new webhook.
|
|
68
72
|
*
|
|
69
73
|
* @param webhook - The webhook data.
|
|
74
|
+
* @param options - Request options
|
|
75
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
70
76
|
* @returns The created webhook object.
|
|
71
77
|
* @see https://docs.apify.com/api/v2/webhooks-post
|
|
72
78
|
*/
|
|
73
|
-
async create(webhook) {
|
|
79
|
+
async create(webhook, options = {}) {
|
|
74
80
|
parseArgument(webhook, webhookCreateSchema);
|
|
75
|
-
|
|
81
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
82
|
+
return this.createResource(schemas.Webhook(), webhook, timeoutSecs);
|
|
76
83
|
}
|
|
77
84
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
3
3
|
import type { WebhookDispatch } from '../models.js';
|
|
4
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
4
5
|
export type { WebhookDispatch, WebhookDispatchCall, WebhookDispatchEventData, WebhookDispatchWebhookSummary, } from '../models.js';
|
|
5
6
|
export { WebhookDispatchStatus } from '../models.js';
|
|
6
7
|
/**
|
|
@@ -29,8 +30,10 @@ export declare class WebhookDispatchClient extends ResourceClient {
|
|
|
29
30
|
/**
|
|
30
31
|
* Retrieves the webhook dispatch.
|
|
31
32
|
*
|
|
33
|
+
* @param options - Request options
|
|
34
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
32
35
|
* @returns The webhook dispatch object, or `undefined` if it does not exist.
|
|
33
36
|
* @see https://docs.apify.com/api/v2/webhook-dispatch-get
|
|
34
37
|
*/
|
|
35
|
-
get(): Promise<WebhookDispatch | undefined>;
|
|
38
|
+
get(options?: TimeoutOptions): Promise<WebhookDispatch | undefined>;
|
|
36
39
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
|
+
import * as schemas from '../schemas.js';
|
|
3
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
4
|
+
import { parseArgument } from '../utils.js';
|
|
2
5
|
export { WebhookDispatchStatus } from '../models.js';
|
|
3
6
|
/**
|
|
4
7
|
* Client for managing a specific webhook dispatch.
|
|
@@ -31,10 +34,13 @@ export class WebhookDispatchClient extends ResourceClient {
|
|
|
31
34
|
/**
|
|
32
35
|
* Retrieves the webhook dispatch.
|
|
33
36
|
*
|
|
37
|
+
* @param options - Request options
|
|
38
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
34
39
|
* @returns The webhook dispatch object, or `undefined` if it does not exist.
|
|
35
40
|
* @see https://docs.apify.com/api/v2/webhook-dispatch-get
|
|
36
41
|
*/
|
|
37
|
-
async get() {
|
|
38
|
-
|
|
42
|
+
async get(options = {}) {
|
|
43
|
+
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
44
|
+
return this.getResource(schemas.WebhookDispatch(), {}, timeoutSecs);
|
|
39
45
|
}
|
|
40
46
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import type { TimeoutOptions } from '../timeouts.js';
|
|
3
4
|
import type { PaginatedIterator, PaginationOptions } from '../utils.js';
|
|
4
5
|
import type { WebhookDispatch } from './webhook_dispatch.js';
|
|
5
6
|
/**
|
|
@@ -42,11 +43,12 @@ export declare class WebhookDispatchCollectionClient extends ResourceCollectionC
|
|
|
42
43
|
* ```
|
|
43
44
|
*
|
|
44
45
|
* @param options - Pagination and sorting options.
|
|
46
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
45
47
|
* @returns A paginated iterator of webhook dispatches.
|
|
46
48
|
* @see https://docs.apify.com/api/v2/webhook-dispatches-get
|
|
47
49
|
*/
|
|
48
50
|
list(options?: WebhookDispatchCollectionListOptions): PaginatedIterator<WebhookDispatch>;
|
|
49
51
|
}
|
|
50
|
-
export interface WebhookDispatchCollectionListOptions extends PaginationOptions {
|
|
52
|
+
export interface WebhookDispatchCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
51
53
|
desc?: boolean;
|
|
52
54
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
|
+
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsShape } from '../timeouts.js';
|
|
3
5
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
4
6
|
const listOptionsSchema = z.strictObject({
|
|
5
7
|
...paginationOptionsShape,
|
|
6
8
|
desc: z.boolean().optional(),
|
|
9
|
+
...timeoutOptionsShape,
|
|
7
10
|
});
|
|
8
11
|
/**
|
|
9
12
|
* Client for managing the collection of webhook dispatches.
|
|
@@ -50,11 +53,12 @@ export class WebhookDispatchCollectionClient extends ResourceCollectionClient {
|
|
|
50
53
|
* ```
|
|
51
54
|
*
|
|
52
55
|
* @param options - Pagination and sorting options.
|
|
56
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
53
57
|
* @returns A paginated iterator of webhook dispatches.
|
|
54
58
|
* @see https://docs.apify.com/api/v2/webhook-dispatches-get
|
|
55
59
|
*/
|
|
56
60
|
list(options = {}) {
|
|
57
61
|
const parsed = parseArgument(options, listOptionsSchema, 'WebhookDispatchCollectionListOptions');
|
|
58
|
-
return this.
|
|
62
|
+
return this.listResourcesPaginated(schemas.ListOfWebhookDispatches(), parsed, 'medium');
|
|
59
63
|
}
|
|
60
64
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when an API response does not match the schema the client expects for it.
|
|
4
|
+
*
|
|
5
|
+
* The schemas are generated from the Apify OpenAPI specification, so this error means the API returned
|
|
6
|
+
* something the specification does not describe -- a missing required field, a different type, a value
|
|
7
|
+
* outside the documented range. Unknown fields and unknown enum values are not errors: the schemas let
|
|
8
|
+
* both through, so the client keeps working when the API grows.
|
|
9
|
+
*
|
|
10
|
+
* The `message` names the request and every offending field with the value it received, and ends by asking for
|
|
11
|
+
* a bug report: the mismatch is in the API or its specification, not in the caller's code. The structured
|
|
12
|
+
* {@link https://zod.dev | zod} issues are available on `issues`, and the original `ZodError` on `cause`,
|
|
13
|
+
* for programmatic inspection.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ResponseValidationError extends Error {
|
|
16
|
+
/** Structured issues from the underlying schema check. */
|
|
17
|
+
readonly issues: z.ZodError['issues'];
|
|
18
|
+
/** HTTP method of the request whose response failed validation, upper-cased. */
|
|
19
|
+
readonly method: string;
|
|
20
|
+
/** URL of the request whose response failed validation, without its query string. */
|
|
21
|
+
readonly url: string;
|
|
22
|
+
constructor(error: z.ZodError, value: unknown, request: {
|
|
23
|
+
method: string;
|
|
24
|
+
url: string;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ArgumentValidationError } from '@apify/validations';
|
|
2
|
+
const REPORT_HINT = 'The API returned something its OpenAPI specification does not describe. ' +
|
|
3
|
+
'Please report this at https://github.com/apify/apify-client-js/issues.';
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when an API response does not match the schema the client expects for it.
|
|
6
|
+
*
|
|
7
|
+
* The schemas are generated from the Apify OpenAPI specification, so this error means the API returned
|
|
8
|
+
* something the specification does not describe -- a missing required field, a different type, a value
|
|
9
|
+
* outside the documented range. Unknown fields and unknown enum values are not errors: the schemas let
|
|
10
|
+
* both through, so the client keeps working when the API grows.
|
|
11
|
+
*
|
|
12
|
+
* The `message` names the request and every offending field with the value it received, and ends by asking for
|
|
13
|
+
* a bug report: the mismatch is in the API or its specification, not in the caller's code. The structured
|
|
14
|
+
* {@link https://zod.dev | zod} issues are available on `issues`, and the original `ZodError` on `cause`,
|
|
15
|
+
* for programmatic inspection.
|
|
16
|
+
*/
|
|
17
|
+
export class ResponseValidationError extends Error {
|
|
18
|
+
/** Structured issues from the underlying schema check. */
|
|
19
|
+
issues;
|
|
20
|
+
/** HTTP method of the request whose response failed validation, upper-cased. */
|
|
21
|
+
method;
|
|
22
|
+
/** URL of the request whose response failed validation, without its query string. */
|
|
23
|
+
url;
|
|
24
|
+
constructor(error, value, request) {
|
|
25
|
+
const method = request.method.toUpperCase();
|
|
26
|
+
// `@apify/validations` keeps its zod error formatter private, so the issue lines come from the
|
|
27
|
+
// message of the error class it does export.
|
|
28
|
+
const details = new ArgumentValidationError(error, value).message;
|
|
29
|
+
super(`Response from ${method} ${request.url} does not match the API schema:\n${details}\n${REPORT_HINT}`, {
|
|
30
|
+
cause: error,
|
|
31
|
+
});
|
|
32
|
+
this.name = 'ResponseValidationError';
|
|
33
|
+
this.issues = error.issues;
|
|
34
|
+
this.method = method;
|
|
35
|
+
this.url = request.url;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { brotliCompress, constants, gzip } from 'node:zlib';
|
|
4
|
+
/**
|
|
5
|
+
* The Node.js implementation of {@link Runtime}. Deno and Bun resolve the `node` condition too and
|
|
6
|
+
* provide the built-ins it uses.
|
|
7
|
+
*/
|
|
8
|
+
export const runtime = {
|
|
9
|
+
isNode: true,
|
|
10
|
+
platform: `${os.platform()}; Node/${process.version}`,
|
|
11
|
+
async compress(data) {
|
|
12
|
+
try {
|
|
13
|
+
// `promisify()` belongs inside the fallback chain: a partial `node:zlib` can export
|
|
14
|
+
// `brotliCompress` without implementing it, and `promisify(undefined)` throws. At module scope
|
|
15
|
+
// that would fail the whole import instead of falling through to gzip.
|
|
16
|
+
const options = { params: { [constants.BROTLI_PARAM_QUALITY]: 6 } };
|
|
17
|
+
return { data: await promisify(brotliCompress)(data, options), encoding: 'br' };
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// Runtimes that only provide a partial `node:zlib` (Node.js compatibility shims) may not implement
|
|
21
|
+
// brotli, but usually do implement gzip.
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
return { data: await promisify(gzip)(data), encoding: 'gzip' };
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
async createHttpAgents({ timeoutMillis }) {
|
|
31
|
+
// Loaded on the first request rather than with the client: the proxy support pulls in a sizeable
|
|
32
|
+
// dependency tree that a client which never sends a request should not pay for.
|
|
33
|
+
const { ProxyAgent } = await import('proxy-agent');
|
|
34
|
+
// We want to keep sockets alive for better performance.
|
|
35
|
+
const agentOptions = {
|
|
36
|
+
keepAlive: true,
|
|
37
|
+
// Timeout for inactive sockets
|
|
38
|
+
// Prevents socket leaks from idle connections
|
|
39
|
+
timeout: timeoutMillis,
|
|
40
|
+
// Keep alive timeout for free sockets (15 seconds)
|
|
41
|
+
// Node.js will close unused sockets after this period
|
|
42
|
+
keepAliveMsecs: 15_000,
|
|
43
|
+
// Maximum number of sockets per host
|
|
44
|
+
maxSockets: 256,
|
|
45
|
+
maxFreeSockets: 256,
|
|
46
|
+
// LIFO scheduling - reuse most recently used sockets for better performance
|
|
47
|
+
scheduling: 'lifo',
|
|
48
|
+
};
|
|
49
|
+
// ProxyAgent picks the proxy up from the environment variables and supports CONNECT tunneling.
|
|
50
|
+
const agent = new ProxyAgent(agentOptions);
|
|
51
|
+
// Disable Nagle's algorithm for lower latency
|
|
52
|
+
// This sends data immediately instead of buffering small packets
|
|
53
|
+
agent.on('socket', (socket) => {
|
|
54
|
+
socket.setNoDelay(true);
|
|
55
|
+
});
|
|
56
|
+
return { httpAgent: agent, httpsAgent: agent };
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type http from 'node:http';
|
|
2
|
+
import type https from 'node:https';
|
|
3
|
+
/**
|
|
4
|
+
* A request body compressed for transport, with the `content-encoding` value that declares it.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface CompressedValue {
|
|
8
|
+
data: Uint8Array;
|
|
9
|
+
encoding: 'br' | 'gzip';
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The agents axios's Node.js adapter sends requests through.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export interface HttpAgents {
|
|
16
|
+
httpAgent: http.Agent;
|
|
17
|
+
httpsAgent: https.Agent;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The runtime-specific part of the client. `#runtime` resolves to the Node.js implementation under the `node`
|
|
21
|
+
* condition and to the Web API one everywhere else (see the `imports` field of `package.json`), so a bundler
|
|
22
|
+
* targeting a browser or an edge runtime never sees the Node.js built-ins the Node.js one uses.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export interface Runtime {
|
|
26
|
+
/**
|
|
27
|
+
* Whether the Node.js implementation was selected, which the `node` condition settles when `#runtime` is
|
|
28
|
+
* resolved - so a Node.js application bundled for a browser or a neutral target reports `false`. The
|
|
29
|
+
* features that need a Node.js `Readable` response - log streaming and the `stream` record option - are
|
|
30
|
+
* gated on it.
|
|
31
|
+
*/
|
|
32
|
+
isNode: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The platform part of the `User-Agent` header, or `undefined` where the runtime does not let a client
|
|
35
|
+
* set that header (browsers).
|
|
36
|
+
*/
|
|
37
|
+
platform: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Compresses a request body, or resolves to `undefined` where compression is not available. Compression
|
|
40
|
+
* is a best-effort optimization, so it never throws.
|
|
41
|
+
*/
|
|
42
|
+
compress(data: Uint8Array): Promise<CompressedValue | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Creates the agents axios's Node.js adapter sends requests through, or resolves to `undefined` where
|
|
45
|
+
* axios does not use agents.
|
|
46
|
+
*/
|
|
47
|
+
createHttpAgents(options: {
|
|
48
|
+
timeoutMillis: number;
|
|
49
|
+
}): Promise<HttpAgents | undefined>;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The {@link Runtime} for browsers and edge runtimes, built on Web APIs only.
|
|
3
|
+
*/
|
|
4
|
+
export const runtime = {
|
|
5
|
+
isNode: false,
|
|
6
|
+
// Browsers do not let a page set the `User-Agent` header.
|
|
7
|
+
platform: undefined,
|
|
8
|
+
// No request compression: brotli has no Web API, and a `content-encoding` request header is not on the
|
|
9
|
+
// list of headers the Apify API allows in a cross-origin request, so a browser would fail the preflight.
|
|
10
|
+
async compress() {
|
|
11
|
+
return undefined;
|
|
12
|
+
},
|
|
13
|
+
// The XHR and fetch adapters of axios do not use agents.
|
|
14
|
+
async createHttpAgents() {
|
|
15
|
+
return undefined;
|
|
16
|
+
},
|
|
17
|
+
};
|