/** * ConfigLoader - JSON config file loader with env var interpolation. * * Supports ${VAR|default} syntax for env var substitution and * dot-notation access for nested values. */ /** JSON configuration file loader with environment variable interpolation and dot-notation access. */ export declare class ConfigLoader { private static readonly DANGEROUS_KEYS; private data; private filePath; /** The ordered list of config file paths that were searched or provided. */ private _configPaths; /** * Create a new ConfigLoader, optionally loading a JSON file immediately. * * Accepts a single file path or an array of paths. When given an array, * the loader iterates in order and loads the first file that exists * (mirroring Python's ordered-search behaviour). * * @param filePaths - Path(s) to a JSON config file to load on construction. */ constructor(filePaths?: string | string[]); /** * Get the ordered list of config file paths that were passed/searched. * @returns The array of config paths. */ get configPaths(): string[]; /** * Load configuration from a JSON file, performing `${VAR|default}` env var interpolation on the raw text. * @param filePath - Path to the JSON config file. * @returns This instance for chaining. */ load(filePath: string): this; /** * Search for a config file in standard locations. * * Default search paths: CWD, `./config`, `$HOME/.signalwire`, * `.swml/`, `$HOME/.swml/`, `/etc/swml/`. * * @param filename - The config file name to search for. * @param additionalPaths - Extra directories to search before the defaults. * @param serviceName - Optional service name; prepends service-specific filenames to the search. * @returns A loaded ConfigLoader if found, or null if the file does not exist in any search path. */ static search(filename: string, additionalPaths?: string[], serviceName?: string): ConfigLoader | null; /** * Find a config file path without loading it. * * Searches service-specific filenames, additional paths, and default paths. * Returns the first found path string or null. * * @param serviceName - Optional service name for service-specific config filenames. * @param additionalPaths - Additional file paths to check. * @returns Path to the first config file found, or null. */ static findConfigFile(serviceName?: string, additionalPaths?: string[]): string | null; /** * Build the list of file paths to search. */ private static _buildSearchPaths; /** * Retrieve a configuration value using a dot-notation path (e.g. `'server.port'`). * @param path - Dot-separated key path into the config object. * @param defaultValue - Value returned when the path does not exist. * @returns The resolved value, or defaultValue if not found. */ get(path: string, defaultValue?: T): T; /** * Set a configuration value at the given dot-notation path, creating intermediate objects as needed. * @param path - Dot-separated key path into the config object. * @param value - The value to store. * @returns This instance for chaining. */ set(path: string, value: unknown): this; /** * Check whether a dot-notation path exists in the loaded configuration. * @param path - Dot-separated key path to check. * @returns True if the path resolves to a defined value. */ has(path: string): boolean; /** * Return a shallow copy of the entire configuration object. * @returns A copy of the top-level config data. */ getAll(): Record; /** * Alias for {@link getAll} — matches the Python SDK's `get_config()` method name. * @returns A copy of the top-level config data. */ getConfig(): Record; /** * Return the absolute path of the loaded config file, if any. * @returns The file path, or null if config was loaded from an object. */ getFilePath(): string | null; /** * Alias for {@link getFilePath} — matches the Python SDK's `get_config_file()` method name. * @returns The file path, or null if config was loaded from an object. */ getConfigFile(): string | null; /** * Check if a configuration was loaded. * * **Deliberate deviation from Python `has_config()`:** Python returns `True` * only when a file was loaded (`self._config is not None`). This TypeScript * implementation also returns `true` when data was loaded via * {@link loadFromObject}, because `loadFromObject` is an extra TS-only method * with no Python equivalent. Treating object-loaded data as "configured" is * the correct semantic for the TS API surface. * * If you need file-load-only detection, check `this.getFilePath() !== null`. * * @returns True if configuration data exists (from file or object). */ hasConfig(): boolean; /** * Get an entire configuration section with all environment variables substituted. * @param section - The top-level section name (e.g. 'security', 'server'). * @returns The configuration section as an object, or an empty object if not found. */ getSection(section: string): Record; /** * Recursively substitute `${VAR|default}` environment variables in any value. * * Walks strings, objects, and arrays. Coerces result strings to boolean * (`"true"` / `"false"`) or number when appropriate. * * @param value - The value to process (string, object, array, or primitive). * @param maxDepth - Maximum recursion depth to prevent infinite loops (default: 10). * @returns The value with all environment variables substituted. */ substituteVars(value: unknown, maxDepth?: number): unknown; /** * Merge configuration with environment variables that match a prefix. * * Config file values take precedence over environment variables. Matching * env var keys are stripped of the prefix, lowercased, split on `_`, and * written into a nested object (e.g. `SWML_FOO_BAR` → `{ foo: { bar: v } }`). * Mirrors Python's `merge_with_env` in * `signalwire/signalwire/core/config_loader.py`. * * @param envPrefix - Prefix for environment variables to consider (default: `'SWML_'`). * @returns Merged configuration dictionary. */ mergeWithEnv(envPrefix?: string): Record; /** * Check if a nested key (underscore-separated path) exists in a dict. * Used by {@link mergeWithEnv} to mirror Python's `_has_nested_key`. */ private _hasNestedKey; /** * Set a value in a dict using an underscore-separated path, creating * intermediate objects as needed. * Used by {@link mergeWithEnv} to mirror Python's `_set_nested_key`. */ private _setNestedKey; /** * Load configuration from a plain object instead of a file, useful for testing or programmatic setup. * @param obj - The configuration object to use. * @returns This instance for chaining. */ loadFromObject(obj: Record): this; /** * Interpolate ${VAR|default} patterns in a raw string. * @param input - The string containing env var references. * @returns The string with all env var references resolved. */ interpolateEnvVars(input: string): string; }