UNPKG

@elevenlabs/convai-cli

Version:

CLI tool to manage ElevenLabs conversational AI agents

169 lines 4.83 kB
"use strict"; /** * Simple credential management for CLI * Just basic keychain storage + secure file permissions */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.storeApiKey = storeApiKey; exports.retrieveApiKey = retrieveApiKey; exports.removeApiKey = removeApiKey; exports.hasApiKey = hasApiKey; const fs = __importStar(require("fs-extra")); const path = __importStar(require("path")); const os = __importStar(require("os")); // Optional keychain import - graceful fallback if not available let keytar; try { // Skip keytar in CI environments where it might cause permission issues if (!process.env.CI && !process.env.GITHUB_ACTIONS && !process.env.DOCKER_CONTAINER) { keytar = require('keytar'); } } catch (error) { // Keychain not available, will use file storage } const SERVICE_NAME = 'ElevenLabs-ConvAI-CLI'; const ACCOUNT_NAME = 'api-key'; /** * Get config directory path */ function getConfigDir() { return path.join(os.homedir(), '.convai'); } /** * Get API key file path */ function getApiKeyFile() { return path.join(getConfigDir(), 'api_key'); } /** * Ensure config directory exists with secure permissions */ async function ensureConfigDir() { const configDir = getConfigDir(); await fs.ensureDir(configDir); // Set secure permissions on Unix-like systems if (process.platform !== 'win32') { await fs.chmod(configDir, 0o700); } } /** * Store API key securely */ async function storeApiKey(apiKey) { // Try keychain first if available if (keytar) { try { await keytar.setPassword(SERVICE_NAME, ACCOUNT_NAME, apiKey); return; } catch (error) { // Fall through to file storage } } // Fall back to secure file storage await ensureConfigDir(); const keyFile = getApiKeyFile(); await fs.writeFile(keyFile, apiKey, { mode: 0o600, encoding: 'utf-8' }); } /** * Retrieve API key from secure storage */ async function retrieveApiKey() { // Environment variable takes highest priority const envKey = process.env.ELEVENLABS_API_KEY; if (envKey) { return envKey; } // Try keychain if available if (keytar) { try { const apiKey = await keytar.getPassword(SERVICE_NAME, ACCOUNT_NAME); if (apiKey) { return apiKey; } } catch (error) { // Fall through to file storage } } // Try file storage try { const keyFile = getApiKeyFile(); if (await fs.pathExists(keyFile)) { return await fs.readFile(keyFile, 'utf-8'); } } catch (error) { // File not readable } return undefined; } /** * Remove API key from secure storage */ async function removeApiKey() { // Remove from keychain if available if (keytar) { try { await keytar.deletePassword(SERVICE_NAME, ACCOUNT_NAME); } catch (error) { // Ignore errors } } // Remove file try { const keyFile = getApiKeyFile(); if (await fs.pathExists(keyFile)) { await fs.remove(keyFile); } } catch (error) { // Ignore errors } } /** * Check if user has API key stored */ async function hasApiKey() { const apiKey = await retrieveApiKey(); return !!apiKey; } //# sourceMappingURL=auth.js.map