apify-client 3.0.0-beta.8 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/apify_api_error.d.ts +11 -26
- package/dist/apify_api_error.js +31 -22
- package/dist/apify_client.d.ts +125 -10
- package/dist/apify_client.js +133 -48
- package/dist/base/api_client.d.ts +7 -7
- package/dist/base/api_client.js +36 -24
- package/dist/base/resource_client.d.ts +21 -8
- package/dist/base/resource_client.js +67 -33
- package/dist/base/resource_collection_client.d.ts +12 -4
- package/dist/base/resource_collection_client.js +34 -11
- package/dist/body_parser.d.ts +3 -4
- package/dist/body_parser.js +19 -26
- package/dist/bundle.js +27 -22
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +785 -290
- package/dist/generated/schemas.d.ts +720 -747
- package/dist/generated/schemas.js +166 -162
- package/dist/http_clients/axios.d.ts +60 -0
- package/dist/http_clients/axios.js +117 -0
- package/dist/http_clients/base.d.ts +331 -0
- package/dist/http_clients/base.js +563 -0
- package/dist/http_clients/index.d.ts +4 -0
- package/dist/http_clients/index.js +2 -0
- package/dist/http_compressors/base.d.ts +40 -0
- package/dist/http_compressors/base.js +9 -0
- package/dist/http_compressors/brotli.d.ts +33 -0
- package/dist/http_compressors/brotli.js +39 -0
- package/dist/http_compressors/gzip.d.ts +33 -0
- package/dist/http_compressors/gzip.js +39 -0
- package/dist/http_compressors/index.d.ts +6 -0
- package/dist/http_compressors/index.js +2 -0
- package/dist/http_compressors/resolve.d.ts +23 -0
- package/dist/http_compressors/resolve.js +27 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/invalid_response_body_error.d.ts +13 -0
- package/dist/invalid_response_body_error.js +17 -0
- package/dist/models.d.ts +162 -194
- package/dist/models.js +6 -4
- package/dist/resource_clients/actor.d.ts +74 -34
- package/dist/resource_clients/actor.js +87 -56
- package/dist/resource_clients/actor_collection.d.ts +18 -12
- package/dist/resource_clients/actor_collection.js +11 -3
- package/dist/resource_clients/actor_env_var.d.ts +11 -4
- package/dist/resource_clients/actor_env_var.js +16 -6
- package/dist/resource_clients/actor_env_var_collection.d.ts +9 -4
- package/dist/resource_clients/actor_env_var_collection.js +11 -4
- package/dist/resource_clients/actor_version.d.ts +20 -5
- package/dist/resource_clients/actor_version.js +19 -9
- package/dist/resource_clients/actor_version_collection.d.ts +11 -4
- package/dist/resource_clients/actor_version_collection.js +13 -4
- package/dist/resource_clients/build.d.ts +20 -7
- package/dist/resource_clients/build.js +35 -15
- package/dist/resource_clients/build_collection.d.ts +7 -5
- package/dist/resource_clients/build_collection.js +4 -1
- package/dist/resource_clients/dataset.d.ts +53 -35
- package/dist/resource_clients/dataset.js +105 -80
- package/dist/resource_clients/dataset_collection.d.ts +10 -6
- package/dist/resource_clients/dataset_collection.js +13 -2
- package/dist/resource_clients/key_value_store.d.ts +62 -20
- package/dist/resource_clients/key_value_store.js +78 -40
- package/dist/resource_clients/key_value_store_collection.d.ts +10 -6
- package/dist/resource_clients/key_value_store_collection.js +13 -2
- package/dist/resource_clients/log.d.ts +13 -20
- package/dist/resource_clients/log.js +141 -59
- package/dist/resource_clients/request_queue.d.ts +68 -31
- package/dist/resource_clients/request_queue.js +173 -91
- package/dist/resource_clients/request_queue_collection.d.ts +9 -5
- package/dist/resource_clients/request_queue_collection.js +9 -3
- package/dist/resource_clients/run.d.ts +119 -28
- package/dist/resource_clients/run.js +190 -49
- package/dist/resource_clients/run_collection.d.ts +5 -3
- package/dist/resource_clients/run_collection.js +4 -1
- package/dist/resource_clients/schedule.d.ts +16 -7
- package/dist/resource_clients/schedule.js +30 -22
- package/dist/resource_clients/schedule_collection.d.ts +6 -2
- package/dist/resource_clients/schedule_collection.js +9 -3
- package/dist/resource_clients/store_collection.d.ts +6 -4
- package/dist/resource_clients/store_collection.js +4 -1
- package/dist/resource_clients/task.d.ts +36 -13
- package/dist/resource_clients/task.js +79 -46
- package/dist/resource_clients/task_collection.d.ts +9 -5
- package/dist/resource_clients/task_collection.js +9 -3
- package/dist/resource_clients/user.d.ts +19 -10
- package/dist/resource_clients/user.js +42 -38
- package/dist/resource_clients/webhook.d.ts +17 -8
- package/dist/resource_clients/webhook.js +30 -22
- package/dist/resource_clients/webhook_collection.d.ts +8 -4
- package/dist/resource_clients/webhook_collection.js +9 -3
- package/dist/resource_clients/webhook_dispatch.d.ts +4 -1
- package/dist/resource_clients/webhook_dispatch.js +7 -2
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +3 -1
- package/dist/resource_clients/webhook_dispatch_collection.js +4 -1
- package/dist/runtime/node.d.ts +6 -0
- package/dist/runtime/node.js +49 -0
- package/dist/runtime/types.d.ts +52 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/web.d.ts +5 -0
- package/dist/runtime/web.js +18 -0
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +1 -1
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/timeouts.d.ts +84 -0
- package/dist/timeouts.js +37 -0
- package/dist/timezones.d.ts +1 -1
- package/dist/utils.d.ts +82 -45
- package/dist/utils.js +197 -146
- package/dist/wait_for_resources.d.ts +8 -0
- package/dist/wait_for_resources.js +39 -0
- package/package.json +32 -29
- package/dist/http_client.d.ts +0 -88
- package/dist/http_client.js +0 -255
- package/dist/interceptors.d.ts +0 -19
- package/dist/interceptors.js +0 -105
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
2
|
import * as schemas from '../schemas.js';
|
|
3
|
-
import {
|
|
3
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
4
|
+
import { anyObjectSchema, parseArgument, parseResponse } from '../utils.js';
|
|
4
5
|
import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
|
|
5
6
|
/**
|
|
6
7
|
* Client for managing a specific webhook.
|
|
@@ -43,51 +44,58 @@ export class WebhookClient extends ResourceClient {
|
|
|
43
44
|
/**
|
|
44
45
|
* Retrieves the webhook.
|
|
45
46
|
*
|
|
47
|
+
* @param options - Request options
|
|
48
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
46
49
|
* @returns The webhook object, or `undefined` if it does not exist.
|
|
47
50
|
* @see https://docs.apify.com/api/v2/webhook-get
|
|
48
51
|
*/
|
|
49
|
-
async get() {
|
|
50
|
-
|
|
52
|
+
async get(options = {}) {
|
|
53
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
54
|
+
return this.getResource(schemas.WebhookResource(), {}, timeoutSecs, signal);
|
|
51
55
|
}
|
|
52
56
|
/**
|
|
53
57
|
* Updates the webhook with the specified fields.
|
|
54
58
|
*
|
|
55
59
|
* @param newFields - Fields to update.
|
|
60
|
+
* @param options - Request options
|
|
61
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
56
62
|
* @returns The updated webhook object.
|
|
57
63
|
* @see https://docs.apify.com/api/v2/webhook-put
|
|
58
64
|
*/
|
|
59
|
-
async update(newFields) {
|
|
65
|
+
async update(newFields, options = {}) {
|
|
60
66
|
parseArgument(newFields, anyObjectSchema);
|
|
61
|
-
|
|
67
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
68
|
+
return this.updateResource(schemas.WebhookResource(), newFields, timeoutSecs, signal);
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* Deletes the webhook.
|
|
65
72
|
*
|
|
73
|
+
* @param options - Request options
|
|
74
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
66
75
|
* @see https://docs.apify.com/api/v2/webhook-delete
|
|
67
76
|
*/
|
|
68
|
-
async delete() {
|
|
69
|
-
|
|
77
|
+
async delete(options = {}) {
|
|
78
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
79
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
70
80
|
}
|
|
71
81
|
/**
|
|
72
82
|
* Tests the webhook by dispatching a test event.
|
|
73
83
|
*
|
|
74
|
-
* @
|
|
84
|
+
* @param options - Request options
|
|
85
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'medium'`.
|
|
86
|
+
* @returns The webhook dispatch object.
|
|
75
87
|
* @see https://docs.apify.com/api/v2/webhook-test-post
|
|
76
88
|
*/
|
|
77
|
-
async test() {
|
|
78
|
-
const
|
|
79
|
-
|
|
89
|
+
async test(options = {}) {
|
|
90
|
+
const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
91
|
+
const response = await this.httpClient.call({
|
|
92
|
+
url: this.buildUrl('test'),
|
|
80
93
|
method: 'POST',
|
|
81
|
-
params: this.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
catchNotFoundOrThrow(err);
|
|
89
|
-
}
|
|
90
|
-
return undefined;
|
|
94
|
+
params: this.buildParams(),
|
|
95
|
+
timeoutSecs,
|
|
96
|
+
signal,
|
|
97
|
+
});
|
|
98
|
+
return parseResponse(response, schemas.WebhookDispatch());
|
|
91
99
|
}
|
|
92
100
|
/**
|
|
93
101
|
* Returns a client for the dispatches of this webhook.
|
|
@@ -96,7 +104,7 @@ export class WebhookClient extends ResourceClient {
|
|
|
96
104
|
* @see https://docs.apify.com/api/v2/webhook-webhook-dispatches-get
|
|
97
105
|
*/
|
|
98
106
|
dispatches() {
|
|
99
|
-
return new WebhookDispatchCollectionClient(this.
|
|
107
|
+
return new WebhookDispatchCollectionClient(this.subResourceOptions({
|
|
100
108
|
resourcePath: 'dispatches',
|
|
101
109
|
}));
|
|
102
110
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
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
|
-
import type {
|
|
5
|
+
import type { WebhookResource, WebhookUpdateData } from './webhook.js';
|
|
5
6
|
/**
|
|
6
7
|
* Client for managing the collection of Webhooks.
|
|
7
8
|
*
|
|
@@ -47,19 +48,22 @@ 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
|
*/
|
|
53
|
-
list(options?: WebhookCollectionListOptions): PaginatedIterator<Omit<
|
|
55
|
+
list(options?: WebhookCollectionListOptions): PaginatedIterator<Omit<WebhookResource, 'payloadTemplate' | 'headersTemplate'>>;
|
|
54
56
|
/**
|
|
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<
|
|
65
|
+
create(webhook?: WebhookUpdateData, options?: TimeoutOptions): Promise<WebhookResource>;
|
|
62
66
|
}
|
|
63
|
-
export interface WebhookCollectionListOptions extends PaginationOptions {
|
|
67
|
+
export interface WebhookCollectionListOptions extends PaginationOptions, TimeoutOptions {
|
|
64
68
|
desc?: boolean;
|
|
65
69
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
3
|
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
4
5
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
6
|
const listOptionsSchema = z.strictObject({
|
|
6
7
|
...paginationOptionsShape,
|
|
7
8
|
desc: z.boolean().optional(),
|
|
9
|
+
...timeoutOptionsShape,
|
|
8
10
|
});
|
|
9
11
|
const webhookCreateSchema = anyObjectSchema.optional();
|
|
10
12
|
/**
|
|
@@ -57,22 +59,26 @@ export class WebhookCollectionClient extends ResourceCollectionClient {
|
|
|
57
59
|
* ```
|
|
58
60
|
*
|
|
59
61
|
* @param options - Pagination and sorting options.
|
|
62
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
60
63
|
* @returns A paginated iterator of webhooks.
|
|
61
64
|
* @see https://docs.apify.com/api/v2/webhooks-get
|
|
62
65
|
*/
|
|
63
66
|
list(options = {}) {
|
|
64
67
|
const parsed = parseArgument(options, listOptionsSchema, 'WebhookCollectionListOptions');
|
|
65
|
-
return this.
|
|
68
|
+
return this.listResourcesPaginated(schemas.ListOfWebhooks(), parsed, 'medium');
|
|
66
69
|
}
|
|
67
70
|
/**
|
|
68
71
|
* Creates a new webhook.
|
|
69
72
|
*
|
|
70
73
|
* @param webhook - The webhook data.
|
|
74
|
+
* @param options - Request options
|
|
75
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
71
76
|
* @returns The created webhook object.
|
|
72
77
|
* @see https://docs.apify.com/api/v2/webhooks-post
|
|
73
78
|
*/
|
|
74
|
-
async create(webhook) {
|
|
79
|
+
async create(webhook, options = {}) {
|
|
75
80
|
parseArgument(webhook, webhookCreateSchema);
|
|
76
|
-
|
|
81
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
82
|
+
return this.createResource(schemas.WebhookResource(), webhook, timeoutSecs, signal);
|
|
77
83
|
}
|
|
78
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,5 +1,7 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
2
|
import * as schemas from '../schemas.js';
|
|
3
|
+
import { timeoutOptionsSchema } from '../timeouts.js';
|
|
4
|
+
import { parseArgument } from '../utils.js';
|
|
3
5
|
export { WebhookDispatchStatus } from '../models.js';
|
|
4
6
|
/**
|
|
5
7
|
* Client for managing a specific webhook dispatch.
|
|
@@ -32,10 +34,13 @@ export class WebhookDispatchClient extends ResourceClient {
|
|
|
32
34
|
/**
|
|
33
35
|
* Retrieves the webhook dispatch.
|
|
34
36
|
*
|
|
37
|
+
* @param options - Request options
|
|
38
|
+
* @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
|
|
35
39
|
* @returns The webhook dispatch object, or `undefined` if it does not exist.
|
|
36
40
|
* @see https://docs.apify.com/api/v2/webhook-dispatch-get
|
|
37
41
|
*/
|
|
38
|
-
async get() {
|
|
39
|
-
|
|
42
|
+
async get(options = {}) {
|
|
43
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
44
|
+
return this.getResource(schemas.WebhookDispatch(), {}, timeoutSecs, signal);
|
|
40
45
|
}
|
|
41
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,10 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
3
3
|
import * as schemas from '../schemas.js';
|
|
4
|
+
import { timeoutOptionsShape } from '../timeouts.js';
|
|
4
5
|
import { paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
6
|
const listOptionsSchema = z.strictObject({
|
|
6
7
|
...paginationOptionsShape,
|
|
7
8
|
desc: z.boolean().optional(),
|
|
9
|
+
...timeoutOptionsShape,
|
|
8
10
|
});
|
|
9
11
|
/**
|
|
10
12
|
* Client for managing the collection of webhook dispatches.
|
|
@@ -51,11 +53,12 @@ export class WebhookDispatchCollectionClient extends ResourceCollectionClient {
|
|
|
51
53
|
* ```
|
|
52
54
|
*
|
|
53
55
|
* @param options - Pagination and sorting options.
|
|
56
|
+
* @param options.timeoutSecs - Timeout for each API request. Default is `'medium'`.
|
|
54
57
|
* @returns A paginated iterator of webhook dispatches.
|
|
55
58
|
* @see https://docs.apify.com/api/v2/webhook-dispatches-get
|
|
56
59
|
*/
|
|
57
60
|
list(options = {}) {
|
|
58
61
|
const parsed = parseArgument(options, listOptionsSchema, 'WebhookDispatchCollectionListOptions');
|
|
59
|
-
return this.
|
|
62
|
+
return this.listResourcesPaginated(schemas.ListOfWebhookDispatches(), parsed, 'medium');
|
|
60
63
|
}
|
|
61
64
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import { brotliCompress, constants, gzip } from 'node:zlib';
|
|
3
|
+
/**
|
|
4
|
+
* The Node.js implementation of {@link Runtime}. Deno and Bun resolve the `node` condition too and
|
|
5
|
+
* provide the built-ins it uses.
|
|
6
|
+
*/
|
|
7
|
+
export const runtime = {
|
|
8
|
+
isNode: true,
|
|
9
|
+
platform: `${os.platform()}; Node/${process.version}`,
|
|
10
|
+
async compress(data, { algorithm, quality }) {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const done = (error, result) => (error ? reject(error) : resolve(result));
|
|
13
|
+
if (algorithm === 'br') {
|
|
14
|
+
brotliCompress(data, { params: { [constants.BROTLI_PARAM_QUALITY]: quality } }, done);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
gzip(data, { level: quality }, done);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
async createHttpAgents({ timeoutMillis }) {
|
|
22
|
+
// Loaded on the first request rather than with the client: the proxy support pulls in a sizeable
|
|
23
|
+
// dependency tree that a client which never sends a request should not pay for.
|
|
24
|
+
const { ProxyAgent } = await import('proxy-agent');
|
|
25
|
+
// We want to keep sockets alive for better performance.
|
|
26
|
+
const agentOptions = {
|
|
27
|
+
keepAlive: true,
|
|
28
|
+
// Timeout for inactive sockets
|
|
29
|
+
// Prevents socket leaks from idle connections
|
|
30
|
+
timeout: timeoutMillis,
|
|
31
|
+
// Keep alive timeout for free sockets (15 seconds)
|
|
32
|
+
// Node.js will close unused sockets after this period
|
|
33
|
+
keepAliveMsecs: 15_000,
|
|
34
|
+
// Maximum number of sockets per host
|
|
35
|
+
maxSockets: 256,
|
|
36
|
+
maxFreeSockets: 256,
|
|
37
|
+
// LIFO scheduling - reuse most recently used sockets for better performance
|
|
38
|
+
scheduling: 'lifo',
|
|
39
|
+
};
|
|
40
|
+
// ProxyAgent picks the proxy up from the environment variables and supports CONNECT tunneling.
|
|
41
|
+
const agent = new ProxyAgent(agentOptions);
|
|
42
|
+
// Disable Nagle's algorithm for lower latency
|
|
43
|
+
// This sends data immediately instead of buffering small packets
|
|
44
|
+
agent.on('socket', (socket) => {
|
|
45
|
+
socket.setNoDelay(true);
|
|
46
|
+
});
|
|
47
|
+
return { httpAgent: agent, httpsAgent: agent };
|
|
48
|
+
},
|
|
49
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type http from 'node:http';
|
|
2
|
+
import type https from 'node:https';
|
|
3
|
+
/**
|
|
4
|
+
* What to compress a request body with, as the built-in `HttpCompressor` implementations ask for it.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export interface CompressionOptions {
|
|
8
|
+
/** Algorithm to compress with, named by the `Content-Encoding` value it produces. */
|
|
9
|
+
algorithm: 'br' | 'gzip';
|
|
10
|
+
/** Compression level, in the range the algorithm defines. */
|
|
11
|
+
quality: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The agents axios's Node.js adapter sends requests through.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export interface HttpAgents {
|
|
18
|
+
httpAgent: http.Agent;
|
|
19
|
+
httpsAgent: https.Agent;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The runtime-specific part of the client. `#runtime` resolves to the Node.js implementation under the `node`
|
|
23
|
+
* condition and to the Web API one everywhere else (see the `imports` field of `package.json`), so a bundler
|
|
24
|
+
* targeting a browser or an edge runtime never sees the Node.js built-ins the Node.js one uses.
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export interface Runtime {
|
|
28
|
+
/**
|
|
29
|
+
* Whether the Node.js implementation was selected, which the `node` condition settles when `#runtime` is
|
|
30
|
+
* resolved - so a Node.js application bundled for a browser or a neutral target reports `false`. Log
|
|
31
|
+
* streaming, the `stream` record option and request body compression are gated on it.
|
|
32
|
+
*/
|
|
33
|
+
isNode: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The platform part of the `User-Agent` header, or `undefined` where the runtime does not let a client
|
|
36
|
+
* set that header (browsers).
|
|
37
|
+
*/
|
|
38
|
+
platform: string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Compresses a request body. The built-in compressors go through it, so a bundle for a browser or an edge
|
|
41
|
+
* runtime carries no `node:zlib`. Throws where the runtime has no compression, which the client never
|
|
42
|
+
* reaches, since it compresses only where {@link isNode} holds.
|
|
43
|
+
*/
|
|
44
|
+
compress(data: Uint8Array, options: CompressionOptions): Promise<Buffer>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates the agents axios's Node.js adapter sends requests through, or resolves to `undefined` where
|
|
47
|
+
* axios does not use agents.
|
|
48
|
+
*/
|
|
49
|
+
createHttpAgents(options: {
|
|
50
|
+
timeoutMillis: number;
|
|
51
|
+
}): Promise<HttpAgents | undefined>;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
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 and gzip have no Web API, and a `content-encoding` request header is not
|
|
9
|
+
// on the list of headers the Apify API allows in a cross-origin request, so a browser would fail the
|
|
10
|
+
// preflight. The client compresses in Node.js alone, so nothing reaches this.
|
|
11
|
+
async compress() {
|
|
12
|
+
throw new Error('Request body compression is only available in Node.js.');
|
|
13
|
+
},
|
|
14
|
+
// The XHR and fetch adapters of axios do not use agents.
|
|
15
|
+
async createHttpAgents() {
|
|
16
|
+
return undefined;
|
|
17
|
+
},
|
|
18
|
+
};
|
package/dist/schemas.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* documented deviation never sends a resource client reaching into `./generated` directly. An override
|
|
7
7
|
* declared here shadows the generated export of the same name and takes the same form, a `lazySchema()` thunk
|
|
8
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
|
|
9
|
+
* top of it, and `spec_guards.ts` checks that each override still produces what the specification describes,
|
|
10
10
|
* so one cannot narrow by accident.
|
|
11
11
|
*
|
|
12
12
|
* Spec gaps need no override: the generated objects are loose, so a field the specification omits passes
|
package/dist/schemas.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* documented deviation never sends a resource client reaching into `./generated` directly. An override
|
|
7
7
|
* declared here shadows the generated export of the same name and takes the same form, a `lazySchema()` thunk
|
|
8
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
|
|
9
|
+
* top of it, and `spec_guards.ts` checks that each override still produces what the specification describes,
|
|
10
10
|
* so one cannot narrow by accident.
|
|
11
11
|
*
|
|
12
12
|
* Spec gaps need no override: the generated objects are loose, so a field the specification omits passes
|
package/dist/statistics.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare class Statistics {
|
|
2
|
+
#private;
|
|
2
3
|
/**
|
|
3
4
|
* Number of Apify client function calls
|
|
4
5
|
*/
|
|
@@ -13,10 +14,4 @@ export declare class Statistics {
|
|
|
13
14
|
*/
|
|
14
15
|
rateLimitErrors: number[];
|
|
15
16
|
addRateLimitError(attempt: number): void;
|
|
16
|
-
/**
|
|
17
|
-
* Removes the necessity to pre-initialize array with correct
|
|
18
|
-
* number of zeroes by dynamically filling the empty indexes
|
|
19
|
-
* when necessary.
|
|
20
|
-
*/
|
|
21
|
-
private _fillBlanksWithZeroes;
|
|
22
17
|
}
|
package/dist/statistics.js
CHANGED
|
@@ -20,7 +20,7 @@ export class Statistics {
|
|
|
20
20
|
// attempt is never 0,
|
|
21
21
|
// but we don't want index 0 empty
|
|
22
22
|
const index = attempt - 1;
|
|
23
|
-
this
|
|
23
|
+
this.#fillBlanksWithZeroes(index);
|
|
24
24
|
this.rateLimitErrors[index]++;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -28,7 +28,7 @@ export class Statistics {
|
|
|
28
28
|
* number of zeroes by dynamically filling the empty indexes
|
|
29
29
|
* when necessary.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
#fillBlanksWithZeroes(inclusiveIndex) {
|
|
32
32
|
if (this.rateLimitErrors.length <= inclusiveIndex) {
|
|
33
33
|
for (let k = 0; k <= inclusiveIndex; k++) {
|
|
34
34
|
if (typeof this.rateLimitErrors[k] !== 'number') {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Default duration of the `short` timeout tier, in seconds. */
|
|
3
|
+
export declare const DEFAULT_TIMEOUT_SHORT_SECS = 5;
|
|
4
|
+
/** Default duration of the `medium` timeout tier, in seconds. */
|
|
5
|
+
export declare const DEFAULT_TIMEOUT_MEDIUM_SECS = 30;
|
|
6
|
+
/** Default duration of the `long` timeout tier, in seconds. */
|
|
7
|
+
export declare const DEFAULT_TIMEOUT_LONG_SECS = 360;
|
|
8
|
+
/** Default cap on the timeout of a single request attempt, in seconds. */
|
|
9
|
+
export declare const DEFAULT_TIMEOUT_MAX_SECS = 360;
|
|
10
|
+
/**
|
|
11
|
+
* Preconfigured timeout tiers. Every client method picks the tier that fits the expected duration of its
|
|
12
|
+
* request: `short` for simple metadata reads and writes, `medium` for listing, batch and trigger operations,
|
|
13
|
+
* `long` for downloads, uploads and streaming. The duration of each tier is set on the {@link ApifyClient}
|
|
14
|
+
* constructor.
|
|
15
|
+
*/
|
|
16
|
+
export type TimeoutTier = 'short' | 'medium' | 'long';
|
|
17
|
+
/**
|
|
18
|
+
* Timeout of a single API request.
|
|
19
|
+
*
|
|
20
|
+
* A tier name picks the duration configured for that tier on the {@link ApifyClient} constructor, a number is
|
|
21
|
+
* an exact duration in seconds, and `'noTimeout'` lets the request run for as long as it takes. A tier or an
|
|
22
|
+
* explicit duration above `timeoutMaxSecs` is capped at it, and the client logs a warning when that happens.
|
|
23
|
+
* The timeout applies to each attempt separately, and doubles with every retry up to the same cap.
|
|
24
|
+
*
|
|
25
|
+
* With `'noTimeout'` the client never aborts the request, so a connection that stalls is not retried either.
|
|
26
|
+
*/
|
|
27
|
+
export type Timeout = TimeoutTier | 'noTimeout' | number;
|
|
28
|
+
/**
|
|
29
|
+
* Options shared by every method that sends a request to the API.
|
|
30
|
+
*/
|
|
31
|
+
export interface TimeoutOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Timeout for the API request: a tier name (`'short'`, `'medium'`, `'long'`), a number of seconds, or
|
|
34
|
+
* `'noTimeout'`. Defaults to the tier the method is assigned, which its documentation names.
|
|
35
|
+
*/
|
|
36
|
+
timeoutSecs?: Timeout;
|
|
37
|
+
/**
|
|
38
|
+
* Aborts the method. Once the signal aborts, the request in flight is ended, no retry or further poll
|
|
39
|
+
* follows, and the method rejects with the signal's `reason`.
|
|
40
|
+
*/
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Schema of {@link Timeout}, optional, for the methods that validate `timeoutSecs` on its own.
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export declare const optionalTimeoutSchema: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
48
|
+
long: "long";
|
|
49
|
+
medium: "medium";
|
|
50
|
+
noTimeout: "noTimeout";
|
|
51
|
+
short: "short";
|
|
52
|
+
}>, z.ZodNumber]>>;
|
|
53
|
+
/**
|
|
54
|
+
* Schema of {@link TimeoutOptions.signal}, for the methods that validate `signal` on its own.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare const optionalSignalSchema: z.ZodOptional<z.ZodInstanceOf<AbortSignal>>;
|
|
58
|
+
/**
|
|
59
|
+
* Schema shape of {@link TimeoutOptions}, to spread into the option schema of every method that sends a
|
|
60
|
+
* request. One copy stops it drifting from the interface.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export declare const timeoutOptionsShape: {
|
|
64
|
+
timeoutSecs: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
65
|
+
long: "long";
|
|
66
|
+
medium: "medium";
|
|
67
|
+
noTimeout: "noTimeout";
|
|
68
|
+
short: "short";
|
|
69
|
+
}>, z.ZodNumber]>>;
|
|
70
|
+
signal: z.ZodOptional<z.ZodInstanceOf<AbortSignal>>;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Schema of {@link TimeoutOptions}, for the methods that take no other option.
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
export declare const timeoutOptionsSchema: z.ZodObject<{
|
|
77
|
+
timeoutSecs: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
78
|
+
long: "long";
|
|
79
|
+
medium: "medium";
|
|
80
|
+
noTimeout: "noTimeout";
|
|
81
|
+
short: "short";
|
|
82
|
+
}>, z.ZodNumber]>>;
|
|
83
|
+
signal: z.ZodOptional<z.ZodInstanceOf<AbortSignal>>;
|
|
84
|
+
}, z.core.$strict>;
|
package/dist/timeouts.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Default duration of the `short` timeout tier, in seconds. */
|
|
3
|
+
export const DEFAULT_TIMEOUT_SHORT_SECS = 5;
|
|
4
|
+
/** Default duration of the `medium` timeout tier, in seconds. */
|
|
5
|
+
export const DEFAULT_TIMEOUT_MEDIUM_SECS = 30;
|
|
6
|
+
/** Default duration of the `long` timeout tier, in seconds. */
|
|
7
|
+
export const DEFAULT_TIMEOUT_LONG_SECS = 360;
|
|
8
|
+
/** Default cap on the timeout of a single request attempt, in seconds. */
|
|
9
|
+
export const DEFAULT_TIMEOUT_MAX_SECS = 360;
|
|
10
|
+
/**
|
|
11
|
+
* Schema of {@link Timeout}. Zero is rejected on purpose - `'noTimeout'` is the explicit way to run without one.
|
|
12
|
+
*/
|
|
13
|
+
const timeoutSchema = z.union([z.enum(['short', 'medium', 'long', 'noTimeout']), z.number().positive()]);
|
|
14
|
+
/**
|
|
15
|
+
* Schema of {@link Timeout}, optional, for the methods that validate `timeoutSecs` on its own.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export const optionalTimeoutSchema = timeoutSchema.optional();
|
|
19
|
+
/**
|
|
20
|
+
* Schema of {@link TimeoutOptions.signal}, for the methods that validate `signal` on its own.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export const optionalSignalSchema = z.instanceof(AbortSignal).optional();
|
|
24
|
+
/**
|
|
25
|
+
* Schema shape of {@link TimeoutOptions}, to spread into the option schema of every method that sends a
|
|
26
|
+
* request. One copy stops it drifting from the interface.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export const timeoutOptionsShape = {
|
|
30
|
+
timeoutSecs: optionalTimeoutSchema,
|
|
31
|
+
signal: optionalSignalSchema,
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Schema of {@link TimeoutOptions}, for the methods that take no other option.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export const timeoutOptionsSchema = z.strictObject(timeoutOptionsShape);
|