launchdarkly-js-sdk-common 5.0.3 → 5.2.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.
package/typings.d.ts CHANGED
@@ -118,7 +118,7 @@ declare module 'launchdarkly-js-sdk-common' {
118
118
  * These are used to send metadata about the SDK (such as the version). They
119
119
  * are also used to send the application.id and application.version set in
120
120
  * the options.
121
- *
121
+ *
122
122
  * This defaults to true (custom headers will be sent). One reason you might
123
123
  * want to set it to false is that the presence of custom headers causes
124
124
  * browsers to make an extra OPTIONS request (a CORS preflight check) before
@@ -161,12 +161,12 @@ declare module 'launchdarkly-js-sdk-common' {
161
161
  * Specifies a list of attribute names (either built-in or custom) which should be marked as
162
162
  * private, and not sent to LaunchDarkly in analytics events. You can also specify this on a
163
163
  * per-context basis with {@link LDContextMeta.privateAttributes}.
164
- *
164
+ *
165
165
  * Any contexts sent to LaunchDarkly with this configuration active will have attributes with
166
166
  * these names removed in analytic events. This is in addition to any attributes that were
167
167
  * marked as private for an individual context with {@link LDContextMeta.privateAttributes}.
168
168
  * Setting {@link LDOptions.allAttributesPrivate} to true overrides this.
169
- *
169
+ *
170
170
  * If and only if a parameter starts with a slash, it is interpreted as a slash-delimited path
171
171
  * that can denote a nested property within a JSON object. For instance, "/address/street" means
172
172
  * that if there is an attribute called "address" that is a JSON object, and one of the object's
@@ -254,24 +254,24 @@ declare module 'launchdarkly-js-sdk-common' {
254
254
  application?: {
255
255
  /**
256
256
  * A unique identifier representing the application where the LaunchDarkly SDK is running.
257
- *
257
+ *
258
258
  * This can be specified as any string value as long as it only uses the following characters: ASCII letters,
259
259
  * ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored.
260
- *
260
+ *
261
261
  * Example: `authentication-service`
262
262
  */
263
263
  id?: string;
264
264
 
265
265
  /**
266
266
  * A unique identifier representing the version of the application where the LaunchDarkly SDK is running.
267
- *
267
+ *
268
268
  * This can be specified as any string value as long as it only uses the following characters: ASCII letters,
269
269
  * ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored.
270
- *
270
+ *
271
271
  * Example: `1.0.0` (standard version string) or `abcdef` (sha prefix)
272
272
  */
273
273
  version?: string;
274
- }
274
+ };
275
275
 
276
276
  /**
277
277
  * Inspectors can be used for collecting information for monitoring, analytics, and debugging.
@@ -284,35 +284,34 @@ declare module 'launchdarkly-js-sdk-common' {
284
284
  * They cannot be addressed in targeting rules.
285
285
  */
286
286
  export interface LDContextMeta {
287
-
288
287
  /**
289
- *
288
+ *
290
289
  * Designate any number of Context attributes, or properties within them, as private: that is,
291
290
  * their values will not be sent to LaunchDarkly in analytics events.
292
- *
291
+ *
293
292
  * Each parameter can be a simple attribute name, such as "email". Or, if the first character is
294
293
  * a slash, the parameter is interpreted as a slash-delimited path to a property within a JSON
295
294
  * object, where the first path component is a Context attribute name and each following
296
295
  * component is a nested property name: for example, suppose the attribute "address" had the
297
296
  * following JSON object value:
298
- *
297
+ *
299
298
  * ```
300
299
  * {"street": {"line1": "abc", "line2": "def"}}
301
300
  * ```
302
- *
301
+ *
303
302
  * Using ["/address/street/line1"] in this case would cause the "line1" property to be marked as
304
303
  * private. This syntax deliberately resembles JSON Pointer, but other JSON Pointer features
305
304
  * such as array indexing are not supported for Private.
306
- *
305
+ *
307
306
  * This action only affects analytics events that involve this particular Context. To mark some
308
307
  * (or all) Context attributes as private for all users, use the overall configuration for the
309
308
  * SDK.
310
309
  * See {@link LDOptions.allAttributesPrivate} and {@link LDOptions.privateAttributes}.
311
- *
310
+ *
312
311
  * The attributes "kind" and "key", and the "_meta" attributes cannot be made private.
313
- *
312
+ *
314
313
  * In this example, firstName is marked as private, but lastName is not:
315
- *
314
+ *
316
315
  * ```
317
316
  * const context = {
318
317
  * kind: 'org',
@@ -320,11 +319,11 @@ declare module 'launchdarkly-js-sdk-common' {
320
319
  * firstName: 'Pierre',
321
320
  * lastName: 'Menard',
322
321
  * _meta: {
323
- * privateAttributes: ['firstName'],
322
+ * privateAttributes: ['firstName'],
324
323
  * }
325
324
  * };
326
325
  * ```
327
- *
326
+ *
328
327
  * This is a metadata property, rather than an attribute that can be addressed in evaluations:
329
328
  * that is, a rule clause that references the attribute name "privateAttributes", will not use
330
329
  * this value, but would use a "privateAttributes" attribute set on the context.
@@ -370,12 +369,11 @@ declare module 'launchdarkly-js-sdk-common' {
370
369
  [attribute: string]: any;
371
370
  }
372
371
 
373
-
374
372
  /**
375
373
  * A context which represents a single kind.
376
- *
374
+ *
377
375
  * For a single kind context the 'kind' may not be 'multi'.
378
- *
376
+ *
379
377
  * ```
380
378
  * const myOrgContext = {
381
379
  * kind: 'org',
@@ -383,7 +381,7 @@ declare module 'launchdarkly-js-sdk-common' {
383
381
  * someAttribute: 'my-attribute-value'
384
382
  * };
385
383
  * ```
386
- *
384
+ *
387
385
  * The above context would be a single kind context representing an organization. It has a key
388
386
  * for that organization, and a single attribute 'someAttribute'.
389
387
  */
@@ -396,9 +394,9 @@ declare module 'launchdarkly-js-sdk-common' {
396
394
 
397
395
  /**
398
396
  * A context which represents multiple kinds. Each kind having its own key and attributes.
399
- *
397
+ *
400
398
  * A multi-context must contain `kind: 'multi'` at the root.
401
- *
399
+ *
402
400
  * ```
403
401
  * const myMultiContext = {
404
402
  * // Multi-contexts must be of kind 'multi'.
@@ -421,7 +419,7 @@ declare module 'launchdarkly-js-sdk-common' {
421
419
  * }
422
420
  * };
423
421
  * ```
424
- *
422
+ *
425
423
  * The above multi-context contains both an 'org' and a 'user'. Each with their own key,
426
424
  * attributes, and _meta attributes.
427
425
  */
@@ -429,15 +427,15 @@ declare module 'launchdarkly-js-sdk-common' {
429
427
  /**
430
428
  * The kind of the context.
431
429
  */
432
- kind: "multi",
430
+ kind: 'multi';
433
431
 
434
432
  /**
435
433
  * The contexts which compose this multi-kind context.
436
- *
434
+ *
437
435
  * These should be of type LDContextCommon. "multi" is to allow
438
436
  * for the top level "kind" attribute.
439
437
  */
440
- [kind: string]: "multi" | LDContextCommon;
438
+ [kind: string]: 'multi' | LDContextCommon;
441
439
  }
442
440
 
443
441
  /**
@@ -452,13 +450,13 @@ declare module 'launchdarkly-js-sdk-common' {
452
450
  * The LDUser object is currently supported for ease of upgrade.
453
451
  * In order to convert an LDUser into a LDSingleKindContext the following changes should
454
452
  * be made.
455
- *
453
+ *
456
454
  * 1.) Add a kind to the object. `kind: 'user'`.
457
- *
455
+ *
458
456
  * 2.) Move custom attributes to the top level of the object.
459
- *
457
+ *
460
458
  * 3.) Move `privateAttributeNames` to `_meta.privateAttributes`.
461
- *
459
+ *
462
460
  * ```
463
461
  * const LDUser: user = {
464
462
  * key: '1234',
@@ -467,7 +465,7 @@ declare module 'launchdarkly-js-sdk-common' {
467
465
  * myAttr: 'value'
468
466
  * }
469
467
  * }
470
- *
468
+ *
471
469
  * const LDSingleKindContext: context = {
472
470
  * kind: 'user',
473
471
  * key: '1234',
@@ -666,7 +664,7 @@ declare module 'launchdarkly-js-sdk-common' {
666
664
  *
667
665
  * ```
668
666
  * // using Promise then() and catch() handlers
669
- * client.waitForInitialization().then(() => {
667
+ * client.waitForInitialization(5).then(() => {
670
668
  * doSomethingWithSuccessfullyInitializedClient();
671
669
  * }).catch(err => {
672
670
  * doSomethingForFailedStartup(err);
@@ -674,7 +672,7 @@ declare module 'launchdarkly-js-sdk-common' {
674
672
  *
675
673
  * // using async/await
676
674
  * try {
677
- * await client.waitForInitialization();
675
+ * await client.waitForInitialization(5);
678
676
  * doSomethingWithSuccessfullyInitializedClient();
679
677
  * } catch (err) {
680
678
  * doSomethingForFailedStartup(err);
@@ -689,11 +687,20 @@ declare module 'launchdarkly-js-sdk-common' {
689
687
  * Note that you can also use event listeners ({@link on}) for the same purpose: the event `"initialized"`
690
688
  * indicates success, and `"failed"` indicates failure.
691
689
  *
690
+ * @param timeout
691
+ * The amount of time, in seconds, to wait for initialization before rejecting the promise.
692
+ * Using a large timeout is not recommended. If you use a large timeout and await it, then
693
+ * any network delays will cause your application to wait a long time before
694
+ * continuing execution.
695
+ *
696
+ * If no timeout is specified, then the returned promise will only be resolved when the client
697
+ * successfully initializes or initialization fails.
698
+ *
692
699
  * @returns
693
700
  * A Promise that will be resolved if the client initializes successfully, or rejected if it
694
- * fails.
701
+ * fails or the specified timeout elapses.
695
702
  */
696
- waitForInitialization(): Promise<void>;
703
+ waitForInitialization(timeout?: number): Promise<void>;
697
704
 
698
705
  /**
699
706
  * Identifies a context to LaunchDarkly.
@@ -720,7 +727,11 @@ declare module 'launchdarkly-js-sdk-common' {
720
727
  * values for the new context are available, providing an {@link LDFlagSet} containing the new values
721
728
  * (which can also be obtained by calling {@link variation}).
722
729
  */
723
- identify(context: LDContext, hash?: string, onDone?: (err: Error | null, flags: LDFlagSet | null) => void): Promise<LDFlagSet>;
730
+ identify(
731
+ context: LDContext,
732
+ hash?: string,
733
+ onDone?: (err: Error | null, flags: LDFlagSet | null) => void
734
+ ): Promise<LDFlagSet>;
724
735
 
725
736
  /**
726
737
  * Returns the client's current context.
@@ -766,7 +777,7 @@ declare module 'launchdarkly-js-sdk-common' {
766
777
  * Determines the variation of a feature flag for a context, along with information about how it was
767
778
  * calculated.
768
779
  *
769
- * Note that this will only work if you have set `evaluationExplanations` to true in {@link LDOptions}.
780
+ * Note that this will only work if you have set `evaluationReasons` to true in {@link LDOptions}.
770
781
  * Otherwise, the `reason` property of the result will be null.
771
782
  *
772
783
  * The `reason` property of the result will also be included in analytics events, if you are
@@ -848,14 +859,14 @@ declare module 'launchdarkly-js-sdk-common' {
848
859
  off(key: string, callback: (...args: any[]) => void, context?: any): void;
849
860
 
850
861
  /**
851
- * Track page events to use in goals or A/B tests.
862
+ * Track page events to use in metrics (goals) or Experimentation.
852
863
  *
853
864
  * LaunchDarkly automatically tracks pageviews and clicks that are specified in the
854
- * Goals section of their dashboard. This can be used to track custom goals or other
855
- * events that do not currently have goals.
865
+ * Metrics section of their dashboard. This can be used to track custom metrics or other
866
+ * events that do not currently have metrics.
856
867
  *
857
868
  * @param key
858
- * The name of the event, which may correspond to a goal in A/B tests.
869
+ * The name of the event, which may correspond to a metric in experiments.
859
870
  * @param data
860
871
  * Additional information to associate with the event.
861
872
  * @param metricValue
@@ -909,7 +920,7 @@ declare module 'launchdarkly-js-sdk-common' {
909
920
  * @param formatter An optional function equivalent to Node's util.format, allowing
910
921
  * for parameter substitution in log messages. If this is omitted, parameter
911
922
  * substitution is not available.
912
- *
923
+ *
913
924
  * @example
914
925
  * This example shows how to use `basicLogger` in your SDK options to enable console
915
926
  * logging only at `warn` and `error` levels.
@@ -927,7 +938,7 @@ declare module 'launchdarkly-js-sdk-common' {
927
938
  * logger: ld.basicLogger({ destination: console.error }),
928
939
  * };
929
940
  * ```
930
- *
941
+ *
931
942
  * @ignore (don't need to show this separately in TypeDoc output; each SDK should provide its own
932
943
  * basicLogger function that delegates to this and sets the formatter parameter)
933
944
  */
@@ -971,7 +982,7 @@ declare module 'launchdarkly-js-sdk-common' {
971
982
  * Setting this property to anything other than a function will cause SDK
972
983
  * initialization to fail.
973
984
  */
974
- destination?: (line: string) => void,
985
+ destination?: (line: string) => void;
975
986
  }
976
987
 
977
988
  /**
@@ -984,26 +995,23 @@ declare module 'launchdarkly-js-sdk-common' {
984
995
  */
985
996
  export type LDLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
986
997
 
987
- export function getContextKeys(
988
- context: LDContext,
989
- logger?: LDLogger,
990
- ): {[attribute: string]: string} | undefined;
998
+ export function getContextKeys(context: LDContext, logger?: LDLogger): { [attribute: string]: string } | undefined;
991
999
 
992
1000
  /**
993
1001
  * Callback interface for collecting information about the SDK at runtime.
994
- *
1002
+ *
995
1003
  * This interface is used to collect information about flag usage.
996
- *
1004
+ *
997
1005
  * This interface should not be used by the application to access flags for the purpose of controlling application
998
1006
  * flow. It is intended for monitoring, analytics, or debugging purposes.
999
1007
  */
1000
1008
  export interface LDInspectionFlagUsedHandler {
1001
- type: 'flag-used',
1009
+ type: 'flag-used';
1002
1010
 
1003
1011
  /**
1004
1012
  * Name of the inspector. Will be used for logging issues with the inspector.
1005
1013
  */
1006
- name: string,
1014
+ name: string;
1007
1015
 
1008
1016
  /**
1009
1017
  * This method is called when a flag is accessed via a variation method, or it can be called based on actions in
@@ -1015,22 +1023,22 @@ declare module 'launchdarkly-js-sdk-common' {
1015
1023
 
1016
1024
  /**
1017
1025
  * Callback interface for collecting information about the SDK at runtime.
1018
- *
1026
+ *
1019
1027
  * This interface is used to collect information about flag data. In order to understand the
1020
1028
  * current flag state it should be combined with {@link LDInspectionFlagValueChangedHandler}.
1021
- * This interface will get the initial flag information, and
1029
+ * This interface will get the initial flag information, and
1022
1030
  * {@link LDInspectionFlagValueChangedHandler} will provide changes to individual flags.
1023
- *
1031
+ *
1024
1032
  * This interface should not be used by the application to access flags for the purpose of controlling application
1025
1033
  * flow. It is intended for monitoring, analytics, or debugging purposes.
1026
1034
  */
1027
1035
  export interface LDInspectionFlagDetailsChangedHandler {
1028
- type: 'flag-details-changed',
1036
+ type: 'flag-details-changed';
1029
1037
 
1030
1038
  /**
1031
1039
  * Name of the inspector. Will be used for logging issues with the inspector.
1032
1040
  */
1033
- name: string,
1041
+ name: string;
1034
1042
 
1035
1043
  /**
1036
1044
  * This method is called when the flags in the store are replaced with new flags. It will contain all flags
@@ -1039,24 +1047,23 @@ declare module 'launchdarkly-js-sdk-common' {
1039
1047
  method: (details: Record<string, LDEvaluationDetail>) => void;
1040
1048
  }
1041
1049
 
1042
-
1043
1050
  /**
1044
1051
  * Callback interface for collecting information about the SDK at runtime.
1045
- *
1052
+ *
1046
1053
  * This interface is used to collect changes to flag data, but does not provide the initial
1047
1054
  * data. It can be combined with {@link LDInspectionFlagValuesChangedHandler} to track the
1048
1055
  * entire flag state.
1049
- *
1056
+ *
1050
1057
  * This interface should not be used by the application to access flags for the purpose of controlling application
1051
1058
  * flow. It is intended for monitoring, analytics, or debugging purposes.
1052
1059
  */
1053
1060
  export interface LDInspectionFlagDetailChangedHandler {
1054
- type: 'flag-detail-changed',
1061
+ type: 'flag-detail-changed';
1055
1062
 
1056
1063
  /**
1057
1064
  * Name of the inspector. Will be used for logging issues with the inspector.
1058
1065
  */
1059
- name: string,
1066
+ name: string;
1060
1067
 
1061
1068
  /**
1062
1069
  * This method is called when a flag is updated. It will not be called
@@ -1067,19 +1074,19 @@ declare module 'launchdarkly-js-sdk-common' {
1067
1074
 
1068
1075
  /**
1069
1076
  * Callback interface for collecting information about the SDK at runtime.
1070
- *
1077
+ *
1071
1078
  * This interface is used to track current identity state of the SDK.
1072
- *
1079
+ *
1073
1080
  * This interface should not be used by the application to access flags for the purpose of controlling application
1074
1081
  * flow. It is intended for monitoring, analytics, or debugging purposes.
1075
1082
  */
1076
1083
  export interface LDInspectionIdentifyHandler {
1077
- type: 'client-identity-changed',
1084
+ type: 'client-identity-changed';
1078
1085
 
1079
1086
  /**
1080
1087
  * Name of the inspector. Will be used for logging issues with the inspector.
1081
1088
  */
1082
- name: string,
1089
+ name: string;
1083
1090
 
1084
1091
  /**
1085
1092
  * This method will be called when an identify operation completes.
@@ -1087,6 +1094,9 @@ declare module 'launchdarkly-js-sdk-common' {
1087
1094
  method: (context: LDContext) => void;
1088
1095
  }
1089
1096
 
1090
- export type LDInspection = LDInspectionFlagUsedHandler | LDInspectionFlagDetailsChangedHandler
1091
- | LDInspectionFlagDetailChangedHandler | LDInspectionIdentifyHandler;
1097
+ export type LDInspection =
1098
+ | LDInspectionFlagUsedHandler
1099
+ | LDInspectionFlagDetailsChangedHandler
1100
+ | LDInspectionFlagDetailChangedHandler
1101
+ | LDInspectionIdentifyHandler;
1092
1102
  }