/**
* Configuration for the Obsidian Local REST API
*/
import { config } from 'dotenv';
// Load .env file if it exists
config();
export interface ObsidianConfig {
/** Base URL for the Obsidian REST API (e.g., http://127.0.0.1:27123) */
apiUrl: string;
/** API Key for authentication */
apiKey: string;
/** Debug mode for verbose logging */
debug: boolean;
}
/**
* Get Obsidian configuration from environment variables
*/
export function getConfig(): ObsidianConfig {
const apiUrl = process.env.OBSIDIAN_API_URL || 'http://127.0.0.1:27123';
const apiKey = process.env.OBSIDIAN_API_KEY || '';
const debug = process.env.DEBUG === 'true' || process.env.DEBUG === '1';
if (!apiKey) {
console.error('Warning: OBSIDIAN_API_KEY environment variable is not set');
}
return {
apiUrl: apiUrl.replace(/\/$/, ''), // Remove trailing slash
apiKey,
debug,
};
}
/**
* Debug logger - only logs when DEBUG is enabled
*/
export function debugLog(message: string, ...args: unknown[]): void {
const cfg = getConfig();
if (cfg.debug) {
const timestamp = new Date().toISOString();
console.error(`[DEBUG ${timestamp}] ${message}`, ...args);
}
}