@trustify-da/trustify-da-javascript-client 0.3.0-ea.29f6867 → 0.3.0-ea.2ea1d77
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 +79 -6
- package/dist/package.json +5 -0
- package/dist/src/analysis.d.ts +14 -0
- package/dist/src/analysis.js +47 -1
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +121 -3
- package/dist/src/cyclone_dx_sbom.js +2 -1
- package/dist/src/index.d.ts +62 -1
- package/dist/src/index.js +265 -4
- package/dist/src/license/licenses_api.js +9 -2
- package/dist/src/license/project_license.d.ts +0 -8
- package/dist/src/license/project_license.js +0 -11
- package/dist/src/provider.d.ts +6 -3
- package/dist/src/provider.js +8 -5
- package/dist/src/providers/base_javascript.d.ts +9 -3
- package/dist/src/providers/base_javascript.js +18 -10
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +2 -2
- package/dist/src/providers/rust_cargo.d.ts +52 -0
- package/dist/src/providers/rust_cargo.js +614 -0
- package/dist/src/workspace.d.ts +61 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -32,6 +32,11 @@ let stackAnalysis = await client.stackAnalysis('/path/to/pom.xml')
|
|
|
32
32
|
let stackAnalysisHtml = await client.stackAnalysis('/path/to/pom.xml', true)
|
|
33
33
|
// Get component analysis in JSON format
|
|
34
34
|
let componentAnalysis = await client.componentAnalysis('/path/to/pom.xml')
|
|
35
|
+
// For monorepos, pass workspace root so the client finds the lock file
|
|
36
|
+
let monorepoOpts = { workspaceDir: '/path/to/workspace-root' }
|
|
37
|
+
let stackAnalysisMonorepo = await client.stackAnalysis('/path/to/package.json', false, monorepoOpts)
|
|
38
|
+
// Batch analysis for entire workspace (Cargo or JS/TS); optional parallel SBOM generation
|
|
39
|
+
let batchReport = await client.stackAnalysisBatch('/path/to/workspace-root', false, { batchConcurrency: 10 })
|
|
35
40
|
// Get image analysis in JSON format
|
|
36
41
|
let imageAnalysis = await client.imageAnalysis(['docker.io/library/node:18'])
|
|
37
42
|
// Get image analysis in HTML format (string)
|
|
@@ -49,7 +54,7 @@ let imageAnalysisWithArch = await client.imageAnalysis(['httpd:2.4.49^^amd64'])
|
|
|
49
54
|
The client automatically detects your project's license with intelligent fallback:
|
|
50
55
|
</p>
|
|
51
56
|
<ul>
|
|
52
|
-
<li><strong>Manifest-first:</strong> For ecosystems with license support (Maven, JavaScript), reads from manifest file (<code>pom.xml</code>, <code>package.json</code>)</li>
|
|
57
|
+
<li><strong>Manifest-first:</strong> For ecosystems with license support (Maven, JavaScript, Rust Cargo), reads from manifest file (<code>pom.xml</code>, <code>package.json</code>, <code>Cargo.toml</code>)</li>
|
|
53
58
|
<li><strong>LICENSE file fallback:</strong> If no license in manifest, or for ecosystems without license support (Gradle, Go, Python), automatically reads from <code>LICENSE</code>, <code>LICENSE.md</code>, or <code>LICENSE.txt</code></li>
|
|
54
59
|
<li><strong>SBOM integration:</strong> Detected licenses are included in generated SBOMs for all ecosystems</li>
|
|
55
60
|
<li><strong>SPDX support:</strong> Automatically detects common licenses (Apache-2.0, MIT, GPL, BSD) from LICENSE file content</li>
|
|
@@ -101,8 +106,9 @@ $ npx @trustify-da/trustify-da-javascript-client help
|
|
|
101
106
|
Usage: trustify-da-javascript-client {component|stack|image|validate-token|license}
|
|
102
107
|
|
|
103
108
|
Commands:
|
|
104
|
-
trustify-da-javascript-client stack </path/to/manifest> [--html|--summary] produce stack report for manifest path
|
|
105
|
-
trustify-da-javascript-client
|
|
109
|
+
trustify-da-javascript-client stack </path/to/manifest> [--workspace-dir <path>] [--html|--summary] produce stack report for manifest path
|
|
110
|
+
trustify-da-javascript-client stack-batch </path/to/workspace-root> [--html|--summary] produce stack report for all packages/crates in workspace
|
|
111
|
+
trustify-da-javascript-client component <path/to/manifest> [--workspace-dir <path>] produce component report for a manifest type and content
|
|
106
112
|
trustify-da-javascript-client image <image-refs..> [--html|--summary] produce image analysis report for OCI image references
|
|
107
113
|
trustify-da-javascript-client license </path/to/manifest> display project license information from manifest and LICENSE file in JSON format
|
|
108
114
|
|
|
@@ -121,9 +127,21 @@ $ npx @trustify-da/trustify-da-javascript-client stack /path/to/pom.xml --summar
|
|
|
121
127
|
# get stack analysis in html format format
|
|
122
128
|
$ npx @trustify-da/trustify-da-javascript-client stack /path/to/pom.xml --html
|
|
123
129
|
|
|
130
|
+
# get stack analysis for monorepo (lock file at workspace root)
|
|
131
|
+
$ npx @trustify-da/trustify-da-javascript-client stack /path/to/package.json --workspace-dir /path/to/workspace-root
|
|
132
|
+
|
|
124
133
|
# get component analysis
|
|
125
134
|
$ npx @trustify-da/trustify-da-javascript-client component /path/to/pom.xml
|
|
126
135
|
|
|
136
|
+
# get component analysis for monorepo
|
|
137
|
+
$ npx @trustify-da/trustify-da-javascript-client component /path/to/package.json -w /path/to/workspace-root
|
|
138
|
+
|
|
139
|
+
# batch stack analysis for entire workspace (Cargo or JS/TS)
|
|
140
|
+
$ npx @trustify-da/trustify-da-javascript-client stack-batch /path/to/workspace-root
|
|
141
|
+
|
|
142
|
+
# optional: extra discovery excludes (merged with defaults); repeat --ignore or use TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE
|
|
143
|
+
$ npx @trustify-da/trustify-da-javascript-client stack-batch /path/to/workspace-root --ignore '**/fixtures/**'
|
|
144
|
+
|
|
127
145
|
# get image analysis in json format
|
|
128
146
|
$ npx @trustify-da/trustify-da-javascript-client image docker.io/library/node:18
|
|
129
147
|
|
|
@@ -162,9 +180,21 @@ $ trustify-da-javascript-client stack /path/to/pom.xml --summary
|
|
|
162
180
|
# get stack analysis in html format format
|
|
163
181
|
$ trustify-da-javascript-client stack /path/to/pom.xml --html
|
|
164
182
|
|
|
183
|
+
# get stack analysis for monorepo (lock file at workspace root)
|
|
184
|
+
$ trustify-da-javascript-client stack /path/to/package.json --workspace-dir /path/to/workspace-root
|
|
185
|
+
|
|
165
186
|
# get component analysis
|
|
166
187
|
$ trustify-da-javascript-client component /path/to/pom.xml
|
|
167
188
|
|
|
189
|
+
# get component analysis for monorepo
|
|
190
|
+
$ trustify-da-javascript-client component /path/to/package.json -w /path/to/workspace-root
|
|
191
|
+
|
|
192
|
+
# batch stack analysis for entire workspace
|
|
193
|
+
$ trustify-da-javascript-client stack-batch /path/to/workspace-root
|
|
194
|
+
|
|
195
|
+
# with extra discovery excludes
|
|
196
|
+
$ trustify-da-javascript-client stack-batch /path/to/workspace-root -i '**/vendor/**'
|
|
197
|
+
|
|
168
198
|
# get image analysis in json format
|
|
169
199
|
$ trustify-da-javascript-client image docker.io/library/node:18
|
|
170
200
|
|
|
@@ -196,6 +226,7 @@ $ trustify-da-javascript-client license /path/to/package.json
|
|
|
196
226
|
<li><a href="https://go.dev/">Golang</a> - <a href="https://go.dev/blog/using-go-modules/">Go Modules</a></li>
|
|
197
227
|
<li><a href="https://www.python.org/">Python</a> - <a href="https://pypi.org/project/pip/">pip Installer</a></li>
|
|
198
228
|
<li><a href="https://gradle.org/">Gradle (Groovy and Kotlin DSL)</a> - <a href="https://gradle.org/install/">Gradle Installation</a></li>
|
|
229
|
+
<li><a href="https://www.rust-lang.org/">Rust</a> - <a href="https://doc.rust-lang.org/cargo/">Cargo</a></li>
|
|
199
230
|
</ul>
|
|
200
231
|
|
|
201
232
|
<h3>License Detection</h3>
|
|
@@ -203,7 +234,7 @@ $ trustify-da-javascript-client license /path/to/package.json
|
|
|
203
234
|
The client automatically detects your project's license with intelligent fallback:
|
|
204
235
|
</p>
|
|
205
236
|
<ul>
|
|
206
|
-
<li><strong>Manifest-first:</strong> For ecosystems with license support (Maven, JavaScript), reads from manifest file (<code>pom.xml</code>, <code>package.json</code>)</li>
|
|
237
|
+
<li><strong>Manifest-first:</strong> For ecosystems with license support (Maven, JavaScript, Rust Cargo), reads from manifest file (<code>pom.xml</code>, <code>package.json</code>, <code>Cargo.toml</code>)</li>
|
|
207
238
|
<li><strong>LICENSE file fallback:</strong> If no license in manifest, or for ecosystems without license support (Gradle, Go, Python), automatically reads from <code>LICENSE</code>, <code>LICENSE.md</code>, or <code>LICENSE.txt</code></li>
|
|
208
239
|
<li><strong>SBOM integration:</strong> Detected licenses are included in generated SBOMs for all ecosystems</li>
|
|
209
240
|
<li><strong>SPDX support:</strong> Automatically detects common licenses (Apache-2.0, MIT, GPL, BSD) from LICENSE file content</li>
|
|
@@ -334,7 +365,21 @@ test {
|
|
|
334
365
|
}
|
|
335
366
|
```
|
|
336
367
|
|
|
337
|
-
|
|
368
|
+
<em>Rust Cargo</em> users can add a comment with <code># trustify-da-ignore</code> (or <code># exhortignore</code>) in <em>Cargo.toml</em> next to the dependency to be ignored. This works for inline declarations, table-based declarations, and workspace-level dependency sections:
|
|
369
|
+
|
|
370
|
+
```toml
|
|
371
|
+
[dependencies]
|
|
372
|
+
serde = "1.0" # trustify-da-ignore
|
|
373
|
+
tokio = { version = "1.35", features = ["full"] }
|
|
374
|
+
|
|
375
|
+
[dependencies.regex] # trustify-da-ignore
|
|
376
|
+
version = "1.10"
|
|
377
|
+
|
|
378
|
+
[workspace.dependencies]
|
|
379
|
+
log = "0.4" # trustify-da-ignore
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
All of the 6 above examples are valid for marking a package to be ignored
|
|
338
383
|
</li>
|
|
339
384
|
|
|
340
385
|
</ul>
|
|
@@ -366,6 +411,9 @@ let options = {
|
|
|
366
411
|
'TRUSTIFY_DA_PYTHON_PATH' : '/path/to/python',
|
|
367
412
|
'TRUSTIFY_DA_PIP_PATH' : '/path/to/pip',
|
|
368
413
|
'TRUSTIFY_DA_GRADLE_PATH' : '/path/to/gradle',
|
|
414
|
+
'TRUSTIFY_DA_CARGO_PATH' : '/path/to/cargo',
|
|
415
|
+
// Workspace root for monorepos (Cargo, npm/pnpm/yarn); lock file expected here
|
|
416
|
+
'workspaceDir': '/path/to/workspace-root',
|
|
369
417
|
// Configure proxy for all requests
|
|
370
418
|
'TRUSTIFY_DA_PROXY_URL': 'http://proxy.example.com:8080'
|
|
371
419
|
}
|
|
@@ -388,6 +436,21 @@ let imageAnalysisWithArch = await client.imageAnalysis(['httpd:2.4.49^^amd64'],
|
|
|
388
436
|
**_Environment variables takes precedence._**
|
|
389
437
|
</p>
|
|
390
438
|
|
|
439
|
+
<h4>Monorepo / Workspace Support</h4>
|
|
440
|
+
<p>
|
|
441
|
+
For monorepos (Cargo workspaces, npm/pnpm/yarn workspaces) where the lock file lives at the workspace root rather than next to the manifest, pass the workspace root via <code>workspaceDir</code> or <code>TRUSTIFY_DA_WORKSPACE_DIR</code>:
|
|
442
|
+
</p>
|
|
443
|
+
<ul>
|
|
444
|
+
<li><strong>Cargo:</strong> When set, the client checks only the given directory for <code>Cargo.lock</code> instead of walking up from the manifest.</li>
|
|
445
|
+
<li><strong>JavaScript (npm, pnpm, yarn):</strong> When set, the client looks for the lock file (<code>package-lock.json</code>, <code>pnpm-lock.yaml</code>, <code>yarn.lock</code>) at the workspace root.</li>
|
|
446
|
+
</ul>
|
|
447
|
+
<p>
|
|
448
|
+
Use <code>stackAnalysisBatch(workspaceRoot, html, opts)</code> to analyze all packages/crates in a workspace in one request. Supports Cargo workspaces and JS/TS workspaces (pnpm, npm, yarn). Optional <code>batchConcurrency</code> (or <code>TRUSTIFY_DA_BATCH_CONCURRENCY</code>) limits parallel SBOM generation (default 10). For JS/TS, each <code>package.json</code> must have non-empty <code>name</code> and <code>version</code>; invalid manifests are skipped (warnings). Per-manifest SBOM failures are skipped if at least one SBOM succeeds (unless <code>continueOnError: false</code>). Set <code>batchMetadata: true</code> (or <code>TRUSTIFY_DA_BATCH_METADATA</code>) to receive <code>{ analysis, metadata }</code> with <code>errors[]</code>. CLI: <code>stack-batch --metadata</code>, <code>--fail-fast</code>. See <a href="./docs/monorepo-implementation-plan.md">monorepo implementation plan</a> §2.3 and §3.5.
|
|
449
|
+
</p>
|
|
450
|
+
<p>
|
|
451
|
+
See <a href="./docs/vscode-extension-integration-requirements.md">VS Code Extension Integration Requirements</a> for integration details.
|
|
452
|
+
</p>
|
|
453
|
+
|
|
391
454
|
<h4>Proxy Configuration</h4>
|
|
392
455
|
<p>
|
|
393
456
|
You can configure a proxy for all HTTP/HTTPS requests made by the API. This is useful when your environment requires going through a proxy to access external services.
|
|
@@ -411,7 +474,7 @@ The proxy URL should be in the format: `http://host:port` or `https://host:port`
|
|
|
411
474
|
|
|
412
475
|
<h4>License resolution and dependency license compliance</h4>
|
|
413
476
|
<p>
|
|
414
|
-
The client can resolve the <strong>project license</strong> from the manifest (e.g. <code>package.json</code> <code>license</code>, <code>pom.xml</code> <code><licenses></code>) and from a <code>LICENSE</code> or <code>LICENSE.md</code> file in the project, and report when they differ. For <strong>component analysis</strong>, you can optionally run a license check: the client fetches dependency licenses from the backend (by purl) and reports dependencies whose licenses are incompatible with the project license. See <a href="docs/license-resolution-and-compliance.md">License resolution and compliance</a> for design and behavior. To disable the check on component analysis, set <code>TRUSTIFY_DA_LICENSE_CHECK=false</code> or pass <code>licenseCheck: false</code> in the options.
|
|
477
|
+
The client can resolve the <strong>project license</strong> from the manifest (e.g. <code>package.json</code> <code>license</code>, <code>pom.xml</code> <code><licenses></code>, <code>Cargo.toml</code> <code>license</code>) and from a <code>LICENSE</code> or <code>LICENSE.md</code> file in the project, and report when they differ. For <strong>component analysis</strong>, you can optionally run a license check: the client fetches dependency licenses from the backend (by purl) and reports dependencies whose licenses are incompatible with the project license. See <a href="docs/license-resolution-and-compliance.md">License resolution and compliance</a> for design and behavior. To disable the check on component analysis, set <code>TRUSTIFY_DA_LICENSE_CHECK=false</code> or pass <code>licenseCheck: false</code> in the options.
|
|
415
478
|
</p>
|
|
416
479
|
|
|
417
480
|
<h4>Customizing Executables</h4>
|
|
@@ -487,6 +550,16 @@ following keys for setting custom paths for the said executables.
|
|
|
487
550
|
<td><em>gradle</em></td>
|
|
488
551
|
<td>TRUSTIFY_DA_PREFER_GRADLEW</td>
|
|
489
552
|
</tr>
|
|
553
|
+
<tr>
|
|
554
|
+
<td><a href="https://www.rust-lang.org/">Rust Cargo</a></td>
|
|
555
|
+
<td><em>cargo</em></td>
|
|
556
|
+
<td>TRUSTIFY_DA_CARGO_PATH</td>
|
|
557
|
+
</tr>
|
|
558
|
+
<tr>
|
|
559
|
+
<td>Workspace root (monorepos)</td>
|
|
560
|
+
<td>—</td>
|
|
561
|
+
<td>workspaceDir / TRUSTIFY_DA_WORKSPACE_DIR</td>
|
|
562
|
+
</tr>
|
|
490
563
|
</table>
|
|
491
564
|
|
|
492
565
|
#### Match Manifest Versions Feature
|
package/dist/package.json
CHANGED
|
@@ -50,12 +50,17 @@
|
|
|
50
50
|
"@babel/core": "^7.23.2",
|
|
51
51
|
"@cyclonedx/cyclonedx-library": "^6.13.0",
|
|
52
52
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
53
|
+
"fast-glob": "^3.3.3",
|
|
53
54
|
"fast-toml": "^0.5.4",
|
|
54
55
|
"fast-xml-parser": "^5.3.4",
|
|
55
56
|
"help": "^3.0.2",
|
|
56
57
|
"https-proxy-agent": "^7.0.6",
|
|
58
|
+
"js-yaml": "^4.1.1",
|
|
59
|
+
"micromatch": "^4.0.8",
|
|
57
60
|
"node-fetch": "^3.3.2",
|
|
61
|
+
"p-limit": "^5.0.0",
|
|
58
62
|
"packageurl-js": "~1.0.2",
|
|
63
|
+
"smol-toml": "^1.6.0",
|
|
59
64
|
"tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
|
|
60
65
|
"web-tree-sitter": "^0.26.6",
|
|
61
66
|
"yargs": "^18.0.0"
|
package/dist/src/analysis.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
declare namespace _default {
|
|
2
2
|
export { requestComponent };
|
|
3
3
|
export { requestStack };
|
|
4
|
+
export { requestStackBatch };
|
|
4
5
|
export { requestImages };
|
|
5
6
|
export { validateToken };
|
|
6
7
|
}
|
|
@@ -24,6 +25,19 @@ declare function requestComponent(provider: import("./provider").Provider, manif
|
|
|
24
25
|
* @returns {Promise<string|import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
|
|
25
26
|
*/
|
|
26
27
|
declare function requestStack(provider: import("./provider").Provider, manifest: string, url: string, html?: boolean, opts?: import("index.js").Options): Promise<string | import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
|
|
28
|
+
/**
|
|
29
|
+
* Send a batch stack analysis request for multiple manifests (SBOMs keyed by purl).
|
|
30
|
+
* @param {Object.<string, object>} sbomByPurl - Map of root purl to CycloneDX SBOM object
|
|
31
|
+
* @param {string} url - the backend url
|
|
32
|
+
* @param {boolean} [html=false] - true returns HTML, false returns JSON
|
|
33
|
+
* @param {import("index.js").Options} [opts={}]
|
|
34
|
+
* @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
35
|
+
*/
|
|
36
|
+
declare function requestStackBatch(sbomByPurl: {
|
|
37
|
+
[x: string]: any;
|
|
38
|
+
}, url: string, html?: boolean, opts?: import("index.js").Options): Promise<string | {
|
|
39
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
40
|
+
}>;
|
|
27
41
|
/**
|
|
28
42
|
*
|
|
29
43
|
* @param {Array<string>} imageRefs
|
package/dist/src/analysis.js
CHANGED
|
@@ -4,7 +4,7 @@ import { EOL } from "os";
|
|
|
4
4
|
import { runLicenseCheck } from "./license/index.js";
|
|
5
5
|
import { generateImageSBOM, parseImageRef } from "./oci_image/utils.js";
|
|
6
6
|
import { addProxyAgent, getCustom, getTokenHeaders, TRUSTIFY_DA_OPERATION_TYPE_HEADER, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER } from "./tools.js";
|
|
7
|
-
export default { requestComponent, requestStack, requestImages, validateToken };
|
|
7
|
+
export default { requestComponent, requestStack, requestStackBatch, requestImages, validateToken };
|
|
8
8
|
/**
|
|
9
9
|
* Send a stack analysis request and get the report as 'text/html' or 'application/json'.
|
|
10
10
|
* @param {import('./provider').Provider} provider - the provided data for constructing the request
|
|
@@ -124,6 +124,52 @@ async function requestComponent(provider, manifest, url, opts = {}) {
|
|
|
124
124
|
}
|
|
125
125
|
return Promise.resolve(result);
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Send a batch stack analysis request for multiple manifests (SBOMs keyed by purl).
|
|
129
|
+
* @param {Object.<string, object>} sbomByPurl - Map of root purl to CycloneDX SBOM object
|
|
130
|
+
* @param {string} url - the backend url
|
|
131
|
+
* @param {boolean} [html=false] - true returns HTML, false returns JSON
|
|
132
|
+
* @param {import("index.js").Options} [opts={}]
|
|
133
|
+
* @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
134
|
+
*/
|
|
135
|
+
async function requestStackBatch(sbomByPurl, url, html = false, opts = {}) {
|
|
136
|
+
const finalUrl = new URL(`${url}/api/v5/batch-analysis`);
|
|
137
|
+
if (opts['TRUSTIFY_DA_RECOMMENDATIONS_ENABLED'] === 'false') {
|
|
138
|
+
finalUrl.searchParams.append('recommend', 'false');
|
|
139
|
+
}
|
|
140
|
+
const fetchOptions = addProxyAgent({
|
|
141
|
+
method: 'POST',
|
|
142
|
+
headers: {
|
|
143
|
+
'Accept': html ? 'text/html' : 'application/json',
|
|
144
|
+
'Content-Type': 'application/json',
|
|
145
|
+
...getTokenHeaders(opts)
|
|
146
|
+
},
|
|
147
|
+
body: JSON.stringify(sbomByPurl)
|
|
148
|
+
}, opts);
|
|
149
|
+
const resp = await fetch(finalUrl, fetchOptions);
|
|
150
|
+
if (resp.status === 200) {
|
|
151
|
+
let result;
|
|
152
|
+
if (!html) {
|
|
153
|
+
result = await resp.json();
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
result = await resp.text();
|
|
157
|
+
}
|
|
158
|
+
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
159
|
+
const exRequestId = resp.headers.get("ex-request-id");
|
|
160
|
+
if (exRequestId) {
|
|
161
|
+
console.log("Unique Identifier associated with this request - ex-request-id=" + exRequestId);
|
|
162
|
+
}
|
|
163
|
+
console.log("Response body received from Trustify DA backend server : " + EOL + EOL);
|
|
164
|
+
console.log(JSON.stringify(result, null, 4));
|
|
165
|
+
console.log("Ending time of sending batch stack analysis request to Trustify DA backend server= " + new Date());
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
throw new Error(`Got error response from Trustify DA backend - http return code : ${resp.status}, ex-request-id: ${resp.headers.get("ex-request-id")} error message => ${await resp.text()}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
127
173
|
/**
|
|
128
174
|
*
|
|
129
175
|
* @param {Array<string>} imageRefs
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether to skip failed manifests and continue (default), or fail on first SBOM/validation error.
|
|
3
|
+
* `opts.continueOnError` overrides; env `TRUSTIFY_DA_CONTINUE_ON_ERROR=false` disables continuation.
|
|
4
|
+
*
|
|
5
|
+
* @param {{ continueOnError?: boolean, TRUSTIFY_DA_CONTINUE_ON_ERROR?: string, [key: string]: unknown }} [opts={}]
|
|
6
|
+
* @returns {boolean} true = collect errors (default), false = fail-fast
|
|
7
|
+
*/
|
|
8
|
+
export function resolveContinueOnError(opts?: {
|
|
9
|
+
continueOnError?: boolean;
|
|
10
|
+
TRUSTIFY_DA_CONTINUE_ON_ERROR?: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* When true, `stackAnalysisBatch` returns `{ analysis, metadata }` instead of the backend response only.
|
|
15
|
+
* `opts.batchMetadata` overrides; env `TRUSTIFY_DA_BATCH_METADATA=true` enables.
|
|
16
|
+
*
|
|
17
|
+
* @param {{ batchMetadata?: boolean, TRUSTIFY_DA_BATCH_METADATA?: string, [key: string]: unknown }} [opts={}]
|
|
18
|
+
* @returns {boolean}
|
|
19
|
+
*/
|
|
20
|
+
export function resolveBatchMetadata(opts?: {
|
|
21
|
+
batchMetadata?: boolean;
|
|
22
|
+
TRUSTIFY_DA_BATCH_METADATA?: string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getCustom } from './tools.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether to skip failed manifests and continue (default), or fail on first SBOM/validation error.
|
|
4
|
+
* `opts.continueOnError` overrides; env `TRUSTIFY_DA_CONTINUE_ON_ERROR=false` disables continuation.
|
|
5
|
+
*
|
|
6
|
+
* @param {{ continueOnError?: boolean, TRUSTIFY_DA_CONTINUE_ON_ERROR?: string, [key: string]: unknown }} [opts={}]
|
|
7
|
+
* @returns {boolean} true = collect errors (default), false = fail-fast
|
|
8
|
+
*/
|
|
9
|
+
export function resolveContinueOnError(opts = {}) {
|
|
10
|
+
if (typeof opts.continueOnError === 'boolean') {
|
|
11
|
+
return opts.continueOnError;
|
|
12
|
+
}
|
|
13
|
+
const v = getCustom('TRUSTIFY_DA_CONTINUE_ON_ERROR', null, opts);
|
|
14
|
+
if (v != null && String(v).trim() !== '') {
|
|
15
|
+
return String(v).toLowerCase() !== 'false';
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* When true, `stackAnalysisBatch` returns `{ analysis, metadata }` instead of the backend response only.
|
|
21
|
+
* `opts.batchMetadata` overrides; env `TRUSTIFY_DA_BATCH_METADATA=true` enables.
|
|
22
|
+
*
|
|
23
|
+
* @param {{ batchMetadata?: boolean, TRUSTIFY_DA_BATCH_METADATA?: string, [key: string]: unknown }} [opts={}]
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
export function resolveBatchMetadata(opts = {}) {
|
|
27
|
+
if (typeof opts.batchMetadata === 'boolean') {
|
|
28
|
+
return opts.batchMetadata;
|
|
29
|
+
}
|
|
30
|
+
const v = getCustom('TRUSTIFY_DA_BATCH_METADATA', null, opts);
|
|
31
|
+
if (v != null && String(v).trim() !== '') {
|
|
32
|
+
return String(v).toLowerCase() === 'true';
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
package/dist/src/cli.js
CHANGED
|
@@ -12,10 +12,18 @@ const component = {
|
|
|
12
12
|
desc: 'manifest path for analyzing',
|
|
13
13
|
type: 'string',
|
|
14
14
|
normalize: true,
|
|
15
|
+
}).options({
|
|
16
|
+
workspaceDir: {
|
|
17
|
+
alias: 'w',
|
|
18
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
19
|
+
type: 'string',
|
|
20
|
+
normalize: true,
|
|
21
|
+
}
|
|
15
22
|
}),
|
|
16
23
|
handler: async (args) => {
|
|
17
24
|
let manifestName = args['/path/to/manifest'];
|
|
18
|
-
|
|
25
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
26
|
+
let res = await client.componentAnalysis(manifestName, opts);
|
|
19
27
|
console.log(JSON.stringify(res, null, 2));
|
|
20
28
|
}
|
|
21
29
|
};
|
|
@@ -117,15 +125,22 @@ const stack = {
|
|
|
117
125
|
desc: 'For JSON report, get only the \'summary\'',
|
|
118
126
|
type: 'boolean',
|
|
119
127
|
conflicts: 'html'
|
|
128
|
+
},
|
|
129
|
+
workspaceDir: {
|
|
130
|
+
alias: 'w',
|
|
131
|
+
desc: 'Workspace root directory (for monorepos; lock file is expected here)',
|
|
132
|
+
type: 'string',
|
|
133
|
+
normalize: true,
|
|
120
134
|
}
|
|
121
135
|
}),
|
|
122
136
|
handler: async (args) => {
|
|
123
137
|
let manifest = args['/path/to/manifest'];
|
|
124
138
|
let html = args['html'];
|
|
125
139
|
let summary = args['summary'];
|
|
140
|
+
const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
|
|
126
141
|
let theProvidersSummary = new Map();
|
|
127
142
|
let theProvidersObject = {};
|
|
128
|
-
let res = await client.stackAnalysis(manifest, html);
|
|
143
|
+
let res = await client.stackAnalysis(manifest, html, opts);
|
|
129
144
|
if (summary) {
|
|
130
145
|
for (let provider in res.providers) {
|
|
131
146
|
if (res.providers[provider].sources !== undefined) {
|
|
@@ -143,6 +158,108 @@ const stack = {
|
|
|
143
158
|
console.log(html ? res : JSON.stringify(!html && summary ? theProvidersObject : res, null, 2));
|
|
144
159
|
}
|
|
145
160
|
};
|
|
161
|
+
// command for batch stack analysis (workspace)
|
|
162
|
+
const stackBatch = {
|
|
163
|
+
command: 'stack-batch </path/to/workspace-root> [--html|--summary] [--concurrency <n>] [--ignore <pattern>...] [--metadata] [--fail-fast]',
|
|
164
|
+
desc: 'produce stack report for all packages/crates in a workspace (Cargo or JS/TS)',
|
|
165
|
+
builder: yargs => yargs.positional('/path/to/workspace-root', {
|
|
166
|
+
desc: 'workspace root directory (containing Cargo.toml+Cargo.lock or package.json+lock file)',
|
|
167
|
+
type: 'string',
|
|
168
|
+
normalize: true,
|
|
169
|
+
}).options({
|
|
170
|
+
html: {
|
|
171
|
+
alias: 'r',
|
|
172
|
+
desc: 'Get the report as HTML instead of JSON',
|
|
173
|
+
type: 'boolean',
|
|
174
|
+
conflicts: 'summary'
|
|
175
|
+
},
|
|
176
|
+
summary: {
|
|
177
|
+
alias: 's',
|
|
178
|
+
desc: 'For JSON report, get only the \'summary\' per package',
|
|
179
|
+
type: 'boolean',
|
|
180
|
+
conflicts: 'html'
|
|
181
|
+
},
|
|
182
|
+
concurrency: {
|
|
183
|
+
alias: 'c',
|
|
184
|
+
desc: 'Max parallel SBOM generations (default: 10, env: TRUSTIFY_DA_BATCH_CONCURRENCY)',
|
|
185
|
+
type: 'number',
|
|
186
|
+
},
|
|
187
|
+
ignore: {
|
|
188
|
+
alias: 'i',
|
|
189
|
+
desc: 'Extra glob patterns excluded from workspace discovery (merged with defaults). Repeat flag per pattern. Env: TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE (comma-separated)',
|
|
190
|
+
type: 'string',
|
|
191
|
+
array: true,
|
|
192
|
+
},
|
|
193
|
+
metadata: {
|
|
194
|
+
alias: 'm',
|
|
195
|
+
desc: 'Return { analysis, metadata } with per-manifest errors (env: TRUSTIFY_DA_BATCH_METADATA=true)',
|
|
196
|
+
type: 'boolean',
|
|
197
|
+
default: false,
|
|
198
|
+
},
|
|
199
|
+
failFast: {
|
|
200
|
+
desc: 'Stop on first invalid package.json or SBOM error (env: TRUSTIFY_DA_CONTINUE_ON_ERROR=false)',
|
|
201
|
+
type: 'boolean',
|
|
202
|
+
default: false,
|
|
203
|
+
}
|
|
204
|
+
}),
|
|
205
|
+
handler: async (args) => {
|
|
206
|
+
const workspaceRoot = args['/path/to/workspace-root'];
|
|
207
|
+
const html = args['html'];
|
|
208
|
+
const summary = args['summary'];
|
|
209
|
+
const opts = {};
|
|
210
|
+
if (args.concurrency != null) {
|
|
211
|
+
opts.batchConcurrency = args.concurrency;
|
|
212
|
+
}
|
|
213
|
+
const extraIgnores = Array.isArray(args.ignore) ? args.ignore.filter(p => p != null && String(p).trim()) : [];
|
|
214
|
+
if (extraIgnores.length > 0) {
|
|
215
|
+
opts.workspaceDiscoveryIgnore = extraIgnores;
|
|
216
|
+
}
|
|
217
|
+
if (args.metadata) {
|
|
218
|
+
opts.batchMetadata = true;
|
|
219
|
+
}
|
|
220
|
+
if (args.failFast) {
|
|
221
|
+
opts.continueOnError = false;
|
|
222
|
+
}
|
|
223
|
+
let res = await client.stackAnalysisBatch(workspaceRoot, html, opts);
|
|
224
|
+
const batchAnalysis = res && typeof res === 'object' && res != null && 'analysis' in res ? res.analysis : res;
|
|
225
|
+
if (summary && !html && typeof batchAnalysis === 'object') {
|
|
226
|
+
const summaries = {};
|
|
227
|
+
for (const [purl, report] of Object.entries(batchAnalysis)) {
|
|
228
|
+
if (report?.providers) {
|
|
229
|
+
for (const provider of Object.keys(report.providers)) {
|
|
230
|
+
const sources = report.providers[provider]?.sources;
|
|
231
|
+
if (sources) {
|
|
232
|
+
for (const [source, data] of Object.entries(sources)) {
|
|
233
|
+
if (data?.summary) {
|
|
234
|
+
if (!summaries[purl]) {
|
|
235
|
+
summaries[purl] = {};
|
|
236
|
+
}
|
|
237
|
+
if (!summaries[purl][provider]) {
|
|
238
|
+
summaries[purl][provider] = {};
|
|
239
|
+
}
|
|
240
|
+
summaries[purl][provider][source] = data.summary;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (res && typeof res === 'object' && res != null && 'metadata' in res) {
|
|
248
|
+
res = { analysis: summaries, metadata: res.metadata };
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
res = summaries;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (html) {
|
|
255
|
+
const htmlContent = res && typeof res === 'object' && 'analysis' in res ? res.analysis : res;
|
|
256
|
+
console.log(htmlContent);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
console.log(JSON.stringify(res, null, 2));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
};
|
|
146
263
|
// command for license checking
|
|
147
264
|
const license = {
|
|
148
265
|
command: 'license </path/to/manifest>',
|
|
@@ -210,8 +327,9 @@ const license = {
|
|
|
210
327
|
};
|
|
211
328
|
// parse and invoke the command
|
|
212
329
|
yargs(hideBin(process.argv))
|
|
213
|
-
.usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|image|validate-token|license}`)
|
|
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}`)
|
|
214
331
|
.command(stack)
|
|
332
|
+
.command(stackBatch)
|
|
215
333
|
.command(component)
|
|
216
334
|
.command(image)
|
|
217
335
|
.command(validateToken)
|
|
@@ -120,6 +120,7 @@ export default class CycloneDxSbom {
|
|
|
120
120
|
getAsJsonString(opts) {
|
|
121
121
|
let manifestType = opts["manifest-type"];
|
|
122
122
|
this.setSourceManifest(opts["source-manifest"]);
|
|
123
|
+
const rootPurl = this.rootComponent?.purl;
|
|
123
124
|
this.sbomObject = {
|
|
124
125
|
"bomFormat": "CycloneDX",
|
|
125
126
|
"specVersion": "1.4",
|
|
@@ -129,7 +130,7 @@ export default class CycloneDxSbom {
|
|
|
129
130
|
"component": this.rootComponent,
|
|
130
131
|
"properties": new Array()
|
|
131
132
|
},
|
|
132
|
-
"components": this.components,
|
|
133
|
+
"components": this.components.filter(c => c.purl !== rootPurl),
|
|
133
134
|
"dependencies": this.dependencies
|
|
134
135
|
};
|
|
135
136
|
if (this.rootComponent === undefined) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -18,11 +18,13 @@ export { ImageRef } from "./oci_image/images.js";
|
|
|
18
18
|
declare namespace _default {
|
|
19
19
|
export { componentAnalysis };
|
|
20
20
|
export { stackAnalysis };
|
|
21
|
+
export { stackAnalysisBatch };
|
|
21
22
|
export { imageAnalysis };
|
|
22
23
|
export { validateToken };
|
|
23
24
|
}
|
|
24
25
|
export default _default;
|
|
25
26
|
export type Options = {
|
|
27
|
+
TRUSTIFY_DA_CARGO_PATH?: string | undefined;
|
|
26
28
|
TRUSTIFY_DA_DOCKER_PATH?: string | undefined;
|
|
27
29
|
TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED?: string | undefined;
|
|
28
30
|
TRUSTIFY_DA_GO_PATH?: string | undefined;
|
|
@@ -47,12 +49,43 @@ export type Options = {
|
|
|
47
49
|
TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined;
|
|
48
50
|
TRUSTIFY_DA_SYFT_PATH?: string | undefined;
|
|
49
51
|
TRUSTIFY_DA_YARN_PATH?: string | undefined;
|
|
52
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
|
|
50
53
|
TRUSTIFY_DA_LICENSE_CHECK?: string | undefined;
|
|
51
54
|
MATCH_MANIFEST_VERSIONS?: string | undefined;
|
|
52
55
|
TRUSTIFY_DA_SOURCE?: string | undefined;
|
|
53
56
|
TRUSTIFY_DA_TOKEN?: string | undefined;
|
|
54
57
|
TRUSTIFY_DA_TELEMETRY_ID?: string | undefined;
|
|
55
|
-
|
|
58
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
|
|
59
|
+
batchConcurrency?: number | undefined;
|
|
60
|
+
TRUSTIFY_DA_BATCH_CONCURRENCY?: string | undefined;
|
|
61
|
+
workspaceDiscoveryIgnore?: string[] | undefined;
|
|
62
|
+
TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string | undefined;
|
|
63
|
+
continueOnError?: boolean | undefined;
|
|
64
|
+
TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined;
|
|
65
|
+
batchMetadata?: boolean | undefined;
|
|
66
|
+
TRUSTIFY_DA_BATCH_METADATA?: string | undefined;
|
|
67
|
+
[key: string]: string | number | boolean | string[] | undefined;
|
|
68
|
+
};
|
|
69
|
+
export type BatchAnalysisMetadata = {
|
|
70
|
+
workspaceRoot: string;
|
|
71
|
+
ecosystem: "javascript" | "cargo" | "unknown";
|
|
72
|
+
total: number;
|
|
73
|
+
successful: number;
|
|
74
|
+
failed: number;
|
|
75
|
+
errors: Array<{
|
|
76
|
+
manifestPath: string;
|
|
77
|
+
phase: "validation" | "sbom";
|
|
78
|
+
reason: string;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
export type SbomResult = {
|
|
82
|
+
ok: true;
|
|
83
|
+
purl: string;
|
|
84
|
+
sbom: object;
|
|
85
|
+
} | {
|
|
86
|
+
ok: false;
|
|
87
|
+
manifestPath: string;
|
|
88
|
+
reason: string;
|
|
56
89
|
};
|
|
57
90
|
/**
|
|
58
91
|
* Get component analysis report for a manifest content.
|
|
@@ -91,6 +124,26 @@ declare function stackAnalysis(manifest: string, html: false, opts?: Options | u
|
|
|
91
124
|
* or backend request failed
|
|
92
125
|
*/
|
|
93
126
|
declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
|
|
127
|
+
/**
|
|
128
|
+
* Get stack analysis for all workspace packages/crates (batch).
|
|
129
|
+
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
130
|
+
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
131
|
+
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
132
|
+
*
|
|
133
|
+
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
134
|
+
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
135
|
+
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
136
|
+
* @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 }>}
|
|
137
|
+
* @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.
|
|
138
|
+
*/
|
|
139
|
+
declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean, opts?: Options): Promise<string | {
|
|
140
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
141
|
+
} | {
|
|
142
|
+
analysis: string | {
|
|
143
|
+
[x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
|
|
144
|
+
};
|
|
145
|
+
metadata: BatchAnalysisMetadata;
|
|
146
|
+
}>;
|
|
94
147
|
/**
|
|
95
148
|
* @overload
|
|
96
149
|
* @param {Array<string>} imageRefs
|
|
@@ -131,4 +184,12 @@ declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefi
|
|
|
131
184
|
* @throws {Error} if the backend request failed.
|
|
132
185
|
*/
|
|
133
186
|
declare function validateToken(opts?: Options): Promise<object>;
|
|
187
|
+
import { discoverWorkspacePackages } from './workspace.js';
|
|
188
|
+
import { discoverWorkspaceCrates } from './workspace.js';
|
|
189
|
+
import { validatePackageJson } from './workspace.js';
|
|
190
|
+
import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
|
|
191
|
+
import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
|
|
192
|
+
import { resolveContinueOnError } from './batch_opts.js';
|
|
193
|
+
import { resolveBatchMetadata } from './batch_opts.js';
|
|
194
|
+
export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
|
|
134
195
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|