@teamhanko/hanko-frontend-sdk
Version:
A package for simplifying UI integration with the Hanko API. It is meant for use in browsers only.
71 lines (70 loc) • 2.96 kB
TypeScript
import { SessionCheckResponse } from "../Dto";
export type SessionCheckResult = (Omit<SessionCheckResponse, "expiration_time"> & {
expiration: number;
}) | null;
/**
* Callback type for performing a session check.
* @ignore
*/
type SessionCheckCallback = () => Promise<SessionCheckResult>;
/**
* Callback type for handling session timeout events.
* @ignore
*/
type SessionExpiredCallback = () => void;
/**
* Manages scheduling for periodic and timeout-based session checks.
*
* @category SDK
* @subcategory Internal
* @param {number} checkInterval - The interval in milliseconds between periodic session checks.
* @param {SessionCheckCallback} checkSession - The callback function to perform a session check.
* @param {SessionExpiredCallback} onSessionExpired - The callback function to handle session timeout events.
*/
export declare class Scheduler {
private intervalID;
private timeoutID;
private readonly checkInterval;
private readonly checkSession;
private readonly onSessionExpired;
constructor(checkInterval: number, checkSession: SessionCheckCallback, onSessionExpired: SessionExpiredCallback);
/**
* Handles the session expiration when it is about to expire soon.
* Stops any ongoing checks and schedules a timeout for the expiration.
*
* @param {number} timeToExpiration - The time in milliseconds until the session expires.
*/
scheduleSessionExpiry(timeToExpiration: number): void;
/**
* Starts the session check process.
* Determines when the next check should run based on the last known check time and session expiration.
* If the session is expiring soon, schedules an expiration event instead of starting periodic checks.
*
* @param {number} lastCheck - The timestamp (in milliseconds) of the last session check.
* @param {number} expiration - The timestamp (in milliseconds) of when the session expires.
*/
start(lastCheck?: number, expiration?: number): void;
/**
* Stops the session check process and clears all timers.
*/
stop(): void;
/**
* Checks if the scheduler is currently running.
* @returns {boolean} True if the scheduler is running; otherwise, false.
*/
isRunning(): boolean;
/**
* Checks if the session is about to expire.
* @param {number} expiration - Timestamp when the session will expire.
* @returns {boolean} True if the session is about to expire; otherwise, false.
*/
sessionExpiresSoon(expiration: number): boolean;
/**
* Calculates the time until the next session check should occur.
*
* @param {number} lastCheck - The timestamp (in milliseconds) of the last session check.
* @returns {number} The time in milliseconds until the next check should be performed.
*/
calcTimeToNextCheck(lastCheck: number): number;
}
export {};