Files
irontelemetry-js/dist/esm/config.js
logikonline 8c300c1f8d Include dist folder for git-based installs
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 <noreply@anthropic.com>
2026-01-07 15:12:47 -05:00

65 lines
2.1 KiB
JavaScript

/**
* 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