Class NextDrupalBase

The base class for NextDrupal clients.

Hierarchy (View Summary)

Constructors

  • Instantiates a new NextDrupalBase.

    const client = new NextDrupalBase(baseUrl)

    Parameters

    • baseUrl: string

      The baseUrl of your Drupal site. Do not add the /jsonapi suffix.

    • options: NextDrupalBaseOptions = {}

      Options for NextDrupalBase.

    Returns NextDrupalBase

Properties

accessToken?: AccessToken
baseUrl: string
fetcher?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>

Type declaration

    • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

frontPage: string
isDebugEnabled: boolean
logger: Logger
withAuth: boolean

Accessors

  • get apiPrefix(): string
  • Returns string

  • set apiPrefix(apiPrefix: string): void
  • Parameters

    • apiPrefix: string

    Returns void

  • get headers(): HeadersInit
  • Returns HeadersInit

  • set headers(headers: HeadersInit): void
  • Parameters

    • headers: HeadersInit

    Returns void

  • get token(): AccessToken
  • Returns AccessToken

  • set token(token: AccessToken): void
  • Parameters

    Returns void

Methods

  • Adds a locale prefix to the given path.

    Parameters

    • path: string

      The path.

    • options: { defaultLocale?: string; locale?: string } = {}

      The options for adding the locale prefix.

      • OptionaldefaultLocale?: string

        The default locale.

      • Optionallocale?: string

        The locale.

    Returns string

    The path with the locale prefix.

  • Builds an endpoint URL with the given options.

    Parameters

    • options: { locale?: string; path?: string; searchParams?: EndpointSearchParams } = {}

      The options for building the endpoint.

      • Optionallocale?: string

        The locale.

      • Optionalpath?: string

        The path.

      • OptionalsearchParams?: EndpointSearchParams

        The search parameters.

    Returns Promise<string>

    The constructed endpoint URL.

  • Builds a URL with the given path and search parameters.

    Parameters

    Returns URL

    The constructed URL.

  • Constructs a path from the given segment and options.

    Parameters

    • segment: string | string[]

      The path segment.

    • options: { defaultLocale?: string; locale?: string; pathPrefix?: string } = {}

      The options for constructing the path.

      • OptionaldefaultLocale?: string

        The default locale.

      • Optionallocale?: string

        The locale.

      • OptionalpathPrefix?: string

        The path prefix.

    Returns string

    The constructed path.

  • Logs a debug message if debug mode is enabled.

    Parameters

    • message: any

      The debug message.

    Returns void

  • Fetches a resource from the given input URL or path.

    Parameters

    • input: RequestInfo

      The input URL or path.

    • init: FetchOptions = {}

      The fetch options.

    Returns Promise<Response>

    The fetch response.

  • Gets the authorization header value based on the provided auth configuration.

    Parameters

    Returns Promise<string>

    The authorization header value.

  • Extracts errors from the fetch response.

    Parameters

    • response: Response

      The fetch response.

    Returns Promise<string | JsonApiError[]>

    The extracted errors.

  • Throws an error if the response contains JSON:API errors.

    Parameters

    • response: Response

      The fetch response.

    • messagePrefix: string = ""

      The error message prefix.

    Returns Promise<void>

    The JSON:API errors.

  • Validates the draft URL using the provided search parameters.

    Parameters

    • searchParams: URLSearchParams

      The search parameters.

    Returns Promise<Response>

    The validation response.