Base class providing common functionality for all API clients.

Hierarchy

  • ApiClient

Constructors

Properties

#oauthTokenResponse: null | OAuthTokenResponse = null

Stores the OAuth token response

apiPrefix: undefined | string
authentication: undefined | Authentication
baseUrl: string
cache: undefined | Cache
customFetch: undefined | ((input, init?) => Promise<Response>)

Type declaration

debug: undefined | boolean
defaultLocale: undefined | string
logger: undefined | {
    debug: undefined | LogMethod;
    error: undefined | LogMethod;
    http: undefined | LogMethod;
    info: undefined | LogMethod;
    silly: undefined | LogMethod;
    verbose: undefined | LogMethod;
    warn: undefined | LogMethod;
}

Type declaration

serializer: undefined | Serializer

Methods

  • 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.

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

    Parameters

    • input: RequestInfo | URL

      RequestInfo

    • Optional init: RequestInit

      RequestInit

    Returns Promise<FetchReturn>

    a response wrapped in a promise

  • Fetch the OAuth token from the BaseUrl

    Parameters

    • __namedParameters: {
          clientId: string;
          clientSecret: string;
      }
      • clientId: string
      • clientSecret: string

    Returns Promise<OAuthTokenResponse>

    Param0

    the Client ID

    Param1

    the Client secret

  • 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.

  • 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

Generated using TypeDoc