First commit
This commit is contained in:
1
libs/modules/src/azAppConfig/az-app-config.constants.ts
Normal file
1
libs/modules/src/azAppConfig/az-app-config.constants.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const AZ_APP_CONFIG_OPTIONS = 'AZ_APP_CONFIG_OPTIONS';
|
||||
3
libs/modules/src/azAppConfig/az-app-config.interface.ts
Normal file
3
libs/modules/src/azAppConfig/az-app-config.interface.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface AzAppConfigOptions {
|
||||
connectionString: string;
|
||||
}
|
||||
21
libs/modules/src/azAppConfig/az-app-config.module.ts
Normal file
21
libs/modules/src/azAppConfig/az-app-config.module.ts
Normal 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],
|
||||
};
|
||||
}
|
||||
}
|
||||
34
libs/modules/src/azAppConfig/az-app-config.service.ts
Normal file
34
libs/modules/src/azAppConfig/az-app-config.service.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
5
libs/modules/src/azAppConfig/feature-flag.interface.ts
Normal file
5
libs/modules/src/azAppConfig/feature-flag.interface.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface FeatureFlag {
|
||||
name: string;
|
||||
environment: string;
|
||||
active: string;
|
||||
}
|
||||
2
libs/modules/src/index.ts
Normal file
2
libs/modules/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './azAppConfig/az-app-config.module';
|
||||
export * from './azAppConfig/az-app-config.service';
|
||||
9
libs/modules/tsconfig.lib.json
Normal file
9
libs/modules/tsconfig.lib.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"outDir": "../../dist/libs/modules"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user