apify-client 3.0.0-beta.1 → 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/README.md +5 -3
- package/dist/apify_api_error.d.ts +59 -3
- package/dist/apify_api_error.js +71 -11
- package/dist/apify_client.d.ts +27 -27
- package/dist/apify_client.js +86 -91
- package/dist/base/api_client.d.ts +3 -3
- package/dist/base/api_client.js +6 -10
- package/dist/base/resource_client.d.ts +13 -4
- package/dist/base/resource_client.js +25 -21
- package/dist/base/resource_collection_client.d.ts +7 -6
- package/dist/base/resource_collection_client.js +11 -15
- package/dist/body_parser.js +6 -11
- package/dist/bundle.js +38 -48
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +287 -214
- package/dist/generated/api.js +1 -2
- package/dist/generated/schemas.d.ts +6699 -0
- package/dist/generated/schemas.js +1521 -0
- package/dist/http_client.d.ts +2 -2
- package/dist/http_client.js +23 -28
- package/dist/index.d.ts +33 -32
- package/dist/index.js +32 -36
- package/dist/interceptors.d.ts +1 -1
- package/dist/interceptors.js +14 -19
- package/dist/lazy_schema.d.ts +8 -0
- package/dist/lazy_schema.js +11 -0
- package/dist/models.d.ts +33 -52
- package/dist/models.js +8 -11
- package/dist/resource_clients/actor.d.ts +13 -13
- package/dist/resource_clients/actor.js +70 -73
- package/dist/resource_clients/actor_collection.d.ts +10 -10
- package/dist/resource_clients/actor_collection.js +19 -20
- package/dist/resource_clients/actor_env_var.d.ts +3 -3
- package/dist/resource_clients/actor_env_var.js +7 -10
- package/dist/resource_clients/actor_env_var_collection.d.ts +11 -20
- package/dist/resource_clients/actor_env_var_collection.js +15 -19
- package/dist/resource_clients/actor_version.d.ts +16 -8
- package/dist/resource_clients/actor_version.js +15 -19
- package/dist/resource_clients/actor_version_collection.d.ts +13 -19
- package/dist/resource_clients/actor_version_collection.js +17 -19
- package/dist/resource_clients/build.d.ts +7 -5
- package/dist/resource_clients/build.js +16 -17
- package/dist/resource_clients/build_collection.d.ts +5 -5
- package/dist/resource_clients/build_collection.js +10 -13
- package/dist/resource_clients/dataset.d.ts +8 -8
- package/dist/resource_clients/dataset.js +75 -85
- package/dist/resource_clients/dataset_collection.d.ts +4 -4
- package/dist/resource_clients/dataset_collection.js +18 -21
- package/dist/resource_clients/key_value_store.d.ts +16 -8
- package/dist/resource_clients/key_value_store.js +61 -65
- package/dist/resource_clients/key_value_store_collection.d.ts +4 -4
- package/dist/resource_clients/key_value_store_collection.js +18 -21
- package/dist/resource_clients/log.d.ts +6 -4
- package/dist/resource_clients/log.js +23 -28
- package/dist/resource_clients/request_queue.d.ts +4 -11
- package/dist/resource_clients/request_queue.js +100 -106
- package/dist/resource_clients/request_queue_collection.d.ts +4 -4
- package/dist/resource_clients/request_queue_collection.js +16 -19
- package/dist/resource_clients/run.d.ts +18 -8
- package/dist/resource_clients/run.js +62 -54
- package/dist/resource_clients/run_collection.d.ts +4 -4
- package/dist/resource_clients/run_collection.js +15 -18
- package/dist/resource_clients/schedule.d.ts +8 -8
- package/dist/resource_clients/schedule.js +14 -23
- package/dist/resource_clients/schedule_collection.d.ts +4 -4
- package/dist/resource_clients/schedule_collection.js +13 -16
- package/dist/resource_clients/store_collection.d.ts +5 -5
- package/dist/resource_clients/store_collection.js +15 -18
- package/dist/resource_clients/task.d.ts +11 -11
- package/dist/resource_clients/task.js +49 -59
- package/dist/resource_clients/task_collection.d.ts +6 -6
- package/dist/resource_clients/task_collection.js +12 -15
- package/dist/resource_clients/user.d.ts +11 -11
- package/dist/resource_clients/user.js +16 -35
- package/dist/resource_clients/webhook.d.ts +8 -8
- package/dist/resource_clients/webhook.js +13 -23
- package/dist/resource_clients/webhook_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_collection.js +13 -16
- package/dist/resource_clients/webhook_dispatch.d.ts +5 -5
- package/dist/resource_clients/webhook_dispatch.js +5 -9
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_dispatch_collection.js +10 -13
- package/dist/response_validation_error.d.ts +26 -0
- package/dist/response_validation_error.js +37 -0
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.js +15 -0
- package/dist/statistics.js +5 -9
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +27 -24
- package/dist/utils.js +69 -93
- package/package.json +38 -40
- package/dist/argument_validation_error.d.ts +0 -17
- package/dist/argument_validation_error.js +0 -157
- package/dist/index.mjs +0 -42
|
@@ -1,51 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
collection: zod_1.z.string().optional(),
|
|
14
|
-
prefix: zod_1.z.string().optional(),
|
|
15
|
-
signature: zod_1.z.string().optional(),
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import log from '@apify/log';
|
|
3
|
+
import { createHmacSignatureAsync, createStorageContentSignatureAsync } from '@apify/utilities';
|
|
4
|
+
import { DEFAULT_TIMEOUT_MILLIS, MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS, } from '../base/resource_client.js';
|
|
5
|
+
import * as schemas from '../schemas.js';
|
|
6
|
+
import { anyObjectSchema, applyQueryParamsToUrl, catchNotFoundOrThrow, isBuffer, isNode, isStream, parseArgument, parseResponse, } from '../utils.js';
|
|
7
|
+
const listKeysOptionsSchema = z.strictObject({
|
|
8
|
+
limit: z.number().min(0).optional(),
|
|
9
|
+
exclusiveStartKey: z.string().optional(),
|
|
10
|
+
collection: z.string().optional(),
|
|
11
|
+
prefix: z.string().optional(),
|
|
12
|
+
signature: z.string().optional(),
|
|
16
13
|
});
|
|
17
|
-
const nonEmptyKeySchema =
|
|
14
|
+
const nonEmptyKeySchema = z.string().min(1);
|
|
18
15
|
// `signature` is left out - this method produces one. The options type omits it to match.
|
|
19
|
-
const createKeysPublicUrlOptionsSchema =
|
|
20
|
-
limit:
|
|
21
|
-
exclusiveStartKey:
|
|
22
|
-
collection:
|
|
23
|
-
prefix:
|
|
24
|
-
expiresInSecs:
|
|
16
|
+
const createKeysPublicUrlOptionsSchema = z.strictObject({
|
|
17
|
+
limit: z.number().min(0).optional(),
|
|
18
|
+
exclusiveStartKey: z.string().optional(),
|
|
19
|
+
collection: z.string().optional(),
|
|
20
|
+
prefix: z.string().optional(),
|
|
21
|
+
expiresInSecs: z.number().optional(),
|
|
25
22
|
});
|
|
26
|
-
const keySchema =
|
|
27
|
-
const getRecordOptionsSchema =
|
|
28
|
-
buffer:
|
|
29
|
-
stream:
|
|
30
|
-
disableRedirect:
|
|
31
|
-
signature:
|
|
23
|
+
const keySchema = z.string();
|
|
24
|
+
const getRecordOptionsSchema = z.strictObject({
|
|
25
|
+
buffer: z.boolean().optional(),
|
|
26
|
+
stream: z.boolean().optional(),
|
|
27
|
+
disableRedirect: z.boolean().optional(),
|
|
28
|
+
signature: z.string().optional(),
|
|
32
29
|
});
|
|
33
|
-
const recordSchema =
|
|
34
|
-
key:
|
|
30
|
+
const recordSchema = z.strictObject({
|
|
31
|
+
key: z.string(),
|
|
35
32
|
// Values are arbitrary, and a `z.object()` arm would walk every key of a large buffer.
|
|
36
33
|
// Symbols, bigints, functions and non-finite numbers are rejected because they cannot be serialized
|
|
37
34
|
// to JSON - symbols and bigints throw, functions stringify to `undefined` (an empty request body),
|
|
38
35
|
// and `NaN` / `Infinity` would silently become `null`.
|
|
39
|
-
value:
|
|
36
|
+
value: z.custom((value) => value !== undefined &&
|
|
40
37
|
typeof value !== 'symbol' &&
|
|
41
38
|
typeof value !== 'bigint' &&
|
|
42
39
|
typeof value !== 'function' &&
|
|
43
|
-
(typeof value !== 'number' || Number.isFinite(value)), 'Expected a
|
|
44
|
-
contentType:
|
|
40
|
+
(typeof value !== 'number' || Number.isFinite(value)), 'Expected a JSON-serializable value, binary data, or a stream'),
|
|
41
|
+
contentType: z.string().min(1).optional(),
|
|
45
42
|
});
|
|
46
|
-
const recordOptionsSchema =
|
|
47
|
-
timeoutSecs:
|
|
48
|
-
doNotRetryTimeouts:
|
|
43
|
+
const recordOptionsSchema = z.strictObject({
|
|
44
|
+
timeoutSecs: z.number().optional(),
|
|
45
|
+
doNotRetryTimeouts: z.boolean().optional(),
|
|
49
46
|
});
|
|
50
47
|
/**
|
|
51
48
|
* Client for managing a specific key-value store.
|
|
@@ -75,7 +72,7 @@ const recordOptionsSchema = zod_1.z.strictObject({
|
|
|
75
72
|
*
|
|
76
73
|
* @see https://docs.apify.com/platform/storage/key-value-store
|
|
77
74
|
*/
|
|
78
|
-
class KeyValueStoreClient extends
|
|
75
|
+
export class KeyValueStoreClient extends ResourceClient {
|
|
79
76
|
/**
|
|
80
77
|
* @hidden
|
|
81
78
|
*/
|
|
@@ -92,7 +89,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
92
89
|
* @see https://docs.apify.com/api/v2/key-value-store-get
|
|
93
90
|
*/
|
|
94
91
|
async get() {
|
|
95
|
-
return this._get({},
|
|
92
|
+
return this._get(schemas.KeyValueStore(), {}, SMALL_TIMEOUT_MILLIS);
|
|
96
93
|
}
|
|
97
94
|
/**
|
|
98
95
|
* Updates the key-value store with specified fields.
|
|
@@ -105,8 +102,8 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
105
102
|
* @see https://docs.apify.com/api/v2/key-value-store-put
|
|
106
103
|
*/
|
|
107
104
|
async update(newFields) {
|
|
108
|
-
|
|
109
|
-
return this._update(newFields,
|
|
105
|
+
parseArgument(newFields, anyObjectSchema);
|
|
106
|
+
return this._update(schemas.KeyValueStore(), newFields, DEFAULT_TIMEOUT_MILLIS);
|
|
110
107
|
}
|
|
111
108
|
/**
|
|
112
109
|
* Deletes the key-value store.
|
|
@@ -114,7 +111,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
114
111
|
* @see https://docs.apify.com/api/v2/key-value-store-delete
|
|
115
112
|
*/
|
|
116
113
|
async delete() {
|
|
117
|
-
return this._delete(
|
|
114
|
+
return this._delete(SMALL_TIMEOUT_MILLIS);
|
|
118
115
|
}
|
|
119
116
|
/**
|
|
120
117
|
* Lists all keys in the key-value store.
|
|
@@ -152,15 +149,15 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
152
149
|
* ```
|
|
153
150
|
*/
|
|
154
151
|
listKeys(options = {}) {
|
|
155
|
-
const parsed =
|
|
152
|
+
const parsed = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
|
|
156
153
|
const getPaginatedList = async (kvsListOptions = {}) => {
|
|
157
154
|
const response = await this.httpClient.call({
|
|
158
155
|
url: this._url('keys'),
|
|
159
156
|
method: 'GET',
|
|
160
157
|
params: this._params(kvsListOptions),
|
|
161
|
-
timeout:
|
|
158
|
+
timeout: MEDIUM_TIMEOUT_MILLIS,
|
|
162
159
|
});
|
|
163
|
-
return (
|
|
160
|
+
return parseResponse(response, schemas.ListOfKeys());
|
|
164
161
|
};
|
|
165
162
|
const paginatedListPromise = getPaginatedList(parsed);
|
|
166
163
|
async function* asyncGenerator() {
|
|
@@ -208,11 +205,11 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
208
205
|
* @since Added in 2.14.0
|
|
209
206
|
*/
|
|
210
207
|
async getRecordPublicUrl(key) {
|
|
211
|
-
|
|
208
|
+
parseArgument(key, nonEmptyKeySchema);
|
|
212
209
|
const store = await this.get();
|
|
213
210
|
const recordPublicUrl = new URL(this._publicUrl(['records', key]));
|
|
214
211
|
if (store?.urlSigningSecretKey) {
|
|
215
|
-
const signature = await
|
|
212
|
+
const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
|
|
216
213
|
recordPublicUrl.searchParams.append('signature', signature);
|
|
217
214
|
}
|
|
218
215
|
return recordPublicUrl.toString();
|
|
@@ -241,19 +238,19 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
241
238
|
* @since Added in 2.13.0
|
|
242
239
|
*/
|
|
243
240
|
async createKeysPublicUrl(options = {}) {
|
|
244
|
-
const parsed =
|
|
241
|
+
const parsed = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
|
|
245
242
|
const store = await this.get();
|
|
246
243
|
const { expiresInSecs, ...queryOptions } = parsed;
|
|
247
244
|
let createdPublicKeysUrl = new URL(this._publicUrl('keys'));
|
|
248
245
|
if (store?.urlSigningSecretKey) {
|
|
249
|
-
const signature = await
|
|
246
|
+
const signature = await createStorageContentSignatureAsync({
|
|
250
247
|
resourceId: store.id,
|
|
251
248
|
urlSigningSecretKey: store.urlSigningSecretKey,
|
|
252
249
|
expiresInMillis: expiresInSecs ? expiresInSecs * 1000 : undefined,
|
|
253
250
|
});
|
|
254
251
|
createdPublicKeysUrl.searchParams.set('signature', signature);
|
|
255
252
|
}
|
|
256
|
-
createdPublicKeysUrl =
|
|
253
|
+
createdPublicKeysUrl = applyQueryParamsToUrl(createdPublicKeysUrl, queryOptions);
|
|
257
254
|
return createdPublicKeysUrl.toString();
|
|
258
255
|
}
|
|
259
256
|
/**
|
|
@@ -285,18 +282,18 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
285
282
|
return true;
|
|
286
283
|
}
|
|
287
284
|
catch (err) {
|
|
288
|
-
|
|
285
|
+
catchNotFoundOrThrow(err);
|
|
289
286
|
}
|
|
290
287
|
return false;
|
|
291
288
|
}
|
|
292
289
|
async getRecord(key, options = {}) {
|
|
293
|
-
|
|
294
|
-
const parsed =
|
|
295
|
-
if (parsed.stream && !
|
|
290
|
+
parseArgument(key, keySchema);
|
|
291
|
+
const parsed = parseArgument(options, getRecordOptionsSchema, 'KeyValueClientGetRecordOptions');
|
|
292
|
+
if (parsed.stream && !isNode()) {
|
|
296
293
|
throw new Error('The stream option can only be used in Node.js environment.');
|
|
297
294
|
}
|
|
298
295
|
if ('disableRedirect' in parsed) {
|
|
299
|
-
|
|
296
|
+
log.deprecated('The disableRedirect option for getRecord() is deprecated. ' +
|
|
300
297
|
'It has no effect and will be removed in the following major release.');
|
|
301
298
|
}
|
|
302
299
|
const queryParams = { attachment: 'true' };
|
|
@@ -306,7 +303,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
306
303
|
url: this._url(['records', key]),
|
|
307
304
|
method: 'GET',
|
|
308
305
|
params: this._params(queryParams),
|
|
309
|
-
timeout:
|
|
306
|
+
timeout: DEFAULT_TIMEOUT_MILLIS,
|
|
310
307
|
};
|
|
311
308
|
if (parsed.buffer)
|
|
312
309
|
requestOpts.forceBuffer = true;
|
|
@@ -321,7 +318,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
321
318
|
};
|
|
322
319
|
}
|
|
323
320
|
catch (err) {
|
|
324
|
-
|
|
321
|
+
catchNotFoundOrThrow(err);
|
|
325
322
|
}
|
|
326
323
|
return undefined;
|
|
327
324
|
}
|
|
@@ -338,11 +335,11 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
338
335
|
*
|
|
339
336
|
* @param record - The record to store
|
|
340
337
|
* @param record.key - Record key (unique identifier)
|
|
341
|
-
* @param record.value - Record value (
|
|
338
|
+
* @param record.value - Record value (a JSON-serializable value, Buffer, ArrayBuffer, typed array, or Readable)
|
|
342
339
|
* @param record.contentType - Optional MIME type. Auto-detected if not provided:
|
|
343
340
|
* - Objects: `'application/json; charset=utf-8'`
|
|
344
341
|
* - Strings: `'text/plain; charset=utf-8'`
|
|
345
|
-
* -
|
|
342
|
+
* - Binary values and streams: `'application/octet-stream'`
|
|
346
343
|
* @param options - Storage options
|
|
347
344
|
* @param options.timeoutSecs - Timeout for the upload in seconds. Default varies by value size.
|
|
348
345
|
* @param options.doNotRetryTimeouts - If `true`, don't retry on timeout errors. Default is `false`.
|
|
@@ -373,12 +370,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
373
370
|
* ```
|
|
374
371
|
*/
|
|
375
372
|
async setRecord(record, options = {}) {
|
|
376
|
-
|
|
377
|
-
const parsed =
|
|
373
|
+
parseArgument(record, recordSchema);
|
|
374
|
+
const parsed = parseArgument(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
|
|
378
375
|
const { key } = record;
|
|
379
376
|
let { value, contentType } = record;
|
|
380
377
|
const { timeoutSecs, doNotRetryTimeouts } = parsed;
|
|
381
|
-
const isValueStreamOrBuffer =
|
|
378
|
+
const isValueStreamOrBuffer = isStream(value) || isBuffer(value);
|
|
382
379
|
// To allow saving Objects to JSON without providing content type
|
|
383
380
|
if (!contentType) {
|
|
384
381
|
if (isValueStreamOrBuffer)
|
|
@@ -405,7 +402,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
405
402
|
data: value,
|
|
406
403
|
headers: contentType ? { 'content-type': contentType } : undefined,
|
|
407
404
|
doNotRetryTimeouts,
|
|
408
|
-
timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 :
|
|
405
|
+
timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 : DEFAULT_TIMEOUT_MILLIS,
|
|
409
406
|
};
|
|
410
407
|
await this.httpClient.call(uploadOpts);
|
|
411
408
|
}
|
|
@@ -421,13 +418,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
421
418
|
* ```
|
|
422
419
|
*/
|
|
423
420
|
async deleteRecord(key) {
|
|
424
|
-
|
|
421
|
+
parseArgument(key, keySchema);
|
|
425
422
|
await this.httpClient.call({
|
|
426
423
|
url: this._url(['records', key]),
|
|
427
424
|
method: 'DELETE',
|
|
428
425
|
params: this._params(),
|
|
429
|
-
timeout:
|
|
426
|
+
timeout: SMALL_TIMEOUT_MILLIS,
|
|
430
427
|
});
|
|
431
428
|
}
|
|
432
429
|
}
|
|
433
|
-
exports.KeyValueStoreClient = KeyValueStoreClient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
2
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
3
|
-
import { ResourceCollectionClient } from '../base/resource_collection_client';
|
|
4
|
-
import type { PaginatedList, PaginationOptions } from '../utils';
|
|
5
|
-
import type { KeyValueStore } from './key_value_store';
|
|
2
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
|
+
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import type { PaginatedList, PaginationOptions } from '../utils.js';
|
|
5
|
+
import type { KeyValueStore } from './key_value_store.js';
|
|
6
6
|
/**
|
|
7
7
|
* Client for managing the collection of Key-value stores in your account.
|
|
8
8
|
*
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
desc: zod_1.z.boolean().optional(),
|
|
12
|
-
ownership: zod_1.z.enum(consts_1.STORAGE_OWNERSHIP_FILTER).optional(),
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
3
|
+
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
|
+
import * as schemas from '../schemas.js';
|
|
5
|
+
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
6
|
+
const listOptionsSchema = z.strictObject({
|
|
7
|
+
unnamed: z.boolean().optional(),
|
|
8
|
+
...paginationOptionsShape,
|
|
9
|
+
desc: z.boolean().optional(),
|
|
10
|
+
ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
|
|
13
11
|
});
|
|
14
|
-
const nameSchema =
|
|
15
|
-
const schemaSchema =
|
|
12
|
+
const nameSchema = z.string().optional();
|
|
13
|
+
const schemaSchema = anyObjectSchema.optional();
|
|
16
14
|
/**
|
|
17
15
|
* Client for managing the collection of Key-value stores in your account.
|
|
18
16
|
*
|
|
@@ -33,7 +31,7 @@ const schemaSchema = utils_1.anyObjectSchema.optional();
|
|
|
33
31
|
*
|
|
34
32
|
* @see https://docs.apify.com/platform/storage/key-value-store
|
|
35
33
|
*/
|
|
36
|
-
class KeyValueStoreCollectionClient extends
|
|
34
|
+
export class KeyValueStoreCollectionClient extends ResourceCollectionClient {
|
|
37
35
|
/**
|
|
38
36
|
* @hidden
|
|
39
37
|
*/
|
|
@@ -64,8 +62,8 @@ class KeyValueStoreCollectionClient extends resource_collection_client_1.Resourc
|
|
|
64
62
|
* @see https://docs.apify.com/api/v2/key-value-stores-get
|
|
65
63
|
*/
|
|
66
64
|
list(options = {}) {
|
|
67
|
-
const parsed =
|
|
68
|
-
return this._listPaginated(parsed);
|
|
65
|
+
const parsed = parseArgument(options, listOptionsSchema, 'KeyValueStoreCollectionClientListOptions');
|
|
66
|
+
return this._listPaginated(schemas.ListOfKeyValueStores(), parsed);
|
|
69
67
|
}
|
|
70
68
|
/**
|
|
71
69
|
* Gets or creates a key-value store with the specified name.
|
|
@@ -76,9 +74,8 @@ class KeyValueStoreCollectionClient extends resource_collection_client_1.Resourc
|
|
|
76
74
|
* @see https://docs.apify.com/api/v2/key-value-stores-post
|
|
77
75
|
*/
|
|
78
76
|
async getOrCreate(name, options) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return this._getOrCreate(name, options);
|
|
77
|
+
parseArgument(name, nameSchema);
|
|
78
|
+
parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
|
|
79
|
+
return this._getOrCreate(schemas.KeyValueStore(), name, options);
|
|
82
80
|
}
|
|
83
81
|
}
|
|
84
|
-
exports.KeyValueStoreCollectionClient = KeyValueStoreCollectionClient;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
2
|
import type { Log } from '@apify/log';
|
|
3
3
|
import { Logger, LogLevel } from '@apify/log';
|
|
4
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
5
|
-
import { ResourceClient } from '../base/resource_client';
|
|
4
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
5
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
6
6
|
/**
|
|
7
7
|
* Client for accessing Actor run or build logs.
|
|
8
8
|
*
|
|
@@ -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,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
6
|
-
const log_1 = tslib_1.__importStar(require("@apify/log"));
|
|
7
|
-
const resource_client_1 = require("../base/resource_client");
|
|
8
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import c from 'ansi-colors';
|
|
2
|
+
import log, { Logger, LogLevel } from '@apify/log';
|
|
3
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
+
import { cast, catchNotFoundForResourceOrThrow } from '../utils.js';
|
|
9
5
|
/**
|
|
10
6
|
* Client for accessing Actor run or build logs.
|
|
11
7
|
*
|
|
@@ -28,7 +24,7 @@ const utils_1 = require("../utils");
|
|
|
28
24
|
*
|
|
29
25
|
* @see https://docs.apify.com/platform/actors/running/runs-and-builds#logging
|
|
30
26
|
*/
|
|
31
|
-
class LogClient extends
|
|
27
|
+
export class LogClient extends ResourceClient {
|
|
32
28
|
/**
|
|
33
29
|
* @hidden
|
|
34
30
|
*/
|
|
@@ -43,7 +39,8 @@ class LogClient extends resource_client_1.ResourceClient {
|
|
|
43
39
|
*
|
|
44
40
|
* @param options - Log retrieval options.
|
|
45
41
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
46
|
-
* @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.
|
|
47
44
|
* @see https://docs.apify.com/api/v2/log-get
|
|
48
45
|
*/
|
|
49
46
|
async get(options = {}) {
|
|
@@ -54,10 +51,10 @@ class LogClient extends resource_client_1.ResourceClient {
|
|
|
54
51
|
};
|
|
55
52
|
try {
|
|
56
53
|
const response = await this.httpClient.call(requestOpts);
|
|
57
|
-
return
|
|
54
|
+
return cast(response.data);
|
|
58
55
|
}
|
|
59
56
|
catch (err) {
|
|
60
|
-
(
|
|
57
|
+
catchNotFoundForResourceOrThrow(err, this.id);
|
|
61
58
|
}
|
|
62
59
|
return undefined;
|
|
63
60
|
}
|
|
@@ -66,7 +63,8 @@ class LogClient extends resource_client_1.ResourceClient {
|
|
|
66
63
|
*
|
|
67
64
|
* @param options - Log retrieval options.
|
|
68
65
|
* @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
|
|
69
|
-
* @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.
|
|
70
68
|
* @see https://docs.apify.com/api/v2/log-get
|
|
71
69
|
*/
|
|
72
70
|
async stream(options = {}) {
|
|
@@ -82,22 +80,21 @@ class LogClient extends resource_client_1.ResourceClient {
|
|
|
82
80
|
};
|
|
83
81
|
try {
|
|
84
82
|
const response = await this.httpClient.call(requestOpts);
|
|
85
|
-
return
|
|
83
|
+
return cast(response.data);
|
|
86
84
|
}
|
|
87
85
|
catch (err) {
|
|
88
|
-
(
|
|
86
|
+
catchNotFoundForResourceOrThrow(err, this.id);
|
|
89
87
|
}
|
|
90
88
|
return undefined;
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
|
-
exports.LogClient = LogClient;
|
|
94
91
|
/**
|
|
95
92
|
* Logger for redirected actor logs.
|
|
96
93
|
* @since Added in 2.20.0
|
|
97
94
|
*/
|
|
98
|
-
class LoggerActorRedirect extends
|
|
95
|
+
export class LoggerActorRedirect extends Logger {
|
|
99
96
|
constructor(options = {}) {
|
|
100
|
-
super({ skipTime: true, level:
|
|
97
|
+
super({ skipTime: true, level: LogLevel.DEBUG, ...options });
|
|
101
98
|
}
|
|
102
99
|
_log(level, message, data, exception, opts = {}) {
|
|
103
100
|
if (level > this.options.level) {
|
|
@@ -112,19 +109,18 @@ class LoggerActorRedirect extends log_1.Logger {
|
|
|
112
109
|
if (!this.options.skipTime) {
|
|
113
110
|
maybeDate = `${new Date().toISOString().replace('Z', '').replace('T', ' ')} `;
|
|
114
111
|
}
|
|
115
|
-
const line = `${
|
|
112
|
+
const line = `${c.gray(maybeDate)}${c.cyan(prefix)}${message || ''}`;
|
|
116
113
|
// All redirected logs are logged at info level to avid any console specific formating for non-info levels,
|
|
117
114
|
// which have already been applied once to the original log. (For example error stack traces etc.)
|
|
118
|
-
this._outputWithConsole(
|
|
115
|
+
this._outputWithConsole(LogLevel.INFO, line);
|
|
119
116
|
return line;
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
|
-
exports.LoggerActorRedirect = LoggerActorRedirect;
|
|
123
119
|
/**
|
|
124
120
|
* Helper class for redirecting streamed Actor logs to another log.
|
|
125
121
|
* @since Added in 2.20.0
|
|
126
122
|
*/
|
|
127
|
-
class StreamedLog {
|
|
123
|
+
export class StreamedLog {
|
|
128
124
|
destinationLog;
|
|
129
125
|
streamBuffer = [];
|
|
130
126
|
splitMarker = /(?:\n|^)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/g;
|
|
@@ -172,11 +168,11 @@ class StreamedLog {
|
|
|
172
168
|
* Get log stream from response and redirect it to another log.
|
|
173
169
|
*/
|
|
174
170
|
async streamLog() {
|
|
175
|
-
const logStream = await this.logClient.stream({ raw: true });
|
|
176
|
-
if (!logStream) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
171
|
try {
|
|
172
|
+
const logStream = await this.logClient.stream({ raw: true });
|
|
173
|
+
if (!logStream) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
180
176
|
const lastChunkRemainder = await this.logStreamChunks(logStream);
|
|
181
177
|
// Process whatever is left when exiting. Maybe it is incomplete, maybe it is last log without EOL.
|
|
182
178
|
const lastMessage = Buffer.from(lastChunkRemainder).toString().trim();
|
|
@@ -185,7 +181,7 @@ class StreamedLog {
|
|
|
185
181
|
}
|
|
186
182
|
}
|
|
187
183
|
catch (err) {
|
|
188
|
-
|
|
184
|
+
log.warning(`Log redirection stopped due to error`, err);
|
|
189
185
|
}
|
|
190
186
|
}
|
|
191
187
|
async logStreamChunks(logStream) {
|
|
@@ -235,4 +231,3 @@ class StreamedLog {
|
|
|
235
231
|
});
|
|
236
232
|
}
|
|
237
233
|
}
|
|
238
|
-
exports.StreamedLog = StreamedLog;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
|
|
2
|
-
import type { ApiClientSubResourceOptions } from '../base/api_client';
|
|
3
|
-
import { ResourceClient } from '../base/resource_client';
|
|
4
|
-
import type { RequestQueue, RequestQueueClientAddRequestResult, RequestQueueClientBatchDeleteRequestsResult, RequestQueueClientBatchRequestsOperationResult, RequestQueueClientListAndLockHeadResult, RequestQueueClientListHeadResult, RequestQueueClientListRequestsResult, RequestQueueClientProlongRequestLockResult, RequestQueueClientRequestSchema, RequestQueueClientRequestToAdd, RequestQueueClientRequestToUpdate, RequestQueueClientUnlockRequestsResult } from '../models';
|
|
5
|
-
export type { AllowedHttpMethods, RequestQueue, RequestQueueClientAddRequestResult, RequestQueueClientBatchDeleteRequestsResult, RequestQueueClientBatchRequestsOperationResult, RequestQueueClientListAndLockHeadResult, RequestQueueClientListHeadResult, RequestQueueClientListItem, RequestQueueClientListRequestsResult, RequestQueueClientLockedListItem, RequestQueueClientProlongRequestLockResult, RequestQueueClientRequestSchema, RequestQueueClientRequestToAdd, RequestQueueClientRequestToUpdate, RequestQueueClientUnlockRequestsResult, RequestQueueStats, } from '../models';
|
|
2
|
+
import type { ApiClientSubResourceOptions } from '../base/api_client.js';
|
|
3
|
+
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
+
import type { RequestQueue, RequestQueueClientAddRequestResult, RequestQueueClientBatchDeleteRequestsResult, RequestQueueClientBatchRequestsOperationResult, RequestQueueClientListAndLockHeadResult, RequestQueueClientListHeadResult, RequestQueueClientListRequestsResult, RequestQueueClientProlongRequestLockResult, RequestQueueClientRequestSchema, RequestQueueClientRequestToAdd, RequestQueueClientRequestToUpdate, RequestQueueClientUnlockRequestsResult } from '../models.js';
|
|
5
|
+
export type { AllowedHttpMethods, RequestQueue, RequestQueueClientAddRequestResult, RequestQueueClientBatchDeleteRequestsResult, RequestQueueClientBatchRequestsOperationResult, RequestQueueClientListAndLockHeadResult, RequestQueueClientListHeadResult, RequestQueueClientListItem, RequestQueueClientListRequestsResult, RequestQueueClientLockedListItem, RequestQueueClientProlongRequestLockResult, RequestQueueClientRequestSchema, RequestQueueClientRequestToAdd, RequestQueueClientRequestToUpdate, RequestQueueClientUnlockRequestsResult, RequestQueueStats, } from '../models.js';
|
|
6
6
|
/**
|
|
7
7
|
* Client for managing a specific Request queue.
|
|
8
8
|
*
|
|
@@ -346,11 +346,6 @@ export type RequestQueueListRequestsFilter = 'locked' | 'pending';
|
|
|
346
346
|
*/
|
|
347
347
|
export interface RequestQueueClientListRequestsOptions {
|
|
348
348
|
limit?: number;
|
|
349
|
-
/**
|
|
350
|
-
* Using id of request that does not exist in request queue leads to unpredictable results.
|
|
351
|
-
* @deprecated Use `cursor` for pagination instead.
|
|
352
|
-
*/
|
|
353
|
-
exclusiveStartId?: string;
|
|
354
349
|
/**
|
|
355
350
|
* @since Added in 2.23.2
|
|
356
351
|
*/
|
|
@@ -367,8 +362,6 @@ export interface RequestQueueClientListRequestsOptions {
|
|
|
367
362
|
export interface RequestQueueClientPaginateRequestsOptions {
|
|
368
363
|
limit?: number;
|
|
369
364
|
maxPageLimit?: number;
|
|
370
|
-
/** @deprecated Use `cursor` for pagination instead. */
|
|
371
|
-
exclusiveStartId?: string;
|
|
372
365
|
/**
|
|
373
366
|
* @since Added in 2.23.2
|
|
374
367
|
*/
|