@@ -165,6 +165,11 @@ export interface Config {
165165 * Whether to enable tracking.
166166 */
167167 enableTracking : boolean ;
168+
169+ /**
170+ * Whether to enable offline mode.
171+ */
172+ offline : boolean ;
168173}
169174
170175/**
@@ -228,6 +233,11 @@ export type InitOptions = {
228233 */
229234 appBaseUrl ?: string ;
230235
236+ /**
237+ * Whether to enable offline mode. Defaults to `false`.
238+ */
239+ offline ?: boolean ;
240+
231241 /**
232242 * Feature keys for which `isEnabled` should fallback to true
233243 * if SDK fails to fetch features from Bucket servers. If a record
@@ -294,6 +304,7 @@ const defaultConfig: Config = {
294304 appBaseUrl : APP_BASE_URL ,
295305 sseBaseUrl : SSE_REALTIME_BASE_URL ,
296306 enableTracking : true ,
307+ offline : false ,
297308} ;
298309
299310/**
@@ -396,6 +407,7 @@ export class BucketClient {
396407 appBaseUrl : opts ?. appBaseUrl ?? defaultConfig . appBaseUrl ,
397408 sseBaseUrl : opts ?. sseBaseUrl ?? defaultConfig . sseBaseUrl ,
398409 enableTracking : opts ?. enableTracking ?? defaultConfig . enableTracking ,
410+ offline : opts ?. offline ?? defaultConfig . offline ,
399411 } ;
400412
401413 this . requestFeedbackOptions = {
@@ -423,10 +435,12 @@ export class BucketClient {
423435 staleTimeMs : opts . staleTimeMs ,
424436 fallbackFeatures : opts . fallbackFeatures ,
425437 timeoutMs : opts . timeoutMs ,
438+ offline : this . config . offline ,
426439 } ,
427440 ) ;
428441
429442 if (
443+ ! this . config . offline &&
430444 this . context ?. user &&
431445 ! isNode && // do not prompt on server-side
432446 opts ?. feedback ?. enableAutoFeedback !== false // default to on
@@ -470,6 +484,7 @@ export class BucketClient {
470484 * Must be called before calling other SDK methods.
471485 */
472486 async initialize ( ) {
487+ const start = Date . now ( ) ;
473488 if ( this . autoFeedback ) {
474489 // do not block on automated feedback surveys initialization
475490 this . autoFeedbackInit = this . autoFeedback . initialize ( ) . catch ( ( e ) => {
@@ -489,6 +504,13 @@ export class BucketClient {
489504 this . logger . error ( "error sending company" , e ) ;
490505 } ) ;
491506 }
507+
508+ this . logger . info (
509+ "Bucket initialized in " +
510+ Math . round ( Date . now ( ) - start ) +
511+ "ms" +
512+ ( this . config . offline ? " (offline mode)" : "" ) ,
513+ ) ;
492514 }
493515
494516 /**
@@ -607,6 +629,10 @@ export class BucketClient {
607629 return ;
608630 }
609631
632+ if ( this . config . offline ) {
633+ return ;
634+ }
635+
610636 const payload : TrackedEvent = {
611637 userId : String ( this . context . user . id ) ,
612638 event : eventName ,
@@ -634,9 +660,14 @@ export class BucketClient {
634660 * @returns The server response.
635661 */
636662 async feedback ( payload : Feedback ) {
663+ if ( this . config . offline ) {
664+ return ;
665+ }
666+
637667 const userId =
638668 payload . userId ||
639669 ( this . context . user ?. id ? String ( this . context . user ?. id ) : undefined ) ;
670+
640671 const companyId =
641672 payload . companyId ||
642673 ( this . context . company ?. id ? String ( this . context . company ?. id ) : undefined ) ;
@@ -833,6 +864,10 @@ export class BucketClient {
833864 return ;
834865 }
835866
867+ if ( this . config . offline ) {
868+ return ;
869+ }
870+
836871 const { id, ...attributes } = this . context . user ;
837872 const payload : User = {
838873 userId : String ( id ) ,
@@ -863,6 +898,10 @@ export class BucketClient {
863898 return ;
864899 }
865900
901+ if ( this . config . offline ) {
902+ return ;
903+ }
904+
866905 const { id, ...attributes } = this . context . company ;
867906 const payload : Company = {
868907 userId : String ( this . context . user . id ) ,
0 commit comments