UNPKG

@casoon/auditmysite

Version:

Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe

288 lines 11.5 kB
"use strict"; /** * Analyzer Factory for AuditMySite * * Provides dependency injection and factory pattern for creating * analyzers with proper configuration and type safety. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AnalyzerNotAvailableError = exports.AnalyzerFactory = void 0; // Import analyzer implementations const content_weight_analyzer_1 = require("../../analyzers/content-weight-analyzer"); const performance_collector_1 = require("../../analyzers/performance-collector"); const mobile_performance_collector_1 = require("../../analyzers/mobile-performance-collector"); const seo_analyzer_1 = require("../../analyzers/seo-analyzer"); const mobile_friendliness_analyzer_1 = require("../../analyzers/mobile-friendliness-analyzer"); const security_headers_analyzer_1 = require("../../analyzers/security-headers-analyzer"); const structured_data_analyzer_1 = require("../../analyzers/structured-data-analyzer"); /** * Factory for creating analyzer instances with proper configuration */ class AnalyzerFactory { constructor(config) { this.analyzerCache = new Map(); this.config = config; } /** * Create an analyzer of the specified type */ createAnalyzer(type) { // Check cache first for singleton behavior if (this.analyzerCache.has(type)) { return this.analyzerCache.get(type); } if (!this.isAvailable(type)) { throw new AnalyzerNotAvailableError(type); } const analyzer = this.createAnalyzerInstance(type); this.analyzerCache.set(type, analyzer); this.config.logger.debug(`Created analyzer: ${type}`, { analyzerName: analyzer.name, analyzerType: analyzer.type }); return analyzer; } /** * Get all available analyzer types */ getAvailableTypes() { const allTypes = [ 'content-weight', 'performance', 'mobile-performance', 'seo', 'mobile-friendliness', 'security-headers', 'structured-data' ]; // Filter by enabled analyzers if specified if (this.config.enabledAnalyzers) { return allTypes.filter(type => this.config.enabledAnalyzers.includes(type)); } return allTypes; } /** * Check if a specific analyzer type is available */ isAvailable(type) { return this.getAvailableTypes().includes(type); } /** * Create multiple analyzers at once */ createAnalyzers(types) { return types.map(type => this.createAnalyzer(type)); } /** * Clean up all cached analyzers */ async cleanup() { const cleanupPromises = Array.from(this.analyzerCache.values()) .filter(analyzer => analyzer.cleanup) .map(analyzer => analyzer.cleanup()); await Promise.all(cleanupPromises); this.analyzerCache.clear(); this.config.logger.debug('All analyzers cleaned up'); } createAnalyzerInstance(type) { switch (type) { case 'content-weight': return new ContentWeightAnalyzerAdapter(new content_weight_analyzer_1.ContentWeightAnalyzer(), this.config.logger.child ? this.config.logger.child('content-weight') : this.config.logger); case 'performance': return new PerformanceAnalyzerAdapter(new performance_collector_1.PerformanceCollector(this.config.qualityAnalysisOptions), this.config.logger.child ? this.config.logger.child('performance') : this.config.logger); case 'mobile-performance': return new MobilePerformanceAnalyzerAdapter(new mobile_performance_collector_1.MobilePerformanceCollector(this.config.qualityAnalysisOptions), this.config.logger.child ? this.config.logger.child('mobile-performance') : this.config.logger); case 'seo': return new SEOAnalyzerAdapter(new seo_analyzer_1.SEOAnalyzer(this.config.qualityAnalysisOptions), this.config.logger.child ? this.config.logger.child('seo') : this.config.logger); case 'mobile-friendliness': return new MobileFriendlinessAnalyzerAdapter(new mobile_friendliness_analyzer_1.MobileFriendlinessAnalyzer({ verbose: false }), this.config.logger.child ? this.config.logger.child('mobile-friendliness') : this.config.logger); case 'security-headers': return new SecurityHeadersAnalyzerAdapter(new security_headers_analyzer_1.SecurityHeadersAnalyzer(), this.config.logger.child ? this.config.logger.child('security-headers') : this.config.logger); case 'structured-data': return new StructuredDataAnalyzerAdapter(new structured_data_analyzer_1.StructuredDataAnalyzer(), this.config.logger.child ? this.config.logger.child('structured-data') : this.config.logger); default: throw new AnalyzerNotAvailableError(type); } } } exports.AnalyzerFactory = AnalyzerFactory; /** * Error thrown when an analyzer type is not available */ class AnalyzerNotAvailableError extends Error { constructor(type) { super(`Analyzer type '${type}' is not available`); this.name = 'AnalyzerNotAvailableError'; } } exports.AnalyzerNotAvailableError = AnalyzerNotAvailableError; /** * Adapter classes to bridge existing analyzers to the new interface */ class ContentWeightAnalyzerAdapter { constructor(analyzer, logger) { this.analyzer = analyzer; this.logger = logger; this.type = 'content-weight'; this.name = 'Content Weight Analyzer'; } async analyze(page, url, options) { const startTime = Date.now(); try { this.logger.debug(`Starting content weight analysis for ${url}`); const result = await this.analyzer.analyze(page, url, { verbose: options?.verbose }); const duration = Date.now() - startTime; this.logger.debug(`Content weight analysis completed in ${duration}ms`); return result; } catch (error) { this.logger.error(`Content weight analysis failed for ${url}`, error); throw error; } } } class PerformanceAnalyzerAdapter { constructor(analyzer, logger) { this.analyzer = analyzer; this.logger = logger; this.type = 'performance'; this.name = 'Performance Analyzer'; } async analyze(page, url, options) { const startTime = Date.now(); try { this.logger.debug(`Starting performance analysis for ${url}`); const result = await this.analyzer.collectEnhancedMetrics(page, url); const duration = Date.now() - startTime; this.logger.debug(`Performance analysis completed in ${duration}ms`); return result; } catch (error) { this.logger.error(`Performance analysis failed for ${url}`, error); throw error; } } } class MobilePerformanceAnalyzerAdapter { constructor(analyzer, logger) { this.analyzer = analyzer; this.logger = logger; this.type = 'mobile-performance'; this.name = 'Mobile Performance Analyzer'; } async analyze(page, url, options) { const startTime = Date.now(); try { this.logger.debug(`Starting mobile performance analysis for ${url}`); const result = await this.analyzer.collectMobileMetrics(page, url); const duration = Date.now() - startTime; this.logger.debug(`Mobile performance analysis completed in ${duration}ms`); return result; } catch (error) { this.logger.error(`Mobile performance analysis failed for ${url}`, error); throw error; } } } class SEOAnalyzerAdapter { constructor(analyzer, logger) { this.analyzer = analyzer; this.logger = logger; this.type = 'seo'; this.name = 'SEO Analyzer'; } async analyze(page, url, options) { const startTime = Date.now(); try { this.logger.debug(`Starting SEO analysis for ${url}`); const result = await this.analyzer.analyzeSEO(page, url); const duration = Date.now() - startTime; this.logger.debug(`SEO analysis completed in ${duration}ms`); return result; } catch (error) { this.logger.error(`SEO analysis failed for ${url}`, error); throw error; } } } class MobileFriendlinessAnalyzerAdapter { constructor(analyzer, logger) { this.analyzer = analyzer; this.logger = logger; this.type = 'mobile-friendliness'; this.name = 'Mobile Friendliness Analyzer'; } async analyze(page, url, options) { const startTime = Date.now(); try { this.logger.debug(`Starting mobile friendliness analysis for ${url}`); const result = await this.analyzer.analyzeMobileFriendliness(page, url); const duration = Date.now() - startTime; this.logger.debug(`Mobile friendliness analysis completed in ${duration}ms`); return result; } catch (error) { this.logger.error(`Mobile friendliness analysis failed for ${url}`, error); throw error; } } } class SecurityHeadersAnalyzerAdapter { constructor(analyzer, logger) { this.analyzer = analyzer; this.logger = logger; this.type = 'security-headers'; this.name = 'Security Headers Analyzer'; } async analyze(page, url, options) { const startTime = Date.now(); try { this.logger.debug(`Starting security headers analysis for ${url}`); // For now, return a placeholder result const result = { score: 50, grade: 'C', headers: [], recommendations: ['Security headers analysis not fully implemented'] }; const duration = Date.now() - startTime; this.logger.debug(`Security headers analysis completed in ${duration}ms`); return result; } catch (error) { this.logger.error(`Security headers analysis failed for ${url}`, error); throw error; } } } class StructuredDataAnalyzerAdapter { constructor(analyzer, logger) { this.analyzer = analyzer; this.logger = logger; this.type = 'structured-data'; this.name = 'Structured Data Analyzer'; } async analyze(page, url, options) { const startTime = Date.now(); try { this.logger.debug(`Starting structured data analysis for ${url}`); // For now, return a placeholder result const result = { score: 50, grade: 'C', structuredData: [], recommendations: ['Structured data analysis not fully implemented'] }; const duration = Date.now() - startTime; this.logger.debug(`Structured data analysis completed in ${duration}ms`); return result; } catch (error) { this.logger.error(`Structured data analysis failed for ${url}`, error); throw error; } } } //# sourceMappingURL=analyzer-factory.js.map