@splitsoftware/splitio 11.0.0-rc.1 → 11.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1679 +0,0 @@
1
- // Type definitions for JavaScript and NodeJS Split Software SDK
2
- // Project: http://www.split.io/
3
- // Definitions by: Nico Zelaya <https://github.com/NicoZelaya/>
4
-
5
- import { RedisOptions } from "ioredis";
6
- import { RequestOptions } from "http";
7
-
8
- export as namespace SplitIO;
9
- export = SplitIO;
10
-
11
- /**
12
- * NodeJS.EventEmitter interface
13
- * @see {@link https://nodejs.org/api/events.html}
14
- */
15
- interface EventEmitter {
16
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
17
- on(event: string | symbol, listener: (...args: any[]) => void): this;
18
- once(event: string | symbol, listener: (...args: any[]) => void): this;
19
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
20
- off(event: string | symbol, listener: (...args: any[]) => void): this;
21
- removeAllListeners(event?: string | symbol): this;
22
- setMaxListeners(n: number): this;
23
- getMaxListeners(): number;
24
- listeners(event: string | symbol): Function[];
25
- rawListeners(event: string | symbol): Function[];
26
- emit(event: string | symbol, ...args: any[]): boolean;
27
- listenerCount(type: string | symbol): number;
28
- // Added in Node 6...
29
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
30
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
31
- eventNames(): Array<string | symbol>;
32
- }
33
- /**
34
- * @typedef {Object} EventConsts
35
- * @property {string} SDK_READY The ready event.
36
- * @property {string} SDK_READY_FROM_CACHE The ready event when fired with cached data.
37
- * @property {string} SDK_READY_TIMED_OUT The timeout event.
38
- * @property {string} SDK_UPDATE The update event.
39
- */
40
- type EventConsts = {
41
- SDK_READY: 'init::ready',
42
- SDK_READY_FROM_CACHE: 'init::cache-ready',
43
- SDK_READY_TIMED_OUT: 'init::timeout',
44
- SDK_UPDATE: 'state::update'
45
- };
46
- /**
47
- * SDK Modes.
48
- * @typedef {string} SDKMode
49
- */
50
- type SDKMode = 'standalone' | 'consumer';
51
- /**
52
- * Storage types.
53
- * @typedef {string} StorageType
54
- */
55
- type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS';
56
- /**
57
- * Settings interface. This is a representation of the settings the SDK expose, that's why
58
- * most of it's props are readonly. Only features should be rewritten when localhost mode is active.
59
- * @interface ISettings
60
- */
61
- interface ISettings {
62
- readonly core: {
63
- authorizationKey: string,
64
- key: SplitIO.SplitKey,
65
- labelsEnabled: boolean,
66
- IPAddressesEnabled: boolean
67
- },
68
- readonly mode: SDKMode,
69
- readonly scheduler: {
70
- featuresRefreshRate: number,
71
- impressionsRefreshRate: number,
72
- impressionsQueueSize: number,
73
- /**
74
- * @deprecated
75
- */
76
- metricsRefreshRate?: number,
77
- telemetryRefreshRate: number,
78
- segmentsRefreshRate: number,
79
- offlineRefreshRate: number,
80
- eventsPushRate: number,
81
- eventsQueueSize: number,
82
- pushRetryBackoffBase: number
83
- },
84
- readonly startup: {
85
- readyTimeout: number,
86
- requestTimeoutBeforeReady: number,
87
- retriesOnFailureBeforeReady: number,
88
- eventsFirstPushWindow: number
89
- },
90
- readonly storage: {
91
- prefix: string,
92
- options: Object,
93
- type: StorageType
94
- },
95
- readonly preloadedData?: SplitIO.PreloadedData,
96
- readonly urls: {
97
- events: string,
98
- sdk: string,
99
- auth: string,
100
- streaming: string,
101
- telemetry: string
102
- },
103
- readonly debug: boolean | LogLevel,
104
- readonly version: string,
105
- /**
106
- * Mocked features map if using in browser, or mocked features file path string if using in NodeJS.
107
- */
108
- features: SplitIO.MockedFeaturesMap | SplitIO.MockedFeaturesFilePath,
109
- readonly streamingEnabled: boolean,
110
- readonly sync: {
111
- splitFilters: SplitIO.SplitFilter[],
112
- impressionsMode: SplitIO.ImpressionsMode,
113
- enabled: boolean,
114
- flagSpecVersion: string,
115
- requestOptions?: {
116
- getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
117
- }
118
- }
119
- /**
120
- * User consent status if using in browser. Undefined if using in NodeJS.
121
- */
122
- readonly userConsent?: SplitIO.ConsentStatus
123
- }
124
- /**
125
- * Log levels.
126
- * @typedef {string} LogLevel
127
- */
128
- type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'NONE';
129
- /**
130
- * Logger API
131
- * @interface ILoggerAPI
132
- */
133
- interface ILoggerAPI {
134
- /**
135
- * Enables SDK logging to the console.
136
- * @function enable
137
- * @returns {void}
138
- */
139
- enable(): void,
140
- /**
141
- * Disables SDK logging.
142
- * @function disable
143
- * @returns {void}
144
- */
145
- disable(): void,
146
- /**
147
- * Sets a log level for the SDK logs.
148
- * @function setLogLevel
149
- * @returns {void}
150
- */
151
- setLogLevel(logLevel: LogLevel): void,
152
- /**
153
- * Log level constants. Use this to pass them to setLogLevel function.
154
- */
155
- LogLevel: {
156
- [level in LogLevel]: LogLevel
157
- }
158
- }
159
- /**
160
- * User consent API
161
- * @interface IUserConsentAPI
162
- */
163
- interface IUserConsentAPI {
164
- /**
165
- * Sets or updates the user consent status. Possible values are `true` and `false`, which represent user consent `'GRANTED'` and `'DECLINED'` respectively.
166
- * - `true ('GRANTED')`: the user has granted consent for tracking events and impressions. The SDK will send them to Split cloud.
167
- * - `false ('DECLINED')`: the user has declined consent for tracking events and impressions. The SDK will not send them to Split cloud.
168
- *
169
- * NOTE: calling this method updates the user consent at a factory level, affecting all clients of the same factory.
170
- *
171
- * @function setStatus
172
- * @param {boolean} userConsent The user consent status, true for 'GRANTED' and false for 'DECLINED'.
173
- * @returns {boolean} Whether the provided param is a valid value (i.e., a boolean value) or not.
174
- */
175
- setStatus(userConsent: boolean): boolean;
176
- /**
177
- * Gets the user consent status.
178
- *
179
- * @function getStatus
180
- * @returns {ConsentStatus} The user consent status.
181
- */
182
- getStatus(): SplitIO.ConsentStatus;
183
- /**
184
- * Consent status constants. Use this to compare with the getStatus function result.
185
- */
186
- Status: {
187
- [status in SplitIO.ConsentStatus]: SplitIO.ConsentStatus
188
- }
189
- }
190
- /**
191
- * Common settings between Browser and NodeJS settings interface.
192
- * @interface ISharedSettings
193
- */
194
- interface ISharedSettings {
195
- /**
196
- * Boolean value to indicate whether the logger should be enabled or disabled, or a log level string.
197
- *
198
- * Examples:
199
- * ```javascript
200
- * config.debug = true
201
- * config.debug = 'WARN'
202
- * ```
203
- * @property {boolean | LogLevel} debug
204
- * @default false
205
- */
206
- debug?: boolean | LogLevel,
207
- /**
208
- * The impression listener, which is optional. Whatever you provide here needs to comply with the SplitIO.IImpressionListener interface,
209
- * which will check for the logImpression method.
210
- * @property {IImpressionListener} impressionListener
211
- * @default undefined
212
- */
213
- impressionListener?: SplitIO.IImpressionListener,
214
- /**
215
- * Boolean flag to enable the streaming service as default synchronization mechanism. In the event of any issue with streaming,
216
- * the SDK would fallback to the polling mechanism. If false, the SDK would poll for changes as usual without attempting to use streaming.
217
- * @property {boolean} streamingEnabled
218
- * @default true
219
- */
220
- streamingEnabled?: boolean,
221
- /**
222
- * SDK synchronization settings.
223
- * @property {Object} sync
224
- */
225
- sync?: {
226
- /**
227
- * 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.
228
- * This configuration is only meaningful when the SDK is working in "standalone" mode.
229
- *
230
- * Example:
231
- * `splitFilter: [
232
- * { 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'
233
- * ]`
234
- * @property {SplitIO.SplitFilter[]} splitFilters
235
- */
236
- splitFilters?: SplitIO.SplitFilter[]
237
- /**
238
- * Impressions Collection Mode. Option to determine how impressions are going to be sent to Split servers.
239
- * Possible values are 'DEBUG', 'OPTIMIZED', and 'NONE'.
240
- * - DEBUG: will send all the impressions generated (recommended only for debugging purposes).
241
- * - OPTIMIZED: will send unique impressions to Split servers, avoiding a considerable amount of traffic that duplicated impressions could generate.
242
- * - 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.
243
- *
244
- * @property {string} impressionsMode
245
- * @default 'OPTIMIZED'
246
- */
247
- impressionsMode?: SplitIO.ImpressionsMode,
248
- /**
249
- * Controls the SDK continuous synchronization flags.
250
- *
251
- * When `true` a running SDK will process rollout plan updates performed on the UI (default).
252
- * When false it'll just fetch all data upon init
253
- *
254
- * @property {boolean} enabled
255
- * @default true
256
- */
257
- enabled?: boolean
258
- }
259
- }
260
- /**
261
- * Common settings interface for SDK instances on NodeJS.
262
- * @interface INodeBasicSettings
263
- * @extends ISharedSettings
264
- */
265
- interface INodeBasicSettings extends ISharedSettings {
266
- /**
267
- * SDK Startup settings for NodeJS.
268
- * @property {Object} startup
269
- */
270
- startup?: {
271
- /**
272
- * Maximum amount of time used before notify a timeout.
273
- * @property {number} readyTimeout
274
- * @default 15
275
- */
276
- readyTimeout?: number,
277
- /**
278
- * 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'.
279
- * @property {number} requestTimeoutBeforeReady
280
- * @default 15
281
- */
282
- requestTimeoutBeforeReady?: number,
283
- /**
284
- * How many quick retries we will do while starting up the SDK.
285
- * @property {number} retriesOnFailureBeforeReady
286
- * @default 1
287
- */
288
- retriesOnFailureBeforeReady?: number,
289
- /**
290
- * For SDK posts the queued events data in bulks with a given rate, but the first push window is defined separately,
291
- * to better control on browsers. This number defines that window before the first events push.
292
- *
293
- * @property {number} eventsFirstPushWindow
294
- * @default 0
295
- */
296
- eventsFirstPushWindow?: number,
297
- },
298
- /**
299
- * SDK scheduler settings.
300
- * @property {Object} scheduler
301
- */
302
- scheduler?: {
303
- /**
304
- * The SDK polls Split servers for changes to feature flag definitions. This parameter controls this polling period in seconds.
305
- * @property {number} featuresRefreshRate
306
- * @default 60
307
- */
308
- featuresRefreshRate?: number,
309
- /**
310
- * 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.
311
- * @property {number} impressionsRefreshRate
312
- * @default 300
313
- */
314
- impressionsRefreshRate?: number,
315
- /**
316
- * The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
317
- * If you use a 0 here, the queue will have no maximum size.
318
- * @property {number} impressionsQueueSize
319
- * @default 30000
320
- */
321
- impressionsQueueSize?: number,
322
- /**
323
- * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
324
- * @property {number} metricsRefreshRate
325
- * @default 120
326
- * @deprecated This parameter is ignored now. Use `telemetryRefreshRate` instead.
327
- */
328
- metricsRefreshRate?: number,
329
- /**
330
- * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
331
- * @property {number} telemetryRefreshRate
332
- * @default 3600
333
- */
334
- telemetryRefreshRate?: number,
335
- /**
336
- * The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
337
- * @property {number} segmentsRefreshRate
338
- * @default 60
339
- */
340
- segmentsRefreshRate?: number,
341
- /**
342
- * The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
343
- * @property {number} eventsPushRate
344
- * @default 60
345
- */
346
- eventsPushRate?: number,
347
- /**
348
- * The maximum number of event items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
349
- * If you use a 0 here, the queue will have no maximum size.
350
- * @property {number} eventsQueueSize
351
- * @default 500
352
- */
353
- eventsQueueSize?: number,
354
- /**
355
- * For mocking/testing only. The SDK will refresh the features mocked data when mode is set to "localhost" by defining the key.
356
- * For more information see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#localhost-mode}
357
- * @property {number} offlineRefreshRate
358
- * @default 15
359
- */
360
- offlineRefreshRate?: number
361
- /**
362
- * When using streaming mode, seconds to wait before re attempting to connect for push notifications.
363
- * Next attempts follow intervals in power of two: base seconds, base x 2 seconds, base x 4 seconds, ...
364
- * @property {number} pushRetryBackoffBase
365
- * @default 1
366
- */
367
- pushRetryBackoffBase?: number,
368
- },
369
- /**
370
- * SDK Core settings for NodeJS.
371
- * @property {Object} core
372
- */
373
- core: {
374
- /**
375
- * Your SDK key.
376
- * @see {@link https://help.split.io/hc/en-us/articles/360019916211-API-keys}
377
- * @property {string} authorizationKey
378
- */
379
- authorizationKey: string,
380
- /**
381
- * Disable labels from being sent to Split backend. Labels may contain sensitive information.
382
- * @property {boolean} labelsEnabled
383
- * @default true
384
- */
385
- labelsEnabled?: boolean
386
- /**
387
- * Disable machine IP and Name from being sent to Split backend.
388
- * @property {boolean} IPAddressesEnabled
389
- * @default true
390
- */
391
- IPAddressesEnabled?: boolean
392
- },
393
- /**
394
- * Defines which kind of storage we should instantiate.
395
- * @property {Object} storage
396
- */
397
- storage?: {
398
- /**
399
- * Storage type to be instantiated by the SDK.
400
- * @property {StorageType} type
401
- * @default 'MEMORY'
402
- */
403
- type?: StorageType,
404
- /**
405
- * Options to be passed to the selected storage.
406
- * @property {Object} options
407
- */
408
- options?: Object,
409
- /**
410
- * Optional prefix to prevent any kind of data collision between SDK versions.
411
- * @property {string} prefix
412
- * @default 'SPLITIO'
413
- */
414
- prefix?: string
415
- },
416
- /**
417
- * The SDK mode. Possible values are "standalone", which is the default when using a synchronous storage, like 'MEMORY' and 'LOCALSTORAGE',
418
- * and "consumer", which must be set when using an asynchronous storage, like 'REDIS'. For "localhost" mode, use "localhost" as authorizationKey.
419
- * @property {SDKMode} mode
420
- * @default 'standalone'
421
- */
422
- mode?: SDKMode,
423
- /**
424
- * Mocked features file path. For testing purposes only. For using this you should specify "localhost" as authorizationKey on core settings.
425
- * @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#localhost-mode}
426
- * @property {MockedFeaturesFilePath} features
427
- * @default '$HOME/.split'
428
- */
429
- features?: SplitIO.MockedFeaturesFilePath,
430
- }
431
- /**
432
- * Common API for entities that expose status handlers.
433
- * @interface IStatusInterface
434
- * @extends EventEmitter
435
- */
436
- interface IStatusInterface extends EventEmitter {
437
- /**
438
- * Constant object containing the SDK events for you to use.
439
- * @property {EventConsts} Event
440
- */
441
- Event: EventConsts,
442
- /**
443
- * 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).
444
- * 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.
445
- *
446
- * Caveats: the method was designed to avoid an unhandled Promise rejection if the rejection case is not handled, so that `onRejected` handler is optional when using promises.
447
- * However, when using async/await syntax, the rejection should be explicitly propagated like in the following example:
448
- * ```
449
- * try {
450
- * await client.ready().catch((e) => { throw e; });
451
- * // SDK is ready
452
- * } catch(e) {
453
- * // SDK has timedout
454
- * }
455
- * ```
456
- *
457
- * @function ready
458
- * @returns {Promise<void>}
459
- */
460
- ready(): Promise<void>
461
- }
462
- /**
463
- * Common definitions between clients for different environments interface.
464
- * @interface IBasicClient
465
- * @extends IStatusInterface
466
- */
467
- interface IBasicClient extends IStatusInterface {
468
- /**
469
- * Destroys the client instance.
470
- * In 'standalone' mode, this method will flush any pending impressions and events, and stop the synchronization of feature flag definitions with the backend.
471
- * In 'consumer' mode, this method will disconnect the SDK from the Redis or Pluggable storage.
472
- *
473
- * @function destroy
474
- * @returns {Promise<void>} A promise that resolves once the client is destroyed.
475
- */
476
- destroy(): Promise<void>
477
- }
478
- /**
479
- * Common definitions between SDK instances for different environments interface.
480
- * @interface IBasicSDK
481
- */
482
- interface IBasicSDK {
483
- /**
484
- * Current settings of the SDK instance.
485
- * @property settings
486
- */
487
- settings: ISettings,
488
- /**
489
- * Logger API.
490
- * @property Logger
491
- */
492
- Logger: ILoggerAPI
493
- /**
494
- * Destroys all the clients created by this factory.
495
- * @function destroy
496
- * @returns {Promise<void>}
497
- */
498
- destroy(): Promise<void>
499
- }
500
- /****** Exposed namespace ******/
501
- /**
502
- * Types and interfaces for `@splitsoftware/splitio` package for usage when integrating JavaScript SDK with TypeScript.
503
- * For the SDK package information see {@link https://www.npmjs.com/package/@splitsoftware/splitio}
504
- */
505
- declare namespace SplitIO {
506
- /**
507
- * Feature flag treatment value, returned by getTreatment.
508
- * @typedef {string} Treatment
509
- */
510
- type Treatment = string;
511
- /**
512
- * Feature flag treatment promise that resolves to actual treatment value.
513
- * @typedef {Promise<string>} AsyncTreatment
514
- */
515
- type AsyncTreatment = Promise<string>;
516
- /**
517
- * An object with the treatments for a bulk of feature flags, returned by getTreatments. For example:
518
- * {
519
- * feature1: 'on',
520
- * feature2: 'off
521
- * }
522
- * @typedef {Object.<Treatment>} Treatments
523
- */
524
- type Treatments = {
525
- [featureName: string]: Treatment
526
- };
527
- /**
528
- * Feature flag treatments promise that resolves to the actual SplitIO.Treatments object.
529
- * @typedef {Promise<Treatments>} AsyncTreatments
530
- */
531
- type AsyncTreatments = Promise<Treatments>;
532
- /**
533
- * Feature flag evaluation result with treatment and configuration, returned by getTreatmentWithConfig.
534
- * @typedef {Object} TreatmentWithConfig
535
- * @property {string} treatment The treatment string
536
- * @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.
537
- */
538
- type TreatmentWithConfig = {
539
- treatment: string,
540
- config: string | null
541
- };
542
- /**
543
- * Feature flag treatment promise that resolves to actual treatment with config value.
544
- * @typedef {Promise<TreatmentWithConfig>} AsyncTreatmentWithConfig
545
- */
546
- type AsyncTreatmentWithConfig = Promise<TreatmentWithConfig>;
547
- /**
548
- * An object with the treatments with configs for a bulk of feature flags, returned by getTreatmentsWithConfig.
549
- * Each existing configuration is a stringified version of the JSON you defined on the Split user interface. For example:
550
- * {
551
- * feature1: { treatment: 'on', config: null }
552
- * feature2: { treatment: 'off', config: '{"bannerText":"Click here."}' }
553
- * }
554
- * @typedef {Object.<TreatmentWithConfig>} Treatments
555
- */
556
- type TreatmentsWithConfig = {
557
- [featureName: string]: TreatmentWithConfig
558
- };
559
- /**
560
- * Feature flag treatments promise that resolves to the actual SplitIO.TreatmentsWithConfig object.
561
- * @typedef {Promise<TreatmentsWithConfig>} AsyncTreatmentsWithConfig
562
- */
563
- type AsyncTreatmentsWithConfig = Promise<TreatmentsWithConfig>;
564
- /**
565
- * Possible Split SDK events.
566
- * @typedef {string} Event
567
- */
568
- type Event = 'init::timeout' | 'init::ready' | 'init::cache-ready' | 'state::update';
569
- /**
570
- * 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.
571
- * @typedef {Object.<AttributeType>} Attributes
572
- * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#attribute-syntax}
573
- */
574
- type Attributes = {
575
- [attributeName: string]: AttributeType
576
- };
577
- /**
578
- * Type of an attribute value
579
- * @typedef {string | number | boolean | Array<string | number>} AttributeType
580
- */
581
- type AttributeType = string | number | boolean | Array<string | number>;
582
- /**
583
- * Properties should be an object with values of type string, number, boolean or null. Size limit of ~31kb.
584
- * @typedef {Object.<number, string, boolean, null>} Properties
585
- * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#track
586
- */
587
- type Properties = {
588
- [propertyName: string]: string | number | boolean | null
589
- };
590
- /**
591
- * The SplitKey object format.
592
- * @typedef {Object.<string>} SplitKeyObject
593
- */
594
- type SplitKeyObject = {
595
- matchingKey: string,
596
- bucketingKey: string
597
- };
598
- /**
599
- * The customer identifier. Could be a SplitKeyObject or a string.
600
- * @typedef {SplitKeyObject|string} SplitKey
601
- */
602
- type SplitKey = SplitKeyObject | string;
603
- /**
604
- * Path to file with mocked features (for node).
605
- * @typedef {string} MockedFeaturesFilePath
606
- */
607
- type MockedFeaturesFilePath = string;
608
- /**
609
- * Object with mocked features mapping (for browser). We need to specify the featureName as key, and the mocked treatment as value.
610
- * @typedef {Object} MockedFeaturesMap
611
- */
612
- type MockedFeaturesMap = {
613
- [featureName: string]: string | TreatmentWithConfig
614
- };
615
- /**
616
- * Object with information about an impression. It contains the generated impression DTO as well as
617
- * complementary information around where and how it was generated in that way.
618
- * @typedef {Object} ImpressionData
619
- */
620
- type ImpressionData = {
621
- impression: {
622
- feature: string,
623
- keyName: string,
624
- treatment: string,
625
- time: number,
626
- bucketingKey?: string,
627
- label: string,
628
- changeNumber: number,
629
- pt?: number,
630
- },
631
- attributes?: SplitIO.Attributes,
632
- ip: string,
633
- hostname: string,
634
- sdkLanguageVersion: string
635
- };
636
- /**
637
- * Data corresponding to one feature flag view.
638
- * @typedef {Object} SplitView
639
- */
640
- type SplitView = {
641
- /**
642
- * The name of the feature flag.
643
- * @property {string} name
644
- */
645
- name: string,
646
- /**
647
- * The traffic type of the feature flag.
648
- * @property {string} trafficType
649
- */
650
- trafficType: string,
651
- /**
652
- * Whether the feature flag is killed or not.
653
- * @property {boolean} killed
654
- */
655
- killed: boolean,
656
- /**
657
- * The list of treatments available for the feature flag.
658
- * @property {Array<string>} treatments
659
- */
660
- treatments: Array<string>,
661
- /**
662
- * Current change number of the feature flag.
663
- * @property {number} changeNumber
664
- */
665
- changeNumber: number,
666
- /**
667
- * Map of configurations per treatment.
668
- * Each existing configuration is a stringified version of the JSON you defined on the Split user interface.
669
- * @property {Object.<string>} configs
670
- */
671
- configs: {
672
- [treatmentName: string]: string
673
- },
674
- /**
675
- * List of sets of the feature flag.
676
- * @property {string[]} sets
677
- */
678
- sets: string[],
679
- /**
680
- * The default treatment of the feature flag.
681
- * @property {string} defaultTreatment
682
- */
683
- defaultTreatment: string,
684
- };
685
- /**
686
- * A promise that resolves to a feature flag view.
687
- * @typedef {Promise<SplitView>} SplitView
688
- */
689
- type SplitViewAsync = Promise<SplitView>;
690
- /**
691
- * An array containing the SplitIO.SplitView elements.
692
- */
693
- type SplitViews = Array<SplitView>;
694
- /**
695
- * A promise that resolves to an SplitIO.SplitViews array.
696
- * @typedef {Promise<SplitViews>} SplitViewsAsync
697
- */
698
- type SplitViewsAsync = Promise<SplitViews>;
699
- /**
700
- * An array of feature flag names.
701
- * @typedef {Array<string>} SplitNames
702
- */
703
- type SplitNames = Array<string>;
704
- /**
705
- * A promise that resolves to an array of feature flag names.
706
- * @typedef {Promise<SplitNames>} SplitNamesAsync
707
- */
708
- type SplitNamesAsync = Promise<SplitNames>;
709
- /**
710
- * Synchronous storage valid types for NodeJS.
711
- * @typedef {string} NodeSyncStorage
712
- */
713
- type NodeSyncStorage = 'MEMORY';
714
- /**
715
- * Asynchronous storages valid types for NodeJS.
716
- * @typedef {string} NodeAsyncStorage
717
- */
718
- type NodeAsyncStorage = 'REDIS';
719
- /**
720
- * Storage valid types for the browser.
721
- * @typedef {string} BrowserStorage
722
- */
723
- type BrowserStorage = 'MEMORY' | 'LOCALSTORAGE';
724
- /**
725
- * Impression listener interface. This is the interface that needs to be implemented
726
- * by the element you provide to the SDK as impression listener.
727
- * @interface IImpressionListener
728
- * @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#listener}
729
- */
730
- interface IImpressionListener {
731
- logImpression(data: SplitIO.ImpressionData): void
732
- }
733
- /**
734
- * Available URL settings for the SDKs.
735
- */
736
- type UrlSettings = {
737
- /**
738
- * String property to override the base URL where the SDK will get rollout plan related data, like feature flags and segments definitions.
739
- * @property {string} sdk
740
- * @default 'https://sdk.split.io/api'
741
- */
742
- sdk?: string,
743
- /**
744
- * String property to override the base URL where the SDK will post event-related information like impressions.
745
- * @property {string} events
746
- * @default 'https://events.split.io/api'
747
- */
748
- events?: string,
749
- /**
750
- * String property to override the base URL where the SDK will get authorization tokens to be used with functionality that requires it, like streaming.
751
- * @property {string} auth
752
- * @default 'https://auth.split.io/api'
753
- */
754
- auth?: string,
755
- /**
756
- * String property to override the base URL where the SDK will connect to receive streaming updates.
757
- * @property {string} streaming
758
- * @default 'https://streaming.split.io'
759
- */
760
- streaming?: string,
761
- /**
762
- * String property to override the base URL where the SDK will post telemetry data.
763
- * @property {string} telemetry
764
- * @default 'https://telemetry.split.io/api'
765
- */
766
- telemetry?: string
767
- };
768
-
769
- /**
770
- * SplitFilter type.
771
- *
772
- * @typedef {string} SplitFilterType
773
- */
774
- type SplitFilterType = 'bySet' | 'byName' | 'byPrefix';
775
- /**
776
- * Defines a feature flag filter, described by a type and list of values.
777
- */
778
- interface SplitFilter {
779
- /**
780
- * Type of the filter.
781
- *
782
- * @property {SplitFilterType} type
783
- */
784
- type: SplitFilterType,
785
- /**
786
- * List of values: feature flag names for 'byName' filter type, and feature flag name prefixes for 'byPrefix' type.
787
- *
788
- * @property {string[]} values
789
- */
790
- values: string[],
791
- }
792
- /**
793
- * ImpressionsMode type
794
- * @typedef {string} ImpressionsMode
795
- */
796
- type ImpressionsMode = 'OPTIMIZED' | 'DEBUG' | 'NONE';
797
- /**
798
- * User consent status.
799
- * @typedef {string} ConsentStatus
800
- */
801
- type ConsentStatus = 'GRANTED' | 'DECLINED' | 'UNKNOWN';
802
- /**
803
- * Defines the format of rollout plan data to preload on the factory storage (cache).
804
- */
805
- type PreloadedData = Object;
806
- /**
807
- * Settings interface for SDK instances created on the browser
808
- * @interface IBrowserSettings
809
- * @extends ISharedSettings
810
- * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#configuration}
811
- */
812
- interface IBrowserSettings extends ISharedSettings {
813
- /**
814
- * SDK Startup settings for the Browser.
815
- * @property {Object} startup
816
- */
817
- startup?: {
818
- /**
819
- * Maximum amount of time used before notify a timeout.
820
- * @property {number} readyTimeout
821
- * @default 1.5
822
- */
823
- readyTimeout?: number,
824
- /**
825
- * 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'.
826
- * @property {number} requestTimeoutBeforeReady
827
- * @default 1.5
828
- */
829
- requestTimeoutBeforeReady?: number,
830
- /**
831
- * How many quick retries we will do while starting up the SDK.
832
- * @property {number} retriesOnFailureBeforeReady
833
- * @default 1
834
- */
835
- retriesOnFailureBeforeReady?: number,
836
- /**
837
- * For SDK posts the queued events data in bulks with a given rate, but the first push window is defined separately,
838
- * to better control on browsers. This number defines that window before the first events push.
839
- *
840
- * @property {number} eventsFirstPushWindow
841
- * @default 10
842
- */
843
- eventsFirstPushWindow?: number,
844
- },
845
- /**
846
- * SDK scheduler settings.
847
- * @property {Object} scheduler
848
- */
849
- scheduler?: {
850
- /**
851
- * The SDK polls Split servers for changes to feature flag definitions. This parameter controls this polling period in seconds.
852
- * @property {number} featuresRefreshRate
853
- * @default 60
854
- */
855
- featuresRefreshRate?: number,
856
- /**
857
- * 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.
858
- * @property {number} impressionsRefreshRate
859
- * @default 60
860
- */
861
- impressionsRefreshRate?: number,
862
- /**
863
- * The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
864
- * If you use a 0 here, the queue will have no maximum size.
865
- * @property {number} impressionsQueueSize
866
- * @default 30000
867
- */
868
- impressionsQueueSize?: number,
869
- /**
870
- * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
871
- * @property {number} metricsRefreshRate
872
- * @default 120
873
- * @deprecated This parameter is ignored now. Use `telemetryRefreshRate` instead.
874
- */
875
- metricsRefreshRate?: number,
876
- /**
877
- * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
878
- * @property {number} telemetryRefreshRate
879
- * @default 3600
880
- */
881
- telemetryRefreshRate?: number,
882
- /**
883
- * The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
884
- * @property {number} segmentsRefreshRate
885
- * @default 60
886
- */
887
- segmentsRefreshRate?: number,
888
- /**
889
- * The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
890
- * @property {number} eventsPushRate
891
- * @default 60
892
- */
893
- eventsPushRate?: number,
894
- /**
895
- * The maximum number of event items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
896
- * If you use a 0 here, the queue will have no maximum size.
897
- * @property {number} eventsQueueSize
898
- * @default 500
899
- */
900
- eventsQueueSize?: number,
901
- /**
902
- * For mocking/testing only. The SDK will refresh the features mocked data when mode is set to "localhost" by defining the key.
903
- * For more information see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#localhost-mode}
904
- * @property {number} offlineRefreshRate
905
- * @default 15
906
- */
907
- offlineRefreshRate?: number,
908
- /**
909
- * When using streaming mode, seconds to wait before re attempting to connect for push notifications.
910
- * Next attempts follow intervals in power of two: base seconds, base x 2 seconds, base x 4 seconds, ...
911
- * @property {number} pushRetryBackoffBase
912
- * @default 1
913
- */
914
- pushRetryBackoffBase?: number,
915
- },
916
- /**
917
- * SDK Core settings for the browser.
918
- * @property {Object} core
919
- */
920
- core: {
921
- /**
922
- * Your SDK key.
923
- * @see {@link https://help.split.io/hc/en-us/articles/360019916211-API-keys}
924
- * @property {string} authorizationKey
925
- */
926
- authorizationKey: string,
927
- /**
928
- * Customer identifier. Whatever this means to you.
929
- * @see {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
930
- * @property {SplitKey} key
931
- */
932
- key: SplitKey,
933
- /**
934
- * Disable labels from being sent to Split backend. Labels may contain sensitive information.
935
- * @property {boolean} labelsEnabled
936
- * @default true
937
- */
938
- labelsEnabled?: boolean
939
- },
940
- /**
941
- * Mocked features map. For testing purposes only. For using this you should specify "localhost" as authorizationKey on core settings.
942
- * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#localhost-mode}
943
- */
944
- features?: MockedFeaturesMap,
945
- /**
946
- * Defines which kind of storage we can instantiate on the browser.
947
- * Possible storage types are 'MEMORY', which is the default, and 'LOCALSTORAGE'.
948
- * @property {Object} storage
949
- */
950
- storage?: {
951
- /**
952
- * Storage type to be instantiated by the SDK.
953
- * @property {BrowserStorage} type
954
- * @default 'MEMORY'
955
- */
956
- type?: BrowserStorage,
957
- /**
958
- * Optional prefix to prevent any kind of data collision between SDK versions.
959
- * @property {string} prefix
960
- * @default 'SPLITIO'
961
- */
962
- prefix?: string
963
- },
964
- /**
965
- * @TODO Add description. Should be inside storage?
966
- */
967
- preloadedData?: SplitIO.PreloadedData,
968
- /**
969
- * List of URLs that the SDK will use as base for it's synchronization functionalities, applicable only when running as standalone.
970
- * Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy.
971
- * @property {Object} urls
972
- */
973
- urls?: UrlSettings,
974
- /**
975
- * User consent status. Possible values are `'GRANTED'`, which is the default, `'DECLINED'` or `'UNKNOWN'`.
976
- * - `'GRANTED'`: the user grants consent for tracking events and impressions. The SDK sends them to Split cloud.
977
- * - `'DECLINED'`: the user declines consent for tracking events and impressions. The SDK does not send them to Split cloud.
978
- * - `'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
979
- * 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.
980
- *
981
- * @typedef {string} userConsent
982
- * @default 'GRANTED'
983
- */
984
- userConsent?: ConsentStatus,
985
- sync?: ISharedSettings['sync'] & {
986
- /**
987
- * Custom options object for HTTP(S) requests in the Browser.
988
- * If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
989
- */
990
- requestOptions?: {
991
- /**
992
- * Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
993
- * Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
994
- * To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
995
- * Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
996
- *
997
- * NOTE: to pass custom headers to the streaming connection in Browser, you should polyfill the `window.EventSource` object with a library that supports headers,
998
- * like https://www.npmjs.com/package/event-source-polyfill, since native EventSource does not support them and will be ignored.
999
- *
1000
- * @property getHeaderOverrides
1001
- * @default undefined
1002
- *
1003
- * @param context - The context for the request.
1004
- * @param context.headers - The current headers in the request.
1005
- * @returns A set of headers to be merged with the current headers.
1006
- *
1007
- * @example
1008
- * const getHeaderOverrides = (context) => {
1009
- * return {
1010
- * 'Authorization': context.headers['Authorization'] + ', other-value',
1011
- * 'custom-header': 'custom-value'
1012
- * };
1013
- * };
1014
- */
1015
- getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
1016
- },
1017
- }
1018
- }
1019
- /**
1020
- * Settings interface for SDK instances created on NodeJS.
1021
- * If your storage is asynchronous (Redis for example) use SplitIO.INodeAsyncSettings instead.
1022
- * @interface INodeSettings
1023
- * @extends INodeBasicSettings
1024
- * @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#configuration}
1025
- */
1026
- interface INodeSettings extends INodeBasicSettings {
1027
- /**
1028
- * List of URLs that the SDK will use as base for it's synchronization functionalities, applicable only when running as standalone.
1029
- * Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy.
1030
- * @property {Object} urls
1031
- */
1032
- urls?: UrlSettings,
1033
- /**
1034
- * Defines which kind of storage we can instantiate on NodeJS for 'standalone' mode.
1035
- * The only possible storage type is 'MEMORY', which is the default.
1036
- * @property {Object} storage
1037
- */
1038
- storage?: {
1039
- /**
1040
- * Synchronous storage type to be instantiated by the SDK.
1041
- * @property {NodeSyncStorage} type
1042
- * @default 'MEMORY'
1043
- */
1044
- type?: NodeSyncStorage,
1045
- /**
1046
- * Optional prefix to prevent any kind of data collision between SDK versions.
1047
- * @property {string} prefix
1048
- * @default 'SPLITIO'
1049
- */
1050
- prefix?: string
1051
- },
1052
- /**
1053
- * The SDK mode. When using the default 'MEMORY' storage, the only possible value is "standalone", which is the default.
1054
- * For "localhost" mode, use "localhost" as authorizationKey.
1055
- *
1056
- * @property {'standalone'} mode
1057
- * @default 'standalone'
1058
- */
1059
- mode?: 'standalone'
1060
- sync?: INodeBasicSettings['sync'] & {
1061
- /**
1062
- * Custom options object for HTTP(S) requests in NodeJS.
1063
- * If provided, this object is merged with the options object passed by the SDK for EventSource and Node-Fetch calls.
1064
- * @see {@link https://www.npmjs.com/package/node-fetch#options}
1065
- */
1066
- requestOptions?: {
1067
- /**
1068
- * Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
1069
- * Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
1070
- * To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
1071
- * Or provide keys with different case since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
1072
- *
1073
- * @property getHeaderOverrides
1074
- * @default undefined
1075
- *
1076
- * @param context - The context for the request.
1077
- * @param context.headers - The current headers in the request.
1078
- * @returns A set of headers to be merged with the current headers.
1079
- *
1080
- * @example
1081
- * const getHeaderOverrides = (context) => {
1082
- * return {
1083
- * 'Authorization': context.headers['Authorization'] + ', other-value',
1084
- * 'custom-header': 'custom-value'
1085
- * };
1086
- * };
1087
- */
1088
- getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>
1089
- /**
1090
- * Custom NodeJS HTTP(S) Agent used by the SDK for HTTP(S) requests.
1091
- *
1092
- * You can use it, for example, for certificate pinning or setting a network proxy:
1093
- *
1094
- * ```javascript
1095
- * const { HttpsProxyAgent } = require('https-proxy-agent');
1096
- *
1097
- * const proxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY || 'http://10.10.1.10:1080');
1098
- *
1099
- * const factory = SplitFactory({
1100
- * ...
1101
- * sync: {
1102
- * requestOptions: {
1103
- * agent: proxyAgent
1104
- * }
1105
- * }
1106
- * })
1107
- * ```
1108
- *
1109
- * @see {@link https://nodejs.org/api/https.html#class-httpsagent}
1110
- *
1111
- * @property {http.Agent | https.Agent} agent
1112
- * @default undefined
1113
- */
1114
- agent?: RequestOptions["agent"]
1115
- },
1116
- }
1117
- }
1118
- /**
1119
- * Settings interface with async storage for SDK instances created on NodeJS.
1120
- * If your storage is synchronous (by defaut we use memory, which is sync) use SplitIO.INodeSettings instead.
1121
- * @interface INodeAsyncSettings
1122
- * @extends INodeBasicSettings
1123
- * @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#configuration}
1124
- */
1125
- interface INodeAsyncSettings extends INodeBasicSettings {
1126
- /**
1127
- * Defines which kind of async storage we can instantiate on NodeJS for 'consumer' mode.
1128
- * The only possible storage type is 'REDIS'.
1129
- * @property {Object} storage
1130
- */
1131
- storage: {
1132
- /**
1133
- * 'REDIS' storage type to be instantiated by the SDK.
1134
- * @property {NodeAsyncStorage} type
1135
- */
1136
- type: NodeAsyncStorage,
1137
- /**
1138
- * Options to be passed to the Redis storage. Use it with storage type: 'REDIS'.
1139
- * @property {Object} options
1140
- */
1141
- options?: {
1142
- /**
1143
- * Redis URL. If set, `host`, `port`, `db` and `pass` params will be ignored.
1144
- *
1145
- * Examples:
1146
- * ```
1147
- * url: 'localhost'
1148
- * url: '127.0.0.1:6379'
1149
- * url: 'redis://:authpassword@127.0.0.1:6379/0'
1150
- * ```
1151
- * @property {string=} url
1152
- */
1153
- url?: string,
1154
- /**
1155
- * Redis host.
1156
- * @property {string=} host
1157
- * @default 'localhost'
1158
- */
1159
- host?: string,
1160
- /**
1161
- * Redis port.
1162
- * @property {number=} port
1163
- * @default 6379
1164
- */
1165
- port?: number,
1166
- /**
1167
- * Redis database to be used.
1168
- * @property {number=} db
1169
- * @default 0
1170
- */
1171
- db?: number,
1172
- /**
1173
- * Redis password. Don't define if no password is used.
1174
- * @property {string=} pass
1175
- * @default undefined
1176
- */
1177
- pass?: string,
1178
- /**
1179
- * The milliseconds before a timeout occurs during the initial connection to the Redis server.
1180
- * @property {number=} connectionTimeout
1181
- * @default 10000
1182
- */
1183
- connectionTimeout?: number,
1184
- /**
1185
- * The milliseconds before Redis commands are timeout by the SDK.
1186
- * Method calls that involve Redis commands, like `client.getTreatment` or `client.track` calls, are resolved when the commands success or timeout.
1187
- * @property {number=} operationTimeout
1188
- * @default 5000
1189
- */
1190
- operationTimeout?: number,
1191
- /**
1192
- * TLS configuration for Redis connection.
1193
- * @see {@link https://www.npmjs.com/package/ioredis#tls-options }
1194
- *
1195
- * @property {Object=} tls
1196
- * @default undefined
1197
- */
1198
- tls?: RedisOptions['tls'],
1199
- },
1200
- /**
1201
- * Optional prefix to prevent any kind of data collision between SDK versions.
1202
- * @property {string} prefix
1203
- * @default 'SPLITIO'
1204
- */
1205
- prefix?: string
1206
- },
1207
- /**
1208
- * The SDK mode. When using 'REDIS' storage type, the only possible value is "consumer", which is required.
1209
- *
1210
- * @see {@link https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK#state-sharing-redis-integration}
1211
- *
1212
- * @property {'consumer'} mode
1213
- */
1214
- mode: 'consumer'
1215
- }
1216
- /**
1217
- * This represents the interface for the SDK instance with synchronous storage.
1218
- * @interface ISDK
1219
- * @extends IBasicSDK
1220
- */
1221
- interface ISDK extends IBasicSDK {
1222
- /**
1223
- * Returns the default client instance of the SDK.
1224
- * @function client
1225
- * @returns {IClient} The client instance.
1226
- */
1227
- client(): IClient,
1228
- /**
1229
- * Returns a manager instance of the SDK to explore available information.
1230
- * @function manager
1231
- * @returns {IManager} The manager instance.
1232
- */
1233
- manager(): IManager,
1234
- /**
1235
- * @TODO add description
1236
- */
1237
- getState(keys?: SplitKey[]): PreloadedData,
1238
- }
1239
- /**
1240
- * This represents the interface for the SDK instance with synchronous storage.
1241
- * @interface IBrowserSDK
1242
- * @extends IBasicSDK
1243
- */
1244
- interface IBrowserSDK extends IBasicSDK {
1245
- /**
1246
- * Returns the default client instance of the SDK.
1247
- * @function client
1248
- * @returns {IBrowserClient} The client instance.
1249
- */
1250
- client(): IBrowserClient,
1251
- /**
1252
- * Returns a shared client of the SDK.
1253
- * @function client
1254
- * @param {SplitKey} key The key for the new client instance.
1255
- * @returns {IBrowserClient} The client instance.
1256
- */
1257
- client(key: SplitKey): IBrowserClient
1258
- /**
1259
- * Returns a manager instance of the SDK to explore available information.
1260
- * @function manager
1261
- * @returns {IManager} The manager instance.
1262
- */
1263
- manager(): IManager,
1264
- /**
1265
- * User consent API.
1266
- * @property UserConsent
1267
- */
1268
- UserConsent: IUserConsentAPI
1269
- }
1270
- /**
1271
- * This represents the interface for the SDK instance with asynchronous storage.
1272
- * @interface IAsyncSDK
1273
- * @extends IBasicSDK
1274
- */
1275
- interface IAsyncSDK extends IBasicSDK {
1276
- /**
1277
- * Returns the default client instance of the SDK.
1278
- * @function client
1279
- * @returns {IAsyncClient} The asynchronous client instance.
1280
- */
1281
- client(): IAsyncClient,
1282
- /**
1283
- * Returns a manager instance of the SDK to explore available information.
1284
- * @function manager
1285
- * @returns {IManager} The manager instance.
1286
- */
1287
- manager(): IAsyncManager
1288
- }
1289
- /**
1290
- * This represents the interface for the Client instance on server-side, where the user key is not bound to the instance and must be provided on each method call.
1291
- * This interface is available in NodeJS, or when importing the 'server' sub-package (e.g., `import { SplitFactory } from '@splitsoftware/splitio/server'`).
1292
- *
1293
- * @interface IClient
1294
- * @extends IBasicClient
1295
- */
1296
- interface IClient extends IBasicClient {
1297
- /**
1298
- * Returns a Treatment value, which is the treatment string for the given feature.
1299
- *
1300
- * @function getTreatment
1301
- * @param {string} key - The string key representing the consumer.
1302
- * @param {string} featureFlagName - The string that represents the feature flag we want to get the treatment.
1303
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1304
- * @returns {Treatment} The treatment string.
1305
- */
1306
- getTreatment(key: SplitKey, featureFlagName: string, attributes?: Attributes): Treatment,
1307
- /**
1308
- * Returns a TreatmentWithConfig value, which is an object with both treatment and config string for the given feature.
1309
- *
1310
- * @function getTreatmentWithConfig
1311
- * @param {string} key - The string key representing the consumer.
1312
- * @param {string} featureFlagName - The string that represents the feature flag we want to get the treatment.
1313
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1314
- * @returns {TreatmentWithConfig} The TreatmentWithConfig, the object containing the treatment string and the
1315
- * configuration stringified JSON (or null if there was no config for that treatment).
1316
- */
1317
- getTreatmentWithConfig(key: SplitKey, featureFlagName: string, attributes?: Attributes): TreatmentWithConfig,
1318
- /**
1319
- * Returns a Treatments value, which is an object map with the treatments for the given features.
1320
- *
1321
- * @function getTreatments
1322
- * @param {string} key - The string key representing the consumer.
1323
- * @param {Array<string>} featureFlagNames - An array of the feature flag names we want to get the treatments.
1324
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1325
- * @returns {Treatments} The treatments object map.
1326
- */
1327
- getTreatments(key: SplitKey, featureFlagNames: string[], attributes?: Attributes): Treatments,
1328
- /**
1329
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given features.
1330
- *
1331
- * @function getTreatmentsWithConfig
1332
- * @param {string} key - The string key representing the consumer.
1333
- * @param {Array<string>} featureFlagNames - An array of the feature flag names we want to get the treatments.
1334
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1335
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1336
- */
1337
- getTreatmentsWithConfig(key: SplitKey, featureFlagNames: string[], attributes?: Attributes): TreatmentsWithConfig,
1338
- /**
1339
- * Returns a Treatments value, which is an object map with the treatments for the feature flags related to the given flag set.
1340
- *
1341
- * @function getTreatmentsByFlagSet
1342
- * @param {string} key - The string key representing the consumer.
1343
- * @param {string} flagSet - The flag set name we want to get the treatments.
1344
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1345
- * @returns {Treatments} The map with all the Treatments objects
1346
- */
1347
- getTreatmentsByFlagSet(key: SplitKey, flagSet: string, attributes?: Attributes): Treatments,
1348
- /**
1349
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the feature flags related to the given flag set.
1350
- *
1351
- * @function getTreatmentsWithConfigByFlagSet
1352
- * @param {string} key - The string key representing the consumer.
1353
- * @param {string} flagSet - The flag set name we want to get the treatments.
1354
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1355
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1356
- */
1357
- getTreatmentsWithConfigByFlagSet(key: SplitKey, flagSet: string, attributes?: Attributes): TreatmentsWithConfig,
1358
- /**
1359
- * Returns a Returns a Treatments value, which is an object with both treatment and config string for to the feature flags related to the given flag sets.
1360
- *
1361
- * @function getTreatmentsByFlagSets
1362
- * @param {string} key - The string key representing the consumer.
1363
- * @param {Array<string>} flagSets - An array of the flag set names we want to get the treatments.
1364
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1365
- * @returns {Treatments} The map with all the Treatments objects
1366
- */
1367
- getTreatmentsByFlagSets(key: SplitKey, flagSets: string[], attributes?: Attributes): Treatments,
1368
- /**
1369
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the feature flags related to the given flag sets.
1370
- *
1371
- * @function getTreatmentsWithConfigByFlagSets
1372
- * @param {string} key - The string key representing the consumer.
1373
- * @param {Array<string>} flagSets - An array of the flag set names we want to get the treatments.
1374
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1375
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1376
- */
1377
- getTreatmentsWithConfigByFlagSets(key: SplitKey, flagSets: string[], attributes?: Attributes): TreatmentsWithConfig,
1378
- /**
1379
- * Tracks an event to be fed to the results product on Split user interface.
1380
- *
1381
- * @function track
1382
- * @param {SplitKey} key - The key that identifies the entity related to this event.
1383
- * @param {string} trafficType - The traffic type of the entity related to this event. See {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
1384
- * @param {string} eventType - The event type corresponding to this event.
1385
- * @param {number=} value - The value of this event.
1386
- * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null.
1387
- * @returns {boolean} Whether the event was added to the queue successfully or not.
1388
- */
1389
- track(key: SplitIO.SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): boolean,
1390
- }
1391
- /**
1392
- * This represents the interface for the Client instance on client-side, where the user key is bound to the instance on creation and does not need to be provided on each method call.
1393
- * This interface is the default when importing the SDK in the Browser, or when importing the 'client' sub-package (e.g., `import { SplitFactory } from '@splitsoftware/splitio/client'`).
1394
- *
1395
- * @interface IBrowserClient
1396
- * @extends IBasicClient
1397
- */
1398
- interface IBrowserClient extends IBasicClient {
1399
- /**
1400
- * Returns a Treatment value, which is the treatment string for the given feature.
1401
- *
1402
- * @function getTreatment
1403
- * @param {string} featureFlagName - The string that represents the feature flag we want to get the treatment.
1404
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1405
- * @returns {Treatment} The treatment string.
1406
- */
1407
- getTreatment(featureFlagName: string, attributes?: Attributes): Treatment,
1408
- /**
1409
- * Returns a TreatmentWithConfig value, which an object with both treatment and config string for the given feature.
1410
- *
1411
- * @function getTreatmentWithConfig
1412
- * @param {string} featureFlagName - The string that represents the feature flag we want to get the treatment.
1413
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1414
- * @returns {TreatmentWithConfig} The TreatmentWithConfig, the object containing the treatment string and the
1415
- * configuration stringified JSON (or null if there was no config for that treatment).
1416
- */
1417
- getTreatmentWithConfig(featureFlagName: string, attributes?: Attributes): TreatmentWithConfig,
1418
- /**
1419
- * Returns a Treatments value, which is an object map with the treatments for the given features.
1420
- *
1421
- * @function getTreatments
1422
- * @param {Array<string>} featureFlagNames - An array of the feature flags names we want to get the treatments.
1423
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1424
- * @returns {Treatments} The treatments object map.
1425
- */
1426
- getTreatments(featureFlagNames: string[], attributes?: Attributes): Treatments,
1427
- /**
1428
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given features.
1429
- *
1430
- * @function getTreatmentsWithConfig
1431
- * @param {Array<string>} featureFlagNames - An array of the feature flag names we want to get the treatments.
1432
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1433
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1434
- */
1435
- getTreatmentsWithConfig(featureFlagNames: string[], attributes?: Attributes): TreatmentsWithConfig,
1436
- /**
1437
- * Returns a Treatments value, which is an object map with the treatments for the feature flags related to the given flag set.
1438
- *
1439
- * @function getTreatmentsByFlagSet
1440
- * @param {string} flagSet - The flag set name we want to get the treatments.
1441
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1442
- * @returns {Treatments} The map with all the Treatments objects
1443
- */
1444
- getTreatmentsByFlagSet(flagSet: string, attributes?: Attributes): Treatments,
1445
- /**
1446
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the feature flags related to the given flag set.
1447
- *
1448
- * @function getTreatmentsWithConfigByFlagSet
1449
- * @param {string} flagSet - The flag set name we want to get the treatments.
1450
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1451
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1452
- */
1453
- getTreatmentsWithConfigByFlagSet(flagSet: string, attributes?: Attributes): TreatmentsWithConfig,
1454
- /**
1455
- * Returns a Returns a Treatments value, which is an object with both treatment and config string for to the feature flags related to the given flag sets.
1456
- *
1457
- * @function getTreatmentsByFlagSets
1458
- * @param {Array<string>} flagSets - An array of the flag set names we want to get the treatments.
1459
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1460
- * @returns {Treatments} The map with all the Treatments objects
1461
- */
1462
- getTreatmentsByFlagSets(flagSets: string[], attributes?: Attributes): Treatments,
1463
- /**
1464
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the feature flags related to the given flag sets.
1465
- *
1466
- * @function getTreatmentsWithConfigByFlagSets
1467
- * @param {Array<string>} flagSets - An array of the flag set names we want to get the treatments.
1468
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1469
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1470
- */
1471
- getTreatmentsWithConfigByFlagSets(flagSets: string[], attributes?: Attributes): TreatmentsWithConfig,
1472
- /**
1473
- * Tracks an event to be fed to the results product on Split user interface.
1474
- *
1475
- * @function track
1476
- * @param {string} trafficType - The traffic type of the entity related to this event. See {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
1477
- * @param {string} eventType - The event type corresponding to this event.
1478
- * @param {number=} value - The value of this event.
1479
- * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null.
1480
- * @returns {boolean} Whether the event was added to the queue successfully or not.
1481
- */
1482
- track(trafficType: string, eventType: string, value?: number, properties?: Properties): boolean,
1483
- /**
1484
- * Add an attribute to client's in memory attributes storage.
1485
- *
1486
- * @param {string} attributeName Attribute name
1487
- * @param {AttributeType} attributeValue Attribute value
1488
- * @returns {boolean} true if the attribute was stored and false otherwise
1489
- */
1490
- setAttribute(attributeName: string, attributeValue: AttributeType): boolean,
1491
- /**
1492
- * Returns the attribute with the given name.
1493
- *
1494
- * @param {string} attributeName Attribute name
1495
- * @returns {AttributeType} Attribute with the given name
1496
- */
1497
- getAttribute(attributeName: string): AttributeType,
1498
- /**
1499
- * Removes from client's in memory attributes storage the attribute with the given name.
1500
- *
1501
- * @param {string} attributeName
1502
- * @returns {boolean} true if attribute was removed and false otherwise
1503
- */
1504
- removeAttribute(attributeName: string): boolean,
1505
- /**
1506
- * Add to client's in memory attributes storage the attributes in 'attributes'.
1507
- *
1508
- * @param {Attributes} attributes Object with attributes to store
1509
- * @returns true if attributes were stored an false otherwise
1510
- */
1511
- setAttributes(attributes: Attributes): boolean,
1512
- /**
1513
- * Return all the attributes stored in client's in memory attributes storage.
1514
- *
1515
- * @returns {Attributes} returns all the stored attributes
1516
- */
1517
- getAttributes(): Attributes,
1518
- /**
1519
- * Remove all the stored attributes in the client's in memory attribute storage.
1520
- *
1521
- * @returns {boolean} true if all attribute were removed and false otherwise
1522
- */
1523
- clearAttributes(): boolean
1524
- }
1525
- /**
1526
- * This represents the interface for the Client instance on server-side with asynchronous storage, like REDIS.
1527
- * User key is not bound to the instance and must be provided on each method call, which returns a promise.
1528
- * This interface is available in NodeJS, or when importing the 'server' sub-package (e.g., `import { SplitFactory } from '@splitsoftware/splitio/server'`).
1529
- *
1530
- * @interface IAsyncClient
1531
- * @extends IBasicClient
1532
- */
1533
- interface IAsyncClient extends IBasicClient {
1534
- /**
1535
- * Returns a Treatment value, which will be (or eventually be) the treatment string for the given feature.
1536
- *
1537
- * @function getTreatment
1538
- * @param {string} key - The string key representing the consumer.
1539
- * @param {string} featureFlagName - The string that represents the feature flag we want to get the treatment.
1540
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1541
- * @returns {AsyncTreatment} Treatment promise that resolves to the treatment string.
1542
- */
1543
- getTreatment(key: SplitKey, featureFlagName: string, attributes?: Attributes): AsyncTreatment,
1544
- /**
1545
- * Returns a TreatmentWithConfig value, which will be (or eventually be) an object with both treatment and config string for the given feature.
1546
- *
1547
- * @function getTreatmentWithConfig
1548
- * @param {string} key - The string key representing the consumer.
1549
- * @param {string} featureFlagName - The string that represents the feature flag we want to get the treatment.
1550
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1551
- * @returns {AsyncTreatmentWithConfig} TreatmentWithConfig promise that resolves to the TreatmentWithConfig object.
1552
- */
1553
- getTreatmentWithConfig(key: SplitKey, featureFlagName: string, attributes?: Attributes): AsyncTreatmentWithConfig,
1554
- /**
1555
- * Returns a Treatments value, which will be (or eventually be) an object map with the treatments for the given features.
1556
- *
1557
- * @function getTreatments
1558
- * @param {string} key - The string key representing the consumer.
1559
- * @param {Array<string>} featureFlagNames - An array of the feature flag names we want to get the treatments.
1560
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1561
- * @returns {AsyncTreatments} Treatments promise that resolves to the treatments object map.
1562
- */
1563
- getTreatments(key: SplitKey, featureFlagNames: string[], attributes?: Attributes): AsyncTreatments,
1564
- /**
1565
- * Returns a TreatmentsWithConfig value, which will be (or eventually be) an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given features.
1566
- *
1567
- * @function getTreatmentsWithConfig
1568
- * @param {string} key - The string key representing the consumer.
1569
- * @param {Array<string>} featureFlagNames - An array of the feature flag names we want to get the treatments.
1570
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1571
- * @returns {AsyncTreatmentsWithConfig} TreatmentsWithConfig promise that resolves to the map of TreatmentsWithConfig objects.
1572
- */
1573
- getTreatmentsWithConfig(key: SplitKey, featureFlagNames: string[], attributes?: Attributes): AsyncTreatmentsWithConfig,
1574
- /**
1575
- * Returns a Treatments value, which is an object map with the treatments for the feature flags related to the given flag set.
1576
- *
1577
- * @function getTreatmentsByFlagSet
1578
- * @param {string} key - The string key representing the consumer.
1579
- * @param {string} flagSet - The flag set name we want to get the treatments.
1580
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1581
- * @returns {AsyncTreatments} Treatments promise that resolves to the treatments object map.
1582
- */
1583
- getTreatmentsByFlagSet(key: SplitKey, flagSet: string, attributes?: Attributes): AsyncTreatments,
1584
- /**
1585
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the feature flags related to the given flag set.
1586
- *
1587
- * @function getTreatmentsWithConfigByFlagSet
1588
- * @param {string} flagSet - The flag set name we want to get the treatments.
1589
- * @param {string} key - The string key representing the consumer.
1590
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1591
- * @returns {AsyncTreatmentsWithConfig} TreatmentsWithConfig promise that resolves to the TreatmentsWithConfig object.
1592
- */
1593
- getTreatmentsWithConfigByFlagSet(key: SplitKey, flagSet: string, attributes?: Attributes): AsyncTreatmentsWithConfig,
1594
- /**
1595
- * Returns a Returns a Treatments value, which is an object with both treatment and config string for to the feature flags related to the given flag sets.
1596
- *
1597
- * @function getTreatmentsByFlagSets
1598
- * @param {string} key - The string key representing the consumer.
1599
- * @param {Array<string>} flagSets - An array of the flag set names we want to get the treatments.
1600
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1601
- * @returns {AsyncTreatments} Treatments promise that resolves to the treatments object map.
1602
- */
1603
- getTreatmentsByFlagSets(key: SplitKey, flagSets: string[], attributes?: Attributes): AsyncTreatments,
1604
- /**
1605
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the feature flags related to the given flag sets.
1606
- *
1607
- * @function getTreatmentsWithConfigByFlagSets
1608
- * @param {string} key - The string key representing the consumer.
1609
- * @param {Array<string>} flagSets - An array of the flag set names we want to get the treatments.
1610
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1611
- * @returns {AsyncTreatmentsWithConfig} TreatmentsWithConfig promise that resolves to the TreatmentsWithConfig object.
1612
- */
1613
- getTreatmentsWithConfigByFlagSets(key: SplitKey, flagSets: string[], attributes?: Attributes): AsyncTreatmentsWithConfig,
1614
- /**
1615
- * Tracks an event to be fed to the results product on Split user interface, and returns a promise to signal when the event was successfully queued (or not).
1616
- *
1617
- * @function track
1618
- * @param {SplitKey} key - The key that identifies the entity related to this event.
1619
- * @param {string} trafficType - The traffic type of the entity related to this event. See {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
1620
- * @param {string} eventType - The event type corresponding to this event.
1621
- * @param {number=} value - The value of this event.
1622
- * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null.
1623
- * @returns {Promise<boolean>} A promise that resolves to a boolean indicating if the event was added to the queue successfully or not.
1624
- */
1625
- track(key: SplitIO.SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): Promise<boolean>
1626
- }
1627
- /**
1628
- * Representation of a manager instance with synchronous storage of the SDK.
1629
- * @interface IManager
1630
- * @extends IStatusInterface
1631
- */
1632
- interface IManager extends IStatusInterface {
1633
- /**
1634
- * Get the array of feature flag names.
1635
- * @function names
1636
- * @returns {SplitNames} The list of feature flag names.
1637
- */
1638
- names(): SplitNames;
1639
- /**
1640
- * Get the array of feature flags data in SplitView format.
1641
- * @function splits
1642
- * @returns {SplitViews} The list of SplitIO.SplitView.
1643
- */
1644
- splits(): SplitViews;
1645
- /**
1646
- * Get the data of a feature flag in SplitView format.
1647
- * @function split
1648
- * @param {string} featureFlagName The name of the feature flag we want to get info of.
1649
- * @returns {SplitView | null} The SplitIO.SplitView of the given feature flag name or null if the feature flag is not found.
1650
- */
1651
- split(featureFlagName: string): SplitView | null;
1652
- }
1653
- /**
1654
- * Representation of a manager instance with asynchronous storage of the SDK.
1655
- * @interface IAsyncManager
1656
- * @extends IStatusInterface
1657
- */
1658
- interface IAsyncManager extends IStatusInterface {
1659
- /**
1660
- * Get the array of feature flag names.
1661
- * @function names
1662
- * @returns {SplitNamesAsync} A promise that resolves to the list of feature flag names.
1663
- */
1664
- names(): SplitNamesAsync;
1665
- /**
1666
- * Get the array of feature flags data in SplitView format.
1667
- * @function splits
1668
- * @returns {SplitViewsAsync} A promise that resolves to the SplitIO.SplitView list.
1669
- */
1670
- splits(): SplitViewsAsync;
1671
- /**
1672
- * Get the data of a feature flag in SplitView format.
1673
- * @function split
1674
- * @param {string} featureFlagName The name of the feature flag we want to get info of.
1675
- * @returns {SplitViewAsync} A promise that resolves to the SplitIO.SplitView value.
1676
- */
1677
- split(featureFlagName: string): SplitViewAsync;
1678
- }
1679
- }