UNPKG

@optimizely/optimizely-sdk

Version:

JavaScript SDK for Optimizely Feature Experimentation, Optimizely Full Stack (legacy), and Optimizely Rollouts

80 lines (79 loc) 3.46 kB
/** * Copyright 2019-2022, 2024, 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 * * http://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 { LoggerFacade } from '../logging/logger'; import { OptimizelyConfig } from '../shared_types'; import { DatafileManager } from './datafile_manager'; import { ProjectConfig } from './project_config'; import { Service, BaseService } from '../service'; import { Consumer, Fn, Transformer } from '../utils/type'; export declare const NO_SDKKEY_OR_DATAFILE = "sdkKey or datafile must be provided"; export declare const GOT_INVALID_DATAFILE = "got invalid datafile"; import { Platform } from '../platform_support'; interface ProjectConfigManagerConfig { datafile?: string | Record<string, unknown>; jsonSchemaValidator?: Transformer<unknown, boolean>; datafileManager?: DatafileManager; logger?: LoggerFacade; } export interface ProjectConfigManager extends Service { setLogger(logger: LoggerFacade): void; getConfig(): ProjectConfig | undefined; getOptimizelyConfig(): OptimizelyConfig | undefined; onUpdate(listener: Consumer<ProjectConfig>): Fn; } /** * ProjectConfigManager provides project config objects via its methods * getConfig and onUpdate. It uses a DatafileManager to fetch datafile if provided. * It is responsible for parsing and validating datafiles, and converting datafile * string into project config objects. * @param {ProjectConfigManagerConfig} config */ export declare const LOGGER_NAME = "ProjectConfigManager"; export declare class ProjectConfigManagerImpl extends BaseService implements ProjectConfigManager { private datafile?; private projectConfig?; private optimizelyConfig?; jsonSchemaValidator?: Transformer<unknown, boolean>; datafileManager?: DatafileManager; private eventEmitter; constructor(config: ProjectConfigManagerConfig); setLogger(logger: LoggerFacade): void; start(): void; makeDisposable(): void; private handleInitError; private handleDatafileManagerError; /** * Handle new datafile by attemping to create a new Project Config object. If successful and * the new config object's revision is newer than the current one, sets/updates the project config * and emits onUpdate event. If unsuccessful, * the project config and optimizely config objects will not be updated. If the error * is fatal, handleInitError will be called. */ private handleNewDatafile; getConfig(): ProjectConfig | undefined; getOptimizelyConfig(): OptimizelyConfig | undefined; /** * Add a listener for project config updates. The listener will be called * whenever this instance has a new project config object available. * Returns a dispose function that removes the subscription * @param {Function} listener * @return {Function} */ onUpdate(listener: Consumer<ProjectConfig>): Fn; stop(): void; } export declare const __platforms: Platform[]; export {};