/** * Hawcx SDK Types * * Defines client-side state types and re-exports protocol types. */ import type { AuthError } from "./errors"; export type { AuthError } from "./errors"; export { AuthErrorCategory } from "./errors"; export interface AuthNotice { code: string; message: string; } export { PROTOCOL_VERSION, type WireRequest, type WireResponse, type ResponseMeta, type Action, type StartAction, type SelectMethodAction, type SubmitCodeAction, type SubmitTotpAction, type SubmitPhoneAction, type SubmitSignatureAction, type OAuthCallbackAction, type ResendAction, type PollAction, type CancelAction, type AuthStep, type SelectMethodStep, type EnterCodeStep, type EnterTotpStep, type SetupTotpStep, type SetupSmsStep, type DeviceChallengeStep, type RedirectStep, type AwaitApprovalStep, type CompletedStep, type ErrorStep, type ErrorAction, type ErrorDetails, type Method, type DeviceInfo, type StepType, isSelectMethodStep, isEnterCodeStep, isEnterTotpStep, isSetupTotpStep, isSetupSmsStep, isDeviceChallengeStep, isRedirectStep, isAwaitApprovalStep, isCompletedStep, isErrorStep, } from "./protocol"; export type AuthMode = "signin" | "signup" | "account_manage"; export interface AuthResult { authCode: string; expiresAt: string; /** PKCE code verifier for OAuth 2.1 token exchange (optional) */ codeVerifier?: string; } export interface AuthStateIdle { status: "idle"; } export interface AuthStateLoading { status: "loading"; session?: string; notice?: AuthNotice; } export interface AuthStateStep { status: "step"; session: string; /** The server's auth step - what the user needs to do */ step: import("./protocol").AuthStep; notice?: AuthNotice; } export interface AuthStateCompleted { status: "completed"; session: string; authCode: string; expiresAt: string; } export interface AuthStateError { status: "error"; session?: string; error: AuthError; /** Previous step preserved for retryable errors (e.g. invalid TOTP/backup code) */ previousStep?: import("./protocol").AuthStep; } export type AuthState = AuthStateIdle | AuthStateLoading | AuthStateStep | AuthStateCompleted | AuthStateError; /** Check if state is idle */ export declare function isIdle(state: AuthState): state is AuthStateIdle; /** Check if state is loading */ export declare function isLoading(state: AuthState): state is AuthStateLoading; /** Check if state has an active step (user action needed) */ export declare function isAuthStep(state: AuthState): state is AuthStateStep; /** Check if state is completed (auth successful) */ export declare function isCompleted(state: AuthState): state is AuthStateCompleted; /** Check if state is error */ export declare function isError(state: AuthState): state is AuthStateError; /** Get step type from state, or null if not in step state */ export declare function getStepType(state: AuthState): import("./protocol").StepType | null; /** Get methods from state (for method selection), or empty array */ export declare function getMethods(state: AuthState): import("./protocol").Method[]; /** Get error from state, or null if not in error state */ export declare function getAuthError(state: AuthState): AuthError | null; export interface StorageAdapter { getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; } export interface Logger { debug?: (message: string, data?: unknown) => void; info?: (message: string, data?: unknown) => void; warn?: (message: string, data?: unknown) => void; error?: (message: string, data?: unknown) => void; } export declare const noopLogger: Logger; export declare const consoleLogger: Logger; export interface AuthConfig { /** Your Hawcx configuration ID (API key) */ configId: string; /** API base URL (default: https://api.hawcx.com/v1) */ apiBase?: string; /** Logger instance for debugging */ logger?: Logger; /** Custom fetch implementation (for testing) */ fetch?: typeof fetch; /** Request timeout in milliseconds (default: 10000) */ timeout?: number; } export interface HawcxAuth { /** * Send an action to the server. * This is the primary method - all auth operations go through here. */ send(action: import("./protocol").Action): Promise; /** * Convenience: Start an authentication flow. */ start(identifier: string, flowType?: AuthMode, device?: import("./protocol").DeviceInfo): Promise; /** * Convenience: Select an authentication method. */ selectMethod(methodId: string): Promise; /** * Convenience: Submit an OTP code. */ submitCode(code: string): Promise; /** * Convenience: Submit a TOTP code. */ submitTotp(code: string): Promise; /** * Convenience: Submit a phone number for SMS OTP enrollment. */ submitPhone(phone: string): Promise; /** * Convenience: Request code resend. */ resend(): Promise; /** * Convenience: Cancel the current flow. */ cancel(): Promise; /** * Get current auth state. */ getState(): AuthState; /** * Get auth completion result (null if not authenticated). */ getCompletion(): AuthResult | null; /** * Get current session ID (for multi-step flows). */ getSessionId(): string | undefined; /** * Reset to idle state. */ reset(): void; /** * Sign out and clear session. */ signOut(): void; /** * Subscribe to state changes. */ onStateChange(listener: (state: AuthState) => void): () => void; /** * Subscribe to auth completion. */ onCompletion(listener: (result: AuthResult | null) => void): () => void; /** * Get configuration ID. */ getConfigId(): string; /** * Check if device has stored credentials for identifier. */ hasDeviceCredentials(identifier: string): Promise; }