@@ -177,11 +177,6 @@ export interface ReactSDKClient extends Omit<optimizely.Client, 'createUserConte
177
177
export const DEFAULT_ON_READY_TIMEOUT = 5000 ;
178
178
179
179
class OptimizelyReactSDKClient implements ReactSDKClient {
180
- public initialConfig : optimizely . Config ;
181
- public user : UserInfo = {
182
- id : null ,
183
- attributes : { } ,
184
- } ;
185
180
private userContext : optimizely . OptimizelyUserContext | null = null ;
186
181
private userPromiseResolver : ( user : UserInfo ) => void ;
187
182
private userPromise : Promise < OnReadyResult > ;
@@ -207,6 +202,12 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
207
202
// promise keeping track of async requests for initializing client instance
208
203
private dataReadyPromise : Promise < OnReadyResult > ;
209
204
205
+ public initialConfig : optimizely . Config ;
206
+ public user : UserInfo = {
207
+ id : null ,
208
+ attributes : { } ,
209
+ } ;
210
+
210
211
/**
211
212
* Creates an instance of OptimizelyReactSDKClient.
212
213
* @param {optimizely.Config } [config={}]
@@ -258,15 +259,29 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
258
259
}
259
260
}
260
261
261
- getIsReadyPromiseFulfilled ( ) : boolean {
262
+ protected getUserContextWithOverrides (
263
+ overrideUserId ?: string ,
264
+ overrideAttributes ?: optimizely . UserAttributes
265
+ ) : UserInfo {
266
+ const finalUserId : string | null = overrideUserId === undefined ? this . user . id : overrideUserId ;
267
+ const finalUserAttributes : optimizely . UserAttributes | undefined =
268
+ overrideAttributes === undefined ? this . user . attributes : overrideAttributes ;
269
+
270
+ return {
271
+ id : finalUserId ,
272
+ attributes : finalUserAttributes ,
273
+ } ;
274
+ }
275
+
276
+ public getIsReadyPromiseFulfilled ( ) : boolean {
262
277
return this . isReadyPromiseFulfilled ;
263
278
}
264
279
265
- getIsUsingSdkKey ( ) : boolean {
280
+ public getIsUsingSdkKey ( ) : boolean {
266
281
return this . isUsingSdkKey ;
267
282
}
268
283
269
- onReady ( config : { timeout ?: number } = { } ) : Promise < OnReadyResult > {
284
+ public onReady ( config : { timeout ?: number } = { } ) : Promise < OnReadyResult > {
270
285
let timeoutId : number | undefined ;
271
286
let timeout : number = DEFAULT_ON_READY_TIMEOUT ;
272
287
if ( config && config . timeout !== undefined ) {
@@ -291,7 +306,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
291
306
} ) ;
292
307
}
293
308
294
- getUserContextInstance ( userInfo : UserInfo ) : optimizely . OptimizelyUserContext | null {
309
+ public getUserContextInstance ( userInfo : UserInfo ) : optimizely . OptimizelyUserContext | null {
295
310
if ( ! this . _client ) {
296
311
logger . warn (
297
312
'Unable to get user context for user id "%s" because Optimizely client failed to initialize.' ,
@@ -323,7 +338,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
323
338
return null ;
324
339
}
325
340
326
- async fetchQualifiedSegments ( ) : Promise < boolean > {
341
+ public async fetchQualifiedSegments ( ) : Promise < boolean > {
327
342
if ( ! this . userContext ) {
328
343
logger . warn ( 'Unable to fetch qualified segments for user because Optimizely client failed to initialize.' ) ;
329
344
return false ;
@@ -332,7 +347,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
332
347
return await this . userContext . fetchQualifiedSegments ( ) ;
333
348
}
334
349
335
- setUser ( userInfo : UserInfo ) : void {
350
+ public setUser ( userInfo : UserInfo ) : void {
336
351
// TODO add check for valid user
337
352
if ( userInfo . id ) {
338
353
this . user . id = userInfo . id ;
@@ -360,7 +375,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
360
375
this . onUserUpdateHandlers . forEach ( handler => handler ( this . user ) ) ;
361
376
}
362
377
363
- onUserUpdate ( handler : OnUserUpdateHandler ) : DisposeFn {
378
+ public onUserUpdate ( handler : OnUserUpdateHandler ) : DisposeFn {
364
379
this . onUserUpdateHandlers . push ( handler ) ;
365
380
366
381
return ( ) => {
@@ -377,7 +392,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
377
392
* @param {OnForcedVariationsUpdateHandler } handler
378
393
* @returns {DisposeFn }
379
394
*/
380
- onForcedVariationsUpdate ( handler : OnForcedVariationsUpdateHandler ) : DisposeFn {
395
+ public onForcedVariationsUpdate ( handler : OnForcedVariationsUpdateHandler ) : DisposeFn {
381
396
this . onForcedVariationsUpdateHandlers . push ( handler ) ;
382
397
383
398
return ( ) : void => {
@@ -388,7 +403,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
388
403
} ;
389
404
}
390
405
391
- isReady ( ) : boolean {
406
+ public isReady ( ) : boolean {
392
407
// React SDK Instance only becomes ready when both JS SDK client and the user info is ready.
393
408
return this . isUserReady && this . isClientReady ;
394
409
}
@@ -952,7 +967,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
952
967
* @returns {(unknown | null) }
953
968
* @memberof OptimizelyReactSDKClient
954
969
*/
955
- getFeatureVariable (
970
+ public getFeatureVariable (
956
971
featureKey : string ,
957
972
variableKey : string ,
958
973
overrideUserId : string ,
@@ -989,7 +1004,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
989
1004
* @returns {({ [variableKey: string]: unknown } | null) }
990
1005
* @memberof OptimizelyReactSDKClient
991
1006
*/
992
- getAllFeatureVariables (
1007
+ public getAllFeatureVariables (
993
1008
featureKey : string ,
994
1009
overrideUserId : string ,
995
1010
overrideAttributes ?: optimizely . UserAttributes
@@ -1174,33 +1189,23 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
1174
1189
return this . _client . notificationCenter ;
1175
1190
}
1176
1191
1177
- protected getUserContextWithOverrides (
1178
- overrideUserId ?: string ,
1179
- overrideAttributes ?: optimizely . UserAttributes
1180
- ) : UserInfo {
1181
- const finalUserId : string | null = overrideUserId === undefined ? this . user . id : overrideUserId ;
1182
- const finalUserAttributes : optimizely . UserAttributes | undefined =
1183
- overrideAttributes === undefined ? this . user . attributes : overrideAttributes ;
1184
-
1185
- return {
1186
- id : finalUserId ,
1187
- attributes : finalUserAttributes ,
1188
- } ;
1189
- }
1190
-
1191
- // TODO: discuss if we want to expose these method and provide implementation
1192
- getVuid ( ) : string | undefined {
1192
+ // TODO: this is tobe removed in future once the js-sdk gets updated
1193
+ public getVuid ( ) : string | undefined {
1193
1194
return undefined ;
1194
1195
}
1195
1196
1196
- // TODO: discuss if we want to expose these method and provide implementation
1197
- sendOdpEvent (
1197
+ public sendOdpEvent (
1198
1198
action : string ,
1199
- type : string | undefined ,
1200
- identifiers : Map < string , string > | undefined ,
1201
- data : Map < string , unknown > | undefined
1199
+ type ? : string ,
1200
+ identifiers ? : Map < string , string > ,
1201
+ data ? : Map < string , unknown >
1202
1202
) : void {
1203
- // no-op
1203
+ if ( ! action || ! action . trim ( ) ) {
1204
+ logger . error ( 'ODP action is not valid (cannot be empty).' ) ;
1205
+ return ;
1206
+ }
1207
+
1208
+ this . client ?. sendOdpEvent ( action , type , identifiers , data ) ;
1204
1209
}
1205
1210
}
1206
1211
0 commit comments