|
1 | 1 | // Copyright (c) Microsoft Corporation. |
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | | -// Converted from https://github.com/Azure/AppConfiguration/blob/main/docs/FeatureManagement/FeatureFlag.v1.1.0.schema.json |
| 4 | +// Converted from: |
| 5 | +// https://github.com/Azure/AppConfiguration/blob/6e544296a5607f922a423df165f60801717c7800/docs/FeatureManagement/FeatureFlag.v2.0.0.schema.json |
5 | 6 |
|
| 7 | +/** |
| 8 | + * A feature flag is a named property that can be toggled to enable or disable some feature of an application. |
| 9 | + */ |
6 | 10 | export interface FeatureFlag { |
7 | 11 | /** |
8 | 12 | * An ID used to uniquely identify and reference the feature. |
9 | 13 | */ |
10 | | - id: string |
11 | | - |
| 14 | + id: string; |
12 | 15 | /** |
13 | 16 | * A description of the feature. |
14 | 17 | */ |
15 | | - description?: string |
16 | | - |
| 18 | + description?: string; |
17 | 19 | /** |
18 | 20 | * A display name for the feature to use for display rather than the ID. |
19 | 21 | */ |
20 | | - display_name?: string |
21 | | - |
| 22 | + display_name?: string; |
22 | 23 | /** |
23 | 24 | * 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. |
24 | 25 | */ |
25 | | - enabled: boolean |
| 26 | + enabled?: boolean; |
| 27 | + /** |
| 28 | + * The declaration of conditions used to dynamically enable the feature. |
| 29 | + */ |
| 30 | + conditions?: FeatureEnablementConditions; |
| 31 | + /** |
| 32 | + * 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. |
| 33 | + */ |
| 34 | + variants?: Variant[]; |
| 35 | + /** |
| 36 | + * Determines how variants should be allocated for the feature to various users. |
| 37 | + */ |
| 38 | + allocation?: VariantAllocation; |
| 39 | + /** |
| 40 | + * The declaration of options used to configure telemetry for this feature. |
| 41 | + */ |
| 42 | + telemetry?: TelemetryOptions |
| 43 | +} |
26 | 44 |
|
| 45 | +/** |
| 46 | +* The declaration of conditions used to dynamically enable the feature |
| 47 | +*/ |
| 48 | +interface FeatureEnablementConditions { |
27 | 49 | /** |
28 | | - * The declaration of conditions used to dynamically enable features. |
| 50 | + * Determines whether any or all registered client filters must be evaluated as true for the feature to be considered enabled. |
29 | 51 | */ |
30 | | - conditions?: FeatureEnablementConditions |
| 52 | + requirement_type?: RequirementType; |
| 53 | + /** |
| 54 | + * Filters that must run on the client and be evaluated as true for the feature to be considered enabled. |
| 55 | + */ |
| 56 | + client_filters?: ClientFilter[]; |
31 | 57 | } |
32 | 58 |
|
33 | | -export enum RequirementType { |
34 | | - Any = "Any", |
35 | | - All = "All" |
| 59 | +export type RequirementType = "Any" | "All"; |
| 60 | + |
| 61 | +interface ClientFilter { |
| 62 | + /** |
| 63 | + * The name used to refer to a client filter. |
| 64 | + */ |
| 65 | + name: string; |
| 66 | + /** |
| 67 | + * Parameters for a given client filter. A client filter can require any set of parameters of any type. |
| 68 | + */ |
| 69 | + parameters?: Record<string, unknown>; |
36 | 70 | } |
37 | 71 |
|
38 | | -export interface FeatureEnablementConditions { |
| 72 | +interface Variant { |
39 | 73 | /** |
40 | | - * Determines whether any or all registered client filters must be evaluated as true for the feature to be considered enabled. |
| 74 | + * The name used to refer to a feature variant. |
41 | 75 | */ |
42 | | - requirement_type?: RequirementType |
| 76 | + name: string; |
| 77 | + /** |
| 78 | + * The configuration value for this feature variant. |
| 79 | + */ |
| 80 | + configuration_value?: unknown; |
| 81 | + /** |
| 82 | + * The path to a configuration section used as the configuration value for this feature variant. |
| 83 | + */ |
| 84 | + configuration_reference?: string; |
| 85 | + /** |
| 86 | + * Overrides the enabled state of the feature if the given variant is assigned. Does not override the state if value is None. |
| 87 | + */ |
| 88 | + status_override?: "None" | "Enabled" | "Disabled"; |
| 89 | +} |
43 | 90 |
|
| 91 | +/** |
| 92 | +* Determines how variants should be allocated for the feature to various users. |
| 93 | +*/ |
| 94 | +interface VariantAllocation { |
44 | 95 | /** |
45 | | - * Filters that must run on the client and be evaluated as true for the feature to be considered enabled. |
| 96 | + * Specifies which variant should be used when the feature is considered disabled. |
| 97 | + */ |
| 98 | + default_when_disabled?: string; |
| 99 | + /** |
| 100 | + * Specifies which variant should be used when the feature is considered enabled and no other allocation rules are applicable. |
| 101 | + */ |
| 102 | + default_when_enabled?: string; |
| 103 | + /** |
| 104 | + * A list of objects, each containing a variant name and list of users for whom that variant should be used. |
| 105 | + */ |
| 106 | + user?: UserAllocation[]; |
| 107 | + /** |
| 108 | + * A list of objects, each containing a variant name and list of groups for which that variant should be used. |
| 109 | + */ |
| 110 | + group?: GroupAllocation[]; |
| 111 | + /** |
| 112 | + * A list of objects, each containing a variant name and percentage range for which that variant should be used. |
| 113 | + */ |
| 114 | + percentile?: PercentileAllocation[] |
| 115 | + /** |
| 116 | + * 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. |
| 117 | + */ |
| 118 | + seed?: string; |
| 119 | +} |
| 120 | + |
| 121 | +interface UserAllocation { |
| 122 | + /** |
| 123 | + * The name of the variant to use if the user allocation matches the current user. |
| 124 | + */ |
| 125 | + variant: string; |
| 126 | + /** |
| 127 | + * Collection of users where if any match the current user, the variant specified in the user allocation is used. |
| 128 | + */ |
| 129 | + users: string[]; |
| 130 | +} |
| 131 | + |
| 132 | +interface GroupAllocation { |
| 133 | + /** |
| 134 | + * The name of the variant to use if the group allocation matches a group the current user is in. |
| 135 | + */ |
| 136 | + variant: string; |
| 137 | + /** |
| 138 | + * Collection of groups where if the current user is in any of these groups, the variant specified in the group allocation is used. |
| 139 | + */ |
| 140 | + groups: string[]; |
| 141 | +} |
| 142 | + |
| 143 | +interface PercentileAllocation { |
| 144 | + /** |
| 145 | + * The name of the variant to use if the calculated percentile for the current user falls in the provided range. |
| 146 | + */ |
| 147 | + variant: string; |
| 148 | + /** |
| 149 | + * The lower end of the percentage range for which this variant will be used. |
| 150 | + */ |
| 151 | + from: number; |
| 152 | + /** |
| 153 | + * The upper end of the percentage range for which this variant will be used. |
46 | 154 | */ |
47 | | - client_filters?: ClientFilter[] |
| 155 | + to: number; |
48 | 156 | } |
49 | 157 |
|
50 | | -export interface ClientFilter { |
| 158 | +/** |
| 159 | +* The declaration of options used to configure telemetry for this feature. |
| 160 | +*/ |
| 161 | +interface TelemetryOptions { |
51 | 162 | /** |
52 | | - * The name used to refer to and require a client filter. |
| 163 | + * Indicates if telemetry is enabled. |
53 | 164 | */ |
54 | | - name: string |
| 165 | + enabled?: boolean; |
55 | 166 | /** |
56 | | - * Custom parameters for a given client filter. A client filter can require any set of parameters of any type. |
| 167 | + * A container for metadata that should be bundled with flag telemetry. |
57 | 168 | */ |
58 | | - parameters?: unknown |
| 169 | + metadata?: Record<string, string>; |
59 | 170 | } |
60 | 171 |
|
61 | 172 | // Feature Management Section fed into feature manager. |
|
0 commit comments