@trustify-da/trustify-da-javascript-client 0.3.0-ea.9988076 → 0.3.0-ea.9a6adf7
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 +127 -10
- package/dist/package.json +27 -23
- package/dist/src/analysis.d.ts +21 -5
- package/dist/src/analysis.js +53 -4
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +171 -4
- package/dist/src/cyclone_dx_sbom.d.ts +14 -1
- package/dist/src/cyclone_dx_sbom.js +43 -8
- package/dist/src/index.d.ts +137 -6
- package/dist/src/index.js +350 -5
- package/dist/src/license/index.d.ts +3 -3
- package/dist/src/license/index.js +4 -1
- package/dist/src/license/license_utils.js +4 -1
- package/dist/src/license/licenses_api.d.ts +2 -2
- package/dist/src/oci_image/images.d.ts +1 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/provider.d.ts +8 -4
- package/dist/src/provider.js +13 -4
- package/dist/src/providers/base_java.d.ts +14 -12
- package/dist/src/providers/base_java.js +18 -44
- package/dist/src/providers/base_javascript.d.ts +37 -10
- package/dist/src/providers/base_javascript.js +108 -20
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/golang_gomodules.d.ts +23 -13
- package/dist/src/providers/golang_gomodules.js +165 -119
- 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 +19 -0
- package/dist/src/providers/java_gradle.js +116 -2
- 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 +10 -2
- package/dist/src/providers/java_maven.js +165 -1
- package/dist/src/providers/javascript_bun.d.ts +10 -0
- package/dist/src/providers/javascript_bun.js +100 -0
- package/dist/src/providers/javascript_npm.d.ts +6 -0
- package/dist/src/providers/javascript_npm.js +21 -0
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +8 -4
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +65 -7
- package/dist/src/providers/python_pip.d.ts +5 -0
- package/dist/src/providers/python_pip.js +6 -6
- package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
- package/dist/src/providers/python_pip_pyproject.js +146 -0
- package/dist/src/providers/python_poetry.d.ts +98 -0
- package/dist/src/providers/python_poetry.js +286 -0
- package/dist/src/providers/python_uv.d.ts +46 -0
- package/dist/src/providers/python_uv.js +269 -0
- package/dist/src/providers/rust_cargo.d.ts +12 -3
- package/dist/src/providers/rust_cargo.js +41 -6
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/sbom.d.ts +14 -1
- package/dist/src/sbom.js +13 -2
- package/dist/src/tools.d.ts +28 -2
- package/dist/src/tools.js +58 -0
- package/dist/src/workspace.d.ts +70 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +28 -24
package/dist/src/index.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { EOL } from "os";
|
|
3
|
+
import pLimit from 'p-limit';
|
|
3
4
|
import { availableProviders, match } from './provider.js';
|
|
4
5
|
import analysis from './analysis.js';
|
|
5
6
|
import fs from 'node:fs';
|
|
6
7
|
import { getCustom } from "./tools.js";
|
|
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';
|
|
12
|
+
import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
|
|
13
|
+
import { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
|
|
7
14
|
import.meta.dirname;
|
|
8
15
|
import * as url from 'url';
|
|
9
16
|
export { parseImageRef } from "./oci_image/utils.js";
|
|
10
17
|
export { ImageRef } from "./oci_image/images.js";
|
|
11
18
|
export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
|
|
12
|
-
export default { componentAnalysis, stackAnalysis, imageAnalysis, validateToken };
|
|
19
|
+
export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
|
|
20
|
+
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
13
21
|
/**
|
|
14
22
|
* @typedef {{
|
|
15
23
|
* TRUSTIFY_DA_CARGO_PATH?: string | undefined,
|
|
@@ -37,14 +45,36 @@ export default { componentAnalysis, stackAnalysis, imageAnalysis, validateToken
|
|
|
37
45
|
* TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined,
|
|
38
46
|
* TRUSTIFY_DA_SYFT_PATH?: string | undefined,
|
|
39
47
|
* TRUSTIFY_DA_YARN_PATH?: string | undefined,
|
|
48
|
+
* TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
|
|
40
49
|
* TRUSTIFY_DA_LICENSE_CHECK?: string | undefined,
|
|
41
50
|
* MATCH_MANIFEST_VERSIONS?: string | undefined,
|
|
42
51
|
* TRUSTIFY_DA_SOURCE?: string | undefined,
|
|
43
52
|
* TRUSTIFY_DA_TOKEN?: string | undefined,
|
|
44
53
|
* TRUSTIFY_DA_TELEMETRY_ID?: string | undefined,
|
|
45
|
-
*
|
|
54
|
+
* TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
|
|
55
|
+
* batchConcurrency?: number | undefined,
|
|
56
|
+
* TRUSTIFY_DA_BATCH_CONCURRENCY?: string | undefined,
|
|
57
|
+
* workspaceDiscoveryIgnore?: string[] | undefined,
|
|
58
|
+
* TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string | undefined,
|
|
59
|
+
* continueOnError?: boolean | undefined,
|
|
60
|
+
* TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined,
|
|
61
|
+
* batchMetadata?: boolean | undefined,
|
|
62
|
+
* TRUSTIFY_DA_BATCH_METADATA?: string | undefined,
|
|
63
|
+
* TRUSTIFY_DA_UV_PATH?: string | undefined,
|
|
64
|
+
* TRUSTIFY_DA_POETRY_PATH?: string | undefined,
|
|
65
|
+
* [key: string]: string | number | boolean | string[] | undefined,
|
|
46
66
|
* }} Options
|
|
47
67
|
*/
|
|
68
|
+
/**
|
|
69
|
+
* @typedef {{
|
|
70
|
+
* workspaceRoot: string,
|
|
71
|
+
* ecosystem: 'javascript' | 'cargo' | 'pyproject' | 'unknown',
|
|
72
|
+
* total: number,
|
|
73
|
+
* successful: number,
|
|
74
|
+
* failed: number,
|
|
75
|
+
* errors: Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>
|
|
76
|
+
* }} BatchAnalysisMetadata
|
|
77
|
+
*/
|
|
48
78
|
/**
|
|
49
79
|
* Logs messages to the console if the TRUSTIFY_DA_DEBUG environment variable is set to "true".
|
|
50
80
|
* @param {string} alongsideText - The text to prepend to the log message.
|
|
@@ -130,7 +160,7 @@ export function selectTrustifyDABackend(opts = {}) {
|
|
|
130
160
|
async function stackAnalysis(manifest, html = false, opts = {}) {
|
|
131
161
|
const theUrl = selectTrustifyDABackend(opts);
|
|
132
162
|
fs.accessSync(manifest, fs.constants.R_OK); // throws error if file unreadable
|
|
133
|
-
let provider = match(manifest, availableProviders); // throws error if no matching provider
|
|
163
|
+
let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
|
|
134
164
|
return await analysis.requestStack(provider, manifest, theUrl, html, opts); // throws error request sending failed
|
|
135
165
|
}
|
|
136
166
|
/**
|
|
@@ -144,8 +174,10 @@ async function componentAnalysis(manifest, opts = {}) {
|
|
|
144
174
|
const theUrl = selectTrustifyDABackend(opts);
|
|
145
175
|
fs.accessSync(manifest, fs.constants.R_OK);
|
|
146
176
|
opts["manifest-type"] = path.basename(manifest);
|
|
147
|
-
let provider = match(manifest, availableProviders); // throws error if no matching provider
|
|
148
|
-
|
|
177
|
+
let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
|
|
178
|
+
const result = await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
|
|
179
|
+
result.packageManager = provider.packageManagerName();
|
|
180
|
+
return result;
|
|
149
181
|
}
|
|
150
182
|
/**
|
|
151
183
|
* @overload
|
|
@@ -177,6 +209,319 @@ async function imageAnalysis(imageRefs, html = false, opts = {}) {
|
|
|
177
209
|
const theUrl = selectTrustifyDABackend(opts);
|
|
178
210
|
return await analysis.requestImages(imageRefs, theUrl, html, opts);
|
|
179
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Max concurrent SBOM generations for batch workspace analysis. Env/opts override default 10.
|
|
214
|
+
* @param {Options} opts
|
|
215
|
+
* @returns {number}
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
function resolveBatchConcurrency(opts) {
|
|
219
|
+
const fromEnv = getCustom('TRUSTIFY_DA_BATCH_CONCURRENCY', null, opts);
|
|
220
|
+
const raw = opts.batchConcurrency ?? fromEnv ?? '10';
|
|
221
|
+
const n = typeof raw === 'number' ? raw : parseInt(String(raw), 10);
|
|
222
|
+
if (!Number.isFinite(n) || n < 1) {
|
|
223
|
+
return 10;
|
|
224
|
+
}
|
|
225
|
+
return Math.min(256, n);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* @param {string} root
|
|
229
|
+
* @param {'javascript' | 'cargo' | 'unknown'} ecosystem
|
|
230
|
+
* @param {number} totalSbomAttempts
|
|
231
|
+
* @param {number} successfulSbomCount
|
|
232
|
+
* @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} errors
|
|
233
|
+
* @returns {BatchAnalysisMetadata}
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
function buildBatchAnalysisMetadata(root, ecosystem, totalSbomAttempts, successfulSbomCount, errors) {
|
|
237
|
+
return {
|
|
238
|
+
workspaceRoot: root,
|
|
239
|
+
ecosystem,
|
|
240
|
+
total: totalSbomAttempts,
|
|
241
|
+
successful: successfulSbomCount,
|
|
242
|
+
failed: errors.length,
|
|
243
|
+
errors: [...errors],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Generate a CycloneDX SBOM from a manifest file. No backend HTTP request is made.
|
|
248
|
+
*
|
|
249
|
+
* @param {string} manifestPath - path to the manifest file (e.g. pom.xml, package.json)
|
|
250
|
+
* @param {Options} [opts={}] - optional options (e.g. workspace dir, tool paths)
|
|
251
|
+
* @returns {Promise<object>} parsed CycloneDX SBOM JSON object
|
|
252
|
+
* @throws {Error} if the manifest is unsupported or SBOM generation fails
|
|
253
|
+
*/
|
|
254
|
+
export async function generateSbom(manifestPath, opts = {}) {
|
|
255
|
+
fs.accessSync(manifestPath, fs.constants.R_OK);
|
|
256
|
+
const result = await generateOneSbom(manifestPath, opts);
|
|
257
|
+
if (!result.ok) {
|
|
258
|
+
throw new Error(`Failed to generate SBOM for ${result.manifestPath}: ${result.reason}`);
|
|
259
|
+
}
|
|
260
|
+
return result.sbom;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* @typedef {{ ok: true, purl: string, sbom: object } | { ok: false, manifestPath: string, reason: string }} SbomResult
|
|
264
|
+
*/
|
|
265
|
+
/**
|
|
266
|
+
* Generate an SBOM for a single manifest, returning a normalized result.
|
|
267
|
+
*
|
|
268
|
+
* @param {string} manifestPath
|
|
269
|
+
* @param {Options} workspaceOpts - opts with `TRUSTIFY_DA_WORKSPACE_DIR` set
|
|
270
|
+
* @returns {Promise<SbomResult>}
|
|
271
|
+
* @private
|
|
272
|
+
*/
|
|
273
|
+
async function generateOneSbom(manifestPath, workspaceOpts) {
|
|
274
|
+
const provider = match(manifestPath, availableProviders, workspaceOpts);
|
|
275
|
+
const provided = await provider.provideStack(manifestPath, workspaceOpts);
|
|
276
|
+
const sbom = JSON.parse(provided.content);
|
|
277
|
+
const purl = sbom?.metadata?.component?.purl || sbom?.metadata?.component?.['bom-ref'];
|
|
278
|
+
if (!purl) {
|
|
279
|
+
return { ok: false, manifestPath, reason: 'missing purl in SBOM' };
|
|
280
|
+
}
|
|
281
|
+
return { ok: true, purl, sbom };
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Detect the workspace ecosystem and discover manifest paths.
|
|
285
|
+
*
|
|
286
|
+
* @param {string} root - Resolved workspace root
|
|
287
|
+
* @param {Options} opts
|
|
288
|
+
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'gradle' | 'gomodules' | 'pyproject' | 'unknown', manifestPaths: string[] }>}
|
|
289
|
+
* @private
|
|
290
|
+
*/
|
|
291
|
+
async function detectWorkspaceManifests(root, opts) {
|
|
292
|
+
const cargoToml = path.join(root, 'Cargo.toml');
|
|
293
|
+
const cargoLock = path.join(root, 'Cargo.lock');
|
|
294
|
+
const packageJson = path.join(root, 'package.json');
|
|
295
|
+
const pomXml = path.join(root, 'pom.xml');
|
|
296
|
+
if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
|
|
297
|
+
return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
|
|
298
|
+
}
|
|
299
|
+
if (fs.existsSync(pomXml)) {
|
|
300
|
+
const manifestPaths = await discoverMavenModules(root, opts);
|
|
301
|
+
if (manifestPaths.length > 0) {
|
|
302
|
+
return { ecosystem: 'maven', manifestPaths };
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const hasGradleSettings = fs.existsSync(path.join(root, 'settings.gradle'))
|
|
306
|
+
|| fs.existsSync(path.join(root, 'settings.gradle.kts'));
|
|
307
|
+
if (hasGradleSettings) {
|
|
308
|
+
const manifestPaths = await discoverGradleSubprojects(root, opts);
|
|
309
|
+
if (manifestPaths.length > 0) {
|
|
310
|
+
return { ecosystem: 'gradle', manifestPaths };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (fs.existsSync(path.join(root, 'go.work'))) {
|
|
314
|
+
const manifestPaths = await discoverGoWorkspaceModules(root, opts);
|
|
315
|
+
if (manifestPaths.length > 0) {
|
|
316
|
+
return { ecosystem: 'gomodules', manifestPaths };
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (fs.existsSync(path.join(root, 'pyproject.toml')) && fs.existsSync(path.join(root, 'uv.lock'))) {
|
|
320
|
+
const manifestPaths = await discoverUvWorkspaceMembers(root, opts);
|
|
321
|
+
if (manifestPaths.length > 0) {
|
|
322
|
+
return { ecosystem: 'pyproject', manifestPaths };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const hasJsLock = fs.existsSync(path.join(root, 'bun.lock'))
|
|
326
|
+
|| fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
|
|
327
|
+
|| fs.existsSync(path.join(root, 'yarn.lock'))
|
|
328
|
+
|| fs.existsSync(path.join(root, 'package-lock.json'));
|
|
329
|
+
if (fs.existsSync(packageJson) && hasJsLock) {
|
|
330
|
+
let manifestPaths = await discoverWorkspacePackages(root, opts);
|
|
331
|
+
if (manifestPaths.length === 0) {
|
|
332
|
+
manifestPaths = [packageJson];
|
|
333
|
+
}
|
|
334
|
+
return { ecosystem: 'javascript', manifestPaths };
|
|
335
|
+
}
|
|
336
|
+
return { ecosystem: 'unknown', manifestPaths: [] };
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Validate discovered JS package.json manifests, collecting errors.
|
|
340
|
+
*
|
|
341
|
+
* @param {string[]} manifestPaths
|
|
342
|
+
* @param {boolean} continueOnError
|
|
343
|
+
* @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} collectedErrors - mutated in place
|
|
344
|
+
* @returns {{ validPaths: string[] }}
|
|
345
|
+
* @throws {Error} on first invalid manifest when `continueOnError` is false
|
|
346
|
+
* @private
|
|
347
|
+
*/
|
|
348
|
+
function validateJsManifests(manifestPaths, continueOnError, collectedErrors) {
|
|
349
|
+
const validPaths = [];
|
|
350
|
+
for (const p of manifestPaths) {
|
|
351
|
+
const v = validatePackageJson(p);
|
|
352
|
+
if (v.valid) {
|
|
353
|
+
validPaths.push(p);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
collectedErrors.push({ manifestPath: p, phase: 'validation', reason: v.error });
|
|
357
|
+
console.warn(`Skipping invalid package.json (${v.error}): ${p}`);
|
|
358
|
+
if (!continueOnError) {
|
|
359
|
+
throw new Error(`Invalid package.json (${v.error}): ${p}`);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return { validPaths };
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Generate SBOMs for all manifests. In fail-fast mode, stops on first error.
|
|
367
|
+
* In continue-on-error mode, runs concurrently and collects failures.
|
|
368
|
+
*
|
|
369
|
+
* @param {string[]} manifestPaths
|
|
370
|
+
* @param {Options} workspaceOpts
|
|
371
|
+
* @param {boolean} continueOnError
|
|
372
|
+
* @param {number} concurrency
|
|
373
|
+
* @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} collectedErrors - mutated in place
|
|
374
|
+
* @returns {Promise<Object.<string, object>>} sbomByPurl map
|
|
375
|
+
* @throws {Error} on first SBOM failure when `continueOnError` is false
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
378
|
+
async function generateSboms(manifestPaths, workspaceOpts, continueOnError, concurrency, collectedErrors) {
|
|
379
|
+
/** @type {SbomResult[]} */
|
|
380
|
+
const results = [];
|
|
381
|
+
if (!continueOnError) {
|
|
382
|
+
for (const manifestPath of manifestPaths) {
|
|
383
|
+
const result = await generateOneSbom(manifestPath, workspaceOpts);
|
|
384
|
+
if (!result.ok) {
|
|
385
|
+
collectedErrors.push({ manifestPath: result.manifestPath, phase: 'sbom', reason: result.reason });
|
|
386
|
+
throw new Error(`${result.manifestPath}: ${result.reason}`);
|
|
387
|
+
}
|
|
388
|
+
results.push(result);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
const limit = pLimit(concurrency);
|
|
393
|
+
const settled = await Promise.all(manifestPaths.map(manifestPath => limit(async () => {
|
|
394
|
+
try {
|
|
395
|
+
return await generateOneSbom(manifestPath, workspaceOpts);
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
399
|
+
if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
|
|
400
|
+
console.log(`Skipping ${manifestPath}: ${msg}`);
|
|
401
|
+
}
|
|
402
|
+
return { ok: false, manifestPath, reason: msg };
|
|
403
|
+
}
|
|
404
|
+
})));
|
|
405
|
+
for (const r of settled) {
|
|
406
|
+
results.push(r);
|
|
407
|
+
if (!r.ok) {
|
|
408
|
+
collectedErrors.push({ manifestPath: r.manifestPath, phase: 'sbom', reason: r.reason });
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const sbomByPurl = {};
|
|
413
|
+
for (const r of results) {
|
|
414
|
+
if (r.ok) {
|
|
415
|
+
sbomByPurl[r.purl] = r.sbom;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return sbomByPurl;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Create an Error with optional `batchMetadata` attached.
|
|
422
|
+
* @param {string} message
|
|
423
|
+
* @param {boolean} wantMetadata
|
|
424
|
+
* @param {BatchAnalysisMetadata} [metadata]
|
|
425
|
+
* @returns {Error}
|
|
426
|
+
* @private
|
|
427
|
+
*/
|
|
428
|
+
function batchError(message, wantMetadata, metadata) {
|
|
429
|
+
const err = new Error(message);
|
|
430
|
+
if (wantMetadata && metadata) {
|
|
431
|
+
err.batchMetadata = metadata;
|
|
432
|
+
}
|
|
433
|
+
return err;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* @overload
|
|
437
|
+
* @param {string} workspaceRoot
|
|
438
|
+
* @param {true} html
|
|
439
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
440
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
441
|
+
* @throws {Error}
|
|
442
|
+
*/
|
|
443
|
+
/**
|
|
444
|
+
* @overload
|
|
445
|
+
* @param {string} workspaceRoot
|
|
446
|
+
* @param {true} html
|
|
447
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
448
|
+
* @returns {Promise<string>}
|
|
449
|
+
* @throws {Error}
|
|
450
|
+
*/
|
|
451
|
+
/**
|
|
452
|
+
* @overload
|
|
453
|
+
* @param {string} workspaceRoot
|
|
454
|
+
* @param {false} html
|
|
455
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
456
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
457
|
+
* @throws {Error}
|
|
458
|
+
*/
|
|
459
|
+
/**
|
|
460
|
+
* @overload
|
|
461
|
+
* @param {string} workspaceRoot
|
|
462
|
+
* @param {false} html
|
|
463
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
464
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
465
|
+
* @throws {Error}
|
|
466
|
+
*/
|
|
467
|
+
/**
|
|
468
|
+
* Get stack analysis for all workspace packages/crates (batch).
|
|
469
|
+
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
470
|
+
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
471
|
+
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
472
|
+
*
|
|
473
|
+
* @overload
|
|
474
|
+
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
475
|
+
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
476
|
+
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
477
|
+
* @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 }>}
|
|
478
|
+
* @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.
|
|
479
|
+
*/
|
|
480
|
+
async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
|
|
481
|
+
const theUrl = selectTrustifyDABackend(opts);
|
|
482
|
+
const root = path.resolve(workspaceRoot);
|
|
483
|
+
fs.accessSync(root, fs.constants.R_OK);
|
|
484
|
+
const continueOnError = resolveContinueOnError(opts);
|
|
485
|
+
const wantMetadata = resolveBatchMetadata(opts);
|
|
486
|
+
/** @type {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} */
|
|
487
|
+
const collectedErrors = [];
|
|
488
|
+
const { ecosystem, manifestPaths: discovered } = await detectWorkspaceManifests(root, opts);
|
|
489
|
+
let manifestPaths = discovered;
|
|
490
|
+
if (ecosystem === 'javascript') {
|
|
491
|
+
try {
|
|
492
|
+
const { validPaths } = validateJsManifests(manifestPaths, continueOnError, collectedErrors);
|
|
493
|
+
manifestPaths = validPaths;
|
|
494
|
+
}
|
|
495
|
+
catch (err) {
|
|
496
|
+
throw batchError(err.message, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, 0, 0, collectedErrors));
|
|
497
|
+
}
|
|
498
|
+
if (manifestPaths.length === 0 && discovered.length > 0) {
|
|
499
|
+
const detail = collectedErrors.map(e => `${e.manifestPath}: ${e.reason}`).join('; ');
|
|
500
|
+
throw batchError(`No valid packages after validation at ${root}. ${detail}`, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, 0, 0, collectedErrors));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (manifestPaths.length === 0) {
|
|
504
|
+
throw new Error(`No workspace manifests found at ${root}. Ensure a supported workspace root exists (Cargo.toml+Cargo.lock, pom.xml, build.gradle, go.work, pyproject.toml+uv.lock, or package.json+lock file).`);
|
|
505
|
+
}
|
|
506
|
+
const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
|
|
507
|
+
const concurrency = resolveBatchConcurrency(opts);
|
|
508
|
+
let sbomByPurl;
|
|
509
|
+
try {
|
|
510
|
+
sbomByPurl = await generateSboms(manifestPaths, workspaceOpts, continueOnError, concurrency, collectedErrors);
|
|
511
|
+
}
|
|
512
|
+
catch (err) {
|
|
513
|
+
throw batchError(err.message, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, 0, collectedErrors));
|
|
514
|
+
}
|
|
515
|
+
if (Object.keys(sbomByPurl).length === 0) {
|
|
516
|
+
throw batchError(`No valid SBOMs produced from ${manifestPaths.length} manifest(s) at ${root}`, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, 0, collectedErrors));
|
|
517
|
+
}
|
|
518
|
+
const analysisResult = await analysis.requestStackBatch(sbomByPurl, theUrl, html, opts);
|
|
519
|
+
const meta = buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, Object.keys(sbomByPurl).length, collectedErrors);
|
|
520
|
+
if (wantMetadata) {
|
|
521
|
+
return { analysis: analysisResult, metadata: meta };
|
|
522
|
+
}
|
|
523
|
+
return analysisResult;
|
|
524
|
+
}
|
|
180
525
|
/**
|
|
181
526
|
* Validates the Exhort token.
|
|
182
527
|
* @param {Options} [opts={}] - Optional parameters, potentially including token override.
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* @param {import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport} [analysisResult] - analysis result that includes licenses array from backend
|
|
10
10
|
* @returns {Promise<{ projectLicense: { manifest: Object|null, file: Object|null, mismatch: boolean }, incompatibleDependencies: Array<{ purl: string, licenses: string[], category?: string, reason: string }>, error?: string }>}
|
|
11
11
|
*/
|
|
12
|
-
export function runLicenseCheck(sbomContent: string, manifestPath: string, url: string, opts?: import("../index.js").Options, analysisResult?:
|
|
12
|
+
export function runLicenseCheck(sbomContent: string, manifestPath: string, url: string, opts?: import("../index.js").Options, analysisResult?: any): Promise<{
|
|
13
13
|
projectLicense: {
|
|
14
|
-
manifest:
|
|
15
|
-
file:
|
|
14
|
+
manifest: Object | null;
|
|
15
|
+
file: Object | null;
|
|
16
16
|
mismatch: boolean;
|
|
17
17
|
};
|
|
18
18
|
incompatibleDependencies: Array<{
|
|
@@ -85,11 +85,14 @@ export async function runLicenseCheck(sbomContent, manifestPath, url, opts = {},
|
|
|
85
85
|
continue;
|
|
86
86
|
const status = getCompatibility(projectCategory, entry.category);
|
|
87
87
|
if (status === 'incompatible') {
|
|
88
|
+
const reason = entry.category?.toUpperCase() === 'UNKNOWN'
|
|
89
|
+
? 'License not recognized as a standard SPDX identifier. Manual review recommended to verify compatibility.'
|
|
90
|
+
: 'Dependency license(s) are incompatible with the project license.';
|
|
88
91
|
incompatibleDependencies.push({
|
|
89
92
|
purl,
|
|
90
93
|
licenses: entry.licenses,
|
|
91
94
|
category: entry.category,
|
|
92
|
-
reason
|
|
95
|
+
reason
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
}
|
|
@@ -114,9 +114,12 @@ export function getCompatibility(projectCategory, dependencyCategory) {
|
|
|
114
114
|
}
|
|
115
115
|
const proj = projectCategory.toUpperCase();
|
|
116
116
|
const dep = dependencyCategory.toUpperCase();
|
|
117
|
-
if (proj === 'UNKNOWN'
|
|
117
|
+
if (proj === 'UNKNOWN') {
|
|
118
118
|
return 'unknown';
|
|
119
119
|
}
|
|
120
|
+
if (dep === 'UNKNOWN') {
|
|
121
|
+
return 'incompatible';
|
|
122
|
+
}
|
|
120
123
|
const restrictiveness = {
|
|
121
124
|
'PERMISSIVE': 1,
|
|
122
125
|
'WEAK_COPYLEFT': 2,
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @param {import('../index.js').Options} [opts={}] - options (proxy, token, TRUSTIFY_DA_BACKEND_URL, etc.)
|
|
7
7
|
* @returns {Promise<Object|null>} License details or null if not found
|
|
8
8
|
*/
|
|
9
|
-
export function getLicenseDetails(spdxId: string, opts?: import("../index.js").Options): Promise<
|
|
9
|
+
export function getLicenseDetails(spdxId: string, opts?: import("../index.js").Options): Promise<Object | null>;
|
|
10
10
|
/**
|
|
11
11
|
* Normalize the LicensesResponse shape (array of LicenseProviderResult) into a map of purl -> license info.
|
|
12
12
|
* Each provider result has { status, summary, packages } where packages is { [purl]: { concluded, evidence } }.
|
|
@@ -28,7 +28,7 @@ export function normalizeLicensesResponse(data: unknown, purls?: string[]): Map<
|
|
|
28
28
|
* @param {string[]} [purls] - optional list of purls to restrict to
|
|
29
29
|
* @returns {Map<string, { licenses: string[], category?: string }>}
|
|
30
30
|
*/
|
|
31
|
-
export function licensesFromReport(analysisReport:
|
|
31
|
+
export function licensesFromReport(analysisReport: any, purls?: string[]): Map<string, {
|
|
32
32
|
licenses: string[];
|
|
33
33
|
category?: string;
|
|
34
34
|
}>;
|
|
@@ -78,7 +78,7 @@ export class ImageRef {
|
|
|
78
78
|
* @param {string} [platform]
|
|
79
79
|
* @param {import("index.js").Options} [opts={}]
|
|
80
80
|
*/
|
|
81
|
-
constructor(image: string, platform?: string, opts?:
|
|
81
|
+
constructor(image: string, platform?: string, opts?: any);
|
|
82
82
|
/** @type {Image} */
|
|
83
83
|
image: Image;
|
|
84
84
|
/** @type {Platform} */
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {import("../index.js").Options} [opts={}] - optional various options to pass along the application
|
|
5
5
|
* @returns {{}}
|
|
6
6
|
*/
|
|
7
|
-
export function generateImageSBOM(imageRef:
|
|
7
|
+
export function generateImageSBOM(imageRef: any, opts?: import("../index.js").Options): {};
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
* @param {string} image
|
|
@@ -25,7 +25,7 @@ export function getImagePlatform(opts?: import("../index.js").Options): Platform
|
|
|
25
25
|
* @returns {Object.<string, string>} - The image digests
|
|
26
26
|
* @throws {Error} If the image info is invalid
|
|
27
27
|
*/
|
|
28
|
-
export function getImageDigests(imageRef:
|
|
28
|
+
export function getImageDigests(imageRef: any, opts?: import("../index.js").Options): {
|
|
29
29
|
[x: string]: string;
|
|
30
30
|
};
|
|
31
31
|
export type SyftImageSource = {
|
|
@@ -34,9 +34,9 @@ export type SyftImageSource = {
|
|
|
34
34
|
getVariant: () => string;
|
|
35
35
|
};
|
|
36
36
|
export type SyftImageSourceType = {
|
|
37
|
-
getOs: (arg0:
|
|
38
|
-
getArch: (arg0:
|
|
39
|
-
getVariant: (arg0:
|
|
37
|
+
getOs: (arg0: Object) => string;
|
|
38
|
+
getArch: (arg0: Object) => string;
|
|
39
|
+
getVariant: (arg0: Object) => string;
|
|
40
40
|
};
|
|
41
41
|
import { ImageRef } from './images.js';
|
|
42
42
|
import { Platform } from './platform.js';
|
|
@@ -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.d.ts
CHANGED
|
@@ -13,12 +13,15 @@ export function matchForLicense(manifestPath: string, providers: [Provider]): Pr
|
|
|
13
13
|
* Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
|
|
14
14
|
* @param {string} manifest - the name-type or path of the manifest
|
|
15
15
|
* @param {[Provider]} providers - list of providers to iterate over
|
|
16
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
|
|
16
17
|
* @returns {Provider}
|
|
17
18
|
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
18
19
|
*/
|
|
19
|
-
export function match(manifest: string, providers: [Provider]
|
|
20
|
+
export function match(manifest: string, providers: [Provider], opts?: {
|
|
21
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
22
|
+
}): Provider;
|
|
20
23
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
21
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
24
|
+
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string, Object=): string | null, packageManagerName: function(): string}} Provider */
|
|
22
25
|
/**
|
|
23
26
|
* MUST include all providers here.
|
|
24
27
|
* @type {[Provider]}
|
|
@@ -31,8 +34,9 @@ export type Provided = {
|
|
|
31
34
|
};
|
|
32
35
|
export type Provider = {
|
|
33
36
|
isSupported: (arg0: string) => boolean;
|
|
34
|
-
validateLockFile: (arg0: string) => void;
|
|
37
|
+
validateLockFile: (arg0: string, arg1: Object) => void;
|
|
35
38
|
provideComponent: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
36
39
|
provideStack: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
37
|
-
readLicenseFromManifest: (arg0: string) => string | null;
|
|
40
|
+
readLicenseFromManifest: (arg0: string, arg1: Object | undefined) => string | null;
|
|
41
|
+
packageManagerName: () => string;
|
|
38
42
|
};
|
package/dist/src/provider.js
CHANGED
|
@@ -3,13 +3,17 @@ import golangGomodulesProvider from './providers/golang_gomodules.js';
|
|
|
3
3
|
import Java_gradle_groovy from "./providers/java_gradle_groovy.js";
|
|
4
4
|
import Java_gradle_kotlin from "./providers/java_gradle_kotlin.js";
|
|
5
5
|
import Java_maven from "./providers/java_maven.js";
|
|
6
|
+
import Javascript_bun from './providers/javascript_bun.js';
|
|
6
7
|
import Javascript_npm from './providers/javascript_npm.js';
|
|
7
8
|
import Javascript_pnpm from './providers/javascript_pnpm.js';
|
|
8
9
|
import Javascript_yarn from './providers/javascript_yarn.js';
|
|
9
10
|
import pythonPipProvider from './providers/python_pip.js';
|
|
11
|
+
import Python_pip_pyproject from './providers/python_pip_pyproject.js';
|
|
12
|
+
import Python_poetry from './providers/python_poetry.js';
|
|
13
|
+
import Python_uv from './providers/python_uv.js';
|
|
10
14
|
import rustCargoProvider from './providers/rust_cargo.js';
|
|
11
15
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
12
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
|
|
16
|
+
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string, Object=): string | null, packageManagerName: function(): string}} Provider */
|
|
13
17
|
/**
|
|
14
18
|
* MUST include all providers here.
|
|
15
19
|
* @type {[Provider]}
|
|
@@ -18,11 +22,15 @@ export const availableProviders = [
|
|
|
18
22
|
new Java_maven(),
|
|
19
23
|
new Java_gradle_groovy(),
|
|
20
24
|
new Java_gradle_kotlin(),
|
|
21
|
-
new
|
|
25
|
+
new Javascript_bun(),
|
|
22
26
|
new Javascript_pnpm(),
|
|
23
27
|
new Javascript_yarn(),
|
|
28
|
+
new Javascript_npm(),
|
|
24
29
|
golangGomodulesProvider,
|
|
25
30
|
pythonPipProvider,
|
|
31
|
+
new Python_poetry(),
|
|
32
|
+
new Python_uv(),
|
|
33
|
+
new Python_pip_pyproject(),
|
|
26
34
|
rustCargoProvider
|
|
27
35
|
];
|
|
28
36
|
/**
|
|
@@ -47,16 +55,17 @@ export function matchForLicense(manifestPath, providers) {
|
|
|
47
55
|
* Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
|
|
48
56
|
* @param {string} manifest - the name-type or path of the manifest
|
|
49
57
|
* @param {[Provider]} providers - list of providers to iterate over
|
|
58
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
|
|
50
59
|
* @returns {Provider}
|
|
51
60
|
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
52
61
|
*/
|
|
53
|
-
export function match(manifest, providers) {
|
|
62
|
+
export function match(manifest, providers, opts = {}) {
|
|
54
63
|
const manifestPath = path.parse(manifest);
|
|
55
64
|
const supported = providers.filter(prov => prov.isSupported(manifestPath.base));
|
|
56
65
|
if (supported.length === 0) {
|
|
57
66
|
throw new Error(`${manifestPath.base} is not supported`);
|
|
58
67
|
}
|
|
59
|
-
const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir));
|
|
68
|
+
const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir, opts));
|
|
60
69
|
if (!provider) {
|
|
61
70
|
throw new Error(`${manifestPath.base} requires a lock file. Use your preferred package manager to generate the lock file.`);
|
|
62
71
|
}
|