1
- import { Dsn , DsnLike , SdkMetadata } from '@sentry/types' ;
2
- import { makeDsn , urlEncode } from '@sentry/utils' ;
1
+ import { DsnComponents , DsnLike , SdkMetadata } from '@sentry/types' ;
2
+ import { dsnToString , makeDsn , urlEncode } from '@sentry/utils' ;
3
3
4
4
const SENTRY_API_VERSION = '7' ;
5
5
@@ -12,7 +12,7 @@ export interface APIDetails {
12
12
/** Metadata about the SDK (name, version, etc) for inclusion in envelope headers */
13
13
metadata : SdkMetadata ;
14
14
/** The internally used Dsn object. */
15
- readonly dsn : Dsn ;
15
+ readonly dsn : DsnComponents ;
16
16
/** The envelope tunnel to use. */
17
17
readonly tunnel ?: string ;
18
18
}
@@ -32,7 +32,7 @@ export class API {
32
32
public metadata : SdkMetadata ;
33
33
34
34
/** The internally used Dsn object. */
35
- private readonly _dsnObject : Dsn ;
35
+ private readonly _dsnObject : DsnComponents ;
36
36
37
37
/** The envelope tunnel to use. */
38
38
private readonly _tunnel ?: string ;
@@ -46,7 +46,7 @@ export class API {
46
46
}
47
47
48
48
/** Returns the Dsn object. */
49
- public getDsn ( ) : Dsn {
49
+ public getDsn ( ) : DsnComponents {
50
50
return this . _dsnObject ;
51
51
}
52
52
@@ -95,19 +95,19 @@ export function initAPIDetails(dsn: DsnLike, metadata?: SdkMetadata, tunnel?: st
95
95
}
96
96
97
97
/** Returns the prefix to construct Sentry ingestion API endpoints. */
98
- function getBaseApiEndpoint ( dsn : Dsn ) : string {
98
+ function getBaseApiEndpoint ( dsn : DsnComponents ) : string {
99
99
const protocol = dsn . protocol ? `${ dsn . protocol } :` : '' ;
100
100
const port = dsn . port ? `:${ dsn . port } ` : '' ;
101
101
return `${ protocol } //${ dsn . host } ${ port } ${ dsn . path ? `/${ dsn . path } ` : '' } /api/` ;
102
102
}
103
103
104
104
/** 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 {
106
106
return `${ getBaseApiEndpoint ( dsn ) } ${ dsn . projectId } /${ target } /` ;
107
107
}
108
108
109
109
/** 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 {
111
111
return urlEncode ( {
112
112
// We send only the minimum set of required information. See
113
113
// https://github.com/getsentry/sentry-javascript/issues/2572.
@@ -117,7 +117,7 @@ function _encodedAuth(dsn: Dsn): string {
117
117
}
118
118
119
119
/** Returns the store endpoint URL. */
120
- function getStoreEndpoint ( dsn : Dsn ) : string {
120
+ function getStoreEndpoint ( dsn : DsnComponents ) : string {
121
121
return _getIngestEndpoint ( dsn , 'store' ) ;
122
122
}
123
123
@@ -126,12 +126,12 @@ function getStoreEndpoint(dsn: Dsn): string {
126
126
*
127
127
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
128
128
*/
129
- export function getStoreEndpointWithUrlEncodedAuth ( dsn : Dsn ) : string {
129
+ export function getStoreEndpointWithUrlEncodedAuth ( dsn : DsnComponents ) : string {
130
130
return `${ getStoreEndpoint ( dsn ) } ?${ _encodedAuth ( dsn ) } ` ;
131
131
}
132
132
133
133
/** Returns the envelope endpoint URL. */
134
- function _getEnvelopeEndpoint ( dsn : Dsn ) : string {
134
+ function _getEnvelopeEndpoint ( dsn : DsnComponents ) : string {
135
135
return _getIngestEndpoint ( dsn , 'envelope' ) ;
136
136
}
137
137
@@ -140,15 +140,19 @@ function _getEnvelopeEndpoint(dsn: Dsn): string {
140
140
*
141
141
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
142
142
*/
143
- export function getEnvelopeEndpointWithUrlEncodedAuth ( dsn : Dsn , tunnel ?: string ) : string {
143
+ export function getEnvelopeEndpointWithUrlEncodedAuth ( dsn : DsnComponents , tunnel ?: string ) : string {
144
144
return tunnel ? tunnel : `${ _getEnvelopeEndpoint ( dsn ) } ?${ _encodedAuth ( dsn ) } ` ;
145
145
}
146
146
147
147
/**
148
148
* Returns an object that can be used in request headers.
149
149
* This is needed for node and the old /store endpoint in sentry
150
150
*/
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 } {
152
156
// CHANGE THIS to use metadata but keep clientName and clientVersion compatible
153
157
const header = [ `Sentry sentry_version=${ SENTRY_API_VERSION } ` ] ;
154
158
header . push ( `sentry_client=${ clientName } /${ clientVersion } ` ) ;
0 commit comments