diff --git a/packages/inngest/src/components/InngestCommHandler.ts b/packages/inngest/src/components/InngestCommHandler.ts index c07c86f31..334df7cef 100644 --- a/packages/inngest/src/components/InngestCommHandler.ts +++ b/packages/inngest/src/components/InngestCommHandler.ts @@ -1249,7 +1249,7 @@ export type Handler< export type HandlerResponse = { // eslint-disable-next-line @typescript-eslint/no-explicit-any body: () => MaybePromise; - env?: () => MaybePromise; + env?: () => MaybePromise; headers: (key: string) => MaybePromise; /** diff --git a/packages/inngest/src/remix.ts b/packages/inngest/src/remix.ts index 3f55bb29e..9126f0417 100644 --- a/packages/inngest/src/remix.ts +++ b/packages/inngest/src/remix.ts @@ -1,8 +1,10 @@ +import { z } from "zod"; import { InngestCommHandler, type ActionResponse, type ServeHandlerOptions, } from "./components/InngestCommHandler"; +import { type Env } from "./helpers/env"; import { type SupportedFrameworkName } from "./types"; export const frameworkName: SupportedFrameworkName = "remix"; @@ -56,11 +58,28 @@ const createNewResponse = ({ * @public */ export const serve = (options: ServeHandlerOptions) => { + const contextSchema = z.object({ + env: z.record(z.string(), z.any()), + }); + const handler = new InngestCommHandler({ frameworkName, ...options, - handler: ({ request: req }: { request: Request }) => { + handler: ({ + request: req, + context, + }: { + request: Request; + context?: unknown; + }) => { return { + env: () => { + const ctxParse = contextSchema.safeParse(context); + + if (ctxParse.success && Object.keys(ctxParse.data.env).length) { + return ctxParse.data.env as Env; + } + }, body: () => req.json(), headers: (key) => req.headers.get(key), method: () => req.method,