@@ -18,21 +18,30 @@ export class API {
18
18
/** The internally used Dsn object. */
19
19
private readonly _dsnObject : Dsn ;
20
20
21
+ /** The envelope tunnel to use. */
22
+ private readonly _tunnel ?: string ;
23
+
21
24
/** Create a new instance of API */
22
- public constructor ( dsn : DsnLike , metadata : SdkMetadata = { } ) {
25
+ public constructor ( dsn : DsnLike , metadata : SdkMetadata = { } , tunnel ?: string ) {
23
26
this . dsn = dsn ;
24
27
this . _dsnObject = new Dsn ( dsn ) ;
25
28
this . metadata = metadata ;
29
+ this . _tunnel = tunnel ;
26
30
}
27
31
28
32
/** Returns the Dsn object. */
29
33
public getDsn ( ) : Dsn {
30
34
return this . _dsnObject ;
31
35
}
32
36
37
+ /** Does this transport force envelopes? */
38
+ public forceEnvelope ( ) : boolean {
39
+ return ! ! this . _tunnel ;
40
+ }
41
+
33
42
/** Returns the prefix to construct Sentry ingestion API endpoints. */
34
43
public getBaseApiEndpoint ( ) : string {
35
- const dsn = this . _dsnObject ;
44
+ const dsn = this . getDsn ( ) ;
36
45
const protocol = dsn . protocol ? `${ dsn . protocol } :` : '' ;
37
46
const port = dsn . port ? `:${ dsn . port } ` : '' ;
38
47
return `${ protocol } //${ dsn . host } ${ port } ${ dsn . path ? `/${ dsn . path } ` : '' } /api/` ;
@@ -58,12 +67,16 @@ export class API {
58
67
* Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
59
68
*/
60
69
public getEnvelopeEndpointWithUrlEncodedAuth ( ) : string {
70
+ if ( this . forceEnvelope ( ) ) {
71
+ return this . _tunnel as string ;
72
+ }
73
+
61
74
return `${ this . _getEnvelopeEndpoint ( ) } ?${ this . _encodedAuth ( ) } ` ;
62
75
}
63
76
64
77
/** Returns only the path component for the store endpoint. */
65
78
public getStoreEndpointPath ( ) : string {
66
- const dsn = this . _dsnObject ;
79
+ const dsn = this . getDsn ( ) ;
67
80
return `${ dsn . path ? `/${ dsn . path } ` : '' } /api/${ dsn . projectId } /store/` ;
68
81
}
69
82
@@ -73,7 +86,7 @@ export class API {
73
86
*/
74
87
public getRequestHeaders ( clientName : string , clientVersion : string ) : { [ key : string ] : string } {
75
88
// CHANGE THIS to use metadata but keep clientName and clientVersion compatible
76
- const dsn = this . _dsnObject ;
89
+ const dsn = this . getDsn ( ) ;
77
90
const header = [ `Sentry sentry_version=${ SENTRY_API_VERSION } ` ] ;
78
91
header . push ( `sentry_client=${ clientName } /${ clientVersion } ` ) ;
79
92
header . push ( `sentry_key=${ dsn . publicKey } ` ) ;
@@ -94,7 +107,7 @@ export class API {
94
107
user ?: { name ?: string ; email ?: string } ;
95
108
} = { } ,
96
109
) : string {
97
- const dsn = this . _dsnObject ;
110
+ const dsn = this . getDsn ( ) ;
98
111
const endpoint = `${ this . getBaseApiEndpoint ( ) } embed/error-page/` ;
99
112
100
113
const encodedOptions = [ ] ;
@@ -132,14 +145,17 @@ export class API {
132
145
133
146
/** Returns the ingest API endpoint for target. */
134
147
private _getIngestEndpoint ( target : 'store' | 'envelope' ) : string {
148
+ if ( this . _tunnel ) {
149
+ return this . _tunnel ;
150
+ }
135
151
const base = this . getBaseApiEndpoint ( ) ;
136
- const dsn = this . _dsnObject ;
152
+ const dsn = this . getDsn ( ) ;
137
153
return `${ base } ${ dsn . projectId } /${ target } /` ;
138
154
}
139
155
140
156
/** Returns a URL-encoded string with auth config suitable for a query string. */
141
157
private _encodedAuth ( ) : string {
142
- const dsn = this . _dsnObject ;
158
+ const dsn = this . getDsn ( ) ;
143
159
const auth = {
144
160
// We send only the minimum set of required information. See
145
161
// https://github.com/getsentry/sentry-javascript/issues/2572.
0 commit comments