@trustify-da/trustify-da-javascript-client 0.3.0-ea.daa4d82 → 0.3.0-ea.dcb2120

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 (65) hide show
  1. package/README.md +191 -11
  2. package/dist/package.json +23 -10
  3. package/dist/src/analysis.d.ts +21 -5
  4. package/dist/src/analysis.js +74 -80
  5. package/dist/src/batch_opts.d.ts +24 -0
  6. package/dist/src/batch_opts.js +35 -0
  7. package/dist/src/cli.js +241 -8
  8. package/dist/src/cyclone_dx_sbom.d.ts +10 -2
  9. package/dist/src/cyclone_dx_sbom.js +32 -5
  10. package/dist/src/index.d.ts +138 -11
  11. package/dist/src/index.js +288 -7
  12. package/dist/src/license/index.d.ts +28 -0
  13. package/dist/src/license/index.js +100 -0
  14. package/dist/src/license/license_utils.d.ts +40 -0
  15. package/dist/src/license/license_utils.js +134 -0
  16. package/dist/src/license/licenses_api.d.ts +34 -0
  17. package/dist/src/license/licenses_api.js +98 -0
  18. package/dist/src/license/project_license.d.ts +20 -0
  19. package/dist/src/license/project_license.js +62 -0
  20. package/dist/src/oci_image/images.d.ts +4 -5
  21. package/dist/src/oci_image/utils.d.ts +4 -4
  22. package/dist/src/oci_image/utils.js +11 -2
  23. package/dist/src/provider.d.ts +17 -5
  24. package/dist/src/provider.js +27 -5
  25. package/dist/src/providers/base_java.d.ts +3 -5
  26. package/dist/src/providers/base_javascript.d.ts +29 -7
  27. package/dist/src/providers/base_javascript.js +129 -22
  28. package/dist/src/providers/base_pyproject.d.ts +168 -0
  29. package/dist/src/providers/base_pyproject.js +336 -0
  30. package/dist/src/providers/golang_gomodules.d.ts +20 -13
  31. package/dist/src/providers/golang_gomodules.js +112 -114
  32. package/dist/src/providers/gomod_parser.d.ts +4 -0
  33. package/dist/src/providers/gomod_parser.js +16 -0
  34. package/dist/src/providers/java_gradle.d.ts +9 -3
  35. package/dist/src/providers/java_gradle.js +12 -2
  36. package/dist/src/providers/java_gradle_groovy.d.ts +1 -1
  37. package/dist/src/providers/java_gradle_kotlin.d.ts +1 -1
  38. package/dist/src/providers/java_maven.d.ts +12 -5
  39. package/dist/src/providers/java_maven.js +33 -5
  40. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  41. package/dist/src/providers/javascript_pnpm.js +2 -2
  42. package/dist/src/providers/manifest.d.ts +2 -0
  43. package/dist/src/providers/manifest.js +22 -4
  44. package/dist/src/providers/processors/yarn_berry_processor.js +82 -3
  45. package/dist/src/providers/python_controller.d.ts +5 -2
  46. package/dist/src/providers/python_controller.js +56 -58
  47. package/dist/src/providers/python_pip.d.ts +11 -4
  48. package/dist/src/providers/python_pip.js +47 -54
  49. package/dist/src/providers/python_poetry.d.ts +42 -0
  50. package/dist/src/providers/python_poetry.js +169 -0
  51. package/dist/src/providers/python_uv.d.ts +27 -0
  52. package/dist/src/providers/python_uv.js +146 -0
  53. package/dist/src/providers/requirements_parser.d.ts +6 -0
  54. package/dist/src/providers/requirements_parser.js +24 -0
  55. package/dist/src/providers/rust_cargo.d.ts +52 -0
  56. package/dist/src/providers/rust_cargo.js +614 -0
  57. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  58. package/dist/src/providers/tree-sitter-requirements.wasm +0 -0
  59. package/dist/src/sbom.d.ts +10 -1
  60. package/dist/src/sbom.js +12 -2
  61. package/dist/src/tools.d.ts +22 -6
  62. package/dist/src/tools.js +56 -1
  63. package/dist/src/workspace.d.ts +61 -0
  64. package/dist/src/workspace.js +256 -0
  65. package/package.json +24 -11
@@ -0,0 +1,169 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { environmentVariableIsPopulated, getCustom, getCustomPath, invokeCommand } from '../tools.js';
4
+ import Base_pyproject from './base_pyproject.js';
5
+ export default class Python_poetry extends Base_pyproject {
6
+ /**
7
+ * Poetry has no native workspace/monorepo support (python-poetry/poetry#2270).
8
+ * Each poetry project is treated independently — no lock file walk-up.
9
+ * Running `poetry show` from a parent directory returns the parent's deps, not
10
+ * the sub-package's, so walk-up would produce incorrect SBOMs.
11
+ * @param {string} manifestDir
12
+ * @param {Object} [opts={}]
13
+ * @returns {string|null}
14
+ * @protected
15
+ */
16
+ _findLockFileDir(manifestDir, opts = {}) {
17
+ const workspaceDir = getCustom('TRUSTIFY_DA_WORKSPACE_DIR', null, opts);
18
+ if (workspaceDir) {
19
+ const dir = path.resolve(workspaceDir);
20
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
21
+ }
22
+ const dir = path.resolve(manifestDir);
23
+ return fs.existsSync(path.join(dir, this._lockFileName())) ? dir : null;
24
+ }
25
+ /** @returns {string} */
26
+ _lockFileName() {
27
+ return 'poetry.lock';
28
+ }
29
+ /** @returns {string} */
30
+ _cmdName() {
31
+ return 'poetry';
32
+ }
33
+ /**
34
+ * @param {string} manifestDir
35
+ * @param {string} _workspaceDir - unused (poetry has no workspace support)
36
+ * @param {object} parsed - parsed pyproject.toml
37
+ * @param {Object} opts
38
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
39
+ */
40
+ // eslint-disable-next-line no-unused-vars
41
+ async _getDependencyData(manifestDir, _workspaceDir, parsed, opts) {
42
+ let treeOutput = this._getPoetryShowTreeOutput(manifestDir, opts);
43
+ let showAllOutput = this._getPoetryShowAllOutput(manifestDir, opts);
44
+ let versionMap = this._parsePoetryShowAll(showAllOutput);
45
+ return this._parsePoetryTree(treeOutput, versionMap);
46
+ }
47
+ /**
48
+ * Get poetry show --tree output.
49
+ * @param {string} manifestDir
50
+ * @param {Object} opts
51
+ * @returns {string}
52
+ */
53
+ _getPoetryShowTreeOutput(manifestDir, opts) {
54
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
55
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
56
+ }
57
+ let poetryBin = getCustomPath('poetry', opts);
58
+ return invokeCommand(poetryBin, ['show', '--tree', '--no-ansi'], { cwd: manifestDir }).toString();
59
+ }
60
+ /**
61
+ * Get poetry show --all output (flat list with resolved versions).
62
+ * @param {string} manifestDir
63
+ * @param {Object} opts
64
+ * @returns {string}
65
+ */
66
+ _getPoetryShowAllOutput(manifestDir, opts) {
67
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL')) {
68
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_ALL'], 'base64').toString('utf-8');
69
+ }
70
+ let poetryBin = getCustomPath('poetry', opts);
71
+ return invokeCommand(poetryBin, ['show', '--no-ansi', '--all'], { cwd: manifestDir }).toString();
72
+ }
73
+ /**
74
+ * Parse poetry show --all output into a version map.
75
+ * Lines look like: "name (!) 1.2.3 Description text..."
76
+ * or: "name 1.2.3 Description text..."
77
+ * @param {string} output
78
+ * @returns {Map<string, string>} canonical name -> version
79
+ */
80
+ _parsePoetryShowAll(output) {
81
+ let versions = new Map();
82
+ let lines = output.split(/\r?\n/);
83
+ for (let line of lines) {
84
+ let trimmed = line.trim();
85
+ if (!trimmed) {
86
+ continue;
87
+ }
88
+ let match = trimmed.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(?:\(!\)\s+)?(\S+)/);
89
+ if (match) {
90
+ versions.set(this._canonicalize(match[1]), match[2]);
91
+ }
92
+ }
93
+ return versions;
94
+ }
95
+ /**
96
+ * Parse poetry show --tree output into a dependency graph structure.
97
+ * Top-level lines (no indentation/tree chars) are direct deps: "name version description"
98
+ * Indented lines are transitive deps with tree chars: "├── name >=constraint"
99
+ *
100
+ * @param {string} treeOutput
101
+ * @param {Map<string, string>} versionMap - canonical name -> resolved version
102
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
103
+ */
104
+ _parsePoetryTree(treeOutput, versionMap) {
105
+ let lines = treeOutput.split(/\r?\n/);
106
+ let graph = new Map();
107
+ let directDeps = [];
108
+ let stack = []; // [{key, depth}]
109
+ let currentDirectDep = null;
110
+ for (let line of lines) {
111
+ if (!line.trim()) {
112
+ continue;
113
+ }
114
+ // top-level line: "name version description..."
115
+ let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)(?:\s|$)/);
116
+ if (topMatch) {
117
+ let name = topMatch[1];
118
+ let version = topMatch[2];
119
+ let key = this._canonicalize(name);
120
+ directDeps.push(key);
121
+ if (!graph.has(key)) {
122
+ graph.set(key, { name, version, children: [] });
123
+ }
124
+ currentDirectDep = key;
125
+ stack = [{ key, depth: -1 }];
126
+ continue;
127
+ }
128
+ if (!currentDirectDep) {
129
+ continue;
130
+ }
131
+ // indented line with tree chars (UTF-8 box-drawing: ├── └── │)
132
+ let nameStart = line.search(/[A-Za-z0-9]/);
133
+ if (nameStart < 0) {
134
+ continue;
135
+ }
136
+ let rest = line.substring(nameStart);
137
+ let depMatch = rest.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)/);
138
+ if (!depMatch) {
139
+ continue;
140
+ }
141
+ let depName = depMatch[1];
142
+ let depKey = this._canonicalize(depName);
143
+ // determine depth by counting tree-drawing groups in the prefix
144
+ let prefix = line.substring(0, nameStart);
145
+ let depth = (prefix.match(/(?:[├└│ ][\s─]{2} ?)/g) || []).length;
146
+ // resolve version from the version map
147
+ let version = versionMap.get(depKey) || null;
148
+ if (!version) {
149
+ throw new Error(`poetry: package '${depName}' has no resolved version`);
150
+ }
151
+ if (!graph.has(depKey)) {
152
+ graph.set(depKey, { name: depName, version, children: [] });
153
+ }
154
+ // pop stack back to find the parent at depth-1
155
+ while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
156
+ stack.pop();
157
+ }
158
+ if (stack.length > 0) {
159
+ let parentKey = stack[stack.length - 1].key;
160
+ let parentEntry = graph.get(parentKey);
161
+ if (parentEntry && !parentEntry.children.includes(depKey)) {
162
+ parentEntry.children.push(depKey);
163
+ }
164
+ }
165
+ stack.push({ key: depKey, depth });
166
+ }
167
+ return { directDeps, graph };
168
+ }
169
+ }
@@ -0,0 +1,27 @@
1
+ export default class Python_uv extends Base_pyproject {
2
+ /**
3
+ * Get the uv export output, either from env var or by running the command.
4
+ * @param {string} manifestDir
5
+ * @param {Object} opts
6
+ * @returns {string}
7
+ */
8
+ _getUvExportOutput(manifestDir: string, opts: any): string;
9
+ /**
10
+ * Parse uv export output into a dependency graph using tree-sitter-requirements
11
+ * for package/version extraction and string parsing for "# via" comments.
12
+ *
13
+ * @param {string} output
14
+ * @param {string} projectName - canonical project name to identify direct deps
15
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
16
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
17
+ */
18
+ _parseUvExport(output: string, projectName: string, workspaceDir: string): Promise<{
19
+ directDeps: string[];
20
+ graph: Map<string, {
21
+ name: string;
22
+ version: string;
23
+ children: string[];
24
+ }>;
25
+ }>;
26
+ }
27
+ import Base_pyproject from './base_pyproject.js';
@@ -0,0 +1,146 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parse as parseToml } from 'smol-toml';
4
+ import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
5
+ import Base_pyproject from './base_pyproject.js';
6
+ import { getParser, getPinnedVersionQuery } from './requirements_parser.js';
7
+ export default class Python_uv extends Base_pyproject {
8
+ /** @returns {string} */
9
+ _lockFileName() {
10
+ return 'uv.lock';
11
+ }
12
+ /** @returns {string} */
13
+ _cmdName() {
14
+ return 'uv';
15
+ }
16
+ /**
17
+ * @param {string} manifestDir - directory containing the target pyproject.toml
18
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
19
+ * @param {object} parsed - parsed pyproject.toml
20
+ * @param {Object} opts
21
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
22
+ */
23
+ async _getDependencyData(manifestDir, workspaceDir, parsed, opts) {
24
+ let projectName = this._getProjectName(parsed);
25
+ let uvOutput = this._getUvExportOutput(manifestDir, opts);
26
+ return this._parseUvExport(uvOutput, projectName, workspaceDir);
27
+ }
28
+ /**
29
+ * Get the uv export output, either from env var or by running the command.
30
+ * @param {string} manifestDir
31
+ * @param {Object} opts
32
+ * @returns {string}
33
+ */
34
+ _getUvExportOutput(manifestDir, opts) {
35
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_UV_EXPORT')) {
36
+ return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
37
+ }
38
+ let uvBin = getCustomPath('uv', opts);
39
+ return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes'], { cwd: manifestDir }).toString();
40
+ }
41
+ /**
42
+ * Parse uv export output into a dependency graph using tree-sitter-requirements
43
+ * for package/version extraction and string parsing for "# via" comments.
44
+ *
45
+ * @param {string} output
46
+ * @param {string} projectName - canonical project name to identify direct deps
47
+ * @param {string} workspaceDir - workspace root (for resolving editable install paths)
48
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
49
+ */
50
+ async _parseUvExport(output, projectName, workspaceDir) {
51
+ let [parser, pinnedVersionQuery] = await Promise.all([
52
+ getParser(), getPinnedVersionQuery()
53
+ ]);
54
+ let tree = parser.parse(output);
55
+ let root = tree.rootNode;
56
+ let canonProjectName = this._canonicalize(projectName);
57
+ let packages = new Map(); // canonical name -> {name, version, parents: Set}
58
+ let currentPkg = null;
59
+ let collectingVia = false;
60
+ for (let child of root.children) {
61
+ if (child.type === 'global_opt') {
62
+ let optNode = child.children.find(c => c.type === 'option');
63
+ let pathNode = child.children.find(c => c.type === 'path');
64
+ if (optNode?.text === '-e' && pathNode && workspaceDir) {
65
+ let memberDir = path.resolve(workspaceDir, pathNode.text);
66
+ let memberManifest = path.join(memberDir, 'pyproject.toml');
67
+ if (fs.existsSync(memberManifest)) {
68
+ let memberParsed = parseToml(fs.readFileSync(memberManifest, 'utf-8'));
69
+ let name = memberParsed.project?.name || memberParsed.tool?.poetry?.name;
70
+ let version = memberParsed.project?.version || memberParsed.tool?.poetry?.version;
71
+ if (name && version) {
72
+ let key = this._canonicalize(name);
73
+ currentPkg = { name, version, parents: new Set() };
74
+ packages.set(key, currentPkg);
75
+ collectingVia = false;
76
+ continue;
77
+ }
78
+ }
79
+ }
80
+ currentPkg = null;
81
+ collectingVia = false;
82
+ continue;
83
+ }
84
+ if (child.type === 'requirement') {
85
+ let nameNode = child.children.find(c => c.type === 'package');
86
+ if (!nameNode) {
87
+ continue;
88
+ }
89
+ let name = nameNode.text;
90
+ let version = null;
91
+ let versionMatches = pinnedVersionQuery.matches(child);
92
+ if (versionMatches.length > 0) {
93
+ version = versionMatches[0].captures.find(c => c.name === 'version').node.text;
94
+ }
95
+ if (!version) {
96
+ throw new Error(`uv export: package '${name}' has no pinned version`);
97
+ }
98
+ let key = this._canonicalize(name);
99
+ currentPkg = { name, version, parents: new Set() };
100
+ packages.set(key, currentPkg);
101
+ collectingVia = false;
102
+ continue;
103
+ }
104
+ if (child.type === 'comment' && currentPkg) {
105
+ let text = child.text.trim();
106
+ let viaSingle = text.match(/^# via ([A-Za-z0-9][A-Za-z0-9._-]*)$/);
107
+ if (viaSingle) {
108
+ currentPkg.parents.add(this._canonicalize(viaSingle[1]));
109
+ collectingVia = false;
110
+ continue;
111
+ }
112
+ if (text === '# via') {
113
+ collectingVia = true;
114
+ continue;
115
+ }
116
+ if (collectingVia) {
117
+ let parentMatch = text.match(/^#\s+([A-Za-z0-9][A-Za-z0-9._-]*)$/);
118
+ if (parentMatch) {
119
+ currentPkg.parents.add(this._canonicalize(parentMatch[1]));
120
+ continue;
121
+ }
122
+ collectingVia = false;
123
+ }
124
+ }
125
+ }
126
+ // Build forward dependency map and extract direct deps in one pass
127
+ let graph = new Map();
128
+ let directDeps = [];
129
+ for (let [key, pkg] of packages) {
130
+ graph.set(key, { name: pkg.name, version: pkg.version, children: [] });
131
+ }
132
+ for (let [childKey, pkg] of packages) {
133
+ for (let parentKey of pkg.parents) {
134
+ if (parentKey === canonProjectName) {
135
+ directDeps.push(childKey);
136
+ continue;
137
+ }
138
+ let parentEntry = graph.get(parentKey);
139
+ if (parentEntry) {
140
+ parentEntry.children.push(childKey);
141
+ }
142
+ }
143
+ }
144
+ return { directDeps, graph };
145
+ }
146
+ }
@@ -0,0 +1,6 @@
1
+ export function getParser(): Promise<Parser>;
2
+ export function getRequirementQuery(): Promise<Query>;
3
+ export function getIgnoreQuery(): Promise<Query>;
4
+ export function getPinnedVersionQuery(): Promise<Query>;
5
+ import { Parser } from 'web-tree-sitter';
6
+ import { Query } from 'web-tree-sitter';
@@ -0,0 +1,24 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { Language, Parser, Query } from 'web-tree-sitter';
3
+ const wasmUrl = new URL('./tree-sitter-requirements.wasm', import.meta.url);
4
+ async function init() {
5
+ await Parser.init();
6
+ const wasmBytes = new Uint8Array(await readFile(wasmUrl));
7
+ return await Language.load(wasmBytes);
8
+ }
9
+ export async function getParser() {
10
+ const language = await init();
11
+ return new Parser().setLanguage(language);
12
+ }
13
+ export async function getRequirementQuery() {
14
+ const language = await init();
15
+ return new Query(language, '(requirement (package) @name) @req');
16
+ }
17
+ export async function getIgnoreQuery() {
18
+ const language = await init();
19
+ return new Query(language, '((requirement (package) @name) @req . (comment) @comment (#match? @comment "^#[\\t ]*exhortignore"))');
20
+ }
21
+ export async function getPinnedVersionQuery() {
22
+ const language = await init();
23
+ return new Query(language, '(version_spec (version_cmp) @cmp (version) @version (#eq? @cmp "=="))');
24
+ }
@@ -0,0 +1,52 @@
1
+ declare namespace _default {
2
+ export { isSupported };
3
+ export { validateLockFile };
4
+ export { provideComponent };
5
+ export { provideStack };
6
+ export { readLicenseFromManifest };
7
+ }
8
+ export default _default;
9
+ export type Provided = import("../provider").Provided;
10
+ /**
11
+ * @param {string} manifestName - the subject manifest name-type
12
+ * @returns {boolean} - return true if `Cargo.toml` is the manifest name-type
13
+ */
14
+ declare function isSupported(manifestName: string): boolean;
15
+ /**
16
+ * Validates that Cargo.lock exists in the manifest directory or in a parent
17
+ * workspace root directory. In Cargo workspaces the lock file always lives at
18
+ * the workspace root, so when a member crate's Cargo.toml is provided we walk
19
+ * up the directory tree looking for Cargo.lock (stopping when we find a
20
+ * Cargo.toml that contains a [workspace] section, or when we reach the
21
+ * filesystem root).
22
+ * When TRUSTIFY_DA_WORKSPACE_DIR is provided (via env var or opts),
23
+ * checks only that directory for Cargo.lock — no walk-up.
24
+ * @param {string} manifestDir - the directory where the manifest lies
25
+ * @param {{TRUSTIFY_DA_WORKSPACE_DIR?: string}} [opts={}] - optional workspace root
26
+ * @returns {boolean} true if Cargo.lock is found
27
+ */
28
+ declare function validateLockFile(manifestDir: string, opts?: {
29
+ TRUSTIFY_DA_WORKSPACE_DIR?: string;
30
+ }): boolean;
31
+ /**
32
+ * Provide content and content type for Cargo component analysis.
33
+ * @param {string} manifest - path to Cargo.toml for component report
34
+ * @param {{}} [opts={}] - optional various options to pass along the application
35
+ * @returns {Provided}
36
+ */
37
+ declare function provideComponent(manifest: string, opts?: {}): Provided;
38
+ /**
39
+ * Provide content and content type for Cargo stack analysis.
40
+ * @param {string} manifest - the manifest path
41
+ * @param {{}} [opts={}] - optional various options to pass along the application
42
+ * @returns {Provided}
43
+ */
44
+ declare function provideStack(manifest: string, opts?: {}): Provided;
45
+ /**
46
+ * Read project license from Cargo.toml, with fallback to LICENSE file.
47
+ * Supports the `license` field under `[package]` (single crate / workspace
48
+ * with root) and under `[workspace.package]` (virtual workspaces).
49
+ * @param {string} manifestPath - path to Cargo.toml
50
+ * @returns {string|null} SPDX identifier or null
51
+ */
52
+ declare function readLicenseFromManifest(manifestPath: string): string | null;