@trustify-da/trustify-da-javascript-client 0.3.0-ea.e12bc82 → 0.3.0-ea.e348975
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.
- package/README.md +193 -13
- package/dist/package.json +43 -27
- package/dist/src/analysis.d.ts +28 -5
- package/dist/src/analysis.js +99 -89
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +346 -9
- package/dist/src/cyclone_dx_sbom.d.ts +17 -3
- package/dist/src/cyclone_dx_sbom.js +56 -8
- package/dist/src/index.d.ts +202 -12
- package/dist/src/index.js +361 -9
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +103 -0
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +137 -0
- package/dist/src/license/licenses_api.d.ts +34 -0
- package/dist/src/license/licenses_api.js +98 -0
- package/dist/src/license/project_license.d.ts +20 -0
- package/dist/src/license/project_license.js +62 -0
- package/dist/src/oci_image/images.d.ts +4 -5
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +7 -7
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +18 -5
- package/dist/src/provider.js +33 -5
- package/dist/src/providers/base_java.d.ts +15 -15
- package/dist/src/providers/base_java.js +18 -44
- package/dist/src/providers/base_javascript.d.ts +45 -12
- package/dist/src/providers/base_javascript.js +138 -24
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +30 -13
- package/dist/src/providers/golang_gomodules.js +176 -121
- package/dist/src/providers/gomod_parser.d.ts +4 -0
- package/dist/src/providers/gomod_parser.js +16 -0
- package/dist/src/providers/java_gradle.d.ts +28 -3
- package/dist/src/providers/java_gradle.js +128 -4
- package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
- package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
- package/dist/src/providers/java_maven.d.ts +20 -5
- package/dist/src/providers/java_maven.js +198 -6
- package/dist/src/providers/javascript_bun.d.ts +10 -0
- package/dist/src/providers/javascript_bun.js +100 -0
- package/dist/src/providers/javascript_npm.d.ts +6 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +8 -4
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
- package/dist/src/providers/python_controller.d.ts +10 -3
- package/dist/src/providers/python_controller.js +122 -63
- package/dist/src/providers/python_pip.d.ts +16 -4
- package/dist/src/providers/python_pip.js +51 -58
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +269 -0
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +24 -0
- package/dist/src/providers/rust_cargo.d.ts +56 -0
- package/dist/src/providers/rust_cargo.js +641 -0
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +17 -2
- package/dist/src/sbom.js +16 -4
- package/dist/src/tools.d.ts +48 -6
- package/dist/src/tools.js +114 -1
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/dist/src/workspace.d.ts +70 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +44 -28
|
@@ -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
|
+
}
|
package/dist/src/sbom.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ export default class Sbom {
|
|
|
2
2
|
sbomModel: CycloneDxSbom;
|
|
3
3
|
/**
|
|
4
4
|
* @param {PackageURL} root - add main/root component for sbom
|
|
5
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
5
6
|
* @return Sbom
|
|
6
7
|
*/
|
|
7
|
-
addRoot(root: PackageURL): CycloneDxSbom;
|
|
8
|
+
addRoot(root: PackageURL, licenses?: string | any[]): CycloneDxSbom;
|
|
8
9
|
/**
|
|
9
10
|
* @return {{{"bom-ref": string, name, purl: string, type, version}}} root component of sbom.
|
|
10
11
|
*/
|
|
@@ -24,9 +25,14 @@ export default class Sbom {
|
|
|
24
25
|
/**
|
|
25
26
|
* @param {component} sourceRef current source Component ( Starting from root component by clients)
|
|
26
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
|
|
27
30
|
* @return Sbom
|
|
28
31
|
*/
|
|
29
|
-
addDependency(sourceRef: component, targetRef: PackageURL, scope
|
|
32
|
+
addDependency(sourceRef: component, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
|
|
33
|
+
alg: string;
|
|
34
|
+
content: string;
|
|
35
|
+
}>): CycloneDxSbom;
|
|
30
36
|
/**
|
|
31
37
|
* @return String sbom json in a string format
|
|
32
38
|
*/
|
|
@@ -43,6 +49,8 @@ export default class Sbom {
|
|
|
43
49
|
type: any;
|
|
44
50
|
version: any;
|
|
45
51
|
scope: any;
|
|
52
|
+
licenses?: any;
|
|
53
|
+
hashes?: any;
|
|
46
54
|
};
|
|
47
55
|
/** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
|
|
48
56
|
* @param {} component to search in its dependencies
|
|
@@ -51,6 +59,13 @@ export default class Sbom {
|
|
|
51
59
|
* @return {boolean}
|
|
52
60
|
*/
|
|
53
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;
|
|
54
69
|
/** Removes the root component from the sbom
|
|
55
70
|
*/
|
|
56
71
|
removeRootComponent(): void;
|
package/dist/src/sbom.js
CHANGED
|
@@ -12,10 +12,11 @@ export default class Sbom {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* @param {PackageURL} root - add main/root component for sbom
|
|
15
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
15
16
|
* @return Sbom
|
|
16
17
|
*/
|
|
17
|
-
addRoot(root) {
|
|
18
|
-
return this.sbomModel.addRoot(root);
|
|
18
|
+
addRoot(root, licenses) {
|
|
19
|
+
return this.sbomModel.addRoot(root, licenses);
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* @return {{{"bom-ref": string, name, purl: string, type, version}}} root component of sbom.
|
|
@@ -42,10 +43,12 @@ export default class Sbom {
|
|
|
42
43
|
/**
|
|
43
44
|
* @param {component} sourceRef current source Component ( Starting from root component by clients)
|
|
44
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
|
|
45
48
|
* @return Sbom
|
|
46
49
|
*/
|
|
47
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
48
|
-
return this.sbomModel.addDependency(sourceRef, targetRef, scope);
|
|
50
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
51
|
+
return this.sbomModel.addDependency(sourceRef, targetRef, scope, targetHashes);
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
54
|
* @return String sbom json in a string format
|
|
@@ -76,6 +79,15 @@ export default class Sbom {
|
|
|
76
79
|
checkIfPackageInsideDependsOnList(component, name) {
|
|
77
80
|
return this.sbomModel.checkIfPackageInsideDependsOnList(component, name);
|
|
78
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
|
+
}
|
|
79
91
|
/** Removes the root component from the sbom
|
|
80
92
|
*/
|
|
81
93
|
removeRootComponent() {
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="packageurl-js/src/package-url" />
|
|
3
1
|
/**
|
|
4
2
|
*
|
|
5
3
|
* @param {string} key to log its value from environment variables and from opts, if it exists
|
|
6
4
|
* @param {{}} [opts={}] different options of application, if key in it, log it.
|
|
7
5
|
* @param {string }defValue default value of key in case there is no option and environment variable values for key
|
|
8
6
|
*/
|
|
9
|
-
export function logValueFromObjects(key: string, opts?: {}
|
|
7
|
+
export function logValueFromObjects(key: string, opts?: {}, defValue: string): void;
|
|
10
8
|
/**
|
|
11
9
|
* Utility function will return the value for key from the environment variables,
|
|
12
10
|
* if not present will return the value for key from the opts objects only if it's a string,
|
|
@@ -17,7 +15,7 @@ export function logValueFromObjects(key: string, opts?: {} | undefined, defValue
|
|
|
17
15
|
* @returns {string|null} the value of the key found in the environment, options object, or the
|
|
18
16
|
* default supplied
|
|
19
17
|
*/
|
|
20
|
-
export function getCustom(key: string, def?: string | null
|
|
18
|
+
export function getCustom(key: string, def?: string | null, opts?: {}): string | null;
|
|
21
19
|
/**
|
|
22
20
|
* Utility function for looking up custom variable for a binary path.
|
|
23
21
|
* Will look in the environment variables (1) or in opts (2) for a key with TRUSTIFY_DA_x_PATH, x is an
|
|
@@ -28,7 +26,7 @@ export function getCustom(key: string, def?: string | null | undefined, opts?: {
|
|
|
28
26
|
* @returns {string|null} the value of the key found in the environment, options object, or the
|
|
29
27
|
* original name supplied
|
|
30
28
|
*/
|
|
31
|
-
export function getCustomPath(name: any, opts?: {}
|
|
29
|
+
export function getCustomPath(name: any, opts?: {}): string | null;
|
|
32
30
|
/**
|
|
33
31
|
* Utility function for determining whether wrappers for build tools such as gradlew/mvnw should be
|
|
34
32
|
* preferred over invoking the binary directly.
|
|
@@ -63,12 +61,56 @@ export function toPurlFromString(strPurl: any): PackageURL | null;
|
|
|
63
61
|
* @param {string} cwd - directory for which to find the root of the git repository.
|
|
64
62
|
*/
|
|
65
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;
|
|
66
90
|
/** this method invokes command string in a process in a synchronous way.
|
|
67
91
|
* @param {string} bin - the command to be invoked
|
|
68
92
|
* @param {Array<string>} args - the args to pass to the binary
|
|
69
93
|
* @param {import('child_process').ExecFileOptionsWithStringEncoding} [opts={}]
|
|
70
94
|
* @returns {string}
|
|
71
95
|
*/
|
|
72
|
-
export function invokeCommand(bin: string, args: Array<string>, opts?: import("child_process").ExecFileOptionsWithStringEncoding
|
|
96
|
+
export function invokeCommand(bin: string, args: Array<string>, opts?: import("child_process").ExecFileOptionsWithStringEncoding): string;
|
|
97
|
+
/**
|
|
98
|
+
* Adds proxy agent configuration to fetch options if a proxy URL is specified
|
|
99
|
+
* @param {RequestInit} options - The base fetch options
|
|
100
|
+
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
101
|
+
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
102
|
+
*/
|
|
103
|
+
export function addProxyAgent(options: RequestInit, opts: any): RequestInit;
|
|
104
|
+
/**
|
|
105
|
+
* Utility function for fetching vendor tokens
|
|
106
|
+
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
107
|
+
* @returns {{}}
|
|
108
|
+
*/
|
|
109
|
+
export function getTokenHeaders(opts?: any): {};
|
|
73
110
|
export const RegexNotToBeLogged: RegExp;
|
|
111
|
+
export const TRUSTIFY_DA_TOKEN_HEADER: "trust-da-token";
|
|
112
|
+
export const TRUSTIFY_DA_TELEMETRY_ID_HEADER: "telemetry-anonymous-id";
|
|
113
|
+
export const TRUSTIFY_DA_SOURCE_HEADER: "trust-da-source";
|
|
114
|
+
export const TRUSTIFY_DA_OPERATION_TYPE_HEADER: "trust-da-operation-type";
|
|
115
|
+
export const TRUSTIFY_DA_PACKAGE_MANAGER_HEADER: "trust-da-pkg-manager";
|
|
74
116
|
import { PackageURL } from "packageurl-js";
|
package/dist/src/tools.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { execFileSync } from "child_process";
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
2
4
|
import { EOL } from "os";
|
|
5
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
3
6
|
import { PackageURL } from "packageurl-js";
|
|
4
|
-
export const RegexNotToBeLogged = /TRUSTIFY_DA_.*
|
|
7
|
+
export const RegexNotToBeLogged = /TRUSTIFY_DA_(.*_)?TOKEN|ex-.*-token|trust-.*-token/;
|
|
5
8
|
/**
|
|
6
9
|
*
|
|
7
10
|
* @param {string} key to log its value from environment variables and from opts, if it exists
|
|
@@ -127,6 +130,62 @@ export function getGitRootDir(cwd) {
|
|
|
127
130
|
return undefined;
|
|
128
131
|
}
|
|
129
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Normalize a filesystem path, lowercasing on Windows for case-insensitive comparison.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} thePath
|
|
137
|
+
* @returns {string}
|
|
138
|
+
*/
|
|
139
|
+
export function normalizePath(thePath) {
|
|
140
|
+
const normalized = path.resolve(thePath).normalize();
|
|
141
|
+
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Walk up from `startDir` to `repoRoot` looking for an executable wrapper script.
|
|
145
|
+
*
|
|
146
|
+
* @param {string} startDir - Absolute directory to start from
|
|
147
|
+
* @param {string} wrapperName - Wrapper filename (e.g. `mvnw`, `gradlew`)
|
|
148
|
+
* @param {string} [repoRoot] - Stop boundary (defaults to git root or filesystem root)
|
|
149
|
+
* @returns {string | undefined}
|
|
150
|
+
*/
|
|
151
|
+
export function traverseForWrapper(startDir, wrapperName, repoRoot = undefined) {
|
|
152
|
+
const currentDir = normalizePath(startDir);
|
|
153
|
+
repoRoot = repoRoot || getGitRootDir(currentDir) || path.parse(currentDir).root;
|
|
154
|
+
const wrapperPath = path.join(currentDir, wrapperName);
|
|
155
|
+
try {
|
|
156
|
+
fs.accessSync(wrapperPath, fs.constants.X_OK);
|
|
157
|
+
return wrapperPath;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
const rootDir = path.parse(currentDir).root;
|
|
161
|
+
if (currentDir === repoRoot || currentDir === rootDir) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const parentDir = path.dirname(currentDir);
|
|
165
|
+
if (parentDir === currentDir || parentDir === rootDir) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
return traverseForWrapper(parentDir, wrapperName, repoRoot);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Resolve a build-tool binary, preferring a wrapper when configured.
|
|
173
|
+
*
|
|
174
|
+
* @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
|
|
175
|
+
* @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
|
|
176
|
+
* @param {string} startDir - Directory from which to start the wrapper search
|
|
177
|
+
* @param {import('./index.js').Options} [opts={}]
|
|
178
|
+
* @returns {string} Path to the resolved binary
|
|
179
|
+
*/
|
|
180
|
+
export function resolveBinary(globalBinary, localWrapper, startDir, opts = {}) {
|
|
181
|
+
if (getWrapperPreference(globalBinary, opts)) {
|
|
182
|
+
const wrapper = traverseForWrapper(startDir, localWrapper);
|
|
183
|
+
if (wrapper !== undefined) {
|
|
184
|
+
return wrapper;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return getCustomPath(globalBinary, opts);
|
|
188
|
+
}
|
|
130
189
|
/** this method invokes command string in a process in a synchronous way.
|
|
131
190
|
* @param {string} bin - the command to be invoked
|
|
132
191
|
* @param {Array<string>} args - the args to pass to the binary
|
|
@@ -157,3 +216,57 @@ export function invokeCommand(bin, args, opts = {}) {
|
|
|
157
216
|
};
|
|
158
217
|
return execFileSync(bin, args, { ...{ stdio: 'pipe', encoding: 'utf-8' }, ...opts });
|
|
159
218
|
}
|
|
219
|
+
export const TRUSTIFY_DA_TOKEN_HEADER = "trust-da-token";
|
|
220
|
+
export const TRUSTIFY_DA_TELEMETRY_ID_HEADER = "telemetry-anonymous-id";
|
|
221
|
+
export const TRUSTIFY_DA_SOURCE_HEADER = "trust-da-source";
|
|
222
|
+
export const TRUSTIFY_DA_OPERATION_TYPE_HEADER = "trust-da-operation-type";
|
|
223
|
+
export const TRUSTIFY_DA_PACKAGE_MANAGER_HEADER = "trust-da-pkg-manager";
|
|
224
|
+
/**
|
|
225
|
+
* Adds proxy agent configuration to fetch options if a proxy URL is specified
|
|
226
|
+
* @param {RequestInit} options - The base fetch options
|
|
227
|
+
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
228
|
+
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
229
|
+
*/
|
|
230
|
+
export function addProxyAgent(options, opts) {
|
|
231
|
+
const proxyUrl = getCustom('TRUSTIFY_DA_PROXY_URL', null, opts);
|
|
232
|
+
if (proxyUrl) {
|
|
233
|
+
options.agent = new HttpsProxyAgent(proxyUrl);
|
|
234
|
+
}
|
|
235
|
+
return options;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Utility function for fetching vendor tokens
|
|
239
|
+
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
240
|
+
* @returns {{}}
|
|
241
|
+
*/
|
|
242
|
+
export function getTokenHeaders(opts = {}) {
|
|
243
|
+
let headers = {};
|
|
244
|
+
setCustomHeader(TRUSTIFY_DA_TOKEN_HEADER, headers, 'TRUSTIFY_DA_TOKEN', opts);
|
|
245
|
+
setCustomHeader(TRUSTIFY_DA_SOURCE_HEADER, headers, 'TRUSTIFY_DA_SOURCE', opts);
|
|
246
|
+
setCustomHeader(TRUSTIFY_DA_OPERATION_TYPE_HEADER, headers, TRUSTIFY_DA_OPERATION_TYPE_HEADER.toUpperCase().replaceAll("-", "_"), opts);
|
|
247
|
+
setCustomHeader(TRUSTIFY_DA_PACKAGE_MANAGER_HEADER, headers, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER.toUpperCase().replaceAll("-", "_"), opts);
|
|
248
|
+
setCustomHeader(TRUSTIFY_DA_TELEMETRY_ID_HEADER, headers, 'TRUSTIFY_DA_TELEMETRY_ID', opts);
|
|
249
|
+
if (getCustom("TRUSTIFY_DA_DEBUG", null, opts) === "true") {
|
|
250
|
+
console.log("Headers Values to be sent to Trustify DA backend:" + EOL);
|
|
251
|
+
for (const headerKey in headers) {
|
|
252
|
+
if (!headerKey.match(RegexNotToBeLogged)) {
|
|
253
|
+
console.log(`${headerKey}: ${headers[headerKey]}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return headers;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* @param {string} headerName - the header name to populate in request
|
|
262
|
+
* @param headers
|
|
263
|
+
* @param {string} optsKey - key in the options object to use the value for
|
|
264
|
+
* @param {import("index.js").Options} [opts={}] - options input object to fetch header values from
|
|
265
|
+
* @private
|
|
266
|
+
*/
|
|
267
|
+
function setCustomHeader(headerName, headers, optsKey, opts) {
|
|
268
|
+
let customHeaderValue = getCustom(optsKey, null, opts);
|
|
269
|
+
if (customHeaderValue) {
|
|
270
|
+
headers[headerName] = customHeaderValue;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates dependency versions in a Maven pom.xml while preserving file formatting.
|
|
3
|
+
*
|
|
4
|
+
* Uses `fast-xml-parser` to understand the XML structure (dependencies and properties),
|
|
5
|
+
* then performs position-based string splice to replace version strings without altering
|
|
6
|
+
* any other formatting, comments, whitespace, or indentation.
|
|
7
|
+
*
|
|
8
|
+
* Supports `${property}` indirection: when a dependency's `<version>` is a property
|
|
9
|
+
* reference, the updater resolves the property chain (including recursive references)
|
|
10
|
+
* and updates the terminal property value in `<properties>` instead.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} pomContent - the raw pom.xml file content
|
|
13
|
+
* @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges -
|
|
14
|
+
* list of version changes to apply
|
|
15
|
+
* @returns {{content: string, applied: Array, skipped: Array}} the updated content and
|
|
16
|
+
* lists of applied and skipped changes
|
|
17
|
+
*/
|
|
18
|
+
export function updateMavenVersions(pomContent: string, versionChanges: Array<{
|
|
19
|
+
groupId: string;
|
|
20
|
+
artifactId: string;
|
|
21
|
+
newVersion: string;
|
|
22
|
+
}>): {
|
|
23
|
+
content: string;
|
|
24
|
+
applied: any[];
|
|
25
|
+
skipped: any[];
|
|
26
|
+
};
|