/** * Authentication module for Bellwether Cloud. * * Handles session storage, retrieval, and management. * Sessions are stored in ~/.bellwether/session.json with restricted permissions. */ import type { StoredSession, ProjectLink, SessionTeam } from './types.js'; /** * Directory for bellwether configuration. */ export declare const CONFIG_DIR: string; /** * Path to session file. */ export declare const SESSION_FILE: string; /** * Path to device ID file. */ export declare const DEVICE_ID_FILE: string; /** * Environment variable name for session token. */ export declare const SESSION_ENV_VAR = "BELLWETHER_SESSION"; /** * Environment variable name for API base URL. */ export declare const BASE_URL_ENV_VAR = "BELLWETHER_API_URL"; /** * Environment variable name for team ID override. */ export declare const TEAM_ID_ENV_VAR = "BELLWETHER_TEAM_ID"; /** * Session token prefix for validation. */ export declare const SESSION_PREFIX: "sess_"; /** * Mock session prefix for development. */ export declare const MOCK_SESSION_PREFIX: "sess_mock_"; /** * Ensure the config directory exists. */ export declare function ensureConfigDir(): void; /** * Get or create a stable device ID for this CLI install. */ export declare function getOrCreateDeviceId(): string; /** * Get the stored session. * Returns null if no session exists, session is expired, or file is corrupted. */ export declare function getStoredSession(): StoredSession | null; /** * Save session to disk. * File is created with 0600 permissions (owner read/write only). */ export declare function saveSession(session: StoredSession): void; /** * Clear the stored session. */ export declare function clearSession(): void; /** * Get the session token. * * Priority: * 1. BELLWETHER_SESSION environment variable * 2. Stored session in ~/.bellwether/session.json */ export declare function getSessionToken(): string | undefined; /** * Get the API base URL. * * Priority: * 1. BELLWETHER_API_URL environment variable * 2. Default: https://api.bellwether.sh * * Security: Validates that custom URLs use HTTPS (except localhost for development). */ export declare function getBaseUrl(): string; /** * Check if a session token appears valid (strict format check). * Validates against exact patterns to prevent injection. */ export declare function isValidSessionFormat(token: string): boolean; /** * Check if a session token is a mock session (for development). */ export declare function isMockSession(token: string): boolean; /** * Check if currently authenticated. */ export declare function isAuthenticated(): boolean; /** * Get the active team ID. * * Priority: * 1. BELLWETHER_TEAM_ID environment variable * 2. Team ID from project link (if in a linked project directory) * 3. Active team ID from stored session */ export declare function getTeamId(projectDir?: string): string | undefined; /** * Get the active team details. * Returns the full team object if available. */ export declare function getActiveTeam(projectDir?: string): SessionTeam | undefined; /** * Get all teams from the stored session. */ export declare function getSessionTeams(): SessionTeam[]; /** * Set the active team in the stored session. * Returns true if successful, false if team not found in session. */ export declare function setActiveTeam(teamId: string): boolean; /** * Update the session token in the stored session. * Called when the server rotates the token and returns a new one. * * @param newToken - The new session token from the server * @returns Promise that resolves when the session is updated */ export declare function updateSessionToken(newToken: string): Promise; /** * Directory name for per-project bellwether config. */ export declare const PROJECT_CONFIG_DIR = ".bellwether"; /** * File name for project link configuration. */ export declare const LINK_FILE = "link.json"; /** * Get the project link file path for a given directory. */ export declare function getLinkFilePath(projectDir?: string): string; /** * Get the linked project for the current directory. */ export declare function getLinkedProject(projectDir?: string): ProjectLink | null; /** * Save a project link for the current directory. */ export declare function saveProjectLink(link: ProjectLink, projectDir?: string): void; /** * Remove the project link for the current directory. */ export declare function removeProjectLink(projectDir?: string): boolean; /** * Check if the current directory is linked to a project. */ export declare function isLinked(projectDir?: string): boolean; //# sourceMappingURL=auth.d.ts.map