1
- import {
2
- BaseTransportOptions ,
3
- getEnvelopeEndpointWithUrlEncodedAuth ,
4
- initAPIDetails ,
5
- NewTransport ,
6
- NoopTransport ,
7
- } from '@sentry/core' ;
8
- import { Transport , TransportOptions } from '@sentry/types' ;
1
+ import { getEnvelopeEndpointWithUrlEncodedAuth , initAPIDetails } from '@sentry/core' ;
2
+ import { BaseTransportOptions , NewTransport , TransportOptions } from '@sentry/types' ;
9
3
import { supportsFetch } from '@sentry/utils' ;
10
4
11
5
import { BrowserOptions } from '../client' ;
12
- import { FetchTransport } from './fetch' ;
13
6
import { makeNewFetchTransport } from './new-fetch' ;
14
7
import { makeNewXHRTransport } from './new-xhr' ;
15
- import { XHRTransport } from './xhr' ;
16
8
17
9
export interface BrowserTransportOptions extends BaseTransportOptions {
18
10
// options to pass into fetch request
@@ -25,20 +17,11 @@ export interface BrowserTransportOptions extends BaseTransportOptions {
25
17
* Sets up Browser transports based on the passed `options`. If available, the returned
26
18
* transport will use the fetch API. In case fetch is not supported, an XMLHttpRequest
27
19
* based transport is created.
28
- *
29
- * @returns an object currently still containing both, the old `Transport` and
30
- * `NewTransport` which will eventually replace `Transport`. Once this is replaced,
31
- * this function will return a ready to use `NewTransport`.
32
20
*/
33
- // TODO(v7): Adjust return value when NewTransport is the default
34
- export function setupBrowserTransport ( options : BrowserOptions ) : { transport : Transport ; newTransport ?: NewTransport } {
35
- if ( ! options . dsn ) {
36
- // We return the noop transport here in case there is no Dsn.
37
- return { transport : new NoopTransport ( ) } ;
38
- }
39
-
21
+ export function setupBrowserTransport ( options : BrowserOptions ) : NewTransport {
40
22
const transportOptions : TransportOptions = {
41
23
...options . transportOptions ,
24
+ // @ts -ignore figure out dsn stuff
42
25
dsn : options . dsn ,
43
26
tunnel : options . tunnel ,
44
27
sendClientReports : options . sendClientReports ,
@@ -49,20 +32,16 @@ export function setupBrowserTransport(options: BrowserOptions): { transport: Tra
49
32
const url = getEnvelopeEndpointWithUrlEncodedAuth ( api . dsn , api . tunnel ) ;
50
33
51
34
if ( options . transport ) {
52
- return { transport : new options . transport ( transportOptions ) } ;
35
+ return options . transport ;
53
36
}
54
37
55
38
if ( supportsFetch ( ) ) {
56
39
const requestOptions : RequestInit = { ...transportOptions . fetchParameters } ;
57
- const newTransport = makeNewFetchTransport ( { requestOptions, url } ) ;
58
- const fetchTransport = new FetchTransport ( transportOptions ) ;
59
- return { transport : fetchTransport , newTransport } ;
40
+ return makeNewFetchTransport ( { requestOptions, url } ) ;
60
41
}
61
42
62
- const newTransport = makeNewXHRTransport ( {
43
+ return makeNewXHRTransport ( {
63
44
url,
64
45
headers : transportOptions . headers ,
65
46
} ) ;
66
- const transport = new XHRTransport ( transportOptions ) ;
67
- return { transport, newTransport } ;
68
47
}
0 commit comments