next-drupal / NextDrupal
Class: NextDrupal
Defined in: packages/next-drupal/src/next-drupal.ts:51
The NextDrupal class extends the NextDrupalBase class and provides methods for interacting with a Drupal backend.
Extends
Extended by
Constructors
new NextDrupal()
new NextDrupal(
baseUrl
,options
):NextDrupal
Defined in: packages/next-drupal/src/next-drupal.ts:68
Instantiates a new NextDrupal.
const client = new NextDrupal(baseUrl)
Parameters
baseUrl
string
The baseUrl of your Drupal site. Do not add the /jsonapi suffix.
options
NextDrupalOptions
= {}
Options for NextDrupal.
Returns
Overrides
Properties
accessToken?
optional
accessToken:AccessToken
Defined in: packages/next-drupal/src/next-drupal-base.ts:37
Inherited from
baseUrl
baseUrl:
string
Defined in: packages/next-drupal/src/next-drupal-base.ts:39
Inherited from
cache?
optional
cache:DataCache
Defined in: packages/next-drupal/src/next-drupal.ts:52
deserializer
deserializer:
JsonDeserializer
Defined in: packages/next-drupal/src/next-drupal.ts:54
fetcher()?
optional
fetcher: (input
,init
?) =>Promise
\<Response
>
Defined in: packages/next-drupal/src/next-drupal-base.ts:41
Parameters
input
RequestInfo
| URL
init?
RequestInit
Returns
Promise
\<Response
>
Inherited from
frontPage
frontPage:
string
Defined in: packages/next-drupal/src/next-drupal-base.ts:43
Inherited from
isDebugEnabled
isDebugEnabled:
boolean
Defined in: packages/next-drupal/src/next-drupal-base.ts:45
Inherited from
logger
logger:
Logger
Defined in: packages/next-drupal/src/next-drupal-base.ts:47
Inherited from
throwJsonApiErrors
throwJsonApiErrors:
boolean
Defined in: packages/next-drupal/src/next-drupal.ts:56
useDefaultEndpoints
useDefaultEndpoints:
boolean
Defined in: packages/next-drupal/src/next-drupal.ts:58
withAuth
withAuth:
boolean
Defined in: packages/next-drupal/src/next-drupal-base.ts:49
Inherited from
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
auth
Get Signature
get auth():
NextDrupalAuth
Defined in: packages/next-drupal/src/next-drupal-base.ts:158
Returns
Set Signature
set auth(
auth
):void
Defined in: packages/next-drupal/src/next-drupal-base.ts:113
Parameters
auth
Returns
void
Inherited from
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
token
Get Signature
get token():
AccessToken
Defined in: packages/next-drupal/src/next-drupal-base.ts:175
Returns
Set Signature
set token(
token
):void
Defined in: packages/next-drupal/src/next-drupal-base.ts:170
Parameters
token
Returns
void
Inherited from
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
NextDrupalBase
.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.
Overrides
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?
The search parameters.
Returns
URL
The constructed URL.
Inherited from
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
NextDrupalBase
.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
The body of the file resource.
options?
JsonApiOptions
& JsonApiWithNextFetchOptions
Options for the request.
Returns
Promise
\<T
>
The created file resource.
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
The body of the resource.
options?
JsonApiOptions
& JsonApiWithNextFetchOptions
Options for the request.
Returns
Promise
\<T
>
The created resource.
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
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.
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.
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
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.
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?
The client ID and secret.
Returns
Promise
\<AccessToken
>
The access token.
Inherited from
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
The auth configuration.
Returns
Promise
\<string
>
The authorization header value.
Inherited from
NextDrupalBase
.getAuthorizationHeader
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
NextDrupalBase
.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?
Options for the request.
Returns
Promise
\<JsonApiResponse
>
The JSON:API index.
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
menuName
string
The name of the menu.
options?
JsonApiOptions
& JsonApiWithCacheOptions
& JsonApiWithNextFetchOptions
Options for the request.
Returns
Promise
\<{ items
: T
[]; tree
: T
[]; }>
The fetched menu.
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.
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.
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.
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.
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.
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.
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
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
NextDrupalBase
.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.
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
The body of the resource.
options?
JsonApiOptions
& JsonApiWithNextFetchOptions
Options for the request.
Returns
Promise
\<T
>
The updated resource.
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.