33 */
44
55import { getProjectLicense , findLicenseFilePath , identifyLicense } from './project_license.js' ;
6- import { licenseMapFromAnalysisReport } from './licenses_api.js' ;
6+ import { licenseMapFromAnalysisReport , getLicenseDetails } from './licenses_api.js' ;
77import { getCompatibility } from './compatibility.js' ;
88
99export { getProjectLicense , getProjectLicenseFromManifest , findLicenseFilePath , identifyLicense as identifyLicenseViaBackend } from './project_license.js' ;
@@ -39,15 +39,15 @@ export function extractPurlsFromSbom(sbomContent, excludeRoot = true) {
3939}
4040
4141/**
42- * Run full license check: resolve project license (with optional backend identification for LICENSE file ),
42+ * Run full license check: resolve project license (with backend identification and details ),
4343 * get dependency licenses from analysis report, and compute incompatibilities.
4444 *
4545 * @param {string } sbomContent - CycloneDX SBOM JSON string (the one sent for component analysis)
4646 * @param {string } manifestPath - path to manifest
4747 * @param {string } backendUrl - Trustify DA backend base URL
4848 * @param {import('../index.js').Options } [opts={}]
4949 * @param {import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport } [analysisResult] - analysis result that includes licenses array from backend
50- * @returns {Promise<{ projectLicenseFromManifest: string |null, projectLicenseFromFile: string |null, manifestVsFileMismatch : boolean, incompatibleDependencies: Array<{ purl: string, licenses: string[], category?: string, reason: string }>, dependencyLicenses: Array<{ purl: string, licenses: string[], category? : string }>, error?: string }> }
50+ * @returns {Promise<{ projectLicense: { manifest: Object |null, file: Object |null, mismatch : boolean } , incompatibleDependencies: Array<{ purl: string, licenses: string[], category?: string, reason: string }>, error?: string }> }
5151 */
5252export async function runLicenseCheck ( sbomContent , manifestPath , backendUrl , opts = { } , analysisResult = null ) {
5353 // Get project license from manifest (always available)
@@ -71,14 +71,35 @@ export async function runLicenseCheck(sbomContent, manifestPath, backendUrl, opt
7171 projectLicense . fromManifest . toLowerCase ( ) !== finalFromFile . toLowerCase ( )
7272 ) ;
7373
74+ // Fetch detailed license info from backend for both manifest and file licenses
75+ let manifestLicenseInfo = null ;
76+ let fileLicenseInfo = null ;
77+
78+ if ( projectLicense . fromManifest && backendUrl ) {
79+ try {
80+ manifestLicenseInfo = await getLicenseDetails ( projectLicense . fromManifest , backendUrl , opts ) ;
81+ } catch {
82+ // Backend might not have this license; keep as null
83+ }
84+ }
85+
86+ if ( finalFromFile && backendUrl ) {
87+ try {
88+ fileLicenseInfo = await getLicenseDetails ( finalFromFile , backendUrl , opts ) ;
89+ } catch {
90+ // Backend might not have this license; keep as null
91+ }
92+ }
93+
7494 const purls = extractPurlsFromSbom ( sbomContent , true ) ;
7595 if ( purls . length === 0 ) {
7696 return {
77- projectLicenseFromManifest : projectLicense . fromManifest ,
78- projectLicenseFromFile : finalFromFile ,
79- manifestVsFileMismatch : finalMismatch ,
80- incompatibleDependencies : [ ] ,
81- dependencyLicenses : [ ]
97+ projectLicense : {
98+ manifest : manifestLicenseInfo ,
99+ file : fileLicenseInfo ,
100+ mismatch : finalMismatch
101+ } ,
102+ incompatibleDependencies : [ ]
82103 } ;
83104 }
84105
@@ -87,23 +108,23 @@ export async function runLicenseCheck(sbomContent, manifestPath, backendUrl, opt
87108 if ( licenseByPurl . size === 0 && analysisResult ) {
88109 // No license data in analysis report - this might be expected for some backends
89110 return {
90- projectLicenseFromManifest : projectLicense . fromManifest ,
91- projectLicenseFromFile : finalFromFile ,
92- manifestVsFileMismatch : finalMismatch ,
111+ projectLicense : {
112+ manifest : manifestLicenseInfo ,
113+ file : fileLicenseInfo ,
114+ mismatch : finalMismatch
115+ } ,
93116 incompatibleDependencies : [ ] ,
94- dependencyLicenses : [ ] ,
95117 error : 'No license data available in analysis report'
96118 } ;
97119 }
98120
99- const projectLicenseForCheck = projectLicense . fromManifest || finalFromFile || null ;
100- const dependencyLicenses = [ ] ;
121+ // Use backend category from project license details (prefer manifest, fallback to file)
122+ const projectCategory = manifestLicenseInfo ?. category || fileLicenseInfo ?. category || null ;
101123 const incompatibleDependencies = [ ] ;
102124
103125 for ( const purl of purls ) {
104126 const entry = licenseByPurl . get ( purl ) || { licenses : [ ] , category : undefined } ;
105- dependencyLicenses . push ( { purl, licenses : entry . licenses , category : entry . category } ) ;
106- const status = getCompatibility ( projectLicenseForCheck , entry . licenses , entry . category ) ;
127+ const status = getCompatibility ( projectCategory , entry . category ) ;
107128 if ( status === 'incompatible' ) {
108129 incompatibleDependencies . push ( {
109130 purl,
@@ -115,10 +136,11 @@ export async function runLicenseCheck(sbomContent, manifestPath, backendUrl, opt
115136 }
116137
117138 return {
118- projectLicenseFromManifest : projectLicense . fromManifest ,
119- projectLicenseFromFile : finalFromFile ,
120- manifestVsFileMismatch : finalMismatch ,
121- incompatibleDependencies,
122- dependencyLicenses
139+ projectLicense : {
140+ manifest : manifestLicenseInfo ,
141+ file : fileLicenseInfo ,
142+ mismatch : finalMismatch
143+ } ,
144+ incompatibleDependencies
123145 } ;
124146}
0 commit comments