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 3.94 kB
{"version":3,"file":"digitalocean.cjs","names":["frameworkName: SupportedFrameworkName","InngestCommHandler"],"sources":["../src/digitalocean.ts"],"sourcesContent":["/**\n * An adapter for DigitalOcean Functions to serve and register any declared\n * functions with Inngest, making them available to be triggered by events.\n *\n * @example\n * ```ts\n * import { serve } from \"inngest/digitalocean\";\n * import { inngest } from \"./src/inngest/client\";\n * import fnA from \"./src/inngest/fnA\"; // Your own function\n *\n * const main = serve({\n * client: inngest,\n * functions: [fnA],\n * // Your digitalocean hostname. This is required otherwise your functions won't work.\n * serveOrigin: \"https://faas-sfo3-your-url.doserverless.co\",\n * // And your DO path, also required.\n * servePath: \"/api/v1/web/fn-your-uuid/inngest\",\n * });\n *\n * // IMPORTANT: Makes the function available as a module in the project.\n * // This is required for any functions that require external dependencies.\n * module.exports.main = main;\n * ```\n *\n * @module\n */\n\nimport {\n type ActionResponse,\n InngestCommHandler,\n type ServeHandlerOptions,\n} from \"./components/InngestCommHandler.ts\";\nimport type { SupportedFrameworkName } from \"./types.ts\";\n\ntype HTTP = {\n headers: Record<string, string>;\n method: string;\n path: string;\n};\n\ntype Main =\n | {\n http?: HTTP;\n // data can include any JSON-decoded post-data, and query args/saerch params.\n [data: string]: unknown;\n }\n | undefined;\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 = \"digitalocean\";\n\n/**\n * In DigitalOcean Functions, 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/digitalocean\";\n * import { inngest } from \"./src/inngest/client\";\n * import fnA from \"./src/inngest/fnA\"; // Your own function\n *\n * const main = serve({\n * client: inngest,\n * functions: [fnA],\n * // Your digitalocean hostname. This is required otherwise your functions won't work.\n * serveOrigin: \"https://faas-sfo3-your-url.doserverless.co\",\n * // And your DO path, also required.\n * servePath: \"/api/v1/web/fn-your-uuid/inngest\",\n * });\n *\n * // IMPORTANT: Makes the function available as a module in the project.\n * // This is required for any functions that require external dependencies.\n * module.exports.main = main;\n * ```\n *\n * @public\n */\n// Has explicit return type to avoid JSR-defined \"slow types\"\nexport const serve = (\n options: ServeHandlerOptions &\n Required<Pick<NonNullable<ServeHandlerOptions>, \"serveOrigin\">>,\n): ((main?: Main) => Promise<ActionResponse<string>>) => {\n const handler = new InngestCommHandler({\n frameworkName,\n ...options,\n handler: (main: Main = {}) => {\n const { http = { method: \"GET\", headers: {}, path: \"\" }, ...data } = main;\n\n return {\n body: () => data || {},\n headers: (key) => http?.headers?.[key],\n method: () => http.method,\n url: () => new URL(`${options.serveOrigin}${options.servePath || \"/\"}`),\n queryString: (key) => main[key] as string,\n transformResponse: (res) => res,\n };\n },\n });\n\n return handler.createHandler();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAaA,gBAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BrD,MAAa,SACX,YAEuD;AAkBvD,QAjBgB,IAAIC,8CAAmB;EACrC;EACA,GAAG;EACH,UAAU,OAAa,EAAE,KAAK;GAC5B,MAAM,EAAE,OAAO;IAAE,QAAQ;IAAO,SAAS,EAAE;IAAE,MAAM;IAAI,EAAE,GAAG,SAAS;AAErE,UAAO;IACL,YAAY,QAAQ,EAAE;IACtB,UAAU,QAAQ,MAAM,UAAU;IAClC,cAAc,KAAK;IACnB,WAAW,IAAI,IAAI,GAAG,QAAQ,cAAc,QAAQ,aAAa,MAAM;IACvE,cAAc,QAAQ,KAAK;IAC3B,oBAAoB,QAAQ;IAC7B;;EAEJ,CAAC,CAEa,eAAe"}