@@ -17,29 +17,54 @@ export class API {
1717 return this . _dsnObject ;
1818 }
1919
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. */
2129 public getStoreEndpoint ( ) : string {
22- return `${ this . _getBaseUrl ( ) } ${ this . getStoreEndpointPath ( ) } ` ;
30+ return this . _getIngestEndpoint ( 'store' ) ;
31+ }
32+
33+ /** Returns the envelope endpoint URL. */
34+ public getEnvelopeEndpoint ( ) : string {
35+ return this . _getIngestEndpoint ( 'envelope' ) ;
36+ }
37+
38+ private _getIngestEndpoint ( target : string ) : string {
39+ const base = this . getBaseApiEndpoint ( ) ;
40+ const dsn = this . _dsnObject ;
41+ return `${ base } ${ dsn . projectId } /${ target } /` ;
2342 }
2443
25- /** Returns the store endpoint with auth added in url encoded. */
44+ /** Returns the store endpoint URL with auth in the query string.
45+ *
46+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
47+ */
2648 public getStoreEndpointWithUrlEncodedAuth ( ) : string {
49+ return `${ this . getStoreEndpoint ( ) } ?${ this . _encodedAuth ( ) } ` ;
50+ }
51+
52+ /** Returns the envelope endpoint URL with auth in the query string.
53+ *
54+ * Sending auth as part of the query string and not as custom HTTP headers avoids CORS preflight requests.
55+ */
56+ public getEnvelopeEndpointWithUrlEncodedAuth ( ) : string {
57+ return `${ this . getEnvelopeEndpoint ( ) } ?${ this . _encodedAuth ( ) } ` ;
58+ }
59+
60+ private _encodedAuth ( ) : string {
2761 const dsn = this . _dsnObject ;
2862 const auth = {
29- sentry_key : dsn . user , // sentry_key is currently used in tracing integration to identify internal sentry requests
63+ sentry_key : dsn . user ,
3064 sentry_version : SENTRY_API_VERSION ,
65+ // REVIEW: don't we send sentry_client (with SDK info) when using this?! Compare with `getRequestHeaders`.
3166 } ;
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 } ` ;
67+ return urlEncode ( auth ) ;
4368 }
4469
4570 /** Returns only the path component for the store endpoint. */
@@ -48,7 +73,10 @@ export class API {
4873 return `${ dsn . path ? `/${ dsn . path } ` : '' } /api/${ dsn . projectId } /store/` ;
4974 }
5075
51- /** Returns an object that can be used in request headers. */
76+ /** Returns an object that can be used in request headers.
77+ *
78+ * @deprecated in favor of `getStoreEndpointWithUrlEncodedAuth` and `getEnvelopeEndpointWithUrlEncodedAuth`.
79+ */
5280 public getRequestHeaders ( clientName : string , clientVersion : string ) : { [ key : string ] : string } {
5381 const dsn = this . _dsnObject ;
5482 const header = [ `Sentry sentry_version=${ SENTRY_API_VERSION } ` ] ;
@@ -71,7 +99,7 @@ export class API {
7199 } = { } ,
72100 ) : string {
73101 const dsn = this . _dsnObject ;
74- const endpoint = `${ this . _getBaseUrl ( ) } ${ dsn . path ? `/ ${ dsn . path } ` : '' } /api/ embed/error-page/` ;
102+ const endpoint = `${ this . getBaseApiEndpoint ( ) } embed/error-page/` ;
75103
76104 const encodedOptions = [ ] ;
77105 encodedOptions . push ( `dsn=${ dsn . toString ( ) } ` ) ;
0 commit comments