import { AuthConfig, AuthTokens, HttpClient } from '../types'; import { Logger } from './Logger'; import { StorageManager } from './StorageManager'; /** Options for a single refresh call. */ export interface RefreshOptions { /** Always ask the server, even if another instance already renewed the tokens. */ force?: boolean; /** * Access token this instance knew when it decided to refresh. If storage * holds a different, fresh one, another tab or window already renewed it and * it is adopted instead of calling the server again. Defaults to the * instance's current token. */ knownAccessToken?: string | null; /** Schedule automatic retries after a network or server error (default: true). */ retryOnFailure?: boolean; } /** * True when the server rejected the refresh token, so the session is over. * False for network or server failures that may succeed on a later attempt: * those must not end the session (e.g. Wi-Fi still reconnecting after the * machine wakes up). */ export declare function isRefreshRejection(error: unknown): boolean; /** * 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?; private onTokensAdopted?; private getCurrentTokens?; private logger; constructor(config: Required, storageManager: StorageManager, httpClient: HttpClient, callbacks?: { onTokenRefresh?: (tokens: AuthTokens) => void; onRefreshError?: (error: Error) => void; onSessionRenewed?: (tokens: AuthTokens) => void; /** Tokens another tab or window renewed, taken from storage without a request. */ onTokensAdopted?: (tokens: AuthTokens) => void; /** Tokens this instance currently holds in memory. */ getCurrentTokens?: () => AuthTokens | null; }, logger?: Logger); /** * Schedule automatic token refresh based on expiration time */ scheduleTokenRefresh(tokens: AuthTokens): void; /** * Perform token refresh with enhanced session management */ refreshTokens(options?: RefreshOptions): Promise; /** * 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; /** * 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; /** * Runs `refresh` holding a Web Lock shared by every tab and window of the * origin, so only one of them talks to the refresh endpoint at a time. * Without the lock, instances holding the same tokens schedule their refresh * for the same moment and send the same refresh token: with rotation the * server accepts one and answers 401 to the rest, which used to end the * session everywhere. * * Where the Web Locks API is missing, runs unlocked (previous behaviour); * `performRefresh` still recovers from a 401 caused by another tab. */ private withRefreshLock; /** True when a refresh token is stored, regardless of a refresh in progress. */ hasRefreshToken(): Promise; /** Not due for a refresh: more than `bufferTime` left, or no expiry info. */ private isFresh; /** Takes tokens another instance stored, without calling the server. */ private adoptStoredTokens; /** * 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; } //# sourceMappingURL=RefreshManager.d.ts.map