/** * Configuration resolution. * * This module provides the ConfigResolver class, the preferred high-level API * for loading B2C Commerce configuration from multiple sources. * * @module config/resolver */ import type { AuthCredentials } from '../auth/types.js'; import type { B2CInstance } from '../instance/index.js'; import type { ConfigSource, ConfigResolutionResult, NormalizedConfig, ResolveConfigOptions, ResolvedB2CConfig } from './types.js'; /** * Resolves configuration from multiple sources with consistent behavior. * * ConfigResolver is the preferred high-level API for loading B2C configuration. * It provides: * - Consistent hostname mismatch protection across SDK and CLI * - Extensibility via the ConfigSource interface * - Convenience methods for creating B2CInstance and auth credentials * * ## Resolution Priority * * Configuration is resolved with the following precedence (highest to lowest): * 1. Explicit overrides (passed to resolve methods) * 2. Sources in order (dw.json, ~/.mobify by default) * * ## Usage * * ```typescript * import { createConfigResolver } from '@salesforce/b2c-tooling-sdk/config'; * * const resolver = createConfigResolver(); * * // Simple resolution * const { config, warnings } = resolver.resolve({ * hostname: process.env.SFCC_SERVER, * clientId: process.env.SFCC_CLIENT_ID, * }); * * // Create B2CInstance directly * const instance = resolver.createInstance({ hostname: '...' }); * * // Get auth credentials for use with resolveAuthStrategy * const credentials = resolver.createAuthCredentials({ clientId: '...' }); * ``` * * ## Custom Sources * * You can provide custom configuration sources: * * ```typescript * import { ConfigResolver } from '@salesforce/b2c-tooling-sdk/config'; * * class MySource implements ConfigSource { * name = 'my-source'; * load(options) { return { hostname: 'custom.example.com' }; } * } * * const resolver = new ConfigResolver([new MySource()]); * ``` */ export declare class ConfigResolver { private sources; /** * Creates a new ConfigResolver. * * @param sources - Custom configuration sources. If not provided, uses default sources (dw.json, ~/.mobify, package.json). * Sources are automatically sorted by priority (lower number = higher priority). */ constructor(sources?: ConfigSource[]); /** * Resolves configuration from all sources. * * @param overrides - Explicit values that take highest priority * @param options - Resolution options * @returns Resolution result with config, warnings, and source info * * @example * ```typescript * const { config, warnings, sources } = resolver.resolve( * { hostname: process.env.SFCC_SERVER }, * { instance: 'staging' } * ); * * if (warnings.length > 0) { * console.warn('Config warnings:', warnings); * } * ``` */ resolve(overrides?: Partial, options?: ResolveConfigOptions): Promise; /** * Creates a B2CInstance from resolved configuration. * * This is a convenience method that combines configuration resolution * with B2CInstance creation. * * @param overrides - Explicit values that take highest priority * @param options - Resolution options * @returns Configured B2CInstance * @throws Error if hostname is not available in resolved config * * @example * ```typescript * const instance = resolver.createInstance({ * clientId: process.env.SFCC_CLIENT_ID, * clientSecret: process.env.SFCC_CLIENT_SECRET, * }); * * await instance.webdav.put('path/file.txt', content); * ``` */ createInstance(overrides?: Partial, options?: ResolveConfigOptions): Promise; /** * Creates auth credentials from resolved configuration. * * The returned credentials can be used with `resolveAuthStrategy()` * to automatically select the best authentication method. * * @param overrides - Explicit values that take highest priority * @param options - Resolution options * @returns Auth credentials suitable for resolveAuthStrategy() * * @example * ```typescript * import { resolveAuthStrategy } from '@salesforce/b2c-tooling-sdk'; * * const credentials = resolver.createAuthCredentials({ * clientId: process.env.SFCC_CLIENT_ID, * }); * * const strategy = resolveAuthStrategy(credentials); * ``` */ createAuthCredentials(overrides?: Partial, options?: ResolveConfigOptions): Promise; } /** * Creates a ConfigResolver with default sources (dw.json, ~/.mobify). * * This is the recommended way to create a ConfigResolver for most use cases. * * @returns ConfigResolver with default configuration sources * * @example * ```typescript * import { createConfigResolver } from '@salesforce/b2c-tooling-sdk/config'; * * const resolver = createConfigResolver(); * const { config } = resolver.resolve({ hostname: 'example.com' }); * ``` */ export declare function createConfigResolver(): ConfigResolver; /** * Resolves configuration from multiple sources and returns a rich config object. * * This is the preferred high-level API for configuration resolution. It returns * a {@link ResolvedB2CConfig} object with validation methods and factory methods * for creating SDK objects. * * ## Resolution Priority * * 1. Explicit overrides (passed as first argument) * 2. Default sources (dw.json, ~/.mobify) * 3. Custom sources (via options.sources) * * ## Example * * ```typescript * import { resolveConfig } from '@salesforce/b2c-tooling-sdk/config'; * * const config = resolveConfig({ * hostname: process.env.SFCC_SERVER, * clientId: process.env.SFCC_CLIENT_ID, * mrtApiKey: process.env.MRT_API_KEY, * }); * * // Check what's available and create objects * if (config.hasB2CInstanceConfig()) { * const instance = config.createB2CInstance(); * await instance.webdav.propfind('Cartridges'); * } * * if (config.hasMrtConfig()) { * const mrtAuth = config.createMrtAuth(); * } * ``` * * @param overrides - Explicit configuration values (highest priority) * @param options - Resolution options * @returns Resolved configuration with factory methods */ export declare function resolveConfig(overrides?: Partial, options?: ResolveConfigOptions): Promise;