Skip to content

[FSSDK-11510] refactor unsupported factories to not throw #1056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/entrypoint.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { NOTIFICATION_TYPES, DECISION_NOTIFICATION_TYPES } from './notification_
import { LogLevel } from './logging/logger';

import { OptimizelyDecideOption } from './shared_types';
import { Maybe } from './utils/type';

export type Entrypoint = {
// client factory
Expand All @@ -66,7 +67,7 @@ export type Entrypoint = {

// event processor related exports
eventDispatcher: EventDispatcher;
getSendBeaconEventDispatcher: () => EventDispatcher;
getSendBeaconEventDispatcher: () => Maybe<EventDispatcher>;
createForwardingEventProcessor: (eventDispatcher?: EventDispatcher) => OpaqueEventProcessor;
createBatchEventProcessor: (options?: BatchEventProcessorOptions) => OpaqueEventProcessor;

Expand Down
2 changes: 1 addition & 1 deletion lib/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const createInstance = function(config: Config): Client | null {
return client;
};

export const getSendBeaconEventDispatcher = (): EventDispatcher => {
export const getSendBeaconEventDispatcher = (): EventDispatcher | undefined => {
return sendBeaconEventDispatcher;
};

Expand Down
4 changes: 2 additions & 2 deletions lib/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const createInstance = function(config: Config): Client | null {
return getOptimizelyInstance(nodeConfig);
};

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

export { default as eventDispatcher } from './event_processor/event_dispatcher/default_dispatcher.node';
Expand Down
4 changes: 2 additions & 2 deletions lib/index.react_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const createInstance = function(config: Config): Client | null {
return getOptimizelyInstance(rnConfig);
};

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

export { default as eventDispatcher } from './event_processor/event_dispatcher/default_dispatcher.browser';
Expand Down
2 changes: 1 addition & 1 deletion lib/vuid/vuid_manager_factory.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { LocalStorageCache } from '../utils/cache/local_storage_cache.browser';
import { DefaultVuidManager, VuidCacheManager } from './vuid_manager';
import { extractVuidManager } from './vuid_manager_factory';

describe('extractVuidManager(createVuidManager', () => {
describe('createVuidManager', () => {
const MockVuidCacheManager = vi.mocked(VuidCacheManager);
const MockLocalStorageCache = vi.mocked(LocalStorageCache);
const MockDefaultVuidManager = vi.mocked(DefaultVuidManager);
Expand Down
8 changes: 4 additions & 4 deletions lib/vuid/vuid_manager_factory.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import { vi, describe, expect, it } from 'vitest';

import { createVuidManager } from './vuid_manager_factory.node';
import { VUID_IS_NOT_SUPPORTED_IN_NODEJS } from './vuid_manager_factory.node';
import { extractVuidManager } from './vuid_manager_factory';

describe('createVuidManager', () => {
it('should throw an error', () => {
expect(() => createVuidManager({ enableVuid: true }))
.toThrowError(VUID_IS_NOT_SUPPORTED_IN_NODEJS);
it('should return a undefined vuid manager wrapped as OpaqueVuidManager', () => {
expect(extractVuidManager(createVuidManager({ enableVuid: true })))
.toBeUndefined();
});
});
7 changes: 2 additions & 5 deletions lib/vuid/vuid_manager_factory.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { VuidManager } from './vuid_manager';
import { OpaqueVuidManager, VuidManagerOptions } from './vuid_manager_factory';

export const VUID_IS_NOT_SUPPORTED_IN_NODEJS= 'VUID is not supported in Node.js environment';
import { OpaqueVuidManager, VuidManagerOptions, wrapVuidManager } from './vuid_manager_factory';

export const createVuidManager = (options: VuidManagerOptions = {}): OpaqueVuidManager => {
throw new Error(VUID_IS_NOT_SUPPORTED_IN_NODEJS);
return wrapVuidManager(undefined);
};
7 changes: 4 additions & 3 deletions lib/vuid/vuid_manager_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { Store } from '../utils/cache/store';
import { Maybe } from '../utils/type';
import { VuidManager } from './vuid_manager';

export type VuidManagerOptions = {
Expand All @@ -28,11 +29,11 @@ export type OpaqueVuidManager = {
[vuidManagerSymbol]: unknown;
};

export const extractVuidManager = (opaqueVuidManager: OpaqueVuidManager): VuidManager => {
return opaqueVuidManager[vuidManagerSymbol] as VuidManager;
export const extractVuidManager = (opaqueVuidManager: OpaqueVuidManager): Maybe<VuidManager> => {
return opaqueVuidManager[vuidManagerSymbol] as Maybe<VuidManager>;
};

export const wrapVuidManager = (vuidManager: VuidManager): OpaqueVuidManager => {
export const wrapVuidManager = (vuidManager: Maybe<VuidManager>): OpaqueVuidManager => {
return {
[vuidManagerSymbol]: vuidManager
}
Expand Down
Loading