Skip to content

Instantly share code, notes, and snippets.

@ashinzekene
Created July 17, 2020 06:57
Show Gist options
  • Save ashinzekene/da87b8ce3a26fd6e16ba17348d0f42fb to your computer and use it in GitHub Desktop.
Save ashinzekene/da87b8ce3a26fd6e16ba17348d0f42fb to your computer and use it in GitHub Desktop.
import { AppConfigurationClient, ConfigurationSettingId } from "@azure/app-configuration";
import FeatureContext from "../Contracts/FeatureFlags/FeatureContext";
import { FeatureName } from "./FeatureNames";
import { IAppConfiguration } from "../Contracts/FeatureFlags/IAppConfiguration";
export class AppConfiguration implements IAppConfiguration {
private connectionString: string;
private environment: string
private client: AppConfigurationClient;
constructor(connectionString: string, environment: string) {
this.connectionString = connectionString;
this.environment = environment;
this.client = new AppConfigurationClient(this.connectionString);
}
getFeature(featureName: FeatureName): Q.Promise<FeatureContext> {
const environment = this.environment;
const featureConfig = this.getFeatureFlagOptions(featureName);
return (this.client.getConfigurationSetting(featureConfig)
.then(function (result) {
if (result && result.value) {
return JSON.parse(result.value)
}
})
.catch(function (error) {
if (error && error.statusCode === 404) {
throw new Error(`Could not find config with key ${featureName} on env: ${environment}`);
}
throw error;
}) as unknown as Q.Promise<FeatureContext>)
}
private getFeatureFlagOptions(key: FeatureName): ConfigurationSettingId {
return {
key: `.appconfig.featureflag/${key}`,
label: this.environment,
}
}
}
{
"compileOnSave": true,
"compilerOptions": {
"baseUrl": "Client",
"composite": true,
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": true,
"module": "amd",
"moduleResolution": "node",
"noEmitHelpers": true,
"noImplicitAny": true,
"noImplicitThis": true,
"outDir": "Output/Content/Scripts",
"paths": {
"*": [
"*"
]
},
"removeComments": false,
"rootDir": "Client",
"sourceMap": true,
"strictBindCallApply": true,
"target": "es5",
"types": []
},
"plugins": [{"name": "typescript-tslint-plugin"}],
"include": [
"Client/**/*",
"Definitions/**/*"
]
}
let timer = setTimeout(() => {
this._publishVerificationResultNotification(
result,
clientValidationNotification,
timer
);
timer = this._pollApplicationStatus(result, clientValidationNotification);
}, validationRetryInterval);
// Here's a completely unrelated file where `setTimeout` returns `NodeJS.Timeout` intead of `number`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment