diff --git a/examples/example-blog/.env.example b/examples/example-blog/.env.example index 300411a3..859c1894 100644 --- a/examples/example-blog/.env.example +++ b/examples/example-blog/.env.example @@ -3,5 +3,4 @@ NEXT_IMAGE_DOMAIN=localhost DRUPAL_CLIENT_ID=52ce1a10-bf5c-4c81-8edf-eea3af95da84 DRUPAL_CLIENT_SECRET=SA9AGbHnx6pOamaAus2f9LG9XudHFjKs DRUPAL_SITE_ID=1ccd4bc4-bbc6-4c19-a816-c7d100feff02 -DRUPAL_PREVIEW_SECRET=secret -DRUPAL_FRONT_PAGE=/home \ No newline at end of file +DRUPAL_FRONT_PAGE=/home diff --git a/examples/example-client/.env.example b/examples/example-client/.env.example index 9fb38b46..35a46fbc 100644 --- a/examples/example-client/.env.example +++ b/examples/example-client/.env.example @@ -1,11 +1,10 @@ # Required NEXT_PUBLIC_DRUPAL_BASE_URL=http://localhost:8080 NEXT_IMAGE_DOMAIN=localhost -DRUPAL_PREVIEW_SECRET= DRUPAL_CLIENT_ID= DRUPAL_CLIENT_SECRET= # Optional DRUPAL_SITE_ID= DRUPAL_FRONT_PAGE=/home -DRUPAL_JSONAPI_PREFIX=/jsonapi \ No newline at end of file +DRUPAL_JSONAPI_PREFIX=/jsonapi diff --git a/examples/example-graphql/.env.example b/examples/example-graphql/.env.example index 952a38a0..6ee70364 100644 --- a/examples/example-graphql/.env.example +++ b/examples/example-graphql/.env.example @@ -1,6 +1,3 @@ # See https://next-drupal.org/docs/environment-variables NEXT_PUBLIC_DRUPAL_BASE_URL=https://dev.next-drupal.org NEXT_IMAGE_DOMAIN=dev.next-drupal.org - -# Required for Preview Mode -DRUPAL_PREVIEW_SECRET=secret \ No newline at end of file diff --git a/examples/example-graphql/lib/drupal.ts b/examples/example-graphql/lib/drupal.ts index f1c78d5b..fa9e9b21 100644 --- a/examples/example-graphql/lib/drupal.ts +++ b/examples/example-graphql/lib/drupal.ts @@ -7,7 +7,6 @@ export const drupal = new DrupalClient( clientId: process.env.DRUPAL_CLIENT_ID, clientSecret: process.env.DRUPAL_CLIENT_SECRET, }, - previewSecret: process.env.DRUPAL_PREVIEW_SECRET, } ) diff --git a/examples/example-graphql/pages/api/revalidate.ts b/examples/example-graphql/pages/api/revalidate.ts index c1b462b7..cf90a0d4 100644 --- a/examples/example-graphql/pages/api/revalidate.ts +++ b/examples/example-graphql/pages/api/revalidate.ts @@ -1,4 +1,4 @@ -import { NextApiRequest, NextApiResponse } from "next" +import type { NextApiRequest, NextApiResponse } from "next" export default async function handler( request: NextApiRequest, @@ -8,7 +8,7 @@ export default async function handler( const secret = request.query.secret as string // Validate secret. - if (secret !== process.env.DRUPAL_PREVIEW_SECRET) { + if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) { return response.status(401).json({ message: "Invalid secret." }) } @@ -23,7 +23,7 @@ export default async function handler( return response.json({}) } catch (error) { return response.status(404).json({ - message: error.message, + message: (error as Error).message, }) } } diff --git a/examples/example-marketing/.env.example b/examples/example-marketing/.env.example index 1ab48b3f..6ac4b9c5 100644 --- a/examples/example-marketing/.env.example +++ b/examples/example-marketing/.env.example @@ -3,5 +3,4 @@ NEXT_IMAGE_DOMAIN=localhost DRUPAL_CLIENT_ID=52ce1a10-bf5c-4c81-8edf-eea3af95da84 DRUPAL_CLIENT_SECRET=SA9AGbHnx6pOamaAus2f9LG9XudHFjKs DRUPAL_SITE_ID=example_marketing -DRUPAL_PREVIEW_SECRET=secret -DRUPAL_FRONT_PAGE=/home \ No newline at end of file +DRUPAL_FRONT_PAGE=/home diff --git a/examples/example-marketing/lib/drupal.ts b/examples/example-marketing/lib/drupal.ts index 0afd7279..1ca65d9f 100644 --- a/examples/example-marketing/lib/drupal.ts +++ b/examples/example-marketing/lib/drupal.ts @@ -4,7 +4,6 @@ export const drupal = new DrupalClient( process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { frontPage: "/home", - previewSecret: "secret", auth: { clientId: process.env.DRUPAL_CLIENT_ID, clientSecret: process.env.DRUPAL_CLIENT_SECRET, diff --git a/examples/example-marketing/pages/api/revalidate.ts b/examples/example-marketing/pages/api/revalidate.ts index 3e7d8dab..0fbe346e 100644 --- a/examples/example-marketing/pages/api/revalidate.ts +++ b/examples/example-marketing/pages/api/revalidate.ts @@ -1,4 +1,4 @@ -import { NextApiRequest, NextApiResponse } from "next" +import type { NextApiRequest, NextApiResponse } from "next" export default async function handler( request: NextApiRequest, @@ -8,7 +8,7 @@ export default async function handler( const secret = request.query.secret as string // Validate secret. - if (secret !== process.env.DRUPAL_PREVIEW_SECRET) { + if (secret !== process.env.DRUPAL_REVALIDATE_SECRET) { return response.status(401).json({ message: "Invalid secret." }) } @@ -28,7 +28,7 @@ export default async function handler( return response.json({}) } catch (error) { return response.status(404).json({ - message: error.message, + message: (error as Error).message, }) } } diff --git a/examples/example-umami/.env.example b/examples/example-umami/.env.example index 0439317a..f39f7d18 100644 --- a/examples/example-umami/.env.example +++ b/examples/example-umami/.env.example @@ -1,7 +1,6 @@ NEXT_PUBLIC_DRUPAL_BASE_URL=http://localhost:8080 NEXT_IMAGE_DOMAIN=localhost -DRUPAL_PREVIEW_SECRET=secret NEXTAUTH_SECRET= NEXTAUTH_URL=http://localhost:3000 DRUPAL_CLIENT_ID= -DRUPAL_CLIENT_SECRET= \ No newline at end of file +DRUPAL_CLIENT_SECRET= diff --git a/examples/example-umami/lib/drupal.ts b/examples/example-umami/lib/drupal.ts index c35a0b40..1bfe99fc 100644 --- a/examples/example-umami/lib/drupal.ts +++ b/examples/example-umami/lib/drupal.ts @@ -1,8 +1,3 @@ import { DrupalClient } from "next-drupal" -export const drupal = new DrupalClient( - process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, - { - previewSecret: process.env.DRUPAL_PREVIEW_SECRET, - } -) +export const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL) diff --git a/modules/next/src/Controller/NextSiteEntityController.php b/modules/next/src/Controller/NextSiteEntityController.php index d6e280e8..1e582888 100644 --- a/modules/next/src/Controller/NextSiteEntityController.php +++ b/modules/next/src/Controller/NextSiteEntityController.php @@ -62,13 +62,6 @@ public function environmentVariables(NextSiteInterface $next_site) { 'DRUPAL_CLIENT_SECRET' => 'Retrieve this from /admin/config/services/consumer', ]; - if ($secret = $next_site->getPreviewSecret()) { - $variables += [ - 'preview_variables' => '# Required for Draft Mode', - 'DRUPAL_PREVIEW_SECRET' => $secret, - ]; - } - if ($revalidate_secret = $next_site->getRevalidateSecret()) { $variables += [ 'revalidate_variables' => '# Required for On-demand Revalidation', diff --git a/modules/next/tests/src/Kernel/Controller/NextSiteEntityControllerTest.php b/modules/next/tests/src/Kernel/Controller/NextSiteEntityControllerTest.php index b9c694e0..c15ebe86 100644 --- a/modules/next/tests/src/Kernel/Controller/NextSiteEntityControllerTest.php +++ b/modules/next/tests/src/Kernel/Controller/NextSiteEntityControllerTest.php @@ -54,7 +54,6 @@ public function testEnvironmentVariables() { $this->assertEquals(\Drupal::requestStack()->getCurrentRequest()->getSchemeAndHttpHost(), $build['container']['NEXT_PUBLIC_DRUPAL_BASE_URL']['#context']['value']); $this->assertEquals(\Drupal::requestStack()->getCurrentRequest()->getHost(), $build['container']['NEXT_IMAGE_DOMAIN']['#context']['value']); - $this->assertEquals($this->nextSite->getPreviewSecret(), $build['container']['DRUPAL_PREVIEW_SECRET']['#context']['value']); $this->assertEquals($this->nextSite->getRevalidateSecret(), $build['container']['DRUPAL_REVALIDATE_SECRET']['#context']['value']); } @@ -63,12 +62,12 @@ public function testEnvironmentVariables() { */ public function testOverriddenEnvironmentVariables() { $GLOBALS['config']['next.next_site.' . $this->nextSite->id()] = [ - 'preview_secret' => 'overridden', + 'revalidate_secret' => 'overridden', ]; $overridden_entity = NextSite::load($this->nextSite->id()); $controller = NextSiteEntityController::create($this->container); $build = $controller->environmentVariables($overridden_entity); - $this->assertEquals('overridden', $build['container']['DRUPAL_PREVIEW_SECRET']['#context']['value']); + $this->assertEquals('overridden', $build['container']['DRUPAL_REVALIDATE_SECRET']['#context']['value']); } } diff --git a/packages/next-drupal/src/client.ts b/packages/next-drupal/src/client.ts index 71dab8e1..438c6944 100644 --- a/packages/next-drupal/src/client.ts +++ b/packages/next-drupal/src/client.ts @@ -115,8 +115,6 @@ export class DrupalClient { private withAuth?: DrupalClientOptions["withAuth"] - private previewSecret?: DrupalClientOptions["previewSecret"] - /** * Instantiates a new DrupalClient. * @@ -142,7 +140,6 @@ export class DrupalClient { withAuth = DEFAULT_WITH_AUTH, fetcher, auth, - previewSecret, accessToken, throwJsonApiErrors = true, } = options @@ -158,7 +155,6 @@ export class DrupalClient { this.headers = headers this.logger = logger this.withAuth = withAuth - this.previewSecret = previewSecret this.cache = cache this.accessToken = accessToken this.throwJsonApiErrors = throwJsonApiErrors diff --git a/packages/next-drupal/src/types/client.ts b/packages/next-drupal/src/types/client.ts index 924caa53..7433458e 100644 --- a/packages/next-drupal/src/types/client.ts +++ b/packages/next-drupal/src/types/client.ts @@ -115,16 +115,6 @@ export type DrupalClientOptions = { */ useDefaultResourceTypeEntry?: boolean - /** - * The secret to use for preview mode. - * - * * **Default value**: `null` - * * **Required**: *No* - * - * [Documentation](https://next-drupal.org/docs/client/configuration#previewsecret) - */ - previewSecret?: string - /** * A long-lived access token you can set for the client. * diff --git a/packages/next-drupal/tests/DrupalClient/basic-methods.test.ts b/packages/next-drupal/tests/DrupalClient/basic-methods.test.ts index ff83e0f0..89cbfbb5 100644 --- a/packages/next-drupal/tests/DrupalClient/basic-methods.test.ts +++ b/packages/next-drupal/tests/DrupalClient/basic-methods.test.ts @@ -3,6 +3,8 @@ import { DrupalClient, JsonApiErrors } from "../../src" import { BASE_URL, mockLogger, spyOnFetch, spyOnFetchOnce } from "../utils" import type { DrupalNode, JsonApiError, Serializer } from "../../src" +jest.setTimeout(10000) + afterEach(() => { jest.restoreAllMocks() }) diff --git a/packages/next-drupal/tests/DrupalClient/constructor.test.ts b/packages/next-drupal/tests/DrupalClient/constructor.test.ts index b23c0226..d1e02243 100644 --- a/packages/next-drupal/tests/DrupalClient/constructor.test.ts +++ b/packages/next-drupal/tests/DrupalClient/constructor.test.ts @@ -247,22 +247,6 @@ describe("options parameter", () => { }) }) - describe("previewSecret", () => { - test("defaults to `undefined`", () => { - const client = new DrupalClient(BASE_URL) - expect(client.previewSecret).toBe(undefined) - }) - - test("sets up a custom previewSecret", () => { - const customPreviewSecret = "custom-secret-value" - - const client = new DrupalClient(BASE_URL, { - previewSecret: customPreviewSecret, - }) - expect(client.previewSecret).toBe(customPreviewSecret) - }) - }) - describe("serializer", () => { test("defaults to `new Jsona()`", () => { const client = new DrupalClient(BASE_URL) diff --git a/packages/next-drupal/tests/DrupalClient/pages-router-methods.test.ts b/packages/next-drupal/tests/DrupalClient/pages-router-methods.test.ts index e9c2a587..fa734c51 100644 --- a/packages/next-drupal/tests/DrupalClient/pages-router-methods.test.ts +++ b/packages/next-drupal/tests/DrupalClient/pages-router-methods.test.ts @@ -4,6 +4,8 @@ import { DRAFT_DATA_COOKIE_NAME, DrupalClient } from "../../src" import { BASE_URL, mockLogger, mocks, spyOnFetch } from "../utils" import type { DrupalNode, JsonApiResourceWithPath } from "../../src" +jest.setTimeout(10000) + afterEach(() => { jest.restoreAllMocks() }) diff --git a/packages/next-drupal/tests/DrupalClient/resource-methods.test.ts b/packages/next-drupal/tests/DrupalClient/resource-methods.test.ts index c1494562..51fc43b1 100644 --- a/packages/next-drupal/tests/DrupalClient/resource-methods.test.ts +++ b/packages/next-drupal/tests/DrupalClient/resource-methods.test.ts @@ -3,6 +3,8 @@ import { DrupalClient } from "../../src" import { BASE_URL, mocks, spyOnFetch } from "../utils" import type { DrupalNode, DrupalSearchApiJsonApiResponse } from "../../src" +jest.setTimeout(10000) + afterEach(() => { jest.restoreAllMocks() }) diff --git a/starters/basic-starter/.env.example b/starters/basic-starter/.env.example index f0a9bcf3..951ea909 100644 --- a/starters/basic-starter/.env.example +++ b/starters/basic-starter/.env.example @@ -8,8 +8,5 @@ NEXT_IMAGE_DOMAIN=site.example.com DRUPAL_CLIENT_ID=Retrieve this from /admin/config/services/consumer DRUPAL_CLIENT_SECRET=Retrieve this from /admin/config/services/consumer -# Required for Preview Mode -DRUPAL_PREVIEW_SECRET=Retrieve this from /admin/config/services/next - # Required for On-demand Revalidation DRUPAL_REVALIDATE_SECRET=Retrieve this from /admin/config/services/next diff --git a/starters/basic-starter/README.md b/starters/basic-starter/README.md index 00a1a34a..03dfcfb4 100644 --- a/starters/basic-starter/README.md +++ b/starters/basic-starter/README.md @@ -8,7 +8,7 @@ A simple starter for building your site with Next.js and Drupal. ## Deploy to Vercel -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fchapter-three%2Fnext-drupal-basic-starter&env=NEXT_PUBLIC_DRUPAL_BASE_URL,NEXT_IMAGE_DOMAIN,DRUPAL_PREVIEW_SECRET,DRUPAL_CLIENT_ID,DRUPAL_CLIENT_SECRET&envDescription=Learn%20more%20about%20environment%20variables&envLink=https%3A%2F%2Fnext-drupal.org%2Fdocs%2Fenvironment-variables&project-name=next-drupal&demo-title=Next.js%20for%20Drupal&demo-description=A%20next-generation%20front-end%20for%20your%20Drupal%20site.&demo-url=https%3A%2F%2Fdemo.next-drupal.org&demo-image=https%3A%2F%2Fnext-drupal.org%2Fimages%2Fdemo-screenshot.jpg) +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fchapter-three%2Fnext-drupal-basic-starter&env=NEXT_PUBLIC_DRUPAL_BASE_URL,NEXT_IMAGE_DOMAIN,DRUPAL_CLIENT_ID,DRUPAL_CLIENT_SECRET&envDescription=Learn%20more%20about%20environment%20variables&envLink=https%3A%2F%2Fnext-drupal.org%2Fdocs%2Fenvironment-variables&project-name=next-drupal&demo-title=Next.js%20for%20Drupal&demo-description=A%20next-generation%20front-end%20for%20your%20Drupal%20site.&demo-url=https%3A%2F%2Fdemo.next-drupal.org&demo-image=https%3A%2F%2Fnext-drupal.org%2Fimages%2Fdemo-screenshot.jpg) ## Documentation diff --git a/starters/basic-starter/lib/drupal.ts b/starters/basic-starter/lib/drupal.ts index 64444951..513b3bf2 100644 --- a/starters/basic-starter/lib/drupal.ts +++ b/starters/basic-starter/lib/drupal.ts @@ -3,12 +3,10 @@ import { DrupalClient } from "next-drupal" const baseUrl: string = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || "" const clientId = process.env.DRUPAL_CLIENT_ID || "" const clientSecret = process.env.DRUPAL_CLIENT_SECRET || "" -const previewSecret = process.env.DRUPAL_PREVIEW_SECRET export const drupal = new DrupalClient(baseUrl, { auth: { clientId, clientSecret, }, - previewSecret, }) diff --git a/starters/graphql-starter/.env.example b/starters/graphql-starter/.env.example index f0a9bcf3..951ea909 100644 --- a/starters/graphql-starter/.env.example +++ b/starters/graphql-starter/.env.example @@ -8,8 +8,5 @@ NEXT_IMAGE_DOMAIN=site.example.com DRUPAL_CLIENT_ID=Retrieve this from /admin/config/services/consumer DRUPAL_CLIENT_SECRET=Retrieve this from /admin/config/services/consumer -# Required for Preview Mode -DRUPAL_PREVIEW_SECRET=Retrieve this from /admin/config/services/next - # Required for On-demand Revalidation DRUPAL_REVALIDATE_SECRET=Retrieve this from /admin/config/services/next diff --git a/starters/graphql-starter/lib/drupal.ts b/starters/graphql-starter/lib/drupal.ts index f191e1b3..7a7921c2 100644 --- a/starters/graphql-starter/lib/drupal.ts +++ b/starters/graphql-starter/lib/drupal.ts @@ -3,14 +3,12 @@ import { DrupalClient } from "next-drupal" const baseUrl: string = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || "" const clientId = process.env.DRUPAL_CLIENT_ID || "" const clientSecret = process.env.DRUPAL_CLIENT_SECRET || "" -const previewSecret = process.env.DRUPAL_PREVIEW_SECRET export const drupal = new DrupalClient(baseUrl, { auth: { clientId, clientSecret, }, - previewSecret, }) export const graphqlEndpoint = drupal.buildUrl("/graphql") diff --git a/www/content/docs/configuration.mdx b/www/content/docs/configuration.mdx index baaaec03..e46e7cd9 100644 --- a/www/content/docs/configuration.mdx +++ b/www/content/docs/configuration.mdx @@ -182,15 +182,6 @@ If your resources follow the `entity_type--bundle` naming convention, you can sa --- -### previewSecret - -- **Default value**: `null` -- **Required**: No - -The secret to use for preview mode. - ---- - ### headers - **Default value**: `{ "Content-Type": "application/vnd.api+json", Accept: "application/vnd.api+json" }` diff --git a/www/content/docs/environment-variables.mdx b/www/content/docs/environment-variables.mdx index 557378e5..62e9e45b 100644 --- a/www/content/docs/environment-variables.mdx +++ b/www/content/docs/environment-variables.mdx @@ -8,9 +8,6 @@ excerpt: Configuration variables for Next.js and Drupal. NEXT_PUBLIC_DRUPAL_BASE_URL=http://localhost:8080 NEXT_IMAGE_DOMAIN=localhost -# Required for Preview Mode -DRUPAL_PREVIEW_SECRET= - # Required for On-demand Revalidation DRUPAL_REVALIDATE_SECRET= @@ -44,20 +41,6 @@ const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL) --- -## Preview Mode - -Environment variables required for preview mode. - -| Name | Description | -| ----------------------- | :----------------------------------------------------------------------- | -| `DRUPAL_PREVIEW_SECRET` | The secret for [preview mode](/docs/preview-mode). Example: `6SZy9xkdtR` | - -```ts -const drupal = new DrupalClient(process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { - previewSecret: process.env.DRUPAL_PREVIEW_SECRET, -}) -``` - ## On-demand Revalidation Environment variables required for on-demand revalidation. diff --git a/www/content/docs/reference/preview.mdx b/www/content/docs/reference/preview.mdx index e9e33b5b..f5ef8b67 100644 --- a/www/content/docs/reference/preview.mdx +++ b/www/content/docs/reference/preview.mdx @@ -29,16 +29,6 @@ await drupal.preview(request, response, options?: { ## Notes - The `preview` method should be called in an API route. -- Remember to set a `previewSecret` on the client. - -```ts title=lib/drupal.ts -export const drupal = new DrupalClient( - process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, - { - previewSecret: process.env.DRUPAL_PREVIEW_SECRET, - } -) -``` --- diff --git a/www/content/docs/upgrade-guide.mdx b/www/content/docs/upgrade-guide.mdx index bc5125a2..49b2c9bf 100644 --- a/www/content/docs/upgrade-guide.mdx +++ b/www/content/docs/upgrade-guide.mdx @@ -92,7 +92,6 @@ export const drupal = new DrupalClient( process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { frontPage: "/home", - previewSecret: process.env.DRUPAL_PREVIEW_SECRET, auth: { clientId: process.env.DRUPAL_CLIENT_ID, clientSecret: process.env.DRUPAL_CLIENT_SECRET, @@ -114,7 +113,6 @@ export const drupal = new DrupalClient( process.env.NEXT_PUBLIC_DRUPAL_BASE_URL, { frontPage: "/home", - previewSecret: process.env.DRUPAL_PREVIEW_SECRET, auth: { clientId: process.env.DRUPAL_CLIENT_ID, clientSecret: process.env.DRUPAL_CLIENT_SECRET,