diff --git a/packages/shared/sdk-client/src/LDClientImpl.storage.test.ts b/packages/shared/sdk-client/src/LDClientImpl.storage.test.ts index 8fd27e69c0..c3370e41db 100644 --- a/packages/shared/sdk-client/src/LDClientImpl.storage.test.ts +++ b/packages/shared/sdk-client/src/LDClientImpl.storage.test.ts @@ -98,11 +98,10 @@ describe('sdk-client storage', () => { expect(basicPlatform.storage.get).toHaveBeenCalledWith('org:Testy Pizza'); // 'change' should not have been emitted - expect(emitter.emit).toHaveBeenCalledTimes(3); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'identifying', context); - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, defaultFlagKeys); + expect(emitter.emit).toHaveBeenCalledTimes(2); + expect(emitter.emit).toHaveBeenNthCalledWith(1, 'change', context, defaultFlagKeys); expect(emitter.emit).toHaveBeenNthCalledWith( - 3, + 2, 'error', context, expect.objectContaining({ message: 'test-error' }), @@ -135,20 +134,15 @@ describe('sdk-client storage', () => { ); // 'change' should not have been emitted - expect(emitter.emit).toHaveBeenCalledTimes(3); + expect(emitter.emit).toHaveBeenCalledTimes(2); expect(emitter.emit).toHaveBeenNthCalledWith( 1, - 'identifying', - expect.objectContaining(toMulti(context)), - ); - expect(emitter.emit).toHaveBeenNthCalledWith( - 2, 'change', expect.objectContaining(toMulti(context)), defaultFlagKeys, ); expect(emitter.emit).toHaveBeenNthCalledWith( - 3, + 2, 'error', expect.objectContaining(toMulti(context)), expect.objectContaining({ message: 'test-error' }), @@ -175,8 +169,6 @@ describe('sdk-client storage', () => { ldc.identify(context).then(noop); await jest.runAllTimersAsync(); - expect(emitter.emit).toHaveBeenCalledTimes(1); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'identifying', context); expect(basicPlatform.storage.set).toHaveBeenNthCalledWith( 1, 'org:Testy Pizza', @@ -207,9 +199,8 @@ describe('sdk-client storage', () => { 'org:Testy Pizza', JSON.stringify(putResponse), ); - expect(emitter.emit).toHaveBeenNthCalledWith(1, 'identifying', context); - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, defaultFlagKeys); - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, ['dev-test-flag']); + expect(emitter.emit).toHaveBeenNthCalledWith(1, 'change', context, defaultFlagKeys); + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, ['dev-test-flag']); }); test('syncing storage when a flag is added', async () => { @@ -229,7 +220,7 @@ describe('sdk-client storage', () => { 'org:Testy Pizza', JSON.stringify(putResponse), ); - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, ['another-dev-test-flag']); + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, ['another-dev-test-flag']); }); test('syncing storage when a flag is updated', async () => { @@ -239,7 +230,7 @@ describe('sdk-client storage', () => { const allFlags = await identifyGetAllFlags(false, putResponse); expect(allFlags).toMatchObject({ 'dev-test-flag': false }); - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, ['dev-test-flag']); + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, ['dev-test-flag']); }); test('syncing storage on multiple flag operations', async () => { @@ -254,7 +245,7 @@ describe('sdk-client storage', () => { expect(allFlags).toMatchObject({ 'dev-test-flag': false, 'another-dev-test-flag': true }); expect(allFlags).not.toHaveProperty('moonshot-demo'); - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, [ + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, [ 'moonshot-demo', 'dev-test-flag', 'another-dev-test-flag', @@ -275,8 +266,8 @@ describe('sdk-client storage', () => { 'org:Testy Pizza', JSON.stringify(defaultPutResponse), ); - expect(emitter.emit).toHaveBeenCalledTimes(2); - expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, defaultFlagKeys); + expect(emitter.emit).toHaveBeenCalledTimes(1); + expect(emitter.emit).toHaveBeenNthCalledWith(1, 'change', context, defaultFlagKeys); // this is defaultPutResponse expect(allFlags).toEqual({ @@ -306,7 +297,7 @@ describe('sdk-client storage', () => { // both previous and current are true but inExperiment has changed // so a change event should be emitted - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, ['dev-test-flag']); + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, ['dev-test-flag']); }); test('patch should emit change event', async () => { @@ -324,8 +315,8 @@ describe('sdk-client storage', () => { expect.stringContaining(JSON.stringify(patchResponse)), ); expect(flagsInStorage['dev-test-flag'].version).toEqual(patchResponse.version); - expect(emitter.emit).toHaveBeenCalledTimes(3); - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, ['dev-test-flag']); + expect(emitter.emit).toHaveBeenCalledTimes(2); + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, ['dev-test-flag']); }); test('patch should add new flags', async () => { @@ -341,8 +332,8 @@ describe('sdk-client storage', () => { expect.stringContaining(JSON.stringify(patchResponse)), ); expect(flagsInStorage).toHaveProperty('another-dev-test-flag'); - expect(emitter.emit).toHaveBeenCalledTimes(3); - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, ['another-dev-test-flag']); + expect(emitter.emit).toHaveBeenCalledTimes(2); + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, ['another-dev-test-flag']); }); test('patch should ignore older version', async () => { @@ -395,8 +386,8 @@ describe('sdk-client storage', () => { expect.stringContaining('dev-test-flag'), ); expect(flagsInStorage['dev-test-flag']).toMatchObject({ ...deleteResponse, deleted: true }); - expect(emitter.emit).toHaveBeenCalledTimes(3); - expect(emitter.emit).toHaveBeenNthCalledWith(3, 'change', context, ['dev-test-flag']); + expect(emitter.emit).toHaveBeenCalledTimes(2); + expect(emitter.emit).toHaveBeenNthCalledWith(2, 'change', context, ['dev-test-flag']); }); test('delete should not delete equal version', async () => { diff --git a/packages/shared/sdk-client/src/LDClientImpl.ts b/packages/shared/sdk-client/src/LDClientImpl.ts index df79830f16..af8a873703 100644 --- a/packages/shared/sdk-client/src/LDClientImpl.ts +++ b/packages/shared/sdk-client/src/LDClientImpl.ts @@ -299,7 +299,6 @@ export default class LDClientImpl implements LDClient { const { identifyPromise, identifyResolve } = this.createPromiseWithListeners(); this.logger.debug(`Identifying ${JSON.stringify(context)}`); - this.emitter.emit('identifying', context); const flagsStorage = await this.getFlagsFromStorage(checkedContext.canonicalKey); if (flagsStorage) { diff --git a/packages/shared/sdk-client/src/api/LDClient.ts b/packages/shared/sdk-client/src/api/LDClient.ts index 4aaa347142..757b55d130 100644 --- a/packages/shared/sdk-client/src/api/LDClient.ts +++ b/packages/shared/sdk-client/src/api/LDClient.ts @@ -66,7 +66,7 @@ export interface LDClient { * events. After the client is closed, all calls to {@link variation} will return default values, * and it will not make any requests to LaunchDarkly. */ - close(): void; + close(): Promise; /** * Flushes all pending analytics events. @@ -80,6 +80,11 @@ export interface LDClient { */ flush(): Promise<{ error?: Error; result: boolean }>; + /** + * Gets the SDK connection mode. + */ + getConnectionMode(): ConnectionMode; + /** * Returns the client's current context. * @@ -196,7 +201,6 @@ export interface LDClient { * * The following event names (keys) are used by the client: * - * - `"identifying"`: The client starts to fetch feature flags. * - `"error"`: General event for any kind of error condition during client operation. * The callback parameter is an Error object. If you do not listen for "error" * events, then the errors will be logged with `console.log()`. diff --git a/packages/shared/sdk-client/src/api/LDEmitter.test.ts b/packages/shared/sdk-client/src/api/LDEmitter.test.ts index 6cf6a7593c..eff966efee 100644 --- a/packages/shared/sdk-client/src/api/LDEmitter.test.ts +++ b/packages/shared/sdk-client/src/api/LDEmitter.test.ts @@ -55,13 +55,11 @@ describe('LDEmitter', () => { test('eventNames', () => { const errorHandler1 = jest.fn(); const changeHandler = jest.fn(); - const readyHandler = jest.fn(); - emitter.on('identifying', readyHandler); emitter.on('error', errorHandler1); emitter.on('change', changeHandler); - expect(emitter.eventNames()).toEqual(['identifying', 'error', 'change']); + expect(emitter.eventNames()).toEqual(['error', 'change']); }); test('listener count', () => { diff --git a/packages/shared/sdk-client/src/api/LDEmitter.ts b/packages/shared/sdk-client/src/api/LDEmitter.ts index 9248f58745..18e4bdab14 100644 --- a/packages/shared/sdk-client/src/api/LDEmitter.ts +++ b/packages/shared/sdk-client/src/api/LDEmitter.ts @@ -1,4 +1,4 @@ -export type EventName = 'identifying' | 'error' | 'change'; +export type EventName = 'error' | 'change'; type CustomEventListeners = { original: Function;