1- import { DsnLike , SdkMetadata } from '@sentry/types' ;
2- import { Dsn , urlEncode } from '@sentry/utils' ;
1+ import { DsnComponents , DsnLike , SdkMetadata } from '@sentry/types' ;
2+ import { dsnToString , makeDsn , urlEncode } from '@sentry/utils' ;
33
44const SENTRY_API_VERSION = '7' ;
55
@@ -12,7 +12,7 @@ export interface APIDetails {
1212 /** Metadata about the SDK (name, version, etc) for inclusion in envelope headers */
1313 metadata : SdkMetadata ;
1414 /** The internally used Dsn object. */
15- readonly dsn : Dsn ;
15+ readonly dsn : DsnComponents ;
1616 /** The envelope tunnel to use. */
1717 readonly tunnel ?: string ;
1818}
@@ -32,21 +32,21 @@ export class API {
3232 public metadata : SdkMetadata ;
3333
3434 /** The internally used Dsn object. */
35- private readonly _dsnObject : Dsn ;
35+ private readonly _dsnObject : DsnComponents ;
3636
3737 /** The envelope tunnel to use. */
3838 private readonly _tunnel ?: string ;
3939
4040 /** Create a new instance of API */
4141 public constructor ( dsn : DsnLike , metadata : SdkMetadata = { } , tunnel ?: string ) {
4242 this . dsn = dsn ;
43- this . _dsnObject = new Dsn ( dsn ) ;
43+ this . _dsnObject = makeDsn ( dsn ) ;
4444 this . metadata = metadata ;
4545 this . _tunnel = tunnel ;
4646 }
4747
4848 /** Returns the Dsn object. */
49- public getDsn ( ) : Dsn {
49+ public getDsn ( ) : DsnComponents {
5050 return this . _dsnObject ;
5151 }
5252
@@ -89,25 +89,25 @@ export function initAPIDetails(dsn: DsnLike, metadata?: SdkMetadata, tunnel?: st
8989 return {
9090 initDsn : dsn ,
9191 metadata : metadata || { } ,
92- dsn : new Dsn ( dsn ) ,
92+ dsn : makeDsn ( dsn ) ,
9393 tunnel,
9494 } as APIDetails ;
9595}
9696
9797/** Returns the prefix to construct Sentry ingestion API endpoints. */
98- function getBaseApiEndpoint ( dsn : Dsn ) : string {
98+ function getBaseApiEndpoint ( dsn : DsnComponents ) : string {
9999 const protocol = dsn . protocol ? `${ dsn . protocol } :` : '' ;
100100 const port = dsn . port ? `:${ dsn . port } ` : '' ;
101101 return `${ protocol } //${ dsn . host } ${ port } ${ dsn . path ? `/${ dsn . path } ` : '' } /api/` ;
102102}
103103
104104/** Returns the ingest API endpoint for target. */
105- function _getIngestEndpoint ( dsn : Dsn , target : 'store' | 'envelope' ) : string {
105+ function _getIngestEndpoint ( dsn : DsnComponents , target : 'store' | 'envelope' ) : string {
106106 return `${ getBaseApiEndpoint ( dsn ) } ${ dsn . projectId } /${ target } /` ;
107107}
108108
109109/** Returns a URL-encoded string with auth config suitable for a query string. */
110- function _encodedAuth ( dsn : Dsn ) : string {
110+ function _encodedAuth ( dsn : DsnComponents ) : string {
111111 return urlEncode ( {
112112 // We send only the minimum set of required information. See
113113 // https://github.com/getsentry/sentry-javascript/issues/2572.
@@ -117,7 +117,7 @@ function _encodedAuth(dsn: Dsn): string {
117117}
118118
119119/** Returns the store endpoint URL. */
120- function getStoreEndpoint ( dsn : Dsn ) : string {
120+ function getStoreEndpoint ( dsn : DsnComponents ) : string {
121121 return _getIngestEndpoint ( dsn , 'store' ) ;
122122}
123123
@@ -126,12 +126,12 @@ function getStoreEndpoint(dsn: Dsn): string {
126126 *
127127 * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
128128 */
129- export function getStoreEndpointWithUrlEncodedAuth ( dsn : Dsn ) : string {
129+ export function getStoreEndpointWithUrlEncodedAuth ( dsn : DsnComponents ) : string {
130130 return `${ getStoreEndpoint ( dsn ) } ?${ _encodedAuth ( dsn ) } ` ;
131131}
132132
133133/** Returns the envelope endpoint URL. */
134- function _getEnvelopeEndpoint ( dsn : Dsn ) : string {
134+ function _getEnvelopeEndpoint ( dsn : DsnComponents ) : string {
135135 return _getIngestEndpoint ( dsn , 'envelope' ) ;
136136}
137137
@@ -140,15 +140,19 @@ function _getEnvelopeEndpoint(dsn: Dsn): string {
140140 *
141141 * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
142142 */
143- export function getEnvelopeEndpointWithUrlEncodedAuth ( dsn : Dsn , tunnel ?: string ) : string {
143+ export function getEnvelopeEndpointWithUrlEncodedAuth ( dsn : DsnComponents , tunnel ?: string ) : string {
144144 return tunnel ? tunnel : `${ _getEnvelopeEndpoint ( dsn ) } ?${ _encodedAuth ( dsn ) } ` ;
145145}
146146
147147/**
148148 * Returns an object that can be used in request headers.
149149 * This is needed for node and the old /store endpoint in sentry
150150 */
151- export function getRequestHeaders ( dsn : Dsn , clientName : string , clientVersion : string ) : { [ key : string ] : string } {
151+ export function getRequestHeaders (
152+ dsn : DsnComponents ,
153+ clientName : string ,
154+ clientVersion : string ,
155+ ) : { [ key : string ] : string } {
152156 // CHANGE THIS to use metadata but keep clientName and clientVersion compatible
153157 const header = [ `Sentry sentry_version=${ SENTRY_API_VERSION } ` ] ;
154158 header . push ( `sentry_client=${ clientName } /${ clientVersion } ` ) ;
@@ -171,10 +175,10 @@ export function getReportDialogEndpoint(
171175 user ?: { name ?: string ; email ?: string } ;
172176 } ,
173177) : string {
174- const dsn = new Dsn ( dsnLike ) ;
178+ const dsn = makeDsn ( dsnLike ) ;
175179 const endpoint = `${ getBaseApiEndpoint ( dsn ) } embed/error-page/` ;
176180
177- let encodedOptions = `dsn=${ dsn . toString ( ) } ` ;
181+ let encodedOptions = `dsn=${ dsnToString ( dsn ) } ` ;
178182 for ( const key in dialogOptions ) {
179183 if ( key === 'dsn' ) {
180184 continue ;
0 commit comments