@@ -4,7 +4,6 @@ import { impressionsTrackerFactory } from '../trackers/impressionsTracker';
44import { eventTrackerFactory } from '../trackers/eventTracker' ;
55import { telemetryTrackerFactory } from '../trackers/telemetryTracker' ;
66import SplitIO from '../../types/splitio' ;
7- import { validateAndTrackApiKey } from '../utils/inputValidation/apiKey' ;
87import { createLoggerAPI } from '../logger/sdkLogger' ;
98import { NEW_FACTORY , RETRIEVE_MANAGER } from '../logger/constants' ;
109import { SDK_SPLITS_ARRIVED , SDK_SEGMENTS_ARRIVED , SDK_SPLITS_CACHE_LOADED } from '../readiness/constants' ;
@@ -33,9 +32,6 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IA
3332 // @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid SDK Key, etc.
3433 // On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
3534
36- // initialization
37- let hasInit = false ;
38-
3935 const sdkReadinessManager = sdkReadinessManagerFactory ( platform . EventEmitter , settings ) ;
4036 const readiness = sdkReadinessManager . readinessManager ;
4137
@@ -62,7 +58,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IA
6258 if ( ( storage as IStorageSync ) . splits . getChangeNumber ( ) > - 1 ) readiness . splits . emit ( SDK_SPLITS_CACHE_LOADED , { initialCacheLoad : false /* Not an initial load, cache exists */ } ) ;
6359 }
6460
65- const clients : Record < string , SplitIO . IBasicClient > = { } ;
61+ const clients : Record < string , SplitIO . IBasicClient & { init : ( ) => void } > = { } ;
6662 const telemetryTracker = telemetryTrackerFactory ( storage . telemetry , platform . now ) ;
6763 const integrationsManager = integrationsManagerFactory && integrationsManagerFactory ( { settings, storage, telemetryTracker } ) ;
6864
@@ -87,6 +83,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IA
8783 const syncManager = syncManagerFactory && syncManagerFactory ( ctx as ISdkFactoryContextSync ) ;
8884 ctx . syncManager = syncManager ;
8985
86+ // @TODO : move into platform, and call inside sdkClientFactory (if it's used only there)
9087 const signalListener = SignalListener && new SignalListener ( syncManager , settings , storage , splitApi ) ;
9188 ctx . signalListener = signalListener ;
9289
@@ -96,15 +93,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IA
9693
9794
9895 function init ( ) {
99- if ( hasInit ) return ;
100- hasInit = true ;
101-
102- // We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
103- validateAndTrackApiKey ( log , settings . core . authorizationKey ) ;
104- readiness . init ( ) ;
105- uniqueKeysTracker . start ( ) ;
106- syncManager && syncManager . start ( ) ;
107- signalListener && signalListener . start ( ) ;
96+ Object . keys ( clients ) . map ( key => clients [ key ] . init ( ) ) ;
10897 }
10998
11099 log . info ( NEW_FACTORY , [ settings . version ] ) ;
@@ -126,7 +115,6 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IA
126115 settings,
127116
128117 destroy ( ) {
129- hasInit = false ;
130118 return Promise . all ( Object . keys ( clients ) . map ( key => clients [ key ] . destroy ( ) ) ) . then ( ( ) => { } ) ;
131119 }
132120 } , extraProps && extraProps ( ctx ) , lazyInit ? { init } : init ( ) ) ;
0 commit comments