UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

155 lines 8.7 kB
import { FrankAuthError, JSONObject } from '../types'; export declare class FrankAuthBaseError extends Error { readonly code: string; readonly statusCode?: number; readonly details?: JSONObject; readonly timestamp: string; readonly context?: string; constructor(message: string, code?: string, statusCode?: number, details?: JSONObject, context?: string); toJSON(): FrankAuthError; } export declare class AuthenticationError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class AuthorizationError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class ValidationError extends FrankAuthBaseError { readonly fieldErrors: Record<string, string[]>; constructor(message?: string, fieldErrors?: Record<string, string[]>, details?: JSONObject); getFieldError(field: string): string | undefined; hasFieldError(field: string): boolean; getAllFieldErrors(): string[]; } export declare class NetworkError extends FrankAuthBaseError { readonly isRetryable: boolean; constructor(message?: string, isRetryable?: boolean, details?: JSONObject); } export declare class TimeoutError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class RateLimitError extends FrankAuthBaseError { readonly retryAfter?: number; constructor(message?: string, retryAfter?: number, details?: JSONObject); } export declare class ServerError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class ConfigurationError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class SessionError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class MFAError extends FrankAuthBaseError { readonly challenge?: any; constructor(message?: string, challenge?: any, details?: JSONObject); } export declare class PasskeyError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class OAuthError extends FrankAuthBaseError { readonly provider?: string; readonly errorCode?: string; constructor(message?: string, provider?: string, errorCode?: string, details?: JSONObject); } export declare class OrganizationError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare class InvitationError extends FrankAuthBaseError { constructor(message?: string, details?: JSONObject); } export declare const createError: (type: string, message: string, details?: JSONObject) => FrankAuthBaseError; export declare const createAuthenticationError: (message?: string, details?: JSONObject) => AuthenticationError; export declare const createAuthorizationError: (message?: string, details?: JSONObject) => AuthorizationError; export declare const createValidationError: (message?: string, fieldErrors?: Record<string, string[]>, details?: JSONObject) => ValidationError; export declare const createNetworkError: (message?: string, isRetryable?: boolean, details?: JSONObject) => NetworkError; export declare const createSessionError: (message?: string, details?: JSONObject) => SessionError; export declare const createMFAError: (message?: string, challenge?: any, details?: JSONObject) => MFAError; export declare const isFrankAuthError: (error: any) => error is FrankAuthBaseError; export declare const isAuthenticationError: (error: any) => error is AuthenticationError; export declare const isAuthorizationError: (error: any) => error is AuthorizationError; export declare const isValidationError: (error: any) => error is ValidationError; export declare const isNetworkError: (error: any) => error is NetworkError; export declare const isTimeoutError: (error: any) => error is TimeoutError; export declare const isRateLimitError: (error: any) => error is RateLimitError; export declare const isServerError: (error: any) => error is ServerError; export declare const isSessionError: (error: any) => error is SessionError; export declare const isMFAError: (error: any) => error is MFAError; export declare const isPasskeyError: (error: any) => error is PasskeyError; export declare const isOAuthError: (error: any) => error is OAuthError; export declare const isRetryableError: (error: any) => boolean; export declare const handleError: (error: any, context?: string, defaultMessage?: string) => FrankAuthBaseError; export declare const parseAPIError: (response: any) => FrankAuthBaseError; export declare const formatErrorMessage: (error: any) => string; export declare const getErrorCode: (error: any) => string; export declare const getErrorDetails: (error: any) => JSONObject | undefined; export interface ErrorLogger { error(message: string, error?: any, context?: JSONObject): void; warn(message: string, context?: JSONObject): void; info(message: string, context?: JSONObject): void; debug(message: string, context?: JSONObject): void; } export declare const createConsoleLogger: () => ErrorLogger; export declare const logError: (error: any, logger?: ErrorLogger, context?: JSONObject) => void; export interface RetryOptions { maxAttempts: number; delay: number; backoff: 'fixed' | 'exponential' | 'linear'; shouldRetry?: (error: any, attempt: number) => boolean; onRetry?: (error: any, attempt: number) => void; } export declare const withRetry: <T>(operation: () => Promise<T>, options?: Partial<RetryOptions>) => Promise<T>; export interface ErrorBoundaryState { hasError: boolean; error?: FrankAuthBaseError; } export declare const createErrorBoundaryState: () => ErrorBoundaryState; export declare const handleErrorBoundaryError: (error: any, errorInfo?: any) => ErrorBoundaryState; export declare const ErrorUtils: { FrankAuthBaseError: typeof FrankAuthBaseError; AuthenticationError: typeof AuthenticationError; AuthorizationError: typeof AuthorizationError; ValidationError: typeof ValidationError; NetworkError: typeof NetworkError; TimeoutError: typeof TimeoutError; RateLimitError: typeof RateLimitError; ServerError: typeof ServerError; ConfigurationError: typeof ConfigurationError; SessionError: typeof SessionError; MFAError: typeof MFAError; PasskeyError: typeof PasskeyError; OAuthError: typeof OAuthError; OrganizationError: typeof OrganizationError; InvitationError: typeof InvitationError; createError: (type: string, message: string, details?: JSONObject) => FrankAuthBaseError; createAuthenticationError: (message?: string, details?: JSONObject) => AuthenticationError; createAuthorizationError: (message?: string, details?: JSONObject) => AuthorizationError; createValidationError: (message?: string, fieldErrors?: Record<string, string[]>, details?: JSONObject) => ValidationError; createNetworkError: (message?: string, isRetryable?: boolean, details?: JSONObject) => NetworkError; createSessionError: (message?: string, details?: JSONObject) => SessionError; createMFAError: (message?: string, challenge?: any, details?: JSONObject) => MFAError; isFrankAuthError: (error: any) => error is FrankAuthBaseError; isAuthenticationError: (error: any) => error is AuthenticationError; isAuthorizationError: (error: any) => error is AuthorizationError; isValidationError: (error: any) => error is ValidationError; isNetworkError: (error: any) => error is NetworkError; isTimeoutError: (error: any) => error is TimeoutError; isRateLimitError: (error: any) => error is RateLimitError; isServerError: (error: any) => error is ServerError; isSessionError: (error: any) => error is SessionError; isMFAError: (error: any) => error is MFAError; isPasskeyError: (error: any) => error is PasskeyError; isOAuthError: (error: any) => error is OAuthError; isRetryableError: (error: any) => boolean; handleError: (error: any, context?: string, defaultMessage?: string) => FrankAuthBaseError; parseAPIError: (response: any) => FrankAuthBaseError; formatErrorMessage: (error: any) => string; getErrorCode: (error: any) => string; getErrorDetails: (error: any) => JSONObject | undefined; logError: (error: any, logger?: ErrorLogger, context?: JSONObject) => void; withRetry: <T>(operation: () => Promise<T>, options?: Partial<RetryOptions>) => Promise<T>; createErrorBoundaryState: () => ErrorBoundaryState; handleErrorBoundaryError: (error: any, errorInfo?: any) => ErrorBoundaryState; }; //# sourceMappingURL=error.d.ts.map