Feature Flags Builder
Overview
The feature flags builder is a legacy implementation of feature flags that was configured in the Digital gateway. This is only used to support the legacy implementation. The plugin will be used in the future of the new feature flag implementation.
shell
npm install --save @investec/plugins-feature-flags-builderImplementation Guide
The plugin exposes a single function to get all the feature flags. The function uses the code in the following snippet:
ts
import { IAuthResponse } from '../types/auth-response.interface';
interface features{
Code : string,
ExclusiveHide: boolean,
Id : number
}
export async function gatherResponse(response:any) {
const { headers } = response;
const contentType = headers.get('content-type') || '';
if (contentType.includes('application/json')) {
return JSON.stringify(await response.json());
} else if (contentType.includes('application/text')) {
return response.text();
} else if (contentType.includes('text/html')) {
return response.text();
} else {
return response.text();
}
}
export async function getUserFeatures(authRes: IAuthResponse){
const fetchArray = [];
let featureObj = {alwaysTrue: true}
fetchArray.push(fetch('/proxy/feature',{headers:{'WPaaS': 'critical'}}));
if(authRes?.PrivateBankZA){
fetchArray.push(fetch('/proxy/za/pb/feature',{headers:{'WPaaS': 'critical'}}));
fetchArray.push(fetch('/proxy/za/wi/feature',{headers:{'WPaaS': 'critical'}}));
}
if(authRes?.PrivateBankUK){
fetchArray.push(fetch('/proxy/uk/pb/feature',{headers:{'WPaaS': 'critical'}}));
fetchArray.push(fetch('/proxy/uk/pb/feature/dynamic',{headers:{'WPaaS': 'critical'}}));
}
const responses = await Promise.all(fetchArray);
const resList: Array<any> = [];
responses.forEach((value:any) => {
if(value.message !== 'error'){
resList.push(gatherResponse(value))
}
})
const results = await Promise.all(resList);
results.forEach(value => {
if(!(value as string).includes('Error')){
(JSON.parse(value) as Array<features>).forEach(feature => {
if(!feature.ExclusiveHide){
if (Object.keys(featureObj).find(x => x === feature.Code) === undefined) {
featureObj = {...featureObj, ...{[feature.Code] : true}}
}
}
})
}
})
return featureObj
}These functions are responsible for making the api calls and combining all the results in a single object that is loaded in the platform and exposed via the SKD.