@@ -2,6 +2,7 @@ import got from 'got';
2
2
3
3
import ld , {
4
4
createMigration ,
5
+ DataSourceOptions ,
5
6
LDClient ,
6
7
LDConcurrentExecution ,
7
8
LDContext ,
@@ -33,6 +34,11 @@ interface SdkConfigOptions {
33
34
pollIntervalMs : number ;
34
35
filter ?: string ;
35
36
} ;
37
+ dataSystem ?: {
38
+ initializers ?: SDKDataSystemInitializerParams [ ] ;
39
+ synchronizers ?: SDKDataSystemSynchronizerParams ;
40
+ payloadFilter ?: string ;
41
+ } ;
36
42
events ?: {
37
43
allAttributesPrivate ?: boolean ;
38
44
baseUri : string ;
@@ -67,6 +73,31 @@ interface SdkConfigOptions {
67
73
} ;
68
74
}
69
75
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
+
70
101
interface CommandParams {
71
102
command : string ;
72
103
evaluate ?: {
@@ -128,8 +159,7 @@ export function makeSdkConfig(options: SdkConfigOptions, tag: string): LDOptions
128
159
cf . streamUri = options . streaming . baseUri ;
129
160
cf . streamInitialReconnectDelay = maybeTime ( options . streaming . initialRetryDelayMs ) ;
130
161
if ( options . streaming . filter ) {
131
- cf . application = cf . application || { } ;
132
- cf . application . payloadFilterKey = options . streaming . filter ;
162
+ cf . payloadFilterKey = options . streaming . filter ;
133
163
}
134
164
}
135
165
@@ -138,8 +168,7 @@ export function makeSdkConfig(options: SdkConfigOptions, tag: string): LDOptions
138
168
cf . baseUri = options . polling . baseUri ;
139
169
cf . pollInterval = options . polling . pollIntervalMs / 1000 ;
140
170
if ( options . polling . filter ) {
141
- cf . application = cf . application || { } ;
142
- cf . application . payloadFilterKey = options . polling . filter ;
171
+ cf . payloadFilterKey = options . polling . filter ;
143
172
}
144
173
}
145
174
@@ -192,6 +221,64 @@ export function makeSdkConfig(options: SdkConfigOptions, tag: string): LDOptions
192
221
}
193
222
}
194
223
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
+
195
282
return cf ;
196
283
}
197
284
0 commit comments