@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/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
- editor: { const: "select" }
214
+ isSecret: {
215
+ not: {
216
+ const: true
217
+ }
218
+ }
212
219
  }
213
220
  },
214
221
  then: {
215
- additionalProperties: false,
216
- required: ["items"],
217
- properties: {
218
- type: { enum: ["array"] },
219
- editor: { enum: ["select"] },
220
- title: { type: "string" },
221
- description: { type: "string" },
222
- default: { type: "array" },
223
- prefill: { type: "array" },
224
- example: { type: "array" },
225
- nullable: { type: "boolean" },
226
- minItems: { type: "integer" },
227
- maxItems: { type: "integer" },
228
- uniqueItems: { type: "boolean" },
229
- sectionCaption: { type: "string" },
230
- sectionDescription: { type: "string" },
231
- items: {
232
- type: "object",
233
- additionalProperties: false,
234
- properties: {
235
- type: { enum: ["string"] },
236
- enum: {
237
- type: "array",
238
- items: { type: "string" },
239
- uniqueItems: true
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
- enumTitles: {
242
- type: "array",
243
- items: { type: "string" }
244
- }
259
+ required: ["type", "enum"]
245
260
  },
246
- required: ["type", "enum"]
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", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "hidden"] },
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
- placeholderKey: { type: "string" },
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: false,
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
- sectionCaption: { type: "string" },
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.map((error) => parseAjvError(error, "input", properties, input)).filter((error) => !!error);
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 });