Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
reporter.ts.backup

vulnify-report.json
# Build outputs
dist/
build/
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vulnify",
"version": "1.0.0",
"version": "1.0.2",
"description": "CLI tool for vulnerability analysis using Vulnify SCA API - similar to Snyk CLI",
"main": "dist/index.js",
"bin": {
Expand Down
5 changes: 4 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Command } from 'commander';
import { testCommand } from './commands/test';
import { helpCommand } from './commands/help';
import { infoCommand } from './commands/info';
import { pingCommand } from './commands/ping';
import { colors } from './utils/colors';

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

// Add commands
program.addCommand(testCommand);
program.addCommand(pingCommand);
program.addCommand(helpCommand);
program.addCommand(infoCommand);

Expand All @@ -26,6 +28,7 @@ program.on('--help', () => {
console.log(' $ vulnify test # Analyze current project');
console.log(' $ vulnify test --file package.json # Analyze specific file');
console.log(' $ vulnify test --ecosystem npm # Force ecosystem detection');
console.log(' $ vulnify ping # Test API connectivity');
console.log(' $ vulnify info # Show API information');
console.log('');
console.log(colors.muted('For more information, visit: https://docs.vulnify.io'));
Expand Down
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './test';
export * from './help';
export * from './info';
export * from './ping';

98 changes: 98 additions & 0 deletions src/commands/ping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Command } from 'commander';
import { colors } from '../utils/colors';
import { createSpinner } from '../utils/spinner';
import { logger } from '../utils/logger';
import { config } from '../utils/config';
import { ApiClient } from '../services/api';

/**
* Ping command to test API connectivity
*/
export const pingCommand = new Command('ping')
.description('Test connectivity to vulnerability analysis API')
.option('--verbose', 'show detailed connection information')
.action(async (options) => {
console.log(colors.title('🏓 Vulnify API Connectivity Test'));
console.log('');

if (options.verbose) {
console.log(colors.muted('Configuration:'));
console.log(colors.muted(` API URL: ${config.getApiUrl()}`));
console.log(colors.muted(` Timeout: ${config.getTimeout()}ms`));
console.log('');
}

const spinner = createSpinner('🔍 Testing API connectivity...');
spinner.start();

try {
// Test connectivity to API - simple HTTP check
const apiClient = new ApiClient();
const startTime = Date.now();

// Try to make a simple request to test connectivity
// We'll catch the error but if we get a response (even an error), it means the API is reachable
try {
await apiClient.analyze({
ecosystem: 'npm',
dependencies: []
});
} catch (error) {
// If we get a validation error, it means the API is reachable
if (error instanceof Error && (
error.message.includes('dependencies') ||
error.message.includes('At least one dependency is required')
)) {
// This is expected - empty dependencies array causes validation error
// but it means the API is responding
} else {
throw error;
}
}

const responseTime = Date.now() - startTime;

spinner.stop();
console.log('');

// Display API results
console.log(colors.info('📡 API Service:'));
console.log(colors.success(` ✅ Available (${responseTime}ms)`));

// Overall status
console.log('');
console.log(colors.success('🎉 API service is available!'));
console.log(colors.info('💡 Ready to analyze dependencies for vulnerabilities'));

console.log('');
console.log(colors.muted('Use "vulnify test" to start analyzing your project'));

} catch (error) {
spinner.fail('❌ Connectivity test failed');

console.log('');
console.log(colors.error('Error details:'));
if (error instanceof Error) {
console.log(colors.error(` ${error.message}`));
} else {
console.log(colors.error(' Unknown error occurred'));
}

console.log('');
console.log(colors.warning('💡 Troubleshooting:'));
console.log(' • Check your internet connection');
console.log(' • Verify the API endpoint is accessible');
console.log(' • Try again in a few moments');
console.log(' • Use --verbose for more details');

if (options.verbose) {
logger.error('Ping command failed', {
error: error instanceof Error ? error.message : 'Unknown error',
stack: error instanceof Error ? error.stack : undefined
});
}

process.exit(1);
}
});

Loading
Loading