Class

ApiManager

ApiManager()

The ApiManager holds configurations and instances of ApiInterfaces. It updates the ApiInterfaces with tokens that are used for authorisation.

Constructor

# new ApiManager()

View Source services/ApiManager.tsx, line 14

Classes

ApiManager

Members

# static getTemplatedScope

Basic common function for templating API scopes to the correct environment

View Source services/ApiManager.tsx, line 243

Methods

# static addInterface(apiInterface)

Adds an interface to the list of interfaces to load when this class is initialised.

Parameters:
Name Type Description
apiInterface

ApiInterface derivative class (not an instance) to add to load when an ApiManager is created

View Source services/ApiManager.tsx, line 54

# static getTemplatedScope(scope, env) → {string}

Basic common function for templating API scopes to the correct environment

Parameters:
Name Type Description
scope string

The untemplated scope

env string

The environment string to insert into the template

View Source services/ApiManager.tsx, line 179

The new templated scope

string

# static templateScopes(scopes, data)

Takes an array of scopes and substitutes in template values. Returns new scopes array.

Parameters:
Name Type Description
scopes

array of scopes to be templated.

data

object whose keys are the value to replace, and the value is what to put in place.

View Source services/ApiManager.tsx, line 38

Populated map of original scopes, matched to their templated scopes.

# addInterface(apiInterface)

Helper function for adding an ApiInterface to the ApiManager's library of available APIs. Any API that is required will need to be added to the library prior to being usable.

APIs should be added in the base App.js, in a place where it will be run BEFORE the app is rendered. This is important as the OIDC library queries the ApiManagers library of registered APIs to ask for the correct OIDC scopes.

     import { ApiManager } from '@jcu/spark'

     ...

     ApiManager.addInterface(TestInterface)

     function App() {
     ...
Parameters:
Name Type Description
apiInterface ApiInterface

The ApiInterface class to add to library

View Source services/ApiManager.tsx, line 107

# checkLoadedInterfaces()

Compare the loaded interfaces against the list of APIs that have had configs loaded

View Source services/ApiManager.tsx, line 156

# getApiInterface(apiInterface, version) → {ApiInterface|undefined}

Load an API interface from the library by name and version. Name and version need to be defined (and matching) in two locations: SPA config and the interface class.

Handles instantiating and configuring API interface based on the information defined in the API section of the SPA config.

Parameters:
Name Type Default Description
apiInterface string

The name of the API

version string latest

The version of the API

View Source services/ApiManager.tsx, line 129

The requested ApiInterface object or undefined if it doesn't exist

ApiInterface | undefined

# updateHeader(header, value)

Provide a new header to propagate to ApiInterface instances

Parameters:
Name Type Description
header

Header to set

value

if not null, sets the header, otherwise clears it.

View Source services/ApiManager.tsx, line 74