@trustify-da/trustify-da-javascript-client 0.3.0-ea.3aa725a → 0.3.0-ea.4558b63

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 +23 -10
  3. package/dist/src/analysis.d.ts +21 -5
  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 +10 -2
  9. package/dist/src/cyclone_dx_sbom.js +32 -5
  10. package/dist/src/index.d.ts +194 -11
  11. package/dist/src/index.js +329 -7
  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/images.d.ts +4 -5
  21. package/dist/src/oci_image/utils.d.ts +4 -4
  22. package/dist/src/oci_image/utils.js +11 -2
  23. package/dist/src/provider.d.ts +17 -5
  24. package/dist/src/provider.js +29 -5
  25. package/dist/src/providers/base_java.d.ts +3 -14
  26. package/dist/src/providers/base_java.js +2 -38
  27. package/dist/src/providers/base_javascript.d.ts +29 -7
  28. package/dist/src/providers/base_javascript.js +129 -22
  29. package/dist/src/providers/base_pyproject.d.ts +149 -0
  30. package/dist/src/providers/base_pyproject.js +314 -0
  31. package/dist/src/providers/golang_gomodules.d.ts +20 -13
  32. package/dist/src/providers/golang_gomodules.js +112 -114
  33. package/dist/src/providers/gomod_parser.d.ts +4 -0
  34. package/dist/src/providers/gomod_parser.js +16 -0
  35. package/dist/src/providers/java_gradle.d.ts +9 -3
  36. package/dist/src/providers/java_gradle.js +12 -2
  37. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  38. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  39. package/dist/src/providers/java_maven.d.ts +20 -5
  40. package/dist/src/providers/java_maven.js +126 -6
  41. package/dist/src/providers/javascript_npm.d.ts +1 -0
  42. package/dist/src/providers/javascript_npm.js +21 -0
  43. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  44. package/dist/src/providers/javascript_pnpm.js +8 -4
  45. package/dist/src/providers/manifest.d.ts +2 -0
  46. package/dist/src/providers/manifest.js +22 -4
  47. package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
  48. package/dist/src/providers/python_controller.d.ts +5 -2
  49. package/dist/src/providers/python_controller.js +60 -58
  50. package/dist/src/providers/python_pip.d.ts +11 -4
  51. package/dist/src/providers/python_pip.js +47 -54
  52. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  53. package/dist/src/providers/python_pip_pyproject.js +144 -0
  54. package/dist/src/providers/python_poetry.d.ts +43 -0
  55. package/dist/src/providers/python_poetry.js +175 -0
  56. package/dist/src/providers/python_uv.d.ts +27 -0
  57. package/dist/src/providers/python_uv.js +149 -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 +52 -0
  61. package/dist/src/providers/rust_cargo.js +614 -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 +10 -1
  65. package/dist/src/sbom.js +12 -2
  66. package/dist/src/tools.d.ts +38 -6
  67. package/dist/src/tools.js +96 -1
  68. package/dist/src/workspace.d.ts +61 -0
  69. package/dist/src/workspace.js +256 -0
  70. package/package.json +24 -11
@@ -5,10 +5,11 @@ 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
+ * @return {{"bom-ref": string, name, purl: string, type, version, scope, licenses?}}
9
10
  * @private
10
11
  */
11
- function getComponent(component, type, scope) {
12
+ function getComponent(component, type, scope, licenses) {
12
13
  let componentObject;
13
14
  if (component instanceof PackageURL) {
14
15
  if (component.namespace) {
@@ -36,6 +37,16 @@ function getComponent(component, type, scope) {
36
37
  else {
37
38
  componentObject = component;
38
39
  }
40
+ // Add licenses if provided (CycloneDX format). Callers must provide valid SPDX identifiers.
41
+ if (licenses) {
42
+ const licenseArray = Array.isArray(licenses) ? licenses : [licenses];
43
+ componentObject.licenses = licenseArray.map(lic => {
44
+ if (typeof lic === 'string') {
45
+ return { license: { id: lic } };
46
+ }
47
+ return lic;
48
+ });
49
+ }
39
50
  return componentObject;
40
51
  }
41
52
  function createDependency(dependency) {
@@ -56,11 +67,12 @@ export default class CycloneDxSbom {
56
67
  }
57
68
  /**
58
69
  * @param {PackageURL} root - add main/root component for sbom
70
+ * @param {string|Array} [licenses] - optional license(s) for the root component
59
71
  * @return {CycloneDxSbom} the CycloneDxSbom Sbom Object
60
72
  */
61
- addRoot(root) {
73
+ addRoot(root, licenses) {
62
74
  this.rootComponent =
63
- getComponent(root, "application");
75
+ getComponent(root, "application", undefined, licenses);
64
76
  this.components.push(this.rootComponent);
65
77
  return this;
66
78
  }
@@ -108,6 +120,7 @@ export default class CycloneDxSbom {
108
120
  getAsJsonString(opts) {
109
121
  let manifestType = opts["manifest-type"];
110
122
  this.setSourceManifest(opts["source-manifest"]);
123
+ const rootPurl = this.rootComponent?.purl;
111
124
  this.sbomObject = {
112
125
  "bomFormat": "CycloneDX",
113
126
  "specVersion": "1.4",
@@ -117,7 +130,7 @@ export default class CycloneDxSbom {
117
130
  "component": this.rootComponent,
118
131
  "properties": new Array()
119
132
  },
120
- "components": this.components,
133
+ "components": this.components.filter(c => c.purl !== rootPurl),
121
134
  "dependencies": this.dependencies
122
135
  };
123
136
  if (this.rootComponent === undefined) {
@@ -229,6 +242,20 @@ export default class CycloneDxSbom {
229
242
  return false;
230
243
  }
231
244
  }
245
+ /**
246
+ * Checks if any entry in the dependsOn list of sourceRef starts with the given purl prefix.
247
+ * @param {PackageURL} sourceRef - The source component
248
+ * @param {string} purlPrefix - The purl prefix to match (e.g. "pkg:npm/minimist@")
249
+ * @return {boolean}
250
+ */
251
+ checkDependsOnByPurlPrefix(sourceRef, purlPrefix) {
252
+ const sourcePurl = sourceRef.toString();
253
+ const depIndex = this.getDependencyIndex(sourcePurl);
254
+ if (depIndex < 0) {
255
+ return false;
256
+ }
257
+ return this.dependencies[depIndex].dependsOn.some(dep => dep.startsWith(purlPrefix));
258
+ }
232
259
  /** Removes the root component from the sbom
233
260
  */
234
261
  removeRootComponent() {
@@ -12,18 +12,29 @@
12
12
  export function selectTrustifyDABackend(opts?: {
13
13
  TRUSTIFY_DA_DEBUG?: string | undefined;
14
14
  TRUSTIFY_DA_BACKEND_URL?: string | undefined;
15
- } | undefined): string;
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 = {
26
- [key: string]: string | undefined;
37
+ TRUSTIFY_DA_CARGO_PATH?: string | undefined;
27
38
  TRUSTIFY_DA_DOCKER_PATH?: string | undefined;
28
39
  TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED?: string | undefined;
29
40
  TRUSTIFY_DA_GO_PATH?: string | undefined;
@@ -48,10 +59,45 @@ export type Options = {
48
59
  TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined;
49
60
  TRUSTIFY_DA_SYFT_PATH?: string | undefined;
50
61
  TRUSTIFY_DA_YARN_PATH?: string | undefined;
62
+ TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
63
+ TRUSTIFY_DA_LICENSE_CHECK?: string | undefined;
51
64
  MATCH_MANIFEST_VERSIONS?: string | undefined;
52
- RHDA_SOURCE?: string | undefined;
53
- RHDA_TOKEN?: string | undefined;
54
- RHDA_TELEMETRY_ID?: 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" | "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.
@@ -60,16 +106,143 @@ export type Options = {
60
106
  * @returns {Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
61
107
  * @throws {Error} if no matching provider, failed to get create content, or backend request failed
62
108
  */
63
- declare function componentAnalysis(manifest: string, opts?: Options | undefined): Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>;
109
+ declare function componentAnalysis(manifest: string, opts?: Options): Promise<import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
110
+ /**
111
+ * @overload
112
+ * @param {string} manifest
113
+ * @param {true} html
114
+ * @param {Options} [opts={}]
115
+ * @returns {Promise<string>}
116
+ * @throws {Error}
117
+ */
64
118
  declare function stackAnalysis(manifest: string, html: true, opts?: Options | undefined): Promise<string>;
65
- declare function stackAnalysis(manifest: string, html: false, opts?: Options | undefined): Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>;
66
- declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>;
119
+ /**
120
+ * @overload
121
+ * @param {string} manifest
122
+ * @param {false} html
123
+ * @param {Options} [opts={}]
124
+ * @returns {Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
125
+ * @throws {Error}
126
+ */
127
+ declare function stackAnalysis(manifest: string, html: false, opts?: Options | undefined): Promise<import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport>;
128
+ /**
129
+ * Get stack analysis report for a manifest file.
130
+ * @overload
131
+ * @param {string} manifest - path for the manifest
132
+ * @param {boolean} [html=false] - true will return a html string, false will return AnalysisReport object.
133
+ * @param {Options} [opts={}] - optional various options to pass along the application
134
+ * @returns {Promise<string|import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
135
+ * @throws {Error} if manifest inaccessible, no matching provider, failed to get create content,
136
+ * or backend request failed
137
+ */
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
+ }>;
214
+ /**
215
+ * @overload
216
+ * @param {Array<string>} imageRefs
217
+ * @param {true} html
218
+ * @param {Options} [opts={}]
219
+ * @returns {Promise<string>}
220
+ * @throws {Error}
221
+ */
67
222
  declare function imageAnalysis(imageRefs: Array<string>, html: true, opts?: Options | undefined): Promise<string>;
223
+ /**
224
+ * @overload
225
+ * @param {Array<string>} imageRefs
226
+ * @param {false} html
227
+ * @param {Options} [opts={}]
228
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
229
+ * @throws {Error}
230
+ */
68
231
  declare function imageAnalysis(imageRefs: Array<string>, html: false, opts?: Options | undefined): Promise<{
69
- [x: string]: import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport;
232
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
70
233
  }>;
234
+ /**
235
+ * Get image analysis report for a set of OCI image references.
236
+ * @overload
237
+ * @param {Array<string>} imageRefs - OCI image references
238
+ * @param {boolean} [html=false] - true will return a html string, false will return AnalysisReport
239
+ * @param {Options} [opts={}] - optional various options to pass along the application
240
+ * @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
241
+ * @throws {Error} if manifest inaccessible, no matching provider, failed to get create content,
242
+ * or backend request failed
243
+ */
71
244
  declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
72
- [x: string]: import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport;
245
+ [x: string]: import("@trustify-da/trustify-da-api-model/model/v5/AnalysisReport").AnalysisReport;
73
246
  }>;
74
247
  /**
75
248
  * Validates the Exhort token.
@@ -77,4 +250,14 @@ declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefi
77
250
  * @returns {Promise<object>} A promise that resolves with the validation result from the backend.
78
251
  * @throws {Error} if the backend request failed.
79
252
  */
80
- declare function validateToken(opts?: Options | undefined): Promise<object>;
253
+ declare function validateToken(opts?: Options): Promise<object>;
254
+ import { discoverMavenModules } from './providers/java_maven.js';
255
+ import { discoverWorkspacePackages } from './workspace.js';
256
+ import { discoverWorkspaceCrates } from './workspace.js';
257
+ import { validatePackageJson } from './workspace.js';
258
+ import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
259
+ import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
260
+ import { resolveContinueOnError } from './batch_opts.js';
261
+ import { resolveBatchMetadata } from './batch_opts.js';
262
+ export { discoverMavenModules, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
263
+ export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";