/** * Programmatic API for @slashgear/gdpr-cookie-scanner. * * @example * ```ts * import { scan } from '@slashgear/gdpr-cookie-scanner'; * * const result = await scan('https://example.com'); * console.log(result.compliance.grade); // 'A' | 'B' | 'C' | 'D' | 'F' * ``` * * @example Advanced usage * ```ts * import { scan, ReportGenerator } from '@slashgear/gdpr-cookie-scanner'; * * const result = await scan('https://example.com', { locale: 'fr-FR', timeout: 60_000 }); * const generator = new ReportGenerator({ ...result, outputDir: './reports', formats: ['html'] }); * const paths = await generator.generate(result); * ``` */ export { Scanner } from "./scanner/index.js"; export { ReportGenerator } from "./report/generator.js"; // All public types export type { ScanResult, ScanOptions, ComplianceScore, ConsentModal, ConsentButton, ConsentCheckbox, ScannedCookie, NetworkRequest, DarkPatternIssue, DarkPatternType, CookieCategory, TrackerCategory, ConsentButtonType, ReportFormat, ViewportPreset, } from "./types.js"; import { Scanner } from "./scanner/index.js"; import type { ScanResult, ViewportPreset } from "./types.js"; /** * Options for the `scan()` convenience function. * All fields are optional — sensible defaults are applied. */ export interface ScanApiOptions { /** Browser navigation timeout in ms. Default: 30 000. */ timeout?: number; /** Capture full-page screenshots after reject and accept interactions. * The consent modal is always screenshotted (cropped to the element) when detected. * Requires `outputDir`. Default: false. */ screenshots?: boolean; /** Directory where screenshots (and optionally reports) are saved. */ outputDir?: string; /** Browser locale used for language detection. Default: 'en-US'. */ locale?: string; /** Log verbose scanner output. Default: false. */ verbose?: boolean; /** Viewport preset. desktop=1280×900, tablet=768×1024, mobile=390×844. Default: 'desktop'. */ viewport?: ViewportPreset; /** Treat unrecognised cookies and unknown third-party requests as requiring consent. Default: false. */ strict?: boolean; } /** * Scan a URL for GDPR cookie consent compliance. * * Returns the raw `ScanResult` without writing any file. * To generate reports, pass the result to `ReportGenerator`. * * @param url - Absolute URL to scan (e.g. `"https://example.com"`). * @param options - Optional scan configuration. */ export async function scan(url: string, options: ScanApiOptions = {}): Promise { const normalizedUrl = url.startsWith("http://") || url.startsWith("https://") ? url : `https://${url}`; const scanner = new Scanner({ url: normalizedUrl, timeout: options.timeout ?? 30_000, screenshots: options.screenshots ?? false, outputDir: options.outputDir, locale: options.locale ?? "en-US", verbose: options.verbose ?? false, formats: [], viewport: options.viewport ?? "desktop", strict: options.strict ?? false, }); return scanner.run(); }