UNPKG

sdk-simple-auth

Version:

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

85 lines 2.52 kB
import { AuthConfig, AuthTokens, HttpClient } from '../types'; import { StorageManager } from './StorageManager'; /** * Enhanced RefreshManager with automatic session renewal and retry logic */ export declare class RefreshManager { private config; private storageManager; private httpClient; private refreshTimer; private isRefreshing; private refreshPromise; private refreshAttempts; private lastRefreshTime; private onTokenRefresh?; private onRefreshError?; private onSessionRenewed?; constructor(config: Required<AuthConfig>, storageManager: StorageManager, httpClient: HttpClient, callbacks?: { onTokenRefresh?: (tokens: AuthTokens) => void; onRefreshError?: (error: Error) => void; onSessionRenewed?: (tokens: AuthTokens) => void; }); /** * Schedule automatic token refresh based on expiration time */ scheduleTokenRefresh(tokens: AuthTokens): void; /** * Perform token refresh with enhanced session management */ refreshTokens(): Promise<AuthTokens>; /** * Check if token should be refreshed based on expiration */ shouldRefreshToken(token: string): boolean; /** * Async version to check if token should be refreshed (for non-JWT tokens) */ shouldRefreshTokenAsync(token: string): Promise<boolean>; /** * Clear refresh timer */ clearRefreshTimer(): void; /** * Get refresh status information */ getRefreshStatus(): { isRefreshing: boolean; refreshAttempts: number; lastRefreshTime: number; nextRefreshScheduled: boolean; }; /** * Force refresh regardless of timing */ forceRefresh(): Promise<AuthTokens>; /** * Detect if error is an authentication error (401, 403, etc) */ private isAuthenticationError; /** * Private method to perform the actual refresh */ private performRefresh; /** * Process refresh response and extract tokens */ private processRefreshResponse; /** * Schedule refresh timer with error handling */ private scheduleRefreshTimer; /** * Check if token should be refreshed based on stored metadata */ private shouldRefreshBasedOnMetadata; /** * Reset refresh state (useful for logout) */ reset(): void; /** * Check if refresh is currently possible */ canRefresh(): Promise<boolean>; } //# sourceMappingURL=RefreshManager.d.ts.map