Skip to content

ApiClient

Base class providing common functionality for all API clients.

See

ApiClientOptions and BaseUrl

Constructors

new ApiClient()

new ApiClient(baseUrl, options?): ApiClient

Parameters

baseUrl: string

The base URL for all API requests. BaseUrl

options?: ApiClientOptions

Optional configuration options. ApiClientOptions

Returns

ApiClient

Source

ApiClient.ts:73

Properties

#oauthTokenResponse

private #oauthTokenResponse: null | OAuthTokenResponse = null;

Stores the OAuth token response

Source

ApiClient.ts:21


apiPrefix

apiPrefix: undefined | string;

ApiClientOptions.apiPrefix

Source

ApiClient.ts:31


authentication

authentication: undefined | Authentication;

ApiClientOptions.authentication

Source

ApiClient.ts:41


baseUrl

baseUrl: string;

BaseUrl

Source

ApiClient.ts:26


cache

cache: undefined | Cache;

ApiClientOptions.cache

Source

ApiClient.ts:51


customFetch

customFetch: undefined | (input, init?) => Promise<Response>;

ApiClientOptions.customFetch

Source

ApiClient.ts:36


debug

debug: undefined | boolean;

ApiClientOptions.debug

Source

ApiClient.ts:66


defaultLocale

defaultLocale: undefined | string;

ApiClientOptions.defaultLocale

Source

ApiClient.ts:46


logger

logger: undefined | object;

ApiClientOptions.logger

Source

ApiClient.ts:61


serializer

serializer: undefined | Serializer;

ApiClientOptions.serializer

Source

ApiClient.ts:56

Methods

addAuthorizationHeader()

addAuthorizationHeader(options): Promise<RequestInit>

Adds an authorization header to the provided RequestInit options if authentication of type “Basic” is configured. If the authentication type is “OAuth”, it will fetch a new access token or use the stored access token if it exists and is still valid. if the authentication type is “Custom”, it will use the provided value.

Parameters

options: undefined | RequestInit

The RequestInit options to which the authorization header should be added.

Returns

Promise<RequestInit>

The updated RequestInit options with the authorization header, if applicable.

Source

ApiClient.ts:203


fetch()

fetch(input, init?): Promise<FetchReturn>

Uses customFetch if it is set, otherwise uses the default fetch

Parameters

input: RequestInfo | URL

RequestInfo

init?: RequestInit

RequestInit

Returns

Promise<FetchReturn>

a response wrapped in a promise

Source

ApiClient.ts:105


getAccessToken()

protected getAccessToken(__namedParameters): Promise<OAuthTokenResponse>

Fetch the OAuth token from the BaseUrl

Parameters

__namedParameters

__namedParameters.clientId: string

__namedParameters.clientSecret: string

Returns

Promise<OAuthTokenResponse>

Param0

the Client ID

Param1

the Client secret

Source

ApiClient.ts:138


getCachedResponse()

getCachedResponse<T>(cacheKey): Promise<null | NonNullable<Awaited<T>>>

Retrieves a cached response from the cache.

Type parameters

T

Parameters

cacheKey: string

The cache key to use for retrieving the cached response.

Returns

Promise<null | NonNullable<Awaited<T>>>

A promise wrapping the cached response as a generic type.

Source

ApiClient.ts:290


log()

log(level, message): void

Calls the appropriate logger method based on level

Parameters

level: LogLevels

level based on npm log levels

message: string

the message to log

Returns

void

Source

ApiClient.ts:275