1- import " whatwg-fetch" ;
2- import { TinyEmitter } from " tiny-emitter" ;
3- import { Base64 } from " js-base64" ;
4- import { FPUser } from " ./FPUser" ;
1+ import ' whatwg-fetch' ;
2+ import { TinyEmitter } from ' tiny-emitter' ;
3+ import { Base64 } from ' js-base64' ;
4+ import { FPUser } from ' ./FPUser' ;
55
66const EVENTS = {
7- READY : " ready" ,
8- ERROR : " error" ,
7+ READY : ' ready' ,
8+ ERROR : ' error' ,
99} ;
1010
1111interface IValue {
@@ -63,22 +63,22 @@ class FeatureProbe extends TinyEmitter {
6363 } : IOption ) {
6464 super ( ) ;
6565 if ( ! clientSdkKey ) {
66- throw new Error ( " clientSdkKey is required" ) ;
66+ throw new Error ( ' clientSdkKey is required' ) ;
6767 }
6868 if ( refreshInterval <= 0 ) {
69- throw new Error ( " refreshInterval is invalid" ) ;
69+ throw new Error ( ' refreshInterval is invalid' ) ;
7070 }
7171
7272 if ( ! remoteUrl && ! togglesUrl ) {
73- throw new Error ( " remoteUrl or togglesUrl is required" ) ;
73+ throw new Error ( ' remoteUrl or togglesUrl is required' ) ;
7474 }
7575
7676 if ( ! remoteUrl && ! eventsUrl ) {
77- throw new Error ( " remoteUrl or eventsUrl is required" ) ;
77+ throw new Error ( ' remoteUrl or eventsUrl is required' ) ;
7878 }
7979
8080 if ( ! remoteUrl && ! togglesUrl && ! eventsUrl ) {
81- throw new Error ( " remoteUrl is required" ) ;
81+ throw new Error ( ' remoteUrl is required' ) ;
8282 }
8383
8484 this . togglesUrl = new URL ( togglesUrl || ( remoteUrl + '/api/client-sdk/toggles' ) ) ;
@@ -101,35 +101,35 @@ class FeatureProbe extends TinyEmitter {
101101 }
102102
103103 public boolValue ( key : string , defaultValue : boolean ) : boolean {
104- return this . toggleValue ( key , defaultValue , " boolean" ) as boolean ;
104+ return this . toggleValue ( key , defaultValue , ' boolean' ) as boolean ;
105105 }
106106
107107 public numberValue ( key : string , defaultValue : number ) : number {
108- return this . toggleValue ( key , defaultValue , " number" ) as number ;
108+ return this . toggleValue ( key , defaultValue , ' number' ) as number ;
109109 }
110110
111111 public stringValue ( key : string , defaultValue : string ) : string {
112- return this . toggleValue ( key , defaultValue , " string" ) as string ;
112+ return this . toggleValue ( key , defaultValue , ' string' ) as string ;
113113 }
114114
115115 public jsonValue ( key : string , defaultValue : object ) : object {
116- return this . toggleValue ( key , defaultValue , " object" ) as object ;
116+ return this . toggleValue ( key , defaultValue , ' object' ) as object ;
117117 }
118118
119119 public boolDetail ( key : string , defaultValue : boolean ) : FPToggleDetail {
120- return this . toggleDetail ( key , defaultValue , " boolean" ) ;
120+ return this . toggleDetail ( key , defaultValue , ' boolean' ) ;
121121 }
122122
123123 public numberDetail ( key : string , defaultValue : number ) : FPToggleDetail {
124- return this . toggleDetail ( key , defaultValue , " number" ) ;
124+ return this . toggleDetail ( key , defaultValue , ' number' ) ;
125125 }
126126
127127 public stringDetail ( key : string , defaultValue : string ) : FPToggleDetail {
128- return this . toggleDetail ( key , defaultValue , " string" ) ;
128+ return this . toggleDetail ( key , defaultValue , ' string' ) ;
129129 }
130130
131131 public jsonDetail ( key : string , defaultValue : object ) : FPToggleDetail {
132- return this . toggleDetail ( key , defaultValue , " object" ) ;
132+ return this . toggleDetail ( key , defaultValue , ' object' ) ;
133133 }
134134
135135 public allToggles ( ) : { [ key : string ] : FPToggleDetail } | undefined {
@@ -172,7 +172,7 @@ class FeatureProbe extends TinyEmitter {
172172 value : defaultValue ,
173173 ruleIndex : null ,
174174 version : 0 ,
175- reason : " Not ready" ,
175+ reason : ' Not ready' ,
176176 } ;
177177 }
178178
@@ -182,7 +182,7 @@ class FeatureProbe extends TinyEmitter {
182182 value : defaultValue ,
183183 ruleIndex : null ,
184184 version : null ,
185- reason : " Toggle: [" + key + " ] not found" ,
185+ reason : ' Toggle: [' + key + ' ] not found' ,
186186 } ;
187187 } else if ( typeof detail . value === valueType ) {
188188 return detail ;
@@ -191,7 +191,7 @@ class FeatureProbe extends TinyEmitter {
191191 value : defaultValue ,
192192 ruleIndex : null ,
193193 version : null ,
194- reason : " Value type mismatch" ,
194+ reason : ' Value type mismatch' ,
195195 } ;
196196 }
197197 }
@@ -200,14 +200,14 @@ class FeatureProbe extends TinyEmitter {
200200 const userStr = JSON . stringify ( this . user ) ;
201201 const userParam = Base64 . encode ( userStr ) ;
202202 const url = this . togglesUrl ;
203- url . searchParams . set ( " user" , userParam ) ;
203+ url . searchParams . set ( ' user' , userParam ) ;
204204
205205 await fetch ( url . toString ( ) , {
206- method : " GET" ,
207- cache : " no-cache" ,
206+ method : ' GET' ,
207+ cache : ' no-cache' ,
208208 headers : {
209209 Authorization : this . clientSdkKey ,
210- " Content-Type" : " application/json" ,
210+ ' Content-Type' : ' application/json' ,
211211 } ,
212212 } )
213213 . then ( ( response ) => {
@@ -226,27 +226,27 @@ class FeatureProbe extends TinyEmitter {
226226 const timestamp = Date . now ( ) ;
227227 const payload : IParams [ ] = [
228228 {
229- " access" : {
230- " startTime" : timestamp ,
231- " endTime" : timestamp ,
232- " counters" : {
229+ ' access' : {
230+ ' startTime' : timestamp ,
231+ ' endTime' : timestamp ,
232+ ' counters' : {
233233 [ key ] : [ {
234- " count" : 1 ,
235- " value" : this . toggles [ key ] . value ,
236- " index" : this . toggles [ key ] . ruleIndex ,
237- " version" : this . toggles [ key ] . version ,
234+ ' count' : 1 ,
235+ ' value' : this . toggles [ key ] . value ,
236+ ' index' : this . toggles [ key ] . ruleIndex ,
237+ ' version' : this . toggles [ key ] . version ,
238238 } ]
239239 }
240240 }
241241 }
242242 ] ;
243243
244244 await fetch ( this . eventsUrl . toString ( ) , {
245- cache : " no-cache" ,
246- method : " POST" ,
245+ cache : ' no-cache' ,
246+ method : ' POST' ,
247247 headers : {
248248 Authorization : this . clientSdkKey ,
249- " Content-Type" : " application/json" ,
249+ ' Content-Type' : ' application/json' ,
250250 } ,
251251 body : JSON . stringify ( payload ) ,
252252 } ) ;
0 commit comments