-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsplitio.d.ts
More file actions
2138 lines (2131 loc) · 87.8 KB
/
splitio.d.ts
File metadata and controls
2138 lines (2131 loc) · 87.8 KB
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 Split Software SDKs
// Project: https://www.split.io/
import { RedisOptions } from 'ioredis';
import { RequestOptions } from 'http';
export as namespace SplitIO;
export = SplitIO;
/**
* Common settings properties.
*/
interface ISharedSettings {
/**
* 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.
*
* @defaultValue `undefined`
*/
impressionListener?: SplitIO.IImpressionListener;
/**
* SDK synchronization settings.
*/
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.
*
* NOTES:
* - This configuration is only meaningful when the SDK is working in `"standalone"` mode.
* - If `bySet` filter is provided, `byName` and `byPrefix` filters are ignored.
* - If both `byName` and `byPrefix` filters are provided, the intersection of the two groups of feature flags is fetched.
*
* 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'
* ]
* ```
*/
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.
*
* @defaultValue `'OPTIMIZED'`
*/
impressionsMode?: SplitIO.ImpressionsMode;
/**
* Custom options object for HTTP(S) requests.
* If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
* This configuration has no effect in "consumer" mode, as no HTTP(S) requests are made by the SDK.
*/
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 cases 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 they will be ignored.
*
* @defaultValue `undefined`
*
* @param context - The context for the request, which contains the `headers` property object representing the current headers in the request.
* @returns An object representing a set of headers to be merged with the current headers.
*
* @example
* ```
* const factory = SplitFactory({
* ...
* sync: {
* getHeaderOverrides: (context) => {
* return {
* 'Authorization': context.headers['Authorization'] + ', other-value',
* 'custom-header': 'custom-value'
* };
* }
* }
* });
* ```
*/
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>;
};
};
/**
* List of URLs that the SDK will use as base for it's synchronization functionalities, applicable only when running as standalone and partial consumer modes.
* Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy.
*/
urls?: SplitIO.UrlSettings;
/**
* Custom logger object. If not provided, the SDK will use the default `console.log` method for all log levels.
* Set together with `debug` option to `true` or a log level string to enable logging.
*/
logger?: SplitIO.Logger;
}
/**
* Common settings properties for SDKs with synchronous API (standalone and localhost modes).
*/
interface ISyncSharedSettings extends ISharedSettings {
/**
* The SDK mode. When using the default in-memory storage or `InLocalStorage` as storage, the only possible value is "standalone", which is the default.
* For "localhost" mode, use "localhost" as authorizationKey.
*
* @defaultValue `'standalone'`
*/
mode?: 'standalone';
/**
* 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.
*
* @defaultValue `true`
*/
streamingEnabled?: boolean;
/**
* SDK synchronization settings.
*/
sync?: ISharedSettings['sync'] & {
/**
* 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.
*
* @defaultValue `true`
*/
enabled?: boolean;
};
}
/**
* Common settings properties for SDKs with pluggable options.
*/
interface IPluggableSharedSettings {
/**
* Boolean value to indicate whether the logger should be enabled or disabled by default, or a log level string or a Logger object.
* Passing a logger object is required to get descriptive log messages. Otherwise most logs will print with message codes.
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/browser-sdk/#logging}.
*
* Examples:
* ```
* config.debug = true
* config.debug = 'WARN'
* config.debug = ErrorLogger()
* ```
*
* @defaultValue `false`
*/
debug?: boolean | SplitIO.LogLevel | SplitIO.ILogger;
/**
* Defines an optional list of factory functions used to instantiate SDK integrations.
*
* NOTE: at the moment there are not integrations to plug in.
*/
integrations?: SplitIO.IntegrationFactory[];
}
/**
* Common settings properties for SDKs without pluggable options.
*/
interface INonPluggableSharedSettings {
/**
* Boolean value to indicate whether the logger should be enabled or disabled, or a log level string.
*
* Examples:
* ```
* config.debug = true
* config.debug = 'WARN'
* ```
*
* @defaultValue `false`
*/
debug?: boolean | SplitIO.LogLevel;
}
/**
* Common settings properties for SDKs with server-side API.
*/
interface IServerSideSharedSettings {
/**
* SDK Core settings for Node.js.
*/
core: {
/**
* Your SDK key.
*
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/account-settings/api-keys/}
*/
authorizationKey: string;
/**
* Disable labels from being sent to Split backend. Labels may contain sensitive information.
*
* @defaultValue `true`
*/
labelsEnabled?: boolean;
/**
* Disable machine IP and Name from being sent to Split backend.
*
* @defaultValue `true`
*/
IPAddressesEnabled?: boolean;
};
/**
* SDK Startup settings for Node.js.
*/
startup?: {
/**
* Maximum amount of time used before notify a timeout.
*
* @defaultValue `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'.
*
* @defaultValue `15`
*/
requestTimeoutBeforeReady?: number;
/**
* How many quick retries we will do while starting up the SDK.
*
* @defaultValue `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.
*
* @defaultValue `0`
*/
eventsFirstPushWindow?: number;
};
/**
* SDK scheduler settings.
*/
scheduler?: {
/**
* The SDK polls Split servers for changes to feature flag definitions. This parameter controls this polling period in seconds.
*
* @defaultValue `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.
*
* @defaultValue `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.
*
* @defaultValue `30000`
*/
impressionsQueueSize?: number;
/**
* The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
*
* @defaultValue `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.
*
* @defaultValue `3600`
*/
telemetryRefreshRate?: number;
/**
* The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
*
* @defaultValue `60`
*/
segmentsRefreshRate?: number;
/**
* The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
*
* @defaultValue `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.
*
* @defaultValue `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://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/nodejs-sdk/#localhost-mode}
*
* @defaultValue `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, ...
*
* @defaultValue `1`
*/
pushRetryBackoffBase?: number;
};
/**
* Mocked features file path. For testing purposes only. For using this you should specify "localhost" as authorizationKey on core settings.
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/nodejs-sdk/#localhost-mode}
*
* @defaultValue `'$HOME/.split'`
*/
features?: SplitIO.MockedFeaturesFilePath;
}
/**
* Common settings properties for SDKs with client-side API.
*/
interface IClientSideSharedSettings {
/**
* SDK Core settings for client-side.
*/
core: {
/**
* Your SDK key.
*
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/account-settings/api-keys/}
*/
authorizationKey: string;
/**
* Customer identifier. Whatever this means to you.
*
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/fme-settings/traffic-types/}
*/
key: SplitIO.SplitKey;
/**
* Disable labels from being sent to Split backend. Labels may contain sensitive information.
*
* @defaultValue `true`
*/
labelsEnabled?: boolean;
};
/**
* 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.
*
* @defaultValue `'GRANTED'`
*/
userConsent?: SplitIO.ConsentStatus;
}
/**
* Common settings properties for SDKs with client-side and synchronous API (standalone and localhost modes).
*/
interface IClientSideSyncSharedSettings extends IClientSideSharedSettings, ISyncSharedSettings {
/**
* Mocked features map. For testing purposes only. For using this you should specify "localhost" as authorizationKey on core settings.
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/javascript-sdk/#localhost-mode}
*/
features?: SplitIO.MockedFeaturesMap;
/**
* Rollout plan object (i.e., feature flags and segment definitions) to initialize the SDK storage with. If provided and valid, the SDK will be ready from cache immediately.
* This object is derived from calling the Node.js SDK’s `getRolloutPlan` method.
*/
initialRolloutPlan?: SplitIO.RolloutPlan;
/**
* SDK Startup settings.
*/
startup?: {
/**
* Maximum amount of time used before notify a timeout.
*
* @defaultValue `10`
*/
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'.
*
* @defaultValue `5`
*/
requestTimeoutBeforeReady?: number;
/**
* How many quick retries we will do while starting up the SDK.
*
* @defaultValue `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 or mobile. This number defines that window before the first events push.
*
* @defaultValue `10`
*/
eventsFirstPushWindow?: number;
};
/**
* SDK scheduler settings.
*/
scheduler?: {
/**
* The SDK polls Split servers for changes to feature flag definitions. This parameter controls this polling period in seconds.
*
* @defaultValue `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.
*
* @defaultValue `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.
*
* @defaultValue `30000`
*/
impressionsQueueSize?: number;
/**
* The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
*
* @defaultValue `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.
*
* @defaultValue `3600`
*/
telemetryRefreshRate?: number;
/**
* The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
*
* @defaultValue `60`
*/
segmentsRefreshRate?: number;
/**
* The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
*
* @defaultValue `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.
*
* @defaultValue `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://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/javascript-sdk/#localhost-mode}
*
* @defaultValue `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, ...
*
* @defaultValue `1`
*/
pushRetryBackoffBase?: number;
};
}
/****** Exposed namespace ******/
/**
* Shared types and interfaces for `@splitsoftware` packages, to support integrating JavaScript SDKs with TypeScript.
*/
declare namespace SplitIO {
interface StorageWrapper {
/**
* Returns the value associated with the given key, or null if the key does not exist.
* If the operation is asynchronous, returns a Promise.
*/
getItem(key: string): string | null | Promise<string | null>;
/**
* Sets the value for the given key, creating a new key/value pair if key does not exist.
* If the operation is asynchronous, returns a Promise.
*/
setItem(key: string, value: string): void | Promise<void>;
/**
* Removes the key/value pair for the given key, if the key exists.
* If the operation is asynchronous, returns a Promise.
*/
removeItem(key: string): void | Promise<void>;
}
/**
* EventEmitter interface based on a subset of the Node.js EventEmitter methods.
*/
interface IEventEmitter {
addListener(event: string, listener: (...args: any[]) => void): this;
on(event: string, listener: (...args: any[]) => void): this;
once(event: string, listener: (...args: any[]) => void): this;
removeListener(event: string, listener: (...args: any[]) => void): this;
off(event: string, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string): this;
emit(event: string, ...args: any[]): boolean;
}
/**
* Node.js EventEmitter interface
* @see {@link https://nodejs.org/api/events.html}
*/
interface EventEmitter extends IEventEmitter {
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;
emit(event: string | symbol, ...args: any[]): boolean;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(event: string | symbol): Function[];
rawListeners(event: string | symbol): Function[];
listenerCount(type: string | symbol): number;
// Added in Node.js 6...
prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
eventNames(): Array<string | symbol>;
}
/**
* Event constants.
*/
type EventConsts = {
/**
* The ready event emitted once the SDK is ready to evaluate feature flags with cache synchronized with the backend.
*/
SDK_READY: 'init::ready';
/**
* The ready event emitted once the SDK is ready to evaluate feature flags with cache that could be stale. Use SDK_READY if you want to be sure the cache is in sync with the backend.
*/
SDK_READY_FROM_CACHE: 'init::cache-ready';
/**
* The timeout event emitted after `startup.readyTimeout` seconds if the SDK_READY event was not emitted.
*/
SDK_READY_TIMED_OUT: 'init::timeout';
/**
* The update event emitted when the SDK cache is updated with new data from the backend.
*/
SDK_UPDATE: 'state::update';
};
/**
* SDK Modes.
*/
type SDKMode = 'standalone' | 'localhost' | 'consumer' | 'consumer_partial';
/**
* Storage types.
*/
type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
/**
* 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 {
readonly core: {
authorizationKey: string;
key: SplitKey;
labelsEnabled: boolean;
IPAddressesEnabled: boolean;
};
readonly mode: SDKMode;
readonly scheduler: {
featuresRefreshRate: number;
impressionsRefreshRate: number;
impressionsQueueSize: number;
/**
* @deprecated Use `telemetryRefreshRate` instead.
*/
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: StorageSyncFactory | StorageAsyncFactory | StorageOptions;
readonly initialRolloutPlan?: SplitIO.RolloutPlan;
readonly urls: {
events: string;
sdk: string;
auth: string;
streaming: string;
telemetry: string;
};
readonly integrations?: IntegrationFactory[];
readonly logger?: Logger;
readonly debug: boolean | LogLevel | ILogger;
readonly version: string;
/**
* Mocked features map if using in client-side, or mocked features file path string if using in server-side (Node.js).
*/
features: MockedFeaturesMap | MockedFeaturesFilePath;
readonly streamingEnabled: boolean;
readonly sync: {
splitFilters: SplitFilter[];
impressionsMode: ImpressionsMode;
enabled: boolean;
flagSpecVersion: string;
requestOptions?: {
getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>;
};
};
readonly runtime: {
ip: string | false;
hostname: string | false;
};
readonly impressionListener?: IImpressionListener;
/**
* User consent status if using in client-side. Undefined if using in server-side (Node.js).
*/
readonly userConsent?: ConsentStatus;
}
/**
* Log levels.
*/
type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
/**
* Custom logger interface.
*/
interface Logger {
debug(message: string): any;
info(message: string): any;
warn(message: string): any;
error(message: string): any;
}
/**
* Logger API
*/
interface ILoggerAPI {
/**
* Enables SDK logging to the console.
*/
enable(): void;
/**
* Disables SDK logging.
*/
disable(): void;
/**
* Sets a log level for the SDK logs.
*
* @param logLevel - The log level to set.
*/
setLogLevel(logLevel: LogLevel): void;
/**
* Sets a custom logger for the SDK logs.
*
* @param logger - The custom logger to set, or `undefined` to remove the custom logger and fall back to the default `console.log` method.
*/
setLogger(logger?: Logger): void;
/**
* Log level constants. Use this to pass them to setLogLevel function.
*/
LogLevel: {
[level in LogLevel]: LogLevel;
};
}
/**
* User consent API
*/
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.
*
* @param userConsent - The user consent status, true for 'GRANTED' and false for 'DECLINED'.
* @returns Whether the provided param is a valid value (i.e., a boolean value) or not.
*/
setStatus(userConsent: boolean): boolean;
/**
* Gets the user consent status.
*
* @returns The user consent status.
*/
getStatus(): ConsentStatus;
/**
* Consent status constants. Use this to compare with the getStatus function result.
*/
Status: {
[status in ConsentStatus]: ConsentStatus;
};
}
/**
* Common API for entities that expose status handlers.
*/
interface IStatusInterface extends EventEmitter {
/**
* Constant object containing the SDK events for you to use.
*/
Event: EventConsts;
/**
* Returns a promise that resolves when the SDK has finished initial synchronization with the backend (`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 than event listeners, given that the SDK might be ready after a timeout event, the `whenReady` 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 set the `startup.readyTimeout` configuration option to 0 to avoid the timeout and thus the rejection.
*
* @returns A promise that resolves once the SDK_READY event is emitted or rejects if the SDK has timedout.
*/
whenReady(): Promise<void>;
/**
* Returns a promise that resolves when the SDK is ready for evaluations using cached data, which might not yet be synchronized with the backend (`SDK_READY_FROM_CACHE` event emitted), or rejected if the SDK has timedout (`SDK_READY_TIMED_OUT` event emitted).
* As it's meant to provide similar flexibility than event listeners, given that the SDK might be ready from cache after a timeout event, the `whenReadyFromCache` method will return a resolved promise once the SDK is ready from cache.
* You must handle the promise rejection to avoid an unhandled promise rejection error, or set the `startup.readyTimeout` configuration option to 0 to avoid the timeout and thus the rejection.
*
* @returns A promise that resolves once the SDK_READY_FROM_CACHE event is emitted or rejects if the SDK has timedout. The promise resolves with a boolean value that
* indicates whether the SDK_READY_FROM_CACHE event was emitted together with the SDK_READY event (i.e., the SDK is ready and synchronized with the backend) or not.
*/
whenReadyFromCache(): Promise<boolean>;
}
/**
* Common definitions between clients for different environments interface.
*/
interface IBasicClient extends IStatusInterface {
/**
* Destroys the client instance.
*
* In 'standalone' and 'partial consumer' modes, this method will flush any pending impressions and events.
* In 'standalone' mode, it also stops the synchronization of feature flag definitions with the backend.
* In 'consumer' and 'partial consumer' modes, this method also disconnects the SDK from the Pluggable storage.
*
* @returns A promise that resolves once the client is destroyed.
*/
destroy(): Promise<void>;
}
/**
* Common definitions between SDK instances for different environments interface.
*/
interface IBasicSDK {
/**
* Current settings of the SDK instance.
*/
settings: ISettings;
/**
* Logger API.
*/
Logger: ILoggerAPI;
/**
* Destroys all the clients created by this factory.
*
* @returns A promise that resolves once all clients are destroyed.
*/
destroy(): Promise<void>;
}
/**
* Feature flag treatment value, returned by getTreatment.
*/
type Treatment = string;
/**
* Feature flag treatment promise that resolves to actual treatment value.
*/
type AsyncTreatment = Promise<Treatment>;
/**
* An object with the treatments for a bulk of feature flags, returned by getTreatments. For example:
* ```
* {
* feature1: 'on',
* feature2: 'off'
* }
* ```
*/
type Treatments = {
[featureName: string]: Treatment;
};
/**
* Feature flag treatments promise that resolves to the actual SplitIO.Treatments object.
*/
type AsyncTreatments = Promise<Treatments>;
/**
* Feature flag evaluation result with treatment and configuration, returned by getTreatmentWithConfig.
*/
type TreatmentWithConfig = {
/**
* The treatment string.
*/
treatment: string;
/**
* The stringified version of the JSON config defined for that treatment, null if there is no config for the resulting treatment.
*/
config: string | null;
};
/**
* Feature flag treatment promise that resolves to actual SplitIO.TreatmentWithConfig object.
*/
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."}' }
* }
* ```
*/
type TreatmentsWithConfig = {
[featureName: string]: TreatmentWithConfig;
};
/**
* Feature flag treatments promise that resolves to the actual SplitIO.TreatmentsWithConfig object.
*/
type AsyncTreatmentsWithConfig = Promise<TreatmentsWithConfig>;
/**
* Possible Split SDK events.
*/
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.
*
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/javascript-sdk/#attribute-syntax}
*/
type Attributes = {
[attributeName: string]: AttributeType;
};
/**
* Type of an attribute value
*/
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.
*
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/javascript-sdk/#track}
*/
type Properties = {
[propertyName: string]: string | number | boolean | null;
};
/**
* Evaluation options object for getTreatment methods.
*/
type EvaluationOptions = {
/**
* Optional properties to append to the generated impression object sent to Split backend.
*/
properties?: Properties;
}
/**
* The SplitKey object format.
*/
type SplitKeyObject = {
matchingKey: string;
bucketingKey: string;
};
/**
* The customer identifier. Could be a SplitKeyObject or a string.
*/
type SplitKey = SplitKeyObject | string;
/**
* Path to file with mocked features (for node).
*/
type MockedFeaturesFilePath = string;
/**
* Object with mocked features mapping for client-side (e.g., Browser or React Native). We need to specify the featureName as key, and the mocked treatment as value.
*/
type MockedFeaturesMap = {
[featureName: string]: string | TreatmentWithConfig;
};
/**
* Impression DTO generated by the SDK when processing evaluations.
*/
type ImpressionDTO = {
/**
* Feature flag name.
*/
feature: string;
/**
* Key.
*/
keyName: string;
/**
* Treatment value.
*/
treatment: string;
/**
* Impression timestamp.
*/
time: number;
/**
* Bucketing Key
*/
bucketingKey?: string;
/**
* Rule label
*/
label: string;
/**
* Version of the feature flag
*/
changeNumber: number;
/**
* Previous time
*/
pt?: number;
/**
* JSON stringified version of the impression properties.
*/
properties?: string;
}
/**
* 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.
*/
type ImpressionData = {
impression: ImpressionDTO;
attributes?: Attributes;
ip: string | false;
hostname: string | false;
sdkLanguageVersion: string;
};
/**
* Data corresponding to one feature flag view.
*/
type SplitView = {
/**
* The name of the feature flag.
*/
name: string;
/**
* The traffic type of the feature flag.
*/
trafficType: string;
/**
* Whether the feature flag is killed or not.
*/
killed: boolean;
/**
* The list of treatments available for the feature flag.
*/
treatments: string[];
/**
* Current change number of the feature flag.
*/
changeNumber: number;
/**
* Map of configurations per treatment.
* Each existing configuration is a stringified version of the JSON you defined on the Split user interface.
*/
configs: {
[treatmentName: string]: string;
};
/**
* List of sets of the feature flag.
*/
sets: string[];
/**
* The default treatment of the feature flag.
*/
defaultTreatment: string;
/**
* Whether the feature flag has impressions tracking disabled or not.
*/
impressionsDisabled: boolean;
/**
* Prerequisites for the feature flag.
*/
prerequisites: Array<{ flagName: string, treatments: string[] }>;
};
/**
* A promise that resolves to a feature flag view or null if the feature flag is not found.
*/
type SplitViewAsync = Promise<SplitView | null>;
/**
* An array containing the SplitIO.SplitView elements.
*/
type SplitViews = Array<SplitView>;
/**
* A promise that resolves to an SplitIO.SplitViews array.
*/
type SplitViewsAsync = Promise<SplitViews>;
/**
* An array of feature flag names.
*/
type SplitNames = Array<string>;
/**
* A promise that resolves to an array of feature flag names.
*/
type SplitNamesAsync = Promise<SplitNames>;
/**
* Storage for synchronous (standalone) SDK.
* Its interface details are not part of the public API.
*/
type StorageSync = any;
/**
* Storage builder for synchronous (standalone) SDK.
* Input parameter details are not part of the public API.
*/
type StorageSyncFactory = {
readonly type: StorageType;
(params: any): (StorageSync | undefined);
}
/**
* Configuration params for `InLocalStorage`