launchdarkly-js-sdk-common
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -5,2 +5,13 @@ # Change log | ||
## [5.1.0] - 2024-03-19 | ||
### Changed: | ||
- Redact anonymous attributes within feature events | ||
- Always inline contexts for feature events | ||
### Fixed: | ||
- Pin dev version of node to compatible types. | ||
### Removed: | ||
- HTTP fallback ping | ||
## [5.0.3] - 2023-03-21 | ||
@@ -7,0 +18,0 @@ ### Changed: |
{ | ||
"name": "launchdarkly-js-sdk-common", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"description": "LaunchDarkly SDK for JavaScript - common code", | ||
@@ -41,6 +41,6 @@ "author": "LaunchDarkly <team@launchdarkly.com>", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"jest": "^25.5.4", | ||
"jest": "^26.6.3", | ||
"jsdom": "^11.11.0", | ||
"launchdarkly-js-test-helpers": "1.1.0", | ||
"prettier": "1.11.1", | ||
"prettier": "1.19.1", | ||
"readline-sync": "^1.4.9", | ||
@@ -47,0 +47,0 @@ "typescript": "~4.4.4" |
@@ -120,3 +120,6 @@ import { baseOptionDefs } from '../configuration'; | ||
eventsInLastBatch: 2, | ||
streamInits: [{ timestamp: 1001, durationMillis: 100 }, { timestamp: 1002, failed: true, durationMillis: 500 }], | ||
streamInits: [ | ||
{ timestamp: 1001, durationMillis: 100 }, | ||
{ timestamp: 1002, failed: true, durationMillis: 500 }, | ||
], | ||
}; | ||
@@ -396,3 +399,6 @@ const expectedStatsForPeriodicEvent2 = { | ||
eventsInLastBatch: 3, | ||
streamInits: [{ timestamp: 1000, durationMillis: 500 }, { timestamp: 1001, durationMillis: 501 }], | ||
streamInits: [ | ||
{ timestamp: 1000, durationMillis: 500 }, | ||
{ timestamp: 1001, durationMillis: 501 }, | ||
], | ||
}); | ||
@@ -399,0 +405,0 @@ expect(firstEvent.creationDate).toBeGreaterThanOrEqual(timeBeforeStart); |
@@ -13,4 +13,7 @@ import EventProcessor from '../EventProcessor'; | ||
describe.each([ | ||
[{ key: 'userKey', name: 'Red' }, { key: 'userKey', kind: 'user', _meta: { redactedAttributes: ['/name'] } }], | ||
[ | ||
{ key: 'userKey', name: 'Red' }, | ||
{ key: 'userKey', kind: 'user', _meta: { redactedAttributes: ['/name'] } }, | ||
], | ||
[ | ||
{ kind: 'user', key: 'userKey', name: 'Red' }, | ||
@@ -17,0 +20,0 @@ { key: 'userKey', kind: 'user', _meta: { redactedAttributes: ['/name'] } }, |
@@ -102,3 +102,6 @@ import EventSummarizer from '../EventSummarizer'; | ||
default: 111, | ||
counters: [{ variation: 0, value: 100, version: 11, count: 1 }, { value: 111, version: 11, count: 2 }], | ||
counters: [ | ||
{ variation: 0, value: 100, version: 11, count: 1 }, | ||
{ value: 111, version: 11, count: 2 }, | ||
], | ||
}, | ||
@@ -105,0 +108,0 @@ }; |
@@ -80,3 +80,3 @@ import * as messages from '../messages'; | ||
await withClientAndEventProcessor(user, {}, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -91,3 +91,3 @@ expect(ep.events.length).toEqual(1); | ||
await withClientAndEventProcessor(numericUser, {}, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -104,3 +104,3 @@ expect(ep.events.length).toEqual(1); | ||
const user1 = { key: 'user1' }; | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -120,3 +120,3 @@ expect(ep.events.length).toEqual(1); | ||
await withClientAndEventProcessor(user, { baseUrl: server.url }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -138,3 +138,3 @@ expect(ep.events.length).toEqual(1); | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
await client.identify(user1); | ||
@@ -150,3 +150,3 @@ | ||
await withClientAndEventProcessor(user, { bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -174,3 +174,3 @@ client.variation('foo', 'x'); | ||
await withClientAndEventProcessor(anonUser, { baseUrl: server.url, bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -199,3 +199,3 @@ client.variation('foo', 'x'); | ||
await withClientAndEventProcessor(user, { bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.variationDetail('foo', 'x'); | ||
@@ -223,3 +223,3 @@ | ||
await withClientAndEventProcessor(user, { bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.variation('foo', 'x'); | ||
@@ -247,3 +247,3 @@ | ||
await withClientAndEventProcessor(user, { bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.variation('foo', 'x'); | ||
@@ -273,3 +273,3 @@ | ||
await withClientAndEventProcessor(user, { baseUrl: server.url, bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -295,3 +295,3 @@ const user1 = { key: 'user1' }; | ||
await withClientAndEventProcessor(user, extraConfig, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -316,3 +316,3 @@ const user1 = { key: 'user1' }; | ||
await withClientAndEventProcessor(user, extraConfig, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -333,3 +333,3 @@ sp.emit('update', { flags: newFlags }); | ||
await withClientAndEventProcessor(user, { bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.allFlags(); | ||
@@ -351,3 +351,3 @@ | ||
await withClientAndEventProcessor(user, extraConfig, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.allFlags(); | ||
@@ -363,3 +363,3 @@ | ||
await withClientAndEventProcessor(user, { bootstrap: initData }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.variation('foo', 'x'); | ||
@@ -375,3 +375,3 @@ | ||
await withClientAndEventProcessor(user, {}, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.variation('foo', 'x'); | ||
@@ -397,3 +397,3 @@ | ||
await withCloseable(client, async () => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.variation('foo', 'x'); | ||
@@ -420,3 +420,3 @@ | ||
await withClientAndEventProcessor(user, {}, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.track('eventkey'); | ||
@@ -439,3 +439,3 @@ | ||
await withClientAndEventProcessor(anonUser, { baseUrl: server.url }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.track('eventkey'); | ||
@@ -458,3 +458,3 @@ | ||
const eventData = { thing: 'stuff' }; | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.track('eventkey', eventData); | ||
@@ -477,3 +477,3 @@ | ||
const metricValue = 1.5; | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.track('eventkey', eventData, metricValue); | ||
@@ -497,3 +497,3 @@ | ||
const eventData = { thing: 'stuff' }; | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.track('eventkey', eventData); | ||
@@ -506,3 +506,3 @@ expect(ep.events.length).toEqual(0); | ||
await withClientAndEventProcessor(user, {}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -514,5 +514,17 @@ client.track('known'); | ||
it('does warn when a metric value is non-numeric', async () => { | ||
await withClientAndEventProcessor(user, {}, async client => { | ||
await client.waitForInitialization(5); | ||
client.track('known', undefined, '12'); | ||
expect(platform.testing.logger.output.warn).toEqual([ | ||
'The track function was called with a non-numeric "metricValue" (string), ' + | ||
'only numeric metric values are supported.', | ||
]); | ||
}); | ||
}); | ||
it('emits an error when tracking a non-string custom event', async () => { | ||
await withClientAndEventProcessor(user, {}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -541,3 +553,3 @@ const badCustomEventKeys = [123, [], {}, null, undefined]; | ||
await withClientAndEventProcessor(user, { stateProvider: sp }, async (client, ep) => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -584,3 +596,3 @@ client.track('eventkey'); | ||
await withCloseable(client, async () => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
await client.flush(); | ||
@@ -609,3 +621,3 @@ const data = await expectDiagnosticEventAndDiscardRegularEvent(server); | ||
await withCloseable(client, async () => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
await client.flush(); | ||
@@ -633,3 +645,3 @@ const data = await expectDiagnosticEventAndDiscardRegularEvent(server); | ||
await withCloseable(client, async () => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
await client.flush(); | ||
@@ -636,0 +648,0 @@ expect(server.requests.length()).toEqual(1); |
@@ -41,3 +41,3 @@ import * as messages from '../messages'; | ||
await withClient(user, { baseUrl: server.url }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -62,3 +62,3 @@ // should see a flag request to the server right away, as if bootstrap was not specified | ||
await withClient(user, { baseUrl: server.url }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -84,3 +84,3 @@ expect(client.variation('flag-key')).toEqual(1); | ||
// verify that the flags get requested from LD | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
expect(client.variation('flag-key')).toEqual(1); | ||
@@ -99,3 +99,3 @@ }); | ||
await withClient(user, { baseUrl: server.url }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
expect(platform.testing.logger.output.warn).toEqual([messages.localStorageUnavailable(myError)]); | ||
@@ -114,3 +114,3 @@ }); | ||
await withClient(user, { baseUrl: server.url }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -131,3 +131,3 @@ await sleepAsync(0); // allow any pending async tasks to complete | ||
await withClient(user, { baseUrl: server.url }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -150,3 +150,3 @@ await sleepAsync(0); // allow any pending async tasks to complete | ||
await withClient(user, { baseUrl: server.url, hash }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
const value = platform.testing.getLocalStorageImmediately(lsKeyHash); | ||
@@ -169,3 +169,3 @@ expect(JSON.parse(value)).toEqual({ | ||
await withClient(user, { baseUrl: server.url }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -172,0 +172,0 @@ await sleepAsync(0); // allow any pending async tasks to complete |
@@ -64,3 +64,3 @@ import * as messages from '../messages'; | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -73,3 +73,3 @@ expectNoStreamIsOpen(); | ||
await withClientAndServer({ streaming: true }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -83,3 +83,3 @@ await platform.testing.expectStream(fullStreamUrlWithUser); | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -93,3 +93,3 @@ client.setStreaming(true); | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -107,3 +107,3 @@ client.setStreaming(true); | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.on('change', () => {}); | ||
@@ -117,3 +117,3 @@ | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.on('change:flagkey', () => {}); | ||
@@ -127,3 +127,3 @@ | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.on('error', () => {}); | ||
@@ -137,3 +137,3 @@ | ||
await withClientAndServer({ streaming: false }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.on('change', () => {}); | ||
@@ -147,3 +147,3 @@ | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(false); | ||
@@ -162,3 +162,3 @@ client.on('change', () => {}); | ||
const listener2 = () => {}; | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -185,3 +185,3 @@ client.on('change', listener1); | ||
const listener2 = newValue => changes2.push(newValue); | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -226,3 +226,3 @@ client.setStreaming(true); | ||
await withClientAndServer({ hash }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.on('change:flagKey', () => {}); | ||
@@ -236,3 +236,3 @@ | ||
await withClientAndServer({ evaluationReasons: true }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -246,3 +246,3 @@ | ||
await withClientAndServer({ hash, evaluationReasons: true }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -257,3 +257,3 @@ | ||
server.byDefault(respondJson({ flagKey: { value: true, version: 1 } })); | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -280,3 +280,3 @@ | ||
const initPromise = client.waitForInitialization(); | ||
const initPromise = client.waitForInitialization(5); | ||
const poll1 = await reqRespQueue.take(); | ||
@@ -318,3 +318,3 @@ expect(poll1.req.path).toContain(initUserBase64); | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -335,3 +335,3 @@ | ||
await withClientAndServer({ bootstrap: 'localstorage' }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -352,3 +352,3 @@ | ||
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -377,3 +377,3 @@ const receivedChange = eventSink(client, 'change'); | ||
await withClientAndServer(config, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -398,3 +398,3 @@ const receivedChange = eventSink(client, 'change'); | ||
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -415,3 +415,3 @@ const receivedChange = eventSink(client, 'change:flagKey'); | ||
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -429,3 +429,3 @@ | ||
await withClientAndServer({ bootstrap: initData }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -446,3 +446,3 @@ expect(client.variation('flagKey')).toEqual('a'); | ||
await withClientAndServer({ bootstrap: initData }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -463,3 +463,3 @@ expect(client.variation('flagKey')).toEqual('a'); | ||
await withClientAndServer({ bootstrap: initData }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -480,3 +480,3 @@ expect(client.variation('flagKey')).toEqual('a'); | ||
await withClientAndServer({ bootstrap: initData }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -498,3 +498,3 @@ expect(client.variation('flagKey')).toEqual('a'); | ||
await withClientAndServer({ bootstrap: 'localstorage' }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -515,3 +515,3 @@ | ||
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -534,3 +534,3 @@ const receivedChange = eventSink(client, 'change'); | ||
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -551,3 +551,3 @@ const receivedChange = eventSink(client, 'change:flagKey'); | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -570,3 +570,3 @@ const receivedChange = eventSink(client, 'change'); | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -587,3 +587,3 @@ const receivedChange = eventSink(client, 'change:flagKey'); | ||
await withClientAndServer({ bootstrap: { flagKey: false } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -602,3 +602,3 @@ | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -623,3 +623,3 @@ | ||
await withClientAndServer({ bootstrap: initData }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -638,3 +638,3 @@ | ||
await withClientAndServer({ bootstrap: { flagKey: true } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -657,3 +657,3 @@ const receivedChange = eventSink(client, 'change'); | ||
await withClientAndServer({ bootstrap: { flagKey: true } }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -676,3 +676,3 @@ const receivedChange = eventSink(client, 'change:flagKey'); | ||
await withClientAndServer({ bootstrap: 'localstorage' }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -695,3 +695,3 @@ | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -708,3 +708,3 @@ | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -729,3 +729,3 @@ | ||
await withClientAndServer({}, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -746,3 +746,3 @@ | ||
await withClientAndServer({ hash }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
client.setStreaming(true); | ||
@@ -749,0 +749,0 @@ |
@@ -67,3 +67,3 @@ import * as LDClient from '../index'; | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
}); | ||
@@ -86,3 +86,3 @@ }); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -101,3 +101,3 @@ const req = await pollServer.nextRequest(); | ||
await withClient(user, { ...baseConfig, evaluationReasons: true }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -114,3 +114,3 @@ const req = await pollServer.nextRequest(); | ||
await withClient(user, { ...baseConfig, sendLDHeaders }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
const request = await pollServer.nextRequest(); | ||
@@ -133,3 +133,3 @@ expect(request.headers['user-agent']).toEqual( | ||
await withClient(numericUser, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
expect(client.getContext()).toEqual(stringifiedNumericUser); | ||
@@ -145,3 +145,3 @@ }); | ||
await withClient(anonUser, baseConfig, async client0 => { | ||
await client0.waitForInitialization(); | ||
await client0.waitForInitialization(5); | ||
@@ -153,3 +153,3 @@ generatedUser = client0.getContext(); | ||
await withClient(anonUser, baseConfig, async client1 => { | ||
await client1.waitForInitialization(); | ||
await client1.waitForInitialization(5); | ||
@@ -169,3 +169,3 @@ const newUser1 = client1.getContext(); | ||
await withClient(anonUser, baseConfig, async client0 => { | ||
await client0.waitForInitialization(); | ||
await client0.waitForInitialization(5); | ||
@@ -178,3 +178,3 @@ generatedUser = client0.getContext(); | ||
await withClient(anonUser, baseConfig, async client1 => { | ||
await client1.waitForInitialization(); | ||
await client1.waitForInitialization(5); | ||
@@ -204,3 +204,3 @@ const newUser1 = client1.getContext(); | ||
await runTest(async client => { | ||
await expect(client.waitForInitialization()).rejects.toThrow(); | ||
await expect(client.waitForInitialization(5)).rejects.toThrow(); | ||
}); | ||
@@ -276,3 +276,3 @@ }); | ||
await withClient(user, { ...baseConfig, bootstrap: {} }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -296,3 +296,3 @@ expect(pollServer.requests.length()).toEqual(0); | ||
await withClient(user, { bootstrap: initData, sendEvents: false }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -306,3 +306,3 @@ expect(platform.testing.logger.output.warn).toEqual([messages.bootstrapOldFormat()]); | ||
await withClient(user, { bootstrap: initData, sendEvents: false }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -322,3 +322,3 @@ expect(platform.testing.logger.output.warn).toEqual([]); | ||
await withClient(user, config, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -335,3 +335,3 @@ expect(client.variation('foo')).toEqual('bar'); | ||
await withClient(user, config, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -347,3 +347,3 @@ expect(client.variation('foo')).toEqual('bar'); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -360,3 +360,3 @@ expect(client.variation('enable-foo', 1)).toEqual(true); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -372,3 +372,3 @@ expect(client.variation('foo', 'default')).toEqual('default'); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -388,3 +388,3 @@ expect(client.variation('foo', 'default')).toEqual('default'); | ||
await withClient(user, config, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -398,3 +398,3 @@ expect(client.variationDetail('foo')).toEqual({ value: 'bar', variationIndex: 2, reason: reason }); | ||
await withClient(user, config, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -410,3 +410,3 @@ expect(client.variationDetail('foo')).toEqual({ value: 'bar', variationIndex: null, reason: null }); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -423,3 +423,3 @@ expect(client.variationDetail('foo', 'default')).toEqual({ value: 'bar', variationIndex: 2, reason: reason }); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -455,3 +455,3 @@ expect(client.variationDetail('foo', 'default')).toEqual({ | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -481,3 +481,3 @@ expect(client.allFlags()).toEqual({ key1: 'value1', key2: 'value2' }); | ||
const user2 = { key: 'user2' }; | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -510,3 +510,3 @@ // Make the server wait until signaled to return the next response | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -536,3 +536,3 @@ expect(client.variation('enable-foo')).toBe(false); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -560,3 +560,3 @@ expect(client.variation('enable-foo')).toBe(false); | ||
await withClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -586,3 +586,3 @@ const anonUser = { anonymous: true, country: 'US' }; | ||
await withClient(null, { ...baseConfig, stateProvider: sp }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -617,3 +617,3 @@ expect(client.variation('flagkey')).toEqual('value'); | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
expect(client.variation('flagkey')).toEqual('value'); | ||
@@ -633,3 +633,3 @@ }); | ||
await withClient(null, { stateProvider: sp, sendEvents: false }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -661,3 +661,3 @@ expect(client.variation('flagkey')).toEqual('value0'); | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
const newFlags = await client.identify(user1); | ||
@@ -684,3 +684,3 @@ | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
expect(client.variation('flagkey')).toEqual('value'); | ||
@@ -704,3 +704,3 @@ | ||
await withClient(user, { ...baseConfig, flushInterval: 100000 }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
}); | ||
@@ -719,3 +719,3 @@ | ||
await withClient(user, { ...baseConfig, flushInterval: 100000 }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -737,3 +737,3 @@ await client.close(); | ||
await withClient(user, { ...baseConfig, flushInterval: 100000 }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -748,3 +748,3 @@ await client.close(); // shouldn't throw or have an unhandled rejection | ||
await withClient(user, { ...baseConfig }, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
@@ -769,3 +769,3 @@ await promisifySingle(client.close)(); | ||
await withDiagnosticsEnabledClient(user, baseConfig, async client => { | ||
await client.waitForInitialization(); | ||
await client.waitForInitialization(5); | ||
await client.flush(); | ||
@@ -772,0 +772,0 @@ |
@@ -121,4 +121,4 @@ const AttributeReference = require('./attributeReference'); | ||
// cause the literal to incorrectly be treated as a reference. | ||
filtered._meta.privateAttributes = user.privateAttributeNames.map( | ||
literal => (literal.startsWith('/') ? AttributeReference.literalToReference(literal) : literal) | ||
filtered._meta.privateAttributes = user.privateAttributeNames.map(literal => | ||
literal.startsWith('/') ? AttributeReference.literalToReference(literal) : literal | ||
); | ||
@@ -125,0 +125,0 @@ } |
@@ -22,2 +22,3 @@ function createCustomError(name) { | ||
const LDInvalidDataError = createCustomError('LaunchDarklyInvalidDataError'); | ||
const LDTimeoutError = createCustomError('LaunchDarklyTimeoutError'); | ||
@@ -39,3 +40,4 @@ function isHttpErrorRecoverable(status) { | ||
LDFlagFetchError, | ||
LDTimeoutError, | ||
isHttpErrorRecoverable, | ||
}; |
@@ -20,4 +20,4 @@ const { getLDUserAgentString } = require('./utils'); | ||
.sort() | ||
.map( | ||
key => (Array.isArray(tags[key]) ? tags[key].sort().map(value => `${key}/${value}`) : [`${key}/${tags[key]}`]) | ||
.map(key => | ||
Array.isArray(tags[key]) ? tags[key].sort().map(value => `${key}/${value}`) : [`${key}/${tags[key]}`] | ||
) | ||
@@ -24,0 +24,0 @@ .reduce((flattened, item) => flattened.concat(item), []) |
@@ -19,5 +19,7 @@ const EventProcessor = require('./EventProcessor'); | ||
const { InspectorTypes, InspectorManager } = require('./InspectorManager'); | ||
const timedPromise = require('./timedPromise'); | ||
const changeEvent = 'change'; | ||
const internalChangeEvent = 'internal-change'; | ||
const highTimeoutThreshold = 5; | ||
@@ -369,2 +371,5 @@ // This is called by the per-platform initialize functions to create the base client object that we | ||
} | ||
if (metricValue !== undefined && typeof metricValue !== 'number') { | ||
logger.warn(messages.invalidMetricValue(typeof metricValue)); | ||
} | ||
@@ -777,4 +782,38 @@ // The following logic was used only for the JS browser SDK (js-client-sdk) and | ||
function waitForInitializationWithTimeout(timeout) { | ||
if (timeout > highTimeoutThreshold) { | ||
logger.warn( | ||
'The waitForInitialization function was called with a timeout greater than ' + | ||
`${highTimeoutThreshold} seconds. We recommend a timeout of ` + | ||
`${highTimeoutThreshold} seconds or less.` | ||
); | ||
} | ||
const initPromise = initializationStateTracker.getInitializationPromise(); | ||
const timeoutPromise = timedPromise(timeout, 'waitForInitialization'); | ||
return Promise.race([timeoutPromise, initPromise]).catch(e => { | ||
if (e instanceof errors.LDTimeoutError) { | ||
logger.error(`waitForInitialization error: ${e}`); | ||
} | ||
throw e; | ||
}); | ||
} | ||
function waitForInitialization(timeout = undefined) { | ||
if (timeout !== undefined && timeout !== null) { | ||
if (typeof timeout === 'number') { | ||
return waitForInitializationWithTimeout(timeout); | ||
} | ||
logger.warn('The waitForInitialization method was provided with a non-numeric timeout.'); | ||
} | ||
logger.warn( | ||
'The waitForInitialization function was called without a timeout specified.' + | ||
' In a future version a default timeout will be applied.' | ||
); | ||
return initializationStateTracker.getInitializationPromise(); | ||
} | ||
const client = { | ||
waitForInitialization: () => initializationStateTracker.getInitializationPromise(), | ||
waitForInitialization, | ||
waitUntilReady: () => initializationStateTracker.getReadyPromise(), | ||
@@ -781,0 +820,0 @@ identify: identify, |
@@ -193,2 +193,5 @@ const errors = require('./errors'); | ||
const invalidMetricValue = badType => | ||
`The track function was called with a non-numeric "metricValue" (${badType}), only numeric metric values are supported.`; | ||
module.exports = { | ||
@@ -223,2 +226,3 @@ bootstrapInvalid, | ||
invalidKey, | ||
invalidMetricValue, | ||
invalidContext, | ||
@@ -225,0 +229,0 @@ invalidTagValue, |
@@ -57,3 +57,3 @@ | ||
client.waitUntilReady().then(() => {}); | ||
client.waitForInitialization().then(() => {}); | ||
client.waitForInitialization(5).then(() => {}); | ||
@@ -60,0 +60,0 @@ client.identify(user).then(() => {}); |
144
typings.d.ts
@@ -121,3 +121,3 @@ /** | ||
* the options. | ||
* | ||
* | ||
* This defaults to true (custom headers will be sent). One reason you might | ||
@@ -165,3 +165,3 @@ * want to set it to false is that the presence of custom headers causes | ||
* per-context basis with {@link LDContextMeta.privateAttributes}. | ||
* | ||
* | ||
* Any contexts sent to LaunchDarkly with this configuration active will have attributes with | ||
@@ -171,3 +171,3 @@ * these names removed in analytic events. This is in addition to any attributes that were | ||
* Setting {@link LDOptions.allAttributesPrivate} to true overrides this. | ||
* | ||
* | ||
* If and only if a parameter starts with a slash, it is interpreted as a slash-delimited path | ||
@@ -260,6 +260,6 @@ * that can denote a nested property within a JSON object. For instance, "/address/street" means | ||
* A unique identifier representing the application where the LaunchDarkly SDK is running. | ||
* | ||
* | ||
* This can be specified as any string value as long as it only uses the following characters: ASCII letters, | ||
* ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored. | ||
* | ||
* | ||
* Example: `authentication-service` | ||
@@ -271,10 +271,10 @@ */ | ||
* A unique identifier representing the version of the application where the LaunchDarkly SDK is running. | ||
* | ||
* | ||
* This can be specified as any string value as long as it only uses the following characters: ASCII letters, | ||
* ASCII digits, period, hyphen, underscore. A string containing any other characters will be ignored. | ||
* | ||
* | ||
* Example: `1.0.0` (standard version string) or `abcdef` (sha prefix) | ||
*/ | ||
version?: string; | ||
} | ||
}; | ||
@@ -292,8 +292,7 @@ /** | ||
export interface LDContextMeta { | ||
/** | ||
* | ||
* | ||
* Designate any number of Context attributes, or properties within them, as private: that is, | ||
* their values will not be sent to LaunchDarkly in analytics events. | ||
* | ||
* | ||
* Each parameter can be a simple attribute name, such as "email". Or, if the first character is | ||
@@ -304,11 +303,11 @@ * a slash, the parameter is interpreted as a slash-delimited path to a property within a JSON | ||
* following JSON object value: | ||
* | ||
* | ||
* ``` | ||
* {"street": {"line1": "abc", "line2": "def"}} | ||
* ``` | ||
* | ||
* | ||
* Using ["/address/street/line1"] in this case would cause the "line1" property to be marked as | ||
* private. This syntax deliberately resembles JSON Pointer, but other JSON Pointer features | ||
* such as array indexing are not supported for Private. | ||
* | ||
* | ||
* This action only affects analytics events that involve this particular Context. To mark some | ||
@@ -318,7 +317,7 @@ * (or all) Context attributes as private for all users, use the overall configuration for the | ||
* See {@link LDOptions.allAttributesPrivate} and {@link LDOptions.privateAttributes}. | ||
* | ||
* | ||
* The attributes "kind" and "key", and the "_meta" attributes cannot be made private. | ||
* | ||
* | ||
* In this example, firstName is marked as private, but lastName is not: | ||
* | ||
* | ||
* ``` | ||
@@ -331,7 +330,7 @@ * const context = { | ||
* _meta: { | ||
* privateAttributes: ['firstName'], | ||
* privateAttributes: ['firstName'], | ||
* } | ||
* }; | ||
* ``` | ||
* | ||
* | ||
* This is a metadata property, rather than an attribute that can be addressed in evaluations: | ||
@@ -382,8 +381,7 @@ * that is, a rule clause that references the attribute name "privateAttributes", will not use | ||
/** | ||
* A context which represents a single kind. | ||
* | ||
* | ||
* For a single kind context the 'kind' may not be 'multi'. | ||
* | ||
* | ||
* ``` | ||
@@ -396,3 +394,3 @@ * const myOrgContext = { | ||
* ``` | ||
* | ||
* | ||
* The above context would be a single kind context representing an organization. It has a key | ||
@@ -410,5 +408,5 @@ * for that organization, and a single attribute 'someAttribute'. | ||
* A context which represents multiple kinds. Each kind having its own key and attributes. | ||
* | ||
* | ||
* A multi-context must contain `kind: 'multi'` at the root. | ||
* | ||
* | ||
* ``` | ||
@@ -436,3 +434,3 @@ * const myMultiContext = { | ||
* ``` | ||
* | ||
* | ||
* The above multi-context contains both an 'org' and a 'user'. Each with their own key, | ||
@@ -445,11 +443,11 @@ * attributes, and _meta attributes. | ||
*/ | ||
kind: "multi", | ||
kind: 'multi'; | ||
/** | ||
* The contexts which compose this multi-kind context. | ||
* | ||
* | ||
* These should be of type LDContextCommon. "multi" is to allow | ||
* for the top level "kind" attribute. | ||
*/ | ||
[kind: string]: "multi" | LDContextCommon; | ||
[kind: string]: 'multi' | LDContextCommon; | ||
} | ||
@@ -469,9 +467,9 @@ | ||
* be made. | ||
* | ||
* | ||
* 1.) Add a kind to the object. `kind: 'user'`. | ||
* | ||
* | ||
* 2.) Move custom attributes to the top level of the object. | ||
* | ||
* | ||
* 3.) Move `privateAttributeNames` to `_meta.privateAttributes`. | ||
* | ||
* | ||
* ``` | ||
@@ -485,3 +483,3 @@ * const LDUser: user = { | ||
* } | ||
* | ||
* | ||
* const LDSingleKindContext: context = { | ||
@@ -685,3 +683,3 @@ * kind: 'user', | ||
* // using Promise then() and catch() handlers | ||
* client.waitForInitialization().then(() => { | ||
* client.waitForInitialization(5).then(() => { | ||
* doSomethingWithSuccessfullyInitializedClient(); | ||
@@ -694,3 +692,3 @@ * }).catch(err => { | ||
* try { | ||
* await client.waitForInitialization(); | ||
* await client.waitForInitialization(5); | ||
* doSomethingWithSuccessfullyInitializedClient(); | ||
@@ -710,7 +708,16 @@ * } catch (err) { | ||
* | ||
* @param timeout | ||
* The amount of time, in seconds, to wait for initialization before rejecting the promise. | ||
* Using a large timeout is not recommended. If you use a large timeout and await it, then | ||
* any network delays will cause your application to wait a long time before | ||
* continuing execution. | ||
* | ||
* If no timeout is specified, then the returned promise will only be resolved when the client | ||
* successfully initializes or initialization fails. | ||
* | ||
* @returns | ||
* A Promise that will be resolved if the client initializes successfully, or rejected if it | ||
* fails. | ||
* fails or the specified timeout elapses. | ||
*/ | ||
waitForInitialization(): Promise<void>; | ||
waitForInitialization(timeout?: number): Promise<void>; | ||
@@ -742,3 +749,7 @@ /** | ||
*/ | ||
identify(context: LDContext, hash?: string, onDone?: (err: Error | null, flags: LDFlagSet | null) => void): Promise<LDFlagSet>; | ||
identify( | ||
context: LDContext, | ||
hash?: string, | ||
onDone?: (err: Error | null, flags: LDFlagSet | null) => void | ||
): Promise<LDFlagSet>; | ||
@@ -789,3 +800,3 @@ /** | ||
* | ||
* Note that this will only work if you have set `evaluationExplanations` to true in {@link LDOptions}. | ||
* Note that this will only work if you have set `evaluationReasons` to true in {@link LDOptions}. | ||
* Otherwise, the `reason` property of the result will be null. | ||
@@ -933,3 +944,3 @@ * | ||
* substitution is not available. | ||
* | ||
* | ||
* @example | ||
@@ -952,3 +963,3 @@ * This example shows how to use `basicLogger` in your SDK options to enable console | ||
* ``` | ||
* | ||
* | ||
* @ignore (don't need to show this separately in TypeDoc output; each SDK should provide its own | ||
@@ -997,3 +1008,3 @@ * basicLogger function that delegates to this and sets the formatter parameter) | ||
*/ | ||
destination?: (line: string) => void, | ||
destination?: (line: string) => void; | ||
} | ||
@@ -1011,12 +1022,9 @@ | ||
export function getContextKeys( | ||
context: LDContext, | ||
logger?: LDLogger, | ||
): {[attribute: string]: string} | undefined; | ||
export function getContextKeys(context: LDContext, logger?: LDLogger): { [attribute: string]: string } | undefined; | ||
/** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* | ||
* This interface is used to collect information about flag usage. | ||
* | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
@@ -1026,3 +1034,3 @@ * flow. It is intended for monitoring, analytics, or debugging purposes. | ||
export interface LDInspectionFlagUsedHandler { | ||
type: 'flag-used', | ||
type: 'flag-used'; | ||
@@ -1032,3 +1040,3 @@ /** | ||
*/ | ||
name: string, | ||
name: string; | ||
@@ -1045,8 +1053,8 @@ /** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* | ||
* This interface is used to collect information about flag data. In order to understand the | ||
* current flag state it should be combined with {@link LDInspectionFlagValueChangedHandler}. | ||
* This interface will get the initial flag information, and | ||
* This interface will get the initial flag information, and | ||
* {@link LDInspectionFlagValueChangedHandler} will provide changes to individual flags. | ||
* | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
@@ -1056,3 +1064,3 @@ * flow. It is intended for monitoring, analytics, or debugging purposes. | ||
export interface LDInspectionFlagDetailsChangedHandler { | ||
type: 'flag-details-changed', | ||
type: 'flag-details-changed'; | ||
@@ -1062,3 +1070,3 @@ /** | ||
*/ | ||
name: string, | ||
name: string; | ||
@@ -1072,10 +1080,9 @@ /** | ||
/** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* | ||
* This interface is used to collect changes to flag data, but does not provide the initial | ||
* data. It can be combined with {@link LDInspectionFlagValuesChangedHandler} to track the | ||
* entire flag state. | ||
* | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
@@ -1085,3 +1092,3 @@ * flow. It is intended for monitoring, analytics, or debugging purposes. | ||
export interface LDInspectionFlagDetailChangedHandler { | ||
type: 'flag-detail-changed', | ||
type: 'flag-detail-changed'; | ||
@@ -1091,3 +1098,3 @@ /** | ||
*/ | ||
name: string, | ||
name: string; | ||
@@ -1103,5 +1110,5 @@ /** | ||
* Callback interface for collecting information about the SDK at runtime. | ||
* | ||
* | ||
* This interface is used to track current identity state of the SDK. | ||
* | ||
* | ||
* This interface should not be used by the application to access flags for the purpose of controlling application | ||
@@ -1111,3 +1118,3 @@ * flow. It is intended for monitoring, analytics, or debugging purposes. | ||
export interface LDInspectionIdentifyHandler { | ||
type: 'client-identity-changed', | ||
type: 'client-identity-changed'; | ||
@@ -1117,3 +1124,3 @@ /** | ||
*/ | ||
name: string, | ||
name: string; | ||
@@ -1126,4 +1133,7 @@ /** | ||
export type LDInspection = LDInspectionFlagUsedHandler | LDInspectionFlagDetailsChangedHandler | ||
| LDInspectionFlagDetailChangedHandler | LDInspectionIdentifyHandler; | ||
export type LDInspection = | ||
| LDInspectionFlagUsedHandler | ||
| LDInspectionFlagDetailsChangedHandler | ||
| LDInspectionFlagDetailChangedHandler | ||
| LDInspectionIdentifyHandler; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
444155
79
10497