import { ScraperEngineConfig, BrowserPoolConfig, ScraperExecutionOptions } from './types'; /** * @file Manages scraper engine configurations from various sources like files, * environment variables, and programmatic updates. It supports configuration profiles * and a fluent builder API for creating configurations. */ /** * Represents the source from which a configuration part was loaded. * - `file`: Configuration loaded from a YAML or JSON file. * - `env`: Configuration loaded from environment variables. * - `programmatic`: Configuration applied directly via code (e.g., `updateConfig`, `applyProfile`). * - `default`: The base default configuration of the toolkit. */ export type ConfigSource = 'file' | 'env' | 'programmatic' | 'default'; /** * Defines the structure for a configuration profile, allowing predefined sets of configurations. */ export interface ConfigProfile { /** The unique name of the profile (e.g., "development", "production_large_pool"). */ name: string; /** An optional description for what this profile is intended for. */ description?: string; /** The partial scraper engine configuration that this profile applies. */ config: Partial; } /** * Defines the expected structure of a configuration file (e.g., `scraper.config.yaml`). */ export interface ConfigFile { /** * A map of configuration profiles, where each key is the profile name. * @example * profiles: * development: * config: { browserPool: { maxSize: 2 } } * production: * config: { browserPool: { maxSize: 10 } } */ profiles?: Record; /** Default configuration settings to be applied if no specific profile is chosen or to serve as a base. */ default?: Partial; /** * An array of paths to other configuration files to extend from. * Paths are relative to the current configuration file. * Configurations are merged shallowly, with later files overriding earlier ones. * @example * extends: * - ./base.config.yaml * - ./production.config.yaml */ extends?: string[]; } /** * Manages the loading, merging, and validation of scraper engine configurations. * Configurations can be sourced from files (YAML/JSON), environment variables, * programmatic updates, and predefined profiles. * It follows a layered approach for merging configurations: * Defaults < File < Environment Variables < Programmatic Updates/Profiles. */ export declare class ConfigManager { private config; private profiles; private sources; /** * Creates an instance of ConfigManager. * @param autoLoad If `true` (default), automatically loads configuration from * default file paths (e.g., `./scraper.config.yaml`) and environment variables upon instantiation. */ constructor(autoLoad?: boolean); /** * Retrieves a deep copy of the current, fully merged scraper engine configuration. * @returns The current `ScraperEngineConfig` object. */ getConfig(): ScraperEngineConfig; /** * Programmatically updates the current configuration with the provided partial configuration. * These updates are applied with the highest precedence, overriding any other sources. * @param updates A `Partial` object containing the configuration updates. */ updateConfig(updates: Partial): void; /** * Loads configuration from a specified file path. Supports JSON and YAML formats. * The loaded configuration is merged into the existing configuration. * Can handle `extends` within configuration files to inherit from other files. * @param filePath The absolute or relative path to the configuration file. * @throws Error if the file is not found, unsupported format, or parsing fails. */ loadFromFile(filePath: string): void; /** * Loads configuration settings from predefined environment variables. * Environment variables typically override file configurations but are overridden * by programmatic updates. * Recognized environment variables include: * - `BROWSER_POOL_SIZE`, `BROWSER_MAX_AGE_MS`, `BROWSER_HEADLESS`, `BROWSER_ARGS` * - `SCRAPING_MAX_RETRIES`, `SCRAPING_TIMEOUT`, `SCRAPING_USER_AGENT` * - `LOG_LEVEL`, `LOG_FORMAT` */ loadFromEnv(): void; /** * Applies a named configuration profile to the current configuration. * The profile's configuration is treated as a programmatic update, * overriding other sources. * @param profileName The name of the profile to apply (must be loaded from a config file). * @throws Error if the specified profile name is not found. */ applyProfile(profileName: string): void; /** * Retrieves a list of all currently loaded configuration profiles. * @returns An array of `ConfigProfile` objects. */ getProfiles(): ConfigProfile[]; /** * Validates a given configuration object (or the current configuration if none is provided) * against the defined Zod schema. * @param config Optional. A `Partial` to validate. If not provided, * the ConfigManager's current internal configuration is validated. * @returns An object with `valid: boolean` and `errors: string[]`. * `errors` is an array of human-readable error messages if validation fails. */ validateConfig(config?: Partial): { valid: boolean; errors: string[]; }; /** * Exports the current, fully merged configuration to a string in the specified format. * @param format The desired output format, either 'json' or 'yaml'. Defaults to 'yaml'. * @returns A string representation of the current configuration. */ exportConfig(format?: 'json' | 'yaml'): string; /** * Gets the default configuration by parsing an empty object with the Zod schema, * which populates all default values. * @returns The default `ScraperEngineConfig`. */ private getDefaultConfig; /** * Parse configuration file content */ private parseConfigFile; /** * Rebuild configuration from all sources */ private rebuildConfig; /** * Load configuration from various sources */ private loadConfiguration; } /** * A global, pre-initialized instance of `ConfigManager`. * This instance automatically loads configurations from default files and environment variables * upon module initialization, making it ready for immediate use. * @example * import { configManager } from 'crawlee-scraper-toolkit'; * const currentConfig = configManager.getConfig(); */ export declare const configManager: ConfigManager; /** * Provides a fluent (builder) API for programmatically constructing a `ScraperEngineConfig` object. * Useful for creating configurations in code rather than relying on files or environment variables. * An instance of this builder is typically obtained via the `createConfig()` factory function. * @example * import { createConfig } from 'crawlee-scraper-toolkit'; * const myConfig = createConfig() * .browserPool({ maxSize: 3 }) * .defaultOptions({ retries: 1 }) * .logging({ level: 'debug' }) * .build(); */ export declare class ConfigBuilder { private config; /** * Sets or updates the browser pool configuration. * Merges provided partial configuration with existing browser pool settings in the builder. * @param config A `Partial` object. * @returns The `ConfigBuilder` instance for chaining. */ browserPool(config: Partial): ConfigBuilder; /** * Sets or updates the default scraper execution options. * Merges provided partial options with existing default options in the builder. * @param options A `Partial` object. * @returns The `ConfigBuilder` instance for chaining. */ defaultOptions(options: Partial): ConfigBuilder; /** * Adds a list of plugin names or paths to the configuration. * These plugins will be loaded by the `ScraperEngine`. * @param plugins An array of strings, where each string is a plugin name or a path to a plugin module. * @returns The `ConfigBuilder` instance for chaining. */ plugins(plugins: string[]): ConfigBuilder; /** * Sets or updates the logging configuration. * Merges provided partial logging configuration with existing settings in the builder. * @param config An object with optional `level` and `format` properties. * @returns The `ConfigBuilder` instance for chaining. */ logging(config: { level?: 'debug' | 'info' | 'warn' | 'error'; format?: 'json' | 'text'; }): ConfigBuilder; /** * Finalizes the configuration building process and returns the constructed * partial `ScraperEngineConfig` object. This object can then be used to * initialize a `ScraperEngine` or update a `ConfigManager`. * @returns A `Partial` object. */ build(): Partial; } /** * Factory function that creates and returns a new `ConfigBuilder` instance. * This is the recommended way to start programmatically building a configuration. * @returns A new `ConfigBuilder` instance. * @example * import { createConfig } from 'crawlee-scraper-toolkit'; * const config = createConfig().defaultOptions({ timeout: 60000 }).build(); */ export declare function createConfig(): ConfigBuilder; //# sourceMappingURL=config-manager.d.ts.map