(str: string)
| 37 | * @returns Dsn as DsnComponents or undefined if @param str is not a valid DSN string |
| 38 | */ |
| 39 | export 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 | |
| 71 | function dsnFromComponents(components: DsnComponents): DsnComponents { |
| 72 | return { |
no test coverage detected