Skip to content

Commit cc2fb40

Browse files
authored
Merge pull request #2 from vulnify/dev
better result but showing mongo details
2 parents daa896d + df678e7 commit cc2fb40

14 files changed

Lines changed: 1296 additions & 178 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ node_modules/
33
npm-debug.log*
44
yarn-debug.log*
55
yarn-error.log*
6+
reporter.ts.backup
67

8+
vulnify-report.json
79
# Build outputs
810
dist/
911
build/

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vulnify",
3-
"version": "1.0.0",
3+
"version": "1.0.2",
44
"description": "CLI tool for vulnerability analysis using Vulnify SCA API - similar to Snyk CLI",
55
"main": "dist/index.js",
66
"bin": {

src/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Command } from 'commander';
44
import { testCommand } from './commands/test';
55
import { helpCommand } from './commands/help';
66
import { infoCommand } from './commands/info';
7+
import { pingCommand } from './commands/ping';
78
import { colors } from './utils/colors';
89

910
const program = new Command();
@@ -12,10 +13,11 @@ const program = new Command();
1213
program
1314
.name('vulnify')
1415
.description('CLI tool for vulnerability analysis using Vulnify SCA API')
15-
.version('1.0.0', '-v, --version', 'display version number');
16+
.version('1.0.2', '-v, --version', 'display version number');
1617

1718
// Add commands
1819
program.addCommand(testCommand);
20+
program.addCommand(pingCommand);
1921
program.addCommand(helpCommand);
2022
program.addCommand(infoCommand);
2123

@@ -26,6 +28,7 @@ program.on('--help', () => {
2628
console.log(' $ vulnify test # Analyze current project');
2729
console.log(' $ vulnify test --file package.json # Analyze specific file');
2830
console.log(' $ vulnify test --ecosystem npm # Force ecosystem detection');
31+
console.log(' $ vulnify ping # Test API connectivity');
2932
console.log(' $ vulnify info # Show API information');
3033
console.log('');
3134
console.log(colors.muted('For more information, visit: https://docs.vulnify.io'));

src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './test';
22
export * from './help';
33
export * from './info';
4+
export * from './ping';
45

src/commands/ping.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { Command } from 'commander';
2+
import { colors } from '../utils/colors';
3+
import { createSpinner } from '../utils/spinner';
4+
import { logger } from '../utils/logger';
5+
import { config } from '../utils/config';
6+
import { ApiClient } from '../services/api';
7+
8+
/**
9+
* Ping command to test API connectivity
10+
*/
11+
export const pingCommand = new Command('ping')
12+
.description('Test connectivity to vulnerability analysis API')
13+
.option('--verbose', 'show detailed connection information')
14+
.action(async (options) => {
15+
console.log(colors.title('🏓 Vulnify API Connectivity Test'));
16+
console.log('');
17+
18+
if (options.verbose) {
19+
console.log(colors.muted('Configuration:'));
20+
console.log(colors.muted(` API URL: ${config.getApiUrl()}`));
21+
console.log(colors.muted(` Timeout: ${config.getTimeout()}ms`));
22+
console.log('');
23+
}
24+
25+
const spinner = createSpinner('🔍 Testing API connectivity...');
26+
spinner.start();
27+
28+
try {
29+
// Test connectivity to API - simple HTTP check
30+
const apiClient = new ApiClient();
31+
const startTime = Date.now();
32+
33+
// Try to make a simple request to test connectivity
34+
// We'll catch the error but if we get a response (even an error), it means the API is reachable
35+
try {
36+
await apiClient.analyze({
37+
ecosystem: 'npm',
38+
dependencies: []
39+
});
40+
} catch (error) {
41+
// If we get a validation error, it means the API is reachable
42+
if (error instanceof Error && (
43+
error.message.includes('dependencies') ||
44+
error.message.includes('At least one dependency is required')
45+
)) {
46+
// This is expected - empty dependencies array causes validation error
47+
// but it means the API is responding
48+
} else {
49+
throw error;
50+
}
51+
}
52+
53+
const responseTime = Date.now() - startTime;
54+
55+
spinner.stop();
56+
console.log('');
57+
58+
// Display API results
59+
console.log(colors.info('📡 API Service:'));
60+
console.log(colors.success(` ✅ Available (${responseTime}ms)`));
61+
62+
// Overall status
63+
console.log('');
64+
console.log(colors.success('🎉 API service is available!'));
65+
console.log(colors.info('💡 Ready to analyze dependencies for vulnerabilities'));
66+
67+
console.log('');
68+
console.log(colors.muted('Use "vulnify test" to start analyzing your project'));
69+
70+
} catch (error) {
71+
spinner.fail('❌ Connectivity test failed');
72+
73+
console.log('');
74+
console.log(colors.error('Error details:'));
75+
if (error instanceof Error) {
76+
console.log(colors.error(` ${error.message}`));
77+
} else {
78+
console.log(colors.error(' Unknown error occurred'));
79+
}
80+
81+
console.log('');
82+
console.log(colors.warning('💡 Troubleshooting:'));
83+
console.log(' • Check your internet connection');
84+
console.log(' • Verify the API endpoint is accessible');
85+
console.log(' • Try again in a few moments');
86+
console.log(' • Use --verbose for more details');
87+
88+
if (options.verbose) {
89+
logger.error('Ping command failed', {
90+
error: error instanceof Error ? error.message : 'Unknown error',
91+
stack: error instanceof Error ? error.stack : undefined
92+
});
93+
}
94+
95+
process.exit(1);
96+
}
97+
});
98+

0 commit comments

Comments
 (0)