Skip to content

Toggles Builder

Overview

The feature flags builder is a legacy implementation of toggles 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 toggles implementation. The main purpose of this plugin is to aggregate all the feature toggles (kill switches) and expose them to the platform and invsy SDK. The platform as well as the feature library can use these toggles to update accordingly.

shell
npm install --save @investec/plugins-toggles-builder

Implementation Guide

The plugin exposes 3 function to get all the feature toggles and use them in the platform. The function uses the code in the following snippet:

ts
export function getToggles(){
  return fetch('/proxy/toggles',{
    credentials: 'include',
    method: 'POST',
    headers: {'Content-Type': 'application/json','Access-Control-Allow-Origin':'*'},
    body: JSON.stringify({ CategoryName: 'IO.Core' }),
  }).then(res => res.json()).catch(err => console.error(err))
}


export function mapToggles(toggleList:string[]){
  toggleList.map(toggle => {
    for (let i = 0; i < togglesMapper.length; i++) {
      const toggleElement = togglesMapper[i];
      if(toggleElement.toggle === toggle){
        toggleElement.active = false
        break
      }
    }
  })

  return togglesMapper
}

export function removeToggledFeatures(featureList:IFeatureApps[]){
  togglesMapper.forEach(value => {
    for (let i = 0; i < featureList.length; i++) {
      const feature = featureList[i];
      if(value.name === feature.value.name && !value.active){
        featureList.splice(i,1)
        break
      }
    }
  })

  return featureList
}

These functions can be used in multiple places in the platform to disable features or by feature teams themselves to know when a specific feature is enabled or disabled.

Add feature toggles

Simply add the feature key name as per the feature registry in the togglesMapper object in the toggles-builder.ts file.

ts
export const togglesMapper = [
  {name:'private-vault', active: true, toggle:'de3a332326751840d15932449d5f0676e465082e3175b546c87c6d28bab4b147'},
  {name:'global-analytics-migration', active: true, toggle:'83b8d4a33c625a94369bf23308cc02bf81333b9907aaa836bc5af9bf5b3c1a5f'}
]

INFO

Please ensure that the name of the toggle is in accordance with the feature's key name in the feature registry.