UNPKG

reporting-api

Version:

Roll your own Reporting API collector. Supports CSP, COEP, COOP, Document-Policy, Crash reports, Deprecation reports, Intervention reports and Network Error Logging

47 lines (46 loc) 1.71 kB
import express, { Request, Response } from 'express'; import { Report } from './schemas'; import { ZodError } from 'zod'; export interface ReportingEndpointConfig { /** * Called when a report is received */ onReport: (report: Report, req: Request) => any; /** * Called when a report validation error occured. * * This should not happen as the schemas are well relaxed but if a new type of * report is received then this function is used to track these reports so we * can take action on them. * * @param error The validation error * @param object The body of the report that failed the validation * @param req The request */ onValidationError?: (error: ZodError | Error, body: any, req: Request) => any; /** * Ignore CSP violations from browser extensions */ ignoreBrowserExtensions?: boolean; /** * The max age of reports in seconds. The reporting API is buffering * reports and can send more than one in a single report call */ maxAge?: number; /** * Debug mode */ debug?: boolean; /** * Set this field to enable CORS for reports sent cross origin to other domains. * A special value '*' can be set to allow any domain to send reports to your endpoint. * * @example 'https://example.com' * @example /https:\/\/(.*)\.example.com$/ */ allowedOrigins?: string | RegExp | (string | RegExp)[]; } /** * Express route to collect reports */ export declare const reportingEndpoint: (config: ReportingEndpointConfig) => (((req: Request, res: Response) => express.Response<any, Record<string, any>>) | import("connect").NextHandleFunction)[];