apify-client 3.0.0-rc.0 → 3.0.0-rc.1
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 +6 -0
- package/dist/apify_api_error.d.ts +2 -1
- package/dist/apify_api_error.js +2 -1
- package/dist/apify_client_error.d.ts +10 -0
- package/dist/apify_client_error.js +10 -0
- package/dist/base/api_client.js +8 -20
- package/dist/base/resource_client.js +8 -8
- package/dist/bundle.js +13 -13
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +2300 -690
- package/dist/generated/schemas.d.ts +1720 -246
- package/dist/generated/schemas.js +416 -75
- package/dist/http_clients/axios.d.ts +2 -1
- package/dist/http_clients/axios.js +6 -4
- package/dist/http_clients/base.d.ts +80 -20
- package/dist/http_clients/base.js +127 -40
- package/dist/http_compressors/index.d.ts +2 -0
- package/dist/http_compressors/index.js +1 -0
- package/dist/http_compressors/resolve.d.ts +4 -3
- package/dist/http_compressors/resolve.js +4 -1
- package/dist/http_compressors/zstd.d.ts +34 -0
- package/dist/http_compressors/zstd.js +43 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/invalid_response_body_error.d.ts +5 -4
- package/dist/invalid_response_body_error.js +5 -4
- package/dist/models.d.ts +30 -61
- package/dist/resource_clients/actor.d.ts +30 -0
- package/dist/resource_clients/actor.js +43 -0
- package/dist/resource_clients/actor_server.d.ts +149 -0
- package/dist/resource_clients/actor_server.js +199 -0
- package/dist/resource_clients/actor_version.d.ts +5 -0
- package/dist/resource_clients/dataset.d.ts +33 -4
- package/dist/resource_clients/dataset.js +16 -54
- package/dist/resource_clients/key_value_store.d.ts +51 -11
- package/dist/resource_clients/key_value_store.js +59 -15
- package/dist/resource_clients/log.d.ts +29 -3
- package/dist/resource_clients/log.js +7 -11
- package/dist/resource_clients/request_queue.d.ts +9 -0
- package/dist/resource_clients/request_queue.js +9 -6
- package/dist/resource_clients/run.d.ts +9 -0
- package/dist/resource_clients/run.js +6 -3
- package/dist/response_validation_error.d.ts +2 -1
- package/dist/response_validation_error.js +2 -1
- package/dist/runtime/node.js +44 -6
- package/dist/runtime/types.d.ts +9 -1
- package/dist/runtime/web.js +4 -1
- package/dist/schemas.d.ts +369 -3
- package/dist/schemas.js +25 -3
- package/dist/utils.d.ts +23 -26
- package/dist/utils.js +32 -25
- package/package.json +23 -23
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ automatic retries and convenience functions that improve the experience of using
|
|
|
15
15
|
- [Features](#features)
|
|
16
16
|
- [Automatic parsing and error handling](#automatic-parsing-and-error-handling)
|
|
17
17
|
- [Retries with exponential backoff](#retries-with-exponential-backoff)
|
|
18
|
+
- [Server Actors](#server-actors)
|
|
18
19
|
- [Convenience functions and options](#convenience-functions-and-options)
|
|
19
20
|
- [Usage concepts](#usage-concepts)
|
|
20
21
|
- [Nested clients](#nested-clients)
|
|
@@ -65,6 +66,11 @@ The client ships with an axios-based HTTP client and accepts a custom one. Exten
|
|
|
65
66
|
`sendRequest()` over the HTTP library of your choice and plug it in with `ApifyClient.withCustomHttpClient()`. The
|
|
66
67
|
custom client inherits the retries, timeouts, compression and error handling of the built-in one.
|
|
67
68
|
|
|
69
|
+
### Server Actors
|
|
70
|
+
|
|
71
|
+
`client.actor(id).server()` returns a client for a Server Actor (formerly Actor Standby). It sends HTTP requests to
|
|
72
|
+
the Actor's web server with your token, and returns the server's URL and OpenAPI specification.
|
|
73
|
+
|
|
68
74
|
### Convenience functions and options
|
|
69
75
|
|
|
70
76
|
Some actions can't be performed by the API itself, such as indefinite waiting for an actor run to finish
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LiteralUnion } from 'type-fest';
|
|
2
|
+
import { ApifyClientError } from './apify_client_error.js';
|
|
2
3
|
import type { ApifyResponse } from './http_clients/base.js';
|
|
3
4
|
import type { ErrorType } from './models.js';
|
|
4
5
|
export type { ErrorType } from './models.js';
|
|
@@ -16,7 +17,7 @@ export type { ErrorType } from './models.js';
|
|
|
16
17
|
* subclass extends `ApifyApiError`, so `instanceof ApifyApiError` matches all of them. Errors that
|
|
17
18
|
* share a status code are told apart by their `type`.
|
|
18
19
|
*/
|
|
19
|
-
export declare class ApifyApiError extends
|
|
20
|
+
export declare class ApifyApiError extends ApifyClientError {
|
|
20
21
|
#private;
|
|
21
22
|
name: string;
|
|
22
23
|
/**
|
package/dist/apify_api_error.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ApifyClientError } from './apify_client_error.js';
|
|
1
2
|
import { isBuffer } from './utils.js';
|
|
2
3
|
/**
|
|
3
4
|
* Examples of capturing groups for "...at ActorCollectionClient.listResources (/Users/..."
|
|
@@ -30,7 +31,7 @@ const CLIENT_METHOD_REGEX = /at( async)? (?![A-Za-z]*HttpClient\.)([A-Za-z]+(Col
|
|
|
30
31
|
* subclass extends `ApifyApiError`, so `instanceof ApifyApiError` matches all of them. Errors that
|
|
31
32
|
* share a status code are told apart by their `type`.
|
|
32
33
|
*/
|
|
33
|
-
export class ApifyApiError extends
|
|
34
|
+
export class ApifyApiError extends ApifyClientError {
|
|
34
35
|
name;
|
|
35
36
|
/**
|
|
36
37
|
* The resource client and the method parsed from the stack trace, such as `ActorClient.getResource`. A public
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class of the errors the client throws for a failed API call: {@link ApifyApiError} and its subclasses,
|
|
3
|
+
* {@link InvalidResponseBodyError} and {@link ResponseValidationError}. A single `instanceof ApifyClientError`
|
|
4
|
+
* check catches all of them.
|
|
5
|
+
*
|
|
6
|
+
* Invalid arguments throw an `ArgumentValidationError` before any request is sent, and transport errors, timeouts
|
|
7
|
+
* and aborts surface as the errors the transport raised. None of those extend this class.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ApifyClientError extends Error {
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class of the errors the client throws for a failed API call: {@link ApifyApiError} and its subclasses,
|
|
3
|
+
* {@link InvalidResponseBodyError} and {@link ResponseValidationError}. A single `instanceof ApifyClientError`
|
|
4
|
+
* check catches all of them.
|
|
5
|
+
*
|
|
6
|
+
* Invalid arguments throw an `ArgumentValidationError` before any request is sent, and transport errors, timeouts
|
|
7
|
+
* and aborts surface as the errors the transport raised. None of those extend this class.
|
|
8
|
+
*/
|
|
9
|
+
export class ApifyClientError extends Error {
|
|
10
|
+
}
|
package/dist/base/api_client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { minForLimitParam, toPath, toPathSegment } from '../utils.js';
|
|
2
2
|
/** @private */
|
|
3
3
|
export class ApiClient {
|
|
4
4
|
id;
|
|
@@ -54,32 +54,20 @@ export class ApiClient {
|
|
|
54
54
|
* Returns async iterator to iterate through all items and Promise that can be awaited to get first page of results.
|
|
55
55
|
*/
|
|
56
56
|
listPaginatedFromCallback(getPaginatedList, options = {}) {
|
|
57
|
-
const minForLimitParam = (a, b) => {
|
|
58
|
-
// API treats 0 as undefined for limit parameter
|
|
59
|
-
if (a === 0)
|
|
60
|
-
a = undefined;
|
|
61
|
-
if (b === 0)
|
|
62
|
-
b = undefined;
|
|
63
|
-
if (a === undefined)
|
|
64
|
-
return b;
|
|
65
|
-
if (b === undefined)
|
|
66
|
-
return a;
|
|
67
|
-
return Math.min(a, b);
|
|
68
|
-
};
|
|
69
57
|
// `chunkSize` only sizes this loop's requests; it is not an API parameter, so it must not reach
|
|
70
58
|
// `buildParams()` and the query string. The same goes for `timeoutSecs` and `signal`, which callers take out
|
|
71
59
|
// before calling this, since they also apply to every page request.
|
|
72
60
|
const { chunkSize, ...listOptions } = options;
|
|
73
61
|
const firstPageLimit = minForLimitParam(options.limit, chunkSize);
|
|
74
62
|
const paginatedListPromise = getPaginatedList({ ...listOptions, limit: firstPageLimit });
|
|
75
|
-
// A page can return more or fewer items than the rows it scanned (see `
|
|
76
|
-
// the stop condition follow the scanned rows: advancing by `items.length` would re-scan
|
|
77
|
-
// dropped some and skip rows after `unwind` multiplied them, and stopping at an empty page
|
|
78
|
-
// iteration in front of rows a filter hid. The
|
|
79
|
-
//
|
|
80
|
-
//
|
|
63
|
+
// A page of dataset items can return more or fewer items than the rows it scanned (see `PaginatedList.count`).
|
|
64
|
+
// The next offset and the stop condition follow the scanned rows: advancing by `items.length` would re-scan
|
|
65
|
+
// rows after a filter dropped some and skip rows after `unwind` multiplied them, and stopping at an empty page
|
|
66
|
+
// would end the iteration in front of rows a filter hid. The step is the larger of `count` and `items.length`,
|
|
67
|
+
// capped at the rows the request asked for, which keeps an unwound page from advancing past rows the next
|
|
68
|
+
// request would then never read.
|
|
81
69
|
const scannedRows = (page, requestedLimit) => {
|
|
82
|
-
const scanned = Math.max(page
|
|
70
|
+
const scanned = Math.max(page.count ?? 0, page.items.length);
|
|
83
71
|
return requestedLimit ? Math.min(scanned, requestedLimit) : scanned;
|
|
84
72
|
};
|
|
85
73
|
// `total` is not consulted, as it changes when the listed resource grows during the iteration.
|
|
@@ -102,7 +102,7 @@ export class ResourceClient extends ApiClient {
|
|
|
102
102
|
const hasJobEnded = job && ACT_JOB_TERMINAL_STATUSES.includes(job.status);
|
|
103
103
|
return !hasJobEnded;
|
|
104
104
|
};
|
|
105
|
-
|
|
105
|
+
while (true) {
|
|
106
106
|
const millisSinceStart = Date.now() - startedAt;
|
|
107
107
|
const remainingWaitSeconds = Math.round((waitMillis - millisSinceStart) / 1000);
|
|
108
108
|
const waitForFinish = Math.max(0, remainingWaitSeconds);
|
|
@@ -124,13 +124,13 @@ export class ResourceClient extends ApiClient {
|
|
|
124
124
|
notFoundSince ??= Date.now();
|
|
125
125
|
notFoundError = err;
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
127
|
+
if (!shouldRepeat())
|
|
128
|
+
break;
|
|
129
|
+
// The API answers right away when the remaining wait rounds to 0 seconds, and database replicas may not see
|
|
130
|
+
// a new job for a short while, so pause before the next poll.
|
|
131
|
+
await sleep(250, signal);
|
|
132
|
+
signal?.throwIfAborted();
|
|
133
|
+
}
|
|
134
134
|
if (!job)
|
|
135
135
|
throw notFoundError;
|
|
136
136
|
return job;
|