UNPKG

ibm-appconfiguration-js-client-sdk

Version:
105 lines (104 loc) 4.07 kB
/** * Copyright 2022 IBM Corp. All Rights Reserved. * * 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 { IFeatureSegmentRule } from './FeatureSegmentRule'; import { RolloutConfiguration } from '../utils/rollout'; export interface IFeature { name: string; feature_id: string; type: string; format?: string; enabled_value: any; disabled_value: any; segment_rules: IFeatureSegmentRule[]; enabled: boolean; rollout_percentage?: number; rollout_type?: string; rollout_configuration?: RolloutConfiguration; } export default class Feature { private name; private feature_id; private type; private format; private enabled_value; private disabled_value; private segment_rules; private enabled; private rollout_percentage; private rollout_type; private rollout_configuration; constructor({ name, feature_id, type, format, enabled_value, disabled_value, segment_rules, enabled, rollout_percentage, rollout_type, rollout_configuration, }: IFeature); /** * Get the Feature flag name. * * @return {*} {string} The Feature flag name. * @memberof Feature */ getFeatureName(): string; /** * Get the Feature flag Id. * * @return {*} {string} The Feature flag Id. * @memberof Feature */ getFeatureId(): string; /** * Get the Feature flag data type. * * @return {*} {string} string named BOOLEAN/STRING/NUMERIC. * @memberof Feature */ getFeatureDataType(): string; /** * Get the Feature flag data format. * Applicable only for STRING datatype feature flag. * * @return {*} {(string | undefined)} string named TEXT/JSON/YAML. * @memberof Feature */ getFeatureDataFormat(): string | undefined; /** * Returns the state of the feature flag. * * @return {*} {boolean} Returns true, if the feature flag is enabled, otherwise returns false. * @memberof Feature */ isEnabled(): boolean; /** * Get the evaluated value of the feature flag. * * @param {string} entityId - Id of the Entity. * This will be a string identifier related to the Entity against which the feature is evaluated. * For example, an entity might be an instance of an app that runs on a mobile device, a microservice that runs on the cloud, or a component of infrastructure that runs that microservice. * For any entity to interact with App Configuration, it must provide a unique entity ID. * * @param {{ [x: string]: any; }} entityAttributes - A JSON object consisting of the attribute name and their values that defines the specified entity. * This is an optional parameter if the feature flag is not configured with any targeting definition. If the targeting is configured, then entityAttributes should be provided for the rule evaluation. * An attribute is a parameter that is used to define a segment. The SDK uses the attribute values to determine if the * specified entity satisfies the targeting rules, and returns the appropriate feature flag value. * * @return {*} {*} Returns one of the Enabled/Disabled/Overridden value based on the evaluation. * The data type of returned value matches that of feature flag. * @memberof Feature */ getCurrentValue(entityId: string, entityAttributes?: { [x: string]: any; }): any; private featureEvaluation; private parseRules; private evaluateRules; private evaluateSegment; }