Skip to content

Commit

Permalink
fix bug (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanliang-ms authored Jan 8, 2025
1 parent add9e26 commit f247557
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 180 deletions.
7 changes: 7 additions & 0 deletions sdk/feature-management/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
"@typescript-eslint"
],
"rules": {
"keyword-spacing": [
"error",
{
"before": true,
"after": true
}
],
"quotes": [
"error",
"double",
Expand Down
183 changes: 74 additions & 109 deletions sdk/feature-management/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions sdk/feature-management/src/featureProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ export class ConfigurationMapFeatureFlagProvider implements IFeatureFlagProvider

async getFeatureFlags(): Promise<FeatureFlag[]> {
const featureConfig = this.#configuration.get<FeatureManagementConfiguration>(FEATURE_MANAGEMENT_KEY);
const featureFlag = featureConfig?.[FEATURE_FLAGS_KEY] ?? [];
validateFeatureFlag(featureFlag);
return featureFlag;
const featureFlags = featureConfig?.[FEATURE_FLAGS_KEY] ?? [];
featureFlags.forEach(featureFlag => {
validateFeatureFlag(featureFlag);
});
return featureFlags;
}
}

Expand All @@ -60,8 +62,10 @@ export class ConfigurationObjectFeatureFlagProvider implements IFeatureFlagProvi
}

async getFeatureFlags(): Promise<FeatureFlag[]> {
const featureFlag = this.#configuration[FEATURE_MANAGEMENT_KEY]?.[FEATURE_FLAGS_KEY] ?? [];
validateFeatureFlag(featureFlag);
return featureFlag;
const featureFlags = this.#configuration[FEATURE_MANAGEMENT_KEY]?.[FEATURE_FLAGS_KEY] ?? [];
featureFlags.forEach(featureFlag => {
validateFeatureFlag(featureFlag);
});
return featureFlags;
}
}
8 changes: 4 additions & 4 deletions sdk/feature-management/src/filter/TargetingFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class TargetingFilter implements IFeatureFilter {

async evaluate(context: TargetingFilterEvaluationContext, appContext?: ITargetingContext): Promise<boolean> {
const { featureName, parameters } = context;
TargetingFilter.#validateParameters(parameters);
TargetingFilter.#validateParameters(featureName, parameters);

if (appContext === undefined) {
throw new Error("The app context is required for targeting filter.");
Expand Down Expand Up @@ -79,15 +79,15 @@ export class TargetingFilter implements IFeatureFilter {
return isTargetedPercentile(appContext?.userId, hint, 0, parameters.Audience.DefaultRolloutPercentage);
}

static #validateParameters(parameters: TargetingFilterParameters): void {
static #validateParameters(featureName: string, parameters: TargetingFilterParameters): void {
if (parameters.Audience.DefaultRolloutPercentage < 0 || parameters.Audience.DefaultRolloutPercentage > 100) {
throw new Error("Audience.DefaultRolloutPercentage must be a number between 0 and 100.");
throw new Error(`Invalid feature flag: ${featureName}. Audience.DefaultRolloutPercentage must be a number between 0 and 100.`);
}
// validate RolloutPercentage for each group
if (parameters.Audience.Groups !== undefined) {
for (const group of parameters.Audience.Groups) {
if (group.RolloutPercentage < 0 || group.RolloutPercentage > 100) {
throw new Error(`RolloutPercentage of group ${group.Name} must be a number between 0 and 100.`);
throw new Error(`Invalid feature flag: ${featureName}. RolloutPercentage of group ${group.Name} must be a number between 0 and 100.`);
}
}
}
Expand Down
Loading

0 comments on commit f247557

Please sign in to comment.