/** * Smart Network Request Sanitizer * * This module provides intelligent filtering of network requests to: * - Reduce data footprint by ~60% * - Keep all debugging information (failures, slow requests) * - Filter out static resources (already captured by ResourceTiming API) * - Remove third-party tracking requests * - Maintain complete API call timeline */ import type { RequestResponseData } from './network.js'; /** * Configuration for the smart sanitizer */ export interface SmartSanitizerOptions { /** * Always capture requests slower than this threshold (milliseconds) * @default 2000 */ slowRequestThreshold?: number; /** * Always capture requests with status >= this threshold * @default 400 */ errorStatusThreshold?: number; /** * Domains to ignore (third-party tracking, analytics, etc.) * @default Common tracking domains */ ignoredDomains?: string[]; /** * URL patterns that identify API calls (regex or string contains) * @default ['/api/', '/graphql', '/v1/', '/v2/'] */ apiPatterns?: (string | RegExp)[]; /** * File extensions to ignore (static resources) * @default ['.js', '.css', '.png', '.jpg', ...] */ ignoredExtensions?: string[]; /** * Capture all requests to your own domain(s) * @default [window.location.hostname] */ ownDomains?: string[]; /** * Custom filter function (applied after built-in rules) */ customFilter?: (data: RequestResponseData) => boolean; } /** * Create a smart sanitizer function * * @param options - Configuration options * @returns Sanitizer function compatible with network module * * @example * ```typescript * const tracker = new Tracker({ * projectKey: 'YOUR_PROJECT_KEY', * network: { * sanitizer: createSmartSanitizer({ * slowRequestThreshold: 3000, // 3 seconds * apiPatterns: ['/api/', '/backend/'], * }), * }, * }) * ``` */ export declare function createSmartSanitizer(options?: SmartSanitizerOptions): (data: RequestResponseData) => RequestResponseData | null; /** * Preset configurations for common use cases */ export declare const SmartSanitizerPresets: { /** * Strict: Only failures and very slow requests * ~80% reduction in data */ strict: () => (data: RequestResponseData) => RequestResponseData | null; /** * Balanced: Failures, slow requests, and API calls (default) * ~60% reduction in data */ balanced: () => (data: RequestResponseData) => RequestResponseData | null; /** * Verbose: Capture more, but still filter static resources * ~40% reduction in data */ verbose: () => (data: RequestResponseData) => RequestResponseData | null; /** * Debug: Capture everything (same as no sanitizer) * 0% reduction in data */ debug: () => (data: RequestResponseData) => RequestResponseData | null; }; /** * Helper to create a custom sanitizer with easy domain/pattern config * * @example * ```typescript * const sanitizer = createCustomSanitizer({ * captureOnly: { * domains: ['api.myapp.com', 'backend.myapp.com'], * patterns: ['/api/', '/graphql'], * }, * ignore: { * domains: ['cdn.myapp.com', 'static.myapp.com'], * }, * }) * ``` */ export declare function createCustomSanitizer(config: { captureOnly?: { domains?: string[]; patterns?: (string | RegExp)[]; }; ignore?: { domains?: string[]; patterns?: (string | RegExp)[]; }; }): (data: RequestResponseData) => RequestResponseData | null;