UNPKG

@diagramers/api

Version:

Diagramers API - A comprehensive Node.js API template with TypeScript, Firebase Functions, and Socket.io

102 lines (86 loc) 2 kB
import { User } from '../../../shared/types/common'; import { AuthProvider } from '../../../shared/constants/enums'; export interface AuthProviderConfig { enabled: boolean; [key: string]: any; } export interface AuthCredentials { email?: string; password?: string; token?: string; code?: string; phone?: string; [key: string]: any; } export interface AuthResult { success: boolean; user?: any; token?: string; refreshToken?: string; expiresIn?: number; error?: string; provider: string; } export interface AuthProviderHealth { status: 'healthy' | 'unhealthy' | 'degraded'; message?: string; details?: Record<string, any>; timestamp: Date; } export interface AuthProviderMetrics { isActive: boolean; totalAuthentications: number; successfulAuthentications: number; failedAuthentications: number; averageResponseTime: number; lastAuthentication?: Date; } export abstract class BaseAuthProvider { protected name: string; protected config: any; protected isInitialized: boolean = false; constructor(name: string, config: any) { this.name = name; this.config = config; } /** * Initialize the auth provider */ abstract initialize(): Promise<void>; /** * Authenticate user credentials */ abstract authenticate(credentials: AuthCredentials): Promise<AuthResult>; /** * Validate a token */ abstract validateToken(token: string): Promise<any>; /** * Refresh a token */ abstract refreshToken(refreshToken: string): Promise<AuthResult>; /** * Cleanup resources */ abstract cleanup(): Promise<void>; /** * Get provider health status */ abstract getHealth(): Promise<AuthProviderHealth>; /** * Get provider metrics */ abstract getMetrics(): Promise<AuthProviderMetrics>; /** * Get provider name */ getName(): string { return this.name; } /** * Check if provider is initialized */ isReady(): boolean { return this.isInitialized; } }