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.31 kB
Source Map (JSON)
{"version":3,"file":"hono.cjs","names":["frameworkName: SupportedFrameworkName","InngestCommHandler","scheme: \"http\" | \"https\""],"sources":["../src/hono.ts"],"sourcesContent":["/**\n * An adapter for Hono to serve and register any declared functions with\n * Inngest, making them available to be triggered by events.\n *\n * @example\n * ```ts\n * const handler = serve({\n * client: inngest,\n * functions\n * });\n *\n * app.use('/api/inngest', async (c) => {\n * return handler(c);\n * });\n * ```\n *\n * @module\n */\n\nimport type { Context } from \"hono\";\nimport { env } from \"hono/adapter\";\nimport {\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 = \"hono\";\n\n/**\n * Using Hono, serve and register any declared functions with Inngest,\n * making them available to be triggered by events.\n *\n * @example\n * ```ts\n * const handler = serve({\n * client: inngest,\n * functions\n * });\n *\n * app.use('/api/inngest', async (c) => {\n * return handler(c);\n * });\n * ```\n *\n * @public\n */\n// Has explicit return type to avoid JSR-defined \"slow types\"\nexport const serve = (\n options: ServeHandlerOptions,\n): ((c: Context) => Promise<Response>) => {\n const handler = new InngestCommHandler({\n frameworkName,\n ...options,\n handler: (c: Context) => {\n return {\n transformResponse: ({ headers, status, body }) => {\n return c.body(body, { headers, status });\n },\n url: () => {\n try {\n // If this is an absolute URL, use it right now.\n return new URL(c.req.url);\n } catch {\n // no-op\n }\n\n // We now know that `c.req.url` is a relative URL, so let's try\n // to build a base URL to pair it with.\n const host = options.serveOrigin || c.req.header(\"host\");\n if (!host) {\n throw new Error(\n \"No host header found in request and no `serveOrigin` given either.\",\n );\n }\n\n let baseUrl = host;\n // Only set the scheme if we don't already have one, as a user may\n // have specified the protocol in `serveOrigin` as a way to force it\n // in their environment, e.g. for testing.\n if (!baseUrl.includes(\"://\")) {\n let scheme: \"http\" | \"https\" = \"https\";\n try {\n // If we're in dev, assume `http` instead. Not that we directly\n // access the environment instead of using any helpers here to\n // ensure compatibility with tools with Webpack which will replace\n // this with a literal.\n if (process.env.NODE_ENV !== \"production\") {\n scheme = \"http\";\n }\n } catch (_err) {\n // no-op\n }\n\n baseUrl = `${scheme}://${baseUrl}`;\n }\n\n return new URL(c.req.url, baseUrl);\n },\n queryString: (key) => c.req.query(key),\n headers: (key) => c.req.header(key),\n method: () => c.req.method,\n body: () => c.req.text(),\n env: () => env(c) as Env,\n };\n },\n });\n\n return handler.createHandler();\n};\n"],"mappings":";;;;;;;;;AAgCA,MAAaA,gBAAwC;;;;;;;;;;;;;;;;;;;AAqBrD,MAAa,SACX,YACwC;AA0DxC,QAzDgB,IAAIC,8CAAmB;EACrC;EACA,GAAG;EACH,UAAU,MAAe;AACvB,UAAO;IACL,oBAAoB,EAAE,SAAS,QAAQ,WAAW;AAChD,YAAO,EAAE,KAAK,MAAM;MAAE;MAAS;MAAQ,CAAC;;IAE1C,WAAW;AACT,SAAI;AAEF,aAAO,IAAI,IAAI,EAAE,IAAI,IAAI;aACnB;KAMR,MAAM,OAAO,QAAQ,eAAe,EAAE,IAAI,OAAO,OAAO;AACxD,SAAI,CAAC,KACH,OAAM,IAAI,MACR,qEACD;KAGH,IAAI,UAAU;AAId,SAAI,CAAC,QAAQ,SAAS,MAAM,EAAE;MAC5B,IAAIC,SAA2B;AAC/B,UAAI;AAKF,WAAI,QAAQ,IAAI,aAAa,aAC3B,UAAS;eAEJ,MAAM;AAIf,gBAAU,GAAG,OAAO,KAAK;;AAG3B,YAAO,IAAI,IAAI,EAAE,IAAI,KAAK,QAAQ;;IAEpC,cAAc,QAAQ,EAAE,IAAI,MAAM,IAAI;IACtC,UAAU,QAAQ,EAAE,IAAI,OAAO,IAAI;IACnC,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI,MAAM;IACxB,iCAAe,EAAE;IAClB;;EAEJ,CAAC,CAEa,eAAe"}