@@ -60,9 +60,8 @@ export function getDefaultIntegrations(_options: Options): Integration[] {
6060}
6161
6262/** Exported only for tests. */
63- export function applyDefaultOptions ( optionsArg : BrowserOptions = { } ) : BrowserOptions {
63+ export function applyDefaultOptions ( optionsArg : BrowserOptions ) : BrowserOptions {
6464 const defaultOptions : BrowserOptions = {
65- defaultIntegrations : getDefaultIntegrations ( optionsArg ) ,
6665 release :
6766 typeof __SENTRY_RELEASE__ === 'string' // This allows build tooling to find-and-replace __SENTRY_RELEASE__ to inject a release value
6867 ? __SENTRY_RELEASE__
@@ -72,27 +71,10 @@ export function applyDefaultOptions(optionsArg: BrowserOptions = {}): BrowserOpt
7271
7372 return {
7473 ...defaultOptions ,
75- ...dropTopLevelUndefinedKeys ( optionsArg ) ,
74+ ...optionsArg ,
7675 } ;
7776}
7877
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-
9678/**
9779 * The Sentry Browser SDK Client.
9880 *
@@ -143,15 +125,34 @@ export function init(browserOptions: BrowserOptions = {}): Client | undefined {
143125 if ( ! browserOptions . skipBrowserExtensionCheck && _checkForBrowserExtension ( ) ) {
144126 return ;
145127 }
128+ return _init ( browserOptions , getDefaultIntegrations ( browserOptions ) ) ;
129+ }
146130
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+ }
154146
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 ) ;
155156 return initAndBind ( BrowserClient , clientOptions ) ;
156157}
157158
@@ -215,3 +216,12 @@ function _checkForBrowserExtension(): true | void {
215216 return true ;
216217 }
217218}
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