From 658ffe2e0edf17cfd56a4cf64fc0803bd27ead6f Mon Sep 17 00:00:00 2001 From: Joel Hooks Date: Thu, 15 Aug 2024 09:45:36 -0600 Subject: [PATCH] examples: inngest example for latest version (#68600) Co-authored-by: malewis5 Co-authored-by: Lee Robinson --- examples/cms-contentful/.env.local.example | 1 - .../cms-contentful/app/api/draft/route.ts | 24 ++------------ examples/cms-contentful/package.json | 1 + examples/inngest/package.json | 9 ++--- examples/inngest/src/app/api/inngest/route.ts | 5 ++- examples/inngest/src/app/page.tsx | 2 +- .../src/inngest/functions/hello-world.ts | 10 ------ .../inngest/src/inngest/inngest.client.ts | 4 --- .../inngest/src/inngest/inngest.config.ts | 33 +++++++++++++++++++ 9 files changed, 44 insertions(+), 45 deletions(-) delete mode 100755 examples/inngest/src/inngest/functions/hello-world.ts delete mode 100755 examples/inngest/src/inngest/inngest.client.ts create mode 100644 examples/inngest/src/inngest/inngest.config.ts diff --git a/examples/cms-contentful/.env.local.example b/examples/cms-contentful/.env.local.example index eac50f166461e..4b0e3ac561ee6 100644 --- a/examples/cms-contentful/.env.local.example +++ b/examples/cms-contentful/.env.local.example @@ -1,5 +1,4 @@ CONTENTFUL_SPACE_ID= CONTENTFUL_ACCESS_TOKEN= CONTENTFUL_PREVIEW_ACCESS_TOKEN= -CONTENTFUL_PREVIEW_SECRET= CONTENTFUL_REVALIDATE_SECRET= \ No newline at end of file diff --git a/examples/cms-contentful/app/api/draft/route.ts b/examples/cms-contentful/app/api/draft/route.ts index fb0d83fb20838..a89c2f3cd13d6 100644 --- a/examples/cms-contentful/app/api/draft/route.ts +++ b/examples/cms-contentful/app/api/draft/route.ts @@ -1,22 +1,2 @@ -import { draftMode } from "next/headers"; -import { redirect } from "next/navigation"; -import { getPreviewPostBySlug } from "../../../lib/api"; - -export async function GET(request: Request) { - const { searchParams } = new URL(request.url); - const secret = searchParams.get("secret"); - const slug = searchParams.get("slug"); - - if (secret !== process.env.CONTENTFUL_PREVIEW_SECRET) { - return new Response("Invalid token", { status: 401 }); - } - - const post = await getPreviewPostBySlug(slug); - - if (!post) { - return new Response("Invalid slug", { status: 401 }); - } - - draftMode().enable(); - redirect(`/posts/${post.slug}`); -} +//@ts-ignore +export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router"; diff --git a/examples/cms-contentful/package.json b/examples/cms-contentful/package.json index 6f8cbac311b23..232212205ed96 100644 --- a/examples/cms-contentful/package.json +++ b/examples/cms-contentful/package.json @@ -9,6 +9,7 @@ "dependencies": { "@contentful/rich-text-react-renderer": "^15.17.1", "@contentful/rich-text-types": "^16.2.1", + "@contentful/vercel-nextjs-toolkit": "latest", "@tailwindcss/typography": "0.5.9", "@types/node": "^20.5.0", "@types/react": "^18.2.20", diff --git a/examples/inngest/package.json b/examples/inngest/package.json index c86ec816af529..d5a93e5b197df 100755 --- a/examples/inngest/package.json +++ b/examples/inngest/package.json @@ -2,13 +2,13 @@ "private": true, "scripts": { "dev": "concurrently \"npm:dev:*\"", - "dev:next": "next dev", - "dev:inngest": "npx inngest-cli@latest dev", + "dev:next": "next dev --turbo", + "dev:inngest": "inngest-cli dev --no-discovery -u http://localhost:3000/api/inngest", "build": "next build", "start": "next start" }, "dependencies": { - "inngest": "latest", + "inngest": "3.x", "next": "latest", "react": "18.2.0", "react-dom": "18.2.0" @@ -19,6 +19,7 @@ "@types/react-dom": "18.2.7", "concurrently": "^8.2.1", "encoding": "^0.1.13", - "typescript": "5.2.2" + "inngest-cli": "latest", + "typescript": "5.5.4" } } diff --git a/examples/inngest/src/app/api/inngest/route.ts b/examples/inngest/src/app/api/inngest/route.ts index 1c4353142736f..6b08044ea5ce1 100755 --- a/examples/inngest/src/app/api/inngest/route.ts +++ b/examples/inngest/src/app/api/inngest/route.ts @@ -1,5 +1,4 @@ +import { inngestConfig } from "@/inngest/inngest.config"; import { serve } from "inngest/next"; -import { inngest } from "@/inngest/inngest.client"; -import { helloWorld } from "@/inngest/functions/hello-world"; -export const { GET, POST, PUT } = serve(inngest, [helloWorld]); +export const { GET, POST, PUT } = serve(inngestConfig); diff --git a/examples/inngest/src/app/page.tsx b/examples/inngest/src/app/page.tsx index 3089b9b43009b..46c1f5fae0fbe 100755 --- a/examples/inngest/src/app/page.tsx +++ b/examples/inngest/src/app/page.tsx @@ -1,4 +1,4 @@ -import { inngest } from "@/inngest/inngest.client"; +import { inngest } from "@/inngest/inngest.config"; import { redirect } from "next/navigation"; export default function Home() { diff --git a/examples/inngest/src/inngest/functions/hello-world.ts b/examples/inngest/src/inngest/functions/hello-world.ts deleted file mode 100755 index a31ddf4d00159..0000000000000 --- a/examples/inngest/src/inngest/functions/hello-world.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { inngest } from "../inngest.client"; - -export const helloWorld = inngest.createFunction( - { id: "hello-world", name: "Hello World" }, - { event: "test/hello.world" }, - async ({ event, step }) => { - await step.sleep("sleep for a second", "1s"); - return { event, body: event.data.message }; - }, -); diff --git a/examples/inngest/src/inngest/inngest.client.ts b/examples/inngest/src/inngest/inngest.client.ts deleted file mode 100755 index c11ec011e3140..0000000000000 --- a/examples/inngest/src/inngest/inngest.client.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Inngest } from "inngest"; - -// Create a client to send and receive events -export const inngest = new Inngest({ id: "Basic Inngest Application" }); diff --git a/examples/inngest/src/inngest/inngest.config.ts b/examples/inngest/src/inngest/inngest.config.ts new file mode 100644 index 0000000000000..74617accec9b7 --- /dev/null +++ b/examples/inngest/src/inngest/inngest.config.ts @@ -0,0 +1,33 @@ +import { EventSchemas, Inngest } from "inngest"; + +// TypeScript schema for the events +export type Events = { + "test/hello.world": { + name: "test/hello.world"; + data: { + message: string; + }; + }; +}; + +// Inngest client to send and receive events +export const inngest = new Inngest({ + id: "demo-app", + schemas: new EventSchemas().fromRecord(), +}); + +// a function to execute, typically in its own file +const helloWorld = inngest.createFunction( + { id: "hello-world", name: "Hello World" }, + { event: "test/hello.world" }, + async ({ event, step }) => { + await step.sleep("sleep for a second", "1s"); + return { event, body: event.data.message }; + }, +); + +// configuration for the Inngest api router +export const inngestConfig = { + client: inngest, + functions: [helloWorld], +};