Skip to content

Profiles builder

@investec/plugins-profiles-builder retrieves customer profiles and publishes them through reactive state for downstream consumers such as portfolio loading and profile selectors.

Package

sh
npm install --save @investec/plugins-profiles-builder

What it owns

  • fetching ZA private-bank profiles and intermediary profiles
  • normalising those records to include name and id
  • legacy typed collections through updateAppState
  • grouped client-type profile state through profilesList

Public contract

The package exports:

  • profilesBuilder
  • getProfiles()
  • profile and auth-response types

profilesBuilder contains:

  • activeEnvironment
  • updateAppState
  • authResponse
  • clearState
  • profilesList

Integration pattern

ts
import {
  getProfiles,
  profilesBuilder,
} from '@investec/plugins-profiles-builder';

profilesBuilder.authResponse.next(authResponse);

profilesBuilder.updateAppState.subscribe((profiles) => {
  // Legacy typed profile buckets.
});

profilesBuilder.profilesList.subscribe((profileList) => {
  // Client-type grouped profile data.
});

getProfiles();

Returned state

The plugin exposes two views of the data.

updateAppState

Legacy grouped buckets:

ts
{
  PrivateBankZA: IZaProfile[];
  IntermediaryBanking: IIfaProfile[];
}

profilesList

Client-type grouped data for newer selectors:

ts
{
  data: [
    {
      clientType: 'private-client',
      profilesList: [{ PrivateBankZA: [...] }],
      selectedProfile: [{ PrivateBankZA: selectedProfile }]
    }
  ]
}

Runtime behaviour

getProfiles() checks auth flags and calls:

  • /edge/base/za/pb/profiles
  • /edge/cxt-ifi/api/v2/Intermediary

depending on which profile families the authenticated user has available.

How consumers extend it

Consumers normally extend this package by owning profile selection and app-state projection after the shared fetch is complete.

Typical patterns are:

  • subscribe to profilesList and map it into a profile selector UI;
  • mirror the selected profile into app-owned state;
  • pass the chosen profile onward to portfolio and feature-eligibility logic;
  • reset or rebuild downstream state when clearState is triggered.

Change the package when a new profile family, new upstream endpoint, or new shared grouped state shape is required.

Extension example: derive a selected profile in consumer state

ts
import {
  getProfiles,
  profilesBuilder,
  type IProfilesList,
} from '@investec/plugins-profiles-builder';

type SelectedProfileState = {
  clientType: string;
  profileKey: string;
  profile: unknown;
};

let selectedProfileState: SelectedProfileState | undefined;

profilesBuilder.authResponse.next(authResponse);

profilesBuilder.profilesList.subscribe((profileList: IProfilesList) => {
  const privateClientEntry = profileList.data.find(
    (item) => item.clientType === 'private-client'
  );

  if (!privateClientEntry || privateClientEntry.selectedProfile.length === 0) {
    return;
  }

  const wrappedProfile = privateClientEntry.selectedProfile[0];
  const profileKey = Object.keys(wrappedProfile)[0];

  selectedProfileState = {
    clientType: privateClientEntry.clientType,
    profileKey,
    profile: wrappedProfile[profileKey],
  };
});

getProfiles();

Consumer notes

  • getProfiles() depends on profilesBuilder.authResponse being set first.
  • clearState.next() resets the cached auth response, profile buckets, and the grouped profilesList.
  • The package keeps adding profile families into profilesList rather than replacing the whole object every time, which is useful for multi-client-type consumers.