inngest-js
inngest-js copied to clipboard
Allow for configuration via serve
In a monorepo setup where Inngest functions live in a separate package, there's no solution to pass runtime configuration to functions.
apps
└── nextjs
└── app
└── api
└── inngest
└── route.tsx (serve is called there)
packages
└── inngest
└── functions
└── myfunction.ts
└── index.ts (middleware is setup here)
The Inngest package is a dependency of the Nextjs app. So it shouldn't import exported values from it since it will introduce cycle.
My proposed solution
I want to pass custom configuration data via serve to the client init function so I can set up the parametrized context. This follows the same context creation logic proposed by tRPC. Example from create-t3-turbo
// nextjs api route
import { inngest } from "@acme/inngest" // custom package in monorepo
import { functions } from "@acme/inngest/functions"
serve({
client: inngest,
functions,
ctx: inngest.createContext({
myProp: "myValue"
})
})
// packages/inngest
interface InitialContext {
myValue: string
}
const i = new Inngest<InitialContext>({
schemas: new EventSchemas().fromRecord<Events>()
})
const middleware = i.createMiddleware({
name: "Test Middleware",
// here come values from serve
init({ client, ctx }) {
return {
...
};
};
});
export const inngest = i.use(middleware)
Describe alternatives you've considered
I considered accessing process.env.ENV_VAR directly in inngest package. This is suboptimal due to the lack of type safety. Also, this limits me only to process.env usage.