@cyclonedx/cdxgen 10.1.0 → 10.1.2

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 (52) hide show
  1. package/README.md +7 -0
  2. package/analyzer.js +21 -18
  3. package/bin/cdxgen.js +4 -4
  4. package/bin/evinse.js +2 -2
  5. package/bin/repl.js +4 -4
  6. package/bin/verify.js +1 -1
  7. package/binary.js +3 -3
  8. package/db.js +1 -1
  9. package/docker.js +8 -8
  10. package/docker.test.js +5 -5
  11. package/envcontext.js +6 -6
  12. package/envcontext.test.js +7 -7
  13. package/evinser.js +25 -25
  14. package/index.js +170 -148
  15. package/package.json +15 -11
  16. package/protobom.test.js +2 -2
  17. package/server.js +2 -2
  18. package/types/analyzer.d.ts +5 -0
  19. package/types/analyzer.d.ts.map +1 -0
  20. package/types/binary.d.ts +13 -0
  21. package/types/binary.d.ts.map +1 -0
  22. package/types/cbomutils.d.ts +2 -0
  23. package/types/cbomutils.d.ts.map +1 -0
  24. package/types/db.d.ts +19 -0
  25. package/types/db.d.ts.map +1 -0
  26. package/types/display.d.ts +8 -0
  27. package/types/display.d.ts.map +1 -0
  28. package/types/docker.d.ts +44 -0
  29. package/types/docker.d.ts.map +1 -0
  30. package/types/envcontext.d.ts +61 -0
  31. package/types/envcontext.d.ts.map +1 -0
  32. package/types/evinser.d.ts +728 -0
  33. package/types/evinser.d.ts.map +1 -0
  34. package/types/index.d.ts +48 -0
  35. package/types/index.d.ts.map +1 -0
  36. package/types/jest.config.d.ts +10 -0
  37. package/types/jest.config.d.ts.map +1 -0
  38. package/types/piptree.d.ts +2 -0
  39. package/types/piptree.d.ts.map +1 -0
  40. package/types/postgen.d.ts +3 -0
  41. package/types/postgen.d.ts.map +1 -0
  42. package/types/protobom.d.ts +3 -0
  43. package/types/protobom.d.ts.map +1 -0
  44. package/types/server.d.ts +3 -0
  45. package/types/server.d.ts.map +1 -0
  46. package/types/utils.d.ts +517 -0
  47. package/types/utils.d.ts.map +1 -0
  48. package/types/validator.d.ts +5 -0
  49. package/types/validator.d.ts.map +1 -0
  50. package/utils.js +222 -74
  51. package/utils.test.js +91 -67
  52. package/validator.js +2 -2
package/README.md CHANGED
@@ -540,11 +540,18 @@ Refer to the [permissions document](./docs/PERMISSIONS.md)
540
540
  Follow the usual PR process, but before raising a PR, run the following commands.
541
541
 
542
542
  ```bash
543
+ # Generate types using jsdoc syntax
544
+ npm run gen-types
545
+ # Run eslint with auto fix
543
546
  npm run lint
547
+ # Run prettier
544
548
  npm run pretty
549
+ # Run jest tests
545
550
  npm test
546
551
  ```
547
552
 
553
+ If you are completely new to contributing to open-source projects, then look for [issues](https://github.com/CycloneDX/cdxgen/issues) with the labels "good first issue" or "help wanted".
554
+
548
555
  ## Enterprise support
549
556
 
550
557
  Enterprise support, including custom development and integration services, is available via [AppThreat Ltd](https://www.appthreat.com). Free community support is also available via [Discord](https://discord.gg/tmmtjCEHNV).
package/analyzer.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { parse } from "@babel/parser";
2
2
  import traverse from "@babel/traverse";
3
- import { join } from "node:path";
4
3
  import process from "node:process";
5
- import { readdirSync, lstatSync, readFileSync } from "node:fs";
6
- import { basename, resolve, isAbsolute, relative } from "node:path";
4
+ import { lstatSync, readFileSync, readdirSync } from "node:fs";
5
+ import { basename, isAbsolute, join, relative, resolve } from "node:path";
7
6
 
8
7
  const IGNORE_DIRS = process.env.ASTGEN_IGNORE_DIRS
9
8
  ? process.env.ASTGEN_IGNORE_DIRS.split(",")
@@ -190,21 +189,25 @@ const fileToParseableCode = (file) => {
190
189
  let code = readFileSync(file, "utf-8");
191
190
  if (file.endsWith(".vue") || file.endsWith(".svelte")) {
192
191
  code = code
193
- .replace(vueCommentRegex, function (match) {
194
- return match.replaceAll(/\S/g, " ");
195
- })
196
- .replace(vueCleaningRegex, function (match) {
197
- return match.replaceAll(/\S/g, " ").substring(1) + ";";
198
- })
199
- .replace(vueBindRegex, function (match, grA, grB, grC) {
200
- return grA.replaceAll(/\S/g, " ") + grB + grC.replaceAll(/\S/g, " ");
201
- })
202
- .replace(vuePropRegex, function (match, grA, grB) {
203
- return " " + grA.replace(/[.:@]/g, " ") + grB;
204
- })
205
- .replace(vueTemplateRegex, function (match, grA, grB, grC) {
206
- return grA + grB.replaceAll("{{", "{ ").replaceAll("}}", " }") + grC;
207
- });
192
+ .replace(vueCommentRegex, (match) => match.replaceAll(/\S/g, " "))
193
+ .replace(
194
+ vueCleaningRegex,
195
+ (match) => match.replaceAll(/\S/g, " ").substring(1) + ";"
196
+ )
197
+ .replace(
198
+ vueBindRegex,
199
+ (match, grA, grB, grC) =>
200
+ grA.replaceAll(/\S/g, " ") + grB + grC.replaceAll(/\S/g, " ")
201
+ )
202
+ .replace(
203
+ vuePropRegex,
204
+ (match, grA, grB) => " " + grA.replace(/[.:@]/g, " ") + grB
205
+ )
206
+ .replace(
207
+ vueTemplateRegex,
208
+ (match, grA, grB, grC) =>
209
+ grA + grB.replaceAll("{{", "{ ").replaceAll("}}", " }") + grC
210
+ );
208
211
  }
209
212
  return code;
210
213
  };
package/bin/cdxgen.js CHANGED
@@ -7,16 +7,16 @@ import { tmpdir } from "node:os";
7
7
  import { basename, dirname, join, resolve } from "node:path";
8
8
  import jws from "jws";
9
9
  import crypto from "node:crypto";
10
- import { fileURLToPath, URL } from "node:url";
10
+ import { URL, fileURLToPath } from "node:url";
11
11
  import globalAgent from "global-agent";
12
12
  import process from "node:process";
13
13
  import {
14
14
  printCallStack,
15
+ printDependencyTree,
15
16
  printOccurrences,
16
- printServices,
17
17
  printReachables,
18
- printTable,
19
- printDependencyTree
18
+ printServices,
19
+ printTable
20
20
  } from "../display.js";
21
21
  import { findUpSync } from "find-up";
22
22
  import { load as _load } from "js-yaml";
package/bin/evinse.js CHANGED
@@ -10,8 +10,8 @@ import { validateBom } from "../validator.js";
10
10
  import {
11
11
  printCallStack,
12
12
  printOccurrences,
13
- printServices,
14
- printReachables
13
+ printReachables,
14
+ printServices
15
15
  } from "../display.js";
16
16
  import { ATOM_DB } from "../utils.js";
17
17
  import { findUpSync } from "find-up";
package/bin/repl.js CHANGED
@@ -11,11 +11,11 @@ import { createBom } from "../index.js";
11
11
  import { validateBom } from "../validator.js";
12
12
  import {
13
13
  printCallStack,
14
- printOccurrences,
15
- printOSTable,
16
- printTable,
17
14
  printDependencyTree,
18
- printServices
15
+ printOSTable,
16
+ printOccurrences,
17
+ printServices,
18
+ printTable
19
19
  } from "../display.js";
20
20
 
21
21
  const options = {
package/bin/verify.js CHANGED
@@ -5,7 +5,7 @@ import { hideBin } from "yargs/helpers";
5
5
  import fs from "node:fs";
6
6
  import jws from "jws";
7
7
  import process from "node:process";
8
- import { fileURLToPath, URL } from "node:url";
8
+ import { URL, fileURLToPath } from "node:url";
9
9
  import { dirname, join } from "node:path";
10
10
 
11
11
  let url = import.meta.url;
package/binary.js CHANGED
@@ -1,4 +1,4 @@
1
- import { platform as _platform, arch as _arch, tmpdir, homedir } from "node:os";
1
+ import { arch as _arch, platform as _platform, homedir, tmpdir } from "node:os";
2
2
  import process from "node:process";
3
3
  import { Buffer } from "node:buffer";
4
4
  import {
@@ -8,12 +8,12 @@ import {
8
8
  readFileSync,
9
9
  rmSync
10
10
  } from "node:fs";
11
- import { join, dirname, basename } from "node:path";
11
+ import { basename, dirname, join } from "node:path";
12
12
  import { spawnSync } from "node:child_process";
13
13
  import { PackageURL } from "packageurl-js";
14
14
  import { DEBUG_MODE, TIMEOUT_MS, findLicenseId } from "./utils.js";
15
15
 
16
- import { fileURLToPath, URL } from "node:url";
16
+ import { URL, fileURLToPath } from "node:url";
17
17
 
18
18
  let url = import.meta.url;
19
19
  if (!url.startsWith("file://")) {
package/db.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { Sequelize, DataTypes, Model } from "sequelize";
2
+ import { DataTypes, Model, Sequelize } from "sequelize";
3
3
  import SQLite from "sqlite3";
4
4
 
5
5
  class Namespaces extends Model {}
package/docker.js CHANGED
@@ -5,21 +5,21 @@ import stream from "node:stream/promises";
5
5
  import process from "node:process";
6
6
  import { Buffer } from "node:buffer";
7
7
  import {
8
+ createReadStream,
8
9
  existsSync,
9
- readdirSync,
10
- statSync,
11
10
  lstatSync,
12
- readFileSync,
13
- createReadStream,
14
- mkdtempSync,
15
11
  mkdirSync,
16
- rmSync
12
+ mkdtempSync,
13
+ readFileSync,
14
+ readdirSync,
15
+ rmSync,
16
+ statSync
17
17
  } from "node:fs";
18
18
  import { join } from "node:path";
19
19
  import {
20
+ platform as _platform,
20
21
  userInfo as _userInfo,
21
22
  homedir,
22
- platform as _platform,
23
23
  tmpdir
24
24
  } from "node:os";
25
25
  import { x } from "tar";
@@ -1196,7 +1196,7 @@ export const addSkippedSrcFiles = (skippedImageSrcs, components) => {
1196
1196
  for (const co of components) {
1197
1197
  const srcFileValues = [];
1198
1198
  let srcImageValue;
1199
- co.properties.forEach(function (property) {
1199
+ co.properties.forEach((property) => {
1200
1200
  if (property.name === "oci:SrcImage") {
1201
1201
  srcImageValue = property.value;
1202
1202
  }
package/docker.test.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
+ addSkippedSrcFiles,
3
+ exportImage,
2
4
  getConnection,
3
- parseImageName,
4
5
  getImage,
5
- removeImage,
6
- exportImage,
7
6
  isWin,
8
- addSkippedSrcFiles
7
+ parseImageName,
8
+ removeImage
9
9
  } from "./docker.js";
10
- import { expect, test, describe, beforeEach } from "@jest/globals";
10
+ import { beforeEach, describe, expect, test } from "@jest/globals";
11
11
 
12
12
  test("docker connection", async () => {
13
13
  if (!(isWin && process.env.CI === "true")) {
package/envcontext.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import {
3
- isWin,
4
- PYTHON_CMD,
5
- JAVA_CMD,
3
+ CARGO_CMD,
6
4
  DOTNET_CMD,
7
- NODE_CMD,
8
- NPM_CMD,
9
5
  GCC_CMD,
10
6
  GO_CMD,
7
+ JAVA_CMD,
8
+ NODE_CMD,
9
+ NPM_CMD,
10
+ PYTHON_CMD,
11
11
  RUSTC_CMD,
12
- CARGO_CMD
12
+ isWin
13
13
  } from "./utils.js";
14
14
  import process from "node:process";
15
15
  import { Buffer } from "node:buffer";
@@ -1,16 +1,16 @@
1
1
  import { expect, test } from "@jest/globals";
2
2
 
3
3
  import {
4
- getBranch,
5
- getOriginUrl,
6
- listFiles,
7
- collectJavaInfo,
8
4
  collectDotnetInfo,
9
- collectPythonInfo,
10
- collectNodeInfo,
11
5
  collectGccInfo,
6
+ collectGoInfo,
7
+ collectJavaInfo,
8
+ collectNodeInfo,
9
+ collectPythonInfo,
12
10
  collectRustInfo,
13
- collectGoInfo
11
+ getBranch,
12
+ getOriginUrl,
13
+ listFiles
14
14
  } from "./envcontext.js";
15
15
 
16
16
  test("git tests", () => {
package/evinser.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
+ DEBUG_MODE,
3
+ collectGradleDependencies,
4
+ collectMvnDependencies,
2
5
  executeAtom,
3
6
  getAllFiles,
4
7
  getGradleCommand,
5
- getMavenCommand,
6
- collectGradleDependencies,
7
- collectMvnDependencies,
8
- DEBUG_MODE
8
+ getMavenCommand
9
9
  } from "./utils.js";
10
10
  import { tmpdir } from "node:os";
11
11
  import path from "node:path";
@@ -20,7 +20,7 @@ const typePurlsCache = {};
20
20
  /**
21
21
  * Function to create the db for the libraries referred in the sbom.
22
22
  *
23
- * @param {object} Command line options
23
+ * @param {Object} Command line options
24
24
  */
25
25
  export const prepareDB = async (options) => {
26
26
  if (!options.dbPath.includes("memory") && !fs.existsSync(options.dbPath)) {
@@ -318,8 +318,8 @@ export const initFromSbom = (components, language) => {
318
318
  /**
319
319
  * Function to analyze the project
320
320
  *
321
- * @param {object} dbObjMap DB and model instances
322
- * @param {object} Command line options
321
+ * @param {Object} dbObjMap DB and model instances
322
+ * @param {Object} Command line options
323
323
  */
324
324
  export const analyzeProject = async (dbObjMap, options) => {
325
325
  const dirPath = options._[0] || ".";
@@ -479,11 +479,11 @@ export const parseObjectSlices = async (
479
479
  * https://github.com/AppThreat/atom/blob/main/specification/docs/slices.md#use
480
480
  *
481
481
  * @param {string} language Application language
482
- * @param {object} userDefinedTypesMap User Defined types in the application
483
- * @param {array} usages Usages array for each objectSlice
484
- * @param {object} dbObjMap DB Models
485
- * @param {object} purlLocationMap Object to track locations where purls are used
486
- * @param {object} purlImportsMap Object to track package urls and their import aliases
482
+ * @param {Object} userDefinedTypesMap User Defined types in the application
483
+ * @param {Array} usages Usages array for each objectSlice
484
+ * @param {Object} dbObjMap DB Models
485
+ * @param {Object} purlLocationMap Object to track locations where purls are used
486
+ * @param {Object} purlImportsMap Object to track package urls and their import aliases
487
487
  * @returns
488
488
  */
489
489
  export const parseSliceUsages = async (
@@ -764,8 +764,8 @@ export const isFilterableType = (
764
764
  * Method to detect services from annotation objects in the usage slice
765
765
  *
766
766
  * @param {string} language Application language
767
- * @param {array} usages Usages array for each objectSlice
768
- * @param {object} servicesMap Existing service map
767
+ * @param {Array} usages Usages array for each objectSlice
768
+ * @param {Object} servicesMap Existing service map
769
769
  */
770
770
  export const detectServicesFromUsages = (language, slice, servicesMap = {}) => {
771
771
  const usages = slice.usages;
@@ -830,8 +830,8 @@ export const detectServicesFromUsages = (language, slice, servicesMap = {}) => {
830
830
  * Method to detect services from user defined types in the usage slice
831
831
  *
832
832
  * @param {string} language Application language
833
- * @param {array} userDefinedTypes User defined types
834
- * @param {object} servicesMap Existing service map
833
+ * @param {Array} userDefinedTypes User defined types
834
+ * @param {Object} servicesMap Existing service map
835
835
  */
836
836
  export const detectServicesFromUDT = (
837
837
  language,
@@ -962,8 +962,8 @@ export const extractEndpoints = (language, code) => {
962
962
  /**
963
963
  * Method to create the SBOM with evidence file called evinse file.
964
964
  *
965
- * @param {object} sliceArtefacts Various artefacts from the slice operation
966
- * @param {object} options Command line options
965
+ * @param {Object} sliceArtefacts Various artefacts from the slice operation
966
+ * @param {Object} options Command line options
967
967
  * @returns
968
968
  */
969
969
  export const createEvinseFile = (sliceArtefacts, options) => {
@@ -1085,11 +1085,11 @@ export const createEvinseFile = (sliceArtefacts, options) => {
1085
1085
  * Implemented based on the logic proposed here - https://github.com/AppThreat/atom/blob/main/specification/docs/slices.md#data-flow-slice
1086
1086
  *
1087
1087
  * @param {string} language Application language
1088
- * @param {object} userDefinedTypesMap User Defined types in the application
1089
- * @param {object} dataFlowSlice Data flow slice object from atom
1090
- * @param {object} dbObjMap DB models
1091
- * @param {object} purlLocationMap Object to track locations where purls are used
1092
- * @param {object} purlImportsMap Object to track package urls and their import aliases
1088
+ * @param {Object} userDefinedTypesMap User Defined types in the application
1089
+ * @param {Object} dataFlowSlice Data flow slice object from atom
1090
+ * @param {Object} dbObjMap DB models
1091
+ * @param {Object} purlLocationMap Object to track locations where purls are used
1092
+ * @param {Object} purlImportsMap Object to track package urls and their import aliases
1093
1093
  */
1094
1094
  export const collectDataFlowFrames = async (
1095
1095
  language,
@@ -1212,7 +1212,7 @@ export const collectDataFlowFrames = async (
1212
1212
  * Implemented based on the logic proposed here - https://github.com/AppThreat/atom/blob/main/specification/docs/slices.md#data-flow-slice
1213
1213
  *
1214
1214
  * @param {string} language Application language
1215
- * @param {object} reachablesSlice Reachables slice object from atom
1215
+ * @param {Object} reachablesSlice Reachables slice object from atom
1216
1216
  */
1217
1217
  export const collectReachableFrames = (language, reachablesSlice) => {
1218
1218
  const reachableNodes = reachablesSlice?.reachables || [];
@@ -1253,7 +1253,7 @@ export const collectReachableFrames = (language, reachablesSlice) => {
1253
1253
  /**
1254
1254
  * Method to pick a callstack frame as an evidence. This method is required since CycloneDX 1.5 accepts only a single frame as evidence.
1255
1255
  *
1256
- * @param {array} dfFrames Data flow frames
1256
+ * @param {Array} dfFrames Data flow frames
1257
1257
  * @returns
1258
1258
  */
1259
1259
  export const framePicker = (dfFrames) => {