@trustify-da/trustify-da-javascript-client 0.3.0-ea.cb4ae28 → 0.3.0-ea.cdf078c

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 (40) hide show
  1. package/README.md +151 -13
  2. package/dist/package.json +10 -4
  3. package/dist/src/analysis.d.ts +16 -0
  4. package/dist/src/analysis.js +53 -4
  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 +171 -4
  8. package/dist/src/cyclone_dx_sbom.d.ts +7 -0
  9. package/dist/src/cyclone_dx_sbom.js +16 -1
  10. package/dist/src/index.d.ts +74 -1
  11. package/dist/src/index.js +283 -4
  12. package/dist/src/oci_image/utils.js +11 -2
  13. package/dist/src/provider.d.ts +6 -3
  14. package/dist/src/provider.js +12 -5
  15. package/dist/src/providers/base_javascript.d.ts +19 -3
  16. package/dist/src/providers/base_javascript.js +99 -18
  17. package/dist/src/providers/base_pyproject.d.ts +170 -0
  18. package/dist/src/providers/base_pyproject.js +338 -0
  19. package/dist/src/providers/golang_gomodules.d.ts +12 -12
  20. package/dist/src/providers/golang_gomodules.js +100 -111
  21. package/dist/src/providers/gomod_parser.d.ts +4 -0
  22. package/dist/src/providers/gomod_parser.js +16 -0
  23. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  24. package/dist/src/providers/javascript_pnpm.js +2 -2
  25. package/dist/src/providers/manifest.d.ts +2 -0
  26. package/dist/src/providers/manifest.js +22 -4
  27. package/dist/src/providers/processors/yarn_berry_processor.js +82 -3
  28. package/dist/src/providers/python_pip.js +1 -1
  29. package/dist/src/providers/python_poetry.d.ts +42 -0
  30. package/dist/src/providers/python_poetry.js +169 -0
  31. package/dist/src/providers/python_uv.d.ts +27 -0
  32. package/dist/src/providers/python_uv.js +146 -0
  33. package/dist/src/providers/rust_cargo.d.ts +52 -0
  34. package/dist/src/providers/rust_cargo.js +614 -0
  35. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  36. package/dist/src/sbom.d.ts +7 -0
  37. package/dist/src/sbom.js +9 -0
  38. package/dist/src/workspace.d.ts +61 -0
  39. package/dist/src/workspace.js +256 -0
  40. package/package.json +11 -5
package/dist/src/index.js CHANGED
@@ -1,17 +1,22 @@
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 { discoverWorkspaceCrates, discoverWorkspacePackages, filterManifestPathsByDiscoveryIgnore, resolveWorkspaceDiscoveryIgnore, validatePackageJson, } from './workspace.js';
7
10
  import.meta.dirname;
8
11
  import * as url from 'url';
9
12
  export { parseImageRef } from "./oci_image/utils.js";
10
13
  export { ImageRef } from "./oci_image/images.js";
11
14
  export { getProjectLicense, findLicenseFilePath, identifyLicense, getLicenseDetails, licensesFromReport, normalizeLicensesResponse, runLicenseCheck, getCompatibility } from "./license/index.js";
12
- export default { componentAnalysis, stackAnalysis, imageAnalysis, validateToken };
15
+ export default { componentAnalysis, stackAnalysis, stackAnalysisBatch, imageAnalysis, validateToken, generateSbom };
16
+ export { discoverWorkspacePackages, discoverWorkspaceCrates, validatePackageJson, resolveWorkspaceDiscoveryIgnore, filterManifestPathsByDiscoveryIgnore, resolveContinueOnError, resolveBatchMetadata, };
13
17
  /**
14
18
  * @typedef {{
19
+ * TRUSTIFY_DA_CARGO_PATH?: string | undefined,
15
20
  * TRUSTIFY_DA_DOCKER_PATH?: string | undefined,
16
21
  * TRUSTIFY_DA_GO_MVS_LOGIC_ENABLED?: string | undefined,
17
22
  * TRUSTIFY_DA_GO_PATH?: string | undefined,
@@ -36,14 +41,36 @@ export default { componentAnalysis, stackAnalysis, imageAnalysis, validateToken
36
41
  * TRUSTIFY_DA_SYFT_CONFIG_PATH?: string | undefined,
37
42
  * TRUSTIFY_DA_SYFT_PATH?: string | undefined,
38
43
  * TRUSTIFY_DA_YARN_PATH?: string | undefined,
44
+ * TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
39
45
  * TRUSTIFY_DA_LICENSE_CHECK?: string | undefined,
40
46
  * MATCH_MANIFEST_VERSIONS?: string | undefined,
41
47
  * TRUSTIFY_DA_SOURCE?: string | undefined,
42
48
  * TRUSTIFY_DA_TOKEN?: string | undefined,
43
49
  * TRUSTIFY_DA_TELEMETRY_ID?: string | undefined,
44
- * [key: string]: string | undefined,
50
+ * TRUSTIFY_DA_WORKSPACE_DIR?: string | undefined,
51
+ * batchConcurrency?: number | undefined,
52
+ * TRUSTIFY_DA_BATCH_CONCURRENCY?: string | undefined,
53
+ * workspaceDiscoveryIgnore?: string[] | undefined,
54
+ * TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string | undefined,
55
+ * continueOnError?: boolean | undefined,
56
+ * TRUSTIFY_DA_CONTINUE_ON_ERROR?: string | undefined,
57
+ * batchMetadata?: boolean | undefined,
58
+ * TRUSTIFY_DA_BATCH_METADATA?: string | undefined,
59
+ * TRUSTIFY_DA_UV_PATH?: string | undefined,
60
+ * TRUSTIFY_DA_POETRY_PATH?: string | undefined,
61
+ * [key: string]: string | number | boolean | string[] | undefined,
45
62
  * }} Options
46
63
  */
64
+ /**
65
+ * @typedef {{
66
+ * workspaceRoot: string,
67
+ * ecosystem: 'javascript' | 'cargo' | 'unknown',
68
+ * total: number,
69
+ * successful: number,
70
+ * failed: number,
71
+ * errors: Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>
72
+ * }} BatchAnalysisMetadata
73
+ */
47
74
  /**
48
75
  * Logs messages to the console if the TRUSTIFY_DA_DEBUG environment variable is set to "true".
49
76
  * @param {string} alongsideText - The text to prepend to the log message.
@@ -129,7 +156,7 @@ export function selectTrustifyDABackend(opts = {}) {
129
156
  async function stackAnalysis(manifest, html = false, opts = {}) {
130
157
  const theUrl = selectTrustifyDABackend(opts);
131
158
  fs.accessSync(manifest, fs.constants.R_OK); // throws error if file unreadable
132
- let provider = match(manifest, availableProviders); // throws error if no matching provider
159
+ let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
133
160
  return await analysis.requestStack(provider, manifest, theUrl, html, opts); // throws error request sending failed
134
161
  }
135
162
  /**
@@ -143,7 +170,7 @@ async function componentAnalysis(manifest, opts = {}) {
143
170
  const theUrl = selectTrustifyDABackend(opts);
144
171
  fs.accessSync(manifest, fs.constants.R_OK);
145
172
  opts["manifest-type"] = path.basename(manifest);
146
- let provider = match(manifest, availableProviders); // throws error if no matching provider
173
+ let provider = match(manifest, availableProviders, opts); // throws error if no matching provider
147
174
  return await analysis.requestComponent(provider, manifest, theUrl, opts); // throws error request sending failed
148
175
  }
149
176
  /**
@@ -176,6 +203,258 @@ async function imageAnalysis(imageRefs, html = false, opts = {}) {
176
203
  const theUrl = selectTrustifyDABackend(opts);
177
204
  return await analysis.requestImages(imageRefs, theUrl, html, opts);
178
205
  }
206
+ /**
207
+ * Max concurrent SBOM generations for batch workspace analysis. Env/opts override default 10.
208
+ * @param {Options} opts
209
+ * @returns {number}
210
+ * @private
211
+ */
212
+ function resolveBatchConcurrency(opts) {
213
+ const fromEnv = getCustom('TRUSTIFY_DA_BATCH_CONCURRENCY', null, opts);
214
+ const raw = opts.batchConcurrency ?? fromEnv ?? '10';
215
+ const n = typeof raw === 'number' ? raw : parseInt(String(raw), 10);
216
+ if (!Number.isFinite(n) || n < 1) {
217
+ return 10;
218
+ }
219
+ return Math.min(256, n);
220
+ }
221
+ /**
222
+ * @param {string} root
223
+ * @param {'javascript' | 'cargo' | 'unknown'} ecosystem
224
+ * @param {number} totalSbomAttempts
225
+ * @param {number} successfulSbomCount
226
+ * @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} errors
227
+ * @returns {BatchAnalysisMetadata}
228
+ * @private
229
+ */
230
+ function buildBatchAnalysisMetadata(root, ecosystem, totalSbomAttempts, successfulSbomCount, errors) {
231
+ return {
232
+ workspaceRoot: root,
233
+ ecosystem,
234
+ total: totalSbomAttempts,
235
+ successful: successfulSbomCount,
236
+ failed: errors.length,
237
+ errors: [...errors],
238
+ };
239
+ }
240
+ /**
241
+ * Generate a CycloneDX SBOM from a manifest file. No backend HTTP request is made.
242
+ *
243
+ * @param {string} manifestPath - path to the manifest file (e.g. pom.xml, package.json)
244
+ * @param {Options} [opts={}] - optional options (e.g. workspace dir, tool paths)
245
+ * @returns {Promise<object>} parsed CycloneDX SBOM JSON object
246
+ * @throws {Error} if the manifest is unsupported or SBOM generation fails
247
+ */
248
+ export async function generateSbom(manifestPath, opts = {}) {
249
+ fs.accessSync(manifestPath, fs.constants.R_OK);
250
+ const result = await generateOneSbom(manifestPath, opts);
251
+ if (!result.ok) {
252
+ throw new Error(`Failed to generate SBOM for ${result.manifestPath}: ${result.reason}`);
253
+ }
254
+ return result.sbom;
255
+ }
256
+ /**
257
+ * @typedef {{ ok: true, purl: string, sbom: object } | { ok: false, manifestPath: string, reason: string }} SbomResult
258
+ */
259
+ /**
260
+ * Generate an SBOM for a single manifest, returning a normalized result.
261
+ *
262
+ * @param {string} manifestPath
263
+ * @param {Options} workspaceOpts - opts with `TRUSTIFY_DA_WORKSPACE_DIR` set
264
+ * @returns {Promise<SbomResult>}
265
+ * @private
266
+ */
267
+ async function generateOneSbom(manifestPath, workspaceOpts) {
268
+ const provider = match(manifestPath, availableProviders, workspaceOpts);
269
+ const provided = await provider.provideStack(manifestPath, workspaceOpts);
270
+ const sbom = JSON.parse(provided.content);
271
+ const purl = sbom?.metadata?.component?.purl || sbom?.metadata?.component?.['bom-ref'];
272
+ if (!purl) {
273
+ return { ok: false, manifestPath, reason: 'missing purl in SBOM' };
274
+ }
275
+ return { ok: true, purl, sbom };
276
+ }
277
+ /**
278
+ * Detect the workspace ecosystem and discover manifest paths.
279
+ *
280
+ * @param {string} root - Resolved workspace root
281
+ * @param {Options} opts
282
+ * @returns {Promise<{ ecosystem: 'javascript' | 'cargo' | 'unknown', manifestPaths: string[] }>}
283
+ * @private
284
+ */
285
+ async function detectWorkspaceManifests(root, opts) {
286
+ const cargoToml = path.join(root, 'Cargo.toml');
287
+ const cargoLock = path.join(root, 'Cargo.lock');
288
+ const packageJson = path.join(root, 'package.json');
289
+ if (fs.existsSync(cargoToml) && fs.existsSync(cargoLock)) {
290
+ return { ecosystem: 'cargo', manifestPaths: await discoverWorkspaceCrates(root, opts) };
291
+ }
292
+ const hasJsLock = fs.existsSync(path.join(root, 'pnpm-lock.yaml'))
293
+ || fs.existsSync(path.join(root, 'yarn.lock'))
294
+ || fs.existsSync(path.join(root, 'package-lock.json'));
295
+ if (fs.existsSync(packageJson) && hasJsLock) {
296
+ let manifestPaths = await discoverWorkspacePackages(root, opts);
297
+ if (manifestPaths.length === 0) {
298
+ manifestPaths = [packageJson];
299
+ }
300
+ return { ecosystem: 'javascript', manifestPaths };
301
+ }
302
+ return { ecosystem: 'unknown', manifestPaths: [] };
303
+ }
304
+ /**
305
+ * Validate discovered JS package.json manifests, collecting errors.
306
+ *
307
+ * @param {string[]} manifestPaths
308
+ * @param {boolean} continueOnError
309
+ * @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} collectedErrors - mutated in place
310
+ * @returns {{ validPaths: string[] }}
311
+ * @throws {Error} on first invalid manifest when `continueOnError` is false
312
+ * @private
313
+ */
314
+ function validateJsManifests(manifestPaths, continueOnError, collectedErrors) {
315
+ const validPaths = [];
316
+ for (const p of manifestPaths) {
317
+ const v = validatePackageJson(p);
318
+ if (v.valid) {
319
+ validPaths.push(p);
320
+ }
321
+ else {
322
+ collectedErrors.push({ manifestPath: p, phase: 'validation', reason: v.error });
323
+ console.warn(`Skipping invalid package.json (${v.error}): ${p}`);
324
+ if (!continueOnError) {
325
+ throw new Error(`Invalid package.json (${v.error}): ${p}`);
326
+ }
327
+ }
328
+ }
329
+ return { validPaths };
330
+ }
331
+ /**
332
+ * Generate SBOMs for all manifests. In fail-fast mode, stops on first error.
333
+ * In continue-on-error mode, runs concurrently and collects failures.
334
+ *
335
+ * @param {string[]} manifestPaths
336
+ * @param {Options} workspaceOpts
337
+ * @param {boolean} continueOnError
338
+ * @param {number} concurrency
339
+ * @param {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} collectedErrors - mutated in place
340
+ * @returns {Promise<Object.<string, object>>} sbomByPurl map
341
+ * @throws {Error} on first SBOM failure when `continueOnError` is false
342
+ * @private
343
+ */
344
+ async function generateSboms(manifestPaths, workspaceOpts, continueOnError, concurrency, collectedErrors) {
345
+ /** @type {SbomResult[]} */
346
+ const results = [];
347
+ if (!continueOnError) {
348
+ for (const manifestPath of manifestPaths) {
349
+ const result = await generateOneSbom(manifestPath, workspaceOpts);
350
+ if (!result.ok) {
351
+ collectedErrors.push({ manifestPath: result.manifestPath, phase: 'sbom', reason: result.reason });
352
+ throw new Error(`${result.manifestPath}: ${result.reason}`);
353
+ }
354
+ results.push(result);
355
+ }
356
+ }
357
+ else {
358
+ const limit = pLimit(concurrency);
359
+ const settled = await Promise.all(manifestPaths.map(manifestPath => limit(async () => {
360
+ try {
361
+ return await generateOneSbom(manifestPath, workspaceOpts);
362
+ }
363
+ catch (err) {
364
+ const msg = err instanceof Error ? err.message : String(err);
365
+ if (process.env["TRUSTIFY_DA_DEBUG"] === "true") {
366
+ console.log(`Skipping ${manifestPath}: ${msg}`);
367
+ }
368
+ return { ok: false, manifestPath, reason: msg };
369
+ }
370
+ })));
371
+ for (const r of settled) {
372
+ results.push(r);
373
+ if (!r.ok) {
374
+ collectedErrors.push({ manifestPath: r.manifestPath, phase: 'sbom', reason: r.reason });
375
+ }
376
+ }
377
+ }
378
+ const sbomByPurl = {};
379
+ for (const r of results) {
380
+ if (r.ok) {
381
+ sbomByPurl[r.purl] = r.sbom;
382
+ }
383
+ }
384
+ return sbomByPurl;
385
+ }
386
+ /**
387
+ * Create an Error with optional `batchMetadata` attached.
388
+ * @param {string} message
389
+ * @param {boolean} wantMetadata
390
+ * @param {BatchAnalysisMetadata} [metadata]
391
+ * @returns {Error}
392
+ * @private
393
+ */
394
+ function batchError(message, wantMetadata, metadata) {
395
+ const err = new Error(message);
396
+ if (wantMetadata && metadata) {
397
+ err.batchMetadata = metadata;
398
+ }
399
+ return err;
400
+ }
401
+ /**
402
+ * Get stack analysis for all workspace packages/crates (batch).
403
+ * Detects ecosystem from workspace root: Cargo (Cargo.toml + Cargo.lock) or JS/TS (package.json + lock file).
404
+ * SBOMs are generated in parallel (see `batchConcurrency`) unless `continueOnError: false` (fail-fast sequential).
405
+ * With `opts.batchMetadata` / `TRUSTIFY_DA_BATCH_METADATA`, returns `{ analysis, metadata }` including validation and SBOM errors.
406
+ *
407
+ * @param {string} workspaceRoot - Path to workspace root (containing lock file and workspace config)
408
+ * @param {boolean} [html=false] - true returns HTML, false returns JSON report
409
+ * @param {Options} [opts={}] - `batchConcurrency`, discovery ignores, `continueOnError` (default true), `batchMetadata` (default false)
410
+ * @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 }>}
411
+ * @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.
412
+ */
413
+ async function stackAnalysisBatch(workspaceRoot, html = false, opts = {}) {
414
+ const theUrl = selectTrustifyDABackend(opts);
415
+ const root = path.resolve(workspaceRoot);
416
+ fs.accessSync(root, fs.constants.R_OK);
417
+ const continueOnError = resolveContinueOnError(opts);
418
+ const wantMetadata = resolveBatchMetadata(opts);
419
+ /** @type {Array<{ manifestPath: string, phase: 'validation' | 'sbom', reason: string }>} */
420
+ const collectedErrors = [];
421
+ const { ecosystem, manifestPaths: discovered } = await detectWorkspaceManifests(root, opts);
422
+ let manifestPaths = discovered;
423
+ if (ecosystem === 'javascript') {
424
+ try {
425
+ const { validPaths } = validateJsManifests(manifestPaths, continueOnError, collectedErrors);
426
+ manifestPaths = validPaths;
427
+ }
428
+ catch (err) {
429
+ throw batchError(err.message, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, 0, 0, collectedErrors));
430
+ }
431
+ if (manifestPaths.length === 0 && discovered.length > 0) {
432
+ const detail = collectedErrors.map(e => `${e.manifestPath}: ${e.reason}`).join('; ');
433
+ throw batchError(`No valid packages after validation at ${root}. ${detail}`, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, 0, 0, collectedErrors));
434
+ }
435
+ }
436
+ if (manifestPaths.length === 0) {
437
+ throw new Error(`No workspace manifests found at ${root}. Ensure Cargo.toml+Cargo.lock or package.json+lock file exist.`);
438
+ }
439
+ const workspaceOpts = { ...opts, TRUSTIFY_DA_WORKSPACE_DIR: root };
440
+ const concurrency = resolveBatchConcurrency(opts);
441
+ let sbomByPurl;
442
+ try {
443
+ sbomByPurl = await generateSboms(manifestPaths, workspaceOpts, continueOnError, concurrency, collectedErrors);
444
+ }
445
+ catch (err) {
446
+ throw batchError(err.message, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, 0, collectedErrors));
447
+ }
448
+ if (Object.keys(sbomByPurl).length === 0) {
449
+ throw batchError(`No valid SBOMs produced from ${manifestPaths.length} manifest(s) at ${root}`, wantMetadata, buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, 0, collectedErrors));
450
+ }
451
+ const analysisResult = await analysis.requestStackBatch(sbomByPurl, theUrl, html, opts);
452
+ const meta = buildBatchAnalysisMetadata(root, ecosystem, manifestPaths.length, Object.keys(sbomByPurl).length, collectedErrors);
453
+ if (wantMetadata) {
454
+ return { analysis: analysisResult, metadata: meta };
455
+ }
456
+ return analysisResult;
457
+ }
179
458
  /**
180
459
  * Validates the Exhort token.
181
460
  * @param {Options} [opts={}] - Optional parameters, potentially including token override.
@@ -135,7 +135,7 @@ function execSyft(imageRef, opts = {}) {
135
135
  function getSyftEnvs(dockerPath, podmanPath) {
136
136
  let path = null;
137
137
  if (dockerPath && podmanPath) {
138
- path = `${dockerPath}${File.pathSeparator}${podmanPath}`;
138
+ path = `${dockerPath}${delimiter}${podmanPath}`;
139
139
  }
140
140
  else if (dockerPath) {
141
141
  path = dockerPath;
@@ -276,7 +276,16 @@ function podmanGetVariant(opts = {}) {
276
276
  * @returns {string} - The information
277
277
  */
278
278
  function dockerPodmanInfo(dockerSupplier, podmanSupplier, opts = {}) {
279
- return dockerSupplier(opts) || podmanSupplier(opts);
279
+ try {
280
+ const result = dockerSupplier(opts);
281
+ if (result) {
282
+ return result;
283
+ }
284
+ }
285
+ catch (_) {
286
+ // docker not available, fall through to podman
287
+ }
288
+ return podmanSupplier(opts);
280
289
  }
281
290
  /**
282
291
  * Gets the digests for an image
@@ -13,12 +13,15 @@ export function matchForLicense(manifestPath: string, providers: [Provider]): Pr
13
13
  * Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
14
14
  * @param {string} manifest - the name-type or path of the manifest
15
15
  * @param {[Provider]} providers - list of providers to iterate over
16
+ * @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
16
17
  * @returns {Provider}
17
18
  * @throws {Error} when the manifest is not supported and no provider was matched
18
19
  */
19
- export function match(manifest: string, providers: [Provider]): Provider;
20
+ export function match(manifest: string, providers: [Provider], opts?: {
21
+ TRUSTIFY_DA_WORKSPACE_DIR?: string;
22
+ }): Provider;
20
23
  /** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
21
- /** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
24
+ /** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
22
25
  /**
23
26
  * MUST include all providers here.
24
27
  * @type {[Provider]}
@@ -31,7 +34,7 @@ export type Provided = {
31
34
  };
32
35
  export type Provider = {
33
36
  isSupported: (arg0: string) => boolean;
34
- validateLockFile: (arg0: string) => void;
37
+ validateLockFile: (arg0: string, arg1: any) => void;
35
38
  provideComponent: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
36
39
  provideStack: (arg0: string, arg1: {}) => Provided | Promise<Provided>;
37
40
  readLicenseFromManifest: (arg0: string) => string | null;
@@ -7,8 +7,11 @@ import Javascript_npm from './providers/javascript_npm.js';
7
7
  import Javascript_pnpm from './providers/javascript_pnpm.js';
8
8
  import Javascript_yarn from './providers/javascript_yarn.js';
9
9
  import pythonPipProvider from './providers/python_pip.js';
10
+ import Python_poetry from './providers/python_poetry.js';
11
+ import Python_uv from './providers/python_uv.js';
12
+ import rustCargoProvider from './providers/rust_cargo.js';
10
13
  /** @typedef {{ecosystem: string, contentType: string, content: string}} Provided */
11
- /** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
14
+ /** @typedef {{isSupported: function(string): boolean, validateLockFile: function(string, Object): void, provideComponent: function(string, {}): Provided | Promise<Provided>, provideStack: function(string, {}): Provided | Promise<Provided>, readLicenseFromManifest: function(string): string | null}} Provider */
12
15
  /**
13
16
  * MUST include all providers here.
14
17
  * @type {[Provider]}
@@ -17,11 +20,14 @@ export const availableProviders = [
17
20
  new Java_maven(),
18
21
  new Java_gradle_groovy(),
19
22
  new Java_gradle_kotlin(),
20
- new Javascript_npm(),
21
23
  new Javascript_pnpm(),
22
24
  new Javascript_yarn(),
25
+ new Javascript_npm(),
23
26
  golangGomodulesProvider,
24
- pythonPipProvider
27
+ pythonPipProvider,
28
+ new Python_poetry(),
29
+ new Python_uv(),
30
+ rustCargoProvider
25
31
  ];
26
32
  /**
27
33
  * Match a provider by manifest type only (no lock file check). Used for license reading.
@@ -45,16 +51,17 @@ export function matchForLicense(manifestPath, providers) {
45
51
  * Each provider MUST export 'provideStack' taking manifest path returning a {@link Provided}.
46
52
  * @param {string} manifest - the name-type or path of the manifest
47
53
  * @param {[Provider]} providers - list of providers to iterate over
54
+ * @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional; TRUSTIFY_DA_WORKSPACE_DIR overrides lock file location for workspaces
48
55
  * @returns {Provider}
49
56
  * @throws {Error} when the manifest is not supported and no provider was matched
50
57
  */
51
- export function match(manifest, providers) {
58
+ export function match(manifest, providers, opts = {}) {
52
59
  const manifestPath = path.parse(manifest);
53
60
  const supported = providers.filter(prov => prov.isSupported(manifestPath.base));
54
61
  if (supported.length === 0) {
55
62
  throw new Error(`${manifestPath.base} is not supported`);
56
63
  }
57
- const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir));
64
+ const provider = supported.find(prov => prov.validateLockFile(manifestPath.dir, opts));
58
65
  if (!provider) {
59
66
  throw new Error(`${manifestPath.base} requires a lock file. Use your preferred package manager to generate the lock file.`);
60
67
  }
@@ -67,11 +67,26 @@ export default class Base_javascript {
67
67
  */
68
68
  isSupported(manifestName: string): boolean;
69
69
  /**
70
- * Checks if a required lock file exists in the same path as the manifest
70
+ * Walks up the directory tree from manifestDir looking for the lock file.
71
+ * Stops when the lock file is found, when a package.json with a "workspaces"
72
+ * field is encountered without a lock file (workspace root boundary), or
73
+ * when the filesystem root is reached.
74
+ *
75
+ * When TRUSTIFY_DA_WORKSPACE_DIR is set, checks only that directory (no walk-up).
76
+ *
77
+ * @param {string} manifestDir - The directory to start searching from
78
+ * @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
79
+ * @returns {string|null} The directory containing the lock file, or null
80
+ * @protected
81
+ */
82
+ protected _isWorkspaceRoot(dir: any): string | null;
83
+ _findLockFileDir(manifestDir: any, opts?: {}): string | null;
84
+ /**
71
85
  * @param {string} manifestDir - The base directory where the manifest is located
86
+ * @param {Object} [opts={}] - optional; may contain TRUSTIFY_DA_WORKSPACE_DIR
72
87
  * @returns {boolean} True if the lock file exists
73
88
  */
74
- validateLockFile(manifestDir: string): boolean;
89
+ validateLockFile(manifestDir: string, opts?: any): boolean;
75
90
  /**
76
91
  * Provides content and content type for stack analysis
77
92
  * @param {string} manifestPath - The manifest path or name
@@ -95,10 +110,11 @@ export default class Base_javascript {
95
110
  /**
96
111
  * Builds the dependency tree for the project
97
112
  * @param {boolean} includeTransitive - Whether to include transitive dependencies
113
+ * @param {Object} [opts={}] - Configuration options; when `TRUSTIFY_DA_WORKSPACE_DIR` is set, commands run from workspace root
98
114
  * @returns {Object} The dependency tree
99
115
  * @protected
100
116
  */
101
- protected _buildDependencyTree(includeTransitive: boolean): any;
117
+ protected _buildDependencyTree(includeTransitive: boolean, opts?: any): any;
102
118
  /**
103
119
  * Recursively builds the Sbom from the JSON that npm listing returns
104
120
  * @param {Sbom} sbom - The SBOM object to add dependencies to