UNPKG

@critters/next

Version:

Secure bug reporting library for Next.js applications

146 lines (145 loc) 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BugTrackerConfig = void 0; /** * Configuration manager for the bug tracker */ class BugTrackerConfig { constructor(config) { this._initialized = false; this._config = Object.assign({ enabled: true, debug: false, environment: typeof process !== "undefined" ? process.env.NODE_ENV || "development" : "development", captureConsole: true, captureNetworkRequests: true, captureUserInteractions: true, captureApplicationState: true }, config); this._initialized = true; } /** * Initialize the configuration */ static init(config) { if (!BugTrackerConfig.instance) { BugTrackerConfig.instance = new BugTrackerConfig(config); } else { BugTrackerConfig.instance.update(config); } return BugTrackerConfig.instance; } /** * Get the configuration instance */ static getInstance() { if (!BugTrackerConfig.instance) { throw new Error("BugTrackerConfig not initialized. Call init() first."); } return BugTrackerConfig.instance; } /** * Update configuration */ update(config) { this._config = Object.assign(Object.assign({}, this._config), config); } /** * Check if the bug tracker is initialized */ isInitialized() { return this._initialized; } /** * Check if the bug tracker is enabled */ isEnabled() { return !!this._config.enabled; } /** * Check if debug mode is enabled */ isDebugMode() { return !!this._config.debug; } /** * Get the API key */ getApiKey() { return this._config.apiKey; } /** * Get the secret key */ getSecretKey() { return this._config.secretKey; } /** * Get the endpoint */ getEndpoint() { return this._config.endpoint || "https://bugtrack.critters.dev/api/bugs"; } /** * Get the project ID */ getProjectId() { return this._config.projectId; } /** * Get the environment */ getEnvironment() { return this._config.environment || "development"; } /** * Get the onBeforeReport hook */ getOnBeforeReport() { return this._config.onBeforeReport; } /** * Get the onAfterReport hook */ getOnAfterReport() { return this._config.onAfterReport; } /** * Check if console capture is enabled */ shouldCaptureConsole() { return !!this._config.captureConsole; } /** * Check if network request capture is enabled */ shouldCaptureNetworkRequests() { return !!this._config.captureNetworkRequests; } /** * Check if user interaction capture is enabled */ shouldCaptureUserInteractions() { return !!this._config.captureUserInteractions; } /** * Check if application state capture is enabled */ shouldCaptureApplicationState() { return !!this._config.captureApplicationState; } /** * Get the full configuration */ getConfig() { return Object.assign({}, this._config); } /** * Set the secret key */ setSecretKey(secretKey) { this._config.secretKey = secretKey; } /** * Set the project ID */ setProjectId(projectId) { this._config.projectId = projectId; } } exports.BugTrackerConfig = BugTrackerConfig;