|
| 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/project_config' { |
| 18 | + import { LogHandler } from '@optimizely/js-sdk-logging'; |
| 19 | + |
| 20 | + // eslint-disable-next-line @typescript-eslint/no-empty-interface |
| 21 | + export interface ProjectConfig {} |
| 22 | + /** |
| 23 | + * Determine for given experiment if event is running, which determines whether should be dispatched or not |
| 24 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 25 | + * @param {string} experimentKey Experiment key for which the status is to be determined |
| 26 | + * @return {boolean} True is the experiment is running |
| 27 | + * False is the experiment is not running |
| 28 | + * |
| 29 | + */ |
| 30 | + export function isRunning(configObj: ProjectConfig, experimentKey: string): boolean; |
| 31 | + |
| 32 | + /** |
| 33 | + * Get the variation ID given the experiment key and variation key |
| 34 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 35 | + * @param {string} experimentKey Key of the experiment the variation belongs to |
| 36 | + * @param {string} variationKey The variation key |
| 37 | + * @return {string} the variation ID |
| 38 | + */ |
| 39 | + export function getVariationIdFromExperimentAndVariationKey(configObj: ProjectConfig, experimentKey: string, variationKey: string): string; |
| 40 | + |
| 41 | + /** |
| 42 | + * Get experiment ID for the provided experiment key |
| 43 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 44 | + * @param {string} experimentKey Experiment key for which ID is to be determined |
| 45 | + * @return {string} Experiment ID corresponding to the provided experiment key |
| 46 | + * @throws If experiment key is not in datafile |
| 47 | + */ |
| 48 | + export function getExperimentId(configObj: ProjectConfig, experimentKey: string): string | never; |
| 49 | + |
| 50 | + /** |
| 51 | + * Check if the event with a specific key is present in the datafile |
| 52 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 53 | + * @param {string} eventKey Event key for which event is to be determined |
| 54 | + * @returns {boolean} True if key exists in the datafile |
| 55 | + * False if key does not exist in the datafile |
| 56 | + */ |
| 57 | + export function eventWithKeyExists(configObj: ProjectConfig, eventKey: string): boolean; |
| 58 | + |
| 59 | + /** |
| 60 | + * Check if the experiment is belongs to any feature |
| 61 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 62 | + * @param {string} experimentId Experiment ID of an experiment |
| 63 | + * @returns {boolean} True if experiement belongs to any feature |
| 64 | + * False if experiement does not belong to any feature |
| 65 | + */ |
| 66 | + export function isFeatureExperiment(configObj: ProjectConfig, experimentId: string): boolean; |
| 67 | + |
| 68 | + /** |
| 69 | + * Get feature from provided feature key. Log an error if no feature exists in |
| 70 | + * the project config with the given key. |
| 71 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 72 | + * @param {string} featureKey Key of a feature for which feature is to be determined |
| 73 | + * @param {LogHandler} logger Logger instance |
| 74 | + * @return {FeatureFlag|null} Feature object, or null if no feature with the given |
| 75 | + * key exists |
| 76 | + */ |
| 77 | + export function getFeatureFromKey(configObj: ProjectConfig, featureKey: string, logger: LogHandler): import('./entities').FeatureFlag | null; |
| 78 | + |
| 79 | + /** |
| 80 | + * Get the variable with the given key associated with the feature with the |
| 81 | + * given key. If the feature key or the variable key are invalid, log an error |
| 82 | + * message. |
| 83 | + * @param {ProjectConfig} configObj Object representing project configuration |
| 84 | + * @param {string} featureKey Key of a feature for which feature is to be determined |
| 85 | + * @param {string} variableKey Key of a variable for which variable is to be determined |
| 86 | + * @param {LogHandler} logger Logger instances |
| 87 | + * @return {FeatureVariable|null} Variable object, or null one or both of the given |
| 88 | + * feature and variable keys are invalid |
| 89 | + */ |
| 90 | + export function getVariableForFeature(configObj: ProjectConfig, featureKey: string, variableKey: string, logger: LogHandler): import('./entities').FeatureVariable | null; |
| 91 | + |
| 92 | + /** |
| 93 | + * Given a variable value in string form, try to cast it to the argument type. |
| 94 | + * If the type cast succeeds, return the type casted value, otherwise log an |
| 95 | + * error and return null. |
| 96 | + * @param {string} variableValue Variable value in string form |
| 97 | + * @param {string} type Type of the variable whose value was passed |
| 98 | + * in the first argument. Must be one of |
| 99 | + * FEATURE_VARIABLE_TYPES in |
| 100 | + * lib/utils/enums/index.js. The return value's |
| 101 | + * type is determined by this argument (boolean |
| 102 | + * for BOOLEAN, number for INTEGER or DOUBLE, |
| 103 | + * and string for STRING). |
| 104 | + * @param {LogHandler} logger Logger instance |
| 105 | + * @returns {T} Variable value of the appropriate type, or |
| 106 | + * null if the type cast failed |
| 107 | + */ |
| 108 | + export function getTypeCastValue<T>(variableValue: string, type: string, logger: LogHandler): T; |
| 109 | +} |
0 commit comments