@trustify-da/trustify-da-javascript-client 0.3.0-ea.f2d5d72 → 0.3.0-ea.f501753
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/dist/package.json +1 -1
- package/dist/src/analysis.js +3 -2
- package/dist/src/cli.js +51 -2
- package/dist/src/cyclone_dx_sbom.d.ts +7 -1
- package/dist/src/cyclone_dx_sbom.js +18 -5
- package/dist/src/index.d.ts +70 -2
- package/dist/src/index.js +77 -4
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.js +2 -0
- package/dist/src/providers/base_java.d.ts +0 -9
- package/dist/src/providers/base_java.js +2 -38
- package/dist/src/providers/base_pyproject.d.ts +35 -29
- package/dist/src/providers/base_pyproject.js +114 -78
- package/dist/src/providers/golang_gomodules.d.ts +9 -0
- package/dist/src/providers/golang_gomodules.js +64 -7
- package/dist/src/providers/java_gradle.d.ts +19 -0
- package/dist/src/providers/java_gradle.js +114 -0
- package/dist/src/providers/java_maven.d.ts +8 -0
- package/dist/src/providers/java_maven.js +93 -1
- package/dist/src/providers/javascript_npm.d.ts +1 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.js +6 -2
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/processors/yarn_berry_processor.js +6 -2
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +8 -4
- package/dist/src/providers/python_pip.d.ts +4 -0
- package/dist/src/providers/python_pip.js +4 -4
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +144 -0
- package/dist/src/providers/python_poetry.d.ts +37 -4
- package/dist/src/providers/python_poetry.js +108 -16
- package/dist/src/providers/python_uv.d.ts +17 -1
- package/dist/src/providers/python_uv.js +47 -5
- package/dist/src/sbom.d.ts +7 -1
- package/dist/src/sbom.js +4 -2
- package/dist/src/tools.d.ts +26 -0
- package/dist/src/tools.js +58 -0
- package/package.json +2 -2
package/dist/package.json
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"lint": "eslint src test --ext js",
|
|
39
39
|
"lint:fix": "eslint src test --ext js --fix",
|
|
40
40
|
"test": "c8 npm run tests",
|
|
41
|
-
"tests": "mocha --config .mocharc.json
|
|
41
|
+
"tests": "mocha --config .mocharc.json",
|
|
42
42
|
"tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
|
|
43
43
|
"pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm",
|
|
44
44
|
"precompile": "rm -rf dist",
|
package/dist/src/analysis.js
CHANGED
|
@@ -189,7 +189,7 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
|
|
|
189
189
|
if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
|
|
190
190
|
finalUrl.searchParams.append('recommend', 'false');
|
|
191
191
|
}
|
|
192
|
-
const
|
|
192
|
+
const fetchOptions = addProxyAgent({
|
|
193
193
|
method: 'POST',
|
|
194
194
|
headers: {
|
|
195
195
|
'Accept': html ? 'text/html' : 'application/json',
|
|
@@ -197,7 +197,8 @@ async function requestImages(imageRefs, url, html = false, opts = {}) {
|
|
|
197
197
|
...getTokenHeaders(opts)
|
|
198
198
|
},
|
|
199
199
|
body: JSON.stringify(imageSboms),
|
|
200
|
-
});
|
|
200
|
+
}, opts);
|
|
201
|
+
const resp = await fetch(finalUrl, fetchOptions);
|
|
201
202
|
if (resp.status === 200) {
|
|
202
203
|
let result;
|
|
203
204
|
if (!html) {
|
package/dist/src/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import * as path from "path";
|
|
3
4
|
import yargs from 'yargs';
|
|
4
5
|
import { hideBin } from 'yargs/helpers';
|
|
5
6
|
import { getProjectLicense, getLicenseDetails } from './license/index.js';
|
|
6
|
-
import client, { selectTrustifyDABackend } from './index.js';
|
|
7
|
+
import client, { selectTrustifyDABackend, generateSbom } from './index.js';
|
|
7
8
|
// command for component analysis take manifest type and content
|
|
8
9
|
const component = {
|
|
9
10
|
command: 'component </path/to/manifest>',
|
|
@@ -325,15 +326,63 @@ const license = {
|
|
|
325
326
|
console.log(JSON.stringify(output, null, 2));
|
|
326
327
|
}
|
|
327
328
|
};
|
|
329
|
+
const sbom = {
|
|
330
|
+
command: 'sbom </path/to/manifest> [--output]',
|
|
331
|
+
desc: 'generate a CycloneDX SBOM from a manifest file',
|
|
332
|
+
builder: yargs => yargs.positional('/path/to/manifest', {
|
|
333
|
+
desc: 'manifest path for SBOM generation',
|
|
334
|
+
type: 'string',
|
|
335
|
+
normalize: true,
|
|
336
|
+
}).options({
|
|
337
|
+
output: {
|
|
338
|
+
alias: 'o',
|
|
339
|
+
desc: 'Write SBOM JSON to a file instead of stdout',
|
|
340
|
+
type: 'string',
|
|
341
|
+
normalize: true,
|
|
342
|
+
},
|
|
343
|
+
workspaceDir: {
|
|
344
|
+
alias: 'w',
|
|
345
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
346
|
+
type: 'string',
|
|
347
|
+
normalize: true,
|
|
348
|
+
}
|
|
349
|
+
}),
|
|
350
|
+
handler: async (args) => {
|
|
351
|
+
let manifest = args['/path/to/manifest'];
|
|
352
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
353
|
+
let result;
|
|
354
|
+
try {
|
|
355
|
+
result = await generateSbom(manifest, opts);
|
|
356
|
+
}
|
|
357
|
+
catch (err) {
|
|
358
|
+
console.error(JSON.stringify({ error: `Failed to generate SBOM: ${err.message}` }, null, 2));
|
|
359
|
+
process.exit(1);
|
|
360
|
+
}
|
|
361
|
+
const json = JSON.stringify(result, null, 2);
|
|
362
|
+
if (args.output) {
|
|
363
|
+
try {
|
|
364
|
+
fs.writeFileSync(args.output, json);
|
|
365
|
+
}
|
|
366
|
+
catch (err) {
|
|
367
|
+
console.error(JSON.stringify({ error: `Failed to write output file: ${err.message}` }, null, 2));
|
|
368
|
+
process.exit(1);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
console.log(json);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
328
376
|
// parse and invoke the command
|
|
329
377
|
yargs(hideBin(process.argv))
|
|
330
|
-
.usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|stack-batch|image|validate-token|license}`)
|
|
378
|
+
.usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|stack-batch|image|validate-token|license|sbom}`)
|
|
331
379
|
.command(stack)
|
|
332
380
|
.command(stackBatch)
|
|
333
381
|
.command(component)
|
|
334
382
|
.command(image)
|
|
335
383
|
.command(validateToken)
|
|
336
384
|
.command(license)
|
|
385
|
+
.command(sbom)
|
|
337
386
|
.scriptName('')
|
|
338
387
|
.version(false)
|
|
339
388
|
.demandCommand(1)
|
|
@@ -18,9 +18,14 @@ export default class CycloneDxSbom {
|
|
|
18
18
|
* Adds a dependency relationship between two components in the SBOM
|
|
19
19
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
20
20
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
21
|
+
* @param {string} [scope] - Scope of the dependency
|
|
22
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
21
23
|
* @return {CycloneDxSbom} The updated SBOM
|
|
22
24
|
*/
|
|
23
|
-
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope
|
|
25
|
+
addDependency(sourceRef: PackageURL, targetRef: PackageURL, scope?: string, targetHashes?: Array<{
|
|
26
|
+
alg: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}>): CycloneDxSbom;
|
|
24
29
|
/** @param {{}} opts - various options, settings and configuration of application.
|
|
25
30
|
* @return String CycloneDx Sbom json object in a string format
|
|
26
31
|
*/
|
|
@@ -50,6 +55,7 @@ export default class CycloneDxSbom {
|
|
|
50
55
|
version: any;
|
|
51
56
|
scope: any;
|
|
52
57
|
licenses?: any;
|
|
58
|
+
hashes?: any;
|
|
53
59
|
};
|
|
54
60
|
/**
|
|
55
61
|
* This method gets an array of dependencies to be ignored, and remove all of them from CycloneDx Sbom
|
|
@@ -6,10 +6,11 @@ import { PackageURL } from "packageurl-js";
|
|
|
6
6
|
* @param type type of package - application or library
|
|
7
7
|
* @param scope scope of the component - runtime or compile
|
|
8
8
|
* @param licenses optional license string or array of licenses for the component
|
|
9
|
-
* @
|
|
9
|
+
* @param hashes optional array of hash objects for the component, e.g. [{alg: "SHA-256", content: "..."}]
|
|
10
|
+
* @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?, hashes?}}
|
|
10
11
|
* @private
|
|
11
12
|
*/
|
|
12
|
-
function getComponent(component, type, scope, licenses) {
|
|
13
|
+
function getComponent(component, type, scope, licenses, hashes) {
|
|
13
14
|
let componentObject;
|
|
14
15
|
if (component instanceof PackageURL) {
|
|
15
16
|
if (component.namespace) {
|
|
@@ -47,6 +48,10 @@ function getComponent(component, type, scope, licenses) {
|
|
|
47
48
|
return lic;
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
// Add hashes if provided (CycloneDX 1.4 format).
|
|
52
|
+
if (hashes && hashes.length > 0) {
|
|
53
|
+
componentObject.hashes = hashes;
|
|
54
|
+
}
|
|
50
55
|
return componentObject;
|
|
51
56
|
}
|
|
52
57
|
function createDependency(dependency) {
|
|
@@ -86,16 +91,24 @@ export default class CycloneDxSbom {
|
|
|
86
91
|
* Adds a dependency relationship between two components in the SBOM
|
|
87
92
|
* @param {PackageURL} sourceRef - The source component (parent)
|
|
88
93
|
* @param {PackageURL} targetRef - The target component (dependency)
|
|
94
|
+
* @param {string} [scope] - Scope of the dependency
|
|
95
|
+
* @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
|
|
89
96
|
* @return {CycloneDxSbom} The updated SBOM
|
|
90
97
|
*/
|
|
91
|
-
addDependency(sourceRef, targetRef, scope) {
|
|
98
|
+
addDependency(sourceRef, targetRef, scope, targetHashes) {
|
|
92
99
|
const sourcePurl = sourceRef.toString();
|
|
93
100
|
const targetPurl = targetRef.toString();
|
|
94
101
|
// Ensure both components exist in the components list
|
|
95
102
|
[sourceRef, targetRef].forEach((ref, index) => {
|
|
96
103
|
const purl = index === 0 ? sourcePurl : targetPurl;
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
const existingIndex = this.getComponentIndex(purl);
|
|
105
|
+
if (existingIndex < 0) {
|
|
106
|
+
const hashes = index === 1 ? targetHashes : undefined;
|
|
107
|
+
this.components.push(getComponent(ref, "library", scope, undefined, hashes));
|
|
108
|
+
}
|
|
109
|
+
else if (index === 1 && targetHashes && targetHashes.length > 0 && !this.components[existingIndex].hashes) {
|
|
110
|
+
// Update hashes if the component was first seen without them (e.g. as a source)
|
|
111
|
+
this.components[existingIndex].hashes = targetHashes;
|
|
99
112
|
}
|
|
100
113
|
});
|
|
101
114
|
// Ensure source dependency exists
|
package/dist/src/index.d.ts
CHANGED
|
@@ -13,6 +13,15 @@ export function selectTrustifyDABackend(opts?: {
|
|
|
13
13
|
TRUSTIFY_DA_DEBUG?: string | undefined;
|
|
14
14
|
TRUSTIFY_DA_BACKEND_URL?: string | undefined;
|
|
15
15
|
}): string;
|
|
16
|
+
/**
|
|
17
|
+
* Generate a CycloneDX SBOM from a manifest file. No backend HTTP request is made.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} manifestPath - path to the manifest file (e.g. pom.xml, package.json)
|
|
20
|
+
* @param {Options} [opts={}] - optional options (e.g. workspace dir, tool paths)
|
|
21
|
+
* @returns {Promise<object>} parsed CycloneDX SBOM JSON object
|
|
22
|
+
* @throws {Error} if the manifest is unsupported or SBOM generation fails
|
|
23
|
+
*/
|
|
24
|
+
export function generateSbom(manifestPath: string, opts?: Options): Promise<object>;
|
|
16
25
|
export { parseImageRef } from "./oci_image/utils.js";
|
|
17
26
|
export { ImageRef } from "./oci_image/images.js";
|
|
18
27
|
declare namespace _default {
|
|
@@ -21,6 +30,7 @@ declare namespace _default {
|
|
|
21
30
|
export { stackAnalysisBatch };
|
|
22
31
|
export { imageAnalysis };
|
|
23
32
|
export { validateToken };
|
|
33
|
+
export { generateSbom };
|
|
24
34
|
}
|
|
25
35
|
export default _default;
|
|
26
36
|
export type Options = {
|
|
@@ -126,19 +136,74 @@ declare function stackAnalysis(manifest: string, html: false, opts?: Options | u
|
|
|
126
136
|
* or backend request failed
|
|
127
137
|
*/
|
|
128
138
|
declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
|
|
139
|
+
/**
|
|
140
|
+
* @overload
|
|
141
|
+
* @param {string} workspaceRoot
|
|
142
|
+
* @param {true} html
|
|
143
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
144
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
145
|
+
* @throws {Error}
|
|
146
|
+
*/
|
|
147
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts: Options & {
|
|
148
|
+
batchMetadata: true;
|
|
149
|
+
}): Promise<{
|
|
150
|
+
analysis: string;
|
|
151
|
+
metadata: BatchAnalysisMetadata;
|
|
152
|
+
}>;
|
|
153
|
+
/**
|
|
154
|
+
* @overload
|
|
155
|
+
* @param {string} workspaceRoot
|
|
156
|
+
* @param {true} html
|
|
157
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
158
|
+
* @returns {Promise<string>}
|
|
159
|
+
* @throws {Error}
|
|
160
|
+
*/
|
|
161
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts?: (Options & {
|
|
162
|
+
batchMetadata?: false;
|
|
163
|
+
}) | undefined): Promise<string>;
|
|
164
|
+
/**
|
|
165
|
+
* @overload
|
|
166
|
+
* @param {string} workspaceRoot
|
|
167
|
+
* @param {false} html
|
|
168
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
169
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
170
|
+
* @throws {Error}
|
|
171
|
+
*/
|
|
172
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts: Options & {
|
|
173
|
+
batchMetadata: true;
|
|
174
|
+
}): Promise<{
|
|
175
|
+
analysis: {
|
|
176
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
177
|
+
};
|
|
178
|
+
metadata: BatchAnalysisMetadata;
|
|
179
|
+
}>;
|
|
180
|
+
/**
|
|
181
|
+
* @overload
|
|
182
|
+
* @param {string} workspaceRoot
|
|
183
|
+
* @param {false} html
|
|
184
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
185
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
186
|
+
* @throws {Error}
|
|
187
|
+
*/
|
|
188
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts?: (Options & {
|
|
189
|
+
batchMetadata?: false;
|
|
190
|
+
}) | undefined): Promise<{
|
|
191
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
192
|
+
}>;
|
|
129
193
|
/**
|
|
130
194
|
* Get stack analysis for all workspace packages/crates (batch).
|
|
131
195
|
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
132
196
|
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
133
197
|
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
134
198
|
*
|
|
199
|
+
* @overload
|
|
135
200
|
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
136
201
|
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
137
202
|
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
138
203
|
* @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>|{ analysis: string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
139
204
|
* @throws {Error} if workspace root invalid, no manifests found, no packages pass validation, no SBOMs produced, or backend request failed. When `opts.batchMetadata` is set, `error.batchMetadata` may be set on thrown errors.
|
|
140
205
|
*/
|
|
141
|
-
declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean, opts?: Options): Promise<string | {
|
|
206
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
|
|
142
207
|
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
143
208
|
} | {
|
|
144
209
|
analysis: string | {
|
|
@@ -186,6 +251,9 @@ declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefi
|
|
|
186
251
|
* @throws {Error} if the backend request failed.
|
|
187
252
|
*/
|
|
188
253
|
declare function validateToken(opts?: Options): Promise<object>;
|
|
254
|
+
import { discoverMavenModules } from './providers/java_maven.js';
|
|
255
|
+
import { discoverGradleSubprojects } from './providers/java_gradle.js';
|
|
256
|
+
import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
|
|
189
257
|
import { discoverWorkspacePackages } from './workspace.js';
|
|
190
258
|
import { discoverWorkspaceCrates } from './workspace.js';
|
|
191
259
|
import { validatePackageJson } from './workspace.js';
|
|
@@ -193,5 +261,5 @@ import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
|
|
|
193
261
|
import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
|
|
194
262
|
import { resolveContinueOnError } from './batch_opts.js';
|
|
195
263
|
import { resolveBatchMetadata } from './batch_opts.js';
|
|
196
|
-
export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
264
|
+
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
197
265
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
package/dist/src/index.js
CHANGED
|
@@ -6,14 +6,17 @@ import analysis from './analysis.js';
|
|
|
6
6
|
import fs from 'node:fs';
|
|
7
7
|
import { getCustom } from "./tools.js";
|
|
8
8
|
import { resolveBatchMetadata, resolveContinueOnError } from './batch_opts.js';
|
|
9
|
+
import { discoverMavenModules } from './providers/java_maven.js';
|
|
10
|
+
import { discoverGradleSubprojects } from './providers/java_gradle.js';
|
|
11
|
+
import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
|
|
9
12
|
import { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
|
|
10
13
|
import.meta.dirname;
|
|
11
14
|
import * as url from 'url';
|
|
12
15
|
export { parseImageRef } from "./oci_image/utils.js";
|
|
13
16
|
export { ImageRef } from "./oci_image/images.js";
|
|
14
17
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
|
15
|
-
export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken };
|
|
16
|
-
export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
18
|
+
export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
|
|
19
|
+
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
17
20
|
/**
|
|
18
21
|
* @typedef {{
|
|
19
22
|
* TRUSTIFY_DA_CARGO_PATH?: string | undefined,
|
|
@@ -237,6 +240,22 @@ function buildBatchAnalysisMetadata(root, ecosystem, totalSbomAttempts, successf
|
|
|
237
240
|
errors: [...errors],
|
|
238
241
|
};
|
|
239
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Generate a CycloneDX SBOM from a manifest file. No backend HTTP request is made.
|
|
245
|
+
*
|
|
246
|
+
* @param {string} manifestPath - path to the manifest file (e.g. pom.xml, package.json)
|
|
247
|
+
* @param {Options} [opts={}] - optional options (e.g. workspace dir, tool paths)
|
|
248
|
+
* @returns {Promise<object>} parsed CycloneDX SBOM JSON object
|
|
249
|
+
* @throws {Error} if the manifest is unsupported or SBOM generation fails
|
|
250
|
+
*/
|
|
251
|
+
export async function generateSbom(manifestPath, opts = {}) {
|
|
252
|
+
fs.accessSync(manifestPath, fs.constants.R_OK);
|
|
253
|
+
const result = await generateOneSbom(manifestPath, opts);
|
|
254
|
+
if (!result.ok) {
|
|
255
|
+
throw new Error(`Failed to generate SBOM for ${result.manifestPath}: ${result.reason}`);
|
|
256
|
+
}
|
|
257
|
+
return result.sbom;
|
|
258
|
+
}
|
|
240
259
|
/**
|
|
241
260
|
* @typedef {{ ok: true, purl: string, sbom: object } | { ok: false, manifestPath: string, reason: string }} SbomResult
|
|
242
261
|
*/
|
|
@@ -263,16 +282,37 @@ async function generateOneSbom(manifestPath, workspaceOpts) {
|
|
|
263
282
|
*
|
|
264
283
|
* @param {string} root - Resolved workspace root
|
|
265
284
|
* @param {Options} opts
|
|
266
|
-
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'unknown', manifestPaths: string[] }>}
|
|
285
|
+
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'gradle' | 'gomodules' | 'unknown', manifestPaths: string[] }>}
|
|
267
286
|
* @private
|
|
268
287
|
*/
|
|
269
288
|
async function detectWorkspaceManifests(root, opts) {
|
|
270
289
|
const cargoToml = path.join(root, 'Cargo.toml');
|
|
271
290
|
const cargoLock = path.join(root, 'Cargo.lock');
|
|
272
291
|
const packageJson = path.join(root, 'package.json');
|
|
292
|
+
const pomXml = path.join(root, 'pom.xml');
|
|
273
293
|
if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
|
|
274
294
|
return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
|
|
275
295
|
}
|
|
296
|
+
if (fs.existsSync(pomXml)) {
|
|
297
|
+
const manifestPaths = await discoverMavenModules(root, opts);
|
|
298
|
+
if (manifestPaths.length > 0) {
|
|
299
|
+
return { ecosystem: 'maven', manifestPaths };
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const hasGradleSettings = fs.existsSync(path.join(root, 'settings.gradle'))
|
|
303
|
+
|| fs.existsSync(path.join(root, 'settings.gradle.kts'));
|
|
304
|
+
if (hasGradleSettings) {
|
|
305
|
+
const manifestPaths = await discoverGradleSubprojects(root, opts);
|
|
306
|
+
if (manifestPaths.length > 0) {
|
|
307
|
+
return { ecosystem: 'gradle', manifestPaths };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (fs.existsSync(path.join(root, 'go.work'))) {
|
|
311
|
+
const manifestPaths = await discoverGoWorkspaceModules(root, opts);
|
|
312
|
+
if (manifestPaths.length > 0) {
|
|
313
|
+
return { ecosystem: 'gomodules', manifestPaths };
|
|
314
|
+
}
|
|
315
|
+
}
|
|
276
316
|
const hasJsLock = fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
|
|
277
317
|
|| fs.existsSync(path.join(root, 'yarn.lock'))
|
|
278
318
|
|| fs.existsSync(path.join(root, 'package-lock.json'));
|
|
@@ -382,12 +422,45 @@ function batchError(message, wantMetadata, metadata) {
|
|
|
382
422
|
}
|
|
383
423
|
return err;
|
|
384
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* @overload
|
|
427
|
+
* @param {string} workspaceRoot
|
|
428
|
+
* @param {true} html
|
|
429
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
430
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
431
|
+
* @throws {Error}
|
|
432
|
+
*/
|
|
433
|
+
/**
|
|
434
|
+
* @overload
|
|
435
|
+
* @param {string} workspaceRoot
|
|
436
|
+
* @param {true} html
|
|
437
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
438
|
+
* @returns {Promise<string>}
|
|
439
|
+
* @throws {Error}
|
|
440
|
+
*/
|
|
441
|
+
/**
|
|
442
|
+
* @overload
|
|
443
|
+
* @param {string} workspaceRoot
|
|
444
|
+
* @param {false} html
|
|
445
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
446
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
447
|
+
* @throws {Error}
|
|
448
|
+
*/
|
|
449
|
+
/**
|
|
450
|
+
* @overload
|
|
451
|
+
* @param {string} workspaceRoot
|
|
452
|
+
* @param {false} html
|
|
453
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
454
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
455
|
+
* @throws {Error}
|
|
456
|
+
*/
|
|
385
457
|
/**
|
|
386
458
|
* Get stack analysis for all workspace packages/crates (batch).
|
|
387
459
|
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
388
460
|
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
389
461
|
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
390
462
|
*
|
|
463
|
+
* @overload
|
|
391
464
|
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
392
465
|
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
393
466
|
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
@@ -418,7 +491,7 @@ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
|
|
|
418
491
|
}
|
|
419
492
|
}
|
|
420
493
|
if (manifestPaths.length === 0) {
|
|
421
|
-
throw new Error(`No workspace manifests found at ${root}. Ensure Cargo.toml+Cargo.lock or package.json+lock file
|
|
494
|
+
throw new Error(`No workspace manifests found at ${root}. Ensure a supported workspace root exists (Cargo.toml+Cargo.lock, go.work, or package.json+lock file).`);
|
|
422
495
|
}
|
|
423
496
|
const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
|
|
424
497
|
const concurrency = resolveBatchConcurrency(opts);
|
|
@@ -135,7 +135,7 @@ function execSyft(imageRef, opts = {}) {
|
|
|
135
135
|
function getSyftEnvs(dockerPath, podmanPath) {
|
|
136
136
|
let path = null;
|
|
137
137
|
if (dockerPath && podmanPath) {
|
|
138
|
-
path = `${dockerPath}${
|
|
138
|
+
path = `${dockerPath}${delimiter}${podmanPath}`;
|
|
139
139
|
}
|
|
140
140
|
else if (dockerPath) {
|
|
141
141
|
path = dockerPath;
|
|
@@ -276,7 +276,16 @@ function podmanGetVariant(opts = {}) {
|
|
|
276
276
|
* @returns {string} - The information
|
|
277
277
|
*/
|
|
278
278
|
function dockerPodmanInfo(dockerSupplier, podmanSupplier, opts = {}) {
|
|
279
|
-
|
|
279
|
+
try {
|
|
280
|
+
const result = dockerSupplier(opts);
|
|
281
|
+
if (result) {
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch (_) {
|
|
286
|
+
// docker not available, fall through to podman
|
|
287
|
+
}
|
|
288
|
+
return podmanSupplier(opts);
|
|
280
289
|
}
|
|
281
290
|
/**
|
|
282
291
|
* Gets the digests for an image
|
package/dist/src/provider.js
CHANGED
|
@@ -7,6 +7,7 @@ import Javascript_npm from './providers/javascript_npm.js';
|
|
|
7
7
|
import Javascript_pnpm from './providers/javascript_pnpm.js';
|
|
8
8
|
import Javascript_yarn from './providers/javascript_yarn.js';
|
|
9
9
|
import pythonPipProvider from './providers/python_pip.js';
|
|
10
|
+
import Python_pip_pyproject from './providers/python_pip_pyproject.js';
|
|
10
11
|
import Python_poetry from './providers/python_poetry.js';
|
|
11
12
|
import Python_uv from './providers/python_uv.js';
|
|
12
13
|
import rustCargoProvider from './providers/rust_cargo.js';
|
|
@@ -27,6 +28,7 @@ export const availableProviders = [
|
|
|
27
28
|
pythonPipProvider,
|
|
28
29
|
new Python_poetry(),
|
|
29
30
|
new Python_uv(),
|
|
31
|
+
new Python_pip_pyproject(),
|
|
30
32
|
rustCargoProvider
|
|
31
33
|
];
|
|
32
34
|
/**
|
|
@@ -57,15 +57,6 @@ export default class Base_Java {
|
|
|
57
57
|
* @returns string
|
|
58
58
|
*/
|
|
59
59
|
selectToolBinary(manifestPath: string, opts: {}): string | null;
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @param {string} startingManifest - the path of the manifest from which to start searching for the wrapper
|
|
63
|
-
* @param {string} repoRoot - the root of the repository at which point to stop searching for mvnw, derived via git if unset and then fallsback
|
|
64
|
-
* to the root of the drive the manifest is on (assumes absolute path is given)
|
|
65
|
-
* @returns {string|undefined}
|
|
66
|
-
*/
|
|
67
|
-
traverseForWrapper(startingManifest: string, repoRoot?: string): string | undefined;
|
|
68
|
-
normalizePath(thePath: any): string;
|
|
69
60
|
#private;
|
|
70
61
|
}
|
|
71
62
|
export type Provided = import("../provider").Provided;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { PackageURL } from 'packageurl-js';
|
|
4
|
-
import { getCustomPath,
|
|
3
|
+
import { getCustomPath, getWrapperPreference, invokeCommand, traverseForWrapper } from "../tools.js";
|
|
5
4
|
/** @typedef {import('../provider').Provider} */
|
|
6
5
|
/** @typedef {import('../provider').Provided} Provided */
|
|
7
6
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -131,7 +130,7 @@ export default class Base_Java {
|
|
|
131
130
|
const toolPath = getCustomPath(this.globalBinary, opts);
|
|
132
131
|
const useWrapper = getWrapperPreference(this.globalBinary, opts);
|
|
133
132
|
if (useWrapper) {
|
|
134
|
-
const wrapper = this.
|
|
133
|
+
const wrapper = traverseForWrapper(manifestDir, this.localWrapper);
|
|
135
134
|
if (wrapper !== undefined) {
|
|
136
135
|
try {
|
|
137
136
|
this._invokeCommand(wrapper, ['--version'], { cwd: manifestDir });
|
|
@@ -156,39 +155,4 @@ export default class Base_Java {
|
|
|
156
155
|
}
|
|
157
156
|
return toolPath;
|
|
158
157
|
}
|
|
159
|
-
/**
|
|
160
|
-
*
|
|
161
|
-
* @param {string} startingManifest - the path of the manifest from which to start searching for the wrapper
|
|
162
|
-
* @param {string} repoRoot - the root of the repository at which point to stop searching for mvnw, derived via git if unset and then fallsback
|
|
163
|
-
* to the root of the drive the manifest is on (assumes absolute path is given)
|
|
164
|
-
* @returns {string|undefined}
|
|
165
|
-
*/
|
|
166
|
-
traverseForWrapper(startingManifest, repoRoot = undefined) {
|
|
167
|
-
const normalizedManifest = this.normalizePath(startingManifest);
|
|
168
|
-
const currentDir = this.normalizePath(path.dirname(normalizedManifest));
|
|
169
|
-
repoRoot = repoRoot || getGitRootDir(currentDir) || path.parse(normalizedManifest).root;
|
|
170
|
-
const wrapperPath = path.join(currentDir, this.localWrapper);
|
|
171
|
-
try {
|
|
172
|
-
fs.accessSync(wrapperPath, fs.constants.X_OK);
|
|
173
|
-
return wrapperPath;
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
if (error.code === 'ENOENT') {
|
|
177
|
-
const rootDir = path.parse(currentDir).root;
|
|
178
|
-
if (currentDir === repoRoot || currentDir === rootDir) {
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
const parentDir = path.dirname(currentDir);
|
|
182
|
-
if (parentDir === currentDir || parentDir === rootDir) {
|
|
183
|
-
return undefined;
|
|
184
|
-
}
|
|
185
|
-
return this.traverseForWrapper(path.join(parentDir, path.basename(normalizedManifest)), repoRoot);
|
|
186
|
-
}
|
|
187
|
-
throw new Error(`failure searching for ${this.localWrapper}`, { cause: error });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
normalizePath(thePath) {
|
|
191
|
-
const normalized = path.resolve(thePath).normalize();
|
|
192
|
-
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
193
|
-
}
|
|
194
158
|
}
|