@trustify-da/trustify-da-javascript-client 0.3.0-ea.b40d888 → 0.3.0-ea.b6d9c3f

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 (88) hide show
  1. package/README.md +193 -13
  2. package/dist/package.json +43 -27
  3. package/dist/src/analysis.d.ts +28 -5
  4. package/dist/src/analysis.js +99 -89
  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 +299 -9
  8. package/dist/src/cyclone_dx_sbom.d.ts +17 -3
  9. package/dist/src/cyclone_dx_sbom.js +56 -8
  10. package/dist/src/index.d.ts +201 -12
  11. package/dist/src/index.js +360 -9
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +103 -0
  14. package/dist/src/license/license_utils.d.ts +40 -0
  15. package/dist/src/license/license_utils.js +137 -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/images.js +15 -1
  22. package/dist/src/oci_image/utils.d.ts +7 -7
  23. package/dist/src/oci_image/utils.js +11 -2
  24. package/dist/src/provider.d.ts +18 -5
  25. package/dist/src/provider.js +33 -5
  26. package/dist/src/providers/base_java.d.ts +15 -15
  27. package/dist/src/providers/base_java.js +18 -44
  28. package/dist/src/providers/base_javascript.d.ts +45 -12
  29. package/dist/src/providers/base_javascript.js +138 -24
  30. package/dist/src/providers/base_pyproject.d.ts +158 -0
  31. package/dist/src/providers/base_pyproject.js +322 -0
  32. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  33. package/dist/src/providers/containerfile_parser.js +20 -0
  34. package/dist/src/providers/golang_gomodules.d.ts +30 -13
  35. package/dist/src/providers/golang_gomodules.js +176 -121
  36. package/dist/src/providers/gomod_parser.d.ts +4 -0
  37. package/dist/src/providers/gomod_parser.js +16 -0
  38. package/dist/src/providers/java_gradle.d.ts +28 -3
  39. package/dist/src/providers/java_gradle.js +128 -4
  40. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  41. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  42. package/dist/src/providers/java_maven.d.ts +20 -5
  43. package/dist/src/providers/java_maven.js +198 -6
  44. package/dist/src/providers/javascript_bun.d.ts +10 -0
  45. package/dist/src/providers/javascript_bun.js +100 -0
  46. package/dist/src/providers/javascript_npm.d.ts +6 -0
  47. package/dist/src/providers/javascript_npm.js +21 -0
  48. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  49. package/dist/src/providers/javascript_pnpm.js +8 -4
  50. package/dist/src/providers/manifest.d.ts +2 -0
  51. package/dist/src/providers/manifest.js +22 -4
  52. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  53. package/dist/src/providers/marker_evaluator.js +191 -0
  54. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  55. package/dist/src/providers/oci_dockerfile.js +177 -0
  56. package/dist/src/providers/processors/yarn_berry_processor.d.ts +2 -2
  57. package/dist/src/providers/processors/yarn_berry_processor.js +88 -5
  58. package/dist/src/providers/processors/yarn_classic_processor.d.ts +2 -2
  59. package/dist/src/providers/python_controller.d.ts +10 -3
  60. package/dist/src/providers/python_controller.js +122 -63
  61. package/dist/src/providers/python_pip.d.ts +16 -4
  62. package/dist/src/providers/python_pip.js +51 -58
  63. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  64. package/dist/src/providers/python_pip_pyproject.js +146 -0
  65. package/dist/src/providers/python_poetry.d.ts +98 -0
  66. package/dist/src/providers/python_poetry.js +286 -0
  67. package/dist/src/providers/python_uv.d.ts +46 -0
  68. package/dist/src/providers/python_uv.js +269 -0
  69. package/dist/src/providers/requirements_parser.d.ts +6 -0
  70. package/dist/src/providers/requirements_parser.js +24 -0
  71. package/dist/src/providers/rust_cargo.d.ts +56 -0
  72. package/dist/src/providers/rust_cargo.js +641 -0
  73. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  74. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  75. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  76. package/dist/src/remediation.d.ts +33 -0
  77. package/dist/src/remediation.js +321 -0
  78. package/dist/src/sbom.d.ts +17 -2
  79. package/dist/src/sbom.js +16 -4
  80. package/dist/src/tools.d.ts +48 -6
  81. package/dist/src/tools.js +114 -1
  82. package/dist/src/updaters/maven_updater.d.ts +26 -0
  83. package/dist/src/updaters/maven_updater.js +322 -0
  84. package/dist/src/updaters/toml_updater.d.ts +33 -0
  85. package/dist/src/updaters/toml_updater.js +244 -0
  86. package/dist/src/workspace.d.ts +70 -0
  87. package/dist/src/workspace.js +256 -0
  88. package/package.json +44 -28
@@ -12,18 +12,30 @@
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";
27
+ export { extractRemediations } from "./remediation.js";
18
28
  declare namespace _default {
19
29
  export { componentAnalysis };
20
30
  export { stackAnalysis };
31
+ export { stackAnalysisBatch };
21
32
  export { imageAnalysis };
22
33
  export { validateToken };
34
+ export { generateSbom };
23
35
  }
24
36
  export default _default;
25
37
  export type Options = {
26
- [key: string]: string | undefined;
38
+ TRUSTIFY_DA_CARGO_PATH?: string | undefined;
27
39
  TRUSTIFY_DA_DOCKER_PATH?: string | undefined;
28
40
  TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED?: string | undefined;
29
41
  TRUSTIFY_DA_GO_PATH?: string | undefined;
@@ -42,16 +54,53 @@ export type Options = {
42
54
  TRUSTIFY_DA_PYTHON_PATH?: string | undefined;
43
55
  TRUSTIFY_DA_PYTHON_VIRTUAL_ENV?: string | undefined;
44
56
  TRUSTIFY_DA_PYTHON3_PATH?: string | undefined;
45
- TRUSTIFY_DA_RECOMMENDATIONS_ENABLED?: string | undefined;
57
+ TRUSTIFY_DA_PROVIDERS?: string | undefined;
58
+ TRUSTIFY_DA_RECOMMEND?: string | undefined;
59
+ TRUSTIFY_DA_SOURCES?: string | undefined;
46
60
  TRUSTIFY_DA_SKOPEO_CONFIG_PATH?: string | undefined;
47
61
  TRUSTIFY_DA_SKOPEO_PATH?: string | undefined;
48
62
  TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined;
49
63
  TRUSTIFY_DA_SYFT_PATH?: string | undefined;
50
64
  TRUSTIFY_DA_YARN_PATH?: string | undefined;
65
+ TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
66
+ TRUSTIFY_DA_LICENSE_CHECK?: string | undefined;
51
67
  MATCH_MANIFEST_VERSIONS?: string | undefined;
52
- RHDA_SOURCE?: string | undefined;
53
- RHDA_TOKEN?: string | undefined;
54
- RHDA_TELEMETRY_ID?: string | undefined;
68
+ TRUSTIFY_DA_SOURCE?: string | undefined;
69
+ TRUSTIFY_DA_TOKEN?: string | undefined;
70
+ TRUSTIFY_DA_TELEMETRY_ID?: string | undefined;
71
+ TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined;
72
+ batchConcurrency?: number | undefined;
73
+ TRUSTIFY_DA_BATCH_CONCURRENCY?: string | undefined;
74
+ workspaceDiscoveryIgnore?: string[] | undefined;
75
+ TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string | undefined;
76
+ continueOnError?: boolean | undefined;
77
+ TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined;
78
+ batchMetadata?: boolean | undefined;
79
+ TRUSTIFY_DA_BATCH_METADATA?: string | undefined;
80
+ TRUSTIFY_DA_UV_PATH?: string | undefined;
81
+ TRUSTIFY_DA_POETRY_PATH?: string | undefined;
82
+ [key: string]: string | number | boolean | string[] | undefined;
83
+ };
84
+ export type BatchAnalysisMetadata = {
85
+ workspaceRoot: string;
86
+ ecosystem: "javascript" | "cargo" | "pyproject" | "unknown";
87
+ total: number;
88
+ successful: number;
89
+ failed: number;
90
+ errors: Array<{
91
+ manifestPath: string;
92
+ phase: "validation" | "sbom";
93
+ reason: string;
94
+ }>;
95
+ };
96
+ export type SbomResult = {
97
+ ok: true;
98
+ purl: string;
99
+ sbom: object;
100
+ } | {
101
+ ok: false;
102
+ manifestPath: string;
103
+ reason: string;
55
104
  };
56
105
  /**
57
106
  * Get component analysis report for a manifest content.
@@ -60,16 +109,143 @@ export type Options = {
60
109
  * @returns {Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
61
110
  * @throws {Error} if no matching provider, failed to get create content, or backend request failed
62
111
  */
63
- declare function componentAnalysis(manifest: string, opts?: Options | undefined): Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>;
112
+ declare function componentAnalysis(manifest: string, opts?: Options): Promise<any>;
113
+ /**
114
+ * @overload
115
+ * @param {string} manifest
116
+ * @param {true} html
117
+ * @param {Options} [opts={}]
118
+ * @returns {Promise<string>}
119
+ * @throws {Error}
120
+ */
64
121
  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>;
122
+ /**
123
+ * @overload
124
+ * @param {string} manifest
125
+ * @param {false} html
126
+ * @param {Options} [opts={}]
127
+ * @returns {Promise<import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
128
+ * @throws {Error}
129
+ */
130
+ declare function stackAnalysis(manifest: string, html: false, opts?: Options | undefined): Promise<any>;
131
+ /**
132
+ * Get stack analysis report for a manifest file.
133
+ * @overload
134
+ * @param {string} manifest - path for the manifest
135
+ * @param {boolean} [html=false] - true will return a html string, false will return AnalysisReport object.
136
+ * @param {Options} [opts={}] - optional various options to pass along the application
137
+ * @returns {Promise<string|import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>}
138
+ * @throws {Error} if manifest inaccessible, no matching provider, failed to get create content,
139
+ * or backend request failed
140
+ */
141
+ declare function stackAnalysis(manifest: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | any>;
142
+ /**
143
+ * @overload
144
+ * @param {string} workspaceRoot
145
+ * @param {true} html
146
+ * @param {Options & { batchMetadata: true }} opts
147
+ * @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
148
+ * @throws {Error}
149
+ */
150
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts: Options & {
151
+ batchMetadata: true;
152
+ }): Promise<{
153
+ analysis: string;
154
+ metadata: BatchAnalysisMetadata;
155
+ }>;
156
+ /**
157
+ * @overload
158
+ * @param {string} workspaceRoot
159
+ * @param {true} html
160
+ * @param {Options & { batchMetadata?: false }} [opts={}]
161
+ * @returns {Promise<string>}
162
+ * @throws {Error}
163
+ */
164
+ declare function stackAnalysisBatch(workspaceRoot: string, html: true, opts?: (Options & {
165
+ batchMetadata?: false;
166
+ }) | undefined): Promise<string>;
167
+ /**
168
+ * @overload
169
+ * @param {string} workspaceRoot
170
+ * @param {false} html
171
+ * @param {Options & { batchMetadata: true }} opts
172
+ * @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
173
+ * @throws {Error}
174
+ */
175
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts: Options & {
176
+ batchMetadata: true;
177
+ }): Promise<{
178
+ analysis: {
179
+ [x: string]: any;
180
+ };
181
+ metadata: BatchAnalysisMetadata;
182
+ }>;
183
+ /**
184
+ * @overload
185
+ * @param {string} workspaceRoot
186
+ * @param {false} html
187
+ * @param {Options & { batchMetadata?: false }} [opts={}]
188
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
189
+ * @throws {Error}
190
+ */
191
+ declare function stackAnalysisBatch(workspaceRoot: string, html: false, opts?: (Options & {
192
+ batchMetadata?: false;
193
+ }) | undefined): Promise<{
194
+ [x: string]: any;
195
+ }>;
196
+ /**
197
+ * Get stack analysis for all workspace packages/crates (batch).
198
+ * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
199
+ * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
200
+ * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
201
+ *
202
+ * @overload
203
+ * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
204
+ * @param {boolean} [html=false] - true returns HTML, false returns JSON report
205
+ * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
206
+ * @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 }>}
207
+ * @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.
208
+ */
209
+ declare function stackAnalysisBatch(workspaceRoot: string, html?: boolean | undefined, opts?: Options | undefined): Promise<string | {
210
+ [x: string]: any;
211
+ } | {
212
+ analysis: string | {
213
+ [x: string]: any;
214
+ };
215
+ metadata: BatchAnalysisMetadata;
216
+ }>;
217
+ /**
218
+ * @overload
219
+ * @param {Array<string>} imageRefs
220
+ * @param {true} html
221
+ * @param {Options} [opts={}]
222
+ * @returns {Promise<string>}
223
+ * @throws {Error}
224
+ */
67
225
  declare function imageAnalysis(imageRefs: Array<string>, html: true, opts?: Options | undefined): Promise<string>;
226
+ /**
227
+ * @overload
228
+ * @param {Array<string>} imageRefs
229
+ * @param {false} html
230
+ * @param {Options} [opts={}]
231
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
232
+ * @throws {Error}
233
+ */
68
234
  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;
235
+ [x: string]: any;
70
236
  }>;
237
+ /**
238
+ * Get image analysis report for a set of OCI image references.
239
+ * @overload
240
+ * @param {Array<string>} imageRefs - OCI image references
241
+ * @param {boolean} [html=false] - true will return a html string, false will return AnalysisReport
242
+ * @param {Options} [opts={}] - optional various options to pass along the application
243
+ * @returns {Promise<string|Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
244
+ * @throws {Error} if manifest inaccessible, no matching provider, failed to get create content,
245
+ * or backend request failed
246
+ */
71
247
  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;
248
+ [x: string]: any;
73
249
  }>;
74
250
  /**
75
251
  * Validates the Exhort token.
@@ -77,4 +253,17 @@ declare function imageAnalysis(imageRefs: Array<string>, html?: boolean | undefi
77
253
  * @returns {Promise<object>} A promise that resolves with the validation result from the backend.
78
254
  * @throws {Error} if the backend request failed.
79
255
  */
80
- declare function validateToken(opts?: Options | undefined): Promise<object>;
256
+ declare function validateToken(opts?: Options): Promise<object>;
257
+ import { discoverMavenModules } from './providers/java_maven.js';
258
+ import { discoverGradleSubprojects } from './providers/java_gradle.js';
259
+ import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
260
+ import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
261
+ import { discoverWorkspacePackages } from './workspace.js';
262
+ import { discoverWorkspaceCrates } from './workspace.js';
263
+ import { validatePackageJson } from './workspace.js';
264
+ import { resolveWorkspaceDiscoveryIgnore } from './workspace.js';
265
+ import { filterManifestPathsByDiscoveryIgnore } from './workspace.js';
266
+ import { resolveContinueOnError } from './batch_opts.js';
267
+ import { resolveBatchMetadata } from './batch_opts.js';
268
+ export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata };
269
+ export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
package/dist/src/index.js CHANGED
@@ -1,16 +1,27 @@
1
1
  import path from "node:path";
2
2
  import { EOL } from "os";
3
+ import pLimit from 'p-limit';
3
4
  import { availableProviders, match } from './provider.js';
4
5
  import analysis from './analysis.js';
5
6
  import fs from 'node:fs';
6
7
  import { getCustom } from "./tools.js";
8
+ import { resolveBatchMetadata, resolveContinueOnError } from './batch_opts.js';
9
+ import { discoverMavenModules } from './providers/java_maven.js';
10
+ import { discoverGradleSubprojects } from './providers/java_gradle.js';
11
+ import { discoverGoWorkspaceModules } from './providers/golang_gomodules.js';
12
+ import { discoverUvWorkspaceMembers } from './providers/python_uv.js';
13
+ import { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
7
14
  import.meta.dirname;
8
15
  import * as url from 'url';
9
16
  export { parseImageRef } from "./oci_image/utils.js";
10
17
  export { ImageRef } from "./oci_image/images.js";
11
- export default { componentAnalysis, stackAnalysis, imageAnalysis, validateToken };
18
+ export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
19
+ export { extractRemediations } from "./remediation.js";
20
+ export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
21
+ export { discoverMavenModules, discoverGradleSubprojects, discoverGoWorkspaceModules, discoverUvWorkspaceMembers, discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
12
22
  /**
13
23
  * @typedef {{
24
+ * TRUSTIFY_DA_CARGO_PATH?: string | undefined,
14
25
  * TRUSTIFY_DA_DOCKER_PATH?: string | undefined,
15
26
  * TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED?: string | undefined,
16
27
  * TRUSTIFY_DA_GO_PATH?: string | undefined,
@@ -29,19 +40,44 @@ export default { componentAnalysis, stackAnalysis, imageAnalysis, validateToken
29
40
  * TRUSTIFY_DA_PYTHON_PATH?: string | undefined,
30
41
  * TRUSTIFY_DA_PYTHON_VIRTUAL_ENV?: string | undefined,
31
42
  * TRUSTIFY_DA_PYTHON3_PATH?: string | undefined,
32
- * TRUSTIFY_DA_RECOMMENDATIONS_ENABLED?: string | undefined,
43
+ * TRUSTIFY_DA_PROVIDERS?: string | undefined,
44
+ * TRUSTIFY_DA_RECOMMEND?: string | undefined,
45
+ * TRUSTIFY_DA_SOURCES?: string | undefined,
33
46
  * TRUSTIFY_DA_SKOPEO_CONFIG_PATH?: string | undefined,
34
47
  * TRUSTIFY_DA_SKOPEO_PATH?: string | undefined,
35
48
  * TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined,
36
49
  * TRUSTIFY_DA_SYFT_PATH?: string | undefined,
37
50
  * TRUSTIFY_DA_YARN_PATH?: string | undefined,
51
+ * TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
52
+ * TRUSTIFY_DA_LICENSE_CHECK?: string | undefined,
38
53
  * MATCH_MANIFEST_VERSIONS?: string | undefined,
39
- * RHDA_SOURCE?: string | undefined,
40
- * RHDA_TOKEN?: string | undefined,
41
- * RHDA_TELEMETRY_ID?: string | undefined,
42
- * [key: string]: string | undefined,
54
+ * TRUSTIFY_DA_SOURCE?: string | undefined,
55
+ * TRUSTIFY_DA_TOKEN?: string | undefined,
56
+ * TRUSTIFY_DA_TELEMETRY_ID?: string | undefined,
57
+ * TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
58
+ * batchConcurrency?: number | undefined,
59
+ * TRUSTIFY_DA_BATCH_CONCURRENCY?: string | undefined,
60
+ * workspaceDiscoveryIgnore?: string[] | undefined,
61
+ * TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string | undefined,
62
+ * continueOnError?: boolean | undefined,
63
+ * TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined,
64
+ * batchMetadata?: boolean | undefined,
65
+ * TRUSTIFY_DA_BATCH_METADATA?: string | undefined,
66
+ * TRUSTIFY_DA_UV_PATH?: string | undefined,
67
+ * TRUSTIFY_DA_POETRY_PATH?: string | undefined,
68
+ * [key: string]: string | number | boolean | string[] | undefined,
43
69
  * }} Options
44
70
  */
71
+ /**
72
+ * @typedef {{
73
+ * workspaceRoot: string,
74
+ * ecosystem: 'javascript' | 'cargo' | 'pyproject' | 'unknown',
75
+ * total: number,
76
+ * successful: number,
77
+ * failed: number,
78
+ * errors: Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>
79
+ * }} BatchAnalysisMetadata
80
+ */
45
81
  /**
46
82
  * Logs messages to the console if the TRUSTIFY_DA_DEBUG environment variable is set to "true".
47
83
  * @param {string} alongsideText - The text to prepend to the log message.
@@ -127,7 +163,7 @@ export function selectTrustifyDABackend(opts = {}) {
127
163
  async function stackAnalysis(manifest, html = false, opts = {}) {
128
164
  const theUrl = selectTrustifyDABackend(opts);
129
165
  fs.accessSync(manifest, fs.constants.R_OK); // throws error if file unreadable
130
- let provider = match(manifest, availableProviders); // throws error if no matching provider
166
+ let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
131
167
  return await analysis.requestStack(provider, manifest, theUrl, html, opts); // throws error request sending failed
132
168
  }
133
169
  /**
@@ -141,8 +177,10 @@ async function componentAnalysis(manifest, opts = {}) {
141
177
  const theUrl = selectTrustifyDABackend(opts);
142
178
  fs.accessSync(manifest, fs.constants.R_OK);
143
179
  opts["manifest-type"] = path.basename(manifest);
144
- let provider = match(manifest, availableProviders); // throws error if no matching provider
145
- return await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
180
+ let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
181
+ const result = await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
182
+ result.packageManager = provider.packageManagerName();
183
+ return result;
146
184
  }
147
185
  /**
148
186
  * @overload
@@ -174,6 +212,319 @@ async function imageAnalysis(imageRefs, html = false, opts = {}) {
174
212
  const theUrl = selectTrustifyDABackend(opts);
175
213
  return await analysis.requestImages(imageRefs, theUrl, html, opts);
176
214
  }
215
+ /**
216
+ * Max concurrent SBOM generations for batch workspace analysis. Env/opts override default 10.
217
+ * @param {Options} opts
218
+ * @returns {number}
219
+ * @private
220
+ */
221
+ function resolveBatchConcurrency(opts) {
222
+ const fromEnv = getCustom('TRUSTIFY_DA_BATCH_CONCURRENCY', null, opts);
223
+ const raw = opts.batchConcurrency ?? fromEnv ?? '10';
224
+ const n = typeof raw === 'number' ? raw : parseInt(String(raw), 10);
225
+ if (!Number.isFinite(n) || n < 1) {
226
+ return 10;
227
+ }
228
+ return Math.min(256, n);
229
+ }
230
+ /**
231
+ * @param {string} root
232
+ * @param {'javascript' | 'cargo' | 'unknown'} ecosystem
233
+ * @param {number} totalSbomAttempts
234
+ * @param {number} successfulSbomCount
235
+ * @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} errors
236
+ * @returns {BatchAnalysisMetadata}
237
+ * @private
238
+ */
239
+ function buildBatchAnalysisMetadata(root, ecosystem, totalSbomAttempts, successfulSbomCount, errors) {
240
+ return {
241
+ workspaceRoot: root,
242
+ ecosystem,
243
+ total: totalSbomAttempts,
244
+ successful: successfulSbomCount,
245
+ failed: errors.length,
246
+ errors: [...errors],
247
+ };
248
+ }
249
+ /**
250
+ * Generate a CycloneDX SBOM from a manifest file. No backend HTTP request is made.
251
+ *
252
+ * @param {string} manifestPath - path to the manifest file (e.g. pom.xml, package.json)
253
+ * @param {Options} [opts={}] - optional options (e.g. workspace dir, tool paths)
254
+ * @returns {Promise<object>} parsed CycloneDX SBOM JSON object
255
+ * @throws {Error} if the manifest is unsupported or SBOM generation fails
256
+ */
257
+ export async function generateSbom(manifestPath, opts = {}) {
258
+ fs.accessSync(manifestPath, fs.constants.R_OK);
259
+ const result = await generateOneSbom(manifestPath, opts);
260
+ if (!result.ok) {
261
+ throw new Error(`Failed to generate SBOM for ${result.manifestPath}: ${result.reason}`);
262
+ }
263
+ return result.sbom;
264
+ }
265
+ /**
266
+ * @typedef {{ ok: true, purl: string, sbom: object } | { ok: false, manifestPath: string, reason: string }} SbomResult
267
+ */
268
+ /**
269
+ * Generate an SBOM for a single manifest, returning a normalized result.
270
+ *
271
+ * @param {string} manifestPath
272
+ * @param {Options} workspaceOpts - opts with `TRUSTIFY_DA_WORKSPACE_DIR` set
273
+ * @returns {Promise<SbomResult>}
274
+ * @private
275
+ */
276
+ async function generateOneSbom(manifestPath, workspaceOpts) {
277
+ const provider = match(manifestPath, availableProviders, workspaceOpts);
278
+ const provided = await provider.provideStack(manifestPath, workspaceOpts);
279
+ const sbom = JSON.parse(provided.content);
280
+ const purl = sbom?.metadata?.component?.purl || sbom?.metadata?.component?.['bom-ref'];
281
+ if (!purl) {
282
+ return { ok: false, manifestPath, reason: 'missing purl in SBOM' };
283
+ }
284
+ return { ok: true, purl, sbom };
285
+ }
286
+ /**
287
+ * Detect the workspace ecosystem and discover manifest paths.
288
+ *
289
+ * @param {string} root - Resolved workspace root
290
+ * @param {Options} opts
291
+ * @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'maven' | 'gradle' | 'gomodules' | 'pyproject' | 'unknown', manifestPaths: string[] }>}
292
+ * @private
293
+ */
294
+ async function detectWorkspaceManifests(root, opts) {
295
+ const cargoToml = path.join(root, 'Cargo.toml');
296
+ const cargoLock = path.join(root, 'Cargo.lock');
297
+ const packageJson = path.join(root, 'package.json');
298
+ const pomXml = path.join(root, 'pom.xml');
299
+ if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
300
+ return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
301
+ }
302
+ if (fs.existsSync(pomXml)) {
303
+ const manifestPaths = await discoverMavenModules(root, opts);
304
+ if (manifestPaths.length > 0) {
305
+ return { ecosystem: 'maven', manifestPaths };
306
+ }
307
+ }
308
+ const hasGradleSettings = fs.existsSync(path.join(root, 'settings.gradle'))
309
+ || fs.existsSync(path.join(root, 'settings.gradle.kts'));
310
+ if (hasGradleSettings) {
311
+ const manifestPaths = await discoverGradleSubprojects(root, opts);
312
+ if (manifestPaths.length > 0) {
313
+ return { ecosystem: 'gradle', manifestPaths };
314
+ }
315
+ }
316
+ if (fs.existsSync(path.join(root, 'go.work'))) {
317
+ const manifestPaths = await discoverGoWorkspaceModules(root, opts);
318
+ if (manifestPaths.length > 0) {
319
+ return { ecosystem: 'gomodules', manifestPaths };
320
+ }
321
+ }
322
+ if (fs.existsSync(path.join(root, 'pyproject.toml')) && fs.existsSync(path.join(root, 'uv.lock'))) {
323
+ const manifestPaths = await discoverUvWorkspaceMembers(root, opts);
324
+ if (manifestPaths.length > 0) {
325
+ return { ecosystem: 'pyproject', manifestPaths };
326
+ }
327
+ }
328
+ const hasJsLock = fs.existsSync(path.join(root, 'bun.lock'))
329
+ || fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
330
+ || fs.existsSync(path.join(root, 'yarn.lock'))
331
+ || fs.existsSync(path.join(root, 'package-lock.json'));
332
+ if (fs.existsSync(packageJson) && hasJsLock) {
333
+ let manifestPaths = await discoverWorkspacePackages(root, opts);
334
+ if (manifestPaths.length === 0) {
335
+ manifestPaths = [packageJson];
336
+ }
337
+ return { ecosystem: 'javascript', manifestPaths };
338
+ }
339
+ return { ecosystem: 'unknown', manifestPaths: [] };
340
+ }
341
+ /**
342
+ * Validate discovered JS package.json manifests, collecting errors.
343
+ *
344
+ * @param {string[]} manifestPaths
345
+ * @param {boolean} continueOnError
346
+ * @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} collectedErrors - mutated in place
347
+ * @returns {{ validPaths: string[] }}
348
+ * @throws {Error} on first invalid manifest when `continueOnError` is false
349
+ * @private
350
+ */
351
+ function validateJsManifests(manifestPaths, continueOnError, collectedErrors) {
352
+ const validPaths = [];
353
+ for (const p of manifestPaths) {
354
+ const v = validatePackageJson(p);
355
+ if (v.valid) {
356
+ validPaths.push(p);
357
+ }
358
+ else {
359
+ collectedErrors.push({ manifestPath: p, phase: 'validation', reason: v.error });
360
+ console.warn(`Skipping invalid package.json (${v.error}): ${p}`);
361
+ if (!continueOnError) {
362
+ throw new Error(`Invalid package.json (${v.error}): ${p}`);
363
+ }
364
+ }
365
+ }
366
+ return { validPaths };
367
+ }
368
+ /**
369
+ * Generate SBOMs for all manifests. In fail-fast mode, stops on first error.
370
+ * In continue-on-error mode, runs concurrently and collects failures.
371
+ *
372
+ * @param {string[]} manifestPaths
373
+ * @param {Options} workspaceOpts
374
+ * @param {boolean} continueOnError
375
+ * @param {number} concurrency
376
+ * @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} collectedErrors - mutated in place
377
+ * @returns {Promise<Object.<string, object>>} sbomByPurl map
378
+ * @throws {Error} on first SBOM failure when `continueOnError` is false
379
+ * @private
380
+ */
381
+ async function generateSboms(manifestPaths, workspaceOpts, continueOnError, concurrency, collectedErrors) {
382
+ /** @type {SbomResult[]} */
383
+ const results = [];
384
+ if (!continueOnError) {
385
+ for (const manifestPath of manifestPaths) {
386
+ const result = await generateOneSbom(manifestPath, workspaceOpts);
387
+ if (!result.ok) {
388
+ collectedErrors.push({ manifestPath: result.manifestPath, phase: 'sbom', reason: result.reason });
389
+ throw new Error(`${result.manifestPath}: ${result.reason}`);
390
+ }
391
+ results.push(result);
392
+ }
393
+ }
394
+ else {
395
+ const limit = pLimit(concurrency);
396
+ const settled = await Promise.all(manifestPaths.map(manifestPath => limit(async () => {
397
+ try {
398
+ return await generateOneSbom(manifestPath, workspaceOpts);
399
+ }
400
+ catch (err) {
401
+ const msg = err instanceof Error ? err.message : String(err);
402
+ if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
403
+ console.log(`Skipping ${manifestPath}: ${msg}`);
404
+ }
405
+ return { ok: false, manifestPath, reason: msg };
406
+ }
407
+ })));
408
+ for (const r of settled) {
409
+ results.push(r);
410
+ if (!r.ok) {
411
+ collectedErrors.push({ manifestPath: r.manifestPath, phase: 'sbom', reason: r.reason });
412
+ }
413
+ }
414
+ }
415
+ const sbomByPurl = {};
416
+ for (const r of results) {
417
+ if (r.ok) {
418
+ sbomByPurl[r.purl] = r.sbom;
419
+ }
420
+ }
421
+ return sbomByPurl;
422
+ }
423
+ /**
424
+ * Create an Error with optional `batchMetadata` attached.
425
+ * @param {string} message
426
+ * @param {boolean} wantMetadata
427
+ * @param {BatchAnalysisMetadata} [metadata]
428
+ * @returns {Error}
429
+ * @private
430
+ */
431
+ function batchError(message, wantMetadata, metadata) {
432
+ const err = new Error(message);
433
+ if (wantMetadata && metadata) {
434
+ err.batchMetadata = metadata;
435
+ }
436
+ return err;
437
+ }
438
+ /**
439
+ * @overload
440
+ * @param {string} workspaceRoot
441
+ * @param {true} html
442
+ * @param {Options & { batchMetadata: true }} opts
443
+ * @returns {Promise<{ analysis: string, metadata: BatchAnalysisMetadata }>}
444
+ * @throws {Error}
445
+ */
446
+ /**
447
+ * @overload
448
+ * @param {string} workspaceRoot
449
+ * @param {true} html
450
+ * @param {Options & { batchMetadata?: false }} [opts={}]
451
+ * @returns {Promise<string>}
452
+ * @throws {Error}
453
+ */
454
+ /**
455
+ * @overload
456
+ * @param {string} workspaceRoot
457
+ * @param {false} html
458
+ * @param {Options & { batchMetadata: true }} opts
459
+ * @returns {Promise<{ analysis: Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>, metadata: BatchAnalysisMetadata }>}
460
+ * @throws {Error}
461
+ */
462
+ /**
463
+ * @overload
464
+ * @param {string} workspaceRoot
465
+ * @param {false} html
466
+ * @param {Options & { batchMetadata?: false }} [opts={}]
467
+ * @returns {Promise<Object.<string, import('@trustify-da/trustify-da-api-model/model/v5/AnalysisReport').AnalysisReport>>}
468
+ * @throws {Error}
469
+ */
470
+ /**
471
+ * Get stack analysis for all workspace packages/crates (batch).
472
+ * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
473
+ * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
474
+ * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
475
+ *
476
+ * @overload
477
+ * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
478
+ * @param {boolean} [html=false] - true returns HTML, false returns JSON report
479
+ * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
480
+ * @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 }>}
481
+ * @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.
482
+ */
483
+ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
484
+ const theUrl = selectTrustifyDABackend(opts);
485
+ const root = path.resolve(workspaceRoot);
486
+ fs.accessSync(root, fs.constants.R_OK);
487
+ const continueOnError = resolveContinueOnError(opts);
488
+ const wantMetadata = resolveBatchMetadata(opts);
489
+ /** @type {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} */
490
+ const collectedErrors = [];
491
+ const { ecosystem, manifestPaths: discovered } = await detectWorkspaceManifests(root, opts);
492
+ let manifestPaths = discovered;
493
+ if (ecosystem === 'javascript') {
494
+ try {
495
+ const { validPaths } = validateJsManifests(manifestPaths, continueOnError, collectedErrors);
496
+ manifestPaths = validPaths;
497
+ }
498
+ catch (err) {
499
+ throw batchError(err.message, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, 0, 0, collectedErrors));
500
+ }
501
+ if (manifestPaths.length === 0 && discovered.length > 0) {
502
+ const detail = collectedErrors.map(e => `${e.manifestPath}: ${e.reason}`).join('; ');
503
+ throw batchError(`No valid packages after validation at ${root}. ${detail}`, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, 0, 0, collectedErrors));
504
+ }
505
+ }
506
+ if (manifestPaths.length === 0) {
507
+ 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).`);
508
+ }
509
+ const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
510
+ const concurrency = resolveBatchConcurrency(opts);
511
+ let sbomByPurl;
512
+ try {
513
+ sbomByPurl = await generateSboms(manifestPaths, workspaceOpts, continueOnError, concurrency, collectedErrors);
514
+ }
515
+ catch (err) {
516
+ throw batchError(err.message, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, 0, collectedErrors));
517
+ }
518
+ if (Object.keys(sbomByPurl).length === 0) {
519
+ throw batchError(`No valid SBOMs produced from ${manifestPaths.length} manifest(s) at ${root}`, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, 0, collectedErrors));
520
+ }
521
+ const analysisResult = await analysis.requestStackBatch(sbomByPurl, theUrl, html, opts);
522
+ const meta = buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, Object.keys(sbomByPurl).length, collectedErrors);
523
+ if (wantMetadata) {
524
+ return { analysis: analysisResult, metadata: meta };
525
+ }
526
+ return analysisResult;
527
+ }
177
528
  /**
178
529
  * Validates the Exhort token.
179
530
  * @param {Options} [opts={}] - Optional parameters, potentially including token override.