Skip to content

Commit b70e79e

Browse files
authored
[FSSDK-11510] refactor unsupported factories to not throw (#1056)
1 parent 1cd028d commit b70e79e

8 files changed

+18
-19
lines changed

lib/entrypoint.test-d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { NOTIFICATION_TYPES, DECISION_NOTIFICATION_TYPES } from './notification_
5555
import { LogLevel } from './logging/logger';
5656

5757
import { OptimizelyDecideOption } from './shared_types';
58+
import { Maybe } from './utils/type';
5859

5960
export type Entrypoint = {
6061
// client factory
@@ -66,7 +67,7 @@ export type Entrypoint = {
6667

6768
// event processor related exports
6869
eventDispatcher: EventDispatcher;
69-
getSendBeaconEventDispatcher: () => EventDispatcher;
70+
getSendBeaconEventDispatcher: () => Maybe<EventDispatcher>;
7071
createForwardingEventProcessor: (eventDispatcher?: EventDispatcher) => OpaqueEventProcessor;
7172
createBatchEventProcessor: (options?: BatchEventProcessorOptions) => OpaqueEventProcessor;
7273

lib/index.browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const createInstance = function(config: Config): Client | null {
4545
return client;
4646
};
4747

48-
export const getSendBeaconEventDispatcher = (): EventDispatcher => {
48+
export const getSendBeaconEventDispatcher = (): EventDispatcher | undefined => {
4949
return sendBeaconEventDispatcher;
5050
};
5151

lib/index.node.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export const createInstance = function(config: Config): Client | null {
3535
return getOptimizelyInstance(nodeConfig);
3636
};
3737

38-
export const getSendBeaconEventDispatcher = function(): EventDispatcher {
39-
throw new Error('Send beacon event dispatcher is not supported in NodeJS');
38+
export const getSendBeaconEventDispatcher = function(): EventDispatcher | undefined {
39+
return undefined;
4040
};
4141

4242
export { default as eventDispatcher } from './event_processor/event_dispatcher/default_dispatcher.node';

lib/index.react_native.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export const createInstance = function(config: Config): Client | null {
3838
return getOptimizelyInstance(rnConfig);
3939
};
4040

41-
export const getSendBeaconEventDispatcher = function(): EventDispatcher {
42-
throw new Error('Send beacon event dispatcher is not supported in React Native');
41+
export const getSendBeaconEventDispatcher = function(): EventDispatcher | undefined {
42+
return undefined;
4343
};
4444

4545
export { default as eventDispatcher } from './event_processor/event_dispatcher/default_dispatcher.browser';

lib/vuid/vuid_manager_factory.browser.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { LocalStorageCache } from '../utils/cache/local_storage_cache.browser';
3535
import { DefaultVuidManager, VuidCacheManager } from './vuid_manager';
3636
import { extractVuidManager } from './vuid_manager_factory';
3737

38-
describe('extractVuidManager(createVuidManager', () => {
38+
describe('createVuidManager', () => {
3939
const MockVuidCacheManager = vi.mocked(VuidCacheManager);
4040
const MockLocalStorageCache = vi.mocked(LocalStorageCache);
4141
const MockDefaultVuidManager = vi.mocked(DefaultVuidManager);

lib/vuid/vuid_manager_factory.node.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import { vi, describe, expect, it } from 'vitest';
1818

1919
import { createVuidManager } from './vuid_manager_factory.node';
20-
import { VUID_IS_NOT_SUPPORTED_IN_NODEJS } from './vuid_manager_factory.node';
20+
import { extractVuidManager } from './vuid_manager_factory';
2121

2222
describe('createVuidManager', () => {
23-
it('should throw an error', () => {
24-
expect(() => createVuidManager({ enableVuid: true }))
25-
.toThrowError(VUID_IS_NOT_SUPPORTED_IN_NODEJS);
23+
it('should return a undefined vuid manager wrapped as OpaqueVuidManager', () => {
24+
expect(extractVuidManager(createVuidManager({ enableVuid: true })))
25+
.toBeUndefined();
2626
});
2727
});

lib/vuid/vuid_manager_factory.node.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { VuidManager } from './vuid_manager';
17-
import { OpaqueVuidManager, VuidManagerOptions } from './vuid_manager_factory';
18-
19-
export const VUID_IS_NOT_SUPPORTED_IN_NODEJS= 'VUID is not supported in Node.js environment';
16+
import { OpaqueVuidManager, VuidManagerOptions, wrapVuidManager } from './vuid_manager_factory';
2017

2118
export const createVuidManager = (options: VuidManagerOptions = {}): OpaqueVuidManager => {
22-
throw new Error(VUID_IS_NOT_SUPPORTED_IN_NODEJS);
19+
return wrapVuidManager(undefined);
2320
};

lib/vuid/vuid_manager_factory.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { Store } from '../utils/cache/store';
18+
import { Maybe } from '../utils/type';
1819
import { VuidManager } from './vuid_manager';
1920

2021
export type VuidManagerOptions = {
@@ -28,11 +29,11 @@ export type OpaqueVuidManager = {
2829
[vuidManagerSymbol]: unknown;
2930
};
3031

31-
export const extractVuidManager = (opaqueVuidManager: OpaqueVuidManager): VuidManager => {
32-
return opaqueVuidManager[vuidManagerSymbol] as VuidManager;
32+
export const extractVuidManager = (opaqueVuidManager: OpaqueVuidManager): Maybe<VuidManager> => {
33+
return opaqueVuidManager[vuidManagerSymbol] as Maybe<VuidManager>;
3334
};
3435

35-
export const wrapVuidManager = (vuidManager: VuidManager): OpaqueVuidManager => {
36+
export const wrapVuidManager = (vuidManager: Maybe<VuidManager>): OpaqueVuidManager => {
3637
return {
3738
[vuidManagerSymbol]: vuidManager
3839
}

0 commit comments

Comments
 (0)