@@ -49,10 +49,10 @@ const default_user: UserInfo = {
49
49
attributes : { } ,
50
50
} ;
51
51
52
- export interface ReactSDKClient extends Omit < optimizely . Client , 'createUserContext' | 'getVuid' > {
52
+ export interface ReactSDKClient extends Omit < optimizely . Client , 'createUserContext' > {
53
53
user : UserInfo ;
54
54
55
- onReady ( opts ?: { timeout ?: number } ) : Promise < any > ;
55
+ onReady ( opts ?: { timeout ?: number ; } ) : Promise < any > ;
56
56
setUser ( userInfo : UserInfo ) : Promise < void > ;
57
57
onUserUpdate ( handler : OnUserUpdateHandler ) : DisposeFn ;
58
58
isReady ( ) : boolean ;
@@ -123,7 +123,7 @@ export interface ReactSDKClient extends Omit<optimizely.Client, 'createUserConte
123
123
featureKey : string ,
124
124
overrideUserId : string ,
125
125
overrideAttributes ?: optimizely . UserAttributes
126
- ) : { [ variableKey : string ] : unknown } | null ;
126
+ ) : { [ variableKey : string ] : unknown ; } | null ;
127
127
128
128
isFeatureEnabled (
129
129
featureKey : string ,
@@ -159,14 +159,14 @@ export interface ReactSDKClient extends Omit<optimizely.Client, 'createUserConte
159
159
options ?: optimizely . OptimizelyDecideOption [ ] ,
160
160
overrideUserId ?: string ,
161
161
overrideAttributes ?: optimizely . UserAttributes
162
- ) : { [ key : string ] : OptimizelyDecision } ;
162
+ ) : { [ key : string ] : OptimizelyDecision ; } ;
163
163
164
164
decideForKeys (
165
165
keys : string [ ] ,
166
166
options ?: optimizely . OptimizelyDecideOption [ ] ,
167
167
overrideUserId ?: string ,
168
168
overrideAttributes ?: optimizely . UserAttributes
169
- ) : { [ key : string ] : OptimizelyDecision } ;
169
+ ) : { [ key : string ] : OptimizelyDecision ; } ;
170
170
171
171
setForcedDecision (
172
172
decisionContext : optimizely . OptimizelyDecisionContext ,
@@ -180,9 +180,13 @@ export interface ReactSDKClient extends Omit<optimizely.Client, 'createUserConte
180
180
getForcedDecision ( decisionContext : optimizely . OptimizelyDecisionContext ) : optimizely . OptimizelyForcedDecision | null ;
181
181
182
182
fetchQualifiedSegments ( options ?: optimizely . OptimizelySegmentOption [ ] ) : Promise < boolean > ;
183
+
184
+ getUserContext ( ) : optimizely . OptimizelyUserContext | null ;
185
+
186
+ getVuid ( ) : string | undefined ;
183
187
}
184
188
185
- export const DEFAULT_ON_READY_TIMEOUT = 5000 ;
189
+ export const DEFAULT_ON_READY_TIMEOUT = 5_000 ;
186
190
187
191
class OptimizelyReactSDKClient implements ReactSDKClient {
188
192
private userContext : optimizely . OptimizelyUserContext | null = null ;
@@ -291,7 +295,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
291
295
return this . isUsingSdkKey ;
292
296
}
293
297
294
- public onReady ( config : { timeout ?: number } = { } ) : Promise < OnReadyResult > {
298
+ public onReady ( config : { timeout ?: number ; } = { } ) : Promise < OnReadyResult > {
295
299
let timeoutId : number | undefined ;
296
300
let timeout : number = DEFAULT_ON_READY_TIMEOUT ;
297
301
if ( config && config . timeout !== undefined ) {
@@ -326,6 +330,24 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
326
330
} ) ;
327
331
}
328
332
333
+ public getUserContext ( ) : optimizely . OptimizelyUserContext | null {
334
+ if ( ! this . _client ) {
335
+ logger . warn (
336
+ 'Unable to get user context because Optimizely client failed to initialize.'
337
+ ) ;
338
+ return null ;
339
+ }
340
+
341
+ if ( ! this . userContext ) {
342
+ logger . warn (
343
+ 'Unable to get user context because user was not set.'
344
+ ) ;
345
+ return null ;
346
+ }
347
+
348
+ return this . userContext ;
349
+ }
350
+
329
351
public getUserContextInstance ( userInfo : UserInfo ) : optimizely . OptimizelyUserContext | null {
330
352
if ( ! this . _client ) {
331
353
logger . warn (
@@ -501,7 +523,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
501
523
options : optimizely . OptimizelyDecideOption [ ] = [ ] ,
502
524
overrideUserId ?: string ,
503
525
overrideAttributes ?: optimizely . UserAttributes
504
- ) : { [ key : string ] : OptimizelyDecision } {
526
+ ) : { [ key : string ] : OptimizelyDecision ; } {
505
527
if ( ! this . _client ) {
506
528
logger . warn ( 'Unable to evaluate features for keys because Optimizely client failed to initialize.' ) ;
507
529
return { } ;
@@ -517,7 +539,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
517
539
const optlyUserContext = this . getUserContextInstance ( user ) ;
518
540
if ( optlyUserContext ) {
519
541
return Object . entries ( optlyUserContext . decideForKeys ( keys , options ) ) . reduce (
520
- ( decisions : { [ key : string ] : OptimizelyDecision } , [ key , decision ] ) => {
542
+ ( decisions : { [ key : string ] : OptimizelyDecision ; } , [ key , decision ] ) => {
521
543
decisions [ key ] = {
522
544
...decision ,
523
545
userContext : {
@@ -537,7 +559,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
537
559
options : optimizely . OptimizelyDecideOption [ ] = [ ] ,
538
560
overrideUserId ?: string ,
539
561
overrideAttributes ?: optimizely . UserAttributes
540
- ) : { [ key : string ] : OptimizelyDecision } {
562
+ ) : { [ key : string ] : OptimizelyDecision ; } {
541
563
if ( ! this . _client ) {
542
564
logger . warn ( 'Unable to evaluate all feature decisions because Optimizely client is not initialized.' ) ;
543
565
return { } ;
@@ -553,7 +575,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
553
575
const optlyUserContext = this . getUserContextInstance ( user ) ;
554
576
if ( optlyUserContext ) {
555
577
return Object . entries ( optlyUserContext . decideAll ( options ) ) . reduce (
556
- ( decisions : { [ key : string ] : OptimizelyDecision } , [ key , decision ] ) => {
578
+ ( decisions : { [ key : string ] : OptimizelyDecision ; } , [ key , decision ] ) => {
557
579
decisions [ key ] = {
558
580
...decision ,
559
581
userContext : {
@@ -1033,7 +1055,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
1033
1055
featureKey : string ,
1034
1056
overrideUserId : string ,
1035
1057
overrideAttributes ?: optimizely . UserAttributes
1036
- ) : { [ variableKey : string ] : unknown } | null {
1058
+ ) : { [ variableKey : string ] : unknown ; } | null {
1037
1059
if ( ! this . _client ) {
1038
1060
logger . warn (
1039
1061
'Unable to get all feature variables from feature "%s" because Optimizely client failed to initialize.' ,
@@ -1162,7 +1184,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
1162
1184
* Cleanup method for killing an running timers and flushing eventQueue
1163
1185
* @returns {Promise<{ success: boolean; reason?: string }> }
1164
1186
*/
1165
- public close ( ) : Promise < { success : boolean ; reason ?: string } > {
1187
+ public close ( ) : Promise < { success : boolean ; reason ?: string ; } > {
1166
1188
if ( ! this . _client ) {
1167
1189
/**
1168
1190
* Note:
@@ -1171,7 +1193,7 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
1171
1193
* - If we resolve as "false", then the cleanup for timers and the event queue will never trigger.
1172
1194
* - Not triggering cleanup may lead to memory leaks and other inefficiencies.
1173
1195
*/
1174
- return new Promise < { success : boolean ; reason : string } > ( ( resolve , reject ) =>
1196
+ return new Promise < { success : boolean ; reason : string ; } > ( ( resolve , reject ) =>
1175
1197
resolve ( {
1176
1198
success : true ,
1177
1199
reason : 'Optimizely client is not initialized.' ,
@@ -1227,6 +1249,14 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
1227
1249
1228
1250
this . client ?. sendOdpEvent ( action , type , identifiers , data ) ;
1229
1251
}
1252
+
1253
+ public getVuid ( ) : string | undefined {
1254
+ if ( ! this . _client ) {
1255
+ logger . warn ( 'Unable to get VUID because Optimizely client failed to initialize.' ) ;
1256
+ return undefined ;
1257
+ }
1258
+ return this . _client . getVuid ( ) ;
1259
+ }
1230
1260
}
1231
1261
1232
1262
export function createInstance ( config : optimizely . Config ) : ReactSDKClient {
0 commit comments