ApiClient
Defined in: ApiClient.ts:18
Base class providing common functionality for all API clients.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ApiClient(baseUrl, options?): ApiClient;Defined in: ApiClient.ts:74
Parameters
Section titled “Parameters”baseUrl
Section titled “baseUrl”string
The base URL for all API requests. BaseUrl
options?
Section titled “options?”Optional configuration options. ApiClientOptions
Returns
Section titled “Returns”ApiClient
Properties
Section titled “Properties”apiPrefix
Section titled “apiPrefix”apiPrefix: string | undefined;Defined in: ApiClient.ts:32
authentication
Section titled “authentication”authentication: Authentication | undefined;Defined in: ApiClient.ts:42
ApiClientOptions.authentication
baseUrl
Section titled “baseUrl”baseUrl: string;Defined in: ApiClient.ts:27
cache: | Cache | undefined;Defined in: ApiClient.ts:52
customFetch
Section titled “customFetch”customFetch: | ((input, init?) => Promise<Response>) | undefined;Defined in: ApiClient.ts:37
debug: boolean | undefined;Defined in: ApiClient.ts:67
defaultLocale
Section titled “defaultLocale”defaultLocale: string | undefined;Defined in: ApiClient.ts:47
ApiClientOptions.defaultLocale
logger
Section titled “logger”logger: | { debug?: LogMethod; error?: LogMethod; http?: LogMethod; info?: LogMethod; silly?: LogMethod; verbose?: LogMethod; warn?: LogMethod;} | undefined;Defined in: ApiClient.ts:62
serializer
Section titled “serializer”serializer: | Serializer | undefined;Defined in: ApiClient.ts:57
Methods
Section titled “Methods”addAuthorizationHeader()
Section titled “addAuthorizationHeader()”addAuthorizationHeader(options): Promise<RequestInit>;Defined in: ApiClient.ts:220
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
Section titled “Parameters”options
Section titled “options”RequestInit | undefined
The RequestInit options to which the authorization header should be added.
Returns
Section titled “Returns”Promise<RequestInit>
The updated RequestInit options with the authorization header, if applicable.
fetch()
Section titled “fetch()”fetch(input, init?): Promise<FetchReturn>;Defined in: ApiClient.ts:106
Uses customFetch if it is set, otherwise uses the default fetch
Parameters
Section titled “Parameters”RequestInfo | URL
RequestInfo
RequestInit
RequestInit
Returns
Section titled “Returns”a response wrapped in a promise
getAccessToken()
Section titled “getAccessToken()”protected getAccessToken(__namedParameters): Promise<OAuthTokenResponse>;Defined in: ApiClient.ts:138
Fetch the OAuth token from the BaseUrl
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”Returns
Section titled “Returns”Params
Section titled “Params”params - The credentials for getting an OAuth token. OAuthCredentials
getCachedResponse()
Section titled “getCachedResponse()”getCachedResponse<T>(cacheKey): Promise< | NonNullable<Awaited<T>>| null>;Defined in: ApiClient.ts:310
Retrieves a cached response from the cache.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”cacheKey
Section titled “cacheKey”string
The cache key to use for retrieving the cached response.
Returns
Section titled “Returns”Promise<
| NonNullable<Awaited<T>>
| null>
A promise wrapping the cached response as a generic type.
log(level, message): void;Defined in: ApiClient.ts:295
Calls the appropriate logger method based on level
Parameters
Section titled “Parameters”level based on npm log levels
message
Section titled “message”string
the message to log
Returns
Section titled “Returns”void