@trustify-da/trustify-da-javascript-client 0.3.0-ea.8adb67b → 0.3.0-ea.8eab29b

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 (70) hide show
  1. package/README.md +191 -11
  2. package/dist/package.json +19 -6
  3. package/dist/src/analysis.d.ts +16 -0
  4. package/dist/src/analysis.js +74 -80
  5. package/dist/src/batch_opts.d.ts +24 -0
  6. package/dist/src/batch_opts.js +35 -0
  7. package/dist/src/cli.js +241 -8
  8. package/dist/src/cyclone_dx_sbom.d.ts +17 -2
  9. package/dist/src/cyclone_dx_sbom.js +56 -8
  10. package/dist/src/index.d.ts +138 -4
  11. package/dist/src/index.js +356 -8
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +100 -0
  14. package/dist/src/license/license_utils.d.ts +40 -0
  15. package/dist/src/license/license_utils.js +134 -0
  16. package/dist/src/license/licenses_api.d.ts +34 -0
  17. package/dist/src/license/licenses_api.js +98 -0
  18. package/dist/src/license/project_license.d.ts +20 -0
  19. package/dist/src/license/project_license.js +62 -0
  20. package/dist/src/oci_image/utils.js +11 -2
  21. package/dist/src/provider.d.ts +18 -5
  22. package/dist/src/provider.js +31 -5
  23. package/dist/src/providers/base_java.d.ts +5 -9
  24. package/dist/src/providers/base_java.js +9 -38
  25. package/dist/src/providers/base_javascript.d.ts +40 -7
  26. package/dist/src/providers/base_javascript.js +138 -24
  27. package/dist/src/providers/base_pyproject.d.ts +158 -0
  28. package/dist/src/providers/base_pyproject.js +322 -0
  29. package/dist/src/providers/golang_gomodules.d.ts +29 -12
  30. package/dist/src/providers/golang_gomodules.js +176 -121
  31. package/dist/src/providers/gomod_parser.d.ts +4 -0
  32. package/dist/src/providers/gomod_parser.js +16 -0
  33. package/dist/src/providers/java_gradle.d.ts +25 -0
  34. package/dist/src/providers/java_gradle.js +128 -4
  35. package/dist/src/providers/java_maven.d.ts +16 -1
  36. package/dist/src/providers/java_maven.js +125 -5
  37. package/dist/src/providers/javascript_bun.d.ts +10 -0
  38. package/dist/src/providers/javascript_bun.js +100 -0
  39. package/dist/src/providers/javascript_npm.d.ts +1 -0
  40. package/dist/src/providers/javascript_npm.js +21 -0
  41. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  42. package/dist/src/providers/javascript_pnpm.js +8 -4
  43. package/dist/src/providers/manifest.d.ts +2 -0
  44. package/dist/src/providers/manifest.js +22 -4
  45. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  46. package/dist/src/providers/marker_evaluator.js +191 -0
  47. package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
  48. package/dist/src/providers/python_controller.d.ts +10 -3
  49. package/dist/src/providers/python_controller.js +118 -62
  50. package/dist/src/providers/python_pip.d.ts +16 -4
  51. package/dist/src/providers/python_pip.js +51 -58
  52. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  53. package/dist/src/providers/python_pip_pyproject.js +146 -0
  54. package/dist/src/providers/python_poetry.d.ts +75 -0
  55. package/dist/src/providers/python_poetry.js +238 -0
  56. package/dist/src/providers/python_uv.d.ts +55 -0
  57. package/dist/src/providers/python_uv.js +227 -0
  58. package/dist/src/providers/requirements_parser.d.ts +6 -0
  59. package/dist/src/providers/requirements_parser.js +24 -0
  60. package/dist/src/providers/rust_cargo.d.ts +56 -0
  61. package/dist/src/providers/rust_cargo.js +641 -0
  62. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  63. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  64. package/dist/src/sbom.d.ts +17 -2
  65. package/dist/src/sbom.js +16 -4
  66. package/dist/src/tools.d.ts +44 -0
  67. package/dist/src/tools.js +114 -1
  68. package/dist/src/workspace.d.ts +70 -0
  69. package/dist/src/workspace.js +256 -0
  70. package/package.json +20 -7
@@ -5,10 +5,12 @@ import { PackageURL } from "packageurl-js";
5
5
  * @param component {PackageURL}
6
6
  * @param type type of package - application or library
7
7
  * @param scope scope of the component - runtime or compile
8
- * @return {{"bom-ref": string, name, purl: string, type, version, scope}}
8
+ * @param licenses optional license string or array of licenses for the component
9
+ * @param hashes optional array of hash objects for the component, e.g. [{alg: "SHA-256", content: "..."}]
10
+ * @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?, hashes?}}
9
11
  * @private
10
12
  */
11
- function getComponent(component, type, scope) {
13
+ function getComponent(component, type, scope, licenses, hashes) {
12
14
  let componentObject;
13
15
  if (component instanceof PackageURL) {
14
16
  if (component.namespace) {
@@ -36,6 +38,28 @@ function getComponent(component, type, scope) {
36
38
  else {
37
39
  componentObject = component;
38
40
  }
41
+ // Add licenses if provided (CycloneDX format). Callers must provide valid SPDX identifiers.
42
+ if (licenses) {
43
+ const licenseArray = Array.isArray(licenses) ? licenses : [licenses];
44
+ const validLicenses = licenseArray
45
+ .map(lic => {
46
+ if (typeof lic === 'string') {
47
+ return { license: { id: lic } };
48
+ }
49
+ if (typeof lic === 'object' && lic !== null && ('license' in lic || 'expression' in lic)) {
50
+ return lic;
51
+ }
52
+ return null;
53
+ })
54
+ .filter(Boolean);
55
+ if (validLicenses.length > 0) {
56
+ componentObject.licenses = validLicenses;
57
+ }
58
+ }
59
+ // Add hashes if provided (CycloneDX 1.4 format).
60
+ if (hashes && hashes.length > 0) {
61
+ componentObject.hashes = hashes;
62
+ }
39
63
  return componentObject;
40
64
  }
41
65
  function createDependency(dependency) {
@@ -56,11 +80,12 @@ export default class CycloneDxSbom {
56
80
  }
57
81
  /**
58
82
  * @param {PackageURL} root - add main/root component for sbom
83
+ * @param {string|Array} [licenses] - optional license(s) for the root component
59
84
  * @return {CycloneDxSbom} the CycloneDxSbom Sbom Object
60
85
  */
61
- addRoot(root) {
86
+ addRoot(root, licenses) {
62
87
  this.rootComponent =
63
- getComponent(root, "application");
88
+ getComponent(root, "application", undefined, licenses);
64
89
  this.components.push(this.rootComponent);
65
90
  return this;
66
91
  }
@@ -74,16 +99,24 @@ export default class CycloneDxSbom {
74
99
  * Adds a dependency relationship between two components in the SBOM
75
100
  * @param {PackageURL} sourceRef - The source component (parent)
76
101
  * @param {PackageURL} targetRef - The target component (dependency)
102
+ * @param {string} [scope] - Scope of the dependency
103
+ * @param {Array<{alg: string, content: string}>} [targetHashes] - Optional hashes for the target component
77
104
  * @return {CycloneDxSbom} The updated SBOM
78
105
  */
79
- addDependency(sourceRef, targetRef, scope) {
106
+ addDependency(sourceRef, targetRef, scope, targetHashes) {
80
107
  const sourcePurl = sourceRef.toString();
81
108
  const targetPurl = targetRef.toString();
82
109
  // Ensure both components exist in the components list
83
110
  [sourceRef, targetRef].forEach((ref, index) => {
84
111
  const purl = index === 0 ? sourcePurl : targetPurl;
85
- if (this.getComponentIndex(purl) < 0) {
86
- this.components.push(getComponent(ref, "library", scope));
112
+ const existingIndex = this.getComponentIndex(purl);
113
+ if (existingIndex < 0) {
114
+ const hashes = index === 1 ? targetHashes : undefined;
115
+ this.components.push(getComponent(ref, "library", scope, undefined, hashes));
116
+ }
117
+ else if (index === 1 && targetHashes && targetHashes.length > 0 && !this.components[existingIndex].hashes) {
118
+ // Update hashes if the component was first seen without them (e.g. as a source)
119
+ this.components[existingIndex].hashes = targetHashes;
87
120
  }
88
121
  });
89
122
  // Ensure source dependency exists
@@ -108,6 +141,7 @@ export default class CycloneDxSbom {
108
141
  getAsJsonString(opts) {
109
142
  let manifestType = opts["manifest-type"];
110
143
  this.setSourceManifest(opts["source-manifest"]);
144
+ const rootPurl = this.rootComponent?.purl;
111
145
  this.sbomObject = {
112
146
  "bomFormat": "CycloneDX",
113
147
  "specVersion": "1.4",
@@ -117,7 +151,7 @@ export default class CycloneDxSbom {
117
151
  "component": this.rootComponent,
118
152
  "properties": new Array()
119
153
  },
120
- "components": this.components,
154
+ "components": this.components.filter(c => c.purl !== rootPurl),
121
155
  "dependencies": this.dependencies
122
156
  };
123
157
  if (this.rootComponent === undefined) {
@@ -229,6 +263,20 @@ export default class CycloneDxSbom {
229
263
  return false;
230
264
  }
231
265
  }
266
+ /**
267
+ * Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
268
+ * @param {PackageURL} sourceRef - The source component
269
+ * @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
270
+ * @return {boolean}
271
+ */
272
+ checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
273
+ const sourcePurl = sourceRef.toString();
274
+ const depIndex = this.getDependencyIndex(sourcePurl);
275
+ if (depIndex < 0) {
276
+ return false;
277
+ }
278
+ return this.dependencies[depIndex].dependsOn.some(dep => dep.startsWith(purlPrefix));
279
+ }
232
280
  /** Removes the root component from the sbom
233
281
  */
234
282
  removeRootComponent() {
@@ -13,16 +13,28 @@ export function selectTrustifyDABackend(opts?: {
13
13
  TRUSTIFY_DA_DEBUG?: string | undefined;
14
14
  TRUSTIFY_DA_BACKEND_URL?: string | undefined;
15
15
  }): string;
16
+ /**
17
+ * Generate a CycloneDX SBOM from a manifest file. No backend HTTP request is made.
18
+ *
19
+ * @param {string} manifestPath - path to the manifest file (e.g. pom.xml, package.json)
20
+ * @param {Options} [opts={}] - optional options (e.g. workspace dir, tool paths)
21
+ * @returns {Promise<object>} parsed CycloneDX SBOM JSON object
22
+ * @throws {Error} if the manifest is unsupported or SBOM generation fails
23
+ */
24
+ export function generateSbom(manifestPath: string, opts?: Options): Promise<object>;
16
25
  export { parseImageRef } from "./oci_image/utils.js";
17
26
  export { ImageRef } from "./oci_image/images.js";
18
27
  declare namespace _default {
19
28
  export { componentAnalysis };
20
29
  export { stackAnalysis };
30
+ export { stackAnalysisBatch };
21
31
  export { imageAnalysis };
22
32
  export { validateToken };
33
+ export { generateSbom };
23
34
  }
24
35
  export default _default;
25
36
  export type Options = {
37
+ TRUSTIFY_DA_CARGO_PATH?: string | undefined;
26
38
  TRUSTIFY_DA_DOCKER_PATH?: string | undefined;
27
39
  TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED?: string | undefined;
28
40
  TRUSTIFY_DA_GO_PATH?: string | undefined;
@@ -47,11 +59,45 @@ export type Options = {
47
59
  TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined;
48
60
  TRUSTIFY_DA_SYFT_PATH?: string | undefined;
49
61
  TRUSTIFY_DA_YARN_PATH?: string | undefined;
62
+ TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
63
+ TRUSTIFY_DA_LICENSE_CHECK?: string | undefined;
50
64
  MATCH_MANIFEST_VERSIONS?: string | undefined;
51
- RHDA_SOURCE?: string | undefined;
52
- RHDA_TOKEN?: string | undefined;
53
- RHDA_TELEMETRY_ID?: string | undefined;
54
- [key: string]: string | undefined;
65
+ TRUSTIFY_DA_SOURCE?: string | undefined;
66
+ TRUSTIFY_DA_TOKEN?: string | undefined;
67
+ TRUSTIFY_DA_TELEMETRY_ID?: string | undefined;
68
+ TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
69
+ batchConcurrency?: number | undefined;
70
+ TRUSTIFY_DA_BATCH_CONCURRENCY?: string | undefined;
71
+ workspaceDiscoveryIgnore?: string[] | undefined;
72
+ TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string | undefined;
73
+ continueOnError?: boolean | undefined;
74
+ TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined;
75
+ batchMetadata?: boolean | undefined;
76
+ TRUSTIFY_DA_BATCH_METADATA?: string | undefined;
77
+ TRUSTIFY_DA_UV_PATH?: string | undefined;
78
+ TRUSTIFY_DA_POETRY_PATH?: string | undefined;
79
+ [key: string]: string | number | boolean | string[] | undefined;
80
+ };
81
+ export type BatchAnalysisMetadata = {
82
+ workspaceRoot: string;
83
+ ecosystem: "javascript" | "cargo" | "pyproject" | "unknown";
84
+ total: number;
85
+ successful: number;
86
+ failed: number;
87
+ errors: Array<{
88
+ manifestPath: string;
89
+ phase: "validation" | "sbom";
90
+ reason: string;
91
+ }>;
92
+ };
93
+ export type SbomResult = {
94
+ ok: true;
95
+ purl: string;
96
+ sbom: object;
97
+ } | {
98
+ ok: false;
99
+ manifestPath: string;
100
+ reason: string;
55
101
  };
56
102
  /**
57
103
  * Get component analysis report for a manifest content.
@@ -90,6 +136,81 @@ declare function stackAnalysis(manifest: string, html: false, opts?: Options | u
90
136
  * or backend request failed
91
137
  */
92
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>;
139
+ /**
140
+ * @overload
141
+ * @param {string} workspaceRoot
142
+ * @param {true} html
143
+ * @param {Options & { batchMetadata: true }} opts
144
+ * @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
145
+ * @throws {Error}
146
+ */
147
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts: Options & {
148
+ batchMetadata: true;
149
+ }): Promise<{
150
+ analysis: string;
151
+ metadata: BatchAnalysisMetadata;
152
+ }>;
153
+ /**
154
+ * @overload
155
+ * @param {string} workspaceRoot
156
+ * @param {true} html
157
+ * @param {Options & { batchMetadata?: false }} [opts={}]
158
+ * @returns {Promise<string>}
159
+ * @throws {Error}
160
+ */
161
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts?: (Options & {
162
+ batchMetadata?: false;
163
+ }) | undefined): Promise<string>;
164
+ /**
165
+ * @overload
166
+ * @param {string} workspaceRoot
167
+ * @param {false} html
168
+ * @param {Options & { batchMetadata: true }} opts
169
+ * @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
170
+ * @throws {Error}
171
+ */
172
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts: Options & {
173
+ batchMetadata: true;
174
+ }): Promise<{
175
+ analysis: {
176
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
177
+ };
178
+ metadata: BatchAnalysisMetadata;
179
+ }>;
180
+ /**
181
+ * @overload
182
+ * @param {string} workspaceRoot
183
+ * @param {false} html
184
+ * @param {Options & { batchMetadata?: false }} [opts={}]
185
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
186
+ * @throws {Error}
187
+ */
188
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts?: (Options & {
189
+ batchMetadata?: false;
190
+ }) | undefined): Promise<{
191
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
192
+ }>;
193
+ /**
194
+ * Get stack analysis for all workspace packages/crates (batch).
195
+ * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
196
+ * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
197
+ * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
198
+ *
199
+ * @overload
200
+ * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
201
+ * @param {boolean} [html=false] - true returns HTML, false returns JSON report
202
+ * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
203
+ * @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 }>}
204
+ * @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.
205
+ */
206
+ declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
207
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
208
+ } | {
209
+ analysis: string | {
210
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
211
+ };
212
+ metadata: BatchAnalysisMetadata;
213
+ }>;
93
214
  /**
94
215
  * @overload
95
216
  * @param {Array<string>} imageRefs
@@ -130,3 +251,16 @@ declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefi
130
251
  * @throws {Error} if the backend request failed.
131
252
  */
132
253
  declare function validateToken(opts?: Options): Promise<object>;
254
+ import { discoverMavenModules } from './providers/java_maven.js';
255
+ import { discoverGradleSubprojects } from './providers/java_gradle.js';
256
+ import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
257
+ import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
258
+ import { discoverWorkspacePackages } from './workspace.js';
259
+ import { discoverWorkspaceCrates } from './workspace.js';
260
+ import { validatePackageJson } from './workspace.js';
261
+ import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
262
+ import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
263
+ import { resolveContinueOnError } from './batch_opts.js';
264
+ import { resolveBatchMetadata } from './batch_opts.js';
265
+ export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
266
+ export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";