ApiClient
Base class providing common functionality for all API clients.
See
Constructors
new ApiClient()
Parameters
• baseUrl: string
The base URL for all API requests. BaseUrl
• options?: ApiClientOptions
Optional configuration options. ApiClientOptions
Returns
Source
ApiClient.ts:74
Properties
#oauthTokenResponse
Stores the OAuth token response
Source
ApiClient.ts:22
apiPrefix
ApiClientOptions.apiPrefix
Source
ApiClient.ts:32
authentication
ApiClientOptions.authentication
Source
ApiClient.ts:42
baseUrl
Source
ApiClient.ts:27
cache
ApiClientOptions.cache
Source
ApiClient.ts:52
customFetch
ApiClientOptions.customFetch
Source
ApiClient.ts:37
debug
ApiClientOptions.debug
Source
ApiClient.ts:67
defaultLocale
ApiClientOptions.defaultLocale
Source
ApiClient.ts:47
logger
ApiClientOptions.logger
Source
ApiClient.ts:62
serializer
ApiClientOptions.serializer
Source
ApiClient.ts:57
Methods
addAuthorizationHeader()
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()
Uses customFetch if it is set, otherwise uses the default fetch
Parameters
• input: RequestInfo
| URL
RequestInfo
• init?: RequestInit
RequestInit
Returns
a response wrapped in a promise
Source
ApiClient.ts:106
getAccessToken()
Fetch the OAuth token from the BaseUrl
Parameters
• __namedParameters: OAuthCredentials
Returns
Params
params - The credentials for getting an OAuth token. OAuthCredentials
Source
ApiClient.ts:138
getCachedResponse()
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()
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