@bugspotter/sdk
Version:
Professional bug reporting SDK with screenshots, session replay, and automatic error capture for web applications
141 lines (140 loc) • 5.72 kB
TypeScript
import type { BrowserMetadata } from './capture/metadata';
import { type FloatingButtonOptions } from './widget/button';
import type { eventWithTime } from '@rrweb/types';
import { type AuthConfig, type RetryConfig } from './core/transport';
import type { OfflineConfig } from './core/offline-queue';
export declare class BugSpotter {
private static instance;
private config;
private screenshot;
private console;
private network;
private metadata;
private domCollector?;
private widget?;
private sanitizer?;
constructor(config: BugSpotterConfig);
static init(config: BugSpotterConfig): BugSpotter;
static getInstance(): BugSpotter | null;
/**
* Capture bug report data
* Note: Screenshot is captured for modal preview only (_screenshotPreview)
* Actual file uploads use presigned URLs (screenshotKey/replayKey set after upload)
*/
capture(): Promise<BugReport>;
private handleBugReport;
private submitBugReport;
getConfig(): Readonly<BugSpotterConfig>;
destroy(): void;
}
export interface BugSpotterConfig {
endpoint?: string;
showWidget?: boolean;
widgetOptions?: FloatingButtonOptions;
/** Authentication configuration */
auth?: AuthConfig;
/** Retry configuration for failed requests */
retry?: RetryConfig;
/** Offline queue configuration */
offline?: OfflineConfig;
replay?: {
/** Enable session replay recording (default: true) */
enabled?: boolean;
/** Duration in seconds to keep replay events (default: 15, max recommended: 30) */
duration?: number;
/** Sampling configuration for performance optimization */
sampling?: {
/** Throttle mousemove events in milliseconds (default: 50) */
mousemove?: number;
/** Throttle scroll events in milliseconds (default: 100) */
scroll?: number;
};
};
sanitize?: {
/** Enable PII sanitization (default: true) */
enabled?: boolean;
/**
* PII patterns to detect and mask
* - Can be a preset name: 'all', 'minimal', 'financial', 'contact', 'gdpr', 'pci', etc.
* - Or an array of pattern names: ['email', 'phone', 'ip']
*/
patterns?: 'all' | 'minimal' | 'financial' | 'contact' | 'identification' | 'kazakhstan' | 'gdpr' | 'pci' | Array<'email' | 'phone' | 'creditcard' | 'ssn' | 'iin' | 'ip' | 'custom'>;
/** Custom regex patterns for PII detection */
customPatterns?: Array<{
name: string;
regex: RegExp;
description?: string;
examples?: string[];
priority?: number;
}>;
/** CSS selectors to exclude from sanitization */
excludeSelectors?: string[];
};
}
export interface BugReportPayload {
title: string;
description: string;
report: BugReport;
}
export interface BugReport {
screenshotKey?: string;
console: Array<{
level: string;
message: string;
timestamp: number;
stack?: string;
}>;
network: Array<{
url: string;
method: string;
status: number;
duration: number;
timestamp: number;
error?: string;
}>;
metadata: BrowserMetadata;
replay?: eventWithTime[];
replayKey?: string;
_screenshotPreview?: string;
}
export type { BrowserMetadata } from './capture/metadata';
export { ScreenshotCapture } from './capture/screenshot';
export { ConsoleCapture } from './capture/console';
export { NetworkCapture } from './capture/network';
export { MetadataCapture } from './capture/metadata';
export { DOMCollector } from './collectors';
export type { DOMCollectorConfig } from './collectors';
export { CircularBuffer } from './core/buffer';
export type { CircularBufferConfig } from './core/buffer';
export { compressData, decompressData, compressImage, estimateSize, getCompressionRatio, } from './core/compress';
export { submitWithAuth, getAuthHeaders, clearOfflineQueue } from './core/transport';
export type { AuthConfig, TransportOptions, RetryConfig } from './core/transport';
export type { OfflineConfig } from './core/offline-queue';
export type { Logger, LogLevel, LoggerConfig } from './utils/logger';
export { getLogger, configureLogger, createLogger } from './utils/logger';
export { DirectUploader } from './core/uploader';
export type { UploadResult } from './core/uploader';
export { compressReplayEvents, canvasToBlob, estimateCompressedReplaySize, isWithinSizeLimit, } from './core/upload-helpers';
export { createSanitizer, Sanitizer } from './utils/sanitize';
export type { PIIPattern, CustomPattern, SanitizeConfig } from './utils/sanitize';
export { DEFAULT_PATTERNS, PATTERN_PRESETS, PATTERN_CATEGORIES, PatternBuilder, createPatternConfig, getPattern, getPatternsByCategory, validatePattern, } from './utils/sanitize';
export type { PIIPatternName, PatternDefinition } from './utils/sanitize';
export { FloatingButton } from './widget/button';
export type { FloatingButtonOptions } from './widget/button';
export { BugReportModal } from './widget/modal';
export type { BugReportData, BugReportModalOptions, PIIDetection } from './widget/modal';
export type { eventWithTime } from '@rrweb/types';
/**
* Convenience function to sanitize text with default PII patterns
* Useful for quick sanitization without creating a Sanitizer instance
*
* @param text - Text to sanitize
* @returns Sanitized text with PII redacted
*
* @example
* ```typescript
* const sanitized = sanitize('Email: user@example.com');
* // Returns: 'Email: [REDACTED]'
* ```
*/
export declare function sanitize(text: string): string;