Skip to content

Commit f377da8

Browse files
MontiMarco92Marco Montibacklineint
authored
docs(next-drupal): updated docs (#787)
Co-authored-by: Marco Monti <marco@easytech.com.ar> Co-authored-by: Brian Perry <contact.brianperry@gmail.com>
1 parent 1cda615 commit f377da8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+876
-459
lines changed

www/config/docs.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export const docsConfig: DocsConfig = {
4949
href: "/docs/environment-variables",
5050
},
5151
{
52-
title: "Preview Mode",
53-
href: "/docs/preview-mode",
52+
title: "Draft Mode",
53+
href: "/docs/draft-mode",
5454
},
5555
{
5656
title: "TypeScript",
@@ -108,8 +108,8 @@ export const docsConfig: DocsConfig = {
108108
href: "/docs/fetcher",
109109
},
110110
{
111-
title: "Serializer",
112-
href: "/docs/serializer",
111+
title: "Deserializer",
112+
href: "/docs/deserializer",
113113
},
114114
{
115115
title: "Caching",
@@ -124,10 +124,6 @@ export const docsConfig: DocsConfig = {
124124
title: "getResource",
125125
href: "/docs/reference/getresource",
126126
},
127-
{
128-
title: "getResourceFromContext",
129-
href: "/docs/reference/getresourcefromcontext",
130-
},
131127
{
132128
title: "getResourceByPath",
133129
href: "/docs/reference/getresourcebypath",
@@ -136,10 +132,6 @@ export const docsConfig: DocsConfig = {
136132
title: "getResourceCollection",
137133
href: "/docs/reference/getresourcecollection",
138134
},
139-
{
140-
title: "getResourceCollectionFromContext",
141-
href: "/docs/reference/getresourcecollectionfromcontext",
142-
},
143135
{
144136
title: "createResource",
145137
href: "/docs/reference/createresource",
@@ -157,28 +149,20 @@ export const docsConfig: DocsConfig = {
157149
href: "/docs/reference/deleteresource",
158150
},
159151
{
160-
title: "getStaticPathsFromContext",
161-
href: "/docs/reference/getstaticpathsfromcontext",
152+
title: "getResourceCollectionPathSegments",
153+
href: "/docs/reference/getresourcecollectionpathsegments",
162154
},
163155
{
164156
title: "translatePath",
165157
href: "/docs/reference/translatepath",
166158
},
167159
{
168-
title: "translatePathFromContext",
169-
href: "/docs/reference/translatepathfromcontext",
170-
},
171-
{
172-
title: "getPathFromContext",
173-
href: "/docs/reference/getpathfromcontext",
174-
},
175-
{
176-
title: "getEntryForResourceType",
177-
href: "/docs/reference/getentryforresourcetype",
160+
title: "constructPathFromSegment",
161+
href: "/docs/reference/constructpathfromsegment",
178162
},
179163
{
180-
title: "preview",
181-
href: "/docs/reference/preview",
164+
title: "buildEndpoint",
165+
href: "/docs/reference/buildendpoint",
182166
},
183167
{
184168
title: "getAccessToken",
@@ -208,6 +192,10 @@ export const docsConfig: DocsConfig = {
208192
title: "deserialize",
209193
href: "/docs/reference/deserialize",
210194
},
195+
{
196+
title: "getAuthorizationHeader",
197+
href: "/docs/reference/getauthorizationheader",
198+
},
211199
],
212200
},
213201
{

www/config/tutorials.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export const tutorialsConfig = [
1212
items: [],
1313
},
1414
{
15-
title: "Preview Mode",
16-
excerpt: "Implement Preview Mode for Entity Types.",
17-
url: "/learn/preview-mode",
15+
title: "Draft Mode",
16+
excerpt: "Implement Draft Mode for Entity Types.",
17+
url: "/learn/draft-mode",
1818
items: [],
1919
},
2020
{

www/content/docs/authentication.mdx

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: Authentication
3-
excerpt: Making authenticated requests with DrupalClient.
3+
excerpt: Making authenticated requests with NextDrupal.
44
---
55

6-
The `DrupalClient` works with several auth types. You can use **Bearer** tokens, **Basic** tokens or bring your own authorization headers.
6+
The `NextDrupal` client works with several auth types. You can use **Bearer** tokens, **Basic** tokens or bring your own authorization headers.
77

88
Authentication can be set globally on the client or custom per method.
99

@@ -16,9 +16,9 @@ This is the default authentication configured on the client.
1616
**This is used most of the time for fetching and building static pages.**
1717

1818
```ts title=lib/drupal.ts
19-
import { DrupalClient } from "next-drupal"
19+
import { NextDrupal } from "next-drupal"
2020

21-
export const drupal = new DrupalClient(
21+
export const drupal = new NextDrupal(
2222
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
2323
{
2424
auth: // Configure the global auth here.
@@ -59,15 +59,12 @@ You need to enable the `simple_oauth` module on Drupal.
5959

6060
```ts title=lib/drupal.ts
6161
// Client
62-
export const drupal = new DrupalClient(
63-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
64-
{
65-
auth: {
66-
clientId: process.env.DRUPAL_CLIENT_ID,
67-
clientSecret: process.env.DRUPAL_CLIENT_SECRET,
68-
},
69-
}
70-
)
62+
export const drupal = new NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, {
63+
auth: {
64+
clientId: process.env.DRUPAL_CLIENT_ID,
65+
clientSecret: process.env.DRUPAL_CLIENT_SECRET,
66+
},
67+
})
7168

7269
// Method
7370
const article = drupal.getResource(
@@ -82,26 +79,23 @@ const article = drupal.getResource(
8279
)
8380
```
8481

85-
`DrupalClient` will fetch **Bearer** token and handle expiration for you.
82+
`NextDrupal` client will fetch **Bearer** token and handle expiration for you.
8683

8784
If you need to customize the OAuth URL you can use the `url` option.
8885

8986
```ts title=lib/drupal.ts
90-
export const drupal = new DrupalClient(
91-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
92-
{
93-
auth: {
94-
clientId: process.env.DRUPAL_CLIENT_ID,
95-
clientSecret: process.env.DRUPAL_CLIENT_SECRET,
96-
// highlight-start
97-
url: `/oauth2/token`,
98-
// highlight-end
99-
},
100-
}
101-
)
87+
export const drupal = new NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, {
88+
auth: {
89+
clientId: process.env.DRUPAL_CLIENT_ID,
90+
clientSecret: process.env.DRUPAL_CLIENT_SECRET,
91+
// highlight-start
92+
url: `/oauth2/token`,
93+
// highlight-end
94+
},
95+
})
10296
```
10397

104-
By default, `DrupalClient` uses `/oauth/token` as the default URL.
98+
By default, `NextDrupal` uses `/oauth/token` as the default URL.
10599

106100
---
107101

@@ -117,15 +111,12 @@ You need to enable the `basic_auth` module on Drupal.
117111

118112
```ts
119113
// Client.
120-
export const drupal = new DrupalClient(
121-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
122-
{
123-
auth: {
124-
username: process.env.DRUPAL_USERNAME,
125-
password: process.env.DRUPAL_PASSWORD,
126-
},
127-
}
128-
)
114+
export const drupal = new NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, {
115+
auth: {
116+
username: process.env.DRUPAL_USERNAME,
117+
password: process.env.DRUPAL_PASSWORD,
118+
},
119+
})
129120

130121
// Method
131122
const articles = await drupal.getResourceCollection("node--article", {
@@ -144,14 +135,11 @@ You can also provide a custom callback for authentication. The callback must ret
144135

145136
```ts
146137
// Client
147-
export const drupal = new DrupalClient(
148-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
149-
{
150-
auth: () => {
151-
// Do something and return an Authorization header.
152-
},
153-
}
154-
)
138+
export const drupal = new NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, {
139+
auth: () => {
140+
// Do something and return an Authorization header.
141+
},
142+
})
155143

156144
// Method
157145
const users = await drupal.getResourceCollection("user--user", {
@@ -167,16 +155,13 @@ You can also pass in an access token.
167155

168156
```ts
169157
// Client
170-
export const drupal = new DrupalClient(
171-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
172-
{
173-
auth: {
174-
access_token: "ECYM594IlARGc3S8KgBHvTpki0rDtWx6...",
175-
token_type: "Bearer",
176-
expires_in: 3600,
177-
},
178-
}
179-
)
158+
export const drupal = new NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, {
159+
auth: {
160+
access_token: "ECYM594IlARGc3S8KgBHvTpki0rDtWx6...",
161+
token_type: "Bearer",
162+
expires_in: 3600,
163+
},
164+
})
180165

181166
// Method
182167
const articles = await drupal.getResourceCollection("node--article", {
@@ -198,7 +183,7 @@ import { getSession } from "next-auth/react"
198183
const session = getSession(...)
199184

200185
// Client
201-
export const drupal = new DrupalClient(
186+
export const drupal = new NextDrupal(
202187
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
203188
{
204189
auth: session.accessToken,

www/content/docs/cache.mdx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Caching
33
excerpt: Using a custom cache for resources.
44
---
55

6-
The `DrupalClient` has support for caching resources.
6+
The `NextDrupal` client has support for caching resources.
77

88
This is handy when dealing with global data: you can fetch data once and re-use during builds.
99

@@ -22,7 +22,7 @@ Note: as of `next-drupal 1.3.0`, only `getResource` and `getMenu` support cachin
2222
</Callout>
2323

2424
```ts title=lib/drupal.ts
25-
import { DrupalClient, DataCache } from "next-drupal"
25+
import { NextDrupal, DataCache } from "next-drupal"
2626
import Redis from "ioredis"
2727

2828
const redis = new Redis(process.env.REDIS_URL)
@@ -37,12 +37,9 @@ export const redisCache: DataCache = {
3737
},
3838
}
3939

40-
export const drupal = new DrupalClient(
41-
process.env.NEXT_PUBLIC_DRUPAL_BASE_URL,
42-
{
43-
cache: redisCache,
44-
}
45-
)
40+
export const drupal = new NextDrupal(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, {
41+
cache: redisCache,
42+
})
4643
```
4744

4845
Now when you make a `getResource` or `getMenu` call you can tell the client to cache and re-use responses.

www/content/docs/client.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: Drupal Client
2+
title: NextDrupal Client
33
excerpt: A powerful JSON:API client for Drupal.
44
---
55

6-
The `DrupalClient` is a powerful JSON:API client that ships with helpers for working with Drupal data.
6+
The `NextDrupal` client is a powerful JSON:API client that ships with helpers for working with Drupal data.
77

8-
You can use the `DrupalClient` to fetch JSON:API data from Drupal to build static pages.
8+
You can use the `NextDrupal` client to fetch JSON:API data from Drupal to build static pages in advance, or server render pages on-demand.
99

1010
It also comes with full support for JSON:API write operations which means you can create JSON:API resources from Next.js to Drupal.
1111

@@ -27,10 +27,10 @@ It also comes with full support for JSON:API write operations which means you ca
2727
## Usage
2828

2929
```ts
30-
import { DrupalClient } from "next-drupal"
30+
import { NextDrupal } from "next-drupal"
3131

32-
// Create a new DrupalClient.
33-
const drupal = new DrupalClient("https://example.com")
32+
// Create a new NextDrupal client.
33+
const drupal = new NextDrupal("https://example.com")
3434

3535
// Fetch articles.
3636
const articles = await drupal.getResourceCollection("node--article")

0 commit comments

Comments
 (0)