mcp-cve-intelligence-server-lite-test
Version:
Lite Model Context Protocol server for comprehensive CVE intelligence gathering with multi-source exploit discovery, designed for security professionals and cybersecurity researchers - Alpha Release
76 lines • 2.86 kB
JavaScript
/**
* GitHub API Response Utilities
*
* Helper functions for handling GitHub API responses and errors
*/
/**
* Type guard to check if a value is a valid GitHub rate limit resource type
*/
function isValidLimitType(value) {
return value === 'core' || value === 'search' || value === 'graphql';
}
/**
* Analyzes a GitHub API 403 response to determine the specific cause
*/
export function analyzeGitHub403Error(response) {
const rateLimitRemaining = response.headers.get('x-ratelimit-remaining');
const rateLimitReset = response.headers.get('x-ratelimit-reset');
const rateLimitResource = response.headers.get('x-ratelimit-resource');
// Check if it's a rate limit issue
if (rateLimitRemaining === '0') {
const resetTime = rateLimitReset
? new Date(parseInt(rateLimitReset) * 1000).toISOString()
: undefined;
// Validate and normalize the rate limit resource type
const limitType = isValidLimitType(rateLimitResource) ? rateLimitResource : undefined;
return {
isRateLimit: true,
message: `GitHub API rate limit exceeded for ${rateLimitResource || 'unknown'} resource`,
resetTime,
limitType,
};
}
// Check for other common 403 causes
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
// Could parse the JSON error message for more specific error details
return {
isRateLimit: false,
message: 'GitHub API access forbidden (check permissions, authentication, or repository access)',
};
}
return {
isRateLimit: false,
message: 'GitHub API access forbidden (insufficient permissions or repository restrictions)',
};
}
/**
* Formats a rate limit reset time for display
*/
export function formatRateLimitReset(resetTime) {
const resetDate = new Date(resetTime);
const now = new Date();
const diffMs = resetDate.getTime() - now.getTime();
if (diffMs <= 0) {
return 'now';
}
const diffMinutes = Math.ceil(diffMs / (1000 * 60));
if (diffMinutes < 60) {
return `${diffMinutes} minute${diffMinutes === 1 ? '' : 's'}`;
}
const diffHours = Math.ceil(diffMinutes / 60);
return `${diffHours} hour${diffHours === 1 ? '' : 's'}`;
}
/**
* Gets rate limit information from GitHub API response headers
*/
export function getRateLimitInfo(response) {
return {
limit: response.headers.get('x-ratelimit-limit'),
remaining: response.headers.get('x-ratelimit-remaining'),
reset: response.headers.get('x-ratelimit-reset'),
resource: response.headers.get('x-ratelimit-resource'),
used: response.headers.get('x-ratelimit-used'),
};
}
//# sourceMappingURL=github-api.js.map