@trustify-da/trustify-da-javascript-client 0.3.0-ea.ec6824b → 0.3.0-ea.efdc87d

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 (66) hide show
  1. package/README.md +199 -11
  2. package/dist/package.json +15 -10
  3. package/dist/src/analysis.d.ts +47 -19
  4. package/dist/src/analysis.js +70 -18
  5. package/dist/src/cli.js +188 -6
  6. package/dist/src/config.d.ts +120 -0
  7. package/dist/src/config.js +260 -0
  8. package/dist/src/cyclone_dx_sbom.d.ts +13 -0
  9. package/dist/src/cyclone_dx_sbom.js +39 -1
  10. package/dist/src/index.d.ts +27 -22
  11. package/dist/src/index.js +27 -38
  12. package/dist/src/license/index.d.ts +2 -2
  13. package/dist/src/license/index.js +9 -6
  14. package/dist/src/license/licenses_api.d.ts +2 -2
  15. package/dist/src/license/licenses_api.js +1 -1
  16. package/dist/src/oci_image/images.js +15 -1
  17. package/dist/src/package_version.d.ts +8 -0
  18. package/dist/src/package_version.js +31 -0
  19. package/dist/src/provider.js +3 -1
  20. package/dist/src/providers/base_java.d.ts +53 -0
  21. package/dist/src/providers/base_java.js +64 -17
  22. package/dist/src/providers/base_javascript.d.ts +54 -0
  23. package/dist/src/providers/base_javascript.js +106 -4
  24. package/dist/src/providers/containerfile_parser.d.ts +5 -0
  25. package/dist/src/providers/containerfile_parser.js +20 -0
  26. package/dist/src/providers/golang_gomodules.js +49 -7
  27. package/dist/src/providers/java_gradle.d.ts +48 -0
  28. package/dist/src/providers/java_gradle.js +196 -18
  29. package/dist/src/providers/java_maven.d.ts +28 -8
  30. package/dist/src/providers/java_maven.js +104 -10
  31. package/dist/src/providers/javascript_bun.d.ts +12 -0
  32. package/dist/src/providers/javascript_bun.js +42 -1
  33. package/dist/src/providers/javascript_npm.d.ts +13 -0
  34. package/dist/src/providers/javascript_npm.js +40 -1
  35. package/dist/src/providers/javascript_pnpm.d.ts +13 -0
  36. package/dist/src/providers/javascript_pnpm.js +47 -1
  37. package/dist/src/providers/javascript_yarn.d.ts +12 -0
  38. package/dist/src/providers/javascript_yarn.js +75 -2
  39. package/dist/src/providers/manifest.js +6 -3
  40. package/dist/src/providers/oci_dockerfile.d.ts +51 -0
  41. package/dist/src/providers/oci_dockerfile.js +177 -0
  42. package/dist/src/providers/processors/yarn_berry_processor.d.ts +5 -1
  43. package/dist/src/providers/processors/yarn_berry_processor.js +3 -2
  44. package/dist/src/providers/processors/yarn_classic_processor.d.ts +5 -1
  45. package/dist/src/providers/processors/yarn_classic_processor.js +8 -6
  46. package/dist/src/providers/python_controller.js +4 -1
  47. package/dist/src/providers/requirements_parser.js +1 -1
  48. package/dist/src/providers/rust_cargo.js +70 -29
  49. package/dist/src/providers/tree-sitter-containerfile.wasm +0 -0
  50. package/dist/src/remediate.d.ts +120 -0
  51. package/dist/src/remediate.js +253 -0
  52. package/dist/src/remediation.d.ts +58 -0
  53. package/dist/src/remediation.js +425 -0
  54. package/dist/src/remediation_report.d.ts +40 -0
  55. package/dist/src/remediation_report.js +159 -0
  56. package/dist/src/sbom.d.ts +11 -0
  57. package/dist/src/sbom.js +10 -0
  58. package/dist/src/tools.d.ts +9 -11
  59. package/dist/src/tools.js +34 -13
  60. package/dist/src/updaters/maven_updater.d.ts +58 -0
  61. package/dist/src/updaters/maven_updater.js +345 -0
  62. package/dist/src/updaters/toml_updater.d.ts +62 -0
  63. package/dist/src/updaters/toml_updater.js +276 -0
  64. package/dist/src/workspace.d.ts +2 -1
  65. package/dist/src/workspace.js +2 -1
  66. package/package.json +16 -11
@@ -0,0 +1,276 @@
1
+ import { parse as parseToml } from 'smol-toml';
2
+ /**
3
+ * One entry in {@link updateTomlVersions}' `applied` list: a version that was changed and where.
4
+ * `type` discriminates the edit site — `'ref'` for a `[libraries]` entry pointing at a shared
5
+ * `[versions]` alias via `version.ref` (then `versionRef` names that alias), `'inline'` for a
6
+ * version declared directly on the library. `alias` is the library's catalog key in both cases.
7
+ * @typedef {{
8
+ * groupId: string,
9
+ * artifactId: string,
10
+ * newVersion: string,
11
+ * oldVersion: string,
12
+ * type: ('ref'|'inline'),
13
+ * alias: string,
14
+ * versionRef?: string
15
+ * }} TomlAppliedChange
16
+ */
17
+ /**
18
+ * Stable edit-site key for a TOML (Gradle version catalog) change: same key => same commit/PR.
19
+ * Deps sharing one `[versions]` alias via `version.ref` share the ref key and are inseparable.
20
+ * @param {string} manifestPath
21
+ * @param {TomlAppliedChange} applied
22
+ * @returns {string}
23
+ */
24
+ export function tomlChangeKey(manifestPath, applied) {
25
+ return applied.type === 'ref'
26
+ ? `toml:ref:${manifestPath}:${applied.versionRef}`
27
+ : `toml:inline:${manifestPath}:${applied.alias}`;
28
+ }
29
+ /**
30
+ * Updates dependency versions in a Gradle version catalog (libs.versions.toml) file.
31
+ *
32
+ * Supports two version declaration patterns:
33
+ * - Centralized: [versions] section defines version aliases, [libraries] references via version.ref
34
+ * - Inline: [libraries] entries include version = "x.y.z" directly
35
+ *
36
+ * Uses smol-toml parse() to locate keys, then performs position-based string replacement
37
+ * on the raw content to preserve formatting and comments.
38
+ *
39
+ * @param {string} tomlContent - raw TOML file content
40
+ * @param {import('../remediate.js').VersionChangeRequest[]} versionChanges
41
+ * @returns {{content: string, applied: TomlAppliedChange[], skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}}
42
+ */
43
+ export function updateTomlVersions(tomlContent, versionChanges) {
44
+ const applied = [];
45
+ const skipped = [];
46
+ if (!versionChanges || versionChanges.length === 0) {
47
+ return { content: tomlContent, applied, skipped };
48
+ }
49
+ let parsed;
50
+ try {
51
+ parsed = parseToml(tomlContent);
52
+ }
53
+ catch (err) {
54
+ for (const change of versionChanges) {
55
+ skipped.push({
56
+ groupId: change.groupId,
57
+ artifactId: change.artifactId,
58
+ newVersion: change.newVersion,
59
+ reason: `Failed to parse TOML: ${err.message}`
60
+ });
61
+ }
62
+ return { content: tomlContent, applied, skipped };
63
+ }
64
+ const libraries = parsed.libraries || {};
65
+ const versions = parsed.versions || {};
66
+ const libraryIndex = buildLibraryIndex(libraries);
67
+ let updatedContent = tomlContent;
68
+ for (const change of versionChanges) {
69
+ const moduleKey = `${change.groupId}:${change.artifactId}`;
70
+ const alias = libraryIndex.get(moduleKey);
71
+ if (!alias) {
72
+ skipped.push({
73
+ groupId: change.groupId,
74
+ artifactId: change.artifactId,
75
+ newVersion: change.newVersion,
76
+ reason: `No library entry found for module ${moduleKey}`
77
+ });
78
+ continue;
79
+ }
80
+ const libEntry = libraries[alias];
81
+ const versionRef = getVersionRef(libEntry);
82
+ if (versionRef) {
83
+ const oldVersion = versions[versionRef];
84
+ if (oldVersion === undefined) {
85
+ skipped.push({
86
+ groupId: change.groupId,
87
+ artifactId: change.artifactId,
88
+ newVersion: change.newVersion,
89
+ reason: `Version ref "${versionRef}" not found in [versions] section`
90
+ });
91
+ continue;
92
+ }
93
+ if (oldVersion === change.newVersion) {
94
+ skipped.push({
95
+ groupId: change.groupId,
96
+ artifactId: change.artifactId,
97
+ newVersion: change.newVersion,
98
+ reason: `Version already at ${change.newVersion}`
99
+ });
100
+ continue;
101
+ }
102
+ updatedContent = replaceVersionInSection(updatedContent, versionRef, oldVersion, change.newVersion);
103
+ applied.push({
104
+ groupId: change.groupId,
105
+ artifactId: change.artifactId,
106
+ newVersion: change.newVersion,
107
+ oldVersion,
108
+ type: 'ref',
109
+ versionRef,
110
+ alias
111
+ });
112
+ }
113
+ else {
114
+ const inlineVersion = getInlineVersion(libEntry);
115
+ if (inlineVersion === undefined) {
116
+ skipped.push({
117
+ groupId: change.groupId,
118
+ artifactId: change.artifactId,
119
+ newVersion: change.newVersion,
120
+ reason: `No version.ref or inline version found for library "${alias}"`
121
+ });
122
+ continue;
123
+ }
124
+ if (inlineVersion === change.newVersion) {
125
+ skipped.push({
126
+ groupId: change.groupId,
127
+ artifactId: change.artifactId,
128
+ newVersion: change.newVersion,
129
+ reason: `Version already at ${change.newVersion}`
130
+ });
131
+ continue;
132
+ }
133
+ const beforeInline = updatedContent;
134
+ updatedContent = replaceInlineVersion(updatedContent, alias, inlineVersion, change.newVersion);
135
+ if (updatedContent !== beforeInline) {
136
+ applied.push({
137
+ groupId: change.groupId,
138
+ artifactId: change.artifactId,
139
+ newVersion: change.newVersion,
140
+ oldVersion: inlineVersion,
141
+ type: 'inline',
142
+ alias
143
+ });
144
+ }
145
+ else {
146
+ skipped.push({
147
+ groupId: change.groupId,
148
+ artifactId: change.artifactId,
149
+ newVersion: change.newVersion,
150
+ reason: `Inline version replacement did not match for library "${alias}"`
151
+ });
152
+ }
153
+ }
154
+ }
155
+ return { content: updatedContent, applied, skipped };
156
+ }
157
+ /**
158
+ * Builds a map from "groupId:artifactId" to the TOML library alias.
159
+ * @param {object} libraries - parsed [libraries] section
160
+ * @returns {Map<string, string>}
161
+ */
162
+ function buildLibraryIndex(libraries) {
163
+ const index = new Map();
164
+ for (const [alias, entry] of Object.entries(libraries)) {
165
+ const module = getModule(entry);
166
+ if (module) {
167
+ index.set(module, alias);
168
+ }
169
+ }
170
+ return index;
171
+ }
172
+ /**
173
+ * Extracts the module identifier from a library entry.
174
+ * Handles both string shorthand ("group:artifact:version") and object notation
175
+ * ({ module = "group:artifact" } or { group = "...", name = "..." }).
176
+ * @param {string|object} entry
177
+ * @returns {string|undefined} "groupId:artifactId"
178
+ */
179
+ function getModule(entry) {
180
+ if (typeof entry === 'string') {
181
+ const parts = entry.split(':');
182
+ if (parts.length >= 2) {
183
+ return `${parts[0]}:${parts[1]}`;
184
+ }
185
+ return undefined;
186
+ }
187
+ if (entry.module) {
188
+ const parts = entry.module.split(':');
189
+ if (parts.length >= 2) {
190
+ return `${parts[0]}:${parts[1]}`;
191
+ }
192
+ return entry.module;
193
+ }
194
+ if (entry.group && entry.name) {
195
+ return `${entry.group}:${entry.name}`;
196
+ }
197
+ return undefined;
198
+ }
199
+ /**
200
+ * Extracts the version.ref from a library entry, if present.
201
+ * @param {string|object} entry
202
+ * @returns {string|undefined}
203
+ */
204
+ function getVersionRef(entry) {
205
+ if (typeof entry === 'object' && entry.version) {
206
+ if (typeof entry.version === 'object' && entry.version.ref) {
207
+ return entry.version.ref;
208
+ }
209
+ }
210
+ return undefined;
211
+ }
212
+ /**
213
+ * Extracts an inline version string from a library entry.
214
+ * Handles { version = "1.2.3" } and string shorthand "group:artifact:version".
215
+ * @param {string|object} entry
216
+ * @returns {string|undefined}
217
+ */
218
+ function getInlineVersion(entry) {
219
+ if (typeof entry === 'string') {
220
+ const parts = entry.split(':');
221
+ if (parts.length >= 3) {
222
+ return parts[2];
223
+ }
224
+ return undefined;
225
+ }
226
+ if (typeof entry === 'object' && entry.version) {
227
+ if (typeof entry.version === 'string') {
228
+ return entry.version;
229
+ }
230
+ }
231
+ return undefined;
232
+ }
233
+ /**
234
+ * Replaces a version value using position-based string replacement.
235
+ * Targets lines matching: key = "oldVersion"
236
+ * @param {string} content - raw TOML content
237
+ * @param {string} key - version alias key
238
+ * @param {string} oldVersion - current version string
239
+ * @param {string} newVersion - replacement version string
240
+ * @returns {string} updated content
241
+ */
242
+ function replaceVersionInSection(content, key, oldVersion, newVersion) {
243
+ const escapedKey = escapeRegExp(key);
244
+ const escapedOld = escapeRegExp(oldVersion);
245
+ const pattern = new RegExp(`^(\\s*${escapedKey}\\s*=\\s*")${escapedOld}("\\s*)$`, 'm');
246
+ return content.replace(pattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
247
+ }
248
+ /**
249
+ * Replaces an inline version in a library entry.
250
+ * Targets patterns like: version = "oldVersion" or version ="oldVersion"
251
+ * on the line containing the library alias.
252
+ * @param {string} content - raw TOML content
253
+ * @param {string} alias - library alias
254
+ * @param {string} oldVersion - current version string
255
+ * @param {string} newVersion - replacement version string
256
+ * @returns {string} updated content
257
+ */
258
+ function replaceInlineVersion(content, alias, oldVersion, newVersion) {
259
+ const escapedAlias = escapeRegExp(alias);
260
+ const escapedOld = escapeRegExp(oldVersion);
261
+ const pattern = new RegExp(`^(\\s*${escapedAlias}\\s*=\\s*\\{[^}]*version\\s*=\\s*")${escapedOld}("[^}]*\\}\\s*)$`, 'm');
262
+ const result = content.replace(pattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
263
+ if (result !== content) {
264
+ return result;
265
+ }
266
+ const stringPattern = new RegExp(`^(\\s*${escapedAlias}\\s*=\\s*"[^:]+:[^:]+:)${escapedOld}("\\s*)$`, 'm');
267
+ return content.replace(stringPattern, (_, p1, p2) => `${p1}${newVersion}${p2}`);
268
+ }
269
+ /**
270
+ * Escapes special regex characters in a string.
271
+ * @param {string} str
272
+ * @returns {string}
273
+ */
274
+ function escapeRegExp(str) {
275
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
276
+ }
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Resolve ignore globs for workspace discovery: defaults + `TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE` + `opts.workspaceDiscoveryIgnore`.
2
+ * Resolve ignore globs for workspace discovery. Unlike scalar options, ignore patterns are additive:
3
+ * defaults + `opts.TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE`/environment + `opts.workspaceDiscoveryIgnore`.
3
4
  * Patterns are fast-glob / micromatch style, relative to the workspace root (forward slashes).
4
5
  *
5
6
  * @param {{ workspaceDiscoveryIgnore?: string[], TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string, [key: string]: unknown }} [opts={}]
@@ -10,7 +10,8 @@ const DEFAULT_WORKSPACE_DISCOVERY_IGNORE = [
10
10
  '**/.git/**',
11
11
  ];
12
12
  /**
13
- * Resolve ignore globs for workspace discovery: defaults + `TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE` + `opts.workspaceDiscoveryIgnore`.
13
+ * Resolve ignore globs for workspace discovery. Unlike scalar options, ignore patterns are additive:
14
+ * defaults + `opts.TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE`/environment + `opts.workspaceDiscoveryIgnore`.
14
15
  * Patterns are fast-glob / micromatch style, relative to the workspace root (forward slashes).
15
16
  *
16
17
  * @param {{ workspaceDiscoveryIgnore?: string[], TRUSTIFY_DA_WORKSPACE_DISCOVERY_IGNORE?: string, [key: string]: unknown }} [opts={}]
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.ec6824b",
3
+ "version": "0.3.0-ea.efdc87d",
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": "dist/src/cli.js",
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,14 @@
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
- "@babel/core": "^7.23.2",
51
- "@cyclonedx/cyclonedx-library": "^10.0.0",
52
+ "@yarnpkg/parsers": "^3.1.0",
52
53
  "eslint-import-resolver-typescript": "^4.4.4",
53
54
  "fast-glob": "^3.3.3",
54
55
  "fast-xml-parser": "^5.3.4",
@@ -61,25 +62,26 @@
61
62
  "p-limit": "^7.3.0",
62
63
  "packageurl-js": "~1.0.2",
63
64
  "smol-toml": "^1.6.0",
65
+ "tree-sitter-containerfile": "^0.8.1",
64
66
  "tree-sitter-gomod": "github:strum355/tree-sitter-go-mod#56326f2ad478892ace58ff247a97d492a3cbcdda",
65
67
  "tree-sitter-requirements": "github:Strum355/tree-sitter-requirements#d0261ee76b84253997fe70d7d397e78c006c3801",
66
68
  "web-tree-sitter": "^0.26.7",
67
69
  "yargs": "^18.0.0"
68
70
  },
69
71
  "devDependencies": {
70
- "@babel/core": "^7.23.2",
71
- "@trustify-da/trustify-da-api-model": "^2.0.8",
72
+ "@cyclonedx/cyclonedx-library": "^10.2.0",
73
+ "@eslint/js": "^10.0.0",
74
+ "@trustify-da/trustify-da-api-model": "^2.0.12",
72
75
  "@types/node": "^25.9.1",
73
76
  "@types/which": "^3.0.4",
74
- "babel-plugin-rewire": "^1.2.0",
77
+ "ajv": "^8.20.0",
75
78
  "c8": "^11.0.0",
76
79
  "chai": "^6.2.2",
77
- "@eslint/js": "^10.0.0",
78
80
  "eslint": "^10.4.1",
79
81
  "eslint-import-resolver-typescript": "^4.4.4",
80
82
  "eslint-plugin-import-x": "^4.16.2",
81
- "globals": "^17.6.0",
82
83
  "esmock": "^2.6.2",
84
+ "globals": "^17.6.0",
83
85
  "mocha": "^11.7.6",
84
86
  "msw": "^2.12.7",
85
87
  "sinon": "^22.0.0",
@@ -117,6 +119,9 @@
117
119
  "text"
118
120
  ]
119
121
  },
122
+ "overrides": {
123
+ "tree-sitter": "0.22.4"
124
+ },
120
125
  "resolutions": {
121
126
  "@hapi/joi": "17.1.1"
122
127
  }