@@ -17,6 +17,7 @@ import {
17
17
ObfuscatedFlag ,
18
18
BoundedEventQueue ,
19
19
validation ,
20
+ Event ,
20
21
} from '@eppo/js-client-sdk-common' ;
21
22
22
23
import { assignmentCacheFactory } from './cache/assignment-cache-factory' ;
@@ -335,6 +336,7 @@ export async function init(config: IClientConfig): Promise<EppoClient> {
335
336
pollAfterSuccessfulInitialization = false ,
336
337
pollAfterFailedInitialization = false ,
337
338
skipInitialRequest = false ,
339
+ eventIngestionConfig,
338
340
} = config ;
339
341
try {
340
342
if ( EppoJSClient . initialized ) {
@@ -404,7 +406,7 @@ export async function init(config: IClientConfig): Promise<EppoClient> {
404
406
skipInitialPoll : skipInitialRequest ,
405
407
} ;
406
408
instance . setConfigurationRequestParameters ( requestConfiguration ) ;
407
- instance . setEventDispatcher ( newEventDispatcher ( apiKey ) ) ;
409
+ instance . setEventDispatcher ( newEventDispatcher ( apiKey , eventIngestionConfig ) ) ;
408
410
409
411
// We have two at-bats for initialization: from the configuration store and from fetching
410
412
// We can resolve the initialization promise as soon as either one succeeds
@@ -595,7 +597,7 @@ export async function precomputedInit(
595
597
throwOnFailedInitialization : true , // always use true here as underlying instance fetch is surrounded by try/catch
596
598
skipInitialPoll : skipInitialRequest ,
597
599
} ;
598
- instance . setPrecomputedFlagsRequestParameters ( precomputedFlagsRequestParameters ) ;
600
+ instance . setSubjectAndPrecomputedFlagsRequestParameters ( precomputedFlagsRequestParameters ) ;
599
601
600
602
await instance . fetchPrecomputedFlags ( ) ;
601
603
@@ -613,14 +615,30 @@ export function getPrecomputedInstance(): EppoPrecomputedClient {
613
615
return EppoPrecomputedJSClient . instance ;
614
616
}
615
617
616
- function newEventDispatcher ( sdkKey : string ) : EventDispatcher {
618
+ function newEventDispatcher (
619
+ sdkKey : string ,
620
+ config : IClientConfig [ 'eventIngestionConfig' ] = { } ,
621
+ ) : EventDispatcher {
617
622
const eventQueue = hasWindowLocalStorage ( )
618
- ? new LocalStorageBackedNamedEventQueue ( 'events' )
619
- : new BoundedEventQueue ( 'events' ) ;
623
+ ? new LocalStorageBackedNamedEventQueue < Event > ( 'events' )
624
+ : new BoundedEventQueue < Event > ( 'events' ) ;
620
625
const emptyNetworkStatusListener =
621
626
// eslint-disable-next-line @typescript-eslint/no-empty-function
622
627
{ isOffline : ( ) => false , onNetworkStatusChange : ( ) => { } } ;
623
628
const networkStatusListener =
624
629
typeof window !== 'undefined' ? new BrowserNetworkStatusListener ( ) : emptyNetworkStatusListener ;
625
- return newDefaultEventDispatcher ( eventQueue , networkStatusListener , sdkKey ) ;
630
+ // initialize config with default values
631
+ const {
632
+ batchSize = 100 ,
633
+ deliveryIntervalMs = 10_000 ,
634
+ retryIntervalMs = 5_000 ,
635
+ maxRetryDelayMs = 30_000 ,
636
+ maxRetries = 3 ,
637
+ } = config ;
638
+ return newDefaultEventDispatcher ( eventQueue , networkStatusListener , sdkKey , batchSize , {
639
+ deliveryIntervalMs,
640
+ retryIntervalMs,
641
+ maxRetryDelayMs,
642
+ maxRetries,
643
+ } ) ;
626
644
}
0 commit comments