@trustify-da/trustify-da-javascript-client 0.3.0-ea.7ed8d8c → 0.3.0-ea.7ee4047
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 +388 -20
- package/dist/package.json +39 -26
- package/dist/src/analysis.d.ts +58 -20
- package/dist/src/analysis.js +134 -78
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +427 -12
- package/dist/src/config.d.ts +120 -0
- package/dist/src/config.js +260 -0
- package/dist/src/cyclone_dx_sbom.d.ts +30 -2
- package/dist/src/cyclone_dx_sbom.js +95 -9
- package/dist/src/index.d.ts +154 -16
- package/dist/src/index.js +372 -36
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +106 -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 +1 -1
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.d.ts +16 -3
- package/dist/src/provider.js +33 -5
- package/dist/src/providers/base_java.d.ts +67 -12
- package/dist/src/providers/base_java.js +82 -61
- package/dist/src/providers/base_javascript.d.ts +99 -12
- package/dist/src/providers/base_javascript.js +244 -28
- 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 +219 -122
- 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 +73 -0
- package/dist/src/providers/java_gradle.js +331 -23
- 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 +44 -9
- package/dist/src/providers/java_maven.js +299 -13
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -0
- package/dist/src/providers/javascript_npm.js +61 -1
- package/dist/src/providers/javascript_pnpm.d.ts +14 -1
- package/dist/src/providers/javascript_pnpm.js +55 -5
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +28 -7
- 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 +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +69 -8
- package/dist/src/providers/python_pip.d.ts +12 -0
- package/dist/src/providers/python_pip.js +18 -8
- 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 +275 -0
- package/dist/src/providers/requirements_parser.js +6 -9
- package/dist/src/providers/rust_cargo.d.ts +56 -0
- package/dist/src/providers/rust_cargo.js +682 -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 +107 -0
- package/dist/src/remediate.js +244 -0
- package/dist/src/remediation.d.ts +81 -0
- package/dist/src/remediation.js +475 -0
- package/dist/src/remediation_report.d.ts +23 -0
- package/dist/src/remediation_report.js +180 -0
- package/dist/src/sbom.d.ts +28 -2
- package/dist/src/sbom.js +26 -4
- package/dist/src/tools.d.ts +53 -11
- package/dist/src/tools.js +147 -13
- package/dist/src/updaters/maven_updater.d.ts +58 -0
- package/dist/src/updaters/maven_updater.js +345 -0
- package/dist/src/updaters/toml_updater.d.ts +62 -0
- package/dist/src/updaters/toml_updater.js +276 -0
- package/dist/src/workspace.d.ts +71 -0
- package/dist/src/workspace.js +257 -0
- package/package.json +40 -27
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,25 @@ 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;
|
|
36
|
+
/**
|
|
37
|
+
* Attach hashes to existing components by matching their PURL. Post-processing
|
|
38
|
+
* step used by ecosystem-specific providers (e.g. Maven) to enrich the SBOM
|
|
39
|
+
* with artifact hashes without leaking their concern into the shared parser.
|
|
40
|
+
* @param {Map<string, Array<{alg: string, content: string}>>} hashMap - PURL→hashes map
|
|
41
|
+
* @return {Sbom}
|
|
42
|
+
*/
|
|
43
|
+
attachHashes(hashMap: Map<string, Array<{
|
|
44
|
+
alg: string;
|
|
45
|
+
content: string;
|
|
46
|
+
}>>): Sbom;
|
|
30
47
|
/**
|
|
31
48
|
* @return String sbom json in a string format
|
|
32
49
|
*/
|
|
@@ -43,6 +60,8 @@ export default class Sbom {
|
|
|
43
60
|
type: any;
|
|
44
61
|
version: any;
|
|
45
62
|
scope: any;
|
|
63
|
+
licenses?: any;
|
|
64
|
+
hashes?: any;
|
|
46
65
|
};
|
|
47
66
|
/** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
|
|
48
67
|
* @param {} component to search in its dependencies
|
|
@@ -51,6 +70,13 @@ export default class Sbom {
|
|
|
51
70
|
* @return {boolean}
|
|
52
71
|
*/
|
|
53
72
|
checkIfPackageInsideDependsOnList(component: any, name: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
75
|
+
* @param {PackageURL} sourceRef - The source component to check
|
|
76
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
77
|
+
* @return {boolean}
|
|
78
|
+
*/
|
|
79
|
+
checkDependsOnByPurlPrefix(sourceRef: PackageURL, purlPrefix: string): boolean;
|
|
54
80
|
/** Removes the root component from the sbom
|
|
55
81
|
*/
|
|
56
82
|
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,22 @@ 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);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Attach hashes to existing components by matching their PURL. Post-processing
|
|
55
|
+
* step used by ecosystem-specific providers (e.g. Maven) to enrich the SBOM
|
|
56
|
+
* with artifact hashes without leaking their concern into the shared parser.
|
|
57
|
+
* @param {Map<string, Array<{alg: string, content: string}>>} hashMap - PURL→hashes map
|
|
58
|
+
* @return {Sbom}
|
|
59
|
+
*/
|
|
60
|
+
attachHashes(hashMap) {
|
|
61
|
+
return this.sbomModel.attachHashes(hashMap);
|
|
49
62
|
}
|
|
50
63
|
/**
|
|
51
64
|
* @return String sbom json in a string format
|
|
@@ -76,6 +89,15 @@ export default class Sbom {
|
|
|
76
89
|
checkIfPackageInsideDependsOnList(component, name) {
|
|
77
90
|
return this.sbomModel.checkIfPackageInsideDependsOnList(component, name);
|
|
78
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
|
|
94
|
+
* @param {PackageURL} sourceRef - The source component to check
|
|
95
|
+
* @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
|
|
96
|
+
* @return {boolean}
|
|
97
|
+
*/
|
|
98
|
+
checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
|
|
99
|
+
return this.sbomModel.checkDependsOnByPurlPrefix(sourceRef, purlPrefix);
|
|
100
|
+
}
|
|
79
101
|
/** Removes the root component from the sbom
|
|
80
102
|
*/
|
|
81
103
|
removeRootComponent() {
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -6,24 +6,22 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export function logValueFromObjects(key: string, opts?: {}, defValue: string): void;
|
|
8
8
|
/**
|
|
9
|
-
* Utility function
|
|
10
|
-
*
|
|
11
|
-
* if not present, or not string will return the default value supplied which default to null.
|
|
9
|
+
* Utility function returns the value for key from opts, then environment variables,
|
|
10
|
+
* then the supplied default. Values from opts are used only if they are strings.
|
|
12
11
|
* @param {string} key the key to look for in the environment variables and the opts object
|
|
13
12
|
* @param {string|null} [def=null] the value to return if nothing else found
|
|
14
|
-
* @param {{}} [opts={}] the options object to
|
|
15
|
-
* @returns {string|null} the value of the key found in the
|
|
13
|
+
* @param {{}} [opts={}] the options object to check before the environment
|
|
14
|
+
* @returns {string|null} the value of the key found in the options object, environment, or the
|
|
16
15
|
* default supplied
|
|
17
16
|
*/
|
|
18
17
|
export function getCustom(key: string, def?: string | null, opts?: {}): string | null;
|
|
19
18
|
/**
|
|
20
19
|
* Utility function for looking up custom variable for a binary path.
|
|
21
|
-
*
|
|
22
|
-
* uppercase version of
|
|
23
|
-
* found.
|
|
20
|
+
* Looks in opts, then environment variables, for a key with TRUSTIFY_DA_x_PATH, where x is an
|
|
21
|
+
* uppercase version of the supplied name. The name is returned if neither contains the key.
|
|
24
22
|
* @param name the binary name to look for, will be returned as value in nothing else found
|
|
25
|
-
* @param {{}} [opts={}] the options object to
|
|
26
|
-
* @returns {string|null} the value of the key found in the
|
|
23
|
+
* @param {{}} [opts={}] the options object to check before the environment
|
|
24
|
+
* @returns {string|null} the value of the key found in the options object, environment, or the
|
|
27
25
|
* original name supplied
|
|
28
26
|
*/
|
|
29
27
|
export function getCustomPath(name: any, opts?: {}): string | null;
|
|
@@ -31,7 +29,7 @@ export function getCustomPath(name: any, opts?: {}): string | null;
|
|
|
31
29
|
* Utility function for determining whether wrappers for build tools such as gradlew/mvnw should be
|
|
32
30
|
* preferred over invoking the binary directly.
|
|
33
31
|
* @param {string} name - binary for which to search for its wrapper
|
|
34
|
-
* @param {{}} opts - the options object to
|
|
32
|
+
* @param {{}} opts - the options object to check before the environment
|
|
35
33
|
* @returns {boolean} whether to prefer the wrapper if exists or not
|
|
36
34
|
*/
|
|
37
35
|
export function getWrapperPreference(name: string, opts?: {}): boolean;
|
|
@@ -61,6 +59,32 @@ export function toPurlFromString(strPurl: any): PackageURL | null;
|
|
|
61
59
|
* @param {string} cwd - directory for which to find the root of the git repository.
|
|
62
60
|
*/
|
|
63
61
|
export function getGitRootDir(cwd: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Normalize a filesystem path, lowercasing on Windows for case-insensitive comparison.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} thePath
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
export function normalizePath(thePath: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Walk up from `startDir` to `repoRoot` looking for an executable wrapper script.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} startDir - Absolute directory to start from
|
|
73
|
+
* @param {string} wrapperName - Wrapper filename (e.g. `mvnw`, `gradlew`)
|
|
74
|
+
* @param {string} [repoRoot] - Stop boundary (defaults to git root or filesystem root)
|
|
75
|
+
* @returns {string | undefined}
|
|
76
|
+
*/
|
|
77
|
+
export function traverseForWrapper(startDir: string, wrapperName: string, repoRoot?: string): string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Resolve a build-tool binary, preferring a wrapper when configured.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
|
|
82
|
+
* @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
|
|
83
|
+
* @param {string} startDir - Directory from which to start the wrapper search
|
|
84
|
+
* @param {import('./index.js').Options} [opts={}]
|
|
85
|
+
* @returns {string} Path to the resolved binary
|
|
86
|
+
*/
|
|
87
|
+
export function resolveBinary(globalBinary: string, localWrapper: string, startDir: string, opts?: import("./index.js").Options): string;
|
|
64
88
|
/** this method invokes command string in a process in a synchronous way.
|
|
65
89
|
* @param {string} bin - the command to be invoked
|
|
66
90
|
* @param {Array<string>} args - the args to pass to the binary
|
|
@@ -68,5 +92,23 @@ export function getGitRootDir(cwd: string): string | undefined;
|
|
|
68
92
|
* @returns {string}
|
|
69
93
|
*/
|
|
70
94
|
export function invokeCommand(bin: string, args: Array<string>, opts?: import("child_process").ExecFileOptionsWithStringEncoding): string;
|
|
95
|
+
/**
|
|
96
|
+
* Adds proxy agent configuration to fetch options if a proxy URL is specified
|
|
97
|
+
* @param {RequestInit} options - The base fetch options
|
|
98
|
+
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
99
|
+
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
100
|
+
*/
|
|
101
|
+
export function addProxyAgent(options: RequestInit, opts: any): RequestInit;
|
|
102
|
+
/**
|
|
103
|
+
* Utility function for fetching vendor tokens
|
|
104
|
+
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
105
|
+
* @returns {{}}
|
|
106
|
+
*/
|
|
107
|
+
export function getTokenHeaders(opts?: any): {};
|
|
71
108
|
export const RegexNotToBeLogged: RegExp;
|
|
109
|
+
export const TRUSTIFY_DA_TOKEN_HEADER: "trust-da-token";
|
|
110
|
+
export const TRUSTIFY_DA_TELEMETRY_ID_HEADER: "telemetry-anonymous-id";
|
|
111
|
+
export const TRUSTIFY_DA_SOURCE_HEADER: "trust-da-source";
|
|
112
|
+
export const TRUSTIFY_DA_OPERATION_TYPE_HEADER: "trust-da-operation-type";
|
|
113
|
+
export const TRUSTIFY_DA_PACKAGE_MANAGER_HEADER: "trust-da-pkg-manager";
|
|
72
114
|
import { PackageURL } from "packageurl-js";
|
package/dist/src/tools.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
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
7
|
export const RegexNotToBeLogged = /TRUSTIFY_DA_(.*_)?TOKEN|ex-.*-token|trust-.*-token/;
|
|
5
8
|
/**
|
|
@@ -24,39 +27,60 @@ export function logValueFromObjects(key, opts, defValue) {
|
|
|
24
27
|
console.log(`default value for ${key} = ${defValue} ${EOL}`);
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
|
-
* Utility function
|
|
28
|
-
*
|
|
29
|
-
* if not present, or not string will return the default value supplied which default to null.
|
|
30
|
+
* Utility function returns the value for key from opts, then environment variables,
|
|
31
|
+
* then the supplied default. Values from opts are used only if they are strings.
|
|
30
32
|
* @param {string} key the key to look for in the environment variables and the opts object
|
|
31
33
|
* @param {string|null} [def=null] the value to return if nothing else found
|
|
32
|
-
* @param {{}} [opts={}] the options object to
|
|
33
|
-
* @returns {string|null} the value of the key found in the
|
|
34
|
+
* @param {{}} [opts={}] the options object to check before the environment
|
|
35
|
+
* @returns {string|null} the value of the key found in the options object, environment, or the
|
|
34
36
|
* default supplied
|
|
35
37
|
*/
|
|
36
38
|
export function getCustom(key, def = null, opts = {}) {
|
|
37
39
|
if (process.env["TRUSTIFY_DA_DEBUG"] === "true" && !key.match(RegexNotToBeLogged)) {
|
|
38
40
|
logValueFromObjects(key, opts, def);
|
|
39
41
|
}
|
|
40
|
-
return key in
|
|
42
|
+
return key in opts && typeof opts[key] === 'string' ? opts[key] : key in process.env ? process.env[key] : def;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validates that an executable path does not use directory traversal or relative segments.
|
|
46
|
+
* @param {string} binPath - The executable path to validate.
|
|
47
|
+
* @returns {string} The validated path.
|
|
48
|
+
* @throws {Error} If the path contains '..' segments or is a relative path with separators.
|
|
49
|
+
*/
|
|
50
|
+
function validateExecutablePath(binPath) {
|
|
51
|
+
if (typeof binPath !== 'string' || binPath.length === 0) {
|
|
52
|
+
throw new Error('Executable path rejected: expected a non-empty string');
|
|
53
|
+
}
|
|
54
|
+
if (binPath.startsWith('./') || binPath.startsWith('.\\')) {
|
|
55
|
+
throw new Error(`Executable path rejected: relative paths starting with './' are not allowed: ${binPath}`);
|
|
56
|
+
}
|
|
57
|
+
const segments = binPath.split(/[/\\]/);
|
|
58
|
+
if (segments.includes('..')) {
|
|
59
|
+
throw new Error(`Executable path rejected: path contains directory traversal segment (..): ${binPath}`);
|
|
60
|
+
}
|
|
61
|
+
if ((binPath.includes('/') || binPath.includes('\\')) && !path.isAbsolute(binPath)) {
|
|
62
|
+
throw new Error(`Executable path rejected: relative paths are not allowed, use an absolute path or a bare command name: ${binPath}`);
|
|
63
|
+
}
|
|
64
|
+
return binPath;
|
|
41
65
|
}
|
|
42
66
|
/**
|
|
43
67
|
* Utility function for looking up custom variable for a binary path.
|
|
44
|
-
*
|
|
45
|
-
* uppercase version of
|
|
46
|
-
* found.
|
|
68
|
+
* Looks in opts, then environment variables, for a key with TRUSTIFY_DA_x_PATH, where x is an
|
|
69
|
+
* uppercase version of the supplied name. The name is returned if neither contains the key.
|
|
47
70
|
* @param name the binary name to look for, will be returned as value in nothing else found
|
|
48
|
-
* @param {{}} [opts={}] the options object to
|
|
49
|
-
* @returns {string|null} the value of the key found in the
|
|
71
|
+
* @param {{}} [opts={}] the options object to check before the environment
|
|
72
|
+
* @returns {string|null} the value of the key found in the options object, environment, or the
|
|
50
73
|
* original name supplied
|
|
51
74
|
*/
|
|
52
75
|
export function getCustomPath(name, opts = {}) {
|
|
53
|
-
|
|
76
|
+
const resolvedPath = getCustom(`TRUSTIFY_DA_${name.toUpperCase()}_PATH`, name, opts);
|
|
77
|
+
return validateExecutablePath(resolvedPath);
|
|
54
78
|
}
|
|
55
79
|
/**
|
|
56
80
|
* Utility function for determining whether wrappers for build tools such as gradlew/mvnw should be
|
|
57
81
|
* preferred over invoking the binary directly.
|
|
58
82
|
* @param {string} name - binary for which to search for its wrapper
|
|
59
|
-
* @param {{}} opts - the options object to
|
|
83
|
+
* @param {{}} opts - the options object to check before the environment
|
|
60
84
|
* @returns {boolean} whether to prefer the wrapper if exists or not
|
|
61
85
|
*/
|
|
62
86
|
export function getWrapperPreference(name, opts = {}) {
|
|
@@ -127,6 +151,62 @@ export function getGitRootDir(cwd) {
|
|
|
127
151
|
return undefined;
|
|
128
152
|
}
|
|
129
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Normalize a filesystem path, lowercasing on Windows for case-insensitive comparison.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} thePath
|
|
158
|
+
* @returns {string}
|
|
159
|
+
*/
|
|
160
|
+
export function normalizePath(thePath) {
|
|
161
|
+
const normalized = path.resolve(thePath).normalize();
|
|
162
|
+
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Walk up from `startDir` to `repoRoot` looking for an executable wrapper script.
|
|
166
|
+
*
|
|
167
|
+
* @param {string} startDir - Absolute directory to start from
|
|
168
|
+
* @param {string} wrapperName - Wrapper filename (e.g. `mvnw`, `gradlew`)
|
|
169
|
+
* @param {string} [repoRoot] - Stop boundary (defaults to git root or filesystem root)
|
|
170
|
+
* @returns {string | undefined}
|
|
171
|
+
*/
|
|
172
|
+
export function traverseForWrapper(startDir, wrapperName, repoRoot = undefined) {
|
|
173
|
+
const currentDir = normalizePath(startDir);
|
|
174
|
+
repoRoot = repoRoot || getGitRootDir(currentDir) || path.parse(currentDir).root;
|
|
175
|
+
const wrapperPath = path.join(currentDir, wrapperName);
|
|
176
|
+
try {
|
|
177
|
+
fs.accessSync(wrapperPath, fs.constants.X_OK);
|
|
178
|
+
return wrapperPath;
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
const rootDir = path.parse(currentDir).root;
|
|
182
|
+
if (currentDir === repoRoot || currentDir === rootDir) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const parentDir = path.dirname(currentDir);
|
|
186
|
+
if (parentDir === currentDir || parentDir === rootDir) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
return traverseForWrapper(parentDir, wrapperName, repoRoot);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Resolve a build-tool binary, preferring a wrapper when configured.
|
|
194
|
+
*
|
|
195
|
+
* @param {string} globalBinary - Global binary name (e.g. `mvn`, `gradle`)
|
|
196
|
+
* @param {string} localWrapper - Wrapper filename (e.g. `mvnw`, `gradlew.bat`)
|
|
197
|
+
* @param {string} startDir - Directory from which to start the wrapper search
|
|
198
|
+
* @param {import('./index.js').Options} [opts={}]
|
|
199
|
+
* @returns {string} Path to the resolved binary
|
|
200
|
+
*/
|
|
201
|
+
export function resolveBinary(globalBinary, localWrapper, startDir, opts = {}) {
|
|
202
|
+
if (getWrapperPreference(globalBinary, opts)) {
|
|
203
|
+
const wrapper = traverseForWrapper(startDir, localWrapper);
|
|
204
|
+
if (wrapper !== undefined) {
|
|
205
|
+
return wrapper;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return getCustomPath(globalBinary, opts);
|
|
209
|
+
}
|
|
130
210
|
/** this method invokes command string in a process in a synchronous way.
|
|
131
211
|
* @param {string} bin - the command to be invoked
|
|
132
212
|
* @param {Array<string>} args - the args to pass to the binary
|
|
@@ -157,3 +237,57 @@ export function invokeCommand(bin, args, opts = {}) {
|
|
|
157
237
|
};
|
|
158
238
|
return execFileSync(bin, args, { ...{ stdio: 'pipe', encoding: 'utf-8' }, ...opts });
|
|
159
239
|
}
|
|
240
|
+
export const TRUSTIFY_DA_TOKEN_HEADER = "trust-da-token";
|
|
241
|
+
export const TRUSTIFY_DA_TELEMETRY_ID_HEADER = "telemetry-anonymous-id";
|
|
242
|
+
export const TRUSTIFY_DA_SOURCE_HEADER = "trust-da-source";
|
|
243
|
+
export const TRUSTIFY_DA_OPERATION_TYPE_HEADER = "trust-da-operation-type";
|
|
244
|
+
export const TRUSTIFY_DA_PACKAGE_MANAGER_HEADER = "trust-da-pkg-manager";
|
|
245
|
+
/**
|
|
246
|
+
* Adds proxy agent configuration to fetch options if a proxy URL is specified
|
|
247
|
+
* @param {RequestInit} options - The base fetch options
|
|
248
|
+
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
249
|
+
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
250
|
+
*/
|
|
251
|
+
export function addProxyAgent(options, opts) {
|
|
252
|
+
const proxyUrl = getCustom('TRUSTIFY_DA_PROXY_URL', null, opts);
|
|
253
|
+
if (proxyUrl) {
|
|
254
|
+
options.agent = new HttpsProxyAgent(proxyUrl);
|
|
255
|
+
}
|
|
256
|
+
return options;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Utility function for fetching vendor tokens
|
|
260
|
+
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
261
|
+
* @returns {{}}
|
|
262
|
+
*/
|
|
263
|
+
export function getTokenHeaders(opts = {}) {
|
|
264
|
+
let headers = {};
|
|
265
|
+
setCustomHeader(TRUSTIFY_DA_TOKEN_HEADER, headers, 'TRUSTIFY_DA_TOKEN', opts);
|
|
266
|
+
setCustomHeader(TRUSTIFY_DA_SOURCE_HEADER, headers, 'TRUSTIFY_DA_SOURCE', opts);
|
|
267
|
+
setCustomHeader(TRUSTIFY_DA_OPERATION_TYPE_HEADER, headers, TRUSTIFY_DA_OPERATION_TYPE_HEADER.toUpperCase().replaceAll("-", "_"), opts);
|
|
268
|
+
setCustomHeader(TRUSTIFY_DA_PACKAGE_MANAGER_HEADER, headers, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER.toUpperCase().replaceAll("-", "_"), opts);
|
|
269
|
+
setCustomHeader(TRUSTIFY_DA_TELEMETRY_ID_HEADER, headers, 'TRUSTIFY_DA_TELEMETRY_ID', opts);
|
|
270
|
+
if (getCustom("TRUSTIFY_DA_DEBUG", null, opts) === "true") {
|
|
271
|
+
console.log("Headers Values to be sent to Trustify DA backend:" + EOL);
|
|
272
|
+
for (const headerKey in headers) {
|
|
273
|
+
if (!headerKey.match(RegexNotToBeLogged)) {
|
|
274
|
+
console.log(`${headerKey}: ${headers[headerKey]}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return headers;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
*
|
|
282
|
+
* @param {string} headerName - the header name to populate in request
|
|
283
|
+
* @param headers
|
|
284
|
+
* @param {string} optsKey - key in the options object to use the value for
|
|
285
|
+
* @param {import("index.js").Options} [opts={}] - options input object to fetch header values from
|
|
286
|
+
* @private
|
|
287
|
+
*/
|
|
288
|
+
function setCustomHeader(headerName, headers, optsKey, opts) {
|
|
289
|
+
let customHeaderValue = getCustom(optsKey, null, opts);
|
|
290
|
+
if (customHeaderValue) {
|
|
291
|
+
headers[headerName] = customHeaderValue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One entry in {@link updateMavenVersions}' `applied` list: a version that was changed and
|
|
3
|
+
* where. `type` discriminates the edit site — `'direct'` for a dependency's own `<version>`,
|
|
4
|
+
* `'property'` for a `${property}` reference (then `property` names the resolved property).
|
|
5
|
+
* @typedef {{
|
|
6
|
+
* groupId: string,
|
|
7
|
+
* artifactId: string,
|
|
8
|
+
* newVersion: string,
|
|
9
|
+
* type: ('direct'|'property'),
|
|
10
|
+
* property?: string
|
|
11
|
+
* }} MavenAppliedChange
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Stable edit-site key for a Maven change: same key => same commit/PR. Deps whose versions
|
|
15
|
+
* resolve to one `${property}` share the property key and are therefore inseparable.
|
|
16
|
+
* @param {string} manifestPath
|
|
17
|
+
* @param {MavenAppliedChange} applied
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export function mavenChangeKey(manifestPath: string, applied: MavenAppliedChange): string;
|
|
21
|
+
/**
|
|
22
|
+
* Updates dependency versions in a Maven pom.xml while preserving file formatting.
|
|
23
|
+
*
|
|
24
|
+
* Uses `fast-xml-parser` to understand the XML structure (dependencies and properties),
|
|
25
|
+
* then performs position-based string splice to replace version strings without altering
|
|
26
|
+
* any other formatting, comments, whitespace, or indentation.
|
|
27
|
+
*
|
|
28
|
+
* Supports `${property}` indirection: when a dependency's `<version>` is a property
|
|
29
|
+
* reference, the updater resolves the property chain (including recursive references)
|
|
30
|
+
* and updates the terminal property value in `<properties>` instead.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} pomContent - the raw pom.xml file content
|
|
33
|
+
* @param {import('../remediate.js').VersionChangeRequest[]} versionChanges - list of version changes to apply
|
|
34
|
+
* @returns {{content: string, applied: MavenAppliedChange[], skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}} the updated content and
|
|
35
|
+
* lists of applied and skipped changes
|
|
36
|
+
*/
|
|
37
|
+
export function updateMavenVersions(pomContent: string, versionChanges: import("../remediate.js").VersionChangeRequest[]): {
|
|
38
|
+
content: string;
|
|
39
|
+
applied: MavenAppliedChange[];
|
|
40
|
+
skipped: Array<{
|
|
41
|
+
groupId: string;
|
|
42
|
+
artifactId: string;
|
|
43
|
+
newVersion: string;
|
|
44
|
+
reason: string;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* One entry in {@link updateMavenVersions}' `applied` list: a version that was changed and
|
|
49
|
+
* where. `type` discriminates the edit site — `'direct'` for a dependency's own `<version>`,
|
|
50
|
+
* `'property'` for a `${property}` reference (then `property` names the resolved property).
|
|
51
|
+
*/
|
|
52
|
+
export type MavenAppliedChange = {
|
|
53
|
+
groupId: string;
|
|
54
|
+
artifactId: string;
|
|
55
|
+
newVersion: string;
|
|
56
|
+
type: ("direct" | "property");
|
|
57
|
+
property?: string;
|
|
58
|
+
};
|