import { createSimplyScanBeacon } from './simplyscan-beacon.mjs';
const beacon=createSimplyScanBeacon({key:Deno.env.get('SIMPLYSCAN_INGEST_KEY')!});
// Wrap the owner's handler. clientIp must come from your trusted hosting adapter.
export function withSimplyScan(handler:(r:Request)=>Promise<Response>,clientIp:(r:Request)=>string){
 return async(req:Request)=>{const res=await handler(req);beacon.record({method:req.method,path:new URL(req.url).pathname,status:res.status,ip:clientIp(req),userAgent:req.headers.get('user-agent')??''});
 EdgeRuntime.waitUntil(beacon.flush().catch(()=>{}));return res;};
}
