{"version":3,"file":"server.cjs","sources":["../src/util/highlight-node.ts","../src/server.ts","../src/util/with-highlight-nodejs-page-router.ts","../src/util/with-highlight-nodejs-app-router.ts","../src/util/register-highlight.ts"],"sourcesContent":["import type { HighlightContext, NodeOptions } from '@highlight-run/node'\nimport { H as NodeH } from '@highlight-run/node'\nimport { isNodeJsRuntime } from './is-node-js-runtime'\nimport { HighlightInterface } from './types'\n\nexport type HighlightEnv = NodeOptions\n\nexport declare interface Metric {\n\tname: string\n\tvalue: number\n\ttags?: { name: string; value: string }[]\n}\n\nexport const H: HighlightInterface = {\n\t...NodeH,\n\tinit: (options: NodeOptions) => {\n\t\tif (isNodeJsRuntime()) {\n\t\t\treturn NodeH.init(options)\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Highlight not registered due to unexpected runtime: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`,\n\t\t\t)\n\t\t}\n\t},\n\tinitEdge: () => {\n\t\tthrow new Error(\n\t\t\t'H.initEdge is not supported by the Node runtime. Try H.init instead.',\n\t\t)\n\t},\n\tisInitialized: () => NodeH.isInitialized(),\n\tmetrics: (metrics: Metric[], opts?: HighlightContext) => {\n\t\tif (!opts?.secureSessionId) {\n\t\t\treturn console.warn(\n\t\t\t\t'H.metrics session could not be inferred the handler context.',\n\t\t\t)\n\t\t}\n\t\tfor (const m of metrics) {\n\t\t\tconst tags = [...(m.tags ?? [])]\n\t\t\tif (opts.secureSessionId) {\n\t\t\t\ttags.push({\n\t\t\t\t\tname: 'highlight.session_id',\n\t\t\t\t\tvalue: opts.secureSessionId,\n\t\t\t\t})\n\t\t\t}\n\t\t\tif (opts.requestId) {\n\t\t\t\ttags.push({\n\t\t\t\t\tname: 'highlight.trace_id',\n\t\t\t\t\tvalue: opts.requestId,\n\t\t\t\t})\n\t\t\t}\n\t\t\tNodeH.recordMetric({\n\t\t\t\t...m,\n\t\t\t\ttags,\n\t\t\t})\n\t\t}\n\t},\n}\n","import * as withHighlightNodeJsAppRouter from './util/with-highlight-nodejs-app-router'\nimport * as withHighlightNodeJsPageRouter from './util/with-highlight-nodejs-page-router'\n\nimport { isNodeJsRuntime } from './util/is-node-js-runtime'\nimport type { HighlightEnv } from './util/types'\nimport type {\n\tEdgeHandler,\n\tNextRequest,\n\tNextFetchEvent,\n} from './util/with-highlight-edge'\n\nexport { H } from '@highlight-run/node' // Imports from server.edge.ts for the edge runtime\nexport { highlightMiddleware } from './util/highlight-middleware'\nexport { isNodeJsRuntime } from './util/is-node-js-runtime'\nexport { registerHighlight } from './util/register-highlight'\nexport type { HighlightEnv } from './util/types'\n\ntype PageRouterHighlightHandler = ReturnType<\n\ttypeof withHighlightNodeJsPageRouter.Highlight\n>\n\nexport const Highlight = PageRouterHighlight\nexport function PageRouterHighlight(\n\tenv: HighlightEnv,\n): PageRouterHighlightHandler {\n\tif (isNodeJsRuntime()) {\n\t\treturn withHighlightNodeJsPageRouter.Highlight(env)\n\t} else {\n\t\tthrow new Error(\n\t\t\t`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`,\n\t\t)\n\t}\n}\n\nexport function AppRouterHighlight(env: HighlightEnv) {\n\tif (isNodeJsRuntime()) {\n\t\treturn withHighlightNodeJsAppRouter.Highlight(env)\n\t} else {\n\t\tthrow new Error(\n\t\t\t`unidentified NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`,\n\t\t)\n\t}\n}\n\nexport function EdgeHighlight(\n\t_: HighlightEnv,\n): (\n\thandler: EdgeHandler,\n) => (request: NextRequest, context: NextFetchEvent) => Promise<Response> {\n\tthrow new Error(`unsupported NEXT_RUNTIME: ${process.env.NEXT_RUNTIME}`)\n}\n","import { NodeOptions } from '@highlight-run/node'\nimport { H } from './highlight-node'\n\nimport type { IncomingHttpHeaders } from 'http'\n\nexport declare type HasHeaders = {\n\theaders: IncomingHttpHeaders\n\tmethod?: string\n\turl?: string\n}\nexport declare type HasStatus = {\n\treadonly statusCode: number\n\treadonly statusMessage: string\n\tstatus: (statusCode: number) => HasStatus\n\tsend: (body: string) => void\n}\nexport declare type ApiHandler<T extends HasHeaders, S extends HasStatus> = (\n\treq: T,\n\tres: S,\n) => unknown | Promise<unknown>\n\nexport const Highlight =\n\t(options: NodeOptions) =>\n\t<T extends HasHeaders, S extends HasStatus>(\n\t\toriginalHandler: ApiHandler<T, S>,\n\t): ApiHandler<T, S> => {\n\t\tconst NodeH = H.init(options)\n\n\t\treturn async (req, res) => {\n\t\t\tif (!NodeH) throw new Error('Highlight not initialized')\n\n\t\t\treturn await H.runWithHeaders(\n\t\t\t\t`${req.method?.toUpperCase()} - ${req.url}`,\n\t\t\t\treq.headers,\n\t\t\t\tasync () => {\n\t\t\t\t\treturn await originalHandler(req, res)\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n// this code was assisted by https://github.com/getsentry/sentry-javascript/blob/2f2d099dcc668f12109913caf36097f73a1bc966/packages/nextjs/src/utils/withSentry.ts\n","import { H, NodeOptions } from '@highlight-run/node'\n\ntype NextContext = {\n\tparams: Promise<Record<string, string>>\n}\ntype NextHandler = (request: Request, context: NextContext) => Promise<Response>\n\nexport function Highlight(options: NodeOptions) {\n\tconst NodeH = H.init(options)\n\n\treturn (originalHandler: NextHandler) =>\n\t\tasync (request: Request, context: NextContext) => {\n\t\t\tif (!NodeH) throw new Error('Highlight not initialized')\n\n\t\t\treturn await H.runWithHeaders<Promise<Response>>(\n\t\t\t\t`${request.method?.toUpperCase()} - ${request.url}`,\n\t\t\t\trequest.headers as any,\n\t\t\t\tasync () => originalHandler(request, context),\n\t\t\t)\n\t\t}\n}\n","import type { NodeOptions } from '@highlight-run/node'\nimport { isNodeJsRuntime } from './is-node-js-runtime'\n\nexport async function registerHighlight(nodeOptions: NodeOptions) {\n\tif (isNodeJsRuntime()) {\n\t\tconst { H } = await import('@highlight-run/node')\n\n\t\tH.init(nodeOptions)\n\t} else {\n\t\tconsole.info(\n\t\t\t`Highlight not registered: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`,\n\t\t)\n\t}\n}\n"],"names":["H","NodeH","init","options","isNodeJsRuntime","Error","process","env","NEXT_RUNTIME","initEdge","isInitialized","metrics","opts","secureSessionId","console","warn","m","tags","push","name","value","requestId","recordMetric","Highlight","PageRouterHighlight","originalHandler","async","req","res","runWithHeaders","method","toUpperCase","url","headers","request","context","withHighlightNodeJsAppRouter.Highlight","_","nodeOptions","import","info"],"mappings":"wHAaO,MAAMA,EAAwB,IACjCC,EAAAA,EACHC,KAAOC,IACN,GAAIC,EAAAA,kBACH,OAAOH,EAAAA,EAAMC,KAAKC,GAElB,MAAM,IAAIE,MACT,oEAAoEC,QAAQC,IAAIC,eAElF,EAEDC,SAAU,KACT,MAAM,IAAIJ,MACT,uEACA,EAEFK,cAAe,IAAMT,EAAAA,EAAMS,gBAC3BC,QAAS,CAACA,EAAmBC,KAC5B,IAAKA,GAAMC,gBACV,OAAOC,QAAQC,KACd,gEAGF,IAAK,MAAMC,KAAKL,EAAS,CACxB,MAAMM,EAAO,IAAKD,EAAEC,MAAQ,IACxBL,EAAKC,iBACRI,EAAKC,KAAK,CACTC,KAAM,uBACNC,MAAOR,EAAKC,kBAGVD,EAAKS,WACRJ,EAAKC,KAAK,CACTC,KAAM,qBACNC,MAAOR,EAAKS,YAGdpB,EAAAA,EAAMqB,aAAa,IACfN,EACHC,QAEF,ICjCK,MAAMM,EAAYC,EACnB,SAAUA,EACfjB,GAEA,GAAIH,EAAAA,kBACH,OCJAD,EDI+CI,ECF/CkB,IAEA,MAAMxB,EAAQD,EAAEE,KAAKC,GAErB,OAAOuB,MAAOC,EAAKC,KAClB,IAAK3B,EAAO,MAAM,IAAII,MAAM,6BAE5B,aAAaL,EAAE6B,eACd,GAAGF,EAAIG,QAAQC,mBAAmBJ,EAAIK,MACtCL,EAAIM,SACJP,eACcD,EAAgBE,EAAKC,IAEnC,CACD,EDVD,MAAM,IAAIvB,MACT,8BAA8BC,QAAQC,IAAIC,gBCP5C,IAACL,CDUF,sMAEM,SAA6BI,GAClC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