@trustify-da/trustify-da-javascript-client 0.3.0-ea.b8af0f8 → 0.3.0-ea.bdaadb2
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 +250 -11
- package/dist/package.json +33 -25
- package/dist/src/analysis.d.ts +14 -7
- package/dist/src/analysis.js +32 -15
- package/dist/src/cli.js +156 -3
- package/dist/src/cyclone_dx_sbom.d.ts +27 -1
- package/dist/src/cyclone_dx_sbom.js +82 -9
- package/dist/src/index.d.ts +86 -11
- package/dist/src/index.js +102 -30
- 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/images.js +15 -1
- package/dist/src/oci_image/utils.d.ts +5 -5
- package/dist/src/oci_image/utils.js +11 -2
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.d.ts +4 -3
- package/dist/src/provider.js +12 -2
- package/dist/src/providers/base_java.d.ts +67 -12
- package/dist/src/providers/base_java.js +82 -61
- package/dist/src/providers/base_javascript.d.ts +74 -9
- package/dist/src/providers/base_javascript.js +149 -9
- package/dist/src/providers/base_pyproject.d.ts +158 -0
- package/dist/src/providers/base_pyproject.js +322 -0
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.d.ts +23 -13
- package/dist/src/providers/golang_gomodules.js +207 -120
- 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 +67 -0
- package/dist/src/providers/java_gradle.js +310 -17
- 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 +38 -5
- package/dist/src/providers/java_maven.js +261 -8
- package/dist/src/providers/javascript_bun.d.ts +22 -0
- package/dist/src/providers/javascript_bun.js +141 -0
- package/dist/src/providers/javascript_npm.d.ts +19 -0
- package/dist/src/providers/javascript_npm.js +61 -1
- package/dist/src/providers/javascript_pnpm.d.ts +13 -0
- package/dist/src/providers/javascript_pnpm.js +53 -3
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/marker_evaluator.d.ts +14 -0
- package/dist/src/providers/marker_evaluator.js +191 -0
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.d.ts +5 -1
- package/dist/src/providers/python_controller.js +69 -8
- package/dist/src/providers/python_pip.d.ts +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 +6 -2
- package/dist/src/providers/rust_cargo.js +101 -33
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +25 -1
- package/dist/src/sbom.js +23 -2
- package/dist/src/tools.d.ts +28 -2
- package/dist/src/tools.js +82 -1
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/dist/src/workspace.d.ts +9 -0
- package/dist/src/workspace.js +1 -1
- package/package.json +34 -26
package/dist/src/index.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { EOL } from "os";
|
|
3
4
|
import pLimit from 'p-limit';
|
|
4
|
-
import { availableProviders, match } from './provider.js';
|
|
5
5
|
import analysis from './analysis.js';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import { getCustom } from "./tools.js";
|
|
8
6
|
import { resolveBatchMetadata, resolveContinueOnError } from './batch_opts.js';
|
|
7
|
+
import { getPackageVersion } from './package_version.js';
|
|
8
|
+
import { availableProviders, match } from './provider.js';
|
|
9
|
+
import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
|
|
10
|
+
import { discoverGradleSubprojects } from './providers/java_gradle.js';
|
|
11
|
+
import { discoverMavenModules } from './providers/java_maven.js';
|
|
12
|
+
import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
|
|
13
|
+
import { getCustom } from "./tools.js";
|
|
9
14
|
import { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
|
|
10
|
-
import.meta.dirname;
|
|
11
|
-
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
|
|
16
|
-
export {
|
|
18
|
+
export { extractRemediations } from "./remediation.js";
|
|
19
|
+
export { generateReport, generateDeduplicationKey } from './remediation_report.js';
|
|
20
|
+
export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
|
|
21
|
+
export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
|
|
17
22
|
/**
|
|
18
23
|
* @typedef {{
|
|
19
24
|
* TRUSTIFY_DA_CARGO_PATH?: string | undefined,
|
|
@@ -35,7 +40,9 @@ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson
|
|
|
35
40
|
* TRUSTIFY_DA_PYTHON_PATH?: string | undefined,
|
|
36
41
|
* TRUSTIFY_DA_PYTHON_VIRTUAL_ENV?: string | undefined,
|
|
37
42
|
* TRUSTIFY_DA_PYTHON3_PATH?: string | undefined,
|
|
38
|
-
*
|
|
43
|
+
* TRUSTIFY_DA_PROVIDERS?: string | undefined,
|
|
44
|
+
* TRUSTIFY_DA_RECOMMEND?: string | undefined,
|
|
45
|
+
* TRUSTIFY_DA_SOURCES?: string | undefined,
|
|
39
46
|
* TRUSTIFY_DA_SKOPEO_CONFIG_PATH?: string | undefined,
|
|
40
47
|
* TRUSTIFY_DA_SKOPEO_PATH?: string | undefined,
|
|
41
48
|
* TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined,
|
|
@@ -56,13 +63,15 @@ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson
|
|
|
56
63
|
* TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined,
|
|
57
64
|
* batchMetadata?: boolean | undefined,
|
|
58
65
|
* TRUSTIFY_DA_BATCH_METADATA?: string | undefined,
|
|
66
|
+
* TRUSTIFY_DA_UV_PATH?: string | undefined,
|
|
67
|
+
* TRUSTIFY_DA_POETRY_PATH?: string | undefined,
|
|
59
68
|
* [key: string]: string | number | boolean | string[] | undefined,
|
|
60
69
|
* }} Options
|
|
61
70
|
*/
|
|
62
71
|
/**
|
|
63
72
|
* @typedef {{
|
|
64
73
|
* workspaceRoot: string,
|
|
65
|
-
* ecosystem: 'javascript' | 'cargo' | 'unknown',
|
|
74
|
+
* ecosystem: 'javascript' | 'cargo' | 'pyproject' | 'unknown',
|
|
66
75
|
* total: number,
|
|
67
76
|
* successful: number,
|
|
68
77
|
* failed: number,
|
|
@@ -85,23 +94,7 @@ function logOptionsAndEnvironmentsVariables(alongsideText, valueToBePrinted) {
|
|
|
85
94
|
* @private
|
|
86
95
|
*/
|
|
87
96
|
function readAndPrintVersionFromPackageJson() {
|
|
88
|
-
|
|
89
|
-
// new ESM way in nodeJS ( since node version 22 ) to bring module directory.
|
|
90
|
-
dirName = import.meta.dirname;
|
|
91
|
-
// old ESM way in nodeJS ( before node versions 22.00 to bring module directory)
|
|
92
|
-
if (!dirName) {
|
|
93
|
-
dirName = url.fileURLToPath(new URL('.', import.meta.url));
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
if (__dirname) {
|
|
97
|
-
dirName = __dirname;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
console.log("__dirname is not defined, continue with fileUrlPath");
|
|
102
|
-
}
|
|
103
|
-
let packageJson = JSON.parse(fs.readFileSync(path.join(dirName, "..", "package.json")).toString());
|
|
104
|
-
logOptionsAndEnvironmentsVariables("trustify-da-javascript-client analysis started, version: ", packageJson.version);
|
|
97
|
+
logOptionsAndEnvironmentsVariables("trustify-da-javascript-client analysis started, version: ", getPackageVersion());
|
|
105
98
|
}
|
|
106
99
|
/**
|
|
107
100
|
* This function is used to determine the Trustify DA backend URL.
|
|
@@ -169,7 +162,9 @@ async function componentAnalysis(manifest, opts = {}) {
|
|
|
169
162
|
fs.accessSync(manifest, fs.constants.R_OK);
|
|
170
163
|
opts["manifest-type"] = path.basename(manifest);
|
|
171
164
|
let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
|
|
172
|
-
|
|
165
|
+
const result = await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
|
|
166
|
+
result.packageManager = provider.packageManagerName();
|
|
167
|
+
return result;
|
|
173
168
|
}
|
|
174
169
|
/**
|
|
175
170
|
* @overload
|
|
@@ -235,6 +230,22 @@ function buildBatchAnalysisMetadata(root, ecosystem, totalSbomAttempts, successf
|
|
|
235
230
|
errors: [...errors],
|
|
236
231
|
};
|
|
237
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Generate a CycloneDX SBOM from a manifest file. No backend HTTP request is made.
|
|
235
|
+
*
|
|
236
|
+
* @param {string} manifestPath - path to the manifest file (e.g. pom.xml, package.json)
|
|
237
|
+
* @param {Options} [opts={}] - optional options (e.g. workspace dir, tool paths)
|
|
238
|
+
* @returns {Promise<object>} parsed CycloneDX SBOM JSON object
|
|
239
|
+
* @throws {Error} if the manifest is unsupported or SBOM generation fails
|
|
240
|
+
*/
|
|
241
|
+
export async function generateSbom(manifestPath, opts = {}) {
|
|
242
|
+
fs.accessSync(manifestPath, fs.constants.R_OK);
|
|
243
|
+
const result = await generateOneSbom(manifestPath, opts);
|
|
244
|
+
if (!result.ok) {
|
|
245
|
+
throw new Error(`Failed to generate SBOM for ${result.manifestPath}: ${result.reason}`);
|
|
246
|
+
}
|
|
247
|
+
return result.sbom;
|
|
248
|
+
}
|
|
238
249
|
/**
|
|
239
250
|
* @typedef {{ ok: true, purl: string, sbom: object } | { ok: false, manifestPath: string, reason: string }} SbomResult
|
|
240
251
|
*/
|
|
@@ -261,17 +272,45 @@ async function generateOneSbom(manifestPath, workspaceOpts) {
|
|
|
261
272
|
*
|
|
262
273
|
* @param {string} root - Resolved workspace root
|
|
263
274
|
* @param {Options} opts
|
|
264
|
-
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'unknown', manifestPaths: string[] }>}
|
|
275
|
+
* @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'gradle' | 'gomodules' | 'pyproject' | 'unknown', manifestPaths: string[] }>}
|
|
265
276
|
* @private
|
|
266
277
|
*/
|
|
267
278
|
async function detectWorkspaceManifests(root, opts) {
|
|
268
279
|
const cargoToml = path.join(root, 'Cargo.toml');
|
|
269
280
|
const cargoLock = path.join(root, 'Cargo.lock');
|
|
270
281
|
const packageJson = path.join(root, 'package.json');
|
|
282
|
+
const pomXml = path.join(root, 'pom.xml');
|
|
271
283
|
if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
|
|
272
284
|
return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
|
|
273
285
|
}
|
|
274
|
-
|
|
286
|
+
if (fs.existsSync(pomXml)) {
|
|
287
|
+
const manifestPaths = await discoverMavenModules(root, opts);
|
|
288
|
+
if (manifestPaths.length > 0) {
|
|
289
|
+
return { ecosystem: 'maven', manifestPaths };
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const hasGradleSettings = fs.existsSync(path.join(root, 'settings.gradle'))
|
|
293
|
+
|| fs.existsSync(path.join(root, 'settings.gradle.kts'));
|
|
294
|
+
if (hasGradleSettings) {
|
|
295
|
+
const manifestPaths = await discoverGradleSubprojects(root, opts);
|
|
296
|
+
if (manifestPaths.length > 0) {
|
|
297
|
+
return { ecosystem: 'gradle', manifestPaths };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (fs.existsSync(path.join(root, 'go.work'))) {
|
|
301
|
+
const manifestPaths = await discoverGoWorkspaceModules(root, opts);
|
|
302
|
+
if (manifestPaths.length > 0) {
|
|
303
|
+
return { ecosystem: 'gomodules', manifestPaths };
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (fs.existsSync(path.join(root, 'pyproject.toml')) && fs.existsSync(path.join(root, 'uv.lock'))) {
|
|
307
|
+
const manifestPaths = await discoverUvWorkspaceMembers(root, opts);
|
|
308
|
+
if (manifestPaths.length > 0) {
|
|
309
|
+
return { ecosystem: 'pyproject', manifestPaths };
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const hasJsLock = fs.existsSync(path.join(root, 'bun.lock'))
|
|
313
|
+
|| fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
|
|
275
314
|
|| fs.existsSync(path.join(root, 'yarn.lock'))
|
|
276
315
|
|| fs.existsSync(path.join(root, 'package-lock.json'));
|
|
277
316
|
if (fs.existsSync(packageJson) && hasJsLock) {
|
|
@@ -380,12 +419,45 @@ function batchError(message, wantMetadata, metadata) {
|
|
|
380
419
|
}
|
|
381
420
|
return err;
|
|
382
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* @overload
|
|
424
|
+
* @param {string} workspaceRoot
|
|
425
|
+
* @param {true} html
|
|
426
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
427
|
+
* @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
|
|
428
|
+
* @throws {Error}
|
|
429
|
+
*/
|
|
430
|
+
/**
|
|
431
|
+
* @overload
|
|
432
|
+
* @param {string} workspaceRoot
|
|
433
|
+
* @param {true} html
|
|
434
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
435
|
+
* @returns {Promise<string>}
|
|
436
|
+
* @throws {Error}
|
|
437
|
+
*/
|
|
438
|
+
/**
|
|
439
|
+
* @overload
|
|
440
|
+
* @param {string} workspaceRoot
|
|
441
|
+
* @param {false} html
|
|
442
|
+
* @param {Options & { batchMetadata: true }} opts
|
|
443
|
+
* @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
|
|
444
|
+
* @throws {Error}
|
|
445
|
+
*/
|
|
446
|
+
/**
|
|
447
|
+
* @overload
|
|
448
|
+
* @param {string} workspaceRoot
|
|
449
|
+
* @param {false} html
|
|
450
|
+
* @param {Options & { batchMetadata?: false }} [opts={}]
|
|
451
|
+
* @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
|
|
452
|
+
* @throws {Error}
|
|
453
|
+
*/
|
|
383
454
|
/**
|
|
384
455
|
* Get stack analysis for all workspace packages/crates (batch).
|
|
385
456
|
* Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
|
|
386
457
|
* SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
|
|
387
458
|
* With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
|
|
388
459
|
*
|
|
460
|
+
* @overload
|
|
389
461
|
* @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
|
|
390
462
|
* @param {boolean} [html=false] - true returns HTML, false returns JSON report
|
|
391
463
|
* @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
|
|
@@ -416,7 +488,7 @@ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
|
|
|
416
488
|
}
|
|
417
489
|
}
|
|
418
490
|
if (manifestPaths.length === 0) {
|
|
419
|
-
throw new Error(`No workspace manifests found at ${root}. Ensure Cargo.toml+Cargo.lock or package.json+lock file
|
|
491
|
+
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).`);
|
|
420
492
|
}
|
|
421
493
|
const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
|
|
422
494
|
const concurrency = resolveBatchConcurrency(opts);
|
|
@@ -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} */
|
|
@@ -242,8 +242,22 @@ export class ImageRef {
|
|
|
242
242
|
getPackageURL() {
|
|
243
243
|
/** @type {Object.<string, string>} */
|
|
244
244
|
const qualifiers = {};
|
|
245
|
-
|
|
245
|
+
let repositoryUrl = this.image.getNameWithoutTag();
|
|
246
246
|
const simpleName = this.image.getSimpleName();
|
|
247
|
+
// Normalize Docker Hub image references so all forms produce the same PURL:
|
|
248
|
+
// node → docker.io/node
|
|
249
|
+
// docker.io/library/node → docker.io/node
|
|
250
|
+
if (repositoryUrl != null) {
|
|
251
|
+
const lower = repositoryUrl.toLowerCase();
|
|
252
|
+
if (lower === simpleName.toLowerCase()) {
|
|
253
|
+
// Bare name (e.g. "node") — default to docker.io
|
|
254
|
+
repositoryUrl = `docker.io/${simpleName}`;
|
|
255
|
+
}
|
|
256
|
+
else if (lower.startsWith('docker.io/library/')) {
|
|
257
|
+
// Official image with library/ prefix — strip it
|
|
258
|
+
repositoryUrl = `docker.io/${lower.substring('docker.io/library/'.length)}`;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
247
261
|
if (repositoryUrl != null && repositoryUrl.toLowerCase() !== simpleName.toLowerCase()) {
|
|
248
262
|
qualifiers[ImageRef.REPOSITORY_QUALIFIER] = repositoryUrl.toLowerCase();
|
|
249
263
|
}
|
|
@@ -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
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads this package's version from package.json, resolving the path relative
|
|
3
|
+
* to this module. Works under ESM (node >= 22 import.meta.dirname, older via
|
|
4
|
+
* import.meta.url) and CommonJS (__dirname). Returns undefined if the file
|
|
5
|
+
* cannot be read, so callers never fail on a missing version.
|
|
6
|
+
* @return {string|undefined} the package version, or undefined
|
|
7
|
+
*/
|
|
8
|
+
export function getPackageVersion(): string | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import * as url from "url";
|
|
4
|
+
/**
|
|
5
|
+
* Reads this package's version from package.json, resolving the path relative
|
|
6
|
+
* to this module. Works under ESM (node >= 22 import.meta.dirname, older via
|
|
7
|
+
* import.meta.url) and CommonJS (__dirname). Returns undefined if the file
|
|
8
|
+
* cannot be read, so callers never fail on a missing version.
|
|
9
|
+
* @return {string|undefined} the package version, or undefined
|
|
10
|
+
*/
|
|
11
|
+
export function getPackageVersion() {
|
|
12
|
+
try {
|
|
13
|
+
let dirName = import.meta.dirname;
|
|
14
|
+
if (!dirName) {
|
|
15
|
+
dirName = url.fileURLToPath(new URL('.', import.meta.url));
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
if (__dirname) {
|
|
19
|
+
dirName = __dirname;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// __dirname not defined under ESM, continue with fileURLToPath
|
|
24
|
+
}
|
|
25
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(dirName, "..", "package.json")).toString());
|
|
26
|
+
return packageJson.version;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function match(manifest: string, providers: [Provider], opts?: {
|
|
|
21
21
|
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
22
22
|
}): Provider;
|
|
23
23
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
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): 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 */
|
|
25
25
|
/**
|
|
26
26
|
* MUST include all providers here.
|
|
27
27
|
* @type {[Provider]}
|
|
@@ -34,8 +34,9 @@ export type Provided = {
|
|
|
34
34
|
};
|
|
35
35
|
export type Provider = {
|
|
36
36
|
isSupported: (arg0: string) => boolean;
|
|
37
|
-
validateLockFile: (arg0: string, arg1:
|
|
37
|
+
validateLockFile: (arg0: string, arg1: Object) => void;
|
|
38
38
|
provideComponent: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
39
39
|
provideStack: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
40
|
-
readLicenseFromManifest: (arg0: string) => string | null;
|
|
40
|
+
readLicenseFromManifest: (arg0: string, arg1: Object | undefined) => string | null;
|
|
41
|
+
packageManagerName: () => string;
|
|
41
42
|
};
|
package/dist/src/provider.js
CHANGED
|
@@ -3,13 +3,18 @@ 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';
|
|
10
|
+
import dockerfileProvider from './providers/oci_dockerfile.js';
|
|
9
11
|
import pythonPipProvider from './providers/python_pip.js';
|
|
12
|
+
import Python_pip_pyproject from './providers/python_pip_pyproject.js';
|
|
13
|
+
import Python_poetry from './providers/python_poetry.js';
|
|
14
|
+
import Python_uv from './providers/python_uv.js';
|
|
10
15
|
import rustCargoProvider from './providers/rust_cargo.js';
|
|
11
16
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
12
|
-
/** @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): string | null}} Provider */
|
|
17
|
+
/** @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
18
|
/**
|
|
14
19
|
* MUST include all providers here.
|
|
15
20
|
* @type {[Provider]}
|
|
@@ -18,12 +23,17 @@ export const availableProviders = [
|
|
|
18
23
|
new Java_maven(),
|
|
19
24
|
new Java_gradle_groovy(),
|
|
20
25
|
new Java_gradle_kotlin(),
|
|
26
|
+
new Javascript_bun(),
|
|
21
27
|
new Javascript_pnpm(),
|
|
22
28
|
new Javascript_yarn(),
|
|
23
29
|
new Javascript_npm(),
|
|
24
30
|
golangGomodulesProvider,
|
|
25
31
|
pythonPipProvider,
|
|
26
|
-
|
|
32
|
+
new Python_poetry(),
|
|
33
|
+
new Python_uv(),
|
|
34
|
+
new Python_pip_pyproject(),
|
|
35
|
+
rustCargoProvider,
|
|
36
|
+
dockerfileProvider
|
|
27
37
|
];
|
|
28
38
|
/**
|
|
29
39
|
* Match a provider by manifest type only (no lock file check). Used for license reading.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ecosystem_maven =
|
|
1
|
+
export type ecosystem_maven = any;
|
|
2
2
|
/** @typedef {import('../provider').Provider} */
|
|
3
3
|
/** @typedef {import('../provider').Provided} Provided */
|
|
4
4
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -10,6 +10,13 @@ export type ecosystem_maven = import("../provider").Provider;
|
|
|
10
10
|
export const ecosystem_maven: string;
|
|
11
11
|
export const ecosystem_gradle: "gradle";
|
|
12
12
|
export default class Base_Java {
|
|
13
|
+
/**
|
|
14
|
+
* Maven dependency scopes. Used to detect whether the trailing column of a
|
|
15
|
+
* dependency-tree line is a scope keyword — which in turn signals that an
|
|
16
|
+
* optional classifier column is present between the packaging and version.
|
|
17
|
+
* @type {string[]}
|
|
18
|
+
*/
|
|
19
|
+
static MAVEN_SCOPES: string[];
|
|
13
20
|
/**
|
|
14
21
|
*
|
|
15
22
|
* @param {string} globalBinary name of the global binary
|
|
@@ -20,6 +27,11 @@ export default class Base_Java {
|
|
|
20
27
|
CONFLICT_REGEX: RegExp;
|
|
21
28
|
globalBinary: string;
|
|
22
29
|
localWrapper: string;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the package manager name (e.g. mvn, gradle)
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
packageManagerName(): string;
|
|
23
35
|
/**
|
|
24
36
|
* Recursively populates the SBOM instance with the parsed graph
|
|
25
37
|
* @param {string} src - Source dependency to start the calculations from
|
|
@@ -28,6 +40,59 @@ export default class Base_Java {
|
|
|
28
40
|
* @param {Sbom} sbom - The SBOM where the dependencies are being added
|
|
29
41
|
*/
|
|
30
42
|
parseDependencyTree(src: string, srcDepth: number, lines: any[], sbom: Sbom): void;
|
|
43
|
+
/**
|
|
44
|
+
* Calculates how deep in the graph is the given line
|
|
45
|
+
* @param {string} line - line to calculate the depth from
|
|
46
|
+
* @returns {number} The calculated depth
|
|
47
|
+
* @protected
|
|
48
|
+
*/
|
|
49
|
+
protected _getDepth(line: string): number;
|
|
50
|
+
/**
|
|
51
|
+
* Parse a single dependency-tree line into its Maven coordinate parts.
|
|
52
|
+
*
|
|
53
|
+
* This is the single source of truth for interpreting a dependency-tree
|
|
54
|
+
* line. Both {@link parseDep} (used to build SBOM component PURLs) and the
|
|
55
|
+
* Maven hash-map builder rely on it, so the PURL key and the artifact file
|
|
56
|
+
* path can never drift from one another.
|
|
57
|
+
*
|
|
58
|
+
* A line has the shape `groupId:artifactId:packaging[:classifier]:version[:scope]`.
|
|
59
|
+
* The classifier column is only present when a sixth column holds a known
|
|
60
|
+
* Maven scope keyword; otherwise the fourth column is the version.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} line - line to parse from a dependency tree
|
|
63
|
+
* @returns {{groupId: string, artifactId: string, packaging: string, classifier: (string|null), version: string, scope: (string|null), overridden: boolean}}
|
|
64
|
+
* Parsed coordinate. `version` is the resolved concrete version — when the
|
|
65
|
+
* line carries a conflict override the override version replaces it and
|
|
66
|
+
* `overridden` is set, mirroring how Maven records the winning version.
|
|
67
|
+
*/
|
|
68
|
+
parseCoordinate(line: string): {
|
|
69
|
+
groupId: string;
|
|
70
|
+
artifactId: string;
|
|
71
|
+
packaging: string;
|
|
72
|
+
classifier: (string | null);
|
|
73
|
+
version: string;
|
|
74
|
+
scope: (string | null);
|
|
75
|
+
overridden: boolean;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Build the canonical PackageURL for a parsed coordinate.
|
|
79
|
+
*
|
|
80
|
+
* The classifier is folded into the version component (e.g.
|
|
81
|
+
* `4.1.0-linux-x86_64`) except when the version came from a conflict
|
|
82
|
+
* override, in which case the override version stands alone — matching the
|
|
83
|
+
* historical behavior of {@link parseDep}.
|
|
84
|
+
*
|
|
85
|
+
* @param {{groupId: string, artifactId: string, classifier: (string|null), version: string, overridden: boolean}} coord
|
|
86
|
+
* @returns {PackageURL} The canonical packageURL for the coordinate
|
|
87
|
+
* @protected
|
|
88
|
+
*/
|
|
89
|
+
protected _coordinateToPurl(coord: {
|
|
90
|
+
groupId: string;
|
|
91
|
+
artifactId: string;
|
|
92
|
+
classifier: (string | null);
|
|
93
|
+
version: string;
|
|
94
|
+
overridden: boolean;
|
|
95
|
+
}): PackageURL;
|
|
31
96
|
/**
|
|
32
97
|
* Create a PackageURL from any line in a Text Graph dependency tree for a manifest path.
|
|
33
98
|
* @param {string} line - line to parse from a dependencies.txt file
|
|
@@ -57,18 +122,8 @@ export default class Base_Java {
|
|
|
57
122
|
* @returns string
|
|
58
123
|
*/
|
|
59
124
|
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
|
-
#private;
|
|
70
125
|
}
|
|
71
|
-
export type Provided =
|
|
126
|
+
export type Provided = any;
|
|
72
127
|
export type Package = {
|
|
73
128
|
name: string;
|
|
74
129
|
version: string;
|