This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
index.d.ts
2426 lines (2239 loc) · 93.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Type definitions for launchdarkly-node-server-sdk
/**
* This is the API reference for the LaunchDarkly Server-Side SDK for Node.js.
*
* In typical usage, you will call [[init]] once at startup time to obtain an instance of
* [[LDClient]], which provides access to all of the SDK's functionality.
*
* For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/server-side/node-js).
*/
declare module 'launchdarkly-node-server-sdk' {
import { EventEmitter } from 'events';
import * as interfaces from 'launchdarkly-node-server-sdk/interfaces';
namespace errors {
export const LDPollingError: ErrorConstructor;
export const LDStreamingError: ErrorConstructor;
export const LDClientError: ErrorConstructor;
export const LDUnexpectedResponseError: ErrorConstructor;
export const LDInvalidSDKKeyError: ErrorConstructor;
}
/**
* Creates an instance of the LaunchDarkly client.
*
* Applications should instantiate a single instance for the lifetime of the application.
* The client will begin attempting to connect to LaunchDarkly as soon as it is created. To
* determine when it is ready to use, call [[LDClient.waitForInitialization]], or register an
* event listener for the `"ready"` event using [[LDClient.on]].
*
* **Important:** Do **not** try to instantiate `LDClient` with its constructor (`new LDClient()`); the SDK
* does not currently support this.
*
* @param key
* The SDK key.
* @param options
* Optional configuration settings.
* @return
* The new client instance.
*/
export function init(key: string, options?: LDOptions): LDClient;
/**
* The types of values a feature flag can have.
*
* Flags can have any JSON-serializable value.
*/
export type LDFlagValue = any;
/**
* A map of feature flags from their keys to their values.
*/
export interface LDFlagSet {
[key: string]: LDFlagValue;
}
/**
* An object that contains the state of all feature flags, generated by [[LDClient.allFlagsState]].
*/
export interface LDFlagsState {
/**
* True if this object contains a valid snapshot of feature flag state, or false if the
* state could not be computed (for instance, because the client was offline or there
* was no user).
*/
valid: boolean;
/**
* Returns the value of an individual feature flag at the time the state was recorded.
* It will be null if the flag returned the default value, or if there was no such flag.
*
* @param key
* The flag key.
*/
getFlagValue(key: string): LDFlagValue;
/**
* Returns the evaluation reason for a feature flag at the time the state was recorded.
* It will be null if reasons were not recorded, or if there was no such flag.
*
* @param key
* The flag key.
*/
getFlagReason(key: string): LDEvaluationReason;
/**
* Returns a map of feature flag keys to values. If a flag would have evaluated to the
* default value, its value will be null.
*
* Do not use this method if you are passing data to the front end to "bootstrap" the
* JavaScript client. Instead, use [[toJSON]].
*/
allValues(): LDFlagSet;
/**
* Returns a Javascript representation of the entire state map, in the format used by
* the Javascript SDK. Use this method if you are passing data to the front end in
* order to "bootstrap" the JavaScript client.
*
* Do not rely on the exact shape of this data, as it may change in future to support
* the needs of the JavaScript client.
*/
toJSON(): object;
}
/**
* Describes the reason that a flag evaluation produced a particular value. This is
* part of the [[LDEvaluationDetail]] object returned by [[LDClient.variationDetail]].
*/
export interface LDEvaluationReason {
/**
* The general category of the reason:
*
* - `'OFF'`: The flag was off and therefore returned its configured off value.
* - `'FALLTHROUGH'`: The flag was on but the context did not match any targets or rules.
* - `'TARGET_MATCH'`: The context key was specifically targeted for this flag.
* - `'RULE_MATCH'`: the context matched one of the flag's rules.
* - `'PREREQUISITE_FAILED'`: The flag was considered off because it had at least one
* prerequisite flag that either was off or did not return the desired variation.
* - `'ERROR'`: The flag could not be evaluated, e.g. because it does not exist or due
* to an unexpected error.
*/
kind: string;
/**
* A further description of the error condition, if the kind was `'ERROR'`.
*/
errorKind?: string;
/**
* The index of the matched rule (0 for the first), if the kind was `'RULE_MATCH'`.
*/
ruleIndex?: number;
/**
* The unique identifier of the matched rule, if the kind was `'RULE_MATCH'`.
*/
ruleId?: string;
/**
* The key of the failed prerequisite flag, if the kind was `'PREREQUISITE_FAILED'`.
*/
prerequisiteKey?: string;
/**
* Whether the evaluation was part of an experiment.
*
* This is true if the evaluation resulted in an experiment rollout and served one of
* the variations in the experiment. Otherwise it is false or undefined.
*/
inExperiment?: boolean;
/**
* Describes the validity of Big Segment information, if and only if the flag evaluation
* required querying at least one Big Segment.
*
* - `'HEALTHY'`: The Big Segment query involved in the flag evaluation was successful, and
* the segment state is considered up to date.
* - `'STALE'`: The Big Segment query involved in the flag evaluation was successful, but
* the segment state may not be up to date
* - `'NOT_CONFIGURED'`: Big Segments could not be queried for the flag evaluation because
* the SDK configuration did not include a Big Segment store.
* - `'STORE_ERROR'`: The Big Segment query involved in the flag evaluation failed, for
* instance due to a database error.
*/
bigSegmentsStatus?: "HEALTHY" | "STALE" | "NOT_CONFIGURED" | "STORE_ERROR";
}
/**
* An object that combines the result of a feature flag evaluation with information about
* how it was calculated.
*
* This is the result of calling [[LDClient.variationDetail]].
*
* For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#nodejs-server-side).
*/
export interface LDEvaluationDetail {
/**
* The result of the flag evaluation. This will be either one of the flag's variations or
* the default value that was passed to [[LDClient.variationDetail]].
*/
value: LDFlagValue;
/**
* The index of the returned value within the flag's list of variations, e.g. 0 for the
* first variation-- or `null` if the default value was returned.
*/
variationIndex?: number;
/**
* An object describing the main factor that influenced the flag evaluation value.
*/
reason: LDEvaluationReason;
}
/**
* LaunchDarkly initialization options.
*/
export interface LDOptions {
/**
* The base URI for the LaunchDarkly server.
*
* Most users should use the default value.
*/
baseUri?: string;
/**
* The base URI for the LaunchDarkly streaming server.
*
* Most users should use the default value.
*/
streamUri?: string;
/**
* The base URI for the LaunchDarkly events server.
*
* Most users should use the default value.
*/
eventsUri?: string;
/**
* The connection timeout, in seconds.
*/
timeout?: number;
/**
* The capacity of the analytics events queue.
*
* The client buffers up to this many events in memory before flushing. If the capacity is
* exceeded before the buffer is flushed, events will be discarded.
*/
capacity?: number;
/**
* Configures a logger for warnings and errors generated by the SDK.
*
* The logger can be any object that conforms to the [[LDLogger]] interface.
* For a simple implementation that lets you filter by log level, see
* [[basicLogger]]. You can also use an instance of `winston.Logger` from
* the Winston logging package.
*
* If you do not set this property, the SDK uses [[basicLogger]] with a
* minimum level of `info`.
*/
logger?: LDLogger;
/**
* A component that stores feature flags and related data received from LaunchDarkly.
*
* By default, this is an in-memory data structure. Database integrations are also
* available, as described in the
* [SDK features guide](https://docs.launchdarkly.com/sdk/concepts/data-stores).
*
* Some implementations provide the store implementation object itself, while others
* provide a factory function that creates the store implementation based on the SDK
* configuration; this property accepts either.
*/
featureStore?: LDFeatureStore | ((options: LDOptions) => LDFeatureStore);
/**
* Additional parameters for configuring the SDK's Big Segments behavior.
*
* Big Segments are a specific type of user segments. For more information, read the
* LaunchDarkly documentation: https://docs.launchdarkly.com/home/users/big-segments
*
* By default, there is no configuration and Big Segments cannot be evaluated. In this
* case, any flag evaluation that references a Big Segment will behave as if no users
* are included in any Big Segments, and the {@link LDEvaluationReason} associated with any
* such flag evaluation will have a `bigSegmentsStatus` of `"NOT_CONFIGURED"`.
*/
bigSegments?: LDBigSegmentsOptions;
/**
* A component that obtains feature flag data and puts it in the feature store.
*
* By default, this is the client's default streaming or polling component. It can be changed
* for testing purposes; see [[FileDataSource]].
*/
updateProcessor?: object;
/**
* The interval in between flushes of the analytics events queue, in seconds.
*/
flushInterval?: number;
/**
* The time between polling requests, in seconds. Ignored in streaming mode.
*/
pollInterval?: number;
/**
* Allows you to specify a host for an optional HTTP proxy.
*/
proxyHost?: string;
/**
* Allows you to specify a port for an optional HTTP proxy.
*
* Both the host and port must be specified to enable proxy support.
*/
proxyPort?: number;
/**
* When using an HTTP proxy, specifies whether it is accessed via `http` or `https`.
*/
proxyScheme?: string;
/**
* Allows you to specify basic authentication parameters for an optional HTTP proxy.
* Usually of the form `username:password`.
*/
proxyAuth?: string;
/**
* Whether the client should be initialized in offline mode.
*/
offline?: boolean;
/**
* Whether streaming mode should be used to receive flag updates.
*
* This is true by default. If you set it to false, the client will use polling.
* Streaming should only be disabled on the advice of LaunchDarkly support.
*/
stream?: boolean;
/**
* Sets the initial reconnect delay for the streaming connection, in seconds.
*
* The streaming service uses a backoff algorithm (with jitter) every time the connection needs
* to be reestablished. The delay for the first reconnection will start near this value, and then
* increase exponentially for any subsequent connection failures.
*
* The default value is 1.
*/
streamInitialReconnectDelay?: number;
/**
* Whether you are using the LaunchDarkly Relay Proxy in daemon mode.
*
* In this configuration, the client will not connect to LaunchDarkly to get feature flags,
* but will instead get feature state from a database (Redis or another supported feature
* store integration) that is populated by the Relay Proxy. By default, this is false.
* To learn more, read [Using daemon mode](https://docs.launchdarkly.com/home/relay-proxy/using#using-daemon-mode).
*/
useLdd?: boolean;
/**
* Whether to send analytics events back to LaunchDarkly. By default, this is true.
*/
sendEvents?: boolean;
/**
* Whether all context attributes (except the contexy key) should be marked as private, and
* not sent to LaunchDarkly.
*
* By default, this is false.
*/
allAttributesPrivate?: boolean;
/**
* The names of any context attributes that should be marked as private, and not sent
* to LaunchDarkly.
*
* Any contexts sent to LaunchDarkly with this configuration active will have attributes with
* these names removed. This is in addition to any attributes that were marked as private for an
* individual context with {@link LDContextMeta.privateAttributes}. Setting
* {@link LDOptions.allAttributesPrivate} to true overrides this.
*
* If and only if a parameter starts with a slash, it is interpreted as a slash-delimited path
* that can denote a nested property within a JSON object. For instance, "/address/street" means
* that if there is an attribute called "address" that is a JSON object, and one of the object's
* properties is "street", the "street" property will be redacted from the analytics data but
* other properties within "address" will still be sent. This syntax also uses the JSON Pointer
* convention of escaping a literal slash character as "~1" and a tilde as "~0".
*/
privateAttributes?: Array<string>;
/**
* The number of context keys that the event processor can remember at any one time,
* so that duplicate context details will not be sent in analytics events.
*
* Defaults to 1000.
*/
contextKeysCapacity?: number;
/**
* The interval (in seconds) at which the event processor will reset its set of
* known context keys.
*
* Defaults to 300.
*/
contextKeysFlushInterval?: number;
/**
* The number of user keys that the event processor can remember at any one time,
* so that duplicate user details will not be sent in analytics events.
*
* Defaults to 1000.
*
* @deprecated Use contextKeysCapacity instead.
*/
userKeysCapacity?: number;
/**
* The interval (in seconds) at which the event processor will reset its set of
* known user keys.
*
* Defaults to 300.
*
* @deprecated Use contextKeysFlushInterval instead.
*/
userKeysFlushInterval?: number;
/**
* Additional parameters to pass to the Node HTTPS API for secure requests. These can include any
* of the TLS-related parameters supported by `https.request()`, such as `ca`, `cert`, and `key`.
*
* For more information, see the Node documentation for `https.request()` and `tls.connect()`.
*/
tlsParams?: LDTLSOptions;
/**
* Set to true to opt out of sending diagnostics data.
*
* Unless the `diagnosticOptOut` field is set to true, the client will send some diagnostics data to the
* LaunchDarkly servers in order to assist in the development of future SDK improvements. These diagnostics
* consist of an initial payload containing some details of SDK in use, the SDK's configuration, and the platform
* the SDK is being run on, as well as payloads sent periodically with information on irregular occurrences such
* as dropped events.
*/
diagnosticOptOut?: boolean;
/**
* The interval at which periodic diagnostic data is sent, in seconds.
*
* The default is 900 (every 15 minutes) and the minimum value is 60 (every minute).
*/
diagnosticRecordingInterval?: number;
/**
* For use by wrapper libraries to set an identifying name for the wrapper being used.
*
* This will be sent in User-Agent headers during requests to the LaunchDarkly servers to allow recording
* metrics on the usage of these wrapper libraries.
*/
wrapperName?: string;
/**
* For use by wrapper libraries to report the version of the library in use.
*
* If `wrapperName` is not set, this field will be ignored. Otherwise the version string will be included in
* the User-Agent headers along with the `wrapperName` during requests to the LaunchDarkly servers.
*/
wrapperVersion?: string;
/**
* Information about the application where the LaunchDarkly SDK is running.
*/
application?: {
/**
* A unique identifier representing the application where the LaunchDarkly SDK is running.
*
* This can be specified as any string value as long as it only uses the following characters: ASCII letters,
* ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored.
*
* Example: `authentication-service`
*/
id?: string;
/**
* A unique identifier representing the version of the application where the LaunchDarkly SDK is running.
*
* This can be specified as any string value as long as it only uses the following characters: ASCII letters,
* ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored.
*
* Example: `1.0.0` (standard version string) or `abcdef` (sha prefix)
*/
version?: string;
}
}
/**
* Additional parameters for configuring the SDK's Big Segments behavior.
*
* Big Segments are a specific type of user segments. For more information, read the LaunchDarkly
* documentation: https://docs.launchdarkly.com/home/users/big-segments
*
* @see {@link LDOptions.bigSegments}
*/
export interface LDBigSegmentsOptions {
/**
* Specifies the storage component that provides Big Segments data.
*
* This property is mandatory. It must be obtained from one of the SDK's database integrations,
* such as https://github.com/launchdarkly/node-server-sdk-redis. You will normally specify a
* database implementation that matches how the LaunchDarkly Relay Proxy is configured, since the
* Relay Proxy manages the Big Segment data.
*/
store: (options: LDOptions) => interfaces.BigSegmentStore;
/**
* The maximum number of users whose Big Segment state will be cached by the SDK at any given time.
*
* To reduce database traffic, the SDK maintains a least-recently-used cache by user key. When a feature
* flag that references a Big Segment is evaluated for some user who is not currently in the cache, the
* SDK queries the database for all Big Segment memberships of that user, and stores them together in a
* single cache entry. If the cache is full, the oldest entry is dropped.
*
* A higher value for `userCacheSize` means that database queries for Big Segments will be done
* less often for recently-referenced users, if the application has many users, at the cost of
* increased memory used by the cache.
*
* Cache entries can also expire based on the setting of {@link userCacheTime}.
*
* If not specified, the default value is 1000.
*/
userCacheSize?: number;
/**
* The maximum length of time that the Big Segment state for a user will be cached by the SDK,
* in seconds.
*
* See {@link userCacheSize} for more about this cache. A higher value for `userCacheTime` means
* that database queries for the Big Segment state of any given user will be done less often, but
* that changes to segment membership may not be detected as soon.
*
* If not specified, the default value is 5. Negative values are changed to the default.
*/
userCacheTime?: number;
/**
* The interval at which the SDK will poll the Big Segment store to make sure it is available
* and to determine how long ago it was updated, in seconds.
*
* If not specified, the default value is 5. Zero or negative values are changed to the default.
*/
statusPollInterval?: number;
/**
* The maximum length of time between updates of the Big Segments data before the data is
* considered out of date, in seconds.
*
* Normally, the LaunchDarkly Relay Proxy updates a timestamp in the Big Segment store at intervals to
* confirm that it is still in sync with the LaunchDarkly data, even if there have been no changes to the
* If the timestamp falls behind the current time by the amount specified in `staleAfter`, the SDK
* assumes that something is not working correctly in this process and that the data may not be accurate.
*
* While in a stale state, the SDK will still continue using the last known data, but the status from
* {@link interfaces.BigSegmentStoreStatusProvider.getStatus} will have `stale: true`, and any
* {@link LDEvaluationReason} generated from a feature flag that references a Big Segment will have a
* `bigSegmentsStatus` of `"STALE"`.
*
* If not specified, the default value is 120 (two minutes). Zero or negative values are changed to
* the default.
*/
staleAfter?: number;
}
/**
* Additional parameters to pass to the Node HTTPS API for secure requests. These can include any
* of the TLS-related parameters supported by `https.request()`, such as `ca`, `cert`, and `key`.
*
* For more information, see the Node documentation for `https.request()` and `tls.connect()`.
*/
export interface LDTLSOptions {
ca?: string | string[] | Buffer | Buffer[];
cert?: string | string[] | Buffer | Buffer[];
checkServerIdentity?: (servername: string, cert: any) => Error | undefined;
ciphers?: string;
pfx?: string | string[] | Buffer | Buffer[] | object[];
key?: string | string[] | Buffer | Buffer[] | object[];
passphrase?: string;
rejectUnauthorized?: boolean;
secureProtocol?: string;
servername?: string;
}
/**
* Meta attributes are used to control behavioral aspects of the Context.
* They cannot be addressed in targeting rules.
*/
export interface LDContextMeta {
/**
*
* Designate any number of Context attributes, or properties within them, as private: that is,
* their values will not be sent to LaunchDarkly.
*
* Each parameter can be a simple attribute name, such as "email". Or, if the first character is
* a slash, the parameter is interpreted as a slash-delimited path to a property within a JSON
* object, where the first path component is a Context attribute name and each following
* component is a nested property name: for example, suppose the attribute "address" had the
* following JSON object value:
*
* ```
* {"street": {"line1": "abc", "line2": "def"}}
* ```
*
* Using ["/address/street/line1"] in this case would cause the "line1" property to be marked as
* private. This syntax deliberately resembles JSON Pointer, but other JSON Pointer features
* such as array indexing are not supported for Private.
*
* This action only affects analytics events that involve this particular Context. To mark some
* (or all) Context attributes as private for all users, use the overall configuration for the
* SDK.
* See {@link LDOptions.allAttributesPrivate} and {@link LDOptions.privateAttributes}.
*
* The attributes "kind" and "key", and the "_meta" attributes cannot be made private.
*
* In this example, firstName is marked as private, but lastName is not:
*
* ```
* const context = {
* kind: 'org',
* key: 'my-key',
* firstName: 'Pierre',
* lastName: 'Menard',
* _meta: {
* privateAttributes: ['firstName'],
* }
* };
* ```
*
* This is a metadata property, rather than an attribute that can be addressed in evaluations:
* that is, a rule clause that references the attribute name "privateAttributes", will not use
* this value, but would use a "privateAttributes" attribute set on the context.
*/
privateAttributes?: string[];
}
interface LDContextCommon {
/**
* If true, the context will _not_ appear on the Contexts page in the LaunchDarkly dashboard.
*/
anonymous?: boolean;
/**
* A unique string identifying a context.
*/
key: string;
/**
* The context's name.
*
* You can search for contexts on the Contexts page by name.
*/
name?: string;
/**
* Meta attributes are used to control behavioral aspects of the Context, such as private
* private attributes. See {@link LDContextMeta.privateAttributes} as an example.
*
* They cannot be addressed in targeting rules.
*/
_meta?: LDContextMeta;
/**
* Any additional attributes associated with the context.
*/
[attribute: string]: any;
}
/**
* A context which represents a single kind.
*
* For a single kind context the 'kind' may not be 'multi'.
*
* ```
* const myOrgContext = {
* kind: 'org',
* key: 'my-org-key',
* someAttribute: 'my-attribute-value'
* };
* ```
*
* The above context would be a single kind context representing an organization. It has a key
* for that organization, and a single attribute 'someAttribute'.
*/
interface LDSingleKindContext extends LDContextCommon {
/**
* The kind of the context.
*/
kind: string;
}
/**
* A context which represents multiple kinds. Each kind having its own key and attributes.
*
* A multi-context must contain `kind: 'multi'` at the root.
*
* ```
* const myMultiContext = {
* // Multi-contexts must be of kind 'multi'.
* kind: 'multi',
* // The context is namespaced by its kind. This is an 'org' kind context.
* org: {
* // Each component context has its own key and attributes.
* key: 'my-org-key',
* someAttribute: 'my-attribute-value',
* },
* user: {
* key: 'my-user-key',
* firstName: 'Bob',
* lastName: 'Bobberson',
* _meta: {
* // Each component context has its own _meta attributes. This will only apply the this
* // 'user' context.
* privateAttributes: ['firstName']
* }
* }
* };
* ```
*
* The above multi-context contains both an 'org' and a 'user'. Each with their own key,
* attributes, and _meta attributes.
*/
interface LDMultiKindContext {
/**
* The kind of the context.
*/
kind: "multi",
/**
* The contexts which compose this multi-kind context.
*
* These should be of type LDContextCommon. "multi" is to allow
* for the top level "kind" attribute.
*/
[kind: string]: "multi" | LDContextCommon;
}
/**
* A LaunchDarkly context object.
*/
export type LDContext = LDUser | LDSingleKindContext | LDMultiKindContext;
/**
* A legacy LaunchDarkly user object.
*
* This type exists for easing migration to contexts, but code should be moved to use single/multi
* contexts.
*
* The LDUser object is currently supported for ease of upgrade. It may be removed in a future
* release.
* In order to convert an LDUser into a LDSingleKindContext the following changes should
* be made.
*
* 1.) Add a kind to the object. `kind: 'user'`.
*
* 2.) Move custom attributes to the top level of the object.
*
* 3.) Move `privateAttributeNames` to `_meta.privateAttributes`.
*
* ```
* const LDUser: user = {
* key: '1234',
* privateAttributeNames: ['myAttr']
* custom: {
* myAttr: 'value'
* }
* }
*
* const LDSingleKindContext: context = {
* kind: 'user',
* key: '1234',
* myAttr: 'value'
* _meta: {
* privateAttributes: ['myAttr']
* }
* }
* ```
*/
export interface LDUser {
/**
* A unique string identifying a user.
*/
key: string;
/**
* The user's name.
*
* You can search for users on the User page by name.
*/
name?: string;
/**
* The user's first name.
*/
firstName?: string;
/**
* The user's last name.
*/
lastName?: string;
/**
* The user's email address.
*
* If an `avatar` URL is not provided, LaunchDarkly will use Gravatar
* to try to display an avatar for the user on the Users page.
*/
email?: string;
/**
* An absolute URL to an avatar image for the user.
*/
avatar?: string;
/**
* The user's IP address.
*
* If you provide an IP, LaunchDarkly will use a geolocation service to
* automatically infer a `country` for the user, unless you've already
* specified one.
*/
ip?: string;
/**
* The country associated with the user.
*/
country?: string;
/**
* If true, the user will _not_ appear on the Users page in the LaunchDarkly dashboard.
*/
anonymous?: boolean;
/**
* Any additional attributes associated with the user.
*/
custom?: {
[key: string]:
| string
| boolean
| number
| Array<string | boolean | number>;
};
/**
* Specifies a list of attribute names (either built-in or custom) which should be
* marked as private, and not sent to LaunchDarkly in analytics events. This is in
* addition to any private attributes designated in the global configuration
* with [[LDOptions.privateAttributeNames]] or [[LDOptions.allAttributesPrivate]].
*/
privateAttributeNames?: Array<string>;
}
/**
* The LaunchDarkly client logger interface.
*
* The [[LDOptions.logger]] property accepts any object that conforms to this
* interface. The SDK only uses four logging levels: `error`, `warn`, `info`, and
* `debug`. It will call the corresponding method of the `LDLogger` either with a
* single string argument, or with a format string and variable arguments in the
* format used by Node's `util.format()`.
*
* The [Winston](https://github.com/winstonjs/winston) logging package provides a
* logger that conforms to this interface, so if you have created a logger with
* Winston, you can simply put it into the [[LDOptions.logger]] property.
*
* If you do not provide a logger object, the SDK uses the [[basicLogger]]
* implementation with a minimum level of `info`.
*/
export interface LDLogger {
/**
* The error logger.
*
* @param args
* A sequence of any JavaScript values.
*/
error(...args: any[]): void;
/**
* The warning logger.
*
* @param args
* A sequence of any JavaScript values.
*/
warn(...args: any[]): void;
/**
* The info logger.
*
* @param args
* A sequence of any JavaScript values.
*/
info(...args: any[]): void;
/**
* The debug logger.
*
* @param args
* A sequence of any JavaScript values.
*/
debug(...args: any[]): void;
}
/**
* Interface for a feature store component.
*
* The feature store is what the client uses to store feature flag data that has been received
* from LaunchDarkly. By default, it uses an in-memory implementation; database integrations are
* also available. Read the [SDK features guide](https://docs.launchdarkly.com/sdk/concepts/data-stores).
* You will not need to use this interface unless you are writing your own implementation.
*
* Feature store methods can and should call their callbacks directly whenever possible, rather
* than deferring them with setImmediate() or process.nextTick(). This means that if for any
* reason you are updating or querying a feature store directly in your application code (which
* is not part of normal use of the SDK) you should be aware that the callback may be executed
* immediately.
*/
export interface LDFeatureStore {
/**
* Get an entity from the store.
*
* The store should treat any entity with the property `deleted: true` as "not found".
*
* @param kind
* The type of data to be accessed. The store should not make any assumptions about the format
* of the data, but just return a JSON object. The actual type of this parameter is
* [[interfaces.DataKind]].
*
* @param key
* The unique key of the entity within the specified collection.
*
* @param callback
* Will be called with the retrieved entity, or null if not found. The actual type of the result
* value is [[interfaces.VersionedData]].
*/
get(kind: object, key: string, callback: (res: object) => void): void;
/**
* Get all entities from a collection.
*
* The store should filter out any entities with the property `deleted: true`.
*
* @param kind
* The type of data to be accessed. The store should not make any assumptions about the format
* of the data, but just return an object in which each key is the `key` property of an entity
* and the value is the entity. The actual type of this parameter is [[interfaces.DataKind]].
*
* @param callback
* Will be called with the resulting map. The actual type of the result value is
* `interfaces.KeyedItems<VersionedData>`.
*/
all(kind: object, callback: (res: object) => void): void;
/**
* Initialize the store, overwriting any existing data.
*
* @param allData
* An object in which each key is the "namespace" of a collection (e.g. `"features"`) and
* the value is an object that maps keys to entities. The actual type of this parameter is
* `interfaces.FullDataSet<VersionedData>`.
*
* @param callback
* Will be called when the store has been initialized.
*/
init(allData: object, callback: () => void): void;
/**
* Delete an entity from the store.
*
* Deletion should be implemented by storing a placeholder object with the property
* `deleted: true` and a `version` property equal to the provided version. In other words,
* it should be exactly the same as calling `upsert` with such an object.
*
* @param kind
* The type of data to be accessed. The actual type of this parameter is
* [[interfaces.DataKind]].
*
* @param key
* The unique key of the entity within the specified collection.
*
* @param version
* A number that must be greater than the `version` property of the existing entity in
* order for it to be deleted. If it is less than or equal to the existing version, the
* method should do nothing.
*
* @param callback
* Will be called when the delete operation is complete.
*/
delete(kind: object, key: string, version: string, callback: () => void): void;
/**
* Add an entity or update an existing entity.
*
* @param kind
* The type of data to be accessed. The actual type of this parameter is
* [[interfaces.DataKind]].
*
* @param data
* The contents of the entity, as an object that can be converted to JSON. The store
* should check the `version` property of this object, and should *not* overwrite any
* existing data if the existing `version` is greater than or equal to that value.
* The actual type of this parameter is [[interfaces.VersionedData]].
*
* @param callback