apify-client 3.0.0-beta.1 → 3.0.0-beta.2
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 +2 -2
- package/dist/apify_api_error.js +5 -9
- package/dist/apify_client.d.ts +27 -27
- package/dist/apify_client.js +86 -91
- package/dist/argument_validation_error.js +1 -5
- package/dist/base/api_client.d.ts +3 -3
- package/dist/base/api_client.js +6 -10
- package/dist/base/resource_client.d.ts +1 -1
- package/dist/base/resource_client.js +14 -18
- package/dist/base/resource_collection_client.d.ts +2 -2
- package/dist/base/resource_collection_client.js +6 -10
- package/dist/body_parser.js +6 -11
- package/dist/bundle.js +8 -8
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.js +1 -2
- package/dist/http_client.d.ts +2 -2
- package/dist/http_client.js +23 -28
- package/dist/index.d.ts +32 -32
- package/dist/index.js +31 -36
- package/dist/interceptors.d.ts +1 -1
- package/dist/interceptors.js +14 -19
- package/dist/models.d.ts +3 -3
- package/dist/models.js +8 -11
- package/dist/resource_clients/actor.d.ts +13 -13
- package/dist/resource_clients/actor.js +67 -71
- package/dist/resource_clients/actor_collection.d.ts +7 -7
- package/dist/resource_clients/actor_collection.js +14 -18
- package/dist/resource_clients/actor_env_var.d.ts +3 -3
- package/dist/resource_clients/actor_env_var.js +4 -8
- package/dist/resource_clients/actor_env_var_collection.d.ts +4 -4
- package/dist/resource_clients/actor_env_var_collection.js +5 -9
- package/dist/resource_clients/actor_version.d.ts +7 -7
- package/dist/resource_clients/actor_version.js +12 -17
- package/dist/resource_clients/actor_version_collection.d.ts +4 -4
- package/dist/resource_clients/actor_version_collection.js +5 -9
- package/dist/resource_clients/build.d.ts +5 -5
- package/dist/resource_clients/build.js +11 -15
- package/dist/resource_clients/build_collection.d.ts +5 -5
- package/dist/resource_clients/build_collection.js +8 -12
- package/dist/resource_clients/dataset.d.ts +5 -5
- package/dist/resource_clients/dataset.js +72 -76
- package/dist/resource_clients/dataset_collection.d.ts +4 -4
- package/dist/resource_clients/dataset_collection.js +15 -19
- package/dist/resource_clients/key_value_store.d.ts +4 -4
- package/dist/resource_clients/key_value_store.js +57 -62
- package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
- package/dist/resource_clients/key_value_store_collection.js +15 -19
- package/dist/resource_clients/log.d.ts +2 -2
- package/dist/resource_clients/log.js +15 -22
- package/dist/resource_clients/request_queue.d.ts +4 -4
- package/dist/resource_clients/request_queue.js +91 -96
- package/dist/resource_clients/request_queue_collection.d.ts +4 -4
- package/dist/resource_clients/request_queue_collection.js +13 -17
- package/dist/resource_clients/run.d.ts +8 -8
- package/dist/resource_clients/run.js +46 -50
- package/dist/resource_clients/run_collection.d.ts +4 -4
- package/dist/resource_clients/run_collection.js +13 -17
- package/dist/resource_clients/schedule.d.ts +6 -6
- package/dist/resource_clients/schedule.js +7 -12
- package/dist/resource_clients/schedule_collection.d.ts +4 -4
- package/dist/resource_clients/schedule_collection.js +10 -14
- package/dist/resource_clients/store_collection.d.ts +5 -5
- package/dist/resource_clients/store_collection.js +13 -17
- package/dist/resource_clients/task.d.ts +9 -9
- package/dist/resource_clients/task.js +44 -48
- package/dist/resource_clients/task_collection.d.ts +6 -6
- package/dist/resource_clients/task_collection.js +9 -13
- package/dist/resource_clients/user.d.ts +5 -5
- package/dist/resource_clients/user.js +8 -13
- package/dist/resource_clients/webhook.d.ts +6 -6
- package/dist/resource_clients/webhook.js +8 -12
- package/dist/resource_clients/webhook_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_collection.js +10 -14
- package/dist/resource_clients/webhook_dispatch.d.ts +5 -5
- package/dist/resource_clients/webhook_dispatch.js +3 -8
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_dispatch_collection.js +8 -12
- package/dist/statistics.js +5 -9
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +32 -53
- package/package.json +4 -7
- package/dist/index.mjs +0 -42
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const consts_1 = require("@apify/consts");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const api_client_1 = require("./api_client");
|
|
1
|
+
import { ACT_JOB_TERMINAL_STATUSES } from '@apify/consts';
|
|
2
|
+
import { catchNotFoundOrThrow, parseDateFields, pluckData } from '../utils.js';
|
|
3
|
+
import { ApiClient } from './api_client.js';
|
|
7
4
|
/**
|
|
8
5
|
* We need to supply some number for the API,
|
|
9
6
|
* because it would not accept "Infinity".
|
|
10
7
|
* 999999 seconds is more than 10 days.
|
|
11
8
|
*/
|
|
12
9
|
const MAX_WAIT_FOR_FINISH = 999999;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export const SMALL_TIMEOUT_MILLIS = 5 * 1000; // For fast and common actions. Suitable for idempotent actions.
|
|
11
|
+
export const MEDIUM_TIMEOUT_MILLIS = 30 * 1000; // For actions that may take longer.
|
|
12
|
+
export const DEFAULT_TIMEOUT_MILLIS = 360 * 1000; // 6 minutes
|
|
16
13
|
/**
|
|
17
14
|
* Resource client.
|
|
18
15
|
* @private
|
|
19
16
|
*/
|
|
20
|
-
class ResourceClient extends
|
|
17
|
+
export class ResourceClient extends ApiClient {
|
|
21
18
|
async _get(options = {}, timeoutMillis) {
|
|
22
19
|
const requestOpts = {
|
|
23
20
|
url: this._url(),
|
|
@@ -27,10 +24,10 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
27
24
|
};
|
|
28
25
|
try {
|
|
29
26
|
const response = await this.httpClient.call(requestOpts);
|
|
30
|
-
return
|
|
27
|
+
return parseDateFields(pluckData(response.data));
|
|
31
28
|
}
|
|
32
29
|
catch (err) {
|
|
33
|
-
|
|
30
|
+
catchNotFoundOrThrow(err);
|
|
34
31
|
}
|
|
35
32
|
return undefined;
|
|
36
33
|
}
|
|
@@ -42,7 +39,7 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
42
39
|
data: newFields,
|
|
43
40
|
timeout: timeoutMillis,
|
|
44
41
|
});
|
|
45
|
-
return
|
|
42
|
+
return parseDateFields(pluckData(response.data));
|
|
46
43
|
}
|
|
47
44
|
async _delete(timeoutMillis) {
|
|
48
45
|
try {
|
|
@@ -54,7 +51,7 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
53
|
catch (err) {
|
|
57
|
-
|
|
54
|
+
catchNotFoundOrThrow(err);
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
@@ -70,7 +67,7 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
70
67
|
const millisSinceStart = Date.now() - startedAt;
|
|
71
68
|
if (millisSinceStart >= waitMillis)
|
|
72
69
|
return false;
|
|
73
|
-
const hasJobEnded = job &&
|
|
70
|
+
const hasJobEnded = job && ACT_JOB_TERMINAL_STATUSES.includes(job.status);
|
|
74
71
|
return !hasJobEnded;
|
|
75
72
|
};
|
|
76
73
|
do {
|
|
@@ -84,10 +81,10 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
84
81
|
};
|
|
85
82
|
try {
|
|
86
83
|
const response = await this.httpClient.call(requestOpts);
|
|
87
|
-
job =
|
|
84
|
+
job = parseDateFields(pluckData(response.data));
|
|
88
85
|
}
|
|
89
86
|
catch (err) {
|
|
90
|
-
|
|
87
|
+
catchNotFoundOrThrow(err);
|
|
91
88
|
job = undefined;
|
|
92
89
|
}
|
|
93
90
|
// It might take some time for database replicas to get up-to-date,
|
|
@@ -105,4 +102,3 @@ class ResourceClient extends api_client_1.ApiClient {
|
|
|
105
102
|
return job;
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
|
-
exports.ResourceClient = ResourceClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PaginatedResponse, PaginationOptions } from '../utils';
|
|
2
|
-
import { ApiClient } from './api_client';
|
|
1
|
+
import type { PaginatedResponse, PaginationOptions } from '../utils.js';
|
|
2
|
+
import { ApiClient } from './api_client.js';
|
|
3
3
|
/**
|
|
4
4
|
* Resource collection client.
|
|
5
5
|
* @private
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ResourceCollectionClient = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const api_client_1 = require("./api_client");
|
|
1
|
+
import { parseDateFields, pluckData } from '../utils.js';
|
|
2
|
+
import { ApiClient } from './api_client.js';
|
|
6
3
|
/**
|
|
7
4
|
* Resource collection client.
|
|
8
5
|
* @private
|
|
9
6
|
*/
|
|
10
|
-
class ResourceCollectionClient extends
|
|
7
|
+
export class ResourceCollectionClient extends ApiClient {
|
|
11
8
|
/**
|
|
12
9
|
* @private
|
|
13
10
|
*/
|
|
@@ -17,7 +14,7 @@ class ResourceCollectionClient extends api_client_1.ApiClient {
|
|
|
17
14
|
method: 'GET',
|
|
18
15
|
params: this._params(options),
|
|
19
16
|
});
|
|
20
|
-
return
|
|
17
|
+
return parseDateFields(pluckData(response.data));
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
23
20
|
* Returns async iterator to iterate through all items and Promise that can be awaited to get first page of results.
|
|
@@ -32,7 +29,7 @@ class ResourceCollectionClient extends api_client_1.ApiClient {
|
|
|
32
29
|
params: this._params(),
|
|
33
30
|
data: resource,
|
|
34
31
|
});
|
|
35
|
-
return
|
|
32
|
+
return parseDateFields(pluckData(response.data));
|
|
36
33
|
}
|
|
37
34
|
async _getOrCreate(name, resource) {
|
|
38
35
|
const response = await this.httpClient.call({
|
|
@@ -41,7 +38,6 @@ class ResourceCollectionClient extends api_client_1.ApiClient {
|
|
|
41
38
|
params: this._params({ name }),
|
|
42
39
|
data: resource,
|
|
43
40
|
});
|
|
44
|
-
return
|
|
41
|
+
return parseDateFields(pluckData(response.data));
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
|
-
exports.ResourceCollectionClient = ResourceCollectionClient;
|
package/dist/body_parser.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.maybeParseBody = maybeParseBody;
|
|
4
|
-
exports.isomorphicBufferToString = isomorphicBufferToString;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const content_type_1 = tslib_1.__importDefault(require("content-type"));
|
|
7
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import contentTypeParser from 'content-type';
|
|
2
|
+
import { isNode } from './utils.js';
|
|
8
3
|
const CONTENT_TYPE_JSON = 'application/json';
|
|
9
4
|
const STRINGIFIABLE_CONTENT_TYPE_RXS = [new RegExp(`^${CONTENT_TYPE_JSON}`, 'i'), /^application\/.*xml$/i, /^text\//i];
|
|
10
5
|
/**
|
|
@@ -17,11 +12,11 @@ const STRINGIFIABLE_CONTENT_TYPE_RXS = [new RegExp(`^${CONTENT_TYPE_JSON}`, 'i')
|
|
|
17
12
|
* If the header includes a charset, the body will be stringified only
|
|
18
13
|
* if the charset represents a known encoding to Node.js or Browser.
|
|
19
14
|
*/
|
|
20
|
-
function maybeParseBody(body, contentTypeHeader) {
|
|
15
|
+
export function maybeParseBody(body, contentTypeHeader) {
|
|
21
16
|
let contentType;
|
|
22
17
|
let charset;
|
|
23
18
|
try {
|
|
24
|
-
const result =
|
|
19
|
+
const result = contentTypeParser.parse(contentTypeHeader);
|
|
25
20
|
contentType = result.type;
|
|
26
21
|
charset = result.parameters.charset;
|
|
27
22
|
}
|
|
@@ -36,7 +31,7 @@ function maybeParseBody(body, contentTypeHeader) {
|
|
|
36
31
|
const dataString = isomorphicBufferToString(body, charset);
|
|
37
32
|
return contentType === CONTENT_TYPE_JSON ? JSON.parse(dataString) : dataString;
|
|
38
33
|
}
|
|
39
|
-
function isomorphicBufferToString(buffer, encoding) {
|
|
34
|
+
export function isomorphicBufferToString(buffer, encoding) {
|
|
40
35
|
if (buffer.constructor.name !== ArrayBuffer.name) {
|
|
41
36
|
return buffer.toString(encoding);
|
|
42
37
|
}
|
|
@@ -47,7 +42,7 @@ function isomorphicBufferToString(buffer, encoding) {
|
|
|
47
42
|
function isCharsetStringifiable(charset) {
|
|
48
43
|
if (!charset)
|
|
49
44
|
return true; // hope that it's utf-8
|
|
50
|
-
if (
|
|
45
|
+
if (isNode())
|
|
51
46
|
return Buffer.isEncoding(charset);
|
|
52
47
|
const normalizedCharset = charset.toLowerCase().replace('-', '');
|
|
53
48
|
// Browsers only support decoding utf-8 buffers.
|