apify-client 3.0.0-beta.27 → 3.0.0-beta.28
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/api_client.js +2 -2
- package/dist/base/resource_client.d.ts +3 -3
- package/dist/base/resource_client.js +13 -9
- package/dist/base/resource_collection_client.d.ts +5 -4
- package/dist/base/resource_collection_client.js +12 -7
- package/dist/bundle.js +6 -6
- package/dist/bundle.js.map +1 -1
- package/dist/http_clients/base.js +1 -21
- package/dist/resource_clients/actor.js +17 -13
- package/dist/resource_clients/actor_collection.js +2 -2
- package/dist/resource_clients/actor_env_var.js +6 -6
- package/dist/resource_clients/actor_env_var_collection.js +4 -4
- package/dist/resource_clients/actor_version.js +6 -6
- package/dist/resource_clients/actor_version_collection.js +4 -4
- package/dist/resource_clients/build.js +8 -6
- package/dist/resource_clients/dataset.js +18 -14
- package/dist/resource_clients/dataset_collection.js +6 -5
- package/dist/resource_clients/key_value_store.js +19 -14
- package/dist/resource_clients/key_value_store_collection.js +6 -5
- package/dist/resource_clients/log.d.ts +2 -0
- package/dist/resource_clients/log.js +10 -4
- package/dist/resource_clients/request_queue.js +37 -21
- package/dist/resource_clients/request_queue_collection.js +2 -2
- package/dist/resource_clients/run.js +21 -15
- package/dist/resource_clients/schedule.js +8 -7
- package/dist/resource_clients/schedule_collection.js +2 -2
- package/dist/resource_clients/task.js +15 -12
- package/dist/resource_clients/task_collection.js +2 -2
- package/dist/resource_clients/user.js +8 -5
- package/dist/resource_clients/webhook.js +8 -7
- package/dist/resource_clients/webhook_collection.js +2 -2
- package/dist/resource_clients/webhook_dispatch.js +2 -2
- package/dist/timeouts.d.ts +12 -0
- package/dist/timeouts.js +6 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +21 -0
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ import { InvalidResponseBodyError } from '../invalid_response_body_error.js';
|
|
|
9
9
|
import { Statistics } from '../statistics.js';
|
|
10
10
|
import { DEFAULT_TIMEOUT_LONG_SECS, DEFAULT_TIMEOUT_MAX_SECS, DEFAULT_TIMEOUT_MEDIUM_SECS, DEFAULT_TIMEOUT_SHORT_SECS, } from '../timeouts.js';
|
|
11
11
|
import { runtime } from '#runtime';
|
|
12
|
-
import { asArray, getEnv, isBuffer, isCompressibleContentType, isStream, MIN_COMPRESS_BYTES, parseArgument, toBytes, version, } from '../utils.js';
|
|
12
|
+
import { asArray, getEnv, isBuffer, isCompressibleContentType, isStream, MIN_COMPRESS_BYTES, parseArgument, sleep, toBytes, version, } from '../utils.js';
|
|
13
13
|
export const DEFAULT_MAX_RETRIES = 8;
|
|
14
14
|
export const DEFAULT_MIN_DELAY_BETWEEN_RETRIES_MILLIS = 500;
|
|
15
15
|
const RATE_LIMIT_EXCEEDED_STATUS_CODE = 429;
|
|
@@ -415,26 +415,6 @@ export class HttpClient {
|
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
}
|
|
418
|
-
/**
|
|
419
|
-
* Resolves after `millis`, or right away once `signal` aborts.
|
|
420
|
-
*/
|
|
421
|
-
async function sleep(millis, signal) {
|
|
422
|
-
return new Promise((resolve) => {
|
|
423
|
-
if (signal?.aborted) {
|
|
424
|
-
resolve();
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
const onAbort = () => {
|
|
428
|
-
clearTimeout(timer);
|
|
429
|
-
resolve();
|
|
430
|
-
};
|
|
431
|
-
const timer = setTimeout(() => {
|
|
432
|
-
signal?.removeEventListener('abort', onAbort);
|
|
433
|
-
resolve();
|
|
434
|
-
}, millis);
|
|
435
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
418
|
/**
|
|
439
419
|
* Looks a header up by name, compared case-insensitively.
|
|
440
420
|
*/
|
|
@@ -96,8 +96,8 @@ export class ActorClient extends ResourceClient {
|
|
|
96
96
|
* @see https://docs.apify.com/api/v2/act-get
|
|
97
97
|
*/
|
|
98
98
|
async get(options = {}) {
|
|
99
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
100
|
-
return this.getResource(schemas.Actor(), {}, timeoutSecs);
|
|
99
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
100
|
+
return this.getResource(schemas.Actor(), {}, timeoutSecs, signal);
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Updates the Actor with specified fields.
|
|
@@ -110,8 +110,8 @@ export class ActorClient extends ResourceClient {
|
|
|
110
110
|
*/
|
|
111
111
|
async update(newFields, options = {}) {
|
|
112
112
|
parseArgument(newFields, anyObjectSchema);
|
|
113
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
|
-
return this.updateResource(schemas.Actor(), newFields, timeoutSecs);
|
|
113
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
|
+
return this.updateResource(schemas.Actor(), newFields, timeoutSecs, signal);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* Deletes the Actor.
|
|
@@ -121,8 +121,8 @@ export class ActorClient extends ResourceClient {
|
|
|
121
121
|
* @see https://docs.apify.com/api/v2/act-delete
|
|
122
122
|
*/
|
|
123
123
|
async delete(options = {}) {
|
|
124
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
125
|
-
return this.deleteResource(timeoutSecs);
|
|
124
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
125
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Starts the Actor and immediately returns the Run object.
|
|
@@ -160,7 +160,7 @@ export class ActorClient extends ResourceClient {
|
|
|
160
160
|
*/
|
|
161
161
|
async start(input, options = {}) {
|
|
162
162
|
const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
|
|
163
|
-
const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, timeoutSecs, } = parsed;
|
|
163
|
+
const { waitForFinish, runTimeoutSecs, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, timeoutSecs, signal, } = parsed;
|
|
164
164
|
// The API's `timeout` parameter bounds the run, not the request.
|
|
165
165
|
const params = {
|
|
166
166
|
waitForFinish,
|
|
@@ -181,6 +181,7 @@ export class ActorClient extends ResourceClient {
|
|
|
181
181
|
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
182
182
|
stringifyFunctions: true,
|
|
183
183
|
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', waitForFinish),
|
|
184
|
+
signal,
|
|
184
185
|
};
|
|
185
186
|
if (parsed.contentType) {
|
|
186
187
|
request.headers = {
|
|
@@ -229,17 +230,17 @@ export class ActorClient extends ResourceClient {
|
|
|
229
230
|
*/
|
|
230
231
|
async call(input, options = {}) {
|
|
231
232
|
const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
|
|
232
|
-
const { waitSecs, log, timeoutSecs = 'noTimeout', ...startOptions } = parsed;
|
|
233
|
-
const { id } = await this.start(input, { ...startOptions, timeoutSecs });
|
|
233
|
+
const { waitSecs, log, timeoutSecs = 'noTimeout', signal, ...startOptions } = parsed;
|
|
234
|
+
const { id } = await this.start(input, { ...startOptions, timeoutSecs, signal });
|
|
234
235
|
// Calling root client because we need access to top level API.
|
|
235
236
|
// Creating a new instance of RunClient here would only allow
|
|
236
237
|
// setting it up as a nested route under actor API.
|
|
237
238
|
const newRunClient = this.apifyClient.run(id);
|
|
238
|
-
const streamedLog = await newRunClient.getStreamedLog({ toLog: log });
|
|
239
|
+
const streamedLog = await newRunClient.getStreamedLog({ toLog: log, signal });
|
|
239
240
|
streamedLog?.start();
|
|
240
241
|
return this.apifyClient
|
|
241
242
|
.run(id)
|
|
242
|
-
.waitForFinish({ waitSecs, timeoutSecs })
|
|
243
|
+
.waitForFinish({ waitSecs, timeoutSecs, signal })
|
|
243
244
|
.finally(async () => {
|
|
244
245
|
await streamedLog?.stop();
|
|
245
246
|
});
|
|
@@ -283,6 +284,7 @@ export class ActorClient extends ResourceClient {
|
|
|
283
284
|
// Actor input may carry page functions, which plain JSON serialization would drop.
|
|
284
285
|
stringifyFunctions: true,
|
|
285
286
|
timeoutSecs: parsed.timeoutSecs ?? 'short',
|
|
287
|
+
signal: parsed.signal,
|
|
286
288
|
};
|
|
287
289
|
if (parsed.contentType) {
|
|
288
290
|
request.headers = {
|
|
@@ -325,7 +327,7 @@ export class ActorClient extends ResourceClient {
|
|
|
325
327
|
*/
|
|
326
328
|
async build(versionNumber, options = {}) {
|
|
327
329
|
parseArgument(versionNumber, versionNumberSchema);
|
|
328
|
-
const { timeoutSecs, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
|
|
330
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, buildOptionsSchema, 'ActorBuildOptions');
|
|
329
331
|
const response = await this.httpClient.call({
|
|
330
332
|
url: this.buildUrl('builds'),
|
|
331
333
|
method: 'POST',
|
|
@@ -334,6 +336,7 @@ export class ActorClient extends ResourceClient {
|
|
|
334
336
|
...params,
|
|
335
337
|
}),
|
|
336
338
|
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'medium', params.waitForFinish),
|
|
339
|
+
signal,
|
|
337
340
|
});
|
|
338
341
|
return parseResponse(response, schemas.Build());
|
|
339
342
|
}
|
|
@@ -365,12 +368,13 @@ export class ActorClient extends ResourceClient {
|
|
|
365
368
|
* @since Added in 2.12.2
|
|
366
369
|
*/
|
|
367
370
|
async defaultBuild(options = {}) {
|
|
368
|
-
const { timeoutSecs, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
|
|
371
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, defaultBuildOptionsSchema, 'BuildClientGetOptions');
|
|
369
372
|
const response = await this.httpClient.call({
|
|
370
373
|
url: this.buildUrl('builds/default'),
|
|
371
374
|
method: 'GET',
|
|
372
375
|
params: this.buildParams(params),
|
|
373
376
|
timeoutSecs: this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish),
|
|
377
|
+
signal,
|
|
374
378
|
});
|
|
375
379
|
const { id } = parseResponse(response, schemas.Build());
|
|
376
380
|
return new BuildClient({
|
|
@@ -73,8 +73,8 @@ export class ActorCollectionClient extends ResourceCollectionClient {
|
|
|
73
73
|
*/
|
|
74
74
|
async create(actor, options = {}) {
|
|
75
75
|
parseArgument(actor, actorCreateSchema);
|
|
76
|
-
const { timeoutSecs = 'medium' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
77
|
-
return this.createResource(schemas.Actor(), actor, timeoutSecs);
|
|
76
|
+
const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
77
|
+
return this.createResource(schemas.Actor(), actor, timeoutSecs, signal);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -44,8 +44,8 @@ export class ActorEnvVarClient extends ResourceClient {
|
|
|
44
44
|
* @see https://docs.apify.com/api/v2/act-version-env-var-get
|
|
45
45
|
*/
|
|
46
46
|
async get(options = {}) {
|
|
47
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
48
|
-
return this.getResource(schemas.EnvVar(), {}, timeoutSecs);
|
|
47
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
48
|
+
return this.getResource(schemas.EnvVar(), {}, timeoutSecs, signal);
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Updates the environment variable.
|
|
@@ -58,8 +58,8 @@ export class ActorEnvVarClient extends ResourceClient {
|
|
|
58
58
|
*/
|
|
59
59
|
async update(actorEnvVar, options = {}) {
|
|
60
60
|
parseArgument(actorEnvVar, anyObjectSchema);
|
|
61
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
62
|
-
return this.updateResource(schemas.EnvVar(), actorEnvVar, timeoutSecs);
|
|
61
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
62
|
+
return this.updateResource(schemas.EnvVar(), actorEnvVar, timeoutSecs, signal);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Deletes the environment variable.
|
|
@@ -69,7 +69,7 @@ export class ActorEnvVarClient extends ResourceClient {
|
|
|
69
69
|
* @see https://docs.apify.com/api/v2/act-version-env-var-delete
|
|
70
70
|
*/
|
|
71
71
|
async delete(options = {}) {
|
|
72
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
73
|
-
return this.deleteResource(timeoutSecs);
|
|
72
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
73
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -61,8 +61,8 @@ export class ActorEnvVarCollectionClient extends ResourceCollectionClient {
|
|
|
61
61
|
* @see https://docs.apify.com/api/v2/act-version-env-vars-get
|
|
62
62
|
*/
|
|
63
63
|
list(options = {}) {
|
|
64
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
65
|
-
return this.listResourcesPaginated(schemas.ListOfEnvVars(), {}, timeoutSecs);
|
|
64
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
65
|
+
return this.listResourcesPaginated(schemas.ListOfEnvVars(), { signal }, timeoutSecs);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Creates a new environment variable for this Actor version.
|
|
@@ -75,7 +75,7 @@ export class ActorEnvVarCollectionClient extends ResourceCollectionClient {
|
|
|
75
75
|
*/
|
|
76
76
|
async create(actorEnvVar, options = {}) {
|
|
77
77
|
parseArgument(actorEnvVar, actorEnvVarSchema);
|
|
78
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
79
|
-
return this.createResource(schemas.EnvVar(), actorEnvVar, timeoutSecs);
|
|
78
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
79
|
+
return this.createResource(schemas.EnvVar(), actorEnvVar, timeoutSecs, signal);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -47,8 +47,8 @@ export class ActorVersionClient extends ResourceClient {
|
|
|
47
47
|
* @see https://docs.apify.com/api/v2/act-version-get
|
|
48
48
|
*/
|
|
49
49
|
async get(options = {}) {
|
|
50
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
51
|
-
return this.getResource(schemas.Version(), {}, timeoutSecs);
|
|
50
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
51
|
+
return this.getResource(schemas.Version(), {}, timeoutSecs, signal);
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Updates the Actor version with the specified fields.
|
|
@@ -61,8 +61,8 @@ export class ActorVersionClient extends ResourceClient {
|
|
|
61
61
|
*/
|
|
62
62
|
async update(newFields, options = {}) {
|
|
63
63
|
parseArgument(newFields, anyObjectSchema);
|
|
64
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
65
|
-
return this.updateResource(schemas.Version(), newFields, timeoutSecs);
|
|
64
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
65
|
+
return this.updateResource(schemas.Version(), newFields, timeoutSecs, signal);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Deletes the Actor version.
|
|
@@ -72,8 +72,8 @@ export class ActorVersionClient extends ResourceClient {
|
|
|
72
72
|
* @see https://docs.apify.com/api/v2/act-version-delete
|
|
73
73
|
*/
|
|
74
74
|
async delete(options = {}) {
|
|
75
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
76
|
-
return this.deleteResource(timeoutSecs);
|
|
75
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
76
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Returns a client for the specified environment variable of this Actor version.
|
|
@@ -60,8 +60,8 @@ export class ActorVersionCollectionClient extends ResourceCollectionClient {
|
|
|
60
60
|
* @see https://docs.apify.com/api/v2/act-versions-get
|
|
61
61
|
*/
|
|
62
62
|
list(options = {}) {
|
|
63
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
64
|
-
return this.listResourcesPaginated(schemas.ListOfVersions(), {}, timeoutSecs);
|
|
63
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
64
|
+
return this.listResourcesPaginated(schemas.ListOfVersions(), { signal }, timeoutSecs);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Creates a new Actor version.
|
|
@@ -74,7 +74,7 @@ export class ActorVersionCollectionClient extends ResourceCollectionClient {
|
|
|
74
74
|
*/
|
|
75
75
|
async create(actorVersion, options = {}) {
|
|
76
76
|
parseArgument(actorVersion, actorVersionSchema);
|
|
77
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
78
|
-
return this.createResource(schemas.Version(), actorVersion, timeoutSecs);
|
|
77
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
78
|
+
return this.createResource(schemas.Version(), actorVersion, timeoutSecs, signal);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -60,8 +60,8 @@ export class BuildClient extends ResourceClient {
|
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
async get(options = {}) {
|
|
63
|
-
const { timeoutSecs, ...params } = parseArgument(options, getOptionsSchema, 'BuildClientGetOptions');
|
|
64
|
-
return this.getResource(schemas.Build(), params, this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish));
|
|
63
|
+
const { timeoutSecs, signal, ...params } = parseArgument(options, getOptionsSchema, 'BuildClientGetOptions');
|
|
64
|
+
return this.getResource(schemas.Build(), params, this.timeoutForWaitForFinish(timeoutSecs, 'short', params.waitForFinish), signal);
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Aborts the Actor build.
|
|
@@ -79,12 +79,13 @@ export class BuildClient extends ResourceClient {
|
|
|
79
79
|
* ```
|
|
80
80
|
*/
|
|
81
81
|
async abort(options = {}) {
|
|
82
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
82
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
83
83
|
const response = await this.httpClient.call({
|
|
84
84
|
url: this.buildUrl('abort'),
|
|
85
85
|
method: 'POST',
|
|
86
86
|
params: this.buildParams(),
|
|
87
87
|
timeoutSecs,
|
|
88
|
+
signal,
|
|
88
89
|
});
|
|
89
90
|
return parseResponse(response, schemas.Build());
|
|
90
91
|
}
|
|
@@ -97,8 +98,8 @@ export class BuildClient extends ResourceClient {
|
|
|
97
98
|
* @since Added in 2.8.1
|
|
98
99
|
*/
|
|
99
100
|
async delete(options = {}) {
|
|
100
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
101
|
-
return this.deleteResource(timeoutSecs);
|
|
101
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
102
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Retrieves the OpenAPI definition for the Actor build.
|
|
@@ -110,12 +111,13 @@ export class BuildClient extends ResourceClient {
|
|
|
110
111
|
* @since Added in 2.11.2
|
|
111
112
|
*/
|
|
112
113
|
async getOpenApiDefinition(options = {}) {
|
|
113
|
-
const { timeoutSecs = 'medium' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
|
+
const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
115
|
const response = await this.httpClient.call({
|
|
115
116
|
url: this.buildUrl('openapi.json'),
|
|
116
117
|
method: 'GET',
|
|
117
118
|
params: this.buildParams(),
|
|
118
119
|
timeoutSecs,
|
|
120
|
+
signal,
|
|
119
121
|
});
|
|
120
122
|
return response.data;
|
|
121
123
|
}
|
|
@@ -44,8 +44,8 @@ const downloadItemsOptionsSchema = z.strictObject({
|
|
|
44
44
|
...timeoutOptionsShape,
|
|
45
45
|
});
|
|
46
46
|
const pushItemsSchema = z.union([itemSchema, z.string(), z.array(itemSchema)]);
|
|
47
|
-
// Apart from `timeoutSecs` and `expiresInSecs`, every option becomes a query parameter of the generated
|
|
48
|
-
// `chunkSize` (client-side only) and `signature` (which this method produces) are left out. The options type
|
|
47
|
+
// Apart from `timeoutSecs`, `signal` and `expiresInSecs`, every option becomes a query parameter of the generated
|
|
48
|
+
// URL, so `chunkSize` (client-side only) and `signature` (which this method produces) are left out. The options type
|
|
49
49
|
// omits both to match.
|
|
50
50
|
const createItemsPublicUrlOptionsSchema = z.strictObject({
|
|
51
51
|
clean: z.boolean().optional(),
|
|
@@ -110,8 +110,8 @@ export class DatasetClient extends ResourceClient {
|
|
|
110
110
|
* @see https://docs.apify.com/api/v2/dataset-get
|
|
111
111
|
*/
|
|
112
112
|
async get(options = {}) {
|
|
113
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
|
-
return this.getResource(schemas.Dataset(), {}, timeoutSecs);
|
|
113
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
114
|
+
return this.getResource(schemas.Dataset(), {}, timeoutSecs, signal);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* Updates the dataset with specified fields.
|
|
@@ -124,8 +124,8 @@ export class DatasetClient extends ResourceClient {
|
|
|
124
124
|
*/
|
|
125
125
|
async update(newFields, options = {}) {
|
|
126
126
|
parseArgument(newFields, anyObjectSchema);
|
|
127
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
128
|
-
return this.updateResource(schemas.Dataset(), newFields, timeoutSecs);
|
|
127
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
128
|
+
return this.updateResource(schemas.Dataset(), newFields, timeoutSecs, signal);
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* Deletes the dataset.
|
|
@@ -135,8 +135,8 @@ export class DatasetClient extends ResourceClient {
|
|
|
135
135
|
* @see https://docs.apify.com/api/v2/dataset-delete
|
|
136
136
|
*/
|
|
137
137
|
async delete(options = {}) {
|
|
138
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
139
|
-
return this.deleteResource(timeoutSecs);
|
|
138
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
139
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Lists items in the dataset.
|
|
@@ -184,13 +184,14 @@ export class DatasetClient extends ResourceClient {
|
|
|
184
184
|
* ```
|
|
185
185
|
*/
|
|
186
186
|
listItems(options = {}) {
|
|
187
|
-
const { timeoutSecs = 'long', ...listOptions } = parseArgument(options, listItemsOptionsSchema, 'DatasetClientListItemOptions');
|
|
187
|
+
const { timeoutSecs = 'long', signal, ...listOptions } = parseArgument(options, listItemsOptionsSchema, 'DatasetClientListItemOptions');
|
|
188
188
|
const fetchItems = async (datasetListOptions = {}) => {
|
|
189
189
|
const response = await this.httpClient.call({
|
|
190
190
|
url: this.buildUrl('items'),
|
|
191
191
|
method: 'GET',
|
|
192
192
|
params: this.buildParams(datasetListOptions),
|
|
193
193
|
timeoutSecs,
|
|
194
|
+
signal,
|
|
194
195
|
});
|
|
195
196
|
return this.#createPaginationList(response, datasetListOptions.desc ?? false);
|
|
196
197
|
};
|
|
@@ -239,7 +240,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
239
240
|
*/
|
|
240
241
|
async downloadItems(format, options = {}) {
|
|
241
242
|
parseArgument(format, itemFormatSchema);
|
|
242
|
-
const { timeoutSecs = 'long', ...query } = parseArgument(options, downloadItemsOptionsSchema, 'DatasetClientDownloadItemsOptions');
|
|
243
|
+
const { timeoutSecs = 'long', signal, ...query } = parseArgument(options, downloadItemsOptionsSchema, 'DatasetClientDownloadItemsOptions');
|
|
243
244
|
const { data } = await this.httpClient.call({
|
|
244
245
|
url: this.buildUrl('items'),
|
|
245
246
|
method: 'GET',
|
|
@@ -249,6 +250,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
249
250
|
}),
|
|
250
251
|
responseType: 'buffer',
|
|
251
252
|
timeoutSecs,
|
|
253
|
+
signal,
|
|
252
254
|
});
|
|
253
255
|
return cast(data);
|
|
254
256
|
}
|
|
@@ -286,7 +288,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
286
288
|
*/
|
|
287
289
|
async pushItems(items, options = {}) {
|
|
288
290
|
parseArgument(items, pushItemsSchema);
|
|
289
|
-
const { timeoutSecs = 'medium' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
291
|
+
const { timeoutSecs = 'medium', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
290
292
|
await this.httpClient.call({
|
|
291
293
|
url: this.buildUrl('items'),
|
|
292
294
|
method: 'POST',
|
|
@@ -297,6 +299,7 @@ export class DatasetClient extends ResourceClient {
|
|
|
297
299
|
params: this.buildParams(),
|
|
298
300
|
doNotRetryTimeouts: true,
|
|
299
301
|
timeoutSecs,
|
|
302
|
+
signal,
|
|
300
303
|
});
|
|
301
304
|
}
|
|
302
305
|
/**
|
|
@@ -312,12 +315,13 @@ export class DatasetClient extends ResourceClient {
|
|
|
312
315
|
* @since Added in 2.11.2
|
|
313
316
|
*/
|
|
314
317
|
async getStatistics(options = {}) {
|
|
315
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
318
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
316
319
|
const response = await this.httpClient.call({
|
|
317
320
|
url: this.buildUrl('statistics'),
|
|
318
321
|
method: 'GET',
|
|
319
322
|
params: this.buildParams(),
|
|
320
323
|
timeoutSecs,
|
|
324
|
+
signal,
|
|
321
325
|
});
|
|
322
326
|
return parseResponse(response, schemas.DatasetStatistics());
|
|
323
327
|
}
|
|
@@ -355,8 +359,8 @@ export class DatasetClient extends ResourceClient {
|
|
|
355
359
|
* @since Added in 2.13.0
|
|
356
360
|
*/
|
|
357
361
|
async createItemsPublicUrl(options = {}) {
|
|
358
|
-
const { timeoutSecs = 'long', expiresInSecs, ...queryOptions } = parseArgument(options, createItemsPublicUrlOptionsSchema, 'DatasetClientCreateItemsUrlOptions');
|
|
359
|
-
const dataset = await this.get({ timeoutSecs });
|
|
362
|
+
const { timeoutSecs = 'long', signal, expiresInSecs, ...queryOptions } = parseArgument(options, createItemsPublicUrlOptionsSchema, 'DatasetClientCreateItemsUrlOptions');
|
|
363
|
+
const dataset = await this.get({ timeoutSecs, signal });
|
|
360
364
|
let createdItemsPublicUrl = new URL(this.buildPublicUrl('items'));
|
|
361
365
|
if (dataset?.urlSigningSecretKey) {
|
|
362
366
|
const signature = await createStorageContentSignatureAsync({
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
4
|
import * as schemas from '../schemas.js';
|
|
5
|
-
import { optionalTimeoutSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
5
|
+
import { optionalSignalSchema, optionalTimeoutSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
6
6
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
7
7
|
const listOptionsSchema = z.strictObject({
|
|
8
8
|
unnamed: z.boolean().optional(),
|
|
@@ -82,10 +82,11 @@ export class DatasetCollectionClient extends ResourceCollectionClient {
|
|
|
82
82
|
parseArgument(name, nameSchema);
|
|
83
83
|
parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
|
|
84
84
|
parseArgument(options?.timeoutSecs, optionalTimeoutSchema);
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
|
|
85
|
+
parseArgument(options?.signal, optionalSignalSchema);
|
|
86
|
+
// `timeoutSecs` and `signal` are not part of the resource, so the body carries only the rest, and stays
|
|
87
|
+
// absent when there is nothing else to send.
|
|
88
|
+
const { timeoutSecs = 'short', signal, ...resource } = options ?? {};
|
|
88
89
|
const hasResource = Object.keys(resource).length > 0;
|
|
89
|
-
return this.getOrCreateResource(schemas.Dataset(), name, hasResource ? resource : undefined, timeoutSecs);
|
|
90
|
+
return this.getOrCreateResource(schemas.Dataset(), name, hasResource ? resource : undefined, timeoutSecs, signal);
|
|
90
91
|
}
|
|
91
92
|
}
|
|
@@ -96,8 +96,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
96
96
|
* @see https://docs.apify.com/api/v2/key-value-store-get
|
|
97
97
|
*/
|
|
98
98
|
async get(options = {}) {
|
|
99
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
100
|
-
return this.getResource(schemas.KeyValueStore(), {}, timeoutSecs);
|
|
99
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
100
|
+
return this.getResource(schemas.KeyValueStore(), {}, timeoutSecs, signal);
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Updates the key-value store with specified fields.
|
|
@@ -113,8 +113,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
113
113
|
*/
|
|
114
114
|
async update(newFields, options = {}) {
|
|
115
115
|
parseArgument(newFields, anyObjectSchema);
|
|
116
|
-
const { timeoutSecs = 'long' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
117
|
-
return this.updateResource(schemas.KeyValueStore(), newFields, timeoutSecs);
|
|
116
|
+
const { timeoutSecs = 'long', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
117
|
+
return this.updateResource(schemas.KeyValueStore(), newFields, timeoutSecs, signal);
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* Deletes the key-value store.
|
|
@@ -124,8 +124,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
124
124
|
* @see https://docs.apify.com/api/v2/key-value-store-delete
|
|
125
125
|
*/
|
|
126
126
|
async delete(options = {}) {
|
|
127
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
128
|
-
return this.deleteResource(timeoutSecs);
|
|
127
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
128
|
+
return this.deleteResource(timeoutSecs, signal);
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* Lists all keys in the key-value store.
|
|
@@ -164,13 +164,14 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
166
166
|
listKeys(options = {}) {
|
|
167
|
-
const { timeoutSecs = 'medium', ...parsed } = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
|
|
167
|
+
const { timeoutSecs = 'medium', signal, ...parsed } = parseArgument(options, listKeysOptionsSchema, 'KeyValueClientListKeysOptions');
|
|
168
168
|
const getPaginatedList = async (kvsListOptions = {}) => {
|
|
169
169
|
const response = await this.httpClient.call({
|
|
170
170
|
url: this.buildUrl('keys'),
|
|
171
171
|
method: 'GET',
|
|
172
172
|
params: this.buildParams(kvsListOptions),
|
|
173
173
|
timeoutSecs,
|
|
174
|
+
signal,
|
|
174
175
|
});
|
|
175
176
|
return parseResponse(response, schemas.ListOfKeys());
|
|
176
177
|
};
|
|
@@ -223,8 +224,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
223
224
|
*/
|
|
224
225
|
async getRecordPublicUrl(key, options = {}) {
|
|
225
226
|
parseArgument(key, nonEmptyKeySchema);
|
|
226
|
-
const { timeoutSecs = 'long' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
227
|
-
const store = await this.get({ timeoutSecs });
|
|
227
|
+
const { timeoutSecs = 'long', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
228
|
+
const store = await this.get({ timeoutSecs, signal });
|
|
228
229
|
const recordPublicUrl = new URL(this.buildPublicUrl(['records', key]));
|
|
229
230
|
if (store?.urlSigningSecretKey) {
|
|
230
231
|
const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
|
|
@@ -257,8 +258,8 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
257
258
|
* @since Added in 2.13.0
|
|
258
259
|
*/
|
|
259
260
|
async createKeysPublicUrl(options = {}) {
|
|
260
|
-
const { timeoutSecs = 'long', expiresInSecs, ...queryOptions } = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
|
|
261
|
-
const store = await this.get({ timeoutSecs });
|
|
261
|
+
const { timeoutSecs = 'long', signal, expiresInSecs, ...queryOptions } = parseArgument(options, createKeysPublicUrlOptionsSchema, 'KeyValueClientCreateKeysUrlOptions');
|
|
262
|
+
const store = await this.get({ timeoutSecs, signal });
|
|
262
263
|
let createdPublicKeysUrl = new URL(this.buildPublicUrl('keys'));
|
|
263
264
|
if (store?.urlSigningSecretKey) {
|
|
264
265
|
const signature = await createStorageContentSignatureAsync({
|
|
@@ -292,12 +293,13 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
292
293
|
* @since Added in 2.9.0
|
|
293
294
|
*/
|
|
294
295
|
async recordExists(key, options = {}) {
|
|
295
|
-
const { timeoutSecs = 'long' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
296
|
+
const { timeoutSecs = 'long', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
296
297
|
const requestOpts = {
|
|
297
298
|
url: this.buildUrl(['records', key]),
|
|
298
299
|
method: 'HEAD',
|
|
299
300
|
params: this.buildParams(),
|
|
300
301
|
timeoutSecs,
|
|
302
|
+
signal,
|
|
301
303
|
};
|
|
302
304
|
try {
|
|
303
305
|
await this.httpClient.call(requestOpts);
|
|
@@ -326,6 +328,7 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
326
328
|
method: 'GET',
|
|
327
329
|
params: this.buildParams(queryParams),
|
|
328
330
|
timeoutSecs: parsed.timeoutSecs ?? 'long',
|
|
331
|
+
signal: parsed.signal,
|
|
329
332
|
};
|
|
330
333
|
if (parsed.buffer)
|
|
331
334
|
requestOpts.responseType = 'buffer';
|
|
@@ -404,7 +407,7 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
404
407
|
const parsed = parseArgument(options, recordOptionsSchema, 'KeyValueStoreRecordOptions');
|
|
405
408
|
const { key } = record;
|
|
406
409
|
let { value, contentType } = record;
|
|
407
|
-
const { timeoutSecs = 'long', doNotRetryTimeouts } = parsed;
|
|
410
|
+
const { timeoutSecs = 'long', signal, doNotRetryTimeouts } = parsed;
|
|
408
411
|
const isValueStreamOrBuffer = isStream(value) || isBuffer(value);
|
|
409
412
|
// To allow saving Objects to JSON without providing content type
|
|
410
413
|
if (!contentType) {
|
|
@@ -433,6 +436,7 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
433
436
|
headers: contentType ? { 'content-type': contentType } : undefined,
|
|
434
437
|
doNotRetryTimeouts,
|
|
435
438
|
timeoutSecs,
|
|
439
|
+
signal,
|
|
436
440
|
};
|
|
437
441
|
await this.httpClient.call(uploadOpts);
|
|
438
442
|
}
|
|
@@ -451,12 +455,13 @@ export class KeyValueStoreClient extends ResourceClient {
|
|
|
451
455
|
*/
|
|
452
456
|
async deleteRecord(key, options = {}) {
|
|
453
457
|
parseArgument(key, keySchema);
|
|
454
|
-
const { timeoutSecs = 'short' } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
458
|
+
const { timeoutSecs = 'short', signal } = parseArgument(options, timeoutOptionsSchema, 'TimeoutOptions');
|
|
455
459
|
await this.httpClient.call({
|
|
456
460
|
url: this.buildUrl(['records', key]),
|
|
457
461
|
method: 'DELETE',
|
|
458
462
|
params: this.buildParams(),
|
|
459
463
|
timeoutSecs,
|
|
464
|
+
signal,
|
|
460
465
|
});
|
|
461
466
|
}
|
|
462
467
|
}
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { STORAGE_OWNERSHIP_FILTER } from '@apify/consts';
|
|
3
3
|
import { ResourceCollectionClient } from '../base/resource_collection_client.js';
|
|
4
4
|
import * as schemas from '../schemas.js';
|
|
5
|
-
import { optionalTimeoutSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
5
|
+
import { optionalSignalSchema, optionalTimeoutSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
6
6
|
import { anyObjectSchema, paginationOptionsShape, parseArgument } from '../utils.js';
|
|
7
7
|
const listOptionsSchema = z.strictObject({
|
|
8
8
|
unnamed: z.boolean().optional(),
|
|
@@ -82,10 +82,11 @@ export class KeyValueStoreCollectionClient extends ResourceCollectionClient {
|
|
|
82
82
|
parseArgument(name, nameSchema);
|
|
83
83
|
parseArgument(options?.schema, schemaSchema); // TODO: Add schema validation
|
|
84
84
|
parseArgument(options?.timeoutSecs, optionalTimeoutSchema);
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
|
|
85
|
+
parseArgument(options?.signal, optionalSignalSchema);
|
|
86
|
+
// `timeoutSecs` and `signal` are not part of the resource, so the body carries only the rest, and stays
|
|
87
|
+
// absent when there is nothing else to send.
|
|
88
|
+
const { timeoutSecs = 'short', signal, ...resource } = options ?? {};
|
|
88
89
|
const hasResource = Object.keys(resource).length > 0;
|
|
89
|
-
return this.getOrCreateResource(schemas.KeyValueStore(), name, hasResource ? resource : undefined, timeoutSecs);
|
|
90
|
+
return this.getOrCreateResource(schemas.KeyValueStore(), name, hasResource ? resource : undefined, timeoutSecs, signal);
|
|
90
91
|
}
|
|
91
92
|
}
|