@@ -26,6 +26,7 @@ import { ReflagContext, ReflagDeprecatedContext } from "./context";
2626import { HookArgs , HooksManager , State } from "./hooksManager" ;
2727import { HttpClient } from "./httpClient" ;
2828import { Logger , loggerWithPrefix , quietConsoleLogger } from "./logger" ;
29+ import { StorageAdapter } from "./storage" ;
2930import { showToolbarToggle } from "./toolbar" ;
3031
3132const isMobile = typeof window !== "undefined" && window . innerWidth < 768 ;
@@ -297,6 +298,12 @@ export type InitOptions = ReflagDeprecatedContext & {
297298 * Pre-fetched flags to be used instead of fetching them from the server.
298299 */
299300 bootstrappedFlags ?: RawFlags ;
301+
302+ /**
303+ * Optional storage adapter used for caching flags and overrides.
304+ * Useful for React Native (AsyncStorage).
305+ */
306+ storage ?: StorageAdapter ;
300307} ;
301308
302309const defaultConfig : Config = {
@@ -366,7 +373,9 @@ export interface Flag {
366373
367374function shouldShowToolbar ( opts : InitOptions ) {
368375 const toolbarOpts = opts . toolbar ;
369- if ( typeof window === "undefined" ) return false ;
376+ if ( typeof window === "undefined" || typeof window . location === "undefined" ) {
377+ return false ;
378+ }
370379 if ( typeof toolbarOpts === "boolean" ) return toolbarOpts ;
371380 if ( typeof toolbarOpts ?. show === "boolean" ) return toolbarOpts . show ;
372381 return window . location . hostname === "localhost" ;
@@ -391,6 +400,8 @@ export class ReflagClient {
391400
392401 private readonly hooks : HooksManager ;
393402
403+ private toolbarToggleShown = false ;
404+
394405 /**
395406 * Create a new ReflagClient instance.
396407 */
@@ -439,6 +450,7 @@ export class ReflagClient {
439450 timeoutMs : opts . timeoutMs ,
440451 fallbackFlags : opts . fallbackFlags ,
441452 offline : this . config . offline ,
453+ storage : opts . storage ,
442454 } ,
443455 ) ;
444456
@@ -466,12 +478,9 @@ export class ReflagClient {
466478 }
467479
468480 if ( shouldShowToolbar ( opts ) ) {
469- this . logger . info ( "opening toolbar toggler" ) ;
470- showToolbarToggle ( {
471- reflagClient : this ,
472- position :
473- typeof opts . toolbar === "object" ? opts . toolbar . position : undefined ,
474- } ) ;
481+ const position =
482+ typeof opts . toolbar === "object" ? opts . toolbar . position : undefined ;
483+ this . showToolbarToggle ( position ) ;
475484 }
476485
477486 // Register hooks
@@ -870,6 +879,13 @@ export class ReflagClient {
870879 return this . flagsClient . getFlags ( ) ;
871880 }
872881
882+ /**
883+ * Force refresh flags from the API, bypassing cache.
884+ */
885+ refresh ( ) {
886+ return this . flagsClient . refreshFlags ( ) ;
887+ }
888+
873889 /**
874890 * @deprecated Use `getFlag` instead.
875891 */
@@ -947,6 +963,19 @@ export class ReflagClient {
947963 } ;
948964 }
949965
966+ showToolbarToggle ( position ?: ToolbarPosition ) {
967+ if ( this . toolbarToggleShown ) {
968+ return ;
969+ }
970+ this . toolbarToggleShown = true ;
971+ this . logger . info ( "opening toolbar toggler" ) ;
972+
973+ showToolbarToggle ( {
974+ reflagClient : this ,
975+ position,
976+ } ) ;
977+ }
978+
950979 private setState ( state : State ) {
951980 this . state = state ;
952981 this . hooks . trigger ( "stateUpdated" , state ) ;
0 commit comments