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.

1 lines 4.12 kB
{"version":3,"file":"remix.cjs","names":["frameworkName: SupportedFrameworkName","Res: typeof Response","z","InngestCommHandler"],"sources":["../src/remix.ts"],"sourcesContent":["/**\n * An adapter for Remix to serve and register any declared functions with\n * Inngest, making them available to be triggered by events.\n *\n * @example\n * ```ts\n * import { serve } from \"inngest/remix\";\n * import functions from \"~/inngest\";\n *\n * const handler = serve({ id: \"my-remix-app\", functions });\n *\n * export { handler as loader, handler as action };\n * ```\n *\n * @module\n */\n\nimport { z } from \"zod/v3\";\nimport {\n type ActionResponse,\n InngestCommHandler,\n type ServeHandlerOptions,\n} from \"./components/InngestCommHandler.ts\";\nimport type { Env } from \"./helpers/env.ts\";\nimport type { SupportedFrameworkName } from \"./types.ts\";\n\n/**\n * The name of the framework, used to identify the framework in Inngest\n * dashboards and during testing.\n */\nexport const frameworkName: SupportedFrameworkName = \"remix\";\n\nconst createNewResponse = ({\n body,\n status,\n headers,\n}: ActionResponse<string | ReadableStream>): Response => {\n /**\n * If `Response` isn't included in this environment, it's probably a Node env\n * that isn't already polyfilling. In this case, we can polyfill it here to be\n * safe.\n */\n let Res: typeof Response;\n\n if (typeof Response === \"undefined\") {\n Res = require(\"cross-fetch\").Response;\n } else {\n Res = Response;\n }\n\n return new Res(body, {\n status,\n headers,\n });\n};\n\n/**\n * In Remix, serve and register any declared functions with Inngest, making them\n * available to be triggered by events.\n *\n * Remix requires that you export both a \"loader\" for serving `GET` requests,\n * and an \"action\" for serving other requests, therefore exporting both is\n * required.\n *\n * See {@link https://remix.run/docs/en/v1/guides/resource-routes}\n *\n * @example\n * ```ts\n * import { serve } from \"inngest/remix\";\n * import functions from \"~/inngest\";\n *\n * const handler = serve({ id: \"my-remix-app\", functions });\n *\n * export { handler as loader, handler as action };\n * ```\n *\n * @public\n */\n// Has explicit return type to avoid JSR-defined \"slow types\"\nexport const serve = (\n options: ServeHandlerOptions,\n): ((ctx: { request: Request; context?: unknown }) => Promise<Response>) => {\n const contextSchema = z.object({\n env: z.record(z.string(), z.any()),\n });\n\n const handler = new InngestCommHandler({\n frameworkName,\n ...options,\n handler: ({\n request: req,\n context,\n }: {\n request: Request;\n context?: unknown;\n }) => {\n return {\n env: () => {\n const ctxParse = contextSchema.safeParse(context);\n\n if (ctxParse.success && Object.keys(ctxParse.data.env).length) {\n return ctxParse.data.env as Env;\n }\n\n return;\n },\n body: () => req.text(),\n headers: (key) => req.headers.get(key),\n method: () => req.method,\n url: () => new URL(req.url, `https://${req.headers.get(\"host\") || \"\"}`),\n transformResponse: createNewResponse,\n transformStreamingResponse: createNewResponse,\n };\n },\n });\n\n return handler.createHandler();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAaA,gBAAwC;AAErD,MAAM,qBAAqB,EACzB,MACA,QACA,cACuD;;;;;;CAMvD,IAAIC;AAEJ,KAAI,OAAO,aAAa,YACtB,OAAM,QAAQ,cAAc,CAAC;KAE7B,OAAM;AAGR,QAAO,IAAI,IAAI,MAAM;EACnB;EACA;EACD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AA0BJ,MAAa,SACX,YAC0E;CAC1E,MAAM,gBAAgBC,SAAE,OAAO,EAC7B,KAAKA,SAAE,OAAOA,SAAE,QAAQ,EAAEA,SAAE,KAAK,CAAC,EACnC,CAAC;AAgCF,QA9BgB,IAAIC,8CAAmB;EACrC;EACA,GAAG;EACH,UAAU,EACR,SAAS,KACT,cAII;AACJ,UAAO;IACL,WAAW;KACT,MAAM,WAAW,cAAc,UAAU,QAAQ;AAEjD,SAAI,SAAS,WAAW,OAAO,KAAK,SAAS,KAAK,IAAI,CAAC,OACrD,QAAO,SAAS,KAAK;;IAKzB,YAAY,IAAI,MAAM;IACtB,UAAU,QAAQ,IAAI,QAAQ,IAAI,IAAI;IACtC,cAAc,IAAI;IAClB,WAAW,IAAI,IAAI,IAAI,KAAK,WAAW,IAAI,QAAQ,IAAI,OAAO,IAAI,KAAK;IACvE,mBAAmB;IACnB,4BAA4B;IAC7B;;EAEJ,CAAC,CAEa,eAAe"}