@herodevs/cli 1.1.0-beta.1 → 1.3.0-beta.1
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 +16 -309
- package/bin/dev.js +6 -5
- package/bin/run.js +3 -2
- package/dist/api/client.d.ts +0 -2
- package/dist/api/client.js +19 -18
- package/dist/api/nes/nes.client.d.ts +10 -3
- package/dist/api/nes/nes.client.js +89 -2
- package/dist/api/queries/nes/sbom.js +5 -0
- package/dist/api/types/hd-cli.types.d.ts +29 -0
- package/dist/api/types/hd-cli.types.js +10 -0
- package/dist/api/types/nes.types.d.ts +39 -22
- package/dist/api/types/nes.types.js +1 -1
- package/dist/commands/report/committers.js +45 -28
- package/dist/commands/report/purls.js +42 -29
- package/dist/commands/scan/eol.d.ts +16 -4
- package/dist/commands/scan/eol.js +144 -41
- package/dist/commands/scan/sbom.d.ts +1 -0
- package/dist/commands/scan/sbom.js +53 -32
- package/dist/service/committers.svc.js +24 -3
- package/dist/service/eol/cdx.svc.d.ts +2 -8
- package/dist/service/eol/cdx.svc.js +2 -18
- package/dist/service/eol/eol.svc.d.ts +1 -23
- package/dist/service/eol/eol.svc.js +0 -61
- package/dist/service/error.svc.d.ts +8 -0
- package/dist/service/error.svc.js +28 -0
- package/dist/service/nes/nes.svc.d.ts +4 -3
- package/dist/service/nes/nes.svc.js +5 -4
- package/dist/service/purls.svc.d.ts +6 -0
- package/dist/service/purls.svc.js +26 -0
- package/dist/ui/date.ui.d.ts +1 -0
- package/dist/ui/date.ui.js +15 -0
- package/dist/ui/eol.ui.d.ts +5 -3
- package/dist/ui/eol.ui.js +56 -15
- package/dist/ui/shared.us.d.ts +3 -0
- package/dist/ui/shared.us.js +13 -0
- package/package.json +10 -9
- package/dist/service/line.svc.d.ts +0 -24
- package/dist/service/line.svc.js +0 -61
|
@@ -3,6 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
4
|
import { Command, Flags, ux } from '@oclif/core';
|
|
5
5
|
import { createSbom, validateIsCycloneDxSbom } from "../../service/eol/eol.svc.js";
|
|
6
|
+
import { getErrorMessage } from "../../service/error.svc.js";
|
|
6
7
|
export default class ScanSbom extends Command {
|
|
7
8
|
static description = 'Scan a SBOM for purls';
|
|
8
9
|
static enableJsonFlag = true;
|
|
@@ -30,6 +31,15 @@ export default class ScanSbom extends Command {
|
|
|
30
31
|
description: 'Run the scan in the background',
|
|
31
32
|
}),
|
|
32
33
|
};
|
|
34
|
+
static async loadSbom(flags, config) {
|
|
35
|
+
const sbomArgs = ScanSbom.getSbomArgs(flags);
|
|
36
|
+
const sbomCommand = new ScanSbom(sbomArgs, config);
|
|
37
|
+
const sbom = await sbomCommand.run();
|
|
38
|
+
if (!sbom) {
|
|
39
|
+
throw new Error('SBOM not generated');
|
|
40
|
+
}
|
|
41
|
+
return sbom;
|
|
42
|
+
}
|
|
33
43
|
static getSbomArgs(flags) {
|
|
34
44
|
const { dir, file, save, json, background } = flags ?? {};
|
|
35
45
|
const sbomArgs = [];
|
|
@@ -37,8 +47,7 @@ export default class ScanSbom extends Command {
|
|
|
37
47
|
sbomArgs.push('--file', file);
|
|
38
48
|
if (dir)
|
|
39
49
|
sbomArgs.push('--dir', dir);
|
|
40
|
-
if (save)
|
|
41
|
-
sbomArgs.push('--save');
|
|
50
|
+
// if (save) sbomArgs.push('--save'); // only save if sbom command is used directly with -s flag
|
|
42
51
|
if (json)
|
|
43
52
|
sbomArgs.push('--json');
|
|
44
53
|
if (background)
|
|
@@ -54,7 +63,7 @@ export default class ScanSbom extends Command {
|
|
|
54
63
|
const { dir, save, file, background } = flags;
|
|
55
64
|
// Validate that exactly one of --file or --dir is provided
|
|
56
65
|
if (file && dir) {
|
|
57
|
-
|
|
66
|
+
this.error('Cannot specify both --file and --dir flags. Please use one or the other.');
|
|
58
67
|
}
|
|
59
68
|
let sbom;
|
|
60
69
|
const path = dir || process.cwd();
|
|
@@ -76,39 +85,53 @@ export default class ScanSbom extends Command {
|
|
|
76
85
|
}
|
|
77
86
|
async _getSbomFromScan(_dirFlag) {
|
|
78
87
|
const dir = resolve(_dirFlag);
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
try {
|
|
89
|
+
if (!fs.existsSync(dir)) {
|
|
90
|
+
this.error(`Directory not found: ${dir}`);
|
|
91
|
+
}
|
|
92
|
+
const stats = fs.statSync(dir);
|
|
93
|
+
if (!stats.isDirectory()) {
|
|
94
|
+
this.error(`Path is not a directory: ${dir}`);
|
|
95
|
+
}
|
|
96
|
+
ux.action.start(`Scanning ${dir}`);
|
|
97
|
+
const options = this.getScanOptions();
|
|
98
|
+
const sbom = await createSbom(dir, options);
|
|
99
|
+
if (!sbom) {
|
|
100
|
+
this.error(`SBOM failed to generate for dir: ${dir}`);
|
|
101
|
+
}
|
|
102
|
+
return sbom;
|
|
81
103
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const sbom = await createSbom(dir, options);
|
|
85
|
-
if (!sbom) {
|
|
86
|
-
throw new Error(`SBOM failed to generate for dir: ${dir}`);
|
|
104
|
+
catch (error) {
|
|
105
|
+
this.error(`Failed to scan directory: ${getErrorMessage(error)}`);
|
|
87
106
|
}
|
|
88
|
-
return sbom;
|
|
89
107
|
}
|
|
90
108
|
_getSbomInBackground(path) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
try {
|
|
110
|
+
const opts = this.getScanOptions();
|
|
111
|
+
const args = [
|
|
112
|
+
JSON.stringify({
|
|
113
|
+
opts,
|
|
114
|
+
path,
|
|
115
|
+
}),
|
|
116
|
+
];
|
|
117
|
+
const workerProcess = spawn('node', [join(import.meta.url, '../../service/eol/sbom.worker.js'), ...args], {
|
|
118
|
+
stdio: 'ignore',
|
|
119
|
+
detached: true,
|
|
120
|
+
env: { ...process.env },
|
|
121
|
+
});
|
|
122
|
+
workerProcess.unref();
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
this.error(`Failed to start background scan: ${getErrorMessage(error)}`);
|
|
126
|
+
}
|
|
104
127
|
}
|
|
105
128
|
_getSbomFromFile(_fileFlag) {
|
|
106
129
|
const file = resolve(_fileFlag);
|
|
107
|
-
if (!fs.existsSync(file)) {
|
|
108
|
-
throw new Error(`SBOM file not found: ${file}`);
|
|
109
|
-
}
|
|
110
|
-
ux.action.start(`Loading sbom from ${file}`);
|
|
111
130
|
try {
|
|
131
|
+
if (!fs.existsSync(file)) {
|
|
132
|
+
this.error(`SBOM file not found: ${file}`);
|
|
133
|
+
}
|
|
134
|
+
ux.action.start(`Loading sbom from ${file}`);
|
|
112
135
|
const fileContent = fs.readFileSync(file, {
|
|
113
136
|
encoding: 'utf8',
|
|
114
137
|
flag: 'r',
|
|
@@ -118,8 +141,7 @@ export default class ScanSbom extends Command {
|
|
|
118
141
|
return sbom;
|
|
119
142
|
}
|
|
120
143
|
catch (error) {
|
|
121
|
-
|
|
122
|
-
throw new Error(`Failed to read or parse SBOM file: ${errorMessage}`);
|
|
144
|
+
this.error(`Failed to read SBOM file: ${getErrorMessage(error)}`);
|
|
123
145
|
}
|
|
124
146
|
}
|
|
125
147
|
_saveSbom(dir, sbom) {
|
|
@@ -131,8 +153,7 @@ export default class ScanSbom extends Command {
|
|
|
131
153
|
}
|
|
132
154
|
}
|
|
133
155
|
catch (error) {
|
|
134
|
-
|
|
135
|
-
this.warn(`Failed to save SBOM: ${errorMessage}`);
|
|
156
|
+
this.error(`Failed to save SBOM: ${getErrorMessage(error)}`);
|
|
136
157
|
}
|
|
137
158
|
}
|
|
138
159
|
}
|
|
@@ -21,7 +21,14 @@ export function parseGitLogOutput(output) {
|
|
|
21
21
|
export function groupCommitsByMonth(entries) {
|
|
22
22
|
const result = {};
|
|
23
23
|
// Group commits by month
|
|
24
|
-
const commitsByMonth =
|
|
24
|
+
const commitsByMonth = entries.reduce((acc, entry) => {
|
|
25
|
+
const monthKey = entry.month;
|
|
26
|
+
if (!acc[monthKey]) {
|
|
27
|
+
acc[monthKey] = [];
|
|
28
|
+
}
|
|
29
|
+
acc[monthKey].push(entry);
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
25
32
|
// Process each month
|
|
26
33
|
for (const [month, commits] of Object.entries(commitsByMonth)) {
|
|
27
34
|
if (!commits) {
|
|
@@ -29,7 +36,14 @@ export function groupCommitsByMonth(entries) {
|
|
|
29
36
|
continue;
|
|
30
37
|
}
|
|
31
38
|
// Count commits per author for this month
|
|
32
|
-
const commitsByAuthor =
|
|
39
|
+
const commitsByAuthor = commits.reduce((acc, entry) => {
|
|
40
|
+
const authorKey = entry.author;
|
|
41
|
+
if (!acc[authorKey]) {
|
|
42
|
+
acc[authorKey] = [];
|
|
43
|
+
}
|
|
44
|
+
acc[authorKey].push(entry);
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
33
47
|
const authorCounts = {};
|
|
34
48
|
for (const [author, authorCommits] of Object.entries(commitsByAuthor)) {
|
|
35
49
|
authorCounts[author] = authorCommits?.length ?? 0;
|
|
@@ -44,7 +58,14 @@ export function groupCommitsByMonth(entries) {
|
|
|
44
58
|
* @returns Object with authors as keys and total commit counts as values
|
|
45
59
|
*/
|
|
46
60
|
export function calculateOverallStats(entries) {
|
|
47
|
-
const commitsByAuthor =
|
|
61
|
+
const commitsByAuthor = entries.reduce((acc, entry) => {
|
|
62
|
+
const authorKey = entry.author;
|
|
63
|
+
if (!acc[authorKey]) {
|
|
64
|
+
acc[authorKey] = [];
|
|
65
|
+
}
|
|
66
|
+
acc[authorKey].push(entry);
|
|
67
|
+
return acc;
|
|
68
|
+
}, {});
|
|
48
69
|
const result = {};
|
|
49
70
|
// Count commits for each author
|
|
50
71
|
for (const author in commitsByAuthor) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CdxGenOptions } from './eol.svc.ts';
|
|
2
2
|
export interface SbomEntry {
|
|
3
3
|
group: string;
|
|
4
4
|
name: string;
|
|
@@ -65,10 +65,4 @@ export declare const SBOM_DEFAULT__OPTIONS: {
|
|
|
65
65
|
* Lazy loads cdxgen (for ESM purposes), scans
|
|
66
66
|
* `directory`, and returns the `bomJson` property.
|
|
67
67
|
*/
|
|
68
|
-
export declare function createBomFromDir(directory: string, opts?: CdxGenOptions): Promise<
|
|
69
|
-
export declare const cdxgen: {
|
|
70
|
-
createBom: CdxCreator | undefined;
|
|
71
|
-
};
|
|
72
|
-
export declare function getCdxGen(): Promise<{
|
|
73
|
-
createBom: CdxCreator | undefined;
|
|
74
|
-
}>;
|
|
68
|
+
export declare function createBomFromDir(directory: string, opts?: CdxGenOptions): Promise<any>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createBom } from '@cyclonedx/cdxgen';
|
|
1
2
|
import { debugLogger } from "../../service/log.svc.js";
|
|
2
3
|
export const SBOM_DEFAULT__OPTIONS = {
|
|
3
4
|
$0: 'cdxgen',
|
|
@@ -58,24 +59,7 @@ export const SBOM_DEFAULT__OPTIONS = {
|
|
|
58
59
|
* `directory`, and returns the `bomJson` property.
|
|
59
60
|
*/
|
|
60
61
|
export async function createBomFromDir(directory, opts = {}) {
|
|
61
|
-
const
|
|
62
|
-
const sbom = await createBom?.(directory, { ...SBOM_DEFAULT__OPTIONS, ...opts });
|
|
62
|
+
const sbom = await createBom(directory, { ...SBOM_DEFAULT__OPTIONS, ...opts });
|
|
63
63
|
debugLogger('Successfully generated SBOM');
|
|
64
64
|
return sbom?.bomJson;
|
|
65
65
|
}
|
|
66
|
-
// use a value holder, for easier mocking
|
|
67
|
-
export const cdxgen = { createBom: undefined };
|
|
68
|
-
export async function getCdxGen() {
|
|
69
|
-
if (cdxgen.createBom) {
|
|
70
|
-
return cdxgen;
|
|
71
|
-
}
|
|
72
|
-
const ogEnv = process.env.NODE_ENV;
|
|
73
|
-
process.env.NODE_ENV = undefined;
|
|
74
|
-
try {
|
|
75
|
-
cdxgen.createBom = (await import('@cyclonedx/cdxgen')).createBom;
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
process.env.NODE_ENV = ogEnv;
|
|
79
|
-
}
|
|
80
|
-
return cdxgen;
|
|
81
|
-
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ScanResult } from '../../api/types/nes.types.ts';
|
|
2
|
-
import type { Line } from '../line.svc.ts';
|
|
3
1
|
import { type Sbom } from './cdx.svc.ts';
|
|
4
2
|
export interface CdxGenOptions {
|
|
5
3
|
projectType?: string[];
|
|
@@ -10,25 +8,5 @@ export interface ScanOptions {
|
|
|
10
8
|
export type CdxCreator = (dir: string, opts: CdxGenOptions) => Promise<{
|
|
11
9
|
bomJson: Sbom;
|
|
12
10
|
}>;
|
|
13
|
-
export declare function createSbom(directory: string, opts?: ScanOptions): Promise<
|
|
11
|
+
export declare function createSbom(directory: string, opts?: ScanOptions): Promise<any>;
|
|
14
12
|
export declare function validateIsCycloneDxSbom(sbom: unknown): asserts sbom is Sbom;
|
|
15
|
-
/**
|
|
16
|
-
* Main function to scan directory and collect SBOM data
|
|
17
|
-
*/
|
|
18
|
-
export declare function scanForEol(sbom: Sbom): Promise<{
|
|
19
|
-
purls: string[];
|
|
20
|
-
scan: ScanResult;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Uses the purls from the sbom to run the scan.
|
|
24
|
-
*/
|
|
25
|
-
export declare function submitScan(purls: string[]): Promise<ScanResult>;
|
|
26
|
-
/**
|
|
27
|
-
* Work in progress; creates "rows" for each component
|
|
28
|
-
* based on the model + the scan result from NES.
|
|
29
|
-
*
|
|
30
|
-
* The idea being that each row can easily be used for
|
|
31
|
-
* processing and/or rendering.
|
|
32
|
-
*/
|
|
33
|
-
export declare function prepareRows(purls: string[], scan: ScanResult): Promise<Line[]>;
|
|
34
|
-
export { cdxgen } from './cdx.svc.ts';
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { NesApolloClient } from "../../api/nes/nes.client.js";
|
|
2
1
|
import { debugLogger } from "../../service/log.svc.js";
|
|
3
|
-
import { getDaysEolFromEolAt, getStatusFromComponent } from "../line.svc.js";
|
|
4
|
-
import { extractPurls } from "../purls.svc.js";
|
|
5
2
|
import { createBomFromDir } from "./cdx.svc.js";
|
|
6
3
|
export async function createSbom(directory, opts = {}) {
|
|
7
4
|
const sbom = await createBomFromDir(directory, opts.cdxgen || {});
|
|
@@ -26,61 +23,3 @@ export function validateIsCycloneDxSbom(sbom) {
|
|
|
26
23
|
throw new Error('Invalid SBOM: missing or invalid components array');
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Main function to scan directory and collect SBOM data
|
|
31
|
-
*/
|
|
32
|
-
export async function scanForEol(sbom) {
|
|
33
|
-
const purls = await extractPurls(sbom);
|
|
34
|
-
const scan = await submitScan(purls);
|
|
35
|
-
return { purls, scan };
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Uses the purls from the sbom to run the scan.
|
|
39
|
-
*/
|
|
40
|
-
export async function submitScan(purls) {
|
|
41
|
-
// NOTE: GRAPHQL_HOST is set in `./bin/dev.js` or tests
|
|
42
|
-
const host = process.env.GRAPHQL_HOST || 'https://api.nes.herodevs.com';
|
|
43
|
-
const path = process.env.GRAPHQL_PATH || '/graphql';
|
|
44
|
-
const url = host + path;
|
|
45
|
-
const client = new NesApolloClient(url);
|
|
46
|
-
const scan = await client.scan.sbom(purls);
|
|
47
|
-
return scan;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Work in progress; creates "rows" for each component
|
|
51
|
-
* based on the model + the scan result from NES.
|
|
52
|
-
*
|
|
53
|
-
* The idea being that each row can easily be used for
|
|
54
|
-
* processing and/or rendering.
|
|
55
|
-
*/
|
|
56
|
-
export async function prepareRows(purls, scan) {
|
|
57
|
-
const lines = [];
|
|
58
|
-
for (const purl of purls) {
|
|
59
|
-
const details = scan.components.get(purl);
|
|
60
|
-
if (!details) {
|
|
61
|
-
// In this case, the purl string is in the generated sbom, but the NES/XEOL api has no data
|
|
62
|
-
// TODO: add UNKNOWN Component Status, create new line, and create flag to show/hide unknown results
|
|
63
|
-
debugLogger(`Unknown status: ${purl}.`);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
const { info } = details;
|
|
67
|
-
// Handle date deserialization from GraphQL
|
|
68
|
-
if (typeof info.eolAt === 'string' && info.eolAt) {
|
|
69
|
-
info.eolAt = new Date(info.eolAt);
|
|
70
|
-
}
|
|
71
|
-
const daysEol = getDaysEolFromEolAt(info.eolAt);
|
|
72
|
-
const status = getStatusFromComponent(details, daysEol);
|
|
73
|
-
const showOk = process.env.SHOW_OK === 'true';
|
|
74
|
-
if (!showOk && status === 'OK') {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
lines.push({
|
|
78
|
-
daysEol,
|
|
79
|
-
info,
|
|
80
|
-
purl,
|
|
81
|
-
status,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
return lines;
|
|
85
|
-
}
|
|
86
|
-
export { cdxgen } from "./cdx.svc.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const isError: (error: unknown) => error is Error;
|
|
2
|
+
export declare const isErrnoException: (error: unknown) => error is NodeJS.ErrnoException;
|
|
3
|
+
export declare const isApolloError: (error: unknown) => error is ApolloError;
|
|
4
|
+
export declare const getErrorMessage: (error: unknown) => string;
|
|
5
|
+
export declare class ApolloError extends Error {
|
|
6
|
+
readonly originalError?: unknown;
|
|
7
|
+
constructor(message: string, original?: unknown);
|
|
8
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const isError = (error) => {
|
|
2
|
+
return error instanceof Error;
|
|
3
|
+
};
|
|
4
|
+
export const isErrnoException = (error) => {
|
|
5
|
+
return isError(error) && 'code' in error;
|
|
6
|
+
};
|
|
7
|
+
export const isApolloError = (error) => {
|
|
8
|
+
return error instanceof ApolloError;
|
|
9
|
+
};
|
|
10
|
+
export const getErrorMessage = (error) => {
|
|
11
|
+
if (isError(error)) {
|
|
12
|
+
return error.message;
|
|
13
|
+
}
|
|
14
|
+
return 'Unknown error';
|
|
15
|
+
};
|
|
16
|
+
export class ApolloError extends Error {
|
|
17
|
+
originalError;
|
|
18
|
+
constructor(message, original) {
|
|
19
|
+
if (isError(original)) {
|
|
20
|
+
super(`${message}: ${original.message}`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
super(`${message}: ${String(original)}`);
|
|
24
|
+
}
|
|
25
|
+
this.name = 'ApolloError';
|
|
26
|
+
this.originalError = original;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NesApolloClient } from '../../api/nes/nes.client.ts';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
2
|
+
import type { ScanInputOptions, ScanResult } from '../../api/types/hd-cli.types.ts';
|
|
3
|
+
import type { InsightsEolScanResult } from '../../api/types/nes.types.ts';
|
|
4
|
+
export declare const buildScanResult: (scan: InsightsEolScanResult) => ScanResult;
|
|
5
|
+
export declare const SbomScanner: (client: NesApolloClient) => (purls: string[], options: ScanInputOptions) => Promise<InsightsEolScanResult>;
|
|
@@ -9,10 +9,12 @@ export const buildScanResult = (scan) => {
|
|
|
9
9
|
components,
|
|
10
10
|
message: scan.message,
|
|
11
11
|
success: true,
|
|
12
|
+
warnings: scan.warnings || [],
|
|
12
13
|
};
|
|
13
14
|
};
|
|
14
|
-
export const SbomScanner = (client) => async (purls) => {
|
|
15
|
-
const
|
|
15
|
+
export const SbomScanner = (client) => async (purls, options) => {
|
|
16
|
+
const { type, page, totalPages, scanId } = options;
|
|
17
|
+
const input = { components: purls, type, page, totalPages, scanId };
|
|
16
18
|
const res = await client.mutate(M_SCAN.gql, { input });
|
|
17
19
|
const scan = res.data?.insights?.scan?.eol;
|
|
18
20
|
if (!scan?.success) {
|
|
@@ -20,6 +22,5 @@ export const SbomScanner = (client) => async (purls) => {
|
|
|
20
22
|
debugLogger('scan failed');
|
|
21
23
|
throw new Error('Failed to provide scan: ');
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
return result;
|
|
25
|
+
return scan;
|
|
25
26
|
};
|
|
@@ -15,3 +15,9 @@ export declare function getPurlOutput(purls: string[], output: string): string;
|
|
|
15
15
|
* Translate an SBOM to a list of purls for api request.
|
|
16
16
|
*/
|
|
17
17
|
export declare function extractPurls(sbom: Sbom): Promise<string[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a purls file in either JSON or text format, including the format of
|
|
20
|
+
* nes.purls.json - { purls: [ 'pkg:npm/express@4.18.2', 'pkg:npm/react@18.3.1' ] }
|
|
21
|
+
* or a text file with one purl per line.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parsePurlsFile(purlsFileString: string): string[];
|
|
@@ -27,3 +27,29 @@ export async function extractPurls(sbom) {
|
|
|
27
27
|
const { components: comps } = sbom;
|
|
28
28
|
return comps.map((c) => c.purl) ?? [];
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse a purls file in either JSON or text format, including the format of
|
|
32
|
+
* nes.purls.json - { purls: [ 'pkg:npm/express@4.18.2', 'pkg:npm/react@18.3.1' ] }
|
|
33
|
+
* or a text file with one purl per line.
|
|
34
|
+
*/
|
|
35
|
+
export function parsePurlsFile(purlsFileString) {
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(purlsFileString);
|
|
38
|
+
if (parsed && Array.isArray(parsed.purls)) {
|
|
39
|
+
return parsed.purls;
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(parsed)) {
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
const lines = purlsFileString
|
|
47
|
+
.split('\n')
|
|
48
|
+
.map((line) => line.trim())
|
|
49
|
+
.filter((line) => line.length > 0 && line.startsWith('pkg:'));
|
|
50
|
+
if (lines.length > 0) {
|
|
51
|
+
return lines;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new Error('Invalid purls file: must be either JSON with purls array or text file with one purl per line');
|
|
55
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseMomentToSimpleDate(momentDate: string | Date | number | null): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function parseMomentToSimpleDate(momentDate) {
|
|
2
|
+
// Only return empty string for null
|
|
3
|
+
if (momentDate === null)
|
|
4
|
+
return '';
|
|
5
|
+
try {
|
|
6
|
+
const dateObj = new Date(momentDate);
|
|
7
|
+
if (Number.isNaN(dateObj.getTime())) {
|
|
8
|
+
throw new Error('Invalid date');
|
|
9
|
+
}
|
|
10
|
+
return dateObj.toISOString().split('T')[0];
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw new Error('Invalid date');
|
|
14
|
+
}
|
|
15
|
+
}
|
package/dist/ui/eol.ui.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
export declare function
|
|
1
|
+
import type { ScanResultComponentsMap } from '../api/types/hd-cli.types.ts';
|
|
2
|
+
import type { ComponentStatus } from '../api/types/nes.types.ts';
|
|
3
|
+
export declare function truncatePurl(purl: string): string;
|
|
4
|
+
export declare function colorizeStatus(status: ComponentStatus): string;
|
|
5
|
+
export declare function createStatusDisplay(components: ScanResultComponentsMap, all: boolean): Record<ComponentStatus, string[]>;
|
package/dist/ui/eol.ui.js
CHANGED
|
@@ -1,17 +1,58 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import { parseMomentToSimpleDate } from "./date.ui.js";
|
|
3
|
+
import { INDICATORS, STATUS_COLORS } from "./shared.us.js";
|
|
4
|
+
export function truncatePurl(purl) {
|
|
5
|
+
return purl.length > 60 ? `${purl.slice(0, 57)}...` : purl;
|
|
6
|
+
}
|
|
7
|
+
export function colorizeStatus(status) {
|
|
8
|
+
return ux.colorize(STATUS_COLORS[status], status);
|
|
9
|
+
}
|
|
10
|
+
function formatSimpleComponent(purl, status) {
|
|
11
|
+
const color = STATUS_COLORS[status];
|
|
12
|
+
return ` ${INDICATORS[status]} ${ux.colorize(color, truncatePurl(purl))}`;
|
|
13
|
+
}
|
|
14
|
+
function getDaysEolString(daysEol) {
|
|
15
|
+
// UNKNOWN || OK
|
|
16
|
+
if (daysEol === null) {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
// LTS
|
|
20
|
+
if (daysEol < 0) {
|
|
21
|
+
return `${Math.abs(daysEol)} days from now`;
|
|
22
|
+
}
|
|
23
|
+
// EOL
|
|
24
|
+
if (daysEol === 0) {
|
|
25
|
+
return 'today';
|
|
26
|
+
}
|
|
27
|
+
return `${daysEol} days ago`;
|
|
28
|
+
}
|
|
29
|
+
function formatDetailedComponent(purl, eolAt, daysEol, status) {
|
|
30
|
+
const simpleComponent = formatSimpleComponent(purl, status);
|
|
31
|
+
const eolAtString = parseMomentToSimpleDate(eolAt);
|
|
32
|
+
const daysEolString = getDaysEolString(daysEol);
|
|
33
|
+
const output = [`${simpleComponent}`, ` ⮑ EOL Date: ${eolAtString} (${daysEolString})`]
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join('\n');
|
|
36
|
+
return output;
|
|
37
|
+
}
|
|
38
|
+
export function createStatusDisplay(components, all) {
|
|
39
|
+
const statusOutput = {
|
|
40
|
+
UNKNOWN: [],
|
|
41
|
+
OK: [],
|
|
42
|
+
LTS: [],
|
|
43
|
+
EOL: [],
|
|
7
44
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
45
|
+
// Single loop to separate and format components
|
|
46
|
+
for (const [purl, component] of components.entries()) {
|
|
47
|
+
const { status, eolAt, daysEol } = component.info;
|
|
48
|
+
if (all) {
|
|
49
|
+
if (status === 'UNKNOWN' || status === 'OK') {
|
|
50
|
+
statusOutput[status].push(formatSimpleComponent(purl, status));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (status === 'LTS' || status === 'EOL') {
|
|
54
|
+
statusOutput[status].push(formatDetailedComponent(purl, eolAt, daysEol, status));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return statusOutput;
|
|
17
58
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
export const STATUS_COLORS = {
|
|
3
|
+
EOL: 'red',
|
|
4
|
+
UNKNOWN: 'default',
|
|
5
|
+
OK: 'green',
|
|
6
|
+
LTS: 'yellow',
|
|
7
|
+
};
|
|
8
|
+
export const INDICATORS = {
|
|
9
|
+
EOL: ux.colorize(STATUS_COLORS.EOL, '✗'),
|
|
10
|
+
UNKNOWN: ux.colorize(STATUS_COLORS.UNKNOWN, '•'),
|
|
11
|
+
OK: ux.colorize(STATUS_COLORS.OK, '✔'),
|
|
12
|
+
LTS: ux.colorize(STATUS_COLORS.LTS, '⚡'),
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herodevs/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-beta.1",
|
|
4
4
|
"author": "HeroDevs, Inc",
|
|
5
5
|
"bin": {
|
|
6
6
|
"hd": "./bin/run.js"
|
|
@@ -19,16 +19,17 @@
|
|
|
19
19
|
"clean": "shx rm -rf dist && npm run clean:files && shx rm -rf node_modules",
|
|
20
20
|
"clean:files": "shx rm -f nes.**.csv nes.**.json nes.**.text",
|
|
21
21
|
"dev": "npm run build && ./bin/dev.js",
|
|
22
|
-
"dev:debug": "npm run build && DEBUG
|
|
22
|
+
"dev:debug": "npm run build && DEBUG=oclif:* ./bin/dev.js",
|
|
23
23
|
"format": "biome format --write",
|
|
24
24
|
"lint": "biome lint --write",
|
|
25
25
|
"postpack": "shx rm -f oclif.manifest.json",
|
|
26
26
|
"prepack": "oclif manifest && oclif readme",
|
|
27
27
|
"pretest": "npm run lint && npm run typecheck",
|
|
28
28
|
"readme": "npm run ci:fix && npm run build && npm exec oclif readme",
|
|
29
|
-
"test": "
|
|
29
|
+
"test": "globstar -- node --import tsx --test \"test/**/*.test.ts\"",
|
|
30
30
|
"typecheck": "tsc --noEmit",
|
|
31
|
-
"version": "oclif readme && git add README.md"
|
|
31
|
+
"version": "oclif readme && git add README.md",
|
|
32
|
+
"test:e2e": "globstar -- node --import tsx --test \"e2e/**/*.test.ts\""
|
|
32
33
|
},
|
|
33
34
|
"keywords": [
|
|
34
35
|
"herodevs",
|
|
@@ -37,12 +38,10 @@
|
|
|
37
38
|
],
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@apollo/client": "^3.13.1",
|
|
40
|
-
"@cyclonedx/cdxgen": "^11.2.
|
|
41
|
+
"@cyclonedx/cdxgen": "^11.2.3",
|
|
41
42
|
"@oclif/core": "^4",
|
|
42
43
|
"@oclif/plugin-help": "^6",
|
|
43
|
-
"
|
|
44
|
-
"graphql": "^16.8.1",
|
|
45
|
-
"inquirer": "^12.5.0"
|
|
44
|
+
"graphql": "^16.8.1"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@biomejs/biome": "^1.8.3",
|
|
@@ -50,14 +49,16 @@
|
|
|
50
49
|
"@types/inquirer": "^9.0.7",
|
|
51
50
|
"@types/node": "^22",
|
|
52
51
|
"@types/sinon": "^17.0.4",
|
|
52
|
+
"globstar": "^1.0.0",
|
|
53
53
|
"oclif": "^4",
|
|
54
54
|
"shx": "^0.3.3",
|
|
55
55
|
"sinon": "^19.0.2",
|
|
56
56
|
"ts-node": "^10",
|
|
57
|
+
"tsx": "^4.19.3",
|
|
57
58
|
"typescript": "^5.8.0"
|
|
58
59
|
},
|
|
59
60
|
"engines": {
|
|
60
|
-
"node": ">=
|
|
61
|
+
"node": ">=20.0.0"
|
|
61
62
|
},
|
|
62
63
|
"files": [
|
|
63
64
|
"./bin",
|