apify-client 3.0.0-beta.10 → 3.0.0-beta.11
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.js +1 -1
- 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 +10 -0
- package/dist/resource_clients/run.js +12 -1
- 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
|
@@ -40,7 +40,7 @@ const validateInputOptionsSchema = z.strictObject({
|
|
|
40
40
|
build: z.string().optional(),
|
|
41
41
|
contentType: z.string().optional(),
|
|
42
42
|
});
|
|
43
|
-
const versionNumberSchema = z.string();
|
|
43
|
+
const versionNumberSchema = z.string().min(1);
|
|
44
44
|
const buildOptionsSchema = z.strictObject({
|
|
45
45
|
betaPackages: z.boolean().optional(),
|
|
46
46
|
tag: z.string().optional(),
|
|
@@ -4,7 +4,7 @@ import * as schemas from '../schemas.js';
|
|
|
4
4
|
import { anyObjectSchema, parseArgument } from '../utils.js';
|
|
5
5
|
import { ActorEnvVarClient } from './actor_env_var.js';
|
|
6
6
|
import { ActorEnvVarCollectionClient } from './actor_env_var_collection.js';
|
|
7
|
-
const envVarNameSchema = z.string();
|
|
7
|
+
const envVarNameSchema = z.string().min(1);
|
|
8
8
|
export { ActorSourceType } from '../models.js';
|
|
9
9
|
/**
|
|
10
10
|
* Client for managing a specific Actor version.
|
|
@@ -113,6 +113,8 @@ export declare class BuildClient extends ResourceClient {
|
|
|
113
113
|
/**
|
|
114
114
|
* Returns a client for accessing the log of this Actor build.
|
|
115
115
|
*
|
|
116
|
+
* A 404 from this client throws an `ApifyApiError`, since the build itself may be what is missing.
|
|
117
|
+
*
|
|
116
118
|
* @returns A client for accessing the build's log
|
|
117
119
|
* @see https://docs.apify.com/api/v2/actor-build-log-get
|
|
118
120
|
*
|
|
@@ -142,6 +142,8 @@ export class BuildClient extends ResourceClient {
|
|
|
142
142
|
/**
|
|
143
143
|
* Returns a client for accessing the log of this Actor build.
|
|
144
144
|
*
|
|
145
|
+
* A 404 from this client throws an `ApifyApiError`, since the build itself may be what is missing.
|
|
146
|
+
*
|
|
145
147
|
* @returns A client for accessing the build's log
|
|
146
148
|
* @see https://docs.apify.com/api/v2/actor-build-log-get
|
|
147
149
|
*
|
|
@@ -184,11 +184,11 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
|
|
|
184
184
|
* Returns statistics for each field in the dataset, including information about
|
|
185
185
|
* data types, null counts, and value ranges.
|
|
186
186
|
*
|
|
187
|
-
* @returns Dataset statistics
|
|
187
|
+
* @returns Dataset statistics
|
|
188
188
|
* @see https://docs.apify.com/api/v2/dataset-statistics-get
|
|
189
189
|
* @since Added in 2.11.2
|
|
190
190
|
*/
|
|
191
|
-
getStatistics(): Promise<DatasetStatistics
|
|
191
|
+
getStatistics(): Promise<DatasetStatistics>;
|
|
192
192
|
/**
|
|
193
193
|
* Generates a public URL for accessing dataset items.
|
|
194
194
|
*
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { createStorageContentSignatureAsync } from '@apify/utilities';
|
|
3
3
|
import { DEFAULT_TIMEOUT_MILLIS, MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS, } from '../base/resource_client.js';
|
|
4
4
|
import * as schemas from '../schemas.js';
|
|
5
|
-
import { anyObjectSchema, applyQueryParamsToUrl, cast,
|
|
5
|
+
import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, } from '../utils.js';
|
|
6
6
|
// A predicate, not a `z.object()` arm, which would walk and copy every key of every pushed item.
|
|
7
7
|
const itemSchema = z.custom(isNonArrayObject, 'Expected an object');
|
|
8
8
|
const listItemsOptionsSchema = z.strictObject({
|
|
@@ -288,25 +288,18 @@ export class DatasetClient extends ResourceClient {
|
|
|
288
288
|
* Returns statistics for each field in the dataset, including information about
|
|
289
289
|
* data types, null counts, and value ranges.
|
|
290
290
|
*
|
|
291
|
-
* @returns Dataset statistics
|
|
291
|
+
* @returns Dataset statistics
|
|
292
292
|
* @see https://docs.apify.com/api/v2/dataset-statistics-get
|
|
293
293
|
* @since Added in 2.11.2
|
|
294
294
|
*/
|
|
295
295
|
async getStatistics() {
|
|
296
|
-
const
|
|
296
|
+
const response = await this.httpClient.call({
|
|
297
297
|
url: this._url('statistics'),
|
|
298
298
|
method: 'GET',
|
|
299
299
|
params: this._params(),
|
|
300
300
|
timeout: SMALL_TIMEOUT_MILLIS,
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
const response = await this.httpClient.call(requestOpts);
|
|
304
|
-
return parseResponse(response, schemas.DatasetStatistics());
|
|
305
|
-
}
|
|
306
|
-
catch (err) {
|
|
307
|
-
catchNotFoundOrThrow(err);
|
|
308
|
-
}
|
|
309
|
-
return undefined;
|
|
301
|
+
});
|
|
302
|
+
return parseResponse(response, schemas.DatasetStatistics());
|
|
310
303
|
}
|
|
311
304
|
/**
|
|
312
305
|
* Generates a public URL for accessing dataset items.
|
|
@@ -35,7 +35,8 @@ export declare class LogClient extends ResourceClient {
|
|
|
35
35
|
*
|
|
36
36
|
* @param options - Log retrieval options.
|
|
37
37
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
38
|
-
* @returns The log content as a string, or `undefined` if it does not exist.
|
|
38
|
+
* @returns The log content as a string, or `undefined` if it does not exist. A chained client such as
|
|
39
|
+
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
39
40
|
* @see https://docs.apify.com/api/v2/log-get
|
|
40
41
|
*/
|
|
41
42
|
get(options?: LogOptions): Promise<string | undefined>;
|
|
@@ -44,7 +45,8 @@ export declare class LogClient extends ResourceClient {
|
|
|
44
45
|
*
|
|
45
46
|
* @param options - Log retrieval options.
|
|
46
47
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
47
|
-
* @returns The log content as a Readable stream, or `undefined` if it does not exist.
|
|
48
|
+
* @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
|
|
49
|
+
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
48
50
|
* @see https://docs.apify.com/api/v2/log-get
|
|
49
51
|
*/
|
|
50
52
|
stream(options?: LogOptions): Promise<Readable | undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import c from 'ansi-colors';
|
|
2
2
|
import log, { Logger, LogLevel } from '@apify/log';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
-
import { cast,
|
|
4
|
+
import { cast, catchNotFoundForResourceOrThrow } from '../utils.js';
|
|
5
5
|
/**
|
|
6
6
|
* Client for accessing Actor run or build logs.
|
|
7
7
|
*
|
|
@@ -39,7 +39,8 @@ export class LogClient extends ResourceClient {
|
|
|
39
39
|
*
|
|
40
40
|
* @param options - Log retrieval options.
|
|
41
41
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
42
|
-
* @returns The log content as a string, or `undefined` if it does not exist.
|
|
42
|
+
* @returns The log content as a string, or `undefined` if it does not exist. A chained client such as
|
|
43
|
+
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
43
44
|
* @see https://docs.apify.com/api/v2/log-get
|
|
44
45
|
*/
|
|
45
46
|
async get(options = {}) {
|
|
@@ -53,7 +54,7 @@ export class LogClient extends ResourceClient {
|
|
|
53
54
|
return cast(response.data);
|
|
54
55
|
}
|
|
55
56
|
catch (err) {
|
|
56
|
-
|
|
57
|
+
catchNotFoundForResourceOrThrow(err, this.id);
|
|
57
58
|
}
|
|
58
59
|
return undefined;
|
|
59
60
|
}
|
|
@@ -62,7 +63,8 @@ export class LogClient extends ResourceClient {
|
|
|
62
63
|
*
|
|
63
64
|
* @param options - Log retrieval options.
|
|
64
65
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
65
|
-
* @returns The log content as a Readable stream, or `undefined` if it does not exist.
|
|
66
|
+
* @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
|
|
67
|
+
* `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
66
68
|
* @see https://docs.apify.com/api/v2/log-get
|
|
67
69
|
*/
|
|
68
70
|
async stream(options = {}) {
|
|
@@ -81,7 +83,7 @@ export class LogClient extends ResourceClient {
|
|
|
81
83
|
return cast(response.data);
|
|
82
84
|
}
|
|
83
85
|
catch (err) {
|
|
84
|
-
|
|
86
|
+
catchNotFoundForResourceOrThrow(err, this.id);
|
|
85
87
|
}
|
|
86
88
|
return undefined;
|
|
87
89
|
}
|
|
@@ -166,11 +168,11 @@ export class StreamedLog {
|
|
|
166
168
|
* Get log stream from response and redirect it to another log.
|
|
167
169
|
*/
|
|
168
170
|
async streamLog() {
|
|
169
|
-
const logStream = await this.logClient.stream({ raw: true });
|
|
170
|
-
if (!logStream) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
171
|
try {
|
|
172
|
+
const logStream = await this.logClient.stream({ raw: true });
|
|
173
|
+
if (!logStream) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
174
176
|
const lastChunkRemainder = await this.logStreamChunks(logStream);
|
|
175
177
|
// Process whatever is left when exiting. Maybe it is incomplete, maybe it is last log without EOL.
|
|
176
178
|
const lastMessage = Buffer.from(lastChunkRemainder).toString().trim();
|
|
@@ -210,6 +210,8 @@ export declare class RunClient extends ResourceClient {
|
|
|
210
210
|
/**
|
|
211
211
|
* Returns a client for the default dataset of this Actor run.
|
|
212
212
|
*
|
|
213
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
214
|
+
*
|
|
213
215
|
* @returns A client for accessing the run's default dataset
|
|
214
216
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
215
217
|
*
|
|
@@ -223,6 +225,9 @@ export declare class RunClient extends ResourceClient {
|
|
|
223
225
|
/**
|
|
224
226
|
* Returns a client for the default key-value store of this Actor run.
|
|
225
227
|
*
|
|
228
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
|
|
229
|
+
* lookups such as `getRecord()` read a 404 as a missing record.
|
|
230
|
+
*
|
|
226
231
|
* @returns A client for accessing the run's default key-value store
|
|
227
232
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
228
233
|
*
|
|
@@ -236,6 +241,9 @@ export declare class RunClient extends ResourceClient {
|
|
|
236
241
|
/**
|
|
237
242
|
* Returns a client for the default Request queue of this Actor run.
|
|
238
243
|
*
|
|
244
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
245
|
+
* `getRequest()` reads a 404 as a missing request.
|
|
246
|
+
*
|
|
239
247
|
* @returns A client for accessing the run's default Request queue
|
|
240
248
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
241
249
|
*
|
|
@@ -249,6 +257,8 @@ export declare class RunClient extends ResourceClient {
|
|
|
249
257
|
/**
|
|
250
258
|
* Returns a client for accessing the log of this Actor run.
|
|
251
259
|
*
|
|
260
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
261
|
+
*
|
|
252
262
|
* @returns A client for accessing the run's log
|
|
253
263
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
254
264
|
*
|
|
@@ -315,6 +315,8 @@ export class RunClient extends ResourceClient {
|
|
|
315
315
|
/**
|
|
316
316
|
* Returns a client for the default dataset of this Actor run.
|
|
317
317
|
*
|
|
318
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
319
|
+
*
|
|
318
320
|
* @returns A client for accessing the run's default dataset
|
|
319
321
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
320
322
|
*
|
|
@@ -332,6 +334,9 @@ export class RunClient extends ResourceClient {
|
|
|
332
334
|
/**
|
|
333
335
|
* Returns a client for the default key-value store of this Actor run.
|
|
334
336
|
*
|
|
337
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
|
|
338
|
+
* lookups such as `getRecord()` read a 404 as a missing record.
|
|
339
|
+
*
|
|
335
340
|
* @returns A client for accessing the run's default key-value store
|
|
336
341
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
337
342
|
*
|
|
@@ -349,6 +354,9 @@ export class RunClient extends ResourceClient {
|
|
|
349
354
|
/**
|
|
350
355
|
* Returns a client for the default Request queue of this Actor run.
|
|
351
356
|
*
|
|
357
|
+
* `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
|
|
358
|
+
* `getRequest()` reads a 404 as a missing request.
|
|
359
|
+
*
|
|
352
360
|
* @returns A client for accessing the run's default Request queue
|
|
353
361
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
354
362
|
*
|
|
@@ -366,6 +374,8 @@ export class RunClient extends ResourceClient {
|
|
|
366
374
|
/**
|
|
367
375
|
* Returns a client for accessing the log of this Actor run.
|
|
368
376
|
*
|
|
377
|
+
* A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
|
|
378
|
+
*
|
|
369
379
|
* @returns A client for accessing the run's log
|
|
370
380
|
* @see https://docs.apify.com/api/v2/actor-run-get
|
|
371
381
|
*
|
|
@@ -398,7 +408,8 @@ export class RunClient extends ResourceClient {
|
|
|
398
408
|
const runData = await this.get();
|
|
399
409
|
const runId = runData?.id ?? '';
|
|
400
410
|
const actorId = runData?.actId ?? '';
|
|
401
|
-
|
|
411
|
+
// `apifyClient.actor()` rejects an empty ID, which is what a run that could not be read leaves here.
|
|
412
|
+
const actorData = actorId ? await this.apifyClient.actor(actorId).get() : undefined;
|
|
402
413
|
const actorName = actorData?.name ?? '';
|
|
403
414
|
const name = [actorName, `runId:${runId}`].filter(Boolean).join(' ');
|
|
404
415
|
toLog = new Log({ level: LEVELS.DEBUG, prefix: `${name} -> `, logger: new LoggerActorRedirect() });
|
|
@@ -56,10 +56,10 @@ export declare class ScheduleClient extends ResourceClient {
|
|
|
56
56
|
/**
|
|
57
57
|
* Retrieves the schedule's log.
|
|
58
58
|
*
|
|
59
|
-
* @returns The schedule log, one entry per invocation
|
|
59
|
+
* @returns The schedule log, one entry per invocation.
|
|
60
60
|
* @see https://docs.apify.com/api/v2/schedule-log-get
|
|
61
61
|
*/
|
|
62
|
-
getLog(): Promise<ScheduleInvoked[]
|
|
62
|
+
getLog(): Promise<ScheduleInvoked[]>;
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Data for creating or updating a Schedule.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ResourceClient } from '../base/resource_client.js';
|
|
3
3
|
import * as schemas from '../schemas.js';
|
|
4
|
-
import { anyObjectSchema,
|
|
4
|
+
import { anyObjectSchema, parseArgument, parseResponse } from '../utils.js';
|
|
5
5
|
export { ScheduleActions } from '../models.js';
|
|
6
6
|
const scheduleLogSchema = z.array(schemas.ScheduleInvoked());
|
|
7
7
|
/**
|
|
@@ -68,22 +68,15 @@ export class ScheduleClient extends ResourceClient {
|
|
|
68
68
|
/**
|
|
69
69
|
* Retrieves the schedule's log.
|
|
70
70
|
*
|
|
71
|
-
* @returns The schedule log, one entry per invocation
|
|
71
|
+
* @returns The schedule log, one entry per invocation.
|
|
72
72
|
* @see https://docs.apify.com/api/v2/schedule-log-get
|
|
73
73
|
*/
|
|
74
74
|
async getLog() {
|
|
75
|
-
const
|
|
75
|
+
const response = await this.httpClient.call({
|
|
76
76
|
url: this._url('log'),
|
|
77
77
|
method: 'GET',
|
|
78
78
|
params: this._params(),
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const response = await this.httpClient.call(requestOpts);
|
|
82
|
-
return parseResponse(response, scheduleLogSchema);
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
catchNotFoundOrThrow(err);
|
|
86
|
-
}
|
|
87
|
-
return undefined;
|
|
79
|
+
});
|
|
80
|
+
return parseResponse(response, scheduleLogSchema);
|
|
88
81
|
}
|
|
89
82
|
}
|
|
@@ -117,10 +117,10 @@ export declare class TaskClient extends ResourceClient {
|
|
|
117
117
|
/**
|
|
118
118
|
* Retrieves the Actor task's input object.
|
|
119
119
|
*
|
|
120
|
-
* @returns The Task's input
|
|
120
|
+
* @returns The Task's input.
|
|
121
121
|
* @see https://docs.apify.com/api/v2/actor-task-input-get
|
|
122
122
|
*/
|
|
123
|
-
getInput(): Promise<Dictionary | Dictionary[]
|
|
123
|
+
getInput(): Promise<Dictionary | Dictionary[]>;
|
|
124
124
|
/**
|
|
125
125
|
* Updates the Actor task's input object.
|
|
126
126
|
*
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { ACT_JOB_STATUSES, META_ORIGINS } from '@apify/consts';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
4
|
import * as schemas from '../schemas.js';
|
|
5
|
-
import { anyObjectSchema, cast,
|
|
5
|
+
import { anyObjectSchema, cast, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
|
|
6
6
|
import { RunClient } from './run.js';
|
|
7
7
|
import { RunCollectionClient } from './run_collection.js';
|
|
8
8
|
import { WebhookCollectionClient } from './webhook_collection.js';
|
|
@@ -194,23 +194,16 @@ export class TaskClient extends ResourceClient {
|
|
|
194
194
|
/**
|
|
195
195
|
* Retrieves the Actor task's input object.
|
|
196
196
|
*
|
|
197
|
-
* @returns The Task's input
|
|
197
|
+
* @returns The Task's input.
|
|
198
198
|
* @see https://docs.apify.com/api/v2/actor-task-input-get
|
|
199
199
|
*/
|
|
200
200
|
async getInput() {
|
|
201
|
-
const
|
|
201
|
+
const response = await this.httpClient.call({
|
|
202
202
|
url: this._url('input'),
|
|
203
203
|
method: 'GET',
|
|
204
204
|
params: this._params(),
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const response = await this.httpClient.call(requestOpts);
|
|
208
|
-
return cast(response.data);
|
|
209
|
-
}
|
|
210
|
-
catch (err) {
|
|
211
|
-
catchNotFoundOrThrow(err);
|
|
212
|
-
}
|
|
213
|
-
return undefined;
|
|
205
|
+
});
|
|
206
|
+
return cast(response.data);
|
|
214
207
|
}
|
|
215
208
|
/**
|
|
216
209
|
* Updates the Actor task's input object.
|
|
@@ -38,26 +38,26 @@ export declare class UserClient extends ResourceClient {
|
|
|
38
38
|
* Depending on whether ApifyClient was created with a token,
|
|
39
39
|
* the method will either return public or private user data.
|
|
40
40
|
*
|
|
41
|
-
* @returns The user object.
|
|
41
|
+
* @returns The user object, or `undefined` if it does not exist.
|
|
42
42
|
* @see https://docs.apify.com/api/v2/user-get
|
|
43
43
|
*/
|
|
44
|
-
get(): Promise<User>;
|
|
44
|
+
get(): Promise<User | undefined>;
|
|
45
45
|
/**
|
|
46
46
|
* Retrieves the user's monthly usage data.
|
|
47
47
|
*
|
|
48
|
-
* @returns The monthly usage object
|
|
48
|
+
* @returns The monthly usage object.
|
|
49
49
|
* @see https://docs.apify.com/api/v2/users-me-usage-monthly-get
|
|
50
50
|
* @since Added in 2.9.2
|
|
51
51
|
*/
|
|
52
|
-
monthlyUsage(): Promise<MonthlyUsage
|
|
52
|
+
monthlyUsage(): Promise<MonthlyUsage>;
|
|
53
53
|
/**
|
|
54
54
|
* Retrieves the user's account and usage limits.
|
|
55
55
|
*
|
|
56
|
-
* @returns The account and usage limits object
|
|
56
|
+
* @returns The account and usage limits object.
|
|
57
57
|
* @see https://docs.apify.com/api/v2/users-me-limits-get
|
|
58
58
|
* @since Added in 2.9.2
|
|
59
59
|
*/
|
|
60
|
-
limits(): Promise<AccountAndUsageLimits
|
|
60
|
+
limits(): Promise<AccountAndUsageLimits>;
|
|
61
61
|
/**
|
|
62
62
|
* Updates the user's account and usage limits.
|
|
63
63
|
*
|
|
@@ -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").
|