@microsoft/feature-management 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/common/targetingEvaluator.js.map +1 -1
- package/dist/commonjs/featureManager.js +5 -5
- package/dist/commonjs/featureManager.js.map +1 -1
- package/dist/commonjs/featureProvider.js.map +1 -1
- package/dist/commonjs/filter/recurrence/evaluator.js +142 -0
- package/dist/commonjs/filter/recurrence/evaluator.js.map +1 -0
- package/dist/commonjs/filter/recurrence/model.js +52 -0
- package/dist/commonjs/filter/recurrence/model.js.map +1 -0
- package/dist/commonjs/filter/recurrence/utils.js +53 -0
- package/dist/commonjs/filter/recurrence/utils.js.map +1 -0
- package/dist/commonjs/filter/recurrence/validator.js +197 -0
- package/dist/commonjs/filter/recurrence/validator.js.map +1 -0
- package/dist/commonjs/filter/{TargetingFilter.js → targetingFilter.js} +1 -1
- package/dist/commonjs/filter/{TargetingFilter.js.map → targetingFilter.js.map} +1 -1
- package/dist/commonjs/filter/timeWindowFilter.js +49 -0
- package/dist/commonjs/filter/timeWindowFilter.js.map +1 -0
- package/dist/commonjs/filter/utils.js +16 -0
- package/dist/commonjs/filter/utils.js.map +1 -0
- package/dist/commonjs/schema/model.js.map +1 -1
- package/dist/commonjs/schema/validator.js.map +1 -1
- package/dist/commonjs/telemetry/featureEvaluationEvent.js.map +1 -1
- package/dist/commonjs/variant/{Variant.js → variant.js} +1 -1
- package/dist/commonjs/variant/variant.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/commonjs/version.js.map +1 -1
- package/dist/esm/common/targetingEvaluator.js.map +1 -1
- package/dist/esm/featureManager.js +3 -3
- package/dist/esm/featureManager.js.map +1 -1
- package/dist/esm/featureProvider.js.map +1 -1
- package/dist/esm/filter/recurrence/evaluator.js +140 -0
- package/dist/esm/filter/recurrence/evaluator.js.map +1 -0
- package/dist/esm/filter/recurrence/model.js +49 -0
- package/dist/esm/filter/recurrence/model.js.map +1 -0
- package/dist/esm/filter/recurrence/utils.js +48 -0
- package/dist/esm/filter/recurrence/utils.js.map +1 -0
- package/dist/esm/filter/recurrence/validator.js +184 -0
- package/dist/esm/filter/recurrence/validator.js.map +1 -0
- package/dist/esm/filter/{TargetingFilter.js → targetingFilter.js} +1 -1
- package/dist/esm/filter/{TargetingFilter.js.map → targetingFilter.js.map} +1 -1
- package/dist/esm/filter/timeWindowFilter.js +47 -0
- package/dist/esm/filter/timeWindowFilter.js.map +1 -0
- package/dist/esm/filter/utils.js +11 -0
- package/dist/esm/filter/utils.js.map +1 -0
- package/dist/esm/schema/model.js.map +1 -1
- package/dist/esm/schema/validator.js.map +1 -1
- package/dist/esm/telemetry/featureEvaluationEvent.js.map +1 -1
- package/dist/esm/variant/{Variant.js → variant.js} +1 -1
- package/dist/esm/variant/variant.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/{types → dist/types}/index.d.ts +43 -42
- package/dist/umd/index.js +439 -3
- package/dist/umd/index.js.map +1 -1
- package/package.json +41 -26
- package/dist/commonjs/filter/TimeWindowFilter.js +0 -22
- package/dist/commonjs/filter/TimeWindowFilter.js.map +0 -1
- package/dist/commonjs/variant/Variant.js.map +0 -1
- package/dist/esm/filter/TimeWindowFilter.js +0 -20
- package/dist/esm/filter/TimeWindowFilter.js.map +0 -1
- package/dist/esm/variant/Variant.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sources":["../../../../src/filter/recurrence/validator.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { RecurrenceParameters } from \"../timeWindowFilter.js\";\nimport { VALUE_OUT_OF_RANGE_ERROR_MESSAGE, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE, REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE, buildInvalidParameterErrorMessage } from \"../utils.js\";\nimport { DayOfWeek, RecurrenceSpec, RecurrencePattern, RecurrenceRange, RecurrencePatternType, RecurrenceRangeType, DAYS_PER_WEEK, ONE_DAY_IN_MILLISECONDS } from \"./model.js\";\nimport { calculateWeeklyDayOffset, sortDaysOfWeek, getDayOfWeek } from \"./utils.js\";\n\nexport const START_NOT_MATCHED_ERROR_MESSAGE = \"Start date is not a valid first occurrence.\";\nexport const TIME_WINDOW_DURATION_OUT_OF_RANGE_ERROR_MESSAGE = \"Time window duration cannot be longer than how frequently it occurs or be longer than 10 years.\";\nexport const PATTERN = \"Recurrence.Pattern\";\nexport const PATTERN_TYPE = \"Recurrence.Pattern.Type\";\nexport const INTERVAL = \"Recurrence.Pattern.Interval\";\nexport const DAYS_OF_WEEK = \"Recurrence.Pattern.DaysOfWeek\";\nexport const FIRST_DAY_OF_WEEK = \"Recurrence.Pattern.FirstDayOfWeek\";\nexport const RANGE = \"Recurrence.Range\";\nexport const RANGE_TYPE = \"Recurrence.Range.Type\";\nexport const END_DATE = \"Recurrence.Range.EndDate\";\nexport const NUMBER_OF_OCCURRENCES = \"Recurrence.Range.NumberOfOccurrences\";\n\n/**\n * Parses @see RecurrenceParameters into a @see RecurrenceSpec object. If the parameter is invalid, an error will be thrown.\n * @param startTime The start time of the base time window\n * @param day2 The end time of the base time window\n * @param recurrenceParameters The @see RecurrenceParameters to parse\n * @param TimeZoneOffset The time zone offset in milliseconds, by default 0\n * @returns A @see RecurrenceSpec object\n */\nexport function parseRecurrenceParameter(startTime: Date | undefined, endTime: Date | undefined, recurrenceParameters: RecurrenceParameters, TimeZoneOffset: number = 0): RecurrenceSpec {\n if (startTime === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(\"Start\", REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE));\n }\n if (endTime === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(\"End\", REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE));\n }\n if (startTime >= endTime) {\n throw new Error(buildInvalidParameterErrorMessage(\"End\", VALUE_OUT_OF_RANGE_ERROR_MESSAGE));\n }\n const timeWindowDuration = endTime.getTime() - startTime.getTime();\n if (timeWindowDuration > 10 * 365 * ONE_DAY_IN_MILLISECONDS) { // time window duration cannot be longer than 10 years\n throw new Error(buildInvalidParameterErrorMessage(\"End\", TIME_WINDOW_DURATION_OUT_OF_RANGE_ERROR_MESSAGE));\n }\n\n return {\n startTime: startTime,\n duration: timeWindowDuration,\n pattern: parseRecurrencePattern(startTime, endTime, recurrenceParameters, TimeZoneOffset),\n range: parseRecurrenceRange(startTime, recurrenceParameters),\n timezoneOffset: TimeZoneOffset\n };\n}\n\nfunction parseRecurrencePattern(startTime: Date, endTime: Date, recurrenceParameters: RecurrenceParameters, timeZoneOffset: number): RecurrencePattern {\n const rawPattern = recurrenceParameters.Pattern;\n if (rawPattern === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(PATTERN, REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE));\n }\n if (rawPattern.Type === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(PATTERN_TYPE, REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE));\n }\n const patternType = RecurrencePatternType[rawPattern.Type];\n if (patternType === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(PATTERN_TYPE, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n }\n let interval = rawPattern.Interval;\n if (interval !== undefined) {\n if (typeof interval !== \"number\") {\n throw new Error(buildInvalidParameterErrorMessage(INTERVAL, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n } else if (interval <= 0 || !Number.isInteger(interval)) {\n throw new Error(buildInvalidParameterErrorMessage(INTERVAL, VALUE_OUT_OF_RANGE_ERROR_MESSAGE));\n }\n } else {\n interval = 1;\n }\n const parsedPattern: RecurrencePattern = {\n type: patternType,\n interval: interval\n };\n const timeWindowDuration = endTime.getTime() - startTime.getTime();\n if (patternType === RecurrencePatternType.Daily) {\n if (timeWindowDuration > interval * ONE_DAY_IN_MILLISECONDS) {\n throw new Error(buildInvalidParameterErrorMessage(\"End\", TIME_WINDOW_DURATION_OUT_OF_RANGE_ERROR_MESSAGE));\n }\n } else if (patternType === RecurrencePatternType.Weekly) {\n let firstDayOfWeek: DayOfWeek;\n if (rawPattern.FirstDayOfWeek !== undefined) {\n firstDayOfWeek = DayOfWeek[rawPattern.FirstDayOfWeek];\n if (firstDayOfWeek === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(FIRST_DAY_OF_WEEK, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n }\n }\n else {\n firstDayOfWeek = DayOfWeek.Sunday;\n }\n parsedPattern.firstDayOfWeek = firstDayOfWeek;\n\n if (rawPattern.DaysOfWeek === undefined || rawPattern.DaysOfWeek.length === 0) {\n throw new Error(buildInvalidParameterErrorMessage(DAYS_OF_WEEK, REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE));\n }\n if (!Array.isArray(rawPattern.DaysOfWeek)) {\n throw new Error(buildInvalidParameterErrorMessage(DAYS_OF_WEEK, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n }\n const daysOfWeek = [...new Set(rawPattern.DaysOfWeek.map(day => DayOfWeek[day]))]; // dedup array\n if (daysOfWeek.some(day => day === undefined)) {\n throw new Error(buildInvalidParameterErrorMessage(DAYS_OF_WEEK, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n }\n if (timeWindowDuration > interval * DAYS_PER_WEEK * ONE_DAY_IN_MILLISECONDS ||\n !isDurationCompliantWithDaysOfWeek(timeWindowDuration, interval, daysOfWeek, firstDayOfWeek)) {\n throw new Error(buildInvalidParameterErrorMessage(\"End\", TIME_WINDOW_DURATION_OUT_OF_RANGE_ERROR_MESSAGE));\n }\n parsedPattern.daysOfWeek = daysOfWeek;\n\n // check whether \"Start\" is a valid first occurrence\n const alignedStartDay = getDayOfWeek(startTime, timeZoneOffset);\n if (!daysOfWeek.find(day => day === alignedStartDay)) {\n throw new Error(buildInvalidParameterErrorMessage(\"Start\", START_NOT_MATCHED_ERROR_MESSAGE));\n }\n }\n return parsedPattern;\n}\n\nfunction parseRecurrenceRange(startTime: Date, recurrenceParameters: RecurrenceParameters): RecurrenceRange {\n const rawRange = recurrenceParameters.Range;\n if (rawRange === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(RANGE, REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE));\n }\n if (rawRange.Type === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(RANGE_TYPE, REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE));\n }\n const rangeType = RecurrenceRangeType[rawRange.Type];\n if (rangeType === undefined) {\n throw new Error(buildInvalidParameterErrorMessage(RANGE_TYPE, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n }\n const parsedRange: RecurrenceRange = { type: rangeType };\n if (rangeType === RecurrenceRangeType.EndDate) {\n let endDate: Date;\n if (rawRange.EndDate !== undefined) {\n endDate = new Date(rawRange.EndDate);\n if (isNaN(endDate.getTime())) {\n throw new Error(buildInvalidParameterErrorMessage(END_DATE, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n }\n if (endDate < startTime) {\n throw new Error(buildInvalidParameterErrorMessage(END_DATE, VALUE_OUT_OF_RANGE_ERROR_MESSAGE));\n }\n } else {\n endDate = new Date(8.64e15); // the maximum date in ECMAScript: https://262.ecma-international.org/5.1/#sec-15.9.1.1\n }\n parsedRange.endDate = endDate;\n } else if (rangeType === RecurrenceRangeType.Numbered) {\n let numberOfOccurrences = rawRange.NumberOfOccurrences;\n if (numberOfOccurrences !== undefined) {\n if (typeof numberOfOccurrences !== \"number\") {\n throw new Error(buildInvalidParameterErrorMessage(NUMBER_OF_OCCURRENCES, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n } else if (numberOfOccurrences <= 0 || !Number.isInteger(numberOfOccurrences)) {\n throw new Error(buildInvalidParameterErrorMessage(NUMBER_OF_OCCURRENCES, VALUE_OUT_OF_RANGE_ERROR_MESSAGE));\n }\n } else {\n numberOfOccurrences = Number.MAX_SAFE_INTEGER;\n }\n parsedRange.numberOfOccurrences = numberOfOccurrences;\n }\n return parsedRange;\n}\n\nfunction isDurationCompliantWithDaysOfWeek(duration: number, interval: number, daysOfWeek: DayOfWeek[], firstDayOfWeek: DayOfWeek): boolean {\n if (daysOfWeek.length === 1) {\n return true;\n }\n const sortedDaysOfWeek = sortDaysOfWeek(daysOfWeek, firstDayOfWeek);\n let prev = sortedDaysOfWeek[0]; // the closest occurrence day to the first day of week\n let minGap = DAYS_PER_WEEK * ONE_DAY_IN_MILLISECONDS;\n for (let i = 1; i < sortedDaysOfWeek.length; i++) { // skip the first day\n const gap = calculateWeeklyDayOffset(sortedDaysOfWeek[i], prev) * ONE_DAY_IN_MILLISECONDS;\n minGap = gap < minGap ? gap : minGap;\n prev = sortedDaysOfWeek[i];\n }\n // It may across weeks. Check the next week if the interval is one week.\n if (interval == 1) {\n const gap = calculateWeeklyDayOffset(sortedDaysOfWeek[0], prev) * ONE_DAY_IN_MILLISECONDS;\n minGap = gap < minGap ? gap : minGap;\n }\n return minGap >= duration;\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;AAOO,MAAM,+BAA+B,GAAG;AACxC,MAAM,+CAA+C,GAAG;AACxD,MAAM,OAAO,GAAG;AAChB,MAAM,YAAY,GAAG;AACrB,MAAM,QAAQ,GAAG;AACjB,MAAM,YAAY,GAAG;AACrB,MAAM,iBAAiB,GAAG;AAC1B,MAAM,KAAK,GAAG;AACd,MAAM,UAAU,GAAG;AACnB,MAAM,QAAQ,GAAG;AACjB,MAAM,qBAAqB,GAAG;AAErC;;;;;;;AAOG;AACG,SAAU,wBAAwB,CAAC,SAA2B,EAAE,OAAyB,EAAE,oBAA0C,EAAE,cAAA,GAAyB,CAAC,EAAA;AACnK,IAAA,IAAI,SAAS,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,OAAO,EAAE,wCAAwC,CAAC,CAAC;IACzG;AACA,IAAA,IAAI,OAAO,KAAK,SAAS,EAAE;QACvB,MA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AG,GAAG,MAAM;AACpC,QAAA,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC;IAC9B;;AAEA,IAAA,IAAI,QAAQ,IAAI,CAAC,EAAE;AACf,QAAA,MAAM,GAAG,GAAG,wBAAwB,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,uBAAuB;AACzF,QAAA,MAAM,GAAG,GAAG,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM;IACxC;IACA,OAAO,MAAM,IAAI,QAAQ;AAC7B;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"targetingFilter.js","sources":["../../../src/filter/targetingFilter.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { IFeatureFilter } from \"./featureFilter.js\";\nimport { isTargetedPercentile } from \"../common/targetingEvaluator.js\";\nimport { ITargetingContext, ITargetingContextAccessor } from \"../common/targetingContext.js\";\n\ntype TargetingFilterParameters = {\n Audience: {\n DefaultRolloutPercentage: number;\n Users?: string[];\n Groups?: {\n Name: string;\n RolloutPercentage: number;\n }[];\n Exclusion?: {\n Users?: string[];\n Groups?: string[];\n };\n }\n}\n\ntype TargetingFilterEvaluationContext = {\n featureName: string;\n parameters: TargetingFilterParameters;\n}\n\nexport class TargetingFilter implements IFeatureFilter {\n readonly name: string = \"Microsoft.Targeting\";\n readonly #targetingContextAccessor?: ITargetingContextAccessor;\n\n constructor(targetingContextAccessor?: ITargetingContextAccessor) {\n this.#targetingContextAccessor = targetingContextAccessor;\n }\n\n async evaluate(context: TargetingFilterEvaluationContext, appContext?: ITargetingContext): Promise<boolean> {\n const { featureName, parameters } = context;\n TargetingFilter.#validateParameters(featureName, parameters);\n\n let targetingContext: ITargetingContext | undefined;\n if (appContext?.userId !== undefined || appContext?.groups !== undefined) {\n targetingContext = appContext;\n } else if (this.#targetingContextAccessor !== undefined) {\n targetingContext = this.#targetingContextAccessor.getTargetingContext();\n }\n\n if (parameters.Audience.Exclusion !== undefined) {\n // check if the user is in the exclusion list\n if (targetingContext?.userId !== undefined &&\n parameters.Audience.Exclusion.Users !== undefined &&\n parameters.Audience.Exclusion.Users.includes(targetingContext.userId)) {\n return false;\n }\n // check if the user is in a group within exclusion list\n if (targetingContext?.groups !== undefined &&\n parameters.Audience.Exclusion.Groups !== undefined) {\n for (const excludedGroup of parameters.Audience.Exclusion.Groups) {\n if (targetingContext.groups.includes(excludedGroup)) {\n return false;\n }\n }\n }\n }\n\n // check if the user is being targeted directly\n if (targetingContext?.userId !== undefined &&\n parameters.Audience.Users !== undefined &&\n parameters.Audience.Users.includes(targetingContext.userId)) {\n return true;\n }\n\n // check if the user is in a group that is being targeted\n if (targetingContext?.groups !== undefined &&\n parameters.Audience.Groups !== undefined) {\n for (const group of parameters.Audience.Groups) {\n if (targetingContext.groups.includes(group.Name)) {\n const hint = `${featureName}\\n${group.Name}`;\n if (await isTargetedPercentile(targetingContext.userId, hint, 0, group.RolloutPercentage)) {\n return true;\n }\n }\n }\n }\n\n // check if the user is being targeted by a default rollout percentage\n const hint = featureName;\n return isTargetedPercentile(targetingContext?.userId, hint, 0, parameters.Audience.DefaultRolloutPercentage);\n }\n\n static #validateParameters(featureName: string, parameters: TargetingFilterParameters): void {\n if (parameters.Audience.DefaultRolloutPercentage < 0 || parameters.Audience.DefaultRolloutPercentage > 100) {\n throw new Error(`Invalid feature flag: ${featureName}. Audience.DefaultRolloutPercentage must be a number between 0 and 100.`);\n }\n // validate RolloutPercentage for each group\n if (parameters.Audience.Groups !== undefined) {\n for (const group of parameters.Audience.Groups) {\n if (group.RolloutPercentage < 0 || group.RolloutPercentage > 100) {\n throw new Error(`Invalid feature flag: ${featureName}. RolloutPercentage of group ${group.Name} must be a number between 0 and 100.`);\n }\n }\n }\n }\n}\n"],"names":[],"mappings":";;AAAA;AACA;MA0Ba,eAAe,CAAA;IACf,IAAI,GAAW,qBAAqB;AACpC,IAAA,yBAAyB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KAAK,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE;AAC5C,gBAAA,IAAI,KAAK,CAAC,iBAAiB,GAAG,CAAC,IAAI,KAAK,CAAC,iBAAiB,GAAG,GAAG,EAAE;oBAC9D,MAAM,IAAI,KAAK,CAAC,CAAA,sBAAA,EAAyB,WAAW,CAAA,6BAAA,EAAgC,KAAK,CAAC,IAAI,CAAA,oCAAA,CAAsC,CAAC;gBACzI;YACJ;QACJ;IACJ;AACH;;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { parseRecurrenceParameter } from './recurrence/validator.js';
|
|
2
|
+
import { matchRecurrence } from './recurrence/evaluator.js';
|
|
3
|
+
import { buildInvalidParameterErrorMessage, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE } from './utils.js';
|
|
4
|
+
|
|
5
|
+
// Copyright (c) Microsoft Corporation.
|
|
6
|
+
// Licensed under the MIT license.
|
|
7
|
+
class TimeWindowFilter {
|
|
8
|
+
name = "Microsoft.TimeWindow";
|
|
9
|
+
evaluate(context) {
|
|
10
|
+
const { featureName, parameters } = context;
|
|
11
|
+
const startTime = parameters.Start !== undefined ? new Date(parameters.Start) : undefined;
|
|
12
|
+
const endTime = parameters.End !== undefined ? new Date(parameters.End) : undefined;
|
|
13
|
+
const baseErrorMessage = `The ${this.name} feature filter is not valid for feature ${featureName}. `;
|
|
14
|
+
if (startTime === undefined && endTime === undefined) {
|
|
15
|
+
// If neither start nor end time is specified, then the filter is not applicable.
|
|
16
|
+
console.warn(baseErrorMessage + "It must specify either 'Start', 'End', or both.");
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (startTime !== undefined && isNaN(startTime.getTime())) {
|
|
20
|
+
console.warn(baseErrorMessage + buildInvalidParameterErrorMessage("Start", UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (endTime !== undefined && isNaN(endTime.getTime())) {
|
|
24
|
+
console.warn(baseErrorMessage + buildInvalidParameterErrorMessage("End", UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const now = new Date();
|
|
28
|
+
if ((startTime === undefined || startTime <= now) && (endTime === undefined || now < endTime)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (parameters.Recurrence !== undefined) {
|
|
32
|
+
let recurrence;
|
|
33
|
+
try {
|
|
34
|
+
recurrence = parseRecurrenceParameter(startTime, endTime, parameters.Recurrence);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.warn(baseErrorMessage + error.message);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return matchRecurrence(now, recurrence);
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { TimeWindowFilter };
|
|
47
|
+
//# sourceMappingURL=timeWindowFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeWindowFilter.js","sources":["../../../src/filter/timeWindowFilter.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { IFeatureFilter } from \"./featureFilter.js\";\nimport { RecurrenceSpec } from \"./recurrence/model.js\";\nimport { parseRecurrenceParameter } from \"./recurrence/validator.js\";\nimport { matchRecurrence } from \"./recurrence/evaluator.js\";\nimport { UNRECOGNIZABLE_VALUE_ERROR_MESSAGE, buildInvalidParameterErrorMessage } from \"./utils.js\";\n\ntype TimeWindowFilterEvaluationContext = {\n featureName: string;\n parameters: TimeWindowParameters;\n};\n\ntype TimeWindowParameters = {\n Start?: string;\n End?: string;\n Recurrence?: RecurrenceParameters;\n};\n\nexport type RecurrenceParameters = {\n Pattern: {\n Type: string;\n Interval?: number;\n DaysOfWeek?: string[];\n FirstDayOfWeek?: string;\n },\n Range: {\n Type: string;\n EndDate?: string;\n NumberOfOccurrences?: number;\n }\n};\n\nexport class TimeWindowFilter implements IFeatureFilter {\n readonly name: string = \"Microsoft.TimeWindow\";\n\n evaluate(context: TimeWindowFilterEvaluationContext): boolean {\n const {featureName, parameters} = context;\n const startTime = parameters.Start !== undefined ? new Date(parameters.Start) : undefined;\n const endTime = parameters.End !== undefined ? new Date(parameters.End) : undefined;\n\n const baseErrorMessage = `The ${this.name} feature filter is not valid for feature ${featureName}. `;\n\n if (startTime === undefined && endTime === undefined) {\n // If neither start nor end time is specified, then the filter is not applicable.\n console.warn(baseErrorMessage + \"It must specify either 'Start', 'End', or both.\");\n return false;\n }\n\n if (startTime !== undefined && isNaN(startTime.getTime())) {\n console.warn(baseErrorMessage + buildInvalidParameterErrorMessage(\"Start\", UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n return false;\n }\n\n if (endTime !== undefined && isNaN(endTime.getTime())) {\n console.warn(baseErrorMessage + buildInvalidParameterErrorMessage(\"End\", UNRECOGNIZABLE_VALUE_ERROR_MESSAGE));\n return false;\n }\n\n const now = new Date();\n\n if ((startTime === undefined || startTime <= now) && (endTime === undefined || now < endTime)) {\n return true;\n }\n\n if (parameters.Recurrence !== undefined) {\n let recurrence: RecurrenceSpec;\n try {\n recurrence = parseRecurrenceParameter(startTime, endTime, parameters.Recurrence);\n } catch (error) {\n console.warn(baseErrorMessage + error.message);\n return false;\n }\n return matchRecurrence(now, recurrence);\n }\n\n return false;\n }\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;MAiCa,gBAAgB,CAAA;IAChB,IAAI,GAAW,sBAAsB;AAE9C,IAAA,QAAQ,CAAC,OAA0C,EAAA;AAC/C,QAAA,MAAM,EAAC,WAAW,EAAE,UAAU,EAAC,GAAG,OAAO;QACzC,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,KAAK,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,SAAS;QACzF,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,KAA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,CAAC,OAAO,CAAC;AAC9C,gBAAA,OAAO,KAAK;YAChB;AACA,YAAA,OAAO,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC;QAC3C;AAEA,QAAA,OAAO,KAAK;IAChB;AACH;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
const VALUE_OUT_OF_RANGE_ERROR_MESSAGE = "The value is out of the accepted range.";
|
|
4
|
+
const UNRECOGNIZABLE_VALUE_ERROR_MESSAGE = "The value is unrecognizable.";
|
|
5
|
+
const REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE = "Value cannot be undefined or empty.";
|
|
6
|
+
function buildInvalidParameterErrorMessage(parameterName, additionalInfo) {
|
|
7
|
+
return `The ${parameterName} parameter is not valid. ` + (additionalInfo ?? "");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE, UNRECOGNIZABLE_VALUE_ERROR_MESSAGE, VALUE_OUT_OF_RANGE_ERROR_MESSAGE, buildInvalidParameterErrorMessage };
|
|
11
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/filter/utils.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const VALUE_OUT_OF_RANGE_ERROR_MESSAGE = \"The value is out of the accepted range.\";\nexport const UNRECOGNIZABLE_VALUE_ERROR_MESSAGE = \"The value is unrecognizable.\";\nexport const REQUIRED_PARAMETER_MISSING_ERROR_MESSAGE = \"Value cannot be undefined or empty.\";\n\nexport function buildInvalidParameterErrorMessage(parameterName: string, additionalInfo?: string): string {\n return `The ${parameterName} parameter is not valid. ` + (additionalInfo ?? \"\");\n}\n"],"names":[],"mappings":"AAAA;AACA;AAEO,MAAM,gCAAgC,GAAG;AACzC,MAAM,kCAAkC,GAAG;AAC3C,MAAM,wCAAwC,GAAG;AAElD,SAAU,iCAAiC,CAAC,aAAqB,EAAE,cAAuB,EAAA;IAC5F,OAAO,CAAA,IAAA,EAAO,aAAa,CAAA,yBAAA,CAA2B,IAAI,cAAc,IAAI,EAAE,CAAC;AACnF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sources":["../../../src/schema/model.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// Converted from:\n// https://github.com/Azure/AppConfiguration/blob/6e544296a5607f922a423df165f60801717c7800/docs/FeatureManagement/FeatureFlag.v2.0.0.schema.json\n\n/**\n * A feature flag is a named property that can be toggled to enable or disable some feature of an application.\n */\nexport interface FeatureFlag {\n /**\n * An ID used to uniquely identify and reference the feature.\n */\n id: string;\n /**\n * A feature is OFF if enabled is false. If enabled is true, then the feature is ON if there are no conditions (null or empty) or if the conditions are satisfied.\n */\n enabled?: boolean;\n /**\n * The declaration of conditions used to dynamically enable the feature.\n */\n conditions?: FeatureEnablementConditions;\n /**\n * The list of variants defined for this feature. A variant represents a configuration value of a feature flag that can be a string, a number, a boolean, or a JSON object.\n */\n variants?: VariantDefinition[];\n /**\n * Determines how variants should be allocated for the feature to various users.\n */\n allocation?: VariantAllocation;\n /**\n * The declaration of options used to configure telemetry for this feature.\n */\n telemetry?: TelemetryOptions\n }\n\n /**\n * The declaration of conditions used to dynamically enable the feature\n */\n interface FeatureEnablementConditions {\n /**\n * Determines whether any or all registered client filters must be evaluated as true for the feature to be considered enabled.\n */\n requirement_type?: RequirementType;\n /**\n * Filters that must run on the client and be evaluated as true for the feature to be considered enabled.\n */\n client_filters?: ClientFilter[];\n }\n\n export type RequirementType = \"Any\" | \"All\";\n\n interface ClientFilter {\n /**\n * The name used to refer to a client filter.\n */\n name: string;\n /**\n * Parameters for a given client filter. A client filter can require any set of parameters of any type.\n */\n parameters?: Record<string, unknown>;\n }\n\n export interface VariantDefinition {\n /**\n * The name used to refer to a feature variant.\n */\n name: string;\n /**\n * The configuration value for this feature variant.\n */\n configuration_value?: unknown;\n /**\n * Overrides the enabled state of the feature if the given variant is assigned. Does not override the state if value is None.\n */\n status_override?: \"None\" | \"Enabled\" | \"Disabled\";\n }\n\n /**\n * Determines how variants should be allocated for the feature to various users.\n */\n interface VariantAllocation {\n /**\n * Specifies which variant should be used when the feature is considered disabled.\n */\n default_when_disabled?: string;\n /**\n * Specifies which variant should be used when the feature is considered enabled and no other allocation rules are applicable.\n */\n default_when_enabled?: string;\n /**\n * A list of objects, each containing a variant name and list of users for whom that variant should be used.\n */\n user?: UserAllocation[];\n /**\n * A list of objects, each containing a variant name and list of groups for which that variant should be used.\n */\n group?: GroupAllocation[];\n /**\n * A list of objects, each containing a variant name and percentage range for which that variant should be used.\n */\n percentile?: PercentileAllocation[]\n /**\n * The value percentile calculations are based on. The calculated percentile is consistent across features for a given user if the same nonempty seed is used.\n */\n seed?: string;\n }\n\n interface UserAllocation {\n /**\n * The name of the variant to use if the user allocation matches the current user.\n */\n variant: string;\n /**\n * Collection of users where if any match the current user, the variant specified in the user allocation is used.\n */\n users: string[];\n }\n\n interface GroupAllocation {\n /**\n * The name of the variant to use if the group allocation matches a group the current user is in.\n */\n variant: string;\n /**\n * Collection of groups where if the current user is in any of these groups, the variant specified in the group allocation is used.\n */\n groups: string[];\n }\n\n interface PercentileAllocation {\n /**\n * The name of the variant to use if the calculated percentile for the current user falls in the provided range.\n */\n variant: string;\n /**\n * The lower end of the percentage range for which this variant will be used.\n */\n from: number;\n /**\n * The upper end of the percentage range for which this variant will be used.\n */\n to: number;\n }\n\n /**\n * The declaration of options used to configure telemetry for this feature.\n */\n interface TelemetryOptions {\n /**\n * Indicates if telemetry is enabled.\n */\n enabled?: boolean;\n /**\n * A container for metadata that should be bundled with flag telemetry.\n */\n metadata?: Record<string, string>;\n }\n\n // Feature Management Section fed into feature manager.\n // Converted from https://github.com/Azure/AppConfiguration/blob/main/docs/FeatureManagement/FeatureManagement.v1.0.0.schema.json\n\n export const FEATURE_MANAGEMENT_KEY = \"feature_management\";\n export const FEATURE_FLAGS_KEY = \"feature_flags\";\n\n export interface FeatureManagementConfiguration {\n feature_management: FeatureManagement\n }\n\n /**\n * Declares feature management configuration.\n */\n export interface FeatureManagement {\n feature_flags: FeatureFlag[];\n }\n"],"names":[],"mappings":"AAAA;AACA;AA8JE;AACA;AAEO,MAAM,sBAAsB,GAAG
|
|
1
|
+
{"version":3,"file":"model.js","sources":["../../../src/schema/model.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// Converted from:\n// https://github.com/Azure/AppConfiguration/blob/6e544296a5607f922a423df165f60801717c7800/docs/FeatureManagement/FeatureFlag.v2.0.0.schema.json\n\n/**\n * A feature flag is a named property that can be toggled to enable or disable some feature of an application.\n */\nexport interface FeatureFlag {\n /**\n * An ID used to uniquely identify and reference the feature.\n */\n id: string;\n /**\n * A feature is OFF if enabled is false. If enabled is true, then the feature is ON if there are no conditions (null or empty) or if the conditions are satisfied.\n */\n enabled?: boolean;\n /**\n * The declaration of conditions used to dynamically enable the feature.\n */\n conditions?: FeatureEnablementConditions;\n /**\n * The list of variants defined for this feature. A variant represents a configuration value of a feature flag that can be a string, a number, a boolean, or a JSON object.\n */\n variants?: VariantDefinition[];\n /**\n * Determines how variants should be allocated for the feature to various users.\n */\n allocation?: VariantAllocation;\n /**\n * The declaration of options used to configure telemetry for this feature.\n */\n telemetry?: TelemetryOptions\n }\n\n /**\n * The declaration of conditions used to dynamically enable the feature\n */\n interface FeatureEnablementConditions {\n /**\n * Determines whether any or all registered client filters must be evaluated as true for the feature to be considered enabled.\n */\n requirement_type?: RequirementType;\n /**\n * Filters that must run on the client and be evaluated as true for the feature to be considered enabled.\n */\n client_filters?: ClientFilter[];\n }\n\n export type RequirementType = \"Any\" | \"All\";\n\n interface ClientFilter {\n /**\n * The name used to refer to a client filter.\n */\n name: string;\n /**\n * Parameters for a given client filter. A client filter can require any set of parameters of any type.\n */\n parameters?: Record<string, unknown>;\n }\n\n export interface VariantDefinition {\n /**\n * The name used to refer to a feature variant.\n */\n name: string;\n /**\n * The configuration value for this feature variant.\n */\n configuration_value?: unknown;\n /**\n * Overrides the enabled state of the feature if the given variant is assigned. Does not override the state if value is None.\n */\n status_override?: \"None\" | \"Enabled\" | \"Disabled\";\n }\n\n /**\n * Determines how variants should be allocated for the feature to various users.\n */\n interface VariantAllocation {\n /**\n * Specifies which variant should be used when the feature is considered disabled.\n */\n default_when_disabled?: string;\n /**\n * Specifies which variant should be used when the feature is considered enabled and no other allocation rules are applicable.\n */\n default_when_enabled?: string;\n /**\n * A list of objects, each containing a variant name and list of users for whom that variant should be used.\n */\n user?: UserAllocation[];\n /**\n * A list of objects, each containing a variant name and list of groups for which that variant should be used.\n */\n group?: GroupAllocation[];\n /**\n * A list of objects, each containing a variant name and percentage range for which that variant should be used.\n */\n percentile?: PercentileAllocation[]\n /**\n * The value percentile calculations are based on. The calculated percentile is consistent across features for a given user if the same nonempty seed is used.\n */\n seed?: string;\n }\n\n interface UserAllocation {\n /**\n * The name of the variant to use if the user allocation matches the current user.\n */\n variant: string;\n /**\n * Collection of users where if any match the current user, the variant specified in the user allocation is used.\n */\n users: string[];\n }\n\n interface GroupAllocation {\n /**\n * The name of the variant to use if the group allocation matches a group the current user is in.\n */\n variant: string;\n /**\n * Collection of groups where if the current user is in any of these groups, the variant specified in the group allocation is used.\n */\n groups: string[];\n }\n\n interface PercentileAllocation {\n /**\n * The name of the variant to use if the calculated percentile for the current user falls in the provided range.\n */\n variant: string;\n /**\n * The lower end of the percentage range for which this variant will be used.\n */\n from: number;\n /**\n * The upper end of the percentage range for which this variant will be used.\n */\n to: number;\n }\n\n /**\n * The declaration of options used to configure telemetry for this feature.\n */\n interface TelemetryOptions {\n /**\n * Indicates if telemetry is enabled.\n */\n enabled?: boolean;\n /**\n * A container for metadata that should be bundled with flag telemetry.\n */\n metadata?: Record<string, string>;\n }\n\n // Feature Management Section fed into feature manager.\n // Converted from https://github.com/Azure/AppConfiguration/blob/main/docs/FeatureManagement/FeatureManagement.v1.0.0.schema.json\n\n export const FEATURE_MANAGEMENT_KEY = \"feature_management\";\n export const FEATURE_FLAGS_KEY = \"feature_flags\";\n\n export interface FeatureManagementConfiguration {\n feature_management: FeatureManagement\n }\n\n /**\n * Declares feature management configuration.\n */\n export interface FeatureManagement {\n feature_flags: FeatureFlag[];\n }\n"],"names":[],"mappings":"AAAA;AACA;AA8JE;AACA;AAEO,MAAM,sBAAsB,GAAG;AAC/B,MAAM,iBAAiB,GAAG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sources":["../../../src/schema/validator.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Validates a feature flag object, checking if it conforms to the schema.\n * @param featureFlag The feature flag object to validate.\n */\nexport function validateFeatureFlag(featureFlag: any): void {\n if (featureFlag === undefined) {\n return; // no-op if feature flag is undefined, indicating that the feature flag is not found\n }\n if (featureFlag === null || typeof featureFlag !== \"object\") { // Note: typeof null = \"object\"\n throw new TypeError(\"Feature flag must be an object.\");\n }\n if (typeof featureFlag.id !== \"string\") {\n throw new TypeError(\"Feature flag 'id' must be a string.\");\n }\n\n if (featureFlag.enabled !== undefined && typeof featureFlag.enabled !== \"boolean\") {\n throw new TypeError(`Invalid feature flag: ${featureFlag.id}. Feature flag 'enabled' must be a boolean.`);\n }\n if (featureFlag.conditions !== undefined) {\n validateFeatureEnablementConditions(featureFlag.id, featureFlag.conditions);\n }\n if (featureFlag.variants !== undefined) {\n validateVariants(featureFlag.id, featureFlag.variants);\n }\n if (featureFlag.allocation !== undefined) {\n validateVariantAllocation(featureFlag.id, featureFlag.allocation);\n }\n if (featureFlag.telemetry !== undefined) {\n validateTelemetryOptions(featureFlag.id, featureFlag.telemetry);\n }\n}\n\nfunction validateFeatureEnablementConditions(id: string, conditions: any) {\n if (typeof conditions !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag 'conditions' must be an object.`);\n }\n if (conditions.requirement_type !== undefined && conditions.requirement_type !== \"Any\" && conditions.requirement_type !== \"All\") {\n throw new TypeError(`Invalid feature flag: ${id}. 'requirement_type' must be 'Any' or 'All'.`);\n }\n if (conditions.client_filters !== undefined) {\n validateClientFilters(id, conditions.client_filters);\n }\n}\n\nfunction validateClientFilters(id: string, client_filters: any) {\n if (!Array.isArray(client_filters)) {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag conditions 'client_filters' must be an array.`);\n }\n\n for (const filter of client_filters) {\n if (typeof filter.name !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Client filter 'name' must be a string.`);\n }\n if (filter.parameters !== undefined && typeof filter.parameters !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Client filter 'parameters' must be an object.`);\n }\n }\n}\n\nfunction validateVariants(id: string, variants: any) {\n if (!Array.isArray(variants)) {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag 'variants' must be an array.`);\n }\n\n for (const variant of variants) {\n if (typeof variant.name !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'name' must be a string.`);\n }\n // skip configuration_value validation as it accepts any type\n if (variant.status_override !== undefined && typeof variant.status_override !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'status_override' must be a string.`);\n }\n if (variant.status_override !== undefined && variant.status_override !== \"None\" && variant.status_override !== \"Enabled\" && variant.status_override !== \"Disabled\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'status_override' must be 'None', 'Enabled', or 'Disabled'.`);\n }\n }\n}\n\nfunction validateVariantAllocation(id: string, allocation: any) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'allocation' must be an object.`);\n }\n\n if (allocation.default_when_disabled !== undefined && typeof allocation.default_when_disabled !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant allocation 'default_when_disabled' must be a string.`);\n }\n if (allocation.default_when_enabled !== undefined && typeof allocation.default_when_enabled !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant allocation 'default_when_enabled' must be a string.`);\n }\n if (allocation.user !== undefined) {\n validateUserVariantAllocation(id, allocation.user);\n }\n if (allocation.group !== undefined) {\n validateGroupVariantAllocation(id, allocation.group);\n }\n if (allocation.percentile !== undefined) {\n validatePercentileVariantAllocation(id, allocation.percentile);\n }\n if (allocation.seed !== undefined && typeof allocation.seed !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant allocation 'seed' must be a string.`);\n }\n}\n\nfunction validateUserVariantAllocation(id: string, UserAllocations: any) {\n if (!Array.isArray(UserAllocations)) {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'user' allocation must be an array.`);\n }\n\n for (const allocation of UserAllocations) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in variant 'user' allocation must be an object.`);\n }\n if (typeof allocation.variant !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. User allocation 'variant' must be a string.`);\n }\n if (!Array.isArray(allocation.users)) {\n throw new TypeError(`Invalid feature flag: ${id}. User allocation 'users' must be an array.`);\n }\n for (const user of allocation.users) {\n if (typeof user !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in user allocation 'users' must be strings.`);\n }\n }\n }\n}\n\nfunction validateGroupVariantAllocation(id: string, groupAllocations: any) {\n if (!Array.isArray(groupAllocations)) {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'group' allocation must be an array.`);\n }\n\n for (const allocation of groupAllocations) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in variant 'group' allocation must be an object.`);\n }\n if (typeof allocation.variant !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Group allocation 'variant' must be a string.`);\n }\n if (!Array.isArray(allocation.groups)) {\n throw new TypeError(`Invalid feature flag: ${id}. Group allocation 'groups' must be an array.`);\n }\n for (const group of allocation.groups) {\n if (typeof group !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in group allocation 'groups' must be strings.`);\n }\n }\n }\n}\n\nfunction validatePercentileVariantAllocation(id: string, percentileAllocations: any) {\n if (!Array.isArray(percentileAllocations)) {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'percentile' allocation must be an array.`);\n }\n\n for (const allocation of percentileAllocations) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in variant 'percentile' allocation must be an object.`);\n }\n if (typeof allocation.variant !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Percentile allocation 'variant' must be a string.`);\n }\n if (typeof allocation.from !== \"number\" || allocation.from < 0 || allocation.from > 100) {\n throw new TypeError(`Invalid feature flag: ${id}. Percentile allocation 'from' must be a number between 0 and 100.`);\n }\n if (typeof allocation.to !== \"number\" || allocation.to < 0 || allocation.to > 100) {\n throw new TypeError(`Invalid feature flag: ${id}. Percentile allocation 'to' must be a number between 0 and 100.`);\n }\n }\n}\n// #endregion\n\n// #region Telemetry\nfunction validateTelemetryOptions(id: string, telemetry: any) {\n if (typeof telemetry !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag 'telemetry' must be an object.`);\n }\n if (telemetry.enabled !== undefined && typeof telemetry.enabled !== \"boolean\") {\n throw new TypeError(`Invalid feature flag: ${id}. Telemetry 'enabled' must be a boolean.`);\n }\n if (telemetry.metadata !== undefined && typeof telemetry.metadata !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Telemetry 'metadata' must be an object.`);\n }\n}\n// #endregion\n"],"names":[],"mappings":"AAAA;AACA;AAEA;;;AAGG;AACG,SAAU,mBAAmB,CAAC,WAAgB,EAAA;AAChD,IAAA,IAAI,WAAW,KAAK,SAAS,EAAE;AAC3B,QAAA,OAAO;KACV;IACD,IAAI,WAAW,KAAK,IAAI,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;AACzD,QAA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Q,KAAK,QAAQ,EAAE;AAC5E,QAAA,MAAM,IAAI,SAAS,CAAC,yBAAyB,EAAE,CAAA,yCAAA,CAA2C,CAAC,CAAC;KAC/F;AACL,CAAC;AACD;;;;"}
|
|
1
|
+
{"version":3,"file":"validator.js","sources":["../../../src/schema/validator.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * Validates a feature flag object, checking if it conforms to the schema.\n * @param featureFlag The feature flag object to validate.\n */\nexport function validateFeatureFlag(featureFlag: any): void {\n if (featureFlag === undefined) {\n return; // no-op if feature flag is undefined, indicating that the feature flag is not found\n }\n if (featureFlag === null || typeof featureFlag !== \"object\") { // Note: typeof null = \"object\"\n throw new TypeError(\"Feature flag must be an object.\");\n }\n if (typeof featureFlag.id !== \"string\") {\n throw new TypeError(\"Feature flag 'id' must be a string.\");\n }\n\n if (featureFlag.enabled !== undefined && typeof featureFlag.enabled !== \"boolean\") {\n throw new TypeError(`Invalid feature flag: ${featureFlag.id}. Feature flag 'enabled' must be a boolean.`);\n }\n if (featureFlag.conditions !== undefined) {\n validateFeatureEnablementConditions(featureFlag.id, featureFlag.conditions);\n }\n if (featureFlag.variants !== undefined) {\n validateVariants(featureFlag.id, featureFlag.variants);\n }\n if (featureFlag.allocation !== undefined) {\n validateVariantAllocation(featureFlag.id, featureFlag.allocation);\n }\n if (featureFlag.telemetry !== undefined) {\n validateTelemetryOptions(featureFlag.id, featureFlag.telemetry);\n }\n}\n\nfunction validateFeatureEnablementConditions(id: string, conditions: any) {\n if (typeof conditions !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag 'conditions' must be an object.`);\n }\n if (conditions.requirement_type !== undefined && conditions.requirement_type !== \"Any\" && conditions.requirement_type !== \"All\") {\n throw new TypeError(`Invalid feature flag: ${id}. 'requirement_type' must be 'Any' or 'All'.`);\n }\n if (conditions.client_filters !== undefined) {\n validateClientFilters(id, conditions.client_filters);\n }\n}\n\nfunction validateClientFilters(id: string, client_filters: any) {\n if (!Array.isArray(client_filters)) {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag conditions 'client_filters' must be an array.`);\n }\n\n for (const filter of client_filters) {\n if (typeof filter.name !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Client filter 'name' must be a string.`);\n }\n if (filter.parameters !== undefined && typeof filter.parameters !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Client filter 'parameters' must be an object.`);\n }\n }\n}\n\nfunction validateVariants(id: string, variants: any) {\n if (!Array.isArray(variants)) {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag 'variants' must be an array.`);\n }\n\n for (const variant of variants) {\n if (typeof variant.name !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'name' must be a string.`);\n }\n // skip configuration_value validation as it accepts any type\n if (variant.status_override !== undefined && typeof variant.status_override !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'status_override' must be a string.`);\n }\n if (variant.status_override !== undefined && variant.status_override !== \"None\" && variant.status_override !== \"Enabled\" && variant.status_override !== \"Disabled\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'status_override' must be 'None', 'Enabled', or 'Disabled'.`);\n }\n }\n}\n\nfunction validateVariantAllocation(id: string, allocation: any) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'allocation' must be an object.`);\n }\n\n if (allocation.default_when_disabled !== undefined && typeof allocation.default_when_disabled !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant allocation 'default_when_disabled' must be a string.`);\n }\n if (allocation.default_when_enabled !== undefined && typeof allocation.default_when_enabled !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant allocation 'default_when_enabled' must be a string.`);\n }\n if (allocation.user !== undefined) {\n validateUserVariantAllocation(id, allocation.user);\n }\n if (allocation.group !== undefined) {\n validateGroupVariantAllocation(id, allocation.group);\n }\n if (allocation.percentile !== undefined) {\n validatePercentileVariantAllocation(id, allocation.percentile);\n }\n if (allocation.seed !== undefined && typeof allocation.seed !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Variant allocation 'seed' must be a string.`);\n }\n}\n\nfunction validateUserVariantAllocation(id: string, UserAllocations: any) {\n if (!Array.isArray(UserAllocations)) {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'user' allocation must be an array.`);\n }\n\n for (const allocation of UserAllocations) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in variant 'user' allocation must be an object.`);\n }\n if (typeof allocation.variant !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. User allocation 'variant' must be a string.`);\n }\n if (!Array.isArray(allocation.users)) {\n throw new TypeError(`Invalid feature flag: ${id}. User allocation 'users' must be an array.`);\n }\n for (const user of allocation.users) {\n if (typeof user !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in user allocation 'users' must be strings.`);\n }\n }\n }\n}\n\nfunction validateGroupVariantAllocation(id: string, groupAllocations: any) {\n if (!Array.isArray(groupAllocations)) {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'group' allocation must be an array.`);\n }\n\n for (const allocation of groupAllocations) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in variant 'group' allocation must be an object.`);\n }\n if (typeof allocation.variant !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Group allocation 'variant' must be a string.`);\n }\n if (!Array.isArray(allocation.groups)) {\n throw new TypeError(`Invalid feature flag: ${id}. Group allocation 'groups' must be an array.`);\n }\n for (const group of allocation.groups) {\n if (typeof group !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in group allocation 'groups' must be strings.`);\n }\n }\n }\n}\n\nfunction validatePercentileVariantAllocation(id: string, percentileAllocations: any) {\n if (!Array.isArray(percentileAllocations)) {\n throw new TypeError(`Invalid feature flag: ${id}. Variant 'percentile' allocation must be an array.`);\n }\n\n for (const allocation of percentileAllocations) {\n if (typeof allocation !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Elements in variant 'percentile' allocation must be an object.`);\n }\n if (typeof allocation.variant !== \"string\") {\n throw new TypeError(`Invalid feature flag: ${id}. Percentile allocation 'variant' must be a string.`);\n }\n if (typeof allocation.from !== \"number\" || allocation.from < 0 || allocation.from > 100) {\n throw new TypeError(`Invalid feature flag: ${id}. Percentile allocation 'from' must be a number between 0 and 100.`);\n }\n if (typeof allocation.to !== \"number\" || allocation.to < 0 || allocation.to > 100) {\n throw new TypeError(`Invalid feature flag: ${id}. Percentile allocation 'to' must be a number between 0 and 100.`);\n }\n }\n}\n// #endregion\n\n// #region Telemetry\nfunction validateTelemetryOptions(id: string, telemetry: any) {\n if (typeof telemetry !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Feature flag 'telemetry' must be an object.`);\n }\n if (telemetry.enabled !== undefined && typeof telemetry.enabled !== \"boolean\") {\n throw new TypeError(`Invalid feature flag: ${id}. Telemetry 'enabled' must be a boolean.`);\n }\n if (telemetry.metadata !== undefined && typeof telemetry.metadata !== \"object\") {\n throw new TypeError(`Invalid feature flag: ${id}. Telemetry 'metadata' must be an object.`);\n }\n}\n// #endregion\n"],"names":[],"mappings":"AAAA;AACA;AAEA;;;AAGG;AACG,SAAU,mBAAmB,CAAC,WAAgB,EAAA;AAChD,IAAA,IAAI,WAAW,KAAK,SAAS,EAAE;AAC3B,QAAA,OAAO;IACX;IACA,IAAI,WAAW,KAAK,IAAI,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;AACzD,QAAA,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC;IAC1D;AACA,IAAA,IAAI,OAAO,WAAW,CAAC,EAAE,KAAK,QAAQ,EAAE;AACpC,QAAA,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC;IAC9D;AAEA,IAAA,IAAI,WAAW,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,WAAW,CAAC,OAAO,KAAK,SAAS,EAA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kEAAA,CAAoE,CAAC;QACxH;AACA,QAAA,IAAI,OAAO,UAAU,CAAC,EAAE,KAAK,QAAQ,IAAI,UAAU,CAAC,EAAE,GAAG,CAAC,IAAI,UAAU,CAAC,EAAE,GAAG,GAAG,EAAE;AAC/E,YAAA,MAAM,IAAI,SAAS,CAAC,yBAAyB,EAAE,CAAA,gEAAA,CAAkE,CAAC;QACtH;IACJ;AACJ;AACA;AAEA;AACA,SAAS,wBAAwB,CAAC,EAAU,EAAE,SAAc,EAAA;AACxD,IAAA,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;AAC/B,QAAA,MAAM,IAAI,SAAS,CAAC,yBAAyB,EAAE,CAAA,6CAAA,CAA+C,CAAC;IACnG;AACA,IAAA,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,SAAS,CAAC,OAAO,KAAK,SAAS,EAAE;AAC3E,QAAA,MAAM,IAAI,SAAS,CAAC,yBAAyB,EAAE,CAAA,wCAAA,CAA0C,CAAC;IAC9F;AACA,IAAA,IAAI,SAAS,CAAC,QAAQ,KAAK,SAAS,IAAI,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE;AAC5E,QAAA,MAAM,IAAI,SAAS,CAAC,yBAAyB,EAAE,CAAA,yCAAA,CAA2C,CAAC;IAC/F;AACJ;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featureEvaluationEvent.js","sources":["../../../src/telemetry/featureEvaluationEvent.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { EvaluationResult, VariantAssignmentReason } from \"../featureManager\";\nimport { EVALUATION_EVENT_VERSION } from \"../version.js\";\n\nconst VERSION = \"Version\";\nconst FEATURE_NAME = \"FeatureName\";\nconst ENABLED = \"Enabled\";\nconst TARGETING_ID = \"TargetingId\";\nconst VARIANT = \"Variant\";\nconst VARIANT_ASSIGNMENT_REASON = \"VariantAssignmentReason\";\nconst DEFAULT_WHEN_ENABLED = \"DefaultWhenEnabled\";\nconst VARIANT_ASSIGNMENT_PERCENTAGE = \"VariantAssignmentPercentage\";\n\nexport function createFeatureEvaluationEventProperties(result: EvaluationResult): any {\n if (result.feature === undefined) {\n return undefined;\n }\n\n const eventProperties = {\n [VERSION]: EVALUATION_EVENT_VERSION,\n [FEATURE_NAME]: result.feature ? result.feature.id : \"\",\n [ENABLED]: result.enabled ? \"True\" : \"False\",\n // Ensure targetingId is string so that it will be placed in customDimensions\n [TARGETING_ID]: result.targetingId ? result.targetingId.toString() : \"\",\n [VARIANT]: result.variant ? result.variant.name : \"\",\n [VARIANT_ASSIGNMENT_REASON]: result.variantAssignmentReason,\n };\n\n if (result.feature.allocation?.default_when_enabled) {\n eventProperties[DEFAULT_WHEN_ENABLED] = result.feature.allocation.default_when_enabled;\n }\n\n if (result.variantAssignmentReason === VariantAssignmentReason.DefaultWhenEnabled) {\n let percentileAllocationPercentage = 0;\n if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {\n for (const percentile of result.feature.allocation.percentile) {\n percentileAllocationPercentage += percentile.to - percentile.from;\n }\n }\n eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = (100 - percentileAllocationPercentage).toString();\n }\n else if (result.variantAssignmentReason === VariantAssignmentReason.Percentile) {\n let percentileAllocationPercentage = 0;\n if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {\n for (const percentile of result.feature.allocation.percentile) {\n if (percentile.variant === result.variant.name) {\n percentileAllocationPercentage += percentile.to - percentile.from;\n }\n }\n }\n eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = percentileAllocationPercentage.toString();\n }\n\n const metadata = result.feature.telemetry?.metadata;\n if (metadata) {\n for (const key in metadata) {\n if (!(key in eventProperties)) {\n eventProperties[key] = metadata[key];\n }\n }\n }\n\n return eventProperties;\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAKA,MAAM,OAAO,GAAG,SAAS
|
|
1
|
+
{"version":3,"file":"featureEvaluationEvent.js","sources":["../../../src/telemetry/featureEvaluationEvent.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { EvaluationResult, VariantAssignmentReason } from \"../featureManager.js\";\nimport { EVALUATION_EVENT_VERSION } from \"../version.js\";\n\nconst VERSION = \"Version\";\nconst FEATURE_NAME = \"FeatureName\";\nconst ENABLED = \"Enabled\";\nconst TARGETING_ID = \"TargetingId\";\nconst VARIANT = \"Variant\";\nconst VARIANT_ASSIGNMENT_REASON = \"VariantAssignmentReason\";\nconst DEFAULT_WHEN_ENABLED = \"DefaultWhenEnabled\";\nconst VARIANT_ASSIGNMENT_PERCENTAGE = \"VariantAssignmentPercentage\";\n\nexport function createFeatureEvaluationEventProperties(result: EvaluationResult): any {\n if (result.feature === undefined) {\n return undefined;\n }\n\n const eventProperties = {\n [VERSION]: EVALUATION_EVENT_VERSION,\n [FEATURE_NAME]: result.feature ? result.feature.id : \"\",\n [ENABLED]: result.enabled ? \"True\" : \"False\",\n // Ensure targetingId is string so that it will be placed in customDimensions\n [TARGETING_ID]: result.targetingId ? result.targetingId.toString() : \"\",\n [VARIANT]: result.variant ? result.variant.name : \"\",\n [VARIANT_ASSIGNMENT_REASON]: result.variantAssignmentReason,\n };\n\n if (result.feature.allocation?.default_when_enabled) {\n eventProperties[DEFAULT_WHEN_ENABLED] = result.feature.allocation.default_when_enabled;\n }\n\n if (result.variantAssignmentReason === VariantAssignmentReason.DefaultWhenEnabled) {\n let percentileAllocationPercentage = 0;\n if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {\n for (const percentile of result.feature.allocation.percentile) {\n percentileAllocationPercentage += percentile.to - percentile.from;\n }\n }\n eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = (100 - percentileAllocationPercentage).toString();\n }\n else if (result.variantAssignmentReason === VariantAssignmentReason.Percentile) {\n let percentileAllocationPercentage = 0;\n if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {\n for (const percentile of result.feature.allocation.percentile) {\n if (percentile.variant === result.variant.name) {\n percentileAllocationPercentage += percentile.to - percentile.from;\n }\n }\n }\n eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = percentileAllocationPercentage.toString();\n }\n\n const metadata = result.feature.telemetry?.metadata;\n if (metadata) {\n for (const key in metadata) {\n if (!(key in eventProperties)) {\n eventProperties[key] = metadata[key];\n }\n }\n }\n\n return eventProperties;\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAKA,MAAM,OAAO,GAAG,SAAS;AACzB,MAAM,YAAY,GAAG,aAAa;AAClC,MAAM,OAAO,GAAG,SAAS;AACzB,MAAM,YAAY,GAAG,aAAa;AAClC,MAAM,OAAO,GAAG,SAAS;AACzB,MAAM,yBAAyB,GAAG,yBAAyB;AAC3D,MAAM,oBAAoB,GAAG,oBAAoB;AACjD,MAAM,6BAA6B,GAAG,6BAA6B;AAE7D,SAAU,sCAAsC,CAAC,MAAwB,EAAA;AAC3E,IAAA,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE;AAC9B,QAAA,OAAO,SAAS;IACpB;AAEA,IAAA,MAAM,eAAe,GAAG;QACpB,CAAC,OAAO,GAAG,wBAAwB;AACnC,QAAA,CAAC,YAAY,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE;AACvD,QAAA,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,OAAO;;AAE5C,QAAA,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE;AACvE,QAAA,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE;AACpD,QAAA,CAAC,yBAAyB,GAAG,MAAM,CAAC,uBAAuB;KAC9D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MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ;IACnD,IAAI,QAAQ,EAAE;AACV,QAAA,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;AACxB,YAAA,IAAI,EAAE,GAAG,IAAI,eAAe,CAAC,EAAE;gBAC3B,eAAe,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC;YACxC;QACJ;IACJ;AAEA,IAAA,OAAO,eAAe;AAC1B;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variant.js","sources":["../../../src/variant/variant.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport class Variant {\n constructor(\n public name: string,\n public configuration: unknown\n ) {}\n}\n"],"names":[],"mappings":"AAAA;AACA;MAEa,OAAO,CAAA;AAEL,IAAA,IAAA;AACA,IAAA,aAAA;IAFX,WAAA,CACW,IAAY,EACZ,aAAsB,EAAA;QADtB,IAAA,CAAA,IAAI,GAAJ,IAAI;QACJ,IAAA,CAAA,aAAa,GAAb,aAAa;IACrB;AACN;;;;"}
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../src/version.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const VERSION = \"2.
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../src/version.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const VERSION = \"2.3.0\";\nexport const EVALUATION_EVENT_VERSION = \"1.0.0\";\n"],"names":[],"mappings":"AAAA;AACA;AAEO,MAAM,OAAO,GAAG;AAChB,MAAM,wBAAwB,GAAG;;;;"}
|
|
@@ -151,46 +151,6 @@ interface TelemetryOptions {
|
|
|
151
151
|
metadata?: Record<string, string>;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
interface IGettable {
|
|
155
|
-
get<T>(key: string): T | undefined;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
interface IFeatureFlagProvider {
|
|
159
|
-
/**
|
|
160
|
-
* Get all feature flags.
|
|
161
|
-
*/
|
|
162
|
-
getFeatureFlags(): Promise<FeatureFlag[]>;
|
|
163
|
-
/**
|
|
164
|
-
* Get a feature flag by name.
|
|
165
|
-
* @param featureName The name of the feature flag.
|
|
166
|
-
*/
|
|
167
|
-
getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined>;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* A feature flag provider that uses a map-like configuration to provide feature flags.
|
|
171
|
-
*/
|
|
172
|
-
declare class ConfigurationMapFeatureFlagProvider implements IFeatureFlagProvider {
|
|
173
|
-
#private;
|
|
174
|
-
constructor(configuration: IGettable);
|
|
175
|
-
getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined>;
|
|
176
|
-
getFeatureFlags(): Promise<FeatureFlag[]>;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* A feature flag provider that uses an object-like configuration to provide feature flags.
|
|
180
|
-
*/
|
|
181
|
-
declare class ConfigurationObjectFeatureFlagProvider implements IFeatureFlagProvider {
|
|
182
|
-
#private;
|
|
183
|
-
constructor(configuration: Record<string, unknown>);
|
|
184
|
-
getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined>;
|
|
185
|
-
getFeatureFlags(): Promise<FeatureFlag[]>;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
declare class Variant {
|
|
189
|
-
name: string;
|
|
190
|
-
configuration: unknown;
|
|
191
|
-
constructor(name: string, configuration: unknown);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
154
|
/**
|
|
195
155
|
* Contextual information that is required to perform a targeting evaluation.
|
|
196
156
|
*/
|
|
@@ -214,6 +174,12 @@ interface ITargetingContextAccessor {
|
|
|
214
174
|
getTargetingContext: () => ITargetingContext | undefined;
|
|
215
175
|
}
|
|
216
176
|
|
|
177
|
+
declare class Variant {
|
|
178
|
+
name: string;
|
|
179
|
+
configuration: unknown;
|
|
180
|
+
constructor(name: string, configuration: unknown);
|
|
181
|
+
}
|
|
182
|
+
|
|
217
183
|
interface IFeatureManager {
|
|
218
184
|
/**
|
|
219
185
|
* Get the list of feature names.
|
|
@@ -232,6 +198,17 @@ interface IFeatureManager {
|
|
|
232
198
|
*/
|
|
233
199
|
getVariant(featureName: string, context: ITargetingContext): Promise<Variant | undefined>;
|
|
234
200
|
}
|
|
201
|
+
interface IFeatureFlagProvider {
|
|
202
|
+
/**
|
|
203
|
+
* Get all feature flags.
|
|
204
|
+
*/
|
|
205
|
+
getFeatureFlags(): Promise<FeatureFlag[]>;
|
|
206
|
+
/**
|
|
207
|
+
* Get a feature flag by name.
|
|
208
|
+
* @param featureName The name of the feature flag.
|
|
209
|
+
*/
|
|
210
|
+
getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined>;
|
|
211
|
+
}
|
|
235
212
|
|
|
236
213
|
declare class FeatureManager implements IFeatureManager {
|
|
237
214
|
#private;
|
|
@@ -290,8 +267,32 @@ declare enum VariantAssignmentReason {
|
|
|
290
267
|
Percentile = "Percentile"
|
|
291
268
|
}
|
|
292
269
|
|
|
270
|
+
interface IGettable {
|
|
271
|
+
get<T>(key: string): T | undefined;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* A feature flag provider that uses a map-like configuration to provide feature flags.
|
|
276
|
+
*/
|
|
277
|
+
declare class ConfigurationMapFeatureFlagProvider implements IFeatureFlagProvider {
|
|
278
|
+
#private;
|
|
279
|
+
constructor(configuration: IGettable);
|
|
280
|
+
getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined>;
|
|
281
|
+
getFeatureFlags(): Promise<FeatureFlag[]>;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* A feature flag provider that uses an object-like configuration to provide feature flags.
|
|
285
|
+
*/
|
|
286
|
+
declare class ConfigurationObjectFeatureFlagProvider implements IFeatureFlagProvider {
|
|
287
|
+
#private;
|
|
288
|
+
constructor(configuration: Record<string, unknown>);
|
|
289
|
+
getFeatureFlag(featureName: string): Promise<FeatureFlag | undefined>;
|
|
290
|
+
getFeatureFlags(): Promise<FeatureFlag[]>;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
293
|
declare function createFeatureEvaluationEventProperties(result: EvaluationResult): any;
|
|
294
294
|
|
|
295
|
-
declare const VERSION = "2.
|
|
295
|
+
declare const VERSION = "2.3.0";
|
|
296
296
|
|
|
297
|
-
export { ConfigurationMapFeatureFlagProvider, ConfigurationObjectFeatureFlagProvider, EvaluationResult, FeatureManager,
|
|
297
|
+
export { ConfigurationMapFeatureFlagProvider, ConfigurationObjectFeatureFlagProvider, EvaluationResult, FeatureManager, VERSION, VariantAssignmentReason, createFeatureEvaluationEventProperties };
|
|
298
|
+
export type { FeatureManagerOptions, IFeatureFilter, IFeatureFilterEvaluationContext, IFeatureFlagProvider, IFeatureManager, ITargetingContext, ITargetingContextAccessor };
|