Portfolio builder plugin
Overview
The portfolio builder plugin is a service that is used to build the various portfolios for the WPaaS platform based on the client context (AuthResponse). The main function of the plugin is to expose every portfolio call based on the clients context, aggregate them into a single object and expose them via the SDK. Additionally, the plugin calculates the net-worth that is being used in the private client dashboard.
npm install --save @investec/plugins-portfolio-builderEnvironment
The plugin makes use of environments and an object that is exposed to the platform for other params to be injected into it. The object is defined as follows:
export const portfolioBuilder = {activeEnvironment : 'staging',updateAppState : new ReplaySubject<IPortfolioEntity>(1),currentPortfolioState: new ReplaySubject<IPortfolioEntity>(1),authResponse: new ReplaySubject<IAuthResponse>(1),clearState: new ReplaySubject<void>(1)}
portfolioBuilder.updateAppState.subscribe((data:IPortfolioEntity) => currentPortfolioState = data)
portfolioBuilder.authResponse.subscribe((data:IAuthResponse) => authResponse = data)
portfolioBuilder.clearState.subscribe(() => {
currentPortfolioState = {}
authResponse = {}
});
let authResponse:IAuthResponse = {}
let currentPortfolioState: IPortfolioEntity = {}INFO
The exposed portfolio object portfolioBuilder is also used to send back data as it receives new data to and from the platform via events updateAppState : new ReplaySubject<IPortfolioEntity>(1).
Implementation Guide
The plugin exposes a portfolio object with all the different functions inside of it.
Adding a new portfolio
Add a new portfolio property to the object:
getPrivateBankZAPortfolio: function (currency: string, profileId?: string) {
return new Promise((resolve,reject) => {
portfolio.getPortfolio('za', '/pbv2/portfolio', currency, profileId).then((res: {
PrivateBanker: any,
PortfolioAssets: number,
PortfolioAvailableBalance: number,
PrivateBankAccounts: Array<{ PocketBalance?: number }>
}) => {
//save in the store
portfolio.addPortfolio({
currency: currency,
portfolios: { PrivateBankZA: res },
callResultMap: [{ flag: 'PrivateBankZA', result: true }]
})
portfolio.UpdateContactData({
type: 'privateBanker',
contactData: res.PrivateBanker
})
resolve(res);
}).catch(err => {
portfolio.addFailedPortfolio({ flag: 'PrivateBankZA', result: false })
reject(err)
})
})
},INFO
Based on where the portfolio is hosted , make use of the getPortfolio function for api.secure.investec.com api and the getAzurePortfolio function for the azure hosted portfolios.
Now add your new portfolio to the getAllPortfoliosStream function in the switch case statement:
INFO
REMEMBER to add it to the correct authResponse flag and follow the pattern of the other portfolios.
Object.keys(authRes).forEach(value => {
switch (value) {
case 'PrivateBankZA':
if (authRes[value] === true) {
apiCount++
portfolio.getPrivateBankZAPortfolio(target.data.__msg.currency, target.data.__msg.selectedProfile !== undefined ? target.data.__msg.selectedProfile.ProfileId : '').then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'PrivateBankCI':
if (authRes[value] === true) {
apiCount++
portfolio.getPrivateBankCIPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'PrivateBankMU':
if (authRes[value] === true) {
apiCount++
portfolio.getPrivateBankMUPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'WealthAndInvestmentZA':
if (authRes[value] === true) {
apiCount++
portfolio.getWealthAndInvestmentZAPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'WealthAndInvestmentUK':
if (authRes[value] === true) {
apiCount++
portfolio.getWealthAndInvestmentUKPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'WealthAndInvestmentGU':
if (authRes[value] === true) {
apiCount++
portfolio.getWealthAndInvestmentGUPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'WealthAndInvestmentClick':
if (authRes[value] === true) {
apiCount++
portfolio.getWealthAndInvestmentClickPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'WealthAndInvestmentCI':
if (authRes[value] === true) {
apiCount++
portfolio.getWealthAndInvestmentCIPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
case 'PrivateBankUK':
if (authRes[value] === true) {
apiCount++;
portfolio.getPrivateBankUKPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(err => {
promiseResolver()
})
}
break;
case 'Pfm':
if (authRes[value] === true) {
try {
apiCount++;
portfolio.getAllNonInvestecAccounts(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(err => {
promiseResolver()
})
} catch (error) {
promiseResolver()
}
}
break;
case 'ShareSchemes':
if (authRes[value] === true) {
try {
apiCount++;
portfolio.getShareSchemesData().then(() => {
this.UpdatePortfolioExcludes([{flag:'ShareSchemes',result:true}])
promiseResolver()
}).catch(err => {
promiseResolver()
})
} catch (error) {
promiseResolver()
}
}
break;
case 'ClientProfileFlags':
try {
if(authRes.ClientProfileFlags?.UKExecutiveClientPlatform){
apiCount++
portfolio.getUkExecClientPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
} catch (error) {
promiseResolver()
}
break;
case 'Life':
if (authRes[value] === true) {
apiCount += 2;
try {
portfolio.getLifeAdvisorContactData().then(() => {
promiseResolver()
}).catch(err => {
promiseResolver()
})
} catch (error) {
promiseResolver()
}
try {
portfolio.getLifePolicyOverviewData().then(() => {
promiseResolver()
}).catch(err => {
promiseResolver()
})
} catch (error) {
promiseResolver()
}
}
break;
case 'Ibsag':
if (authRes[value] === true) {
apiCount++
portfolio.getIbsagPortfolio(target.data.__msg.currency).then(() => {
promiseResolver()
}).catch(() => {
promiseResolver()
})
}
break
}
})WARNING
Changes to the portfolio builder will have a direct impact on the platform and multiple features that use the config via the SDK. Please ensure that you have tested the changes thoroughly before deploying.