|
| 1 | +/** |
| 2 | + * Copyright 2025, Optimizely |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { expectTypeOf } from 'vitest'; |
| 18 | + |
| 19 | +import * as universal from './index.universal'; |
| 20 | + |
| 21 | +type WithoutReadonly<T> = { -readonly [P in keyof T]: T[P] }; |
| 22 | + |
| 23 | +const universalEntrypoint: WithoutReadonly<typeof universal> = universal; |
| 24 | + |
| 25 | +import { |
| 26 | + Config, |
| 27 | + Client, |
| 28 | + StaticConfigManagerConfig, |
| 29 | + OpaqueConfigManager, |
| 30 | + EventDispatcher, |
| 31 | + OpaqueEventProcessor, |
| 32 | + OpaqueLevelPreset, |
| 33 | + LoggerConfig, |
| 34 | + OpaqueLogger, |
| 35 | + ErrorHandler, |
| 36 | + OpaqueErrorNotifier, |
| 37 | +} from './export_types'; |
| 38 | + |
| 39 | +import { UniversalPollingConfigManagerConfig } from './project_config/config_manager_factory.universal'; |
| 40 | +import { RequestHandler } from './utils/http_request_handler/http'; |
| 41 | +import { UniversalBatchEventProcessorOptions } from './event_processor/event_processor_factory.universal'; |
| 42 | +import { |
| 43 | + DECISION_SOURCES, |
| 44 | + DECISION_NOTIFICATION_TYPES, |
| 45 | + NOTIFICATION_TYPES, |
| 46 | +} from './utils/enums'; |
| 47 | + |
| 48 | +import { LogLevel } from './logging/logger'; |
| 49 | + |
| 50 | +import { OptimizelyDecideOption } from './shared_types'; |
| 51 | + |
| 52 | +export type UniversalEntrypoint = { |
| 53 | + // client factory |
| 54 | + createInstance: (config: Config) => Client | null; |
| 55 | + |
| 56 | + // config manager related exports |
| 57 | + createStaticProjectConfigManager: (config: StaticConfigManagerConfig) => OpaqueConfigManager; |
| 58 | + createPollingProjectConfigManager: (config: UniversalPollingConfigManagerConfig) => OpaqueConfigManager; |
| 59 | + |
| 60 | + // event processor related exports |
| 61 | + createEventDispatcher: (requestHandler: RequestHandler) => EventDispatcher; |
| 62 | + createForwardingEventProcessor: (eventDispatcher: EventDispatcher) => OpaqueEventProcessor; |
| 63 | + createBatchEventProcessor: (options: UniversalBatchEventProcessorOptions) => OpaqueEventProcessor; |
| 64 | + |
| 65 | + // TODO: odp manager related exports |
| 66 | + // createOdpManager: (options: OdpManagerOptions) => OpaqueOdpManager; |
| 67 | + |
| 68 | + // TODO: vuid manager related exports |
| 69 | + // createVuidManager: (options: VuidManagerOptions) => OpaqueVuidManager; |
| 70 | + |
| 71 | + // logger related exports |
| 72 | + LogLevel: typeof LogLevel; |
| 73 | + DebugLog: OpaqueLevelPreset, |
| 74 | + InfoLog: OpaqueLevelPreset, |
| 75 | + WarnLog: OpaqueLevelPreset, |
| 76 | + ErrorLog: OpaqueLevelPreset, |
| 77 | + createLogger: (config: LoggerConfig) => OpaqueLogger; |
| 78 | + |
| 79 | + // error related exports |
| 80 | + createErrorNotifier: (errorHandler: ErrorHandler) => OpaqueErrorNotifier; |
| 81 | + |
| 82 | + // enums |
| 83 | + DECISION_SOURCES: typeof DECISION_SOURCES; |
| 84 | + DECISION_NOTIFICATION_TYPES: typeof DECISION_NOTIFICATION_TYPES; |
| 85 | + NOTIFICATION_TYPES: typeof NOTIFICATION_TYPES; |
| 86 | + |
| 87 | + // decide options |
| 88 | + OptimizelyDecideOption: typeof OptimizelyDecideOption; |
| 89 | + |
| 90 | + // client engine |
| 91 | + clientEngine: string; |
| 92 | +} |
| 93 | + |
| 94 | + |
| 95 | +expectTypeOf(universalEntrypoint).toEqualTypeOf<UniversalEntrypoint>(); |
0 commit comments