/**
 * Secure storage utility for sensitive data
 * Uses Electron's IPC to store sensitive data in the main process
 */ // Check if we're in a browser environment
const isBrowser = typeof window !== "undefined";
export class SecureStorage {
    static cache = new Map();
    /**
   * Store sensitive data securely
   * @param key - The key to store the data under
   * @param value - The sensitive value to store
   */ static async set(key, value) {
        if (isBrowser && window.electronAPI?.setSecureValue) {
            await window.electronAPI.setSecureValue(key, value);
            this.cache.set(key, value);
        } else {
            // Fallback for non-electron environments (testing)
            console.warn("Secure storage not available, using memory cache");
            this.cache.set(key, value);
        }
    }
    /**
   * Retrieve sensitive data securely
   * @param key - The key to retrieve data for
   * @returns The stored value or null if not found
   */ static async get(key) {
        // Check cache first
        if (this.cache.has(key)) {
            return this.cache.get(key) || null;
        }
        if (isBrowser && window.electronAPI?.getSecureValue) {
            const value = await window.electronAPI.getSecureValue(key);
            if (value) {
                this.cache.set(key, value);
            }
            return value;
        }
        return null;
    }
    /**
   * Remove sensitive data
   * @param key - The key to remove
   */ static async remove(key) {
        this.cache.delete(key);
        if (isBrowser && window.electronAPI?.removeSecureValue) {
            await window.electronAPI.removeSecureValue(key);
        }
    }
    /**
   * Clear all cached values (on logout/cleanup)
   */ static clearCache() {
        this.cache.clear();
    }
}
// Helper functions for API key management
export async function getApiKey() {
    return SecureStorage.get("apiKey");
}
export async function setApiKey(apiKey) {
    return SecureStorage.set("apiKey", apiKey);
}
export async function removeApiKey() {
    return SecureStorage.remove("apiKey");
}

//# sourceMappingURL=secureStorage.js.map