@trustify-da/trustify-da-javascript-client 0.3.0-ea.ce73b2f → 0.3.0-ea.d71f957
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 +136 -10
- package/dist/package.json +22 -9
- package/dist/src/analysis.d.ts +21 -5
- package/dist/src/analysis.js +71 -78
- package/dist/src/batch_opts.d.ts +24 -0
- package/dist/src/batch_opts.js +35 -0
- package/dist/src/cli.js +192 -8
- package/dist/src/cyclone_dx_sbom.d.ts +10 -2
- package/dist/src/cyclone_dx_sbom.js +32 -5
- package/dist/src/index.d.ts +126 -11
- package/dist/src/index.js +270 -7
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +100 -0
- package/dist/src/license/license_utils.d.ts +40 -0
- package/dist/src/license/license_utils.js +134 -0
- package/dist/src/license/licenses_api.d.ts +34 -0
- package/dist/src/license/licenses_api.js +98 -0
- package/dist/src/license/project_license.d.ts +20 -0
- package/dist/src/license/project_license.js +62 -0
- package/dist/src/oci_image/images.d.ts +4 -5
- package/dist/src/oci_image/utils.d.ts +4 -4
- package/dist/src/provider.d.ts +17 -5
- package/dist/src/provider.js +23 -5
- package/dist/src/providers/base_java.d.ts +3 -5
- package/dist/src/providers/base_javascript.d.ts +29 -7
- package/dist/src/providers/base_javascript.js +129 -22
- package/dist/src/providers/golang_gomodules.d.ts +20 -13
- package/dist/src/providers/golang_gomodules.js +112 -114
- 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 +9 -3
- package/dist/src/providers/java_gradle.js +12 -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 +12 -5
- package/dist/src/providers/java_maven.js +33 -5
- package/dist/src/providers/javascript_pnpm.d.ts +1 -1
- package/dist/src/providers/javascript_pnpm.js +2 -2
- package/dist/src/providers/manifest.d.ts +2 -0
- package/dist/src/providers/manifest.js +22 -4
- package/dist/src/providers/processors/yarn_berry_processor.js +82 -3
- package/dist/src/providers/python_controller.d.ts +5 -2
- package/dist/src/providers/python_controller.js +56 -58
- package/dist/src/providers/python_pip.d.ts +11 -4
- package/dist/src/providers/python_pip.js +47 -54
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +24 -0
- package/dist/src/providers/rust_cargo.d.ts +52 -0
- package/dist/src/providers/rust_cargo.js +614 -0
- package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
- package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
- package/dist/src/sbom.d.ts +10 -1
- package/dist/src/sbom.js +12 -2
- package/dist/src/tools.d.ts +22 -6
- package/dist/src/tools.js +56 -1
- package/dist/src/workspace.d.ts +61 -0
- package/dist/src/workspace.js +256 -0
- package/package.json +23 -10
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client for the Trustify DA backend License Analysis API (POST /api/v5/licenses).
|
|
3
|
+
* The same license data shape is returned in the dependency analysis JSON report (result.licenses).
|
|
4
|
+
* @see https://github.com/guacsec/trustify-dependency-analytics#license-analysis-apiv5licenses
|
|
5
|
+
* @see https://github.com/guacsec/trustify-da-api-spec/blob/main/api/v5/openapi.yaml
|
|
6
|
+
*/
|
|
7
|
+
import { PackageURL } from 'packageurl-js';
|
|
8
|
+
import { selectTrustifyDABackend } from '../index.js';
|
|
9
|
+
import { addProxyAgent, getTokenHeaders } from '../tools.js';
|
|
10
|
+
/**
|
|
11
|
+
* Fetch license details by SPDX identifier from the backend GET /api/v5/licenses/{spdx}.
|
|
12
|
+
* Returns detailed information about a specific license including category, name, and text.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} spdxId - SPDX identifier (e.g., "Apache-2.0", "MIT")
|
|
15
|
+
* @param {import('../index.js').Options} [opts={}] - options (proxy, token, TRUSTIFY_DA_BACKEND_URL, etc.)
|
|
16
|
+
* @returns {Promise<Object|null>} License details or null if not found
|
|
17
|
+
*/
|
|
18
|
+
export async function getLicenseDetails(spdxId, opts = {}) {
|
|
19
|
+
if (!spdxId) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const url = selectTrustifyDABackend(opts);
|
|
23
|
+
const finalUrl = new URL(`${url}/api/v5/licenses/${encodeURIComponent(spdxId)}`);
|
|
24
|
+
const fetchOptions = addProxyAgent({
|
|
25
|
+
method: 'GET',
|
|
26
|
+
headers: {
|
|
27
|
+
'Accept': 'application/json',
|
|
28
|
+
...getTokenHeaders(opts)
|
|
29
|
+
},
|
|
30
|
+
}, opts);
|
|
31
|
+
try {
|
|
32
|
+
const resp = await fetch(finalUrl, fetchOptions);
|
|
33
|
+
if (!resp.ok) {
|
|
34
|
+
const errorText = await resp.text().catch(() => '');
|
|
35
|
+
throw new Error(`HTTP ${resp.status}: ${errorText || resp.statusText}`);
|
|
36
|
+
}
|
|
37
|
+
return await resp.json();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
throw new Error(`Failed to fetch license details: ${err.message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function normalizePurlString(purl) {
|
|
44
|
+
const parsed = PackageURL.fromString(purl);
|
|
45
|
+
return new PackageURL(parsed.type, parsed.namespace, parsed.name, parsed.version, null, null).toString();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Normalize the LicensesResponse shape (array of LicenseProviderResult) into a map of purl -> license info.
|
|
49
|
+
* Each provider result has { status, summary, packages } where packages is { [purl]: { concluded, evidence } }.
|
|
50
|
+
* We merge the first successful provider's packages; concluded has identifiers[], category (PERMISSIVE | WEAK_COPYLEFT | STRONG_COPYLEFT | UNKNOWN).
|
|
51
|
+
*
|
|
52
|
+
* @param {unknown} data - LicensesResponse (array) or analysis report's licenses field
|
|
53
|
+
* @param {string[]} [purls] - optional list of purls to restrict to (for consistency with getLicensesByPurl)
|
|
54
|
+
* @returns {Map<string, { licenses: string[], category?: string }>}
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeLicensesResponse(data, purls = []) {
|
|
57
|
+
const map = new Map();
|
|
58
|
+
if (!data || !Array.isArray(data)) {
|
|
59
|
+
return map;
|
|
60
|
+
}
|
|
61
|
+
const normalizedPurlsSet = purls.length > 0 ? new Set(purls.map(normalizePurlString)) : null;
|
|
62
|
+
for (const providerResult of data) {
|
|
63
|
+
const packages = providerResult?.packages;
|
|
64
|
+
if (!packages || typeof packages !== 'object') {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const [purl, pkgLicense] of Object.entries(packages)) {
|
|
68
|
+
const concluded = pkgLicense?.concluded;
|
|
69
|
+
const identifiers = Array.isArray(concluded?.identifiers) ? concluded.identifiers : [];
|
|
70
|
+
const expression = concluded?.expression;
|
|
71
|
+
const licenses = identifiers.length > 0 ? identifiers : (expression ? [expression] : []);
|
|
72
|
+
const category = concluded?.category; // PERMISSIVE | WEAK_COPYLEFT | STRONG_COPYLEFT | UNKNOWN
|
|
73
|
+
const normalizedPurl = normalizePurlString(purl);
|
|
74
|
+
if (normalizedPurlsSet === null || normalizedPurlsSet.has(normalizedPurl)) {
|
|
75
|
+
map.set(normalizedPurl, { licenses: licenses.filter(Boolean), category });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Use first provider that has packages; backend may return multiple (e.g. deps.dev)
|
|
79
|
+
if (map.size > 0) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return map;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build license map from an analysis report that already includes license data (result.licenses).
|
|
87
|
+
* Use this when the dependency analysis response already contains the licenses array to avoid a second request.
|
|
88
|
+
*
|
|
89
|
+
* @param {import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport} analysisReport - full analysis JSON
|
|
90
|
+
* @param {string[]} [purls] - optional list of purls to restrict to
|
|
91
|
+
* @returns {Map<string, { licenses: string[], category?: string }>}
|
|
92
|
+
*/
|
|
93
|
+
export function licensesFromReport(analysisReport, purls = []) {
|
|
94
|
+
if (!analysisReport?.licenses) {
|
|
95
|
+
return new Map();
|
|
96
|
+
}
|
|
97
|
+
return normalizeLicensesResponse(analysisReport.licenses, purls);
|
|
98
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve project license from manifest and from LICENSE / LICENSE.md in manifest dir or git root.
|
|
3
|
+
* Uses local pattern matching for LICENSE file identification (synchronous).
|
|
4
|
+
* For more accurate backend-based identification, use identifyLicense() separately.
|
|
5
|
+
* @param {string} manifestPath - path to manifest
|
|
6
|
+
* @returns {{ fromManifest: string|null, fromFile: string|null, mismatch: boolean }}
|
|
7
|
+
*/
|
|
8
|
+
export function getProjectLicense(manifestPath: string): {
|
|
9
|
+
fromManifest: string | null;
|
|
10
|
+
fromFile: string | null;
|
|
11
|
+
mismatch: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Call backend /licenses/identify endpoint to identify license from file.
|
|
15
|
+
* @param {string} licenseFilePath - path to LICENSE file
|
|
16
|
+
* @param {{}} [opts={}] - options (proxy, token, etc.)
|
|
17
|
+
* @returns {Promise<string|null>} - SPDX identifier or null
|
|
18
|
+
*/
|
|
19
|
+
export function identifyLicense(licenseFilePath: string, opts?: {}): Promise<string | null>;
|
|
20
|
+
export { findLicenseFilePath, readLicenseFile } from "./license_utils.js";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the project license from the manifest and from a LICENSE / LICENSE.md file.
|
|
3
|
+
* Used to report manifest-vs-file mismatch and as the baseline for dependency license compatibility.
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { selectTrustifyDABackend } from '../index.js';
|
|
8
|
+
import { matchForLicense, availableProviders } from '../provider.js';
|
|
9
|
+
import { addProxyAgent, getTokenHeaders } from '../tools.js';
|
|
10
|
+
import { normalizeSpdx, readLicenseFile } from './license_utils.js';
|
|
11
|
+
/**
|
|
12
|
+
* Resolve project license from manifest and from LICENSE / LICENSE.md in manifest dir or git root.
|
|
13
|
+
* Uses local pattern matching for LICENSE file identification (synchronous).
|
|
14
|
+
* For more accurate backend-based identification, use identifyLicense() separately.
|
|
15
|
+
* @param {string} manifestPath - path to manifest
|
|
16
|
+
* @returns {{ fromManifest: string|null, fromFile: string|null, mismatch: boolean }}
|
|
17
|
+
*/
|
|
18
|
+
export function getProjectLicense(manifestPath) {
|
|
19
|
+
const resolved = path.resolve(manifestPath);
|
|
20
|
+
const provider = matchForLicense(resolved, availableProviders);
|
|
21
|
+
const fromManifest = provider.readLicenseFromManifest(resolved);
|
|
22
|
+
const fromFile = readLicenseFile(resolved);
|
|
23
|
+
const mismatch = Boolean(fromManifest && fromFile && normalizeSpdx(fromManifest) !== normalizeSpdx(fromFile));
|
|
24
|
+
return {
|
|
25
|
+
fromManifest: fromManifest || null,
|
|
26
|
+
fromFile: fromFile || null,
|
|
27
|
+
mismatch
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { findLicenseFilePath, readLicenseFile } from './license_utils.js';
|
|
31
|
+
/**
|
|
32
|
+
* Call backend /licenses/identify endpoint to identify license from file.
|
|
33
|
+
* @param {string} licenseFilePath - path to LICENSE file
|
|
34
|
+
* @param {{}} [opts={}] - options (proxy, token, etc.)
|
|
35
|
+
* @returns {Promise<string|null>} - SPDX identifier or null
|
|
36
|
+
*/
|
|
37
|
+
export async function identifyLicense(licenseFilePath, opts = {}) {
|
|
38
|
+
try {
|
|
39
|
+
const fileContent = fs.readFileSync(licenseFilePath);
|
|
40
|
+
const backendUrl = selectTrustifyDABackend(opts);
|
|
41
|
+
const url = new URL(`${backendUrl}/api/v5/licenses/identify`);
|
|
42
|
+
const tokenHeaders = getTokenHeaders(opts);
|
|
43
|
+
const fetchOptions = addProxyAgent({
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers: {
|
|
46
|
+
'Content-Type': 'application/octet-stream',
|
|
47
|
+
...tokenHeaders,
|
|
48
|
+
},
|
|
49
|
+
body: fileContent,
|
|
50
|
+
}, opts);
|
|
51
|
+
const resp = await fetch(url, fetchOptions);
|
|
52
|
+
if (!resp.ok) {
|
|
53
|
+
return null; // Fallback to local detection on error
|
|
54
|
+
}
|
|
55
|
+
const data = await resp.json();
|
|
56
|
+
// Extract SPDX identifier from backend response
|
|
57
|
+
return data?.license?.id || data?.spdx_id || data?.identifier || null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null; // Fallback to local detection on error
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="packageurl-js/src/package-url.js" />
|
|
2
1
|
/**
|
|
3
2
|
* Helper class for parsing docker repository/image names:
|
|
4
3
|
*
|
|
@@ -26,7 +25,7 @@ export class Image {
|
|
|
26
25
|
* @param {string} fullName
|
|
27
26
|
* @param {string} [givenTag]
|
|
28
27
|
*/
|
|
29
|
-
constructor(fullName: string, givenTag?: string
|
|
28
|
+
constructor(fullName: string, givenTag?: string);
|
|
30
29
|
repository: string;
|
|
31
30
|
registry: string;
|
|
32
31
|
tag: string;
|
|
@@ -46,12 +45,12 @@ export class Image {
|
|
|
46
45
|
* @param {string} [optionalRegistry]
|
|
47
46
|
* @returns {string}
|
|
48
47
|
*/
|
|
49
|
-
getNameWithoutTag(optionalRegistry?: string
|
|
48
|
+
getNameWithoutTag(optionalRegistry?: string): string;
|
|
50
49
|
/**
|
|
51
50
|
* @param {string} [optionalRegistry]
|
|
52
51
|
* @returns {string}
|
|
53
52
|
*/
|
|
54
|
-
getFullName(optionalRegistry?: string
|
|
53
|
+
getFullName(optionalRegistry?: string): string;
|
|
55
54
|
/**
|
|
56
55
|
* @returns {string}
|
|
57
56
|
*/
|
|
@@ -79,7 +78,7 @@ export class ImageRef {
|
|
|
79
78
|
* @param {string} [platform]
|
|
80
79
|
* @param {import("index.js").Options} [opts={}]
|
|
81
80
|
*/
|
|
82
|
-
constructor(image: string, platform?: string
|
|
81
|
+
constructor(image: string, platform?: string, opts?: import("index.js").Options);
|
|
83
82
|
/** @type {Image} */
|
|
84
83
|
image: Image;
|
|
85
84
|
/** @type {Platform} */
|
|
@@ -4,20 +4,20 @@
|
|
|
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: import(
|
|
7
|
+
export function generateImageSBOM(imageRef: import("./images").ImageRef, opts?: import("../index.js").Options): {};
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
* @param {string} image
|
|
11
11
|
* @param {import("../index.js").Options} [opts={}] - optional various options to pass along the application
|
|
12
12
|
* @returns {ImageRef}
|
|
13
13
|
*/
|
|
14
|
-
export function parseImageRef(image: string, opts?: import("../index.js").Options
|
|
14
|
+
export function parseImageRef(image: string, opts?: import("../index.js").Options): ImageRef;
|
|
15
15
|
/**
|
|
16
16
|
* Gets the platform information for an image
|
|
17
17
|
* @param {import("../index.js").Options} [opts={}] - optional various options to pass along the application
|
|
18
18
|
* @returns {Platform|null} - The platform information or null
|
|
19
19
|
*/
|
|
20
|
-
export function getImagePlatform(opts?: import("../index.js").Options
|
|
20
|
+
export function getImagePlatform(opts?: import("../index.js").Options): Platform | null;
|
|
21
21
|
/**
|
|
22
22
|
* Gets the digests for an image
|
|
23
23
|
* @param {import('./images').ImageRef} imageRef - The image reference
|
|
@@ -25,7 +25,7 @@ export function getImagePlatform(opts?: import("../index.js").Options | undefine
|
|
|
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: import(
|
|
28
|
+
export function getImageDigests(imageRef: import("./images").ImageRef, opts?: import("../index.js").Options): {
|
|
29
29
|
[x: string]: string;
|
|
30
30
|
};
|
|
31
31
|
export type SyftImageSource = {
|
package/dist/src/provider.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Match a provider by manifest type only (no lock file check). Used for license reading.
|
|
3
|
+
* @param {string} manifestPath - path or name of the manifest
|
|
4
|
+
* @param {[Provider]} providers - list of providers to iterate over
|
|
5
|
+
* @returns {Provider}
|
|
6
|
+
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
7
|
+
*/
|
|
8
|
+
export function matchForLicense(manifestPath: string, providers: [Provider]): Provider;
|
|
1
9
|
/**
|
|
2
10
|
* Match a provider from a list or providers based on file type.
|
|
3
11
|
* Each provider MUST export 'isSupported' taking a file name-type and returning true if supported.
|
|
@@ -5,12 +13,15 @@
|
|
|
5
13
|
* Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
|
|
6
14
|
* @param {string} manifest - the name-type or path of the manifest
|
|
7
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
|
|
8
17
|
* @returns {Provider}
|
|
9
18
|
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
10
19
|
*/
|
|
11
|
-
export function match(manifest: string, providers: [Provider]
|
|
20
|
+
export function match(manifest: string, providers: [Provider], opts?: {
|
|
21
|
+
TRUSTIFY_DA_WORKSPACE_DIR?: string;
|
|
22
|
+
}): Provider;
|
|
12
23
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
13
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(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 */
|
|
14
25
|
/**
|
|
15
26
|
* MUST include all providers here.
|
|
16
27
|
* @type {[Provider]}
|
|
@@ -23,7 +34,8 @@ export type Provided = {
|
|
|
23
34
|
};
|
|
24
35
|
export type Provider = {
|
|
25
36
|
isSupported: (arg0: string) => boolean;
|
|
26
|
-
validateLockFile: (arg0: string) => void;
|
|
27
|
-
provideComponent: (arg0: string, arg1: {}) => Provided
|
|
28
|
-
provideStack: (arg0: string, arg1: {}) => Provided
|
|
37
|
+
validateLockFile: (arg0: string, arg1: any) => void;
|
|
38
|
+
provideComponent: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
39
|
+
provideStack: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
|
|
40
|
+
readLicenseFromManifest: (arg0: string) => string | null;
|
|
29
41
|
};
|
package/dist/src/provider.js
CHANGED
|
@@ -7,8 +7,9 @@ import Javascript_npm from './providers/javascript_npm.js';
|
|
|
7
7
|
import Javascript_pnpm from './providers/javascript_pnpm.js';
|
|
8
8
|
import Javascript_yarn from './providers/javascript_yarn.js';
|
|
9
9
|
import pythonPipProvider from './providers/python_pip.js';
|
|
10
|
+
import rustCargoProvider from './providers/rust_cargo.js';
|
|
10
11
|
/** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
|
|
11
|
-
/** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(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 */
|
|
12
13
|
/**
|
|
13
14
|
* MUST include all providers here.
|
|
14
15
|
* @type {[Provider]}
|
|
@@ -17,12 +18,28 @@ export const availableProviders = [
|
|
|
17
18
|
new Java_maven(),
|
|
18
19
|
new Java_gradle_groovy(),
|
|
19
20
|
new Java_gradle_kotlin(),
|
|
20
|
-
new Javascript_npm(),
|
|
21
21
|
new Javascript_pnpm(),
|
|
22
22
|
new Javascript_yarn(),
|
|
23
|
+
new Javascript_npm(),
|
|
23
24
|
golangGomodulesProvider,
|
|
24
|
-
pythonPipProvider
|
|
25
|
+
pythonPipProvider,
|
|
26
|
+
rustCargoProvider
|
|
25
27
|
];
|
|
28
|
+
/**
|
|
29
|
+
* Match a provider by manifest type only (no lock file check). Used for license reading.
|
|
30
|
+
* @param {string} manifestPath - path or name of the manifest
|
|
31
|
+
* @param {[Provider]} providers - list of providers to iterate over
|
|
32
|
+
* @returns {Provider}
|
|
33
|
+
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
34
|
+
*/
|
|
35
|
+
export function matchForLicense(manifestPath, providers) {
|
|
36
|
+
const base = path.parse(manifestPath).base;
|
|
37
|
+
const provider = providers.find(prov => prov.isSupported(base));
|
|
38
|
+
if (!provider) {
|
|
39
|
+
throw new Error(`${base} is not supported`);
|
|
40
|
+
}
|
|
41
|
+
return provider;
|
|
42
|
+
}
|
|
26
43
|
/**
|
|
27
44
|
* Match a provider from a list or providers based on file type.
|
|
28
45
|
* Each provider MUST export 'isSupported' taking a file name-type and returning true if supported.
|
|
@@ -30,16 +47,17 @@ export const availableProviders = [
|
|
|
30
47
|
* Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
|
|
31
48
|
* @param {string} manifest - the name-type or path of the manifest
|
|
32
49
|
* @param {[Provider]} providers - list of providers to iterate over
|
|
50
|
+
* @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
|
|
33
51
|
* @returns {Provider}
|
|
34
52
|
* @throws {Error} when the manifest is not supported and no provider was matched
|
|
35
53
|
*/
|
|
36
|
-
export function match(manifest, providers) {
|
|
54
|
+
export function match(manifest, providers, opts = {}) {
|
|
37
55
|
const manifestPath = path.parse(manifest);
|
|
38
56
|
const supported = providers.filter(prov => prov.isSupported(manifestPath.base));
|
|
39
57
|
if (supported.length === 0) {
|
|
40
58
|
throw new Error(`${manifestPath.base} is not supported`);
|
|
41
59
|
}
|
|
42
|
-
const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir));
|
|
60
|
+
const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir, opts));
|
|
43
61
|
if (!provider) {
|
|
44
62
|
throw new Error(`${manifestPath.base} requires a lock file. Use your preferred package manager to generate the lock file.`);
|
|
45
63
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="packageurl-js/src/package-url.js" />
|
|
3
|
-
export type ecosystem_maven = import('../provider').Provider;
|
|
1
|
+
export type ecosystem_maven = import("../provider").Provider;
|
|
4
2
|
/** @typedef {import('../provider').Provider} */
|
|
5
3
|
/** @typedef {import('../provider').Provided} Provided */
|
|
6
4
|
/** @typedef {{name: string, version: string}} Package */
|
|
@@ -51,7 +49,7 @@ export default class Base_Java {
|
|
|
51
49
|
* @param {import('child_process').ExecFileOptionsWithStringEncoding} [opts={}]
|
|
52
50
|
* @protected
|
|
53
51
|
*/
|
|
54
|
-
protected _invokeCommand(bin: any, args: any, opts?: import("child_process").ExecFileOptionsWithStringEncoding
|
|
52
|
+
protected _invokeCommand(bin: any, args: any, opts?: import("child_process").ExecFileOptionsWithStringEncoding): string;
|
|
55
53
|
/**
|
|
56
54
|
*
|
|
57
55
|
* @param {string} manifestPath
|
|
@@ -70,7 +68,7 @@ export default class Base_Java {
|
|
|
70
68
|
normalizePath(thePath: any): string;
|
|
71
69
|
#private;
|
|
72
70
|
}
|
|
73
|
-
export type Provided = import(
|
|
71
|
+
export type Provided = import("../provider").Provided;
|
|
74
72
|
export type Package = {
|
|
75
73
|
name: string;
|
|
76
74
|
version: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/** @typedef {import('../provider
|
|
1
|
+
export type purlType = import("../provider").Provider;
|
|
2
|
+
/** @typedef {import('../provider').Provider} */
|
|
3
|
+
/** @typedef {import('../provider').Provided} Provided */
|
|
3
4
|
/**
|
|
4
5
|
* The ecosystem identifier for JavaScript/npm packages
|
|
5
6
|
* @type {string}
|
|
@@ -66,11 +67,26 @@ export default class Base_javascript {
|
|
|
66
67
|
*/
|
|
67
68
|
isSupported(manifestName: string): boolean;
|
|
68
69
|
/**
|
|
69
|
-
*
|
|
70
|
+
* Walks up the directory tree from manifestDir looking for the lock file.
|
|
71
|
+
* Stops when the lock file is found, when a package.json with a "workspaces"
|
|
72
|
+
* field is encountered without a lock file (workspace root boundary), or
|
|
73
|
+
* when the filesystem root is reached.
|
|
74
|
+
*
|
|
75
|
+
* When TRUSTIFY_DA_WORKSPACE_DIR is set, checks only that directory (no walk-up).
|
|
76
|
+
*
|
|
77
|
+
* @param {string} manifestDir - The directory to start searching from
|
|
78
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
79
|
+
* @returns {string|null} The directory containing the lock file, or null
|
|
80
|
+
* @protected
|
|
81
|
+
*/
|
|
82
|
+
protected _isWorkspaceRoot(dir: any): string | null;
|
|
83
|
+
_findLockFileDir(manifestDir: any, opts?: {}): string | null;
|
|
84
|
+
/**
|
|
70
85
|
* @param {string} manifestDir - The base directory where the manifest is located
|
|
86
|
+
* @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
|
|
71
87
|
* @returns {boolean} True if the lock file exists
|
|
72
88
|
*/
|
|
73
|
-
validateLockFile(manifestDir: string): boolean;
|
|
89
|
+
validateLockFile(manifestDir: string, opts?: any): boolean;
|
|
74
90
|
/**
|
|
75
91
|
* Provides content and content type for stack analysis
|
|
76
92
|
* @param {string} manifestPath - The manifest path or name
|
|
@@ -85,13 +101,20 @@ export default class Base_javascript {
|
|
|
85
101
|
* @returns {Provided} The provided data for component analysis
|
|
86
102
|
*/
|
|
87
103
|
provideComponent(manifestPath: string, opts?: any): Provided;
|
|
104
|
+
/**
|
|
105
|
+
* Read license from manifest (package.json). Reused by npm, pnpm, yarn.
|
|
106
|
+
* @param {string} manifestPath - path to package.json
|
|
107
|
+
* @returns {string|null}
|
|
108
|
+
*/
|
|
109
|
+
readLicenseFromManifest(manifestPath: string): string | null;
|
|
88
110
|
/**
|
|
89
111
|
* Builds the dependency tree for the project
|
|
90
112
|
* @param {boolean} includeTransitive - Whether to include transitive dependencies
|
|
113
|
+
* @param {Object} [opts={}] - Configuration options; when `TRUSTIFY_DA_WORKSPACE_DIR` is set, commands run from workspace root
|
|
91
114
|
* @returns {Object} The dependency tree
|
|
92
115
|
* @protected
|
|
93
116
|
*/
|
|
94
|
-
protected _buildDependencyTree(includeTransitive: boolean): any;
|
|
117
|
+
protected _buildDependencyTree(includeTransitive: boolean, opts?: any): any;
|
|
95
118
|
/**
|
|
96
119
|
* Recursively builds the Sbom from the JSON that npm listing returns
|
|
97
120
|
* @param {Sbom} sbom - The SBOM object to add dependencies to
|
|
@@ -121,7 +144,6 @@ export default class Base_javascript {
|
|
|
121
144
|
protected _parseDepTreeOutput(output: string): string;
|
|
122
145
|
#private;
|
|
123
146
|
}
|
|
124
|
-
export type
|
|
125
|
-
export type Provided = import('../provider.js').Provided;
|
|
147
|
+
export type Provided = import("../provider").Provided;
|
|
126
148
|
import Manifest from './manifest.js';
|
|
127
149
|
import Sbom from '../sbom.js';
|