UNPKG

sdk-simple-auth

Version:

Universal JavaScript/TypeScript authentication SDK with multi-backend support, automatic token refresh, and React integration

225 lines 6.55 kB
export * from './index'; export interface EnhancedAuthConfig { authServiceUrl: string; endpoints?: { login?: string; register?: string; refresh?: string; logout?: string; profile?: string; }; storage?: { type?: 'localStorage' | 'indexedDB'; dbName?: string; dbVersion?: number; storeName?: string; tokenKey?: string; refreshTokenKey?: string; userKey?: string; }; tokenRefresh?: { enabled?: boolean; bufferTime?: number; maxRetries?: number; minimumTokenLifetime?: number; gracePeriod?: number; }; httpClient?: HttpClient; backend?: { type?: 'node-express' | 'laravel-sanctum' | 'jwt-standard' | 'custom'; userSearchPaths?: string[]; fieldMappings?: BackendFieldMappings; preserveOriginalData?: boolean; }; } export interface BackendFieldMappings { userId?: string[]; email?: string[]; name?: string[]; firstName?: string[]; lastName?: string[]; role?: string[]; permissions?: string[]; token?: string[]; refreshToken?: string[]; expires?: string[]; tokenType?: string[]; [key: string]: string[] | undefined; } export interface BackendPresets { 'node-express': BackendConfig; 'laravel-sanctum': BackendConfig; 'jwt-standard': BackendConfig; 'custom': BackendConfig; } export interface BackendConfig { userSearchPaths: string[]; fieldMappings: BackendFieldMappings; preserveOriginalData: boolean; tokenFormat: 'jwt' | 'opaque' | 'mixed'; } export interface HttpClient { post(url: string, data?: any, config?: any): Promise<any>; get(url: string, config?: any): Promise<any>; put(url: string, data?: any, config?: any): Promise<any>; delete(url: string, config?: any): Promise<any>; } export interface EnhancedAuthTokens { accessToken: string; refreshToken?: string; expiresIn?: number; expiresAt?: string | number; tokenType?: string; scope?: string; tokenId?: string; issuedAt?: number; _originalTokenResponse?: any; _backendType?: string; _tokenFormat?: 'jwt' | 'opaque' | 'sanctum'; } export interface EnhancedAuthUser { id: string; email?: string; name?: string; firstName?: string; lastName?: string; username?: string; role?: string | string[]; roles?: string[]; permissions?: string[]; isActive?: boolean; profile?: any; email_verified_at?: string; created_at?: string; updated_at?: string; sucursales?: Array<{ id: number; sucursal: string; sigla: string; rol: string; }>; lastLogin?: string | Date; createdAt?: string | Date; updatedAt?: string | Date; sub?: string; aud?: string | string[]; iss?: string; exp?: number; iat?: number; _originalUserResponse?: any; _backendType?: string; _extractionMethod?: 'direct' | 'nested' | 'jwt-parsed' | 'scattered'; [key: string]: any; } export interface ExtendedSessionInfo { isValid: boolean; user: EnhancedAuthUser | null; tokens: EnhancedAuthTokens | null; tokenType: string | null; tokenFormat: 'jwt' | 'opaque' | 'sanctum' | null; expiresIn: number | null; refreshAvailable: boolean; canRefresh: boolean; sessionId: string | null; backendType: string | null; storedAt: number | null; lastRefreshed: number | null; originalResponse: any; } export interface EnhancedLoginCredentials { email?: string; password?: string; usuario?: string; clave?: string; code?: string; username?: string; phone?: string; otp?: string; twoFactorCode?: string; remember?: boolean; grant_type?: string; device_name?: string; [key: string]: any; } export interface EnhancedRegisterData { email: string; password: string; name?: string; firstName?: string; lastName?: string; username?: string; phone?: string; usuario?: string; clave?: string; code?: string; confirmPassword?: string; acceptTerms?: boolean; newsletter?: boolean; [key: string]: any; } export interface EnhancedAuthState { isAuthenticated: boolean; user: EnhancedAuthUser | null; tokens: EnhancedAuthTokens | null; loading: boolean; error: string | null; isRefreshing?: boolean; lastActivity?: number; sessionExpiry?: number; backendType?: string; capabilities?: { canRefresh: boolean; hasProfile: boolean; supportsOTP: boolean; supportsBiometric: boolean; }; } export interface EnhancedAuthCallbacks { onAuthStateChanged?: (state: EnhancedAuthState) => void; onTokenRefresh?: (tokens: EnhancedAuthTokens) => void; onLogin?: (user: EnhancedAuthUser, tokens: EnhancedAuthTokens) => void; onLogout?: () => void; onError?: (error: string) => void; onTokenExpired?: () => void; onSessionRestored?: (user: EnhancedAuthUser) => void; onRefreshFailed?: (error: string) => void; onUserUpdated?: (user: EnhancedAuthUser) => void; onBackendDetected?: (backendType: string) => void; } export declare const BACKEND_PRESETS: BackendPresets; export interface ResponseAnalysis { backendType: string; structure: { hasUser: boolean; hasTokens: boolean; userPath: string | null; tokenFields: string[]; userFields: string[]; }; extraction: { tokensExtracted: boolean; userExtracted: boolean; missingFields: string[]; }; recommendations: string[]; } export interface AuthSDKFactory { create(backendType: keyof BackendPresets, customConfig?: Partial<EnhancedAuthConfig>): any; createCustom(config: EnhancedAuthConfig): any; analyzeResponse(response: any): ResponseAnalysis; } export type AuthEventType = 'login' | 'logout' | 'token-refresh' | 'token-expired' | 'session-restored' | 'user-updated' | 'error'; export interface AuthEvent { type: AuthEventType; payload: any; timestamp: number; sessionId?: string; } export type AuthConfig = EnhancedAuthConfig; export type AuthTokens = EnhancedAuthTokens; export type AuthUser = EnhancedAuthUser; export type AuthState = EnhancedAuthState; export type AuthCallbacks = EnhancedAuthCallbacks; export type LoginCredentials = EnhancedLoginCredentials; export type RegisterData = EnhancedRegisterData; //# sourceMappingURL=enhanced_types.d.ts.map