@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 CHANGED
@@ -49,7 +49,8 @@ var intlStrings = {
49
49
  "inputSchema.validation.noAvailableAutoProxy": "Currently you do not have access to any proxy group usable in automatic mode.",
50
50
  "inputSchema.validation.noMatchingDefinition": "Field schema.properties.{fieldKey} is not matching any input schema type definition. Please make sure that it's type is valid.",
51
51
  "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.",
52
- "inputSchema.validation.proxyGroupMustBeArrayOfStrings": "Field {rootName}.{fieldKey}.apifyProxyGroups must be an array of strings."
52
+ "inputSchema.validation.proxyGroupMustBeArrayOfStrings": "Field {rootName}.{fieldKey}.apifyProxyGroups must be an array of strings.",
53
+ "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."
53
54
  };
54
55
  function m(stringId, variables) {
55
56
  let text = intlStrings[stringId];
@@ -218,6 +219,7 @@ var schema_default = {
218
219
  type: { enum: ["string"] },
219
220
  title: { type: "string" },
220
221
  description: { type: "string" },
222
+ prefill: { type: "string" },
221
223
  example: { type: "string" },
222
224
  nullable: { type: "boolean" },
223
225
  editor: { enum: ["textfield", "textarea", "hidden"] },
@@ -232,48 +234,84 @@ var schema_default = {
232
234
  type: "object",
233
235
  properties: {
234
236
  type: { enum: ["array"] },
235
- editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "select", "hidden"] }
237
+ editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "select", "hidden"] },
238
+ isSecret: { type: "boolean" }
236
239
  },
237
240
  additionalProperties: true,
238
241
  required: ["type", "title", "description", "editor"],
239
242
  if: {
240
243
  properties: {
241
- editor: { const: "select" }
244
+ isSecret: {
245
+ not: {
246
+ const: true
247
+ }
248
+ }
242
249
  }
243
250
  },
244
251
  then: {
245
- additionalProperties: false,
246
- required: ["items"],
247
- properties: {
248
- type: { enum: ["array"] },
249
- editor: { enum: ["select"] },
250
- title: { type: "string" },
251
- description: { type: "string" },
252
- default: { type: "array" },
253
- prefill: { type: "array" },
254
- example: { type: "array" },
255
- nullable: { type: "boolean" },
256
- minItems: { type: "integer" },
257
- maxItems: { type: "integer" },
258
- uniqueItems: { type: "boolean" },
259
- sectionCaption: { type: "string" },
260
- sectionDescription: { type: "string" },
261
- items: {
262
- type: "object",
263
- additionalProperties: false,
264
- properties: {
265
- type: { enum: ["string"] },
266
- enum: {
267
- type: "array",
268
- items: { type: "string" },
269
- uniqueItems: true
252
+ if: {
253
+ properties: {
254
+ editor: { const: "select" }
255
+ }
256
+ },
257
+ then: {
258
+ additionalProperties: false,
259
+ required: ["items"],
260
+ properties: {
261
+ type: { enum: ["array"] },
262
+ editor: { enum: ["select"] },
263
+ title: { type: "string" },
264
+ description: { type: "string" },
265
+ default: { type: "array" },
266
+ prefill: { type: "array" },
267
+ example: { type: "array" },
268
+ nullable: { type: "boolean" },
269
+ minItems: { type: "integer" },
270
+ maxItems: { type: "integer" },
271
+ uniqueItems: { type: "boolean" },
272
+ sectionCaption: { type: "string" },
273
+ sectionDescription: { type: "string" },
274
+ items: {
275
+ type: "object",
276
+ additionalProperties: false,
277
+ properties: {
278
+ type: { enum: ["string"] },
279
+ enum: {
280
+ type: "array",
281
+ items: { type: "string" },
282
+ uniqueItems: true
283
+ },
284
+ enumTitles: {
285
+ type: "array",
286
+ items: { type: "string" }
287
+ }
270
288
  },
271
- enumTitles: {
272
- type: "array",
273
- items: { type: "string" }
274
- }
289
+ required: ["type", "enum"]
275
290
  },
276
- required: ["type", "enum"]
291
+ isSecret: { enum: [false] }
292
+ }
293
+ },
294
+ else: {
295
+ additionalProperties: false,
296
+ properties: {
297
+ type: { enum: ["array"] },
298
+ editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "hidden"] },
299
+ title: { type: "string" },
300
+ description: { type: "string" },
301
+ default: { type: "array" },
302
+ prefill: { type: "array" },
303
+ example: { type: "array" },
304
+ nullable: { type: "boolean" },
305
+ minItems: { type: "integer" },
306
+ maxItems: { type: "integer" },
307
+ uniqueItems: { type: "boolean" },
308
+ sectionCaption: { type: "string" },
309
+ sectionDescription: { type: "string" },
310
+ placeholderKey: { type: "string" },
311
+ placeholderValue: { type: "string" },
312
+ patternKey: { type: "string" },
313
+ patternValue: { type: "string" },
314
+ isSecret: { enum: [false] }
277
315
  }
278
316
  }
279
317
  },
@@ -281,10 +319,9 @@ var schema_default = {
281
319
  additionalProperties: false,
282
320
  properties: {
283
321
  type: { enum: ["array"] },
284
- editor: { enum: ["json", "requestListSources", "pseudoUrls", "globs", "keyValue", "stringList", "hidden"] },
322
+ editor: { enum: ["json", "hidden"] },
285
323
  title: { type: "string" },
286
324
  description: { type: "string" },
287
- default: { type: "array" },
288
325
  prefill: { type: "array" },
289
326
  example: { type: "array" },
290
327
  nullable: { type: "boolean" },
@@ -293,34 +330,70 @@ var schema_default = {
293
330
  uniqueItems: { type: "boolean" },
294
331
  sectionCaption: { type: "string" },
295
332
  sectionDescription: { type: "string" },
296
- placeholderKey: { type: "string" },
297
- placeholderValue: { type: "string" },
298
- patternKey: { type: "string" },
299
- patternValue: { type: "string" }
333
+ isSecret: { enum: [true] }
300
334
  }
301
335
  }
302
336
  },
303
337
  objectProperty: {
304
338
  title: "Object property",
305
339
  type: "object",
306
- additionalProperties: false,
340
+ additionalProperties: true,
307
341
  properties: {
308
342
  type: { enum: ["object"] },
309
343
  title: { type: "string" },
310
344
  description: { type: "string" },
311
- default: { type: "object" },
312
- prefill: { type: "object" },
313
- example: { type: "object" },
314
- patternKey: { type: "string" },
315
- patternValue: { type: "string" },
316
- nullable: { type: "boolean" },
317
- minProperties: { type: "integer" },
318
- maxProperties: { type: "integer" },
319
345
  editor: { enum: ["json", "proxy", "hidden"] },
320
- sectionCaption: { type: "string" },
321
- sectionDescription: { type: "string" }
346
+ isSecret: { type: "boolean" }
322
347
  },
323
- required: ["type", "title", "description", "editor"]
348
+ required: ["type", "title", "description", "editor"],
349
+ if: {
350
+ properties: {
351
+ isSecret: {
352
+ not: {
353
+ const: true
354
+ }
355
+ }
356
+ }
357
+ },
358
+ then: {
359
+ additionalProperties: false,
360
+ properties: {
361
+ type: { enum: ["object"] },
362
+ title: { type: "string" },
363
+ description: { type: "string" },
364
+ default: { type: "object" },
365
+ prefill: { type: "object" },
366
+ example: { type: "object" },
367
+ patternKey: { type: "string" },
368
+ patternValue: { type: "string" },
369
+ nullable: { type: "boolean" },
370
+ minProperties: { type: "integer" },
371
+ maxProperties: { type: "integer" },
372
+ editor: { enum: ["json", "proxy", "hidden"] },
373
+ sectionCaption: { type: "string" },
374
+ sectionDescription: { type: "string" },
375
+ isSecret: { enum: [false] }
376
+ }
377
+ },
378
+ else: {
379
+ additionalProperties: false,
380
+ properties: {
381
+ type: { enum: ["object"] },
382
+ title: { type: "string" },
383
+ description: { type: "string" },
384
+ prefill: { type: "object" },
385
+ example: { type: "object" },
386
+ patternKey: { type: "string" },
387
+ patternValue: { type: "string" },
388
+ nullable: { type: "boolean" },
389
+ minProperties: { type: "integer" },
390
+ maxProperties: { type: "integer" },
391
+ editor: { enum: ["json", "hidden"] },
392
+ sectionCaption: { type: "string" },
393
+ sectionDescription: { type: "string" },
394
+ isSecret: { enum: [true] }
395
+ }
396
+ }
324
397
  },
325
398
  integerProperty: {
326
399
  title: "Integer property",
@@ -587,6 +660,7 @@ __name(validateInputSchema, "validateInputSchema");
587
660
  var import_acorn_loose = require("acorn-loose");
588
661
  var import_countries_list = require("countries-list");
589
662
  var import_consts = require("@apify/consts");
663
+ var import_input_secrets = require("@apify/input_secrets");
590
664
  function validateProxyField(fieldKey, value, isRequired = false, options = null) {
591
665
  const fieldErrors = [];
592
666
  if (isRequired) {
@@ -656,11 +730,21 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
656
730
  const required = inputSchema.required || [];
657
731
  let errors = [];
658
732
  if (!isValid) {
659
- errors = validator.errors.map((error) => parseAjvError(error, "input", properties, input)).filter((error) => !!error);
733
+ errors = validator.errors.filter((error) => {
734
+ if (error.keyword === "type" && error.instancePath) {
735
+ const path = error.instancePath.replace(/^\//, "").split("/")[0];
736
+ const propSchema = inputSchema.properties?.[path];
737
+ const value = input[path];
738
+ if (propSchema?.isSecret && typeof value === "string" && (propSchema.type === "object" || propSchema.type === "array") && (0, import_input_secrets.isEncryptedValueForFieldType)(value, propSchema.type)) {
739
+ return false;
740
+ }
741
+ }
742
+ return true;
743
+ }).map((error) => parseAjvError(error, "input", properties, input)).filter((error) => !!error);
660
744
  }
661
745
  Object.keys(properties).forEach((property) => {
662
746
  const value = input[property];
663
- const { type, editor, patternKey, patternValue } = properties[property];
747
+ const { type, editor, patternKey, patternValue, isSecret } = properties[property];
664
748
  const fieldErrors = [];
665
749
  if (type === "object" && editor === "proxy") {
666
750
  const proxyValidationErrors = validateProxyField(property, value, required.includes(property), options.proxy);
@@ -730,7 +814,7 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
730
814
  }
731
815
  }
732
816
  }
733
- if (type === "object" && value) {
817
+ if (type === "object" && value && typeof value === "object") {
734
818
  if (patternKey) {
735
819
  const check = new RegExp(patternKey);
736
820
  const invalidKeys = [];
@@ -763,6 +847,11 @@ function validateInputUsingValidator(validator, inputSchema, input, options = {}
763
847
  }
764
848
  }
765
849
  }
850
+ if (isSecret && value && typeof value === "string") {
851
+ if ((0, import_input_secrets.isEncryptedValueForFieldType)(value, type) && !(0, import_input_secrets.isEncryptedValueForFieldSchema)(value, properties[property])) {
852
+ fieldErrors.push(m("inputSchema.validation.secretFieldSchemaChanged", { fieldKey: property }));
853
+ }
854
+ }
766
855
  if (fieldErrors.length > 0) {
767
856
  const message = fieldErrors.join(", ");
768
857
  errors.push({ fieldKey: property, message });