@@ -23,6 +23,9 @@ const STATUS = {
2323 ERROR : "error" ,
2424} ;
2525
26+ const REFRESH_INTERVAL = 1000 ;
27+ const TIMEOUT_INTERVAL = 10000 ;
28+
2629/**
2730 * You can obtainan a client of FeatureProbe,
2831 * which provides access to all of the SDK's functionality.
@@ -54,8 +57,8 @@ class FeatureProbe extends TinyEmitter {
5457 realtimePath,
5558 clientSdkKey,
5659 user,
57- refreshInterval = 1000 ,
58- timeoutInterval = 10000 ,
60+ refreshInterval = REFRESH_INTERVAL ,
61+ timeoutInterval = TIMEOUT_INTERVAL ,
5962 enableAutoReporting = true ,
6063 } : FPConfig ) {
6164 super ( ) ;
@@ -98,6 +101,29 @@ class FeatureProbe extends TinyEmitter {
98101 }
99102 }
100103
104+ public static newForTest ( toggles : { [ key : string ] : boolean } ) : FeatureProbe {
105+ const fp = new FeatureProbe ( {
106+ remoteUrl : "http://127.0.0.1:4000" ,
107+ clientSdkKey : "_" ,
108+ user : new FPUser ( ) ,
109+ timeoutInterval : 1000 ,
110+ } ) ;
111+ const _toggles : { [ key : string ] : FPDetail } = { } ;
112+ for ( const key in toggles ) {
113+ const value = toggles [ key ] ;
114+ _toggles [ key ] = {
115+ value : value ,
116+ ruleIndex : null ,
117+ variationIndex : null ,
118+ version : 0 ,
119+ reason : "" ,
120+ } ;
121+ }
122+ fp . toggles = _toggles ;
123+ fp . successInitialized ( ) ;
124+ return fp ;
125+ }
126+
101127 /**
102128 * Start the FeatureProbe client.
103129 */
@@ -339,29 +365,6 @@ class FeatureProbe extends TinyEmitter {
339365 } ) ;
340366 }
341367
342- static newForTest ( toggles : { [ key : string ] : boolean } ) : FeatureProbe {
343- const fp = new FeatureProbe ( {
344- remoteUrl : "http://127.0.0.1:4000" ,
345- clientSdkKey : "_" ,
346- user : new FPUser ( ) ,
347- timeoutInterval : 1000 ,
348- } ) ;
349- const _toggles : { [ key : string ] : FPDetail } = { } ;
350- for ( const key in toggles ) {
351- const value = toggles [ key ] ;
352- _toggles [ key ] = {
353- value : value ,
354- ruleIndex : null ,
355- variationIndex : null ,
356- version : 0 ,
357- reason : "" ,
358- } ;
359- }
360- fp . toggles = _toggles ;
361- fp . successInitialized ( ) ;
362- return fp ;
363- }
364-
365368 private connectSocket ( ) {
366369 const socket = io ( this . realtimeUrl , {
367370 path : this . realtimePath ,
@@ -395,13 +398,16 @@ class FeatureProbe extends TinyEmitter {
395398 if ( typeof v == valueType ) {
396399 const timestamp = Date . now ( ) ;
397400
401+ const DEFAULT_VARIATION_INDEX = - 1 ;
402+ const DEFAULT_VERSION = 0 ;
403+
398404 this . eventRecorder ?. recordAccessEvent ( {
399405 time : timestamp ,
400406 key : key ,
401407 value : detail . value ,
402- index : detail . variationIndex ?? - 1 ,
403- version : detail . version ?? 0 ,
404- reason : detail . reason
408+ index : detail . variationIndex ?? DEFAULT_VARIATION_INDEX ,
409+ version : detail . version ?? DEFAULT_VERSION ,
410+ reason : detail . reason ,
405411 } ) ;
406412
407413 if ( detail . trackAccessEvents ) {
@@ -411,9 +417,9 @@ class FeatureProbe extends TinyEmitter {
411417 user : this . getUser ( ) . getKey ( ) ,
412418 key : key ,
413419 value : detail . value ,
414- variationIndex : detail . variationIndex ?? - 1 ,
420+ variationIndex : detail . variationIndex ?? DEFAULT_VARIATION_INDEX ,
415421 ruleIndex : detail . ruleIndex ?? null ,
416- version : detail . version ?? 0 ,
422+ version : detail . version ?? DEFAULT_VERSION ,
417423 } ) ;
418424 }
419425
@@ -494,7 +500,7 @@ class FeatureProbe extends TinyEmitter {
494500 "Content-Type" : "application/json" ,
495501 UA : getPlatform ( ) ?. UA ,
496502 } , {
497- user : userParam
503+ user : userParam ,
498504 } , ( json : unknown ) => {
499505 if ( this . status !== STATUS . ERROR ) {
500506 this . toggles = json as { [ key : string ] : FPDetail ; } | undefined ;
0 commit comments