@trustify-da/trustify-da-javascript-client 0.3.0-ea.608d6fa → 0.3.0-ea.62b88e5

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 (94) hide show
  1. package/README.md +326 -21
  2. package/dist/package.json +36 -27
  3. package/dist/src/analysis.d.ts +58 -14
  4. package/dist/src/analysis.js +118 -17
  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 +357 -8
  8. package/dist/src/config.d.ts +120 -0
  9. package/dist/src/config.js +260 -0
  10. package/dist/src/cyclone_dx_sbom.d.ts +27 -1
  11. package/dist/src/cyclone_dx_sbom.js +84 -10
  12. package/dist/src/index.d.ts +151 -16
  13. package/dist/src/index.js +369 -36
  14. package/dist/src/license/index.d.ts +4 -4
  15. package/dist/src/license/index.js +13 -7
  16. package/dist/src/license/license_utils.js +4 -1
  17. package/dist/src/license/licenses_api.d.ts +3 -3
  18. package/dist/src/license/licenses_api.js +1 -1
  19. package/dist/src/oci_image/images.d.ts +1 -1
  20. package/dist/src/oci_image/images.js +15 -1
  21. package/dist/src/oci_image/utils.d.ts +5 -5
  22. package/dist/src/oci_image/utils.js +11 -2
  23. package/dist/src/package_version.d.ts +8 -0
  24. package/dist/src/package_version.js +31 -0
  25. package/dist/src/provider.d.ts +8 -4
  26. package/dist/src/provider.js +16 -5
  27. package/dist/src/providers/base_java.d.ts +67 -12
  28. package/dist/src/providers/base_java.js +82 -61
  29. package/dist/src/providers/base_javascript.d.ts +91 -10
  30. package/dist/src/providers/base_javascript.js +214 -24
  31. package/dist/src/providers/base_pyproject.d.ts +158 -0
  32. package/dist/src/providers/base_pyproject.js +322 -0
  33. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  34. package/dist/src/providers/containerfile_parser.js +20 -0
  35. package/dist/src/providers/golang_gomodules.d.ts +23 -13
  36. package/dist/src/providers/golang_gomodules.js +208 -120
  37. package/dist/src/providers/gomod_parser.d.ts +4 -0
  38. package/dist/src/providers/gomod_parser.js +16 -0
  39. package/dist/src/providers/java_gradle.d.ts +67 -0
  40. package/dist/src/providers/java_gradle.js +320 -22
  41. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  42. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  43. package/dist/src/providers/java_maven.d.ts +37 -9
  44. package/dist/src/providers/java_maven.js +269 -11
  45. package/dist/src/providers/javascript_bun.d.ts +22 -0
  46. package/dist/src/providers/javascript_bun.js +141 -0
  47. package/dist/src/providers/javascript_npm.d.ts +19 -0
  48. package/dist/src/providers/javascript_npm.js +61 -1
  49. package/dist/src/providers/javascript_pnpm.d.ts +14 -1
  50. package/dist/src/providers/javascript_pnpm.js +55 -5
  51. package/dist/src/providers/javascript_yarn.d.ts +12 -0
  52. package/dist/src/providers/javascript_yarn.js +75 -2
  53. package/dist/src/providers/manifest.d.ts +2 -0
  54. package/dist/src/providers/manifest.js +28 -7
  55. package/dist/src/providers/marker_evaluator.d.ts +14 -0
  56. package/dist/src/providers/marker_evaluator.js +191 -0
  57. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  58. package/dist/src/providers/oci_dockerfile.js +177 -0
  59. package/dist/src/providers/processors/yarn_berry_processor.d.ts +6 -2
  60. package/dist/src/providers/processors/yarn_berry_processor.js +91 -7
  61. package/dist/src/providers/processors/yarn_classic_processor.d.ts +6 -2
  62. package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
  63. package/dist/src/providers/python_controller.d.ts +5 -1
  64. package/dist/src/providers/python_controller.js +69 -8
  65. package/dist/src/providers/python_pip.d.ts +5 -0
  66. package/dist/src/providers/python_pip.js +6 -6
  67. package/dist/src/providers/python_pip_pyproject.d.ts +61 -0
  68. package/dist/src/providers/python_pip_pyproject.js +146 -0
  69. package/dist/src/providers/python_poetry.d.ts +98 -0
  70. package/dist/src/providers/python_poetry.js +286 -0
  71. package/dist/src/providers/python_uv.d.ts +46 -0
  72. package/dist/src/providers/python_uv.js +275 -0
  73. package/dist/src/providers/requirements_parser.js +1 -1
  74. package/dist/src/providers/rust_cargo.d.ts +12 -3
  75. package/dist/src/providers/rust_cargo.js +107 -31
  76. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  77. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  78. package/dist/src/remediate.d.ts +107 -0
  79. package/dist/src/remediate.js +244 -0
  80. package/dist/src/remediation.d.ts +81 -0
  81. package/dist/src/remediation.js +475 -0
  82. package/dist/src/remediation_report.d.ts +23 -0
  83. package/dist/src/remediation_report.js +180 -0
  84. package/dist/src/sbom.d.ts +25 -1
  85. package/dist/src/sbom.js +23 -2
  86. package/dist/src/tools.d.ts +37 -13
  87. package/dist/src/tools.js +92 -13
  88. package/dist/src/updaters/maven_updater.d.ts +58 -0
  89. package/dist/src/updaters/maven_updater.js +345 -0
  90. package/dist/src/updaters/toml_updater.d.ts +62 -0
  91. package/dist/src/updaters/toml_updater.js +276 -0
  92. package/dist/src/workspace.d.ts +71 -0
  93. package/dist/src/workspace.js +257 -0
  94. package/package.json +37 -28
package/dist/src/cli.js CHANGED
@@ -1,9 +1,47 @@
1
1
  #!/usr/bin/env node
2
+ import fs from 'node:fs';
2
3
  import * as path from "path";
3
4
  import yargs from 'yargs';
4
5
  import { hideBin } from 'yargs/helpers';
6
+ import { resolveConfig } from './config.js';
5
7
  import { getProjectLicense, getLicenseDetails } from './license/index.js';
6
- import client, { selectTrustifyDABackend } from './index.js';
8
+ import { runRemediation } from './remediate.js';
9
+ import { generateReport } from './remediation_report.js';
10
+ import client, { selectTrustifyDABackend, generateSbom } from './index.js';
11
+ /**
12
+ * Builds a yargs middleware that loads `.trustify-da.yml` (discovered by walking
13
+ * up from the command's target path, or cwd when no path is available) and fills `--providers`, `--sources`, and
14
+ * `--group-by` with config file values when they were not supplied on the CLI or
15
+ * via environment variables. Precedence: CLI flag > env var > config file > default.
16
+ * @param {string} [pathKey] - positional argument holding the target path; defaults to the current working directory
17
+ * @param {{ groupBy?: boolean }} [options={}] - set `groupBy` when the command exposes `--group-by`
18
+ * @returns {(args: object) => object} yargs middleware
19
+ */
20
+ function configMiddleware(pathKey, options = {}) {
21
+ return args => {
22
+ const startPath = pathKey === undefined ? process.cwd() : args[pathKey];
23
+ const envVars = options.groupBy
24
+ ? process.env
25
+ : Object.fromEntries(Object.entries(process.env).filter(([key]) => key !== 'TRUSTIFY_DA_GROUP_BY'));
26
+ const merged = resolveConfig(startPath, { backendUrl: args.backendUrl, providers: args.providers, sources: args.sources, groupBy: args['group-by'] }, envVars);
27
+ if (merged.backendUrlSource === 'file' && process.env.TRUSTIFY_DA_TOKEN) {
28
+ throw new Error('Refusing to send TRUSTIFY_DA_TOKEN to a backend selected by project configuration. Set --backend-url or TRUSTIFY_DA_BACKEND_URL to explicitly trust it.');
29
+ }
30
+ if (args.providers !== undefined || merged.providers.length) {
31
+ args.providers = merged.providers.join(',');
32
+ }
33
+ if (args.sources !== undefined || merged.sources.length) {
34
+ args.sources = merged.sources.join(',');
35
+ }
36
+ if (merged.backendUrl != null) {
37
+ args.backendUrl = merged.backendUrl;
38
+ }
39
+ if (options.groupBy) {
40
+ args['group-by'] = merged.groupBy;
41
+ }
42
+ return args;
43
+ };
44
+ }
7
45
  // command for component analysis take manifest type and content
8
46
  const component = {
9
47
  command: 'component </path/to/manifest>',
@@ -12,10 +50,39 @@ const component = {
12
50
  desc: 'manifest path for analyzing',
13
51
  type: 'string',
14
52
  normalize: true,
15
- }),
53
+ }).options({
54
+ workspaceDir: {
55
+ alias: 'w',
56
+ desc: 'Workspace root directory (for monorepos; lock file is expected here)',
57
+ type: 'string',
58
+ normalize: true,
59
+ },
60
+ backendUrl: {
61
+ desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
62
+ type: 'string',
63
+ },
64
+ providers: {
65
+ desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
66
+ type: 'string',
67
+ },
68
+ sources: {
69
+ desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
70
+ type: 'string',
71
+ }
72
+ }).middleware(configMiddleware('/path/to/manifest')),
16
73
  handler: async (args) => {
17
74
  let manifestName = args['/path/to/manifest'];
18
- let res = await client.componentAnalysis(manifestName);
75
+ const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
76
+ if (args.backendUrl !== undefined) {
77
+ opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
78
+ }
79
+ if (args.providers !== undefined) {
80
+ opts.TRUSTIFY_DA_PROVIDERS = args.providers;
81
+ }
82
+ if (args.sources !== undefined) {
83
+ opts.TRUSTIFY_DA_SOURCES = args.sources;
84
+ }
85
+ let res = await client.componentAnalysis(manifestName, opts);
19
86
  console.log(JSON.stringify(res, null, 2));
20
87
  }
21
88
  };
@@ -63,8 +130,20 @@ const image = {
63
130
  desc: 'For JSON report, get only the \'summary\'',
64
131
  type: 'boolean',
65
132
  conflicts: 'html'
133
+ },
134
+ backendUrl: {
135
+ desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
136
+ type: 'string',
137
+ },
138
+ providers: {
139
+ desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
140
+ type: 'string',
141
+ },
142
+ sources: {
143
+ desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
144
+ type: 'string',
66
145
  }
67
- }),
146
+ }).middleware(configMiddleware()),
68
147
  handler: async (args) => {
69
148
  let imageRefs = args['image-refs'];
70
149
  if (!Array.isArray(imageRefs)) {
@@ -72,7 +151,17 @@ const image = {
72
151
  }
73
152
  let html = args['html'];
74
153
  let summary = args['summary'];
75
- let res = await client.imageAnalysis(imageRefs, html);
154
+ const opts = {};
155
+ if (args.backendUrl !== undefined) {
156
+ opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
157
+ }
158
+ if (args.providers !== undefined) {
159
+ opts.TRUSTIFY_DA_PROVIDERS = args.providers;
160
+ }
161
+ if (args.sources !== undefined) {
162
+ opts.TRUSTIFY_DA_SOURCES = args.sources;
163
+ }
164
+ let res = await client.imageAnalysis(imageRefs, html, opts);
76
165
  if (summary && !html) {
77
166
  let summaries = {};
78
167
  for (let [imageRef, report] of Object.entries(res)) {
@@ -117,15 +206,43 @@ const stack = {
117
206
  desc: 'For JSON report, get only the \'summary\'',
118
207
  type: 'boolean',
119
208
  conflicts: 'html'
209
+ },
210
+ workspaceDir: {
211
+ alias: 'w',
212
+ desc: 'Workspace root directory (for monorepos; lock file is expected here)',
213
+ type: 'string',
214
+ normalize: true,
215
+ },
216
+ backendUrl: {
217
+ desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
218
+ type: 'string',
219
+ },
220
+ providers: {
221
+ desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
222
+ type: 'string',
223
+ },
224
+ sources: {
225
+ desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
226
+ type: 'string',
120
227
  }
121
- }),
228
+ }).middleware(configMiddleware('/path/to/manifest')),
122
229
  handler: async (args) => {
123
230
  let manifest = args['/path/to/manifest'];
124
231
  let html = args['html'];
125
232
  let summary = args['summary'];
233
+ const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
234
+ if (args.backendUrl !== undefined) {
235
+ opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
236
+ }
237
+ if (args.providers !== undefined) {
238
+ opts.TRUSTIFY_DA_PROVIDERS = args.providers;
239
+ }
240
+ if (args.sources !== undefined) {
241
+ opts.TRUSTIFY_DA_SOURCES = args.sources;
242
+ }
126
243
  let theProvidersSummary = new Map();
127
244
  let theProvidersObject = {};
128
- let res = await client.stackAnalysis(manifest, html);
245
+ let res = await client.stackAnalysis(manifest, html, opts);
129
246
  if (summary) {
130
247
  for (let provider in res.providers) {
131
248
  if (res.providers[provider].sources !== undefined) {
@@ -143,6 +260,129 @@ const stack = {
143
260
  console.log(html ? res : JSON.stringify(!html && summary ? theProvidersObject : res, null, 2));
144
261
  }
145
262
  };
263
+ // command for batch stack analysis (workspace)
264
+ const stackBatch = {
265
+ command: 'stack-batch </path/to/workspace-root> [--html|--summary] [--concurrency <n>] [--ignore <pattern>...] [--metadata] [--fail-fast]',
266
+ desc: 'produce stack report for all packages/crates in a workspace (Cargo or JS/TS)',
267
+ builder: yargs => yargs.positional('/path/to/workspace-root', {
268
+ desc: 'workspace root directory (containing Cargo.toml+Cargo.lock or package.json+lock file)',
269
+ type: 'string',
270
+ normalize: true,
271
+ }).options({
272
+ html: {
273
+ alias: 'r',
274
+ desc: 'Get the report as HTML instead of JSON',
275
+ type: 'boolean',
276
+ conflicts: 'summary'
277
+ },
278
+ summary: {
279
+ alias: 's',
280
+ desc: 'For JSON report, get only the \'summary\' per package',
281
+ type: 'boolean',
282
+ conflicts: 'html'
283
+ },
284
+ concurrency: {
285
+ alias: 'c',
286
+ desc: 'Max parallel SBOM generations (default: 10, env: TRUSTIFY_DA_BATCH_CONCURRENCY)',
287
+ type: 'number',
288
+ },
289
+ ignore: {
290
+ alias: 'i',
291
+ desc: 'Extra glob patterns excluded from workspace discovery (merged with defaults). Repeat flag per pattern. Env: TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE (comma-separated)',
292
+ type: 'string',
293
+ array: true,
294
+ },
295
+ metadata: {
296
+ alias: 'm',
297
+ desc: 'Return { analysis, metadata } with per-manifest errors (env: TRUSTIFY_DA_BATCH_METADATA=true)',
298
+ type: 'boolean',
299
+ default: false,
300
+ },
301
+ failFast: {
302
+ desc: 'Stop on first invalid package.json or SBOM error (env: TRUSTIFY_DA_CONTINUE_ON_ERROR=false)',
303
+ type: 'boolean',
304
+ default: false,
305
+ },
306
+ backendUrl: {
307
+ desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
308
+ type: 'string',
309
+ },
310
+ providers: {
311
+ desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
312
+ type: 'string',
313
+ },
314
+ sources: {
315
+ desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
316
+ type: 'string',
317
+ }
318
+ }).middleware(configMiddleware('/path/to/workspace-root')),
319
+ handler: async (args) => {
320
+ const workspaceRoot = args['/path/to/workspace-root'];
321
+ const html = args['html'];
322
+ const summary = args['summary'];
323
+ const opts = {};
324
+ if (args.backendUrl !== undefined) {
325
+ opts.TRUSTIFY_DA_BACKEND_URL = args.backendUrl;
326
+ }
327
+ if (args.concurrency != null) {
328
+ opts.batchConcurrency = args.concurrency;
329
+ }
330
+ const extraIgnores = Array.isArray(args.ignore) ? args.ignore.filter(p => p != null && String(p).trim()) : [];
331
+ if (extraIgnores.length > 0) {
332
+ opts.workspaceDiscoveryIgnore = extraIgnores;
333
+ }
334
+ if (args.metadata) {
335
+ opts.batchMetadata = true;
336
+ }
337
+ if (args.failFast) {
338
+ opts.continueOnError = false;
339
+ }
340
+ if (args.providers !== undefined) {
341
+ opts.TRUSTIFY_DA_PROVIDERS = args.providers;
342
+ }
343
+ if (args.sources !== undefined) {
344
+ opts.TRUSTIFY_DA_SOURCES = args.sources;
345
+ }
346
+ let res = await client.stackAnalysisBatch(workspaceRoot, html, opts);
347
+ const batchAnalysis = res && typeof res === 'object' && res != null && 'analysis' in res ? res.analysis : res;
348
+ if (summary && !html && typeof batchAnalysis === 'object') {
349
+ const summaries = {};
350
+ for (const [purl, report] of Object.entries(batchAnalysis)) {
351
+ if (report?.providers) {
352
+ for (const provider of Object.keys(report.providers)) {
353
+ const sources = report.providers[provider]?.sources;
354
+ if (sources) {
355
+ for (const [source, data] of Object.entries(sources)) {
356
+ if (data?.summary) {
357
+ if (!summaries[purl]) {
358
+ summaries[purl] = {};
359
+ }
360
+ if (!summaries[purl][provider]) {
361
+ summaries[purl][provider] = {};
362
+ }
363
+ summaries[purl][provider][source] = data.summary;
364
+ }
365
+ }
366
+ }
367
+ }
368
+ }
369
+ }
370
+ if (res && typeof res === 'object' && res != null && 'metadata' in res) {
371
+ res = { analysis: summaries, metadata: res.metadata };
372
+ }
373
+ else {
374
+ res = summaries;
375
+ }
376
+ }
377
+ if (html) {
378
+ const htmlContent = res && typeof res === 'object' && 'analysis' in res ? res.analysis : res;
379
+ console.log(htmlContent);
380
+ }
381
+ else {
382
+ console.log(JSON.stringify(res, null, 2));
383
+ }
384
+ }
385
+ };
146
386
  // command for license checking
147
387
  const license = {
148
388
  command: 'license </path/to/manifest>',
@@ -208,14 +448,123 @@ const license = {
208
448
  console.log(JSON.stringify(output, null, 2));
209
449
  }
210
450
  };
451
+ const sbom = {
452
+ command: 'sbom </path/to/manifest> [--output]',
453
+ desc: 'generate a CycloneDX SBOM from a manifest file',
454
+ builder: yargs => yargs.positional('/path/to/manifest', {
455
+ desc: 'manifest path for SBOM generation',
456
+ type: 'string',
457
+ normalize: true,
458
+ }).options({
459
+ output: {
460
+ alias: 'o',
461
+ desc: 'Write SBOM JSON to a file instead of stdout',
462
+ type: 'string',
463
+ normalize: true,
464
+ },
465
+ workspaceDir: {
466
+ alias: 'w',
467
+ desc: 'Workspace root directory (for monorepos; lock file is expected here)',
468
+ type: 'string',
469
+ normalize: true,
470
+ }
471
+ }),
472
+ handler: async (args) => {
473
+ let manifest = args['/path/to/manifest'];
474
+ const opts = args.workspaceDir ? { TRUSTIFY_DA_WORKSPACE_DIR: args.workspaceDir } : {};
475
+ let result;
476
+ try {
477
+ result = await generateSbom(manifest, opts);
478
+ }
479
+ catch (err) {
480
+ console.error(JSON.stringify({ error: `Failed to generate SBOM: ${err.message}` }, null, 2));
481
+ process.exit(1);
482
+ }
483
+ const json = JSON.stringify(result, null, 2);
484
+ if (args.output) {
485
+ try {
486
+ fs.writeFileSync(args.output, json);
487
+ }
488
+ catch (err) {
489
+ console.error(JSON.stringify({ error: `Failed to write output file: ${err.message}` }, null, 2));
490
+ process.exit(1);
491
+ }
492
+ }
493
+ else {
494
+ console.log(json);
495
+ }
496
+ }
497
+ };
498
+ const remediate = {
499
+ command: 'remediate <path>',
500
+ desc: 'Scan and apply vulnerability remediations to manifest files',
501
+ builder: yargs => yargs.positional('path', {
502
+ desc: 'Path to manifest file or directory',
503
+ type: 'string',
504
+ normalize: true,
505
+ }).options({
506
+ 'dry-run': {
507
+ alias: 'd',
508
+ type: 'boolean',
509
+ desc: 'Preview changes without modifying files',
510
+ },
511
+ providers: {
512
+ desc: 'Comma-separated list of vulnerability providers (env: TRUSTIFY_DA_PROVIDERS)',
513
+ type: 'string',
514
+ },
515
+ sources: {
516
+ desc: 'Comma-separated list of vulnerability sources (env: TRUSTIFY_DA_SOURCES)',
517
+ type: 'string',
518
+ },
519
+ 'group-by': {
520
+ type: 'string',
521
+ choices: ['dependency', 'bundle'],
522
+ desc: 'Report grouping strategy (default: dependency)',
523
+ },
524
+ backendUrl: {
525
+ desc: 'Trustify DA backend URL (env: TRUSTIFY_DA_BACKEND_URL)',
526
+ type: 'string',
527
+ },
528
+ }).middleware(configMiddleware('path', { groupBy: true })),
529
+ handler: async (args) => {
530
+ try {
531
+ const result = await runRemediation(args.path, {
532
+ dryRun: args['dry-run'],
533
+ providers: args.providers,
534
+ sources: args.sources,
535
+ backendUrl: args.backendUrl,
536
+ });
537
+ if (result.remediations.length === 0 && result.manifests.length === 0) {
538
+ console.log('No supported manifest files found.');
539
+ process.exit(result.exitCode);
540
+ }
541
+ if (!args['dry-run'] && result.appliedFiles.length > 0) {
542
+ console.log(`Updated ${result.appliedFiles.length} file(s):`);
543
+ for (const file of result.appliedFiles) {
544
+ console.log(` ${file}`);
545
+ }
546
+ console.log('');
547
+ }
548
+ console.log(generateReport(result.remediations, { groupBy: args['group-by'], dryRun: args['dry-run'] }));
549
+ process.exit(result.exitCode);
550
+ }
551
+ catch (err) {
552
+ console.error(err.message);
553
+ process.exit(1);
554
+ }
555
+ }
556
+ };
211
557
  // parse and invoke the command
212
558
  yargs(hideBin(process.argv))
213
- .usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|image|validate-token|license}`)
559
+ .usage(`Usage: ${process.argv[0].includes("node") ? path.parse(process.argv[1]).base : path.parse(process.argv[0]).base} {component|stack|stack-batch|image|validate-token|license|sbom|remediate}`)
214
560
  .command(stack)
561
+ .command(stackBatch)
215
562
  .command(component)
216
563
  .command(image)
217
564
  .command(validateToken)
218
565
  .command(license)
566
+ .command(sbom)
567
+ .command(remediate)
219
568
  .scriptName('')
220
569
  .version(false)
221
570
  .demandCommand(1)
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Discovers and parses `.trustify-da.yml` by walking up from `startPath`.
3
+ * A missing config file is not an error — an empty object is returned so callers
4
+ * can fall back to defaults.
5
+ * @param {string} [startPath] - manifest file or directory to start the search from
6
+ * @returns {FileConfig} the parsed config object, or `{}` when no file is found
7
+ * @throws {Error} when the config file exists but contains malformed YAML
8
+ */
9
+ export function loadConfig(startPath?: string): FileConfig;
10
+ /**
11
+ * Merges config sources with precedence: CLI flag > environment variable
12
+ * (`TRUSTIFY_DA_*`) > config file > hardcoded default. Providers and sources are
13
+ * normalized to arrays regardless of whether the source used a YAML array or a
14
+ * comma-separated string.
15
+ * @param {FileConfig} [fileConfig={}] - values parsed from `.trustify-da.yml`
16
+ * @param {{ providers?: string, sources?: string, groupBy?: string, backendUrl?: string }} [cliFlags={}]
17
+ * @param {{ [key: string]: string | undefined }} [envVars={}] - typically `process.env`
18
+ * @returns {ResolvedConfig} the resolved, typed config object
19
+ */
20
+ export function mergeConfig(fileConfig?: FileConfig, cliFlags?: {
21
+ providers?: string;
22
+ sources?: string;
23
+ groupBy?: string;
24
+ backendUrl?: string;
25
+ }, envVars?: {
26
+ [key: string]: string | undefined;
27
+ }): ResolvedConfig;
28
+ /**
29
+ * Loads and merges the project configuration for a target path.
30
+ * @param {string} [startPath] - manifest file or directory to start discovery from
31
+ * @param {{ providers?: string, sources?: string, groupBy?: string, backendUrl?: string }} [cliFlags={}] - explicit options
32
+ * @param {{ [key: string]: string | undefined }} [envVars={}] - typically `process.env`
33
+ * @returns {ResolvedConfig} the resolved, typed config object
34
+ */
35
+ export function resolveConfig(startPath?: string, cliFlags?: {
36
+ providers?: string;
37
+ sources?: string;
38
+ groupBy?: string;
39
+ backendUrl?: string;
40
+ }, envVars?: {
41
+ [key: string]: string | undefined;
42
+ }): ResolvedConfig;
43
+ /**
44
+ * @typedef {{
45
+ * 'group-by'?: 'dependency' | 'bundle',
46
+ * exclude?: string[],
47
+ * labels?: string[],
48
+ * 'branch-prefix'?: string,
49
+ * [key: string]: unknown
50
+ * }} RemediationConfig
51
+ */
52
+ /** @typedef {{ critical?: number, high?: number, 'license-conflicts'?: number, [key: string]: unknown }} FailOnConfig */
53
+ /** @typedef {{ 'fail-on'?: FailOnConfig, [key: string]: unknown }} CheckConfig */
54
+ /** @typedef {{ format?: string, targets?: string[], [key: string]: unknown }} SbomConfig */
55
+ /**
56
+ * @typedef {{
57
+ * 'backend-url'?: string,
58
+ * providers?: string[] | string,
59
+ * sources?: string[] | string,
60
+ * remediation?: RemediationConfig,
61
+ * check?: CheckConfig,
62
+ * sbom?: SbomConfig,
63
+ * [key: string]: unknown
64
+ * }} FileConfig
65
+ */
66
+ /**
67
+ * @typedef {{
68
+ * backendUrl: string | null,
69
+ * backendUrlSource: 'cli' | 'environment' | 'file' | 'default',
70
+ * providers: string[],
71
+ * sources: string[],
72
+ * groupBy: string,
73
+ * remediation: object,
74
+ * check: object,
75
+ * sbom: object
76
+ * }} ResolvedConfig
77
+ */
78
+ /** Config file names discovered by walking up the directory tree, in precedence order. */
79
+ export const CONFIG_FILENAMES: string[];
80
+ export type RemediationConfig = {
81
+ "group-by"?: "dependency" | "bundle";
82
+ exclude?: string[];
83
+ labels?: string[];
84
+ "branch-prefix"?: string;
85
+ [key: string]: unknown;
86
+ };
87
+ export type FailOnConfig = {
88
+ critical?: number;
89
+ high?: number;
90
+ "license-conflicts"?: number;
91
+ [key: string]: unknown;
92
+ };
93
+ export type CheckConfig = {
94
+ "fail-on"?: FailOnConfig;
95
+ [key: string]: unknown;
96
+ };
97
+ export type SbomConfig = {
98
+ format?: string;
99
+ targets?: string[];
100
+ [key: string]: unknown;
101
+ };
102
+ export type FileConfig = {
103
+ "backend-url"?: string;
104
+ providers?: string[] | string;
105
+ sources?: string[] | string;
106
+ remediation?: RemediationConfig;
107
+ check?: CheckConfig;
108
+ sbom?: SbomConfig;
109
+ [key: string]: unknown;
110
+ };
111
+ export type ResolvedConfig = {
112
+ backendUrl: string | null;
113
+ backendUrlSource: "cli" | "environment" | "file" | "default";
114
+ providers: string[];
115
+ sources: string[];
116
+ groupBy: string;
117
+ remediation: object;
118
+ check: object;
119
+ sbom: object;
120
+ };