@trustify-da/trustify-da-javascript-client 0.3.0-ea.477151f → 0.3.0-ea.608d6fa

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 (38) hide show
  1. package/README.md +65 -2
  2. package/dist/package.json +6 -2
  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 +3 -0
  9. package/dist/src/index.js +3 -0
  10. package/dist/src/license/index.d.ts +28 -0
  11. package/dist/src/license/index.js +100 -0
  12. package/dist/src/license/license_utils.d.ts +40 -0
  13. package/dist/src/license/license_utils.js +134 -0
  14. package/dist/src/license/licenses_api.d.ts +34 -0
  15. package/dist/src/license/licenses_api.js +98 -0
  16. package/dist/src/license/project_license.d.ts +20 -0
  17. package/dist/src/license/project_license.js +62 -0
  18. package/dist/src/provider.d.ts +10 -1
  19. package/dist/src/provider.js +19 -2
  20. package/dist/src/providers/base_javascript.d.ts +10 -4
  21. package/dist/src/providers/base_javascript.js +30 -4
  22. package/dist/src/providers/golang_gomodules.d.ts +8 -1
  23. package/dist/src/providers/golang_gomodules.js +13 -4
  24. package/dist/src/providers/java_gradle.d.ts +6 -0
  25. package/dist/src/providers/java_gradle.js +12 -2
  26. package/dist/src/providers/java_maven.d.ts +8 -1
  27. package/dist/src/providers/java_maven.js +32 -4
  28. package/dist/src/providers/python_pip.d.ts +7 -0
  29. package/dist/src/providers/python_pip.js +13 -3
  30. package/dist/src/providers/requirements_parser.js +5 -8
  31. package/dist/src/providers/rust_cargo.d.ts +47 -0
  32. package/dist/src/providers/rust_cargo.js +606 -0
  33. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  34. package/dist/src/sbom.d.ts +3 -1
  35. package/dist/src/sbom.js +3 -2
  36. package/dist/src/tools.d.ts +18 -0
  37. package/dist/src/tools.js +55 -0
  38. package/package.json +7 -3
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.477151f",
3
+ "version": "0.3.0-ea.608d6fa",
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",
@@ -40,8 +40,11 @@
40
40
  "test": "c8 npm run tests",
41
41
  "tests": "mocha --config .mocharc.json --grep \".*analysis module.*\" --invert",
42
42
  "tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
43
+ "pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm",
43
44
  "precompile": "rm -rf dist",
44
- "compile": "tsc -p tsconfig.json"
45
+ "compile": "tsc -p tsconfig.json",
46
+ "compile:dev": "tsc -p tsconfig.dev.json",
47
+ "postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm"
45
48
  },
46
49
  "dependencies": {
47
50
  "@babel/core": "^7.23.2",
@@ -53,13 +56,14 @@
53
56
  "https-proxy-agent": "^7.0.6",
54
57
  "node-fetch": "^3.3.2",
55
58
  "packageurl-js": "~1.0.2",
59
+ "smol-toml": "^1.6.0",
56
60
  "tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
57
61
  "web-tree-sitter": "^0.26.6",
58
62
  "yargs": "^18.0.0"
59
63
  },
60
64
  "devDependencies": {
61
65
  "@babel/core": "^7.23.2",
62
- "@trustify-da/trustify-da-api-model": "^2.0.1",
66
+ "@trustify-da/trustify-da-api-model": "^2.0.7",
63
67
  "@types/node": "^20.17.30",
64
68
  "@types/which": "^3.0.4",
65
69
  "babel-plugin-rewire": "^1.2.0",