@apify/input_schema 3.1.5 → 3.2.1
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/index.js +45 -10
- package/index.js.map +1 -1
- package/index.mjs +45 -10
- package/index.mjs.map +1 -1
- package/package.json +3 -3
- package/schema.json +45 -10
package/index.js
CHANGED
|
@@ -142,23 +142,58 @@ var schema_default = {
|
|
|
142
142
|
stringProperty: {
|
|
143
143
|
title: "String property",
|
|
144
144
|
type: "object",
|
|
145
|
-
additionalProperties:
|
|
145
|
+
additionalProperties: true,
|
|
146
146
|
properties: {
|
|
147
147
|
type: { enum: ["string"] },
|
|
148
148
|
title: { type: "string" },
|
|
149
149
|
description: { type: "string" },
|
|
150
|
-
default: { type: "string" },
|
|
151
|
-
prefill: { type: "string" },
|
|
152
|
-
example: { type: "string" },
|
|
153
|
-
pattern: { type: "string" },
|
|
154
150
|
nullable: { type: "boolean" },
|
|
155
|
-
minLength: { type: "integer" },
|
|
156
|
-
maxLength: { type: "integer" },
|
|
157
151
|
editor: { enum: ["javascript", "python", "textfield", "textarea", "hidden"] },
|
|
158
|
-
|
|
159
|
-
sectionDescription: { type: "string" }
|
|
152
|
+
isSecret: { type: "boolean" }
|
|
160
153
|
},
|
|
161
|
-
required: ["type", "title", "description", "editor"]
|
|
154
|
+
required: ["type", "title", "description", "editor"],
|
|
155
|
+
if: {
|
|
156
|
+
properties: {
|
|
157
|
+
isSecret: {
|
|
158
|
+
not: {
|
|
159
|
+
const: true
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
then: {
|
|
165
|
+
additionalProperties: false,
|
|
166
|
+
properties: {
|
|
167
|
+
type: { enum: ["string"] },
|
|
168
|
+
title: { type: "string" },
|
|
169
|
+
description: { type: "string" },
|
|
170
|
+
default: { type: "string" },
|
|
171
|
+
prefill: { type: "string" },
|
|
172
|
+
example: { type: "string" },
|
|
173
|
+
pattern: { type: "string" },
|
|
174
|
+
nullable: { type: "boolean" },
|
|
175
|
+
minLength: { type: "integer" },
|
|
176
|
+
maxLength: { type: "integer" },
|
|
177
|
+
editor: { enum: ["javascript", "python", "textfield", "textarea", "hidden"] },
|
|
178
|
+
isSecret: { type: "boolean" },
|
|
179
|
+
sectionCaption: { type: "string" },
|
|
180
|
+
sectionDescription: { type: "string" }
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
else: {
|
|
184
|
+
additionalProperties: false,
|
|
185
|
+
properties: {
|
|
186
|
+
type: { enum: ["string"] },
|
|
187
|
+
title: { type: "string" },
|
|
188
|
+
description: { type: "string" },
|
|
189
|
+
example: { type: "string" },
|
|
190
|
+
nullable: { type: "boolean" },
|
|
191
|
+
editor: { enum: ["textfield", "textarea", "hidden"] },
|
|
192
|
+
isSecret: { type: "boolean" },
|
|
193
|
+
sectionCaption: { type: "string" },
|
|
194
|
+
sectionDescription: { type: "string" }
|
|
195
|
+
}
|
|
196
|
+
}
|
|
162
197
|
},
|
|
163
198
|
arrayProperty: {
|
|
164
199
|
title: "Array property",
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/intl.ts","../src/input_schema.ts","../src/utilities.ts"],"sourcesContent":["export * from './intl';\nexport * from './input_schema';\nexport * from './utilities';\n","/* eslint-disable max-len,quotes,quote-props */\nconst intlStrings = {\n 'inputSchema.validation.generic':\n 'Field {rootName}.{fieldKey} {message}',\n 'inputSchema.validation.required':\n 'Field {rootName}.{fieldKey} is required',\n 'inputSchema.validation.proxyRequired':\n 'Field {rootName}.{fieldKey} is required. Please provide custom proxy URLs or use Apify Proxy.',\n 'inputSchema.validation.requestListSourcesInvalid':\n 'Items in {rootName}.{fieldKey} at positions [{invalidIndexes}] do not contain valid URLs',\n 'inputSchema.validation.arrayKeysInvalid':\n 'Keys in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.arrayValuesInvalid':\n 'Values in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.objectKeysInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must match regular expression \"{pattern}',\n 'inputSchema.validation.objectValuesInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must have string value which matches regular expression \"{pattern}\"',\n 'inputSchema.validation.additionalProperty':\n 'Property {rootName}.{fieldKey} is not allowed.',\n 'inputSchema.validation.proxyGroupsNotAvailable':\n 'You currently do not have access to proxy groups: {groups}',\n 'inputSchema.validation.customProxyInvalid':\n 'Proxy URL \"{invalidUrl}\" has invalid format, it must be http://[username[:password]]@hostname:port.',\n 'inputSchema.validation.apifyProxyCountryInvalid':\n 'Country code \"{invalidCountry}\" is invalid. Only ISO 3166-1 alpha-2 country codes are supported.',\n 'inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden':\n 'The country for Apify Proxy can be specified only when using Apify Proxy.',\n 'inputSchema.validation.noAvailableAutoProxy':\n 'Currently you do not have access to any proxy group usable in automatic mode.',\n 'inputSchema.validation.noMatchingDefinition':\n 'Field schema.properties.{fieldKey} is not matching any input schema type definition. Please make sure that it\\'s type is valid.',\n};\n/* eslint-enable max-len,quotes,quote-props */\n\n/**\n * Helper function to simulate intl formatMessage function\n */\nexport function m(stringId: string, variables?: Record<string, any>) {\n let text = intlStrings[stringId];\n if (!text) return stringId;\n\n if (variables) {\n Object.keys(variables).forEach((variableName) => {\n text = text.split(`{${variableName}}`).join(variables[variableName]);\n });\n }\n\n return text;\n}\n","import Ajv, { ErrorObject } from 'ajv';\nimport schema from './schema.json';\nimport { m } from './intl';\n\nexport { schema as inputSchema };\nconst { definitions } = schema;\n\n/**\n * This function parses AJV error and transforms it into a readable string.\n *\n * @param error An error as returned from AJV.\n * @param rootName Usually 'input' or 'schema' based on if we are passing the input or schema.\n * @param properties (Used only when parsing input errors) List of input schema properties.\n * @param input (Used only when parsing input errors) Actual input that is being parsed.\n * @returns {null|{fieldKey: *, message: *}}\n */\nexport function parseAjvError(\n error: ErrorObject,\n rootName: string,\n properties: Record<string, { nullable?: boolean }> = {},\n input: Record<string, unknown> = {},\n): { fieldKey: string; message: string } | null {\n // There are 3 possible errors comming from validation:\n // - either { keword: 'anything', instancePath: '/someField', message: 'error message that we can use' }\n // - or { keyword: 'additionalProperties', params: { additionalProperty: 'field' }, message: 'must NOT have additional properties' }\n // - or { keyword: 'required', instancePath: '', params.missingProperty: 'someField' }\n\n let fieldKey: string;\n let message: string;\n\n // If error is with keyword type, it means that type of input is incorrect\n // this can mean that provided value is null\n if (error.keyword === 'type') {\n fieldKey = error.instancePath.split('/').pop()!;\n // Check if value is null and field is nullable, if yes, then skip this error\n if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {\n return null;\n }\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n } else if (error.keyword === 'required') {\n fieldKey = error.params.missingProperty;\n message = m('inputSchema.validation.required', { rootName, fieldKey });\n } else if (error.keyword === 'additionalProperties') {\n fieldKey = error.params.additionalProperty;\n message = m('inputSchema.validation.additionalProperty', { rootName, fieldKey });\n } else if (error.keyword === 'enum') {\n fieldKey = error.instancePath.split('/').pop()!;\n const errorMessage = `${error.message}: \"${error.params.allowedValues.join('\", \"')}\"`;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: errorMessage });\n } else {\n fieldKey = error.instancePath.split('/').pop()!;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n }\n\n return { fieldKey, message };\n}\n\n/**\n * Validates given object against schema and throws a human readable error.\n */\nconst validateAgainstSchemaOrThrow = <T> (validator: Ajv, obj: T, inputSchema: any, rootName: string) => {\n if (validator.validate(inputSchema, obj)) return;\n\n const errorMessage = parseAjvError(validator.errors![0], rootName)?.message;\n throw new Error(`Input schema is not valid (${errorMessage})`);\n};\n\n/**\n * This validates given object only against the basic input schema without checking the particular fields.\n * We override schema.properties.properties not to validate field defitions.\n */\nconst validateBasicStructure = <T> (validator: Ajv, obj: T) => {\n const schemaWithoutProperties = { ...schema };\n schemaWithoutProperties.properties = { ...schema.properties, properties: { type: 'object' } as any };\n validateAgainstSchemaOrThrow(validator, obj, schemaWithoutProperties, 'schema');\n};\n\n/**\n * Validates particular field against it's schema.\n */\nconst validateField = <T extends Record<string, any>> (validator: Ajv, fieldSchema: T, fieldKey: string) => {\n const matchingDefinitions = Object\n .values<any>(definitions) // cast as any, as the code in first branch seems to be invalid\n .filter((definition) => {\n return definition.properties.type.enum\n // This is a normal case where fieldSchema.type can be only one possible value matching definition.properties.type.enum.0\n ? definition.properties.type.enum[0] === fieldSchema.type\n // This is a type \"Any\" where fieldSchema.type is an array of possible values\n : Array.isArray(fieldSchema.type);\n });\n\n // There is not matching definition.\n if (matchingDefinitions.length === 0) {\n const errorMessage = m('inputSchema.validation.noMatchingDefinition', { fieldKey });\n throw new Error(`Input schema is not valid (${errorMessage})`);\n }\n\n // If there is only one matching then we are done and simply compare it.\n if (matchingDefinitions.length === 1) {\n validateAgainstSchemaOrThrow(validator, fieldSchema, matchingDefinitions[0], `schema.properties.${fieldKey}`);\n return;\n }\n\n // If there are more matching definitions then the type is string and we need to get the right one.\n // If the definition contains \"enum\" property then it's enum type.\n if (fieldSchema.enum) {\n const definition = matchingDefinitions.filter((item) => !!item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find \"enum property\" definition');\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}.enum`);\n return;\n }\n // Otherwise we use the other definition.\n const definition = matchingDefinitions.filter((item) => !item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find other than \"enum property\" definition');\n\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}`);\n};\n\n/**\n * This function validates given input schema first just for basic structure then each field one by one and\n * finally fully against the whole schema.\n *\n * This way we get the most accurate error message for user.\n */\nexport function validateInputSchema<T extends Record<string, any>>(validator: Ajv, inputSchema: T) {\n // First validate just basic structure without fields.\n validateBasicStructure(validator, inputSchema);\n\n // Then validate each field separately.\n Object.entries<any>(inputSchema.properties).forEach(([fieldKey, fieldSchema]) => validateField(validator, fieldSchema, fieldKey));\n\n // Finally just to be sure run validation against the whole shema.\n validateAgainstSchemaOrThrow(validator, inputSchema, schema, 'schema');\n}\n","import { PROXY_URL_REGEX, URL_REGEX } from '@apify/consts';\nimport { countries } from 'countries-list';\nimport { ValidateFunction } from 'ajv';\nimport { parseScript } from 'escaya';\nimport { m } from './intl';\nimport { parseAjvError } from './input_schema';\n\n/**\n * Validates input field configured with proxy editor\n * @param fieldKey Proxy field value\n * @param value Proxy field value\n * @param [isRequired] Whether the field is required or not\n * @param [options] Information about proxy groups availability\n * @param [options.hasAutoProxyGroups] Informs validation whether user has atleast one proxy group available in auto mode\n * @param [options.availableProxyGroups] List of available proxy groups\n * @param [options.disabledProxyGroups] Object with groupId as key and error message as value (mostly for residential/SERP)\n */\nfunction validateProxyField(\n fieldKey: Record<string, unknown>,\n value: Record<string, any>,\n isRequired = false,\n options: { hasAutoProxyGroups?: boolean; availableProxyGroups?: string[]; disabledProxyGroups?: Record<string, unknown> } | null = null,\n) {\n const fieldErrors: any[] = [];\n if (isRequired) {\n // Nullable error is already handled by AJV\n if (value === null) return fieldErrors;\n if (!value) {\n const message = m('inputSchema.validation.required', { rootName: 'input', fieldKey });\n fieldErrors.push(message);\n return fieldErrors;\n }\n\n const { useApifyProxy, proxyUrls } = value;\n if (!useApifyProxy && (!Array.isArray(proxyUrls) || proxyUrls.length === 0)) {\n fieldErrors.push(m('inputSchema.validation.proxyRequired', { rootName: 'input', fieldKey }));\n return fieldErrors;\n }\n }\n\n // Input is not required, so missing value is valid\n if (!value) return fieldErrors;\n\n const { useApifyProxy, proxyUrls, apifyProxyGroups, apifyProxyCountry } = value;\n\n if (!useApifyProxy && Array.isArray(proxyUrls)) {\n let invalidUrl = false;\n proxyUrls.forEach((url) => {\n if (!PROXY_URL_REGEX.test(url.trim())) invalidUrl = url.trim();\n });\n if (invalidUrl) {\n fieldErrors.push(m('inputSchema.validation.customProxyInvalid', { invalidUrl }));\n }\n }\n\n // Apify proxy country can be set only when using Apify proxy\n if (!useApifyProxy && apifyProxyCountry) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden'));\n }\n\n // If Apify proxy is not used skip additional checks\n if (!useApifyProxy) return fieldErrors;\n\n // If Apify proxy is used, check if there is a selected country and if so, check that it's valid (empty or a valid country code)\n if (apifyProxyCountry && !countries[apifyProxyCountry]) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryInvalid', { invalidCountry: apifyProxyCountry }));\n }\n\n // If options are not provided skip additional checks\n if (!options) return fieldErrors;\n\n const selectedProxyGroups = (apifyProxyGroups || []);\n\n // Auto mode, check that user has access to alteast one proxy group usable in this mode\n if (!selectedProxyGroups.length && !options.hasAutoProxyGroups) {\n fieldErrors.push(m('inputSchema.validation.noAvailableAutoProxy'));\n return fieldErrors;\n }\n\n // Check if proxy groups selected by user are available to him\n const availableProxyGroupsById = {};\n (options.availableProxyGroups || []).forEach((group) => { availableProxyGroupsById[group] = true; });\n const unavailableProxyGroups = selectedProxyGroups.filter((group: string) => !availableProxyGroupsById[group]);\n\n if (unavailableProxyGroups.length) {\n fieldErrors.push(m('inputSchema.validation.proxyGroupsNotAvailable', {\n rootName: 'input',\n fieldKey,\n groups: unavailableProxyGroups.join(', '),\n }));\n }\n\n // Check if any of the proxy groups are blocked and if yes then output the associated message\n const blockedProxyGroupsById = options.disabledProxyGroups || {};\n selectedProxyGroups\n .filter((group: string) => blockedProxyGroupsById[group])\n .forEach((blockedGroup: string) => {\n fieldErrors.push(blockedProxyGroupsById[blockedGroup]);\n });\n\n return fieldErrors;\n}\n\n/**\n * Uses AJV validator to validate input with input schema and then\n * does custom validation for our own properties (nullable, patternKey, patternValue)\n * @param validator Initialized AJV validator\n * @param inputSchema Valid input schema in object\n * @param input Input object to be validated\n * @param options (Optional) Additional validation configuration for certain fields\n */\nexport function validateInputUsingValidator(\n validator: ValidateFunction,\n inputSchema: Record<string, any>,\n input: Record<string, unknown>,\n options: Record<string, any> = {},\n) {\n const isValid = validator(input); // Check if input is valid based on schema values\n\n const { properties } = inputSchema;\n const required = inputSchema.required || [];\n\n let errors: { fieldKey: string, message: string }[] = [];\n // Process AJV validation errors\n if (!isValid) {\n errors = validator.errors!\n .map((error) => parseAjvError(error, 'input', properties, input))\n .filter((error) => !!error) as any[];\n }\n\n Object.keys(properties).forEach((property) => {\n const value = input[property] as Record<string, any>;\n const { type, editor, patternKey, patternValue } = properties[property];\n const fieldErrors = [];\n // Check that proxy is required, if yes, valides that it's correctly setup\n if (type === 'object' && editor === 'proxy') {\n const proxyValidationErrors = validateProxyField(property as any, value, required.includes(property), options.proxy);\n proxyValidationErrors.forEach((error) => {\n fieldErrors.push(error);\n });\n }\n // Check that array items fit patternKey and patternValue\n if (type === 'array' && value && Array.isArray(value)) {\n if (editor === 'requestListSources') {\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!item) invalidIndexes.push(index);\n else if (!item.url && !item.requestsFromUrl) invalidIndexes.push(index);\n else if (item.url && !URL_REGEX.test(item.url)) invalidIndexes.push(index);\n else if (item.requestsFromUrl && !URL_REGEX.test(item.requestsFromUrl)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.requestListSourcesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n }));\n }\n }\n // If patternKey is provided, then validate keys of objects in array\n if (patternKey && editor === 'keyValue') {\n const check = new RegExp(patternKey);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.key)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternKey,\n }));\n }\n }\n // If patternValue is provided and editor is keyValue, then validate values of objecs in array\n if (patternValue && editor === 'keyValue') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.value)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n // If patternValue is provided and editor is stringList, then validate each item in array\n } else if (patternValue && editor === 'stringList') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n // Check that object items fit patternKey and patternValue\n if (type === 'object' && value) {\n if (patternKey) {\n const check = new RegExp(patternKey);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n if (!check.test(key)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternKey,\n }));\n }\n }\n if (patternValue) {\n const check = new RegExp(patternValue);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n const propertyValue = value[key];\n if (typeof propertyValue !== 'string' || !check.test(propertyValue)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n if (fieldErrors.length > 0) {\n const message = fieldErrors.join(', ');\n errors.push({ fieldKey: property, message });\n }\n });\n\n return errors;\n}\n\n/**\n * This functions parses all given JSON and then takes each of the jsFields.\n * Then if the field:\n * - is valid JS single function it replaces its single line string with a function delacation.\n * - is valid multiline JS code then replaces its single line string with `multiline` string\n * Then stringifies the code with given number of jsonSpacing spaces and finally prefixes whole\n * stringified JSON except the first line with globalSpacing spaces.\n */\nexport function makeInputJsFieldsReadable(json: string, jsFields: string[], jsonSpacing = 4, globalSpacing = 0): string {\n const parsedJson = JSON.parse(json);\n const replacements: Record<string, any> = {};\n\n jsFields.forEach((field) => {\n let maybeFunction = parsedJson[field];\n if (!maybeFunction || typeof maybeFunction !== 'string') return;\n\n let ast;\n try {\n ast = parseScript(maybeFunction, { cst: true });\n } catch (err) {\n // Don't do anything in a case of invalid JS code.\n return;\n }\n\n const isMultiline = maybeFunction.includes('\\n');\n const isSingleFunction = ast\n && ast.leafs\n && ast.leafs.length === 1 // Must have only one expression inside!\n && ast.leafs[0]\n && (\n // Normal function ...\n ast.leafs[0].type === 'FunctionDeclaration'\n // or arrow function\n || (\n ast.leafs[0].type === 'ExpressionStatement'\n && (ast.leafs[0] as { expression: { type: string } }).expression.type === 'ArrowFunction'\n )\n );\n\n // If it's not a function declaration or multiline JS code then we do nothing.\n if (!isSingleFunction && !isMultiline) return;\n\n const spaces = (new Array(isSingleFunction ? jsonSpacing : jsonSpacing * 2)).fill(' ').join('');\n maybeFunction = maybeFunction\n .split('\\n').join(`\\n${spaces}`) // This prefixes each line with spaces.\n .trim(); // Trim whitespace on both sides\n\n const replacementValue = isSingleFunction\n ? maybeFunction.replace(/[;]+$/g, '') // Remove trailing semicolons\n : `\\`${maybeFunction}\\``;\n const replacementToken = `<<<REPLACEMENT_TOKEN:${Math.random()}>>>`;\n replacements[replacementToken] = replacementValue;\n parsedJson[field] = replacementToken;\n });\n\n let niceJson = JSON.stringify(parsedJson, null, jsonSpacing);\n\n Object.entries(replacements).forEach(([replacementToken, replacementValue]) => {\n niceJson = niceJson.replace(`\"${replacementToken}\"`, replacementValue);\n });\n\n const globalSpaces = (new Array(globalSpacing)).fill(' ').join('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,mBAAmB,mBACnB,cAAc,QAAQ,UAAU,EAAE,IAClC,KAAK;AACX,UAAM,mBAAmB,wBAAwB,KAAK,OAAO;AAC7D,iBAAa,oBAAoB;AACjC,eAAW,SAAS;AAAA,EACxB,CAAC;AAED,MAAI,WAAW,KAAK,UAAU,YAAY,MAAM,WAAW;AAE3D,SAAO,QAAQ,YAAY,EAAE,QAAQ,CAAC,CAAC,kBAAkB,gBAAgB,MAAM;AAC3E,eAAW,SAAS,QAAQ,IAAI,qBAAqB,gBAAgB;AAAA,EACzE,CAAC;AAED,QAAM,eAAgB,IAAI,MAAM,aAAa,EAAG,KAAK,GAAG,EAAE,KAAK,EAAE;AACjE,aAAW,SAAS,MAAM,IAAI,EAAE,KAAK;AAAA,EAAK,cAAc;AAExD,SAAO;AACX;AAzDgB;","names":["definition","useApifyProxy","proxyUrls"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/intl.ts","../src/input_schema.ts","../src/utilities.ts"],"sourcesContent":["export * from './intl';\nexport * from './input_schema';\nexport * from './utilities';\n","/* eslint-disable max-len,quotes,quote-props */\nconst intlStrings = {\n 'inputSchema.validation.generic':\n 'Field {rootName}.{fieldKey} {message}',\n 'inputSchema.validation.required':\n 'Field {rootName}.{fieldKey} is required',\n 'inputSchema.validation.proxyRequired':\n 'Field {rootName}.{fieldKey} is required. Please provide custom proxy URLs or use Apify Proxy.',\n 'inputSchema.validation.requestListSourcesInvalid':\n 'Items in {rootName}.{fieldKey} at positions [{invalidIndexes}] do not contain valid URLs',\n 'inputSchema.validation.arrayKeysInvalid':\n 'Keys in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.arrayValuesInvalid':\n 'Values in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.objectKeysInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must match regular expression \"{pattern}',\n 'inputSchema.validation.objectValuesInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must have string value which matches regular expression \"{pattern}\"',\n 'inputSchema.validation.additionalProperty':\n 'Property {rootName}.{fieldKey} is not allowed.',\n 'inputSchema.validation.proxyGroupsNotAvailable':\n 'You currently do not have access to proxy groups: {groups}',\n 'inputSchema.validation.customProxyInvalid':\n 'Proxy URL \"{invalidUrl}\" has invalid format, it must be http://[username[:password]]@hostname:port.',\n 'inputSchema.validation.apifyProxyCountryInvalid':\n 'Country code \"{invalidCountry}\" is invalid. Only ISO 3166-1 alpha-2 country codes are supported.',\n 'inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden':\n 'The country for Apify Proxy can be specified only when using Apify Proxy.',\n 'inputSchema.validation.noAvailableAutoProxy':\n 'Currently you do not have access to any proxy group usable in automatic mode.',\n 'inputSchema.validation.noMatchingDefinition':\n 'Field schema.properties.{fieldKey} is not matching any input schema type definition. Please make sure that it\\'s type is valid.',\n};\n/* eslint-enable max-len,quotes,quote-props */\n\n/**\n * Helper function to simulate intl formatMessage function\n */\nexport function m(stringId: string, variables?: Record<string, any>) {\n let text = intlStrings[stringId];\n if (!text) return stringId;\n\n if (variables) {\n Object.keys(variables).forEach((variableName) => {\n text = text.split(`{${variableName}}`).join(variables[variableName]);\n });\n }\n\n return text;\n}\n","import Ajv, { ErrorObject } from 'ajv';\nimport schema from './schema.json';\nimport { m } from './intl';\n\nexport { schema as inputSchema };\nconst { definitions } = schema;\n\n/**\n * This function parses AJV error and transforms it into a readable string.\n *\n * @param error An error as returned from AJV.\n * @param rootName Usually 'input' or 'schema' based on if we are passing the input or schema.\n * @param properties (Used only when parsing input errors) List of input schema properties.\n * @param input (Used only when parsing input errors) Actual input that is being parsed.\n * @returns {null|{fieldKey: *, message: *}}\n */\nexport function parseAjvError(\n error: ErrorObject,\n rootName: string,\n properties: Record<string, { nullable?: boolean }> = {},\n input: Record<string, unknown> = {},\n): { fieldKey: string; message: string } | null {\n // There are 3 possible errors comming from validation:\n // - either { keword: 'anything', instancePath: '/someField', message: 'error message that we can use' }\n // - or { keyword: 'additionalProperties', params: { additionalProperty: 'field' }, message: 'must NOT have additional properties' }\n // - or { keyword: 'required', instancePath: '', params.missingProperty: 'someField' }\n\n let fieldKey: string;\n let message: string;\n\n // If error is with keyword type, it means that type of input is incorrect\n // this can mean that provided value is null\n if (error.keyword === 'type') {\n fieldKey = error.instancePath.split('/').pop()!;\n // Check if value is null and field is nullable, if yes, then skip this error\n if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {\n return null;\n }\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n } else if (error.keyword === 'required') {\n fieldKey = error.params.missingProperty;\n message = m('inputSchema.validation.required', { rootName, fieldKey });\n } else if (error.keyword === 'additionalProperties') {\n fieldKey = error.params.additionalProperty;\n message = m('inputSchema.validation.additionalProperty', { rootName, fieldKey });\n } else if (error.keyword === 'enum') {\n fieldKey = error.instancePath.split('/').pop()!;\n const errorMessage = `${error.message}: \"${error.params.allowedValues.join('\", \"')}\"`;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: errorMessage });\n } else {\n fieldKey = error.instancePath.split('/').pop()!;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n }\n\n return { fieldKey, message };\n}\n\n/**\n * Validates given object against schema and throws a human readable error.\n */\nconst validateAgainstSchemaOrThrow = <T> (validator: Ajv, obj: T, inputSchema: any, rootName: string) => {\n if (validator.validate(inputSchema, obj)) return;\n\n const errorMessage = parseAjvError(validator.errors![0], rootName)?.message;\n throw new Error(`Input schema is not valid (${errorMessage})`);\n};\n\n/**\n * This validates given object only against the basic input schema without checking the particular fields.\n * We override schema.properties.properties not to validate field defitions.\n */\nconst validateBasicStructure = <T> (validator: Ajv, obj: T) => {\n const schemaWithoutProperties = { ...schema };\n schemaWithoutProperties.properties = { ...schema.properties, properties: { type: 'object' } as any };\n validateAgainstSchemaOrThrow(validator, obj, schemaWithoutProperties, 'schema');\n};\n\n/**\n * Validates particular field against it's schema.\n */\nconst validateField = <T extends Record<string, any>> (validator: Ajv, fieldSchema: T, fieldKey: string) => {\n const matchingDefinitions = Object\n .values<any>(definitions) // cast as any, as the code in first branch seems to be invalid\n .filter((definition) => {\n return definition.properties.type.enum\n // This is a normal case where fieldSchema.type can be only one possible value matching definition.properties.type.enum.0\n ? definition.properties.type.enum[0] === fieldSchema.type\n // This is a type \"Any\" where fieldSchema.type is an array of possible values\n : Array.isArray(fieldSchema.type);\n });\n\n // There is not matching definition.\n if (matchingDefinitions.length === 0) {\n const errorMessage = m('inputSchema.validation.noMatchingDefinition', { fieldKey });\n throw new Error(`Input schema is not valid (${errorMessage})`);\n }\n\n // If there is only one matching then we are done and simply compare it.\n if (matchingDefinitions.length === 1) {\n validateAgainstSchemaOrThrow(validator, fieldSchema, matchingDefinitions[0], `schema.properties.${fieldKey}`);\n return;\n }\n\n // If there are more matching definitions then the type is string and we need to get the right one.\n // If the definition contains \"enum\" property then it's enum type.\n if (fieldSchema.enum) {\n const definition = matchingDefinitions.filter((item) => !!item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find \"enum property\" definition');\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}.enum`);\n return;\n }\n // Otherwise we use the other definition.\n const definition = matchingDefinitions.filter((item) => !item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find other than \"enum property\" definition');\n\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}`);\n};\n\n/**\n * This function validates given input schema first just for basic structure then each field one by one and\n * finally fully against the whole schema.\n *\n * This way we get the most accurate error message for user.\n */\nexport function validateInputSchema<T extends Record<string, any>>(validator: Ajv, inputSchema: T) {\n // First validate just basic structure without fields.\n validateBasicStructure(validator, inputSchema);\n\n // Then validate each field separately.\n Object.entries<any>(inputSchema.properties).forEach(([fieldKey, fieldSchema]) => validateField(validator, fieldSchema, fieldKey));\n\n // Finally just to be sure run validation against the whole shema.\n validateAgainstSchemaOrThrow(validator, inputSchema, schema, 'schema');\n}\n","import { PROXY_URL_REGEX, URL_REGEX } from '@apify/consts';\nimport { countries } from 'countries-list';\nimport { ValidateFunction } from 'ajv';\nimport { parseScript } from 'escaya';\nimport { m } from './intl';\nimport { parseAjvError } from './input_schema';\n\n/**\n * Validates input field configured with proxy editor\n * @param fieldKey Proxy field value\n * @param value Proxy field value\n * @param [isRequired] Whether the field is required or not\n * @param [options] Information about proxy groups availability\n * @param [options.hasAutoProxyGroups] Informs validation whether user has atleast one proxy group available in auto mode\n * @param [options.availableProxyGroups] List of available proxy groups\n * @param [options.disabledProxyGroups] Object with groupId as key and error message as value (mostly for residential/SERP)\n */\nfunction validateProxyField(\n fieldKey: Record<string, unknown>,\n value: Record<string, any>,\n isRequired = false,\n options: { hasAutoProxyGroups?: boolean; availableProxyGroups?: string[]; disabledProxyGroups?: Record<string, unknown> } | null = null,\n) {\n const fieldErrors: any[] = [];\n if (isRequired) {\n // Nullable error is already handled by AJV\n if (value === null) return fieldErrors;\n if (!value) {\n const message = m('inputSchema.validation.required', { rootName: 'input', fieldKey });\n fieldErrors.push(message);\n return fieldErrors;\n }\n\n const { useApifyProxy, proxyUrls } = value;\n if (!useApifyProxy && (!Array.isArray(proxyUrls) || proxyUrls.length === 0)) {\n fieldErrors.push(m('inputSchema.validation.proxyRequired', { rootName: 'input', fieldKey }));\n return fieldErrors;\n }\n }\n\n // Input is not required, so missing value is valid\n if (!value) return fieldErrors;\n\n const { useApifyProxy, proxyUrls, apifyProxyGroups, apifyProxyCountry } = value;\n\n if (!useApifyProxy && Array.isArray(proxyUrls)) {\n let invalidUrl = false;\n proxyUrls.forEach((url) => {\n if (!PROXY_URL_REGEX.test(url.trim())) invalidUrl = url.trim();\n });\n if (invalidUrl) {\n fieldErrors.push(m('inputSchema.validation.customProxyInvalid', { invalidUrl }));\n }\n }\n\n // Apify proxy country can be set only when using Apify proxy\n if (!useApifyProxy && apifyProxyCountry) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden'));\n }\n\n // If Apify proxy is not used skip additional checks\n if (!useApifyProxy) return fieldErrors;\n\n // If Apify proxy is used, check if there is a selected country and if so, check that it's valid (empty or a valid country code)\n if (apifyProxyCountry && !countries[apifyProxyCountry]) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryInvalid', { invalidCountry: apifyProxyCountry }));\n }\n\n // If options are not provided skip additional checks\n if (!options) return fieldErrors;\n\n const selectedProxyGroups = (apifyProxyGroups || []);\n\n // Auto mode, check that user has access to alteast one proxy group usable in this mode\n if (!selectedProxyGroups.length && !options.hasAutoProxyGroups) {\n fieldErrors.push(m('inputSchema.validation.noAvailableAutoProxy'));\n return fieldErrors;\n }\n\n // Check if proxy groups selected by user are available to him\n const availableProxyGroupsById = {};\n (options.availableProxyGroups || []).forEach((group) => { availableProxyGroupsById[group] = true; });\n const unavailableProxyGroups = selectedProxyGroups.filter((group: string) => !availableProxyGroupsById[group]);\n\n if (unavailableProxyGroups.length) {\n fieldErrors.push(m('inputSchema.validation.proxyGroupsNotAvailable', {\n rootName: 'input',\n fieldKey,\n groups: unavailableProxyGroups.join(', '),\n }));\n }\n\n // Check if any of the proxy groups are blocked and if yes then output the associated message\n const blockedProxyGroupsById = options.disabledProxyGroups || {};\n selectedProxyGroups\n .filter((group: string) => blockedProxyGroupsById[group])\n .forEach((blockedGroup: string) => {\n fieldErrors.push(blockedProxyGroupsById[blockedGroup]);\n });\n\n return fieldErrors;\n}\n\n/**\n * Uses AJV validator to validate input with input schema and then\n * does custom validation for our own properties (nullable, patternKey, patternValue)\n * @param validator Initialized AJV validator\n * @param inputSchema Valid input schema in object\n * @param input Input object to be validated\n * @param options (Optional) Additional validation configuration for certain fields\n */\nexport function validateInputUsingValidator(\n validator: ValidateFunction,\n inputSchema: Record<string, any>,\n input: Record<string, unknown>,\n options: Record<string, any> = {},\n) {\n const isValid = validator(input); // Check if input is valid based on schema values\n\n const { properties } = inputSchema;\n const required = inputSchema.required || [];\n\n let errors: { fieldKey: string, message: string }[] = [];\n // Process AJV validation errors\n if (!isValid) {\n errors = validator.errors!\n .map((error) => parseAjvError(error, 'input', properties, input))\n .filter((error) => !!error) as any[];\n }\n\n Object.keys(properties).forEach((property) => {\n const value = input[property] as Record<string, any>;\n const { type, editor, patternKey, patternValue } = properties[property];\n const fieldErrors = [];\n // Check that proxy is required, if yes, valides that it's correctly setup\n if (type === 'object' && editor === 'proxy') {\n const proxyValidationErrors = validateProxyField(property as any, value, required.includes(property), options.proxy);\n proxyValidationErrors.forEach((error) => {\n fieldErrors.push(error);\n });\n }\n // Check that array items fit patternKey and patternValue\n if (type === 'array' && value && Array.isArray(value)) {\n if (editor === 'requestListSources') {\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!item) invalidIndexes.push(index);\n else if (!item.url && !item.requestsFromUrl) invalidIndexes.push(index);\n else if (item.url && !URL_REGEX.test(item.url)) invalidIndexes.push(index);\n else if (item.requestsFromUrl && !URL_REGEX.test(item.requestsFromUrl)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.requestListSourcesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n }));\n }\n }\n // If patternKey is provided, then validate keys of objects in array\n if (patternKey && editor === 'keyValue') {\n const check = new RegExp(patternKey);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.key)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternKey,\n }));\n }\n }\n // If patternValue is provided and editor is keyValue, then validate values of objecs in array\n if (patternValue && editor === 'keyValue') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.value)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n // If patternValue is provided and editor is stringList, then validate each item in array\n } else if (patternValue && editor === 'stringList') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n // Check that object items fit patternKey and patternValue\n if (type === 'object' && value) {\n if (patternKey) {\n const check = new RegExp(patternKey);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n if (!check.test(key)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternKey,\n }));\n }\n }\n if (patternValue) {\n const check = new RegExp(patternValue);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n const propertyValue = value[key];\n if (typeof propertyValue !== 'string' || !check.test(propertyValue)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n if (fieldErrors.length > 0) {\n const message = fieldErrors.join(', ');\n errors.push({ fieldKey: property, message });\n }\n });\n\n return errors;\n}\n\n/**\n * This functions parses all given JSON and then takes each of the jsFields.\n * Then if the field:\n * - is valid JS single function it replaces its single line string with a function delacation.\n * - is valid multiline JS code then replaces its single line string with `multiline` string\n * Then stringifies the code with given number of jsonSpacing spaces and finally prefixes whole\n * stringified JSON except the first line with globalSpacing spaces.\n */\nexport function makeInputJsFieldsReadable(json: string, jsFields: string[], jsonSpacing = 4, globalSpacing = 0): string {\n const parsedJson = JSON.parse(json);\n const replacements: Record<string, any> = {};\n\n jsFields.forEach((field) => {\n let maybeFunction = parsedJson[field];\n if (!maybeFunction || typeof maybeFunction !== 'string') return;\n\n let ast;\n try {\n ast = parseScript(maybeFunction, { cst: true });\n } catch (err) {\n // Don't do anything in a case of invalid JS code.\n return;\n }\n\n const isMultiline = maybeFunction.includes('\\n');\n const isSingleFunction = ast\n && ast.leafs\n && ast.leafs.length === 1 // Must have only one expression inside!\n && ast.leafs[0]\n && (\n // Normal function ...\n ast.leafs[0].type === 'FunctionDeclaration'\n // or arrow function\n || (\n ast.leafs[0].type === 'ExpressionStatement'\n && (ast.leafs[0] as { expression: { type: string } }).expression.type === 'ArrowFunction'\n )\n );\n\n // If it's not a function declaration or multiline JS code then we do nothing.\n if (!isSingleFunction && !isMultiline) return;\n\n const spaces = (new Array(isSingleFunction ? jsonSpacing : jsonSpacing * 2)).fill(' ').join('');\n maybeFunction = maybeFunction\n .split('\\n').join(`\\n${spaces}`) // This prefixes each line with spaces.\n .trim(); // Trim whitespace on both sides\n\n const replacementValue = isSingleFunction\n ? maybeFunction.replace(/[;]+$/g, '') // Remove trailing semicolons\n : `\\`${maybeFunction}\\``;\n const replacementToken = `<<<REPLACEMENT_TOKEN:${Math.random()}>>>`;\n replacements[replacementToken] = replacementValue;\n parsedJson[field] = replacementToken;\n });\n\n let niceJson = JSON.stringify(parsedJson, null, jsonSpacing);\n\n Object.entries(replacements).forEach(([replacementToken, replacementValue]) => {\n niceJson = niceJson.replace(`\"${replacementToken}\"`, replacementValue);\n });\n\n const globalSpaces = (new Array(globalSpacing)).fill(' ').join('');\n niceJson = niceJson.split('\\n').join(`\\n${globalSpaces}`);\n\n return niceJson;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAM,cAAc;AA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AAAA,EACxB,CAAC;AAED,MAAI,WAAW,KAAK,UAAU,YAAY,MAAM,WAAW;AAE3D,SAAO,QAAQ,YAAY,EAAE,QAAQ,CAAC,CAAC,kBAAkB,gBAAgB,MAAM;AAC3E,eAAW,SAAS,QAAQ,IAAI,qBAAqB,gBAAgB;AAAA,EACzE,CAAC;AAED,QAAM,eAAgB,IAAI,MAAM,aAAa,EAAG,KAAK,GAAG,EAAE,KAAK,EAAE;AACjE,aAAW,SAAS,MAAM,IAAI,EAAE,KAAK;AAAA,EAAK,cAAc;AAExD,SAAO;AACX;AAzDgB;","names":["definition","useApifyProxy","proxyUrls"]}
|
package/index.mjs
CHANGED
|
@@ -113,23 +113,58 @@ var schema_default = {
|
|
|
113
113
|
stringProperty: {
|
|
114
114
|
title: "String property",
|
|
115
115
|
type: "object",
|
|
116
|
-
additionalProperties:
|
|
116
|
+
additionalProperties: true,
|
|
117
117
|
properties: {
|
|
118
118
|
type: { enum: ["string"] },
|
|
119
119
|
title: { type: "string" },
|
|
120
120
|
description: { type: "string" },
|
|
121
|
-
default: { type: "string" },
|
|
122
|
-
prefill: { type: "string" },
|
|
123
|
-
example: { type: "string" },
|
|
124
|
-
pattern: { type: "string" },
|
|
125
121
|
nullable: { type: "boolean" },
|
|
126
|
-
minLength: { type: "integer" },
|
|
127
|
-
maxLength: { type: "integer" },
|
|
128
122
|
editor: { enum: ["javascript", "python", "textfield", "textarea", "hidden"] },
|
|
129
|
-
|
|
130
|
-
sectionDescription: { type: "string" }
|
|
123
|
+
isSecret: { type: "boolean" }
|
|
131
124
|
},
|
|
132
|
-
required: ["type", "title", "description", "editor"]
|
|
125
|
+
required: ["type", "title", "description", "editor"],
|
|
126
|
+
if: {
|
|
127
|
+
properties: {
|
|
128
|
+
isSecret: {
|
|
129
|
+
not: {
|
|
130
|
+
const: true
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
then: {
|
|
136
|
+
additionalProperties: false,
|
|
137
|
+
properties: {
|
|
138
|
+
type: { enum: ["string"] },
|
|
139
|
+
title: { type: "string" },
|
|
140
|
+
description: { type: "string" },
|
|
141
|
+
default: { type: "string" },
|
|
142
|
+
prefill: { type: "string" },
|
|
143
|
+
example: { type: "string" },
|
|
144
|
+
pattern: { type: "string" },
|
|
145
|
+
nullable: { type: "boolean" },
|
|
146
|
+
minLength: { type: "integer" },
|
|
147
|
+
maxLength: { type: "integer" },
|
|
148
|
+
editor: { enum: ["javascript", "python", "textfield", "textarea", "hidden"] },
|
|
149
|
+
isSecret: { type: "boolean" },
|
|
150
|
+
sectionCaption: { type: "string" },
|
|
151
|
+
sectionDescription: { type: "string" }
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
else: {
|
|
155
|
+
additionalProperties: false,
|
|
156
|
+
properties: {
|
|
157
|
+
type: { enum: ["string"] },
|
|
158
|
+
title: { type: "string" },
|
|
159
|
+
description: { type: "string" },
|
|
160
|
+
example: { type: "string" },
|
|
161
|
+
nullable: { type: "boolean" },
|
|
162
|
+
editor: { enum: ["textfield", "textarea", "hidden"] },
|
|
163
|
+
isSecret: { type: "boolean" },
|
|
164
|
+
sectionCaption: { type: "string" },
|
|
165
|
+
sectionDescription: { type: "string" }
|
|
166
|
+
}
|
|
167
|
+
}
|
|
133
168
|
},
|
|
134
169
|
arrayProperty: {
|
|
135
170
|
title: "Array property",
|
package/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/intl.ts","../src/input_schema.ts","../src/utilities.ts"],"sourcesContent":["/* eslint-disable max-len,quotes,quote-props */\nconst intlStrings = {\n 'inputSchema.validation.generic':\n 'Field {rootName}.{fieldKey} {message}',\n 'inputSchema.validation.required':\n 'Field {rootName}.{fieldKey} is required',\n 'inputSchema.validation.proxyRequired':\n 'Field {rootName}.{fieldKey} is required. Please provide custom proxy URLs or use Apify Proxy.',\n 'inputSchema.validation.requestListSourcesInvalid':\n 'Items in {rootName}.{fieldKey} at positions [{invalidIndexes}] do not contain valid URLs',\n 'inputSchema.validation.arrayKeysInvalid':\n 'Keys in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.arrayValuesInvalid':\n 'Values in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.objectKeysInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must match regular expression \"{pattern}',\n 'inputSchema.validation.objectValuesInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must have string value which matches regular expression \"{pattern}\"',\n 'inputSchema.validation.additionalProperty':\n 'Property {rootName}.{fieldKey} is not allowed.',\n 'inputSchema.validation.proxyGroupsNotAvailable':\n 'You currently do not have access to proxy groups: {groups}',\n 'inputSchema.validation.customProxyInvalid':\n 'Proxy URL \"{invalidUrl}\" has invalid format, it must be http://[username[:password]]@hostname:port.',\n 'inputSchema.validation.apifyProxyCountryInvalid':\n 'Country code \"{invalidCountry}\" is invalid. Only ISO 3166-1 alpha-2 country codes are supported.',\n 'inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden':\n 'The country for Apify Proxy can be specified only when using Apify Proxy.',\n 'inputSchema.validation.noAvailableAutoProxy':\n 'Currently you do not have access to any proxy group usable in automatic mode.',\n 'inputSchema.validation.noMatchingDefinition':\n 'Field schema.properties.{fieldKey} is not matching any input schema type definition. Please make sure that it\\'s type is valid.',\n};\n/* eslint-enable max-len,quotes,quote-props */\n\n/**\n * Helper function to simulate intl formatMessage function\n */\nexport function m(stringId: string, variables?: Record<string, any>) {\n let text = intlStrings[stringId];\n if (!text) return stringId;\n\n if (variables) {\n Object.keys(variables).forEach((variableName) => {\n text = text.split(`{${variableName}}`).join(variables[variableName]);\n });\n }\n\n return text;\n}\n","import Ajv, { ErrorObject } from 'ajv';\nimport schema from './schema.json';\nimport { m } from './intl';\n\nexport { schema as inputSchema };\nconst { definitions } = schema;\n\n/**\n * This function parses AJV error and transforms it into a readable string.\n *\n * @param error An error as returned from AJV.\n * @param rootName Usually 'input' or 'schema' based on if we are passing the input or schema.\n * @param properties (Used only when parsing input errors) List of input schema properties.\n * @param input (Used only when parsing input errors) Actual input that is being parsed.\n * @returns {null|{fieldKey: *, message: *}}\n */\nexport function parseAjvError(\n error: ErrorObject,\n rootName: string,\n properties: Record<string, { nullable?: boolean }> = {},\n input: Record<string, unknown> = {},\n): { fieldKey: string; message: string } | null {\n // There are 3 possible errors comming from validation:\n // - either { keword: 'anything', instancePath: '/someField', message: 'error message that we can use' }\n // - or { keyword: 'additionalProperties', params: { additionalProperty: 'field' }, message: 'must NOT have additional properties' }\n // - or { keyword: 'required', instancePath: '', params.missingProperty: 'someField' }\n\n let fieldKey: string;\n let message: string;\n\n // If error is with keyword type, it means that type of input is incorrect\n // this can mean that provided value is null\n if (error.keyword === 'type') {\n fieldKey = error.instancePath.split('/').pop()!;\n // Check if value is null and field is nullable, if yes, then skip this error\n if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {\n return null;\n }\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n } else if (error.keyword === 'required') {\n fieldKey = error.params.missingProperty;\n message = m('inputSchema.validation.required', { rootName, fieldKey });\n } else if (error.keyword === 'additionalProperties') {\n fieldKey = error.params.additionalProperty;\n message = m('inputSchema.validation.additionalProperty', { rootName, fieldKey });\n } else if (error.keyword === 'enum') {\n fieldKey = error.instancePath.split('/').pop()!;\n const errorMessage = `${error.message}: \"${error.params.allowedValues.join('\", \"')}\"`;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: errorMessage });\n } else {\n fieldKey = error.instancePath.split('/').pop()!;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n }\n\n return { fieldKey, message };\n}\n\n/**\n * Validates given object against schema and throws a human readable error.\n */\nconst validateAgainstSchemaOrThrow = <T> (validator: Ajv, obj: T, inputSchema: any, rootName: string) => {\n if (validator.validate(inputSchema, obj)) return;\n\n const errorMessage = parseAjvError(validator.errors![0], rootName)?.message;\n throw new Error(`Input schema is not valid (${errorMessage})`);\n};\n\n/**\n * This validates given object only against the basic input schema without checking the particular fields.\n * We override schema.properties.properties not to validate field defitions.\n */\nconst validateBasicStructure = <T> (validator: Ajv, obj: T) => {\n const schemaWithoutProperties = { ...schema };\n schemaWithoutProperties.properties = { ...schema.properties, properties: { type: 'object' } as any };\n validateAgainstSchemaOrThrow(validator, obj, schemaWithoutProperties, 'schema');\n};\n\n/**\n * Validates particular field against it's schema.\n */\nconst validateField = <T extends Record<string, any>> (validator: Ajv, fieldSchema: T, fieldKey: string) => {\n const matchingDefinitions = Object\n .values<any>(definitions) // cast as any, as the code in first branch seems to be invalid\n .filter((definition) => {\n return definition.properties.type.enum\n // This is a normal case where fieldSchema.type can be only one possible value matching definition.properties.type.enum.0\n ? definition.properties.type.enum[0] === fieldSchema.type\n // This is a type \"Any\" where fieldSchema.type is an array of possible values\n : Array.isArray(fieldSchema.type);\n });\n\n // There is not matching definition.\n if (matchingDefinitions.length === 0) {\n const errorMessage = m('inputSchema.validation.noMatchingDefinition', { fieldKey });\n throw new Error(`Input schema is not valid (${errorMessage})`);\n }\n\n // If there is only one matching then we are done and simply compare it.\n if (matchingDefinitions.length === 1) {\n validateAgainstSchemaOrThrow(validator, fieldSchema, matchingDefinitions[0], `schema.properties.${fieldKey}`);\n return;\n }\n\n // If there are more matching definitions then the type is string and we need to get the right one.\n // If the definition contains \"enum\" property then it's enum type.\n if (fieldSchema.enum) {\n const definition = matchingDefinitions.filter((item) => !!item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find \"enum property\" definition');\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}.enum`);\n return;\n }\n // Otherwise we use the other definition.\n const definition = matchingDefinitions.filter((item) => !item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find other than \"enum property\" definition');\n\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}`);\n};\n\n/**\n * This function validates given input schema first just for basic structure then each field one by one and\n * finally fully against the whole schema.\n *\n * This way we get the most accurate error message for user.\n */\nexport function validateInputSchema<T extends Record<string, any>>(validator: Ajv, inputSchema: T) {\n // First validate just basic structure without fields.\n validateBasicStructure(validator, inputSchema);\n\n // Then validate each field separately.\n Object.entries<any>(inputSchema.properties).forEach(([fieldKey, fieldSchema]) => validateField(validator, fieldSchema, fieldKey));\n\n // Finally just to be sure run validation against the whole shema.\n validateAgainstSchemaOrThrow(validator, inputSchema, schema, 'schema');\n}\n","import { PROXY_URL_REGEX, URL_REGEX } from '@apify/consts';\nimport { countries } from 'countries-list';\nimport { ValidateFunction } from 'ajv';\nimport { parseScript } from 'escaya';\nimport { m } from './intl';\nimport { parseAjvError } from './input_schema';\n\n/**\n * Validates input field configured with proxy editor\n * @param fieldKey Proxy field value\n * @param value Proxy field value\n * @param [isRequired] Whether the field is required or not\n * @param [options] Information about proxy groups availability\n * @param [options.hasAutoProxyGroups] Informs validation whether user has atleast one proxy group available in auto mode\n * @param [options.availableProxyGroups] List of available proxy groups\n * @param [options.disabledProxyGroups] Object with groupId as key and error message as value (mostly for residential/SERP)\n */\nfunction validateProxyField(\n fieldKey: Record<string, unknown>,\n value: Record<string, any>,\n isRequired = false,\n options: { hasAutoProxyGroups?: boolean; availableProxyGroups?: string[]; disabledProxyGroups?: Record<string, unknown> } | null = null,\n) {\n const fieldErrors: any[] = [];\n if (isRequired) {\n // Nullable error is already handled by AJV\n if (value === null) return fieldErrors;\n if (!value) {\n const message = m('inputSchema.validation.required', { rootName: 'input', fieldKey });\n fieldErrors.push(message);\n return fieldErrors;\n }\n\n const { useApifyProxy, proxyUrls } = value;\n if (!useApifyProxy && (!Array.isArray(proxyUrls) || proxyUrls.length === 0)) {\n fieldErrors.push(m('inputSchema.validation.proxyRequired', { rootName: 'input', fieldKey }));\n return fieldErrors;\n }\n }\n\n // Input is not required, so missing value is valid\n if (!value) return fieldErrors;\n\n const { useApifyProxy, proxyUrls, apifyProxyGroups, apifyProxyCountry } = value;\n\n if (!useApifyProxy && Array.isArray(proxyUrls)) {\n let invalidUrl = false;\n proxyUrls.forEach((url) => {\n if (!PROXY_URL_REGEX.test(url.trim())) invalidUrl = url.trim();\n });\n if (invalidUrl) {\n fieldErrors.push(m('inputSchema.validation.customProxyInvalid', { invalidUrl }));\n }\n }\n\n // Apify proxy country can be set only when using Apify proxy\n if (!useApifyProxy && apifyProxyCountry) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden'));\n }\n\n // If Apify proxy is not used skip additional checks\n if (!useApifyProxy) return fieldErrors;\n\n // If Apify proxy is used, check if there is a selected country and if so, check that it's valid (empty or a valid country code)\n if (apifyProxyCountry && !countries[apifyProxyCountry]) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryInvalid', { invalidCountry: apifyProxyCountry }));\n }\n\n // If options are not provided skip additional checks\n if (!options) return fieldErrors;\n\n const selectedProxyGroups = (apifyProxyGroups || []);\n\n // Auto mode, check that user has access to alteast one proxy group usable in this mode\n if (!selectedProxyGroups.length && !options.hasAutoProxyGroups) {\n fieldErrors.push(m('inputSchema.validation.noAvailableAutoProxy'));\n return fieldErrors;\n }\n\n // Check if proxy groups selected by user are available to him\n const availableProxyGroupsById = {};\n (options.availableProxyGroups || []).forEach((group) => { availableProxyGroupsById[group] = true; });\n const unavailableProxyGroups = selectedProxyGroups.filter((group: string) => !availableProxyGroupsById[group]);\n\n if (unavailableProxyGroups.length) {\n fieldErrors.push(m('inputSchema.validation.proxyGroupsNotAvailable', {\n rootName: 'input',\n fieldKey,\n groups: unavailableProxyGroups.join(', '),\n }));\n }\n\n // Check if any of the proxy groups are blocked and if yes then output the associated message\n const blockedProxyGroupsById = options.disabledProxyGroups || {};\n selectedProxyGroups\n .filter((group: string) => blockedProxyGroupsById[group])\n .forEach((blockedGroup: string) => {\n fieldErrors.push(blockedProxyGroupsById[blockedGroup]);\n });\n\n return fieldErrors;\n}\n\n/**\n * Uses AJV validator to validate input with input schema and then\n * does custom validation for our own properties (nullable, patternKey, patternValue)\n * @param validator Initialized AJV validator\n * @param inputSchema Valid input schema in object\n * @param input Input object to be validated\n * @param options (Optional) Additional validation configuration for certain fields\n */\nexport function validateInputUsingValidator(\n validator: ValidateFunction,\n inputSchema: Record<string, any>,\n input: Record<string, unknown>,\n options: Record<string, any> = {},\n) {\n const isValid = validator(input); // Check if input is valid based on schema values\n\n const { properties } = inputSchema;\n const required = inputSchema.required || [];\n\n let errors: { fieldKey: string, message: string }[] = [];\n // Process AJV validation errors\n if (!isValid) {\n errors = validator.errors!\n .map((error) => parseAjvError(error, 'input', properties, input))\n .filter((error) => !!error) as any[];\n }\n\n Object.keys(properties).forEach((property) => {\n const value = input[property] as Record<string, any>;\n const { type, editor, patternKey, patternValue } = properties[property];\n const fieldErrors = [];\n // Check that proxy is required, if yes, valides that it's correctly setup\n if (type === 'object' && editor === 'proxy') {\n const proxyValidationErrors = validateProxyField(property as any, value, required.includes(property), options.proxy);\n proxyValidationErrors.forEach((error) => {\n fieldErrors.push(error);\n });\n }\n // Check that array items fit patternKey and patternValue\n if (type === 'array' && value && Array.isArray(value)) {\n if (editor === 'requestListSources') {\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!item) invalidIndexes.push(index);\n else if (!item.url && !item.requestsFromUrl) invalidIndexes.push(index);\n else if (item.url && !URL_REGEX.test(item.url)) invalidIndexes.push(index);\n else if (item.requestsFromUrl && !URL_REGEX.test(item.requestsFromUrl)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.requestListSourcesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n }));\n }\n }\n // If patternKey is provided, then validate keys of objects in array\n if (patternKey && editor === 'keyValue') {\n const check = new RegExp(patternKey);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.key)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternKey,\n }));\n }\n }\n // If patternValue is provided and editor is keyValue, then validate values of objecs in array\n if (patternValue && editor === 'keyValue') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.value)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n // If patternValue is provided and editor is stringList, then validate each item in array\n } else if (patternValue && editor === 'stringList') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n // Check that object items fit patternKey and patternValue\n if (type === 'object' && value) {\n if (patternKey) {\n const check = new RegExp(patternKey);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n if (!check.test(key)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternKey,\n }));\n }\n }\n if (patternValue) {\n const check = new RegExp(patternValue);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n const propertyValue = value[key];\n if (typeof propertyValue !== 'string' || !check.test(propertyValue)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n if (fieldErrors.length > 0) {\n const message = fieldErrors.join(', ');\n errors.push({ fieldKey: property, message });\n }\n });\n\n return errors;\n}\n\n/**\n * This functions parses all given JSON and then takes each of the jsFields.\n * Then if the field:\n * - is valid JS single function it replaces its single line string with a function delacation.\n * - is valid multiline JS code then replaces its single line string with `multiline` string\n * Then stringifies the code with given number of jsonSpacing spaces and finally prefixes whole\n * stringified JSON except the first line with globalSpacing spaces.\n */\nexport function makeInputJsFieldsReadable(json: string, jsFields: string[], jsonSpacing = 4, globalSpacing = 0): string {\n const parsedJson = JSON.parse(json);\n const replacements: Record<string, any> = {};\n\n jsFields.forEach((field) => {\n let maybeFunction = parsedJson[field];\n if (!maybeFunction || typeof maybeFunction !== 'string') return;\n\n let ast;\n try {\n ast = parseScript(maybeFunction, { cst: true });\n } catch (err) {\n // Don't do anything in a case of invalid JS code.\n return;\n }\n\n const isMultiline = maybeFunction.includes('\\n');\n const isSingleFunction = ast\n && ast.leafs\n && ast.leafs.length === 1 // Must have only one expression inside!\n && ast.leafs[0]\n && (\n // Normal function ...\n ast.leafs[0].type === 'FunctionDeclaration'\n // or arrow function\n || (\n ast.leafs[0].type === 'ExpressionStatement'\n && (ast.leafs[0] as { expression: { type: string } }).expression.type === 'ArrowFunction'\n )\n );\n\n // If it's not a function declaration or multiline JS code then we do nothing.\n if (!isSingleFunction && !isMultiline) return;\n\n const spaces = (new Array(isSingleFunction ? jsonSpacing : jsonSpacing * 2)).fill(' ').join('');\n maybeFunction = maybeFunction\n .split('\\n').join(`\\n${spaces}`) // This prefixes each line with spaces.\n .trim(); // Trim whitespace on both sides\n\n const replacementValue = isSingleFunction\n ? maybeFunction.replace(/[;]+$/g, '') // Remove trailing semicolons\n : `\\`${maybeFunction}\\``;\n const replacementToken = `<<<REPLACEMENT_TOKEN:${Math.random()}>>>`;\n replacements[replacementToken] = replacementValue;\n parsedJson[field] = replacementToken;\n });\n\n let niceJson = JSON.stringify(parsedJson, null, jsonSpacing);\n\n Object.entries(replacements).forEach(([replacementToken, replacementValue]) => {\n niceJson = niceJson.replace(`\"${replacementToken}\"`, replacementValue);\n });\n\n const globalSpaces = (new Array(globalSpacing)).fill(' ').join('');\n niceJson = niceJson.split('\\n').join(`\\n${globalSpaces}`);\n\n return niceJson;\n}\n"],"mappings":";;;;AACA,IAAM,cAAc;AAAA,EAChB,kCACI;AAAA,EACJ,mCACI;AAAA,EACJ,wCACI;AAAA,EACJ,oDACI;AAAA,EACJ,2CACI;AAAA,EACJ,6CACI;AAAA,EACJ,4CACI;AAAA,EACJ,8CACI;AAAA,EACJ,6CACI;AAAA,EACJ,kDACI;AAAA,EACJ,6CACI;AAAA,EACJ,mDACI;AAAA,EACJ,sEACI;AAAA,EACJ,+CACI;AAAA,EACJ,+CACI;AACR;AAMO,SAAS,EAAE,UAAkB,WAAiC;AACjE,MAAI,OAAO,YAAY;AACvB,MAAI,CAAC;AAAM,WAAO;AAElB,MAAI,WAAW;AACX,WAAO,KAAK,SAAS,EAAE,QAAQ,CAAC,iBAAiB;AAC7C,aAAO,KAAK,MAAM,IAAI,eAAe,EAAE,KAAK,UAAU,aAAa;AAAA,IACvE,CAAC;AAAA,EACL;AAEA,SAAO;AACX;AAXgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACjChB,IAAM,EAAE,YAAY,IAAI;AAWjB,SAAS,cACZ,OACA,UACA,aAAqD,CAAC,GACtD,QAAiC,CAAC,GACU;AAM5C,MAAI;AACJ,MAAI;AAIJ,MAAI,MAAM,YAAY,QAAQ;AAC1B,eAAW,MAAM,aAAa,MAAM,GAA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oBAAgB,cACX,MAAM,IAAI,EAAE,KAAK;AAAA,EAAK,QAAQ,EAC9B,KAAK;AAEV,UAAM,mBAAmB,mBACnB,cAAc,QAAQ,UAAU,EAAE,IAClC,KAAK;AACX,UAAM,mBAAmB,wBAAwB,KAAK,OAAO;AAC7D,iBAAa,oBAAoB;AACjC,eAAW,SAAS;AAAA,EACxB,CAAC;AAED,MAAI,WAAW,KAAK,UAAU,YAAY,MAAM,WAAW;AAE3D,SAAO,QAAQ,YAAY,EAAE,QAAQ,CAAC,CAAC,kBAAkB,gBAAgB,MAAM;AAC3E,eAAW,SAAS,QAAQ,IAAI,qBAAqB,gBAAgB;AAAA,EACzE,CAAC;AAED,QAAM,eAAgB,IAAI,MAAM,aAAa,EAAG,KAAK,GAAG,EAAE,KAAK,EAAE;AACjE,aAAW,SAAS,MAAM,IAAI,EAAE,KAAK;AAAA,EAAK,cAAc;AAExD,SAAO;AACX;AAzDgB;","names":["definition","useApifyProxy","proxyUrls"]}
|
|
1
|
+
{"version":3,"sources":["../src/intl.ts","../src/input_schema.ts","../src/utilities.ts"],"sourcesContent":["/* eslint-disable max-len,quotes,quote-props */\nconst intlStrings = {\n 'inputSchema.validation.generic':\n 'Field {rootName}.{fieldKey} {message}',\n 'inputSchema.validation.required':\n 'Field {rootName}.{fieldKey} is required',\n 'inputSchema.validation.proxyRequired':\n 'Field {rootName}.{fieldKey} is required. Please provide custom proxy URLs or use Apify Proxy.',\n 'inputSchema.validation.requestListSourcesInvalid':\n 'Items in {rootName}.{fieldKey} at positions [{invalidIndexes}] do not contain valid URLs',\n 'inputSchema.validation.arrayKeysInvalid':\n 'Keys in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.arrayValuesInvalid':\n 'Values in {rootName}.{fieldKey} at positions [{invalidIndexes}] must match regular expression \"{pattern}\"',\n 'inputSchema.validation.objectKeysInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must match regular expression \"{pattern}',\n 'inputSchema.validation.objectValuesInvalid':\n 'Keys [{invalidKeys}] in {rootName}.{fieldKey} must have string value which matches regular expression \"{pattern}\"',\n 'inputSchema.validation.additionalProperty':\n 'Property {rootName}.{fieldKey} is not allowed.',\n 'inputSchema.validation.proxyGroupsNotAvailable':\n 'You currently do not have access to proxy groups: {groups}',\n 'inputSchema.validation.customProxyInvalid':\n 'Proxy URL \"{invalidUrl}\" has invalid format, it must be http://[username[:password]]@hostname:port.',\n 'inputSchema.validation.apifyProxyCountryInvalid':\n 'Country code \"{invalidCountry}\" is invalid. Only ISO 3166-1 alpha-2 country codes are supported.',\n 'inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden':\n 'The country for Apify Proxy can be specified only when using Apify Proxy.',\n 'inputSchema.validation.noAvailableAutoProxy':\n 'Currently you do not have access to any proxy group usable in automatic mode.',\n 'inputSchema.validation.noMatchingDefinition':\n 'Field schema.properties.{fieldKey} is not matching any input schema type definition. Please make sure that it\\'s type is valid.',\n};\n/* eslint-enable max-len,quotes,quote-props */\n\n/**\n * Helper function to simulate intl formatMessage function\n */\nexport function m(stringId: string, variables?: Record<string, any>) {\n let text = intlStrings[stringId];\n if (!text) return stringId;\n\n if (variables) {\n Object.keys(variables).forEach((variableName) => {\n text = text.split(`{${variableName}}`).join(variables[variableName]);\n });\n }\n\n return text;\n}\n","import Ajv, { ErrorObject } from 'ajv';\nimport schema from './schema.json';\nimport { m } from './intl';\n\nexport { schema as inputSchema };\nconst { definitions } = schema;\n\n/**\n * This function parses AJV error and transforms it into a readable string.\n *\n * @param error An error as returned from AJV.\n * @param rootName Usually 'input' or 'schema' based on if we are passing the input or schema.\n * @param properties (Used only when parsing input errors) List of input schema properties.\n * @param input (Used only when parsing input errors) Actual input that is being parsed.\n * @returns {null|{fieldKey: *, message: *}}\n */\nexport function parseAjvError(\n error: ErrorObject,\n rootName: string,\n properties: Record<string, { nullable?: boolean }> = {},\n input: Record<string, unknown> = {},\n): { fieldKey: string; message: string } | null {\n // There are 3 possible errors comming from validation:\n // - either { keword: 'anything', instancePath: '/someField', message: 'error message that we can use' }\n // - or { keyword: 'additionalProperties', params: { additionalProperty: 'field' }, message: 'must NOT have additional properties' }\n // - or { keyword: 'required', instancePath: '', params.missingProperty: 'someField' }\n\n let fieldKey: string;\n let message: string;\n\n // If error is with keyword type, it means that type of input is incorrect\n // this can mean that provided value is null\n if (error.keyword === 'type') {\n fieldKey = error.instancePath.split('/').pop()!;\n // Check if value is null and field is nullable, if yes, then skip this error\n if (properties[fieldKey] && properties[fieldKey].nullable && input[fieldKey] === null) {\n return null;\n }\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n } else if (error.keyword === 'required') {\n fieldKey = error.params.missingProperty;\n message = m('inputSchema.validation.required', { rootName, fieldKey });\n } else if (error.keyword === 'additionalProperties') {\n fieldKey = error.params.additionalProperty;\n message = m('inputSchema.validation.additionalProperty', { rootName, fieldKey });\n } else if (error.keyword === 'enum') {\n fieldKey = error.instancePath.split('/').pop()!;\n const errorMessage = `${error.message}: \"${error.params.allowedValues.join('\", \"')}\"`;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: errorMessage });\n } else {\n fieldKey = error.instancePath.split('/').pop()!;\n message = m('inputSchema.validation.generic', { rootName, fieldKey, message: error.message });\n }\n\n return { fieldKey, message };\n}\n\n/**\n * Validates given object against schema and throws a human readable error.\n */\nconst validateAgainstSchemaOrThrow = <T> (validator: Ajv, obj: T, inputSchema: any, rootName: string) => {\n if (validator.validate(inputSchema, obj)) return;\n\n const errorMessage = parseAjvError(validator.errors![0], rootName)?.message;\n throw new Error(`Input schema is not valid (${errorMessage})`);\n};\n\n/**\n * This validates given object only against the basic input schema without checking the particular fields.\n * We override schema.properties.properties not to validate field defitions.\n */\nconst validateBasicStructure = <T> (validator: Ajv, obj: T) => {\n const schemaWithoutProperties = { ...schema };\n schemaWithoutProperties.properties = { ...schema.properties, properties: { type: 'object' } as any };\n validateAgainstSchemaOrThrow(validator, obj, schemaWithoutProperties, 'schema');\n};\n\n/**\n * Validates particular field against it's schema.\n */\nconst validateField = <T extends Record<string, any>> (validator: Ajv, fieldSchema: T, fieldKey: string) => {\n const matchingDefinitions = Object\n .values<any>(definitions) // cast as any, as the code in first branch seems to be invalid\n .filter((definition) => {\n return definition.properties.type.enum\n // This is a normal case where fieldSchema.type can be only one possible value matching definition.properties.type.enum.0\n ? definition.properties.type.enum[0] === fieldSchema.type\n // This is a type \"Any\" where fieldSchema.type is an array of possible values\n : Array.isArray(fieldSchema.type);\n });\n\n // There is not matching definition.\n if (matchingDefinitions.length === 0) {\n const errorMessage = m('inputSchema.validation.noMatchingDefinition', { fieldKey });\n throw new Error(`Input schema is not valid (${errorMessage})`);\n }\n\n // If there is only one matching then we are done and simply compare it.\n if (matchingDefinitions.length === 1) {\n validateAgainstSchemaOrThrow(validator, fieldSchema, matchingDefinitions[0], `schema.properties.${fieldKey}`);\n return;\n }\n\n // If there are more matching definitions then the type is string and we need to get the right one.\n // If the definition contains \"enum\" property then it's enum type.\n if (fieldSchema.enum) {\n const definition = matchingDefinitions.filter((item) => !!item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find \"enum property\" definition');\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}.enum`);\n return;\n }\n // Otherwise we use the other definition.\n const definition = matchingDefinitions.filter((item) => !item.properties.enum).pop();\n if (!definition) throw new Error('Input schema validation failed to find other than \"enum property\" definition');\n\n validateAgainstSchemaOrThrow(validator, fieldSchema, definition, `schema.properties.${fieldKey}`);\n};\n\n/**\n * This function validates given input schema first just for basic structure then each field one by one and\n * finally fully against the whole schema.\n *\n * This way we get the most accurate error message for user.\n */\nexport function validateInputSchema<T extends Record<string, any>>(validator: Ajv, inputSchema: T) {\n // First validate just basic structure without fields.\n validateBasicStructure(validator, inputSchema);\n\n // Then validate each field separately.\n Object.entries<any>(inputSchema.properties).forEach(([fieldKey, fieldSchema]) => validateField(validator, fieldSchema, fieldKey));\n\n // Finally just to be sure run validation against the whole shema.\n validateAgainstSchemaOrThrow(validator, inputSchema, schema, 'schema');\n}\n","import { PROXY_URL_REGEX, URL_REGEX } from '@apify/consts';\nimport { countries } from 'countries-list';\nimport { ValidateFunction } from 'ajv';\nimport { parseScript } from 'escaya';\nimport { m } from './intl';\nimport { parseAjvError } from './input_schema';\n\n/**\n * Validates input field configured with proxy editor\n * @param fieldKey Proxy field value\n * @param value Proxy field value\n * @param [isRequired] Whether the field is required or not\n * @param [options] Information about proxy groups availability\n * @param [options.hasAutoProxyGroups] Informs validation whether user has atleast one proxy group available in auto mode\n * @param [options.availableProxyGroups] List of available proxy groups\n * @param [options.disabledProxyGroups] Object with groupId as key and error message as value (mostly for residential/SERP)\n */\nfunction validateProxyField(\n fieldKey: Record<string, unknown>,\n value: Record<string, any>,\n isRequired = false,\n options: { hasAutoProxyGroups?: boolean; availableProxyGroups?: string[]; disabledProxyGroups?: Record<string, unknown> } | null = null,\n) {\n const fieldErrors: any[] = [];\n if (isRequired) {\n // Nullable error is already handled by AJV\n if (value === null) return fieldErrors;\n if (!value) {\n const message = m('inputSchema.validation.required', { rootName: 'input', fieldKey });\n fieldErrors.push(message);\n return fieldErrors;\n }\n\n const { useApifyProxy, proxyUrls } = value;\n if (!useApifyProxy && (!Array.isArray(proxyUrls) || proxyUrls.length === 0)) {\n fieldErrors.push(m('inputSchema.validation.proxyRequired', { rootName: 'input', fieldKey }));\n return fieldErrors;\n }\n }\n\n // Input is not required, so missing value is valid\n if (!value) return fieldErrors;\n\n const { useApifyProxy, proxyUrls, apifyProxyGroups, apifyProxyCountry } = value;\n\n if (!useApifyProxy && Array.isArray(proxyUrls)) {\n let invalidUrl = false;\n proxyUrls.forEach((url) => {\n if (!PROXY_URL_REGEX.test(url.trim())) invalidUrl = url.trim();\n });\n if (invalidUrl) {\n fieldErrors.push(m('inputSchema.validation.customProxyInvalid', { invalidUrl }));\n }\n }\n\n // Apify proxy country can be set only when using Apify proxy\n if (!useApifyProxy && apifyProxyCountry) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryWithoutApifyProxyForbidden'));\n }\n\n // If Apify proxy is not used skip additional checks\n if (!useApifyProxy) return fieldErrors;\n\n // If Apify proxy is used, check if there is a selected country and if so, check that it's valid (empty or a valid country code)\n if (apifyProxyCountry && !countries[apifyProxyCountry]) {\n fieldErrors.push(m('inputSchema.validation.apifyProxyCountryInvalid', { invalidCountry: apifyProxyCountry }));\n }\n\n // If options are not provided skip additional checks\n if (!options) return fieldErrors;\n\n const selectedProxyGroups = (apifyProxyGroups || []);\n\n // Auto mode, check that user has access to alteast one proxy group usable in this mode\n if (!selectedProxyGroups.length && !options.hasAutoProxyGroups) {\n fieldErrors.push(m('inputSchema.validation.noAvailableAutoProxy'));\n return fieldErrors;\n }\n\n // Check if proxy groups selected by user are available to him\n const availableProxyGroupsById = {};\n (options.availableProxyGroups || []).forEach((group) => { availableProxyGroupsById[group] = true; });\n const unavailableProxyGroups = selectedProxyGroups.filter((group: string) => !availableProxyGroupsById[group]);\n\n if (unavailableProxyGroups.length) {\n fieldErrors.push(m('inputSchema.validation.proxyGroupsNotAvailable', {\n rootName: 'input',\n fieldKey,\n groups: unavailableProxyGroups.join(', '),\n }));\n }\n\n // Check if any of the proxy groups are blocked and if yes then output the associated message\n const blockedProxyGroupsById = options.disabledProxyGroups || {};\n selectedProxyGroups\n .filter((group: string) => blockedProxyGroupsById[group])\n .forEach((blockedGroup: string) => {\n fieldErrors.push(blockedProxyGroupsById[blockedGroup]);\n });\n\n return fieldErrors;\n}\n\n/**\n * Uses AJV validator to validate input with input schema and then\n * does custom validation for our own properties (nullable, patternKey, patternValue)\n * @param validator Initialized AJV validator\n * @param inputSchema Valid input schema in object\n * @param input Input object to be validated\n * @param options (Optional) Additional validation configuration for certain fields\n */\nexport function validateInputUsingValidator(\n validator: ValidateFunction,\n inputSchema: Record<string, any>,\n input: Record<string, unknown>,\n options: Record<string, any> = {},\n) {\n const isValid = validator(input); // Check if input is valid based on schema values\n\n const { properties } = inputSchema;\n const required = inputSchema.required || [];\n\n let errors: { fieldKey: string, message: string }[] = [];\n // Process AJV validation errors\n if (!isValid) {\n errors = validator.errors!\n .map((error) => parseAjvError(error, 'input', properties, input))\n .filter((error) => !!error) as any[];\n }\n\n Object.keys(properties).forEach((property) => {\n const value = input[property] as Record<string, any>;\n const { type, editor, patternKey, patternValue } = properties[property];\n const fieldErrors = [];\n // Check that proxy is required, if yes, valides that it's correctly setup\n if (type === 'object' && editor === 'proxy') {\n const proxyValidationErrors = validateProxyField(property as any, value, required.includes(property), options.proxy);\n proxyValidationErrors.forEach((error) => {\n fieldErrors.push(error);\n });\n }\n // Check that array items fit patternKey and patternValue\n if (type === 'array' && value && Array.isArray(value)) {\n if (editor === 'requestListSources') {\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!item) invalidIndexes.push(index);\n else if (!item.url && !item.requestsFromUrl) invalidIndexes.push(index);\n else if (item.url && !URL_REGEX.test(item.url)) invalidIndexes.push(index);\n else if (item.requestsFromUrl && !URL_REGEX.test(item.requestsFromUrl)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.requestListSourcesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n }));\n }\n }\n // If patternKey is provided, then validate keys of objects in array\n if (patternKey && editor === 'keyValue') {\n const check = new RegExp(patternKey);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.key)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternKey,\n }));\n }\n }\n // If patternValue is provided and editor is keyValue, then validate values of objecs in array\n if (patternValue && editor === 'keyValue') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item.value)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n // If patternValue is provided and editor is stringList, then validate each item in array\n } else if (patternValue && editor === 'stringList') {\n const check = new RegExp(patternValue);\n const invalidIndexes: any[] = [];\n value.forEach((item, index) => {\n if (!check.test(item)) invalidIndexes.push(index);\n });\n if (invalidIndexes.length) {\n fieldErrors.push(m('inputSchema.validation.arrayValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidIndexes: invalidIndexes.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n // Check that object items fit patternKey and patternValue\n if (type === 'object' && value) {\n if (patternKey) {\n const check = new RegExp(patternKey);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n if (!check.test(key)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectKeysInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternKey,\n }));\n }\n }\n if (patternValue) {\n const check = new RegExp(patternValue);\n const invalidKeys: any[] = [];\n Object.keys(value).forEach((key) => {\n const propertyValue = value[key];\n if (typeof propertyValue !== 'string' || !check.test(propertyValue)) invalidKeys.push(key);\n });\n if (invalidKeys.length) {\n fieldErrors.push(m('inputSchema.validation.objectValuesInvalid', {\n rootName: 'input',\n fieldKey: property,\n invalidKeys: invalidKeys.join(','),\n pattern: patternValue,\n }));\n }\n }\n }\n if (fieldErrors.length > 0) {\n const message = fieldErrors.join(', ');\n errors.push({ fieldKey: property, message });\n }\n });\n\n return errors;\n}\n\n/**\n * This functions parses all given JSON and then takes each of the jsFields.\n * Then if the field:\n * - is valid JS single function it replaces its single line string with a function delacation.\n * - is valid multiline JS code then replaces its single line string with `multiline` string\n * Then stringifies the code with given number of jsonSpacing spaces and finally prefixes whole\n * stringified JSON except the first line with globalSpacing spaces.\n */\nexport function makeInputJsFieldsReadable(json: string, jsFields: string[], jsonSpacing = 4, globalSpacing = 0): string {\n const parsedJson = JSON.parse(json);\n const replacements: Record<string, any> = {};\n\n jsFields.forEach((field) => {\n let maybeFunction = parsedJson[field];\n if (!maybeFunction || typeof maybeFunction !== 'string') return;\n\n let ast;\n try {\n ast = parseScript(maybeFunction, { cst: true });\n } catch (err) {\n // Don't do anything in a case of invalid JS code.\n return;\n }\n\n const isMultiline = maybeFunction.includes('\\n');\n const isSingleFunction = ast\n && ast.leafs\n && ast.leafs.length === 1 // Must have only one expression inside!\n && ast.leafs[0]\n && (\n // Normal function ...\n ast.leafs[0].type === 'FunctionDeclaration'\n // or arrow function\n || (\n ast.leafs[0].type === 'ExpressionStatement'\n && (ast.leafs[0] as { expression: { type: string } }).expression.type === 'ArrowFunction'\n )\n );\n\n // If it's not a function declaration or multiline JS code then we do nothing.\n if (!isSingleFunction && !isMultiline) return;\n\n const spaces = (new Array(isSingleFunction ? jsonSpacing : jsonSpacing * 2)).fill(' ').join('');\n maybeFunction = maybeFunction\n .split('\\n').join(`\\n${spaces}`) // This prefixes each line with spaces.\n .trim(); // Trim whitespace on both sides\n\n const replacementValue = isSingleFunction\n ? maybeFunction.replace(/[;]+$/g, '') // Remove trailing semicolons\n : `\\`${maybeFunction}\\``;\n const replacementToken = `<<<REPLACEMENT_TOKEN:${Math.random()}>>>`;\n replacements[replacementToken] = replacementValue;\n parsedJson[field] = replacementToken;\n });\n\n let niceJson = JSON.stringify(parsedJson, null, jsonSpacing);\n\n Object.entries(replacements).forEach(([replacementToken, replacementValue]) => {\n niceJson = niceJson.replace(`\"${replacementToken}\"`, replacementValue);\n });\n\n const globalSpaces = (new Array(globalSpacing)).fill(' ').join('');\n niceJson = niceJson.split('\\n').join(`\\n${globalSpaces}`);\n\n return niceJson;\n}\n"],"mappings":";;;;AACA,IAAM,cAAc;AAAA,EAChB,kCACI;AAAA,EACJ,mCACI;AAAA,EACJ,wCACI;A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W,KAAK,UAAU,YAAY,MAAM,WAAW;AAE3D,SAAO,QAAQ,YAAY,EAAE,QAAQ,CAAC,CAAC,kBAAkB,gBAAgB,MAAM;AAC3E,eAAW,SAAS,QAAQ,IAAI,qBAAqB,gBAAgB;AAAA,EACzE,CAAC;AAED,QAAM,eAAgB,IAAI,MAAM,aAAa,EAAG,KAAK,GAAG,EAAE,KAAK,EAAE;AACjE,aAAW,SAAS,MAAM,IAAI,EAAE,KAAK;AAAA,EAAK,cAAc;AAExD,SAAO;AACX;AAzDgB;","names":["definition","useApifyProxy","proxyUrls"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/input_schema",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Tools and constants shared across Apify projects.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.mjs",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@apify/consts": "^2.
|
|
46
|
+
"@apify/consts": "^2.5.0",
|
|
47
47
|
"countries-list": "^2.6.1",
|
|
48
48
|
"escaya": "^0.0.61"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"ajv": "^8.0.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "c79ec67091df07662eedf4914f14433d37790990"
|
|
54
54
|
}
|
package/schema.json
CHANGED
|
@@ -79,23 +79,58 @@
|
|
|
79
79
|
"stringProperty": {
|
|
80
80
|
"title": "String property",
|
|
81
81
|
"type": "object",
|
|
82
|
-
"additionalProperties":
|
|
82
|
+
"additionalProperties": true,
|
|
83
83
|
"properties": {
|
|
84
84
|
"type": { "enum": ["string"] },
|
|
85
85
|
"title": { "type": "string" },
|
|
86
86
|
"description": { "type": "string" },
|
|
87
|
-
"default": { "type": "string" },
|
|
88
|
-
"prefill": { "type": "string" },
|
|
89
|
-
"example": { "type": "string" },
|
|
90
|
-
"pattern": { "type": "string" },
|
|
91
87
|
"nullable": { "type": "boolean" },
|
|
92
|
-
"minLength": { "type": "integer" },
|
|
93
|
-
"maxLength": { "type": "integer" },
|
|
94
88
|
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "hidden"] },
|
|
95
|
-
"
|
|
96
|
-
"sectionDescription": { "type": "string" }
|
|
89
|
+
"isSecret": { "type": "boolean" }
|
|
97
90
|
},
|
|
98
|
-
"required": ["type", "title", "description", "editor"]
|
|
91
|
+
"required": ["type", "title", "description", "editor"],
|
|
92
|
+
"if": {
|
|
93
|
+
"properties": {
|
|
94
|
+
"isSecret": {
|
|
95
|
+
"not": {
|
|
96
|
+
"const": true
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"then": {
|
|
102
|
+
"additionalProperties": false,
|
|
103
|
+
"properties": {
|
|
104
|
+
"type": { "enum": ["string"] },
|
|
105
|
+
"title": { "type": "string" },
|
|
106
|
+
"description": { "type": "string" },
|
|
107
|
+
"default": { "type": "string" },
|
|
108
|
+
"prefill": { "type": "string" },
|
|
109
|
+
"example": { "type": "string" },
|
|
110
|
+
"pattern": { "type": "string" },
|
|
111
|
+
"nullable": { "type": "boolean" },
|
|
112
|
+
"minLength": { "type": "integer" },
|
|
113
|
+
"maxLength": { "type": "integer" },
|
|
114
|
+
"editor": { "enum": ["javascript", "python", "textfield", "textarea", "hidden"] },
|
|
115
|
+
"isSecret": { "type": "boolean" },
|
|
116
|
+
"sectionCaption": { "type": "string" },
|
|
117
|
+
"sectionDescription": { "type": "string" }
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"else": {
|
|
121
|
+
"additionalProperties": false,
|
|
122
|
+
"properties": {
|
|
123
|
+
"type": { "enum": ["string"] },
|
|
124
|
+
"title": { "type": "string" },
|
|
125
|
+
"description": { "type": "string" },
|
|
126
|
+
"example": { "type": "string" },
|
|
127
|
+
"nullable": { "type": "boolean" },
|
|
128
|
+
"editor": { "enum": ["textfield", "textarea", "hidden"] },
|
|
129
|
+
"isSecret": { "type": "boolean" },
|
|
130
|
+
"sectionCaption": { "type": "string" },
|
|
131
|
+
"sectionDescription": { "type": "string" }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
99
134
|
},
|
|
100
135
|
"arrayProperty": {
|
|
101
136
|
"title": "Array property",
|