diff --git a/package.json b/package.json index 131fa1fc..a0d94b98 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "./process": "./lib/process/index.js", "./types": "./lib/types/index.js", "./experimental": "./lib/experimental/index.js", - "./dist/formio.core.min.js": "./dist/formio.core.min.js" + "./dist/formio.core.min.js": "./dist/formio.core.min.js", + "./error": "./lib/error/index.js" }, "scripts": { "test": "TEST=1 mocha -r ts-node/register -r tsconfig-paths/register -r mock-local-storage -r jsdom-global/register -b -t 0 'src/**/__tests__/*.test.ts'", diff --git a/src/index.ts b/src/index.ts index 233ebd6c..145533cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ export * from './modules'; export * from './utils'; export * from './process/validation'; +export * from './process/validation/rules'; export * from './process'; export * from './sdk'; export * from './types'; +export * from './error'; diff --git a/src/process/validation/i18n/en.ts b/src/process/validation/i18n/en.ts index ede84533..b1f9ad2b 100644 --- a/src/process/validation/i18n/en.ts +++ b/src/process/validation/i18n/en.ts @@ -31,9 +31,6 @@ export const EN_ERRORS = { invalidValueProperty: 'Invalid Value Property', mask: '{{field}} does not match the mask.', valueIsNotAvailable: '{{ field }} is an invalid value.', - captchaTokenValidation: 'ReCAPTCHA: Token validation error', - captchaTokenNotSpecified: 'ReCAPTCHA: Token is not specified in submission', - captchaFailure: 'ReCaptcha: Response token not found', time: '{{field}} is not a valid time', invalidDate: '{{field}} is not a valid date', }; diff --git a/src/process/validation/rules/databaseRules.ts b/src/process/validation/rules/databaseRules.ts index ac205e6c..c53198fb 100644 --- a/src/process/validation/rules/databaseRules.ts +++ b/src/process/validation/rules/databaseRules.ts @@ -1,9 +1,7 @@ import { ValidationRuleInfo } from "types"; import { validateUniqueInfo } from "./validateUnique"; -import { validateCaptchaInfo } from "./validateCaptcha"; // These are the validations that require a database connection. export const databaseRules: ValidationRuleInfo[] = [ - validateUniqueInfo, - validateCaptchaInfo + validateUniqueInfo ]; diff --git a/src/process/validation/rules/validateCaptcha.ts b/src/process/validation/rules/validateCaptcha.ts deleted file mode 100644 index 5de789fe..00000000 --- a/src/process/validation/rules/validateCaptcha.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { FieldError } from '../../../error/FieldError'; -import { RuleFn, ValidationContext } from '../../../types/index'; -import { ValidatorError } from 'error'; -import { ProcessorInfo } from 'types/process/ProcessorInfo'; - -export const shouldValidate = (context: ValidationContext) => { - const { component } = context; - if (component.type === 'recaptcha') { - return true; - } - return false; -}; - -export const validateCaptcha: RuleFn = async (context: ValidationContext) => { - const { value, config, component } = context; - if (!shouldValidate(context)) { - return null; - } - - if (!config || !config.database) { - throw new ValidatorError("Can't test for recaptcha success without a database config object"); - } - try { - if (!value || !value.token) { - return new FieldError('captchaTokenNotSpecified', context, 'catpcha'); - } - if (!value.success) { - return new FieldError('captchaTokenValidation', context, 'captcha'); - } - const captchaResult: boolean = await config.database?.validateCaptcha(value.token); - return (captchaResult === true) ? null : new FieldError('captchaFailure', context, 'captcha'); - } - catch (err: any) { - throw new ValidatorError(err.message || err); - } -}; - -export const validateCaptchaInfo: ProcessorInfo = { - name: 'validateCaptcha', - process: validateCaptcha, - shouldProcess: shouldValidate, -}; diff --git a/src/types/project/settings/ProjectSettings.ts b/src/types/project/settings/ProjectSettings.ts index ee8d839d..92348efc 100644 --- a/src/types/project/settings/ProjectSettings.ts +++ b/src/types/project/settings/ProjectSettings.ts @@ -9,7 +9,7 @@ import { ProjectFileStorageConfig, ProjectGoogleDriveConfig, ProjectKickboxConfig, - ProjectReCaptchaConfig, + ProjectCaptchaConfig, ProjectSQLConnectorConfig, } from './integrations'; @@ -39,7 +39,8 @@ export type ProjectSettings = { // Integrations email?: ProjectEmailConfig; - recaptcha?: ProjectReCaptchaConfig; + captcha?: ProjectCaptchaConfig; + recaptcha?: ProjectCaptchaConfig; esign?: ProjectESignConfig; google?: ProjectGoogleDriveConfig; kickbox?: ProjectKickboxConfig; diff --git a/src/types/project/settings/integrations/reCaptcha.ts b/src/types/project/settings/integrations/captcha.ts similarity index 54% rename from src/types/project/settings/integrations/reCaptcha.ts rename to src/types/project/settings/integrations/captcha.ts index 0594423a..dd0ed2f0 100644 --- a/src/types/project/settings/integrations/reCaptcha.ts +++ b/src/types/project/settings/integrations/captcha.ts @@ -1,4 +1,4 @@ -export type ProjectReCaptchaConfig = { +export type ProjectCaptchaConfig = { siteKey: string; secretKey: string; }; diff --git a/src/types/project/settings/integrations/index.ts b/src/types/project/settings/integrations/index.ts index 781cf5bd..fb02f5e1 100644 --- a/src/types/project/settings/integrations/index.ts +++ b/src/types/project/settings/integrations/index.ts @@ -2,4 +2,4 @@ export * from './dataConnections'; export * from './email'; export * from './eSign'; export * from './fileStorage'; -export * from './reCaptcha'; +export * from './captcha';