@trustify-da/trustify-da-javascript-client 0.3.0-ea.29f6867 → 0.3.0-ea.38515a7

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 (43) 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 +121 -3
  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 +64 -1
  11. package/dist/src/index.js +267 -4
  12. package/dist/src/license/licenses_api.js +9 -2
  13. package/dist/src/license/project_license.d.ts +0 -8
  14. package/dist/src/license/project_license.js +0 -11
  15. package/dist/src/oci_image/utils.js +11 -2
  16. package/dist/src/provider.d.ts +6 -3
  17. package/dist/src/provider.js +12 -5
  18. package/dist/src/providers/base_javascript.d.ts +19 -3
  19. package/dist/src/providers/base_javascript.js +99 -18
  20. package/dist/src/providers/base_pyproject.d.ts +147 -0
  21. package/dist/src/providers/base_pyproject.js +279 -0
  22. package/dist/src/providers/golang_gomodules.d.ts +12 -12
  23. package/dist/src/providers/golang_gomodules.js +100 -111
  24. package/dist/src/providers/gomod_parser.d.ts +4 -0
  25. package/dist/src/providers/gomod_parser.js +16 -0
  26. package/dist/src/providers/javascript_pnpm.d.ts +1 -1
  27. package/dist/src/providers/javascript_pnpm.js +2 -2
  28. package/dist/src/providers/manifest.d.ts +2 -0
  29. package/dist/src/providers/manifest.js +22 -4
  30. package/dist/src/providers/processors/yarn_berry_processor.js +82 -3
  31. package/dist/src/providers/python_pip.js +1 -1
  32. package/dist/src/providers/python_poetry.d.ts +42 -0
  33. package/dist/src/providers/python_poetry.js +146 -0
  34. package/dist/src/providers/python_uv.d.ts +26 -0
  35. package/dist/src/providers/python_uv.js +118 -0
  36. package/dist/src/providers/rust_cargo.d.ts +52 -0
  37. package/dist/src/providers/rust_cargo.js +614 -0
  38. package/dist/src/providers/tree-sitter-gomod.wasm +0 -0
  39. package/dist/src/sbom.d.ts +7 -0
  40. package/dist/src/sbom.js +9 -0
  41. package/dist/src/workspace.d.ts +61 -0
  42. package/dist/src/workspace.js +256 -0
  43. package/package.json +11 -5
@@ -0,0 +1,146 @@
1
+ import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
2
+ import Base_pyproject from './base_pyproject.js';
3
+ export default class Python_poetry extends Base_pyproject {
4
+ /** @returns {string} */
5
+ _lockFileName() {
6
+ return 'poetry.lock';
7
+ }
8
+ /** @returns {string} */
9
+ _cmdName() {
10
+ return 'poetry';
11
+ }
12
+ /**
13
+ * @param {string} manifestDir
14
+ * @param {object} parsed - parsed pyproject.toml
15
+ * @param {Object} opts
16
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
17
+ */
18
+ async _getDependencyData(manifestDir, parsed, opts) {
19
+ let treeOutput = this._getPoetryShowTreeOutput(manifestDir, opts);
20
+ let showAllOutput = this._getPoetryShowAllOutput(manifestDir, opts);
21
+ let versionMap = this._parsePoetryShowAll(showAllOutput);
22
+ return this._parsePoetryTree(treeOutput, versionMap);
23
+ }
24
+ /**
25
+ * Get poetry show --tree output.
26
+ * @param {string} manifestDir
27
+ * @param {Object} opts
28
+ * @returns {string}
29
+ */
30
+ _getPoetryShowTreeOutput(manifestDir, opts) {
31
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_TREE')) {
32
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_TREE'], 'base64').toString('utf-8');
33
+ }
34
+ let poetryBin = getCustomPath('poetry', opts);
35
+ return invokeCommand(poetryBin, ['show', '--tree', '--no-ansi'], { cwd: manifestDir }).toString();
36
+ }
37
+ /**
38
+ * Get poetry show --all output (flat list with resolved versions).
39
+ * @param {string} manifestDir
40
+ * @param {Object} opts
41
+ * @returns {string}
42
+ */
43
+ _getPoetryShowAllOutput(manifestDir, opts) {
44
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_POETRY_SHOW_ALL')) {
45
+ return Buffer.from(process.env['TRUSTIFY_DA_POETRY_SHOW_ALL'], 'base64').toString('utf-8');
46
+ }
47
+ let poetryBin = getCustomPath('poetry', opts);
48
+ return invokeCommand(poetryBin, ['show', '--no-ansi', '--all'], { cwd: manifestDir }).toString();
49
+ }
50
+ /**
51
+ * Parse poetry show --all output into a version map.
52
+ * Lines look like: "name (!) 1.2.3 Description text..."
53
+ * or: "name 1.2.3 Description text..."
54
+ * @param {string} output
55
+ * @returns {Map<string, string>} canonical name -> version
56
+ */
57
+ _parsePoetryShowAll(output) {
58
+ let versions = new Map();
59
+ let lines = output.split(/\r?\n/);
60
+ for (let line of lines) {
61
+ let trimmed = line.trim();
62
+ if (!trimmed) {
63
+ continue;
64
+ }
65
+ let match = trimmed.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(?:\(!\)\s+)?(\S+)/);
66
+ if (match) {
67
+ versions.set(this._canonicalize(match[1]), match[2]);
68
+ }
69
+ }
70
+ return versions;
71
+ }
72
+ /**
73
+ * Parse poetry show --tree output into a dependency graph structure.
74
+ * Top-level lines (no indentation/tree chars) are direct deps: "name version description"
75
+ * Indented lines are transitive deps with tree chars: "├── name >=constraint"
76
+ *
77
+ * @param {string} treeOutput
78
+ * @param {Map<string, string>} versionMap - canonical name -> resolved version
79
+ * @returns {{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}}
80
+ */
81
+ _parsePoetryTree(treeOutput, versionMap) {
82
+ let lines = treeOutput.split(/\r?\n/);
83
+ let graph = new Map();
84
+ let directDeps = [];
85
+ let stack = []; // [{key, depth}]
86
+ let currentDirectDep = null;
87
+ for (let line of lines) {
88
+ if (!line.trim()) {
89
+ continue;
90
+ }
91
+ // top-level line: "name version description..."
92
+ let topMatch = line.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)\s+(\S+)\s/);
93
+ if (topMatch) {
94
+ let name = topMatch[1];
95
+ let version = topMatch[2];
96
+ let key = this._canonicalize(name);
97
+ directDeps.push(key);
98
+ if (!graph.has(key)) {
99
+ graph.set(key, { name, version, children: [] });
100
+ }
101
+ currentDirectDep = key;
102
+ stack = [{ key, depth: -1 }];
103
+ continue;
104
+ }
105
+ if (!currentDirectDep) {
106
+ continue;
107
+ }
108
+ // indented line with tree chars (UTF-8 box-drawing: ├── └── │)
109
+ let nameStart = line.search(/[A-Za-z0-9]/);
110
+ if (nameStart < 0) {
111
+ continue;
112
+ }
113
+ let rest = line.substring(nameStart);
114
+ let depMatch = rest.match(/^([A-Za-z0-9][A-Za-z0-9._-]*)/);
115
+ if (!depMatch) {
116
+ continue;
117
+ }
118
+ let depName = depMatch[1];
119
+ let depKey = this._canonicalize(depName);
120
+ // determine depth by counting tree-drawing groups in the prefix
121
+ let prefix = line.substring(0, nameStart);
122
+ let depth = (prefix.match(/(?:[├└│ ][\s─]{2} ?)/g) || []).length;
123
+ // resolve version from the version map
124
+ let version = versionMap.get(depKey) || null;
125
+ if (!version) {
126
+ throw new Error(`poetry: package '${depName}' has no resolved version`);
127
+ }
128
+ if (!graph.has(depKey)) {
129
+ graph.set(depKey, { name: depName, version, children: [] });
130
+ }
131
+ // pop stack back to find the parent at depth-1
132
+ while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
133
+ stack.pop();
134
+ }
135
+ if (stack.length > 0) {
136
+ let parentKey = stack[stack.length - 1].key;
137
+ let parentEntry = graph.get(parentKey);
138
+ if (parentEntry && !parentEntry.children.includes(depKey)) {
139
+ parentEntry.children.push(depKey);
140
+ }
141
+ }
142
+ stack.push({ key: depKey, depth });
143
+ }
144
+ return { directDeps, graph };
145
+ }
146
+ }
@@ -0,0 +1,26 @@
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
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
16
+ */
17
+ _parseUvExport(output: string, projectName: string): Promise<{
18
+ directDeps: string[];
19
+ graph: Map<string, {
20
+ name: string;
21
+ version: string;
22
+ children: string[];
23
+ }>;
24
+ }>;
25
+ }
26
+ import Base_pyproject from './base_pyproject.js';
@@ -0,0 +1,118 @@
1
+ import { environmentVariableIsPopulated, getCustomPath, invokeCommand } from '../tools.js';
2
+ import Base_pyproject from './base_pyproject.js';
3
+ import { getParser, getPinnedVersionQuery } from './requirements_parser.js';
4
+ export default class Python_uv extends Base_pyproject {
5
+ /** @returns {string} */
6
+ _lockFileName() {
7
+ return 'uv.lock';
8
+ }
9
+ /** @returns {string} */
10
+ _cmdName() {
11
+ return 'uv';
12
+ }
13
+ /**
14
+ * @param {string} manifestDir
15
+ * @param {object} parsed - parsed pyproject.toml
16
+ * @param {Object} opts
17
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
18
+ */
19
+ async _getDependencyData(manifestDir, parsed, opts) {
20
+ let projectName = this._getProjectName(parsed);
21
+ let uvOutput = this._getUvExportOutput(manifestDir, opts);
22
+ return this._parseUvExport(uvOutput, projectName);
23
+ }
24
+ /**
25
+ * Get the uv export output, either from env var or by running the command.
26
+ * @param {string} manifestDir
27
+ * @param {Object} opts
28
+ * @returns {string}
29
+ */
30
+ _getUvExportOutput(manifestDir, opts) {
31
+ if (environmentVariableIsPopulated('TRUSTIFY_DA_UV_EXPORT')) {
32
+ return Buffer.from(process.env['TRUSTIFY_DA_UV_EXPORT'], 'base64').toString('ascii');
33
+ }
34
+ let uvBin = getCustomPath('uv', opts);
35
+ return invokeCommand(uvBin, ['export', '--format', 'requirements.txt', '--frozen', '--no-hashes'], { cwd: manifestDir }).toString();
36
+ }
37
+ /**
38
+ * Parse uv export output into a dependency graph using tree-sitter-requirements
39
+ * for package/version extraction and string parsing for "# via" comments.
40
+ *
41
+ * @param {string} output
42
+ * @param {string} projectName - canonical project name to identify direct deps
43
+ * @returns {Promise<{directDeps: string[], graph: Map<string, {name: string, version: string, children: string[]}>}>}
44
+ */
45
+ async _parseUvExport(output, projectName) {
46
+ let [parser, pinnedVersionQuery] = await Promise.all([
47
+ getParser(), getPinnedVersionQuery()
48
+ ]);
49
+ let tree = parser.parse(output);
50
+ let root = tree.rootNode;
51
+ let canonProjectName = this._canonicalize(projectName);
52
+ let packages = new Map(); // canonical name -> {name, version, parents: Set}
53
+ let currentPkg = null;
54
+ let collectingVia = false;
55
+ for (let child of root.children) {
56
+ if (child.type === 'requirement') {
57
+ let nameNode = child.children.find(c => c.type === 'package');
58
+ if (!nameNode) {
59
+ continue;
60
+ }
61
+ let name = nameNode.text;
62
+ let version = null;
63
+ let versionMatches = pinnedVersionQuery.matches(child);
64
+ if (versionMatches.length > 0) {
65
+ version = versionMatches[0].captures.find(c => c.name === 'version').node.text;
66
+ }
67
+ if (!version) {
68
+ throw new Error(`uv export: package '${name}' has no pinned version`);
69
+ }
70
+ let key = this._canonicalize(name);
71
+ currentPkg = { name, version, parents: new Set() };
72
+ packages.set(key, currentPkg);
73
+ collectingVia = false;
74
+ continue;
75
+ }
76
+ if (child.type === 'comment' && currentPkg) {
77
+ let text = child.text.trim();
78
+ let viaSingle = text.match(/^# via ([A-Za-z0-9][A-Za-z0-9._-]*)$/);
79
+ if (viaSingle) {
80
+ currentPkg.parents.add(this._canonicalize(viaSingle[1]));
81
+ collectingVia = false;
82
+ continue;
83
+ }
84
+ if (text === '# via') {
85
+ collectingVia = true;
86
+ continue;
87
+ }
88
+ if (collectingVia) {
89
+ let parentMatch = text.match(/^#\s+([A-Za-z0-9][A-Za-z0-9._-]*)$/);
90
+ if (parentMatch) {
91
+ currentPkg.parents.add(this._canonicalize(parentMatch[1]));
92
+ continue;
93
+ }
94
+ collectingVia = false;
95
+ }
96
+ }
97
+ }
98
+ // Build forward dependency map and extract direct deps in one pass
99
+ let graph = new Map();
100
+ let directDeps = [];
101
+ for (let [key, pkg] of packages) {
102
+ graph.set(key, { name: pkg.name, version: pkg.version, children: [] });
103
+ }
104
+ for (let [childKey, pkg] of packages) {
105
+ for (let parentKey of pkg.parents) {
106
+ if (parentKey === canonProjectName) {
107
+ directDeps.push(childKey);
108
+ continue;
109
+ }
110
+ let parentEntry = graph.get(parentKey);
111
+ if (parentEntry) {
112
+ parentEntry.children.push(childKey);
113
+ }
114
+ }
115
+ }
116
+ return { directDeps, graph };
117
+ }
118
+ }
@@ -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;