@splitsoftware/splitio 10.21.2-rc.1 → 10.21.2-rc.2

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