@trustify-da/trustify-da-javascript-client 0.3.0-ea.c2f6c64 → 0.3.0-ea.c300d9f

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 (86) hide show
  1. package/README.md +199 -11
  2. package/dist/package.json +30 -26
  3. package/dist/src/analysis.d.ts +14 -7
  4. package/dist/src/analysis.js +32 -14
  5. package/dist/src/cli.js +188 -6
  6. package/dist/src/config.d.ts +120 -0
  7. package/dist/src/config.js +260 -0
  8. package/dist/src/cyclone_dx_sbom.d.ts +20 -1
  9. package/dist/src/cyclone_dx_sbom.js +68 -9
  10. package/dist/src/index.d.ts +79 -15
  11. package/dist/src/index.js +90 -34
  12. package/dist/src/license/index.d.ts +3 -3
  13. package/dist/src/license/index.js +4 -1
  14. package/dist/src/license/license_utils.js +4 -1
  15. package/dist/src/license/licenses_api.d.ts +2 -2
  16. package/dist/src/oci_image/images.d.ts +1 -1
  17. package/dist/src/oci_image/images.js +15 -1
  18. package/dist/src/oci_image/utils.d.ts +5 -5
  19. package/dist/src/package_version.d.ts +8 -0
  20. package/dist/src/package_version.js +31 -0
  21. package/dist/src/provider.d.ts +4 -3
  22. package/dist/src/provider.js +8 -2
  23. package/dist/src/providers/base_java.d.ts +67 -12
  24. package/dist/src/providers/base_java.js +82 -61
  25. package/dist/src/providers/base_javascript.d.ts +74 -9
  26. package/dist/src/providers/base_javascript.js +116 -7
  27. package/dist/src/providers/base_pyproject.d.ts +42 -31
  28. package/dist/src/providers/base_pyproject.js +121 -78
  29. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  30. package/dist/src/providers/containerfile_parser.js +20 -0
  31. package/dist/src/providers/golang_gomodules.d.ts +11 -1
  32. package/dist/src/providers/golang_gomodules.js +114 -15
  33. package/dist/src/providers/java_gradle.d.ts +67 -0
  34. package/dist/src/providers/java_gradle.js +312 -20
  35. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  36. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  37. package/dist/src/providers/java_maven.d.ts +37 -9
  38. package/dist/src/providers/java_maven.js +269 -11
  39. package/dist/src/providers/javascript_bun.d.ts +22 -0
  40. package/dist/src/providers/javascript_bun.js +141 -0
  41. package/dist/src/providers/javascript_npm.d.ts +19 -0
  42. package/dist/src/providers/javascript_npm.js +61 -1
  43. package/dist/src/providers/javascript_pnpm.d.ts +13 -0
  44. package/dist/src/providers/javascript_pnpm.js +53 -3
  45. package/dist/src/providers/javascript_yarn.d.ts +12 -0
  46. package/dist/src/providers/javascript_yarn.js +75 -2
  47. package/dist/src/providers/manifest.js +6 -3
  48. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  49. package/dist/src/providers/marker_evaluator.js +191 -0
  50. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  51. package/dist/src/providers/oci_dockerfile.js +177 -0
  52. package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
  53. package/dist/src/providers/processors/yarn_berry_processor.js +9 -4
  54. package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
  55. package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
  56. package/dist/src/providers/python_controller.d.ts +5 -1
  57. package/dist/src/providers/python_controller.js +69 -8
  58. package/dist/src/providers/python_pip.d.ts +5 -0
  59. package/dist/src/providers/python_pip.js +5 -5
  60. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  61. package/dist/src/providers/python_pip_pyproject.js +146 -0
  62. package/dist/src/providers/python_poetry.d.ts +64 -8
  63. package/dist/src/providers/python_poetry.js +165 -25
  64. package/dist/src/providers/python_uv.d.ts +22 -2
  65. package/dist/src/providers/python_uv.js +157 -6
  66. package/dist/src/providers/requirements_parser.js +1 -1
  67. package/dist/src/providers/rust_cargo.d.ts +6 -2
  68. package/dist/src/providers/rust_cargo.js +101 -33
  69. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  70. package/dist/src/remediate.d.ts +120 -0
  71. package/dist/src/remediate.js +253 -0
  72. package/dist/src/remediation.d.ts +57 -0
  73. package/dist/src/remediation.js +436 -0
  74. package/dist/src/remediation_report.d.ts +40 -0
  75. package/dist/src/remediation_report.js +159 -0
  76. package/dist/src/sbom.d.ts +18 -1
  77. package/dist/src/sbom.js +14 -2
  78. package/dist/src/tools.d.ts +37 -13
  79. package/dist/src/tools.js +92 -13
  80. package/dist/src/updaters/maven_updater.d.ts +58 -0
  81. package/dist/src/updaters/maven_updater.js +345 -0
  82. package/dist/src/updaters/toml_updater.d.ts +62 -0
  83. package/dist/src/updaters/toml_updater.js +276 -0
  84. package/dist/src/workspace.d.ts +11 -1
  85. package/dist/src/workspace.js +3 -2
  86. package/package.json +31 -27
@@ -1,15 +1,23 @@
1
1
  import { EOL } from "os";
2
2
  import { PackageURL } from "packageurl-js";
3
+ import { getPackageVersion } from "./package_version.js";
4
+ /**
5
+ * This client's version, read once at module load, used to populate
6
+ * metadata.tools.components[].version in the generated SBOM.
7
+ * @type {string|undefined}
8
+ */
9
+ const PACKAGE_VERSION = getPackageVersion();
3
10
  /**
4
11
  *
5
12
  * @param component {PackageURL}
6
13
  * @param type type of package - application or library
7
14
  * @param scope scope of the component - runtime or compile
8
15
  * @param licenses optional license string or array of licenses for the component
9
- * @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?}}
16
+ * @param hashes optional array of hash objects for the component, e.g. [{alg: "SHA-256", content: "..."}]
17
+ * @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?, hashes?}}
10
18
  * @private
11
19
  */
12
- function getComponent(component, type, scope, licenses) {
20
+ function getComponent(component, type, scope, licenses, hashes) {
13
21
  let componentObject;
14
22
  if (component instanceof PackageURL) {
15
23
  if (component.namespace) {
@@ -40,12 +48,24 @@ function getComponent(component, type, scope, licenses) {
40
48
  // Add licenses if provided (CycloneDX format). Callers must provide valid SPDX identifiers.
41
49
  if (licenses) {
42
50
  const licenseArray = Array.isArray(licenses) ? licenses : [licenses];
43
- componentObject.licenses = licenseArray.map(lic => {
51
+ const validLicenses = licenseArray
52
+ .map(lic => {
44
53
  if (typeof lic === 'string') {
45
54
  return { license: { id: lic } };
46
55
  }
47
- return lic;
48
- });
56
+ if (typeof lic === 'object' && lic !== null && ('license' in lic || 'expression' in lic)) {
57
+ return lic;
58
+ }
59
+ return null;
60
+ })
61
+ .filter(Boolean);
62
+ if (validLicenses.length > 0) {
63
+ componentObject.licenses = validLicenses;
64
+ }
65
+ }
66
+ // Add hashes if provided (CycloneDX 1.4 format).
67
+ if (hashes && hashes.length > 0) {
68
+ componentObject.hashes = hashes;
49
69
  }
50
70
  return componentObject;
51
71
  }
@@ -86,16 +106,24 @@ export default class CycloneDxSbom {
86
106
  * Adds a dependency relationship between two components in the SBOM
87
107
  * @param {PackageURL} sourceRef - The source component (parent)
88
108
  * @param {PackageURL} targetRef - The target component (dependency)
109
+ * @param {string} [scope] - Scope of the dependency
110
+ * @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
89
111
  * @return {CycloneDxSbom} The updated SBOM
90
112
  */
91
- addDependency(sourceRef, targetRef, scope) {
113
+ addDependency(sourceRef, targetRef, scope, targetHashes) {
92
114
  const sourcePurl = sourceRef.toString();
93
115
  const targetPurl = targetRef.toString();
94
116
  // Ensure both components exist in the components list
95
117
  [sourceRef, targetRef].forEach((ref, index) => {
96
118
  const purl = index === 0 ? sourcePurl : targetPurl;
97
- if (this.getComponentIndex(purl) < 0) {
98
- this.components.push(getComponent(ref, "library", scope));
119
+ const existingIndex = this.getComponentIndex(purl);
120
+ if (existingIndex < 0) {
121
+ const hashes = index === 1 ? targetHashes : undefined;
122
+ this.components.push(getComponent(ref, "library", scope, undefined, hashes));
123
+ }
124
+ else if (index === 1 && targetHashes && targetHashes.length > 0 && !this.components[existingIndex].hashes) {
125
+ // Update hashes if the component was first seen without them (e.g. as a source)
126
+ this.components[existingIndex].hashes = targetHashes;
99
127
  }
100
128
  });
101
129
  // Ensure source dependency exists
@@ -114,6 +142,30 @@ export default class CycloneDxSbom {
114
142
  }
115
143
  return this;
116
144
  }
145
+ /**
146
+ * Attach hashes to already-added components by matching their PURL. This is a
147
+ * post-processing step so ecosystem-specific hash sources (e.g. Maven reading
148
+ * the local .m2 cache) can enrich the SBOM without threading their concern
149
+ * through the shared dependency-tree parser. Components without a matching
150
+ * entry, or whose hashes are already set, are left untouched.
151
+ * @param {Map<string, Array<{alg: string, content: string}>>} hashMap - PURL→hashes map
152
+ * @return {CycloneDxSbom} the updated SBOM
153
+ */
154
+ attachHashes(hashMap) {
155
+ if (!hashMap || hashMap.size === 0) {
156
+ return this;
157
+ }
158
+ for (const component of this.components) {
159
+ if (component.hashes) {
160
+ continue;
161
+ }
162
+ const hashes = hashMap.get(component.purl);
163
+ if (hashes && hashes.length > 0) {
164
+ component.hashes = hashes;
165
+ }
166
+ }
167
+ return this;
168
+ }
117
169
  /** @param {{}} opts - various options, settings and configuration of application.
118
170
  * @return String CycloneDx Sbom json object in a string format
119
171
  */
@@ -123,11 +175,18 @@ export default class CycloneDxSbom {
123
175
  const rootPurl = this.rootComponent?.purl;
124
176
  this.sbomObject = {
125
177
  "bomFormat": "CycloneDX",
126
- "specVersion": "1.4",
178
+ "specVersion": "1.6",
127
179
  "version": 1,
128
180
  "metadata": {
129
181
  "timestamp": new Date(),
130
182
  "component": this.rootComponent,
183
+ "tools": {
184
+ "components": [{
185
+ "type": "application",
186
+ "name": "trustify-da-javascript-client",
187
+ "version": PACKAGE_VERSION
188
+ }]
189
+ },
131
190
  "properties": new Array()
132
191
  },
133
192
  "components": this.components.filter(c => c.purl !== rootPurl),
@@ -1,8 +1,6 @@
1
1
  /**
2
- * This function is used to determine the Trustify DA backend URL.
3
- * The TRUSTIFY_DA_BACKEND_URL is evaluated in the following order and selected when it finds it first:
4
- * 1. Environment Variable
5
- * 2. (key,value) from opts object
2
+ * Selects the Trustify DA backend URL from opts.TRUSTIFY_DA_BACKEND_URL, then environment
3
+ * variable TRUSTIFY_DA_BACKEND_URL. Options take precedence over environment variables.
6
4
  * If TRUSTIFY_DA_BACKEND_URL is not set, the function will throw an error.
7
5
  * @param {{TRUSTIFY_DA_DEBUG?: string | undefined; TRUSTIFY_DA_BACKEND_URL?: string | undefined}} [opts={}]
8
6
  * @return {string} - The selected Trustify DA backend URL
@@ -24,6 +22,7 @@ export function selectTrustifyDABackend(opts?: {
24
22
  export function generateSbom(manifestPath: string, opts?: Options): Promise<object>;
25
23
  export { parseImageRef } from "./oci_image/utils.js";
26
24
  export { ImageRef } from "./oci_image/images.js";
25
+ export { extractRemediations } from "./remediation.js";
27
26
  declare namespace _default {
28
27
  export { componentAnalysis };
29
28
  export { stackAnalysis };
@@ -53,7 +52,9 @@ export type Options = {
53
52
  TRUSTIFY_DA_PYTHON_PATH?: string | undefined;
54
53
  TRUSTIFY_DA_PYTHON_VIRTUAL_ENV?: string | undefined;
55
54
  TRUSTIFY_DA_PYTHON3_PATH?: string | undefined;
56
- TRUSTIFY_DA_RECOMMENDATIONS_ENABLED?: string | undefined;
55
+ TRUSTIFY_DA_PROVIDERS?: string | undefined;
56
+ TRUSTIFY_DA_RECOMMEND?: string | undefined;
57
+ TRUSTIFY_DA_SOURCES?: string | undefined;
57
58
  TRUSTIFY_DA_SKOPEO_CONFIG_PATH?: string | undefined;
58
59
  TRUSTIFY_DA_SKOPEO_PATH?: string | undefined;
59
60
  TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined;
@@ -61,6 +62,7 @@ export type Options = {
61
62
  TRUSTIFY_DA_YARN_PATH?: string | undefined;
62
63
  TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
63
64
  TRUSTIFY_DA_LICENSE_CHECK?: string | undefined;
65
+ licenseCheck?: boolean | undefined;
64
66
  MATCH_MANIFEST_VERSIONS?: string | undefined;
65
67
  TRUSTIFY_DA_SOURCE?: string | undefined;
66
68
  TRUSTIFY_DA_TOKEN?: string | undefined;
@@ -80,7 +82,7 @@ export type Options = {
80
82
  };
81
83
  export type BatchAnalysisMetadata = {
82
84
  workspaceRoot: string;
83
- ecosystem: "javascript" | "cargo" | "unknown";
85
+ ecosystem: "javascript" | "cargo" | "pyproject" | "unknown";
84
86
  total: number;
85
87
  successful: number;
86
88
  failed: number;
@@ -106,7 +108,7 @@ export type SbomResult = {
106
108
  * @returns {Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
107
109
  * @throws {Error} if no matching provider, failed to get create content, or backend request failed
108
110
  */
109
- declare function componentAnalysis(manifest: string, opts?: Options): Promise<import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
111
+ declare function componentAnalysis(manifest: string, opts?: Options): Promise<any>;
110
112
  /**
111
113
  * @overload
112
114
  * @param {string} manifest
@@ -124,7 +126,7 @@ declare function stackAnalysis(manifest: string, html: true, opts?: Options | un
124
126
  * @returns {Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
125
127
  * @throws {Error}
126
128
  */
127
- declare function stackAnalysis(manifest: string, html: false, opts?: Options | undefined): Promise<import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
129
+ declare function stackAnalysis(manifest: string, html: false, opts?: Options | undefined): Promise<any>;
128
130
  /**
129
131
  * Get stack analysis report for a manifest file.
130
132
  * @overload
@@ -135,24 +137,79 @@ declare function stackAnalysis(manifest: string, html: false, opts?: Options | u
135
137
  * @throws {Error} if manifest inaccessible, no matching provider, failed to get create content,
136
138
  * or backend request failed
137
139
  */
138
- declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
140
+ declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | any>;
141
+ /**
142
+ * @overload
143
+ * @param {string} workspaceRoot
144
+ * @param {true} html
145
+ * @param {Options & { batchMetadata: true }} opts
146
+ * @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
147
+ * @throws {Error}
148
+ */
149
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts: Options & {
150
+ batchMetadata: true;
151
+ }): Promise<{
152
+ analysis: string;
153
+ metadata: BatchAnalysisMetadata;
154
+ }>;
155
+ /**
156
+ * @overload
157
+ * @param {string} workspaceRoot
158
+ * @param {true} html
159
+ * @param {Options & { batchMetadata?: false }} [opts={}]
160
+ * @returns {Promise<string>}
161
+ * @throws {Error}
162
+ */
163
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts?: (Options & {
164
+ batchMetadata?: false;
165
+ }) | undefined): Promise<string>;
166
+ /**
167
+ * @overload
168
+ * @param {string} workspaceRoot
169
+ * @param {false} html
170
+ * @param {Options & { batchMetadata: true }} opts
171
+ * @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
172
+ * @throws {Error}
173
+ */
174
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts: Options & {
175
+ batchMetadata: true;
176
+ }): Promise<{
177
+ analysis: {
178
+ [x: string]: any;
179
+ };
180
+ metadata: BatchAnalysisMetadata;
181
+ }>;
182
+ /**
183
+ * @overload
184
+ * @param {string} workspaceRoot
185
+ * @param {false} html
186
+ * @param {Options & { batchMetadata?: false }} [opts={}]
187
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
188
+ * @throws {Error}
189
+ */
190
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts?: (Options & {
191
+ batchMetadata?: false;
192
+ }) | undefined): Promise<{
193
+ [x: string]: any;
194
+ }>;
139
195
  /**
140
196
  * Get stack analysis for all workspace packages/crates (batch).
141
197
  * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
142
198
  * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
143
199
  * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
144
200
  *
201
+ * @overload
145
202
  * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
146
203
  * @param {boolean} [html=false] - true returns HTML, false returns JSON report
147
204
  * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
148
205
  * @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>|{ analysis: string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
149
206
  * @throws {Error} if workspace root invalid, no manifests found, no packages pass validation, no SBOMs produced, or backend request failed. When `opts.batchMetadata` is set, `error.batchMetadata` may be set on thrown errors.
150
207
  */
151
- declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean, opts?: Options): Promise<string | {
152
- [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
208
+ declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
209
+ [x: string]: any;
153
210
  } | {
154
211
  analysis: string | {
155
- [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
212
+ [x: string]: any;
156
213
  };
157
214
  metadata: BatchAnalysisMetadata;
158
215
  }>;
@@ -174,7 +231,7 @@ declare function imageAnalysis(imageRefs: Array<string>, html: true, opts?: Opti
174
231
  * @throws {Error}
175
232
  */
176
233
  declare function imageAnalysis(imageRefs: Array<string>, html: false, opts?: Options | undefined): Promise<{
177
- [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
234
+ [x: string]: any;
178
235
  }>;
179
236
  /**
180
237
  * Get image analysis report for a set of OCI image references.
@@ -187,7 +244,7 @@ declare function imageAnalysis(imageRefs: Array<string>, html: false, opts?: Opt
187
244
  * or backend request failed
188
245
  */
189
246
  declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
190
- [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
247
+ [x: string]: any;
191
248
  }>;
192
249
  /**
193
250
  * Validates the Exhort token.
@@ -196,6 +253,10 @@ declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefi
196
253
  * @throws {Error} if the backend request failed.
197
254
  */
198
255
  declare function validateToken(opts?: Options): Promise<object>;
256
+ import { discoverMavenModules } from './providers/java_maven.js';
257
+ import { discoverGradleSubprojects } from './providers/java_gradle.js';
258
+ import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
259
+ import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
199
260
  import { discoverWorkspacePackages } from './workspace.js';
200
261
  import { discoverWorkspaceCrates } from './workspace.js';
201
262
  import { validatePackageJson } from './workspace.js';
@@ -203,5 +264,8 @@ import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
203
264
  import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
204
265
  import { resolveContinueOnError } from './batch_opts.js';
205
266
  import { resolveBatchMetadata } from './batch_opts.js';
206
- export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
267
+ export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
207
268
  export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
269
+ export { generateReport, generateDeduplicationKey } from "./remediation_report.js";
270
+ export { loadConfig, mergeConfig, resolveConfig, CONFIG_FILENAMES } from "./config.js";
271
+ export { runRemediation, findManifests } from "./remediate.js";
package/dist/src/index.js CHANGED
@@ -1,19 +1,26 @@
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";
18
+ export { extractRemediations } from "./remediation.js";
19
+ export { generateReport, generateDeduplicationKey } from './remediation_report.js';
20
+ export { loadConfig, mergeConfig, resolveConfig, CONFIG_FILENAMES } from './config.js';
21
+ export { runRemediation, findManifests } from './remediate.js';
15
22
  export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
16
- export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
23
+ export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
17
24
  /**
18
25
  * @typedef {{
19
26
  * TRUSTIFY_DA_CARGO_PATH?: string | undefined,
@@ -35,7 +42,9 @@ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson
35
42
  * TRUSTIFY_DA_PYTHON_PATH?: string | undefined,
36
43
  * TRUSTIFY_DA_PYTHON_VIRTUAL_ENV?: string | undefined,
37
44
  * TRUSTIFY_DA_PYTHON3_PATH?: string | undefined,
38
- * TRUSTIFY_DA_RECOMMENDATIONS_ENABLED?: string | undefined,
45
+ * TRUSTIFY_DA_PROVIDERS?: string | undefined,
46
+ * TRUSTIFY_DA_RECOMMEND?: string | undefined,
47
+ * TRUSTIFY_DA_SOURCES?: string | undefined,
39
48
  * TRUSTIFY_DA_SKOPEO_CONFIG_PATH?: string | undefined,
40
49
  * TRUSTIFY_DA_SKOPEO_PATH?: string | undefined,
41
50
  * TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined,
@@ -43,6 +52,7 @@ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson
43
52
  * TRUSTIFY_DA_YARN_PATH?: string | undefined,
44
53
  * TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
45
54
  * TRUSTIFY_DA_LICENSE_CHECK?: string | undefined,
55
+ * licenseCheck?: boolean | undefined,
46
56
  * MATCH_MANIFEST_VERSIONS?: string | undefined,
47
57
  * TRUSTIFY_DA_SOURCE?: string | undefined,
48
58
  * TRUSTIFY_DA_TOKEN?: string | undefined,
@@ -64,7 +74,7 @@ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson
64
74
  /**
65
75
  * @typedef {{
66
76
  * workspaceRoot: string,
67
- * ecosystem: 'javascript' | 'cargo' | 'unknown',
77
+ * ecosystem: 'javascript' | 'cargo' | 'pyproject' | 'unknown',
68
78
  * total: number,
69
79
  * successful: number,
70
80
  * failed: number,
@@ -87,29 +97,11 @@ function logOptionsAndEnvironmentsVariables(alongsideText, valueToBePrinted) {
87
97
  * @private
88
98
  */
89
99
  function readAndPrintVersionFromPackageJson() {
90
- let dirName;
91
- // new ESM way in nodeJS ( since node version 22 ) to bring module directory.
92
- dirName = import.meta.dirname;
93
- // old ESM way in nodeJS ( before node versions 22.00 to bring module directory)
94
- if (!dirName) {
95
- dirName = url.fileURLToPath(new URL('.', import.meta.url));
96
- }
97
- try {
98
- if (__dirname) {
99
- dirName = __dirname;
100
- }
101
- }
102
- catch (e) {
103
- console.log("__dirname is not defined, continue with fileUrlPath");
104
- }
105
- let packageJson = JSON.parse(fs.readFileSync(path.join(dirName, "..", "package.json")).toString());
106
- logOptionsAndEnvironmentsVariables("trustify-da-javascript-client analysis started, version: ", packageJson.version);
100
+ logOptionsAndEnvironmentsVariables("trustify-da-javascript-client analysis started, version: ", getPackageVersion());
107
101
  }
108
102
  /**
109
- * This function is used to determine the Trustify DA backend URL.
110
- * The TRUSTIFY_DA_BACKEND_URL is evaluated in the following order and selected when it finds it first:
111
- * 1. Environment Variable
112
- * 2. (key,value) from opts object
103
+ * Selects the Trustify DA backend URL from opts.TRUSTIFY_DA_BACKEND_URL, then environment
104
+ * variable TRUSTIFY_DA_BACKEND_URL. Options take precedence over environment variables.
113
105
  * If TRUSTIFY_DA_BACKEND_URL is not set, the function will throw an error.
114
106
  * @param {{TRUSTIFY_DA_DEBUG?: string | undefined; TRUSTIFY_DA_BACKEND_URL?: string | undefined}} [opts={}]
115
107
  * @return {string} - The selected Trustify DA backend URL
@@ -171,7 +163,9 @@ async function componentAnalysis(manifest, opts = {}) {
171
163
  fs.accessSync(manifest, fs.constants.R_OK);
172
164
  opts["manifest-type"] = path.basename(manifest);
173
165
  let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
174
- return await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
166
+ const result = await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
167
+ result.packageManager = provider.packageManagerName();
168
+ return result;
175
169
  }
176
170
  /**
177
171
  * @overload
@@ -204,7 +198,8 @@ async function imageAnalysis(imageRefs, html = false, opts = {}) {
204
198
  return await analysis.requestImages(imageRefs, theUrl, html, opts);
205
199
  }
206
200
  /**
207
- * Max concurrent SBOM generations for batch workspace analysis. Env/opts override default 10.
201
+ * Max concurrent SBOM generations for batch workspace analysis. Options override environment;
202
+ * environment overrides the default of 10.
208
203
  * @param {Options} opts
209
204
  * @returns {number}
210
205
  * @private
@@ -279,17 +274,45 @@ async function generateOneSbom(manifestPath, workspaceOpts) {
279
274
  *
280
275
  * @param {string} root - Resolved workspace root
281
276
  * @param {Options} opts
282
- * @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'unknown', manifestPaths: string[] }>}
277
+ * @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'gradle' | 'gomodules' | 'pyproject' | 'unknown', manifestPaths: string[] }>}
283
278
  * @private
284
279
  */
285
280
  async function detectWorkspaceManifests(root, opts) {
286
281
  const cargoToml = path.join(root, 'Cargo.toml');
287
282
  const cargoLock = path.join(root, 'Cargo.lock');
288
283
  const packageJson = path.join(root, 'package.json');
284
+ const pomXml = path.join(root, 'pom.xml');
289
285
  if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
290
286
  return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
291
287
  }
292
- const hasJsLock = fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
288
+ if (fs.existsSync(pomXml)) {
289
+ const manifestPaths = await discoverMavenModules(root, opts);
290
+ if (manifestPaths.length > 0) {
291
+ return { ecosystem: 'maven', manifestPaths };
292
+ }
293
+ }
294
+ const hasGradleSettings = fs.existsSync(path.join(root, 'settings.gradle'))
295
+ || fs.existsSync(path.join(root, 'settings.gradle.kts'));
296
+ if (hasGradleSettings) {
297
+ const manifestPaths = await discoverGradleSubprojects(root, opts);
298
+ if (manifestPaths.length > 0) {
299
+ return { ecosystem: 'gradle', manifestPaths };
300
+ }
301
+ }
302
+ if (fs.existsSync(path.join(root, 'go.work'))) {
303
+ const manifestPaths = await discoverGoWorkspaceModules(root, opts);
304
+ if (manifestPaths.length > 0) {
305
+ return { ecosystem: 'gomodules', manifestPaths };
306
+ }
307
+ }
308
+ if (fs.existsSync(path.join(root, 'pyproject.toml')) && fs.existsSync(path.join(root, 'uv.lock'))) {
309
+ const manifestPaths = await discoverUvWorkspaceMembers(root, opts);
310
+ if (manifestPaths.length > 0) {
311
+ return { ecosystem: 'pyproject', manifestPaths };
312
+ }
313
+ }
314
+ const hasJsLock = fs.existsSync(path.join(root, 'bun.lock'))
315
+ || fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
293
316
  || fs.existsSync(path.join(root, 'yarn.lock'))
294
317
  || fs.existsSync(path.join(root, 'package-lock.json'));
295
318
  if (fs.existsSync(packageJson) && hasJsLock) {
@@ -398,12 +421,45 @@ function batchError(message, wantMetadata, metadata) {
398
421
  }
399
422
  return err;
400
423
  }
424
+ /**
425
+ * @overload
426
+ * @param {string} workspaceRoot
427
+ * @param {true} html
428
+ * @param {Options & { batchMetadata: true }} opts
429
+ * @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
430
+ * @throws {Error}
431
+ */
432
+ /**
433
+ * @overload
434
+ * @param {string} workspaceRoot
435
+ * @param {true} html
436
+ * @param {Options & { batchMetadata?: false }} [opts={}]
437
+ * @returns {Promise<string>}
438
+ * @throws {Error}
439
+ */
440
+ /**
441
+ * @overload
442
+ * @param {string} workspaceRoot
443
+ * @param {false} html
444
+ * @param {Options & { batchMetadata: true }} opts
445
+ * @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
446
+ * @throws {Error}
447
+ */
448
+ /**
449
+ * @overload
450
+ * @param {string} workspaceRoot
451
+ * @param {false} html
452
+ * @param {Options & { batchMetadata?: false }} [opts={}]
453
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
454
+ * @throws {Error}
455
+ */
401
456
  /**
402
457
  * Get stack analysis for all workspace packages/crates (batch).
403
458
  * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
404
459
  * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
405
460
  * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
406
461
  *
462
+ * @overload
407
463
  * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
408
464
  * @param {boolean} [html=false] - true returns HTML, false returns JSON report
409
465
  * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
@@ -434,7 +490,7 @@ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
434
490
  }
435
491
  }
436
492
  if (manifestPaths.length === 0) {
437
- throw new Error(`No workspace manifests found at ${root}. Ensure Cargo.toml+Cargo.lock or package.json+lock file exist.`);
493
+ 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).`);
438
494
  }
439
495
  const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
440
496
  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?: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport): Promise<{
12
+ export function runLicenseCheck(sbomContent: string, manifestPath: string, url: string, opts?: import("../index.js").Options, analysisResult?: any): Promise<{
13
13
  projectLicense: {
14
- manifest: any | null;
15
- file: any | null;
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: 'Dependency license(s) are incompatible with the project license.'
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' || dep === '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<any | null>;
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: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport, purls?: string[]): Map<string, {
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?: import("index.js").Options);
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
- const repositoryUrl = this.image.getNameWithoutTag();
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
  }