@@ -60,9 +60,8 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
60
60
}
61
61
62
62
/** Exported only for tests. */
63
- export function applyDefaultOptions ( optionsArg : BrowserOptions = { } ) : BrowserOptions {
63
+ export function applyDefaultOptions ( optionsArg : BrowserOptions ) : BrowserOptions {
64
64
const defaultOptions : BrowserOptions = {
65
- defaultIntegrations : getDefaultIntegrations ( optionsArg ) ,
66
65
release :
67
66
typeof __SENTRY_RELEASE__ === 'string' // This allows build tooling to find-and-replace __SENTRY_RELEASE__ to inject a release value
68
67
? __SENTRY_RELEASE__
@@ -72,27 +71,10 @@ export function applyDefaultOptions(optionsArg: BrowserOptions = {}): BrowserOpt
72
71
73
72
return {
74
73
...defaultOptions ,
75
- ...dropTopLevelUndefinedKeys ( optionsArg ) ,
74
+ ...optionsArg ,
76
75
} ;
77
76
}
78
77
79
- /**
80
- * In contrast to the regular `dropUndefinedKeys` method,
81
- * this one does not deep-drop keys, but only on the top level.
82
- */
83
- function dropTopLevelUndefinedKeys < T extends object > ( obj : T ) : Partial < T > {
84
- const mutatetedObj : Partial < T > = { } ;
85
-
86
- for ( const k of Object . getOwnPropertyNames ( obj ) ) {
87
- const key = k as keyof T ;
88
- if ( obj [ key ] !== undefined ) {
89
- mutatetedObj [ key ] = obj [ key ] ;
90
- }
91
- }
92
-
93
- return mutatetedObj ;
94
- }
95
-
96
78
/**
97
79
* The Sentry Browser SDK Client.
98
80
*
@@ -143,15 +125,34 @@ export function init(browserOptions: BrowserOptions = {}): Client | undefined {
143
125
if ( ! browserOptions . skipBrowserExtensionCheck && _checkForBrowserExtension ( ) ) {
144
126
return ;
145
127
}
128
+ return _init ( browserOptions , getDefaultIntegrations ( browserOptions ) ) ;
129
+ }
146
130
147
- const options = applyDefaultOptions ( browserOptions ) ;
148
- const clientOptions : BrowserClientOptions = {
149
- ...options ,
150
- stackParser : stackParserFromStackParserOptions ( options . stackParser || defaultStackParser ) ,
151
- integrations : getIntegrationsToSetup ( options ) ,
152
- transport : options . transport || makeFetchTransport ,
153
- } ;
131
+ /**
132
+ * Initialize a browser client with the provided options and default integrations getter function.
133
+ * This is an internal method the SDK uses under the hood to set up things - you should not use this as a user!
134
+ * Instead, use `init()` to initialize the SDK.
135
+ *
136
+ * @hidden
137
+ * @internal
138
+ */
139
+ export function initWithDefaultIntegrations (
140
+ browserOptions : BrowserOptions = { } ,
141
+ getDefaultIntegrationsImpl : ( options : BrowserOptions ) => Integration [ ] ,
142
+ ) : BrowserClient | undefined {
143
+ if ( ! browserOptions . skipBrowserExtensionCheck && _checkForBrowserExtension ( ) ) {
144
+ return ;
145
+ }
154
146
147
+ return _init ( browserOptions , getDefaultIntegrationsImpl ( browserOptions ) ) ;
148
+ }
149
+
150
+ /**
151
+ * Acutal implementation shared by init and initWithDefaultIntegrations.
152
+ */
153
+ function _init ( browserOptions : BrowserOptions = { } , defaultIntegrations : Integration [ ] ) : BrowserClient {
154
+ const options = applyDefaultOptions ( browserOptions ) ;
155
+ const clientOptions = getClientOptions ( options , defaultIntegrations ) ;
155
156
return initAndBind ( BrowserClient , clientOptions ) ;
156
157
}
157
158
@@ -215,3 +216,12 @@ function _checkForBrowserExtension(): true | void {
215
216
return true ;
216
217
}
217
218
}
219
+
220
+ function getClientOptions ( options : BrowserOptions , defaultIntegrations : Integration [ ] ) : BrowserClientOptions {
221
+ return {
222
+ ...options ,
223
+ stackParser : stackParserFromStackParserOptions ( options . stackParser || defaultStackParser ) ,
224
+ integrations : getIntegrationsToSetup ( options , defaultIntegrations ) ,
225
+ transport : options . transport || makeFetchTransport ,
226
+ } ;
227
+ }
0 commit comments