@trustify-da/trustify-da-javascript-client 0.3.0-ea.63ae5c2 → 0.3.0-ea.6549d2a

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.
Files changed (35) hide show
  1. package/README.md +13 -1
  2. package/dist/package.json +1 -1
  3. package/dist/src/analysis.d.ts +0 -6
  4. package/dist/src/analysis.js +19 -64
  5. package/dist/src/cli.js +72 -6
  6. package/dist/src/cyclone_dx_sbom.d.ts +3 -1
  7. package/dist/src/cyclone_dx_sbom.js +16 -4
  8. package/dist/src/index.d.ts +2 -0
  9. package/dist/src/index.js +2 -0
  10. package/dist/src/license/compatibility.d.ts +18 -0
  11. package/dist/src/license/compatibility.js +45 -0
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +100 -0
  14. package/dist/src/license/licenses_api.d.ts +34 -0
  15. package/dist/src/license/licenses_api.js +91 -0
  16. package/dist/src/license/project_license.d.ts +25 -0
  17. package/dist/src/license/project_license.js +139 -0
  18. package/dist/src/provider.d.ts +10 -1
  19. package/dist/src/provider.js +16 -1
  20. package/dist/src/providers/base_javascript.d.ts +10 -4
  21. package/dist/src/providers/base_javascript.js +28 -4
  22. package/dist/src/providers/golang_gomodules.d.ts +8 -1
  23. package/dist/src/providers/golang_gomodules.js +12 -4
  24. package/dist/src/providers/java_gradle.d.ts +6 -0
  25. package/dist/src/providers/java_gradle.js +11 -2
  26. package/dist/src/providers/java_maven.d.ts +8 -1
  27. package/dist/src/providers/java_maven.js +31 -4
  28. package/dist/src/providers/python_pip.d.ts +7 -0
  29. package/dist/src/providers/python_pip.js +12 -3
  30. package/dist/src/providers/requirements_parser.js +1 -5
  31. package/dist/src/sbom.d.ts +3 -1
  32. package/dist/src/sbom.js +3 -2
  33. package/dist/src/tools.d.ts +18 -0
  34. package/dist/src/tools.js +55 -0
  35. package/package.json +2 -2
@@ -4,7 +4,7 @@ import Sbom from '../sbom.js';
4
4
  import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from "../tools.js";
5
5
  import Python_controller from './python_controller.js';
6
6
  import { getParser, getIgnoreQuery, getPinnedVersionQuery } from './requirements_parser.js';
7
- export default { isSupported, validateLockFile, provideComponent, provideStack };
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
  */
@@ -167,7 +174,8 @@ async function createSbomStackAnalysis(manifest, opts = {}) {
167
174
  let dependencies = await pythonController.getDependencies(true);
168
175
  let sbom = new Sbom();
169
176
  const rootPurl = toPurl(DEFAULT_PIP_ROOT_COMPONENT_NAME, DEFAULT_PIP_ROOT_COMPONENT_VERSION);
170
- sbom.addRoot(rootPurl);
177
+ const license = readLicenseFromManifest(manifest);
178
+ sbom.addRoot(rootPurl, license);
171
179
  dependencies.forEach(dep => {
172
180
  addAllDependencies(rootPurl, dep, sbom);
173
181
  });
@@ -190,7 +198,8 @@ async function getSbomForComponentAnalysis(manifest, opts = {}) {
190
198
  let dependencies = await pythonController.getDependencies(false);
191
199
  let sbom = new Sbom();
192
200
  const rootPurl = toPurl(DEFAULT_PIP_ROOT_COMPONENT_NAME, DEFAULT_PIP_ROOT_COMPONENT_VERSION);
193
- sbom.addRoot(rootPurl);
201
+ const license = readLicenseFromManifest(manifest);
202
+ sbom.addRoot(rootPurl, license);
194
203
  dependencies.forEach(dep => {
195
204
  sbom.addDependency(rootPurl, toPurl(dep.name, dep.version));
196
205
  });
@@ -2,11 +2,7 @@ import { createRequire } from 'node:module';
2
2
  import { Language, Parser, Query } from 'web-tree-sitter';
3
3
  const require = createRequire(import.meta.url);
4
4
  async function init() {
5
- await Parser.init({
6
- locateFile() {
7
- return require.resolve('web-tree-sitter/web-tree-sitter.wasm');
8
- }
9
- });
5
+ await Parser.init();
10
6
  return await Language.load(require.resolve('tree-sitter-requirements/tree-sitter-requirements.wasm'));
11
7
  }
12
8
  export async function getParser() {
@@ -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.
@@ -68,5 +68,23 @@ export function getGitRootDir(cwd: string): string | undefined;
68
68
  * @returns {string}
69
69
  */
70
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): {};
71
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";
72
90
  import { PackageURL } from "packageurl-js";
package/dist/src/tools.js CHANGED
@@ -1,5 +1,6 @@
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
5
  export const RegexNotToBeLogged = /TRUSTIFY_DA_(.*_)?TOKEN|ex-.*-token|trust-.*-token/;
5
6
  /**
@@ -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.63ae5c2",
3
+ "version": "0.3.0-ea.6549d2a",
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",
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "@babel/core": "^7.23.2",
62
- "@trustify-da/trustify-da-api-model": "^2.0.1",
62
+ "@trustify-da/trustify-da-api-model": "^2.0.7",
63
63
  "@types/node": "^20.17.30",
64
64
  "@types/which": "^3.0.4",
65
65
  "babel-plugin-rewire": "^1.2.0",