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:74

Properties

#oauthTokenResponse

private #oauthTokenResponse: null | OAuthTokenResponse = null;

Stores the OAuth token response

Source

ApiClient.ts:22


apiPrefix

apiPrefix: undefined | string;

ApiClientOptions.apiPrefix

Source

ApiClient.ts:32


authentication

authentication: undefined | Authentication;

ApiClientOptions.authentication

Source

ApiClient.ts:42


baseUrl

baseUrl: string;

BaseUrl

Source

ApiClient.ts:27


cache

cache: undefined | Cache;

ApiClientOptions.cache

Source

ApiClient.ts:52


customFetch

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

ApiClientOptions.customFetch

Source

ApiClient.ts:37


debug

debug: undefined | boolean;

ApiClientOptions.debug

Source

ApiClient.ts:67


defaultLocale

defaultLocale: undefined | string;

ApiClientOptions.defaultLocale

Source

ApiClient.ts:47


logger

logger: undefined | object;

ApiClientOptions.logger

Source

ApiClient.ts:62


serializer

serializer: undefined | Serializer;

ApiClientOptions.serializer

Source

ApiClient.ts:57

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:220


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:106


getAccessToken()

protected getAccessToken(__namedParameters): Promise<OAuthTokenResponse>

Fetch the OAuth token from the BaseUrl

Parameters

__namedParameters: OAuthCredentials

Returns

Promise<OAuthTokenResponse>

Params

params - The credentials for getting an OAuth token. OAuthCredentials

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:310


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:295