apify-client 3.0.0-beta.10 → 3.0.0-beta.12
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/dist/base/resource_client.d.ts +8 -0
- package/dist/base/resource_client.js +11 -3
- package/dist/bundle.js +7 -7
- package/dist/bundle.js.map +1 -1
- package/dist/resource_clients/actor.d.ts +20 -20
- package/dist/resource_clients/actor.js +4 -16
- package/dist/resource_clients/actor_version.js +1 -1
- package/dist/resource_clients/build.d.ts +2 -0
- package/dist/resource_clients/build.js +2 -0
- package/dist/resource_clients/dataset.d.ts +2 -2
- package/dist/resource_clients/dataset.js +5 -12
- package/dist/resource_clients/log.d.ts +4 -2
- package/dist/resource_clients/log.js +11 -9
- package/dist/resource_clients/run.d.ts +18 -4
- package/dist/resource_clients/run.js +13 -4
- package/dist/resource_clients/schedule.d.ts +2 -2
- package/dist/resource_clients/schedule.js +5 -12
- package/dist/resource_clients/task.d.ts +2 -2
- package/dist/resource_clients/task.js +5 -12
- package/dist/resource_clients/user.d.ts +6 -6
- package/dist/resource_clients/user.js +11 -25
- package/dist/resource_clients/webhook.d.ts +2 -2
- package/dist/resource_clients/webhook.js +5 -12
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +12 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
2
|
import * as schemas from '../schemas.js';
|
|
3
|
-
import {
|
|
3
|
+
import { parseResponse } from '../utils.js';
|
|
4
4
|
export { PlatformFeature } from '../models.js';
|
|
5
5
|
/**
|
|
6
6
|
* Client for managing user account information.
|
|
@@ -42,7 +42,7 @@ export class UserClient extends ResourceClient {
|
|
|
42
42
|
* Depending on whether ApifyClient was created with a token,
|
|
43
43
|
* the method will either return public or private user data.
|
|
44
44
|
*
|
|
45
|
-
* @returns The user object.
|
|
45
|
+
* @returns The user object, or `undefined` if it does not exist.
|
|
46
46
|
* @see https://docs.apify.com/api/v2/user-get
|
|
47
47
|
*/
|
|
48
48
|
async get() {
|
|
@@ -51,47 +51,33 @@ export class UserClient extends ResourceClient {
|
|
|
51
51
|
/**
|
|
52
52
|
* Retrieves the user's monthly usage data.
|
|
53
53
|
*
|
|
54
|
-
* @returns The monthly usage object
|
|
54
|
+
* @returns The monthly usage object.
|
|
55
55
|
* @see https://docs.apify.com/api/v2/users-me-usage-monthly-get
|
|
56
56
|
* @since Added in 2.9.2
|
|
57
57
|
*/
|
|
58
58
|
async monthlyUsage() {
|
|
59
|
-
const
|
|
59
|
+
const response = await this.httpClient.call({
|
|
60
60
|
url: this._url('usage/monthly'),
|
|
61
61
|
method: 'GET',
|
|
62
62
|
params: this._params(),
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// `dailyServiceUsages[].date` does not end in `At`, so it has to be named for `parseDateFields`.
|
|
67
|
-
return parseResponse(response, schemas.MonthlyUsage(), (key) => key === 'date');
|
|
68
|
-
}
|
|
69
|
-
catch (err) {
|
|
70
|
-
catchNotFoundOrThrow(err);
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
63
|
+
});
|
|
64
|
+
// `dailyServiceUsages[].date` does not end in `At`, so it has to be named for `parseDateFields`.
|
|
65
|
+
return parseResponse(response, schemas.MonthlyUsage(), (key) => key === 'date');
|
|
73
66
|
}
|
|
74
67
|
/**
|
|
75
68
|
* Retrieves the user's account and usage limits.
|
|
76
69
|
*
|
|
77
|
-
* @returns The account and usage limits object
|
|
70
|
+
* @returns The account and usage limits object.
|
|
78
71
|
* @see https://docs.apify.com/api/v2/users-me-limits-get
|
|
79
72
|
* @since Added in 2.9.2
|
|
80
73
|
*/
|
|
81
74
|
async limits() {
|
|
82
|
-
const
|
|
75
|
+
const response = await this.httpClient.call({
|
|
83
76
|
url: this._url('limits'),
|
|
84
77
|
method: 'GET',
|
|
85
78
|
params: this._params(),
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const response = await this.httpClient.call(requestOpts);
|
|
89
|
-
return parseResponse(response, schemas.AccountLimits());
|
|
90
|
-
}
|
|
91
|
-
catch (err) {
|
|
92
|
-
catchNotFoundOrThrow(err);
|
|
93
|
-
}
|
|
94
|
-
return undefined;
|
|
79
|
+
});
|
|
80
|
+
return parseResponse(response, schemas.AccountLimits());
|
|
95
81
|
}
|
|
96
82
|
/**
|
|
97
83
|
* Updates the user's account and usage limits.
|
|
@@ -61,10 +61,10 @@ export declare class WebhookClient extends ResourceClient {
|
|
|
61
61
|
/**
|
|
62
62
|
* Tests the webhook by dispatching a test event.
|
|
63
63
|
*
|
|
64
|
-
* @returns The webhook dispatch object
|
|
64
|
+
* @returns The webhook dispatch object.
|
|
65
65
|
* @see https://docs.apify.com/api/v2/webhook-test-post
|
|
66
66
|
*/
|
|
67
|
-
test(): Promise<WebhookDispatch
|
|
67
|
+
test(): Promise<WebhookDispatch>;
|
|
68
68
|
/**
|
|
69
69
|
* Returns a client for the dispatches of this webhook.
|
|
70
70
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ResourceClient } from '../base/resource_client.js';
|
|
2
2
|
import * as schemas from '../schemas.js';
|
|
3
|
-
import { anyObjectSchema,
|
|
3
|
+
import { anyObjectSchema, parseArgument, parseResponse } from '../utils.js';
|
|
4
4
|
import { WebhookDispatchCollectionClient } from './webhook_dispatch_collection.js';
|
|
5
5
|
/**
|
|
6
6
|
* Client for managing a specific webhook.
|
|
@@ -71,23 +71,16 @@ export class WebhookClient extends ResourceClient {
|
|
|
71
71
|
/**
|
|
72
72
|
* Tests the webhook by dispatching a test event.
|
|
73
73
|
*
|
|
74
|
-
* @returns The webhook dispatch object
|
|
74
|
+
* @returns The webhook dispatch object.
|
|
75
75
|
* @see https://docs.apify.com/api/v2/webhook-test-post
|
|
76
76
|
*/
|
|
77
77
|
async test() {
|
|
78
|
-
const
|
|
78
|
+
const response = await this.httpClient.call({
|
|
79
79
|
url: this._url('test'),
|
|
80
80
|
method: 'POST',
|
|
81
81
|
params: this._params(),
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const response = await this.httpClient.call(request);
|
|
85
|
-
return parseResponse(response, schemas.WebhookDispatch());
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
catchNotFoundOrThrow(err);
|
|
89
|
-
}
|
|
90
|
-
return undefined;
|
|
82
|
+
});
|
|
83
|
+
return parseResponse(response, schemas.WebhookDispatch());
|
|
91
84
|
}
|
|
92
85
|
/**
|
|
93
86
|
* Returns a client for the dispatches of this webhook.
|
package/dist/utils.d.ts
CHANGED
|
@@ -47,6 +47,14 @@ export declare function pluckData<R>(obj: MaybeData<R>): R;
|
|
|
47
47
|
* Swallows a 404 Not Found API error and rethrows anything else.
|
|
48
48
|
*/
|
|
49
49
|
export declare function catchNotFoundOrThrow(err: ApifyApiError): void;
|
|
50
|
+
/**
|
|
51
|
+
* Like `catchNotFoundOrThrow()`, but swallows the 404 only when the client names its resource by ID.
|
|
52
|
+
*
|
|
53
|
+
* A chained client without an ID, such as `run.dataset()` or `run.log()`, requests a path where a 404 can mean either
|
|
54
|
+
* the parent or the default sub-resource is missing. The response cannot tell the two apart, so the error propagates.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare function catchNotFoundForResourceOrThrow(err: ApifyApiError, resourceId: string | undefined): void;
|
|
50
58
|
type ReturnJsonValue = string | number | boolean | null | Date | ReturnJsonObject | ReturnJsonArray;
|
|
51
59
|
type ReturnJsonObject = {
|
|
52
60
|
[Key in string]?: ReturnJsonValue;
|
package/dist/utils.js
CHANGED
|
@@ -63,6 +63,18 @@ export function catchNotFoundOrThrow(err) {
|
|
|
63
63
|
if (!(err instanceof NotFoundError))
|
|
64
64
|
throw err;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Like `catchNotFoundOrThrow()`, but swallows the 404 only when the client names its resource by ID.
|
|
68
|
+
*
|
|
69
|
+
* A chained client without an ID, such as `run.dataset()` or `run.log()`, requests a path where a 404 can mean either
|
|
70
|
+
* the parent or the default sub-resource is missing. The response cannot tell the two apart, so the error propagates.
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export function catchNotFoundForResourceOrThrow(err, resourceId) {
|
|
74
|
+
if (!resourceId)
|
|
75
|
+
throw err;
|
|
76
|
+
catchNotFoundOrThrow(err);
|
|
77
|
+
}
|
|
66
78
|
/**
|
|
67
79
|
* Traverses JSON structure and converts fields that end with "At" to a Date object (fields such as "modifiedAt" or
|
|
68
80
|
* "createdAt").
|