next-drupal / NextDrupalBase

Class: NextDrupalBase

Defined in: packages/next-drupal/src/next-drupal-base.ts:36

The base class for NextDrupal clients.

Extended by

Constructors

new NextDrupalBase()

new NextDrupalBase(baseUrl, options): NextDrupalBase

Defined in: packages/next-drupal/src/next-drupal-base.ts:71

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?

optional accessToken: AccessToken

Defined in: packages/next-drupal/src/next-drupal-base.ts:37


baseUrl

baseUrl: string

Defined in: packages/next-drupal/src/next-drupal-base.ts:39


fetcher()?

optional fetcher: (input, init?) => Promise\<Response>

Defined in: packages/next-drupal/src/next-drupal-base.ts:41

MDN Reference

Parameters

input

RequestInfo | URL

init?

RequestInit

Returns

Promise\<Response>


frontPage

frontPage: string

Defined in: packages/next-drupal/src/next-drupal-base.ts:43


isDebugEnabled

isDebugEnabled: boolean

Defined in: packages/next-drupal/src/next-drupal-base.ts:45


logger

logger: Logger

Defined in: packages/next-drupal/src/next-drupal-base.ts:47


withAuth

withAuth: boolean

Defined in: packages/next-drupal/src/next-drupal-base.ts:49

Accessors

apiPrefix

Get Signature

get apiPrefix(): string

Defined in: packages/next-drupal/src/next-drupal-base.ts:109

Returns

string

Set Signature

set apiPrefix(apiPrefix): void

Defined in: packages/next-drupal/src/next-drupal-base.ts:102

Parameters

apiPrefix

string

Returns

void


auth

Get Signature

get auth(): NextDrupalAuth

Defined in: packages/next-drupal/src/next-drupal-base.ts:158

Returns

NextDrupalAuth

Set Signature

set auth(auth): void

Defined in: packages/next-drupal/src/next-drupal-base.ts:113

Parameters

auth

NextDrupalAuth

Returns

void


headers

Get Signature

get headers(): HeadersInit

Defined in: packages/next-drupal/src/next-drupal-base.ts:166

Returns

HeadersInit

Set Signature

set headers(headers): void

Defined in: packages/next-drupal/src/next-drupal-base.ts:162

Parameters

headers

HeadersInit

Returns

void


token

Get Signature

get token(): AccessToken

Defined in: packages/next-drupal/src/next-drupal-base.ts:175

Returns

AccessToken

Set Signature

set token(token): void

Defined in: packages/next-drupal/src/next-drupal-base.ts:170

Parameters

token

AccessToken

Returns

void

Methods

addLocalePrefix()

addLocalePrefix(path, options): string

Defined in: packages/next-drupal/src/next-drupal-base.ts:391

Adds a locale prefix to the given path.

Parameters

path

string

The path.

options

The options for adding the locale prefix.

defaultLocale

string

The default locale.

locale

string

The locale.

Returns

string

The path with the locale prefix.


buildEndpoint()

buildEndpoint(options): Promise\<string>

Defined in: packages/next-drupal/src/next-drupal-base.ts:304

Builds an endpoint URL with the given options.

Parameters

options

The options for building the endpoint.

locale

string = ""

The locale.

path

string = ""

The path.

searchParams

EndpointSearchParams

The search parameters.

Returns

Promise\<string>

The constructed endpoint URL.


buildUrl()

buildUrl(path, searchParams?): URL

Defined in: packages/next-drupal/src/next-drupal-base.ts:276

Builds a URL with the given path and search parameters.

Parameters

path

string

The URL path.

searchParams?

EndpointSearchParams

The search parameters.

Returns

URL

The constructed URL.


constructPathFromSegment()

constructPathFromSegment(segment, options): string

Defined in: packages/next-drupal/src/next-drupal-base.ts:335

Constructs a path from the given segment and options.

Parameters

segment

The path segment.

string | string[]

options

The options for constructing the path.

defaultLocale

string

The default locale.

locale

string

The locale.

pathPrefix

string

The path prefix.

Returns

string

The constructed path.


debug()

debug(message): void

Defined in: packages/next-drupal/src/next-drupal-base.ts:538

Logs a debug message if debug mode is enabled.

Parameters

message

any

The debug message.

Returns

void


fetch()

fetch(input, init): Promise\<Response>

Defined in: packages/next-drupal/src/next-drupal-base.ts:186

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.


getAccessToken()

getAccessToken(clientIdSecret?): Promise\<AccessToken>

Defined in: packages/next-drupal/src/next-drupal-base.ts:415

Gets an access token using the provided client ID and secret.

Parameters

clientIdSecret?

NextDrupalAuthClientIdSecret

The client ID and secret.

Returns

Promise\<AccessToken>

The access token.


getAuthorizationHeader()

getAuthorizationHeader(auth): Promise\<string>

Defined in: packages/next-drupal/src/next-drupal-base.ts:234

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

Parameters

auth

NextDrupalAuth

The auth configuration.

Returns

Promise\<string>

The authorization header value.


getErrorsFromResponse()

getErrorsFromResponse(response): Promise\<string | JsonApiError[]>

Defined in: packages/next-drupal/src/next-drupal-base.ts:562

Extracts errors from the fetch response.

Parameters

response

Response

The fetch response.

Returns

Promise\<string | JsonApiError[]>

The extracted errors.


throwIfJsonErrors()

throwIfJsonErrors(response, messagePrefix): Promise\<void>

Defined in: packages/next-drupal/src/next-drupal-base.ts:549

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>

Throws

The JSON:API errors.


validateDraftUrl()

validateDraftUrl(searchParams): Promise\<Response>

Defined in: packages/next-drupal/src/next-drupal-base.ts:500

Validates the draft URL using the provided search parameters.

Parameters

searchParams

URLSearchParams

The search parameters.

Returns

Promise\<Response>

The validation response.