Features/15 add azure app configuration #16

Merged
noahspannbauer merged 3 commits from features/15-add-azure-app-configuration into main 2024-05-28 13:35:34 -04:00
11 changed files with 136 additions and 24 deletions
Showing only changes of commit bea4e7f04b - Show all commits

View File

@@ -26,7 +26,7 @@
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@noahspan/noahspan-modules": "^0.0.1",
"@noahspan/noahspan-modules": "^0.1.1",
"@schematics/angular": "^17.3.7",
"dotenv": "^16.4.5",
"reflect-metadata": "0.1.13",

View File

@@ -1,15 +1,34 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, Query } from '@nestjs/common';
import { AppService } from './app.service';
import { AzAppConfigService } from '@noahspan/noahspan-modules';
import { AppConfigService, AuthService } from '@noahspan/noahspan-modules';
import { FeatureFlagValue } from '@azure/app-configuration';
@Controller()
export class AppController {
constructor(private readonly azAppConfigService: AzAppConfigService) {}
constructor(
private readonly appConfigService: AppConfigService,
private readonly authService: AuthService
) {}
@Get('featureFlag')
getFeatureFlag(key: string, label: string): string {
const featureFlag = this.azAppConfigService.getFeatureFlag(key, label);
console.log(process.env.AZ_APP_CONFIG_CONNECTION_STRING);
return 'blah';
async getFeatureFlag(@Query() query: any): Promise<FeatureFlagValue[]> {
try {
const token: string = await this.authService.getToken(
'client_credentials',
process.env.CLIENT_ID,
process.env.CLIENT_SECRET,
'https://azconfig.io'
);
const featureFlags: FeatureFlagValue[] =
await this.appConfigService.getFeatureFlags(
token,
`${query.key}`,
query.label
);
return featureFlags;
} catch (error) {
console.log(error);
}
}
}

View File

@@ -1,12 +1,15 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AzAppConfigModule } from '@noahspan/noahspan-modules';
import { AppConfigModule, AuthModule } from '@noahspan/noahspan-modules';
@Module({
imports: [
AzAppConfigModule.register({
connectionString: process.env.AZ_APP_CONFIG_CONNECTION_STRING
AppConfigModule.register({
url: process.env.APP_CONFIG_URL
}),
AuthModule.register({
tenantId: process.env.TENANT_ID
})
],
controllers: [AppController],

View File

@@ -1,15 +1,11 @@
import { Route, Routes } from 'react-router-dom';
import Flights from './components/flights/Flights';
import Logbook from './components/logbook/Logbook';
import Checklists from './components/checklists/Checklists';
import Pilots from './components/pilots/Pilots';
const App: React.FC<unknown> = () => {
return (
<Routes>
<Route path="/" element={<Flights />} />
<Route path="logbook" element={<Logbook />} />
<Route path="checklists" element={<Checklists />} />
<Route path="pilots" element={<Pilots />} />
</Routes>
);

View File

@@ -0,0 +1,5 @@
import { Context, createContext } from 'react';
import { IAppContextProps } from './IAppContextProps';
export const AppContext: Context<IAppContextProps> =
createContext<IAppContextProps>({} as IAppContextProps);

View File

@@ -0,0 +1,28 @@
import { IAppContextProviderProps } from './IAppContextProviderProps';
import { IAppContextState } from './IAppContextState';
const AppContextProvider: React.FC<IAppContextProviderProps> = (
props: IAppContextProviderProps
) => {
const intialState: IAppContextState = {
featureFlags: []
};
const [state, dispatch] = useReducer(reducer, intialState);
const contextValue = (IAppContextProps = useMemo(() => {
return (
{
state,
dispatch
},
[state, dispatch]
);
}));
return (
<AppContext.Provider value={contextValue}>
{props.children}
</AppContext.Provider>
);
};
export default AppContextProvider;

View File

@@ -0,0 +1,4 @@
export interface IAppContextProps {
state: IAppContextState;
dispatch: React.Dispatch<Action>;
}

View File

@@ -0,0 +1,3 @@
export interface IAppContextProviderProps {
children: React.ReactNode;
}

View File

@@ -0,0 +1,3 @@
export interface IAppContextState {
featureFlags: unknown[];
}

View File

@@ -0,0 +1,20 @@
import { IAppContextState } from './IAppContextState';
export type Action = { type: 'SET_FEATURE_FLAGS'; payload: unknown[] };
export const reducer = (
state: IAppContextState,
action: Action
): IAppContextState => {
switch (action.type) {
case 'SET_FEATURE_FLAGS': {
return {
...state,
featureFlags: action.payload
};
}
default: {
return state;
}
}
};

49
package-lock.json generated
View File

@@ -37,7 +37,7 @@
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@noahspan/noahspan-modules": "^0.0.1",
"@noahspan/noahspan-modules": "^0.1.1",
"@schematics/angular": "^17.3.7",
"dotenv": "^16.4.5",
"reflect-metadata": "0.1.13",
@@ -4402,14 +4402,15 @@
"link": true
},
"node_modules/@noahspan/noahspan-modules": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.0.1.tgz",
"integrity": "sha512-VTJg2dGY/6q+6NxtngimxENPrKh/jRDmyR8fAhnZovE7+cgqZ2JjImrZAFqcNPZolheFLwLqM2A4O4oU35MHOQ==",
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@noahspan/noahspan-modules/-/noahspan-modules-0.1.1.tgz",
"integrity": "sha512-9rljhDl2AZeIMWZgTR59pFvC7N3i+j332vsfNnHMAh5ApaNjgmWZ6La/8MkGJmcZ8pxT9cqXDaH27A8YWKbJBQ==",
"dependencies": {
"@azure/app-configuration": "^1.6.0",
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"axios": "^1.7.2",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
}
@@ -6971,8 +6972,7 @@
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"dev": true
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/autoprefixer": {
"version": "10.4.19",
@@ -7011,6 +7011,16 @@
"postcss": "^8.1.0"
}
},
"node_modules/axios": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz",
"integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/babel-jest": {
"version": "29.7.0",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz",
@@ -7728,7 +7738,6 @@
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dev": true,
"dependencies": {
"delayed-stream": "~1.0.0"
},
@@ -8018,7 +8027,6 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"dev": true,
"engines": {
"node": ">=0.4.0"
}
@@ -8956,6 +8964,25 @@
"integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==",
"dev": true
},
"node_modules/follow-redirects": {
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/foreground-child": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz",
@@ -9025,7 +9052,6 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dev": true,
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
@@ -12318,6 +12344,11 @@
"node": ">= 0.10"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/punycode": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",