UNPKG

next-api-analyzer

Version:

Minimal, efficient Next.js API analyzer with Postman-ready testing guides for security, performance, and maintainability

145 lines (140 loc) 4.18 kB
interface ApiRouteInfo { path: string; methods: HttpMethod[]; hasAuth: boolean; authTypes: AuthType[]; queryParams: Parameter[]; pathParams: Parameter[]; bodyParams: Parameter[]; headers: string[]; responseStatuses: number[]; middlewares: string[]; description?: string; riskLevel: RiskLevel; hasRateLimit: boolean; hasCors: boolean; hasInputValidation: boolean; dependencies: string[]; complexity: number; lastModified: Date; fileSize: number; linesOfCode: number; performanceScore: number; } interface Parameter { name: string; type: string; required: boolean; description?: string; } interface ApiAnalysisResult { routes: ApiRouteInfo[]; summary: AnalysisSummary; metadata: AnalysisMetadata; recommendations: Recommendation[]; } interface AnalysisSummary { totalRoutes: number; secureRoutes: number; publicRoutes: number; methodsBreakdown: Record<HttpMethod, number>; statusCodeDistribution: Record<string, number>; riskDistribution: Record<RiskLevel, number>; securityScore: number; performanceScore: number; maintainabilityScore: number; testCoverageScore: number; } interface AnalysisMetadata { analyzedAt: Date; version: string; duration: number; totalFiles: number; totalLinesOfCode: number; } interface Recommendation { id: string; type: RecommendationType; severity: Severity; title: string; description: string; route?: string; solution: string; impact: string; effort: Effort; category: string; tags: string[]; codeExample?: string; fixExample?: string; } interface AnalyzerConfig { apiDir: string; outputDir: string; includePatterns: string[]; excludePatterns: string[]; authPatterns: AuthPattern[]; middlewarePatterns: MiddlewarePattern[]; enablePerformanceAnalysis: boolean; enableSecurityAnalysis: boolean; thresholds: QualityThresholds; } interface AuthPattern { name: string; pattern: RegExp; type: AuthType; confidence: number; } interface MiddlewarePattern { name: string; pattern: RegExp; category: string; } interface QualityThresholds { security: number; performance: number; maintainability: number; complexity: number; } type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS"; type RiskLevel = "LOW" | "MEDIUM" | "HIGH" | "CRITICAL"; type Severity = "LOW" | "MEDIUM" | "HIGH" | "CRITICAL"; type Effort = "LOW" | "MEDIUM" | "HIGH"; type RecommendationType = "SECURITY" | "PERFORMANCE" | "MAINTAINABILITY" | "TESTING" | "DOCUMENTATION"; type AuthType = "JWT" | "Bearer Token" | "API Key" | "Session" | "OAuth" | "NextAuth.js" | "Firebase Auth" | "Supabase Auth" | "Auth0" | "Passport"; declare class NextApiAnalyzer { private readonly config; private routes; private startTime; constructor(config?: Partial<AnalyzerConfig>); analyzeRoutes(): Promise<ApiAnalysisResult>; private analyzeFile; private parseRouteInfo; private generateAnalysisResult; generateReport(analysis: ApiAnalysisResult): string; private isAppRouterFile; private getRoutePath; private extractMethods; private detectAuth; private extractAuthTypes; private extractQueryParams; private extractPathParams; private extractBodyParams; private extractHeaders; private extractResponseStatuses; private extractMiddlewares; private extractDescription; private detectRateLimit; private detectCors; private detectInputValidation; private extractDependencies; private generateRecommendations; private calculateMethodsBreakdown; private calculateStatusCodeDistribution; private calculateRiskDistribution; private calculateSecurityScore; private calculatePerformanceScore; private calculateMaintainabilityScore; } declare const DEFAULT_CONFIG: AnalyzerConfig; declare const VERSION = "4.0.1"; export { type AnalyzerConfig, type ApiAnalysisResult, type ApiRouteInfo, DEFAULT_CONFIG, NextApiAnalyzer, type Recommendation, VERSION };