Skip to content

Commit 78b731e

Browse files
author
cwanjau
committed
code improvements
1 parent 0ac1e1c commit 78b731e

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

libraries/azure-app-configuration-importer/src/internal/parsers/defaultConfigurationSettingsConverter.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
SetConfigurationSettingParam,
66
featureFlagPrefix,
77
featureFlagContentType,
8-
ConfigurationSettingParam,
98
SecretReferenceValue
109
} from "@azure/app-configuration";
1110
import { SourceOptions } from "../../importOptions";
@@ -40,7 +39,7 @@ export class DefaultConfigurationSettingsConverter implements ConfigurationSetti
4039
SetConfigurationSettingParam<string | MsFeatureFlagValue>
4140
>();
4241

43-
let featureFlagsConfigSettings = new Array<ConfigurationSettingParam>();
42+
let featureFlagsConfigSettings = new Array<SetConfigurationSettingParam<string>>();
4443
let foundMsFmSchema = false;
4544
let foundDotnetFmSchema = false;
4645
let dotnetFmSchemaKeyWord = "";
@@ -188,8 +187,8 @@ class FeatureFlagConfigurationSettingsConverter implements ConfigurationSettings
188187
Convert(
189188
config: object,
190189
options: SourceOptions
191-
): ConfigurationSettingParam[] {
192-
const settings = new Array<ConfigurationSettingParam>();
190+
): SetConfigurationSettingParam<string>[] {
191+
const settings = new Array<SetConfigurationSettingParam<string>>();
193192
const featureFlags = new Array<MsFeatureFlagValue>();
194193

195194
if (this.dotnetFmSchemaKeyWord) {
@@ -256,8 +255,7 @@ class FeatureFlagConfigurationSettingsConverter implements ConfigurationSettings
256255
tags: options.tags
257256
};
258257

259-
const serializedSetting: ConfigurationSettingParam = serializeFeatureFlagToConfigurationSettingParam(setting);
260-
258+
const serializedSetting: SetConfigurationSettingParam<string> = serializeFeatureFlagToConfigurationSettingParam(setting);
261259
settings.push(serializedSetting);
262260
}
263261

libraries/azure-app-configuration-importer/src/internal/utils.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import {
66
SetConfigurationSettingParam,
77
FeatureFlagValue,
88
featureFlagContentType,
9-
SecretReferenceValue,
10-
ConfigurationSettingParam,
11-
featureFlagPrefix} from "@azure/app-configuration";
9+
SecretReferenceValue,
10+
featureFlagPrefix } from "@azure/app-configuration";
1211
import { isEmpty, isEqual } from "lodash";
13-
import { Tags, FeatureFlagClientFilters } from "../models";
12+
import { Tags, FeatureFlagClientFilters, JsonFeatureFlagValue } from "../models";
1413
import { SourceOptions } from "../importOptions";
1514
import { ConfigurationFormat, ConfigurationProfile } from "../enums";
1615
import { ArgumentError, ArgumentNullError } from "../errors";
@@ -173,22 +172,24 @@ function toFeatureFlagValue(value: string): FeatureFlagValue {
173172
};
174173
}
175174

176-
export function serializeFeatureFlagToConfigurationSettingParam(featureFlag: SetConfigurationSettingParam<MsFeatureFlagValue>): ConfigurationSettingParam {
175+
export function serializeFeatureFlagToConfigurationSettingParam(featureFlag: SetConfigurationSettingParam<MsFeatureFlagValue>): SetConfigurationSettingParam<string> {
177176
if (!featureFlag.value) {
178177
throw new TypeError(`FeatureFlag has an unexpected value - ${featureFlag.value}`);
179178
}
180179
let key = featureFlag.key;
180+
181181
if (typeof featureFlag.key === "string" && !featureFlag.key.startsWith(featureFlagPrefix)) {
182182
key = featureFlagPrefix + featureFlag.key;
183183
}
184-
const jsonFeatureFlagValue: MsFeatureFlagValue = {
184+
185+
const jsonFeatureFlagValue: JsonFeatureFlagValue = {
185186
id: featureFlag.value.id ?? key.replace(featureFlagPrefix, ""),
186187
enabled: featureFlag.value.enabled,
187188
description: featureFlag.value.description,
188189
conditions: {
189-
clientFilters: featureFlag.value.conditions?.clientFilters
190+
client_filters: featureFlag.value.conditions?.clientFilters
190191
},
191-
displayName: featureFlag.value.displayName,
192+
display_name: featureFlag.value.displayName,
192193
allocation: featureFlag.value.allocation,
193194
variants: featureFlag.value.variants,
194195
telemetry: featureFlag.value.telemetry

libraries/azure-app-configuration-importer/src/models.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@ export interface JsonSecretReferenceValue {
1313
uri: string;
1414
}
1515

16+
/**
17+
* @internal
18+
*/
19+
export type JsonFeatureFlagValue = {
20+
conditions: {
21+
client_filters: { name: string; parameters?: Record<string, unknown> }[];
22+
};
23+
description?: string;
24+
enabled: boolean;
25+
id?: string;
26+
display_name?: string;
27+
allocation?: {
28+
user?: { variant: string; users: string[] }[];
29+
group?: { variant: string; groups: string[] }[];
30+
default_when_enabled?: string;
31+
default_when_disabled?: string;
32+
percentile?: { variant: string; from: number; to: number }[];
33+
seed?: string;
34+
};
35+
variants?: { name: string; configuration_value?: string | number | object | boolean; status_override?: string }[];
36+
telemetry?: { enabled?: boolean; metadata?: object };
37+
};
38+
1639
/**
1740
* @internal
1841
*/

0 commit comments

Comments
 (0)