From 8c300c1f8d58aed61fd3af5901cf8c8ca5100cc1 Mon Sep 17 00:00:00 2001 From: logikonline Date: Wed, 7 Jan 2026 15:12:47 -0500 Subject: [PATCH] Include dist folder for git-based installs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unignored dist/ so yarn/npm can install from git URL without needing to build locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .gitignore | 4 +- dist/cjs/breadcrumbs.js | 62 +++++++ dist/cjs/breadcrumbs.js.map | 1 + dist/cjs/client.js | 306 ++++++++++++++++++++++++++++++++ dist/cjs/client.js.map | 1 + dist/cjs/config.js | 71 ++++++++ dist/cjs/config.js.map | 1 + dist/cjs/index.js | 248 ++++++++++++++++++++++++++ dist/cjs/index.js.map | 1 + dist/cjs/journey.js | 202 +++++++++++++++++++++ dist/cjs/journey.js.map | 1 + dist/cjs/queue.js | 119 +++++++++++++ dist/cjs/queue.js.map | 1 + dist/cjs/transport.js | 104 +++++++++++ dist/cjs/transport.js.map | 1 + dist/cjs/types.js | 3 + dist/cjs/types.js.map | 1 + dist/esm/breadcrumbs.js | 58 ++++++ dist/esm/breadcrumbs.js.map | 1 + dist/esm/client.js | 301 +++++++++++++++++++++++++++++++ dist/esm/client.js.map | 1 + dist/esm/config.js | 65 +++++++ dist/esm/config.js.map | 1 + dist/esm/index.js | 223 +++++++++++++++++++++++ dist/esm/index.js.map | 1 + dist/esm/journey.js | 195 ++++++++++++++++++++ dist/esm/journey.js.map | 1 + dist/esm/queue.js | 115 ++++++++++++ dist/esm/queue.js.map | 1 + dist/esm/transport.js | 100 +++++++++++ dist/esm/transport.js.map | 1 + dist/esm/types.js | 2 + dist/esm/types.js.map | 1 + dist/types/breadcrumbs.d.ts | 32 ++++ dist/types/breadcrumbs.d.ts.map | 1 + dist/types/client.d.ts | 116 ++++++++++++ dist/types/client.d.ts.map | 1 + dist/types/config.d.ts | 21 +++ dist/types/config.d.ts.map | 1 + dist/types/index.d.ts | 96 ++++++++++ dist/types/index.d.ts.map | 1 + dist/types/journey.d.ts | 116 ++++++++++++ dist/types/journey.d.ts.map | 1 + dist/types/queue.d.ts | 47 +++++ dist/types/queue.d.ts.map | 1 + dist/types/transport.d.ts | 23 +++ dist/types/transport.d.ts.map | 1 + dist/types/types.d.ts | 196 ++++++++++++++++++++ dist/types/types.d.ts.map | 1 + 49 files changed, 2847 insertions(+), 2 deletions(-) create mode 100644 dist/cjs/breadcrumbs.js create mode 100644 dist/cjs/breadcrumbs.js.map create mode 100644 dist/cjs/client.js create mode 100644 dist/cjs/client.js.map create mode 100644 dist/cjs/config.js create mode 100644 dist/cjs/config.js.map create mode 100644 dist/cjs/index.js create mode 100644 dist/cjs/index.js.map create mode 100644 dist/cjs/journey.js create mode 100644 dist/cjs/journey.js.map create mode 100644 dist/cjs/queue.js create mode 100644 dist/cjs/queue.js.map create mode 100644 dist/cjs/transport.js create mode 100644 dist/cjs/transport.js.map create mode 100644 dist/cjs/types.js create mode 100644 dist/cjs/types.js.map create mode 100644 dist/esm/breadcrumbs.js create mode 100644 dist/esm/breadcrumbs.js.map create mode 100644 dist/esm/client.js create mode 100644 dist/esm/client.js.map create mode 100644 dist/esm/config.js create mode 100644 dist/esm/config.js.map create mode 100644 dist/esm/index.js create mode 100644 dist/esm/index.js.map create mode 100644 dist/esm/journey.js create mode 100644 dist/esm/journey.js.map create mode 100644 dist/esm/queue.js create mode 100644 dist/esm/queue.js.map create mode 100644 dist/esm/transport.js create mode 100644 dist/esm/transport.js.map create mode 100644 dist/esm/types.js create mode 100644 dist/esm/types.js.map create mode 100644 dist/types/breadcrumbs.d.ts create mode 100644 dist/types/breadcrumbs.d.ts.map create mode 100644 dist/types/client.d.ts create mode 100644 dist/types/client.d.ts.map create mode 100644 dist/types/config.d.ts create mode 100644 dist/types/config.d.ts.map create mode 100644 dist/types/index.d.ts create mode 100644 dist/types/index.d.ts.map create mode 100644 dist/types/journey.d.ts create mode 100644 dist/types/journey.d.ts.map create mode 100644 dist/types/queue.d.ts create mode 100644 dist/types/queue.d.ts.map create mode 100644 dist/types/transport.d.ts create mode 100644 dist/types/transport.d.ts.map create mode 100644 dist/types/types.d.ts create mode 100644 dist/types/types.d.ts.map diff --git a/.gitignore b/.gitignore index 54ea4d5..a6b815e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ # Dependencies node_modules/ -# Build output -dist/ +# Build output - NOT ignored so git installs work +# dist/ # IDE .idea/ diff --git a/dist/cjs/breadcrumbs.js b/dist/cjs/breadcrumbs.js new file mode 100644 index 0000000..a413665 --- /dev/null +++ b/dist/cjs/breadcrumbs.js @@ -0,0 +1,62 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BreadcrumbManager = void 0; +/** + * Manages breadcrumbs for an SDK instance + */ +class BreadcrumbManager { + constructor(maxBreadcrumbs = 100) { + this.breadcrumbs = []; + this.maxBreadcrumbs = maxBreadcrumbs; + } + /** + * Add a breadcrumb + */ + add(message, category = 'custom', level = 'info', data) { + const breadcrumb = { + timestamp: new Date(), + category, + message, + level, + data, + }; + this.breadcrumbs.push(breadcrumb); + // Trim to max size + if (this.breadcrumbs.length > this.maxBreadcrumbs) { + this.breadcrumbs = this.breadcrumbs.slice(-this.maxBreadcrumbs); + } + } + /** + * Add a breadcrumb from a full Breadcrumb object + */ + addBreadcrumb(breadcrumb) { + const fullBreadcrumb = { + ...breadcrumb, + timestamp: breadcrumb.timestamp ?? new Date(), + }; + this.breadcrumbs.push(fullBreadcrumb); + if (this.breadcrumbs.length > this.maxBreadcrumbs) { + this.breadcrumbs = this.breadcrumbs.slice(-this.maxBreadcrumbs); + } + } + /** + * Get all breadcrumbs + */ + getAll() { + return [...this.breadcrumbs]; + } + /** + * Clear all breadcrumbs + */ + clear() { + this.breadcrumbs = []; + } + /** + * Get the number of breadcrumbs + */ + get count() { + return this.breadcrumbs.length; + } +} +exports.BreadcrumbManager = BreadcrumbManager; +//# sourceMappingURL=breadcrumbs.js.map \ No newline at end of file diff --git a/dist/cjs/breadcrumbs.js.map b/dist/cjs/breadcrumbs.js.map new file mode 100644 index 0000000..56a19b0 --- /dev/null +++ b/dist/cjs/breadcrumbs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"breadcrumbs.js","sourceRoot":"","sources":["../../src/breadcrumbs.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,iBAAiB;IAI5B,YAAY,iBAAyB,GAAG;QAFhC,gBAAW,GAAiB,EAAE,CAAC;QAGrC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,GAAG,CACD,OAAe,EACf,WAA+B,QAAQ,EACvC,QAAuB,MAAM,EAC7B,IAA8B;QAE9B,MAAM,UAAU,GAAe;YAC7B,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,QAAQ;YACR,OAAO;YACP,KAAK;YACL,IAAI;SACL,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAElC,mBAAmB;QACnB,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAClD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,UAAgE;QAC5E,MAAM,cAAc,GAAe;YACjC,GAAG,UAAU;YACb,SAAS,EAAE,UAAU,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE;SAC9C,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEtC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAClD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;IACjC,CAAC;CACF;AArED,8CAqEC"} \ No newline at end of file diff --git a/dist/cjs/client.js b/dist/cjs/client.js new file mode 100644 index 0000000..da109e3 --- /dev/null +++ b/dist/cjs/client.js @@ -0,0 +1,306 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TelemetryClient = exports.enableDebugLogging = void 0; +exports.setDebugLogging = setDebugLogging; +const config_1 = require("./config"); +const transport_1 = require("./transport"); +const queue_1 = require("./queue"); +const breadcrumbs_1 = require("./breadcrumbs"); +const journey_1 = require("./journey"); +/** + * Global debug logging flag. When enabled, all IronTelemetry clients + * will output debug information to the console. + */ +exports.enableDebugLogging = false; +/** + * Enable or disable global debug logging for all TelemetryClient instances. + * @param enabled Whether to enable debug logging + */ +function setDebugLogging(enabled) { + exports.enableDebugLogging = enabled; +} +/** + * Main IronTelemetry client class + */ +class TelemetryClient { + constructor(options) { + this.tags = {}; + this.extra = {}; + this.isInitialized = false; + this.options = (0, config_1.resolveOptions)(options); + this.transport = new transport_1.Transport(this.options.parsedDsn, this.options.apiBaseUrl, this.options.debug); + this.queue = this.options.enableOfflineQueue + ? new queue_1.OfflineQueue(this.options.maxOfflineQueueSize, this.options.debug) + : null; + this.breadcrumbs = new breadcrumbs_1.BreadcrumbManager(this.options.maxBreadcrumbs); + this.isInitialized = true; + // Start flush interval for offline queue + if (this.queue) { + this.flushInterval = setInterval(() => this.processQueue(), 30000); + } + if (this.options.debug || exports.enableDebugLogging) { + console.log('[IronTelemetry] Initialized with DSN:', this.options.dsn); + } + } + /** + * Capture an exception + */ + async captureException(error, extra) { + const exception = this.parseException(error); + const event = this.createEvent('error', exception.message, exception); + if (extra) { + event.extra = { ...event.extra, ...extra }; + } + return this.sendEvent(event); + } + /** + * Capture a message + */ + async captureMessage(message, level = 'info') { + const event = this.createEvent(level, message); + return this.sendEvent(event); + } + /** + * Log a structured message with title, message, and optional data. + * Useful for structured logging that differentiates the log title from its details. + * @param level The severity level of the log + * @param title A short, descriptive title for the log entry + * @param message Optional detailed message + * @param data Optional additional data to attach to the log + */ + async logMessage(level, title, message, data) { + const fullMessage = message ? `${title}: ${message}` : title; + const event = this.createEvent(level, fullMessage); + if (data) { + event.extra = { ...event.extra, logTitle: title, logData: data }; + } + else { + event.extra = { ...event.extra, logTitle: title }; + } + return this.sendEvent(event); + } + addBreadcrumb(messageOrBreadcrumb, category, level, data) { + if (typeof messageOrBreadcrumb === 'string') { + this.breadcrumbs.add(messageOrBreadcrumb, category, level, data); + } + else { + this.breadcrumbs.addBreadcrumb(messageOrBreadcrumb); + } + } + /** + * Get a copy of the current breadcrumbs list. + * @returns A read-only array of breadcrumbs + */ + getBreadcrumbs() { + return this.breadcrumbs.getAll(); + } + /** + * Clear all breadcrumbs. + */ + clearBreadcrumbs() { + this.breadcrumbs.clear(); + } + /** + * Set user context + */ + setUser(id, email, data) { + this.user = { id, email, data }; + } + /** + * Clear user context + */ + clearUser() { + this.user = undefined; + } + /** + * Set a tag + */ + setTag(key, value) { + this.tags[key] = value; + } + /** + * Set extra context + */ + setExtra(key, value) { + this.extra[key] = value; + } + /** + * Start a new journey + */ + startJourney(name) { + this.currentJourney = new journey_1.Journey(name); + // Copy user context to journey + if (this.user) { + this.currentJourney.setUser(this.user.id, this.user.email, this.user.data); + } + return new journey_1.JourneyScope(this.currentJourney, () => { + this.currentJourney = undefined; + }); + } + /** + * Start a step in the current journey + */ + startStep(name, category) { + if (!this.currentJourney) { + throw new Error('No active journey. Call startJourney() first.'); + } + const step = this.currentJourney.startStep(name, category); + return new journey_1.StepScope(step); + } + /** + * Flush pending events + */ + async flush() { + await this.processQueue(); + } + /** + * Close the client + */ + close() { + if (this.flushInterval) { + clearInterval(this.flushInterval); + } + } + /** + * Create a telemetry event + */ + createEvent(level, message, exception) { + const event = { + eventId: (0, config_1.generateEventId)(), + timestamp: new Date(), + level, + message, + exception, + user: this.currentJourney?.getUser() ?? this.user, + tags: { ...this.tags }, + extra: { ...this.extra }, + breadcrumbs: this.breadcrumbs.getAll(), + journey: this.currentJourney?.getContext(), + environment: this.options.environment, + appVersion: this.options.appVersion, + platform: this.getPlatformInfo(), + }; + return event; + } + /** + * Send an event + */ + async sendEvent(event) { + // Check sample rate + if (Math.random() > this.options.sampleRate) { + if (this.options.debug || exports.enableDebugLogging) { + console.log('[IronTelemetry] Event dropped due to sample rate'); + } + return { success: true, eventId: event.eventId }; + } + // Apply beforeSend hook + const beforeSendResult = this.options.beforeSend(event); + if (beforeSendResult === false || beforeSendResult === null) { + if (this.options.debug || exports.enableDebugLogging) { + console.log('[IronTelemetry] Event dropped by beforeSend hook'); + } + return { success: true, eventId: event.eventId }; + } + const eventToSend = beforeSendResult === true ? event : beforeSendResult; + // Try to send + const result = await this.transport.send(eventToSend); + if (!result.success && this.queue) { + this.queue.enqueue(eventToSend); + return { ...result, queued: true }; + } + return result; + } + /** + * Process offline queue + */ + async processQueue() { + if (!this.queue || this.queue.isEmpty) { + return; + } + const isOnline = await this.transport.isOnline(); + if (!isOnline) { + return; + } + const events = this.queue.getAll(); + for (const event of events) { + const result = await this.transport.send(event); + if (result.success) { + this.queue.remove(event.eventId); + } + } + } + /** + * Parse an error into exception info + */ + parseException(error) { + if (error instanceof Error) { + return { + type: error.name || 'Error', + message: error.message, + stacktrace: this.parseStackTrace(error.stack), + }; + } + return { + type: 'Error', + message: String(error), + }; + } + /** + * Parse a stack trace string into frames + */ + parseStackTrace(stack) { + if (!stack) + return undefined; + const frames = []; + const lines = stack.split('\n'); + for (const line of lines) { + // Chrome/Node format: " at functionName (filename:line:column)" + const chromeMatch = line.match(/^\s*at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/); + if (chromeMatch) { + frames.push({ + function: chromeMatch[1] || '', + filename: chromeMatch[2], + lineno: parseInt(chromeMatch[3], 10), + colno: parseInt(chromeMatch[4], 10), + }); + continue; + } + // Firefox format: "functionName@filename:line:column" + const firefoxMatch = line.match(/^(.*)@(.+?):(\d+):(\d+)$/); + if (firefoxMatch) { + frames.push({ + function: firefoxMatch[1] || '', + filename: firefoxMatch[2], + lineno: parseInt(firefoxMatch[3], 10), + colno: parseInt(firefoxMatch[4], 10), + }); + } + } + return frames.length > 0 ? frames : undefined; + } + /** + * Get platform information + */ + getPlatformInfo() { + // Check for browser environment + if (typeof window !== 'undefined' && typeof navigator !== 'undefined') { + return { + name: 'browser', + userAgent: navigator.userAgent, + }; + } + // Check for Node.js environment + if (typeof process !== 'undefined' && process.versions?.node) { + return { + name: 'node', + version: process.versions.node, + os: process.platform, + }; + } + return { + name: 'unknown', + }; + } +} +exports.TelemetryClient = TelemetryClient; +//# sourceMappingURL=client.js.map \ No newline at end of file diff --git a/dist/cjs/client.js.map b/dist/cjs/client.js.map new file mode 100644 index 0000000..afa6c13 --- /dev/null +++ b/dist/cjs/client.js.map @@ -0,0 +1 @@ +{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AA4BA,0CAEC;AAlBD,qCAA2D;AAC3D,2CAAwC;AACxC,mCAAuC;AACvC,+CAAkD;AAClD,uCAAmE;AAEnE;;;GAGG;AACQ,QAAA,kBAAkB,GAAG,KAAK,CAAC;AAEtC;;;GAGG;AACH,SAAgB,eAAe,CAAC,OAAgB;IAC9C,0BAAkB,GAAG,OAAO,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,MAAa,eAAe;IAa1B,YAAY,OAAyB;QAP7B,SAAI,GAA2B,EAAE,CAAC;QAClC,UAAK,GAA4B,EAAE,CAAC;QAIpC,kBAAa,GAAY,K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gBACL,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC9B,EAAE,EAAE,OAAO,CAAC,QAAQ;aACrB,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,SAAS;SAChB,CAAC;IACJ,CAAC;CACF;AAlWD,0CAkWC"} \ No newline at end of file diff --git a/dist/cjs/config.js b/dist/cjs/config.js new file mode 100644 index 0000000..5229da2 --- /dev/null +++ b/dist/cjs/config.js @@ -0,0 +1,71 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DEFAULT_OPTIONS = void 0; +exports.parseDsn = parseDsn; +exports.resolveOptions = resolveOptions; +exports.generateEventId = generateEventId; +/** + * Default configuration values + */ +exports.DEFAULT_OPTIONS = { + sampleRate: 1.0, + maxBreadcrumbs: 100, + debug: false, + enableOfflineQueue: true, + maxOfflineQueueSize: 500, +}; +/** + * Parse a DSN string into its components + * Format: https://pk_live_xxx@irontelemetry.com + */ +function parseDsn(dsn) { + try { + const url = new URL(dsn); + const publicKey = url.username; + if (!publicKey || !publicKey.startsWith('pk_')) { + throw new Error('DSN must contain a valid public key starting with pk_'); + } + const protocol = url.protocol.replace(':', ''); + const host = url.host; + return { + publicKey, + host, + protocol, + apiBaseUrl: `${protocol}://${host}`, + }; + } + catch (error) { + if (error instanceof Error && error.message.includes('pk_')) { + throw error; + } + throw new Error(`Invalid DSN format: ${dsn}`); + } +} +/** + * Validate and merge options with defaults + */ +function resolveOptions(options) { + const parsedDsn = parseDsn(options.dsn); + return { + dsn: options.dsn, + environment: options.environment ?? 'production', + appVersion: options.appVersion ?? '0.0.0', + sampleRate: Math.max(0, Math.min(1, options.sampleRate ?? exports.DEFAULT_OPTIONS.sampleRate)), + maxBreadcrumbs: options.maxBreadcrumbs ?? exports.DEFAULT_OPTIONS.maxBreadcrumbs, + debug: options.debug ?? exports.DEFAULT_OPTIONS.debug, + beforeSend: options.beforeSend ?? (() => true), + enableOfflineQueue: options.enableOfflineQueue ?? exports.DEFAULT_OPTIONS.enableOfflineQueue, + maxOfflineQueueSize: options.maxOfflineQueueSize ?? exports.DEFAULT_OPTIONS.maxOfflineQueueSize, + apiBaseUrl: options.apiBaseUrl ?? parsedDsn.apiBaseUrl, + parsedDsn, + }; +} +/** + * Generate a unique event ID + */ +function generateEventId() { + const timestamp = Date.now().toString(36); + const random = Math.random().toString(36).substring(2, 15); + return `${timestamp}-${random}`; +} +//# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/dist/cjs/config.js.map b/dist/cjs/config.js.map new file mode 100644 index 0000000..c96f083 --- /dev/null +++ b/dist/cjs/config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;AAiBA,4BAwBC;AAKD,wCAgBC;AAKD,0CAIC;AArED;;GAEG;AACU,QAAA,eAAe,GAA8B;IACxD,UAAU,EAAE,GAAG;IACf,cAAc,EAAE,GAAG;IACnB,KAAK,EAAE,KAAK;IACZ,kBAAkB,EAAE,IAAI;IACxB,mBAAmB,EAAE,GAAG;CACzB,CAAC;AAEF;;;GAGG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC;QAE/B,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QAEtB,OAAO;YACL,SAAS;YACT,IAAI;YACJ,QAAQ;YACR,UAAU,EAAE,GA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,EAAE,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3D,OAAO,GAAG,SAAS,IAAI,MAAM,EAAE,CAAC;AAClC,CAAC"} \ No newline at end of file diff --git a/dist/cjs/index.js b/dist/cjs/index.js new file mode 100644 index 0000000..3ead4f7 --- /dev/null +++ b/dist/cjs/index.js @@ -0,0 +1,248 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StepScope = exports.Step = exports.JourneyScope = exports.Journey = exports.TelemetryClient = void 0; +exports.init = init; +exports.getClient = getClient; +exports.captureException = captureException; +exports.captureMessage = captureMessage; +exports.addBreadcrumb = addBreadcrumb; +exports.setUser = setUser; +exports.clearUser = clearUser; +exports.setTag = setTag; +exports.setExtra = setExtra; +exports.startJourney = startJourney; +exports.startStep = startStep; +exports.flush = flush; +exports.close = close; +exports.enableErrorCapture = enableErrorCapture; +exports.useUnhandledExceptionHandler = useUnhandledExceptionHandler; +exports.trackStep = trackStep; +exports.trackStepAsync = trackStepAsync; +const client_1 = require("./client"); +// Export classes +var client_2 = require("./client"); +Object.defineProperty(exports, "TelemetryClient", { enumerable: true, get: function () { return client_2.TelemetryClient; } }); +var journey_1 = require("./journey"); +Object.defineProperty(exports, "Journey", { enumerable: true, get: function () { return journey_1.Journey; } }); +Object.defineProperty(exports, "JourneyScope", { enumerable: true, get: function () { return journey_1.JourneyScope; } }); +Object.defineProperty(exports, "Step", { enumerable: true, get: function () { return journey_1.Step; } }); +Object.defineProperty(exports, "StepScope", { enumerable: true, get: function () { return journey_1.StepScope; } }); +// Global client instance +let globalClient = null; +/** + * Initialize the global IronTelemetry client + */ +function init(optionsOrDsn) { + const options = typeof optionsOrDsn === 'string' ? { dsn: optionsOrDsn } : optionsOrDsn; + globalClient = new client_1.TelemetryClient(options); + return globalClient; +} +/** + * Get the global client instance + */ +function getClient() { + return globalClient; +} +/** + * Capture an exception using the global client + */ +async function captureException(error, extra) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return { success: false, error: 'Client not initialized' }; + } + return globalClient.captureException(error, extra); +} +/** + * Capture a message using the global client + */ +async function captureMessage(message, level = 'info') { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return { success: false, error: 'Client not initialized' }; + } + return globalClient.captureMessage(message, level); +} +function addBreadcrumb(messageOrBreadcrumb, category, level, data) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + if (typeof messageOrBreadcrumb === 'string') { + globalClient.addBreadcrumb(messageOrBreadcrumb, category, level, data); + } + else { + globalClient.addBreadcrumb(messageOrBreadcrumb); + } +} +/** + * Set user context using the global client + */ +function setUser(id, email, data) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + globalClient.setUser(id, email, data); +} +/** + * Clear user context using the global client + */ +function clearUser() { + if (!globalClient) { + return; + } + globalClient.clearUser(); +} +/** + * Set a tag using the global client + */ +function setTag(key, value) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + globalClient.setTag(key, value); +} +/** + * Set extra context using the global client + */ +function setExtra(key, value) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + globalClient.setExtra(key, value); +} +/** + * Start a journey using the global client + */ +function startJourney(name) { + if (!globalClient) { + throw new Error('[IronTelemetry] Client not initialized. Call init() first.'); + } + return globalClient.startJourney(name); +} +/** + * Start a step in the current journey using the global client + */ +function startStep(name, category) { + if (!globalClient) { + throw new Error('[IronTelemetry] Client not initialized. Call init() first.'); + } + return globalClient.startStep(name, category); +} +/** + * Flush pending events using the global client + */ +async function flush() { + if (!globalClient) { + return; + } + await globalClient.flush(); +} +/** + * Close the global client + */ +function close() { + if (globalClient) { + globalClient.close(); + globalClient = null; + } +} +// Default export for convenience +const IronTelemetry = { + init, + getClient, + captureException, + captureMessage, + addBreadcrumb, + setUser, + clearUser, + setTag, + setExtra, + startJourney, + startStep, + flush, + close, +}; +exports.default = IronTelemetry; +/** + * Enable the Error.prototype.capture() extension. + * This is opt-in to avoid TypeScript conflicts in projects that create + * Error-like objects without the capture method. + * + * After calling this, you can use: throw new Error('msg').capture() + */ +function enableErrorCapture() { + if (typeof Error.prototype.capture === 'function') { + return; // Already enabled + } + Error.prototype.capture = function () { + captureException(this); + return this; + }; +} +// Type augmentation for projects that call enableErrorCapture() +// Users can add this to their project if they want type support: +// declare global { interface Error { capture(): Error; } } +/** + * Set up global unhandled exception handler + */ +function useUnhandledExceptionHandler() { + if (typeof window !== 'undefined') { + // Browser + window.addEventListener('error', (event) => { + captureException(event.error ?? new Error(event.message)); + }); + window.addEventListener('unhandledrejection', (event) => { + captureException(event.reason ?? new Error('Unhandled Promise rejection')); + }); + } + else if (typeof process !== 'undefined') { + // Node.js + process.on('uncaughtException', (error) => { + captureException(error); + }); + process.on('unhandledRejection', (reason) => { + captureException(reason ?? new Error('Unhandled Promise rejection')); + }); + } +} +/** + * Track a step with automatic error handling + */ +function trackStep(name, fn, category) { + if (!globalClient) { + return fn(); + } + const step = startStep(name, category); + try { + const result = fn(); + step[Symbol.dispose](); + return result; + } + catch (error) { + step.getStep().fail(); + throw error; + } +} +/** + * Track an async step with automatic error handling + */ +async function trackStepAsync(name, fn, category) { + if (!globalClient) { + return fn(); + } + const step = startStep(name, category); + try { + const result = await fn(); + step[Symbol.dispose](); + return result; + } + catch (error) { + step.getStep().fail(); + throw error; + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/index.js.map b/dist/cjs/index.js.map new file mode 100644 index 0000000..14fe03f --- /dev/null +++ b/dist/cjs/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAuCA,oBAIC;AAKD,8BAEC;AAKD,4CAS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IACvE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,EAAE,EAAE,CAAC;QACpB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,cAAc,CAClC,IAAY,EACZ,EAAoB,EACpB,QAAiB;IAEjB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;IAED,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/dist/cjs/journey.js b/dist/cjs/journey.js new file mode 100644 index 0000000..9b915af --- /dev/null +++ b/dist/cjs/journey.js @@ -0,0 +1,202 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.StepScope = exports.JourneyScope = exports.Step = exports.Journey = void 0; +const config_1 = require("./config"); +/** + * Represents an active journey tracking session + */ +class Journey { + constructor(name) { + this.metadata = {}; + this.steps = []; + this._completed = false; + this._failed = false; + this.id = (0, config_1.generateEventId)(); + this.name = name; + this.startedAt = new Date(); + } + /** + * Set user context for this journey + */ + setUser(id, email, data) { + this.user = { id, email, data }; + return this; + } + /** + * Set metadata for this journey + */ + setMetadata(key, value) { + this.metadata[key] = value; + return this; + } + /** + * Start a new step in this journey + */ + startStep(name, category) { + // Complete any existing step + if (this.currentStep && this.currentStep.status === 'in_progress') { + this.currentStep.status = 'completed'; + this.currentStep.endedAt = new Date(); + } + const step = { + name, + category, + startedAt: new Date(), + status: 'in_progress', + data: {}, + }; + this.steps.push(step); + this.currentStep = step; + return new Step(step, this); + } + /** + * Mark the journey as completed + */ + complete() { + if (this.currentStep && this.currentStep.status === 'in_progress') { + this.currentStep.status = 'completed'; + this.currentStep.endedAt = new Date(); + } + this._completed = true; + } + /** + * Mark the journey as failed + */ + fail() { + if (this.currentStep && this.currentStep.status === 'in_progress') { + this.currentStep.status = 'failed'; + this.currentStep.endedAt = new Date(); + } + this._failed = true; + } + /** + * Get the journey context for an event + */ + getContext() { + return { + journeyId: this.id, + name: this.name, + currentStep: this.currentStep?.name, + startedAt: this.startedAt, + metadata: this.metadata, + }; + } + /** + * Get the user context for this journey + */ + getUser() { + return this.user; + } + /** + * Check if the journey is complete + */ + get isComplete() { + return this._completed || this._failed; + } + /** + * Get journey ID + */ + get journeyId() { + return this.id; + } +} +exports.Journey = Journey; +/** + * Represents a step within a journey + */ +class Step { + constructor(step, journey) { + this.step = step; + this.journey = journey; + } + /** + * Set data for this step + */ + setData(key, value) { + this.step.data[key] = value; + return this; + } + /** + * Mark the step as completed + */ + complete() { + this.step.status = 'completed'; + this.step.endedAt = new Date(); + } + /** + * Mark the step as failed + */ + fail() { + this.step.status = 'failed'; + this.step.endedAt = new Date(); + } + /** + * Get the step name + */ + get name() { + return this.step.name; + } + /** + * Get the parent journey + */ + getJourney() { + return this.journey; + } +} +exports.Step = Step; +/** + * Journey scope that auto-completes on disposal + */ +class JourneyScope { + constructor(journey, onComplete) { + this.journey = journey; + this.onComplete = onComplete; + } + /** + * Get the underlying journey + */ + getJourney() { + return this.journey; + } + /** + * Dispose of the journey scope + */ + [Symbol.dispose]() { + if (!this.journey.isComplete) { + this.journey.complete(); + } + this.onComplete?.(); + } +} +exports.JourneyScope = JourneyScope; +/** + * Step scope that auto-completes on disposal + */ +class StepScope { + constructor(step) { + this.step = step; + } + /** + * Get the underlying step + */ + getStep() { + return this.step; + } + /** + * Set data on the step + */ + setData(key, value) { + this.step.setData(key, value); + return this; + } + /** + * Dispose of the step scope + */ + [Symbol.dispose]() { + if (this.step['step'].status === 'in_progress') { + this.step.complete(); + } + } +} +exports.StepScope = StepScope; +//# sourceMappingURL=journey.js.map \ No newline at end of file diff --git a/dist/cjs/journey.js.map b/dist/cjs/journey.js.map new file mode 100644 index 0000000..346357f --- /dev/null +++ b/dist/cjs/journey.js.map @@ -0,0 +1 @@ +{"version":3,"file":"journey.js","sourceRoot":"","sources":["../../src/journey.ts"],"names":[],"mappings":";;;AACA,qCAA2C;AAE3C;;GAEG;AACH,MAAa,OAAO;IAWlB,YAAY,IAAY;QAPhB,aAAQ,GAA4B,EAAE,CAAC;QAEvC,UAAK,GAAkB,EAAE,CAAC;QAE1B,eAAU,GAAY,KAAK,CAAC;QAC5B,YAAO,GAAY,KAAK,CAAC;QAG/B,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAe,GAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,EAAU,EAAE,KAAc,EAAE,IAA8B;QAChE,IAAI,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,GAAW,EAAE,KAAc;QACrC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;Q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AAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AA9CD,oBA8CC;AAED;;GAEG;AACH,MAAa,YAAY;IAIvB,YAAY,OAAgB,EAAE,UAAuB;QACnD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;IACtB,CAAC;CACF;AAzBD,oCAyBC;AAED;;GAEG;AACH,MAAa,SAAS;IAGpB,YAAY,IAAU;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,GAAW,EAAE,KAAc;QACjC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YAC/C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AA9BD,8BA8BC"} \ No newline at end of file diff --git a/dist/cjs/queue.js b/dist/cjs/queue.js new file mode 100644 index 0000000..0885e83 --- /dev/null +++ b/dist/cjs/queue.js @@ -0,0 +1,119 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.OfflineQueue = void 0; +const STORAGE_KEY = 'irontelemetry_queue'; +/** + * Offline queue for storing events when the network is unavailable + */ +class OfflineQueue { + constructor(maxSize = 500, debug = false) { + this.queue = []; + this.maxSize = maxSize; + this.debug = debug; + this.load(); + } + /** + * Add an event to the queue + */ + enqueue(event) { + if (this.queue.length >= this.maxSize) { + // Remove oldest events to make room + this.queue.shift(); + if (this.debug) { + console.log('[IronTelemetry] Queue full, dropping oldest event'); + } + } + this.queue.push(event); + this.save(); + if (this.debug) { + console.log('[IronTelemetry] Event queued, queue size:', this.queue.length); + } + } + /** + * Get all queued events + */ + getAll() { + return [...this.queue]; + } + /** + * Remove an event from the queue + */ + remove(eventId) { + this.queue = this.queue.filter((e) => e.eventId !== eventId); + this.save(); + } + /** + * Clear all queued events + */ + clear() { + this.queue = []; + this.save(); + } + /** + * Get the number of queued events + */ + get size() { + return this.queue.length; + } + /** + * Check if the queue is empty + */ + get isEmpty() { + return this.queue.length === 0; + } + /** + * Load queue from persistent storage + */ + load() { + try { + if (typeof localStorage !== 'undefined') { + const data = localStorage.getItem(STORAGE_KEY); + if (data) { + const parsed = JSON.parse(data); + this.queue = parsed.map((e) => this.deserializeEvent(e)); + } + } + } + catch (error) { + if (this.debug) { + console.error('[IronTelemetry] Failed to load queue from storage:', error); + } + } + } + /** + * Save queue to persistent storage + */ + save() { + try { + if (typeof localStorage !== 'undefined') { + localStorage.setItem(STORAGE_KEY, JSON.stringify(this.queue)); + } + } + catch (error) { + if (this.debug) { + console.error('[IronTelemetry] Failed to save queue to storage:', error); + } + } + } + /** + * Deserialize an event from storage + */ + deserializeEvent(data) { + return { + ...data, + timestamp: new Date(data.timestamp), + breadcrumbs: (data.breadcrumbs ?? []).map((b) => ({ + ...b, + timestamp: new Date(b.timestamp), + })), + journey: data.journey + ? { + ...data.journey, + startedAt: new Date(data.journey.startedAt), + } + : undefined, + }; + } +} +exports.OfflineQueue = OfflineQueue; +//# sourceMappingURL=queue.js.map \ No newline at end of file diff --git a/dist/cjs/queue.js.map b/dist/cjs/queue.js.map new file mode 100644 index 0000000..cef4099 --- /dev/null +++ b/dist/cjs/queue.js.map @@ -0,0 +1 @@ +{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/queue.ts"],"names":[],"mappings":";;;AAEA,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C;;GAEG;AACH,MAAa,YAAY;IAKvB,YAAY,UAAkB,GAAG,EAAE,QAAiB,KAAK;QAFjD,UAAK,GAAqB,EAAE,CAAC;QAGnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,KAAqB;QAC3B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACtC,oCAAoC;YACpC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,EAAE,CAAC;QAEZ,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAe;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,C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AAK,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,kDAAkD,EAAE,KAAK,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,IAA6B;QACpD,OAAO;YACL,GAAG,IAAI;YACP,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,SAAmB,CAAC;YAC7C,WAAW,EAAE,CAAE,IAAI,CAAC,WAAyC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC/E,GAAG,CAAC;gBACJ,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,SAAmB,CAAC;aAC3C,CAAC,CAAC;YACH,OAAO,EAAE,IAAI,CAAC,OAAO;gBACnB,CAAC,CAAC;oBACE,GAAI,IAAI,CAAC,OAAmC;oBAC5C,SAAS,EAAE,IAAI,IAAI,CAAE,IAAI,CAAC,OAAmC,CAAC,SAAmB,CAAC;iBACnF;gBACH,CAAC,CAAC,SAAS;SACI,CAAC;IACtB,CAAC;CACF;AAzHD,oCAyHC"} \ No newline at end of file diff --git a/dist/cjs/transport.js b/dist/cjs/transport.js new file mode 100644 index 0000000..73a3ce9 --- /dev/null +++ b/dist/cjs/transport.js @@ -0,0 +1,104 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Transport = void 0; +/** + * HTTP transport for sending events to the server + */ +class Transport { + constructor(parsedDsn, apiBaseUrl, debug = false) { + this.apiBaseUrl = apiBaseUrl; + this.publicKey = parsedDsn.publicKey; + this.debug = debug; + } + /** + * Send an event to the server + */ + async send(event) { + const url = `${this.apiBaseUrl}/api/v1/events`; + try { + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-Public-Key': this.publicKey, + }, + body: JSON.stringify(this.serializeEvent(event)), + }); + if (!response.ok) { + const errorText = await response.text(); + if (this.debug) { + console.error('[IronTelemetry] Failed to send event:', response.status, errorText); + } + return { + success: false, + error: `HTTP ${response.status}: ${errorText}`, + }; + } + const result = await response.json(); + if (this.debug) { + console.log('[IronTelemetry] Event sent successfully:', event.eventId); + } + return { + success: true, + eventId: result.eventId ?? event.eventId, + }; + } + catch (error) { + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + if (this.debug) { + console.error('[IronTelemetry] Failed to send event:', errorMessage); + } + return { + success: false, + error: errorMessage, + }; + } + } + /** + * Check if the server is reachable + */ + async isOnline() { + try { + const response = await fetch(`${this.apiBaseUrl}/api/v1/health`, { + method: 'GET', + headers: { + 'X-Public-Key': this.publicKey, + }, + }); + return response.ok; + } + catch { + return false; + } + } + /** + * Serialize an event for sending + */ + serializeEvent(event) { + return { + eventId: event.eventId, + timestamp: event.timestamp.toISOString(), + level: event.level, + message: event.message, + exception: event.exception, + user: event.user, + tags: event.tags, + extra: event.extra, + breadcrumbs: event.breadcrumbs.map((b) => ({ + ...b, + timestamp: b.timestamp.toISOString(), + })), + journey: event.journey + ? { + ...event.journey, + startedAt: event.journey.startedAt.toISOString(), + } + : undefined, + environment: event.environment, + appVersion: event.appVersion, + platform: event.platform, + }; + } +} +exports.Transport = Transport; +//# sourceMappingURL=transport.js.map \ No newline at end of file diff --git a/dist/cjs/transport.js.map b/dist/cjs/transport.js.map new file mode 100644 index 0000000..4a15e3b --- /dev/null +++ b/dist/cjs/transport.js.map @@ -0,0 +1 @@ +{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,SAAS;IAKpB,YAAY,SAAoB,EAAE,UAAkB,EAAE,QAAiB,KAAK;QAC1E,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,K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;iBACjD;gBACH,CAAC,CAAC,SAAS;YACb,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACzB,CAAC;IACJ,CAAC;CACF;AAzGD,8BAyGC"} \ No newline at end of file diff --git a/dist/cjs/types.js b/dist/cjs/types.js new file mode 100644 index 0000000..11e638d --- /dev/null +++ b/dist/cjs/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/cjs/types.js.map b/dist/cjs/types.js.map new file mode 100644 index 0000000..7b5fff8 --- /dev/null +++ b/dist/cjs/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/breadcrumbs.js b/dist/esm/breadcrumbs.js new file mode 100644 index 0000000..2eff8d5 --- /dev/null +++ b/dist/esm/breadcrumbs.js @@ -0,0 +1,58 @@ +/** + * Manages breadcrumbs for an SDK instance + */ +export class BreadcrumbManager { + constructor(maxBreadcrumbs = 100) { + this.breadcrumbs = []; + this.maxBreadcrumbs = maxBreadcrumbs; + } + /** + * Add a breadcrumb + */ + add(message, category = 'custom', level = 'info', data) { + const breadcrumb = { + timestamp: new Date(), + category, + message, + level, + data, + }; + this.breadcrumbs.push(breadcrumb); + // Trim to max size + if (this.breadcrumbs.length > this.maxBreadcrumbs) { + this.breadcrumbs = this.breadcrumbs.slice(-this.maxBreadcrumbs); + } + } + /** + * Add a breadcrumb from a full Breadcrumb object + */ + addBreadcrumb(breadcrumb) { + const fullBreadcrumb = { + ...breadcrumb, + timestamp: breadcrumb.timestamp ?? new Date(), + }; + this.breadcrumbs.push(fullBreadcrumb); + if (this.breadcrumbs.length > this.maxBreadcrumbs) { + this.breadcrumbs = this.breadcrumbs.slice(-this.maxBreadcrumbs); + } + } + /** + * Get all breadcrumbs + */ + getAll() { + return [...this.breadcrumbs]; + } + /** + * Clear all breadcrumbs + */ + clear() { + this.breadcrumbs = []; + } + /** + * Get the number of breadcrumbs + */ + get count() { + return this.breadcrumbs.length; + } +} +//# sourceMappingURL=breadcrumbs.js.map \ No newline at end of file diff --git a/dist/esm/breadcrumbs.js.map b/dist/esm/breadcrumbs.js.map new file mode 100644 index 0000000..44e7ac3 --- /dev/null +++ b/dist/esm/breadcrumbs.js.map @@ -0,0 +1 @@ +{"version":3,"file":"breadcrumbs.js","sourceRoot":"","sources":["../../src/breadcrumbs.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAI5B,YAAY,iBAAyB,GAAG;QAFhC,gBAAW,GAAiB,EAAE,CAAC;QAGrC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,GAAG,CACD,OAAe,EACf,WAA+B,QAAQ,EACvC,QAAuB,MAAM,EAC7B,IAA8B;QAE9B,MAAM,UAAU,GAAe;YAC7B,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,QAAQ;YACR,OAAO;YACP,KAAK;YACL,IAAI;SACL,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAElC,mBAAmB;QACnB,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAClD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,UAAgE;QAC5E,MAAM,cAAc,GAAe;YACjC,GAAG,UAAU;YACb,SAAS,EAAE,UAAU,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE;SAC9C,CAAC;QAEF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEtC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAClD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;IACjC,CAAC;CACF"} \ No newline at end of file diff --git a/dist/esm/client.js b/dist/esm/client.js new file mode 100644 index 0000000..abb8f7a --- /dev/null +++ b/dist/esm/client.js @@ -0,0 +1,301 @@ +import { resolveOptions, generateEventId } from './config'; +import { Transport } from './transport'; +import { OfflineQueue } from './queue'; +import { BreadcrumbManager } from './breadcrumbs'; +import { Journey, JourneyScope, StepScope } from './journey'; +/** + * Global debug logging flag. When enabled, all IronTelemetry clients + * will output debug information to the console. + */ +export let enableDebugLogging = false; +/** + * Enable or disable global debug logging for all TelemetryClient instances. + * @param enabled Whether to enable debug logging + */ +export function setDebugLogging(enabled) { + enableDebugLogging = enabled; +} +/** + * Main IronTelemetry client class + */ +export class TelemetryClient { + constructor(options) { + this.tags = {}; + this.extra = {}; + this.isInitialized = false; + this.options = resolveOptions(options); + this.transport = new Transport(this.options.parsedDsn, this.options.apiBaseUrl, this.options.debug); + this.queue = this.options.enableOfflineQueue + ? new OfflineQueue(this.options.maxOfflineQueueSize, this.options.debug) + : null; + this.breadcrumbs = new BreadcrumbManager(this.options.maxBreadcrumbs); + this.isInitialized = true; + // Start flush interval for offline queue + if (this.queue) { + this.flushInterval = setInterval(() => this.processQueue(), 30000); + } + if (this.options.debug || enableDebugLogging) { + console.log('[IronTelemetry] Initialized with DSN:', this.options.dsn); + } + } + /** + * Capture an exception + */ + async captureException(error, extra) { + const exception = this.parseException(error); + const event = this.createEvent('error', exception.message, exception); + if (extra) { + event.extra = { ...event.extra, ...extra }; + } + return this.sendEvent(event); + } + /** + * Capture a message + */ + async captureMessage(message, level = 'info') { + const event = this.createEvent(level, message); + return this.sendEvent(event); + } + /** + * Log a structured message with title, message, and optional data. + * Useful for structured logging that differentiates the log title from its details. + * @param level The severity level of the log + * @param title A short, descriptive title for the log entry + * @param message Optional detailed message + * @param data Optional additional data to attach to the log + */ + async logMessage(level, title, message, data) { + const fullMessage = message ? `${title}: ${message}` : title; + const event = this.createEvent(level, fullMessage); + if (data) { + event.extra = { ...event.extra, logTitle: title, logData: data }; + } + else { + event.extra = { ...event.extra, logTitle: title }; + } + return this.sendEvent(event); + } + addBreadcrumb(messageOrBreadcrumb, category, level, data) { + if (typeof messageOrBreadcrumb === 'string') { + this.breadcrumbs.add(messageOrBreadcrumb, category, level, data); + } + else { + this.breadcrumbs.addBreadcrumb(messageOrBreadcrumb); + } + } + /** + * Get a copy of the current breadcrumbs list. + * @returns A read-only array of breadcrumbs + */ + getBreadcrumbs() { + return this.breadcrumbs.getAll(); + } + /** + * Clear all breadcrumbs. + */ + clearBreadcrumbs() { + this.breadcrumbs.clear(); + } + /** + * Set user context + */ + setUser(id, email, data) { + this.user = { id, email, data }; + } + /** + * Clear user context + */ + clearUser() { + this.user = undefined; + } + /** + * Set a tag + */ + setTag(key, value) { + this.tags[key] = value; + } + /** + * Set extra context + */ + setExtra(key, value) { + this.extra[key] = value; + } + /** + * Start a new journey + */ + startJourney(name) { + this.currentJourney = new Journey(name); + // Copy user context to journey + if (this.user) { + this.currentJourney.setUser(this.user.id, this.user.email, this.user.data); + } + return new JourneyScope(this.currentJourney, () => { + this.currentJourney = undefined; + }); + } + /** + * Start a step in the current journey + */ + startStep(name, category) { + if (!this.currentJourney) { + throw new Error('No active journey. Call startJourney() first.'); + } + const step = this.currentJourney.startStep(name, category); + return new StepScope(step); + } + /** + * Flush pending events + */ + async flush() { + await this.processQueue(); + } + /** + * Close the client + */ + close() { + if (this.flushInterval) { + clearInterval(this.flushInterval); + } + } + /** + * Create a telemetry event + */ + createEvent(level, message, exception) { + const event = { + eventId: generateEventId(), + timestamp: new Date(), + level, + message, + exception, + user: this.currentJourney?.getUser() ?? this.user, + tags: { ...this.tags }, + extra: { ...this.extra }, + breadcrumbs: this.breadcrumbs.getAll(), + journey: this.currentJourney?.getContext(), + environment: this.options.environment, + appVersion: this.options.appVersion, + platform: this.getPlatformInfo(), + }; + return event; + } + /** + * Send an event + */ + async sendEvent(event) { + // Check sample rate + if (Math.random() > this.options.sampleRate) { + if (this.options.debug || enableDebugLogging) { + console.log('[IronTelemetry] Event dropped due to sample rate'); + } + return { success: true, eventId: event.eventId }; + } + // Apply beforeSend hook + const beforeSendResult = this.options.beforeSend(event); + if (beforeSendResult === false || beforeSendResult === null) { + if (this.options.debug || enableDebugLogging) { + console.log('[IronTelemetry] Event dropped by beforeSend hook'); + } + return { success: true, eventId: event.eventId }; + } + const eventToSend = beforeSendResult === true ? event : beforeSendResult; + // Try to send + const result = await this.transport.send(eventToSend); + if (!result.success && this.queue) { + this.queue.enqueue(eventToSend); + return { ...result, queued: true }; + } + return result; + } + /** + * Process offline queue + */ + async processQueue() { + if (!this.queue || this.queue.isEmpty) { + return; + } + const isOnline = await this.transport.isOnline(); + if (!isOnline) { + return; + } + const events = this.queue.getAll(); + for (const event of events) { + const result = await this.transport.send(event); + if (result.success) { + this.queue.remove(event.eventId); + } + } + } + /** + * Parse an error into exception info + */ + parseException(error) { + if (error instanceof Error) { + return { + type: error.name || 'Error', + message: error.message, + stacktrace: this.parseStackTrace(error.stack), + }; + } + return { + type: 'Error', + message: String(error), + }; + } + /** + * Parse a stack trace string into frames + */ + parseStackTrace(stack) { + if (!stack) + return undefined; + const frames = []; + const lines = stack.split('\n'); + for (const line of lines) { + // Chrome/Node format: " at functionName (filename:line:column)" + const chromeMatch = line.match(/^\s*at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/); + if (chromeMatch) { + frames.push({ + function: chromeMatch[1] || '', + filename: chromeMatch[2], + lineno: parseInt(chromeMatch[3], 10), + colno: parseInt(chromeMatch[4], 10), + }); + continue; + } + // Firefox format: "functionName@filename:line:column" + const firefoxMatch = line.match(/^(.*)@(.+?):(\d+):(\d+)$/); + if (firefoxMatch) { + frames.push({ + function: firefoxMatch[1] || '', + filename: firefoxMatch[2], + lineno: parseInt(firefoxMatch[3], 10), + colno: parseInt(firefoxMatch[4], 10), + }); + } + } + return frames.length > 0 ? frames : undefined; + } + /** + * Get platform information + */ + getPlatformInfo() { + // Check for browser environment + if (typeof window !== 'undefined' && typeof navigator !== 'undefined') { + return { + name: 'browser', + userAgent: navigator.userAgent, + }; + } + // Check for Node.js environment + if (typeof process !== 'undefined' && process.versions?.node) { + return { + name: 'node', + version: process.versions.node, + os: process.platform, + }; + } + return { + name: 'unknown', + }; + } +} +//# sourceMappingURL=client.js.map \ No newline at end of file diff --git a/dist/esm/client.js.map b/dist/esm/client.js.map new file mode 100644 index 0000000..78224cb --- /dev/null +++ b/dist/esm/client.js.map @@ -0,0 +1 @@ +{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAQ,SAAS,EAAE,MAAM,WAAW,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,IAAI,kBAAkB,GAAG,KAAK,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,kBA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,SAAS,CAAC,SAAS;aAC/B,CAAC;QACJ,CAAC;QAED,gCAAgC;QAChC,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;YAC7D,OAAO;gBACL,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAC9B,EAAE,EAAE,OAAO,CAAC,QAAQ;aACrB,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,SAAS;SAChB,CAAC;IACJ,CAAC;CACF"} \ No newline at end of file diff --git a/dist/esm/config.js b/dist/esm/config.js new file mode 100644 index 0000000..48218c6 --- /dev/null +++ b/dist/esm/config.js @@ -0,0 +1,65 @@ +/** + * Default configuration values + */ +export const DEFAULT_OPTIONS = { + sampleRate: 1.0, + maxBreadcrumbs: 100, + debug: false, + enableOfflineQueue: true, + maxOfflineQueueSize: 500, +}; +/** + * Parse a DSN string into its components + * Format: https://pk_live_xxx@irontelemetry.com + */ +export function parseDsn(dsn) { + try { + const url = new URL(dsn); + const publicKey = url.username; + if (!publicKey || !publicKey.startsWith('pk_')) { + throw new Error('DSN must contain a valid public key starting with pk_'); + } + const protocol = url.protocol.replace(':', ''); + const host = url.host; + return { + publicKey, + host, + protocol, + apiBaseUrl: `${protocol}://${host}`, + }; + } + catch (error) { + if (error instanceof Error && error.message.includes('pk_')) { + throw error; + } + throw new Error(`Invalid DSN format: ${dsn}`); + } +} +/** + * Validate and merge options with defaults + */ +export function resolveOptions(options) { + const parsedDsn = parseDsn(options.dsn); + return { + dsn: options.dsn, + environment: options.environment ?? 'production', + appVersion: options.appVersion ?? '0.0.0', + sampleRate: Math.max(0, Math.min(1, options.sampleRate ?? DEFAULT_OPTIONS.sampleRate)), + maxBreadcrumbs: options.maxBreadcrumbs ?? DEFAULT_OPTIONS.maxBreadcrumbs, + debug: options.debug ?? DEFAULT_OPTIONS.debug, + beforeSend: options.beforeSend ?? (() => true), + enableOfflineQueue: options.enableOfflineQueue ?? DEFAULT_OPTIONS.enableOfflineQueue, + maxOfflineQueueSize: options.maxOfflineQueueSize ?? DEFAULT_OPTIONS.maxOfflineQueueSize, + apiBaseUrl: options.apiBaseUrl ?? parsedDsn.apiBaseUrl, + parsedDsn, + }; +} +/** + * Generate a unique event ID + */ +export function generateEventId() { + const timestamp = Date.now().toString(36); + const random = Math.random().toString(36).substring(2, 15); + return `${timestamp}-${random}`; +} +//# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/dist/esm/config.js.map b/dist/esm/config.js.map new file mode 100644 index 0000000..b70d8dc --- /dev/null +++ b/dist/esm/config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA8B;IACxD,UAAU,EAAE,GAAG;IACf,cAAc,EAAE,GAAG;IACnB,KAAK,EAAE,KAAK;IACZ,kBAAkB,EAAE,IAAI;IACxB,mBAAmB,EAAE,GAAG;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC;QAE/B,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;QAC3E,CAAC;QAED,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QAEtB,OAAO;YACL,SAAS;YACT,IAAI;YACJ,QAAQ;YACR,UAAU,EAAE,GAAG,QAAQ,MAAM,IAAI,EAAE;SACpC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M,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3D,OAAO,GAAG,SAAS,IAAI,MAAM,EAAE,CAAC;AAClC,CAAC"} \ No newline at end of file diff --git a/dist/esm/index.js b/dist/esm/index.js new file mode 100644 index 0000000..f9601a9 --- /dev/null +++ b/dist/esm/index.js @@ -0,0 +1,223 @@ +import { TelemetryClient } from './client'; +// Export classes +export { TelemetryClient } from './client'; +export { Journey, JourneyScope, Step, StepScope } from './journey'; +// Global client instance +let globalClient = null; +/** + * Initialize the global IronTelemetry client + */ +export function init(optionsOrDsn) { + const options = typeof optionsOrDsn === 'string' ? { dsn: optionsOrDsn } : optionsOrDsn; + globalClient = new TelemetryClient(options); + return globalClient; +} +/** + * Get the global client instance + */ +export function getClient() { + return globalClient; +} +/** + * Capture an exception using the global client + */ +export async function captureException(error, extra) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return { success: false, error: 'Client not initialized' }; + } + return globalClient.captureException(error, extra); +} +/** + * Capture a message using the global client + */ +export async function captureMessage(message, level = 'info') { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return { success: false, error: 'Client not initialized' }; + } + return globalClient.captureMessage(message, level); +} +export function addBreadcrumb(messageOrBreadcrumb, category, level, data) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + if (typeof messageOrBreadcrumb === 'string') { + globalClient.addBreadcrumb(messageOrBreadcrumb, category, level, data); + } + else { + globalClient.addBreadcrumb(messageOrBreadcrumb); + } +} +/** + * Set user context using the global client + */ +export function setUser(id, email, data) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + globalClient.setUser(id, email, data); +} +/** + * Clear user context using the global client + */ +export function clearUser() { + if (!globalClient) { + return; + } + globalClient.clearUser(); +} +/** + * Set a tag using the global client + */ +export function setTag(key, value) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + globalClient.setTag(key, value); +} +/** + * Set extra context using the global client + */ +export function setExtra(key, value) { + if (!globalClient) { + console.warn('[IronTelemetry] Client not initialized. Call init() first.'); + return; + } + globalClient.setExtra(key, value); +} +/** + * Start a journey using the global client + */ +export function startJourney(name) { + if (!globalClient) { + throw new Error('[IronTelemetry] Client not initialized. Call init() first.'); + } + return globalClient.startJourney(name); +} +/** + * Start a step in the current journey using the global client + */ +export function startStep(name, category) { + if (!globalClient) { + throw new Error('[IronTelemetry] Client not initialized. Call init() first.'); + } + return globalClient.startStep(name, category); +} +/** + * Flush pending events using the global client + */ +export async function flush() { + if (!globalClient) { + return; + } + await globalClient.flush(); +} +/** + * Close the global client + */ +export function close() { + if (globalClient) { + globalClient.close(); + globalClient = null; + } +} +// Default export for convenience +const IronTelemetry = { + init, + getClient, + captureException, + captureMessage, + addBreadcrumb, + setUser, + clearUser, + setTag, + setExtra, + startJourney, + startStep, + flush, + close, +}; +export default IronTelemetry; +/** + * Enable the Error.prototype.capture() extension. + * This is opt-in to avoid TypeScript conflicts in projects that create + * Error-like objects without the capture method. + * + * After calling this, you can use: throw new Error('msg').capture() + */ +export function enableErrorCapture() { + if (typeof Error.prototype.capture === 'function') { + return; // Already enabled + } + Error.prototype.capture = function () { + captureException(this); + return this; + }; +} +// Type augmentation for projects that call enableErrorCapture() +// Users can add this to their project if they want type support: +// declare global { interface Error { capture(): Error; } } +/** + * Set up global unhandled exception handler + */ +export function useUnhandledExceptionHandler() { + if (typeof window !== 'undefined') { + // Browser + window.addEventListener('error', (event) => { + captureException(event.error ?? new Error(event.message)); + }); + window.addEventListener('unhandledrejection', (event) => { + captureException(event.reason ?? new Error('Unhandled Promise rejection')); + }); + } + else if (typeof process !== 'undefined') { + // Node.js + process.on('uncaughtException', (error) => { + captureException(error); + }); + process.on('unhandledRejection', (reason) => { + captureException(reason ?? new Error('Unhandled Promise rejection')); + }); + } +} +/** + * Track a step with automatic error handling + */ +export function trackStep(name, fn, category) { + if (!globalClient) { + return fn(); + } + const step = startStep(name, category); + try { + const result = fn(); + step[Symbol.dispose](); + return result; + } + catch (error) { + step.getStep().fail(); + throw error; + } +} +/** + * Track an async step with automatic error handling + */ +export async function trackStepAsync(name, fn, category) { + if (!globalClient) { + return fn(); + } + const step = startStep(name, category); + try { + const result = await fn(); + step[Symbol.dispose](); + return result; + } + catch (error) { + step.getStep().fail(); + throw error; + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map new file mode 100644 index 0000000..cfb3cfd --- /dev/null +++ b/dist/esm/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AA6B3C,iBAAiB;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEnE,yBAAyB;AACzB,IAAI,YAAY,GAA2B,IAAI,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,YAAuC;IAC1D,MAAM,OAAO,GAAG,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;IACxF,YAAY,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,KAAsB,EACtB,KAA+B;IAE/B,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAA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AC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/dist/esm/journey.js b/dist/esm/journey.js new file mode 100644 index 0000000..23f6e5f --- /dev/null +++ b/dist/esm/journey.js @@ -0,0 +1,195 @@ +import { generateEventId } from './config'; +/** + * Represents an active journey tracking session + */ +export class Journey { + constructor(name) { + this.metadata = {}; + this.steps = []; + this._completed = false; + this._failed = false; + this.id = generateEventId(); + this.name = name; + this.startedAt = new Date(); + } + /** + * Set user context for this journey + */ + setUser(id, email, data) { + this.user = { id, email, data }; + return this; + } + /** + * Set metadata for this journey + */ + setMetadata(key, value) { + this.metadata[key] = value; + return this; + } + /** + * Start a new step in this journey + */ + startStep(name, category) { + // Complete any existing step + if (this.currentStep && this.currentStep.status === 'in_progress') { + this.currentStep.status = 'completed'; + this.currentStep.endedAt = new Date(); + } + const step = { + name, + category, + startedAt: new Date(), + status: 'in_progress', + data: {}, + }; + this.steps.push(step); + this.currentStep = step; + return new Step(step, this); + } + /** + * Mark the journey as completed + */ + complete() { + if (this.currentStep && this.currentStep.status === 'in_progress') { + this.currentStep.status = 'completed'; + this.currentStep.endedAt = new Date(); + } + this._completed = true; + } + /** + * Mark the journey as failed + */ + fail() { + if (this.currentStep && this.currentStep.status === 'in_progress') { + this.currentStep.status = 'failed'; + this.currentStep.endedAt = new Date(); + } + this._failed = true; + } + /** + * Get the journey context for an event + */ + getContext() { + return { + journeyId: this.id, + name: this.name, + currentStep: this.currentStep?.name, + startedAt: this.startedAt, + metadata: this.metadata, + }; + } + /** + * Get the user context for this journey + */ + getUser() { + return this.user; + } + /** + * Check if the journey is complete + */ + get isComplete() { + return this._completed || this._failed; + } + /** + * Get journey ID + */ + get journeyId() { + return this.id; + } +} +/** + * Represents a step within a journey + */ +export class Step { + constructor(step, journey) { + this.step = step; + this.journey = journey; + } + /** + * Set data for this step + */ + setData(key, value) { + this.step.data[key] = value; + return this; + } + /** + * Mark the step as completed + */ + complete() { + this.step.status = 'completed'; + this.step.endedAt = new Date(); + } + /** + * Mark the step as failed + */ + fail() { + this.step.status = 'failed'; + this.step.endedAt = new Date(); + } + /** + * Get the step name + */ + get name() { + return this.step.name; + } + /** + * Get the parent journey + */ + getJourney() { + return this.journey; + } +} +/** + * Journey scope that auto-completes on disposal + */ +export class JourneyScope { + constructor(journey, onComplete) { + this.journey = journey; + this.onComplete = onComplete; + } + /** + * Get the underlying journey + */ + getJourney() { + return this.journey; + } + /** + * Dispose of the journey scope + */ + [Symbol.dispose]() { + if (!this.journey.isComplete) { + this.journey.complete(); + } + this.onComplete?.(); + } +} +/** + * Step scope that auto-completes on disposal + */ +export class StepScope { + constructor(step) { + this.step = step; + } + /** + * Get the underlying step + */ + getStep() { + return this.step; + } + /** + * Set data on the step + */ + setData(key, value) { + this.step.setData(key, value); + return this; + } + /** + * Dispose of the step scope + */ + [Symbol.dispose]() { + if (this.step['step'].status === 'in_progress') { + this.step.complete(); + } + } +} +//# sourceMappingURL=journey.js.map \ No newline at end of file diff --git a/dist/esm/journey.js.map b/dist/esm/journey.js.map new file mode 100644 index 0000000..c0f4094 --- /dev/null +++ b/dist/esm/journey.js.map @@ -0,0 +1 @@ +{"version":3,"file":"journey.js","sourceRoot":"","sources":["../../src/journey.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C;;GAEG;AACH,MAAM,OAAO,OAAO;IAWlB,YAAY,IAAY;QAPhB,aAAQ,GAA4B,EAAE,CAAC;QAEvC,UAAK,GAAkB,EAAE,CAAC;QAE1B,eAAU,GAAY,KAAK,CAAC;QAC5B,YAAO,GAAY,KAAK,CAAC;QAG/B,IAAI,CAAC,EAAE,GAAG,eAAe,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,IAA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d,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,aAAa,EAAE,CAAC;YAC/C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF"} \ No newline at end of file diff --git a/dist/esm/queue.js b/dist/esm/queue.js new file mode 100644 index 0000000..c8a3e54 --- /dev/null +++ b/dist/esm/queue.js @@ -0,0 +1,115 @@ +const STORAGE_KEY = 'irontelemetry_queue'; +/** + * Offline queue for storing events when the network is unavailable + */ +export class OfflineQueue { + constructor(maxSize = 500, debug = false) { + this.queue = []; + this.maxSize = maxSize; + this.debug = debug; + this.load(); + } + /** + * Add an event to the queue + */ + enqueue(event) { + if (this.queue.length >= this.maxSize) { + // Remove oldest events to make room + this.queue.shift(); + if (this.debug) { + console.log('[IronTelemetry] Queue full, dropping oldest event'); + } + } + this.queue.push(event); + this.save(); + if (this.debug) { + console.log('[IronTelemetry] Event queued, queue size:', this.queue.length); + } + } + /** + * Get all queued events + */ + getAll() { + return [...this.queue]; + } + /** + * Remove an event from the queue + */ + remove(eventId) { + this.queue = this.queue.filter((e) => e.eventId !== eventId); + this.save(); + } + /** + * Clear all queued events + */ + clear() { + this.queue = []; + this.save(); + } + /** + * Get the number of queued events + */ + get size() { + return this.queue.length; + } + /** + * Check if the queue is empty + */ + get isEmpty() { + return this.queue.length === 0; + } + /** + * Load queue from persistent storage + */ + load() { + try { + if (typeof localStorage !== 'undefined') { + const data = localStorage.getItem(STORAGE_KEY); + if (data) { + const parsed = JSON.parse(data); + this.queue = parsed.map((e) => this.deserializeEvent(e)); + } + } + } + catch (error) { + if (this.debug) { + console.error('[IronTelemetry] Failed to load queue from storage:', error); + } + } + } + /** + * Save queue to persistent storage + */ + save() { + try { + if (typeof localStorage !== 'undefined') { + localStorage.setItem(STORAGE_KEY, JSON.stringify(this.queue)); + } + } + catch (error) { + if (this.debug) { + console.error('[IronTelemetry] Failed to save queue to storage:', error); + } + } + } + /** + * Deserialize an event from storage + */ + deserializeEvent(data) { + return { + ...data, + timestamp: new Date(data.timestamp), + breadcrumbs: (data.breadcrumbs ?? []).map((b) => ({ + ...b, + timestamp: new Date(b.timestamp), + })), + journey: data.journey + ? { + ...data.journey, + startedAt: new Date(data.journey.startedAt), + } + : undefined, + }; + } +} +//# sourceMappingURL=queue.js.map \ No newline at end of file diff --git a/dist/esm/queue.js.map b/dist/esm/queue.js.map new file mode 100644 index 0000000..d24ddad --- /dev/null +++ b/dist/esm/queue.js.map @@ -0,0 +1 @@ +{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../src/queue.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C;;GAEG;AACH,MAAM,OAAO,YAAY;IAKvB,YAAY,UAAkB,GAAG,EAAE,QAAiB,KAAK;QAFjD,UAAK,GAAqB,EAAE,CAAC;QAGnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,KAAqB;QAC3B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACtC,oCAAoC;YACpC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,EAAE,CAAC;QAEZ,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;IAED;;O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AC;YACH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;gBACxC,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,kDAAkD,EAAE,KAAK,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,IAA6B;QACpD,OAAO;YACL,GAAG,IAAI;YACP,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,SAAmB,CAAC;YAC7C,WAAW,EAAE,CAAE,IAAI,CAAC,WAAyC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBAC/E,GAAG,CAAC;gBACJ,SAAS,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,SAAmB,CAAC;aAC3C,CAAC,CAAC;YACH,OAAO,EAAE,IAAI,CAAC,OAAO;gBACnB,CAAC,CAAC;oBACE,GAAI,IAAI,CAAC,OAAmC;oBAC5C,SAAS,EAAE,IAAI,IAAI,CAAE,IAAI,CAAC,OAAmC,CAAC,SAAmB,CAAC;iBACnF;gBACH,CAAC,CAAC,SAAS;SACI,CAAC;IACtB,CAAC;CACF"} \ No newline at end of file diff --git a/dist/esm/transport.js b/dist/esm/transport.js new file mode 100644 index 0000000..85a5a57 --- /dev/null +++ b/dist/esm/transport.js @@ -0,0 +1,100 @@ +/** + * HTTP transport for sending events to the server + */ +export class Transport { + constructor(parsedDsn, apiBaseUrl, debug = false) { + this.apiBaseUrl = apiBaseUrl; + this.publicKey = parsedDsn.publicKey; + this.debug = debug; + } + /** + * Send an event to the server + */ + async send(event) { + const url = `${this.apiBaseUrl}/api/v1/events`; + try { + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-Public-Key': this.publicKey, + }, + body: JSON.stringify(this.serializeEvent(event)), + }); + if (!response.ok) { + const errorText = await response.text(); + if (this.debug) { + console.error('[IronTelemetry] Failed to send event:', response.status, errorText); + } + return { + success: false, + error: `HTTP ${response.status}: ${errorText}`, + }; + } + const result = await response.json(); + if (this.debug) { + console.log('[IronTelemetry] Event sent successfully:', event.eventId); + } + return { + success: true, + eventId: result.eventId ?? event.eventId, + }; + } + catch (error) { + const errorMessage = error instanceof Error ? error.message : 'Unknown error'; + if (this.debug) { + console.error('[IronTelemetry] Failed to send event:', errorMessage); + } + return { + success: false, + error: errorMessage, + }; + } + } + /** + * Check if the server is reachable + */ + async isOnline() { + try { + const response = await fetch(`${this.apiBaseUrl}/api/v1/health`, { + method: 'GET', + headers: { + 'X-Public-Key': this.publicKey, + }, + }); + return response.ok; + } + catch { + return false; + } + } + /** + * Serialize an event for sending + */ + serializeEvent(event) { + return { + eventId: event.eventId, + timestamp: event.timestamp.toISOString(), + level: event.level, + message: event.message, + exception: event.exception, + user: event.user, + tags: event.tags, + extra: event.extra, + breadcrumbs: event.breadcrumbs.map((b) => ({ + ...b, + timestamp: b.timestamp.toISOString(), + })), + journey: event.journey + ? { + ...event.journey, + startedAt: event.journey.startedAt.toISOString(), + } + : undefined, + environment: event.environment, + appVersion: event.appVersion, + platform: event.platform, + }; + } +} +//# sourceMappingURL=transport.js.map \ No newline at end of file diff --git a/dist/esm/transport.js.map b/dist/esm/transport.js.map new file mode 100644 index 0000000..df90e22 --- /dev/null +++ b/dist/esm/transport.js.map @@ -0,0 +1 @@ +{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,SAAS;IAKpB,YAAY,SAAoB,EAAE,UAAkB,EAAE,QAAiB,KAAK;QAC1E,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,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CAAC;oBACE,GAAG,KAAK,CAAC,OAAO;oBAChB,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE;iBACjD;gBACH,CAAC,CAAC,SAAS;YACb,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;SACzB,CAAC;IACJ,CAAC;CACF"} \ No newline at end of file diff --git a/dist/esm/types.js b/dist/esm/types.js new file mode 100644 index 0000000..718fd38 --- /dev/null +++ b/dist/esm/types.js @@ -0,0 +1,2 @@ +export {}; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/dist/esm/types.js.map b/dist/esm/types.js.map new file mode 100644 index 0000000..7b5fff8 --- /dev/null +++ b/dist/esm/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/types/breadcrumbs.d.ts b/dist/types/breadcrumbs.d.ts new file mode 100644 index 0000000..cd64bff --- /dev/null +++ b/dist/types/breadcrumbs.d.ts @@ -0,0 +1,32 @@ +import type { Breadcrumb, BreadcrumbCategory, SeverityLevel } from './types'; +/** + * Manages breadcrumbs for an SDK instance + */ +export declare class BreadcrumbManager { + private readonly maxBreadcrumbs; + private breadcrumbs; + constructor(maxBreadcrumbs?: number); + /** + * Add a breadcrumb + */ + add(message: string, category?: BreadcrumbCategory, level?: SeverityLevel, data?: Record): void; + /** + * Add a breadcrumb from a full Breadcrumb object + */ + addBreadcrumb(breadcrumb: Omit & { + timestamp?: Date; + }): void; + /** + * Get all breadcrumbs + */ + getAll(): Breadcrumb[]; + /** + * Clear all breadcrumbs + */ + clear(): void; + /** + * Get the number of breadcrumbs + */ + get count(): number; +} +//# sourceMappingURL=breadcrumbs.d.ts.map \ No newline at end of file diff --git a/dist/types/breadcrumbs.d.ts.map b/dist/types/breadcrumbs.d.ts.map new file mode 100644 index 0000000..9a37bd5 --- /dev/null +++ b/dist/types/breadcrumbs.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"breadcrumbs.d.ts","sourceRoot":"","sources":["../../src/breadcrumbs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7E;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,WAAW,CAAoB;gBAE3B,cAAc,GAAE,MAAY;IAIxC;;OAEG;IACH,GAAG,CACD,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,kBAA6B,EACvC,KAAK,GAAE,aAAsB,EAC7B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,IAAI;IAiBP;;OAEG;IACH,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG;QAAE,SAAS,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI;IAarF;;OAEG;IACH,MAAM,IAAI,UAAU,EAAE;IAItB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;CACF"} \ No newline at end of file diff --git a/dist/types/client.d.ts b/dist/types/client.d.ts new file mode 100644 index 0000000..b53c580 --- /dev/null +++ b/dist/types/client.d.ts @@ -0,0 +1,116 @@ +import type { TelemetryOptions, SeverityLevel, Breadcrumb, BreadcrumbCategory, SendResult } from './types'; +import { JourneyScope, StepScope } from './journey'; +/** + * Global debug logging flag. When enabled, all IronTelemetry clients + * will output debug information to the console. + */ +export declare let enableDebugLogging: boolean; +/** + * Enable or disable global debug logging for all TelemetryClient instances. + * @param enabled Whether to enable debug logging + */ +export declare function setDebugLogging(enabled: boolean): void; +/** + * Main IronTelemetry client class + */ +export declare class TelemetryClient { + private readonly options; + private readonly transport; + private readonly queue; + private readonly breadcrumbs; + private tags; + private extra; + private user?; + private currentJourney?; + private flushInterval?; + private isInitialized; + constructor(options: TelemetryOptions); + /** + * Capture an exception + */ + captureException(error: Error | unknown, extra?: Record): Promise; + /** + * Capture a message + */ + captureMessage(message: string, level?: SeverityLevel): Promise; + /** + * Log a structured message with title, message, and optional data. + * Useful for structured logging that differentiates the log title from its details. + * @param level The severity level of the log + * @param title A short, descriptive title for the log entry + * @param message Optional detailed message + * @param data Optional additional data to attach to the log + */ + logMessage(level: SeverityLevel, title: string, message?: string, data?: Record): Promise; + /** + * Add a breadcrumb + */ + addBreadcrumb(message: string, category?: BreadcrumbCategory, level?: SeverityLevel, data?: Record): void; + addBreadcrumb(breadcrumb: Omit): void; + /** + * Get a copy of the current breadcrumbs list. + * @returns A read-only array of breadcrumbs + */ + getBreadcrumbs(): ReadonlyArray; + /** + * Clear all breadcrumbs. + */ + clearBreadcrumbs(): void; + /** + * Set user context + */ + setUser(id: string, email?: string, data?: Record): void; + /** + * Clear user context + */ + clearUser(): void; + /** + * Set a tag + */ + setTag(key: string, value: string): void; + /** + * Set extra context + */ + setExtra(key: string, value: unknown): void; + /** + * Start a new journey + */ + startJourney(name: string): JourneyScope; + /** + * Start a step in the current journey + */ + startStep(name: string, category?: string): StepScope; + /** + * Flush pending events + */ + flush(): Promise; + /** + * Close the client + */ + close(): void; + /** + * Create a telemetry event + */ + private createEvent; + /** + * Send an event + */ + private sendEvent; + /** + * Process offline queue + */ + private processQueue; + /** + * Parse an error into exception info + */ + private parseException; + /** + * Parse a stack trace string into frames + */ + private parseStackTrace; + /** + * Get platform information + */ + private getPlatformInfo; +} +//# sourceMappingURL=client.d.ts.map \ No newline at end of file diff --git a/dist/types/client.d.ts.map b/dist/types/client.d.ts.map new file mode 100644 index 0000000..1e259e4 --- /dev/null +++ b/dist/types/client.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAA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AO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,kBAAkB,EAC7B,KAAK,CAAC,EAAE,aAAa,EACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,IAAI;IACP,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,IAAI;IAc9D;;;OAGG;IACH,cAAc,IAAI,aAAa,CAAC,UAAU,CAAC;IAI3C;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAIxB;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIzE;;OAEG;IACH,SAAS,IAAI,IAAI;IAIjB;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxC;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAI3C;;OAEG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAaxC;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS;IASrD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,OAAO,CAAC,WAAW;IAwBnB;;OAEG;YACW,SAAS;IA+BvB;;OAEG;YACW,YAAY;IAoB1B;;OAEG;IACH,OAAO,CAAC,cAAc;IAetB;;OAEG;IACH,OAAO,CAAC,eAAe;IAkCvB;;OAEG;IACH,OAAO,CAAC,eAAe;CAsBxB"} \ No newline at end of file diff --git a/dist/types/config.d.ts b/dist/types/config.d.ts new file mode 100644 index 0000000..8460b74 --- /dev/null +++ b/dist/types/config.d.ts @@ -0,0 +1,21 @@ +import type { TelemetryOptions, ParsedDsn } from './types'; +/** + * Default configuration values + */ +export declare const DEFAULT_OPTIONS: Partial; +/** + * Parse a DSN string into its components + * Format: https://pk_live_xxx@irontelemetry.com + */ +export declare function parseDsn(dsn: string): ParsedDsn; +/** + * Validate and merge options with defaults + */ +export declare function resolveOptions(options: TelemetryOptions): Required & { + parsedDsn: ParsedDsn; +}; +/** + * Generate a unique event ID + */ +export declare function generateEventId(): string; +//# sourceMappingURL=config.d.ts.map \ No newline at end of file diff --git a/dist/types/config.d.ts.map b/dist/types/config.d.ts.map new file mode 100644 index 0000000..954538b --- /dev/null +++ b/dist/types/config.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE3D;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,OAAO,CAAC,gBAAgB,CAMrD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAwB/C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAAG;IAAE,SAAS,EAAE,SAAS,CAAA;CAAE,CAgB/G;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAIxC"} \ No newline at end of file diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts new file mode 100644 index 0000000..14c6511 --- /dev/null +++ b/dist/types/index.d.ts @@ -0,0 +1,96 @@ +import { TelemetryClient } from './client'; +import type { TelemetryOptions, SeverityLevel, Breadcrumb, BreadcrumbCategory, SendResult } from './types'; +import { JourneyScope, StepScope } from './journey'; +export type { TelemetryOptions, TelemetryEvent, SeverityLevel, Breadcrumb, BreadcrumbCategory, User, SendResult, ExceptionInfo, StackFrame, PlatformInfo, JourneyContext, JourneyStep, ParsedDsn, } from './types'; +export { TelemetryClient } from './client'; +export { Journey, JourneyScope, Step, StepScope } from './journey'; +/** + * Initialize the global IronTelemetry client + */ +export declare function init(optionsOrDsn: TelemetryOptions | string): TelemetryClient; +/** + * Get the global client instance + */ +export declare function getClient(): TelemetryClient | null; +/** + * Capture an exception using the global client + */ +export declare function captureException(error: Error | unknown, extra?: Record): Promise; +/** + * Capture a message using the global client + */ +export declare function captureMessage(message: string, level?: SeverityLevel): Promise; +/** + * Add a breadcrumb using the global client + */ +export declare function addBreadcrumb(message: string, category?: BreadcrumbCategory, level?: SeverityLevel, data?: Record): void; +export declare function addBreadcrumb(breadcrumb: Omit): void; +/** + * Set user context using the global client + */ +export declare function setUser(id: string, email?: string, data?: Record): void; +/** + * Clear user context using the global client + */ +export declare function clearUser(): void; +/** + * Set a tag using the global client + */ +export declare function setTag(key: string, value: string): void; +/** + * Set extra context using the global client + */ +export declare function setExtra(key: string, value: unknown): void; +/** + * Start a journey using the global client + */ +export declare function startJourney(name: string): JourneyScope; +/** + * Start a step in the current journey using the global client + */ +export declare function startStep(name: string, category?: string): StepScope; +/** + * Flush pending events using the global client + */ +export declare function flush(): Promise; +/** + * Close the global client + */ +export declare function close(): void; +declare const IronTelemetry: { + init: typeof init; + getClient: typeof getClient; + captureException: typeof captureException; + captureMessage: typeof captureMessage; + addBreadcrumb: typeof addBreadcrumb; + setUser: typeof setUser; + clearUser: typeof clearUser; + setTag: typeof setTag; + setExtra: typeof setExtra; + startJourney: typeof startJourney; + startStep: typeof startStep; + flush: typeof flush; + close: typeof close; +}; +export default IronTelemetry; +/** + * Enable the Error.prototype.capture() extension. + * This is opt-in to avoid TypeScript conflicts in projects that create + * Error-like objects without the capture method. + * + * After calling this, you can use: throw new Error('msg').capture() + */ +export declare function enableErrorCapture(): void; +/** + * Set up global unhandled exception handler + */ +export declare function useUnhandledExceptionHandler(): void; +/** + * Track a step with automatic error handling + */ +export declare function trackStep(name: string, fn: () => T, category?: string): T; +/** + * Track an async step with automatic error handling + */ +export declare function trackStepAsync(name: string, fn: () => Promise, category?: string): Promise; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/types/index.d.ts.map b/dist/types/index.d.ts.map new file mode 100644 index 0000000..3fa9891 --- /dev/null +++ b/dist/types/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EACV,gBAAgB,EAEhB,aAAa,EACb,UAAU,EACV,kBAAkB,EAElB,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGpD,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,IAAI,EACJ,UAAU,EACV,aAAa,EACb,UAAU,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,SAAS,GACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAKnE;;GAEG;AACH,wBAAgB,IAAI,CAAC,YAAY,EAAE,gBAAgB,GAAG,MAAM,GAAG,eAAe,CAI7E;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,eAAe,GAAG,IAAI,CAElD;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,KAAK,GAAG,OAAO,EACtB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,aAAsB,GAC5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AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,CAe5E;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,CAAC,CAAC,CAeZ"} \ No newline at end of file diff --git a/dist/types/journey.d.ts b/dist/types/journey.d.ts new file mode 100644 index 0000000..fa2660c --- /dev/null +++ b/dist/types/journey.d.ts @@ -0,0 +1,116 @@ +import type { JourneyContext, JourneyStep, User } from './types'; +/** + * Represents an active journey tracking session + */ +export declare class Journey { + private readonly id; + private readonly name; + private readonly startedAt; + private metadata; + private user?; + private steps; + private currentStep?; + private _completed; + private _failed; + constructor(name: string); + /** + * Set user context for this journey + */ + setUser(id: string, email?: string, data?: Record): this; + /** + * Set metadata for this journey + */ + setMetadata(key: string, value: unknown): this; + /** + * Start a new step in this journey + */ + startStep(name: string, category?: string): Step; + /** + * Mark the journey as completed + */ + complete(): void; + /** + * Mark the journey as failed + */ + fail(): void; + /** + * Get the journey context for an event + */ + getContext(): JourneyContext; + /** + * Get the user context for this journey + */ + getUser(): User | undefined; + /** + * Check if the journey is complete + */ + get isComplete(): boolean; + /** + * Get journey ID + */ + get journeyId(): string; +} +/** + * Represents a step within a journey + */ +export declare class Step { + private readonly step; + private readonly journey; + constructor(step: JourneyStep, journey: Journey); + /** + * Set data for this step + */ + setData(key: string, value: unknown): this; + /** + * Mark the step as completed + */ + complete(): void; + /** + * Mark the step as failed + */ + fail(): void; + /** + * Get the step name + */ + get name(): string; + /** + * Get the parent journey + */ + getJourney(): Journey; +} +/** + * Journey scope that auto-completes on disposal + */ +export declare class JourneyScope { + private readonly journey; + private readonly onComplete?; + constructor(journey: Journey, onComplete?: () => void); + /** + * Get the underlying journey + */ + getJourney(): Journey; + /** + * Dispose of the journey scope + */ + [Symbol.dispose](): void; +} +/** + * Step scope that auto-completes on disposal + */ +export declare class StepScope { + private readonly step; + constructor(step: Step); + /** + * Get the underlying step + */ + getStep(): Step; + /** + * Set data on the step + */ + setData(key: string, value: unknown): this; + /** + * Dispose of the step scope + */ + [Symbol.dispose](): void; +} +//# sourceMappingURL=journey.d.ts.map \ No newline at end of file diff --git a/dist/types/journey.d.ts.map b/dist/types/journey.d.ts.map new file mode 100644 index 0000000..1066f31 --- /dev/null +++ b/dist/types/journey.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"journey.d.ts","sourceRoot":"","sources":["../../src/journey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAGjE;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAO;IACjC,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAO;IACpB,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,OAAO,CAAkB;gBAErB,IAAI,EAAE,MAAM;IAMxB;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAKzE;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAK9C;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC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AEG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI;CAKzB"} \ No newline at end of file diff --git a/dist/types/queue.d.ts b/dist/types/queue.d.ts new file mode 100644 index 0000000..ca8bada --- /dev/null +++ b/dist/types/queue.d.ts @@ -0,0 +1,47 @@ +import type { TelemetryEvent } from './types'; +/** + * Offline queue for storing events when the network is unavailable + */ +export declare class OfflineQueue { + private readonly maxSize; + private readonly debug; + private queue; + constructor(maxSize?: number, debug?: boolean); + /** + * Add an event to the queue + */ + enqueue(event: TelemetryEvent): void; + /** + * Get all queued events + */ + getAll(): TelemetryEvent[]; + /** + * Remove an event from the queue + */ + remove(eventId: string): void; + /** + * Clear all queued events + */ + clear(): void; + /** + * Get the number of queued events + */ + get size(): number; + /** + * Check if the queue is empty + */ + get isEmpty(): boolean; + /** + * Load queue from persistent storage + */ + private load; + /** + * Save queue to persistent storage + */ + private save; + /** + * Deserialize an event from storage + */ + private deserializeEvent; +} +//# sourceMappingURL=queue.d.ts.map \ No newline at end of file diff --git a/dist/types/queue.d.ts.map b/dist/types/queue.d.ts.map new file mode 100644 index 0000000..02d307e --- /dev/null +++ b/dist/types/queue.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAO,CAAC,KAAK,CAAwB;gBAEzB,OAAO,GAAE,MAAY,EAAE,KAAK,GAAE,OAAe;IAMzD;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAiBpC;;OAEG;IACH,MAAM,IAAI,cAAc,EAAE;IAI1B;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK7B;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,OAAO,CAAC,IAAI;IAgBZ;;OAEG;IACH,OAAO,CAAC,IAAI;IAYZ;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAgBzB"} \ No newline at end of file diff --git a/dist/types/transport.d.ts b/dist/types/transport.d.ts new file mode 100644 index 0000000..f16ac11 --- /dev/null +++ b/dist/types/transport.d.ts @@ -0,0 +1,23 @@ +import type { TelemetryEvent, SendResult, ParsedDsn } from './types'; +/** + * HTTP transport for sending events to the server + */ +export declare class Transport { + private readonly apiBaseUrl; + private readonly publicKey; + private readonly debug; + constructor(parsedDsn: ParsedDsn, apiBaseUrl: string, debug?: boolean); + /** + * Send an event to the server + */ + send(event: TelemetryEvent): Promise; + /** + * Check if the server is reachable + */ + isOnline(): Promise; + /** + * Serialize an event for sending + */ + private serializeEvent; +} +//# sourceMappingURL=transport.d.ts.map \ No newline at end of file diff --git a/dist/types/transport.d.ts.map b/dist/types/transport.d.ts.map new file mode 100644 index 0000000..7896a24 --- /dev/null +++ b/dist/types/transport.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAErE;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;gBAEpB,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,OAAe;IAM5E;;OAEG;IACG,IAAI,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IA8CtD;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAclC;;OAEG;IACH,OAAO,CAAC,cAAc;CAyBvB"} \ No newline at end of file diff --git a/dist/types/types.d.ts b/dist/types/types.d.ts new file mode 100644 index 0000000..e027436 --- /dev/null +++ b/dist/types/types.d.ts @@ -0,0 +1,196 @@ +/** + * Severity levels for events + */ +export type SeverityLevel = 'debug' | 'info' | 'warning' | 'error' | 'fatal'; +/** + * Breadcrumb categories + */ +export type BreadcrumbCategory = 'ui' | 'user' | 'http' | 'navigation' | 'console' | 'auth' | 'business' | 'notification' | 'custom'; +/** + * A breadcrumb representing an event leading up to an error + */ +export interface Breadcrumb { + /** Timestamp when the breadcrumb was created */ + timestamp: Date; + /** Category of the breadcrumb */ + category: BreadcrumbCategory; + /** Human-readable message */ + message: string; + /** Severity level */ + level?: SeverityLevel; + /** Additional data */ + data?: Record; +} +/** + * User information for context + */ +export interface User { + /** Unique identifier for the user */ + id: string; + /** Email address */ + email?: string; + /** Display name */ + name?: string; + /** Additional user data */ + data?: Record; +} +/** + * Exception/error information + */ +export interface ExceptionInfo { + /** Exception type/class name */ + type: string; + /** Error message */ + message: string; + /** Stack trace */ + stacktrace?: StackFrame[]; +} +/** + * Stack frame information + */ +export interface StackFrame { + /** Function name */ + function?: string; + /** File name */ + filename?: string; + /** Line number */ + lineno?: number; + /** Column number */ + colno?: number; + /** Source context around the line */ + context?: string[]; +} +/** + * Event payload sent to the server + */ +export interface TelemetryEvent { + /** Unique event ID */ + eventId: string; + /** Event timestamp */ + timestamp: Date; + /** Severity level */ + level: SeverityLevel; + /** Message */ + message?: string; + /** Exception information */ + exception?: ExceptionInfo; + /** User context */ + user?: User; + /** Tags for categorization */ + tags: Record; + /** Extra contextual data */ + extra: Record; + /** Breadcrumbs leading up to this event */ + breadcrumbs: Breadcrumb[]; + /** Journey context if in a journey */ + journey?: JourneyContext; + /** Environment name */ + environment?: string; + /** Application version */ + appVersion?: string; + /** Platform information */ + platform: PlatformInfo; +} +/** + * Platform/runtime information + */ +export interface PlatformInfo { + /** Platform name (browser, node, etc.) */ + name: string; + /** Platform version */ + version?: string; + /** Operating system */ + os?: string; + /** Browser/runtime user agent */ + userAgent?: string; +} +/** + * Journey context for tracking user flows + */ +export interface JourneyContext { + /** Journey ID */ + journeyId: string; + /** Journey name */ + name: string; + /** Current step name */ + currentStep?: string; + /** Journey start time */ + startedAt: Date; + /** Journey metadata */ + metadata: Record; +} +/** + * Step within a journey + */ +export interface JourneyStep { + /** Step name */ + name: string; + /** Step category */ + category?: string; + /** Step start time */ + startedAt: Date; + /** Step end time */ + endedAt?: Date; + /** Step status */ + status: 'in_progress' | 'completed' | 'failed'; + /** Step data */ + data: Record; +} +/** + * Options for initializing the SDK + */ +export interface TelemetryOptions { + /** + * Data Source Name (DSN) containing the public key + * Format: https://pk_live_xxx@irontelemetry.com + */ + dsn: string; + /** Environment name (e.g., 'production', 'staging') */ + environment?: string; + /** Application version */ + appVersion?: string; + /** Sample rate for events (0.0 to 1.0) */ + sampleRate?: number; + /** Maximum number of breadcrumbs to keep */ + maxBreadcrumbs?: number; + /** Enable debug logging */ + debug?: boolean; + /** + * Hook called before sending an event + * Return false or null to drop the event, or return the (modified) event to send + */ + beforeSend?: (event: TelemetryEvent) => boolean | TelemetryEvent | null; + /** Enable offline queue for failed events */ + enableOfflineQueue?: boolean; + /** Maximum size of the offline queue */ + maxOfflineQueueSize?: number; + /** API base URL (defaults to parsed from DSN) */ + apiBaseUrl?: string; +} +/** + * Parsed DSN components + */ +export interface ParsedDsn { + /** Public key */ + publicKey: string; + /** Host */ + host: string; + /** Protocol (http or https) */ + protocol: string; + /** Full API base URL */ + apiBaseUrl: string; +} +/** + * Result of sending an event + */ +export interface SendResult { + /** Whether the send was successful */ + success: boolean; + /** Event ID if successful */ + eventId?: string; + /** Error message if failed */ + error?: string; + /** Whether the event was queued for retry */ + queued?: boolean; +} +//# sourceMappingURL=types.d.ts.map \ No newline at end of file diff --git a/dist/types/types.d.ts.map b/dist/types/types.d.ts.map new file mode 100644 index 0000000..9405f6a --- /dev/null +++ b/dist/types/types.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE7E;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,IAAI,GACJ,MAAM,GACN,MAAM,GACN,YAAY,GACZ,SAAS,GACT,MAAM,GACN,UAAU,GACV,cAAc,GACd,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,gDAAgD;IAChD,SAAS,EAAE,IAAI,CAAC;IAChB,iCAAiC;IACjC,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB;IACrB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,sBAAsB;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,qCAAqC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,UAA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