bugstack-sdk 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/fingerprint.ts","../../../src/core/deduplicator.ts","../../../src/core/queue.ts","../../../src/core/client.ts","../../../src/core/utils/stack-parser.ts","../../../src/adapters/generic/index.ts"],"names":["SDK_VERSION"],"mappings":";AAcO,SAAS,yBAAyB,KAAA,EAA8B;AAErE,EAAA,MAAM,SAAA,GAAY,MAAM,IAAA,IAAQ,OAAA;AAChC,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,IAAS,SAAA;AAC7B,EAAA,MAAM,cAAA,GAAiB,iBAAA,CAAkB,KAAA,CAAM,KAAK,CAAA;AAEpD,EAAA,MAAM,MAAM,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,KAAK,IAAI,cAAc,CAAA,CAAA;AAGnD,EAAA,OAAO,WAAW,GAAG,CAAA;AACvB;AASA,SAAS,kBAAkB,KAAA,EAAwB;AACjD,EAAA,IAAI,CAAC,OAAO,OAAO,SAAA;AAEnB,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,KAAA,CAAM,IAAI,CAAA;AAI9B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,OAAA,GAAU,KAAK,IAAA,EAAK;AAC1B,IAAA,IAAI,OAAA,CAAQ,UAAA,CAAW,KAAK,CAAA,EAAG;AAC7B,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,OAAA,GAAU,KAAK,IAAA,EAAK;AAC1B,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,OAAO,OAAA;AAAA,IACT;AAAA,EACF;AAEA,EAAA,OAAO,SAAA;AACT;AAYA,SAAS,WAAW,GAAA,EAAqB;AACvC,EAAA,IAAI,IAAA,GA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,KAAW;AAC3C,IAAA,MAAM,KAAA,GAAQ,kBAAkB,KAAA,GAAQ,MAAA,GAAS,IAAI,KAAA,CAAM,MAAA,CAAO,MAAM,CAAC,CAAA;AACzE,IAAA,YAAA,CAAa,OAAO,EAAE,IAAA,EAAM,sBAAsB,CAAA,CAAE,MAAM,MAAM;AAAA,IAEhE,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AACH;AAuBO,SAAS,mBAAmB,YAAA,EAAuC;AACxE,EAAA,OAAO,CAAC,OAAwB,kBAAA,KAAiD;AAC/E,IAAA,OAAO,aAAa,KAAA,EAAO;AAAA,MACzB,GAAG,YAAA;AAAA,MACH,GAAG;AAAA,KACJ,CAAA;AAAA,EACH,CAAA;AACF","file":"index.mjs","sourcesContent":["import type { CapturedError } from \"./types\";\r\n\r\n/**\r\n * Generate a stable fingerprint (hash) for an error\r\n *\r\n * The fingerprint is used for deduplication - same errors should produce\r\n * the same fingerprint. This is based on:\r\n * - Error type/name\r\n * - Route where error occurred\r\n * - First line of stack trace (usually the line that caused the error)\r\n *\r\n * @param error - The captured error object\r\n * @returns A hex string fingerprint\r\n */\r\nexport function generateErrorFingerprint(error: CapturedError): string {\r\n // Build a stable key from error properties\r\n const errorType = error.name || \"Error\";\r\n const route = error.route || \"unknown\";\r\n const stackFirstLine = getStackFirstLine(error.stack);\r\n\r\n const key = `${errorType}:${route}:${stackFirstLine}`;\r\n\r\n // Generate a simple hash\r\n return simpleHash(key);\r\n}\r\n\r\n/**\r\n * Extract the first meaningful line from a stack trace\r\n * This is usually the line where the error actually occurred\r\n *\r\n * @param stack - The stack trace string\r\n * @returns First line of stack or \"unknown\"\r\n */\r\nfunction getStackFirstLine(stack?: string): string {\r\n if (!stack) return \"unknown\";\r\n\r\n const lines = stack.split(\"\\n\");\r\n\r\n // Find first line that looks like a stack frame\r\n // (starts with \"at \" in V8 stack traces)\r\n for (const line of lines) {\r\n const trimmed = line.trim();\r\n if (trimmed.startsWith(\"at \")) {\r\n return trimmed;\r\n }\r\n }\r\n\r\n // Fallback: use first non-empty line\r\n for (const line of lines) {\r\n const trimmed = line.trim();\r\n if (trimmed) {\r\n return trimmed;\r\n }\r\n }\r\n\r\n return \"unknown\";\r\n}\r\n\r\n/**\r\n * Simple string hash function\r\n *\r\n * This is a basic implementation of the DJB2 hash algorithm.\r\n * It's not cryptographically secure, but it's fast and produces\r\n * reasonably distributed hashes for our use case.\r\n *\r\n * @param str - String to hash\r\n * @returns Hex string hash\r\n */\r\nfunction simpleHash(str: string): string {\r\n let hash = 5381;\r\n\r\n for (let i = 0; i < str.length; i++) {\r\n // hash * 33 + char\r\n hash = (hash << 5) + hash + str.charCodeAt(i);\r\n hash = hash & hash; // Convert to 32-bit integer\r\n }\r\n\r\n // Convert to unsigned 32-bit integer and then to hex\r\n const unsignedHash = hash >>> 0;\r\n return unsignedHash.toString(16).padStart(8, \"0\");\r\n}\r\n\r\n/**\r\n * Generate a fingerprint from error-like object\r\n *\r\n * This is a convenience function for generating fingerprints from\r\n * minimal error information (e.g., during server-side processing)\r\n *\r\n * @param errorName - Error type/name\r\n * @param route - Route where error occurred\r\n * @param stack - Stack trace\r\n * @returns Hex string fingerprint\r\n */\r\nexport function generateFingerprintFromParts(\r\n errorName: string,\r\n route: string,\r\n stack?: string\r\n): string {\r\n const stackFirstLine = getStackFirstLine(stack);\r\n const key = `${errorName}:${route}:${stackFirstLine}`;\r\n return simpleHash(key);\r\n}\r\n","/**\r\n * Client-side error deduplicator\r\n *\r\n * Prevents the same error (identified by fingerprint) from being sent\r\n * multiple times within a configurable time window. This helps avoid\r\n * flooding the BugStack service with duplicate errors.\r\n */\r\nexport class ErrorDeduplicator {\r\n /**\r\n * Cache of fingerprint → timestamp mapping\r\n * Key: error fingerprint (hex string)\r\n * Value: timestamp (ms) when error was last sent\r\n */\r\n private cache: Map<string, number>;\r\n\r\n /**\r\n * Time window in milliseconds\r\n * Errors with the same fingerprint within this window are considered duplicates\r\n */\r\n private window: number;\r\n\r\n /**\r\n * Interval ID for cleanup task\r\n */\r\n private cleanupIntervalId?: NodeJS.Timeout;\r\n\r\n /**\r\n * Create a new deduplicator\r\n *\r\n * @param window - Deduplication window in milliseconds (default: 5 minutes)\r\n */\r\n constructor(window: number = 5 * 60 * 1000) {\r\n this.cache = new Map();\r\n this.window = window;\r\n\r\n // Start automatic cleanup every minute\r\n this.startCleanup();\r\n }\r\n\r\n /**\r\n * Check if an error should be sent\r\n *\r\n * @param fingerprint - Error fingerprint\r\n * @returns true if error should be sent, false if it's a duplicate\r\n */\r\n shouldSend(fingerprint: string): boolean {\r\n const now = Date.now();\r\n const lastSent = this.cache.get(fingerprint);\r\n\r\n if (lastSent !== undefined) {\r\n const elapsed = now - lastSent;\r\n\r\n // If error was sent within the window, it's a duplicate\r\n if (elapsed < this.window) {\r\n return false;\r\n }\r\n }\r\n\r\n // Mark this fingerprint as sent\r\n this.cache.set(fingerprint, now);\r\n return true;\r\n }\r\n\r\n /**\r\n * Mark an error as sent (manually)\r\n *\r\n * This can be used to pre-populate the cache or update the timestamp\r\n * after a successful send.\r\n *\r\n * @param fingerprint - Error fingerprint\r\n */\r\n markSent(fingerprint: string): void {\r\n this.cache.set(fingerprint, Date.now());\r\n }\r\n\r\n /**\r\n * Check if an error fingerprint is in the cache\r\n *\r\n * @param fingerprint - Error fingerprint\r\n * @returns true if fingerprint exists and is within the window\r\n */\r\n has(fingerprint: string): boolean {\r\n const lastSent = this.cache.get(fingerprint);\r\n if (lastSent === undefined) {\r\n return false;\r\n }\r\n\r\n const elapsed = Date.now() - lastSent;\r\n return elapsed < this.window;\r\n }\r\n\r\n /**\r\n * Get the number of entries in the cache\r\n */\r\n get size(): number {\r\n return this.cache.size;\r\n }\r\n\r\n /**\r\n * Clear all entries from the cache\r\n */\r\n clear(): void {\r\n this.cache.clear();\r\n }\r\n\r\n /**\r\n * Remove expired entries from the cache\r\n *\r\n * This is called automatically every minute, but can also be\r\n * called manually to free up memory.\r\n */\r\n cleanup(): void {\r\n const now = Date.now();\r\n const toDelete: string[] = [];\r\n\r\n // Find expired entries\r\n for (const [fingerprint, timestamp] of this.cache.entries()) {\r\n const elapsed = now - timestamp;\r\n if (elapsed >= this.window) {\r\n toDelete.push(fingerprint);\r\n }\r\n }\r\n\r\n // Delete expired entries\r\n for (const fingerprint of toDelete) {\r\n this.cache.delete(fingerprint);\r\n }\r\n }\r\n\r\n /**\r\n * Start automatic cleanup task\r\n *\r\n * Runs cleanup every minute to remove expired entries\r\n */\r\n private startCleanup(): void {\r\n // Run cleanup every minute\r\n this.cleanupIntervalId = setInterval(() => {\r\n this.cleanup();\r\n }, 60 * 1000);\r\n\r\n // Ensure the interval doesn't prevent Node.js from exiting\r\n if (this.cleanupIntervalId.unref) {\r\n this.cleanupIntervalId.unref();\r\n }\r\n }\r\n\r\n /**\r\n * Stop automatic cleanup task\r\n *\r\n * This should be called when shutting down to prevent memory leaks\r\n */\r\n destroy(): void {\r\n if (this.cleanupIntervalId) {\r\n clearInterval(this.cleanupIntervalId);\r\n this.cleanupIntervalId = undefined;\r\n }\r\n this.cache.clear();\r\n }\r\n\r\n /**\r\n * Get cache statistics (for debugging)\r\n */\r\n getStats(): {\r\n size: number;\r\n window: number;\r\n entries: Array<{ fingerprint: string; age: number }>;\r\n } {\r\n const now = Date.now();\r\n const entries = Array.from(this.cache.entries()).map(([fingerprint, timestamp]) => ({\r\n fingerprint,\r\n age: now - timestamp,\r\n }));\r\n\r\n return {\r\n size: this.cache.size,\r\n window: this.window,\r\n entries,\r\n };\r\n }\r\n}\r\n","import type { CapturedError, SourceContext } from \"./types\";\r\n\r\n/**\r\n * Queued error item\r\n */\r\ninterface QueuedError {\r\n /**\r\n * The error to send\r\n */\r\n error: CapturedError;\r\n\r\n /**\r\n * Source context (if available)\r\n */\r\n sourceContext?: SourceContext;\r\n\r\n /**\r\n * Number of send attempts\r\n */\r\n attempts: number;\r\n\r\n /**\r\n * Timestamp of last attempt\r\n */\r\n lastAttempt?: number;\r\n\r\n /**\r\n * Next retry timestamp\r\n */\r\n nextRetry: number;\r\n}\r\n\r\n/**\r\n * Function that sends an error to the service\r\n */\r\ntype SendFunction = (\r\n error: CapturedError,\r\n sourceContext?: SourceContext\r\n) => Promise<boolean>;\r\n\r\n/**\r\n * Retry queue with exponential backoff\r\n *\r\n * Handles failed error reports by queuing them and retrying with\r\n * exponentially increasing delays. Never blocks the host application.\r\n */\r\nexport class RetryQueue {\r\n /**\r\n * Queue of errors waiting to be sent\r\n */\r\n private queue: QueuedError[] = [];\r\n\r\n /**\r\n * Whether the queue is currently processing\r\n */\r\n private processing: boolean = false;\r\n\r\n /**\r\n * Maximum number of retry attempts\r\n */\r\n private maxRetries: number = 5;\r\n\r\n /**\r\n * Base backoff delay in milliseconds\r\n */\r\n private baseDelay: number = 1000; // 1 second\r\n\r\n /**\r\n * Maximum backoff delay in milliseconds\r\n */\r\n private maxDelay: number = 16000; // 16 seconds\r\n\r\n /**\r\n * Function to send errors\r\n */\r\n private sendFn: SendFunction;\r\n\r\n /**\r\n * Debug mode\r\n */\r\n private debug: boolean;\r\n\r\n /**\r\n * Processing interval ID\r\n */\r\n private intervalId?: NodeJS.Timeout;\r\n\r\n /**\r\n * Create a new retry queue\r\n *\r\n * @param sendFn - Function to send errors\r\n * @param options - Configuration options\r\n */\r\n constructor(\r\n sendFn: SendFunction,\r\n options?: {\r\n maxRetries?: number;\r\n baseDelay?: number;\r\n maxDelay?: number;\r\n debug?: boolean;\r\n }\r\n ) {\r\n this.sendFn = sendFn;\r\n this.maxRetries = options?.maxRetries ?? 5;\r\n this.baseDelay = options?.baseDelay ?? 1000;\r\n this.maxDelay = options?.maxDelay ?? 16000;\r\n this.debug = options?.debug ?? false;\r\n\r\n // Start processing queue periodically\r\n this.startProcessing();\r\n }\r\n\r\n /**\r\n * Enqueue an error for sending\r\n *\r\n * This is non-blocking and returns immediately.\r\n *\r\n * @param error - The error to send\r\n * @param sourceContext - Source context (optional)\r\n */\r\n enqueue(error: CapturedError, sourceContext?: SourceContext): void {\r\n const queuedError: QueuedError = {\r\n error,\r\n sourceContext,\r\n attempts: 0,\r\n nextRetry: Date.now(), // Send immediately on first attempt\r\n };\r\n\r\n this.queue.push(queuedError);\r\n this.log(`Enqueued error: ${error.id} (queue size: ${this.queue.length})`);\r\n\r\n // Trigger processing\r\n this.processQueue();\r\n }\r\n\r\n /**\r\n * Get the current queue size\r\n */\r\n get size(): number {\r\n return this.queue.length;\r\n }\r\n\r\n /**\r\n * Clear all items from the queue\r\n */\r\n clear(): void {\r\n this.queue = [];\r\n }\r\n\r\n /**\r\n * Destroy the queue and stop processing\r\n */\r\n destroy(): void {\r\n if (this.intervalId) {\r\n clearInterval(this.intervalId);\r\n this.intervalId = undefined;\r\n }\r\n this.queue = [];\r\n this.processing = false;\r\n }\r\n\r\n /**\r\n * Start periodic queue processing\r\n */\r\n private startProcessing(): void {\r\n // Process queue every 500ms\r\n this.intervalId = setInterval(() => {\r\n this.processQueue();\r\n }, 500);\r\n\r\n // Ensure the interval doesn't prevent Node.js from exiting\r\n if (this.intervalId.unref) {\r\n this.intervalId.unref();\r\n }\r\n }\r\n\r\n /**\r\n * Process the queue\r\n *\r\n * This is called periodically and also immediately after enqueue.\r\n * Non-blocking - errors are caught and logged.\r\n */\r\n private async processQueue(): Promise<void> {\r\n if (this.processing || this.queue.length === 0) {\r\n return;\r\n }\r\n\r\n this.processing = true;\r\n\r\n try {\r\n const now = Date.now();\r\n\r\n // Find errors ready to be sent (nextRetry <= now)\r\n const readyErrors = this.queue.filter((item) => item.nextRetry <= now);\r\n\r\n if (readyErrors.length === 0) {\r\n return;\r\n }\r\n\r\n this.log(`Processing ${readyErrors.length} ready errors`);\r\n\r\n // Process each ready error\r\n for (const item of readyErrors) {\r\n await this.processItem(item);\r\n }\r\n } catch (err) {\r\n // Never let queue processing crash\r\n this.logError(\"Queue processing error:\", err);\r\n } finally {\r\n this.processing = false;\r\n }\r\n }\r\n\r\n /**\r\n * Process a single queued error\r\n *\r\n * @param item - The queued error item\r\n */\r\n private async processItem(item: QueuedError): Promise<void> {\r\n try {\r\n item.attempts++;\r\n item.lastAttempt = Date.now();\r\n\r\n this.log(\r\n `Sending error ${item.error.id} (attempt ${item.attempts}/${this.maxRetries})`\r\n );\r\n\r\n // Try to send the error\r\n const success = await this.sendFn(item.error, item.sourceContext);\r\n\r\n if (success) {\r\n // Success - remove from queue\r\n this.log(`Successfully sent error: ${item.error.id}`);\r\n this.removeFromQueue(item);\r\n } else {\r\n // Failed - retry or give up\r\n this.handleFailure(item);\r\n }\r\n } catch (err) {\r\n // Error during send - retry or give up\r\n this.logError(`Error sending ${item.error.id}:`, err);\r\n this.handleFailure(item);\r\n }\r\n }\r\n\r\n /**\r\n * Handle a failed send attempt\r\n *\r\n * @param item - The queued error item\r\n */\r\n private handleFailure(item: QueuedError): void {\r\n if (item.attempts >= this.maxRetries) {\r\n // Max retries exceeded - give up\r\n this.logError(\r\n `Max retries exceeded for error ${item.error.id}, dropping`\r\n );\r\n this.removeFromQueue(item);\r\n } else {\r\n // Schedule retry with exponential backoff\r\n const delay = this.calculateBackoff(item.attempts);\r\n item.nextRetry = Date.now() + delay;\r\n\r\n this.log(\r\n `Scheduling retry for error ${item.error.id} in ${delay}ms (attempt ${item.attempts}/${this.maxRetries})`\r\n );\r\n }\r\n }\r\n\r\n /**\r\n * Calculate exponential backoff delay\r\n *\r\n * Backoff formula: min(baseDelay * 2^(attempts - 1), maxDelay)\r\n * - Attempt 1: 1s\r\n * - Attempt 2: 2s\r\n * - Attempt 3: 4s\r\n * - Attempt 4: 8s\r\n * - Attempt 5: 16s\r\n *\r\n * @param attempts - Number of attempts\r\n * @returns Delay in milliseconds\r\n */\r\n private calculateBackoff(attempts: number): number {\r\n const delay = this.baseDelay * Math.pow(2, attempts - 1);\r\n return Math.min(delay, this.maxDelay);\r\n }\r\n\r\n /**\r\n * Remove an item from the queue\r\n *\r\n * @param item - The item to remove\r\n */\r\n private removeFromQueue(item: QueuedError): void {\r\n const index = this.queue.indexOf(item);\r\n if (index !== -1) {\r\n this.queue.splice(index, 1);\r\n }\r\n }\r\n\r\n /**\r\n * Log a message (if debug mode is enabled)\r\n *\r\n * @param message - Message to log\r\n */\r\n private log(message: string): void {\r\n if (this.debug) {\r\n console.log(`[BugStack Queue] ${message}`);\r\n }\r\n }\r\n\r\n /**\r\n * Log an error (if debug mode is enabled)\r\n *\r\n * @param message - Message to log\r\n * @param error - Error object (optional)\r\n */\r\n private logError(message: string, error?: unknown): void {\r\n if (this.debug) {\r\n if (error) {\r\n console.error(`[BugStack Queue] ${message}`, error);\r\n } else {\r\n console.error(`[BugStack Queue] ${message}`);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Get queue statistics (for debugging)\r\n */\r\n getStats(): {\r\n size: number;\r\n processing: boolean;\r\n items: Array<{\r\n errorId: string;\r\n attempts: number;\r\n nextRetry: number;\r\n timeUntilRetry: number;\r\n }>;\r\n } {\r\n const now = Date.now();\r\n\r\n return {\r\n size: this.queue.length,\r\n processing: this.processing,\r\n items: this.queue.map((item) => ({\r\n errorId: item.error.id,\r\n attempts: item.attempts,\r\n nextRetry: item.nextRetry,\r\n timeUntilRetry: Math.max(0, item.nextRetry - now),\r\n })),\r\n };\r\n }\r\n}\r\n","import type {\r\n ErrorCaptureConfig,\r\n ResolvedConfig,\r\n CapturedError,\r\n ErrorReportPayload,\r\n SourceContext,\r\n} from \"./types\";\r\nimport { generateErrorFingerprint } from \"./fingerprint\";\r\nimport { ErrorDeduplicator } from \"./deduplicator\";\r\nimport { RetryQueue } from \"./queue\";\r\n\r\nconst SDK_VERSION = \"0.2.0\";\r\nconst DEFAULT_ENDPOINT = \"http://localhost:3001/api/capture\";\r\nconst DEFAULT_TIMEOUT = 5000;\r\nconst DEFAULT_MAX_BODY_SIZE = 10000;\r\nconst DEFAULT_DEDUPLICATION_WINDOW = 5 * 60 * 1000; // 5 minutes\r\n\r\n/**\r\n * Default sensitive fields to redact from requests\r\n */\r\nconst DEFAULT_REDACT_FIELDS = [\r\n \"password\",\r\n \"secret\",\r\n \"token\",\r\n \"apikey\",\r\n \"api_key\",\r\n \"apiKey\",\r\n \"authorization\",\r\n \"auth\",\r\n \"credential\",\r\n \"private\",\r\n \"credit_card\",\r\n \"creditcard\",\r\n \"card_number\",\r\n \"cvv\",\r\n \"ssn\",\r\n \"social_security\",\r\n];\r\n\r\n/**\r\n * BugStack Error Capture Client\r\n *\r\n * Singleton client for capturing and reporting errors to the BugStack service.\r\n * Now includes client-side deduplication and retry queue with exponential backoff.\r\n */\r\nexport class ErrorCaptureClient {\r\n private config: ResolvedConfig;\r\n private static instance: ErrorCaptureClient | null = null;\r\n private deduplicator: ErrorDeduplicator;\r\n private retryQueue: RetryQueue;\r\n\r\n constructor(config: ErrorCaptureConfig) {\r\n const isProduction = process.env.NODE_ENV === \"production\";\r\n\r\n this.config = {\r\n apiKey: config.apiKey,\r\n endpoint:\r\n config.endpoint ??\r\n process.env.BUGSTACK_ENDPOINT ??\r\n DEFAULT_ENDPOINT,\r\n projectId: config.projectId ?? process.env.BUGSTACK_PROJECT_ID ?? \"\",\r\n environment:\r\n config.environment ?? process.env.NODE_ENV ?? \"development\",\r\n autoFix: config.autoFix ?? false,\r\n enabled: config.enabled ?? true,\r\n captureRequestBody: config.captureRequestBody ?? true,\r\n captureQueryParams: config.captureQueryParams ?? true,\r\n captureHeaders: config.captureHeaders ?? true,\r\n maxBodySize: config.maxBodySize ?? DEFAULT_MAX_BODY_SIZE,\r\n redactFields: [\r\n ...DEFAULT_REDACT_FIELDS,\r\n ...(config.redactFields ?? []),\r\n ],\r\n metadata: config.metadata ?? {},\r\n timeout: config.timeout ?? DEFAULT_TIMEOUT,\r\n deduplicationWindow:\r\n config.deduplicationWindow ?? DEFAULT_DEDUPLICATION_WINDOW,\r\n debug: config.debug ?? !isProduction,\r\n shouldCapture: config.shouldCapture,\r\n beforeSend: config.beforeSend,\r\n };\r\n\r\n // Initialize deduplicator\r\n this.deduplicator = new ErrorDeduplicator(this.config.deduplicationWindow);\r\n\r\n // Initialize retry queue with send function bound to this instance\r\n this.retryQueue = new RetryQueue(\r\n (error, sourceContext) => this.sendErrorToService(error, sourceContext),\r\n {\r\n maxRetries: 5,\r\n baseDelay: 1000,\r\n maxDelay: 16000,\r\n debug: this.config.debug,\r\n }\r\n );\r\n\r\n this.log(\"BugStack client initialized\", {\r\n endpoint: this.config.endpoint,\r\n projectId: this.config.projectId,\r\n environment: this.config.environment,\r\n autoFix: this.config.autoFix,\r\n deduplicationWindow: this.config.deduplicationWindow,\r\n });\r\n }\r\n\r\n /**\r\n * Initialize the singleton client instance\r\n */\r\n static init(config: ErrorCaptureConfig): ErrorCaptureClient {\r\n // Clean up existing instance if present\r\n if (ErrorCaptureClient.instance) {\r\n ErrorCaptureClient.instance.destroy();\r\n }\r\n\r\n ErrorCaptureClient.instance = new ErrorCaptureClient(config);\r\n return ErrorCaptureClient.instance;\r\n }\r\n\r\n /**\r\n * Get the singleton client instance\r\n */\r\n static getInstance(): ErrorCaptureClient | null {\r\n return ErrorCaptureClient.instance;\r\n }\r\n\r\n /**\r\n * Check if the client has been initialized\r\n */\r\n static isInitialized(): boolean {\r\n return ErrorCaptureClient.instance !== null;\r\n }\r\n\r\n /**\r\n * Reset the client (mainly for testing)\r\n */\r\n static reset(): void {\r\n if (ErrorCaptureClient.instance) {\r\n ErrorCaptureClient.instance.destroy();\r\n }\r\n ErrorCaptureClient.instance = null;\r\n }\r\n\r\n /**\r\n * Report an error to the BugStack service\r\n *\r\n * This method includes deduplication and queuing for resilience.\r\n *\r\n * @param error - The captured error\r\n * @param sourceContext - Source code context (optional)\r\n * @returns Promise that resolves to true if error was accepted (not deduplicated)\r\n */\r\n async reportError(\r\n error: CapturedError,\r\n sourceContext?: SourceContext\r\n ): Promise<boolean> {\r\n if (!this.config.enabled) {\r\n this.log(\"Error capture is disabled, skipping report\");\r\n return false;\r\n }\r\n\r\n // Apply beforeSend hook if provided\r\n let errorToSend = error;\r\n if (this.config.beforeSend) {\r\n const modified = this.config.beforeSend(error);\r\n if (modified === null) {\r\n this.log(\"Error filtered by beforeSend hook\");\r\n return false;\r\n }\r\n errorToSend = modified;\r\n }\r\n\r\n // Generate fingerprint for deduplication\r\n const fingerprint = generateErrorFingerprint(errorToSend);\r\n errorToSend.fingerprint = fingerprint;\r\n\r\n // Check deduplication\r\n if (!this.deduplicator.shouldSend(fingerprint)) {\r\n this.log(`Error deduplicated: ${error.id} (fingerprint: ${fingerprint})`);\r\n return false;\r\n }\r\n\r\n this.log(`Reporting error: ${error.id} (fingerprint: ${fingerprint})`);\r\n\r\n // Add project metadata\r\n errorToSend.projectId = this.config.projectId || errorToSend.projectId;\r\n errorToSend.environment = this.config.environment;\r\n errorToSend.metadata = {\r\n ...this.config.metadata,\r\n ...errorToSend.metadata,\r\n autoFix: this.config.autoFix,\r\n };\r\n\r\n // Enqueue for sending (non-blocking)\r\n this.retryQueue.enqueue(errorToSend, sourceContext);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Send an error to the service (internal method)\r\n *\r\n * This is used by the retry queue. Returns true on success, false on failure.\r\n *\r\n * @param error - The error to send\r\n * @param sourceContext - Source context (optional)\r\n * @returns Promise that resolves to true on success\r\n */\r\n private async sendErrorToService(\r\n error: CapturedError,\r\n sourceContext?: SourceContext\r\n ): Promise<boolean> {\r\n const payload: ErrorReportPayload = {\r\n error,\r\n sourceContext,\r\n };\r\n\r\n try {\r\n const controller = new AbortController();\r\n const timeoutId = setTimeout(\r\n () => controller.abort(),\r\n this.config.timeout\r\n );\r\n\r\n const response = await fetch(this.config.endpoint, {\r\n method: \"POST\",\r\n headers: {\r\n \"Content-Type\": \"application/json\",\r\n \"X-BugStack-API-Key\": this.config.apiKey,\r\n \"X-BugStack-SDK-Version\": SDK_VERSION,\r\n },\r\n body: JSON.stringify(payload),\r\n signal: controller.signal,\r\n });\r\n\r\n clearTimeout(timeoutId);\r\n\r\n if (!response.ok) {\r\n this.logError(\r\n `Failed to send error: HTTP ${response.status} ${response.statusText}`\r\n );\r\n return false;\r\n }\r\n\r\n this.log(`Error sent successfully: ${error.id}`);\r\n return true;\r\n } catch (err) {\r\n if (err instanceof Error && err.name === \"AbortError\") {\r\n this.logError(`Error send timed out after ${this.config.timeout}ms`);\r\n } else {\r\n this.logError(\"Failed to send error:\", err);\r\n }\r\n return false;\r\n }\r\n }\r\n\r\n /**\r\n * Get the resolved configuration\r\n */\r\n getConfig(): ResolvedConfig {\r\n return { ...this.config };\r\n }\r\n\r\n /**\r\n * Check if a field should be redacted\r\n */\r\n shouldRedact(fieldName: string): boolean {\r\n const lowerField = fieldName.toLowerCase();\r\n return this.config.redactFields.some(\r\n (redact) =>\r\n lowerField.includes(redact.toLowerCase()) ||\r\n redact.toLowerCase().includes(lowerField)\r\n );\r\n }\r\n\r\n /**\r\n * Get the SDK version\r\n */\r\n static getVersion(): string {\r\n return SDK_VERSION;\r\n }\r\n\r\n /**\r\n * Get client statistics (for debugging)\r\n */\r\n getStats(): {\r\n deduplicator: ReturnType<ErrorDeduplicator[\"getStats\"]>;\r\n retryQueue: ReturnType<RetryQueue[\"getStats\"]>;\r\n } {\r\n return {\r\n deduplicator: this.deduplicator.getStats(),\r\n retryQueue: this.retryQueue.getStats(),\r\n };\r\n }\r\n\r\n /**\r\n * Clean up resources\r\n *\r\n * Should be called when shutting down to prevent memory leaks\r\n */\r\n destroy(): void {\r\n this.deduplicator.destroy();\r\n this.retryQueue.destroy();\r\n }\r\n\r\n private log(message: string, data?: Record<string, unknown>): void {\r\n if (this.config.debug) {\r\n if (data) {\r\n console.log(`[BugStack] ${message}`, data);\r\n } else {\r\n console.log(`[BugStack] ${message}`);\r\n }\r\n }\r\n }\r\n\r\n private logError(message: string, error?: unknown): void {\r\n if (this.config.debug) {\r\n if (error) {\r\n console.error(`[BugStack] ${message}`, error);\r\n } else {\r\n console.error(`[BugStack] ${message}`);\r\n }\r\n }\r\n }\r\n}\r\n\r\n// Legacy alias for backwards compatibility\r\nexport const BugStackClient = ErrorCaptureClient;\r\n","import type { StackFrame } from \"../types\";\r\n\r\n/**\r\n * Regular expression to parse V8 stack trace frames\r\n * Handles formats like:\r\n * at functionName (file:line:column)\r\n * at file:line:column\r\n * at async functionName (file:line:column)\r\n */\r\nconst V8_STACK_FRAME_REGEX =\r\n /^\\s*at\\s+(?:async\\s+)?(?:(.+?)\\s+\\()?(?:(.+?):(\\d+):(\\d+))\\)?$/;\r\n\r\n/**\r\n * Check if a file path is from node_modules\r\n */\r\nfunction isNodeModule(filePath: string): boolean {\r\n return filePath.includes(\"node_modules\");\r\n}\r\n\r\n/**\r\n * Check if a file path is internal Node.js code\r\n */\r\nfunction isInternalCode(filePath: string): boolean {\r\n return (\r\n filePath.startsWith(\"node:\") ||\r\n filePath.startsWith(\"internal/\") ||\r\n !filePath.includes(\"/\")\r\n );\r\n}\r\n\r\n/**\r\n * Clean up function names\r\n */\r\nfunction cleanFunctionName(name: string | undefined): string | undefined {\r\n if (!name) return undefined;\r\n\r\n // Remove common prefixes\r\n return name\r\n .replace(/^Object\\./, \"\")\r\n .replace(/^Module\\./, \"\")\r\n .replace(/^__webpack_require__\\./, \"\")\r\n .replace(/^webpack_require\\./, \"\")\r\n .trim();\r\n}\r\n\r\n/**\r\n * Parse a V8 stack trace into structured frames\r\n */\r\nexport function parseStackTrace(stack: string | undefined): StackFrame[] {\r\n if (!stack) return [];\r\n\r\n const lines = stack.split(\"\\n\");\r\n const frames: StackFrame[] = [];\r\n\r\n for (const line of lines) {\r\n const match = V8_STACK_FRAME_REGEX.exec(line);\r\n\r\n if (match) {\r\n const [, functionName, file, lineStr, columnStr] = match;\r\n\r\n const frame: StackFrame = {\r\n function: cleanFunctionName(functionName),\r\n file: file ?? undefined,\r\n line: lineStr ? parseInt(lineStr, 10) : undefined,\r\n column: columnStr ? parseInt(columnStr, 10) : undefined,\r\n };\r\n\r\n if (frame.file) {\r\n frame.isNodeModule = isNodeModule(frame.file);\r\n frame.isInternal = isInternalCode(frame.file);\r\n }\r\n\r\n frames.push(frame);\r\n }\r\n }\r\n\r\n return frames;\r\n}\r\n\r\n/**\r\n * Get the first application frame (non-node_modules, non-internal)\r\n */\r\nexport function getFirstAppFrame(frames: StackFrame[]): StackFrame | undefined {\r\n return frames.find((frame) => !frame.isNodeModule && !frame.isInternal);\r\n}\r\n\r\n/**\r\n * Filter stack frames to only include application code\r\n */\r\nexport function getAppFrames(frames: StackFrame[]): StackFrame[] {\r\n return frames.filter((frame) => !frame.isNodeModule && !frame.isInternal);\r\n}\r\n\r\n/**\r\n * Format stack frames back to a string (useful for cleaned stack traces)\r\n */\r\nexport function formatStackFrames(frames: StackFrame[]): string {\r\n return frames\r\n .map((frame) => {\r\n const location = [frame.file, frame.line, frame.column]\r\n .filter(Boolean)\r\n .join(\":\");\r\n\r\n if (frame.function) {\r\n return ` at ${frame.function} (${location})`;\r\n }\r\n return ` at ${location}`;\r\n })\r\n .join(\"\\n\");\r\n}\r\n","/**\r\n * BugStack SDK - Generic Adapter\r\n *\r\n * Generic error capture for any Node.js application\r\n * Use this for non-Express, non-Next.js applications\r\n */\r\n\r\nimport { ErrorCaptureClient } from \"../../core/client\";\r\nimport type { ErrorCaptureConfig, CapturedError } from \"../../core/types\";\r\nimport { parseStackTrace, getFirstAppFrame } from \"../../core/utils/stack-parser\";\r\n\r\nconst SDK_VERSION = \"0.2.0\";\r\n\r\n/**\r\n * Generate a unique error ID\r\n */\r\nfunction generateErrorId(): string {\r\n const timestamp = Date.now().toString(36);\r\n const random = Math.random().toString(36).substring(2, 9);\r\n return `err_${timestamp}_${random}`;\r\n}\r\n\r\n/**\r\n * Get Node.js version\r\n */\r\nfunction getNodeVersion(): string {\r\n try {\r\n return process.version;\r\n } catch {\r\n return \"unknown\";\r\n }\r\n}\r\n\r\n/**\r\n * Build a basic captured error from an Error object\r\n */\r\nfunction buildCapturedError(\r\n error: Error,\r\n client: ErrorCaptureClient,\r\n metadata?: Record<string, unknown>\r\n): CapturedError {\r\n const config = client.getConfig();\r\n const stackFrames = parseStackTrace(error.stack);\r\n const firstAppFrame = getFirstAppFrame(stackFrames);\r\n\r\n const capturedError: CapturedError = {\r\n id: generateErrorId(),\r\n name: error.name || \"Error\",\r\n message: error.message,\r\n stack: error.stack,\r\n stackFrames,\r\n timestamp: new Date().toISOString(),\r\n route: \"generic\",\r\n method: \"N/A\",\r\n statusCode: 500,\r\n url: \"N/A\",\r\n environment: config.environment,\r\n projectId: config.projectId,\r\n sdkVersion: SDK_VERSION,\r\n nodeVersion: getNodeVersion(),\r\n };\r\n\r\n // Add source location from first app frame\r\n if (firstAppFrame) {\r\n capturedError.metadata = {\r\n ...capturedError.metadata,\r\n sourceLocation: {\r\n file: firstAppFrame.file,\r\n line: firstAppFrame.line,\r\n column: firstAppFrame.column,\r\n function: firstAppFrame.function,\r\n },\r\n };\r\n }\r\n\r\n // Merge additional metadata\r\n if (metadata) {\r\n capturedError.metadata = {\r\n ...capturedError.metadata,\r\n ...metadata,\r\n };\r\n }\r\n\r\n return capturedError;\r\n}\r\n\r\n/**\r\n * Initialize BugStack for a generic Node.js application\r\n *\r\n * @example\r\n * ```typescript\r\n * import { initBugStack, captureError } from '@bugstack/sdk/generic';\r\n *\r\n * initBugStack({\r\n * apiKey: 'your-api-key',\r\n * projectId: 'your-project-id',\r\n * autoFix: true\r\n * });\r\n *\r\n * // Later, capture errors manually\r\n * try {\r\n * // your code\r\n * } catch (error) {\r\n * captureError(error, { operation: 'processData' });\r\n * }\r\n * ```\r\n */\r\nexport function initBugStack(config: ErrorCaptureConfig): ErrorCaptureClient {\r\n return ErrorCaptureClient.init(config);\r\n}\r\n\r\n/**\r\n * Manually capture and report an error\r\n *\r\n * @param error - The error to capture\r\n * @param metadata - Optional metadata to attach to the error\r\n * @returns Promise that resolves to true if error was accepted (not deduplicated)\r\n *\r\n * @example\r\n * ```typescript\r\n * import { captureError } from '@bugstack/sdk/generic';\r\n *\r\n * try {\r\n * await processData();\r\n * } catch (error) {\r\n * await captureError(error, {\r\n * operation: 'processData',\r\n * userId: user.id\r\n * });\r\n * throw error; // Re-throw if needed\r\n * }\r\n * ```\r\n */\r\nexport async function captureError(\r\n error: Error | unknown,\r\n metadata?: Record<string, unknown>\r\n): Promise<boolean> {\r\n const client = ErrorCaptureClient.getInstance();\r\n\r\n if (!client) {\r\n console.warn(\r\n \"[BugStack] Client not initialized. Call initBugStack() first.\"\r\n );\r\n return false;\r\n }\r\n\r\n // Normalize to Error instance\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n\r\n // Build and report error\r\n const capturedError = buildCapturedError(err, client, metadata);\r\n return client.reportError(capturedError);\r\n}\r\n\r\n/**\r\n * Capture an exception (alias for captureError)\r\n */\r\nexport const captureException = captureError;\r\n\r\n/**\r\n * Wrap a function with automatic error capture\r\n *\r\n * @param fn - The function to wrap\r\n * @param metadata - Optional metadata to attach to any errors\r\n * @returns Wrapped function that captures errors\r\n *\r\n * @example\r\n * ```typescript\r\n * import { wrapFunction } from '@bugstack/sdk/generic';\r\n *\r\n * const processData = wrapFunction(\r\n * async (data) => {\r\n * // your code that might throw\r\n * },\r\n * { operation: 'processData' }\r\n * );\r\n *\r\n * // Errors will be automatically captured\r\n * await processData(someData);\r\n * ```\r\n */\r\nexport function wrapFunction<T extends (...args: any[]) => any>(\r\n fn: T,\r\n metadata?: Record<string, unknown>\r\n): T {\r\n return ((...args: any[]) => {\r\n try {\r\n const result = fn(...args);\r\n\r\n // Handle async functions\r\n if (result instanceof Promise) {\r\n return result.catch((error) => {\r\n captureError(error, metadata);\r\n throw error; // Re-throw after capturing\r\n });\r\n }\r\n\r\n return result;\r\n } catch (error) {\r\n captureError(error, metadata);\r\n throw error; // Re-throw after capturing\r\n }\r\n }) as T;\r\n}\r\n\r\n/**\r\n * Install global error handlers\r\n *\r\n * This captures unhandled errors and promise rejections globally\r\n *\r\n * @example\r\n * ```typescript\r\n * import { initBugStack, installGlobalHandlers } from '@bugstack/sdk/generic';\r\n *\r\n * initBugStack({\r\n * apiKey: 'your-api-key',\r\n * projectId: 'your-project-id',\r\n * autoFix: true\r\n * });\r\n *\r\n * // Capture all unhandled errors\r\n * installGlobalHandlers();\r\n * ```\r\n */\r\nexport function installGlobalHandlers(): void {\r\n // Capture uncaught exceptions\r\n process.on(\"uncaughtException\", (error) => {\r\n captureError(error, { type: \"uncaughtException\" }).then(() => {\r\n // Give time for error to be sent before exiting\r\n setTimeout(() => {\r\n process.exit(1);\r\n }, 1000);\r\n });\r\n });\r\n\r\n // Capture unhandled promise rejections\r\n process.on(\"unhandledRejection\", (reason) => {\r\n const error = reason instanceof Error ? reason : new Error(String(reason));\r\n captureError(error, { type: \"unhandledRejection\" }).catch(() => {\r\n // Ignore capture failures\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Create a context-aware error capture function\r\n *\r\n * Useful for capturing errors with consistent metadata\r\n *\r\n * @example\r\n * ```typescript\r\n * import { createErrorCapture } from '@bugstack/sdk/generic';\r\n *\r\n * const captureDbError = createErrorCapture({\r\n * component: 'database',\r\n * service: 'user-service'\r\n * });\r\n *\r\n * try {\r\n * await db.query('...');\r\n * } catch (error) {\r\n * await captureDbError(error, { query: '...' });\r\n * }\r\n * ```\r\n */\r\nexport function createErrorCapture(baseMetadata: Record<string, unknown>) {\r\n return (error: Error | unknown, additionalMetadata?: Record<string, unknown>) => {\r\n return captureError(error, {\r\n ...baseMetadata,\r\n ...additionalMetadata,\r\n });\r\n };\r\n}\r\n\r\n// Re-export core functionality\r\nexport { ErrorCaptureClient, BugStackClient } from \"../../core/client\";\r\nexport type { ErrorCaptureConfig, CapturedError } from \"../../core/types\";\r\n"]}
@@ -0,0 +1,50 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { f as RouteContext, b as ErrorCaptureConfig, g as RouteOptions } from '../../client-9EMqVMOl.mjs';
3
+ export { B as BugStackClient, C as CapturedError, E as ErrorCaptureClient } from '../../client-9EMqVMOl.mjs';
4
+
5
+ /**
6
+ * BugStack SDK - Next.js Adapter
7
+ *
8
+ * Error capture wrapper for Next.js App Router API routes
9
+ */
10
+
11
+ /**
12
+ * Type for the wrapped handler function
13
+ */
14
+ type WrappedHandler<T> = (request: NextRequest, context: RouteContext<T>) => Response | Promise<Response>;
15
+ /**
16
+ * Wrap a Next.js App Router API route handler with error capture
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Basic usage
21
+ * export const GET = withErrorCapture(async (request) => {
22
+ * return NextResponse.json({ data: "hello" });
23
+ * });
24
+ *
25
+ * // With configuration (first call only)
26
+ * export const GET = withErrorCapture(
27
+ * async (request) => {
28
+ * return NextResponse.json({ data: "hello" });
29
+ * },
30
+ * {
31
+ * apiKey: "your-api-key",
32
+ * projectId: "your-project-id",
33
+ * autoFix: true
34
+ * }
35
+ * );
36
+ *
37
+ * // With route-specific options
38
+ * export const POST = withErrorCapture(
39
+ * async (request) => {
40
+ * return NextResponse.json({ data: "created" });
41
+ * },
42
+ * undefined,
43
+ * { statusCode: 400, metadata: { operation: "create" } }
44
+ * );
45
+ * ```
46
+ */
47
+ declare function withErrorCapture<T = Record<string, string>>(handler: WrappedHandler<T>, config?: ErrorCaptureConfig, routeOptions?: RouteOptions): WrappedHandler<T>;
48
+ declare const withBugStack: typeof withErrorCapture;
49
+
50
+ export { ErrorCaptureConfig, RouteContext, RouteOptions, withBugStack, withErrorCapture };
@@ -0,0 +1,50 @@
1
+ import { NextRequest } from 'next/server';
2
+ import { f as RouteContext, b as ErrorCaptureConfig, g as RouteOptions } from '../../client-9EMqVMOl.js';
3
+ export { B as BugStackClient, C as CapturedError, E as ErrorCaptureClient } from '../../client-9EMqVMOl.js';
4
+
5
+ /**
6
+ * BugStack SDK - Next.js Adapter
7
+ *
8
+ * Error capture wrapper for Next.js App Router API routes
9
+ */
10
+
11
+ /**
12
+ * Type for the wrapped handler function
13
+ */
14
+ type WrappedHandler<T> = (request: NextRequest, context: RouteContext<T>) => Response | Promise<Response>;
15
+ /**
16
+ * Wrap a Next.js App Router API route handler with error capture
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Basic usage
21
+ * export const GET = withErrorCapture(async (request) => {
22
+ * return NextResponse.json({ data: "hello" });
23
+ * });
24
+ *
25
+ * // With configuration (first call only)
26
+ * export const GET = withErrorCapture(
27
+ * async (request) => {
28
+ * return NextResponse.json({ data: "hello" });
29
+ * },
30
+ * {
31
+ * apiKey: "your-api-key",
32
+ * projectId: "your-project-id",
33
+ * autoFix: true
34
+ * }
35
+ * );
36
+ *
37
+ * // With route-specific options
38
+ * export const POST = withErrorCapture(
39
+ * async (request) => {
40
+ * return NextResponse.json({ data: "created" });
41
+ * },
42
+ * undefined,
43
+ * { statusCode: 400, metadata: { operation: "create" } }
44
+ * );
45
+ * ```
46
+ */
47
+ declare function withErrorCapture<T = Record<string, string>>(handler: WrappedHandler<T>, config?: ErrorCaptureConfig, routeOptions?: RouteOptions): WrappedHandler<T>;
48
+ declare const withBugStack: typeof withErrorCapture;
49
+
50
+ export { ErrorCaptureConfig, RouteContext, RouteOptions, withBugStack, withErrorCapture };