@@ -2,6 +2,7 @@ import got from 'got';
22
33import ld , {
44 createMigration ,
5+ DataSourceOptions ,
56 LDClient ,
67 LDConcurrentExecution ,
78 LDContext ,
@@ -33,6 +34,11 @@ interface SdkConfigOptions {
3334 pollIntervalMs : number ;
3435 filter ?: string ;
3536 } ;
37+ dataSystem ?: {
38+ initializers ?: SDKDataSystemInitializerParams [ ] ;
39+ synchronizers ?: SDKDataSystemSynchronizerParams ;
40+ payloadFilter ?: string ;
41+ } ;
3642 events ?: {
3743 allAttributesPrivate ?: boolean ;
3844 baseUri : string ;
@@ -67,6 +73,31 @@ interface SdkConfigOptions {
6773 } ;
6874}
6975
76+ export interface SDKDataSystemSynchronizerParams {
77+ primary ?: {
78+ streaming ?: SDKDataSourceStreamingParams ;
79+ polling ?: SDKDataSourcePollingParams ;
80+ } ;
81+ secondary ?: {
82+ streaming ?: SDKDataSourceStreamingParams ;
83+ polling ?: SDKDataSourcePollingParams ;
84+ } ;
85+ }
86+
87+ export interface SDKDataSystemInitializerParams {
88+ polling ?: SDKDataSourcePollingParams ;
89+ }
90+
91+ export interface SDKDataSourceStreamingParams {
92+ baseUri ?: string ;
93+ initialRetryDelayMs ?: number ;
94+ }
95+
96+ export interface SDKDataSourcePollingParams {
97+ baseUri ?: string ;
98+ pollIntervalMs ?: number ;
99+ }
100+
70101interface CommandParams {
71102 command : string ;
72103 evaluate ?: {
@@ -128,8 +159,7 @@ export function makeSdkConfig(options: SdkConfigOptions, tag: string): LDOptions
128159 cf . streamUri = options . streaming . baseUri ;
129160 cf . streamInitialReconnectDelay = maybeTime ( options . streaming . initialRetryDelayMs ) ;
130161 if ( options . streaming . filter ) {
131- cf . application = cf . application || { } ;
132- cf . application . payloadFilterKey = options . streaming . filter ;
162+ cf . payloadFilterKey = options . streaming . filter ;
133163 }
134164 }
135165
@@ -138,8 +168,7 @@ export function makeSdkConfig(options: SdkConfigOptions, tag: string): LDOptions
138168 cf . baseUri = options . polling . baseUri ;
139169 cf . pollInterval = options . polling . pollIntervalMs / 1000 ;
140170 if ( options . polling . filter ) {
141- cf . application = cf . application || { } ;
142- cf . application . payloadFilterKey = options . polling . filter ;
171+ cf . payloadFilterKey = options . polling . filter ;
143172 }
144173 }
145174
@@ -192,6 +221,64 @@ export function makeSdkConfig(options: SdkConfigOptions, tag: string): LDOptions
192221 }
193222 }
194223
224+ if ( options . dataSystem ) {
225+ const dataSourceStreamingOptions : SDKDataSourceStreamingParams | undefined =
226+ options . dataSystem . synchronizers ?. primary ?. streaming ??
227+ options . dataSystem . synchronizers ?. secondary ?. streaming ;
228+ const dataSourcePollingOptions : SDKDataSourcePollingParams | undefined =
229+ options . dataSystem . initializers ?. [ 0 ] ?. polling ??
230+ options . dataSystem . synchronizers ?. primary ?. polling ??
231+ options . dataSystem . synchronizers ?. secondary ?. polling ;
232+
233+ if ( dataSourceStreamingOptions ) {
234+ cf . streamUri = dataSourceStreamingOptions . baseUri ;
235+ cf . streamInitialReconnectDelay = maybeTime ( dataSourceStreamingOptions . initialRetryDelayMs ) ;
236+ }
237+ if ( dataSourcePollingOptions ) {
238+ cf . stream = false ;
239+ cf . baseUri = dataSourcePollingOptions . baseUri ;
240+ cf . pollInterval = maybeTime ( dataSourcePollingOptions . pollIntervalMs ) ;
241+ }
242+
243+ let dataSourceOptions : DataSourceOptions | undefined ;
244+ if ( dataSourceStreamingOptions && dataSourcePollingOptions ) {
245+ dataSourceOptions = {
246+ dataSourceOptionsType : 'standard' ,
247+ ...( dataSourceStreamingOptions . initialRetryDelayMs != null && {
248+ streamInitialReconnectDelay : maybeTime ( dataSourceStreamingOptions . initialRetryDelayMs ) ,
249+ } ) ,
250+ ...( dataSourcePollingOptions . pollIntervalMs != null && {
251+ pollInterval : dataSourcePollingOptions . pollIntervalMs ,
252+ } ) ,
253+ } ;
254+ } else if ( dataSourceStreamingOptions ) {
255+ dataSourceOptions = {
256+ dataSourceOptionsType : 'streamingOnly' ,
257+ ...( dataSourceStreamingOptions . initialRetryDelayMs != null && {
258+ streamInitialReconnectDelay : maybeTime ( dataSourceStreamingOptions . initialRetryDelayMs ) ,
259+ } ) ,
260+ } ;
261+ } else if ( dataSourcePollingOptions ) {
262+ dataSourceOptions = {
263+ dataSourceOptionsType : 'pollingOnly' ,
264+ ...( dataSourcePollingOptions . pollIntervalMs != null && {
265+ pollInterval : dataSourcePollingOptions . pollIntervalMs ,
266+ } ) ,
267+ } ;
268+ } else {
269+ // No data source options were specified
270+ dataSourceOptions = undefined ;
271+ }
272+
273+ if ( options . dataSystem . payloadFilter ) {
274+ cf . payloadFilterKey = options . dataSystem . payloadFilter ;
275+ }
276+
277+ cf . dataSystem = {
278+ dataSource : dataSourceOptions ,
279+ } ;
280+ }
281+
195282 return cf ;
196283}
197284
0 commit comments