Skip to content

[FSSDK-11512] remove eventManager and segmentManager from odp public api #1048

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 2 commits into from
May 13, 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
6 changes: 4 additions & 2 deletions lib/entrypoint.universal.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ import { LogLevel } from './logging/logger';

import { OptimizelyDecideOption } from './shared_types';
import { UniversalConfig } from './index.universal';
import { OpaqueOdpManager } from './odp/odp_manager_factory';

import { UniversalOdpManagerOptions } from './odp/odp_manager_factory.universal';

export type UniversalEntrypoint = {
// client factory
Expand All @@ -63,8 +66,7 @@ export type UniversalEntrypoint = {
createForwardingEventProcessor: (eventDispatcher: EventDispatcher) => OpaqueEventProcessor;
createBatchEventProcessor: (options: UniversalBatchEventProcessorOptions) => OpaqueEventProcessor;

// TODO: odp manager related exports
// createOdpManager: (options: OdpManagerOptions) => OpaqueOdpManager;
createOdpManager: (options: UniversalOdpManagerOptions) => OpaqueOdpManager;

// TODO: vuid manager related exports
// createVuidManager: (options: VuidManagerOptions) => OpaqueVuidManager;
Expand Down
4 changes: 4 additions & 0 deletions lib/export_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export type {
OpaqueOdpManager,
} from './odp/odp_manager_factory';

export type {
UserAgentParser,
} from './odp/ua_parser/user_agent_parser';

// Vuid manager related types
export type {
VuidManagerOptions,
Expand Down
14 changes: 12 additions & 2 deletions lib/index.universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export { createPollingProjectConfigManager } from './project_config/config_manag

export { createForwardingEventProcessor, createBatchEventProcessor } from './event_processor/event_processor_factory.universal';

// TODO: decide on universal odp manager factory interface
// export { createOdpManager } from './odp/odp_manager_factory.node';
export { createOdpManager } from './odp/odp_manager_factory.universal';

// TODO: decide on vuid manager API for universal
// export { createVuidManager } from './vuid/vuid_manager_factory.node';

export * from './common_exports';
Expand All @@ -67,6 +68,15 @@ export type {

export type { UniversalBatchEventProcessorOptions } from './event_processor/event_processor_factory.universal';

// odp manager related types
export type {
UniversalOdpManagerOptions,
} from './odp/odp_manager_factory.universal';

export type {
UserAgentParser,
} from './odp/ua_parser/user_agent_parser';

export type {
OpaqueEventProcessor,
} from './event_processor/event_processor_factory';
Expand Down
2 changes: 0 additions & 2 deletions lib/odp/odp_manager_factory.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ describe('createOdpManager', () => {
segmentsCache: {} as any,
segmentsCacheSize: 11,
segmentsCacheTimeout: 2025,
segmentManager: {} as any,
eventFlushInterval: 2222,
eventManager: {} as any,
userAgentParser: {} as any,
};
const odpManager = createOdpManager(options);
Expand Down
2 changes: 0 additions & 2 deletions lib/odp/odp_manager_factory.node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ describe('createOdpManager', () => {
segmentsCache: {} as any,
segmentsCacheSize: 11,
segmentsCacheTimeout: 2025,
segmentManager: {} as any,
eventManager: {} as any,
userAgentParser: {} as any,
};
const odpManager = createOdpManager(options);
Expand Down
1 change: 0 additions & 1 deletion lib/odp/odp_manager_factory.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { NodeRequestHandler } from '../utils/http_request_handler/request_handler.node';
import { eventApiRequestGenerator } from './event_manager/odp_event_api_manager';
import { OdpManager } from './odp_manager';
import { getOpaqueOdpManager, OdpManagerOptions, OpaqueOdpManager } from './odp_manager_factory';

export const NODE_DEFAULT_API_TIMEOUT = 10_000;
Expand Down
2 changes: 0 additions & 2 deletions lib/odp/odp_manager_factory.react_native.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ describe('createOdpManager', () => {
segmentsCache: {} as any,
segmentsCacheSize: 11,
segmentsCacheTimeout: 2025,
segmentManager: {} as any,
eventManager: {} as any,
userAgentParser: {} as any,
};
const odpManager = createOdpManager(options);
Expand Down
34 changes: 2 additions & 32 deletions lib/odp/odp_manager_factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,7 @@ describe('getOdpManager', () => {
MockExponentialBackoff.mockClear();
});

it('should use provided segment manager', () => {
const segmentManager = {} as any;

const odpManager = getOdpManager({
segmentManager,
segmentRequestHandler: getMockRequestHandler(),
eventRequestHandler: getMockRequestHandler(),
eventRequestGenerator: vi.fn(),
});

expect(Object.is(odpManager, MockDefaultOdpManager.mock.instances[0])).toBe(true);
const { segmentManager: usedSegmentManager } = MockDefaultOdpManager.mock.calls[0][0];
expect(usedSegmentManager).toBe(segmentManager);
});

describe('when no segment manager is provided', () => {
describe('segment manager', () => {
it('should create a default segment manager with default api manager using the passed eventRequestHandler', () => {
const segmentRequestHandler = getMockRequestHandler();
const odpManager = getOdpManager({
Expand Down Expand Up @@ -205,22 +190,7 @@ describe('getOdpManager', () => {
});
});

it('uses provided event manager', () => {
const eventManager = {} as any;

const odpManager = getOdpManager({
eventManager,
segmentRequestHandler: getMockRequestHandler(),
eventRequestHandler: getMockRequestHandler(),
eventRequestGenerator: vi.fn(),
});

expect(odpManager).toBe(MockDefaultOdpManager.mock.instances[0]);
const { eventManager: usedEventManager } = MockDefaultOdpManager.mock.calls[0][0];
expect(usedEventManager).toBe(eventManager);
});

describe('when no event manager is provided', () => {
describe('event manager', () => {
it('should use a default event manager with default api manager using the passed eventRequestHandler and eventRequestGenerator', () => {
const eventRequestHandler = getMockRequestHandler();
const eventRequestGenerator = vi.fn();
Expand Down
6 changes: 2 additions & 4 deletions lib/odp/odp_manager_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ export type OdpManagerOptions = {
segmentsCacheSize?: number;
segmentsCacheTimeout?: number;
segmentsApiTimeout?: number;
segmentManager?: OdpSegmentManager;
eventFlushInterval?: number;
eventBatchSize?: number;
eventApiTimeout?: number;
eventManager?: OdpEventManager;
userAgentParser?: UserAgentParser;
};

Expand Down Expand Up @@ -90,8 +88,8 @@ const getDefaultEventManager = (options: OdpManagerFactoryOptions) => {
}

export const getOdpManager = (options: OdpManagerFactoryOptions): OdpManager => {
const segmentManager = options.segmentManager || getDefaultSegmentManager(options);
const eventManager = options.eventManager || getDefaultEventManager(options);
const segmentManager = getDefaultSegmentManager(options);
const eventManager = getDefaultEventManager(options);

return new DefaultOdpManager({
segmentManager,
Expand Down
38 changes: 38 additions & 0 deletions lib/odp/odp_manager_factory.universal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2025, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { RequestHandler } from '../utils/http_request_handler/http';
import { eventApiRequestGenerator } from './event_manager/odp_event_api_manager';
import { getOpaqueOdpManager, OdpManagerOptions, OpaqueOdpManager } from './odp_manager_factory';

export const DEFAULT_API_TIMEOUT = 10_000;
export const DEFAULT_BATCH_SIZE = 1;
export const DEFAULT_FLUSH_INTERVAL = 1000;

export type UniversalOdpManagerOptions = OdpManagerOptions & {
requestHandler: RequestHandler;
};

export const createOdpManager = (options: UniversalOdpManagerOptions): OpaqueOdpManager => {
return getOpaqueOdpManager({
...options,
segmentRequestHandler: options.requestHandler,
eventRequestHandler: options.requestHandler,
eventBatchSize: options.eventBatchSize || DEFAULT_BATCH_SIZE,
eventFlushInterval: options.eventFlushInterval || DEFAULT_FLUSH_INTERVAL,
eventRequestGenerator: eventApiRequestGenerator,
});
};
1 change: 0 additions & 1 deletion lib/vuid/vuid_manager_factory.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ export const createVuidManager = (options: VuidManagerOptions = {}): OpaqueVuidM
enableVuid: options.enableVuid
}));
};

Loading