apify-client 3.0.0-beta.1 → 3.0.0-beta.3
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/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 +35 -47
- 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 +5 -13
- package/dist/utils.js +30 -69
- package/package.json +10 -12
- 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,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exclusiveStartKey: zod_1.z.string().optional(),
|
|
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 { anyObjectSchema, applyQueryParamsToUrl, cast, catchNotFoundOrThrow, isBuffer, isNode, isStream, parseArgument, parseDateFields, pluckData, } from '../utils.js';
|
|
6
|
+
const listKeysOptionsSchema = z.strictObject({
|
|
7
|
+
limit: z.number().min(0).optional(),
|
|
8
|
+
exclusiveStartKey: z.string().optional(),
|
|
9
|
+
collection: z.string().optional(),
|
|
10
|
+
prefix: z.string().optional(),
|
|
11
|
+
signature: z.string().optional(),
|
|
16
12
|
});
|
|
17
|
-
const nonEmptyKeySchema =
|
|
13
|
+
const nonEmptyKeySchema = z.string().min(1);
|
|
18
14
|
// `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:
|
|
15
|
+
const createKeysPublicUrlOptionsSchema = z.strictObject({
|
|
16
|
+
limit: z.number().min(0).optional(),
|
|
17
|
+
exclusiveStartKey: z.string().optional(),
|
|
18
|
+
collection: z.string().optional(),
|
|
19
|
+
prefix: z.string().optional(),
|
|
20
|
+
expiresInSecs: z.number().optional(),
|
|
25
21
|
});
|
|
26
|
-
const keySchema =
|
|
27
|
-
const getRecordOptionsSchema =
|
|
28
|
-
buffer:
|
|
29
|
-
stream:
|
|
30
|
-
disableRedirect:
|
|
31
|
-
signature:
|
|
22
|
+
const keySchema = z.string();
|
|
23
|
+
const getRecordOptionsSchema = z.strictObject({
|
|
24
|
+
buffer: z.boolean().optional(),
|
|
25
|
+
stream: z.boolean().optional(),
|
|
26
|
+
disableRedirect: z.boolean().optional(),
|
|
27
|
+
signature: z.string().optional(),
|
|
32
28
|
});
|
|
33
|
-
const recordSchema =
|
|
34
|
-
key:
|
|
29
|
+
const recordSchema = z.strictObject({
|
|
30
|
+
key: z.string(),
|
|
35
31
|
// Values are arbitrary, and a `z.object()` arm would walk every key of a large buffer.
|
|
36
32
|
// Symbols, bigints, functions and non-finite numbers are rejected because they cannot be serialized
|
|
37
33
|
// to JSON - symbols and bigints throw, functions stringify to `undefined` (an empty request body),
|
|
38
34
|
// and `NaN` / `Infinity` would silently become `null`.
|
|
39
|
-
value:
|
|
35
|
+
value: z.custom((value) => value !== undefined &&
|
|
40
36
|
typeof value !== 'symbol' &&
|
|
41
37
|
typeof value !== 'bigint' &&
|
|
42
38
|
typeof value !== 'function' &&
|
|
43
39
|
(typeof value !== 'number' || Number.isFinite(value)), 'Expected a defined, JSON-serializable value'),
|
|
44
|
-
contentType:
|
|
40
|
+
contentType: z.string().min(1).optional(),
|
|
45
41
|
});
|
|
46
|
-
const recordOptionsSchema =
|
|
47
|
-
timeoutSecs:
|
|
48
|
-
doNotRetryTimeouts:
|
|
42
|
+
const recordOptionsSchema = z.strictObject({
|
|
43
|
+
timeoutSecs: z.number().optional(),
|
|
44
|
+
doNotRetryTimeouts: z.boolean().optional(),
|
|
49
45
|
});
|
|
50
46
|
/**
|
|
51
47
|
* Client for managing a specific key-value store.
|
|
@@ -75,7 +71,7 @@ const recordOptionsSchema = zod_1.z.strictObject({
|
|
|
75
71
|
*
|
|
76
72
|
* @see https://docs.apify.com/platform/storage/key-value-store
|
|
77
73
|
*/
|
|
78
|
-
class KeyValueStoreClient extends
|
|
74
|
+
export class KeyValueStoreClient extends ResourceClient {
|
|
79
75
|
/**
|
|
80
76
|
* @hidden
|
|
81
77
|
*/
|
|
@@ -92,7 +88,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
92
88
|
* @see https://docs.apify.com/api/v2/key-value-store-get
|
|
93
89
|
*/
|
|
94
90
|
async get() {
|
|
95
|
-
return this._get({},
|
|
91
|
+
return this._get({}, SMALL_TIMEOUT_MILLIS);
|
|
96
92
|
}
|
|
97
93
|
/**
|
|
98
94
|
* Updates the key-value store with specified fields.
|
|
@@ -105,8 +101,8 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
105
101
|
* @see https://docs.apify.com/api/v2/key-value-store-put
|
|
106
102
|
*/
|
|
107
103
|
async update(newFields) {
|
|
108
|
-
|
|
109
|
-
return this._update(newFields,
|
|
104
|
+
parseArgument(newFields, anyObjectSchema);
|
|
105
|
+
return this._update(newFields, DEFAULT_TIMEOUT_MILLIS);
|
|
110
106
|
}
|
|
111
107
|
/**
|
|
112
108
|
* Deletes the key-value store.
|
|
@@ -114,7 +110,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
114
110
|
* @see https://docs.apify.com/api/v2/key-value-store-delete
|
|
115
111
|
*/
|
|
116
112
|
async delete() {
|
|
117
|
-
return this._delete(
|
|
113
|
+
return this._delete(SMALL_TIMEOUT_MILLIS);
|
|
118
114
|
}
|
|
119
115
|
/**
|
|
120
116
|
* Lists all keys in the key-value store.
|
|
@@ -152,15 +148,15 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
152
148
|
* ```
|
|
153
149
|
*/
|
|
154
150
|
listKeys(options = {}) {
|
|
155
|
-
const parsed =
|
|
151
|
+
const parsed = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
|
|
156
152
|
const getPaginatedList = async (kvsListOptions = {}) => {
|
|
157
153
|
const response = await this.httpClient.call({
|
|
158
154
|
url: this._url('keys'),
|
|
159
155
|
method: 'GET',
|
|
160
156
|
params: this._params(kvsListOptions),
|
|
161
|
-
timeout:
|
|
157
|
+
timeout: MEDIUM_TIMEOUT_MILLIS,
|
|
162
158
|
});
|
|
163
|
-
return
|
|
159
|
+
return cast(parseDateFields(pluckData(response.data)));
|
|
164
160
|
};
|
|
165
161
|
const paginatedListPromise = getPaginatedList(parsed);
|
|
166
162
|
async function* asyncGenerator() {
|
|
@@ -208,11 +204,11 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
208
204
|
* @since Added in 2.14.0
|
|
209
205
|
*/
|
|
210
206
|
async getRecordPublicUrl(key) {
|
|
211
|
-
|
|
207
|
+
parseArgument(key, nonEmptyKeySchema);
|
|
212
208
|
const store = await this.get();
|
|
213
209
|
const recordPublicUrl = new URL(this._publicUrl(['records', key]));
|
|
214
210
|
if (store?.urlSigningSecretKey) {
|
|
215
|
-
const signature = await
|
|
211
|
+
const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
|
|
216
212
|
recordPublicUrl.searchParams.append('signature', signature);
|
|
217
213
|
}
|
|
218
214
|
return recordPublicUrl.toString();
|
|
@@ -241,19 +237,19 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
241
237
|
* @since Added in 2.13.0
|
|
242
238
|
*/
|
|
243
239
|
async createKeysPublicUrl(options = {}) {
|
|
244
|
-
const parsed =
|
|
240
|
+
const parsed = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
|
|
245
241
|
const store = await this.get();
|
|
246
242
|
const { expiresInSecs, ...queryOptions } = parsed;
|
|
247
243
|
let createdPublicKeysUrl = new URL(this._publicUrl('keys'));
|
|
248
244
|
if (store?.urlSigningSecretKey) {
|
|
249
|
-
const signature = await
|
|
245
|
+
const signature = await createStorageContentSignatureAsync({
|
|
250
246
|
resourceId: store.id,
|
|
251
247
|
urlSigningSecretKey: store.urlSigningSecretKey,
|
|
252
248
|
expiresInMillis: expiresInSecs ? expiresInSecs * 1000 : undefined,
|
|
253
249
|
});
|
|
254
250
|
createdPublicKeysUrl.searchParams.set('signature', signature);
|
|
255
251
|
}
|
|
256
|
-
createdPublicKeysUrl =
|
|
252
|
+
createdPublicKeysUrl = applyQueryParamsToUrl(createdPublicKeysUrl, queryOptions);
|
|
257
253
|
return createdPublicKeysUrl.toString();
|
|
258
254
|
}
|
|
259
255
|
/**
|
|
@@ -285,18 +281,18 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
285
281
|
return true;
|
|
286
282
|
}
|
|
287
283
|
catch (err) {
|
|
288
|
-
|
|
284
|
+
catchNotFoundOrThrow(err);
|
|
289
285
|
}
|
|
290
286
|
return false;
|
|
291
287
|
}
|
|
292
288
|
async getRecord(key, options = {}) {
|
|
293
|
-
|
|
294
|
-
const parsed =
|
|
295
|
-
if (parsed.stream && !
|
|
289
|
+
parseArgument(key, keySchema);
|
|
290
|
+
const parsed = parseArgument(options, getRecordOptionsSchema, 'KeyValueClientGetRecordOptions');
|
|
291
|
+
if (parsed.stream && !isNode()) {
|
|
296
292
|
throw new Error('The stream option can only be used in Node.js environment.');
|
|
297
293
|
}
|
|
298
294
|
if ('disableRedirect' in parsed) {
|
|
299
|
-
|
|
295
|
+
log.deprecated('The disableRedirect option for getRecord() is deprecated. ' +
|
|
300
296
|
'It has no effect and will be removed in the following major release.');
|
|
301
297
|
}
|
|
302
298
|
const queryParams = { attachment: 'true' };
|
|
@@ -306,7 +302,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
306
302
|
url: this._url(['records', key]),
|
|
307
303
|
method: 'GET',
|
|
308
304
|
params: this._params(queryParams),
|
|
309
|
-
timeout:
|
|
305
|
+
timeout: DEFAULT_TIMEOUT_MILLIS,
|
|
310
306
|
};
|
|
311
307
|
if (parsed.buffer)
|
|
312
308
|
requestOpts.forceBuffer = true;
|
|
@@ -321,7 +317,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
321
317
|
};
|
|
322
318
|
}
|
|
323
319
|
catch (err) {
|
|
324
|
-
|
|
320
|
+
catchNotFoundOrThrow(err);
|
|
325
321
|
}
|
|
326
322
|
return undefined;
|
|
327
323
|
}
|
|
@@ -373,12 +369,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
373
369
|
* ```
|
|
374
370
|
*/
|
|
375
371
|
async setRecord(record, options = {}) {
|
|
376
|
-
|
|
377
|
-
const parsed =
|
|
372
|
+
parseArgument(record, recordSchema);
|
|
373
|
+
const parsed = parseArgument(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
|
|
378
374
|
const { key } = record;
|
|
379
375
|
let { value, contentType } = record;
|
|
380
376
|
const { timeoutSecs, doNotRetryTimeouts } = parsed;
|
|
381
|
-
const isValueStreamOrBuffer =
|
|
377
|
+
const isValueStreamOrBuffer = isStream(value) || isBuffer(value);
|
|
382
378
|
// To allow saving Objects to JSON without providing content type
|
|
383
379
|
if (!contentType) {
|
|
384
380
|
if (isValueStreamOrBuffer)
|
|
@@ -405,7 +401,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
405
401
|
data: value,
|
|
406
402
|
headers: contentType ? { 'content-type': contentType } : undefined,
|
|
407
403
|
doNotRetryTimeouts,
|
|
408
|
-
timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 :
|
|
404
|
+
timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 : DEFAULT_TIMEOUT_MILLIS,
|
|
409
405
|
};
|
|
410
406
|
await this.httpClient.call(uploadOpts);
|
|
411
407
|
}
|
|
@@ -421,13 +417,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
421
417
|
* ```
|
|
422
418
|
*/
|
|
423
419
|
async deleteRecord(key) {
|
|
424
|
-
|
|
420
|
+
parseArgument(key, keySchema);
|
|
425
421
|
await this.httpClient.call({
|
|
426
422
|
url: this._url(['records', key]),
|
|
427
423
|
method: 'DELETE',
|
|
428
424
|
params: this._params(),
|
|
429
|
-
timeout:
|
|
425
|
+
timeout: SMALL_TIMEOUT_MILLIS,
|
|
430
426
|
});
|
|
431
427
|
}
|
|
432
428
|
}
|
|
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,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
...utils_1.paginationOptionsShape,
|
|
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 { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
5
|
+
const listOptionsSchema = z.strictObject({
|
|
6
|
+
unnamed: z.boolean().optional(),
|
|
7
|
+
...paginationOptionsShape,
|
|
8
|
+
desc: z.boolean().optional(),
|
|
9
|
+
ownership: z.enum(STORAGE_OWNERSHIP_FILTER).optional(),
|
|
13
10
|
});
|
|
14
|
-
const nameSchema =
|
|
15
|
-
const schemaSchema =
|
|
11
|
+
const nameSchema = z.string().optional();
|
|
12
|
+
const schemaSchema = anyObjectSchema.optional();
|
|
16
13
|
/**
|
|
17
14
|
* Client for managing the collection of Key-value stores in your account.
|
|
18
15
|
*
|
|
@@ -33,7 +30,7 @@ const schemaSchema = utils_1.anyObjectSchema.optional();
|
|
|
33
30
|
*
|
|
34
31
|
* @see https://docs.apify.com/platform/storage/key-value-store
|
|
35
32
|
*/
|
|
36
|
-
class KeyValueStoreCollectionClient extends
|
|
33
|
+
export class KeyValueStoreCollectionClient extends ResourceCollectionClient {
|
|
37
34
|
/**
|
|
38
35
|
* @hidden
|
|
39
36
|
*/
|
|
@@ -64,7 +61,7 @@ class KeyValueStoreCollectionClient extends resource_collection_client_1.Resourc
|
|
|
64
61
|
* @see https://docs.apify.com/api/v2/key-value-stores-get
|
|
65
62
|
*/
|
|
66
63
|
list(options = {}) {
|
|
67
|
-
const parsed =
|
|
64
|
+
const parsed = parseArgument(options, listOptionsSchema, 'KeyValueStoreCollectionClientListOptions');
|
|
68
65
|
return this._listPaginated(parsed);
|
|
69
66
|
}
|
|
70
67
|
/**
|
|
@@ -76,9 +73,8 @@ class KeyValueStoreCollectionClient extends resource_collection_client_1.Resourc
|
|
|
76
73
|
* @see https://docs.apify.com/api/v2/key-value-stores-post
|
|
77
74
|
*/
|
|
78
75
|
async getOrCreate(name, options) {
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
parseArgument(name, nameSchema);
|
|
77
|
+
parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
|
|
81
78
|
return this._getOrCreate(name, options);
|
|
82
79
|
}
|
|
83
80
|
}
|
|
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
|
*
|
|
@@ -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, catchNotFoundOrThrow } 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
|
*/
|
|
@@ -54,10 +50,10 @@ class LogClient extends resource_client_1.ResourceClient {
|
|
|
54
50
|
};
|
|
55
51
|
try {
|
|
56
52
|
const response = await this.httpClient.call(requestOpts);
|
|
57
|
-
return
|
|
53
|
+
return cast(response.data);
|
|
58
54
|
}
|
|
59
55
|
catch (err) {
|
|
60
|
-
|
|
56
|
+
catchNotFoundOrThrow(err);
|
|
61
57
|
}
|
|
62
58
|
return undefined;
|
|
63
59
|
}
|
|
@@ -82,22 +78,21 @@ class LogClient extends resource_client_1.ResourceClient {
|
|
|
82
78
|
};
|
|
83
79
|
try {
|
|
84
80
|
const response = await this.httpClient.call(requestOpts);
|
|
85
|
-
return
|
|
81
|
+
return cast(response.data);
|
|
86
82
|
}
|
|
87
83
|
catch (err) {
|
|
88
|
-
|
|
84
|
+
catchNotFoundOrThrow(err);
|
|
89
85
|
}
|
|
90
86
|
return undefined;
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
|
-
exports.LogClient = LogClient;
|
|
94
89
|
/**
|
|
95
90
|
* Logger for redirected actor logs.
|
|
96
91
|
* @since Added in 2.20.0
|
|
97
92
|
*/
|
|
98
|
-
class LoggerActorRedirect extends
|
|
93
|
+
export class LoggerActorRedirect extends Logger {
|
|
99
94
|
constructor(options = {}) {
|
|
100
|
-
super({ skipTime: true, level:
|
|
95
|
+
super({ skipTime: true, level: LogLevel.DEBUG, ...options });
|
|
101
96
|
}
|
|
102
97
|
_log(level, message, data, exception, opts = {}) {
|
|
103
98
|
if (level > this.options.level) {
|
|
@@ -112,19 +107,18 @@ class LoggerActorRedirect extends log_1.Logger {
|
|
|
112
107
|
if (!this.options.skipTime) {
|
|
113
108
|
maybeDate = `${new Date().toISOString().replace('Z', '').replace('T', ' ')} `;
|
|
114
109
|
}
|
|
115
|
-
const line = `${
|
|
110
|
+
const line = `${c.gray(maybeDate)}${c.cyan(prefix)}${message || ''}`;
|
|
116
111
|
// All redirected logs are logged at info level to avid any console specific formating for non-info levels,
|
|
117
112
|
// which have already been applied once to the original log. (For example error stack traces etc.)
|
|
118
|
-
this._outputWithConsole(
|
|
113
|
+
this._outputWithConsole(LogLevel.INFO, line);
|
|
119
114
|
return line;
|
|
120
115
|
}
|
|
121
116
|
}
|
|
122
|
-
exports.LoggerActorRedirect = LoggerActorRedirect;
|
|
123
117
|
/**
|
|
124
118
|
* Helper class for redirecting streamed Actor logs to another log.
|
|
125
119
|
* @since Added in 2.20.0
|
|
126
120
|
*/
|
|
127
|
-
class StreamedLog {
|
|
121
|
+
export class StreamedLog {
|
|
128
122
|
destinationLog;
|
|
129
123
|
streamBuffer = [];
|
|
130
124
|
splitMarker = /(?:\n|^)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/g;
|
|
@@ -185,7 +179,7 @@ class StreamedLog {
|
|
|
185
179
|
}
|
|
186
180
|
}
|
|
187
181
|
catch (err) {
|
|
188
|
-
|
|
182
|
+
log.warning(`Log redirection stopped due to error`, err);
|
|
189
183
|
}
|
|
190
184
|
}
|
|
191
185
|
async logStreamChunks(logStream) {
|
|
@@ -235,4 +229,3 @@ class StreamedLog {
|
|
|
235
229
|
});
|
|
236
230
|
}
|
|
237
231
|
}
|
|
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
|
*
|