/** * Configuration Helper Utilities for Photon * * Provides utility functions for validating and accessing environment variables * with clear, actionable error messages. */ /** * Require an environment variable, throwing a clear error if not set * * @param name Environment variable name * @param description Optional description of what this variable is used for * @returns The environment variable value * @throws Error if environment variable is not set * * @example * const apiKey = requireEnv('OPENAI_API_KEY', 'Required for OpenAI API access'); */ export declare function requireEnv(name: string, description?: string): string; /** * Get an optional environment variable with a default value * * @param name Environment variable name * @param defaultValue Default value if not set * @returns The environment variable value or default * * @example * const region = optionalEnv('AWS_REGION', 'us-east-1'); * const port = optionalEnv('PORT', '3000'); */ export declare function optionalEnv(name: string, defaultValue?: string): string | undefined; /** * Validate multiple environment variables at once * * @param schema Object mapping env var names to config * @returns Object mapping env var names to values * @throws Error if any required variable is missing * * @example * const config = validateConfig({ * OPENAI_API_KEY: { required: true, description: 'OpenAI API key' }, * OPENAI_ORG_ID: { required: false, default: 'personal' }, * AWS_REGION: { required: false, default: 'us-east-1' } * }); * // Returns: { OPENAI_API_KEY: 'sk-...', OPENAI_ORG_ID: 'personal', AWS_REGION: 'us-east-1' } */ export declare function validateConfig(schema: Record): Record; /** * Check if an environment variable is set * * @param name Environment variable name * @returns True if set and non-empty * * @example * if (hasEnv('OPENAI_API_KEY')) { * // Use OpenAI * } else { * // Fall back to other provider * } */ export declare function hasEnv(name: string): boolean; /** * Get environment variable or throw with custom error message * * @param name Environment variable name * @param errorMessage Custom error message * @returns The environment variable value * @throws Error with custom message if not set * * @example * const token = requireEnvOr( * 'GITHUB_TOKEN', * 'GitHub token required. Get one at https://github.com/settings/tokens' * ); */ export declare function requireEnvOr(name: string, errorMessage: string): string; /** * Validate environment variable matches a pattern * * @param name Environment variable name * @param pattern Regular expression pattern * @param description Description of expected format * @returns The environment variable value * @throws Error if not set or doesn't match pattern * * @example * const apiKey = validateEnvPattern( * 'OPENAI_API_KEY', * /^sk-[a-zA-Z0-9]{40,}$/, * 'OpenAI API key format: sk-...' * ); */ export declare function validateEnvPattern(name: string, pattern: RegExp, description?: string): string; /** * Parse environment variable as integer * * @param name Environment variable name * @param defaultValue Default value if not set or invalid * @returns Parsed integer value * * @example * const port = envInt('PORT', 3000); * const timeout = envInt('TIMEOUT', 30); */ export declare function envInt(name: string, defaultValue: number): number; /** * Parse environment variable as boolean * * Treats 'true', '1', 'yes', 'on' as true (case-insensitive) * Treats 'false', '0', 'no', 'off' as false (case-insensitive) * * @param name Environment variable name * @param defaultValue Default value if not set or invalid * @returns Boolean value * * @example * const debug = envBool('DEBUG', false); * const secure = envBool('SMTP_SECURE', true); */ export declare function envBool(name: string, defaultValue: boolean): boolean; /** * Parse environment variable as JSON * * @param name Environment variable name * @param defaultValue Default value if not set or invalid * @returns Parsed JSON value * * @example * const gcpCreds = envJSON('GCP_CREDENTIALS', {}); * const config = envJSON('APP_CONFIG', { timeout: 30 }); */ export declare function envJSON(name: string, defaultValue: T): T; /** * Build connection string from environment variables * * @param template Template string with {{VAR}} placeholders * @param required Array of required variable names * @returns Connection string with variables replaced * @throws Error if any required variable is missing * * @example * const dbUrl = buildConnectionString( * 'postgresql://{{DB_USER}}:{{DB_PASS}}@{{DB_HOST}}:{{DB_PORT}}/{{DB_NAME}}', * ['DB_USER', 'DB_PASS', 'DB_HOST', 'DB_PORT', 'DB_NAME'] * ); */ export declare function buildConnectionString(template: string, required: string[]): string; //# sourceMappingURL=config-helpers.d.ts.map