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/phone/types.d.ts /** * Configuration options for phone verification. * * @example Standard OTP verification * ```typescript * const config: PhoneConfig = { * otpVerification: true, * otpExpirationInMinutes: 5, * prefill: false, * }; * ``` * * @example With all options * ```typescript * const config: PhoneConfig = { * otpVerification: true, * otpExpirationInMinutes: 10, * prefill: true, * isInstantVerify: false, * optinEnabled: true, * maxOtpAttempts: 3, * }; * ``` */ type PhoneConfig = { /** * Whether to require OTP (SMS code) verification. * If false, phone 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 phone number. * Useful for returning users. */ prefill: boolean; /** * Use carrier-based instant verification instead of OTP. * Not available in all regions. * @default false */ isInstantVerify?: boolean; /** * Show a marketing opt-in checkbox in the UI. * User's preference is sent with the phone submission. * @default false */ optinEnabled?: boolean; /** * Maximum number of OTP verification attempts before lockout. * After exhausting attempts, user sees an error state. * @default 3 */ maxOtpAttempts?: number; }; /** Client-side validation errors for the phone input screen, keyed by field. */ type PhoneValidationErrors = { phone?: string; }; //#endregion //#region src/modules/phone/phoneStateMachine.d.ts declare const phoneMachine: any; type PhoneMachine = typeof phoneMachine; //#endregion //#region src/modules/phone/phoneActor.d.ts type CreatePhoneActorOptions = { config: PhoneConfig; }; type PhoneActor = ActorRefFrom; //#endregion //#region src/modules/phone/phoneManager.d.ts /** Phone manager is in initial state, waiting for `load()` to be called */ type PhoneIdleState = { status: 'idle'; }; /** Loading prefilled phone number from backend (if prefill is enabled) */ type PhoneLoadingPrefillState = { status: 'loadingPrefill'; }; /** * Fetching start info (`ipIsoCode`, `phonePrefix`) before the phone field is interactive. */ type PhoneLoadingStartInfoState = { status: 'loadingStartInfo'; prefilledPhone?: string; otpVerification?: boolean; optinEnabled?: boolean; }; /** * Ready for phone input - use `setPhoneNumber()` and `submit()` * @property countryCode - ISO country code (e.g., 'US', 'MX') * @property phonePrefix - International dialing prefix (e.g., '+1', '+52') * @property prefilledPhone - Pre-populated phone number (if prefill enabled) * @property phoneError - Submission error message if the backend rejected the phone number * @property otpVerification - Whether OTP SMS verification is enabled (from module config). When omitted, treat as `false`. * @property optinEnabled - Whether marketing opt-in checkbox is shown (from module config). When omitted, treat as `false`. */ type PhoneInputtingState = { status: 'inputting'; countryCode: string; phonePrefix: string; prefilledPhone?: string; phoneError?: string; /** Client-side validation errors (e.g. invalid/empty phone). Surfaced on blur and submit. */ validationErrors?: PhoneValidationErrors; /** True iff `validationErrors` is empty. Optimistic semantic: starts true on initial render. */ isValid: boolean; otpVerification?: boolean; optinEnabled?: boolean; }; /** Phone number is being submitted to the backend */ type PhoneSubmittingState = { status: 'submitting'; }; /** OTP is being sent to the phone number on resend */ type PhoneResendingOtpState = { 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 initialy sent to the phone number */ type PhoneSendingInitialOtp = { 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 PhoneAwaitingOtpState = { 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 PhoneVerifyingOtpState = { 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 PhoneOtpErrorState = { status: 'otpError'; otpError: string; attemptsRemaining: number; resendTimer: number; canResend: boolean; otpCode: string; otpLength: number; otpValidationErrors?: OtpValidationErrors; isOtpValid: boolean; }; /** Phone verification completed successfully */ type PhoneFinishedState = { status: 'finished'; }; /** * Fatal error occurred - call `reset()` to start over * @property error - Error message describing what went wrong */ type PhoneErrorState = { status: 'error'; error: string; }; /** * Union of all possible phone manager states. * Use discriminated union pattern to narrow the type: * * @example * ```typescript * const state = phoneManager.getState(); * if (state.status === 'inputting') { * // TypeScript knows state has countryCode, phonePrefix, etc. * console.log(state.countryCode); * } * ``` */ type PhoneState = PhoneIdleState | PhoneLoadingPrefillState | PhoneLoadingStartInfoState | PhoneInputtingState | PhoneSubmittingState | PhoneResendingOtpState | PhoneSendingInitialOtp | PhoneAwaitingOtpState | PhoneVerifyingOtpState | PhoneOtpErrorState | PhoneFinishedState | PhoneErrorState; /** * Creates a phone verification manager for headless or UI-driven usage. * * The manager provides a state machine-based API for phone number verification * with optional OTP (one-time password) verification. * * @param options - Configuration options * @param options.config - Phone 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 phone number * @param options.config.isInstantVerify - Use instant verification API * @param options.config.optinEnabled - Show marketing opt-in checkbox * @param options.config.maxOtpAttempts - Maximum OTP verification attempts (default: 3) * * @returns Phone manager with state, API methods, and subscription * * @example Headless usage * ```typescript * const manager = createPhoneManager({ * config: { otpVerification: true, otpExpirationInMinutes: 5, prefill: false }, * }); * * manager.subscribe((state) => console.log(state.status)); * manager.load(); * manager.setPhoneNumber('+14155551234', true); * manager.submit(); * // ... wait for 'awaitingOtp' state ... * manager.submitOtp('ABC123'); * manager.stop(); * ``` * * @example With React/Preact UI hook * ```tsx * const [state, manager] = useManager(() => createPhoneManager({ config })); * * if (state.status === 'inputting') { * return manager.setPhoneNumber(e.target.value, true)} />; * } * ``` */ declare function createPhoneManager(options: CreatePhoneActorOptions): Manager & { /** * Initializes the phone verification flow. * Transitions from 'idle' to 'loadingPrefill' or 'inputting'. * Must be called before any other method. */ load(): void; /** * Sets the phone number for verification. * Should be called when state is 'inputting'. * * @param phone - Full phone number with country code (e.g., '+14155551234') * @param isValid - Whether the phone number passes validation * * @example * ```typescript * // Using libphonenumber-js for validation * import { isValidPhoneNumber } from 'libphonenumber-js'; * const phone = '+14155551234'; * phoneManager.setPhoneNumber(phone, isValidPhoneNumber(phone)); * ``` */ setPhoneNumber(phone: string, isValid: boolean): void; /** * Validates the current phone number (e.g., on blur). * Populates or clears `validationErrors.phone` on the 'inputting' state. */ validatePhone(): void; /** * Sets the marketing opt-in preference. * Only relevant if `config.optinEnabled` is true. * * @param granted - Whether the user consented to receive marketing messages */ setOptInGranted(granted: boolean): void; /** * Submits the phone number for verification. * Runs full validation first: if the phone 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 * phoneManager.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 phone input screen from OTP entry. * Allows the user to change their phone number. * 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 phone number and OTP. */ reset(): void; }; declare function createPhoneManagerFromActor(actor: PhoneActor): Manager & { /** * Initializes the phone verification flow. * Transitions from 'idle' to 'loadingPrefill' or 'inputting'. * Must be called before any other method. */ load(): void; /** * Sets the phone number for verification. * Should be called when state is 'inputting'. * * @param phone - Full phone number with country code (e.g., '+14155551234') * @param isValid - Whether the phone number passes validation * * @example * ```typescript * // Using libphonenumber-js for validation * import { isValidPhoneNumber } from 'libphonenumber-js'; * const phone = '+14155551234'; * phoneManager.setPhoneNumber(phone, isValidPhoneNumber(phone)); * ``` */ setPhoneNumber(phone: string, isValid: boolean): void; /** * Validates the current phone number (e.g., on blur). * Populates or clears `validationErrors.phone` on the 'inputting' state. */ validatePhone(): void; /** * Sets the marketing opt-in preference. * Only relevant if `config.optinEnabled` is true. * * @param granted - Whether the user consented to receive marketing messages */ setOptInGranted(granted: boolean): void; /** * Submits the phone number for verification. * Runs full validation first: if the phone 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 * phoneManager.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 phone input screen from OTP entry. * Allows the user to change their phone number. * 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 phone number and OTP. */ reset(): void; }; /** * Type representing a phone manager instance. * Includes state access, API methods, and lifecycle management. * * @property getState - Returns the current PhoneState * @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 setPhoneNumber - Sets the phone number * @property setOptInGranted - Sets marketing opt-in preference * @property submit - Submits the phone number * @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 phone input from OTP screen * @property reset - Resets to initial state */ type PhoneManager = ReturnType; //#endregion export { PhoneActor as a, createPhoneManagerFromActor as i, PhoneState as n, phoneMachine as o, createPhoneManager as r, PhoneConfig as s, PhoneManager as t };