@@ -17,29 +17,59 @@ export class API {
17
17
return this . _dsnObject ;
18
18
}
19
19
20
- /** Returns a string with auth headers in the url to the store endpoint. */
20
+ /** Returns the prefix to construct Sentry ingestion API endpoints. */
21
+ public getBaseApiEndpoint ( ) : string {
22
+ const dsn = this . _dsnObject ;
23
+ const protocol = dsn . protocol ? `${ dsn . protocol } :` : '' ;
24
+ const port = dsn . port ? `:${ dsn . port } ` : '' ;
25
+ return `${ protocol } //${ dsn . host } ${ port } ${ dsn . path ? `/${ dsn . path } ` : '' } /api/` ;
26
+ }
27
+
28
+ /** Returns the store endpoint URL. */
21
29
public getStoreEndpoint ( ) : string {
22
- return `${ this . _getBaseUrl ( ) } ${ this . getStoreEndpointPath ( ) } ` ;
30
+ return this . _getIngestEndpoint ( 'store' ) ;
31
+ }
32
+
33
+ /** Returns the envelope endpoint URL. */
34
+ private _getEnvelopeEndpoint ( ) : string {
35
+ return this . _getIngestEndpoint ( 'envelope' ) ;
36
+ }
37
+
38
+ /** Returns the ingest API endpoint for target. */
39
+ private _getIngestEndpoint ( target : 'store' | 'envelope' ) : string {
40
+ const base = this . getBaseApiEndpoint ( ) ;
41
+ const dsn = this . _dsnObject ;
42
+ return `${ base } ${ dsn . projectId } /${ target } /` ;
23
43
}
24
44
25
- /** Returns the store endpoint with auth added in url encoded. */
45
+ /**
46
+ * Returns the store endpoint URL with auth in the query string.
47
+ *
48
+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
49
+ */
26
50
public getStoreEndpointWithUrlEncodedAuth ( ) : string {
51
+ return `${ this . getStoreEndpoint ( ) } ?${ this . _encodedAuth ( ) } ` ;
52
+ }
53
+
54
+ /**
55
+ * Returns the envelope endpoint URL with auth in the query string.
56
+ *
57
+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
58
+ */
59
+ public getEnvelopeEndpointWithUrlEncodedAuth ( ) : string {
60
+ return `${ this . _getEnvelopeEndpoint ( ) } ?${ this . _encodedAuth ( ) } ` ;
61
+ }
62
+
63
+ /** Returns a URL-encoded string with auth config suitable for a query string. */
64
+ private _encodedAuth ( ) : string {
27
65
const dsn = this . _dsnObject ;
28
66
const auth = {
29
- sentry_key : dsn . user , // sentry_key is currently used in tracing integration to identify internal sentry requests
67
+ // We send only the minimum set of required information. See
68
+ // https://github.com/getsentry/sentry-javascript/issues/2572.
69
+ sentry_key : dsn . user ,
30
70
sentry_version : SENTRY_API_VERSION ,
31
71
} ;
32
- // Auth is intentionally sent as part of query string (NOT as custom HTTP header)
33
- // to avoid preflight CORS requests
34
- return `${ this . getStoreEndpoint ( ) } ?${ urlEncode ( auth ) } ` ;
35
- }
36
-
37
- /** Returns the base path of the url including the port. */
38
- private _getBaseUrl ( ) : string {
39
- const dsn = this . _dsnObject ;
40
- const protocol = dsn . protocol ? `${ dsn . protocol } :` : '' ;
41
- const port = dsn . port ? `:${ dsn . port } ` : '' ;
42
- return `${ protocol } //${ dsn . host } ${ port } ` ;
72
+ return urlEncode ( auth ) ;
43
73
}
44
74
45
75
/** Returns only the path component for the store endpoint. */
@@ -48,7 +78,11 @@ export class API {
48
78
return `${ dsn . path ? `/${ dsn . path } ` : '' } /api/${ dsn . projectId } /store/` ;
49
79
}
50
80
51
- /** Returns an object that can be used in request headers. */
81
+ /**
82
+ * Returns an object that can be used in request headers.
83
+ *
84
+ * @deprecated in favor of `getStoreEndpointWithUrlEncodedAuth` and `getEnvelopeEndpointWithUrlEncodedAuth`.
85
+ */
52
86
public getRequestHeaders ( clientName : string , clientVersion : string ) : { [ key : string ] : string } {
53
87
const dsn = this . _dsnObject ;
54
88
const header = [ `Sentry sentry_version=${ SENTRY_API_VERSION } ` ] ;
@@ -71,7 +105,7 @@ export class API {
71
105
} = { } ,
72
106
) : string {
73
107
const dsn = this . _dsnObject ;
74
- const endpoint = `${ this . _getBaseUrl ( ) } ${ dsn . path ? `/ ${ dsn . path } ` : '' } /api/ embed/error-page/` ;
108
+ const endpoint = `${ this . getBaseApiEndpoint ( ) } embed/error-page/` ;
75
109
76
110
const encodedOptions = [ ] ;
77
111
encodedOptions . push ( `dsn=${ dsn . toString ( ) } ` ) ;
0 commit comments