import { type ServiceResult } from '../models/sfdmu-types.js'; import { SFDMUService } from '../services/SFDMUService.js'; /** * SFDMU operation types for import. */ export type ImportOperationType = 'Insert' | 'Upsert'; /** * Options for the definition import operation. */ export type ImportOptions = { /** Target org username or alias to import into */ targetOrg: string; /** Source directory containing CSV files and export.json */ sourceDir: string; /** SFDMU operation type (Insert or Upsert) */ operation?: ImportOperationType; /** Simulation mode - validates and previews changes without modifying data */ simulation?: boolean; /** Optional logger for debug output */ logger?: Console; }; /** * Result of a definition import operation. */ export type ImportResult = { /** Number of definitions imported */ definitionsImported: number; /** Source directory used */ sourceDir: string; /** Whether this was a simulation (no data modified) */ simulation: boolean; /** Raw SFDMU output for debugging */ sfdmuOutput?: string; }; /** * Error codes specific to import operations. * * These codes are returned in ServiceResult.errorCode when import fails. * User action: Check the corresponding message for resolution steps. */ export declare const ImportErrorCodes: { /** Source directory does not exist. User should verify the --source path. */ readonly SOURCE_NOT_FOUND: "IMPORT_SOURCE_NOT_FOUND"; /** Source directory is missing pnova__Profiling_Definition__c.csv. User should verify export was successful. */ readonly INVALID_SOURCE: "IMPORT_INVALID_SOURCE"; /** Failed to write temporary export.json config. Check disk space and permissions. */ readonly CONFIG_WRITE_FAILED: "IMPORT_CONFIG_WRITE_FAILED"; /** SFDMU import operation failed. Check SFDMU output for details. */ readonly IMPORT_FAILED: "IMPORT_FAILED"; }; /** * Orchestrates the import of profiling definitions using SFDMU. * * Follows the 4-layer architecture: Command → Operation → Service → API * This operation layer handles business logic orchestration while delegating * the actual SFDMU execution to SFDMUService. * * @example * ```typescript * const operation = new DefinitionImportOperation(sfdmuService); * const result = await operation.execute({ * targetOrg: 'myOrg', * sourceDir: './backup/definitions', * operation: 'Upsert', * simulation: true * }); * ``` */ export declare class DefinitionImportOperation { /** * SFDMU query for profiling definitions (used in config generation). * Includes formula fields (PropFx_*) for CSV compatibility with export - these are * read-only and will be ignored by Salesforce during import (computed automatically). * * CLI-3039: Removed pnova__Aud_VersionDCBase__c and pnova__Prop_LicenseViolations__c * — both are absent from packaging/v4.12.0 and SFDMU was logging "Missing in the * Target and will be excluded from the migration" warnings on every import. */ private static readonly DEFINITION_QUERY; /** Expected CSV file name */ private static readonly DEFINITION_CSV; /** * Columns stripped from the definition CSV before SFDMU import. * These carry source-org profiling history and must start fresh in the target. */ private static readonly IMPORT_CLEAR_COLUMNS; private readonly sfdmuService; private readonly logger?; /** * Creates a new DefinitionImportOperation. * * @param sfdmuService - The SFDMU service instance for executing operations * @param logger - Optional logger for debug output */ constructor(sfdmuService: SFDMUService, logger?: Console); /** * Builds the SFDMU import configuration. * * Creates an export.json config structure for SFDMU import operations. * Note: SFDMU always reads 'export.json' regardless of operation direction. * * RecordType is declared first as a Readonly reference object so that SFDMU can * resolve the RecordType.$$DeveloperName$NamespacePrefix$SobjectType lookup column * from the RecordType.csv sidecar file. Without this entry, SFDMU finds the sidecar * but does not include RecordType in its import plan, leaving RecordTypeId as #N/A * and causing Salesforce to reject the insert. * * @param operation - The import operation type (Insert or Upsert) * @returns Config object with promptOnMissingParentObjects=false and objects array */ private static buildSFDMUConfig; /** * Counts data rows in the source definition CSV. * * SFDMU import also processes the RecordType.csv sidecar used for lookup resolution, * so its "Processed N records" log lines cover multiple objects. Reading the source CSV * directly gives the exact definition count (CLI-3140). * * Returns 0 if the file is absent or unreadable. */ private static countCsvDataRows; /** * Parses a single CSV line into fields, handling RFC-4180 quoting and a leading UTF-8 BOM * on the first field of the first line (written by SFDMU). */ private static parseCSVLine; /** Serializes fields back to a CSV line, quoting every field for safety. */ private static serializeCSVLine; /** * Removes the specified columns from CSV content (header + corresponding value in every row). * Preserves the original line endings. Returns the original content unchanged if no matching * columns are found. */ private static stripColumns; /** * Executes the import operation. * * @param options - Import options * @returns ServiceResult containing import results or error details */ execute(options: ImportOptions): Promise>; /** Remove the temp directory, logging on failure instead of throwing (to avoid shadowing real errors in finally blocks). */ private cleanupTempDir; }