@trustify-da/trustify-da-javascript-client 0.3.0-ea.243eaef → 0.3.0-ea.24dd325

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.
@@ -6,24 +6,22 @@
6
6
  */
7
7
  export function logValueFromObjects(key: string, opts?: {}, defValue: string): void;
8
8
  /**
9
- * Utility function will return the value for key from the environment variables,
10
- * if not present will return the value for key from the opts objects only if it's a string,
11
- * if not present, or not string will return the default value supplied which default to null.
9
+ * Utility function returns the value for key from opts, then environment variables,
10
+ * then the supplied default. Values from opts are used only if they are strings.
12
11
  * @param {string} key the key to look for in the environment variables and the opts object
13
12
  * @param {string|null} [def=null] the value to return if nothing else found
14
- * @param {{}} [opts={}] the options object to look for the key in if not found in environment
15
- * @returns {string|null} the value of the key found in the environment, options object, or the
13
+ * @param {{}} [opts={}] the options object to check before the environment
14
+ * @returns {string|null} the value of the key found in the options object, environment, or the
16
15
  * default supplied
17
16
  */
18
17
  export function getCustom(key: string, def?: string | null, opts?: {}): string | null;
19
18
  /**
20
19
  * Utility function for looking up custom variable for a binary path.
21
- * Will look in the environment variables (1) or in opts (2) for a key with TRUSTIFY_DA_x_PATH, x is an
22
- * uppercase version of passed name to look for. The name will also be returned if nothing else was
23
- * found.
20
+ * Looks in opts, then environment variables, for a key with TRUSTIFY_DA_x_PATH, where x is an
21
+ * uppercase version of the supplied name. The name is returned if neither contains the key.
24
22
  * @param name the binary name to look for, will be returned as value in nothing else found
25
- * @param {{}} [opts={}] the options object to look for the key in if not found in environment
26
- * @returns {string|null} the value of the key found in the environment, options object, or the
23
+ * @param {{}} [opts={}] the options object to check before the environment
24
+ * @returns {string|null} the value of the key found in the options object, environment, or the
27
25
  * original name supplied
28
26
  */
29
27
  export function getCustomPath(name: any, opts?: {}): string | null;
@@ -31,7 +29,7 @@ export function getCustomPath(name: any, opts?: {}): string | null;
31
29
  * Utility function for determining whether wrappers for build tools such as gradlew/mvnw should be
32
30
  * preferred over invoking the binary directly.
33
31
  * @param {string} name - binary for which to search for its wrapper
34
- * @param {{}} opts - the options object to look for the key in if not found in environment
32
+ * @param {{}} opts - the options object to check before the environment
35
33
  * @returns {boolean} whether to prefer the wrapper if exists or not
36
34
  */
37
35
  export function getWrapperPreference(name: string, opts?: {}): boolean;
package/dist/src/tools.js CHANGED
@@ -27,20 +27,19 @@ export function logValueFromObjects(key, opts, defValue) {
27
27
  console.log(`default value for ${key} = ${defValue} ${EOL}`);
28
28
  }
29
29
  /**
30
- * Utility function will return the value for key from the environment variables,
31
- * if not present will return the value for key from the opts objects only if it's a string,
32
- * if not present, or not string will return the default value supplied which default to null.
30
+ * Utility function returns the value for key from opts, then environment variables,
31
+ * then the supplied default. Values from opts are used only if they are strings.
33
32
  * @param {string} key the key to look for in the environment variables and the opts object
34
33
  * @param {string|null} [def=null] the value to return if nothing else found
35
- * @param {{}} [opts={}] the options object to look for the key in if not found in environment
36
- * @returns {string|null} the value of the key found in the environment, options object, or the
34
+ * @param {{}} [opts={}] the options object to check before the environment
35
+ * @returns {string|null} the value of the key found in the options object, environment, or the
37
36
  * default supplied
38
37
  */
39
38
  export function getCustom(key, def = null, opts = {}) {
40
39
  if (process.env["TRUSTIFY_DA_DEBUG"] === "true" && !key.match(RegexNotToBeLogged)) {
41
40
  logValueFromObjects(key, opts, def);
42
41
  }
43
- return key in process.env ? process.env[key] : key in opts && typeof opts[key] === 'string' ? opts[key] : def;
42
+ return key in opts && typeof opts[key] === 'string' ? opts[key] : key in process.env ? process.env[key] : def;
44
43
  }
45
44
  /**
46
45
  * Validates that an executable path does not use directory traversal or relative segments.
@@ -66,12 +65,11 @@ function validateExecutablePath(binPath) {
66
65
  }
67
66
  /**
68
67
  * Utility function for looking up custom variable for a binary path.
69
- * Will look in the environment variables (1) or in opts (2) for a key with TRUSTIFY_DA_x_PATH, x is an
70
- * uppercase version of passed name to look for. The name will also be returned if nothing else was
71
- * found.
68
+ * Looks in opts, then environment variables, for a key with TRUSTIFY_DA_x_PATH, where x is an
69
+ * uppercase version of the supplied name. The name is returned if neither contains the key.
72
70
  * @param name the binary name to look for, will be returned as value in nothing else found
73
- * @param {{}} [opts={}] the options object to look for the key in if not found in environment
74
- * @returns {string|null} the value of the key found in the environment, options object, or the
71
+ * @param {{}} [opts={}] the options object to check before the environment
72
+ * @returns {string|null} the value of the key found in the options object, environment, or the
75
73
  * original name supplied
76
74
  */
77
75
  export function getCustomPath(name, opts = {}) {
@@ -82,7 +80,7 @@ export function getCustomPath(name, opts = {}) {
82
80
  * Utility function for determining whether wrappers for build tools such as gradlew/mvnw should be
83
81
  * preferred over invoking the binary directly.
84
82
  * @param {string} name - binary for which to search for its wrapper
85
- * @param {{}} opts - the options object to look for the key in if not found in environment
83
+ * @param {{}} opts - the options object to check before the environment
86
84
  * @returns {boolean} whether to prefer the wrapper if exists or not
87
85
  */
88
86
  export function getWrapperPreference(name, opts = {}) {
@@ -1,3 +1,23 @@
1
+ /**
2
+ * One entry in {@link updateMavenVersions}' `applied` list: a version that was changed and
3
+ * where. `type` discriminates the edit site — `'direct'` for a dependency's own `<version>`,
4
+ * `'property'` for a `${property}` reference (then `property` names the resolved property).
5
+ * @typedef {{
6
+ * groupId: string,
7
+ * artifactId: string,
8
+ * newVersion: string,
9
+ * type: ('direct'|'property'),
10
+ * property?: string
11
+ * }} MavenAppliedChange
12
+ */
13
+ /**
14
+ * Stable edit-site key for a Maven change: same key => same commit/PR. Deps whose versions
15
+ * resolve to one `${property}` share the property key and are therefore inseparable.
16
+ * @param {string} manifestPath
17
+ * @param {MavenAppliedChange} applied
18
+ * @returns {string}
19
+ */
20
+ export function mavenChangeKey(manifestPath: string, applied: MavenAppliedChange): string;
1
21
  /**
2
22
  * Updates dependency versions in a Maven pom.xml while preserving file formatting.
3
23
  *
@@ -10,17 +30,29 @@
10
30
  * and updates the terminal property value in `<properties>` instead.
11
31
  *
12
32
  * @param {string} pomContent - the raw pom.xml file content
13
- * @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges -
14
- * list of version changes to apply
15
- * @returns {{content: string, applied: Array, skipped: Array}} the updated content and
33
+ * @param {import('../remediate.js').VersionChangeRequest[]} versionChanges - list of version changes to apply
34
+ * @returns {{content: string, applied: MavenAppliedChange[], skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}} the updated content and
16
35
  * lists of applied and skipped changes
17
36
  */
18
- export function updateMavenVersions(pomContent: string, versionChanges: Array<{
37
+ export function updateMavenVersions(pomContent: string, versionChanges: import("../remediate.js").VersionChangeRequest[]): {
38
+ content: string;
39
+ applied: MavenAppliedChange[];
40
+ skipped: Array<{
41
+ groupId: string;
42
+ artifactId: string;
43
+ newVersion: string;
44
+ reason: string;
45
+ }>;
46
+ };
47
+ /**
48
+ * One entry in {@link updateMavenVersions}' `applied` list: a version that was changed and
49
+ * where. `type` discriminates the edit site — `'direct'` for a dependency's own `<version>`,
50
+ * `'property'` for a `${property}` reference (then `property` names the resolved property).
51
+ */
52
+ export type MavenAppliedChange = {
19
53
  groupId: string;
20
54
  artifactId: string;
21
55
  newVersion: string;
22
- }>): {
23
- content: string;
24
- applied: any[];
25
- skipped: any[];
56
+ type: ("direct" | "property");
57
+ property?: string;
26
58
  };
@@ -160,6 +160,30 @@ function resolvePropertyChain(propName, properties, visited = new Set()) {
160
160
  }
161
161
  return { terminalPropName: propName, resolvedValue: valueStr };
162
162
  }
163
+ /**
164
+ * One entry in {@link updateMavenVersions}' `applied` list: a version that was changed and
165
+ * where. `type` discriminates the edit site — `'direct'` for a dependency's own `<version>`,
166
+ * `'property'` for a `${property}` reference (then `property` names the resolved property).
167
+ * @typedef {{
168
+ * groupId: string,
169
+ * artifactId: string,
170
+ * newVersion: string,
171
+ * type: ('direct'|'property'),
172
+ * property?: string
173
+ * }} MavenAppliedChange
174
+ */
175
+ /**
176
+ * Stable edit-site key for a Maven change: same key => same commit/PR. Deps whose versions
177
+ * resolve to one `${property}` share the property key and are therefore inseparable.
178
+ * @param {string} manifestPath
179
+ * @param {MavenAppliedChange} applied
180
+ * @returns {string}
181
+ */
182
+ export function mavenChangeKey(manifestPath, applied) {
183
+ return applied.type === 'property'
184
+ ? `mvn:prop:${manifestPath}:${applied.property}`
185
+ : `mvn:direct:${manifestPath}:${applied.groupId}:${applied.artifactId}`;
186
+ }
163
187
  /**
164
188
  * Updates dependency versions in a Maven pom.xml while preserving file formatting.
165
189
  *
@@ -172,9 +196,8 @@ function resolvePropertyChain(propName, properties, visited = new Set()) {
172
196
  * and updates the terminal property value in `<properties>` instead.
173
197
  *
174
198
  * @param {string} pomContent - the raw pom.xml file content
175
- * @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges -
176
- * list of version changes to apply
177
- * @returns {{content: string, applied: Array, skipped: Array}} the updated content and
199
+ * @param {import('../remediate.js').VersionChangeRequest[]} versionChanges - list of version changes to apply
200
+ * @returns {{content: string, applied: MavenAppliedChange[], skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}} the updated content and
178
201
  * lists of applied and skipped changes
179
202
  */
180
203
  export function updateMavenVersions(pomContent, versionChanges) {
@@ -1,3 +1,26 @@
1
+ /**
2
+ * One entry in {@link updateTomlVersions}' `applied` list: a version that was changed and where.
3
+ * `type` discriminates the edit site — `'ref'` for a `[libraries]` entry pointing at a shared
4
+ * `[versions]` alias via `version.ref` (then `versionRef` names that alias), `'inline'` for a
5
+ * version declared directly on the library. `alias` is the library's catalog key in both cases.
6
+ * @typedef {{
7
+ * groupId: string,
8
+ * artifactId: string,
9
+ * newVersion: string,
10
+ * oldVersion: string,
11
+ * type: ('ref'|'inline'),
12
+ * alias: string,
13
+ * versionRef?: string
14
+ * }} TomlAppliedChange
15
+ */
16
+ /**
17
+ * Stable edit-site key for a TOML (Gradle version catalog) change: same key => same commit/PR.
18
+ * Deps sharing one `[versions]` alias via `version.ref` share the ref key and are inseparable.
19
+ * @param {string} manifestPath
20
+ * @param {TomlAppliedChange} applied
21
+ * @returns {string}
22
+ */
23
+ export function tomlChangeKey(manifestPath: string, applied: TomlAppliedChange): string;
1
24
  /**
2
25
  * Updates dependency versions in a Gradle version catalog (libs.versions.toml) file.
3
26
  *
@@ -9,21 +32,12 @@
9
32
  * on the raw content to preserve formatting and comments.
10
33
  *
11
34
  * @param {string} tomlContent - raw TOML file content
12
- * @param {Array<{groupId: string, artifactId: string, newVersion: string}>} versionChanges
13
- * @returns {{content: string, applied: Array<{groupId: string, artifactId: string, newVersion: string, oldVersion: string}>, skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}}
35
+ * @param {import('../remediate.js').VersionChangeRequest[]} versionChanges
36
+ * @returns {{content: string, applied: TomlAppliedChange[], skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}}
14
37
  */
15
- export function updateTomlVersions(tomlContent: string, versionChanges: Array<{
16
- groupId: string;
17
- artifactId: string;
18
- newVersion: string;
19
- }>): {
38
+ export function updateTomlVersions(tomlContent: string, versionChanges: import("../remediate.js").VersionChangeRequest[]): {
20
39
  content: string;
21
- applied: Array<{
22
- groupId: string;
23
- artifactId: string;
24
- newVersion: string;
25
- oldVersion: string;
26
- }>;
40
+ applied: TomlAppliedChange[];
27
41
  skipped: Array<{
28
42
  groupId: string;
29
43
  artifactId: string;
@@ -31,3 +45,18 @@ export function updateTomlVersions(tomlContent: string, versionChanges: Array<{
31
45
  reason: string;
32
46
  }>;
33
47
  };
48
+ /**
49
+ * One entry in {@link updateTomlVersions}' `applied` list: a version that was changed and where.
50
+ * `type` discriminates the edit site — `'ref'` for a `[libraries]` entry pointing at a shared
51
+ * `[versions]` alias via `version.ref` (then `versionRef` names that alias), `'inline'` for a
52
+ * version declared directly on the library. `alias` is the library's catalog key in both cases.
53
+ */
54
+ export type TomlAppliedChange = {
55
+ groupId: string;
56
+ artifactId: string;
57
+ newVersion: string;
58
+ oldVersion: string;
59
+ type: ("ref" | "inline");
60
+ alias: string;
61
+ versionRef?: string;
62
+ };
@@ -1,4 +1,31 @@
1
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
+ }
2
29
  /**
3
30
  * Updates dependency versions in a Gradle version catalog (libs.versions.toml) file.
4
31
  *
@@ -10,8 +37,8 @@ import { parse as parseToml } from 'smol-toml';
10
37
  * on the raw content to preserve formatting and comments.
11
38
  *
12
39
  * @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}>}}
40
+ * @param {import('../remediate.js').VersionChangeRequest[]} versionChanges
41
+ * @returns {{content: string, applied: TomlAppliedChange[], skipped: Array<{groupId: string, artifactId: string, newVersion: string, reason: string}>}}
15
42
  */
16
43
  export function updateTomlVersions(tomlContent, versionChanges) {
17
44
  const applied = [];
@@ -77,7 +104,10 @@ export function updateTomlVersions(tomlContent, versionChanges) {
77
104
  groupId: change.groupId,
78
105
  artifactId: change.artifactId,
79
106
  newVersion: change.newVersion,
80
- oldVersion
107
+ oldVersion,
108
+ type: 'ref',
109
+ versionRef,
110
+ alias
81
111
  });
82
112
  }
83
113
  else {
@@ -107,7 +137,9 @@ export function updateTomlVersions(tomlContent, versionChanges) {
107
137
  groupId: change.groupId,
108
138
  artifactId: change.artifactId,
109
139
  newVersion: change.newVersion,
110
- oldVersion: inlineVersion
140
+ oldVersion: inlineVersion,
141
+ type: 'inline',
142
+ alias
111
143
  });
112
144
  }
113
145
  else {
@@ -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.243eaef",
3
+ "version": "0.3.0-ea.24dd325",
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",
@@ -49,7 +49,6 @@
49
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"
50
50
  },
51
51
  "dependencies": {
52
- "@babel/core": "^7.23.2",
53
52
  "@yarnpkg/parsers": "^3.1.0",
54
53
  "eslint-import-resolver-typescript": "^4.4.4",
55
54
  "fast-glob": "^3.3.3",
@@ -70,14 +69,12 @@
70
69
  "yargs": "^18.0.0"
71
70
  },
72
71
  "devDependencies": {
73
- "@babel/core": "^7.23.2",
74
72
  "@cyclonedx/cyclonedx-library": "^10.2.0",
75
73
  "@eslint/js": "^10.0.0",
76
74
  "@trustify-da/trustify-da-api-model": "^2.0.12",
77
75
  "@types/node": "^25.9.1",
78
76
  "@types/which": "^3.0.4",
79
77
  "ajv": "^8.20.0",
80
- "babel-plugin-rewire": "^1.2.0",
81
78
  "c8": "^11.0.0",
82
79
  "chai": "^6.2.2",
83
80
  "eslint": "^10.4.1",