import { AuthAdapter, AuthConfig, AuthResult, AuthType } from '../types.js';
/**
* Clase base abstracta para adaptadores de autenticación
* Proporciona implementación por defecto de métodos comunes
*/
export abstract class BaseAuthAdapter<T extends AuthConfig = AuthConfig> implements AuthAdapter<T> {
abstract readonly type: AuthType;
protected config!: T;
protected baseUrl: string = '';
async initialize(config: T, baseUrl: string): Promise<void> {
this.config = config;
this.baseUrl = baseUrl;
}
abstract applyAuth(): Promise<AuthResult>;
needsRefresh(): boolean {
return false;
}
async refresh(): Promise<void> {
// Por defecto no hace nada
}
cleanup(): void {
// Por defecto no hace nada
}
/**
* Helper para resolver URLs (relativas o absolutas)
*/
protected resolveUrl(url: string): string {
if (url.startsWith('http://') || url.startsWith('https://')) {
return url;
}
return `${this.baseUrl}${url.startsWith('/') ? '' : '/'}${url}`;
}
}