launchdarkly-js-sdk-common 5.1.0 → 5.3.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',
@@ -590,6 +588,14 @@ declare module 'launchdarkly-js-sdk-common' {
590
588
  * The key of the failed prerequisite flag, if the kind was `'PREREQUISITE_FAILED'`.
591
589
  */
592
590
  prerequisiteKey?: string;
591
+
592
+ /**
593
+ * Whether the evaluation was part of an experiment.
594
+ *
595
+ * This is true if the evaluation resulted in an experiment rollout and served one of
596
+ * the variations in the experiment. Otherwise it is false or undefined.
597
+ */
598
+ inExperiment?: boolean;
593
599
  }
594
600
 
595
601
  /**
@@ -666,7 +672,7 @@ declare module 'launchdarkly-js-sdk-common' {
666
672
  *
667
673
  * ```
668
674
  * // using Promise then() and catch() handlers
669
- * client.waitForInitialization().then(() => {
675
+ * client.waitForInitialization(5).then(() => {
670
676
  * doSomethingWithSuccessfullyInitializedClient();
671
677
  * }).catch(err => {
672
678
  * doSomethingForFailedStartup(err);
@@ -674,7 +680,7 @@ declare module 'launchdarkly-js-sdk-common' {
674
680
  *
675
681
  * // using async/await
676
682
  * try {
677
- * await client.waitForInitialization();
683
+ * await client.waitForInitialization(5);
678
684
  * doSomethingWithSuccessfullyInitializedClient();
679
685
  * } catch (err) {
680
686
  * doSomethingForFailedStartup(err);
@@ -689,11 +695,20 @@ declare module 'launchdarkly-js-sdk-common' {
689
695
  * Note that you can also use event listeners ({@link on}) for the same purpose: the event `"initialized"`
690
696
  * indicates success, and `"failed"` indicates failure.
691
697
  *
698
+ * @param timeout
699
+ * The amount of time, in seconds, to wait for initialization before rejecting the promise.
700
+ * Using a large timeout is not recommended. If you use a large timeout and await it, then
701
+ * any network delays will cause your application to wait a long time before
702
+ * continuing execution.
703
+ *
704
+ * If no timeout is specified, then the returned promise will only be resolved when the client
705
+ * successfully initializes or initialization fails.
706
+ *
692
707
  * @returns
693
708
  * A Promise that will be resolved if the client initializes successfully, or rejected if it
694
- * fails.
709
+ * fails or the specified timeout elapses.
695
710
  */
696
- waitForInitialization(): Promise<void>;
711
+ waitForInitialization(timeout?: number): Promise<void>;
697
712
 
698
713
  /**
699
714
  * Identifies a context to LaunchDarkly.
@@ -720,7 +735,11 @@ declare module 'launchdarkly-js-sdk-common' {
720
735
  * values for the new context are available, providing an {@link LDFlagSet} containing the new values
721
736
  * (which can also be obtained by calling {@link variation}).
722
737
  */
723
- identify(context: LDContext, hash?: string, onDone?: (err: Error | null, flags: LDFlagSet | null) => void): Promise<LDFlagSet>;
738
+ identify(
739
+ context: LDContext,
740
+ hash?: string,
741
+ onDone?: (err: Error | null, flags: LDFlagSet | null) => void
742
+ ): Promise<LDFlagSet>;
724
743
 
725
744
  /**
726
745
  * Returns the client's current context.
@@ -766,7 +785,7 @@ declare module 'launchdarkly-js-sdk-common' {
766
785
  * Determines the variation of a feature flag for a context, along with information about how it was
767
786
  * calculated.
768
787
  *
769
- * Note that this will only work if you have set `evaluationExplanations` to true in {@link LDOptions}.
788
+ * Note that this will only work if you have set `evaluationReasons` to true in {@link LDOptions}.
770
789
  * Otherwise, the `reason` property of the result will be null.
771
790
  *
772
791
  * The `reason` property of the result will also be included in analytics events, if you are
@@ -909,7 +928,7 @@ declare module 'launchdarkly-js-sdk-common' {
909
928
  * @param formatter An optional function equivalent to Node's util.format, allowing
910
929
  * for parameter substitution in log messages. If this is omitted, parameter
911
930
  * substitution is not available.
912
- *
931
+ *
913
932
  * @example
914
933
  * This example shows how to use `basicLogger` in your SDK options to enable console
915
934
  * logging only at `warn` and `error` levels.
@@ -927,7 +946,7 @@ declare module 'launchdarkly-js-sdk-common' {
927
946
  * logger: ld.basicLogger({ destination: console.error }),
928
947
  * };
929
948
  * ```
930
- *
949
+ *
931
950
  * @ignore (don't need to show this separately in TypeDoc output; each SDK should provide its own
932
951
  * basicLogger function that delegates to this and sets the formatter parameter)
933
952
  */
@@ -971,7 +990,7 @@ declare module 'launchdarkly-js-sdk-common' {
971
990
  * Setting this property to anything other than a function will cause SDK
972
991
  * initialization to fail.
973
992
  */
974
- destination?: (line: string) => void,
993
+ destination?: (line: string) => void;
975
994
  }
976
995
 
977
996
  /**
@@ -984,26 +1003,30 @@ declare module 'launchdarkly-js-sdk-common' {
984
1003
  */
985
1004
  export type LDLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'none';
986
1005
 
987
- export function getContextKeys(
988
- context: LDContext,
989
- logger?: LDLogger,
990
- ): {[attribute: string]: string} | undefined;
1006
+ export function getContextKeys(context: LDContext, logger?: LDLogger): { [attribute: string]: string } | undefined;
991
1007
 
992
1008
  /**
993
1009
  * Callback interface for collecting information about the SDK at runtime.
994
- *
1010
+ *
995
1011
  * This interface is used to collect information about flag usage.
996
- *
1012
+ *
997
1013
  * This interface should not be used by the application to access flags for the purpose of controlling application
998
1014
  * flow. It is intended for monitoring, analytics, or debugging purposes.
999
1015
  */
1000
1016
  export interface LDInspectionFlagUsedHandler {
1001
- type: 'flag-used',
1017
+ type: 'flag-used';
1002
1018
 
1003
1019
  /**
1004
1020
  * Name of the inspector. Will be used for logging issues with the inspector.
1005
1021
  */
1006
- name: string,
1022
+ name: string;
1023
+
1024
+ /**
1025
+ * If `true`, then the inspector will be ran synchronously with evaluation.
1026
+ * Synchronous inspectors execute inline with evaluation and care should be taken to ensure
1027
+ * they have minimal performance overhead.
1028
+ */
1029
+ synchronous?: boolean,
1007
1030
 
1008
1031
  /**
1009
1032
  * This method is called when a flag is accessed via a variation method, or it can be called based on actions in
@@ -1015,22 +1038,27 @@ declare module 'launchdarkly-js-sdk-common' {
1015
1038
 
1016
1039
  /**
1017
1040
  * Callback interface for collecting information about the SDK at runtime.
1018
- *
1041
+ *
1019
1042
  * This interface is used to collect information about flag data. In order to understand the
1020
1043
  * current flag state it should be combined with {@link LDInspectionFlagValueChangedHandler}.
1021
- * This interface will get the initial flag information, and
1044
+ * This interface will get the initial flag information, and
1022
1045
  * {@link LDInspectionFlagValueChangedHandler} will provide changes to individual flags.
1023
- *
1046
+ *
1024
1047
  * This interface should not be used by the application to access flags for the purpose of controlling application
1025
1048
  * flow. It is intended for monitoring, analytics, or debugging purposes.
1026
1049
  */
1027
1050
  export interface LDInspectionFlagDetailsChangedHandler {
1028
- type: 'flag-details-changed',
1051
+ type: 'flag-details-changed';
1029
1052
 
1030
1053
  /**
1031
1054
  * Name of the inspector. Will be used for logging issues with the inspector.
1032
1055
  */
1033
- name: string,
1056
+ name: string;
1057
+
1058
+ /**
1059
+ * If `true`, then the inspector will be ran synchronously with flag updates.
1060
+ */
1061
+ synchronous?: boolean,
1034
1062
 
1035
1063
  /**
1036
1064
  * This method is called when the flags in the store are replaced with new flags. It will contain all flags
@@ -1039,24 +1067,28 @@ declare module 'launchdarkly-js-sdk-common' {
1039
1067
  method: (details: Record<string, LDEvaluationDetail>) => void;
1040
1068
  }
1041
1069
 
1042
-
1043
1070
  /**
1044
1071
  * Callback interface for collecting information about the SDK at runtime.
1045
- *
1072
+ *
1046
1073
  * This interface is used to collect changes to flag data, but does not provide the initial
1047
1074
  * data. It can be combined with {@link LDInspectionFlagValuesChangedHandler} to track the
1048
1075
  * entire flag state.
1049
- *
1076
+ *
1050
1077
  * This interface should not be used by the application to access flags for the purpose of controlling application
1051
1078
  * flow. It is intended for monitoring, analytics, or debugging purposes.
1052
1079
  */
1053
1080
  export interface LDInspectionFlagDetailChangedHandler {
1054
- type: 'flag-detail-changed',
1081
+ type: 'flag-detail-changed';
1055
1082
 
1056
1083
  /**
1057
1084
  * Name of the inspector. Will be used for logging issues with the inspector.
1058
1085
  */
1059
- name: string,
1086
+ name: string;
1087
+
1088
+ /**
1089
+ * If `true`, then the inspector will be ran synchronously with flag updates.
1090
+ */
1091
+ synchronous?: boolean,
1060
1092
 
1061
1093
  /**
1062
1094
  * This method is called when a flag is updated. It will not be called
@@ -1067,19 +1099,24 @@ declare module 'launchdarkly-js-sdk-common' {
1067
1099
 
1068
1100
  /**
1069
1101
  * Callback interface for collecting information about the SDK at runtime.
1070
- *
1102
+ *
1071
1103
  * This interface is used to track current identity state of the SDK.
1072
- *
1104
+ *
1073
1105
  * This interface should not be used by the application to access flags for the purpose of controlling application
1074
1106
  * flow. It is intended for monitoring, analytics, or debugging purposes.
1075
1107
  */
1076
1108
  export interface LDInspectionIdentifyHandler {
1077
- type: 'client-identity-changed',
1109
+ type: 'client-identity-changed';
1078
1110
 
1079
1111
  /**
1080
1112
  * Name of the inspector. Will be used for logging issues with the inspector.
1081
1113
  */
1082
- name: string,
1114
+ name: string;
1115
+
1116
+ /**
1117
+ * If `true`, then the inspector will be ran synchronously with identification.
1118
+ */
1119
+ synchronous?: boolean,
1083
1120
 
1084
1121
  /**
1085
1122
  * This method will be called when an identify operation completes.
@@ -1087,6 +1124,9 @@ declare module 'launchdarkly-js-sdk-common' {
1087
1124
  method: (context: LDContext) => void;
1088
1125
  }
1089
1126
 
1090
- export type LDInspection = LDInspectionFlagUsedHandler | LDInspectionFlagDetailsChangedHandler
1091
- | LDInspectionFlagDetailChangedHandler | LDInspectionIdentifyHandler;
1127
+ export type LDInspection =
1128
+ | LDInspectionFlagUsedHandler
1129
+ | LDInspectionFlagDetailsChangedHandler
1130
+ | LDInspectionFlagDetailChangedHandler
1131
+ | LDInspectionIdentifyHandler;
1092
1132
  }
@@ -1,25 +0,0 @@
1
- version: 2
2
-
3
- repo:
4
- public: js-sdk-common
5
- private: js-sdk-common-private
6
-
7
- branches:
8
- - name: main
9
- description: 5.x
10
- - name: 4.x
11
- - name: 3.x
12
-
13
- publications:
14
- - url: https://www.npmjs.com/package/launchdarkly-js-sdk-common
15
- description: npm
16
-
17
- jobs:
18
- - docker:
19
- image: node:12-buster
20
- template:
21
- name: npm
22
-
23
- documentation:
24
- gitHubPages: true
25
- title: LaunchDarkly Javascript SDK Core Components
package/docs/typedoc.js DELETED
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- out: '/tmp/project-releaser/project/docs/build/html',
3
- exclude: [
4
- '**/node_modules/**',
5
- 'test-types.ts'
6
- ],
7
- name: "LaunchDarkly Javascript SDK Core Components (4.0.2)",
8
- readme: 'none', // don't add a home page with a copy of README.md
9
- entryPoints: "/tmp/project-releaser/project/typings.d.ts",
10
- entryPointStrategy: "expand"
11
- };