async function e(e){if("nodejs"===process.env.NEXT_RUNTIME){const{H:s}=await import("@highlight-run/node");s.init(e)}else console.info(`Highlight not registered: NEXT_RUNTIME=${process.env.NEXT_RUNTIME}`)}import{HIGHLIGHT_REQUEST_HEADER as s,H as t}from"@highlight-run/node";var r={init:e=>{t.isInitialized()||t.init(e)},isInitialized:()=>t.isInitialized(),metrics:(e,s)=>{const r=global.__HIGHLIGHT__;if(r&&!s&&(s=r),!s?.secureSessionId)return console.warn("H.metrics session could not be inferred the handler context.");for(const r of e)t.recordMetric(s.secureSessionId,r.name,r.value,s.requestId,r.tags)}},i=e=>r=>async(i,a)=>{t.isInitialized()||t.init(e);const o=()=>{if(i.headers&&i.headers[s]){const[e,t]=`${i.headers[s]}`.split("/");if(e&&t)return global.__HIGHLIGHT__={secureSessionId:e,requestId:t},{secureSessionId:e,requestId:t}}return{secureSessionId:void 0,requestId:void 0}},{secureSessionId:n,requestId:c}=o(),u=new Date;try{return await r(i,a)}catch(e){throw e instanceof Error&&(t.consumeError(e,n,c),await t.flush()),a.statusCode=500,a.statusMessage="Internal Server Error",e}finally{const e=1e6*((new Date).getTime()-u.getTime()),{secureSessionId:s,requestId:r}=o();s&&(t.recordMetric(s,"latency",e,r),await t.flush())}};import{uploadSourcemaps as a}from"@highlight-run/sourcemap-uploader/dist/lib";var o=async(e,s)=>{const t=await(async(e,s)=>{const t="production"===process.env.NODE_ENV,r=!!process.env.HIGHLIGHT_SOURCEMAP_UPLOAD_API_KEY||!!s?.apiKey;let i=null;if(e.generateBuildId){const s=e.generateBuildId();i="string"==typeof s?s:await s}return{uploadSourceMaps:t&&(s?.uploadSourceMaps??(!e.productionBrowserSourceMaps&&r)),configureHighlightProxy:s?.configureHighlightProxy??!0,apiKey:s?.apiKey??"",appVersion:s?.appVersion??i??"",sourceMapsPath:s?.sourceMapsPath??".next/",sourceMapsBasePath:s?.sourceMapsBasePath??"_next/"}})(e,s);let r=e.rewrites;(t.uploadSourceMaps||t.configureHighlightProxy)&&(r=async()=>{let s;s=e.rewrites?await e.rewrites():new Array;const r={source:"/:path*.map",destination:"/404"},i={source:"/highlight-events",destination:"https://pub.highlight.run"};return!s||Array.isArray(s)?{beforeFiles:t.uploadSourceMaps?[r]:[],afterFiles:t.configureHighlightProxy?(s??[]).concat(i):[],fallback:[]}:{beforeFiles:t.uploadSourceMaps?(s.beforeFiles??[]).concat(r):s.beforeFiles,afterFiles:t.configureHighlightProxy?(s.afterFiles??[]).concat(i):s.afterFiles,fallback:s.fallback}});let i=e.webpack;return t.uploadSourceMaps&&(i=(s,r)=>{let i=s;return e.webpack&&(i=e.webpack(s,r)),i.plugins.push(new class{apiKey;appVersion;path;basePath;constructor(e,s,t,r){this.apiKey=e,this.appVersion=s,this.path=t,this.basePath=r}apply(e){return e.hooks.afterEmit.tap("HighlightWebpackPlugin",(()=>{a({apiKey:this.apiKey,appVersion:this.appVersion,path:this.path,basePath:this.basePath,allowNoop:!0})})),e}}(t.apiKey,t.appVersion,t.sourceMapsPath,t.sourceMapsBasePath)),i}),{...e,productionBrowserSourceMaps:t.uploadSourceMaps||e.productionBrowserSourceMaps,rewrites:r,webpack:i}},n=async(e,s)=>"function"==typeof e?async(t,{defaultConfig:r})=>{const i=e(t,{defaultConfig:r});if("function"==typeof i){const e=await i;return await o(e,s)}return await o(i,s)}:await o(e,s);export{r as H,i as Highlight,e as registerHighlight,n as withHighlightConfig};//# sourceMappingURL=index.mjs.map