MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / dsnFromString

Function dsnFromString

packages/core/src/utils/dsn.ts:39–69  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

37 * @returns Dsn as DsnComponents or undefined if @param str is not a valid DSN string
38 */
39export function dsnFromString(str: string): DsnComponents | undefined {
40 const match = DSN_REGEX.exec(str);
41
42 if (!match) {
43 // This should be logged to the console
44 consoleSandbox(() => {
45 // eslint-disable-next-line no-console
46 console.error(`Invalid Sentry Dsn: ${str}`);
47 });
48 return undefined;
49 }
50
51 const [protocol, publicKey, pass = '', host = '', port = '', lastPath = ''] = match.slice(1);
52 let path = '';
53 let projectId = lastPath;
54
55 const split = projectId.split('/');
56 if (split.length > 1) {
57 path = split.slice(0, -1).join('/');
58 projectId = split.pop() as string;
59 }
60
61 if (projectId) {
62 const projectMatch = projectId.match(/^\d+/);
63 if (projectMatch) {
64 projectId = projectMatch[0];
65 }
66 }
67
68 return dsnFromComponents({ host, pass, path, projectId, port, protocol: protocol as DsnProtocol, publicKey });
69}
70
71function dsnFromComponents(components: DsnComponents): DsnComponents {
72 return {

Callers 5

offline.test.tsFile · 0.90
getTransportFunction · 0.90
applyTunnelRouteOptionFunction · 0.90
makeDsnFunction · 0.85

Calls 6

consoleSandboxFunction · 0.90
dsnFromComponentsFunction · 0.85
execMethod · 0.80
sliceMethod · 0.80
matchMethod · 0.80
errorMethod · 0.65

Tested by

no test coverage detected