First commit

This commit is contained in:
Noah Spannbauer
2024-05-26 19:08:32 -05:00
commit 32c2da22f5
17 changed files with 9374 additions and 0 deletions

View File

@@ -0,0 +1 @@
export const AZ_APP_CONFIG_OPTIONS = 'AZ_APP_CONFIG_OPTIONS';

View File

@@ -0,0 +1,3 @@
export interface AzAppConfigOptions {
connectionString: string;
}

View File

@@ -0,0 +1,21 @@
import { Module, DynamicModule } from '@nestjs/common';
import { AzAppConfigService } from './az-app-config.service';
import { AzAppConfigOptions } from './az-app-config.interface';
import { AZ_APP_CONFIG_OPTIONS } from './az-app-config.constants';
@Module({})
export class AzAppConfigModule {
static register(options: AzAppConfigOptions): DynamicModule {
return {
module: AzAppConfigModule,
providers: [
{
provide: AZ_APP_CONFIG_OPTIONS,
useValue: options,
},
AzAppConfigService,
],
exports: [AzAppConfigService],
};
}
}

View File

@@ -0,0 +1,34 @@
import { Inject, Injectable } from '@nestjs/common';
import { AzAppConfigOptions } from './az-app-config.interface';
import { FeatureFlag } from './feature-flag.interface';
import { AppConfigurationClient } from '@azure/app-configuration';
import { AZ_APP_CONFIG_OPTIONS } from './az-app-config.constants';
@Injectable()
export class AzAppConfigService {
constructor(
@Inject(AZ_APP_CONFIG_OPTIONS)
private azAppConfigOptions: AzAppConfigOptions,
) { }
async getFeatureFlag(key: string, label: string): Promise<FeatureFlag> {
try {
const client = new AppConfigurationClient(
this.azAppConfigOptions.connectionString,
);
const configurationSetting = await client.getConfigurationSetting({
key: key,
label: label,
});
const featureFlag: FeatureFlag = {
name: configurationSetting.key,
environment: configurationSetting.label,
active: configurationSetting.value,
};
return featureFlag;
} catch (error) {
return error;
}
}
}

View File

@@ -0,0 +1,5 @@
export interface FeatureFlag {
name: string;
environment: string;
active: string;
}

View File

@@ -0,0 +1,2 @@
export * from './azAppConfig/az-app-config.module';
export * from './azAppConfig/az-app-config.service';

View File

@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"outDir": "../../dist/libs/modules"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}