Programmatic API
Using as a Library
Web Guard can be used programmatically for custom integrations:
typescript
import { runWebGuard } from "@promise-inc/web-guard";
async function checkQuality() { const result = await runWebGuard("https://your-site.com", { preset: "recommended", device: "mobile", });
if (!result.passed) { console.error("Quality check failed!"); for (const pillar of result.pillarResults) { if (!pillar.passed) { console.error(` ${pillar.pillar}: ${pillar.violations.length} violations`); } } process.exit(1); }
console.log("All pillars passed! Score:", result.score);}
checkQuality();Core Functions
typescript
// Main API — audit a URL across all pillarsasync function runWebGuard( url: string, options?: Partial<WebGuardConfig>): Promise<WebGuardResult>;
// Load configuration from project directoryfunction loadConfig( cwd: string, overrides?: Partial<WebGuardConfig>): WebGuardConfig;
// Resolve a preset by namefunction resolvePreset(name: string): Partial<WebGuardConfig>;
// Run the full audit with a configasync function runAudit(config: WebGuardConfig): Promise<WebGuardResult>;
// Individual pillar checksasync function checkPerformance(config: WebGuardConfig): Promise<PillarResult>;async function checkA11y(browser: BrowserInstance, config: WebGuardConfig): Promise<PillarResult>;async function checkSeo(browser: BrowserInstance, config: WebGuardConfig): Promise<PillarResult>;async function checkSchema(browser: BrowserInstance, config: WebGuardConfig): Promise<PillarResult>;async function checkSecurity(config: WebGuardConfig): Promise<PillarResult>;async function checkUx(browser: BrowserInstance, config: WebGuardConfig): Promise<PillarResult>;Types
typescript
interface WebGuardResult { passed: boolean; url: string; device: "mobile" | "desktop"; score: number; pillarResults: PillarResult[]; timestamp: string;}
interface PillarResult { pillar: PillarName; passed: boolean; score: number; violations: Violation[];}
interface Violation { rule: string; severity: "critical" | "serious" | "moderate" | "minor"; message: string; element?: string; hint?: string;}
type PillarName = "performance" | "a11y" | "seo" | "schema" | "security" | "ux";The programmatic API launches Chrome headless internally. Make sure Chrome is available on the machine.