launchdarkly-js-sdk-common 4.3.2 → 5.0.0-alpha.2
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/CHANGELOG.md +7 -0
- package/package.json +3 -1
- package/src/AnonymousContextProcessor.js +95 -0
- package/src/ContextFilter.js +137 -0
- package/src/EventProcessor.js +30 -13
- package/src/EventSender.js +1 -1
- package/src/Identity.js +10 -11
- package/src/InspectorManager.js +1 -1
- package/src/PersistentFlagStore.js +3 -3
- package/src/Requestor.js +4 -4
- package/src/SafeInspector.js +1 -1
- package/src/Stream.js +5 -5
- package/src/__tests__/ContextFilter-test.js +427 -0
- package/src/__tests__/EventProcessor-test.js +50 -121
- package/src/__tests__/LDClient-events-test.js +9 -152
- package/src/__tests__/LDClient-inspectors-test.js +1 -1
- package/src/__tests__/LDClient-test.js +18 -15
- package/src/__tests__/TransientContextProcessor-test.js +115 -0
- package/src/__tests__/attributeReference-test.js +400 -0
- package/src/__tests__/configuration-test.js +20 -21
- package/src/__tests__/context-test.js +93 -0
- package/src/__tests__/diagnosticEvents-test.js +0 -4
- package/src/__tests__/testUtils.js +0 -2
- package/src/__tests__/utils-test.js +3 -9
- package/src/attributeReference.js +143 -0
- package/src/configuration.js +4 -8
- package/src/context.js +96 -0
- package/src/diagnosticEvents.js +0 -2
- package/src/index.js +76 -89
- package/src/messages.js +8 -8
- package/src/utils.js +19 -16
- package/test-types.ts +3 -8
- package/typings.d.ts +296 -139
- package/src/UserFilter.js +0 -75
- package/src/UserValidator.js +0 -56
- package/src/__tests__/UserFilter-test.js +0 -93
- package/src/__tests__/UserValidator-test.js +0 -57
package/typings.d.ts
CHANGED
|
@@ -58,8 +58,8 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
58
58
|
* The initial set of flags to use until the remote set is retrieved.
|
|
59
59
|
*
|
|
60
60
|
* If `"localStorage"` is specified, the flags will be saved and retrieved from browser local
|
|
61
|
-
* storage. Alternatively, an
|
|
62
|
-
* source of flag values. In the latter case, the flag values will be available via
|
|
61
|
+
* storage. Alternatively, an {@link LDFlagSet} can be specified which will be used as the initial
|
|
62
|
+
* source of flag values. In the latter case, the flag values will be available via {@link LDClient.variation}
|
|
63
63
|
* immediately after calling `initialize()` (normally they would not be available until the
|
|
64
64
|
* client signals that it is ready).
|
|
65
65
|
*
|
|
@@ -93,7 +93,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
93
93
|
*
|
|
94
94
|
* If this is true, the client will always attempt to maintain a streaming connection; if false,
|
|
95
95
|
* it never will. If you leave the value undefined (the default), the client will open a streaming
|
|
96
|
-
* connection if you subscribe to `"change"` or `"change:flag-key"` events (see
|
|
96
|
+
* connection if you subscribe to `"change"` or `"change:flag-key"` events (see {@link LDClient.on}).
|
|
97
97
|
*
|
|
98
98
|
* This is equivalent to calling `client.setStreaming()` with the same value.
|
|
99
99
|
*/
|
|
@@ -103,9 +103,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
103
103
|
* Whether or not to use the REPORT verb to fetch flag settings.
|
|
104
104
|
*
|
|
105
105
|
* If this is true, flag settings will be fetched with a REPORT request
|
|
106
|
-
* including a JSON entity body with the
|
|
106
|
+
* including a JSON entity body with the context object.
|
|
107
107
|
*
|
|
108
|
-
* Otherwise (by default) a GET request will be issued with the
|
|
108
|
+
* Otherwise (by default) a GET request will be issued with the context passed as
|
|
109
109
|
* a base64 URL-encoded path parameter.
|
|
110
110
|
*
|
|
111
111
|
* Do not use unless advised by LaunchDarkly.
|
|
@@ -139,7 +139,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
139
139
|
* calculated.
|
|
140
140
|
*
|
|
141
141
|
* The additional information will then be available through the client's
|
|
142
|
-
*
|
|
142
|
+
* {@link LDClient.variationDetail} method. Since this increases the size of network requests,
|
|
143
143
|
* such information is not sent unless you set this option to true.
|
|
144
144
|
*/
|
|
145
145
|
evaluationReasons?: boolean;
|
|
@@ -150,7 +150,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
150
150
|
sendEvents?: boolean;
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
|
-
* Whether all
|
|
153
|
+
* Whether all context attributes (except the context key) should be marked as private, and
|
|
154
154
|
* not sent to LaunchDarkly in analytics events.
|
|
155
155
|
*
|
|
156
156
|
* By default, this is false.
|
|
@@ -158,30 +158,23 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
158
158
|
allAttributesPrivate?: boolean;
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
|
-
*
|
|
162
|
-
* to LaunchDarkly in analytics events. You can also specify this on a
|
|
163
|
-
* with
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* that
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
* This option is deprecated, and setting it has no effect.
|
|
177
|
-
*
|
|
178
|
-
* The behavior is now to allow frequent duplicate events.
|
|
179
|
-
*
|
|
180
|
-
* This is not a problem because most events will be summarized, and
|
|
181
|
-
* events which are not summarized are important to the operation of features such as
|
|
182
|
-
* experimentation.
|
|
161
|
+
* Specifies a list of attribute names (either built-in or custom) which should be marked as
|
|
162
|
+
* private, and not sent to LaunchDarkly in analytics events. You can also specify this on a
|
|
163
|
+
* per-context basis with {@link LDContextMeta.privateAttributes}.
|
|
164
|
+
*
|
|
165
|
+
* Any contexts sent to LaunchDarkly with this configuration active will have attributes with
|
|
166
|
+
* these names removed in analytic events. This is in addition to any attributes that were
|
|
167
|
+
* marked as private for an individual context with {@link LDContextMeta.privateAttributes}.
|
|
168
|
+
* Setting {@link LDOptions.allAttributesPrivate} to true overrides this.
|
|
169
|
+
*
|
|
170
|
+
* If and only if a parameter starts with a slash, it is interpreted as a slash-delimited path
|
|
171
|
+
* that can denote a nested property within a JSON object. For instance, "/address/street" means
|
|
172
|
+
* that if there is an attribute called "address" that is a JSON object, and one of the object's
|
|
173
|
+
* properties is "street", the "street" property will be redacted from the analytics data but
|
|
174
|
+
* other properties within "address" will still be sent. This syntax also uses the JSON Pointer
|
|
175
|
+
* convention of escaping a literal slash character as "~1" and a tilde as "~0".
|
|
183
176
|
*/
|
|
184
|
-
|
|
177
|
+
privateAttributes?: Array<string>;
|
|
185
178
|
|
|
186
179
|
/**
|
|
187
180
|
* Whether analytics events should be sent only when you call variation (true), or also when you
|
|
@@ -216,7 +209,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
216
209
|
* How long (in milliseconds) to wait after a failure of the stream connection before trying to
|
|
217
210
|
* reconnect.
|
|
218
211
|
*
|
|
219
|
-
* This only applies if streaming has been enabled by setting
|
|
212
|
+
* This only applies if streaming has been enabled by setting {@link streaming} to true or
|
|
220
213
|
* subscribing to `"change"` events. The default is 1000ms.
|
|
221
214
|
*/
|
|
222
215
|
streamReconnectDelay?: number;
|
|
@@ -235,7 +228,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
235
228
|
/**
|
|
236
229
|
* The interval at which periodic diagnostic data is sent, in milliseconds.
|
|
237
230
|
*
|
|
238
|
-
* The default is 900000 (every 15 minutes) and the minimum value is 6000. See
|
|
231
|
+
* The default is 900000 (every 15 minutes) and the minimum value is 6000. See {@link diagnosticOptOut}
|
|
239
232
|
* for more information on the diagnostics data being sent.
|
|
240
233
|
*/
|
|
241
234
|
diagnosticRecordingInterval?: number;
|
|
@@ -255,14 +248,6 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
255
248
|
*/
|
|
256
249
|
wrapperVersion?: string;
|
|
257
250
|
|
|
258
|
-
/**
|
|
259
|
-
* Whether to disable the automatic sending of an alias event when [[identify]] is
|
|
260
|
-
* called with a non-anonymous user when the previous user is anonymous.
|
|
261
|
-
*
|
|
262
|
-
* The default value is `false`.
|
|
263
|
-
*/
|
|
264
|
-
autoAliasingOptOut?: boolean;
|
|
265
|
-
|
|
266
251
|
/**
|
|
267
252
|
* Information about the application where the LaunchDarkly SDK is running.
|
|
268
253
|
*/
|
|
@@ -294,8 +279,204 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
294
279
|
inspectors?: LDInspection[];
|
|
295
280
|
}
|
|
296
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Meta attributes are used to control behavioral aspects of the Context.
|
|
284
|
+
* They cannot be addressed in targeting rules.
|
|
285
|
+
*/
|
|
286
|
+
export interface LDContextMeta {
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
*
|
|
290
|
+
* Designate any number of Context attributes, or properties within them, as private: that is,
|
|
291
|
+
* their values will not be sent to LaunchDarkly in analytics events.
|
|
292
|
+
*
|
|
293
|
+
* Each parameter can be a simple attribute name, such as "email". Or, if the first character is
|
|
294
|
+
* a slash, the parameter is interpreted as a slash-delimited path to a property within a JSON
|
|
295
|
+
* object, where the first path component is a Context attribute name and each following
|
|
296
|
+
* component is a nested property name: for example, suppose the attribute "address" had the
|
|
297
|
+
* following JSON object value:
|
|
298
|
+
*
|
|
299
|
+
* ```
|
|
300
|
+
* {"street": {"line1": "abc", "line2": "def"}}
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* Using ["/address/street/line1"] in this case would cause the "line1" property to be marked as
|
|
304
|
+
* private. This syntax deliberately resembles JSON Pointer, but other JSON Pointer features
|
|
305
|
+
* such as array indexing are not supported for Private.
|
|
306
|
+
*
|
|
307
|
+
* This action only affects analytics events that involve this particular Context. To mark some
|
|
308
|
+
* (or all) Context attributes as private for all users, use the overall configuration for the
|
|
309
|
+
* SDK.
|
|
310
|
+
* See {@link LDOptions.allAttributesPrivate} and {@link LDOptions.privateAttributes}.
|
|
311
|
+
*
|
|
312
|
+
* The attributes "kind" and "key", and the "_meta" attributes cannot be made private.
|
|
313
|
+
*
|
|
314
|
+
* In this example, firstName is marked as private, but lastName is not:
|
|
315
|
+
*
|
|
316
|
+
* ```
|
|
317
|
+
* const context = {
|
|
318
|
+
* kind: 'org',
|
|
319
|
+
* key: 'my-key',
|
|
320
|
+
* firstName: 'Pierre',
|
|
321
|
+
* lastName: 'Menard',
|
|
322
|
+
* _meta: {
|
|
323
|
+
* privateAttributes: ['firstName'],
|
|
324
|
+
* }
|
|
325
|
+
* };
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* This is a metadata property, rather than an attribute that can be addressed in evaluations:
|
|
329
|
+
* that is, a rule clause that references the attribute name "privateAttributes", will not use
|
|
330
|
+
* this value, but instead will use whatever value (if any) you have set for that name with a
|
|
331
|
+
* method such as SetString.
|
|
332
|
+
*/
|
|
333
|
+
privateAttributes?: string[];
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Interface containing elements which are common to both single kind contexts as well as the
|
|
338
|
+
* parts that compose a multi context. For more information see {@link LDSingleKindContext} and
|
|
339
|
+
* {@link LDMultiKindContext}.
|
|
340
|
+
*/
|
|
341
|
+
interface LDContextCommon {
|
|
342
|
+
/**
|
|
343
|
+
* If true, the context will _not_ appear on the Contexts page in the LaunchDarkly dashboard.
|
|
344
|
+
*/
|
|
345
|
+
anonymous?: boolean;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* A unique string identifying a context.
|
|
349
|
+
*/
|
|
350
|
+
key: string;
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The context's name.
|
|
354
|
+
*
|
|
355
|
+
* You can search for contexts on the Contexts page by name.
|
|
356
|
+
*/
|
|
357
|
+
name?: string;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Meta attributes are used to control behavioral aspects of the Context, such as private
|
|
361
|
+
* private attributes. See {@link LDContextMeta.privateAttributes} as an example.
|
|
362
|
+
*
|
|
363
|
+
* They cannot be addressed in targeting rules.
|
|
364
|
+
*/
|
|
365
|
+
_meta?: LDContextMeta;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Any additional attributes associated with the context.
|
|
369
|
+
*/
|
|
370
|
+
[attribute: string]: any;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* A context which represents a single kind.
|
|
376
|
+
*
|
|
377
|
+
* For a single kind context the 'kind' may not be 'multi'.
|
|
378
|
+
*
|
|
379
|
+
* ```
|
|
380
|
+
* const myOrgContext = {
|
|
381
|
+
* kind: 'org',
|
|
382
|
+
* key: 'my-org-key',
|
|
383
|
+
* someAttribute: 'my-attribute-value'
|
|
384
|
+
* };
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* The above context would be a single kind context representing an organization. It has a key
|
|
388
|
+
* for that organization, and a single attribute 'someAttribute'.
|
|
389
|
+
*/
|
|
390
|
+
interface LDSingleKindContext extends LDContextCommon {
|
|
391
|
+
/**
|
|
392
|
+
* The kind of the context.
|
|
393
|
+
*/
|
|
394
|
+
kind: string;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* A context which represents multiple kinds. Each kind having its own key and attributes.
|
|
399
|
+
*
|
|
400
|
+
* A multi-context must contain `kind: 'multi'` at the root.
|
|
401
|
+
*
|
|
402
|
+
* ```
|
|
403
|
+
* const myMultiContext = {
|
|
404
|
+
* // Multi-contexts must be of kind 'multi'.
|
|
405
|
+
* kind: 'multi',
|
|
406
|
+
* // The context is namespaced by its kind. This is an 'org' kind context.
|
|
407
|
+
* org: {
|
|
408
|
+
* // Each component context has its own key and attributes.
|
|
409
|
+
* key: 'my-org-key',
|
|
410
|
+
* someAttribute: 'my-attribute-value',
|
|
411
|
+
* },
|
|
412
|
+
* user: {
|
|
413
|
+
* key: 'my-user-key',
|
|
414
|
+
* firstName: 'Bob',
|
|
415
|
+
* lastName: 'Bobberson',
|
|
416
|
+
* _meta: {
|
|
417
|
+
* // Each component context has its own _meta attributes. This will only apply the this
|
|
418
|
+
* // 'user' context.
|
|
419
|
+
* privateAttributes: ['firstName']
|
|
420
|
+
* }
|
|
421
|
+
* }
|
|
422
|
+
* };
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* The above multi-context contains both an 'org' and a 'user'. Each with their own key,
|
|
426
|
+
* attributes, and _meta attributes.
|
|
427
|
+
*/
|
|
428
|
+
interface LDMultiKindContext {
|
|
429
|
+
/**
|
|
430
|
+
* The kind of the context.
|
|
431
|
+
*/
|
|
432
|
+
kind: "multi",
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The contexts which compose this multi-kind context.
|
|
436
|
+
*
|
|
437
|
+
* These should be of type LDContextCommon. "multi" is to allow
|
|
438
|
+
* for the top level "kind" attribute.
|
|
439
|
+
*/
|
|
440
|
+
[kind: string]: "multi" | LDContextCommon;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* A LaunchDarkly context object.
|
|
445
|
+
*/
|
|
446
|
+
export type LDContext = LDUser | LDSingleKindContext | LDMultiKindContext;
|
|
447
|
+
|
|
297
448
|
/**
|
|
298
449
|
* A LaunchDarkly user object.
|
|
450
|
+
*
|
|
451
|
+
* @deprecated
|
|
452
|
+
* The LDUser object is currently supported for ease of upgrade.
|
|
453
|
+
* In order to convert an LDUser into a LDSingleKindContext the following changes should
|
|
454
|
+
* be made.
|
|
455
|
+
*
|
|
456
|
+
* 1.) Add a kind to the object. `kind: 'user'`.
|
|
457
|
+
*
|
|
458
|
+
* 2.) Move custom attributes to the top level of the object.
|
|
459
|
+
*
|
|
460
|
+
* 3.) Move `privateAttributeNames` to `_meta.privateAttributes`.
|
|
461
|
+
*
|
|
462
|
+
* ```
|
|
463
|
+
* const LDUser: user = {
|
|
464
|
+
* key: '1234',
|
|
465
|
+
* privateAttributeNames: ['myAttr']
|
|
466
|
+
* custom: {
|
|
467
|
+
* myAttr: 'value'
|
|
468
|
+
* }
|
|
469
|
+
* }
|
|
470
|
+
*
|
|
471
|
+
* const LDSingleKindContext: context = {
|
|
472
|
+
* kind: 'user',
|
|
473
|
+
* key: '1234',
|
|
474
|
+
* myAttr: 'value'
|
|
475
|
+
* _meta: {
|
|
476
|
+
* privateAttributes: ['myAttr']
|
|
477
|
+
* }
|
|
478
|
+
* }
|
|
479
|
+
* ```
|
|
299
480
|
*/
|
|
300
481
|
export interface LDUser {
|
|
301
482
|
/**
|
|
@@ -310,14 +491,6 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
310
491
|
*/
|
|
311
492
|
key?: string;
|
|
312
493
|
|
|
313
|
-
/**
|
|
314
|
-
* An optional secondary key for a user. This affects
|
|
315
|
-
* [feature flag targeting](https://docs.launchdarkly.com/home/flags/targeting-users#targeting-rules-based-on-user-attributes)
|
|
316
|
-
* as follows: if you have chosen to bucket users by a specific attribute, the secondary key (if set)
|
|
317
|
-
* is used to further distinguish between users who are otherwise identical according to that attribute.
|
|
318
|
-
*/
|
|
319
|
-
secondary?: string;
|
|
320
|
-
|
|
321
494
|
/**
|
|
322
495
|
* The user's name.
|
|
323
496
|
*
|
|
@@ -374,23 +547,23 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
374
547
|
* Specifies a list of attribute names (either built-in or custom) which should be
|
|
375
548
|
* marked as private, and not sent to LaunchDarkly in analytics events. This is in
|
|
376
549
|
* addition to any private attributes designated in the global configuration
|
|
377
|
-
* with
|
|
550
|
+
* with {@link LDOptions.privateAttributes} or {@link LDOptions.allAttributesPrivate}.
|
|
378
551
|
*/
|
|
379
552
|
privateAttributeNames?: Array<string>;
|
|
380
553
|
}
|
|
381
554
|
|
|
382
555
|
/**
|
|
383
556
|
* Describes the reason that a flag evaluation produced a particular value. This is
|
|
384
|
-
* part of the
|
|
557
|
+
* part of the {@link LDEvaluationDetail} object returned by {@link LDClient.variationDetail]].
|
|
385
558
|
*/
|
|
386
559
|
interface LDEvaluationReason {
|
|
387
560
|
/**
|
|
388
561
|
* The general category of the reason:
|
|
389
562
|
*
|
|
390
563
|
* - `'OFF'`: The flag was off and therefore returned its configured off value.
|
|
391
|
-
* - `'FALLTHROUGH'`: The flag was on but the
|
|
392
|
-
* - `'TARGET_MATCH'`: The
|
|
393
|
-
* - `'RULE_MATCH'`: the
|
|
564
|
+
* - `'FALLTHROUGH'`: The flag was on but the context did not match any targets or rules.
|
|
565
|
+
* - `'TARGET_MATCH'`: The context key was specifically targeted for this flag.
|
|
566
|
+
* - `'RULE_MATCH'`: the context matched one of the flag's rules.
|
|
394
567
|
* - `'PREREQUISITE_FAILED'`: The flag was considered off because it had at least one
|
|
395
568
|
* prerequisite flag that either was off or did not return the desired variation.
|
|
396
569
|
* - `'ERROR'`: The flag could not be evaluated, e.g. because it does not exist or due
|
|
@@ -423,14 +596,14 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
423
596
|
* An object that combines the result of a feature flag evaluation with information about
|
|
424
597
|
* how it was calculated.
|
|
425
598
|
*
|
|
426
|
-
* This is the result of calling
|
|
599
|
+
* This is the result of calling {@link LDClient.variationDetail}.
|
|
427
600
|
*
|
|
428
601
|
* For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#javascript).
|
|
429
602
|
*/
|
|
430
603
|
export interface LDEvaluationDetail {
|
|
431
604
|
/**
|
|
432
605
|
* The result of the flag evaluation. This will be either one of the flag's variations or
|
|
433
|
-
* the default value that was passed to
|
|
606
|
+
* the default value that was passed to {@link LDClient.variationDetail}.
|
|
434
607
|
*/
|
|
435
608
|
value: LDFlagValue;
|
|
436
609
|
|
|
@@ -475,9 +648,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
475
648
|
* ```
|
|
476
649
|
*
|
|
477
650
|
* If you want to distinguish between these success and failure conditions, use
|
|
478
|
-
*
|
|
651
|
+
* {@link waitForInitialization} instead.
|
|
479
652
|
*
|
|
480
|
-
* If you prefer to use event listeners (
|
|
653
|
+
* If you prefer to use event listeners ({@link on}) rather than Promises, you can listen on the
|
|
481
654
|
* client for a `"ready"` event, which will be fired in either case.
|
|
482
655
|
*
|
|
483
656
|
* @returns
|
|
@@ -513,7 +686,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
513
686
|
* request it, so if you never call `waitForInitialization()` then you do not have to worry about
|
|
514
687
|
* unhandled rejections.
|
|
515
688
|
*
|
|
516
|
-
* Note that you can also use event listeners (
|
|
689
|
+
* Note that you can also use event listeners ({@link on}) for the same purpose: the event `"initialized"`
|
|
517
690
|
* indicates success, and `"failed"` indicates failure.
|
|
518
691
|
*
|
|
519
692
|
* @returns
|
|
@@ -523,45 +696,45 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
523
696
|
waitForInitialization(): Promise<void>;
|
|
524
697
|
|
|
525
698
|
/**
|
|
526
|
-
* Identifies a
|
|
699
|
+
* Identifies a context to LaunchDarkly.
|
|
527
700
|
*
|
|
528
|
-
* Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current
|
|
529
|
-
* which is set at initialization time. You only need to call `identify()` if the
|
|
701
|
+
* Unlike the server-side SDKs, the client-side JavaScript SDKs maintain a current context state,
|
|
702
|
+
* which is set at initialization time. You only need to call `identify()` if the context has changed
|
|
530
703
|
* since then.
|
|
531
704
|
*
|
|
532
|
-
* Changing the current
|
|
533
|
-
* finished, calls to
|
|
705
|
+
* Changing the current context also causes all feature flag values to be reloaded. Until that has
|
|
706
|
+
* finished, calls to {@link variation} will still return flag values for the previous context. You can
|
|
534
707
|
* use a callback or a Promise to determine when the new flag values are available.
|
|
535
708
|
*
|
|
536
|
-
* @param
|
|
537
|
-
* The
|
|
709
|
+
* @param context
|
|
710
|
+
* The context properties. Must contain at least the `key` property.
|
|
538
711
|
* @param hash
|
|
539
|
-
* The signed
|
|
712
|
+
* The signed context key if you are using [Secure Mode](https://docs.launchdarkly.com/sdk/features/secure-mode#configuring-secure-mode-in-the-javascript-client-side-sdk).
|
|
540
713
|
* @param onDone
|
|
541
|
-
* A function which will be called as soon as the flag values for the new
|
|
542
|
-
* with two parameters: an error value (if any), and an
|
|
543
|
-
* (which can also be obtained by calling
|
|
714
|
+
* A function which will be called as soon as the flag values for the new context are available,
|
|
715
|
+
* with two parameters: an error value (if any), and an {@link LDFlagSet} containing the new values
|
|
716
|
+
* (which can also be obtained by calling {@link variation}). If the callback is omitted, you will
|
|
544
717
|
* receive a Promise instead.
|
|
545
718
|
* @returns
|
|
546
719
|
* If you provided a callback, then nothing. Otherwise, a Promise which resolve once the flag
|
|
547
|
-
* values for the new
|
|
548
|
-
* (which can also be obtained by calling
|
|
720
|
+
* values for the new context are available, providing an {@link LDFlagSet} containing the new values
|
|
721
|
+
* (which can also be obtained by calling {@link variation}).
|
|
549
722
|
*/
|
|
550
|
-
identify(
|
|
723
|
+
identify(context: LDContext, hash?: string, onDone?: (err: Error | null, flags: LDFlagSet | null) => void): Promise<LDFlagSet>;
|
|
551
724
|
|
|
552
725
|
/**
|
|
553
|
-
* Returns the client's current
|
|
726
|
+
* Returns the client's current context.
|
|
554
727
|
*
|
|
555
|
-
* This is the
|
|
556
|
-
* been called, the initial
|
|
728
|
+
* This is the context that was most recently passed to {@link identify}, or, if {@link identify} has never
|
|
729
|
+
* been called, the initial context specified when the client was created.
|
|
557
730
|
*/
|
|
558
|
-
|
|
731
|
+
getContext(): LDContext;
|
|
559
732
|
|
|
560
733
|
/**
|
|
561
734
|
* Flushes all pending analytics events.
|
|
562
735
|
*
|
|
563
736
|
* Normally, batches of events are delivered in the background at intervals determined by the
|
|
564
|
-
* `flushInterval` property of
|
|
737
|
+
* `flushInterval` property of {@link LDOptions}. Calling `flush()` triggers an immediate delivery.
|
|
565
738
|
*
|
|
566
739
|
* @param onDone
|
|
567
740
|
* A function which will be called when the flush completes. If omitted, you
|
|
@@ -575,10 +748,10 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
575
748
|
flush(onDone?: () => void): Promise<void>;
|
|
576
749
|
|
|
577
750
|
/**
|
|
578
|
-
* Determines the variation of a feature flag for the current
|
|
751
|
+
* Determines the variation of a feature flag for the current context.
|
|
579
752
|
*
|
|
580
753
|
* In the client-side JavaScript SDKs, this is always a fast synchronous operation because all of
|
|
581
|
-
* the feature flag values for the current
|
|
754
|
+
* the feature flag values for the current context have already been loaded into memory.
|
|
582
755
|
*
|
|
583
756
|
* @param key
|
|
584
757
|
* The unique key of the feature flag.
|
|
@@ -590,10 +763,10 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
590
763
|
variation(key: string, defaultValue?: LDFlagValue): LDFlagValue;
|
|
591
764
|
|
|
592
765
|
/**
|
|
593
|
-
* Determines the variation of a feature flag for a
|
|
766
|
+
* Determines the variation of a feature flag for a context, along with information about how it was
|
|
594
767
|
* calculated.
|
|
595
768
|
*
|
|
596
|
-
* Note that this will only work if you have set `evaluationExplanations` to true in
|
|
769
|
+
* Note that this will only work if you have set `evaluationExplanations` to true in {@link LDOptions}.
|
|
597
770
|
* Otherwise, the `reason` property of the result will be null.
|
|
598
771
|
*
|
|
599
772
|
* The `reason` property of the result will also be included in analytics events, if you are
|
|
@@ -607,7 +780,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
607
780
|
* The default value of the flag, to be used if the value is not available from LaunchDarkly.
|
|
608
781
|
*
|
|
609
782
|
* @returns
|
|
610
|
-
* An
|
|
783
|
+
* An {@link LDEvaluationDetail} object containing the value and explanation.
|
|
611
784
|
*/
|
|
612
785
|
variationDetail(key: string, defaultValue?: LDFlagValue): LDEvaluationDetail;
|
|
613
786
|
|
|
@@ -616,9 +789,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
616
789
|
*
|
|
617
790
|
* If this is true, the client will always attempt to maintain a streaming connection; if false,
|
|
618
791
|
* it never will. If you leave the value undefined (the default), the client will open a streaming
|
|
619
|
-
* connection if you subscribe to `"change"` or `"change:flag-key"` events (see
|
|
792
|
+
* connection if you subscribe to `"change"` or `"change:flag-key"` events (see {@link LDClient.on}).
|
|
620
793
|
*
|
|
621
|
-
* This can also be set as the `streaming` property of
|
|
794
|
+
* This can also be set as the `streaming` property of {@link LDOptions}.
|
|
622
795
|
*/
|
|
623
796
|
setStreaming(value?: boolean): void;
|
|
624
797
|
|
|
@@ -639,9 +812,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
639
812
|
* The callback parameter is an Error object. If you do not listen for "error"
|
|
640
813
|
* events, then the errors will be logged with `console.log()`.
|
|
641
814
|
* - `"change"`: The client has received new feature flag data. This can happen either
|
|
642
|
-
* because you have switched
|
|
815
|
+
* because you have switched contexts with {@link identify}, or because the client has a
|
|
643
816
|
* stream connection and has received a live change to a flag value (see below).
|
|
644
|
-
* The callback parameter is an
|
|
817
|
+
* The callback parameter is an {@link LDFlagChangeset}.
|
|
645
818
|
* - `"change:FLAG-KEY"`: The client has received a new value for a specific flag
|
|
646
819
|
* whose key is `FLAG-KEY`. The callback receives two parameters: the current (new)
|
|
647
820
|
* flag value, and the previous value. This is always accompanied by a general
|
|
@@ -650,27 +823,27 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
650
823
|
* The `"change"` and `"change:FLAG-KEY"` events have special behavior: by default, the
|
|
651
824
|
* client will open a streaming connection to receive live changes if and only if
|
|
652
825
|
* you are listening for one of these events. This behavior can be overridden by
|
|
653
|
-
* setting `streaming` in
|
|
826
|
+
* setting `streaming` in {@link LDOptions} or calling {@link LDClient.setStreaming}.
|
|
654
827
|
*
|
|
655
828
|
* @param key
|
|
656
829
|
* The name of the event for which to listen.
|
|
657
830
|
* @param callback
|
|
658
831
|
* The function to execute when the event fires. The callback may or may not
|
|
659
|
-
* receive parameters, depending on the type of event
|
|
832
|
+
* receive parameters, depending on the type of event.
|
|
660
833
|
* @param context
|
|
661
834
|
* The `this` context to use for the callback.
|
|
662
835
|
*/
|
|
663
836
|
on(key: string, callback: (...args: any[]) => void, context?: any): void;
|
|
664
837
|
|
|
665
838
|
/**
|
|
666
|
-
* Deregisters an event listener. See
|
|
839
|
+
* Deregisters an event listener. See {@link on} for the available event types.
|
|
667
840
|
*
|
|
668
841
|
* @param key
|
|
669
842
|
* The name of the event for which to stop listening.
|
|
670
843
|
* @param callback
|
|
671
844
|
* The function to deregister.
|
|
672
845
|
* @param context
|
|
673
|
-
* The `this` context for the callback, if one was specified for
|
|
846
|
+
* The `this` context for the callback, if one was specified for {@link on}.
|
|
674
847
|
*/
|
|
675
848
|
off(key: string, callback: (...args: any[]) => void, context?: any): void;
|
|
676
849
|
|
|
@@ -694,56 +867,40 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
694
867
|
track(key: string, data?: any, metricValue?: number): void;
|
|
695
868
|
|
|
696
869
|
/**
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
* This can be helpful in the situation where a person is represented by multiple
|
|
700
|
-
* LaunchDarkly users. This may happen, for example, when a person initially logs into
|
|
701
|
-
* an application-- the person might be represented by an anonymous user prior to logging
|
|
702
|
-
* in and a different user after logging in, as denoted by a different user key.
|
|
703
|
-
*
|
|
704
|
-
* @param user
|
|
705
|
-
* The newly identified user.
|
|
706
|
-
* @param previousUser
|
|
707
|
-
* The previously identified user.
|
|
708
|
-
*/
|
|
709
|
-
alias(user: LDUser, previousUser: LDUser): void;
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* Returns a map of all available flags to the current user's values. This will send analytics
|
|
713
|
-
* events unless [[LDOptions.sendEventsOnlyForVariation]] is true.
|
|
870
|
+
* Returns a map of all available flags to the current context's values.
|
|
714
871
|
*
|
|
715
872
|
* @returns
|
|
716
873
|
* An object in which each key is a feature flag key and each value is the flag value.
|
|
717
874
|
* Note that there is no way to specify a default value for each flag as there is with
|
|
718
|
-
*
|
|
875
|
+
* {@link variation}, so any flag that cannot be evaluated will have a null value.
|
|
719
876
|
*/
|
|
720
877
|
allFlags(): LDFlagSet;
|
|
721
878
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
879
|
+
/**
|
|
880
|
+
* Shuts down the client and releases its resources, after delivering any pending analytics
|
|
881
|
+
* events. After the client is closed, all calls to {@link variation} will return default values,
|
|
882
|
+
* and it will not make any requests to LaunchDarkly.
|
|
883
|
+
*
|
|
884
|
+
* @param onDone
|
|
885
|
+
* A function which will be called when the operation completes. If omitted, you
|
|
886
|
+
* will receive a Promise instead.
|
|
887
|
+
*
|
|
888
|
+
* @returns
|
|
889
|
+
* If you provided a callback, then nothing. Otherwise, a Promise which resolves once
|
|
890
|
+
* closing is finished. It will never be rejected.
|
|
891
|
+
*/
|
|
892
|
+
close(onDone?: () => void): Promise<void>;
|
|
736
893
|
}
|
|
737
894
|
|
|
738
895
|
/**
|
|
739
|
-
* Provides a simple
|
|
896
|
+
* Provides a simple {@link LDLogger} implementation.
|
|
740
897
|
*
|
|
741
898
|
* This logging implementation uses a simple format that includes only the log level
|
|
742
899
|
* and the message text. Output is written to the console unless otherwise specified.
|
|
743
|
-
* You can filter by log level as described in
|
|
900
|
+
* You can filter by log level as described in {@link BasicLoggerOptions.level}.
|
|
744
901
|
*
|
|
745
|
-
* To use the logger created by this function, put it into
|
|
746
|
-
* you do not set
|
|
902
|
+
* To use the logger created by this function, put it into {@link LDOptions.logger}. If
|
|
903
|
+
* you do not set {@link LDOptions.logger} to anything, the SDK uses a default logger
|
|
747
904
|
* that is equivalent to `ld.basicLogger({ level: 'info' })`.
|
|
748
905
|
*
|
|
749
906
|
* @param options Configuration for the logger. If no options are specified, the
|
|
@@ -774,19 +931,19 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
774
931
|
* @ignore (don't need to show this separately in TypeDoc output; each SDK should provide its own
|
|
775
932
|
* basicLogger function that delegates to this and sets the formatter parameter)
|
|
776
933
|
*/
|
|
777
|
-
|
|
934
|
+
export function commonBasicLogger(
|
|
778
935
|
options?: BasicLoggerOptions,
|
|
779
936
|
formatter?: (format: string, ...args: any[]) => void
|
|
780
937
|
): LDLogger;
|
|
781
938
|
|
|
782
939
|
/**
|
|
783
|
-
* Configuration for
|
|
940
|
+
* Configuration for {@link basicLogger}.
|
|
784
941
|
*/
|
|
785
942
|
export interface BasicLoggerOptions {
|
|
786
943
|
/**
|
|
787
944
|
* The lowest level of log message to enable.
|
|
788
945
|
*
|
|
789
|
-
* See
|
|
946
|
+
* See {@link LDLogLevel} for a list of possible levels. Setting a level here causes
|
|
790
947
|
* all lower-importance levels to be disabled: for instance, if you specify
|
|
791
948
|
* `'warn'`, then `'debug'` and `'info'` are disabled.
|
|
792
949
|
*
|
|
@@ -818,9 +975,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
818
975
|
}
|
|
819
976
|
|
|
820
977
|
/**
|
|
821
|
-
* Logging levels that can be used with
|
|
978
|
+
* Logging levels that can be used with {@link basicLogger}.
|
|
822
979
|
*
|
|
823
|
-
* Set
|
|
980
|
+
* Set {@link BasicLoggerOptions.level} to one of these values to control what levels
|
|
824
981
|
* of log messages are enabled. Going from lowest importance (and most verbose)
|
|
825
982
|
* to most importance, the levels are `'debug'`, `'info'`, `'warn'`, and `'error'`.
|
|
826
983
|
* You can also specify `'none'` instead to disable all logging.
|
|
@@ -848,9 +1005,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
848
1005
|
* wrapper SDKs which have different methods of tracking when a flag was accessed. It is not called when a call is made
|
|
849
1006
|
* to allFlags.
|
|
850
1007
|
*/
|
|
851
|
-
method: (flagKey: string, flagDetail: LDEvaluationDetail,
|
|
1008
|
+
method: (flagKey: string, flagDetail: LDEvaluationDetail, context: LDContext) => void;
|
|
852
1009
|
}
|
|
853
|
-
|
|
1010
|
+
|
|
854
1011
|
/**
|
|
855
1012
|
* Callback interface for collecting information about the SDK at runtime.
|
|
856
1013
|
*
|
|
@@ -869,15 +1026,15 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
869
1026
|
* Name of the inspector. Will be used for logging issues with the inspector.
|
|
870
1027
|
*/
|
|
871
1028
|
name: string,
|
|
872
|
-
|
|
1029
|
+
|
|
873
1030
|
/**
|
|
874
1031
|
* This method is called when the flags in the store are replaced with new flags. It will contain all flags
|
|
875
1032
|
* regardless of if they have been evaluated.
|
|
876
1033
|
*/
|
|
877
1034
|
method: (details: Record<string, LDEvaluationDetail>) => void;
|
|
878
1035
|
}
|
|
879
|
-
|
|
880
|
-
|
|
1036
|
+
|
|
1037
|
+
|
|
881
1038
|
/**
|
|
882
1039
|
* Callback interface for collecting information about the SDK at runtime.
|
|
883
1040
|
*
|
|
@@ -895,7 +1052,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
895
1052
|
* Name of the inspector. Will be used for logging issues with the inspector.
|
|
896
1053
|
*/
|
|
897
1054
|
name: string,
|
|
898
|
-
|
|
1055
|
+
|
|
899
1056
|
/**
|
|
900
1057
|
* This method is called when a flag is updated. It will not be called
|
|
901
1058
|
* when all flags are updated.
|
|
@@ -918,11 +1075,11 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
918
1075
|
* Name of the inspector. Will be used for logging issues with the inspector.
|
|
919
1076
|
*/
|
|
920
1077
|
name: string,
|
|
921
|
-
|
|
1078
|
+
|
|
922
1079
|
/**
|
|
923
1080
|
* This method will be called when an identify operation completes.
|
|
924
1081
|
*/
|
|
925
|
-
method: (
|
|
1082
|
+
method: (context: LDContext) => void;
|
|
926
1083
|
}
|
|
927
1084
|
|
|
928
1085
|
type LDInspection = LDInspectionFlagUsedHandler | LDInspectionFlagDetailsChangedHandler
|