-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathsplitio.d.ts
1656 lines (1652 loc) · 68.1 KB
/
splitio.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for JavaScript and NodeJS Split Software SDK
// Project: http://www.split.io/
// Definitions by: Nico Zelaya <https://github.com/NicoZelaya/>
import { RedisOptions } from "ioredis";
import { RequestOptions } from "http";
export as namespace SplitIO;
export = SplitIO;
/**
* NodeJS.EventEmitter interface
* @see {@link https://nodejs.org/api/events.html}
*/
interface EventEmitter {
addListener(event: string | symbol, listener: (...args: any[]) => void): this;
on(event: string | symbol, listener: (...args: any[]) => void): this;
once(event: string | symbol, listener: (...args: any[]) => void): this;
removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
off(event: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(event: string | symbol): Function[];
rawListeners(event: string | symbol): Function[];
emit(event: string | symbol, ...args: any[]): boolean;
listenerCount(type: string | symbol): number;
// Added in Node 6...
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
eventNames(): Array<string | symbol>;
}
/**
* @typedef {Object} EventConsts
* @property {string} SDK_READY The ready event.
* @property {string} SDK_READY_FROM_CACHE The ready event when fired with cached data.
* @property {string} SDK_READY_TIMED_OUT The timeout event.
* @property {string} SDK_UPDATE The update event.
*/
type EventConsts = {
SDK_READY: 'init::ready',
SDK_READY_FROM_CACHE: 'init::cache-ready',
SDK_READY_TIMED_OUT: 'init::timeout',
SDK_UPDATE: 'state::update'
};
/**
* SDK Modes.
* @typedef {string} SDKMode
*/
type SDKMode = 'standalone' | 'consumer';
/**
* Storage types.
* @typedef {string} StorageType
*/
type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS';
/**
* Settings interface. This is a representation of the settings the SDK expose, that's why
* most of it's props are readonly. Only features should be rewritten when localhost mode is active.
* @interface ISettings
*/
interface ISettings {
readonly core: {
authorizationKey: string,
key: SplitIO.SplitKey,
labelsEnabled: boolean,
IPAddressesEnabled: boolean
},
readonly mode: SDKMode,
readonly scheduler: {
featuresRefreshRate: number,
impressionsRefreshRate: number,
impressionsQueueSize: number,
/**
* @deprecated
*/
metricsRefreshRate?: number,
telemetryRefreshRate: number,
segmentsRefreshRate: number,
offlineRefreshRate: number,
eventsPushRate: number,
eventsQueueSize: number,
pushRetryBackoffBase: number
},
readonly startup: {
readyTimeout: number,
requestTimeoutBeforeReady: number,
retriesOnFailureBeforeReady: number,
eventsFirstPushWindow: number
},
readonly storage: {
prefix: string,
options: Object,
type: StorageType
},
readonly urls: {
events: string,
sdk: string,
auth: string,
streaming: string,
telemetry: string
},
readonly debug: boolean | LogLevel,
readonly version: string,
/**
* Mocked features map if using in browser, or mocked features file path string if using in NodeJS.
*/
features: SplitIO.MockedFeaturesMap | SplitIO.MockedFeaturesFilePath,
readonly streamingEnabled: boolean,
readonly sync: {
splitFilters: SplitIO.SplitFilter[],
impressionsMode: SplitIO.ImpressionsMode,
enabled: boolean,
flagSpecVersion: string,
requestOptions?: {
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
}
}
/**
* User consent status if using in browser. Undefined if using in NodeJS.
*/
readonly userConsent?: SplitIO.ConsentStatus
}
/**
* Log levels.
* @typedef {string} LogLevel
*/
type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
/**
* Logger API
* @interface ILoggerAPI
*/
interface ILoggerAPI {
/**
* Enables SDK logging to the console.
* @function enable
* @returns {void}
*/
enable(): void,
/**
* Disables SDK logging.
* @function disable
* @returns {void}
*/
disable(): void,
/**
* Sets a log level for the SDK logs.
* @function setLogLevel
* @returns {void}
*/
setLogLevel(logLevel: LogLevel): void,
/**
* Log level constants. Use this to pass them to setLogLevel function.
*/
LogLevel: {
[level in LogLevel]: LogLevel
}
}
/**
* User consent API
* @interface IUserConsentAPI
*/
interface IUserConsentAPI {
/**
* Sets or updates the user consent status. Possible values are `true` and `false`, which represent user consent `'GRANTED'` and `'DECLINED'` respectively.
* - `true ('GRANTED')`: the user has granted consent for tracking events and impressions. The SDK will send them to Split cloud.
* - `false ('DECLINED')`: the user has declined consent for tracking events and impressions. The SDK will not send them to Split cloud.
*
* NOTE: calling this method updates the user consent at a factory level, affecting all clients of the same factory.
*
* @function setStatus
* @param {boolean} userConsent The user consent status, true for 'GRANTED' and false for 'DECLINED'.
* @returns {boolean} Whether the provided param is a valid value (i.e., a boolean value) or not.
*/
setStatus(userConsent: boolean): boolean;
/**
* Gets the user consent status.
*
* @function getStatus
* @returns {ConsentStatus} The user consent status.
*/
getStatus(): SplitIO.ConsentStatus;
/**
* Consent status constants. Use this to compare with the getStatus function result.
*/
Status: {
[status in SplitIO.ConsentStatus]: SplitIO.ConsentStatus
}
}
/**
* Common settings between Browser and NodeJS settings interface.
* @interface ISharedSettings
*/
interface ISharedSettings {
/**
* Boolean value to indicate whether the logger should be enabled or disabled, or a log level string.
*
* Examples:
* ```javascript
* config.debug = true
* config.debug = 'WARN'
* ```
* @property {boolean | LogLevel} debug
* @default false
*/
debug?: boolean | LogLevel,
/**
* The impression listener, which is optional. Whatever you provide here needs to comply with the SplitIO.IImpressionListener interface,
* which will check for the logImpression method.
* @property {IImpressionListener} impressionListener
* @default undefined
*/
impressionListener?: SplitIO.IImpressionListener,
/**
* Boolean flag to enable the streaming service as default synchronization mechanism. In the event of any issue with streaming,
* the SDK would fallback to the polling mechanism. If false, the SDK would poll for changes as usual without attempting to use streaming.
* @property {boolean} streamingEnabled
* @default true
*/
streamingEnabled?: boolean,
/**
* SDK synchronization settings.
* @property {Object} sync
*/
sync?: {
/**
* List of feature flag filters. These filters are used to fetch a subset of the feature flag definitions in your environment, in order to reduce the delay of the SDK to be ready.
* This configuration is only meaningful when the SDK is working in "standalone" mode.
*
* Example:
* `splitFilter: [
* { type: 'byName', values: ['my_feature_flag_1', 'my_feature_flag_2'] }, // will fetch feature flags named 'my_feature_flag_1' and 'my_feature_flag_2'
* ]`
* @property {SplitIO.SplitFilter[]} splitFilters
*/
splitFilters?: SplitIO.SplitFilter[]
/**
* Impressions Collection Mode. Option to determine how impressions are going to be sent to Split servers.
* Possible values are 'DEBUG', 'OPTIMIZED', and 'NONE'.
* - DEBUG: will send all the impressions generated (recommended only for debugging purposes).
* - OPTIMIZED: will send unique impressions to Split servers, avoiding a considerable amount of traffic that duplicated impressions could generate.
* - NONE: will send unique keys evaluated per feature to Split servers instead of full blown impressions, avoiding a considerable amount of traffic that impressions could generate.
*
* @property {string} impressionsMode
* @default 'OPTIMIZED'
*/
impressionsMode?: SplitIO.ImpressionsMode,
/**
* Controls the SDK continuous synchronization flags.
*
* When `true` a running SDK will process rollout plan updates performed on the UI (default).
* When false it'll just fetch all data upon init
*
* @property {boolean} enabled
* @default true
*/
enabled?: boolean
}
}
/**
* Common settings interface for SDK instances on NodeJS.
* @interface INodeBasicSettings
* @extends ISharedSettings
*/
interface INodeBasicSettings extends ISharedSettings {
/**
* SDK Startup settings for NodeJS.
* @property {Object} startup
*/
startup?: {
/**
* Maximum amount of time used before notify a timeout.
* @property {number} readyTimeout
* @default 15
*/
readyTimeout?: number,
/**
* Time to wait for a request before the SDK is ready. If this time expires, JS Sdk will retry 'retriesOnFailureBeforeReady' times before notifying its failure to be 'ready'.
* @property {number} requestTimeoutBeforeReady
* @default 15
*/
requestTimeoutBeforeReady?: number,
/**
* How many quick retries we will do while starting up the SDK.
* @property {number} retriesOnFailureBeforeReady
* @default 1
*/
retriesOnFailureBeforeReady?: number,
/**
* For SDK posts the queued events data in bulks with a given rate, but the first push window is defined separately,
* to better control on browsers. This number defines that window before the first events push.
*
* @property {number} eventsFirstPushWindow
* @default 0
*/
eventsFirstPushWindow?: number,
},
/**
* SDK scheduler settings.
* @property {Object} scheduler
*/
scheduler?: {
/**
* The SDK polls Split servers for changes to feature flag definitions. This parameter controls this polling period in seconds.
* @property {number} featuresRefreshRate
* @default 60
*/
featuresRefreshRate?: number,
/**
* The SDK sends information on who got what treatment at what time back to Split servers to power analytics. This parameter controls how often this data is sent to Split servers. The parameter should be in seconds.
* @property {number} impressionsRefreshRate
* @default 300
*/
impressionsRefreshRate?: number,
/**
* The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
* If you use a 0 here, the queue will have no maximum size.
* @property {number} impressionsQueueSize
* @default 30000
*/
impressionsQueueSize?: number,
/**
* The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
* @property {number} metricsRefreshRate
* @default 120
* @deprecated This parameter is ignored now. Use `telemetryRefreshRate` instead.
*/
metricsRefreshRate?: number,
/**
* The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
* @property {number} telemetryRefreshRate
* @default 3600
*/
telemetryRefreshRate?: number,
/**
* The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
* @property {number} segmentsRefreshRate
* @default 60
*/
segmentsRefreshRate?: number,
/**
* The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
* @property {number} eventsPushRate
* @default 60
*/
eventsPushRate?: number,
/**
* The maximum number of event items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
* If you use a 0 here, the queue will have no maximum size.
* @property {number} eventsQueueSize
* @default 500
*/
eventsQueueSize?: number,
/**
* For mocking/testing only. The SDK will refresh the features mocked data when mode is set to "localhost" by defining the key.
* For more information see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#localhost-mode}
* @property {number} offlineRefreshRate
* @default 15
*/
offlineRefreshRate?: number
/**
* When using streaming mode, seconds to wait before re attempting to connect for push notifications.
* Next attempts follow intervals in power of two: base seconds, base x 2 seconds, base x 4 seconds, ...
* @property {number} pushRetryBackoffBase
* @default 1
*/
pushRetryBackoffBase?: number,
},
/**
* SDK Core settings for NodeJS.
* @property {Object} core
*/
core: {
/**
* Your SDK key.
* @see {@link https://help.split.io/hc/en-us/articles/360019916211-API-keys}
* @property {string} authorizationKey
*/
authorizationKey: string,
/**
* Disable labels from being sent to Split backend. Labels may contain sensitive information.
* @property {boolean} labelsEnabled
* @default true
*/
labelsEnabled?: boolean
/**
* Disable machine IP and Name from being sent to Split backend.
* @property {boolean} IPAddressesEnabled
* @default true
*/
IPAddressesEnabled?: boolean
},
/**
* Defines which kind of storage we should instantiate.
* @property {Object} storage
*/
storage?: {
/**
* Storage type to be instantiated by the SDK.
* @property {StorageType} type
* @default 'MEMORY'
*/
type?: StorageType,
/**
* Options to be passed to the selected storage.
* @property {Object} options
*/
options?: Object,
/**
* Optional prefix to prevent any kind of data collision between SDK versions.
* @property {string} prefix
* @default 'SPLITIO'
*/
prefix?: string
},
/**
* The SDK mode. Possible values are "standalone", which is the default when using a synchronous storage, like 'MEMORY' and 'LOCALSTORAGE',
* and "consumer", which must be set when using an asynchronous storage, like 'REDIS'. For "localhost" mode, use "localhost" as authorizationKey.
* @property {SDKMode} mode
* @default 'standalone'
*/
mode?: SDKMode,
/**
* Mocked features file path. For testing purposes only. For using this you should specify "localhost" as authorizationKey on core settings.
* @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#localhost-mode}
* @property {MockedFeaturesFilePath} features
* @default '$HOME/.split'
*/
features?: SplitIO.MockedFeaturesFilePath,
}
/**
* Common API for entities that expose status handlers.
* @interface IStatusInterface
* @extends EventEmitter
*/
interface IStatusInterface extends EventEmitter {
/**
* Constant object containing the SDK events for you to use.
* @property {EventConsts} Event
*/
Event: EventConsts,
/**
* Returns a promise that resolves once the SDK has finished loading (`SDK_READY` event emitted) or rejected if the SDK has timedout (`SDK_READY_TIMED_OUT` event emitted).
* As it's meant to provide similar flexibility to the event approach, given that the SDK might be eventually ready after a timeout event, the `ready` method will return a resolved promise once the SDK is ready.
* You must handle the promise rejection to avoid an unhandled promise rejection error, or you can set the `startup.readyTimeout` configuration option to 0 to avoid the timeout and thus the rejection.
*
* @function ready
* @returns {Promise<void>}
*/
ready(): Promise<void>
}
/**
* Common definitions between clients for different environments interface.
* @interface IBasicClient
* @extends IStatusInterface
*/
interface IBasicClient extends IStatusInterface {
/**
* Destroys the client instance.
* In 'standalone' mode, this method will flush any pending impressions and events, and stop the synchronization of feature flag definitions with the backend.
* In 'consumer' mode, this method will disconnect the SDK from the Redis or Pluggable storage.
*
* @function destroy
* @returns {Promise<void>} A promise that resolves once the client is destroyed.
*/
destroy(): Promise<void>
}
/**
* Common definitions between SDK instances for different environments interface.
* @interface IBasicSDK
*/
interface IBasicSDK {
/**
* Current settings of the SDK instance.
* @property settings
*/
settings: ISettings,
/**
* Logger API.
* @property Logger
*/
Logger: ILoggerAPI
/**
* Destroys all the clients created by this factory.
* @function destroy
* @returns {Promise<void>}
*/
destroy(): Promise<void>
}
/****** Exposed namespace ******/
/**
* Types and interfaces for `@splitsoftware/splitio` package for usage when integrating JavaScript SDK with TypeScript.
* For the SDK package information see {@link https://www.npmjs.com/package/@splitsoftware/splitio}
*/
declare namespace SplitIO {
/**
* Feature flag treatment value, returned by getTreatment.
* @typedef {string} Treatment
*/
type Treatment = string;
/**
* Feature flag treatment promise that resolves to actual treatment value.
* @typedef {Promise<string>} AsyncTreatment
*/
type AsyncTreatment = Promise<string>;
/**
* An object with the treatments for a bulk of feature flags, returned by getTreatments. For example:
* {
* feature1: 'on',
* feature2: 'off
* }
* @typedef {Object.<Treatment>} Treatments
*/
type Treatments = {
[featureName: string]: Treatment
};
/**
* Feature flag treatments promise that resolves to the actual SplitIO.Treatments object.
* @typedef {Promise<Treatments>} AsyncTreatments
*/
type AsyncTreatments = Promise<Treatments>;
/**
* Feature flag evaluation result with treatment and configuration, returned by getTreatmentWithConfig.
* @typedef {Object} TreatmentWithConfig
* @property {string} treatment The treatment string
* @property {string | null} config The stringified version of the JSON config defined for that treatment, null if there is no config for the resulting treatment.
*/
type TreatmentWithConfig = {
treatment: string,
config: string | null
};
/**
* Feature flag treatment promise that resolves to actual treatment with config value.
* @typedef {Promise<TreatmentWithConfig>} AsyncTreatmentWithConfig
*/
type AsyncTreatmentWithConfig = Promise<TreatmentWithConfig>;
/**
* An object with the treatments with configs for a bulk of feature flags, returned by getTreatmentsWithConfig.
* Each existing configuration is a stringified version of the JSON you defined on the Split user interface. For example:
* {
* feature1: { treatment: 'on', config: null }
* feature2: { treatment: 'off', config: '{"bannerText":"Click here."}' }
* }
* @typedef {Object.<TreatmentWithConfig>} Treatments
*/
type TreatmentsWithConfig = {
[featureName: string]: TreatmentWithConfig
};
/**
* Feature flag treatments promise that resolves to the actual SplitIO.TreatmentsWithConfig object.
* @typedef {Promise<TreatmentsWithConfig>} AsyncTreatmentsWithConfig
*/
type AsyncTreatmentsWithConfig = Promise<TreatmentsWithConfig>;
/**
* Possible Split SDK events.
* @typedef {string} Event
*/
type Event = 'init::timeout' | 'init::ready' | 'init::cache-ready' | 'state::update';
/**
* Attributes should be on object with values of type string, boolean, number (dates should be sent as millis since epoch) or array of strings or numbers.
* @typedef {Object.<AttributeType>} Attributes
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#attribute-syntax}
*/
type Attributes = {
[attributeName: string]: AttributeType
};
/**
* Type of an attribute value
* @typedef {string | number | boolean | Array<string | number>} AttributeType
*/
type AttributeType = string | number | boolean | Array<string | number>;
/**
* Properties should be an object with values of type string, number, boolean or null. Size limit of ~31kb.
* @typedef {Object.<number, string, boolean, null>} Properties
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#track
*/
type Properties = {
[propertyName: string]: string | number | boolean | null
};
/**
* The SplitKey object format.
* @typedef {Object.<string>} SplitKeyObject
*/
type SplitKeyObject = {
matchingKey: string,
bucketingKey: string
};
/**
* The customer identifier. Could be a SplitKeyObject or a string.
* @typedef {SplitKeyObject|string} SplitKey
*/
type SplitKey = SplitKeyObject | string;
/**
* Path to file with mocked features (for node).
* @typedef {string} MockedFeaturesFilePath
*/
type MockedFeaturesFilePath = string;
/**
* Object with mocked features mapping (for browser). We need to specify the featureName as key, and the mocked treatment as value.
* @typedef {Object} MockedFeaturesMap
*/
type MockedFeaturesMap = {
[featureName: string]: string | TreatmentWithConfig
};
/**
* Object with information about an impression. It contains the generated impression DTO as well as
* complementary information around where and how it was generated in that way.
* @typedef {Object} ImpressionData
*/
type ImpressionData = {
impression: {
feature: string,
keyName: string,
treatment: string,
time: number,
bucketingKey?: string,
label: string,
changeNumber: number,
pt?: number,
},
attributes?: SplitIO.Attributes,
ip: string,
hostname: string,
sdkLanguageVersion: string
};
/**
* Data corresponding to one feature flag view.
* @typedef {Object} SplitView
*/
type SplitView = {
/**
* The name of the feature flag.
* @property {string} name
*/
name: string,
/**
* The traffic type of the feature flag.
* @property {string} trafficType
*/
trafficType: string,
/**
* Whether the feature flag is killed or not.
* @property {boolean} killed
*/
killed: boolean,
/**
* The list of treatments available for the feature flag.
* @property {Array<string>} treatments
*/
treatments: Array<string>,
/**
* Current change number of the feature flag.
* @property {number} changeNumber
*/
changeNumber: number,
/**
* Map of configurations per treatment.
* Each existing configuration is a stringified version of the JSON you defined on the Split user interface.
* @property {Object.<string>} configs
*/
configs: {
[treatmentName: string]: string
},
/**
* List of sets of the feature flag.
* @property {string[]} sets
*/
sets: string[],
/**
* The default treatment of the feature flag.
* @property {string} defaultTreatment
*/
defaultTreatment: string,
};
/**
* A promise that resolves to a feature flag view.
* @typedef {Promise<SplitView>} SplitView
*/
type SplitViewAsync = Promise<SplitView>;
/**
* An array containing the SplitIO.SplitView elements.
*/
type SplitViews = Array<SplitView>;
/**
* A promise that resolves to an SplitIO.SplitViews array.
* @typedef {Promise<SplitViews>} SplitViewsAsync
*/
type SplitViewsAsync = Promise<SplitViews>;
/**
* An array of feature flag names.
* @typedef {Array<string>} SplitNames
*/
type SplitNames = Array<string>;
/**
* A promise that resolves to an array of feature flag names.
* @typedef {Promise<SplitNames>} SplitNamesAsync
*/
type SplitNamesAsync = Promise<SplitNames>;
/**
* Synchronous storage valid types for NodeJS.
* @typedef {string} NodeSyncStorage
*/
type NodeSyncStorage = 'MEMORY';
/**
* Asynchronous storages valid types for NodeJS.
* @typedef {string} NodeAsyncStorage
*/
type NodeAsyncStorage = 'REDIS';
/**
* Storage valid types for the browser.
* @typedef {string} BrowserStorage
*/
type BrowserStorage = 'MEMORY' | 'LOCALSTORAGE';
/**
* Impression listener interface. This is the interface that needs to be implemented
* by the element you provide to the SDK as impression listener.
* @interface IImpressionListener
* @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#listener}
*/
interface IImpressionListener {
logImpression(data: SplitIO.ImpressionData): void
}
/**
* Available URL settings for the SDKs.
*/
type UrlSettings = {
/**
* String property to override the base URL where the SDK will get rollout plan related data, like feature flags and segments definitions.
* @property {string} sdk
* @default 'https://sdk.split.io/api'
*/
sdk?: string,
/**
* String property to override the base URL where the SDK will post event-related information like impressions.
* @property {string} events
* @default 'https://events.split.io/api'
*/
events?: string,
/**
* String property to override the base URL where the SDK will get authorization tokens to be used with functionality that requires it, like streaming.
* @property {string} auth
* @default 'https://auth.split.io/api'
*/
auth?: string,
/**
* String property to override the base URL where the SDK will connect to receive streaming updates.
* @property {string} streaming
* @default 'https://streaming.split.io'
*/
streaming?: string,
/**
* String property to override the base URL where the SDK will post telemetry data.
* @property {string} telemetry
* @default 'https://telemetry.split.io/api'
*/
telemetry?: string
};
/**
* SplitFilter type.
*
* @typedef {string} SplitFilterType
*/
type SplitFilterType = 'bySet' | 'byName' | 'byPrefix';
/**
* Defines a feature flag filter, described by a type and list of values.
*/
interface SplitFilter {
/**
* Type of the filter.
*
* @property {SplitFilterType} type
*/
type: SplitFilterType,
/**
* List of values: feature flag names for 'byName' filter type, and feature flag name prefixes for 'byPrefix' type.
*
* @property {string[]} values
*/
values: string[],
}
/**
* ImpressionsMode type
* @typedef {string} ImpressionsMode
*/
type ImpressionsMode = 'OPTIMIZED' | 'DEBUG' | 'NONE';
/**
* User consent status.
* @typedef {string} ConsentStatus
*/
type ConsentStatus = 'GRANTED' | 'DECLINED' | 'UNKNOWN';
/**
* Settings interface for SDK instances created on the browser
* @interface IBrowserSettings
* @extends ISharedSettings
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#configuration}
*/
interface IBrowserSettings extends ISharedSettings {
/**
* SDK Startup settings for the Browser.
* @property {Object} startup
*/
startup?: {
/**
* Maximum amount of time used before notify a timeout.
* @property {number} readyTimeout
* @default 1.5
*/
readyTimeout?: number,
/**
* Time to wait for a request before the SDK is ready. If this time expires, JS Sdk will retry 'retriesOnFailureBeforeReady' times before notifying its failure to be 'ready'.
* @property {number} requestTimeoutBeforeReady
* @default 1.5
*/
requestTimeoutBeforeReady?: number,
/**
* How many quick retries we will do while starting up the SDK.
* @property {number} retriesOnFailureBeforeReady
* @default 1
*/
retriesOnFailureBeforeReady?: number,
/**
* For SDK posts the queued events data in bulks with a given rate, but the first push window is defined separately,
* to better control on browsers. This number defines that window before the first events push.
*
* @property {number} eventsFirstPushWindow
* @default 10
*/
eventsFirstPushWindow?: number,
},
/**
* SDK scheduler settings.
* @property {Object} scheduler
*/
scheduler?: {
/**
* The SDK polls Split servers for changes to feature flag definitions. This parameter controls this polling period in seconds.
* @property {number} featuresRefreshRate
* @default 60
*/
featuresRefreshRate?: number,
/**
* The SDK sends information on who got what treatment at what time back to Split servers to power analytics. This parameter controls how often this data is sent to Split servers. The parameter should be in seconds.
* @property {number} impressionsRefreshRate
* @default 60
*/
impressionsRefreshRate?: number,
/**
* The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
* If you use a 0 here, the queue will have no maximum size.
* @property {number} impressionsQueueSize
* @default 30000
*/
impressionsQueueSize?: number,
/**
* The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
* @property {number} metricsRefreshRate
* @default 120
* @deprecated This parameter is ignored now. Use `telemetryRefreshRate` instead.
*/
metricsRefreshRate?: number,
/**
* The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
* @property {number} telemetryRefreshRate
* @default 3600
*/
telemetryRefreshRate?: number,
/**
* The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
* @property {number} segmentsRefreshRate
* @default 60
*/
segmentsRefreshRate?: number,
/**
* The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
* @property {number} eventsPushRate
* @default 60
*/
eventsPushRate?: number,
/**
* The maximum number of event items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
* If you use a 0 here, the queue will have no maximum size.
* @property {number} eventsQueueSize
* @default 500
*/
eventsQueueSize?: number,
/**
* For mocking/testing only. The SDK will refresh the features mocked data when mode is set to "localhost" by defining the key.
* For more information see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#localhost-mode}
* @property {number} offlineRefreshRate
* @default 15
*/
offlineRefreshRate?: number,
/**
* When using streaming mode, seconds to wait before re attempting to connect for push notifications.
* Next attempts follow intervals in power of two: base seconds, base x 2 seconds, base x 4 seconds, ...
* @property {number} pushRetryBackoffBase
* @default 1
*/
pushRetryBackoffBase?: number,
},
/**
* SDK Core settings for the browser.
* @property {Object} core
*/
core: {
/**
* Your SDK key.
* @see {@link https://help.split.io/hc/en-us/articles/360019916211-API-keys}
* @property {string} authorizationKey
*/
authorizationKey: string,
/**
* Customer identifier. Whatever this means to you.
* @see {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
* @property {SplitKey} key
*/
key: SplitKey,
/**
* Disable labels from being sent to Split backend. Labels may contain sensitive information.
* @property {boolean} labelsEnabled
* @default true
*/
labelsEnabled?: boolean
},
/**
* Mocked features map. For testing purposes only. For using this you should specify "localhost" as authorizationKey on core settings.
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#localhost-mode}
*/
features?: MockedFeaturesMap,
/**
* Defines which kind of storage we can instantiate on the browser.
* Possible storage types are 'MEMORY', which is the default, and 'LOCALSTORAGE'.
* @property {Object} storage
*/
storage?: {
/**
* Storage type to be instantiated by the SDK.
* @property {BrowserStorage} type
* @default 'MEMORY'
*/
type?: BrowserStorage,
/**
* Optional prefix to prevent any kind of data collision between SDK versions.
* @property {string} prefix
* @default 'SPLITIO'
*/
prefix?: string
},
/**
* List of URLs that the SDK will use as base for it's synchronization functionalities, applicable only when running as standalone.
* Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy.
* @property {Object} urls
*/
urls?: UrlSettings,
/**
* User consent status. Possible values are `'GRANTED'`, which is the default, `'DECLINED'` or `'UNKNOWN'`.
* - `'GRANTED'`: the user grants consent for tracking events and impressions. The SDK sends them to Split cloud.
* - `'DECLINED'`: the user declines consent for tracking events and impressions. The SDK does not send them to Split cloud.
* - `'UNKNOWN'`: the user neither grants nor declines consent for tracking events and impressions. The SDK tracks them in its internal storage, and eventually either sends
* them or not if the consent status is updated to 'GRANTED' or 'DECLINED' respectively. The status can be updated at any time with the `UserConsent.setStatus` factory method.
*
* @typedef {string} userConsent
* @default 'GRANTED'
*/
userConsent?: ConsentStatus,
sync?: ISharedSettings['sync'] & {
/**
* Custom options object for HTTP(S) requests in the Browser.
* If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
*/
requestOptions?: {
/**
* Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
* Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
* To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
* Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
*
* NOTE: to pass custom headers to the streaming connection in Browser, you should polyfill the `window.EventSource` object with a library that supports headers,
* like https://www.npmjs.com/package/event-source-polyfill, since native EventSource does not support them and will be ignored.
*
* @property getHeaderOverrides
* @default undefined
*
* @param context - The context for the request.
* @param context.headers - The current headers in the request.
* @returns A set of headers to be merged with the current headers.
*
* @example
* const getHeaderOverrides = (context) => {
* return {
* 'Authorization': context.headers['Authorization'] + ', other-value',
* 'custom-header': 'custom-value'
* };
* };
*/
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
},
}
}
/**