@optimizely/optimizely-sdk
Version:
JavaScript SDK for Optimizely Feature Experimentation, Optimizely Full Stack (legacy), and Optimizely Rollouts
174 lines (173 loc) • 8.72 kB
TypeScript
/**
* Copyright 2020-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 { ProjectConfig } from '../project_config/project_config';
import { Audience, Experiment, FeatureVariable, OptimizelyAttribute, OptimizelyAudience, OptimizelyEvent, OptimizelyExperiment, OptimizelyExperimentsMap, OptimizelyFeaturesMap, OptimizelyVariablesMap, Rollout, Variation, VariationVariable } from '../shared_types';
import { Platform } from '../platform_support';
interface FeatureVariablesMap {
[key: string]: FeatureVariable[];
}
/**
* The OptimizelyConfig class
* @param {ProjectConfig} configObj
* @param {string} datafile
*/
export declare class OptimizelyConfig {
environmentKey: string;
sdkKey: string;
revision: string;
/**
* This experimentsMap is for experiments of legacy projects only.
* For flag projects, experiment keys are not guaranteed to be unique
* across multiple flags, so this map may not include all experiments
* when keys conflict.
*/
experimentsMap: OptimizelyExperimentsMap;
featuresMap: OptimizelyFeaturesMap;
attributes: OptimizelyAttribute[];
audiences: OptimizelyAudience[];
events: OptimizelyEvent[];
private datafile;
constructor(configObj: ProjectConfig, datafile: string, logger?: LoggerFacade);
/**
* Get the datafile
* @returns {string} JSON string representation of the datafile that was used to create the current config object
*/
getDatafile(): string;
/**
* Get Unique audiences list with typedAudiences as priority
* @param {ProjectConfig} configObj
* @returns {OptimizelyAudience[]} Array of unique audiences
*/
static getAudiences(configObj: ProjectConfig): OptimizelyAudience[];
/**
* Converts list of audience conditions to serialized audiences used in experiment
* for examples:
* 1. Input: ["or", "1", "2"]
* Output: "\"us\" OR \"female\""
* 2. Input: ["not", "1"]
* Output: "NOT \"us\""
* 3. Input: ["or", "1"]
* Output: "\"us\""
* 4. Input: ["and", ["or", "1", ["and", "2", "3"]], ["and", "11", ["or", "12", "13"]]]
* Output: "(\"us\" OR (\"female\" AND \"adult\")) AND (\"fr\" AND (\"male\" OR \"kid\"))"
* @param {Array<string | string[]>} conditions
* @param {[id: string]: Audience} audiencesById
* @returns {string} Serialized audiences condition string
*/
static getSerializedAudiences(conditions: Array<string | string[]>, audiencesById: {
[id: string]: Audience;
}): string;
/**
* Get serialized audience condition string for experiment
* @param {Experiment} experiment
* @param {ProjectConfig} configObj
* @returns {string} Serialized audiences condition string
*/
static getExperimentAudiences(experiment: Experiment, configObj: ProjectConfig): string;
/**
* Make map of featureVariable which are associated with given feature experiment
* @param {FeatureVariablesMap} featureIdVariableMap
* @param {[id: string]: FeatureVariable} variableIdMap
* @param {string} featureId
* @param {VariationVariable[] | undefined} featureVariableUsages
* @param {boolean | undefined} isFeatureEnabled
* @returns {OptimizelyVariablesMap} FeatureVariables mapped by key
*/
static mergeFeatureVariables(featureIdVariableMap: FeatureVariablesMap, variableIdMap: {
[id: string]: FeatureVariable;
}, featureId: string, featureVariableUsages: VariationVariable[] | undefined, isFeatureEnabled: boolean | undefined): OptimizelyVariablesMap;
/**
* Gets Map of all experiment variations and variables including rollouts
* @param {Variation[]} variations
* @param {FeatureVariablesMap} featureIdVariableMap
* @param {{[id: string]: FeatureVariable}} variableIdMap
* @param {string} featureId
* @returns {[key: string]: Variation} Variations mapped by key
*/
static getVariationsMap(variations: Variation[], featureIdVariableMap: FeatureVariablesMap, variableIdMap: {
[id: string]: FeatureVariable;
}, featureId: string): {
[key: string]: Variation;
};
/**
* Gets Map of FeatureVariable with respect to featureVariableId
* @param {ProjectConfig} configObj
* @returns {[id: string]: FeatureVariable} FeatureVariables mapped by id
*/
static getVariableIdMap(configObj: ProjectConfig): {
[id: string]: FeatureVariable;
};
/**
* Gets list of rollout experiments
* @param {ProjectConfig} configObj
* @param {FeatureVariablesMap} featureVariableIdMap
* @param {string} featureId
* @param {Experiment[]} experiments
* @param {{[id: string]: FeatureVariable}} variableIdMap
* @returns {OptimizelyExperiment[]} List of Optimizely rollout experiments
*/
static getDeliveryRules(configObj: ProjectConfig, featureVariableIdMap: FeatureVariablesMap, featureId: string, experiments: Experiment[], variableIdMap: {
[id: string]: FeatureVariable;
}): OptimizelyExperiment[];
/**
* Get Experiment Ids which are part of rollout
* @param {Rollout[]} rollouts
* @returns {string[]} Array of experiment Ids
*/
static getRolloutExperimentIds(rollouts: Rollout[]): string[];
/**
* Get experiments mapped by their id's which are not part of a rollout
* @param {ProjectConfig} configObj
* @param {FeatureVariablesMap} featureIdVariableMap
* @param {{[id: string]: FeatureVariable}} variableIdMap
* @returns { experimentsMapById: { [id: string]: OptimizelyExperiment }, experimentsMapByKey: OptimizelyExperimentsMap } Experiments mapped by id and key
*/
static getExperimentsMap(configObj: ProjectConfig, featureIdVariableMap: FeatureVariablesMap, variableIdMap: {
[id: string]: FeatureVariable;
}, logger?: LoggerFacade): {
experimentsMapById: {
[id: string]: OptimizelyExperiment;
};
experimentsMapByKey: OptimizelyExperimentsMap;
};
/**
* Get experiments mapped by their keys
* @param {OptimizelyExperimentsMap} experimentsMapById
* @returns {OptimizelyExperimentsMap} Experiments mapped by key
*/
static getExperimentsKeyMap(experimentsMapById: OptimizelyExperimentsMap): OptimizelyExperimentsMap;
/**
* Gets Map of all FeatureFlags and associated experiment map inside it
* @param {ProjectConfig} configObj
* @param {FeatureVariablesMap} featureVariableIdMap
* @param {OptimizelyExperimentsMap} experimentsMapById
* @param {{[id: string]: FeatureVariable}} variableIdMap
* @returns {OptimizelyFeaturesMap} OptimizelyFeature mapped by key
*/
static getFeaturesMap(configObj: ProjectConfig, featureVariableIdMap: FeatureVariablesMap, experimentsMapById: OptimizelyExperimentsMap, variableIdMap: {
[id: string]: FeatureVariable;
}): OptimizelyFeaturesMap;
}
/**
* Create an instance of OptimizelyConfig
* @param {ProjectConfig} configObj
* @param {string} datafile
* @returns {OptimizelyConfig} An instance of OptimizelyConfig
*/
export declare function createOptimizelyConfig(configObj: ProjectConfig, datafile: string, logger?: LoggerFacade): OptimizelyConfig;
export declare const __platforms: Platform[];
export {};