@splitsoftware/splitio-browserjs 0.8.0 → 0.8.1-rc.0

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