apify-client 3.0.0-beta.0 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/apify_api_error.js +5 -9
- package/dist/apify_client.d.ts +27 -27
- package/dist/apify_client.js +86 -91
- package/dist/argument_validation_error.js +1 -5
- package/dist/base/api_client.d.ts +3 -3
- package/dist/base/api_client.js +6 -10
- package/dist/base/resource_client.d.ts +1 -1
- package/dist/base/resource_client.js +14 -18
- package/dist/base/resource_collection_client.d.ts +2 -2
- package/dist/base/resource_collection_client.js +6 -10
- package/dist/body_parser.js +6 -11
- package/dist/bundle.js +8 -8
- package/dist/bundle.js.map +1 -1
- package/dist/generated/api.d.ts +20522 -0
- package/dist/generated/api.js +5 -0
- 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 +1072 -0
- package/dist/models.js +86 -0
- package/dist/resource_clients/actor.d.ts +13 -459
- package/dist/resource_clients/actor.js +67 -71
- package/dist/resource_clients/actor_collection.d.ts +7 -12
- 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 -44
- package/dist/resource_clients/actor_version.js +12 -22
- 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 -80
- 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 -71
- 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 -73
- package/dist/resource_clients/key_value_store.js +60 -63
- 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 +17 -176
- package/dist/resource_clients/request_queue.js +93 -98
- 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 -84
- package/dist/resource_clients/schedule.js +7 -18
- 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 -33
- package/dist/resource_clients/store_collection.js +13 -17
- package/dist/resource_clients/task.d.ts +9 -79
- package/dist/resource_clients/task.js +44 -48
- package/dist/resource_clients/task_collection.d.ts +6 -5
- package/dist/resource_clients/task_collection.js +9 -13
- package/dist/resource_clients/user.d.ts +5 -181
- package/dist/resource_clients/user.js +8 -21
- package/dist/resource_clients/webhook.d.ts +6 -65
- 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 -38
- package/dist/resource_clients/webhook_dispatch.js +3 -12
- package/dist/resource_clients/webhook_dispatch_collection.d.ts +4 -4
- package/dist/resource_clients/webhook_dispatch_collection.js +8 -12
- package/dist/statistics.js +5 -9
- package/dist/timezones.js +1 -2
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +41 -56
- package/package.json +16 -9
- package/dist/index.mjs +0 -42
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream';
|
|
2
2
|
import type { JsonValue } from 'type-fest';
|
|
3
3
|
import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
|
|
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
|
+
import type { KeyValueClientListKeysResult, KeyValueListItem, KeyValueStore } from '../models.js';
|
|
7
|
+
export type { KeyValueClientListKeysResult, KeyValueListItem, KeyValueStore, KeyValueStoreStats } from '../models.js';
|
|
6
8
|
/**
|
|
7
9
|
* Client for managing a specific key-value store.
|
|
8
10
|
*
|
|
@@ -231,53 +233,6 @@ export declare class KeyValueStoreClient extends ResourceClient {
|
|
|
231
233
|
*/
|
|
232
234
|
deleteRecord(key: string): Promise<void>;
|
|
233
235
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Represents a Key-Value Store storage on the Apify platform.
|
|
236
|
-
*
|
|
237
|
-
* Key-value stores are used to store arbitrary data records or files. Each record is identified
|
|
238
|
-
* by a unique key and can contain any data - JSON objects, strings, binary files, etc.
|
|
239
|
-
*/
|
|
240
|
-
export interface KeyValueStore {
|
|
241
|
-
id: string;
|
|
242
|
-
name?: string;
|
|
243
|
-
/**
|
|
244
|
-
* @since Added in 2.6.1
|
|
245
|
-
*/
|
|
246
|
-
title?: string;
|
|
247
|
-
userId: string;
|
|
248
|
-
/**
|
|
249
|
-
* @since Added in 2.21.0
|
|
250
|
-
*/
|
|
251
|
-
username?: string;
|
|
252
|
-
createdAt: Date;
|
|
253
|
-
modifiedAt: Date;
|
|
254
|
-
accessedAt: Date;
|
|
255
|
-
actId?: string;
|
|
256
|
-
actRunId?: string;
|
|
257
|
-
stats?: KeyValueStoreStats;
|
|
258
|
-
/**
|
|
259
|
-
* @since Added in 2.12.2
|
|
260
|
-
*/
|
|
261
|
-
generalAccess?: STORAGE_GENERAL_ACCESS | null;
|
|
262
|
-
/**
|
|
263
|
-
* @since Added in 2.13.0
|
|
264
|
-
*/
|
|
265
|
-
urlSigningSecretKey?: string | null;
|
|
266
|
-
/**
|
|
267
|
-
* @since Added in 2.13.0
|
|
268
|
-
*/
|
|
269
|
-
keysPublicUrl: string;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Statistics about Key-Value Store usage and storage.
|
|
273
|
-
*/
|
|
274
|
-
export interface KeyValueStoreStats {
|
|
275
|
-
readCount?: number;
|
|
276
|
-
writeCount?: number;
|
|
277
|
-
deleteCount?: number;
|
|
278
|
-
listCount?: number;
|
|
279
|
-
storageBytes?: number;
|
|
280
|
-
}
|
|
281
236
|
/**
|
|
282
237
|
* Options for updating a Key-Value Store.
|
|
283
238
|
*/
|
|
@@ -318,30 +273,6 @@ export interface KeyValueClientListKeysOptions {
|
|
|
318
273
|
export interface KeyValueClientCreateKeysUrlOptions extends Omit<KeyValueClientListKeysOptions, 'signature'> {
|
|
319
274
|
expiresInSecs?: number;
|
|
320
275
|
}
|
|
321
|
-
/**
|
|
322
|
-
* Result of listing keys in a Key-Value Store.
|
|
323
|
-
*
|
|
324
|
-
* Contains paginated list of keys with metadata and pagination information.
|
|
325
|
-
*/
|
|
326
|
-
export interface KeyValueClientListKeysResult {
|
|
327
|
-
count: number;
|
|
328
|
-
limit: number;
|
|
329
|
-
exclusiveStartKey: string;
|
|
330
|
-
isTruncated: boolean;
|
|
331
|
-
nextExclusiveStartKey: string;
|
|
332
|
-
items: KeyValueListItem[];
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Metadata about a single key in a Key-Value Store.
|
|
336
|
-
*/
|
|
337
|
-
export interface KeyValueListItem {
|
|
338
|
-
key: string;
|
|
339
|
-
size: number;
|
|
340
|
-
/**
|
|
341
|
-
* @since Added in 2.15.1
|
|
342
|
-
*/
|
|
343
|
-
recordPublicUrl: string;
|
|
344
|
-
}
|
|
345
276
|
/**
|
|
346
277
|
* Options for retrieving a record from a Key-Value Store.
|
|
347
278
|
*/
|
|
@@ -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() {
|
|
@@ -168,7 +164,9 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
168
164
|
yield* currentPage.items;
|
|
169
165
|
let remainingItems = parsed.limit ? parsed.limit - currentPage.items.length : undefined;
|
|
170
166
|
while (currentPage.items.length > 0 && // Continue only if at least some items were returned in the last page.
|
|
171
|
-
|
|
167
|
+
// Continue only if there is some next key. The API answers with `null` on the last page and
|
|
168
|
+
// omits the field entirely for a listing that was not truncated.
|
|
169
|
+
currentPage.nextExclusiveStartKey != null &&
|
|
172
170
|
(remainingItems === undefined || remainingItems > 0) // Continue only if the limit was not exceeded.
|
|
173
171
|
) {
|
|
174
172
|
const newOptions = {
|
|
@@ -206,11 +204,11 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
206
204
|
* @since Added in 2.14.0
|
|
207
205
|
*/
|
|
208
206
|
async getRecordPublicUrl(key) {
|
|
209
|
-
|
|
207
|
+
parseArgument(key, nonEmptyKeySchema);
|
|
210
208
|
const store = await this.get();
|
|
211
209
|
const recordPublicUrl = new URL(this._publicUrl(['records', key]));
|
|
212
210
|
if (store?.urlSigningSecretKey) {
|
|
213
|
-
const signature = await
|
|
211
|
+
const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
|
|
214
212
|
recordPublicUrl.searchParams.append('signature', signature);
|
|
215
213
|
}
|
|
216
214
|
return recordPublicUrl.toString();
|
|
@@ -239,19 +237,19 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
239
237
|
* @since Added in 2.13.0
|
|
240
238
|
*/
|
|
241
239
|
async createKeysPublicUrl(options = {}) {
|
|
242
|
-
const parsed =
|
|
240
|
+
const parsed = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
|
|
243
241
|
const store = await this.get();
|
|
244
242
|
const { expiresInSecs, ...queryOptions } = parsed;
|
|
245
243
|
let createdPublicKeysUrl = new URL(this._publicUrl('keys'));
|
|
246
244
|
if (store?.urlSigningSecretKey) {
|
|
247
|
-
const signature = await
|
|
245
|
+
const signature = await createStorageContentSignatureAsync({
|
|
248
246
|
resourceId: store.id,
|
|
249
247
|
urlSigningSecretKey: store.urlSigningSecretKey,
|
|
250
248
|
expiresInMillis: expiresInSecs ? expiresInSecs * 1000 : undefined,
|
|
251
249
|
});
|
|
252
250
|
createdPublicKeysUrl.searchParams.set('signature', signature);
|
|
253
251
|
}
|
|
254
|
-
createdPublicKeysUrl =
|
|
252
|
+
createdPublicKeysUrl = applyQueryParamsToUrl(createdPublicKeysUrl, queryOptions);
|
|
255
253
|
return createdPublicKeysUrl.toString();
|
|
256
254
|
}
|
|
257
255
|
/**
|
|
@@ -283,18 +281,18 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
283
281
|
return true;
|
|
284
282
|
}
|
|
285
283
|
catch (err) {
|
|
286
|
-
|
|
284
|
+
catchNotFoundOrThrow(err);
|
|
287
285
|
}
|
|
288
286
|
return false;
|
|
289
287
|
}
|
|
290
288
|
async getRecord(key, options = {}) {
|
|
291
|
-
|
|
292
|
-
const parsed =
|
|
293
|
-
if (parsed.stream && !
|
|
289
|
+
parseArgument(key, keySchema);
|
|
290
|
+
const parsed = parseArgument(options, getRecordOptionsSchema, 'KeyValueClientGetRecordOptions');
|
|
291
|
+
if (parsed.stream && !isNode()) {
|
|
294
292
|
throw new Error('The stream option can only be used in Node.js environment.');
|
|
295
293
|
}
|
|
296
294
|
if ('disableRedirect' in parsed) {
|
|
297
|
-
|
|
295
|
+
log.deprecated('The disableRedirect option for getRecord() is deprecated. ' +
|
|
298
296
|
'It has no effect and will be removed in the following major release.');
|
|
299
297
|
}
|
|
300
298
|
const queryParams = { attachment: 'true' };
|
|
@@ -304,7 +302,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
304
302
|
url: this._url(['records', key]),
|
|
305
303
|
method: 'GET',
|
|
306
304
|
params: this._params(queryParams),
|
|
307
|
-
timeout:
|
|
305
|
+
timeout: DEFAULT_TIMEOUT_MILLIS,
|
|
308
306
|
};
|
|
309
307
|
if (parsed.buffer)
|
|
310
308
|
requestOpts.forceBuffer = true;
|
|
@@ -319,7 +317,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
319
317
|
};
|
|
320
318
|
}
|
|
321
319
|
catch (err) {
|
|
322
|
-
|
|
320
|
+
catchNotFoundOrThrow(err);
|
|
323
321
|
}
|
|
324
322
|
return undefined;
|
|
325
323
|
}
|
|
@@ -371,12 +369,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
371
369
|
* ```
|
|
372
370
|
*/
|
|
373
371
|
async setRecord(record, options = {}) {
|
|
374
|
-
|
|
375
|
-
const parsed =
|
|
372
|
+
parseArgument(record, recordSchema);
|
|
373
|
+
const parsed = parseArgument(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
|
|
376
374
|
const { key } = record;
|
|
377
375
|
let { value, contentType } = record;
|
|
378
376
|
const { timeoutSecs, doNotRetryTimeouts } = parsed;
|
|
379
|
-
const isValueStreamOrBuffer =
|
|
377
|
+
const isValueStreamOrBuffer = isStream(value) || isBuffer(value);
|
|
380
378
|
// To allow saving Objects to JSON without providing content type
|
|
381
379
|
if (!contentType) {
|
|
382
380
|
if (isValueStreamOrBuffer)
|
|
@@ -403,7 +401,7 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
403
401
|
data: value,
|
|
404
402
|
headers: contentType ? { 'content-type': contentType } : undefined,
|
|
405
403
|
doNotRetryTimeouts,
|
|
406
|
-
timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 :
|
|
404
|
+
timeout: timeoutSecs !== undefined ? timeoutSecs * 1000 : DEFAULT_TIMEOUT_MILLIS,
|
|
407
405
|
};
|
|
408
406
|
await this.httpClient.call(uploadOpts);
|
|
409
407
|
}
|
|
@@ -419,13 +417,12 @@ class KeyValueStoreClient extends resource_client_1.ResourceClient {
|
|
|
419
417
|
* ```
|
|
420
418
|
*/
|
|
421
419
|
async deleteRecord(key) {
|
|
422
|
-
|
|
420
|
+
parseArgument(key, keySchema);
|
|
423
421
|
await this.httpClient.call({
|
|
424
422
|
url: this._url(['records', key]),
|
|
425
423
|
method: 'DELETE',
|
|
426
424
|
params: this._params(),
|
|
427
|
-
timeout:
|
|
425
|
+
timeout: SMALL_TIMEOUT_MILLIS,
|
|
428
426
|
});
|
|
429
427
|
}
|
|
430
428
|
}
|
|
431
|
-
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;
|