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