@gitguard/cli 1.1.0
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/LICENSE +21 -0
- package/README.md +356 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +135 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +26 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/scan.d.ts +14 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +85 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/whoami.d.ts +2 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +46 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api-client.d.ts +21 -0
- package/dist/lib/api-client.d.ts.map +1 -0
- package/dist/lib/api-client.js +54 -0
- package/dist/lib/api-client.js.map +1 -0
- package/dist/lib/config.d.ts +19 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +93 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/file-scanner.d.ts +6 -0
- package/dist/lib/file-scanner.d.ts.map +1 -0
- package/dist/lib/file-scanner.js +131 -0
- package/dist/lib/file-scanner.js.map +1 -0
- package/dist/lib/repo-detector.d.ts +6 -0
- package/dist/lib/repo-detector.d.ts.map +1 -0
- package/dist/lib/repo-detector.js +116 -0
- package/dist/lib/repo-detector.js.map +1 -0
- package/dist/lib/reporter.d.ts +18 -0
- package/dist/lib/reporter.d.ts.map +1 -0
- package/dist/lib/reporter.js +178 -0
- package/dist/lib/reporter.js.map +1 -0
- package/dist/types/index.d.ts +70 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whoami.d.ts","sourceRoot":"","sources":["../../src/commands/whoami.ts"],"names":[],"mappings":"AAIA,wBAAsB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAwCnD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whoamiCommand = whoamiCommand;
|
|
4
|
+
const config_1 = require("../lib/config");
|
|
5
|
+
const api_client_1 = require("../lib/api-client");
|
|
6
|
+
const reporter_1 = require("../lib/reporter");
|
|
7
|
+
async function whoamiCommand() {
|
|
8
|
+
const config = new config_1.ConfigManager();
|
|
9
|
+
const reporter = new reporter_1.Reporter(config);
|
|
10
|
+
const apiClient = new api_client_1.APIClient(config);
|
|
11
|
+
if (!config.isAuthenticated()) {
|
|
12
|
+
reporter.warning('Not logged in');
|
|
13
|
+
reporter.info('Run "gitguard login" to authenticate');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const profile = await apiClient.getProfile();
|
|
18
|
+
console.log(`Email: ${profile.email}`);
|
|
19
|
+
console.log(`Subscription: ${profile.subscription}`);
|
|
20
|
+
console.log(`\nDaily Scans:`);
|
|
21
|
+
console.log(` Limit: ${profile.limits.dailyScans}`);
|
|
22
|
+
console.log(` Remaining: ${profile.limits.scansRemaining}`);
|
|
23
|
+
console.log(` Resets: ${new Date(profile.limits.resetsAt).toLocaleString()}`);
|
|
24
|
+
if (profile.subscription !== 'free') {
|
|
25
|
+
console.log(`\nDefault Scan Settings:`);
|
|
26
|
+
console.log(` AI Analysis: ${profile.preferences.aiScanEnabled ? '✓ Enabled' : '✗ Disabled'}`);
|
|
27
|
+
if (profile.subscription === 'premier') {
|
|
28
|
+
console.log(` Dependency Scanning: ${profile.preferences.dependencyScanEnabled ? '✓ Enabled' : '✗ Disabled'}`);
|
|
29
|
+
console.log(` Secret Detection: ${profile.preferences.secretScanEnabled ? '✓ Enabled' : '✗ Disabled'}`);
|
|
30
|
+
}
|
|
31
|
+
console.log(`\nUse --ai, --dependencies, or --secrets to override these defaults.`);
|
|
32
|
+
console.log(`Use --no-ai, --no-dependencies, or --no-secrets to disable features.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.response?.status === 401) {
|
|
37
|
+
reporter.error('Authentication expired. Please login again.');
|
|
38
|
+
config.clearAuth();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
reporter.error('Failed to fetch profile');
|
|
42
|
+
}
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=whoami.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"whoami.js","sourceRoot":"","sources":["../../src/commands/whoami.ts"],"names":[],"mappings":";;AAIA,sCAwCC;AA5CD,0CAA8C;AAC9C,kDAA8C;AAC9C,8CAA2C;AAEpC,KAAK,UAAU,aAAa;IACjC,MAAM,MAAM,GAAG,IAAI,sBAAa,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAI,mBAAQ,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,MAAM,CAAC,CAAC;IAExC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;QAC9B,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAClC,QAAQ,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACtD,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,CAAC;QAE7C,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACvC,OAAO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,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YAC9D,MAAM,CAAC,SAAS,EAAE,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const login_1 = require("./commands/login");
|
|
6
|
+
const logout_1 = require("./commands/logout");
|
|
7
|
+
const whoami_1 = require("./commands/whoami");
|
|
8
|
+
const scan_1 = require("./commands/scan");
|
|
9
|
+
const program = new commander_1.Command();
|
|
10
|
+
program
|
|
11
|
+
.name('gitguard')
|
|
12
|
+
.description('GitGuard CLI - Security scanning for developers')
|
|
13
|
+
.version('1.0.0');
|
|
14
|
+
program
|
|
15
|
+
.command('login')
|
|
16
|
+
.description('Authenticate with GitGuard via browser')
|
|
17
|
+
.action(login_1.loginCommand);
|
|
18
|
+
program
|
|
19
|
+
.command('logout')
|
|
20
|
+
.description('Log out of GitGuard')
|
|
21
|
+
.action(logout_1.logoutCommand);
|
|
22
|
+
program
|
|
23
|
+
.command('whoami')
|
|
24
|
+
.description('Show current user and subscription info')
|
|
25
|
+
.action(whoami_1.whoamiCommand);
|
|
26
|
+
program
|
|
27
|
+
.command('scan')
|
|
28
|
+
.description('Scan code for security vulnerabilities (uses your preferences by default)')
|
|
29
|
+
.option('-d, --dir <path>', 'Directory to scan')
|
|
30
|
+
.option('-f, --file <path>', 'Specific file to scan')
|
|
31
|
+
.option('--ai', 'Force enable AI-powered analysis')
|
|
32
|
+
.option('--no-ai', 'Disable AI-powered analysis')
|
|
33
|
+
.option('--dependencies', 'Force enable dependency scanning')
|
|
34
|
+
.option('--no-dependencies', 'Disable dependency scanning')
|
|
35
|
+
.option('--secrets', 'Force enable secret scanning')
|
|
36
|
+
.option('--no-secrets', 'Disable secret scanning')
|
|
37
|
+
.option('--json', 'Output results as JSON')
|
|
38
|
+
.action(scan_1.scanCommand);
|
|
39
|
+
program.parse(process.argv);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,4CAAgD;AAChD,8CAAkD;AAClD,8CAAkD;AAClD,0CAA8C;AAE9C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,iDAAiD,CAAC;KAC9D,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,wCAAwC,CAAC;KACrD,MAAM,CAAC,oBAAY,CAAC,CAAC;AAExB,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,qBAAqB,CAAC;KAClC,MAAM,CAAC,sBAAa,CAAC,CAAC;AAEzB,OAAO;KACJ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,yCAAyC,CAAC;KACtD,MAAM,CAAC,sBAAa,CAAC,CAAC;AAEzB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,2EAA2E,CAAC;KACxF,MAAM,CAAC,kBAAkB,EAAE,mBAAmB,CAAC;KAC/C,MAAM,CAAC,mBAAmB,EAAE,uBAAuB,CAAC;KACpD,MAAM,CAAC,MAAM,EAAE,kCAAkC,CAAC;KAClD,MAAM,CAAC,SAAS,EAAE,6BAA6B,CAAC;KAChD,MAAM,CAAC,gBAAgB,EAAE,kCAAkC,CAAC;KAC5D,MAAM,CAAC,mBAAmB,EAAE,6BAA6B,CAAC;KAC1D,MAAM,CAAC,WAAW,EAAE,8BAA8B,CAAC;KACnD,MAAM,CAAC,cAAc,EAAE,yBAAyB,CAAC;KACjD,MAAM,CAAC,QAAQ,EAAE,wBAAwB,CAAC;KAC1C,MAAM,CAAC,kBAAW,CAAC,CAAC;AAEvB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ScanRequest, ScanResponse, UserProfile } from '../types';
|
|
2
|
+
import { ConfigManager } from './config';
|
|
3
|
+
export declare class APIClient {
|
|
4
|
+
private client;
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: ConfigManager);
|
|
7
|
+
requestAuth(): Promise<{
|
|
8
|
+
requestCode: string;
|
|
9
|
+
authUrl: string;
|
|
10
|
+
expiresIn: number;
|
|
11
|
+
}>;
|
|
12
|
+
pollAuth(requestCode: string): Promise<{
|
|
13
|
+
status: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
}>;
|
|
16
|
+
revokeToken(): Promise<void>;
|
|
17
|
+
getProfile(): Promise<UserProfile>;
|
|
18
|
+
scan(request: ScanRequest): Promise<ScanResponse>;
|
|
19
|
+
getScanStatus(scanId: string): Promise<ScanResponse>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,aAAa;IAqB3B,WAAW,IAAI,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAKnF,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAK1E,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC;IAKlC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAKjD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAI3D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.APIClient = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
class APIClient {
|
|
9
|
+
client;
|
|
10
|
+
config;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
const apiUrl = config.get().apiUrl;
|
|
14
|
+
this.client = axios_1.default.create({
|
|
15
|
+
baseURL: `${apiUrl}/api/v1/cli`,
|
|
16
|
+
timeout: 60000,
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
this.client.interceptors.request.use((config) => {
|
|
22
|
+
const token = this.config.getApiToken();
|
|
23
|
+
if (token) {
|
|
24
|
+
config.headers.Authorization = `Bearer ${token}`;
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async requestAuth() {
|
|
30
|
+
const response = await this.client.post('/auth/request');
|
|
31
|
+
return response.data.data;
|
|
32
|
+
}
|
|
33
|
+
async pollAuth(requestCode) {
|
|
34
|
+
const response = await this.client.get(`/auth/poll/${requestCode}`);
|
|
35
|
+
return response.data;
|
|
36
|
+
}
|
|
37
|
+
async revokeToken() {
|
|
38
|
+
await this.client.post('/auth/revoke');
|
|
39
|
+
}
|
|
40
|
+
async getProfile() {
|
|
41
|
+
const response = await this.client.get('/profile');
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
async scan(request) {
|
|
45
|
+
const response = await this.client.post('/scan', request);
|
|
46
|
+
return response.data;
|
|
47
|
+
}
|
|
48
|
+
async getScanStatus(scanId) {
|
|
49
|
+
const response = await this.client.get(`/scan/${scanId}`);
|
|
50
|
+
return response.data;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.APIClient = APIClient;
|
|
54
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../../src/lib/api-client.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AAI7C,MAAa,SAAS;IACZ,MAAM,CAAgB;IACtB,MAAM,CAAgB;IAE9B,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;QAEnC,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,GAAG,MAAM,aAAa;YAC/B,OAAO,EAAE,KAAK;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CA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AAC;IACvB,CAAC;CACF;AArDD,8BAqDC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Config } from '../types';
|
|
2
|
+
export declare class ConfigManager {
|
|
3
|
+
private config;
|
|
4
|
+
constructor();
|
|
5
|
+
private ensureConfigDir;
|
|
6
|
+
private loadConfig;
|
|
7
|
+
get(): Config;
|
|
8
|
+
set(updates: Partial<Config>): void;
|
|
9
|
+
getApiToken(): string | undefined;
|
|
10
|
+
setApiToken(token: string, email: string): void;
|
|
11
|
+
setUserProfile(subscription: string, preferences: any): void;
|
|
12
|
+
getSubscription(): string | undefined;
|
|
13
|
+
getPreferences(): any;
|
|
14
|
+
clearAuth(): void;
|
|
15
|
+
isAuthenticated(): boolean;
|
|
16
|
+
private saveConfig;
|
|
17
|
+
getConfigPath(): string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AASlC,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAS;;IAOvB,OAAO,CAAC,eAAe;IAMvB,OAAO,CAAC,UAAU;IAaX,GAAG,IAAI,MAAM;IAIb,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI;IAKnC,WAAW,IAAI,MAAM,GAAG,SAAS;IAIjC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAI/C,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,GAAG,IAAI;IAW5D,eAAe,IAAI,MAAM,GAAG,SAAS;IAIrC,cAAc,IAAI,GAAG;IAQrB,SAAS,IAAI,IAAI;IASjB,eAAe,IAAI,OAAO;IAIjC,OAAO,CAAC,UAAU;IAMX,aAAa,IAAI,MAAM;CAG/B"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConfigManager = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.gitguard');
|
|
11
|
+
const CONFIG_FILE = path_1.default.join(CONFIG_DIR, 'config.json');
|
|
12
|
+
const DEFAULT_CONFIG = {
|
|
13
|
+
apiUrl: process.env.GITGUARD_API_URL || 'https://www.gitguard.net',
|
|
14
|
+
};
|
|
15
|
+
class ConfigManager {
|
|
16
|
+
config;
|
|
17
|
+
constructor() {
|
|
18
|
+
this.ensureConfigDir();
|
|
19
|
+
this.config = this.loadConfig();
|
|
20
|
+
}
|
|
21
|
+
ensureConfigDir() {
|
|
22
|
+
if (!fs_1.default.existsSync(CONFIG_DIR)) {
|
|
23
|
+
fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
loadConfig() {
|
|
27
|
+
if (fs_1.default.existsSync(CONFIG_FILE)) {
|
|
28
|
+
try {
|
|
29
|
+
const content = fs_1.default.readFileSync(CONFIG_FILE, 'utf-8');
|
|
30
|
+
return { ...DEFAULT_CONFIG, ...JSON.parse(content) };
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.warn('Warning: Failed to parse config file, using defaults');
|
|
34
|
+
return DEFAULT_CONFIG;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return DEFAULT_CONFIG;
|
|
38
|
+
}
|
|
39
|
+
get() {
|
|
40
|
+
return this.config;
|
|
41
|
+
}
|
|
42
|
+
set(updates) {
|
|
43
|
+
this.config = { ...this.config, ...updates };
|
|
44
|
+
this.saveConfig();
|
|
45
|
+
}
|
|
46
|
+
getApiToken() {
|
|
47
|
+
return this.config.apiToken;
|
|
48
|
+
}
|
|
49
|
+
setApiToken(token, email) {
|
|
50
|
+
this.set({ apiToken: token, email });
|
|
51
|
+
}
|
|
52
|
+
setUserProfile(subscription, preferences) {
|
|
53
|
+
this.set({
|
|
54
|
+
subscription: subscription,
|
|
55
|
+
preferences: {
|
|
56
|
+
aiScanEnabled: preferences.aiScanEnabled || false,
|
|
57
|
+
dependencyScanEnabled: preferences.dependencyScanEnabled || false,
|
|
58
|
+
secretScanEnabled: preferences.secretScanEnabled || false,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
getSubscription() {
|
|
63
|
+
return this.config.subscription;
|
|
64
|
+
}
|
|
65
|
+
getPreferences() {
|
|
66
|
+
return this.config.preferences || {
|
|
67
|
+
aiScanEnabled: false,
|
|
68
|
+
dependencyScanEnabled: false,
|
|
69
|
+
secretScanEnabled: false,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
clearAuth() {
|
|
73
|
+
this.set({
|
|
74
|
+
apiToken: undefined,
|
|
75
|
+
email: undefined,
|
|
76
|
+
subscription: undefined,
|
|
77
|
+
preferences: undefined,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
isAuthenticated() {
|
|
81
|
+
return !!this.config.apiToken;
|
|
82
|
+
}
|
|
83
|
+
saveConfig() {
|
|
84
|
+
fs_1.default.writeFileSync(CONFIG_FILE, JSON.stringify(this.config, null, 2), {
|
|
85
|
+
mode: 0o600,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
getConfigPath() {
|
|
89
|
+
return CONFIG_FILE;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ConfigManager = ConfigManager;
|
|
93
|
+
//# sourceMappingURL=config.js.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ChB,YAAE,CAAC,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;YAClE,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;IACL,CAAC;IAEM,aAAa;QAClB,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAzFD,sCAyFC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-scanner.d.ts","sourceRoot":"","sources":["../../src/lib/file-scanner.ts"],"names":[],"mappings":"AAoCA,qBAAa,WAAW;IACtB,OAAO,CAAC,aAAa;IAsBf,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAa,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAsDnF,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CA2BxE"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FileScanner = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
10
|
+
const CODE_EXTENSIONS = [
|
|
11
|
+
'.ts',
|
|
12
|
+
'.tsx',
|
|
13
|
+
'.js',
|
|
14
|
+
'.jsx',
|
|
15
|
+
'.mjs',
|
|
16
|
+
'.cjs',
|
|
17
|
+
'.py',
|
|
18
|
+
'.rb',
|
|
19
|
+
'.java',
|
|
20
|
+
'.go',
|
|
21
|
+
'.rs',
|
|
22
|
+
'.php',
|
|
23
|
+
'.c',
|
|
24
|
+
'.cpp',
|
|
25
|
+
'.cs',
|
|
26
|
+
'.swift',
|
|
27
|
+
'.kt',
|
|
28
|
+
'.scala',
|
|
29
|
+
];
|
|
30
|
+
const EXCLUDE_DIRS = [
|
|
31
|
+
'node_modules',
|
|
32
|
+
'dist',
|
|
33
|
+
'build',
|
|
34
|
+
'.next',
|
|
35
|
+
'.git',
|
|
36
|
+
'coverage',
|
|
37
|
+
'__pycache__',
|
|
38
|
+
'vendor',
|
|
39
|
+
];
|
|
40
|
+
class FileScanner {
|
|
41
|
+
loadGitignore(dir) {
|
|
42
|
+
const gitignorePath = path_1.default.join(dir, '.gitignore');
|
|
43
|
+
if (!fs_1.default.existsSync(gitignorePath)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const gitignoreContent = fs_1.default.readFileSync(gitignorePath, 'utf-8');
|
|
48
|
+
const ig = (0, ignore_1.default)();
|
|
49
|
+
ig.add(gitignoreContent);
|
|
50
|
+
// Always ignore .git directory
|
|
51
|
+
ig.add('.git');
|
|
52
|
+
return ig;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
// If we can't read .gitignore, return null and fall back to EXCLUDE_DIRS
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async collectFiles(dir, maxFiles = 1000) {
|
|
60
|
+
const files = {};
|
|
61
|
+
let count = 0;
|
|
62
|
+
// Load .gitignore from the root directory being scanned
|
|
63
|
+
const ig = this.loadGitignore(dir);
|
|
64
|
+
const walk = (currentDir) => {
|
|
65
|
+
if (count >= maxFiles)
|
|
66
|
+
return;
|
|
67
|
+
const entries = fs_1.default.readdirSync(currentDir, { withFileTypes: true });
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
if (count >= maxFiles)
|
|
70
|
+
break;
|
|
71
|
+
const fullPath = path_1.default.join(currentDir, entry.name);
|
|
72
|
+
const relativePath = path_1.default.relative(dir, fullPath);
|
|
73
|
+
// Check .gitignore rules if available
|
|
74
|
+
if (ig && ig.ignores(relativePath)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (entry.isDirectory()) {
|
|
78
|
+
// Fallback to EXCLUDE_DIRS if no .gitignore
|
|
79
|
+
if (!ig && EXCLUDE_DIRS.includes(entry.name)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
// Skip hidden directories (unless .gitignore says otherwise)
|
|
83
|
+
if (!ig && entry.name.startsWith('.')) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
walk(fullPath);
|
|
87
|
+
}
|
|
88
|
+
else if (entry.isFile()) {
|
|
89
|
+
const ext = path_1.default.extname(entry.name).toLowerCase();
|
|
90
|
+
if (CODE_EXTENSIONS.includes(ext)) {
|
|
91
|
+
try {
|
|
92
|
+
const content = fs_1.default.readFileSync(fullPath, 'utf-8');
|
|
93
|
+
files[relativePath] = content;
|
|
94
|
+
count++;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
// Skip files that can't be read
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
walk(dir);
|
|
104
|
+
return files;
|
|
105
|
+
}
|
|
106
|
+
async scanSingleFile(filePath) {
|
|
107
|
+
const files = {};
|
|
108
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
109
|
+
throw new Error(`File not found: ${filePath}`);
|
|
110
|
+
}
|
|
111
|
+
const stats = fs_1.default.statSync(filePath);
|
|
112
|
+
if (!stats.isFile()) {
|
|
113
|
+
throw new Error(`Path is not a file: ${filePath}`);
|
|
114
|
+
}
|
|
115
|
+
const ext = path_1.default.extname(filePath).toLowerCase();
|
|
116
|
+
if (!CODE_EXTENSIONS.includes(ext)) {
|
|
117
|
+
throw new Error(`Unsupported file type: ${ext}. Supported: ${CODE_EXTENSIONS.join(', ')}`);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const content = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
121
|
+
const fileName = path_1.default.basename(filePath);
|
|
122
|
+
files[fileName] = content;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
throw new Error(`Failed to read file: ${error.message}`);
|
|
126
|
+
}
|
|
127
|
+
return files;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.FileScanner = FileScanner;
|
|
131
|
+
//# sourceMappingURL=file-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-scanner.js","sourceRoot":"","sources":["../../src/lib/file-scanner.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,oDAA4B;AAE5B,MAAM,eAAe,GAAG;IACtB,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,KAAK;IACL,OAAO;IACP,KAAK;IACL,KAAK;IACL,MAAM;IACN,IAAI;IACJ,MAAM;IACN,KAAK;IACL,QAAQ;IACR,KAAK;IACL,QAAQ;CACT,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,cAAc;IACd,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,UAAU;IACV,aAAa;IACb,QAAQ;CACT,CAAC;AAEF,MAAa,WAAW;IACd,aAAa,CAAC,GAAW;QAC/B,MAAM,aAAa,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAEnD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACH,MAAM,gBAAgB,GAAG,YAAE,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;YACjE,MAAM,EAAE,GAAG,IAAA,gBAAM,GAAE,CAAC;YACpB,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC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C,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,gBAAgB,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7F,CAAC;QAED,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACnD,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACzC,KAAK,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;QAC5B,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAxGD,kCAwGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-detector.d.ts","sourceRoot":"","sources":["../../src/lib/repo-detector.ts"],"names":[],"mappings":"AAGA,qBAAa,YAAY;IACvB,MAAM,CAAC,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAiBhD,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAkC/B,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAoClC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RepoDetector = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
class RepoDetector {
|
|
40
|
+
static detectRepositoryName(dir) {
|
|
41
|
+
// Try to get name from .git/config
|
|
42
|
+
const gitConfigName = this.getFromGitConfig(dir);
|
|
43
|
+
if (gitConfigName) {
|
|
44
|
+
return gitConfigName;
|
|
45
|
+
}
|
|
46
|
+
// Try to get name from package.json
|
|
47
|
+
const packageJsonName = this.getFromPackageJson(dir);
|
|
48
|
+
if (packageJsonName) {
|
|
49
|
+
return packageJsonName;
|
|
50
|
+
}
|
|
51
|
+
// Fallback to directory name
|
|
52
|
+
return path.basename(dir);
|
|
53
|
+
}
|
|
54
|
+
static getFromGitConfig(dir) {
|
|
55
|
+
try {
|
|
56
|
+
const gitConfigPath = path.join(dir, '.git', 'config');
|
|
57
|
+
if (!fs.existsSync(gitConfigPath)) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const gitConfig = fs.readFileSync(gitConfigPath, 'utf-8');
|
|
61
|
+
// Look for remote origin URL
|
|
62
|
+
// Example: url = git@github.com:username/repo.git
|
|
63
|
+
// or: url = https://github.com/username/repo.git
|
|
64
|
+
const match = gitConfig.match(/\[remote "origin"\][\s\S]*?url\s*=\s*(.+)/i);
|
|
65
|
+
if (match && match[1]) {
|
|
66
|
+
const url = match[1].trim();
|
|
67
|
+
// Extract repo name from git URL
|
|
68
|
+
// git@github.com:username/repo.git -> repo
|
|
69
|
+
// https://github.com/username/repo.git -> repo
|
|
70
|
+
const repoMatch = url.match(/[:/]([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
71
|
+
if (repoMatch && repoMatch[1]) {
|
|
72
|
+
return repoMatch[1]; // Returns "username/repo"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static getFromPackageJson(dir) {
|
|
82
|
+
try {
|
|
83
|
+
const packageJsonPath = path.join(dir, 'package.json');
|
|
84
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
88
|
+
// Prefer repository field if it exists
|
|
89
|
+
if (packageJson.repository) {
|
|
90
|
+
if (typeof packageJson.repository === 'string') {
|
|
91
|
+
// Extract repo name from URL
|
|
92
|
+
const match = packageJson.repository.match(/github\.com[:/](.+?)(?:\.git)?$/);
|
|
93
|
+
if (match && match[1]) {
|
|
94
|
+
return match[1];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (packageJson.repository.url) {
|
|
98
|
+
const match = packageJson.repository.url.match(/github\.com[:/](.+?)(?:\.git)?$/);
|
|
99
|
+
if (match && match[1]) {
|
|
100
|
+
return match[1];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Otherwise use package name
|
|
105
|
+
if (packageJson.name) {
|
|
106
|
+
return packageJson.name;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.RepoDetector = RepoDetector;
|
|
116
|
+
//# sourceMappingURL=repo-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repo-detector.js","sourceRoot":"","sources":["../../src/lib/repo-detector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,MAAa,YAAY;IACvB,MAAM,CAAC,oBAAoB,CAAC,GAAW;QACrC,mCAAmC;QACnC,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACjD,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,oCAAoC;QACpC,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,6BAA6B;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,GAAW;QACzC,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAEvD,IAAI,CAAC,EAAE,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,EAAE,CAAC;oBAC/C,6BAA6B;oBAC7B,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;oBAC9E,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;wBACtB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;oBAClB,CAAC;gBACH,CAAC;qBAAM,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;oBACtC,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;oBAClF,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;wBACtB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;oBAClB,CAAC;gBACH,CAAC;YACH,CAAC;YAED,6BAA6B;YAC7B,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC;gBACrB,OAAO,WAAW,CAAC,IAAI,CAAC;YAC1B,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAxFD,oCAwFC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ScanResponse } from '../types';
|
|
2
|
+
import { ConfigManager } from './config';
|
|
3
|
+
export declare class Reporter {
|
|
4
|
+
private useColors;
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config: ConfigManager, useColors?: boolean);
|
|
7
|
+
private color;
|
|
8
|
+
success(message: string): void;
|
|
9
|
+
error(message: string): void;
|
|
10
|
+
warning(message: string): void;
|
|
11
|
+
info(message: string): void;
|
|
12
|
+
reportScan(result: ScanResponse): void;
|
|
13
|
+
private reportVulnerability;
|
|
14
|
+
private wrapText;
|
|
15
|
+
private getSeverityColor;
|
|
16
|
+
private sortBySeverity;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../../src/lib/reporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiB,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAazC,qBAAa,QAAQ;IACnB,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,aAAa,EAAE,SAAS,GAAE,OAAc;IAK5D,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI9B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5B,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI9B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI3B,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IA0EtC,OAAO,CAAC,mBAAmB;IAqD3B,OAAO,CAAC,QAAQ;IAkBhB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,cAAc;CAMvB"}
|