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
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
@@ -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
@@ -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;

2 changes: 1 addition & 1 deletion lib/index.browser.ts
Original file line number Diff line number Diff line change
@@ -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;
};

4 changes: 2 additions & 2 deletions lib/index.node.ts
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 2 additions & 2 deletions lib/index.react_native.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion lib/vuid/vuid_manager_factory.browser.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
8 changes: 4 additions & 4 deletions lib/vuid/vuid_manager_factory.node.spec.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -15,6 +15,7 @@
*/

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

export type VuidManagerOptions = {
@@ -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
}

Unchanged files with check annotations Beta

isQualifiedFor: segment => segments ? segments.indexOf(segment) > -1 : false,
qualifiedSegments: segments || [],
getUserId: () => 'mockUserId',
setAttribute: (key: string, value: any) => {},

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'key' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'value' is defined but never used

Check warning on line 33 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type
decide: (key: string, options?: OptimizelyDecideOption[]): OptimizelyDecision => ({

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

'options' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

'options' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

'options' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'key' is defined but never used

Check warning on line 35 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

'options' is defined but never used
variationKey: 'mockVariationKey',
enabled: true,
variables: { mockVariable: 'mockValue' },
});
it('calls customAttributeConditionEvaluator.evaluate in the leaf evaluator for audience conditions', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementation((conditions: any, leafEvaluator) => {

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 253 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
});
it('logs correctly when conditionTreeEvaluator.evaluate returns null', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementationOnce((conditions: any, leafEvaluator) => {

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 295 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
});
it('logs correctly when conditionTreeEvaluator.evaluate returns true', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementationOnce((conditions: any, leafEvaluator) => {

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 322 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
});
it('logs correctly when conditionTreeEvaluator.evaluate returns false', () => {
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementationOnce((conditions: any, leafEvaluator) => {

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 348 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type
return leafEvaluator(conditions[1]);
});
};
audienceEvaluator = createAudienceEvaluator({
special_condition_type: {
evaluate: (condition: any, user: any) => {

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / lint

Unexpected any. Specify a different type

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (18)

Unexpected any. Specify a different type

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (20)

Unexpected any. Specify a different type

Check warning on line 384 in lib/core/audience_evaluator/index.spec.ts

GitHub Actions / unit_tests (22)

Unexpected any. Specify a different type
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const result = mockEnvironment[condition.value] && user.getAttributes()[condition.match] > 0;