launchdarkly-js-sdk-common 5.0.0-alpha.1 → 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 +1 -1
- package/src/ContextFilter.js +0 -10
- package/src/InspectorManager.js +1 -1
- package/src/SafeInspector.js +1 -1
- package/src/__tests__/ContextFilter-test.js +0 -43
- package/src/__tests__/testUtils.js +0 -2
- package/src/utils.js +1 -1
- package/test-types.ts +0 -1
- package/typings.d.ts +231 -138
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to the `launchdarkly-js-sdk-common` package will be documented in this file. Changes that affect the dependent SDKs such as `launchdarkly-js-client-sdk` should also be logged in those projects, in the next release that uses the updated version of this package. This project adheres to [Semantic Versioning](http://semver.org).
|
|
4
4
|
|
|
5
|
+
## [4.3.2] - 2022-10-20
|
|
6
|
+
### Added:
|
|
7
|
+
- Implemented `jitter` and `backoff` for streaming connections. When a connection fails the retry will start at the `streamReconnectDelay` and will double on each unsuccessful consecutive connection attempt (`backoff`) to a max of 30 seconds. The delay will be adjusted from 50%-100% of the calculated delay to prevent many clients from attempting to reconnect at the same time (`jitter`).
|
|
8
|
+
|
|
9
|
+
### Changed:
|
|
10
|
+
- Removed usage of `flatMap`. (Thanks [@mateuszsikora](https://github.com/launchdarkly/js-sdk-common/pull/77))
|
|
11
|
+
|
|
5
12
|
## [4.3.1] - 2022-10-17
|
|
6
13
|
### Fixed:
|
|
7
14
|
- Fixed an issue that prevented the `flag-used` inspector from being called.
|
package/package.json
CHANGED
package/src/ContextFilter.js
CHANGED
|
@@ -41,12 +41,6 @@ function ContextFilter(config) {
|
|
|
41
41
|
cloned._meta.redactedAttributes = excluded;
|
|
42
42
|
}
|
|
43
43
|
if (cloned._meta) {
|
|
44
|
-
if (cloned._meta.secondary === null) {
|
|
45
|
-
delete cloned._meta.secondary;
|
|
46
|
-
}
|
|
47
|
-
if (cloned._meta.secondary !== undefined) {
|
|
48
|
-
cloned._meta.secondary = String(cloned._meta.secondary);
|
|
49
|
-
}
|
|
50
44
|
delete cloned._meta['privateAttributes'];
|
|
51
45
|
if (Object.keys(cloned._meta).length === 0) {
|
|
52
46
|
delete cloned._meta;
|
|
@@ -123,10 +117,6 @@ function ContextFilter(config) {
|
|
|
123
117
|
literal => (literal.startsWith('/') ? AttributeReference.literalToReference(literal) : literal)
|
|
124
118
|
);
|
|
125
119
|
}
|
|
126
|
-
if (user.secondary !== undefined && user.secondary !== null) {
|
|
127
|
-
filtered._meta = filtered._meta || {};
|
|
128
|
-
filtered._meta.secondary = String(user.secondary);
|
|
129
|
-
}
|
|
130
120
|
|
|
131
121
|
return filtered;
|
|
132
122
|
};
|
package/src/InspectorManager.js
CHANGED
package/src/SafeInspector.js
CHANGED
|
@@ -216,22 +216,6 @@ describe('when handling single kind contexts', () => {
|
|
|
216
216
|
dizzle: 'ghi',
|
|
217
217
|
};
|
|
218
218
|
|
|
219
|
-
const contextWithNonStringKeyKeyAndSecondary = {
|
|
220
|
-
kind: 'rebel',
|
|
221
|
-
key: 42,
|
|
222
|
-
_meta: {
|
|
223
|
-
secondary: 0,
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const contextWithNullSecondary = {
|
|
228
|
-
kind: 'rebel',
|
|
229
|
-
key: 42,
|
|
230
|
-
_meta: {
|
|
231
|
-
secondary: null,
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
|
|
235
219
|
// expected results from serializing context
|
|
236
220
|
const userWithAllAttrsHidden = {
|
|
237
221
|
kind: 'organization',
|
|
@@ -269,19 +253,6 @@ describe('when handling single kind contexts', () => {
|
|
|
269
253
|
},
|
|
270
254
|
};
|
|
271
255
|
|
|
272
|
-
const contextWithStringifiedKeyKeyAndSecondary = {
|
|
273
|
-
kind: 'rebel',
|
|
274
|
-
key: '42',
|
|
275
|
-
_meta: {
|
|
276
|
-
secondary: '0',
|
|
277
|
-
},
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const contextWithNullSecondaryFiltered = {
|
|
281
|
-
kind: 'rebel',
|
|
282
|
-
key: '42',
|
|
283
|
-
};
|
|
284
|
-
|
|
285
256
|
it('includes all attributes by default', () => {
|
|
286
257
|
const uf = ContextFilter({});
|
|
287
258
|
expect(uf.filter(context)).toEqual(context);
|
|
@@ -312,16 +283,6 @@ describe('when handling single kind contexts', () => {
|
|
|
312
283
|
expect(uf.filter(anonymousContext)).toEqual(contextWithAllAttrsHidden);
|
|
313
284
|
});
|
|
314
285
|
|
|
315
|
-
it('handles non-string key and secondary', () => {
|
|
316
|
-
const uf = ContextFilter({ allAttributesPrivate: true });
|
|
317
|
-
expect(uf.filter(contextWithNonStringKeyKeyAndSecondary)).toEqual(contextWithStringifiedKeyKeyAndSecondary);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it('does not produce "null" as a secondary attribute', () => {
|
|
321
|
-
const cf = ContextFilter({});
|
|
322
|
-
expect(cf.filter(contextWithNullSecondary)).toEqual(contextWithNullSecondaryFiltered);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
286
|
it('converts non-boolean anonymous to boolean.', () => {
|
|
326
287
|
const uf = ContextFilter({});
|
|
327
288
|
expect(uf.filter({ kind: 'user', key: 'user', anonymous: 'string' })).toEqual({
|
|
@@ -376,7 +337,6 @@ describe('when handling mult-kind contexts', () => {
|
|
|
376
337
|
b: 'b',
|
|
377
338
|
},
|
|
378
339
|
_meta: {
|
|
379
|
-
secondary: 'order',
|
|
380
340
|
privateAttributes: ['letters', '/object/b'],
|
|
381
341
|
},
|
|
382
342
|
},
|
|
@@ -393,7 +353,6 @@ describe('when handling mult-kind contexts', () => {
|
|
|
393
353
|
user: {
|
|
394
354
|
key: 'abc',
|
|
395
355
|
_meta: {
|
|
396
|
-
secondary: 'order',
|
|
397
356
|
redactedAttributes: ['/letters', '/name', '/object', '/order'],
|
|
398
357
|
},
|
|
399
358
|
},
|
|
@@ -418,7 +377,6 @@ describe('when handling mult-kind contexts', () => {
|
|
|
418
377
|
a: 'a',
|
|
419
378
|
},
|
|
420
379
|
_meta: {
|
|
421
|
-
secondary: 'order',
|
|
422
380
|
redactedAttributes: ['/letters', '/name', '/object/b'],
|
|
423
381
|
},
|
|
424
382
|
},
|
|
@@ -442,7 +400,6 @@ describe('when handling mult-kind contexts', () => {
|
|
|
442
400
|
a: 'a',
|
|
443
401
|
},
|
|
444
402
|
_meta: {
|
|
445
|
-
secondary: 'order',
|
|
446
403
|
redactedAttributes: ['/letters', '/object/b'],
|
|
447
404
|
},
|
|
448
405
|
},
|
|
@@ -2,7 +2,6 @@ import { AsyncQueue } from 'launchdarkly-js-test-helpers';
|
|
|
2
2
|
|
|
3
3
|
export const numericUser = {
|
|
4
4
|
key: 1,
|
|
5
|
-
secondary: 2,
|
|
6
5
|
ip: 3,
|
|
7
6
|
country: 4,
|
|
8
7
|
email: 5,
|
|
@@ -33,7 +32,6 @@ export function promiseListener() {
|
|
|
33
32
|
|
|
34
33
|
export const stringifiedNumericUser = {
|
|
35
34
|
key: '1',
|
|
36
|
-
secondary: '2',
|
|
37
35
|
ip: '3',
|
|
38
36
|
country: '4',
|
|
39
37
|
email: '5',
|
package/src/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const base64 = require('base64-js');
|
|
2
2
|
const fastDeepEqual = require('fast-deep-equal');
|
|
3
3
|
|
|
4
|
-
const userAttrsToStringify = ['key', '
|
|
4
|
+
const userAttrsToStringify = ['key', 'ip', 'country', 'email', 'firstName', 'lastName', 'avatar', 'name'];
|
|
5
5
|
|
|
6
6
|
function appendUrlPath(baseUrl, path) {
|
|
7
7
|
// Ensure that URL concatenation is done correctly regardless of whether the
|
package/test-types.ts
CHANGED
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
|
*/
|
|
@@ -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;
|
|
@@ -158,9 +158,21 @@ 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
|
|
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".
|
|
164
176
|
*/
|
|
165
177
|
privateAttributes?: Array<string>;
|
|
166
178
|
|
|
@@ -197,7 +209,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
197
209
|
* How long (in milliseconds) to wait after a failure of the stream connection before trying to
|
|
198
210
|
* reconnect.
|
|
199
211
|
*
|
|
200
|
-
* 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
|
|
201
213
|
* subscribing to `"change"` events. The default is 1000ms.
|
|
202
214
|
*/
|
|
203
215
|
streamReconnectDelay?: number;
|
|
@@ -216,7 +228,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
216
228
|
/**
|
|
217
229
|
* The interval at which periodic diagnostic data is sent, in milliseconds.
|
|
218
230
|
*
|
|
219
|
-
* 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}
|
|
220
232
|
* for more information on the diagnostics data being sent.
|
|
221
233
|
*/
|
|
222
234
|
diagnosticRecordingInterval?: number;
|
|
@@ -239,7 +251,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
239
251
|
/**
|
|
240
252
|
* Information about the application where the LaunchDarkly SDK is running.
|
|
241
253
|
*/
|
|
242
|
-
|
|
254
|
+
application?: {
|
|
243
255
|
/**
|
|
244
256
|
* A unique identifier representing the application where the LaunchDarkly SDK is running.
|
|
245
257
|
*
|
|
@@ -268,105 +280,164 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
268
280
|
}
|
|
269
281
|
|
|
270
282
|
/**
|
|
271
|
-
*
|
|
272
|
-
* TKTK
|
|
273
|
-
*
|
|
274
283
|
* Meta attributes are used to control behavioral aspects of the Context.
|
|
275
|
-
* They cannot be addressed in
|
|
284
|
+
* They cannot be addressed in targeting rules.
|
|
276
285
|
*/
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* An optional secondary key for a context.
|
|
280
|
-
*
|
|
281
|
-
* TKTK
|
|
282
|
-
*
|
|
283
|
-
* This affects [feature flag targeting](https://docs.launchdarkly.com/home/flags/targeting-users#targeting-rules-based-on-user-attributes)
|
|
284
|
-
* as follows: if you have chosen to bucket context by a specific attribute, the secondary key (if set)
|
|
285
|
-
* is used to further distinguish between contexts which are otherwise identical according to that attribute.
|
|
286
|
-
*/
|
|
287
|
-
secondary?: string;
|
|
286
|
+
export interface LDContextMeta {
|
|
288
287
|
|
|
289
288
|
/**
|
|
290
289
|
*
|
|
291
|
-
*
|
|
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
292
|
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
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.
|
|
297
332
|
*/
|
|
298
333
|
privateAttributes?: string[];
|
|
299
334
|
}
|
|
300
335
|
|
|
301
336
|
/**
|
|
302
|
-
*
|
|
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}.
|
|
303
340
|
*/
|
|
304
341
|
interface LDContextCommon {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
342
|
+
/**
|
|
343
|
+
* If true, the context will _not_ appear on the Contexts page in the LaunchDarkly dashboard.
|
|
344
|
+
*/
|
|
345
|
+
anonymous?: boolean;
|
|
309
346
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
347
|
+
/**
|
|
348
|
+
* A unique string identifying a context.
|
|
349
|
+
*/
|
|
350
|
+
key: string;
|
|
314
351
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
352
|
+
/**
|
|
353
|
+
* The context's name.
|
|
354
|
+
*
|
|
355
|
+
* You can search for contexts on the Contexts page by name.
|
|
356
|
+
*/
|
|
357
|
+
name?: string;
|
|
321
358
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
_meta?: LDContextMeta;
|
|
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;
|
|
330
366
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Any additional attributes associated with the context.
|
|
369
|
+
*/
|
|
370
|
+
[attribute: string]: any;
|
|
335
371
|
}
|
|
336
372
|
|
|
337
373
|
|
|
338
374
|
/**
|
|
375
|
+
* A context which represents a single kind.
|
|
376
|
+
*
|
|
377
|
+
* For a single kind context the 'kind' may not be 'multi'.
|
|
339
378
|
*
|
|
340
|
-
*
|
|
379
|
+
* ```
|
|
380
|
+
* const myOrgContext = {
|
|
381
|
+
* kind: 'org',
|
|
382
|
+
* key: 'my-org-key',
|
|
383
|
+
* someAttribute: 'my-attribute-value'
|
|
384
|
+
* };
|
|
385
|
+
* ```
|
|
341
386
|
*
|
|
342
|
-
*
|
|
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'.
|
|
343
389
|
*/
|
|
344
390
|
interface LDSingleKindContext extends LDContextCommon {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
391
|
+
/**
|
|
392
|
+
* The kind of the context.
|
|
393
|
+
*/
|
|
394
|
+
kind: string;
|
|
349
395
|
}
|
|
350
396
|
|
|
351
397
|
/**
|
|
398
|
+
* A context which represents multiple kinds. Each kind having its own key and attributes.
|
|
352
399
|
*
|
|
353
|
-
*
|
|
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
|
+
* ```
|
|
354
424
|
*
|
|
355
|
-
*
|
|
425
|
+
* The above multi-context contains both an 'org' and a 'user'. Each with their own key,
|
|
426
|
+
* attributes, and _meta attributes.
|
|
356
427
|
*/
|
|
357
428
|
interface LDMultiKindContext {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
429
|
+
/**
|
|
430
|
+
* The kind of the context.
|
|
431
|
+
*/
|
|
432
|
+
kind: "multi",
|
|
362
433
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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;
|
|
370
441
|
}
|
|
371
442
|
|
|
372
443
|
/**
|
|
@@ -376,6 +447,36 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
376
447
|
|
|
377
448
|
/**
|
|
378
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
|
+
* ```
|
|
379
480
|
*/
|
|
380
481
|
export interface LDUser {
|
|
381
482
|
/**
|
|
@@ -390,14 +491,6 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
390
491
|
*/
|
|
391
492
|
key?: string;
|
|
392
493
|
|
|
393
|
-
/**
|
|
394
|
-
* An optional secondary key for a user. This affects
|
|
395
|
-
* [feature flag targeting](https://docs.launchdarkly.com/home/flags/targeting-users#targeting-rules-based-on-user-attributes)
|
|
396
|
-
* as follows: if you have chosen to bucket users by a specific attribute, the secondary key (if set)
|
|
397
|
-
* is used to further distinguish between users who are otherwise identical according to that attribute.
|
|
398
|
-
*/
|
|
399
|
-
secondary?: string;
|
|
400
|
-
|
|
401
494
|
/**
|
|
402
495
|
* The user's name.
|
|
403
496
|
*
|
|
@@ -454,14 +547,14 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
454
547
|
* Specifies a list of attribute names (either built-in or custom) which should be
|
|
455
548
|
* marked as private, and not sent to LaunchDarkly in analytics events. This is in
|
|
456
549
|
* addition to any private attributes designated in the global configuration
|
|
457
|
-
* with
|
|
550
|
+
* with {@link LDOptions.privateAttributes} or {@link LDOptions.allAttributesPrivate}.
|
|
458
551
|
*/
|
|
459
552
|
privateAttributeNames?: Array<string>;
|
|
460
553
|
}
|
|
461
554
|
|
|
462
555
|
/**
|
|
463
556
|
* Describes the reason that a flag evaluation produced a particular value. This is
|
|
464
|
-
* part of the
|
|
557
|
+
* part of the {@link LDEvaluationDetail} object returned by {@link LDClient.variationDetail]].
|
|
465
558
|
*/
|
|
466
559
|
interface LDEvaluationReason {
|
|
467
560
|
/**
|
|
@@ -503,14 +596,14 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
503
596
|
* An object that combines the result of a feature flag evaluation with information about
|
|
504
597
|
* how it was calculated.
|
|
505
598
|
*
|
|
506
|
-
* This is the result of calling
|
|
599
|
+
* This is the result of calling {@link LDClient.variationDetail}.
|
|
507
600
|
*
|
|
508
601
|
* For more information, see the [SDK reference guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#javascript).
|
|
509
602
|
*/
|
|
510
603
|
export interface LDEvaluationDetail {
|
|
511
604
|
/**
|
|
512
605
|
* The result of the flag evaluation. This will be either one of the flag's variations or
|
|
513
|
-
* the default value that was passed to
|
|
606
|
+
* the default value that was passed to {@link LDClient.variationDetail}.
|
|
514
607
|
*/
|
|
515
608
|
value: LDFlagValue;
|
|
516
609
|
|
|
@@ -555,9 +648,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
555
648
|
* ```
|
|
556
649
|
*
|
|
557
650
|
* If you want to distinguish between these success and failure conditions, use
|
|
558
|
-
*
|
|
651
|
+
* {@link waitForInitialization} instead.
|
|
559
652
|
*
|
|
560
|
-
* 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
|
|
561
654
|
* client for a `"ready"` event, which will be fired in either case.
|
|
562
655
|
*
|
|
563
656
|
* @returns
|
|
@@ -593,7 +686,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
593
686
|
* request it, so if you never call `waitForInitialization()` then you do not have to worry about
|
|
594
687
|
* unhandled rejections.
|
|
595
688
|
*
|
|
596
|
-
* 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"`
|
|
597
690
|
* indicates success, and `"failed"` indicates failure.
|
|
598
691
|
*
|
|
599
692
|
* @returns
|
|
@@ -610,7 +703,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
610
703
|
* since then.
|
|
611
704
|
*
|
|
612
705
|
* Changing the current context also causes all feature flag values to be reloaded. Until that has
|
|
613
|
-
* finished, calls to
|
|
706
|
+
* finished, calls to {@link variation} will still return flag values for the previous context. You can
|
|
614
707
|
* use a callback or a Promise to determine when the new flag values are available.
|
|
615
708
|
*
|
|
616
709
|
* @param context
|
|
@@ -619,20 +712,20 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
619
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).
|
|
620
713
|
* @param onDone
|
|
621
714
|
* A function which will be called as soon as the flag values for the new context are available,
|
|
622
|
-
* with two parameters: an error value (if any), and an
|
|
623
|
-
* (which can also be obtained by calling
|
|
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
|
|
624
717
|
* receive a Promise instead.
|
|
625
718
|
* @returns
|
|
626
719
|
* If you provided a callback, then nothing. Otherwise, a Promise which resolve once the flag
|
|
627
|
-
* values for the new context are available, providing an
|
|
628
|
-
* (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}).
|
|
629
722
|
*/
|
|
630
723
|
identify(context: LDContext, hash?: string, onDone?: (err: Error | null, flags: LDFlagSet | null) => void): Promise<LDFlagSet>;
|
|
631
724
|
|
|
632
725
|
/**
|
|
633
726
|
* Returns the client's current context.
|
|
634
727
|
*
|
|
635
|
-
* This is the context that was most recently passed to
|
|
728
|
+
* This is the context that was most recently passed to {@link identify}, or, if {@link identify} has never
|
|
636
729
|
* been called, the initial context specified when the client was created.
|
|
637
730
|
*/
|
|
638
731
|
getContext(): LDContext;
|
|
@@ -641,7 +734,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
641
734
|
* Flushes all pending analytics events.
|
|
642
735
|
*
|
|
643
736
|
* Normally, batches of events are delivered in the background at intervals determined by the
|
|
644
|
-
* `flushInterval` property of
|
|
737
|
+
* `flushInterval` property of {@link LDOptions}. Calling `flush()` triggers an immediate delivery.
|
|
645
738
|
*
|
|
646
739
|
* @param onDone
|
|
647
740
|
* A function which will be called when the flush completes. If omitted, you
|
|
@@ -673,7 +766,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
673
766
|
* Determines the variation of a feature flag for a context, along with information about how it was
|
|
674
767
|
* calculated.
|
|
675
768
|
*
|
|
676
|
-
* 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}.
|
|
677
770
|
* Otherwise, the `reason` property of the result will be null.
|
|
678
771
|
*
|
|
679
772
|
* The `reason` property of the result will also be included in analytics events, if you are
|
|
@@ -687,7 +780,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
687
780
|
* The default value of the flag, to be used if the value is not available from LaunchDarkly.
|
|
688
781
|
*
|
|
689
782
|
* @returns
|
|
690
|
-
* An
|
|
783
|
+
* An {@link LDEvaluationDetail} object containing the value and explanation.
|
|
691
784
|
*/
|
|
692
785
|
variationDetail(key: string, defaultValue?: LDFlagValue): LDEvaluationDetail;
|
|
693
786
|
|
|
@@ -696,9 +789,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
696
789
|
*
|
|
697
790
|
* If this is true, the client will always attempt to maintain a streaming connection; if false,
|
|
698
791
|
* it never will. If you leave the value undefined (the default), the client will open a streaming
|
|
699
|
-
* 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}).
|
|
700
793
|
*
|
|
701
|
-
* This can also be set as the `streaming` property of
|
|
794
|
+
* This can also be set as the `streaming` property of {@link LDOptions}.
|
|
702
795
|
*/
|
|
703
796
|
setStreaming(value?: boolean): void;
|
|
704
797
|
|
|
@@ -719,9 +812,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
719
812
|
* The callback parameter is an Error object. If you do not listen for "error"
|
|
720
813
|
* events, then the errors will be logged with `console.log()`.
|
|
721
814
|
* - `"change"`: The client has received new feature flag data. This can happen either
|
|
722
|
-
* because you have switched contexts with
|
|
815
|
+
* because you have switched contexts with {@link identify}, or because the client has a
|
|
723
816
|
* stream connection and has received a live change to a flag value (see below).
|
|
724
|
-
* The callback parameter is an
|
|
817
|
+
* The callback parameter is an {@link LDFlagChangeset}.
|
|
725
818
|
* - `"change:FLAG-KEY"`: The client has received a new value for a specific flag
|
|
726
819
|
* whose key is `FLAG-KEY`. The callback receives two parameters: the current (new)
|
|
727
820
|
* flag value, and the previous value. This is always accompanied by a general
|
|
@@ -730,27 +823,27 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
730
823
|
* The `"change"` and `"change:FLAG-KEY"` events have special behavior: by default, the
|
|
731
824
|
* client will open a streaming connection to receive live changes if and only if
|
|
732
825
|
* you are listening for one of these events. This behavior can be overridden by
|
|
733
|
-
* setting `streaming` in
|
|
826
|
+
* setting `streaming` in {@link LDOptions} or calling {@link LDClient.setStreaming}.
|
|
734
827
|
*
|
|
735
828
|
* @param key
|
|
736
829
|
* The name of the event for which to listen.
|
|
737
830
|
* @param callback
|
|
738
831
|
* The function to execute when the event fires. The callback may or may not
|
|
739
|
-
* receive parameters, depending on the type of event
|
|
832
|
+
* receive parameters, depending on the type of event.
|
|
740
833
|
* @param context
|
|
741
834
|
* The `this` context to use for the callback.
|
|
742
835
|
*/
|
|
743
836
|
on(key: string, callback: (...args: any[]) => void, context?: any): void;
|
|
744
837
|
|
|
745
838
|
/**
|
|
746
|
-
* Deregisters an event listener. See
|
|
839
|
+
* Deregisters an event listener. See {@link on} for the available event types.
|
|
747
840
|
*
|
|
748
841
|
* @param key
|
|
749
842
|
* The name of the event for which to stop listening.
|
|
750
843
|
* @param callback
|
|
751
844
|
* The function to deregister.
|
|
752
845
|
* @param context
|
|
753
|
-
* 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}.
|
|
754
847
|
*/
|
|
755
848
|
off(key: string, callback: (...args: any[]) => void, context?: any): void;
|
|
756
849
|
|
|
@@ -779,35 +872,35 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
779
872
|
* @returns
|
|
780
873
|
* An object in which each key is a feature flag key and each value is the flag value.
|
|
781
874
|
* Note that there is no way to specify a default value for each flag as there is with
|
|
782
|
-
*
|
|
875
|
+
* {@link variation}, so any flag that cannot be evaluated will have a null value.
|
|
783
876
|
*/
|
|
784
877
|
allFlags(): LDFlagSet;
|
|
785
878
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
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>;
|
|
800
893
|
}
|
|
801
894
|
|
|
802
895
|
/**
|
|
803
|
-
* Provides a simple
|
|
896
|
+
* Provides a simple {@link LDLogger} implementation.
|
|
804
897
|
*
|
|
805
898
|
* This logging implementation uses a simple format that includes only the log level
|
|
806
899
|
* and the message text. Output is written to the console unless otherwise specified.
|
|
807
|
-
* You can filter by log level as described in
|
|
900
|
+
* You can filter by log level as described in {@link BasicLoggerOptions.level}.
|
|
808
901
|
*
|
|
809
|
-
* To use the logger created by this function, put it into
|
|
810
|
-
* 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
|
|
811
904
|
* that is equivalent to `ld.basicLogger({ level: 'info' })`.
|
|
812
905
|
*
|
|
813
906
|
* @param options Configuration for the logger. If no options are specified, the
|
|
@@ -838,19 +931,19 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
838
931
|
* @ignore (don't need to show this separately in TypeDoc output; each SDK should provide its own
|
|
839
932
|
* basicLogger function that delegates to this and sets the formatter parameter)
|
|
840
933
|
*/
|
|
841
|
-
|
|
934
|
+
export function commonBasicLogger(
|
|
842
935
|
options?: BasicLoggerOptions,
|
|
843
936
|
formatter?: (format: string, ...args: any[]) => void
|
|
844
937
|
): LDLogger;
|
|
845
938
|
|
|
846
939
|
/**
|
|
847
|
-
* Configuration for
|
|
940
|
+
* Configuration for {@link basicLogger}.
|
|
848
941
|
*/
|
|
849
942
|
export interface BasicLoggerOptions {
|
|
850
943
|
/**
|
|
851
944
|
* The lowest level of log message to enable.
|
|
852
945
|
*
|
|
853
|
-
* See
|
|
946
|
+
* See {@link LDLogLevel} for a list of possible levels. Setting a level here causes
|
|
854
947
|
* all lower-importance levels to be disabled: for instance, if you specify
|
|
855
948
|
* `'warn'`, then `'debug'` and `'info'` are disabled.
|
|
856
949
|
*
|
|
@@ -882,9 +975,9 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
882
975
|
}
|
|
883
976
|
|
|
884
977
|
/**
|
|
885
|
-
* Logging levels that can be used with
|
|
978
|
+
* Logging levels that can be used with {@link basicLogger}.
|
|
886
979
|
*
|
|
887
|
-
* Set
|
|
980
|
+
* Set {@link BasicLoggerOptions.level} to one of these values to control what levels
|
|
888
981
|
* of log messages are enabled. Going from lowest importance (and most verbose)
|
|
889
982
|
* to most importance, the levels are `'debug'`, `'info'`, `'warn'`, and `'error'`.
|
|
890
983
|
* You can also specify `'none'` instead to disable all logging.
|
|
@@ -914,7 +1007,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
914
1007
|
*/
|
|
915
1008
|
method: (flagKey: string, flagDetail: LDEvaluationDetail, context: LDContext) => void;
|
|
916
1009
|
}
|
|
917
|
-
|
|
1010
|
+
|
|
918
1011
|
/**
|
|
919
1012
|
* Callback interface for collecting information about the SDK at runtime.
|
|
920
1013
|
*
|
|
@@ -933,15 +1026,15 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
933
1026
|
* Name of the inspector. Will be used for logging issues with the inspector.
|
|
934
1027
|
*/
|
|
935
1028
|
name: string,
|
|
936
|
-
|
|
1029
|
+
|
|
937
1030
|
/**
|
|
938
1031
|
* This method is called when the flags in the store are replaced with new flags. It will contain all flags
|
|
939
1032
|
* regardless of if they have been evaluated.
|
|
940
1033
|
*/
|
|
941
1034
|
method: (details: Record<string, LDEvaluationDetail>) => void;
|
|
942
1035
|
}
|
|
943
|
-
|
|
944
|
-
|
|
1036
|
+
|
|
1037
|
+
|
|
945
1038
|
/**
|
|
946
1039
|
* Callback interface for collecting information about the SDK at runtime.
|
|
947
1040
|
*
|
|
@@ -959,7 +1052,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
959
1052
|
* Name of the inspector. Will be used for logging issues with the inspector.
|
|
960
1053
|
*/
|
|
961
1054
|
name: string,
|
|
962
|
-
|
|
1055
|
+
|
|
963
1056
|
/**
|
|
964
1057
|
* This method is called when a flag is updated. It will not be called
|
|
965
1058
|
* when all flags are updated.
|
|
@@ -982,7 +1075,7 @@ declare module 'launchdarkly-js-sdk-common' {
|
|
|
982
1075
|
* Name of the inspector. Will be used for logging issues with the inspector.
|
|
983
1076
|
*/
|
|
984
1077
|
name: string,
|
|
985
|
-
|
|
1078
|
+
|
|
986
1079
|
/**
|
|
987
1080
|
* This method will be called when an identify operation completes.
|
|
988
1081
|
*/
|