import { ConditionalParameters, JSONSchema } from './conditionals'; import { ActionUpdate, EventState } from '../events/ActionDocument'; import { FieldConditional } from '../events/Conditional'; import { FieldConfig } from '../events/FieldConfig'; import { FieldUpdateValue, FieldValue } from '../events/FieldValue'; import { TranslationConfig } from '../events/TranslationConfig'; import { ITokenPayload } from '../authentication'; import { UUID } from '../uuid'; import { FormState } from '../events/utils'; import { ActionConfig } from '../events/ActionConfig'; import { ActionType } from '../events/ActionType'; import { EventConfig } from '../events/EventConfig'; import { EventDocument } from '../events/EventDocument'; import { EventIndex } from '../events/EventIndex'; import { Location } from '../events/locations'; import { SystemVariables } from '../events/TemplateConfig'; /** Returns today's date as an ISO date string (YYYY-MM-DD). */ export declare function todayISO(): string; /** * Context passed to every serialised client-side function ({@link runClientFunction}). * * `$user` (full {@link ITokenPayload}, validator paths) and `user` (a * {@link SystemVariables} subset for template substitution, default-value * path) are distinct sources, not duplicates. */ export type ClientFunctionContext = { $form: EventState | ActionUpdate; $now: string; $online: boolean; $user?: ITokenPayload; $event?: EventDocument; $leafAdminStructureLocationIds: Array<{ id: UUID; }>; user?: SystemVariables['user']; $window?: SystemVariables['$window']; locations?: Location[]; adminLevelIds?: string[]; $flags?: string[]; $status?: string; }; type CompiledClientFunction = (data: FieldValue | undefined, context: ClientFunctionContext) => unknown; /** * Deserialises a serialised function string (produced by `.toString()`) into a callable. * Results are cached by code string so each unique function body is compiled at most once. * Runs in a clean scope — no access to outer closures or external imports. */ export declare function compileClientFunction(code: string): CompiledClientFunction; export declare function buildClientFunctionContext(input: { form: EventState | ActionUpdate; validatorContext?: ValidatorContext; systemVariables?: SystemVariables; /** * In real use cases, there can be hundreds of thousands of locations. * Make sure that the context contains only the locations that are needed for validation. * E.g. if the user is a leaf admin, only the leaf locations under their admin structure are needed. * Loading few megabytes of locations to memory just for validation is not efficient and will choke the application. */ locations?: Location[]; adminLevelIds?: string[]; }): ClientFunctionContext; export declare function runClientFunction(code: string, data: FieldValue | undefined, context: ClientFunctionContext): unknown; /** * Precompiles action conditional schemas from the event configurations to improve performance of condition validation later on. * Best called once on application startup before any condition validation is done. */ export declare function precompileActionSchemas(eventConfigurations: EventConfig[]): void; export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean; export declare function validateValue(schema: JSONSchema, data: unknown): boolean; export declare function isOnline(): boolean; export declare function isConditionMet(conditional: JSONSchema, values: EventState | ActionUpdate, context: ValidatorContext): boolean; export declare function areConditionsMet(conditions: FieldConditional[], values: Record, context: ValidatorContext, _event: EventIndex): boolean; export type ValidatorContext = { user?: ITokenPayload; leafAdminStructureLocationIds?: Array<{ id: UUID; }>; event?: EventDocument; baseFormState?: EventState; }; export declare function isFieldVisible(field: FieldConfig, form: Partial, context: ValidatorContext): boolean; export declare function isFieldEnabled(field: FieldConfig, form: ActionUpdate | EventState, context: ValidatorContext): boolean; export declare function isFieldDisplayedOnReview(field: FieldConfig, form: ActionUpdate | EventState, context: ValidatorContext): boolean; export declare function isActionEnabled(actionConfig: ActionConfig, event: EventIndex, context: ValidatorContext): boolean; export declare function isActionVisible(actionConfig: ActionConfig, event: EventIndex, context: ValidatorContext): boolean; export declare function isActionAvailable(actionConfig: ActionConfig, event: EventIndex, context: ValidatorContext): boolean; export declare const errorMessages: { hiddenField: { id: string; defaultMessage: string; description: string; }; invalidDate: { defaultMessage: string; description: string; id: string; }; invalidEmail: { defaultMessage: string; description: string; id: string; }; requiredField: { defaultMessage: string; description: string; id: string; }; invalidInput: { defaultMessage: string; description: string; id: string; }; unexpectedField: { defaultMessage: string; description: string; id: string; }; correctionNotAllowed: { defaultMessage: string; description: string; id: string; }; }; /** * Custom error map for Zod to override the default error messages in intl-formik format. */ export type CustomZodToIntlErrorMap = { /** Zod by default expects { message: string } */ message: { /** Override it to match current intl-formik model */ message: TranslationConfig; }; }; /** * Validates primitive fields defined by the FieldConfig type. * e.g. email is proper format, date is a valid date, etc. * for custom validations @see runCustomFieldValidations */ export declare function validateFieldInput({ field, value, actionType }: { field: FieldConfig; value: FieldUpdateValue; actionType?: ActionType; }): { message: TranslationConfig; }[]; export declare function runStructuralValidations({ field, values, context, actionType }: { field: FieldConfig; values: ActionUpdate; context: ValidatorContext; actionType?: ActionType; }): { message: TranslationConfig; }[]; export declare function runFieldValidations({ field: config, form, value, context }: { field: FieldConfig; value: FieldUpdateValue; form: ActionUpdate; context: ValidatorContext; }): FormState>; export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable): NonNullable; export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: ConditionalParameters): boolean; export {}; //# sourceMappingURL=validate.d.ts.map