UNPKG

node-red-contrib-tplink-tapo-connect-api

Version:

This unofficial node-RED node allows connection to TP-Link Tapo devices. This project has been enhanced with AI support to enable new features. Starting with v0.50, we have added support for the KLAP protocol. To prioritize the operation of this node, we

84 lines (83 loc) 2.1 kB
export interface SessionData { sessionId?: string; token?: string; cookies?: string[]; expiresAt?: number; deviceId?: string; terminalUuid?: string; } export interface SessionOptions { sessionTimeout?: number; refreshThreshold?: number; maxRefreshAttempts?: number; } export declare enum SessionState { DISCONNECTED = "disconnected", CONNECTING = "connecting", CONNECTED = "connected", EXPIRED = "expired", ERROR = "error" } /** * Manages device sessions and session lifecycle * Single responsibility: Session state and lifecycle management */ export declare class SessionManager { private sessionData; private sessionState; private refreshPromise; private readonly options; constructor(options?: SessionOptions); /** * Initialize a new session */ initializeSession(sessionData: SessionData): Promise<void>; /** * Get current session data */ getSessionData(): Readonly<SessionData>; /** * Get current session state */ getSessionState(): SessionState; /** * Check if session is valid and not expired */ isSessionValid(): boolean; /** * Check if session needs refresh (close to expiry) */ needsRefresh(): boolean; /** * Refresh session if needed */ refreshSessionIfNeeded(refreshFunction: () => Promise<SessionData>): Promise<void>; /** * Update session data */ updateSession(sessionData: Partial<SessionData>): void; /** * Invalidate current session */ invalidateSession(): void; /** * Mark session as expired */ markExpired(): void; /** * Check if specific session error indicates session expiry */ isSessionError(error: Error): boolean; /** * Handle session error and update state accordingly */ handleSessionError(error: Error): void; /** * Get session headers for requests */ getSessionHeaders(): Record<string, string>; /** * Perform session refresh */ private performRefresh; }