UNPKG

inngest

Version:

Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.

111 lines (109 loc) 4.2 kB
import { InngestEndpointAdapter } from "./components/InngestEndpointAdapter.js"; import { SupportedFrameworkName } from "./types.js"; import { ServeHandlerOptions, SyncHandlerOptions } from "./components/InngestCommHandler.js"; import http from "node:http"; //#region src/node.d.ts /** * The name of the framework, used to identify the framework in Inngest * dashboards and during testing. */ declare const frameworkName: SupportedFrameworkName; /** * Read the incoming message body as text. * * Collects Buffer chunks and decodes once with `Buffer.concat` so multi-byte * UTF-8 characters aren't corrupted when split across chunk boundaries. * Reads via `req.on('data'|'end')` so body-replay wrappers — notably * `@vercel/node`'s `restoreBody()`, which patches only those two events — * deliver the replayed bytes; async-iterator and `readable`-event readers * see an empty body under that wrapper. */ declare function readRequestBody(req: http.IncomingMessage): Promise<string>; /** * Serve and register any declared functions with Inngest, making them available * to be triggered by events. * * @example Serve Inngest functions on all paths * ```ts * import { serve } from "inngest/node"; * import { inngest } from "./src/inngest/client"; * import myFn from "./src/inngest/myFn"; // Your own function * * const server = http.createServer(serve({ * client: inngest, functions: [myFn] * })); * server.listen(3000); * ``` * * @example Serve Inngest on a specific path * ```ts * import { serve } from "inngest/node"; * import { inngest } from "./src/inngest/client"; * import myFn from "./src/inngest/myFn"; // Your own function * * const server = http.createServer((req, res) => { * if (req.url.start === '/api/inngest') { * return serve({ * client: inngest, functions: [myFn] * })(req, res); * } * // ... * }); * server.listen(3000); * ``` * * @public */ declare const serve: (options: ServeHandlerOptions) => http.RequestListener; /** * EXPERIMENTAL - Create an http server to serve Inngest functions. * * @example * ```ts * import { createServer } from "inngest/node"; * import { inngest } from "./src/inngest/client"; * import myFn from "./src/inngest/myFn"; // Your own function * * const server = createServer({ * client: inngest, functions: [myFn] * }); * server.listen(3000); * ``` * * @public */ declare const createServer: (options: ServeHandlerOptions) => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>; type EndpointHandler = (req: Request) => Promise<Response>; /** * Creates a durable endpoint proxy handler for Node.js environments. */ declare function createDurableEndpointProxyHandler(options: InngestEndpointAdapter.ProxyHandlerOptions): http.RequestListener; /** * In a Node.js environment, create a function that can wrap any endpoint to be * able to use steps seamlessly within that API. */ declare const endpointAdapter: ((options: SyncHandlerOptions) => (handler: (...args: any[]) => Promise<any>) => (...args: any[]) => Promise<any>) & InngestEndpointAdapter.Like & { createProxyHandler: typeof createDurableEndpointProxyHandler; }; /** * Bridge a Web API endpoint handler to a Node.js `http.RequestListener`. * * Converts an incoming `http.IncomingMessage` into a Web API `Request`, * invokes the handler, then streams the resulting `Response` back through * the Node.js `http.ServerResponse`. * * Important: uses `value != null` (not `value`) when forwarding headers so * that empty-string headers (like `X-Inngest-Signature: ""` in dev mode) * are preserved. Dropping them breaks `isInngestReq()` detection. */ declare function serveEndpoint(handler: EndpointHandler): http.RequestListener; /** * Create an HTTP server that serves a durable endpoint handler. * * This bridges the Web API `Request`/`Response` interface that Durable * Endpoints use with Node.js's `http.Server`. */ declare function createEndpointServer(handler: EndpointHandler): http.Server; //#endregion export { EndpointHandler, createEndpointServer, createServer, endpointAdapter, frameworkName, readRequestBody, serve, serveEndpoint }; //# sourceMappingURL=node.d.ts.map