/** * B2C Instance management. * * This module provides the {@link B2CInstance} class which represents a connection * to a specific B2C Commerce instance. It combines instance configuration with * authentication to provide typed API clients. * * ## Usage * * ### From configuration (recommended) * * Use {@link resolveConfig} to load configuration from dw.json and create an instance: * * ```typescript * import { resolveConfig } from '@salesforce/b2c-tooling-sdk/config'; * * const config = await resolveConfig({ * clientId: process.env.SFCC_CLIENT_ID, * clientSecret: process.env.SFCC_CLIENT_SECRET, * }); * * const instance = config.createB2CInstance(); * * // Use typed clients * await instance.webdav.put('Cartridges/v1/app.zip', content); * const { data } = await instance.ocapi.GET('/sites', {}); * ``` * * ### Direct construction * * ```typescript * const instance = new B2CInstance( * { hostname: 'your-sandbox.demandware.net', codeVersion: 'v1' }, * { oauth: { clientId: '...', clientSecret: '...' } } * ); * ``` * * @module instance */ import type { AuthConfig } from '../auth/types.js'; import { WebDavClient } from '../clients/webdav.js'; import { type OcapiClient } from '../clients/ocapi.js'; import { type TlsOptions } from '../clients/tls-dispatcher.js'; /** * Instance configuration (hostname, code version, etc.) */ export interface InstanceConfig { /** B2C instance hostname */ hostname: string; /** Code version for deployments */ codeVersion?: string; /** Separate hostname for WebDAV (if different from main hostname) */ webdavHostname?: string; /** TLS options for mTLS/self-signed certificate support */ tlsOptions?: TlsOptions; } /** * Represents a connection to a B2C Commerce instance. * * Provides lazy-loaded, typed API clients for WebDAV and OCAPI operations. * Authentication is handled automatically based on the configured credentials. * * @example * // From configuration (recommended) * import { resolveConfig } from '@salesforce/b2c-tooling-sdk/config'; * * const config = await resolveConfig({ * clientId: process.env.SFCC_CLIENT_ID, * clientSecret: process.env.SFCC_CLIENT_SECRET, * }); * const instance = config.createB2CInstance(); * * // WebDAV uses Basic auth if available, falls back to OAuth * await instance.webdav.mkcol('Cartridges/v1'); * * // OCAPI always uses OAuth * const { data } = await instance.ocapi.GET('/sites', {}); */ export declare class B2CInstance { readonly config: InstanceConfig; readonly auth: AuthConfig; private _webdav?; private _ocapi?; /** * Creates a new B2CInstance. * * @param config - Instance configuration (hostname, code version) * @param auth - Authentication configuration */ constructor(config: InstanceConfig, auth: AuthConfig); /** * The hostname to use for WebDAV operations. * Falls back to main hostname if not specified. */ get webdavHostname(): string; /** * WebDAV client for file operations. * * Uses Basic auth if username/password are configured, * otherwise falls back to OAuth. * * @returns The lazy-initialized WebDAV client for file operations. * * @example * await instance.webdav.mkcol('Cartridges/v1'); * await instance.webdav.put('Cartridges/v1/app.zip', content); * const entries = await instance.webdav.propfind('Cartridges'); */ get webdav(): WebDavClient; /** * OCAPI Data API client. * * Returns the openapi-fetch client directly with full type safety. * Always uses OAuth authentication. * * @returns The OCAPI Data API client (openapi-fetch Client with full type safety). * * @example * const { data, error } = await instance.ocapi.GET('/sites', {}); * const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version_id}', { * params: { path: { code_version_id: 'v1' } }, * body: { active: true } * }); */ get ocapi(): OcapiClient; /** * Gets the auth strategy for WebDAV operations. * Uses authMethods to determine priority, defaulting to basic then OAuth methods. */ private getWebDavAuthStrategy; /** * Gets the OAuth auth strategy based on allowed methods and available credentials. * Uses resolveAuthStrategy to automatically select the best OAuth method. * * @throws Error if no valid OAuth method is available */ private getOAuthStrategy; } export type { AuthConfig }; export type { TlsOptions };