All files / src/utils dsn.ts

93.1% Statements 27/29
100% Branches 5/5
66.66% Functions 2/3
93.1% Lines 27/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 1x 1x 37x 37x 37x 2x 2x 35x 35x 35x 35x 35x 35x 35x 35x 35x 37x 2x 2x 37x 1x 1x 2x 2x 1x 1x      
import type { DSNInfo } from '../types';
 
export function parseDSN(dsn: string): DSNInfo {
  try {
    const match = dsn.match(/^(https?):\/\/([^@]+)@([^/]+)\/(.+)$/);
    if (!match) {
      throw new Error('Invalid DSN format');
    }
 
    const [, protocol, publicKey, host, projectId] = match;
 
    return {
      protocol,
      publicKey,
      host,
      projectId,
    };
  } catch (e) {
    throw new Error(`Failed to parse DSN: ${(e as Error).message}`);
  }
}
 
export function getEnvelopeUrl(dsn: DSNInfo): string {
  return `${dsn.protocol}://${dsn.host}/api/${dsn.projectId}/envelope/?sentry_key=${dsn.publicKey}`;
}
 
export function getStoreUrl(dsn: DSNInfo): string {
  return `${dsn.protocol}://${dsn.host}/api/${dsn.projectId}/store/?sentry_key=${dsn.publicKey}`;
}