|
| 1 | +/** |
| 2 | + * Copyright 2020, 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 | + * http://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 | +declare module '@optimizely/optimizely-sdk/lib/core/projet_config_manager' { |
| 18 | + import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config'; |
| 19 | + |
| 20 | + /** |
| 21 | + * ProjectConfigManager provides project config objects via its methods |
| 22 | + * getConfig and onUpdate. It uses a DatafileManager to fetch datafiles. It is |
| 23 | + * responsible for parsing and validating datafiles, and converting datafile |
| 24 | + * JSON objects into project config objects. |
| 25 | + * @param {ProjectConfig} config |
| 26 | + * @param {Object|string} config.datafile |
| 27 | + * @param {Object} config.datafileOptions |
| 28 | + * @param {Object} config.jsonSchemaValidator |
| 29 | + * @param {string} config.sdkKey |
| 30 | + */ |
| 31 | + export function ProjectConfigManager(config: ProjectConfig): ProjectConfigManager; |
| 32 | + |
| 33 | + interface ProjectConfigManager { |
| 34 | + |
| 35 | + /** |
| 36 | + * Returns the current project config object, or null if no project config object |
| 37 | + * is available |
| 38 | + * @return {ProjectConfig|null} |
| 39 | + */ |
| 40 | + getConfig(): ProjectConfig | null; |
| 41 | + |
| 42 | + /** |
| 43 | + * Add a listener for project config updates. The listener will be called |
| 44 | + * whenever this instance has a new project config object available. |
| 45 | + * Returns a dispose function that removes the subscription |
| 46 | + * @param {Function} listener |
| 47 | + * @return {Function} |
| 48 | + */ |
| 49 | + onUpdate(): (listener: (config: ProjectConfig) => void) => () => void; |
| 50 | + |
| 51 | + /** |
| 52 | + * Returns a Promise that fulfills when this ProjectConfigManager is ready to |
| 53 | + * use (meaning it has a valid project config object), or has failed to become |
| 54 | + * ready. |
| 55 | + * |
| 56 | + * Failure can be caused by the following: |
| 57 | + * - At least one of sdkKey or datafile is not provided in the constructor argument |
| 58 | + * - The provided datafile was invalid |
| 59 | + * - The datafile provided by the datafile manager was invalid |
| 60 | + * - The datafile manager failed to fetch a datafile |
| 61 | + * |
| 62 | + * The returned Promise is fulfilled with a result object containing these |
| 63 | + * properties: |
| 64 | + * - success (boolean): True if this instance is ready to use with a valid |
| 65 | + * project config object, or false if it failed to |
| 66 | + * become ready |
| 67 | + * - reason (string=): If success is false, this is a string property with |
| 68 | + * an explanatory message. |
| 69 | + * @return {Promise} |
| 70 | + */ |
| 71 | + onReady(): Promise<{ success: boolean; reason?: string }>; |
| 72 | + |
| 73 | + /** |
| 74 | + * Returns the optimizely config object |
| 75 | + * @return {OptimizelyConfig} |
| 76 | + */ |
| 77 | + getOptimizelyConfig(): import('../../shared_types').OptimizelyConfig; |
| 78 | + |
| 79 | + /** |
| 80 | + * Stop the internal datafile manager and remove all update listeners |
| 81 | + * @return {void} |
| 82 | + */ |
| 83 | + stop(): void; |
| 84 | + } |
| 85 | +} |
0 commit comments