@trustify-da/trustify-da-javascript-client 0.3.0-ea.b68592e → 0.3.0-ea.b77d624
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.
- package/README.md +189 -3
- package/dist/package.json +16 -7
- package/dist/src/analysis.d.ts +7 -0
- package/dist/src/analysis.js +29 -13
- package/dist/src/cli.js +106 -2
- package/dist/src/cyclone_dx_sbom.d.ts +13 -0
- package/dist/src/cyclone_dx_sbom.js +39 -1
- package/dist/src/index.d.ts +5 -1
- package/dist/src/index.js +12 -25
- package/dist/src/oci_image/images.js +15 -1
- package/dist/src/package_version.d.ts +8 -0
- package/dist/src/package_version.js +31 -0
- package/dist/src/provider.js +3 -1
- package/dist/src/providers/base_java.d.ts +53 -0
- package/dist/src/providers/base_java.js +64 -17
- package/dist/src/providers/base_javascript.d.ts +54 -0
- package/dist/src/providers/base_javascript.js +105 -3
- package/dist/src/providers/containerfile_parser.d.ts +5 -0
- package/dist/src/providers/containerfile_parser.js +20 -0
- package/dist/src/providers/golang_gomodules.js +49 -7
- package/dist/src/providers/java_gradle.d.ts +48 -0
- package/dist/src/providers/java_gradle.js +196 -18
- package/dist/src/providers/java_maven.d.ts +28 -8
- package/dist/src/providers/java_maven.js +104 -10
- package/dist/src/providers/javascript_bun.d.ts +12 -0
- package/dist/src/providers/javascript_bun.js +42 -1
- package/dist/src/providers/javascript_npm.d.ts +13 -0
- package/dist/src/providers/javascript_npm.js +40 -1
- package/dist/src/providers/javascript_pnpm.d.ts +13 -0
- package/dist/src/providers/javascript_pnpm.js +47 -1
- package/dist/src/providers/javascript_yarn.d.ts +12 -0
- package/dist/src/providers/javascript_yarn.js +75 -2
- package/dist/src/providers/manifest.js +6 -3
- package/dist/src/providers/oci_dockerfile.d.ts +51 -0
- package/dist/src/providers/oci_dockerfile.js +177 -0
- package/dist/src/providers/processors/yarn_berry_processor.d.ts +5 -1
- package/dist/src/providers/processors/yarn_berry_processor.js +3 -2
- package/dist/src/providers/processors/yarn_classic_processor.d.ts +5 -1
- package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
- package/dist/src/providers/python_controller.js +4 -1
- package/dist/src/providers/requirements_parser.js +1 -1
- package/dist/src/providers/rust_cargo.js +70 -29
- package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
- package/dist/src/remediate.d.ts +21 -0
- package/dist/src/remediate.js +149 -0
- package/dist/src/remediation.d.ts +57 -0
- package/dist/src/remediation.js +436 -0
- package/dist/src/remediation_report.d.ts +40 -0
- package/dist/src/remediation_report.js +159 -0
- package/dist/src/sbom.d.ts +11 -0
- package/dist/src/sbom.js +10 -0
- package/dist/src/tools.js +24 -1
- package/dist/src/updaters/maven_updater.d.ts +26 -0
- package/dist/src/updaters/maven_updater.js +322 -0
- package/dist/src/updaters/toml_updater.d.ts +33 -0
- package/dist/src/updaters/toml_updater.js +244 -0
- package/package.json +17 -8
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { parse as parseToml } from 'smol-toml';
|
|
2
|
+
/**
|
|
3
|
+
* Updates dependency versions in a Gradle version catalog (libs.versions.toml) file.
|
|
4
|
+
*
|
|
5
|
+
* Supports two version declaration patterns:
|
|
6
|
+
* - Centralized: [versions] section defines version aliases, [libraries] references via version.ref
|
|
7
|
+
* - Inline: [libraries] entries include version = "x.y.z" directly
|
|
8
|
+
*
|
|
9
|
+
* Uses smol-toml parse() to locate keys, then performs position-based string replacement
|
|
10
|
+
* on the raw content to preserve formatting and comments.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} tomlContent - raw TOML file content
|
|
13
|
+
* @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges
|
|
14
|
+
* @returns {{content: string, applied: Array<{groupId: string, artifactId: string, newVersion: string, oldVersion: string}>, skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}}
|
|
15
|
+
*/
|
|
16
|
+
export function updateTomlVersions(tomlContent, versionChanges) {
|
|
17
|
+
const applied = [];
|
|
18
|
+
const skipped = [];
|
|
19
|
+
if (!versionChanges || versionChanges.length === 0) {
|
|
20
|
+
return { content: tomlContent, applied, skipped };
|
|
21
|
+
}
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = parseToml(tomlContent);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
for (const change of versionChanges) {
|
|
28
|
+
skipped.push({
|
|
29
|
+
groupId: change.groupId,
|
|
30
|
+
artifactId: change.artifactId,
|
|
31
|
+
newVersion: change.newVersion,
|
|
32
|
+
reason: `Failed to parse TOML: ${err.message}`
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return { content: tomlContent, applied, skipped };
|
|
36
|
+
}
|
|
37
|
+
const libraries = parsed.libraries || {};
|
|
38
|
+
const versions = parsed.versions || {};
|
|
39
|
+
const libraryIndex = buildLibraryIndex(libraries);
|
|
40
|
+
let updatedContent = tomlContent;
|
|
41
|
+
for (const change of versionChanges) {
|
|
42
|
+
const moduleKey = `${change.groupId}:${change.artifactId}`;
|
|
43
|
+
const alias = libraryIndex.get(moduleKey);
|
|
44
|
+
if (!alias) {
|
|
45
|
+
skipped.push({
|
|
46
|
+
groupId: change.groupId,
|
|
47
|
+
artifactId: change.artifactId,
|
|
48
|
+
newVersion: change.newVersion,
|
|
49
|
+
reason: `No library entry found for module ${moduleKey}`
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const libEntry = libraries[alias];
|
|
54
|
+
const versionRef = getVersionRef(libEntry);
|
|
55
|
+
if (versionRef) {
|
|
56
|
+
const oldVersion = versions[versionRef];
|
|
57
|
+
if (oldVersion === undefined) {
|
|
58
|
+
skipped.push({
|
|
59
|
+
groupId: change.groupId,
|
|
60
|
+
artifactId: change.artifactId,
|
|
61
|
+
newVersion: change.newVersion,
|
|
62
|
+
reason: `Version ref "${versionRef}" not found in [versions] section`
|
|
63
|
+
});
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (oldVersion === change.newVersion) {
|
|
67
|
+
skipped.push({
|
|
68
|
+
groupId: change.groupId,
|
|
69
|
+
artifactId: change.artifactId,
|
|
70
|
+
newVersion: change.newVersion,
|
|
71
|
+
reason: `Version already at ${change.newVersion}`
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
updatedContent = replaceVersionInSection(updatedContent, versionRef, oldVersion, change.newVersion);
|
|
76
|
+
applied.push({
|
|
77
|
+
groupId: change.groupId,
|
|
78
|
+
artifactId: change.artifactId,
|
|
79
|
+
newVersion: change.newVersion,
|
|
80
|
+
oldVersion
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const inlineVersion = getInlineVersion(libEntry);
|
|
85
|
+
if (inlineVersion === undefined) {
|
|
86
|
+
skipped.push({
|
|
87
|
+
groupId: change.groupId,
|
|
88
|
+
artifactId: change.artifactId,
|
|
89
|
+
newVersion: change.newVersion,
|
|
90
|
+
reason: `No version.ref or inline version found for library "${alias}"`
|
|
91
|
+
});
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (inlineVersion === change.newVersion) {
|
|
95
|
+
skipped.push({
|
|
96
|
+
groupId: change.groupId,
|
|
97
|
+
artifactId: change.artifactId,
|
|
98
|
+
newVersion: change.newVersion,
|
|
99
|
+
reason: `Version already at ${change.newVersion}`
|
|
100
|
+
});
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const beforeInline = updatedContent;
|
|
104
|
+
updatedContent = replaceInlineVersion(updatedContent, alias, inlineVersion, change.newVersion);
|
|
105
|
+
if (updatedContent !== beforeInline) {
|
|
106
|
+
applied.push({
|
|
107
|
+
groupId: change.groupId,
|
|
108
|
+
artifactId: change.artifactId,
|
|
109
|
+
newVersion: change.newVersion,
|
|
110
|
+
oldVersion: inlineVersion
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
skipped.push({
|
|
115
|
+
groupId: change.groupId,
|
|
116
|
+
artifactId: change.artifactId,
|
|
117
|
+
newVersion: change.newVersion,
|
|
118
|
+
reason: `Inline version replacement did not match for library "${alias}"`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return { content: updatedContent, applied, skipped };
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Builds a map from "groupId:artifactId" to the TOML library alias.
|
|
127
|
+
* @param {object} libraries - parsed [libraries] section
|
|
128
|
+
* @returns {Map<string, string>}
|
|
129
|
+
*/
|
|
130
|
+
function buildLibraryIndex(libraries) {
|
|
131
|
+
const index = new Map();
|
|
132
|
+
for (const [alias, entry] of Object.entries(libraries)) {
|
|
133
|
+
const module = getModule(entry);
|
|
134
|
+
if (module) {
|
|
135
|
+
index.set(module, alias);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return index;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Extracts the module identifier from a library entry.
|
|
142
|
+
* Handles both string shorthand ("group:artifact:version") and object notation
|
|
143
|
+
* ({ module = "group:artifact" } or { group = "...", name = "..." }).
|
|
144
|
+
* @param {string|object} entry
|
|
145
|
+
* @returns {string|undefined} "groupId:artifactId"
|
|
146
|
+
*/
|
|
147
|
+
function getModule(entry) {
|
|
148
|
+
if (typeof entry === 'string') {
|
|
149
|
+
const parts = entry.split(':');
|
|
150
|
+
if (parts.length >= 2) {
|
|
151
|
+
return `${parts[0]}:${parts[1]}`;
|
|
152
|
+
}
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
if (entry.module) {
|
|
156
|
+
const parts = entry.module.split(':');
|
|
157
|
+
if (parts.length >= 2) {
|
|
158
|
+
return `${parts[0]}:${parts[1]}`;
|
|
159
|
+
}
|
|
160
|
+
return entry.module;
|
|
161
|
+
}
|
|
162
|
+
if (entry.group && entry.name) {
|
|
163
|
+
return `${entry.group}:${entry.name}`;
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Extracts the version.ref from a library entry, if present.
|
|
169
|
+
* @param {string|object} entry
|
|
170
|
+
* @returns {string|undefined}
|
|
171
|
+
*/
|
|
172
|
+
function getVersionRef(entry) {
|
|
173
|
+
if (typeof entry === 'object' && entry.version) {
|
|
174
|
+
if (typeof entry.version === 'object' && entry.version.ref) {
|
|
175
|
+
return entry.version.ref;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Extracts an inline version string from a library entry.
|
|
182
|
+
* Handles { version = "1.2.3" } and string shorthand "group:artifact:version".
|
|
183
|
+
* @param {string|object} entry
|
|
184
|
+
* @returns {string|undefined}
|
|
185
|
+
*/
|
|
186
|
+
function getInlineVersion(entry) {
|
|
187
|
+
if (typeof entry === 'string') {
|
|
188
|
+
const parts = entry.split(':');
|
|
189
|
+
if (parts.length >= 3) {
|
|
190
|
+
return parts[2];
|
|
191
|
+
}
|
|
192
|
+
return undefined;
|
|
193
|
+
}
|
|
194
|
+
if (typeof entry === 'object' && entry.version) {
|
|
195
|
+
if (typeof entry.version === 'string') {
|
|
196
|
+
return entry.version;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Replaces a version value using position-based string replacement.
|
|
203
|
+
* Targets lines matching: key = "oldVersion"
|
|
204
|
+
* @param {string} content - raw TOML content
|
|
205
|
+
* @param {string} key - version alias key
|
|
206
|
+
* @param {string} oldVersion - current version string
|
|
207
|
+
* @param {string} newVersion - replacement version string
|
|
208
|
+
* @returns {string} updated content
|
|
209
|
+
*/
|
|
210
|
+
function replaceVersionInSection(content, key, oldVersion, newVersion) {
|
|
211
|
+
const escapedKey = escapeRegExp(key);
|
|
212
|
+
const escapedOld = escapeRegExp(oldVersion);
|
|
213
|
+
const pattern = new RegExp(`^(\\s*${escapedKey}\\s*=\\s*")${escapedOld}("\\s*)$`, 'm');
|
|
214
|
+
return content.replace(pattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Replaces an inline version in a library entry.
|
|
218
|
+
* Targets patterns like: version = "oldVersion" or version ="oldVersion"
|
|
219
|
+
* on the line containing the library alias.
|
|
220
|
+
* @param {string} content - raw TOML content
|
|
221
|
+
* @param {string} alias - library alias
|
|
222
|
+
* @param {string} oldVersion - current version string
|
|
223
|
+
* @param {string} newVersion - replacement version string
|
|
224
|
+
* @returns {string} updated content
|
|
225
|
+
*/
|
|
226
|
+
function replaceInlineVersion(content, alias, oldVersion, newVersion) {
|
|
227
|
+
const escapedAlias = escapeRegExp(alias);
|
|
228
|
+
const escapedOld = escapeRegExp(oldVersion);
|
|
229
|
+
const pattern = new RegExp(`^(\\s*${escapedAlias}\\s*=\\s*\\{[^}]*version\\s*=\\s*")${escapedOld}("[^}]*\\}\\s*)$`, 'm');
|
|
230
|
+
const result = content.replace(pattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
|
|
231
|
+
if (result !== content) {
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
const stringPattern = new RegExp(`^(\\s*${escapedAlias}\\s*=\\s*"[^:]+:[^:]+:)${escapedOld}("\\s*)$`, 'm');
|
|
235
|
+
return content.replace(stringPattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Escapes special regex characters in a string.
|
|
239
|
+
* @param {string} str
|
|
240
|
+
* @returns {string}
|
|
241
|
+
*/
|
|
242
|
+
function escapeRegExp(str) {
|
|
243
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
244
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustify-da/trustify-da-javascript-client",
|
|
3
|
-
"version": "0.3.0-ea.
|
|
3
|
+
"version": "0.3.0-ea.b77d624",
|
|
4
4
|
"description": "Code-Ready Dependency Analytics JavaScript API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/guacsec/trustify-da-javascript-client#README.md",
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"provenance": true
|
|
26
26
|
},
|
|
27
27
|
"type": "module",
|
|
28
|
-
"bin":
|
|
28
|
+
"bin": {
|
|
29
|
+
"trustify-da": "dist/src/cli.js"
|
|
30
|
+
},
|
|
29
31
|
"main": "dist/src/index.js",
|
|
30
32
|
"module": "dist/src/index.js",
|
|
31
33
|
"types": "dist/src/index.d.ts",
|
|
@@ -40,15 +42,15 @@
|
|
|
40
42
|
"test": "c8 npm run tests",
|
|
41
43
|
"tests": "mocha --config .mocharc.json",
|
|
42
44
|
"tests:rep": "mocha --reporter-option maxDiffSize=0 --reporter json > unit-tests-result.json",
|
|
43
|
-
"pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm",
|
|
45
|
+
"pretest": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm src/providers/tree-sitter-gomod.wasm && cp node_modules/tree-sitter-containerfile/tree-sitter-containerfile.wasm src/providers/tree-sitter-containerfile.wasm",
|
|
44
46
|
"precompile": "rm -rf dist",
|
|
45
47
|
"compile": "tsc -p tsconfig.json",
|
|
46
48
|
"compile:dev": "tsc -p tsconfig.dev.json",
|
|
47
|
-
"postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm"
|
|
49
|
+
"postcompile": "cp node_modules/tree-sitter-requirements/tree-sitter-requirements.wasm dist/src/providers/tree-sitter-requirements.wasm && cp node_modules/tree-sitter-gomod/tree-sitter-gomod.wasm dist/src/providers/tree-sitter-gomod.wasm && cp node_modules/tree-sitter-containerfile/tree-sitter-containerfile.wasm dist/src/providers/tree-sitter-containerfile.wasm"
|
|
48
50
|
},
|
|
49
51
|
"dependencies": {
|
|
50
52
|
"@babel/core": "^7.23.2",
|
|
51
|
-
"@
|
|
53
|
+
"@yarnpkg/parsers": "^3.1.0",
|
|
52
54
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
53
55
|
"fast-glob": "^3.3.3",
|
|
54
56
|
"fast-xml-parser": "^5.3.4",
|
|
@@ -61,6 +63,7 @@
|
|
|
61
63
|
"p-limit": "^7.3.0",
|
|
62
64
|
"packageurl-js": "~1.0.2",
|
|
63
65
|
"smol-toml": "^1.6.0",
|
|
66
|
+
"tree-sitter-containerfile": "^0.8.1",
|
|
64
67
|
"tree-sitter-gomod": "github:strum355/tree-sitter-go-mod#56326f2ad478892ace58ff247a97d492a3cbcdda",
|
|
65
68
|
"tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
|
|
66
69
|
"web-tree-sitter": "^0.26.7",
|
|
@@ -68,18 +71,20 @@
|
|
|
68
71
|
},
|
|
69
72
|
"devDependencies": {
|
|
70
73
|
"@babel/core": "^7.23.2",
|
|
71
|
-
"@
|
|
74
|
+
"@cyclonedx/cyclonedx-library": "^10.2.0",
|
|
75
|
+
"@eslint/js": "^10.0.0",
|
|
76
|
+
"@trustify-da/trustify-da-api-model": "^2.0.12",
|
|
72
77
|
"@types/node": "^25.9.1",
|
|
73
78
|
"@types/which": "^3.0.4",
|
|
79
|
+
"ajv": "^8.20.0",
|
|
74
80
|
"babel-plugin-rewire": "^1.2.0",
|
|
75
81
|
"c8": "^11.0.0",
|
|
76
82
|
"chai": "^6.2.2",
|
|
77
|
-
"@eslint/js": "^10.0.0",
|
|
78
83
|
"eslint": "^10.4.1",
|
|
79
84
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
80
85
|
"eslint-plugin-import-x": "^4.16.2",
|
|
81
|
-
"globals": "^17.6.0",
|
|
82
86
|
"esmock": "^2.6.2",
|
|
87
|
+
"globals": "^17.6.0",
|
|
83
88
|
"mocha": "^11.7.6",
|
|
84
89
|
"msw": "^2.12.7",
|
|
85
90
|
"sinon": "^22.0.0",
|
|
@@ -113,9 +118,13 @@
|
|
|
113
118
|
"reporter": [
|
|
114
119
|
"html",
|
|
115
120
|
"json",
|
|
121
|
+
"lcov",
|
|
116
122
|
"text"
|
|
117
123
|
]
|
|
118
124
|
},
|
|
125
|
+
"overrides": {
|
|
126
|
+
"tree-sitter": "0.22.4"
|
|
127
|
+
},
|
|
119
128
|
"resolutions": {
|
|
120
129
|
"@hapi/joi": "17.1.1"
|
|
121
130
|
}
|