@trustify-da/trustify-da-javascript-client 0.3.0-ea.2ea1d77 → 0.3.0-ea.329b3cf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +75 -10
  2. package/dist/package.json +28 -24
  3. package/dist/src/analysis.d.ts +16 -7
  4. package/dist/src/analysis.js +36 -17
  5. package/dist/src/cli.js +109 -3
  6. package/dist/src/cyclone_dx_sbom.d.ts +14 -1
  7. package/dist/src/cyclone_dx_sbom.js +43 -8
  8. package/dist/src/index.d.ts +86 -11
  9. package/dist/src/index.js +97 -8
  10. package/dist/src/license/index.d.ts +3 -3
  11. package/dist/src/license/index.js +4 -1
  12. package/dist/src/license/license_utils.js +4 -1
  13. package/dist/src/license/licenses_api.d.ts +2 -2
  14. package/dist/src/oci_image/images.d.ts +1 -1
  15. package/dist/src/oci_image/images.js +15 -1
  16. package/dist/src/oci_image/utils.d.ts +5 -5
  17. package/dist/src/oci_image/utils.js +11 -2
  18. package/dist/src/provider.d.ts +4 -3
  19. package/dist/src/provider.js +12 -2
  20. package/dist/src/providers/base_java.d.ts +14 -12
  21. package/dist/src/providers/base_java.js +18 -44
  22. package/dist/src/providers/base_javascript.d.ts +36 -15
  23. package/dist/src/providers/base_javascript.js +100 -20
  24. package/dist/src/providers/base_pyproject.d.ts +158 -0
  25. package/dist/src/providers/base_pyproject.js +322 -0
  26. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  27. package/dist/src/providers/containerfile_parser.js +20 -0
  28. package/dist/src/providers/golang_gomodules.d.ts +23 -13
  29. package/dist/src/providers/golang_gomodules.js +165 -119
  30. package/dist/src/providers/gomod_parser.d.ts +4 -0
  31. package/dist/src/providers/gomod_parser.js +16 -0
  32. package/dist/src/providers/java_gradle.d.ts +19 -0
  33. package/dist/src/providers/java_gradle.js +116 -2
  34. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  35. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  36. package/dist/src/providers/java_maven.d.ts +10 -2
  37. package/dist/src/providers/java_maven.js +165 -1
  38. package/dist/src/providers/javascript_bun.d.ts +10 -0
  39. package/dist/src/providers/javascript_bun.js +100 -0
  40. package/dist/src/providers/javascript_npm.d.ts +6 -0
  41. package/dist/src/providers/javascript_npm.js +21 -0
  42. package/dist/src/providers/javascript_pnpm.js +6 -2
  43. package/dist/src/providers/manifest.d.ts +2 -0
  44. package/dist/src/providers/manifest.js +22 -4
  45. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  46. package/dist/src/providers/marker_evaluator.js +191 -0
  47. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  48. package/dist/src/providers/oci_dockerfile.js +177 -0
  49. package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
  50. package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
  51. package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
  52. package/dist/src/providers/python_controller.d.ts +5 -1
  53. package/dist/src/providers/python_controller.js +69 -8
  54. package/dist/src/providers/python_pip.d.ts +5 -0
  55. package/dist/src/providers/python_pip.js +6 -6
  56. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  57. package/dist/src/providers/python_pip_pyproject.js +146 -0
  58. package/dist/src/providers/python_poetry.d.ts +98 -0
  59. package/dist/src/providers/python_poetry.js +286 -0
  60. package/dist/src/providers/python_uv.d.ts +46 -0
  61. package/dist/src/providers/python_uv.js +269 -0
  62. package/dist/src/providers/rust_cargo.d.ts +6 -2
  63. package/dist/src/providers/rust_cargo.js +31 -4
  64. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  65. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  66. package/dist/src/remediation.d.ts +34 -0
  67. package/dist/src/remediation.js +321 -0
  68. package/dist/src/remediation_report.d.ts +40 -0
  69. package/dist/src/remediation_report.js +159 -0
  70. package/dist/src/sbom.d.ts +14 -1
  71. package/dist/src/sbom.js +13 -2
  72. package/dist/src/tools.d.ts +28 -2
  73. package/dist/src/tools.js +58 -0
  74. package/dist/src/updaters/maven_updater.d.ts +26 -0
  75. package/dist/src/updaters/maven_updater.js +322 -0
  76. package/dist/src/updaters/toml_updater.d.ts +33 -0
  77. package/dist/src/updaters/toml_updater.js +244 -0
  78. package/dist/src/workspace.d.ts +9 -0
  79. package/dist/src/workspace.js +1 -1
  80. package/package.json +29 -25
@@ -0,0 +1,321 @@
1
+ import { PackageURL } from 'packageurl-js';
2
+ /**
3
+ * Extracts actionable remediation instructions from a DA AnalysisReport response.
4
+ *
5
+ * Walks the provider/source/dependency/issue tree, collects fixedIn and trustedContent
6
+ * remediation data, applies provider priority resolution, and for the same dependency
7
+ * affected by multiple CVEs selects the highest fixedIn version from the highest-priority
8
+ * provider. Dependencies with no remediation data are skipped.
9
+ *
10
+ * @param {object} analysisReport - raw DA AnalysisReport JSON response
11
+ * @param {object} [options] - extraction options
12
+ * @param {string[]} [options.providerPriority] - provider names in descending priority order.
13
+ * The first entry has the highest priority. Providers not listed share the lowest priority.
14
+ * When omitted or empty, all providers are treated equally and the highest fix version wins.
15
+ * @returns {Array<{purl: string, groupId: string, artifactId: string, currentVersion: string, fixedInVersion: string, fixedInPurl: string, provider: string, source: string, advisories: Array<{id: string, url: string}>, severity: string, cves: string[]}>}
16
+ */
17
+ export function extractRemediations(analysisReport, options = {}) {
18
+ if (!analysisReport || !analysisReport.providers) {
19
+ return [];
20
+ }
21
+ const priorityMap = buildPriorityMap(options.providerPriority);
22
+ const remediationsByDep = new Map();
23
+ const rankByDep = new Map();
24
+ for (const [providerName, providerReport] of Object.entries(analysisReport.providers)) {
25
+ const providerRank = priorityMap.get(providerName) ?? 0;
26
+ extractFromSources(providerReport, providerName, providerRank, remediationsByDep, rankByDep);
27
+ extractFromRecommendations(providerReport, providerName, providerRank, remediationsByDep, rankByDep);
28
+ }
29
+ return Array.from(remediationsByDep.values())
30
+ .sort((a, b) => a.purl.localeCompare(b.purl));
31
+ }
32
+ /**
33
+ * Builds a priority lookup map from a provider priority array.
34
+ * First entry gets the highest numeric priority.
35
+ * @param {string[]} [providerPriority]
36
+ * @returns {Map<string, number>}
37
+ */
38
+ function buildPriorityMap(providerPriority) {
39
+ const map = new Map();
40
+ if (!providerPriority || providerPriority.length === 0) {
41
+ return map;
42
+ }
43
+ for (let i = 0; i < providerPriority.length; i++) {
44
+ map.set(providerPriority[i], providerPriority.length - i);
45
+ }
46
+ return map;
47
+ }
48
+ /**
49
+ * Extracts remediations from the sources/dependencies/issues tree of a provider report.
50
+ * @param {object} providerReport
51
+ * @param {string} providerName
52
+ * @param {number} providerRank - numeric priority rank for this provider
53
+ * @param {Map<string, object>} remediationsByDep - accumulator keyed by dependency PURL
54
+ * @param {Map<string, number>} rankByDep - tracks current winning rank per dependency
55
+ */
56
+ function extractFromSources(providerReport, providerName, providerRank, remediationsByDep, rankByDep) {
57
+ if (!providerReport.sources) {
58
+ return;
59
+ }
60
+ for (const [sourceName, sourceReport] of Object.entries(providerReport.sources)) {
61
+ if (!sourceReport.dependencies) {
62
+ continue;
63
+ }
64
+ for (const dep of sourceReport.dependencies) {
65
+ if (!dep.issues) {
66
+ continue;
67
+ }
68
+ for (const issue of dep.issues) {
69
+ processIssueRemediation(issue, dep, providerName, sourceName, providerRank, remediationsByDep, rankByDep);
70
+ }
71
+ }
72
+ }
73
+ }
74
+ /**
75
+ * Processes a single issue's remediation data and merges it into the accumulator.
76
+ * @param {object} issue - issue object containing remediation and CVE data
77
+ * @param {object} dep - dependency object containing the ref PURL
78
+ * @param {string} providerName
79
+ * @param {string} sourceName
80
+ * @param {number} providerRank
81
+ * @param {Map<string, object>} remediationsByDep
82
+ * @param {Map<string, number>} rankByDep
83
+ */
84
+ function processIssueRemediation(issue, dep, providerName, sourceName, providerRank, remediationsByDep, rankByDep) {
85
+ const fixedInPurl = getFixedInPurl(issue);
86
+ if (!fixedInPurl) {
87
+ return;
88
+ }
89
+ const depPurl = dep.ref;
90
+ if (!depPurl) {
91
+ return;
92
+ }
93
+ let parsedDep;
94
+ let parsedFix;
95
+ try {
96
+ parsedDep = PackageURL.fromString(depPurl);
97
+ parsedFix = PackageURL.fromString(fixedInPurl);
98
+ }
99
+ catch {
100
+ return;
101
+ }
102
+ const fixedInVersion = parsedFix.version;
103
+ if (!fixedInVersion) {
104
+ return;
105
+ }
106
+ const cveId = issue.id || issue.cve;
107
+ const severity = issue.severity || 'UNKNOWN';
108
+ const advisories = extractAdvisories(issue);
109
+ const existing = remediationsByDep.get(depPurl);
110
+ if (!existing) {
111
+ remediationsByDep.set(depPurl, {
112
+ purl: depPurl,
113
+ groupId: parsedDep.namespace || '',
114
+ artifactId: parsedDep.name,
115
+ currentVersion: parsedDep.version || '',
116
+ fixedInVersion,
117
+ fixedInPurl,
118
+ provider: providerName,
119
+ source: sourceName,
120
+ advisories,
121
+ severity: severity.toUpperCase(),
122
+ cves: cveId ? [cveId] : [],
123
+ });
124
+ rankByDep.set(depPurl, providerRank);
125
+ return;
126
+ }
127
+ if (cveId && !existing.cves.includes(cveId)) {
128
+ existing.cves.push(cveId);
129
+ }
130
+ mergeAdvisories(existing.advisories, advisories);
131
+ const existingRank = rankByDep.get(depPurl);
132
+ if (providerRank > existingRank) {
133
+ existing.fixedInVersion = fixedInVersion;
134
+ existing.fixedInPurl = fixedInPurl;
135
+ existing.provider = providerName;
136
+ existing.source = sourceName;
137
+ existing.severity = higherSeverity(existing.severity, severity);
138
+ rankByDep.set(depPurl, providerRank);
139
+ }
140
+ else if (providerRank === existingRank) {
141
+ if (compareVersions(fixedInVersion, existing.fixedInVersion) > 0) {
142
+ existing.fixedInVersion = fixedInVersion;
143
+ existing.fixedInPurl = fixedInPurl;
144
+ existing.provider = providerName;
145
+ existing.source = sourceName;
146
+ }
147
+ existing.severity = higherSeverity(existing.severity, severity);
148
+ }
149
+ }
150
+ /**
151
+ * Extracts remediations from the recommendations section of a provider report.
152
+ * Merges CVEs and advisories into existing entries when present.
153
+ * @param {object} providerReport
154
+ * @param {string} providerName
155
+ * @param {number} providerRank
156
+ * @param {Map<string, object>} remediationsByDep
157
+ * @param {Map<string, number>} rankByDep
158
+ */
159
+ function extractFromRecommendations(providerReport, providerName, providerRank, remediationsByDep, rankByDep) {
160
+ if (!providerReport.recommendations || !providerReport.recommendations.dependencies) {
161
+ return;
162
+ }
163
+ for (const dep of providerReport.recommendations.dependencies) {
164
+ if (!dep.recommendation || !dep.ref) {
165
+ continue;
166
+ }
167
+ const recommendedPurl = dep.recommendation.ref || dep.recommendation;
168
+ if (typeof recommendedPurl !== 'string') {
169
+ continue;
170
+ }
171
+ let parsedDep;
172
+ let parsedRec;
173
+ try {
174
+ parsedDep = PackageURL.fromString(dep.ref);
175
+ parsedRec = PackageURL.fromString(recommendedPurl);
176
+ }
177
+ catch {
178
+ continue;
179
+ }
180
+ const fixedInVersion = parsedRec.version;
181
+ if (!fixedInVersion) {
182
+ continue;
183
+ }
184
+ const depPurl = dep.ref;
185
+ const existing = remediationsByDep.get(depPurl);
186
+ if (!existing) {
187
+ remediationsByDep.set(depPurl, {
188
+ purl: depPurl,
189
+ groupId: parsedDep.namespace || '',
190
+ artifactId: parsedDep.name,
191
+ currentVersion: parsedDep.version || '',
192
+ fixedInVersion,
193
+ fixedInPurl: recommendedPurl,
194
+ provider: providerName,
195
+ source: 'recommendation',
196
+ advisories: [],
197
+ severity: 'UNKNOWN',
198
+ cves: [],
199
+ });
200
+ rankByDep.set(depPurl, providerRank);
201
+ continue;
202
+ }
203
+ const existingRank = rankByDep.get(depPurl);
204
+ if (providerRank > existingRank) {
205
+ existing.fixedInVersion = fixedInVersion;
206
+ existing.fixedInPurl = recommendedPurl;
207
+ existing.provider = providerName;
208
+ existing.source = 'recommendation';
209
+ rankByDep.set(depPurl, providerRank);
210
+ }
211
+ else if (providerRank === existingRank) {
212
+ if (compareVersions(fixedInVersion, existing.fixedInVersion) > 0) {
213
+ existing.fixedInVersion = fixedInVersion;
214
+ existing.fixedInPurl = recommendedPurl;
215
+ existing.provider = providerName;
216
+ existing.source = 'recommendation';
217
+ }
218
+ }
219
+ }
220
+ }
221
+ /**
222
+ * Gets the fixedIn PURL from an issue's remediation, preferring trustedContent.
223
+ * @param {object} issue
224
+ * @returns {string|undefined}
225
+ */
226
+ function getFixedInPurl(issue) {
227
+ if (!issue.remediation) {
228
+ return undefined;
229
+ }
230
+ if (issue.remediation.trustedContent && issue.remediation.trustedContent.ref) {
231
+ return issue.remediation.trustedContent.ref;
232
+ }
233
+ if (issue.remediation.fixedIn) {
234
+ return issue.remediation.fixedIn;
235
+ }
236
+ return undefined;
237
+ }
238
+ /**
239
+ * Extracts advisory objects from an issue.
240
+ * @param {object} issue
241
+ * @returns {Array<{id: string, url: string}>}
242
+ */
243
+ function extractAdvisories(issue) {
244
+ const advisories = [];
245
+ if (issue.remediation && issue.remediation.trustedContent) {
246
+ const tc = issue.remediation.trustedContent;
247
+ if (tc.advisory) {
248
+ advisories.push({
249
+ id: tc.advisory.id || tc.advisory,
250
+ url: tc.advisory.url || '',
251
+ });
252
+ }
253
+ }
254
+ if (issue.advisories) {
255
+ for (const adv of issue.advisories) {
256
+ advisories.push({
257
+ id: adv.id || adv,
258
+ url: adv.url || '',
259
+ });
260
+ }
261
+ }
262
+ return advisories;
263
+ }
264
+ /**
265
+ * Merges new advisories into existing list, avoiding duplicates by id.
266
+ * @param {Array<{id: string, url: string}>} existing
267
+ * @param {Array<{id: string, url: string}>} incoming
268
+ */
269
+ function mergeAdvisories(existing, incoming) {
270
+ const seen = new Set(existing.map(a => a.id));
271
+ for (const adv of incoming) {
272
+ if (!seen.has(adv.id)) {
273
+ existing.push(adv);
274
+ seen.add(adv.id);
275
+ }
276
+ }
277
+ }
278
+ /**
279
+ * Compares two version strings segment by segment.
280
+ * Returns positive if a > b, negative if a < b, zero if equal.
281
+ * Falls back to lexicographic comparison for non-numeric segments.
282
+ * @param {string} a
283
+ * @param {string} b
284
+ * @returns {number}
285
+ */
286
+ function compareVersions(a, b) {
287
+ const partsA = a.split('.');
288
+ const partsB = b.split('.');
289
+ const len = Math.max(partsA.length, partsB.length);
290
+ for (let i = 0; i < len; i++) {
291
+ const segA = partsA[i] || '';
292
+ const segB = partsB[i] || '';
293
+ const numA = Number(segA);
294
+ const numB = Number(segB);
295
+ if (Number.isFinite(numA) && Number.isFinite(numB)) {
296
+ const diff = numA - numB;
297
+ if (diff !== 0)
298
+ return diff;
299
+ }
300
+ else {
301
+ const cmp = segA.localeCompare(segB);
302
+ if (cmp !== 0)
303
+ return cmp;
304
+ }
305
+ }
306
+ return 0;
307
+ }
308
+ export const SEVERITY_ORDER = ['UNKNOWN', 'LOW', 'MEDIUM', 'HIGH', 'CRITICAL'];
309
+ /**
310
+ * Returns the higher of two severity strings, normalized to uppercase.
311
+ * @param {string} a
312
+ * @param {string} b
313
+ * @returns {string}
314
+ */
315
+ function higherSeverity(a, b) {
316
+ const upperA = a.toUpperCase();
317
+ const upperB = b.toUpperCase();
318
+ const indexA = SEVERITY_ORDER.indexOf(upperA);
319
+ const indexB = SEVERITY_ORDER.indexOf(upperB);
320
+ return indexA >= indexB ? upperA : upperB;
321
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Generates a formatted report from an array of remediation entries.
3
+ *
4
+ * @param {Array<{purl: string, groupId: string, artifactId: string, currentVersion: string,
5
+ * fixedInVersion: string, fixedInPurl: string, provider: string, source: string,
6
+ * advisories: Array<{id: string, url: string}>, severity: string, cves: string[]}>} remediations
7
+ * @param {object} [options]
8
+ * @param {'dependency'|'bundle'} [options.groupBy='dependency'] - grouping strategy
9
+ * @param {'markdown'|'json'} [options.format='markdown'] - output format
10
+ * @param {boolean} [options.dryRun=false] - when true, produces tabular summary
11
+ * @returns {string}
12
+ */
13
+ export function generateReport(remediations: Array<{
14
+ purl: string;
15
+ groupId: string;
16
+ artifactId: string;
17
+ currentVersion: string;
18
+ fixedInVersion: string;
19
+ fixedInPurl: string;
20
+ provider: string;
21
+ source: string;
22
+ advisories: Array<{
23
+ id: string;
24
+ url: string;
25
+ }>;
26
+ severity: string;
27
+ cves: string[];
28
+ }>, options?: {
29
+ groupBy?: "dependency" | "bundle" | undefined;
30
+ format?: "markdown" | "json" | undefined;
31
+ dryRun?: boolean | undefined;
32
+ }): string;
33
+ /**
34
+ * Generates a deterministic deduplication key for a remediation entry.
35
+ * Suitable for checking existing PR titles or branch names.
36
+ *
37
+ * @param {object} remediation - a single remediation entry
38
+ * @returns {string} stable key in the form `groupId:artifactId:newVersion`
39
+ */
40
+ export function generateDeduplicationKey(remediation: object): string;
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Report generator that transforms remediation extractor output into structured
3
+ * markdown for PR bodies, CLI dry-run output, and JSON.
4
+ */
5
+ import { SEVERITY_ORDER } from './remediation.js';
6
+ /**
7
+ * Generates a formatted report from an array of remediation entries.
8
+ *
9
+ * @param {Array<{purl: string, groupId: string, artifactId: string, currentVersion: string,
10
+ * fixedInVersion: string, fixedInPurl: string, provider: string, source: string,
11
+ * advisories: Array<{id: string, url: string}>, severity: string, cves: string[]}>} remediations
12
+ * @param {object} [options]
13
+ * @param {'dependency'|'bundle'} [options.groupBy='dependency'] - grouping strategy
14
+ * @param {'markdown'|'json'} [options.format='markdown'] - output format
15
+ * @param {boolean} [options.dryRun=false] - when true, produces tabular summary
16
+ * @returns {string}
17
+ */
18
+ export function generateReport(remediations, options = {}) {
19
+ const { groupBy = 'dependency', format = 'markdown', dryRun = false } = options;
20
+ if (!remediations || remediations.length === 0) {
21
+ return format === 'json' ? '[]' : 'No remediations found.';
22
+ }
23
+ if (format === 'json') {
24
+ return JSON.stringify(remediations, null, '\t');
25
+ }
26
+ if (dryRun) {
27
+ return generateDryRunReport(remediations);
28
+ }
29
+ if (groupBy === 'bundle') {
30
+ return generateBundledReport(remediations);
31
+ }
32
+ return generatePerDependencyReport(remediations);
33
+ }
34
+ /**
35
+ * Generates a per-dependency markdown report with one section per remediation entry.
36
+ * @param {Array<object>} remediations
37
+ * @returns {string}
38
+ */
39
+ function generatePerDependencyReport(remediations) {
40
+ const sections = remediations.map(rem => {
41
+ const depName = rem.groupId
42
+ ? `${rem.groupId}:${rem.artifactId}`
43
+ : rem.artifactId;
44
+ const lines = [
45
+ `## Security Update: ${depName} ${rem.currentVersion} → ${rem.fixedInVersion}`,
46
+ '',
47
+ `**Provider:** ${rem.provider} | **Source:** ${rem.source}`,
48
+ '',
49
+ ];
50
+ if (rem.cves && rem.cves.length > 0) {
51
+ lines.push('### Vulnerabilities resolved');
52
+ lines.push('');
53
+ lines.push('| CVE | Severity | Advisory |');
54
+ lines.push('| --- | --- | --- |');
55
+ const advisoryLinks = formatAdvisoryLinks(rem.advisories);
56
+ for (const cve of rem.cves) {
57
+ lines.push(`| ${cve} | ${rem.severity} | ${advisoryLinks} |`);
58
+ }
59
+ }
60
+ return lines.join('\n');
61
+ });
62
+ return sections.join('\n\n');
63
+ }
64
+ /**
65
+ * Generates a bundled markdown report grouping all remediations by severity.
66
+ * @param {Array<object>} remediations
67
+ * @returns {string}
68
+ */
69
+ function generateBundledReport(remediations) {
70
+ const lines = ['# Security Update Summary', ''];
71
+ const bySeverity = groupBySeverity(remediations);
72
+ for (const severity of [...SEVERITY_ORDER].reverse()) {
73
+ const group = bySeverity.get(severity);
74
+ if (!group || group.length === 0) {
75
+ continue;
76
+ }
77
+ lines.push(`## ${severity}`);
78
+ lines.push('');
79
+ lines.push('| Dependency | Current | Fixed | Provider | CVEs | Advisory |');
80
+ lines.push('| --- | --- | --- | --- | --- | --- |');
81
+ for (const rem of group) {
82
+ const depName = rem.groupId
83
+ ? `${rem.groupId}:${rem.artifactId}`
84
+ : rem.artifactId;
85
+ const cves = (rem.cves || []).join(', ');
86
+ const advisoryLinks = formatAdvisoryLinks(rem.advisories);
87
+ lines.push(`| ${depName} | ${rem.currentVersion} | ${rem.fixedInVersion}`
88
+ + ` | ${rem.provider} | ${cves} | ${advisoryLinks} |`);
89
+ }
90
+ lines.push('');
91
+ }
92
+ return lines.join('\n').trimEnd();
93
+ }
94
+ /**
95
+ * Generates a tabular dry-run summary of proposed changes.
96
+ * @param {Array<object>} remediations
97
+ * @returns {string}
98
+ */
99
+ function generateDryRunReport(remediations) {
100
+ const lines = [
101
+ 'Proposed dependency updates:',
102
+ '',
103
+ '| Dependency | Current | Fixed | Severity | Provider |',
104
+ '| --- | --- | --- | --- | --- |',
105
+ ];
106
+ for (const rem of remediations) {
107
+ const depName = rem.groupId
108
+ ? `${rem.groupId}:${rem.artifactId}`
109
+ : rem.artifactId;
110
+ lines.push(`| ${depName} | ${rem.currentVersion} | ${rem.fixedInVersion}`
111
+ + ` | ${rem.severity} | ${rem.provider} |`);
112
+ }
113
+ return lines.join('\n');
114
+ }
115
+ /**
116
+ * Groups remediations by their severity.
117
+ * @param {Array<object>} remediations
118
+ * @returns {Map<string, Array<object>>}
119
+ */
120
+ function groupBySeverity(remediations) {
121
+ const map = new Map();
122
+ for (const severity of SEVERITY_ORDER) {
123
+ map.set(severity, []);
124
+ }
125
+ for (const rem of remediations) {
126
+ const sev = rem.severity || 'UNKNOWN';
127
+ if (!map.has(sev)) {
128
+ map.set(sev, []);
129
+ }
130
+ map.get(sev).push(rem);
131
+ }
132
+ return map;
133
+ }
134
+ /**
135
+ * Formats advisory entries into markdown links or plain text.
136
+ * @param {Array<{id: string, url: string}>} advisories
137
+ * @returns {string}
138
+ */
139
+ function formatAdvisoryLinks(advisories) {
140
+ if (!advisories || advisories.length === 0) {
141
+ return '-';
142
+ }
143
+ return advisories
144
+ .map(adv => adv.url ? `[${adv.id}](${adv.url})` : adv.id)
145
+ .join(', ');
146
+ }
147
+ /**
148
+ * Generates a deterministic deduplication key for a remediation entry.
149
+ * Suitable for checking existing PR titles or branch names.
150
+ *
151
+ * @param {object} remediation - a single remediation entry
152
+ * @returns {string} stable key in the form `groupId:artifactId:newVersion`
153
+ */
154
+ export function generateDeduplicationKey(remediation) {
155
+ const group = remediation.groupId || '';
156
+ const artifact = remediation.artifactId || '';
157
+ const version = remediation.fixedInVersion || '';
158
+ return `${group}:${artifact}:${version}`;
159
+ }
@@ -25,9 +25,14 @@ export default class Sbom {
25
25
  /**
26
26
  * @param {component} sourceRef current source Component ( Starting from root component by clients)
27
27
  * @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
28
+ * @param {string} [scope] - Scope of the dependency
29
+ * @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
28
30
  * @return Sbom
29
31
  */
30
- addDependency(sourceRef: component, targetRef: PackageURL, scope: any): CycloneDxSbom;
32
+ addDependency(sourceRef: component, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
33
+ alg: string;
34
+ content: string;
35
+ }>): CycloneDxSbom;
31
36
  /**
32
37
  * @return String sbom json in a string format
33
38
  */
@@ -45,6 +50,7 @@ export default class Sbom {
45
50
  version: any;
46
51
  scope: any;
47
52
  licenses?: any;
53
+ hashes?: any;
48
54
  };
49
55
  /** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
50
56
  * @param {} component to search in its dependencies
@@ -53,6 +59,13 @@ export default class Sbom {
53
59
  * @return {boolean}
54
60
  */
55
61
  checkIfPackageInsideDependsOnList(component: any, name: string): boolean;
62
+ /**
63
+ * Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
64
+ * @param {PackageURL} sourceRef - The source component to check
65
+ * @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
66
+ * @return {boolean}
67
+ */
68
+ checkDependsOnByPurlPrefix(sourceRef: PackageURL, purlPrefix: string): boolean;
56
69
  /** Removes the root component from the sbom
57
70
  */
58
71
  removeRootComponent(): void;
package/dist/src/sbom.js CHANGED
@@ -43,10 +43,12 @@ export default class Sbom {
43
43
  /**
44
44
  * @param {component} sourceRef current source Component ( Starting from root component by clients)
45
45
  * @param {PackageURL} targetRef current dependency to add to Dependencies list of component sourceRef
46
+ * @param {string} [scope] - Scope of the dependency
47
+ * @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
46
48
  * @return Sbom
47
49
  */
48
- addDependency(sourceRef, targetRef, scope) {
49
- return this.sbomModel.addDependency(sourceRef, targetRef, scope);
50
+ addDependency(sourceRef, targetRef, scope, targetHashes) {
51
+ return this.sbomModel.addDependency(sourceRef, targetRef, scope, targetHashes);
50
52
  }
51
53
  /**
52
54
  * @return String sbom json in a string format
@@ -77,6 +79,15 @@ export default class Sbom {
77
79
  checkIfPackageInsideDependsOnList(component, name) {
78
80
  return this.sbomModel.checkIfPackageInsideDependsOnList(component, name);
79
81
  }
82
+ /**
83
+ * Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
84
+ * @param {PackageURL} sourceRef - The source component to check
85
+ * @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
86
+ * @return {boolean}
87
+ */
88
+ checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
89
+ return this.sbomModel.checkDependsOnByPurlPrefix(sourceRef, purlPrefix);
90
+ }
80
91
  /** Removes the root component from the sbom
81
92
  */
82
93
  removeRootComponent() {
@@ -61,6 +61,32 @@ export function toPurlFromString(strPurl: any): PackageURL | null;
61
61
  * @param {string} cwd - directory for which to find the root of the git repository.
62
62
  */
63
63
  export function getGitRootDir(cwd: string): string | undefined;
64
+ /**
65
+ * Normalize a filesystem path, lowercasing on Windows for case-insensitive comparison.
66
+ *
67
+ * @param {string} thePath
68
+ * @returns {string}
69
+ */
70
+ export function normalizePath(thePath: string): string;
71
+ /**
72
+ * Walk up from `startDir` to `repoRoot` looking for an executable wrapper script.
73
+ *
74
+ * @param {string} startDir - Absolute directory to start from
75
+ * @param {string} wrapperName - Wrapper filename (e.g. `mvnw`, `gradlew`)
76
+ * @param {string} [repoRoot] - Stop boundary (defaults to git root or filesystem root)
77
+ * @returns {string | undefined}
78
+ */
79
+ export function traverseForWrapper(startDir: string, wrapperName: string, repoRoot?: string): string | undefined;
80
+ /**
81
+ * Resolve a build-tool binary, preferring a wrapper when configured.
82
+ *
83
+ * @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
84
+ * @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
85
+ * @param {string} startDir - Directory from which to start the wrapper search
86
+ * @param {import('./index.js').Options} [opts={}]
87
+ * @returns {string} Path to the resolved binary
88
+ */
89
+ export function resolveBinary(globalBinary: string, localWrapper: string, startDir: string, opts?: import("./index.js").Options): string;
64
90
  /** this method invokes command string in a process in a synchronous way.
65
91
  * @param {string} bin - the command to be invoked
66
92
  * @param {Array<string>} args - the args to pass to the binary
@@ -74,13 +100,13 @@ export function invokeCommand(bin: string, args: Array<string>, opts?: import("c
74
100
  * @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
75
101
  * @returns {RequestInit} The fetch options with proxy agent if applicable
76
102
  */
77
- export function addProxyAgent(options: RequestInit, opts: import("index.js").Options): RequestInit;
103
+ export function addProxyAgent(options: RequestInit, opts: any): RequestInit;
78
104
  /**
79
105
  * Utility function for fetching vendor tokens
80
106
  * @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
81
107
  * @returns {{}}
82
108
  */
83
- export function getTokenHeaders(opts?: import("index.js").Options): {};
109
+ export function getTokenHeaders(opts?: any): {};
84
110
  export const RegexNotToBeLogged: RegExp;
85
111
  export const TRUSTIFY_DA_TOKEN_HEADER: "trust-da-token";
86
112
  export const TRUSTIFY_DA_TELEMETRY_ID_HEADER: "telemetry-anonymous-id";