import { B2CInstance } from '../../instance/index.js';
import { type JobExecution, type WaitForJobOptions } from './run.js';
/**
 * Options for site archive import.
 */
export interface SiteArchiveImportOptions {
    /** Keep archive on instance after import (default: false) */
    keepArchive?: boolean;
    /** Whether to wait for job completion (default: true) */
    wait?: boolean;
    /** Wait options for job completion */
    waitOptions?: WaitForJobOptions;
    /**
     * Optional list of paths or glob patterns to include in the archive when
     * importing from a directory. Each entry may be:
     * - An absolute path under the root directory
     * - A path relative to the root directory
     * - A glob pattern (relative to the root) — magic chars `* ? [ ] { }`
     *
     * When omitted, the entire root directory is archived (current behavior).
     * Entries that resolve outside the root directory throw an error.
     * Ignored when target is a zip file, Buffer, or remote filename.
     */
    paths?: string[];
    /**
     * Optional soft size ceiling (in bytes) for the assembled archive. When set
     * along with {@link SiteArchiveImportOptions.onOversize} and the archive
     * exceeds it, the callback is invoked before upload — the import still
     * proceeds. The SDK itself does not warn or block; the consumer decides how
     * to react. Use {@link siteArchiveImportSplit} to split oversized imports.
     */
    maxBytes?: number;
    /**
     * Called before upload when the assembled archive exceeds `maxBytes`. Lets
     * the consumer (e.g. the CLI) surface its own guidance. Receives the archive
     * size and the configured ceiling.
     */
    onOversize?: (info: {
        bytes: number;
        maxBytes: number;
    }) => void;
}
/**
 * Result of a site archive import.
 */
export interface SiteArchiveImportResult {
    /** Job execution details */
    execution: JobExecution;
    /** Archive filename on instance */
    archiveFilename: string;
    /** Whether archive was kept on instance */
    archiveKept: boolean;
}
/**
 * Imports a site archive to a B2C Commerce instance.
 *
 * Supports importing from:
 * - A local directory (will be zipped automatically)
 * - A local zip file
 * - A Buffer containing zip data
 * - A filename already on the instance (in Impex/src/instance/)
 *
 * **Buffer handling:** When passing a Buffer, the `archiveName` option controls
 * the contract:
 * - **Without `archiveName`:** The buffer should contain archive entries without
 *   a root directory (e.g. `libraries/mylib/library.xml`). The SDK generates
 *   an archive name and wraps the contents under it.
 * - **With `archiveName`:** The buffer must already be correctly structured with
 *   `archiveName/` as the top-level directory. It is uploaded as-is.
 *
 * @param instance - B2C instance to import to
 * @param target - Source to import (directory path, zip file path, Buffer, or remote filename)
 * @param options - Import options
 * @returns Import result with execution details
 * @throws JobExecutionError if import job fails
 *
 * @example
 * ```typescript
 * // Import from a local directory
 * const result = await siteArchiveImport(instance, './my-site-data');
 *
 * // Import from a zip file
 * const result = await siteArchiveImport(instance, './export.zip');
 *
 * // Import from a buffer (SDK wraps contents automatically)
 * const zip = new JSZip();
 * zip.file('libraries/mylib/library.xml', xmlContent);
 * const buffer = await zip.generateAsync({type: 'nodebuffer'});
 * const result = await siteArchiveImport(instance, buffer);
 *
 * // Import from a buffer with explicit archive name (caller owns structure)
 * const zip = new JSZip();
 * zip.file('my-import/libraries/mylib/library.xml', xmlContent);
 * const buffer = await zip.generateAsync({type: 'nodebuffer'});
 * const result = await siteArchiveImport(instance, buffer, {
 *   archiveName: 'my-import'
 * });
 *
 * // Import from existing file on instance
 * const result = await siteArchiveImport(instance, {
 *   remoteFilename: 'existing-archive.zip'
 * });
 * ```
 */
export declare function siteArchiveImport(instance: B2CInstance, target: string | Buffer | {
    remoteFilename: string;
    archiveName?: string;
}, options?: SiteArchiveImportOptions & {
    archiveName?: string;
}): Promise<SiteArchiveImportResult>;
/**
 * Options for {@link siteArchiveImportSplit}.
 */
export interface SiteArchiveImportSplitOptions {
    /**
     * Maximum size in bytes for each archive part (default: 190 MiB). Parts are
     * packed by estimated compressed size to stay under this ceiling; the
     * instance import limit is the constraint this works around.
     */
    maxBytes?: number;
    /** Keep archive parts on the instance after import (default: false). */
    keepArchive?: boolean;
    /** Wait options applied to each part's import job. */
    waitOptions?: WaitForJobOptions;
    /** Base archive name; parts are suffixed (e.g. `<name>-core`, `<name>-assets-1`). */
    archiveName?: string;
    /** Called when the overall plan is known, before any upload. */
    onPlan?: (plan: SplitImportPlanInfo) => void;
    /** Called before each part begins uploading. */
    onPart?: (info: SplitImportPartInfo) => void;
}
/**
 * Summary of the computed split plan, surfaced via {@link SiteArchiveImportSplitOptions.onPlan}.
 */
export interface SplitImportPlanInfo {
    /** Total number of archive parts that will be imported. */
    partCount: number;
    /** Number of parts containing order-sensitive XML/metadata. */
    xmlPartCount: number;
    /** Number of parts containing deferred static assets. */
    assetPartCount: number;
    /** Per-archive byte ceiling used for packing. */
    maxBytes: number;
}
/**
 * Per-part progress info, surfaced via {@link SiteArchiveImportSplitOptions.onPart}.
 */
export interface SplitImportPartInfo {
    /** 1-based index of this part. */
    index: number;
    /** Total number of parts. */
    total: number;
    /** Tier of this part. */
    kind: 'xml' | 'assets';
    /** Archive filename for this part. */
    filename: string;
    /** Number of files in this part. */
    fileCount: number;
    /** Assembled archive size in bytes. */
    bytes: number;
}
/**
 * Imports a large site archive by splitting it into multiple archive parts that
 * each stay under a size ceiling, then importing them sequentially.
 *
 * This works around the instance-side limit on a single import archive. The
 * strategy:
 * 1. **Order-sensitive XML/metadata** is imported first, kept together in one
 *    archive when it fits (preferred). If it must be split, it splits at
 *    top-level data-unit boundaries in dependency order, never splitting a
 *    single unit — so catalogs (and their internal references) ride together.
 * 2. **Static assets** (catalog/library static resources) are deferred to
 *    subsequent archive parts, bin-packed by compressed size. They are
 *    order-independent and attach to the units created by the XML import.
 *
 * Parts are imported sequentially and the operation stops on the first failure.
 *
 * @param instance - B2C instance to import to
 * @param dir - Local directory to import (must be a directory)
 * @param options - Split import options
 * @returns One import result per archive part, in import order
 * @throws Error if a single file or data unit cannot fit under `maxBytes`
 * @throws JobExecutionError if any part's import job fails
 *
 * @example
 * ```typescript
 * const results = await siteArchiveImportSplit(instance, './big-site-data', {
 *   maxBytes: 190 * 1024 * 1024,
 *   onPart: (p) => console.log(`Part ${p.index}/${p.total}: ${p.kind} (${p.fileCount} files)`),
 * });
 * ```
 */
export declare function siteArchiveImportSplit(instance: B2CInstance, dir: string, options?: SiteArchiveImportSplitOptions): Promise<SiteArchiveImportResult[]>;
/**
 * Configuration for sites in export.
 */
export interface ExportSitesConfiguration {
    ab_tests?: boolean;
    active_data_feeds?: boolean;
    all?: boolean;
    cache_settings?: boolean;
    campaigns_and_promotions?: boolean;
    commerce_feature_states?: boolean;
    content?: boolean;
    coupons?: boolean;
    custom_objects?: boolean;
    customer_cdn_settings?: boolean;
    customer_groups?: boolean;
    distributed_commerce_extensions?: boolean;
    dynamic_file_resources?: boolean;
    gift_certificates?: boolean;
    ocapi_settings?: boolean;
    payment_methods?: boolean;
    payment_processors?: boolean;
    redirect_urls?: boolean;
    search_settings?: boolean;
    shipping?: boolean;
    site_descriptor?: boolean;
    site_preferences?: boolean;
    sitemap_settings?: boolean;
    slots?: boolean;
    sorting_rules?: boolean;
    source_codes?: boolean;
    static_dynamic_alias_mappings?: boolean;
    stores?: boolean;
    tax?: boolean;
    url_rules?: boolean;
}
/**
 * Configuration for global data in export.
 */
export interface ExportGlobalDataConfiguration {
    access_roles?: boolean;
    all?: boolean;
    csc_settings?: boolean;
    csrf_whitelists?: boolean;
    custom_preference_groups?: boolean;
    custom_quota_settings?: boolean;
    custom_types?: boolean;
    geolocations?: boolean;
    global_custom_objects?: boolean;
    job_schedules?: boolean;
    job_schedules_deprecated?: boolean;
    locales?: boolean;
    meta_data?: boolean;
    oauth_providers?: boolean;
    ocapi_settings?: boolean;
    page_meta_tags?: boolean;
    preferences?: boolean;
    price_adjustment_limits?: boolean;
    services?: boolean;
    sorting_rules?: boolean;
    static_resources?: boolean;
    system_type_definitions?: boolean;
    users?: boolean;
    webdav_client_permissions?: boolean;
}
/**
 * Data units configuration for export.
 */
export interface ExportDataUnitsConfiguration {
    /** Catalog static resources to export (catalog_id: true) */
    catalog_static_resources?: Record<string, boolean>;
    /** Catalogs to export (catalog_id: true) */
    catalogs?: Record<string, boolean>;
    /** Customer lists to export (list_id: true) */
    customer_lists?: Record<string, boolean>;
    /** Inventory lists to export (list_id: true) */
    inventory_lists?: Record<string, boolean>;
    /** Library static resources to export (library_id: true) */
    library_static_resources?: Record<string, boolean>;
    /** Libraries to export (library_id: true) */
    libraries?: Record<string, boolean>;
    /** Price books to export (pricebook_id: true) */
    price_books?: Record<string, boolean>;
    /** Sites to export (site_id: ExportSitesConfiguration) */
    sites?: Record<string, Partial<ExportSitesConfiguration> | boolean>;
    /** Global data to export */
    global_data?: Partial<ExportGlobalDataConfiguration>;
}
/**
 * Options for site archive export.
 */
export interface SiteArchiveExportOptions {
    /** Wait options for job completion */
    waitOptions?: WaitForJobOptions;
}
/**
 * Result of a site archive export.
 */
export interface SiteArchiveExportResult {
    /** Job execution details */
    execution: JobExecution;
    /** Archive filename on instance */
    archiveFilename: string;
}
/**
 * Exports a site archive from a B2C Commerce instance.
 *
 * @param instance - B2C instance to export from
 * @param dataUnits - Data units configuration specifying what to export
 * @param options - Export options
 * @returns Export result with archive data
 * @throws JobExecutionError if export job fails
 *
 * @example
 * ```typescript
 * // Export global meta data
 * const result = await siteArchiveExport(instance, {
 *   global_data: { meta_data: true }
 * });
 *
 * // Export a site's content
 * const result = await siteArchiveExport(instance, {
 *   sites: {
 *     'RefArch': { content: true, site_preferences: true }
 *   }
 * });
 *
 * // Export catalogs
 * const result = await siteArchiveExport(instance, {
 *   catalogs: { 'storefront-catalog': true }
 * });
 * ```
 */
export declare function siteArchiveExport(instance: B2CInstance, dataUnits: Partial<ExportDataUnitsConfiguration>, options?: SiteArchiveExportOptions): Promise<SiteArchiveExportResult>;
/**
 * Exports a site archive and downloads it to memory.
 *
 * Runs the export job on the instance, downloads the archive via WebDAV,
 * and returns the data as a Buffer. Optionally keeps the archive on the instance.
 *
 * @param instance - B2C instance to export from
 * @param dataUnits - Data units configuration specifying what to export
 * @param options - Export and download options
 * @returns Export result with archive data buffer
 *
 * @example
 * ```typescript
 * const result = await siteArchiveExportDownload(instance, {
 *   global_data: { meta_data: true }
 * });
 * const zip = await JSZip.loadAsync(result.data);
 * ```
 */
export declare function siteArchiveExportToBuffer(instance: B2CInstance, dataUnits: Partial<ExportDataUnitsConfiguration>, options?: SiteArchiveExportOptions & {
    keepArchive?: boolean;
}): Promise<SiteArchiveExportResult & {
    data: Buffer;
    archiveKept: boolean;
}>;
/**
 * Exports a site archive, downloads it, and saves it to a local path.
 *
 * Runs the export job on the instance, downloads the archive via WebDAV,
 * and saves it locally. Optionally keeps the archive on the instance.
 *
 * @param instance - B2C instance to export from
 * @param dataUnits - Data units configuration
 * @param outputPath - Local path to save the archive
 * @param options - Export and download options
 * @returns Export result with local path
 *
 * @example
 * ```typescript
 * // Export and save to a directory (extracts zip)
 * await siteArchiveExportToPath(instance, { global_data: { meta_data: true } }, './exports');
 *
 * // Export and save as zip
 * await siteArchiveExportToPath(instance, { global_data: { meta_data: true } }, './exports/archive.zip');
 * ```
 */
export declare function siteArchiveExportToPath(instance: B2CInstance, dataUnits: Partial<ExportDataUnitsConfiguration>, outputPath: string, options?: SiteArchiveExportOptions & {
    keepArchive?: boolean;
    extractZip?: boolean;
}): Promise<SiteArchiveExportResult & {
    localPath: string;
    archiveKept: boolean;
}>;
