@@ -19,7 +19,7 @@ function isValidProtocol(protocol?: string): protocol is DsnProtocol {
1919 *
2020 * @param withPassword When set to true, the password will be included.
2121 */
22- function dsntoString ( dsn : Dsn , withPassword : boolean = false ) : string {
22+ export function dsnToString ( dsn : Dsn , withPassword : boolean = false ) : string {
2323 const { host, path, pass, port, projectId, protocol, publicKey } = dsn ;
2424 return (
2525 `${ protocol } ://${ publicKey } ${ withPassword && pass ? `:${ pass } ` : '' } ` +
@@ -72,28 +72,30 @@ function dsnFromComponents(components: DsnComponents): Dsn {
7272 } ;
7373}
7474
75- function validateDsn ( dsn : Dsn ) : boolean {
76- if ( isDebugBuild ( ) ) {
77- const { port, projectId, protocol } = dsn ;
75+ function validateDsn ( dsn : Dsn ) : boolean | void {
76+ if ( ! isDebugBuild ( ) ) {
77+ return ;
78+ }
7879
79- const requiredComponents : ReadonlyArray < keyof DsnComponents > = [ 'protocol' , 'publicKey' , 'host' , 'projectId' ] ;
80- requiredComponents . forEach ( component => {
81- if ( ! dsn [ component ] ) {
82- throw new SentryError ( `Invalid Dsn: ${ component } missing` ) ;
83- }
84- } ) ;
80+ const { port, projectId, protocol } = dsn ;
8581
86- if ( ! projectId . match ( / ^ \d + $ / ) ) {
87- throw new SentryError ( `Invalid Dsn: Invalid projectId ${ projectId } ` ) ;
82+ const requiredComponents : ReadonlyArray < keyof DsnComponents > = [ 'protocol' , 'publicKey' , 'host' , 'projectId' ] ;
83+ requiredComponents . forEach ( component => {
84+ if ( ! dsn [ component ] ) {
85+ throw new SentryError ( `Invalid Dsn: ${ component } missing` ) ;
8886 }
87+ } ) ;
8988
90- if ( ! isValidProtocol ( protocol ) ) {
91- throw new SentryError ( `Invalid Dsn: Invalid protocol ${ protocol } ` ) ;
92- }
89+ if ( ! projectId . match ( / ^ \d + $ / ) ) {
90+ throw new SentryError ( `Invalid Dsn: Invalid projectId ${ projectId } ` ) ;
91+ }
9392
94- if ( port && isNaN ( parseInt ( port , 10 ) ) ) {
95- throw new SentryError ( `Invalid Dsn: Invalid port ${ port } ` ) ;
96- }
93+ if ( ! isValidProtocol ( protocol ) ) {
94+ throw new SentryError ( `Invalid Dsn: Invalid protocol ${ protocol } ` ) ;
95+ }
96+
97+ if ( port && isNaN ( parseInt ( port , 10 ) ) ) {
98+ throw new SentryError ( `Invalid Dsn: Invalid port ${ port } ` ) ;
9799 }
98100
99101 return true ;
@@ -105,10 +107,5 @@ export function makeDsn(from: DsnLike): Dsn {
105107
106108 validateDsn ( components ) ;
107109
108- const dsn : Dsn = {
109- ...components ,
110- toString : ( withPassword ?: boolean ) => dsntoString ( dsn , withPassword ) ,
111- } ;
112-
113- return dsn ;
110+ return components ;
114111}
0 commit comments