1const e=new class{constructor(e={}){this._contributors=new Map,this._collectTimeoutMs=e.collectTimeoutMs??250}register({namespace:e,collect:t}={}){if(!e||"string"!=typeof e)throw new Error("DiagnosticsContext.register: a string `namespace` is required");if("function"!=typeof t)throw new Error(`DiagnosticsContext.register: \`collect\` must be a function for "${e}"`);this._contributors.has(e)&&console.warn(`DiagnosticsContext: contributor for "${e}" re-registered; replacing previous.`),this._contributors.set(e,t)}unregister(e){this._contributors.delete(e)}clear(){this._contributors.clear()}async assemble(){const e=[...this._contributors.keys()],t=await Promise.all(e.map(e=>this._collectOne(e,this._contributors.get(e)))),n={};return e.forEach((e,r)=>{const o=t[r];n[e]=o.ok?o.value:{error:o.error}}),n}async _collectOne(e,t){try{const n=await this._withTimeout(Promise.resolve().then(()=>t()),e);return n&&"object"==typeof n?{ok:!0,value:n}:{ok:!1,error:"contributor returned a non-object"}}catch(e){return{ok:!1,error:e&&e.message?e.message:String(e)}}}_withTimeout(e,t){return this._collectTimeoutMs>0?new Promise((n,r)=>{const o=setTimeout(()=>{r(new Error(`contributor "${t}" timed out after ${this._collectTimeoutMs}ms`))},this._collectTimeoutMs);e.then(e=>{clearTimeout(o),n(e)},e=>{clearTimeout(o),r(e)})}):e}};function t(e,t,n,r=null,o=null){return{t:0,level:e,category:t,event:void 0,msg:"string"==typeof n?n:null,data:"string"==typeof n?null:n,tags:r||void 0,route:void 0,trace_id:o||void 0}}function n(e,t){return()=>{const n=e.indexOf(t);-1!==n&&e.splice(n,1)}}const r="[REDACTED]",o=Object.freeze(["authorization","cookie","token","access_token","refresh_token","password","secret","api_key","apikey","credentials","session","sessionid","session_id"]);function s(e){return function(e){const t=e.split(".");return 3===t.length&&!!t[0].startsWith("eyJ")&&t.every(e=>e.length>=8&&/^[A-Za-z0-9_-]+$/.test(e))}(e)||function(e){return e.length>32&&/^[A-Za-z0-9+/=_-]+$/.test(e)}(e)}function i(e,t){if(null==e)return e;if("object"!=typeof e)return"string"==typeof e&&s(e)?r:e;if(Array.isArray(e))return e.map(e=>i(e,t));const n={};for(const[o,c]of Object.entries(e)){const e=o.toLowerCase();t.some(t=>e.includes(t.toLowerCase()))?n[o]=r:"object"==typeof c&&null!==c?n[o]=i(c,t):"string"==typeof c&&s(c)?n[o]=r:n[o]=c}return n}const c=/eyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}/g;function l(e,t){const n={...e};var o;return e.data&&(n.data=i(e.data,t.keys)),"string"==typeof e.msg&&(n.msg="string"!=typeof(o=e.msg)?o:s(o)?r:o.replace(c,r)),n}function a(e){return"warn"===e.level||"error"===e.level||("exception"===e.category||"breadcrumb"===e.category||!(!Array.isArray(e.tags)||!e.tags.includes("breadcrumb")))}function u(e){if(null==e)return 0;if("string"==typeof e)return e.length;if("number"==typeof e)return 8;if("boolean"==typeof e)return 1;if(Array.isArray(e))return e.reduce((e,t)=>e+u(t),0);if("object"==typeof e){let t=0;for(const[n,r]of Object.entries(e))t+=n.length+u(r);return t}return 0}class d{constructor(){this.items=[],this.head=0}get length(){return this.items.length-this.head}push(e){this.items.push(e)}shift(){if(this.head>=this.items.length)return;const e=this.items[this.head];return this.items[this.head]=void 0,this.head+=1,this.head>64&&2*this.head>this.items.length&&(this.items=this.items.slice(this.head),this.head=0),e}at(e){return this.items[this.head+e]}clear(){this.items=[],this.head=0}}class h{constructor(e){this.protectedTier=new d,this.unprotectedTier=new d,this.nextSeq=0,this.bytes=0,this.maxEvents=e.maxEvents,this.maxBytes=e.maxBytes}get length(){return this.protectedTier.length+this.unprotectedTier.length}push(e){const t=u(e);for(;this.length>=this.maxEvents&&this.evictOne(););for(;this.bytes+t>this.maxBytes&&this.length>0&&this.evictOne(););const n={seq:this.nextSeq,size:t,event:e};this.nextSeq+=1,a(e)?this.protectedTier.push(n):this.unprotectedTier.push(n),this.bytes+=t}all(){const e=[],t=this.protectedTier.length,n=this.unprotectedTier.length;let r=0,o=0;for(;r<t&&o<n;){const t=this.protectedTier.at(r),n=this.unprotectedTier.at(o);t.seq<n.seq?(e.push(t.event),r+=1):(e.push(n.event),o+=1)}for(;r<t;r+=1)e.push(this.protectedTier.at(r).event);for(;o<n;
1o+=1)e.push(this.unprotectedTier.at(o).event);return e}query(e){return this.all().filter(t=>void 0===e.prefix||(t.event??"").startsWith(e.prefix)).filter(t=>void 0===e.since||t.t>=e.since).filter(t=>void 0===e.category||t.category===e.category).filter(t=>void 0===e.level||t.level===e.level).map(e=>JSON.parse(JSON.stringify(e)))}stats(){return{buffered:this.length,bytes:this.bytes,protected:this.protectedTier.length}}clear(){this.protectedTier.clear(),this.unprotectedTier.clear(),this.bytes=0}evictOne(){const e=this.unprotectedTier.shift()??this.protectedTier.shift();return!!e&&(this.bytes-=e.size,!0)}}function f(e){const t=[];let n=0;const r=e=>{if(t.length>=400)return;const r=u(e);n+r>524288||(t.push(e),n+=r)};for(let t=e.length-1;t>=0;t--)a(e[t])&&r(e[t]);for(let t=e.length-1;t>=0;t--)a(e[t])||r(e[t]);return t.sort((e,t)=>e.t-t.t)}function g(e){return"object"==typeof e&&null!==e}function p(e){let t=!1,n=null,r=0,o=!1,s=!1;const i=({clean:n=!1}={})=>{if(t||n)try{e.store.write(function(e){const t={v:1,endedAt:e.endedAt,clean:e.clean,build:e.build,events:f(e.events)};return JSON.stringify(t)}({endedAt:e.clock(),clean:n||s,build:e.buildId,events:e.events()})),t=!1,r=e.clock()}catch(t){e.console()?.warn("Logging: log persist failed:",t)}},c=()=>{s=!0,i({clean:!0})},l=()=>c(),a=()=>{"hidden"===e.document.visibilityState?c():s=!1};return e.target.addEventListener("pagehide",l),e.document.addEventListener("visibilitychange",a),{write(s){if(o)return;t=!0;const c="error"===s.level||"exception"===s.category;c&&e.clock()-r>=250?i():null===n&&(n=e.setTimer(()=>{n=null,i()},c?250:2e3))},dispose(){o=!0,null!==n&&(e.clearTimer(n),n=null),e.target.removeEventListener("pagehide",l),e.document.removeEventListener("visibilitychange",a)}}}function m(){let e=null,t=null;return{restore(t){let n=null;try{n=t.read()}catch(e){return}t.clear(),e=function(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}if(!g(t))return null;const n=(Array.isArray(t.events)?t.events:[]).filter(e=>g(e)&&Number.isFinite(e.t)).slice(-400);if(0===n.length)return null;const r=t.endedAt,o=t.build;return{events:n,endedAt:"number"==typeof r&&Number.isFinite(r)?r:n[n.length-1].t,clean:!1!==t.clean,build:"string"==typeof o&&o?o:null}}(n)},setPreviousTermination(e){t=e&&"object"==typeof e?e:null},info(n){const r=t?{terminated:t}:{};return e?{...r,present:!0,events:e.events.length,ended_at:new Date(e.endedAt).toISOString(),clean:!1!==e.clean,build_changed:Boolean(e.build&&n&&e.build!==n)}:{present:!1,...r}},slice:()=>e}}const v="2.1.0";function y(e){if(!e||0===e.events.length)return[];const t=e.events.map(e=>JSON.stringify({...e,prev:!0}));return t.push(JSON.stringify({t:e.endedAt,level:"info",category:"lifecycle",event:"session.previous_end",msg:"--- end of previous session (recovered from disk) ---",data:{events:e.events.length,ended_at:new Date(e.endedAt).toISOString()}})),t}function b(e){const t=[];return{registerHook(e){"function"==typeof e&&t.push(e)},async snapshot(n={}){const r=n.minutes??20,o=e.clock()-60*r*1e3;await(async()=>{t.length&&await Promise.allSettled(t.map(t=>{let n=null;const r=new Promise(t=>{n=e.setTimer(t,400)});return Promise.race([Promise.resolve().then(t),r]).catch(()=>{}).finally(()=>{null!==n&&e.clearTimer(n)})}))})();const s=e.events().filter(e=>e.t>=o).sort((e,t)=>e.t-t.t);let i;try{i=await e.assembleContext()}catch(t){e.console()?.warn("Logging: client context assembly failed:",t),i={error:"context assembly failed"}}var c;const l=function(e){return[JSON.stringify(e.header),...y(e.previous),...e.events.map(e=>JSON.stringify(e))].join("\n")}({header:(c={createdAt:new Date(e.clock()).toISOString(),clientContext:i,capture:n.capture},{schema_version:v,created_at:c.createdAt,...c.capture?{capture:c.capture}:{},client_context:c.clientContext}),previous:e.previous(),events:s}),a=new Blob([l],{type:"application/x-ndjson"});return{contentType:"application/x-ndjson",filename:"logs.ndjson",bytes:a.size,body:a,schema_version:v,client_context:i}}}}const w=[["log","debug",!1],["info","info",!1],["debug","debug",!1],["trace","debug",!1],["warn","warn",!0],["error","error",!0]];function T(e){if(0===e.length)return null;if(1===e.length){const t=e[0];return"string"==typeof t||"object"==typeof t&&null!==t?t:String(t)}const t=[];for(const n of e)"string"==typeof n||"object"==typeof n&&null!==n?t.push(n):t.push(String(n));return 1===t.length?t[0]:t}const x={structured:!0},k={structured:!1};const S=function(e={}){const r=e.clock??(()=>Date.now()),s=e.setTimer??((e,t)=>setTimeout(e,t)),i=e.clearTimer??(e=>clearTimeout(e)),c=e.console??globalThis.console,a=e.target,u=e.assemble
1Context??(async()=>({}));let d=!1,f=null,g=null,v=null,y=null;const S=()=>g?.originals??c,_=new h({maxEvents:e.maxEvents??1e3,maxBytes:e.maxBytes??5242880}),E=function(e=[]){return{keys:[...o,...e]}}(e.redactKeys??[]),A=function(){let e=null;const t=[];return{write(n){if("exception"!==n.category||!n.data)return;const r=n.data;e={message:r.message||r.reason||null,stack:r.stack||null,source:r.source||"unhandled_exception",at:n.t};for(const n of[...t])try{n(e)}catch(e){}},onException(e){if("function"!=typeof e)throw new Error("Logging: onException requires a function");return t.push(e),()=>{const n=t.indexOf(e);-1!==n&&t.splice(n,1)}},getLastException(){if(!e)return null;const{message:t,stack:n,source:r,at:o}=e;return{message:t??null,stack:n?String(n).slice(0,4e3):null,source:r||"unhandled_exception",at:new Date(o).toISOString()}}}}(),O=m(),L=function(e){const t=[],r=[];return{write(n,o){let s=n;for(const e of t)s=e(s,o);const i={...o,draft:n};for(const t of[...r])try{t.write(s,i)}catch(t){e.console.warn("Logging: sink failed:",t)}},addProcessor:e=>(t.push(e),n(t,e)),addSink:e=>(r.push(e),n(r,e)),dispose(){for(const t of[...r])try{t.dispose?.()}catch(t){e.console.warn("Logging: sink dispose failed:",t)}}}}({console:{warn:(...e)=>S().warn(...e)}});L.addProcessor(e=>l(e,E)),L.addProcessor(function(e){return(t,n)=>{const r={...t,t:e.clock()};return n.structured&&(r.route=e.location()?.pathname),r}}({clock:r,location:()=>a?.location})),L.addSink(A),L.addSink({write:e=>_.push(e)}),L.addSink({write:(e,t)=>y?.write(e,t),dispose:()=>{y?.dispose?.(),y=null}}),L.addSink(function(e){return{write(t,n){if(!n.structured)return;if("warn"!==t.level&&"error"!==t.level&&!e.isVerbose())return;const r=e.console();if(!r)return;const o=n.draft??t,s=r[t.level]||r.log,i=`[${t.category}] ${o.event||o.msg||""}`;null!=o.data?s(i,o.data):s(i)}}}({console:()=>g?.originals??null,isVerbose:()=>d}));const j=b({clock:r,events:()=>_.all(),previous:()=>O.slice(),assembleContext:u,console:S,setTimer:s,clearTimer:i}),C=(e={})=>{g?c.warn("Logging: Already initialized"):(d=!!e.verbose,f="string"==typeof e.buildId&&e.buildId?e.buildId:null,e.store&&(O.restore(e.store),a?.document&&(y=p({store:e.store,buildId:f,clock:r,setTimer:s,clearTimer:i,target:a,document:a.document,console:S,events:()=>_.all()}))),g=function(e){const t=e.console,n={};for(const[r,o,s]of w){const i=t[r];n[r]=i,t[r]=(...n)=>{(s||e.isVerbose())&&i.apply(t,n),e.write(o,T(n))}}return{originals:n,uninstall(){for(const[e]of w)t[e]=n[e]}}}({console:c,isVerbose:()=>d,write:(e,n)=>L.write(t(e,"console",n),k)}),a&&(v=function(e){const t=t=>{const n=t,r=n.error;e.write({message:String(n.message),source:String(n.filename),lineno:n.lineno,colno:n.colno,stack:r?.stack,error:r?.toString()})},n=t=>{const n=t.reason;e.write({message:"Unhandled Promise Rejection",reason:n?.toString(),stack:n?.stack})};return e.target.addEventListener("error",t),e.target.addEventListener("unhandledrejection",n),()=>{e.target.removeEventListener("error",t),e.target.removeEventListener("unhandledrejection",n)}}({target:a,write:e=>L.write(t("error","exception",e),k)})))};return{install:C,init:C,dispose(){g&&(v?.(),v=null,L.dispose(),g.uninstall(),g=null)},setVerbose(e){d=!!e},addStructured(e){L.write(function({level:e="info",category:t,event:n=null,msg:r=null,data:o=null,tags:s=null}){let i=null;return o&&"object"==typeof o?i=o:null!=o&&(i={value:o}),{t:0,level:e,category:t,event:n||void 0,msg:null!=r?r:n||null,data:i,tags:s||void 0,route:void 0,trace_id:void 0}}(e),x)},addBreadcrumb(e,n,r=null){L.write(function(e,n,r=null){return t("info","breadcrumb",function(e,t){return null!==t?{msg:e,...t}:e}(n,r),[e])}(e,n,r),k)},onException:e=>A.onException(e),getLastException:()=>A.getLastException(),registerPreSnapshotHook:e=>j.registerHook(e),getLevelCounts(){let e=0,t=0,n=0;const r=_.all();for(const o of r)"error"===o.level?e+=1:"warn"===o.level&&(t+=1),"exception"===o.category&&(n+=1);return{errors:e,warns:t,exceptions:n,buffered:r.length}},getPreviousSessionInfo:()=>O.info(f),setPreviousTermination:e=>O.setPreviousTermination(e),snapshot:e=>j.snapshot(e),query:(e={})=>_.query(e),stats:()=>_.stats(),clear:()=>_.clear()}}
1({target:"undefined"!=typeof window?window:void 0,assembleContext:()=>e.assemble()}),_=Object.freeze({NAVIGATION:"navigation",HTTP:"http",AUTH:"auth",LIFECYCLE:"lifecycle",NATIVE:"native",DOMAIN:"domain",RENDER:"render",PERF:"perf",EXCEPTION:"exception",ANALYTICS:"analytics",CONSOLE:"console"}),E=new Set(Object.values(_));function A(e){if(!function(e){return E.has(e)}(e))throw new Error(`createLogger: unknown category "${e}". Use a LogCategory value.`);const t=(t,n,r)=>{S.addStructured({level:t,category:e,event:n,data:r??null})};return{debug:(e,n)=>t("debug",e,n),info:(e,n)=>t("info",e,n),warn:(e,n)=>t("warn",e,n),error:(e,n)=>t("error",e,n),event:(e,n)=>t("info",e,n),breadcrumb:(t,n)=>S.addStructured({level:"info",category:e,event:t,data:n??null,tags:["breadcrumb"]})}}var O=Object.freeze({__proto__:null,createLogger:A,default:A});export{_ as L,O as a,A as c,e as d,S as l};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.