apify-client 2.23.5-beta.19 → 2.23.5-beta.20
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/bundle.js +57 -4
- package/dist/bundle.js.map +1 -1
- package/dist/resource_clients/actor.d.ts +48 -0
- package/dist/resource_clients/actor.js +54 -3
- package/package.json +1 -1
|
@@ -133,6 +133,37 @@ export declare class ActorClient extends ResourceClient {
|
|
|
133
133
|
* ```
|
|
134
134
|
*/
|
|
135
135
|
call(input?: unknown, options?: ActorCallOptions): Promise<ActorRun>;
|
|
136
|
+
/**
|
|
137
|
+
* Validates the provided input for the Actor against its input schema.
|
|
138
|
+
*
|
|
139
|
+
* Sends the input to the API, which validates it against the Actor's input schema without
|
|
140
|
+
* starting a run. If the input is valid, the method resolves with `true`. If the input is
|
|
141
|
+
* invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
|
|
142
|
+
* validation problem.
|
|
143
|
+
*
|
|
144
|
+
* @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
|
|
145
|
+
* value (object, array, string, number). If `contentType` is specified in options,
|
|
146
|
+
* input should be a string or Buffer.
|
|
147
|
+
* @param options - Validation options
|
|
148
|
+
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
149
|
+
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
150
|
+
* @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
|
|
151
|
+
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
152
|
+
* @see https://docs.apify.com/api/v2/act-input-validate-post
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```javascript
|
|
156
|
+
* // Validate input against the default build's input schema
|
|
157
|
+
* const isValid = await client.actor('my-actor').validateInput({ url: 'https://example.com' });
|
|
158
|
+
*
|
|
159
|
+
* // Validate against a specific build
|
|
160
|
+
* const isValid = await client.actor('my-actor').validateInput(
|
|
161
|
+
* { url: 'https://example.com' },
|
|
162
|
+
* { build: 'beta' },
|
|
163
|
+
* );
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
validateInput(input?: unknown, options?: ActorValidateInputOptions): Promise<boolean>;
|
|
136
167
|
/**
|
|
137
168
|
* Builds the Actor.
|
|
138
169
|
*
|
|
@@ -586,6 +617,23 @@ export interface ActorRunOptions {
|
|
|
586
617
|
maxTotalChargeUsd?: number;
|
|
587
618
|
restartOnError?: boolean;
|
|
588
619
|
}
|
|
620
|
+
/**
|
|
621
|
+
* Options for validating an Actor input.
|
|
622
|
+
*/
|
|
623
|
+
export interface ActorValidateInputOptions {
|
|
624
|
+
/**
|
|
625
|
+
* Tag or number of the Actor build whose input schema the input is validated against
|
|
626
|
+
* (e.g. `beta` or `1.2.345`). If not provided, the default build is used.
|
|
627
|
+
*/
|
|
628
|
+
build?: string;
|
|
629
|
+
/**
|
|
630
|
+
* Content type for the `input`. If not specified,
|
|
631
|
+
* `input` is expected to be an object that will be stringified to JSON and content type set to
|
|
632
|
+
* `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
|
|
633
|
+
* `String` or `Buffer`.
|
|
634
|
+
*/
|
|
635
|
+
contentType?: string;
|
|
636
|
+
}
|
|
589
637
|
/**
|
|
590
638
|
* Options for building an Actor.
|
|
591
639
|
*/
|
|
@@ -140,9 +140,6 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
140
140
|
params: this._params(params),
|
|
141
141
|
// Apify internal property. Tells the request serialization interceptor
|
|
142
142
|
// to stringify functions to JSON, instead of omitting them.
|
|
143
|
-
// TODO: remove this ts-expect-error once we migrate HttpClient to TS and define Apify
|
|
144
|
-
// extension of Axios configs
|
|
145
|
-
// @ts-expect-error Apify extension
|
|
146
143
|
stringifyFunctions: true,
|
|
147
144
|
};
|
|
148
145
|
if (options.contentType) {
|
|
@@ -221,6 +218,60 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
221
218
|
await streamedLog?.stop();
|
|
222
219
|
});
|
|
223
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Validates the provided input for the Actor against its input schema.
|
|
223
|
+
*
|
|
224
|
+
* Sends the input to the API, which validates it against the Actor's input schema without
|
|
225
|
+
* starting a run. If the input is valid, the method resolves with `true`. If the input is
|
|
226
|
+
* invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
|
|
227
|
+
* validation problem.
|
|
228
|
+
*
|
|
229
|
+
* @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
|
|
230
|
+
* value (object, array, string, number). If `contentType` is specified in options,
|
|
231
|
+
* input should be a string or Buffer.
|
|
232
|
+
* @param options - Validation options
|
|
233
|
+
* @param options.build - Tag or number of the build whose input schema the input is validated against
|
|
234
|
+
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
235
|
+
* @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
|
|
236
|
+
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
237
|
+
* @see https://docs.apify.com/api/v2/act-input-validate-post
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```javascript
|
|
241
|
+
* // Validate input against the default build's input schema
|
|
242
|
+
* const isValid = await client.actor('my-actor').validateInput({ url: 'https://example.com' });
|
|
243
|
+
*
|
|
244
|
+
* // Validate against a specific build
|
|
245
|
+
* const isValid = await client.actor('my-actor').validateInput(
|
|
246
|
+
* { url: 'https://example.com' },
|
|
247
|
+
* { build: 'beta' },
|
|
248
|
+
* );
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
async validateInput(input, options = {}) {
|
|
252
|
+
// input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
|
|
253
|
+
// then it will process input as a buffer.
|
|
254
|
+
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
255
|
+
build: ow_1.default.optional.string,
|
|
256
|
+
contentType: ow_1.default.optional.string,
|
|
257
|
+
}));
|
|
258
|
+
const request = {
|
|
259
|
+
url: this._url('validate-input'),
|
|
260
|
+
method: 'POST',
|
|
261
|
+
data: input,
|
|
262
|
+
params: this._params({ build: options.build }),
|
|
263
|
+
// Apify internal property. Tells the request serialization interceptor
|
|
264
|
+
// to stringify functions to JSON, instead of omitting them.
|
|
265
|
+
stringifyFunctions: true,
|
|
266
|
+
};
|
|
267
|
+
if (options.contentType) {
|
|
268
|
+
request.headers = {
|
|
269
|
+
'content-type': options.contentType,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
const response = await this.httpClient.call(request);
|
|
273
|
+
return response.data.valid;
|
|
274
|
+
}
|
|
224
275
|
/**
|
|
225
276
|
* Builds the Actor.
|
|
226
277
|
*
|