import type { BridgeManifest } from './contracts' import type { LeanixInventoryDryRun } from './to-leanix-inventory-dry-run' /** Summary report for the bridge run (no live sync) */ export interface BridgeReport { generatedAt: string projectId: string manifestVersion: string bridgeVersion: string mappingProfile: string counts: { entities: number views: number relations: number factSheets: number leanixRelations: number } artifacts: { manifest: string leanixDryRun: string } } /** Builds error message listing which coherence fields mismatched (projectId, mappingProfile). */ function buildCoherenceErrorMessage( manifest: BridgeManifest, leanixDryRun: LeanixInventoryDryRun, ): string { const mismatches: string[] = [] if (manifest.projectId !== leanixDryRun.projectId) { mismatches.push(`projectId (manifest: ${manifest.projectId}, leanixDryRun: ${leanixDryRun.projectId})`) } if (manifest.mappingProfile !== leanixDryRun.mappingProfile) { mismatches.push( `mappingProfile (manifest: ${manifest.mappingProfile}, leanixDryRun: ${leanixDryRun.mappingProfile})`, ) } return `Manifest and LeanIX dry-run must belong to the same run. Mismatch: ${mismatches.join('; ')}` } /** * Builds a summary report (counts, artifact names) from manifest and dry-run. Throws if projectId or mappingProfile differ. */ export function buildBridgeReport( manifest: BridgeManifest, leanixDryRun: LeanixInventoryDryRun, ): BridgeReport { if ( manifest.projectId !== leanixDryRun.projectId || manifest.mappingProfile !== leanixDryRun.mappingProfile ) { throw new Error(buildCoherenceErrorMessage(manifest, leanixDryRun)) } return { generatedAt: manifest.generatedAt, projectId: manifest.projectId, manifestVersion: manifest.manifestVersion, bridgeVersion: manifest.bridgeVersion, mappingProfile: manifest.mappingProfile, counts: { entities: Object.keys(manifest.entities).length, views: Object.keys(manifest.views).length, relations: manifest.relations.length, factSheets: leanixDryRun.factSheets.length, leanixRelations: leanixDryRun.relations.length, }, artifacts: { manifest: 'manifest.json', leanixDryRun: 'leanix-dry-run.json', }, } }