[core/api] add name validation in registerFeatureFlag

This commit is contained in:
Bilawal Hameed
2020-03-27 11:52:14 +01:00
parent 24f987b29b
commit 9aaad5d660
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ class FeatureFlagsImpl implements FeatureFlagsApi {
if (!name.match(/^[a-z]+[a-z0-9-]+$/)) {
errors.push(
'The `name` argument must start with a lowercase letter and only contain lowercase letters, numbers and hyphens.' +
'The `name` argument must start with a lowercase letter and only contain lowercase letters, numbers and hyphens. ' +
'Examples: feature-flag-one, alpha, release-2020',
);
}
+10
View File
@@ -21,6 +21,7 @@ import {
RouteOptions,
FeatureFlagName,
} from './types';
import { FeatureFlags } from '../app/FeatureFlags';
import { Widget } from '../widgetView/types';
export type PluginConfig = {
@@ -76,6 +77,7 @@ export default class Plugin {
return [];
}
const pluginId = this.getId();
const outputs = new Array<PluginOutput>();
this.config.register({
@@ -94,6 +96,14 @@ export default class Plugin {
},
featureFlags: {
registerFeatureFlag(name) {
const errors = FeatureFlags.checkFeatureFlagNameErrors(name);
if (errors.length > 0) {
throw new Error(
`Failed to register '${name}' feature flag in '${pluginId}' plugin: ${errors[0]}`,
);
}
outputs.push({ type: 'feature-flag', name });
},
},