import { C11nEnv } from '../interpreter/c11n-env';
/**
* Provides the basic APIs to handle validation in the Constellation infrastructure
*/
/**
Object that contains APIs that handle validations on a field
* @param pConnect The context object that is used for this instance of the ValidationApi
*/
declare class ValidationApi {
private readonly c11nEnv;
constructor(pConnect: C11nEnv);
/**
* It Validates the field against the validation provided to the field and updates the state with the validation message.
* If validation success it will return object with status as true
* else it will return status as false along with an error message.
* @param value - user provided value of the field to be validated.
* @param propertyName - name of the filed to be validated. The default value is taken from redux state if propertyname is not provided.
* @returns object contains status and message
* @public
* @example
example of validate() validate the property with it's value.
*
* pConnect.getValidationApi().validate('mail.com', '.email');
* //Output - when validation fails
* {
* status : false,
* message: 'Invalid Email'
* }
*
* pConnect.getValidationApi().validate('abc@gamil.com', '.email');
* //Output - when validation success
* {
* status : true
* }
*/
validate(value: string, propertyName?: string): {
status: boolean;
message: string;
} | {
status: boolean;
message?: undefined;
};
/**
* Validates an email address and returns the result.
* Use this API to check an email value in your own component logic, for example, before
* submitting a form or enabling a button. The result is returned directly to the caller —
* no error message is displayed on the field automatically.
* To display the validation error on the field automatically, use {@link ValidationApi#validate} instead.
* @param value - the email address to validate.
* @param options - an optional object containing validation settings. Supports the following property:
* @param options.useRFC822Validation - set to `true` to use the RFC 822 email grammar, which
* allows formats such as single-label domains (for example, `user@host`) and IP address
* domain literals (for example, `user@[127.0.0.1]`). Defaults to `false`, which uses the
* stricter RFC 5322 grammar that requires a fully qualified domain name (for example, `user@example.com`).
* @function validateEmail
* @returns `{ status: 'success' }` if the email is valid; `{ status: 'failure', message }` if the email is invalid,
* where `message` contains the error text that can be displayed to the user.
* @public
* @example Example for validateEmail()
* In this example, the API validates the email address entered by the user.
* pConnect.getValidationApi().validateEmail('abc@gmail.com');
* // Output - when validation succeeds
* { status: 'success' }
*
* pConnect.getValidationApi().validateEmail('mail.com');
* // Output - when validation fails
* { status: 'failure', message: 'Enter a valid email address' }
*
* pConnect.getValidationApi().validateEmail('user@host', { useRFC822Validation: true });
* // Output - when validation succeeds using the RFC 822 grammar
* { status: 'success' }
*/
validateEmail(value: string, options?: {
useRFC822Validation?: boolean;
}): {
status: 'success';
} | {
status: 'failure';
message: string;
};
}
export default ValidationApi;