UNPKG

@datalayer/core

Version:

[![Datalayer](https://assets.datalayer.tech/datalayer-25.svg)](https://datalayer.io)

155 lines (154 loc) 4.17 kB
import type { TokenStorage } from './types'; import { UserDTO } from '../../models/UserDTO'; /** * Browser localStorage-based token storage */ export declare class BrowserStorage implements TokenStorage { /** * Get token from browser localStorage */ get(key: string): string | null; /** * Set token in browser localStorage */ set(key: string, value: string): void; /** * Delete token from browser localStorage */ delete(key: string): void; /** * Check if browser localStorage is available */ isAvailable(): boolean; /** * Get stored authentication token */ getToken(): string | null; /** * Store authentication token */ setToken(token: string): void; /** * Delete authentication token */ deleteToken(): void; /** * Get stored user data */ getUser(): UserDTO | null; /** * Store user data */ setUser(user: UserDTO): void; /** * Delete user data */ deleteUser(): void; /** * Clear all authentication data */ clear(): void; } /** * Node.js storage with keyring support using keytar */ export declare class NodeStorage implements TokenStorage { private memoryStorage; private keytar; private serviceUrl; constructor(serviceUrl?: string); /** * Get token from keyring, environment variable, or memory * Supports both sync (getPasswordSync) and async (getPassword) keytar APIs */ get(key: string): string | null; /** * Set token in keyring or memory storage (sync version) */ set(key: string, value: string): void; /** * Async version of set - supports VS Code's async keytar API */ setAsync(key: string, value: string): Promise<void>; /** * Async version of get - supports VS Code's async keytar API */ getAsync(key: string): Promise<string | null>; /** * Delete token from keyring or memory storage (sync version) */ delete(key: string): void; /** * Async version of delete - supports VS Code's async keytar API */ deleteAsync(key: string): Promise<void>; /** * Check if Node.js environment */ isAvailable(): boolean; /** * Get stored authentication token (sync version) * Checks environment variables and memory, but not async keytar */ getToken(): string | null; /** * Get stored authentication token (async version) * Properly checks async keytar API (VS Code), then env vars, then memory */ getTokenAsync(): Promise<string | null>; /** * Store authentication token (async version - use this in auth strategies) */ setToken(token: string): Promise<void>; /** * Delete authentication token (async version - use this in auth manager) */ deleteToken(): Promise<void>; /** * Clear all authentication data (async version - use this in auth manager) */ clear(): Promise<void>; } /** * Electron safeStorage-based token storage * Falls back to BrowserStorage if Electron safeStorage is not available */ export declare class ElectronStorage implements TokenStorage { private browserStorage; /** * Get token from Electron safeStorage or fall back to localStorage */ get(key: string): string | null; /** * Set token in Electron safeStorage or fall back to localStorage */ set(key: string, value: string): void; /** * Delete token from Electron safeStorage or localStorage */ delete(key: string): void; /** * Check if Electron safeStorage or browser storage is available */ isAvailable(): boolean; /** * Get stored authentication token */ getToken(): string | null; /** * Store authentication token */ setToken(token: string): void; /** * Delete authentication token */ deleteToken(): void; /** * Clear all authentication data */ clear(): void; } /** * Get the appropriate storage backend for the current environment */ export declare function getDefaultStorage(): TokenStorage;