import { i as ActorRefFrom } from "./spawn-D9jgw9pW.js"; import { t as Manager } from "./Manager-CQQ99QOI.js"; import "./Actor-iTq7YY48.js"; import { t as OtpValidationErrors } from "./otp-CEWfTj9v.js"; //#region src/modules/email/types.d.ts /** * Configuration options for email verification. * * @example Standard OTP verification * ```typescript * const config: EmailConfig = { * otpVerification: true, * otpExpirationInMinutes: 5, * prefill: false, * }; * ``` * * @example With all options * ```typescript * const config: EmailConfig = { * otpVerification: true, * otpExpirationInMinutes: 10, * prefill: true, * maxOtpAttempts: 3, * }; * ``` */ type EmailConfig = { /** * Whether to require OTP (email code) verification. * If false, email is verified immediately after submission. */ otpVerification: boolean; /** * How long the OTP code remains valid, in minutes. * After expiration, user must request a new code. */ otpExpirationInMinutes: number; /** * Whether to pre-populate with user's previously stored email address. * Useful for returning users. * @default false */ prefill?: boolean; /** * Maximum number of OTP verification attempts before lockout. * After exhausting attempts, user sees an error state. * @default 3 */ maxOtpAttempts?: number; }; type EmailValidationErrors = { email?: string; }; //#endregion //#region src/modules/email/emailStateMachine.d.ts declare const emailMachine: any; type EmailMachine = typeof emailMachine; //#endregion //#region src/modules/email/emailActor.d.ts type CreateEmailActorOptions = { config: EmailConfig; }; type EmailActor = ActorRefFrom; //#endregion //#region src/modules/email/emailManager.d.ts /** Email manager is in initial state, waiting for `load()` to be called */ type EmailIdleState = { status: 'idle'; }; /** Loading prefilled email address from backend (if prefill is enabled) */ type EmailLoadingPrefillState = { status: 'loadingPrefill'; }; /** * Ready for email input - use `setEmail()` and `submit()` * @property prefilledEmail - Pre-populated email address (if prefill enabled) * @property emailError - Server-side validation error message if email was rejected * @property validationErrors - Client-side validation errors (e.g. invalid/empty email). Surfaced on blur and submit. * @property isValid - True iff `validationErrors` is empty. Optimistic semantic: starts true on initial render. * @property otpVerification - Whether OTP email verification is enabled (from module config). When omitted, treat as `false`. */ type EmailInputtingState = { status: 'inputting'; prefilledEmail?: string; emailError?: string; validationErrors?: EmailValidationErrors; isValid: boolean; otpVerification?: boolean; }; /** Email address is being submitted to the backend */ type EmailSubmittingState = { status: 'submitting'; }; /** OTP is being sent to the email address */ type EmailResendingOtpState = { status: 'resendingOtp'; /** The OTP code entered so far (controlled-input value, kept visible while disabled) */ otpCode: string; /** Expected OTP length (owned by Core) */ otpLength: number; }; /** OTP is being sent initialy to the email address */ type EmailSendingInitialOtpState = { status: 'sendingInitialOtp'; }; /** * Waiting for OTP code - use `submitOtp()`, `resendOtp()`, or `back()` * @property resendTimer - Seconds remaining before resend is allowed * @property canResend - Whether the resend button should be enabled * @property attemptsRemaining - Number of OTP verification attempts left * @property otpCode - The OTP code entered so far (controlled-input value) * @property otpLength - Expected OTP length (owned by Core; the UI should not hardcode it) * @property otpValidationErrors - Client-side OTP errors (e.g. incomplete code). Surfaced on blur and submit. * @property isOtpValid - True iff `otpValidationErrors` is empty. Optimistic semantic: starts true. */ type EmailAwaitingOtpState = { status: 'awaitingOtp'; resendTimer: number; canResend: boolean; attemptsRemaining: number; otpCode: string; otpLength: number; otpValidationErrors?: OtpValidationErrors; isOtpValid: boolean; }; /** * OTP code is being verified against the backend * @property resendTimer - Seconds remaining on resend cooldown (unchanged while verifying) * @property canResend - Whether resend is allowed (cooldown finished) * @property otpCode - The code being verified (controlled-input value, kept visible while disabled) * @property otpLength - Expected OTP length (owned by Core) */ type EmailVerifyingOtpState = { status: 'verifyingOtp'; resendTimer: number; canResend: boolean; otpCode: string; otpLength: number; }; /** * OTP verification failed - user can retry with `submitOtp()` * @property error - Error message describing why verification failed * @property attemptsRemaining - Number of remaining attempts before lockout * @property resendTimer - Seconds remaining on resend cooldown (same as awaiting OTP) * @property canResend - Whether resend is allowed (cooldown finished) * @property otpCode - The OTP code entered so far (controlled-input value) * @property otpLength - Expected OTP length (owned by Core) * @property otpValidationErrors - Client-side OTP errors (e.g. incomplete code). Server `otpError` takes precedence in the UI. * @property isOtpValid - True iff `otpValidationErrors` is empty. Optimistic semantic: starts true. */ type EmailOtpErrorState = { status: 'otpError'; otpError: string; attemptsRemaining: number; resendTimer: number; canResend: boolean; otpCode: string; otpLength: number; otpValidationErrors?: OtpValidationErrors; isOtpValid: boolean; }; /** Email verification completed successfully */ type EmailFinishedState = { status: 'finished'; }; /** * Fatal error occurred - call `reset()` to start over * @property error - Error message describing what went wrong */ type EmailErrorState = { status: 'error'; error: string; }; /** * Union of all possible email manager states. * Use discriminated union pattern to narrow the type: * * @example * ```typescript * const state = emailManager.getState(); * if (state.status === 'inputting') { * // TypeScript knows state has prefilledEmail, emailError, etc. * console.log(state.prefilledEmail); * } * ``` */ type EmailState = EmailIdleState | EmailLoadingPrefillState | EmailInputtingState | EmailSubmittingState | EmailResendingOtpState | EmailSendingInitialOtpState | EmailAwaitingOtpState | EmailVerifyingOtpState | EmailOtpErrorState | EmailFinishedState | EmailErrorState; /** * Creates an email verification manager for headless or UI-driven usage. * * The manager provides a state machine-based API for email address verification * with optional OTP (one-time password) verification. * * @param options - Configuration options * @param options.config - Email verification configuration * @param options.config.otpVerification - Whether to require OTP verification * @param options.config.otpExpirationInMinutes - How long the OTP is valid * @param options.config.prefill - Whether to fetch a pre-filled email address * @param options.config.maxOtpAttempts - Maximum OTP verification attempts (default: 3) * * @returns Email manager with state, API methods, and subscription * * @example Headless usage * ```typescript * const manager = createEmailManager({ * config: { otpVerification: true, otpExpirationInMinutes: 5, prefill: false }, * }); * * manager.subscribe((state) => console.log(state.status)); * manager.load(); * manager.setEmail('user@example.com', true); * manager.submit(); * // ... wait for 'awaitingOtp' state ... * manager.submitOtp('ABC123'); * manager.stop(); * ``` * * @example With React/Preact UI hook * ```tsx * const [state, manager] = useManager(() => createEmailManager({ config })); * * if (state.status === 'inputting') { * return manager.setEmail(e.target.value, true)} />; * } * ``` */ declare function createEmailManager(options: CreateEmailActorOptions): Manager & { /** * Initializes the email verification flow. * Transitions from 'idle' to 'loadingPrefill' or 'inputting'. * Must be called before any other method. */ load(): void; /** * Sets the email address for verification. * Should be called when state is 'inputting'. * * @param email - Email address (e.g., 'user@example.com') * @param isValid - Whether the email address passes validation * * @example * ```typescript * // Using regex for validation * const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/; * const email = 'user@example.com'; * emailManager.setEmail(email, emailRegex.test(email)); * ``` */ setEmail(email: string, isValid: boolean): void; /** * Validates the current email address (e.g., on blur). * Populates or clears `validationErrors.email` on the 'inputting' state. */ validateEmail(): void; /** * Submits the email address for verification. * Runs full validation first: if the email is empty or invalid, populates * `validationErrors` and stays on 'inputting'; otherwise transitions to * 'submitting', then to 'sendingInitialOtp' or 'finished' (if no OTP). */ submit(): void; /** * Sets the OTP code without submitting. * Use this for controlled input components. * * @param code - The OTP code entered by the user */ setOtpCode(code: string): void; /** * Validates the current OTP code (e.g. on blur), without submitting. * Populates or clears `otpValidationErrors.otp` on the 'awaitingOtp' / * 'otpError' states (incomplete code → `isOtpValid` becomes false). */ validateOtp(): void; /** * Sets and submits the OTP code in one call. * Should be called when state is 'awaitingOtp' or 'otpError'. * * @param code - The complete OTP code (typically 6 alphanumeric characters) * * @example * ```typescript * // Submit OTP when user completes entry * emailManager.submitOtp('HH36LP'); * ``` */ submitOtp(code: string): void; /** * Requests a new OTP code to be sent. * Only works when state is 'awaitingOtp' and `canResend` is true. * Resets the resend timer. */ resendOtp(): void; /** * Returns to the email input screen from OTP entry. * Allows the user to change their email address. * Transitions from 'awaitingOtp' or 'otpError' back to 'inputting'. */ back(): void; /** * Resets the manager to initial state. * Can be called from 'success' or 'error' states to start over. * Clears all stored data including email address and OTP. */ reset(): void; }; declare function createEmailManagerFromActor(actor: EmailActor): Manager & { /** * Initializes the email verification flow. * Transitions from 'idle' to 'loadingPrefill' or 'inputting'. * Must be called before any other method. */ load(): void; /** * Sets the email address for verification. * Should be called when state is 'inputting'. * * @param email - Email address (e.g., 'user@example.com') * @param isValid - Whether the email address passes validation * * @example * ```typescript * // Using regex for validation * const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/; * const email = 'user@example.com'; * emailManager.setEmail(email, emailRegex.test(email)); * ``` */ setEmail(email: string, isValid: boolean): void; /** * Validates the current email address (e.g., on blur). * Populates or clears `validationErrors.email` on the 'inputting' state. */ validateEmail(): void; /** * Submits the email address for verification. * Runs full validation first: if the email is empty or invalid, populates * `validationErrors` and stays on 'inputting'; otherwise transitions to * 'submitting', then to 'sendingInitialOtp' or 'finished' (if no OTP). */ submit(): void; /** * Sets the OTP code without submitting. * Use this for controlled input components. * * @param code - The OTP code entered by the user */ setOtpCode(code: string): void; /** * Validates the current OTP code (e.g. on blur), without submitting. * Populates or clears `otpValidationErrors.otp` on the 'awaitingOtp' / * 'otpError' states (incomplete code → `isOtpValid` becomes false). */ validateOtp(): void; /** * Sets and submits the OTP code in one call. * Should be called when state is 'awaitingOtp' or 'otpError'. * * @param code - The complete OTP code (typically 6 alphanumeric characters) * * @example * ```typescript * // Submit OTP when user completes entry * emailManager.submitOtp('HH36LP'); * ``` */ submitOtp(code: string): void; /** * Requests a new OTP code to be sent. * Only works when state is 'awaitingOtp' and `canResend` is true. * Resets the resend timer. */ resendOtp(): void; /** * Returns to the email input screen from OTP entry. * Allows the user to change their email address. * Transitions from 'awaitingOtp' or 'otpError' back to 'inputting'. */ back(): void; /** * Resets the manager to initial state. * Can be called from 'success' or 'error' states to start over. * Clears all stored data including email address and OTP. */ reset(): void; }; /** * Type representing an email manager instance. * Includes state access, API methods, and lifecycle management. * * @property getState - Returns the current EmailState * @property subscribe - Subscribes to state changes, returns unsubscribe function * @property stop - Stops the manager and cleans up resources * @property load - Initializes the verification flow * @property setEmail - Sets the email address * @property validateEmail - Validates the current email (e.g. on blur) * @property submit - Submits the email address * @property setOtpCode - Sets OTP code without submitting * @property validateOtp - Validates the current OTP (e.g. on blur) * @property submitOtp - Sets and submits OTP code * @property resendOtp - Requests new OTP code * @property back - Returns to email input from OTP screen * @property reset - Resets to initial state */ type EmailManager = ReturnType; //#endregion export { EmailActor as a, createEmailManagerFromActor as i, EmailState as n, emailMachine as o, createEmailManager as r, EmailConfig as s, EmailManager as t };