/** The fields that can be verified by a code. */ export type RegistrationVerifiableField = 'email' | 'phone'; /** Why a send or a check failed. */ export type RegistrationCodeFailure = 'invalid' | 'expired' | 'rate_limited' | 'error'; /** What the host answers when a code is sent or checked. */ export interface RegistrationCodeResult { ok: boolean; /** Already translated by the host. Shown under the field when `ok` is * false, instead of the kit's own wording for `reason`. */ message?: string; reason?: RegistrationCodeFailure; /** With `rate_limited`: seconds before another send is allowed. */ retryAfterSeconds?: number; /** After a send: seconds before "Send a new code" works. Default 30. */ resendAfterSeconds?: number; /** Development only. The host passes it only when its server says this * is a development environment; it shows in an info alert. */ devCode?: string; /** After a check: the value the server verified. Informational. */ value?: string; } /** Options both ways of verifying a field share. */ export interface RegistrationFieldVerificationOptions { /** Digits in the code. Default 6. */ codeLength?: number; /** True when the server already holds this value as verified, such as * a page that reopens after a refused post. */ verified?: boolean; /** * With `verified`: the person may still change the value. The field * shows as verified with a "Change" action; pressing it unlocks the * field. Typing back exactly the value that started verified (trimmed, * case ignored) is verified again with no code; any other value needs * a code. Without it, `verified` locks the field with no way back. * A plain boolean, so it works from JSON. */ allowChange?: boolean; /** Called with `true` once the code is right. */ onVerifiedChange?: (verified: boolean) => void; } /** Callbacks: for a React host that calls its own API. */ export interface RegistrationFieldVerificationCallbacks extends RegistrationFieldVerificationOptions { /** Sends a code to the value. Resolve, never reject: a rejection is * shown as a failure with reason `error`. */ onSendCode: (value: string) => Promise; /** Checks the code the person typed for the value. */ onVerifyCode: (value: string, code: string) => Promise; sendUrl?: never; verifyUrl?: never; } /** * URLs: data only, for a host that mounts the form from JSON. The kit * POSTs JSON to each (same origin, cookies sent). Send body: * `{ "value" }`. Verify body: `{ "value", "code" }`. The answer is a * `RegistrationCodeResult` as JSON, on success and on failure. A path or * an address on this site only. */ export interface RegistrationFieldVerificationUrls extends RegistrationFieldVerificationOptions { sendUrl: string; verifyUrl: string; onSendCode?: never; onVerifyCode?: never; } /** How one field is verified: both callbacks, or both URLs. */ export type RegistrationFieldVerification = RegistrationFieldVerificationCallbacks | RegistrationFieldVerificationUrls; export type ContactVerificationStatus = 'idle' | 'sending' | 'sent' | 'verifying' | 'verified'; export interface ContactVerificationFailure { reason: RegistrationCodeFailure; /** The host's own message, when it gave one. */ message?: string; } export declare const DEFAULT_CODE_LENGTH = 6; export declare const DEFAULT_RESEND_SECONDS = 30; export interface UseContactVerificationOptions { /** Undefined: the field is not verified and the hook does nothing. */ config: RegistrationFieldVerification | undefined; /** The value now in the field. */ value: string; } export interface UseContactVerificationReturn { /** True when the field takes part in verification. */ enabled: boolean; status: ContactVerificationStatus; /** True once the server has accepted the value. */ verified: boolean; codeLength: number; code: string; setCode: (code: string) => void; failure: ContactVerificationFailure | null; /** Seconds left before a new code may be sent; 0 when it may. */ cooldown: number; devCode: string | undefined; /** The value the code went to. */ sentTo: string; send: () => void; verify: (code?: string) => void; /** Back to idle: the person wants to change the value. */ reset: () => void; /** True when the server's "verified" may be changed (`allowChange`) * and the field is verified right now. */ changeable: boolean; /** Unlocks a `changeable` field so the value can be edited. */ unlock: () => void; } /** Runs one field's verification step. */ export declare function useContactVerification({ config, value, }: UseContactVerificationOptions): UseContactVerificationReturn; //# sourceMappingURL=use-contact-verification.d.ts.map