@trustify-da/trustify-da-javascript-client 0.3.0-ea.e12bc82 → 0.3.0-ea.ff266a3
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 +13 -1
- package/dist/package.json +12 -8
- package/dist/src/analysis.d.ts +5 -5
- package/dist/src/analysis.js +21 -76
- package/dist/src/cli.js +72 -6
- package/dist/src/cyclone_dx_sbom.d.ts +3 -2
- package/dist/src/cyclone_dx_sbom.js +16 -4
- package/dist/src/index.d.ts +65 -11
- package/dist/src/index.js +5 -3
- package/dist/src/license/compatibility.d.ts +18 -0
- package/dist/src/license/compatibility.js +45 -0
- package/dist/src/license/index.d.ts +28 -0
- package/dist/src/license/index.js +100 -0
- package/dist/src/license/licenses_api.d.ts +34 -0
- package/dist/src/license/licenses_api.js +91 -0
- package/dist/src/license/project_license.d.ts +25 -0
- package/dist/src/license/project_license.js +139 -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 +12 -3
- package/dist/src/provider.js +16 -1
- package/dist/src/providers/base_java.d.ts +3 -5
- package/dist/src/providers/base_javascript.d.ts +10 -4
- package/dist/src/providers/base_javascript.js +28 -4
- package/dist/src/providers/golang_gomodules.d.ts +11 -4
- package/dist/src/providers/golang_gomodules.js +12 -4
- package/dist/src/providers/java_gradle.d.ts +9 -3
- package/dist/src/providers/java_gradle.js +11 -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 +32 -5
- 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 +45 -53
- package/dist/src/providers/requirements_parser.d.ts +6 -0
- package/dist/src/providers/requirements_parser.js +23 -0
- package/dist/src/sbom.d.ts +3 -1
- package/dist/src/sbom.js +3 -2
- package/dist/src/tools.d.ts +22 -6
- package/dist/src/tools.js +56 -1
- package/package.json +13 -9
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import { EOL } from 'os';
|
|
3
2
|
import { PackageURL } from 'packageurl-js';
|
|
4
3
|
import Sbom from '../sbom.js';
|
|
5
4
|
import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from "../tools.js";
|
|
6
5
|
import Python_controller from './python_controller.js';
|
|
7
|
-
|
|
6
|
+
import { getParser, getIgnoreQuery, getPinnedVersionQuery } from './requirements_parser.js';
|
|
7
|
+
export default { isSupported, validateLockFile, provideComponent, provideStack, readLicenseFromManifest };
|
|
8
8
|
/** @typedef {{name: string, version: string, dependencies: DependencyEntry[]}} DependencyEntry */
|
|
9
9
|
/**
|
|
10
10
|
* @type {string} ecosystem for python-pip is 'pip'
|
|
@@ -18,6 +18,13 @@ const ecosystem = 'pip';
|
|
|
18
18
|
function isSupported(manifestName) {
|
|
19
19
|
return 'requirements.txt' === manifestName;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Python requirements.txt has no standard license field
|
|
23
|
+
* @param {string} manifestPath - path to requirements.txt
|
|
24
|
+
* @returns {string|null}
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line no-unused-vars
|
|
27
|
+
function readLicenseFromManifest(manifestPath) { return null; }
|
|
21
28
|
/**
|
|
22
29
|
* @param {string} manifestDir - the directory where the manifest lies
|
|
23
30
|
*/
|
|
@@ -26,12 +33,12 @@ function validateLockFile() { return true; }
|
|
|
26
33
|
* Provide content and content type for python-pip stack analysis.
|
|
27
34
|
* @param {string} manifest - the manifest path or name
|
|
28
35
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
29
|
-
* @returns {Provided}
|
|
36
|
+
* @returns {Promise<Provided>}
|
|
30
37
|
*/
|
|
31
|
-
function provideStack(manifest, opts = {}) {
|
|
38
|
+
async function provideStack(manifest, opts = {}) {
|
|
32
39
|
return {
|
|
33
40
|
ecosystem,
|
|
34
|
-
content: createSbomStackAnalysis(manifest, opts),
|
|
41
|
+
content: await createSbomStackAnalysis(manifest, opts),
|
|
35
42
|
contentType: 'application/vnd.cyclonedx+json'
|
|
36
43
|
};
|
|
37
44
|
}
|
|
@@ -39,12 +46,12 @@ function provideStack(manifest, opts = {}) {
|
|
|
39
46
|
* Provide content and content type for python-pip component analysis.
|
|
40
47
|
* @param {string} manifest - path to requirements.txt for component report
|
|
41
48
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
42
|
-
* @returns {Provided}
|
|
49
|
+
* @returns {Promise<Provided>}
|
|
43
50
|
*/
|
|
44
|
-
function provideComponent(manifest, opts = {}) {
|
|
51
|
+
async function provideComponent(manifest, opts = {}) {
|
|
45
52
|
return {
|
|
46
53
|
ecosystem,
|
|
47
|
-
content: getSbomForComponentAnalysis(manifest, opts),
|
|
54
|
+
content: await getSbomForComponentAnalysis(manifest, opts),
|
|
48
55
|
contentType: 'application/vnd.cyclonedx+json'
|
|
49
56
|
};
|
|
50
57
|
}
|
|
@@ -66,49 +73,34 @@ function addAllDependencies(source, dep, sbom) {
|
|
|
66
73
|
}
|
|
67
74
|
/**
|
|
68
75
|
*
|
|
69
|
-
* @param
|
|
70
|
-
* @return {string}
|
|
71
|
-
*/
|
|
72
|
-
function splitToNameVersion(nameVersion) {
|
|
73
|
-
let result = [];
|
|
74
|
-
if (nameVersion.includes("==")) {
|
|
75
|
-
return nameVersion.split("==");
|
|
76
|
-
}
|
|
77
|
-
const regex = /[^\w\s-_]/g;
|
|
78
|
-
let endIndex = nameVersion.search(regex);
|
|
79
|
-
if (endIndex === -1) {
|
|
80
|
-
return [nameVersion.trim()];
|
|
81
|
-
}
|
|
82
|
-
result.push(nameVersion.substring(0, endIndex).trim());
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
*
|
|
87
|
-
* @param {string} requirementTxtContent
|
|
76
|
+
* @param {string} manifest - path to requirements.txt
|
|
88
77
|
* @return {PackageURL []}
|
|
89
78
|
*/
|
|
90
|
-
function getIgnoredDependencies(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
79
|
+
async function getIgnoredDependencies(manifest) {
|
|
80
|
+
const [parser, ignoreQuery, pinnedVersionQuery] = await Promise.all([
|
|
81
|
+
getParser(), getIgnoreQuery(), getPinnedVersionQuery()
|
|
82
|
+
]);
|
|
83
|
+
const content = fs.readFileSync(manifest).toString();
|
|
84
|
+
const tree = parser.parse(content);
|
|
85
|
+
return ignoreQuery.matches(tree.rootNode).map(match => {
|
|
86
|
+
const reqNode = match.captures.find(c => c.name === 'req').node;
|
|
87
|
+
const name = match.captures.find(c => c.name === 'name').node.text;
|
|
88
|
+
const versionMatches = pinnedVersionQuery.matches(reqNode);
|
|
89
|
+
const version = versionMatches.length > 0
|
|
90
|
+
? versionMatches[0].captures.find(c => c.name === 'version').node.text
|
|
91
|
+
: undefined;
|
|
92
|
+
return toPurl(name, version);
|
|
101
93
|
});
|
|
102
94
|
}
|
|
103
95
|
/**
|
|
104
96
|
*
|
|
105
|
-
* @param {string}
|
|
97
|
+
* @param {string} manifest - path to requirements.txt
|
|
106
98
|
* @param {Sbom} sbom object to filter out from it exhortignore dependencies.
|
|
107
99
|
* @param {{Object}} opts - various options and settings for the application
|
|
108
100
|
* @private
|
|
109
101
|
*/
|
|
110
|
-
function handleIgnoredDependencies(
|
|
111
|
-
let ignoredDeps = getIgnoredDependencies(
|
|
102
|
+
async function handleIgnoredDependencies(manifest, sbom, opts = {}) {
|
|
103
|
+
let ignoredDeps = await getIgnoredDependencies(manifest);
|
|
112
104
|
let matchManifestVersions = getCustom("MATCH_MANIFEST_VERSIONS", "true", opts);
|
|
113
105
|
if (matchManifestVersions === "true") {
|
|
114
106
|
const ignoredDepsVersion = ignoredDeps.filter(dep => dep.version !== undefined);
|
|
@@ -172,22 +164,22 @@ const DEFAULT_PIP_ROOT_COMPONENT_VERSION = "0.0.0";
|
|
|
172
164
|
* Create sbom json string out of a manifest path for stack analysis.
|
|
173
165
|
* @param {string} manifest - path for requirements.txt
|
|
174
166
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
175
|
-
* @returns {string} the sbom json string content
|
|
167
|
+
* @returns {Promise<string>} the sbom json string content
|
|
176
168
|
* @private
|
|
177
169
|
*/
|
|
178
|
-
function createSbomStackAnalysis(manifest, opts = {}) {
|
|
170
|
+
async function createSbomStackAnalysis(manifest, opts = {}) {
|
|
179
171
|
let binaries = {};
|
|
180
172
|
let createVirtualPythonEnv = handlePythonEnvironment(binaries, opts);
|
|
181
173
|
let pythonController = new Python_controller(createVirtualPythonEnv === "false", binaries.pip, binaries.python, manifest, opts);
|
|
182
|
-
let dependencies = pythonController.getDependencies(true);
|
|
174
|
+
let dependencies = await pythonController.getDependencies(true);
|
|
183
175
|
let sbom = new Sbom();
|
|
184
176
|
const rootPurl = toPurl(DEFAULT_PIP_ROOT_COMPONENT_NAME, DEFAULT_PIP_ROOT_COMPONENT_VERSION);
|
|
185
|
-
|
|
177
|
+
const license = readLicenseFromManifest(manifest);
|
|
178
|
+
sbom.addRoot(rootPurl, license);
|
|
186
179
|
dependencies.forEach(dep => {
|
|
187
180
|
addAllDependencies(rootPurl, dep, sbom);
|
|
188
181
|
});
|
|
189
|
-
|
|
190
|
-
handleIgnoredDependencies(requirementTxtContent, sbom, opts);
|
|
182
|
+
await handleIgnoredDependencies(manifest, sbom, opts);
|
|
191
183
|
// In python there is no root component, then we must remove the dummy root we added, so the sbom json will be accepted by the DA backend
|
|
192
184
|
// sbom.removeRootComponent()
|
|
193
185
|
return sbom.getAsJsonString(opts);
|
|
@@ -196,22 +188,22 @@ function createSbomStackAnalysis(manifest, opts = {}) {
|
|
|
196
188
|
* Create a sbom json string out of a manifest content for component analysis
|
|
197
189
|
* @param {string} manifest - path to requirements.txt
|
|
198
190
|
* @param {{}} [opts={}] - optional various options to pass along the application
|
|
199
|
-
* @returns {string} the sbom json string content
|
|
191
|
+
* @returns {Promise<string>} the sbom json string content
|
|
200
192
|
* @private
|
|
201
193
|
*/
|
|
202
|
-
function getSbomForComponentAnalysis(manifest, opts = {}) {
|
|
194
|
+
async function getSbomForComponentAnalysis(manifest, opts = {}) {
|
|
203
195
|
let binaries = {};
|
|
204
196
|
let createVirtualPythonEnv = handlePythonEnvironment(binaries, opts);
|
|
205
197
|
let pythonController = new Python_controller(createVirtualPythonEnv === "false", binaries.pip, binaries.python, manifest, opts);
|
|
206
|
-
let dependencies = pythonController.getDependencies(false);
|
|
198
|
+
let dependencies = await pythonController.getDependencies(false);
|
|
207
199
|
let sbom = new Sbom();
|
|
208
200
|
const rootPurl = toPurl(DEFAULT_PIP_ROOT_COMPONENT_NAME, DEFAULT_PIP_ROOT_COMPONENT_VERSION);
|
|
209
|
-
|
|
201
|
+
const license = readLicenseFromManifest(manifest);
|
|
202
|
+
sbom.addRoot(rootPurl, license);
|
|
210
203
|
dependencies.forEach(dep => {
|
|
211
204
|
sbom.addDependency(rootPurl, toPurl(dep.name, dep.version));
|
|
212
205
|
});
|
|
213
|
-
|
|
214
|
-
handleIgnoredDependencies(requirementTxtContent, sbom, opts);
|
|
206
|
+
await handleIgnoredDependencies(manifest, sbom, opts);
|
|
215
207
|
// In python there is no root component, then we must remove the dummy root we added, so the sbom json will be accepted by the DA backend
|
|
216
208
|
// sbom.removeRootComponent()
|
|
217
209
|
return sbom.getAsJsonString(opts);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function getParser(): Promise<Parser>;
|
|
2
|
+
export function getRequirementQuery(): Promise<Query>;
|
|
3
|
+
export function getIgnoreQuery(): Promise<Query>;
|
|
4
|
+
export function getPinnedVersionQuery(): Promise<Query>;
|
|
5
|
+
import { Parser } from 'web-tree-sitter';
|
|
6
|
+
import { Query } from 'web-tree-sitter';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { Language, Parser, Query } from 'web-tree-sitter';
|
|
3
|
+
const wasmPath = fileURLToPath(import.meta.resolve('tree-sitter-requirements/tree-sitter-requirements.wasm'));
|
|
4
|
+
async function init() {
|
|
5
|
+
await Parser.init();
|
|
6
|
+
return await Language.load(wasmPath);
|
|
7
|
+
}
|
|
8
|
+
export async function getParser() {
|
|
9
|
+
const language = await init();
|
|
10
|
+
return new Parser().setLanguage(language);
|
|
11
|
+
}
|
|
12
|
+
export async function getRequirementQuery() {
|
|
13
|
+
const language = await init();
|
|
14
|
+
return new Query(language, '(requirement (package) @name) @req');
|
|
15
|
+
}
|
|
16
|
+
export async function getIgnoreQuery() {
|
|
17
|
+
const language = await init();
|
|
18
|
+
return new Query(language, '((requirement (package) @name) @req . (comment) @comment (#match? @comment "^#[\\t ]*exhortignore"))');
|
|
19
|
+
}
|
|
20
|
+
export async function getPinnedVersionQuery() {
|
|
21
|
+
const language = await init();
|
|
22
|
+
return new Query(language, '(version_spec (version_cmp) @cmp (version) @version (#eq? @cmp "=="))');
|
|
23
|
+
}
|
package/dist/src/sbom.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ export default class Sbom {
|
|
|
2
2
|
sbomModel: CycloneDxSbom;
|
|
3
3
|
/**
|
|
4
4
|
* @param {PackageURL} root - add main/root component for sbom
|
|
5
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
5
6
|
* @return Sbom
|
|
6
7
|
*/
|
|
7
|
-
addRoot(root: PackageURL): CycloneDxSbom;
|
|
8
|
+
addRoot(root: PackageURL, licenses?: string | any[]): CycloneDxSbom;
|
|
8
9
|
/**
|
|
9
10
|
* @return {{{"bom-ref": string, name, purl: string, type, version}}} root component of sbom.
|
|
10
11
|
*/
|
|
@@ -43,6 +44,7 @@ export default class Sbom {
|
|
|
43
44
|
type: any;
|
|
44
45
|
version: any;
|
|
45
46
|
scope: any;
|
|
47
|
+
licenses?: any;
|
|
46
48
|
};
|
|
47
49
|
/** This method gets a component object, and a string name, and checks if the name is a substring of the component' purl.
|
|
48
50
|
* @param {} component to search in its dependencies
|
package/dist/src/sbom.js
CHANGED
|
@@ -12,10 +12,11 @@ export default class Sbom {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* @param {PackageURL} root - add main/root component for sbom
|
|
15
|
+
* @param {string|Array} [licenses] - optional license(s) for the root component
|
|
15
16
|
* @return Sbom
|
|
16
17
|
*/
|
|
17
|
-
addRoot(root) {
|
|
18
|
-
return this.sbomModel.addRoot(root);
|
|
18
|
+
addRoot(root, licenses) {
|
|
19
|
+
return this.sbomModel.addRoot(root, licenses);
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* @return {{{"bom-ref": string, name, purl: string, type, version}}} root component of sbom.
|
package/dist/src/tools.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="packageurl-js/src/package-url" />
|
|
3
1
|
/**
|
|
4
2
|
*
|
|
5
3
|
* @param {string} key to log its value from environment variables and from opts, if it exists
|
|
6
4
|
* @param {{}} [opts={}] different options of application, if key in it, log it.
|
|
7
5
|
* @param {string }defValue default value of key in case there is no option and environment variable values for key
|
|
8
6
|
*/
|
|
9
|
-
export function logValueFromObjects(key: string, opts?: {}
|
|
7
|
+
export function logValueFromObjects(key: string, opts?: {}, defValue: string): void;
|
|
10
8
|
/**
|
|
11
9
|
* Utility function will return the value for key from the environment variables,
|
|
12
10
|
* if not present will return the value for key from the opts objects only if it's a string,
|
|
@@ -17,7 +15,7 @@ export function logValueFromObjects(key: string, opts?: {} | undefined, defValue
|
|
|
17
15
|
* @returns {string|null} the value of the key found in the environment, options object, or the
|
|
18
16
|
* default supplied
|
|
19
17
|
*/
|
|
20
|
-
export function getCustom(key: string, def?: string | null
|
|
18
|
+
export function getCustom(key: string, def?: string | null, opts?: {}): string | null;
|
|
21
19
|
/**
|
|
22
20
|
* Utility function for looking up custom variable for a binary path.
|
|
23
21
|
* Will look in the environment variables (1) or in opts (2) for a key with TRUSTIFY_DA_x_PATH, x is an
|
|
@@ -28,7 +26,7 @@ export function getCustom(key: string, def?: string | null | undefined, opts?: {
|
|
|
28
26
|
* @returns {string|null} the value of the key found in the environment, options object, or the
|
|
29
27
|
* original name supplied
|
|
30
28
|
*/
|
|
31
|
-
export function getCustomPath(name: any, opts?: {}
|
|
29
|
+
export function getCustomPath(name: any, opts?: {}): string | null;
|
|
32
30
|
/**
|
|
33
31
|
* Utility function for determining whether wrappers for build tools such as gradlew/mvnw should be
|
|
34
32
|
* preferred over invoking the binary directly.
|
|
@@ -69,6 +67,24 @@ export function getGitRootDir(cwd: string): string | undefined;
|
|
|
69
67
|
* @param {import('child_process').ExecFileOptionsWithStringEncoding} [opts={}]
|
|
70
68
|
* @returns {string}
|
|
71
69
|
*/
|
|
72
|
-
export function invokeCommand(bin: string, args: Array<string>, opts?: import("child_process").ExecFileOptionsWithStringEncoding
|
|
70
|
+
export function invokeCommand(bin: string, args: Array<string>, opts?: import("child_process").ExecFileOptionsWithStringEncoding): string;
|
|
71
|
+
/**
|
|
72
|
+
* Adds proxy agent configuration to fetch options if a proxy URL is specified
|
|
73
|
+
* @param {RequestInit} options - The base fetch options
|
|
74
|
+
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
75
|
+
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
76
|
+
*/
|
|
77
|
+
export function addProxyAgent(options: RequestInit, opts: import("index.js").Options): RequestInit;
|
|
78
|
+
/**
|
|
79
|
+
* Utility function for fetching vendor tokens
|
|
80
|
+
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
81
|
+
* @returns {{}}
|
|
82
|
+
*/
|
|
83
|
+
export function getTokenHeaders(opts?: import("index.js").Options): {};
|
|
73
84
|
export const RegexNotToBeLogged: RegExp;
|
|
85
|
+
export const TRUSTIFY_DA_TOKEN_HEADER: "trust-da-token";
|
|
86
|
+
export const TRUSTIFY_DA_TELEMETRY_ID_HEADER: "telemetry-anonymous-id";
|
|
87
|
+
export const TRUSTIFY_DA_SOURCE_HEADER: "trust-da-source";
|
|
88
|
+
export const TRUSTIFY_DA_OPERATION_TYPE_HEADER: "trust-da-operation-type";
|
|
89
|
+
export const TRUSTIFY_DA_PACKAGE_MANAGER_HEADER: "trust-da-pkg-manager";
|
|
74
90
|
import { PackageURL } from "packageurl-js";
|
package/dist/src/tools.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { execFileSync } from "child_process";
|
|
2
2
|
import { EOL } from "os";
|
|
3
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
3
4
|
import { PackageURL } from "packageurl-js";
|
|
4
|
-
export const RegexNotToBeLogged = /TRUSTIFY_DA_.*
|
|
5
|
+
export const RegexNotToBeLogged = /TRUSTIFY_DA_(.*_)?TOKEN|ex-.*-token|trust-.*-token/;
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
7
8
|
* @param {string} key to log its value from environment variables and from opts, if it exists
|
|
@@ -157,3 +158,57 @@ export function invokeCommand(bin, args, opts = {}) {
|
|
|
157
158
|
};
|
|
158
159
|
return execFileSync(bin, args, { ...{ stdio: 'pipe', encoding: 'utf-8' }, ...opts });
|
|
159
160
|
}
|
|
161
|
+
export const TRUSTIFY_DA_TOKEN_HEADER = "trust-da-token";
|
|
162
|
+
export const TRUSTIFY_DA_TELEMETRY_ID_HEADER = "telemetry-anonymous-id";
|
|
163
|
+
export const TRUSTIFY_DA_SOURCE_HEADER = "trust-da-source";
|
|
164
|
+
export const TRUSTIFY_DA_OPERATION_TYPE_HEADER = "trust-da-operation-type";
|
|
165
|
+
export const TRUSTIFY_DA_PACKAGE_MANAGER_HEADER = "trust-da-pkg-manager";
|
|
166
|
+
/**
|
|
167
|
+
* Adds proxy agent configuration to fetch options if a proxy URL is specified
|
|
168
|
+
* @param {RequestInit} options - The base fetch options
|
|
169
|
+
* @param {import("index.js").Options} opts - The trustify DA options that may contain proxy configuration
|
|
170
|
+
* @returns {RequestInit} The fetch options with proxy agent if applicable
|
|
171
|
+
*/
|
|
172
|
+
export function addProxyAgent(options, opts) {
|
|
173
|
+
const proxyUrl = getCustom('TRUSTIFY_DA_PROXY_URL', null, opts);
|
|
174
|
+
if (proxyUrl) {
|
|
175
|
+
options.agent = new HttpsProxyAgent(proxyUrl);
|
|
176
|
+
}
|
|
177
|
+
return options;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Utility function for fetching vendor tokens
|
|
181
|
+
* @param {import("index.js").Options} [opts={}] - optional various options to pass along the application
|
|
182
|
+
* @returns {{}}
|
|
183
|
+
*/
|
|
184
|
+
export function getTokenHeaders(opts = {}) {
|
|
185
|
+
let headers = {};
|
|
186
|
+
setCustomHeader(TRUSTIFY_DA_TOKEN_HEADER, headers, 'TRUSTIFY_DA_TOKEN', opts);
|
|
187
|
+
setCustomHeader(TRUSTIFY_DA_SOURCE_HEADER, headers, 'TRUSTIFY_DA_SOURCE', opts);
|
|
188
|
+
setCustomHeader(TRUSTIFY_DA_OPERATION_TYPE_HEADER, headers, TRUSTIFY_DA_OPERATION_TYPE_HEADER.toUpperCase().replaceAll("-", "_"), opts);
|
|
189
|
+
setCustomHeader(TRUSTIFY_DA_PACKAGE_MANAGER_HEADER, headers, TRUSTIFY_DA_PACKAGE_MANAGER_HEADER.toUpperCase().replaceAll("-", "_"), opts);
|
|
190
|
+
setCustomHeader(TRUSTIFY_DA_TELEMETRY_ID_HEADER, headers, 'TRUSTIFY_DA_TELEMETRY_ID', opts);
|
|
191
|
+
if (getCustom("TRUSTIFY_DA_DEBUG", null, opts) === "true") {
|
|
192
|
+
console.log("Headers Values to be sent to Trustify DA backend:" + EOL);
|
|
193
|
+
for (const headerKey in headers) {
|
|
194
|
+
if (!headerKey.match(RegexNotToBeLogged)) {
|
|
195
|
+
console.log(`${headerKey}: ${headers[headerKey]}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return headers;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* @param {string} headerName - the header name to populate in request
|
|
204
|
+
* @param headers
|
|
205
|
+
* @param {string} optsKey - key in the options object to use the value for
|
|
206
|
+
* @param {import("index.js").Options} [opts={}] - options input object to fetch header values from
|
|
207
|
+
* @private
|
|
208
|
+
*/
|
|
209
|
+
function setCustomHeader(headerName, headers, optsKey, opts) {
|
|
210
|
+
let customHeaderValue = getCustom(optsKey, null, opts);
|
|
211
|
+
if (customHeaderValue) {
|
|
212
|
+
headers[headerName] = customHeaderValue;
|
|
213
|
+
}
|
|
214
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustify-da/trustify-da-javascript-client",
|
|
3
|
-
"version": "0.3.0-ea.
|
|
3
|
+
"version": "0.3.0-ea.ff266a3",
|
|
4
4
|
"description": "Code-Ready Dependency Analytics JavaScript API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/guacsec/trustify-da-javascript-client#README.md",
|
|
@@ -45,29 +45,33 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/core": "^7.23.2",
|
|
48
|
-
"@cyclonedx/cyclonedx-library": "
|
|
48
|
+
"@cyclonedx/cyclonedx-library": "^6.13.0",
|
|
49
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
49
50
|
"fast-toml": "^0.5.4",
|
|
50
|
-
"fast-xml-parser": "^
|
|
51
|
+
"fast-xml-parser": "^5.3.4",
|
|
51
52
|
"help": "^3.0.2",
|
|
52
53
|
"https-proxy-agent": "^7.0.6",
|
|
53
|
-
"node-fetch": "^
|
|
54
|
-
"packageurl-js": "
|
|
55
|
-
"
|
|
54
|
+
"node-fetch": "^3.3.2",
|
|
55
|
+
"packageurl-js": "~1.0.2",
|
|
56
|
+
"tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
|
|
57
|
+
"web-tree-sitter": "^0.26.6",
|
|
58
|
+
"yargs": "^18.0.0"
|
|
56
59
|
},
|
|
57
60
|
"devDependencies": {
|
|
58
61
|
"@babel/core": "^7.23.2",
|
|
59
|
-
"@trustify-da/trustify-da-api-model": "^2.0.
|
|
62
|
+
"@trustify-da/trustify-da-api-model": "^2.0.7",
|
|
60
63
|
"@types/node": "^20.17.30",
|
|
61
64
|
"@types/which": "^3.0.4",
|
|
62
65
|
"babel-plugin-rewire": "^1.2.0",
|
|
63
|
-
"c8": "^
|
|
66
|
+
"c8": "^11.0.0",
|
|
64
67
|
"chai": "^4.3.7",
|
|
65
68
|
"eslint": "^8.42.0",
|
|
69
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
66
70
|
"eslint-plugin-editorconfig": "^4.0.3",
|
|
67
71
|
"eslint-plugin-import": "^2.29.1",
|
|
68
72
|
"esmock": "^2.6.2",
|
|
69
73
|
"mocha": "^10.2.0",
|
|
70
|
-
"msw": "^
|
|
74
|
+
"msw": "^2.12.7",
|
|
71
75
|
"sinon": "^15.1.2",
|
|
72
76
|
"sinon-chai": "^3.7.0",
|
|
73
77
|
"typescript": "^5.1.3",
|