import { type ExecFileOptions } from 'node:child_process'; import { type ISFDMUOptions, type ISFDMUResult, type ServiceResult } from '../models/sfdmu-types.js'; /** * Type for the promisified execFile function. */ export type ExecFileAsyncFn = (file: string, args: string[], options: ExecFileOptions) => Promise<{ stdout: string; stderr: string; }>; /** * Configuration options for SFDMUService. */ export type ISFDMUServiceConfig = { /** Optional logger for debug output */ logger?: Console; /** Optional execFile function for testing (dependency injection) */ execFileAsync?: ExecFileAsyncFn; /** Override platform detection (for testing) */ platform?: NodeJS.Platform; }; /** * Service for executing SFDMU (Salesforce Data Move Utility) operations. * * This service provides: * - Runtime verification that SFDMU is installed * - Secure shell execution using execFile (prevents command injection) * - Cross-platform support (Windows/Unix) * - Configurable timeout and buffer sizes * - Result parsing for record counts and errors * * @example * ```typescript * const service = new SFDMUService(); * await service.verifyInstallation(); * const result = await service.runExport({ * configPath: './export.json', * sourceOrg: 'myOrg' * }); * ``` */ export declare class SFDMUService { /** Default timeout for SFDMU operations (5 minutes) */ static readonly DEFAULT_TIMEOUT = 300000; /** Default max buffer size for stdout/stderr (10MB) */ static readonly DEFAULT_MAX_BUFFER: number; /** The sf CLI binary name (platform-specific) */ private readonly sfBinary; /** Logger instance */ private readonly logger?; /** Injected execFile function */ private readonly execFileAsync; /** * Creates a new SFDMUService instance. * * @param config - Optional configuration including logger and test dependencies */ constructor(config?: ISFDMUServiceConfig); /** * Builds command line arguments for SFDMU execution. * * @param options - Operation options * @param operation - The operation type * @returns Array of command line arguments */ private static buildArgs; /** * Parses record count from SFDMU stdout output. * * SFDMU (Salesforce Data Move Utility) outputs record counts in several formats * depending on the operation type and verbosity level: * - Summary lines: "Total: 100 records" — single authoritative count, checked first * - Per-batch lines: "Processed 8 records" repeated per batch — summed to get total * - Alternate phrasing: "100 records processed" * * Per-batch counts must be summed: SFDMU emits "Processed N records" once per batch * (CLI-3140), so taking only the first match caps the reported count at the batch size. * * Tested against SFDMU v4.x output. If patterns fail to match, returns undefined * (graceful degradation — record count is informational, not required). * * @param stdout - Standard output from SFDMU execution * @returns Parsed record count or undefined if no pattern matched */ private static parseRecordCount; /** * Parses error messages from SFDMU stderr output. * * @param stderr - Standard error from SFDMU * @returns Array of error messages */ private static parseErrors; /** * Parses warning messages from SFDMU stderr output. * * @param stderr - Standard error from SFDMU * @returns Array of warning messages */ private static parseWarnings; /** * Returns the sf binary name being used (for testing/debugging). */ getSfBinary(): string; /** * Verifies that SFDMU is installed and available. * * @returns Promise that resolves when SFDMU installation is verified * @throws SfError with code 'SFCLINotFound' if Salesforce CLI is not installed * @throws SfError with code from SFDMUErrorCodes.NOT_INSTALLED if SFDMU plugin is missing */ verifyInstallation(): Promise; /** * Executes an SFDMU export operation. * * @param options - Export options including config path and source org * @returns ServiceResult containing the execution result */ runExport(options: ISFDMUOptions): Promise>; /** * Executes an SFDMU import operation. * * @param options - Import options including config path and target org * @returns ServiceResult containing the execution result */ runImport(options: ISFDMUOptions): Promise>; /** * Executes an SFDMU operation (export or import). * * @param options - Operation options * @param operation - The operation type ('export' or 'import') * @returns ServiceResult containing the execution result */ private executeOperation; }