@@ -17,29 +17,59 @@ 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+ 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 } /` ;
2343 }
2444
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+ */
2650 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 {
2765 const dsn = this . _dsnObject ;
2866 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 ,
3070 sentry_version : SENTRY_API_VERSION ,
3171 } ;
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 ) ;
4373 }
4474
4575 /** Returns only the path component for the store endpoint. */
@@ -48,7 +78,11 @@ export class API {
4878 return `${ dsn . path ? `/${ dsn . path } ` : '' } /api/${ dsn . projectId } /store/` ;
4979 }
5080
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+ */
5286 public getRequestHeaders ( clientName : string , clientVersion : string ) : { [ key : string ] : string } {
5387 const dsn = this . _dsnObject ;
5488 const header = [ `Sentry sentry_version=${ SENTRY_API_VERSION } ` ] ;
@@ -71,7 +105,7 @@ export class API {
71105 } = { } ,
72106 ) : string {
73107 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/` ;
75109
76110 const encodedOptions = [ ] ;
77111 encodedOptions . push ( `dsn=${ dsn . toString ( ) } ` ) ;
0 commit comments