@apify/input_schema 3.15.2 → 3.16.0
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/cjs/index.cjs +143 -54
- package/cjs/index.cjs.map +1 -1
- package/cjs/index.d.ts +290 -118
- package/esm/index.d.mts +290 -118
- package/esm/index.mjs +143 -54
- package/esm/index.mjs.map +1 -1
- package/package.json +3 -2
package/esm/index.mjs
CHANGED
|
@@ -19,7 +19,8 @@ var intlStrings = {
|
|
|
19
19
|
"inputSchema.validation.noAvailableAutoProxy": "Currently you do not have access to any proxy group usable in automatic mode.",
|
|
20
20
|
"inputSchema.validation.noMatchingDefinition": "Field schema.properties.{fieldKey} is not matching any input schema type definition. Please make sure that it's type is valid.",
|
|
21
21
|
"inputSchema.validation.missingRequiredField": "Field schema.properties.{fieldKey} does not exist, but it is specified in schema.required. Either define the field or remove it from schema.required.",
|
|
22
|
-
"inputSchema.validation.proxyGroupMustBeArrayOfStrings": "Field {rootName}.{fieldKey}.apifyProxyGroups must be an array of strings."
|
|
22
|
+
"inputSchema.validation.proxyGroupMustBeArrayOfStrings": "Field {rootName}.{fieldKey}.apifyProxyGroups must be an array of strings.",
|
|
23
|
+
"inputSchema.validation.secretFieldSchemaChanged": "The field schema.properties.{fieldKey} is a secret field, but its schema has changed. Please update the value in the input editor."
|
|
23
24
|
};
|
|
24
25
|
function m(stringId, variables) {
|
|
25
26
|
let text = intlStrings[stringId];
|
|
@@ -188,6 +189,7 @@ var schema_default = {
|
|
|
188
189
|
type: { enum: ["string"] },
|
|
189
190
|
title: { type: "string" },
|
|
190
191
|
description: { type: "string" },
|
|
192
|
+
prefill: { type: "string" },
|
|
191
193
|
example: { type: "string" },
|
|
192
194
|
nullable: { type: "boolean" },
|
|
193
195
|
editor: { enum: ["textfield", "textarea", "hidden"] },
|
|
@@ -202,48 +204,84 @@ var schema_default = {
|
|
|
202
204
|
type: "object",
|
|
203
205
|
properties: {
|
|
204
206
|
type: { enum: ["array"] },
|
|
205
|
-
editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "select", "hidden"] }
|
|
207
|
+
editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "select", "hidden"] },
|
|
208
|
+
isSecret: { type: "boolean" }
|
|
206
209
|
},
|
|
207
210
|
additionalProperties: true,
|
|
208
211
|
required: ["type", "title", "description", "editor"],
|
|
209
212
|
if: {
|
|
210
213
|
properties: {
|
|
211
|
-
|
|
214
|
+
isSecret: {
|
|
215
|
+
not: {
|
|
216
|
+
const: true
|
|
217
|
+
}
|
|
218
|
+
}
|
|
212
219
|
}
|
|
213
220
|
},
|
|
214
221
|
then: {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
type: "
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
if: {
|
|
223
|
+
properties: {
|
|
224
|
+
editor: { const: "select" }
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
then: {
|
|
228
|
+
additionalProperties: false,
|
|
229
|
+
required: ["items"],
|
|
230
|
+
properties: {
|
|
231
|
+
type: { enum: ["array"] },
|
|
232
|
+
editor: { enum: ["select"] },
|
|
233
|
+
title: { type: "string" },
|
|
234
|
+
description: { type: "string" },
|
|
235
|
+
default: { type: "array" },
|
|
236
|
+
prefill: { type: "array" },
|
|
237
|
+
example: { type: "array" },
|
|
238
|
+
nullable: { type: "boolean" },
|
|
239
|
+
minItems: { type: "integer" },
|
|
240
|
+
maxItems: { type: "integer" },
|
|
241
|
+
uniqueItems: { type: "boolean" },
|
|
242
|
+
sectionCaption: { type: "string" },
|
|
243
|
+
sectionDescription: { type: "string" },
|
|
244
|
+
items: {
|
|
245
|
+
type: "object",
|
|
246
|
+
additionalProperties: false,
|
|
247
|
+
properties: {
|
|
248
|
+
type: { enum: ["string"] },
|
|
249
|
+
enum: {
|
|
250
|
+
type: "array",
|
|
251
|
+
items: { type: "string" },
|
|
252
|
+
uniqueItems: true
|
|
253
|
+
},
|
|
254
|
+
enumTitles: {
|
|
255
|
+
type: "array",
|
|
256
|
+
items: { type: "string" }
|
|
257
|
+
}
|
|
240
258
|
},
|
|
241
|
-
|
|
242
|
-
type: "array",
|
|
243
|
-
items: { type: "string" }
|
|
244
|
-
}
|
|
259
|
+
required: ["type", "enum"]
|
|
245
260
|
},
|
|
246
|
-
|
|
261
|
+
isSecret: { enum: [false] }
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
else: {
|
|
265
|
+
additionalProperties: false,
|
|
266
|
+
properties: {
|
|
267
|
+
type: { enum: ["array"] },
|
|
268
|
+
editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "hidden"] },
|
|
269
|
+
title: { type: "string" },
|
|
270
|
+
description: { type: "string" },
|
|
271
|
+
default: { type: "array" },
|
|
272
|
+
prefill: { type: "array" },
|
|
273
|
+
example: { type: "array" },
|
|
274
|
+
nullable: { type: "boolean" },
|
|
275
|
+
minItems: { type: "integer" },
|
|
276
|
+
maxItems: { type: "integer" },
|
|
277
|
+
uniqueItems: { type: "boolean" },
|
|
278
|
+
sectionCaption: { type: "string" },
|
|
279
|
+
sectionDescription: { type: "string" },
|
|
280
|
+
placeholderKey: { type: "string" },
|
|
281
|
+
placeholderValue: { type: "string" },
|
|
282
|
+
patternKey: { type: "string" },
|
|
283
|
+
patternValue: { type: "string" },
|
|
284
|
+
isSecret: { enum: [false] }
|
|
247
285
|
}
|
|
248
286
|
}
|
|
249
287
|
},
|
|
@@ -251,10 +289,9 @@ var schema_default = {
|
|
|
251
289
|
additionalProperties: false,
|
|
252
290
|
properties: {
|
|
253
291
|
type: { enum: ["array"] },
|
|
254
|
-
editor: { enum: ["json", "
|
|
292
|
+
editor: { enum: ["json", "hidden"] },
|
|
255
293
|
title: { type: "string" },
|
|
256
294
|
description: { type: "string" },
|
|
257
|
-
default: { type: "array" },
|
|
258
295
|
prefill: { type: "array" },
|
|
259
296
|
example: { type: "array" },
|
|
260
297
|
nullable: { type: "boolean" },
|
|
@@ -263,34 +300,70 @@ var schema_default = {
|
|
|
263
300
|
uniqueItems: { type: "boolean" },
|
|
264
301
|
sectionCaption: { type: "string" },
|
|
265
302
|
sectionDescription: { type: "string" },
|
|
266
|
-
|
|
267
|
-
placeholderValue: { type: "string" },
|
|
268
|
-
patternKey: { type: "string" },
|
|
269
|
-
patternValue: { type: "string" }
|
|
303
|
+
isSecret: { enum: [true] }
|
|
270
304
|
}
|
|
271
305
|
}
|
|
272
306
|
},
|
|
273
307
|
objectProperty: {
|
|
274
308
|
title: "Object property",
|
|
275
309
|
type: "object",
|
|
276
|
-
additionalProperties:
|
|
310
|
+
additionalProperties: true,
|
|
277
311
|
properties: {
|
|
278
312
|
type: { enum: ["object"] },
|
|
279
313
|
title: { type: "string" },
|
|
280
314
|
description: { type: "string" },
|
|
281
|
-
default: { type: "object" },
|
|
282
|
-
prefill: { type: "object" },
|
|
283
|
-
example: { type: "object" },
|
|
284
|
-
patternKey: { type: "string" },
|
|
285
|
-
patternValue: { type: "string" },
|
|
286
|
-
nullable: { type: "boolean" },
|
|
287
|
-
minProperties: { type: "integer" },
|
|
288
|
-
maxProperties: { type: "integer" },
|
|
289
315
|
editor: { enum: ["json", "proxy", "hidden"] },
|
|
290
|
-
|
|
291
|
-
sectionDescription: { type: "string" }
|
|
316
|
+
isSecret: { type: "boolean" }
|
|
292
317
|
},
|
|
293
|
-
required: ["type", "title", "description", "editor"]
|
|
318
|
+
required: ["type", "title", "description", "editor"],
|
|
319
|
+
if: {
|
|
320
|
+
properties: {
|
|
321
|
+
isSecret: {
|
|
322
|
+
not: {
|
|
323
|
+
const: true
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
then: {
|
|
329
|
+
additionalProperties: false,
|
|
330
|
+
properties: {
|
|
331
|
+
type: { enum: ["object"] },
|
|
332
|
+
title: { type: "string" },
|
|
333
|
+
description: { type: "string" },
|
|
334
|
+
default: { type: "object" },
|
|
335
|
+
prefill: { type: "object" },
|
|
336
|
+
example: { type: "object" },
|
|
337
|
+
patternKey: { type: "string" },
|
|
338
|
+
patternValue: { type: "string" },
|
|
339
|
+
nullable: { type: "boolean" },
|
|
340
|
+
minProperties: { type: "integer" },
|
|
341
|
+
maxProperties: { type: "integer" },
|
|
342
|
+
editor: { enum: ["json", "proxy", "hidden"] },
|
|
343
|
+
sectionCaption: { type: "string" },
|
|
344
|
+
sectionDescription: { type: "string" },
|
|
345
|
+
isSecret: { enum: [false] }
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
else: {
|
|
349
|
+
additionalProperties: false,
|
|
350
|
+
properties: {
|
|
351
|
+
type: { enum: ["object"] },
|
|
352
|
+
title: { type: "string" },
|
|
353
|
+
description: { type: "string" },
|
|
354
|
+
prefill: { type: "object" },
|
|
355
|
+
example: { type: "object" },
|
|
356
|
+
patternKey: { type: "string" },
|
|
357
|
+
patternValue: { type: "string" },
|
|
358
|
+
nullable: { type: "boolean" },
|
|
359
|
+
minProperties: { type: "integer" },
|
|
360
|
+
maxProperties: { type: "integer" },
|
|
361
|
+
editor: { enum: ["json", "hidden"] },
|
|
362
|
+
sectionCaption: { type: "string" },
|
|
363
|
+
sectionDescription: { type: "string" },
|
|
364
|
+
isSecret: { enum: [true] }
|
|
365
|
+
}
|
|
366
|
+
}
|
|
294
367
|
},
|
|
295
368
|
integerProperty: {
|
|
296
369
|
title: "Integer property",
|
|
@@ -557,6 +630,7 @@ __name(validateInputSchema, "validateInputSchema");
|
|
|
557
630
|
import { parse } from "acorn-loose";
|
|
558
631
|
import { countries } from "countries-list";
|
|
559
632
|
import { PROXY_URL_REGEX, URL_REGEX } from "@apify/consts";
|
|
633
|
+
import { isEncryptedValueForFieldSchema, isEncryptedValueForFieldType } from "@apify/input_secrets";
|
|
560
634
|
function validateProxyField(fieldKey, value, isRequired = false, options = null) {
|
|
561
635
|
const fieldErrors = [];
|
|
562
636
|
if (isRequired) {
|
|
@@ -626,11 +700,21 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
626
700
|
const required = inputSchema.required || [];
|
|
627
701
|
let errors = [];
|
|
628
702
|
if (!isValid) {
|
|
629
|
-
errors = validator.errors.
|
|
703
|
+
errors = validator.errors.filter((error) => {
|
|
704
|
+
if (error.keyword === "type" && error.instancePath) {
|
|
705
|
+
const path = error.instancePath.replace(/^\//, "").split("/")[0];
|
|
706
|
+
const propSchema = inputSchema.properties?.[path];
|
|
707
|
+
const value = input[path];
|
|
708
|
+
if (propSchema?.isSecret && typeof value === "string" && (propSchema.type === "object" || propSchema.type === "array") && isEncryptedValueForFieldType(value, propSchema.type)) {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return true;
|
|
713
|
+
}).map((error) => parseAjvError(error, "input", properties, input)).filter((error) => !!error);
|
|
630
714
|
}
|
|
631
715
|
Object.keys(properties).forEach((property) => {
|
|
632
716
|
const value = input[property];
|
|
633
|
-
const { type, editor, patternKey, patternValue } = properties[property];
|
|
717
|
+
const { type, editor, patternKey, patternValue, isSecret } = properties[property];
|
|
634
718
|
const fieldErrors = [];
|
|
635
719
|
if (type === "object" && editor === "proxy") {
|
|
636
720
|
const proxyValidationErrors = validateProxyField(property, value, required.includes(property), options.proxy);
|
|
@@ -700,7 +784,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
700
784
|
}
|
|
701
785
|
}
|
|
702
786
|
}
|
|
703
|
-
if (type === "object" && value) {
|
|
787
|
+
if (type === "object" && value && typeof value === "object") {
|
|
704
788
|
if (patternKey) {
|
|
705
789
|
const check = new RegExp(patternKey);
|
|
706
790
|
const invalidKeys = [];
|
|
@@ -733,6 +817,11 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
|
|
|
733
817
|
}
|
|
734
818
|
}
|
|
735
819
|
}
|
|
820
|
+
if (isSecret && value && typeof value === "string") {
|
|
821
|
+
if (isEncryptedValueForFieldType(value, type) && !isEncryptedValueForFieldSchema(value, properties[property])) {
|
|
822
|
+
fieldErrors.push(m("inputSchema.validation.secretFieldSchemaChanged", { fieldKey: property }));
|
|
823
|
+
}
|
|
824
|
+
}
|
|
736
825
|
if (fieldErrors.length > 0) {
|
|
737
826
|
const message = fieldErrors.join(", ");
|
|
738
827
|
errors.push({ fieldKey: property, message });
|