@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
326 lines • 12.7 kB
JavaScript
;
/**
* 🎯 AuditMySite SDK - Single Source of Truth Interface
*
* This SDK uses ONLY the unified export types and serves as the
* single entry point for all programmatic access to AuditMySite.
*
* Used by:
* - Node.js SDK
* - CLI tool
* - REST API server
* - External integrations
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.auditSDK = exports.AuditMySiteSDK = void 0;
const report_export_1 = require("../reports/types/report-export");
const unified_export_1 = require("../reports/exporters/unified-export");
class AuditMySiteSDK {
constructor(version = '1.8.8') {
this.version = version;
this.exporter = new unified_export_1.UnifiedReportExporter(version);
}
/**
* Get version information
*/
getVersion() {
return {
version: this.version,
nodeVersion: process.version,
apiVersion: '1.0',
features: [
'accessibility-testing',
'performance-metrics',
'screenshot-capture',
'keyboard-navigation',
'color-contrast',
'focus-management',
'multiple-formats'
]
};
}
/**
* Validate audit request
*/
validateRequest(request) {
if (!report_export_1.ReportExportValidator.validateAuditRequest(request)) {
return { valid: false, error: 'Invalid audit request: missing or invalid URL' };
}
if (request.options && !report_export_1.ReportExportValidator.validateAuditOptions(request.options)) {
return { valid: false, error: 'Invalid audit options' };
}
return { valid: true };
}
/**
* Execute audit (main SDK function)
*/
async audit(request, progressCallback) {
try {
// Validate request
const validation = this.validateRequest(request);
if (!validation.valid) {
const error = {
code: 'INVALID_REQUEST',
message: validation.error
};
return {
status: 'error',
report: report_export_1.ReportExportValidator.createErrorReport(error, request.url),
error
};
}
// Progress callback setup
if (progressCallback) {
progressCallback({
step: 'discovering',
progress: 10,
message: 'Discovering pages...',
pagesCompleted: 0,
totalPages: 0
});
}
// Execute the actual audit using existing pipeline
const testResult = await this.executeAudit(request, progressCallback);
if (progressCallback) {
progressCallback({
step: 'generating',
progress: 90,
message: 'Generating reports...',
pagesCompleted: testResult.summary.testedPages,
totalPages: testResult.summary.totalPages
});
}
// Convert to unified format
const unifiedReport = this.exporter.exportUnified(testResult.summary, {
timestamp: new Date().toISOString(),
sitemapUrl: request.url,
...request.metadata
}, request.options);
// Generate files if requested
let files;
if (request.options?.outputFormats?.length) {
files = await this.generateFiles(unifiedReport, testResult.summary, request.options);
}
if (progressCallback) {
progressCallback({
step: 'completed',
progress: 100,
message: 'Audit completed successfully',
pagesCompleted: testResult.summary.testedPages,
totalPages: testResult.summary.totalPages
});
}
return {
status: 'success',
report: unifiedReport,
files
};
}
catch (error) {
const auditError = {
code: error.code || 'AUDIT_FAILED',
message: error.message || 'Audit execution failed',
details: error.details,
stack: error.stack
};
return {
status: 'error',
report: report_export_1.ReportExportValidator.createErrorReport(auditError, request.url),
error: auditError
};
}
}
/**
* Execute audit using existing pipeline
*/
async executeAudit(request, progressCallback) {
// Import the existing pipeline
const { StandardPipeline } = require('../core/pipeline/standard-pipeline');
// Convert SDK options to pipeline options
const pipelineOptions = this.convertToPipelineOptions(request.options);
const pipeline = new StandardPipeline();
if (progressCallback) {
progressCallback({
step: 'testing',
progress: 30,
message: 'Running accessibility tests...',
pagesCompleted: 0,
totalPages: 0
});
}
return await pipeline.execute(request.url, pipelineOptions);
}
/**
* Convert SDK options to pipeline options
*/
convertToPipelineOptions(options) {
if (!options)
return {};
return {
maxPages: options.maxPages || 50,
timeout: options.timeout || 10000,
pa11yStandard: options.pa11yStandard || 'WCAG2AA',
collectPerformanceMetrics: options.collectPerformanceMetrics || false,
captureScreenshots: options.captureScreenshots || false,
testKeyboardNavigation: options.testKeyboardNavigation || false,
testColorContrast: options.testColorContrast || false,
testFocusManagement: options.testFocusManagement || false,
outputFormat: options.outputFormats?.includes('html') ? 'html' : 'markdown'
};
}
/**
* Generate output files
*/
async generateFiles(report, testSummary, options) {
const files = {};
const outputDir = options.outputDir || './reports';
const domain = report.metadata.domain;
const dateStr = new Date().toISOString().split('T')[0];
// Ensure output directory exists
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
const path = await Promise.resolve().then(() => __importStar(require('path')));
await fs.mkdir(outputDir, { recursive: true });
// Generate JSON (always available)
if (options.outputFormats?.includes('json')) {
const jsonPath = path.join(outputDir, `${domain}-audit-${dateStr}.json`);
await this.exporter.saveJsonExport(testSummary, jsonPath, {
timestamp: report.metadata.timestamp,
sitemapUrl: report.metadata.sourceUrl
}, options);
files.json = jsonPath;
}
// Generate HTML
if (options.outputFormats?.includes('html')) {
const htmlPath = path.join(outputDir, `${domain}-audit-${dateStr}.html`);
await this.generateHtmlReport(report, htmlPath);
files.html = htmlPath;
}
// Generate Markdown
if (options.outputFormats?.includes('markdown')) {
const mdPath = path.join(outputDir, `${domain}-audit-${dateStr}.md`);
await this.generateMarkdownReport(report, mdPath);
files.markdown = mdPath;
}
// Generate CSV
if (options.outputFormats?.includes('csv')) {
const csvPath = path.join(outputDir, `${domain}-audit-${dateStr}.csv`);
await this.generateCsvReport(report, csvPath);
files.csv = csvPath;
}
return files;
}
/**
* Generate HTML report using unified data
*/
async generateHtmlReport(report, outputPath) {
// Use HTMLGenerator (current standard)
const { HTMLGenerator } = require('../generators/html-generator');
const generator = new HTMLGenerator();
// Note: May need adapter for unified report format
await generator.generate(report);
}
/**
* Generate Markdown report using unified data
*/
async generateMarkdownReport(report, outputPath) {
const { ModernMarkdownReportGenerator } = require('../reports/generators/modern-markdown-generator');
const generator = new ModernMarkdownReportGenerator();
await generator.generateFromUnified(report, outputPath);
}
/**
* Generate CSV report using unified data
*/
async generateCsvReport(report, outputPath) {
const { ModernCsvReportGenerator } = require('../reports/generators/modern-csv-generator');
const generator = new ModernCsvReportGenerator();
await generator.generateFromUnified(report, outputPath);
}
/**
* Get report summary without full audit (for quick checks)
*/
async getReportSummary(request) {
const { SitemapParser } = require('../core/utils/sitemap-parser');
const parser = new SitemapParser();
try {
const urls = await parser.parseSitemap(request.url, request.options?.maxPages || 50);
const domain = new URL(request.url).hostname;
return {
domain,
estimatedPages: urls.length,
estimatedDuration: urls.length * (request.options?.timeout || 10000)
};
}
catch {
return {
domain: 'unknown',
estimatedPages: 1,
estimatedDuration: request.options?.timeout || 10000
};
}
}
/**
* Export report data in different formats
*/
exportData(report, format) {
switch (format) {
case 'json':
return JSON.stringify(report, null, 2);
case 'minimal':
return {
domain: report.metadata.domain,
timestamp: report.metadata.timestamp,
summary: {
successRate: report.summary.successRate,
totalPages: report.summary.totalPages,
totalErrors: report.summary.totalErrors,
avgScore: report.summary.avgAccessibilityScore
},
recommendations: report.recommendations.length
};
default:
return report;
}
}
}
exports.AuditMySiteSDK = AuditMySiteSDK;
// Export singleton instance for convenience
exports.auditSDK = new AuditMySiteSDK();
// Export all types for external use
__exportStar(require("../reports/types/report-export"), exports);
//# sourceMappingURL=unified-audit-sdk.js.map