@@ -8,14 +8,12 @@ import {
88} from '@launchdarkly/js-client-sdk' ;
99import {
1010 ClientEntity ,
11+ ConfigBuilder ,
1112 CreateInstanceParams ,
1213 IClientEntity ,
13- makeSdkConfig ,
14- parseClientOptions ,
1514 SDKConfigDataInitializer ,
1615 SDKConfigDataSynchronizer ,
1716 SDKConfigModeDefinition ,
18- SDKConfigParams ,
1917} from '@launchdarkly/js-contract-test-utils/client' ;
2018
2119function translateInitializer ( init : SDKConfigDataInitializer ) : InitializerEntry | undefined {
@@ -71,25 +69,28 @@ function translateModeDefinition(modeDef: SDKConfigModeDefinition): ModeDefiniti
7169 return { initializers, synchronizers } ;
7270}
7371
74- /**
75- * Browser-specific makeSdkConfig that wraps the shared base config with
76- * FDv2 data system translation and browser-specific options.
77- */
78- function makeBrowserSdkConfig ( options : SDKConfigParams , tag : string ) : LDOptions {
79- const isSet = ( x ?: unknown ) => x !== null && x !== undefined ;
80- const maybeTime = ( seconds ?: number ) => ( isSet ( seconds ) ? seconds ! / 1000 : undefined ) ;
72+ export async function newSdkClientEntity (
73+ _id : string ,
74+ options : CreateInstanceParams ,
75+ ) : Promise < IClientEntity > {
76+ const config = new ConfigBuilder ( options ) . set ( { fetchGoals : false } ) ;
8177
82- const cf = { ...makeSdkConfig ( options , tag ) , fetchGoals : false } as LDOptions ;
78+ if ( options . configuration . dataSystem ) {
79+ // FDv2: skip legacy streaming — data system handles connection modes
80+ config . skip ( 'streaming' ) ;
8381
84- if ( options . dataSystem ?. payloadFilter ) {
85- cf . payloadFilterKey = options . dataSystem . payloadFilter ;
86- }
82+ const isSet = ( x ?: unknown ) => x !== null && x !== undefined ;
83+ const maybeTime = ( seconds ?: number ) => ( isSet ( seconds ) ? seconds ! / 1000 : undefined ) ;
84+ const fdv2Overrides : Record < string , unknown > = { } ;
85+
86+ if ( options . configuration . dataSystem . payloadFilter ) {
87+ fdv2Overrides . payloadFilterKey = options . configuration . dataSystem . payloadFilter ;
88+ }
8789
88- if ( options . dataSystem ) {
8990 const dataSystem : any = { } ;
9091
91- if ( options . dataSystem . connectionModeConfig ) {
92- const connMode = options . dataSystem . connectionModeConfig ;
92+ if ( options . configuration . dataSystem . connectionModeConfig ) {
93+ const connMode = options . configuration . dataSystem . connectionModeConfig ;
9394 dataSystem . automaticModeSwitching = connMode . initialConnectionMode
9495 ? { type : 'manual' , initialConnectionMode : connMode . initialConnectionMode }
9596 : false ;
@@ -99,58 +100,49 @@ function makeBrowserSdkConfig(options: SDKConfigParams, tag: string): LDOptions
99100 Object . entries ( connMode . customConnectionModes ) . forEach ( ( [ modeName , modeDef ] ) => {
100101 connectionModes [ modeName ] = translateModeDefinition ( modeDef ) ;
101102
102- // Per-entry endpoint overrides also set global URIs for ServiceEndpoints
103- // compatibility. These override the serviceEndpoints values above.
104103 ( modeDef . synchronizers ?? [ ] ) . forEach ( ( sync ) => {
105104 if ( sync . streaming ?. baseUri ) {
106- cf . streamUri = sync . streaming . baseUri ;
107- cf . streamInitialReconnectDelay = maybeTime ( sync . streaming . initialRetryDelayMs ) ;
105+ fdv2Overrides . streamUri = sync . streaming . baseUri ;
106+ fdv2Overrides . streamInitialReconnectDelay = maybeTime (
107+ sync . streaming . initialRetryDelayMs ,
108+ ) ;
108109 }
109110 if ( sync . polling ?. baseUri ) {
110- cf . baseUri = sync . polling . baseUri ;
111+ fdv2Overrides . baseUri = sync . polling . baseUri ;
111112 }
112113 } ) ;
113114 ( modeDef . initializers ?? [ ] ) . forEach ( ( init ) => {
114115 if ( init . polling ?. baseUri ) {
115- cf . baseUri = init . polling . baseUri ;
116+ fdv2Overrides . baseUri = init . polling . baseUri ;
116117 }
117118 } ) ;
118119 } ) ;
119120 dataSystem . connectionModes = connectionModes ;
120121 }
121122 }
122123
123- ( cf as any ) . dataSystem = dataSystem ;
124+ fdv2Overrides . dataSystem = dataSystem ;
125+ config . set ( fdv2Overrides ) ;
124126 }
125127
126- return cf ;
127- }
128-
129- export async function newSdkClientEntity (
130- _id : string ,
131- options : CreateInstanceParams ,
132- ) : Promise < IClientEntity > {
133- const { timeout, initialContext, credential, initCanFail } = parseClientOptions ( options ) ;
134-
135- const sdkConfig = makeBrowserSdkConfig ( options . configuration , options . tag ) ;
136-
137- const client = createClient ( credential , initialContext as LDContext , sdkConfig ) ;
128+ const sdkConfig = config . build ( ) as LDOptions ;
129+ const client = createClient ( config . credential , config . initialContext as LDContext , sdkConfig ) ;
138130
139131 let failed = false ;
140132 try {
141133 await Promise . race ( [
142134 client . start ( ) ,
143135 new Promise ( ( _resolve , reject ) => {
144- setTimeout ( reject , timeout ) ;
136+ setTimeout ( reject , config . timeout ) ;
145137 } ) ,
146138 ] ) ;
147139 } catch ( _ ) {
148140 failed = true ;
149141 }
150- if ( failed && ! initCanFail ) {
142+ if ( failed && ! config . initCanFail ) {
151143 client . close ( ) ;
152144 throw new Error ( 'client initialization failed' ) ;
153145 }
154146
155- return new ClientEntity ( client , options . tag ) ;
147+ return new ClientEntity ( client , config . tag ) ;
156148}
0 commit comments