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

93 lines 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccessibilityService = void 0; const accessibility_1 = require("../../core/accessibility"); const browser_pool_manager_1 = require("../../core/browser/browser-pool-manager"); /** * AccessibilityService - Returns AccessibilityResult (same type used in PageAuditResult) * Used by API endpoint: POST /api/v2/page/accessibility */ class AccessibilityService { constructor() { this.checker = null; } async initialize() { if (!this.checker) { // Create BrowserPoolManager for AccessibilityChecker const poolManager = new browser_pool_manager_1.BrowserPoolManager({ maxConcurrent: 2, // API service uses fewer instances maxIdleTime: 30000, browserType: 'chromium', enableResourceOptimization: true, launchOptions: { headless: true } }); this.checker = new accessibility_1.AccessibilityChecker({ poolManager, enableComprehensiveAnalysis: false // API service only needs basic accessibility }); await this.checker.initialize(); } } async analyzeUrl(url, options = {}) { await this.initialize(); try { // Run single URL accessibility test const pageResult = await this.checker.testPage(url, { timeout: 10000, pa11yStandard: options.pa11yStandard || 'WCAG2AA', includeWarnings: options.includeWarnings || false }); const result = pageResult.accessibilityResult; // Convert to typed AccessibilityResult return { passed: result.passed, wcagLevel: this.getWcagLevel(options.pa11yStandard || 'WCAG2AA'), score: this.calculateScore(result), errors: (result.errors || []).map(error => ({ severity: 'error', message: error, code: 'a11y-error' })), warnings: (result.warnings || []).map(warning => ({ severity: 'warning', message: warning, code: 'a11y-warning' })), pa11yResults: { totalIssues: (result.errors?.length || 0) + (result.warnings?.length || 0), runner: 'pa11y@9.0.0' } }; } catch (error) { throw new Error(`Failed to analyze accessibility: ${error.message}`); } } getWcagLevel(standard) { switch (standard) { case 'WCAG2A': return 'A'; case 'WCAG2AA': return 'AA'; case 'WCAG2AAA': return 'AAA'; default: return 'AA'; } } calculateScore(result) { const errors = result.errors?.length || 0; const warnings = result.warnings?.length || 0; if (errors === 0 && warnings === 0) return 100; // Deduct points for issues (errors weighted more heavily) const score = Math.max(0, 100 - (errors * 10) - (warnings * 2)); return Math.round(score); } async cleanup() { if (this.checker) { await this.checker.cleanup(); this.checker = null; } } } exports.AccessibilityService = AccessibilityService; //# sourceMappingURL=accessibility.service.js.map