@splitsoftware/splitio-browserjs 0.7.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,883 +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/360058730852-Browser-SDK#integrations}
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
- /**
674
- * Object representing the data sent by Split (events and impressions).
675
- * @typedef {Object} IntegrationData
676
- * @property {string} type The type of Split data, either 'IMPRESSION' or 'EVENT'.
677
- * @property {ImpressionData | EventData} payload The data instance itself.
678
- */
679
- type IntegrationData = { type: 'IMPRESSION', payload: SplitIO.ImpressionData } | { type: 'EVENT', payload: SplitIO.EventData };
680
- /**
681
- * Configuration params for 'Split to Google Analytics' integration plugin, to track Split impressions and events as Google Analytics hits.
682
- *
683
- * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#integrations}
684
- */
685
- interface SplitToGoogleAnalyticsOptions {
686
- /**
687
- * Optional flag to filter Split impressions from being tracked as GA hits.
688
- * @property {boolean} impressions
689
- * @default true
690
- */
691
- impressions?: boolean,
692
- /**
693
- * Optional flag to filter Split events from being tracked as GA hits.
694
- * @property {boolean} events
695
- * @default true
696
- */
697
- events?: boolean,
698
- /**
699
- * Optional predicate used to define a custom filter for tracking Split data (events and impressions) as GA hits.
700
- * For example, the following filter allows to track only impressions, equivalent to setting events to false:
701
- * `(data) => data.type === 'IMPRESSION'`
702
- */
703
- filter?: (data: SplitIO.IntegrationData) => boolean,
704
- /**
705
- * Optional function useful when you need to modify the GA hit before sending it.
706
- * This function is invoked with two arguments:
707
- * 1. the input data (Split event or impression).
708
- * 2. the default format of the mapped FieldsObject instance (GA hit).
709
- * The return value must be a FieldsObject, that can be the second argument or a new object.
710
- *
711
- * For example, the following mapper adds a custom dimension to hits:
712
- * `(data, defaultMapping) => {
713
- * defaultMapping.dimension1 = SOME_VALUE;
714
- * return defaultMapping;
715
- * }`
716
- *
717
- * Default FieldsObject instance for data.type === 'IMPRESSION':
718
- * `{
719
- * hitType: 'event',
720
- * eventCategory: 'split-impression',
721
- * eventAction: 'Evaluate ' + data.payload.impression.feature,
722
- * eventLabel: 'Treatment: ' + data.payload.impression.treatment + '. Targeting rule: ' + data.payload.impression.label + '.',
723
- * nonInteraction: true,
724
- * }`
725
- * Default FieldsObject instance for data.type === 'EVENT':
726
- * `{
727
- * hitType: 'event',
728
- * eventCategory: 'split-event',
729
- * eventAction: data.payload.eventTypeId,
730
- * eventValue: data.payload.value,
731
- * nonInteraction: true,
732
- * }`
733
- */
734
- mapper?: (data: SplitIO.IntegrationData, defaultMapping: UniversalAnalytics.FieldsObject) => UniversalAnalytics.FieldsObject,
735
- /**
736
- * List of tracker names to send the hit. An empty string represents the default tracker.
737
- * If not provided, hits are only sent to default tracker.
738
- */
739
- trackerNames?: string[],
740
- }
741
- /**
742
- * Available URL settings for the SDKs.
743
- */
744
- type UrlSettings = {
745
- /**
746
- * String property to override the base URL where the SDK will get feature flagging related data like a Split rollout plan or segments information.
747
- * @property {string} sdk
748
- * @default 'https://sdk.split.io/api'
749
- */
750
- sdk?: string,
751
- /**
752
- * String property to override the base URL where the SDK will post event-related information like impressions.
753
- * @property {string} events
754
- * @default 'https://events.split.io/api'
755
- */
756
- events?: string,
757
- /**
758
- * String property to override the base URL where the SDK will get authorization tokens to be used with functionality that requires it, like streaming.
759
- * @property {string} auth
760
- * @default 'https://auth.split.io/api'
761
- */
762
- auth?: string,
763
- /**
764
- * String property to override the base URL where the SDK will connect to receive streaming updates.
765
- * @property {string} streaming
766
- * @default 'https://streaming.split.io'
767
- */
768
- streaming?: string,
769
- /**
770
- * String property to override the base URL where the SDK will post telemetry data.
771
- * @property {string} telemetry
772
- * @default 'https://telemetry.split.io/api'
773
- */
774
- telemetry?: string
775
- };
776
-
777
- /**
778
- * SplitFilter type.
779
- * @typedef {string} SplitFilterType
780
- */
781
- type SplitFilterType = 'byName' | 'byPrefix';
782
- /**
783
- * Defines a split filter, described by a type and list of values.
784
- */
785
- interface SplitFilter {
786
- /**
787
- * Type of the filter.
788
- * @property {SplitFilterType} type
789
- */
790
- type: SplitFilterType,
791
- /**
792
- * List of values: split names for 'byName' filter type, and split prefixes for 'byPrefix' type.
793
- * @property {string[]} values
794
- */
795
- values: string[],
796
- }
797
- /**
798
- * ImpressionsMode type
799
- * @typedef {string} ImpressionsMode
800
- */
801
- type ImpressionsMode = 'OPTIMIZED' | 'DEBUG';
802
- /**
803
- * User consent status.
804
- * @typedef {string} ConsentStatus
805
- */
806
- type ConsentStatus = 'GRANTED' | 'DECLINED' | 'UNKNOWN';
807
- /**
808
- * Logger
809
- * Its interface details are not part of the public API. It shouldn't be used directly.
810
- * @interface ILogger
811
- */
812
- interface ILogger {
813
- setLogLevel(logLevel: LogLevel): void
814
- }
815
- /**
816
- * Common settings interface for SDK instances created on the browser.
817
- * @interface IBrowserBasicSettings
818
- * @extends ISharedSettings
819
- */
820
- interface IBrowserBasicSettings extends ISharedSettings {
821
- /**
822
- * SDK Core settings for the browser.
823
- * @property {Object} core
824
- */
825
- core: {
826
- /**
827
- * Your API key. More information: @see {@link https://help.split.io/hc/en-us/articles/360019916211-API-keys}
828
- * @property {string} authorizationKey
829
- */
830
- authorizationKey: string,
831
- /**
832
- * Customer identifier. Whatever this means to you. @see {@link https://help.split.io/hc/en-us/articles/360019916311-Traffic-type}
833
- * @property {SplitKey} key
834
- */
835
- key: SplitKey,
836
- /**
837
- * Disable labels from being sent to Split backend. Labels may contain sensitive information.
838
- * @property {boolean} labelsEnabled
839
- * @default true
840
- */
841
- labelsEnabled?: boolean
842
- },
843
- /**
844
- * List of URLs that the SDK will use as base for it's synchronization functionalities, applicable only when running as standalone.
845
- * Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy.
846
- * @property {Object} urls
847
- */
848
- urls?: UrlSettings,
849
- /**
850
- * Defines an optional list of factory functions used to instantiate SDK integrations.
851
- *
852
- * Example:
853
- * ```typescript
854
- * SplitFactory({
855
- * ...
856
- * integrations: [SplitToGoogleAnalytics(), GoogleAnalyticsToSplit()]
857
- * })
858
- * ```
859
- * @property {Object} integrations
860
- */
861
- integrations?: IntegrationFactory[],
862
- /**
863
- * User consent status. Possible values are `'GRANTED'`, which is the default, `'DECLINED'` or `'UNKNOWN'`.
864
- * - `'GRANTED'`: the user grants consent for tracking events and impressions. The SDK sends them to Split cloud.
865
- * - `'DECLINED'`: the user declines consent for tracking events and impressions. The SDK does not send them to Split cloud.
866
- * - `'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
867
- * 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.
868
- *
869
- * @typedef {string} userConsent
870
- * @default 'GRANTED'
871
- */
872
- userConsent?: ConsentStatus
873
- }
874
- /**
875
- * 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.
876
16
  * @interface IBrowserSettings
877
- * @extends ISharedSettings
878
17
  * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#configuration}
879
18
  */
880
- interface IBrowserSettings extends IBrowserBasicSettings {
19
+ interface IBrowserSettings extends IClientSideSharedSettings, IPluggableSettings {
881
20
  /**
882
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.
883
22
  * For "localhost" mode, use "localhost" as authorizationKey.
@@ -886,11 +25,27 @@ declare namespace SplitIO {
886
25
  * @default standalone
887
26
  */
888
27
  mode?: 'standalone',
889
- /**
890
- * Mocked features map. For testing purposses only. For using this you should specify "localhost" as authorizationKey on core settings.
891
- * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#localhost-mode}
892
- */
893
- 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
+ },
894
49
  /**
895
50
  * Defines the factory function to instantiate the storage. If not provided, the default IN MEMORY storage is used.
896
51
  *
@@ -903,112 +58,28 @@ declare namespace SplitIO {
903
58
  * ```
904
59
  * @property {Object} storage
905
60
  */
906
- storage?: StorageSyncFactory,
907
- /**
908
- * SDK Startup settings for the Browser.
909
- * @property {Object} startup
910
- */
911
- startup?: {
912
- /**
913
- * Maximum amount of time used before notify a timeout.
914
- * @property {number} readyTimeout
915
- * @default 1.5
916
- */
917
- readyTimeout?: number,
918
- /**
919
- * 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'.
920
- * @property {number} requestTimeoutBeforeReady
921
- * @default 1.5
922
- */
923
- requestTimeoutBeforeReady?: number,
924
- /**
925
- * How many quick retries we will do while starting up the SDK.
926
- * @property {number} retriesOnFailureBeforeReady
927
- * @default 1
928
- */
929
- retriesOnFailureBeforeReady?: number,
930
- /**
931
- * For SDK posts the queued events data in bulks with a given rate, but the first push window is defined separately,
932
- * to better control on browsers. This number defines that window before the first events push.
933
- *
934
- * @property {number} eventsFirstPushWindow
935
- * @default 10
936
- */
937
- eventsFirstPushWindow?: number,
938
- },
61
+ storage?: SplitIO.StorageSyncFactory,
939
62
  /**
940
- * SDK scheduler settings.
941
- * @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
942
73
  */
943
- scheduler?: {
944
- /**
945
- * The SDK polls Split servers for changes to feature roll-out plans. This parameter controls this polling period in seconds.
946
- * @property {number} featuresRefreshRate
947
- * @default 30
948
- */
949
- featuresRefreshRate?: number,
950
- /**
951
- * 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.
952
- * @property {number} impressionsRefreshRate
953
- * @default 60
954
- */
955
- impressionsRefreshRate?: number,
956
- /**
957
- * The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
958
- * If you use a 0 here, the queue will have no maximum size.
959
- * @property {number} impressionsQueueSize
960
- * @default 30000
961
- */
962
- impressionsQueueSize?: number,
963
- /**
964
- * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
965
- * @property {number} telemetryRefreshRate
966
- * @default 3600
967
- */
968
- telemetryRefreshRate?: number,
969
- /**
970
- * The SDK polls Split servers for changes to segment definitions. This parameter controls this polling period in seconds.
971
- * @property {number} segmentsRefreshRate
972
- * @default 60
973
- */
974
- segmentsRefreshRate?: number,
975
- /**
976
- * The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
977
- * @property {number} eventsPushRate
978
- * @default 60
979
- */
980
- eventsPushRate?: number,
981
- /**
982
- * The maximum number of event items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
983
- * If you use a 0 here, the queue will have no maximum size.
984
- * @property {number} eventsQueueSize
985
- * @default 500
986
- */
987
- eventsQueueSize?: number,
988
- /**
989
- * For mocking/testing only. The SDK will refresh the features mocked data when mode is set to "localhost" by defining the key.
990
- * For more information @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#localhost-mode}
991
- * @property {number} offlineRefreshRate
992
- * @default 15
993
- */
994
- offlineRefreshRate?: number,
995
- /**
996
- * When using streaming mode, seconds to wait before re attempting to connect for push notifications.
997
- * Next attempts follow intervals in power of two: base seconds, base x 2 seconds, base x 4 seconds, ...
998
- * @property {number} pushRetryBackoffBase
999
- * @default 1
1000
- */
1001
- pushRetryBackoffBase?: number,
1002
- }
74
+ integrations?: IntegrationFactory[],
1003
75
  }
1004
76
  /**
1005
77
  * Settings interface with async storage for SDK instances created on the browser.
1006
78
  * If your storage is synchronous (by defaut we use memory, which is sync) use SplitIO.IBrowserSettings instead.
1007
79
  * @interface IBrowserAsyncSettings
1008
- * @extends IBrowserBasicSettings
1009
80
  * @see {@link https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK#configuration}
1010
81
  */
1011
- interface IBrowserAsyncSettings extends IBrowserBasicSettings {
82
+ interface IBrowserAsyncSettings extends IClientSideSharedSettings, IPluggableSettings {
1012
83
  /**
1013
84
  * The SDK mode. When using `PluggableStorage` as storage, the possible values are "consumer" and "consumer_partial".
1014
85
  *
@@ -1030,79 +101,18 @@ declare namespace SplitIO {
1030
101
  * @property {Object} storage
1031
102
  */
1032
103
  storage: StorageAsyncFactory,
1033
- /**
1034
- * SDK Startup settings for the Browser.
1035
- * @property {Object} startup
1036
- */
1037
- startup?: {
1038
- /**
1039
- * Maximum amount of time used before notify a timeout.
1040
- * @property {number} readyTimeout
1041
- * @default 1.5
1042
- */
1043
- readyTimeout?: number,
1044
- /**
1045
- * For SDK posts the queued events data in bulks with a given rate, but the first push window is defined separately,
1046
- * to better control on browsers. This number defines that window before the first events push.
1047
- *
1048
- * NOTE: this param is ignored in 'consumer' mode.
1049
- * @property {number} eventsFirstPushWindow
1050
- * @default 10
1051
- */
1052
- eventsFirstPushWindow?: number,
1053
- },
1054
- /**
1055
- * SDK scheduler settings.
1056
- * @property {Object} scheduler
1057
- */
1058
- scheduler?: {
1059
- /**
1060
- * 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.
1061
- *
1062
- * NOTE: this param is ignored in 'consumer' mode.
1063
- * @property {number} impressionsRefreshRate
1064
- * @default 60
1065
- */
1066
- impressionsRefreshRate?: number,
1067
- /**
1068
- * The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
1069
- * If you use a 0 here, the queue will have no maximum size.
1070
- * @property {number} impressionsQueueSize
1071
- * @default 30000
1072
- */
1073
- impressionsQueueSize?: number,
1074
- /**
1075
- * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
1076
- * @property {number} telemetryRefreshRate
1077
- * @default 3600
1078
- */
1079
- telemetryRefreshRate?: number,
1080
- /**
1081
- * The SDK posts the queued events data in bulks. This parameter controls the posting rate in seconds.
1082
- *
1083
- * NOTE: this param is ignored in 'consumer' mode.
1084
- * @property {number} eventsPushRate
1085
- * @default 60
1086
- */
1087
- eventsPushRate?: number,
1088
- /**
1089
- * The maximum number of event items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
1090
- * If you use a 0 here, the queue will have no maximum size.
1091
- *
1092
- * NOTE: this param is ignored in 'consumer' mode.
1093
- * @property {number} eventsQueueSize
1094
- * @default 500
1095
- */
1096
- eventsQueueSize?: number,
1097
- }
1098
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 { }
1099
111
  /**
1100
- * This represents the interface for the SDK instance with synchronous storage and client-side API,
1101
- * 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.
1102
113
  * @interface ISDK
1103
- * @extends IBasicSDK
1104
114
  */
1105
- interface ISDK extends IBasicSDK {
115
+ interface ISDK extends ISDKWithUserConsent<IClient, IManager> {
1106
116
  /**
1107
117
  * Returns the default client instance of the SDK, associated with the key provided on settings.
1108
118
  * @function client
@@ -1116,20 +126,17 @@ declare namespace SplitIO {
1116
126
  * @returns {IClient} The client instance.
1117
127
  */
1118
128
  client(key: SplitKey): IClient,
1119
- /**
1120
- * Returns a manager instance of the SDK to explore available information.
1121
- * @function manager
1122
- * @returns {IManager} The manager instance.
1123
- */
1124
- manager(): IManager
1125
129
  }
1126
130
  /**
1127
- * This represents the interface for the SDK instance with asynchronous storage and client-side API,
1128
- * 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.
1129
137
  * @interface IAsyncSDK
1130
- * @extends IBasicSDK
1131
138
  */
1132
- interface IAsyncSDK extends IBasicSDK {
139
+ interface IAsyncSDK extends ISDKWithUserConsent<IAsyncClient, IAsyncManager> {
1133
140
  /**
1134
141
  * Returns the default client instance of the SDK, associated with the key provided on settings.
1135
142
  * @function client
@@ -1143,358 +150,5 @@ declare namespace SplitIO {
1143
150
  * @returns {IAsyncClient} The asynchronous client instance.
1144
151
  */
1145
152
  client(key: SplitKey): IAsyncClient,
1146
- /**
1147
- * Returns a manager instance of the SDK to explore available information.
1148
- * @function manager
1149
- * @returns {IManager} The manager instance.
1150
- */
1151
- manager(): IAsyncManager
1152
- }
1153
- /**
1154
- * This represents the interface for the Client instance with synchronous storage for server-side SDK, where we don't have only one key.
1155
- * @interface IClient
1156
- * @extends IBasicClient
1157
- */
1158
- interface IClientSS extends IBasicClient {
1159
- /**
1160
- * Returns a Treatment value, which is the treatment string for the given feature.
1161
- * @function getTreatment
1162
- * @param {string} key - The string key representing the consumer.
1163
- * @param {string} splitName - The string that represents the split we wan't to get the treatment.
1164
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1165
- * @returns {Treatment} The treatment string.
1166
- */
1167
- getTreatment(key: SplitKey, splitName: string, attributes?: Attributes): Treatment,
1168
- /**
1169
- * Returns a TreatmentWithConfig value, which is an object with both treatment and config string for the given feature.
1170
- * @function getTreatmentWithConfig
1171
- * @param {string} key - The string key representing the consumer.
1172
- * @param {string} splitName - The string that represents the split we wan't to get the treatment.
1173
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1174
- * @returns {TreatmentWithConfig} The TreatmentWithConfig, the object containing the treatment string and the
1175
- * configuration stringified JSON (or null if there was no config for that treatment).
1176
- */
1177
- getTreatmentWithConfig(key: SplitKey, splitName: string, attributes?: Attributes): TreatmentWithConfig,
1178
- /**
1179
- * Returns a Treatments value, which is an object map with the treatments for the given features.
1180
- * @function getTreatments
1181
- * @param {string} key - The string key representing the consumer.
1182
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1183
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1184
- * @returns {Treatments} The treatments object map.
1185
- */
1186
- getTreatments(key: SplitKey, splitNames: string[], attributes?: Attributes): Treatments,
1187
- /**
1188
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given features.
1189
- * @function getTreatmentsWithConfig
1190
- * @param {string} key - The string key representing the consumer.
1191
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1192
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1193
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1194
- */
1195
- getTreatmentsWithConfig(key: SplitKey, splitNames: string[], attributes?: Attributes): TreatmentsWithConfig,
1196
- /**
1197
- * Tracks an event to be fed to the results product on Split Webconsole.
1198
- * @function track
1199
- * @param {SplitKey} key - The key that identifies the entity related to this event.
1200
- * @param {string} trafficType - The traffic type of the entity related to this event.
1201
- * @param {string} eventType - The event type corresponding to this event.
1202
- * @param {number=} value - The value of this event.
1203
- * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null.
1204
- * @returns {boolean} Whether the event was added to the queue successfully or not.
1205
- */
1206
- track(key: SplitIO.SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): boolean,
1207
- }
1208
- /**
1209
- * This represents the interface for the Client instance with asynchronous storage for server-side SDK, where we don't have only one key.
1210
- * @interface IAsyncClient
1211
- * @extends IBasicClient
1212
- */
1213
- interface IAsyncClientSS extends IBasicClient {
1214
- /**
1215
- * Returns a Treatment value, which will be (or eventually be) the treatment string for the given feature.
1216
- * For usage on NodeJS as we don't have only one key.
1217
- * NOTE: Treatment will be a promise only in async storages, like REDIS.
1218
- * @function getTreatment
1219
- * @param {string} key - The string key representing the consumer.
1220
- * @param {string} splitName - The string that represents the split we wan't to get the treatment.
1221
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1222
- * @returns {AsyncTreatment} Treatment promise which will resolve to the treatment string.
1223
- */
1224
- getTreatment(key: SplitKey, splitName: string, attributes?: Attributes): AsyncTreatment,
1225
- /**
1226
- * Returns a TreatmentWithConfig value, which will be (or eventually be) an object with both treatment and config 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 getTreatmentWithConfig
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 {AsyncTreatmentWithConfig} TreatmentWithConfig promise which will resolve to the TreatmentWithConfig object.
1234
- */
1235
- getTreatmentWithConfig(key: SplitKey, splitName: string, attributes?: Attributes): AsyncTreatmentWithConfig,
1236
- /**
1237
- * Returns a Treatments value, which will be (or eventually be) an object map with the treatments for the given features.
1238
- * For usage on NodeJS as we don't have only one key.
1239
- * @function getTreatments
1240
- * @param {string} key - The string key representing the consumer.
1241
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1242
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1243
- * @returns {AsyncTreatments} Treatments promise which will resolve to the treatments object map.
1244
- */
1245
- getTreatments(key: SplitKey, splitNames: string[], attributes?: Attributes): AsyncTreatments,
1246
- /**
1247
- * 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.
1248
- * For usage on NodeJS as we don't have only one key.
1249
- * @function getTreatmentsWithConfig
1250
- * @param {string} key - The string key representing the consumer.
1251
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1252
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1253
- * @returns {AsyncTreatmentsWithConfig} TreatmentsWithConfig promise which will resolve to the map of TreatmentsWithConfig objects.
1254
- */
1255
- getTreatmentsWithConfig(key: SplitKey, splitNames: string[], attributes?: Attributes): AsyncTreatmentsWithConfig,
1256
- /**
1257
- * 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).
1258
- * @function track
1259
- * @param {SplitKey} key - The key that identifies the entity related to this event.
1260
- * @param {string} trafficType - The traffic type of the entity related to this event.
1261
- * @param {string} eventType - The event type corresponding to this event.
1262
- * @param {number=} value - The value of this event.
1263
- * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null.
1264
- * @returns {Promise<boolean>} A promise that resolves to a boolean indicating if the event was added to the queue successfully or not.
1265
- */
1266
- track(key: SplitIO.SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): Promise<boolean>
1267
- }
1268
- /**
1269
- * This represents the interface for the Client instance with synchronous storage for client-side SDK, where each client has associated a key.
1270
- * @interface IClient
1271
- * @extends IBasicClient
1272
- */
1273
- interface IClient extends IBasicClient {
1274
- /**
1275
- * Returns a Treatment value, which is the treatment string for the given feature.
1276
- * @function getTreatment
1277
- * @param {string} splitName - The string that represents the split we wan't to get the treatment.
1278
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1279
- * @returns {Treatment} The treatment string.
1280
- */
1281
- getTreatment(splitName: string, attributes?: Attributes): Treatment,
1282
- /**
1283
- * Returns a TreatmentWithConfig value, which is an object with both treatment and config string for the given feature.
1284
- * @function getTreatmentWithConfig
1285
- * @param {string} splitName - The string that represents the split we wan't to get the treatment.
1286
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1287
- * @returns {TreatmentWithConfig} The map containing the treatment and the configuration stringified JSON (or null if there was no config for that treatment).
1288
- */
1289
- getTreatmentWithConfig(splitName: string, attributes?: Attributes): TreatmentWithConfig,
1290
- /**
1291
- * Returns a Treatments value, which is an object map with the treatments for the given features.
1292
- * @function getTreatments
1293
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1294
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1295
- * @returns {Treatments} The treatments object map.
1296
- */
1297
- getTreatments(splitNames: string[], attributes?: Attributes): Treatments,
1298
- /**
1299
- * Returns a TreatmentsWithConfig value, which is an object map with the TreatmentWithConfig (an object with both treatment and config string) for the given features.
1300
- * @function getTreatmentsWithConfig
1301
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1302
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1303
- * @returns {TreatmentsWithConfig} The map with all the TreatmentWithConfig objects
1304
- */
1305
- getTreatmentsWithConfig(splitNames: string[], attributes?: Attributes): TreatmentsWithConfig,
1306
- /**
1307
- * Tracks an event to be fed to the results product on Split Webconsole.
1308
- * @function track
1309
- * @param {string} trafficType - The traffic type of the entity related to this event.
1310
- * @param {string} eventType - The event type corresponding to this event.
1311
- * @param {number=} value - The value of this event.
1312
- * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null.
1313
- * @returns {boolean} Whether the event was added to the queue successfully or not.
1314
- */
1315
- track(trafficType: string, eventType: string, value?: number, properties?: Properties): boolean,
1316
- /**
1317
- * Add an attribute to client's in memory attributes storage.
1318
- *
1319
- * @param {string} attributeName Attribute name
1320
- * @param {AttributeType} attributeValue Attribute value
1321
- * @returns {boolean} true if the attribute was stored and false otherwise
1322
- */
1323
- setAttribute(attributeName: string, attributeValue: AttributeType): boolean,
1324
- /**
1325
- * Returns the attribute with the given key.
1326
- *
1327
- * @param {string} attributeName Attribute name
1328
- * @returns {AttributeType} Attribute with the given key
1329
- */
1330
- getAttribute(attributeName: string): AttributeType,
1331
- /**
1332
- * Removes from client's in memory attributes storage the attribute with the given key.
1333
- *
1334
- * @param {string} attributeName
1335
- * @returns {boolean} true if attribute was removed and false otherwise
1336
- */
1337
- removeAttribute(attributeName: string): boolean,
1338
- /**
1339
- * Add to client's in memory attributes storage the attributes in 'attributes'.
1340
- *
1341
- * @param {Attributes} attributes Object with attributes to store
1342
- * @returns true if attributes were stored an false otherwise
1343
- */
1344
- setAttributes(attributes: Attributes): boolean,
1345
- /**
1346
- * Return all the attributes stored in client's in memory attributes storage.
1347
- *
1348
- * @returns {Attributes} returns all the stored attributes
1349
- */
1350
- getAttributes(): Attributes,
1351
- /**
1352
- * Remove all the stored attributes in the client's in memory attribute storage.
1353
- *
1354
- * @returns {boolean} true if all attribute were removed and false otherwise
1355
- */
1356
- clearAttributes(): boolean
1357
- }
1358
- /**
1359
- * This represents the interface for the Client instance with asynchronous storage for client-side SDK, where each client has associated a key.
1360
- * @interface IAsyncClient
1361
- * @extends IBasicClient
1362
- */
1363
- interface IAsyncClient extends IBasicClient {
1364
- /**
1365
- * Returns a Treatment value, which will be (or eventually be) the treatment string for the given feature.
1366
- * @function getTreatment
1367
- * @param {string} splitName - The string that represents the split we wan't to get the treatment.
1368
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1369
- * @returns {AsyncTreatment} Treatment promise which will resolve to the treatment string.
1370
- */
1371
- getTreatment(splitName: string, attributes?: Attributes): AsyncTreatment,
1372
- /**
1373
- * Returns a TreatmentWithConfig value, which will be (or eventually be) an object with both treatment and config string for the given feature.
1374
- * @function getTreatmentWithConfig
1375
- * @param {string} splitName - The string that represents the split we wan't to get the treatment.
1376
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1377
- * @returns {AsyncTreatmentWithConfig} TreatmentWithConfig promise which will resolve to the TreatmentWithConfig object.
1378
- */
1379
- getTreatmentWithConfig(splitName: string, attributes?: Attributes): AsyncTreatmentWithConfig,
1380
- /**
1381
- * Returns a Treatments value, which will be (or eventually be) an object map with the treatments for the given features.
1382
- * @function getTreatments
1383
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1384
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1385
- * @returns {AsyncTreatments} Treatments promise which will resolve to the treatments object map.
1386
- */
1387
- getTreatments(splitNames: string[], attributes?: Attributes): AsyncTreatments,
1388
- /**
1389
- * 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.
1390
- * @function getTreatmentsWithConfig
1391
- * @param {Array<string>} splitNames - An array of the split names we wan't to get the treatments.
1392
- * @param {Attributes=} attributes - An object of type Attributes defining the attributes for the given key.
1393
- * @returns {TreatmentsWithConfig} TreatmentsWithConfig promise which will resolve to the map of TreatmentsWithConfig objects.
1394
- */
1395
- getTreatmentsWithConfig(splitNames: string[], attributes?: Attributes): AsyncTreatmentsWithConfig,
1396
- /**
1397
- * 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).
1398
- * @function track
1399
- * @param {string} trafficType - The traffic type of the entity related to this event.
1400
- * @param {string} eventType - The event type corresponding to this event.
1401
- * @param {number=} value - The value of this event.
1402
- * @param {Properties=} properties - The properties of this event. Values can be string, number, boolean or null.
1403
- * @returns {boolean} A promise that resolves to a boolean indicating if the event was added to the queue successfully or not.
1404
- */
1405
- track(trafficType: string, eventType: string, value?: number, properties?: Properties): Promise<boolean>,
1406
- /**
1407
- * Add an attribute to client's in memory attributes storage.
1408
- *
1409
- * @param {string} attributeName Attribute name
1410
- * @param {AttributeType} attributeValue Attribute value
1411
- * @returns {boolean} true if the attribute was stored and false otherwise
1412
- */
1413
- setAttribute(attributeName: string, attributeValue: AttributeType): boolean,
1414
- /**
1415
- * Returns the attribute with the given key.
1416
- *
1417
- * @param {string} attributeName Attribute name
1418
- * @returns {AttributeType} Attribute with the given key
1419
- */
1420
- getAttribute(attributeName: string): AttributeType,
1421
- /**
1422
- * Removes from client's in memory attributes storage the attribute with the given key.
1423
- *
1424
- * @param {string} attributeName
1425
- * @returns {boolean} true if attribute was removed and false otherwise
1426
- */
1427
- removeAttribute(attributeName: string): boolean,
1428
- /**
1429
- * Add to client's in memory attributes storage the attributes in 'attributes'.
1430
- *
1431
- * @param {Attributes} attributes Object with attributes to store
1432
- * @returns true if attributes were stored an false otherwise
1433
- */
1434
- setAttributes(attributes: Attributes): boolean,
1435
- /**
1436
- * Return all the attributes stored in client's in memory attributes storage.
1437
- *
1438
- * @returns {Attributes} returns all the stored attributes
1439
- */
1440
- getAttributes(): Attributes,
1441
- /**
1442
- * Remove all the stored attributes in the client's in memory attribute storage.
1443
- *
1444
- * @returns {boolean} true if all attribute were removed and false otherwise
1445
- */
1446
- clearAttributes(): boolean
1447
- }
1448
- /**
1449
- * Representation of a manager instance with synchronous storage of the SDK.
1450
- * @interface IManager
1451
- * @extends IStatusInterface
1452
- */
1453
- interface IManager extends IStatusInterface {
1454
- /**
1455
- * Get the array of Split names.
1456
- * @function names
1457
- * @returns {SplitNames} The lists of Split names.
1458
- */
1459
- names(): SplitNames,
1460
- /**
1461
- * Get the array of splits data in SplitView format.
1462
- * @function splits
1463
- * @returns {SplitViews} The list of SplitIO.SplitView.
1464
- */
1465
- splits(): SplitViews,
1466
- /**
1467
- * Get the data of a split in SplitView format.
1468
- * @function split
1469
- * @param {string} splitName The name of the split we wan't to get info of.
1470
- * @returns {SplitView} The SplitIO.SplitView of the given split.
1471
- */
1472
- split(splitName: string): SplitView,
1473
- }
1474
- /**
1475
- * Representation of a manager instance with asynchronous storage of the SDK.
1476
- * @interface IAsyncManager
1477
- * @extends IStatusInterface
1478
- */
1479
- interface IAsyncManager extends IStatusInterface {
1480
- /**
1481
- * Get the array of Split names.
1482
- * @function names
1483
- * @returns {SplitNamesAsync} A promise that will resolve to the array of Splitio.SplitNames.
1484
- */
1485
- names(): SplitNamesAsync,
1486
- /**
1487
- * Get the array of splits data in SplitView format.
1488
- * @function splits
1489
- * @returns {SplitViewsAsync} A promise that will resolve to the SplitIO.SplitView list.
1490
- */
1491
- splits(): SplitViewsAsync,
1492
- /**
1493
- * Get the data of a split in SplitView format.
1494
- * @function split
1495
- * @param {string} splitName The name of the split we wan't to get info of.
1496
- * @returns {SplitViewAsync} A promise that will resolve to the SplitIO.SplitView value.
1497
- */
1498
- split(splitName: string): SplitViewAsync,
1499
153
  }
1500
154
  }