next-drupal / NextDrupalPages

Class: NextDrupalPages

Defined in: packages/next-drupal/src/next-drupal-pages.ts:34

The NextDrupalPages class extends the NextDrupal class and provides methods for interacting with a Drupal backend in the context of Next.js pages.

Extends

Constructors

new NextDrupalPages()

new NextDrupalPages(baseUrl, options): NextDrupalPages

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

Instantiates a new NextDrupalPages.

const client = new NextDrupalPages(baseUrl)

Parameters

baseUrl

string

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

options

DrupalClientOptions = {}

Options for the client. See Experiment_DrupalClientOptions.

Returns

NextDrupalPages

Overrides

NextDrupal.constructor

Properties

accessToken?

optional accessToken: AccessToken

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

Inherited from

NextDrupal.accessToken


baseUrl

baseUrl: string

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

Inherited from

NextDrupal.baseUrl


cache?

optional cache: DataCache

Defined in: packages/next-drupal/src/next-drupal.ts:52

Inherited from

NextDrupal.cache


deserializer

deserializer: JsonDeserializer

Defined in: packages/next-drupal/src/next-drupal.ts:54

Inherited from

NextDrupal.deserializer


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>

Inherited from

NextDrupal.fetcher


frontPage

frontPage: string

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

Inherited from

NextDrupal.frontPage


getPathsFromContext()

getPathsFromContext: (types, context, options?) => Promise\<(string | { locale: string; params: { slug: string[]; }; })[]>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:273

Gets static paths from the context.

Parameters

types

The types of the resources.

string | string[]

context

GetStaticPathsContext

The static paths context.

options?

object & JsonApiWithAuthOption

Options for the request.

Returns

Promise\<(string | { locale: string; params: { slug: string[]; }; })[]>

The fetched static paths.


isDebugEnabled

isDebugEnabled: boolean

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

Inherited from

NextDrupal.isDebugEnabled


logger

logger: Logger

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

Inherited from

NextDrupal.logger


throwJsonApiErrors

throwJsonApiErrors: boolean

Defined in: packages/next-drupal/src/next-drupal.ts:56

Inherited from

NextDrupal.throwJsonApiErrors


useDefaultEndpoints

useDefaultEndpoints: boolean

Defined in: packages/next-drupal/src/next-drupal.ts:58

Inherited from

NextDrupal.useDefaultEndpoints


withAuth

withAuth: boolean

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

Inherited from

NextDrupal.withAuth

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

Inherited from

NextDrupal.apiPrefix


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

Inherited from

NextDrupal.auth


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

Inherited from

NextDrupal.headers


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

Inherited from

NextDrupal.token

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.

Inherited from

NextDrupal.addLocalePrefix


buildEndpoint()

buildEndpoint(params): Promise\<string>

Defined in: packages/next-drupal/src/next-drupal.ts:709

Builds an endpoint URL for the specified parameters.

Parameters

params

object & object = {}

The parameters for the endpoint.

Returns

Promise\<string>

The built endpoint URL.

Inherited from

NextDrupal.buildEndpoint


buildMenuTree()

buildMenuTree(links, parent): DrupalMenuTree

Defined in: packages/next-drupal/src/next-drupal-pages.ts:84

Parameters

DrupalMenuItem[]

parent

string = ""

Returns

DrupalMenuTree


buildStaticPathsFromResources()

buildStaticPathsFromResources(resources, options?): object[]

Defined in: packages/next-drupal/src/next-drupal-pages.ts:358

Builds static paths from resources.

Parameters

resources

object[]

The resources.

options?

Options for the request.

locale

string

pathPrefix

string

Returns

object[]

The built static paths.


buildStaticPathsParamsFromPaths()

buildStaticPathsParamsFromPaths(paths, options?): object[]

Defined in: packages/next-drupal/src/next-drupal-pages.ts:387

Builds static paths parameters from paths.

Parameters

paths

string[]

The paths.

options?

Options for the request.

locale

string

pathPrefix

string

Returns

object[]

The built static paths parameters.


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.

Inherited from

NextDrupal.buildUrl


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.

Inherited from

NextDrupal.constructPathFromSegment


createFileResource()

createFileResource\<T>(type, body, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal.ts:150

Creates a new file resource for the specified media type.

Type Parameters

T = DrupalFile

Parameters

type

string

The type of the media.

body

JsonApiCreateFileResourceBody

The body of the file resource.

options?

JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<T>

The created file resource.

Inherited from

NextDrupal.createFileResource


createResource()

createResource\<T>(type, body, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal.ts:101

Creates a new resource of the specified type.

Type Parameters

T extends JsonApiResource

Parameters

type

string

The type of the resource.

body

JsonApiCreateResourceBody

The body of the resource.

options?

JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<T>

The created resource.

Inherited from

NextDrupal.createResource


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

Inherited from

NextDrupal.debug


deleteResource()

deleteResource(type, uuid, options?): Promise\<boolean>

Defined in: packages/next-drupal/src/next-drupal.ts:256

Deletes an existing resource of the specified type.

Parameters

type

string

The type of the resource.

uuid

string

The UUID of the resource.

options?

JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<boolean>

True if the resource was deleted, false otherwise.

Inherited from

NextDrupal.deleteResource


deserialize()

deserialize(body, options?): TJsonaModel | TJsonaModel[]

Defined in: packages/next-drupal/src/next-drupal.ts:947

Deserializes the response body.

Parameters

body

any

The response body.

options?

any

Options for deserialization.

Returns

TJsonaModel | TJsonaModel[]

The deserialized response body.

Inherited from

NextDrupal.deserialize


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.

Inherited from

NextDrupal.fetch


fetchResourceEndpoint()

fetchResourceEndpoint(type, locale?): Promise\<URL>

Defined in: packages/next-drupal/src/next-drupal.ts:753

Fetches the endpoint URL for the specified resource type.

Parameters

type

string

The type of the resource.

locale?

string

The locale for the request.

Returns

Promise\<URL>

The fetched endpoint URL.

Inherited from

NextDrupal.fetchResourceEndpoint


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.

Inherited from

NextDrupal.getAccessToken


getAuthFromContextAndOptions()

getAuthFromContextAndOptions(context, options): boolean | NextDrupalAuth

Defined in: packages/next-drupal/src/next-drupal-pages.ts:521

Gets the authentication configuration from the context and options.

Parameters

context

GetStaticPropsContext

The static props context.

options

JsonApiWithAuthOption

Options for the request.

Returns

boolean | NextDrupalAuth

The authentication configuration.


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.

Inherited from

NextDrupal.getAuthorizationHeader


getEntryForResourceType()

getEntryForResourceType(resourceType, locale?): Promise\<string>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:73

Gets the entry point for a given resource type.

Parameters

resourceType

string

The resource type.

locale?

string

The locale.

Returns

Promise\<string>

The entry point URL.


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.

Inherited from

NextDrupal.getErrorsFromResponse


getIndex()

getIndex(locale?, options?): Promise\<JsonApiResponse>

Defined in: packages/next-drupal/src/next-drupal.ts:678

Fetches the JSON:API index.

Parameters

locale?

string

The locale for the request.

options?

JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<JsonApiResponse>

The JSON:API index.

Inherited from

NextDrupal.getIndex


getMenu()

getMenu\<T>(menuName, options?): Promise\<{ items: T[]; tree: T[]; }>

Defined in: packages/next-drupal/src/next-drupal.ts:783

Fetches a menu by its name.

Type Parameters

T = DrupalMenuItem

Parameters

string

The name of the menu.

options?

JsonApiOptions & JsonApiWithCacheOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<{ items: T[]; tree: T[]; }>

The fetched menu.

Inherited from

NextDrupal.getMenu


getPathFromContext()

getPathFromContext(context, options?): string

Defined in: packages/next-drupal/src/next-drupal-pages.ts:260

Gets the path from the context.

Parameters

context

GetStaticPropsContext

The static props context.

options?

Options for the request.

pathPrefix

string

Returns

string

The constructed path.


getResource()

getResource\<T>(type, uuid, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal.ts:298

Fetches a resource of the specified type by its UUID.

Type Parameters

T extends JsonApiResource

Parameters

type

string

The type of the resource.

uuid

string

The UUID of the resource.

options?

JsonApiOptions & JsonApiWithCacheOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<T>

The fetched resource.

Inherited from

NextDrupal.getResource


getResourceByPath()

getResourceByPath\<T>(path, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal.ts:361

Fetches a resource of the specified type by its path.

Type Parameters

T extends JsonApiResource

Parameters

path

string

The path of the resource.

options?

object & JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<T>

The fetched resource.

Inherited from

NextDrupal.getResourceByPath


getResourceCollection()

getResourceCollection\<T>(type, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal.ts:478

Fetches a collection of resources of the specified type.

Type Parameters

T = JsonApiResource[]

Parameters

type

string

The type of the resources.

options?

object & JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<T>

The fetched collection of resources.

Inherited from

NextDrupal.getResourceCollection


getResourceCollectionFromContext()

getResourceCollectionFromContext\<T>(type, context, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:187

Gets a collection of resources from the context.

Type Parameters

T = JsonApiResource[]

Parameters

type

string

The type of the resources.

context

GetStaticPropsContext

The static props context.

options?

object & JsonApiOptions

Options for the request.

Returns

Promise\<T>

The fetched collection of resources.


getResourceCollectionPathSegments()

getResourceCollectionPathSegments(types, options?): Promise\<object[]>

Defined in: packages/next-drupal/src/next-drupal.ts:523

Fetches path segments for a collection of resources of the specified types.

Parameters

types

The types of the resources.

string | string[]

options?

object & JsonApiWithAuthOption & JsonApiWithNextFetchOptions & ({ locales: string[]; defaultLocale: string; } | { locales?: undefined; defaultLocale?: never; })

Options for the request.

Returns

Promise\<object[]>

The fetched path segments.

Inherited from

NextDrupal.getResourceCollectionPathSegments


getResourceFromContext()

getResourceFromContext\<T>(input, context, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:96

Gets a resource from the context.

Type Parameters

T extends JsonApiResource

Parameters

input

The input path or translated path.

string | DrupalTranslatedPath

context

GetStaticPropsContext

The static props context.

options?

object & JsonApiOptions

Options for the request.

Returns

Promise\<T>

The fetched resource.


getSearchIndex()

getSearchIndex\<T>(name, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal.ts:905

Fetches a search index by its name.

Type Parameters

T = JsonApiResource[]

Parameters

name

string

The name of the search index.

options?

JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<T>

The fetched search index.

Inherited from

NextDrupal.getSearchIndex


getSearchIndexFromContext()

getSearchIndexFromContext\<T>(name, context, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:215

Gets a search index from the context.

Type Parameters

T = JsonApiResource[]

Parameters

name

string

The name of the search index.

context

GetStaticPropsContext

The static props context.

options?

JsonApiOptions

Options for the request.

Returns

Promise\<T>

The fetched search index.


getStaticPathsFromContext()

getStaticPathsFromContext(types, context, options?): Promise\<(string | { locale: string; params: { slug: string[]; }; })[]>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:283

Gets static paths from the context.

Parameters

types

The types of the resources.

string | string[]

context

GetStaticPathsContext

The static paths context.

options?

object & JsonApiWithAuthOption

Options for the request.

Returns

Promise\<(string | { locale: string; params: { slug: string[]; }; })[]>

The fetched static paths.


getView()

getView\<T>(name, options?): Promise\<DrupalView\<T>>

Defined in: packages/next-drupal/src/next-drupal.ts:856

Fetches a view by its name.

Type Parameters

T = JsonApiResource

Parameters

name

string

The name of the view.

options?

JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<DrupalView\<T>>

The fetched view.

Inherited from

NextDrupal.getView


logOrThrowError()

logOrThrowError(error): void

Defined in: packages/next-drupal/src/next-drupal.ts:958

Logs or throws an error based on the throwJsonApiErrors flag.

Parameters

error

Error

The error to log or throw.

Returns

void

Inherited from

NextDrupal.logOrThrowError


preview()

preview(request, response, options?): Promise\<void | NextApiResponse>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:423

Handles preview mode.

Parameters

request

NextApiRequest

The API request.

response

NextApiResponse

The API response.

options?

Options for the request.

enable

boolean

Returns

Promise\<void | NextApiResponse>


previewDisable()

previewDisable(request, response): Promise\<void>

Defined in: packages/next-drupal/src/next-drupal-pages.ts:498

Disables preview mode.

Parameters

request

NextApiRequest

The API request.

response

NextApiResponse

The API response.

Returns

Promise\<void>


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.

Inherited from

NextDrupal.throwIfJsonErrors


translatePath()

translatePath(path, options?): Promise\<DrupalTranslatedPath>

Defined in: packages/next-drupal/src/next-drupal.ts:639

Translates a path to a DrupalTranslatedPath object.

Parameters

path

string

The path to translate.

options?

JsonApiWithAuthOption & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<DrupalTranslatedPath>

The translated path.

Inherited from

NextDrupal.translatePath


translatePathFromContext()

translatePathFromContext(context, options?): Promise\<DrupalTranslatedPath>

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

Translates a path from the context.

Parameters

context

GetStaticPropsContext

The static props context.

options?

object & JsonApiWithAuthOption

Options for the request.

Returns

Promise\<DrupalTranslatedPath>

The translated path.


updateResource()

updateResource\<T>(type, uuid, body, options?): Promise\<T>

Defined in: packages/next-drupal/src/next-drupal.ts:204

Updates an existing resource of the specified type.

Type Parameters

T extends JsonApiResource

Parameters

type

string

The type of the resource.

uuid

string

The UUID of the resource.

body

JsonApiUpdateResourceBody

The body of the resource.

options?

JsonApiOptions & JsonApiWithNextFetchOptions

Options for the request.

Returns

Promise\<T>

The updated resource.

Inherited from

NextDrupal.updateResource


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.

Inherited from

NextDrupal.validateDraftUrl