@aiolaapp/logger 0.1.8 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,22 +1,11 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var b=Object.create;var h=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var _=(e,o,n,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of v(o))!$.call(e,r)&&r!==n&&h(e,r,{get:()=>o[r],enumerable:!(s=k(o,r))||s.enumerable});return e};var x=(e,o,n)=>(n=e!=null?b(I(e)):{},_(o||!e||!e.__esModule?h(n,"default",{value:e,enumerable:!0}):n,e));var c=x(require("fs")),m=x(require("path")),A=require("child_process"),j="https://aiola.app/api/sourcemaps-upload";function w(e){let o={};for(let n of e)if(n.startsWith("--")){let[s,...r]=n.slice(2).split("=");o[s]=r.join("=")||"true"}return{dir:o.dir,release:o.release,apiKey:o["api-key"]||o.apiKey,endpoint:o.endpoint}}function E(e){return e||process.env.AIOLA_API_KEY||process.env.AIOLA_KEY||process.env.NEXT_PUBLIC_AIOLA_KEY||process.env.VITE_AIOLA_KEY||null}function K(e){if(e)return e;try{let o=(0,A.execSync)("git rev-parse --short HEAD",{encoding:"utf8",timeout:5e3}).trim();if(o)return o}catch{}try{let o=JSON.parse(c.default.readFileSync("package.json","utf8"));if(o.version)return o.version}catch{}return"unknown"}function N(e){if(e)return c.default.existsSync(e)?e:(console.error(` Directory not found: ${e}`),null);let o=[".next/static","dist","build/static","out",".output"];for(let n of o)if(c.default.existsSync(n))return n;return null}function O(e,o=5){let n=[];function s(r,i){if(!(i>o))try{let l=c.default.readdirSync(r,{withFileTypes:!0});for(let t of l){let a=m.default.join(r,t.name);t.isDirectory()&&!t.name.startsWith(".")&&t.name!=="node_modules"?s(a,i+1):t.isFile()&&t.name.endsWith(".map")&&n.push(a)}}catch{}}return s(e,0),n}async function P(e,o,n,s){let r=0,i=0,l=5;for(let t=0;t<e.length;t+=l){let a=e.slice(t,t+l),u=new FormData;u.append("release",n);for(let p of a){let f=c.default.readFileSync(p),d=m.default.basename(p),g="";try{let y=JSON.parse(f.toString("utf8"));y.file&&(g=y.file)}catch{}g||(g=d.replace(/\.map$/,""));let S=new Blob([f],{type:"application/json"});u.append("file",S,d),g&&u.append(`url:${d}`,g)}try{let p=await fetch(s,{method:"POST",headers:{"x-aiola-key":o},body:u});if(p.ok){let f=await p.json();r+=f.uploaded||a.length;for(let d of a)console.log(` \u2713 ${m.default.relative(".",d)}`)}else{let f=await p.json().catch(()=>({error:p.statusText}));i+=a.length;for(let d of a)console.log(` \u2717 ${m.default.relative(".",d)} \u2014 ${f.error||"upload failed"}`)}}catch(p){i+=a.length,console.error(` \u2717 Network error: ${p}`)}}return{uploaded:r,failed:i}}async function D(){let e=process.argv.slice(2);e[0]!=="upload-sourcemaps"&&(console.log(`
3
- Aiola Logger CLI
4
-
5
- Commands:
6
- upload-sourcemaps Upload source maps for a release
7
-
8
- Options:
9
- --dir=<path> Build output directory (auto-detects .next, dist, build)
10
- --release=<version> Release version (auto-detects from git SHA or package.json)
11
- --api-key=<key> API key (reads from AIOLA_API_KEY env var)
12
- --endpoint=<url> Upload endpoint (default: Aiola cloud)
13
-
14
- Example:
15
- npx @aiolaapp/logger upload-sourcemaps
16
- npx @aiolaapp/logger upload-sourcemaps --dir=.next/static --release=1.0.0
17
- `),process.exit(0));let n=w(e.slice(1));console.log(`
2
+ "use strict";var $=Object.create;var S=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var I=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!w.call(t,n)&&n!==o&&S(t,n,{get:()=>e[n],enumerable:!(i=k(e,n))||i.enumerable});return t};var A=(t,e,o)=>(o=t!=null?$(_(t)):{},I(e||!t||!t.__esModule?S(o,"default",{value:t,enumerable:!0}):o,t));var s=A(require("fs")),f=A(require("path")),j=require("child_process"),D="https://aiola.app/api/sourcemaps-upload";function K(t){let e={};for(let o of t)if(o.startsWith("--")){let[i,...n]=o.slice(2).split("=");e[i]=n.join("=")||"true"}return{dir:e.dir,release:e.release,apiKey:e["api-key"]||e.apiKey,endpoint:e.endpoint}}function O(t){return t||process.env.AIOLA_API_KEY||process.env.AIOLA_KEY||process.env.NEXT_PUBLIC_AIOLA_KEY||process.env.VITE_AIOLA_KEY||null}function b(t){if(t)return t;try{let e=(0,j.execSync)("git rev-parse --short HEAD",{encoding:"utf8",timeout:5e3}).trim();if(e)return e}catch{}try{let e=JSON.parse(s.default.readFileSync("package.json","utf8"));if(e.version)return e.version}catch{}return"unknown"}function E(t){if(t)return s.default.existsSync(t)?t:null;for(let e of[".next/static","dist","build/static","out",".output"])if(s.default.existsSync(e))return e;return null}function v(t){let e=[];function o(i,n){if(!(n>5))try{for(let r of s.default.readdirSync(i,{withFileTypes:!0})){let u=f.default.join(i,r.name);r.isDirectory()&&!r.name.startsWith(".")&&r.name!=="node_modules"?o(u,n+1):r.isFile()&&r.name.endsWith(".js.map")&&e.push(u)}}catch{}}return o(t,0),e}async function F(){let t=process.argv.slice(2);t[0]!=="upload-sourcemaps"&&(console.log(`
3
+ Usage: npx @aiolaapp/logger upload-sourcemaps [--dir=.next] [--release=1.0.0]
4
+ `),process.exit(0));let e=K(t.slice(1));console.log(`
18
5
  Aiola Source Map Upload
19
- `);let s=E(n.apiKey);s||(console.error(" \u2717 No API key found. Set AIOLA_API_KEY environment variable or use --api-key=<key>"),process.exit(0));let r=K(n.release);console.log(` Release: ${r}`);let i=N(n.dir);i||(console.error(" \u2717 No build directory found. Run your build first, or specify --dir=<path>"),process.exit(0)),console.log(` Directory: ${i}`);let l=O(i);l.length===0&&(console.error(` \u2717 No .map files found in ${i}`),console.error(""),console.error(" Your build is not generating source maps. Enable them:"),console.error(""),c.default.existsSync("next.config.mjs")||c.default.existsSync("next.config.js")||c.default.existsSync("next.config.ts")?(console.error(" Next.js \u2014 add to next.config:"),console.error(" productionBrowserSourceMaps: true,")):c.default.existsSync("vite.config.ts")||c.default.existsSync("vite.config.js")?(console.error(" Vite \u2014 add to vite.config:"),console.error(" build: { sourcemap: true }")):(console.error(" Webpack: devtool: 'source-map'"),console.error(" Vite: build: { sourcemap: true }"),console.error(" Next.js: productionBrowserSourceMaps: true")),console.error(""),console.error(" Then rebuild and run this command again."),process.exit(0)),console.log(` Found: ${l.length} source map${l.length!==1?"s":""}
20
- `);let t=n.endpoint||j,{uploaded:a,failed:u}=await P(l,s,r,t);console.log(`
21
- Done: ${a} uploaded${u>0?`, ${u} failed`:""}
22
- `),process.exit(0)}D();
6
+ `);let o=O(e.apiKey);o||(console.error(" \u2717 No API key. Set AIOLA_API_KEY env var or use --api-key=<key>"),process.exit(0));let i=b(e.release);console.log(` Release: ${i}`);let n=E(e.dir);n||(console.error(" \u2717 No build directory found. Run your build first or use --dir=<path>"),(s.default.existsSync("next.config.mjs")||s.default.existsSync("next.config.js")||s.default.existsSync("next.config.ts"))&&console.error(`
7
+ Next.js \u2014 add to next.config: productionBrowserSourceMaps: true`),process.exit(0)),console.log(` Directory: ${n}`);let r=v(n);r.length===0&&(console.error(` \u2717 No .js.map files found in ${n}`),(s.default.existsSync("next.config.mjs")||s.default.existsSync("next.config.js")||s.default.existsSync("next.config.ts"))&&console.error(`
8
+ Next.js \u2014 add to next.config: productionBrowserSourceMaps: true`),process.exit(0)),console.log(` Found: ${r.length} source maps
9
+ `);let u=e.endpoint||D,x=0,d=0;for(let g=0;g<r.length;g+=10){let l=r.slice(g,g+10),y=new FormData;y.append("release",i);for(let c of l){let p=s.default.readFileSync(c),a=f.default.basename(c),m="";try{let h=JSON.parse(p.toString("utf8"));h.file&&(m=h.file)}catch{}m||(m=a.replace(/\.map$/,"")),y.append("file",new Blob([p],{type:"application/json"}),a),y.append(`url:${a}`,m)}try{let c=await fetch(u,{method:"POST",headers:{"x-aiola-key":o},body:y});if(c.ok){let p=await c.json();x+=p.uploaded||l.length;for(let a of l)console.log(` \u2713 ${f.default.relative(".",a)}`)}else{let p=await c.json().catch(()=>({error:c.statusText}));d+=l.length;for(let a of l)console.log(` \u2717 ${f.default.relative(".",a)} \u2014 ${p.error||"failed"}`)}}catch(c){d+=l.length,console.error(` \u2717 Network error: ${c}`)}}console.log(`
10
+ Done: ${x} uploaded${d>0?`, ${d} failed`:""}
11
+ `),process.exit(0)}F();
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var v=(o,e)=>{for(var t in e)d(o,t,{get:e[t],enumerable:!0})},E=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of w(e))!y.call(o,r)&&r!==t&&d(o,r,{get:()=>e[r],enumerable:!(n=g(e,r))||n.enumerable});return o};var b=o=>E(d({},"__esModule",{value:!0}),o);var S={};v(S,{Aiola:()=>R});module.exports=b(S);var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,r){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:r,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(r,s){let i=typeof r=="string"?r:r instanceof URL?r.href:r.url,u=s?.method||"GET";if(e&&i.includes(e))return t.apply(globalThis,[r,s]);let h=Date.now();return t.apply(globalThis,[r,s]).then(c=>(n.add("http",`${u} ${i}`,{status_code:c.status,duration_ms:Date.now()-h}),c),c=>{throw n.add("http",`${u} ${i} (failed)`,{error:String(c),duration_ms:Date.now()-h},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,r=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(s,i){return this._clawMethod=s,this._clawUrl=typeof i=="string"?i:i.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let s=this;if(e&&s._clawUrl.includes(e))return r.apply(this,arguments);let i=Date.now();return s.addEventListener("loadend",function(){let u=Date.now()-i;s.status>0?t.add("http",`${s._clawMethod} ${s._clawUrl}`,{status_code:s.status,duration_ms:u,type:"xhr"}):t.add("http",`${s._clawMethod} ${s._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),r.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),r=t.textContent?.slice(0,50)?.trim(),s=t.id?`#${t.id}`:"",i=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${s}${i}${r?` "${r}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let s=window.location.href;s!==e&&(this.add("navigation",`${e} \u2192 ${s}`),e=s)};window.addEventListener("popstate",t);let n=history.pushState,r=history.replaceState;history.pushState=function(...s){n.apply(this,s),t()},history.replaceState=function(...s){r.apply(this,s),t()}}};var _=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,k=/^(.+?)@(.+?):(\d+):(\d+)$/;function m(o){let e=[],t=o.split(`
2
- `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=_.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")});continue}s=k.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")})}return e}function f(o){return!(!o||o.includes("node_modules")||o.startsWith("node:")||o.includes("internal/")||o.includes("<anonymous>"))}var x="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",T="aiola-js",L="0.1.8",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:x,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?m(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let i=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(i)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let i=t._extractRequestContext(n);throw t.captureException(s,{request:i}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:T,sdk_version:L,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var R=new l;0&&(module.exports={Aiola});
2
+ `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=_.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")});continue}s=k.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")})}return e}function f(o){return!(!o||o.includes("node_modules")||o.startsWith("node:")||o.includes("internal/")||o.includes("<anonymous>"))}var x="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",T="aiola-js",L="0.2.1",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:x,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?m(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let i=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(i)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let i=t._extractRequestContext(n);throw t.captureException(s,{request:i}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:T,sdk_version:L,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var R=new l;0&&(module.exports={Aiola});
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,r){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:r,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(r,s){let o=typeof r=="string"?r:r instanceof URL?r.href:r.url,u=s?.method||"GET";if(e&&o.includes(e))return t.apply(globalThis,[r,s]);let d=Date.now();return t.apply(globalThis,[r,s]).then(c=>(n.add("http",`${u} ${o}`,{status_code:c.status,duration_ms:Date.now()-d}),c),c=>{throw n.add("http",`${u} ${o} (failed)`,{error:String(c),duration_ms:Date.now()-d},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,r=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(s,o){return this._clawMethod=s,this._clawUrl=typeof o=="string"?o:o.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let s=this;if(e&&s._clawUrl.includes(e))return r.apply(this,arguments);let o=Date.now();return s.addEventListener("loadend",function(){let u=Date.now()-o;s.status>0?t.add("http",`${s._clawMethod} ${s._clawUrl}`,{status_code:s.status,duration_ms:u,type:"xhr"}):t.add("http",`${s._clawMethod} ${s._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),r.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),r=t.textContent?.slice(0,50)?.trim(),s=t.id?`#${t.id}`:"",o=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${s}${o}${r?` "${r}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let s=window.location.href;s!==e&&(this.add("navigation",`${e} \u2192 ${s}`),e=s)};window.addEventListener("popstate",t);let n=history.pushState,r=history.replaceState;history.pushState=function(...s){n.apply(this,s),t()},history.replaceState=function(...s){r.apply(this,s),t()}}};var m=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,g=/^(.+?)@(.+?):(\d+):(\d+)$/;function f(i){let e=[],t=i.split(`
2
- `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=m.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")});continue}s=g.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")})}return e}function h(i){return!(!i||i.includes("node_modules")||i.startsWith("node:")||i.includes("internal/")||i.includes("<anonymous>"))}var w="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",y="aiola-js",v="0.1.8",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:w,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?f(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let o=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(o)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let o=t._extractRequestContext(n);throw t.captureException(s,{request:o}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:y,sdk_version:v,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var S=new l;export{S as Aiola};
2
+ `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=m.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")});continue}s=g.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")})}return e}function h(i){return!(!i||i.includes("node_modules")||i.startsWith("node:")||i.includes("internal/")||i.includes("<anonymous>"))}var w="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",y="aiola-js",v="0.2.1",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:w,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?f(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let o=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(o)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let o=t._extractRequestContext(n);throw t.captureException(s,{request:o}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:y,sdk_version:v,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var S=new l;export{S as Aiola};
package/dist/node.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var E=(o,e)=>{for(var t in e)d(o,t,{get:e[t],enumerable:!0})},b=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of y(e))!v.call(o,r)&&r!==t&&d(o,r,{get:()=>e[r],enumerable:!(n=w(e,r))||n.enumerable});return o};var _=o=>b(d({},"__esModule",{value:!0}),o);var S={};E(S,{Aiola:()=>g});module.exports=_(S);var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,r){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:r,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(r,s){let i=typeof r=="string"?r:r instanceof URL?r.href:r.url,u=s?.method||"GET";if(e&&i.includes(e))return t.apply(globalThis,[r,s]);let h=Date.now();return t.apply(globalThis,[r,s]).then(c=>(n.add("http",`${u} ${i}`,{status_code:c.status,duration_ms:Date.now()-h}),c),c=>{throw n.add("http",`${u} ${i} (failed)`,{error:String(c),duration_ms:Date.now()-h},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,r=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(s,i){return this._clawMethod=s,this._clawUrl=typeof i=="string"?i:i.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let s=this;if(e&&s._clawUrl.includes(e))return r.apply(this,arguments);let i=Date.now();return s.addEventListener("loadend",function(){let u=Date.now()-i;s.status>0?t.add("http",`${s._clawMethod} ${s._clawUrl}`,{status_code:s.status,duration_ms:u,type:"xhr"}):t.add("http",`${s._clawMethod} ${s._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),r.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),r=t.textContent?.slice(0,50)?.trim(),s=t.id?`#${t.id}`:"",i=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${s}${i}${r?` "${r}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let s=window.location.href;s!==e&&(this.add("navigation",`${e} \u2192 ${s}`),e=s)};window.addEventListener("popstate",t);let n=history.pushState,r=history.replaceState;history.pushState=function(...s){n.apply(this,s),t()},history.replaceState=function(...s){r.apply(this,s),t()}}};var k=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,x=/^(.+?)@(.+?):(\d+):(\d+)$/;function m(o){let e=[],t=o.split(`
2
- `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=k.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")});continue}s=x.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")})}return e}function f(o){return!(!o||o.includes("node_modules")||o.startsWith("node:")||o.includes("internal/")||o.includes("<anonymous>"))}var L="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",T="aiola-js",R="0.1.8",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:L,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?m(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let i=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(i)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let i=t._extractRequestContext(n);throw t.captureException(s,{request:i}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:T,sdk_version:R,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var g=new l;0&&(module.exports={Aiola});
2
+ `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=k.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")});continue}s=x.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:f(s[2]||"")})}return e}function f(o){return!(!o||o.includes("node_modules")||o.startsWith("node:")||o.includes("internal/")||o.includes("<anonymous>"))}var L="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",T="aiola-js",R="0.2.1",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:L,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?m(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let i=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(i)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let i=t._extractRequestContext(n);throw t.captureException(s,{request:i}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:T,sdk_version:R,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var g=new l;0&&(module.exports={Aiola});
package/dist/node.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  var a=class{constructor(e,t,n){this.endpoint=e;this.apiKey=t;this.flushInterval=n;this.queue=[];this.timer=null}send(e){this.queue.push(e),this.timer||(this.timer=setTimeout(()=>this.flush(),this.flushInterval)),(e.level==="error"||e.level==="fatal")&&this.flush()}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),this.queue.length===0)return;let e=this.queue.splice(0);for(let t of e)this._send(t)}_send(e){let t=JSON.stringify(e);this._fetch(t)}_fetch(e){try{fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-aiola-key":this.apiKey},body:e,keepalive:!0}).catch(()=>{})}catch{}}};var p=class{constructor(e){this.crumbs=[];this.max=e}add(e,t,n,r){this.crumbs.push({timestamp:new Date().toISOString(),category:e,message:t,level:r,data:n}),this.crumbs.length>this.max&&this.crumbs.shift()}getAll(){return[...this.crumbs]}clear(){this.crumbs=[]}instrumentFetch(e){if(typeof globalThis.fetch>"u")return;let t=globalThis.fetch,n=this;globalThis.fetch=function(r,s){let o=typeof r=="string"?r:r instanceof URL?r.href:r.url,u=s?.method||"GET";if(e&&o.includes(e))return t.apply(globalThis,[r,s]);let d=Date.now();return t.apply(globalThis,[r,s]).then(c=>(n.add("http",`${u} ${o}`,{status_code:c.status,duration_ms:Date.now()-d}),c),c=>{throw n.add("http",`${u} ${o} (failed)`,{error:String(c),duration_ms:Date.now()-d},"error"),c})}}instrumentXHR(e){if(typeof XMLHttpRequest>"u")return;let t=this,n=XMLHttpRequest.prototype.open,r=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(s,o){return this._clawMethod=s,this._clawUrl=typeof o=="string"?o:o.href,n.apply(this,arguments)},XMLHttpRequest.prototype.send=function(){let s=this;if(e&&s._clawUrl.includes(e))return r.apply(this,arguments);let o=Date.now();return s.addEventListener("loadend",function(){let u=Date.now()-o;s.status>0?t.add("http",`${s._clawMethod} ${s._clawUrl}`,{status_code:s.status,duration_ms:u,type:"xhr"}):t.add("http",`${s._clawMethod} ${s._clawUrl} (failed)`,{duration_ms:u,type:"xhr"},"error")}),r.apply(this,arguments)}}instrumentClicks(){typeof document>"u"||document.addEventListener("click",e=>{let t=e.target;if(!t)return;let n=t.tagName?.toLowerCase(),r=t.textContent?.slice(0,50)?.trim(),s=t.id?`#${t.id}`:"",o=t.className&&typeof t.className=="string"?`.${t.className.split(" ")[0]}`:"";this.add("click",`${n}${s}${o}${r?` "${r}"`:""}`)},{capture:!0,passive:!0})}instrumentNavigation(){if(typeof window>"u")return;let e=window.location.href,t=()=>{let s=window.location.href;s!==e&&(this.add("navigation",`${e} \u2192 ${s}`),e=s)};window.addEventListener("popstate",t);let n=history.pushState,r=history.replaceState;history.pushState=function(...s){n.apply(this,s),t()},history.replaceState=function(...s){r.apply(this,s),t()}}};var m=/^\s*at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+)|([^)]+))\)?$/,g=/^(.+?)@(.+?):(\d+):(\d+)$/;function f(i){let e=[],t=i.split(`
2
- `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=m.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")});continue}s=g.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")})}return e}function h(i){return!(!i||i.includes("node_modules")||i.startsWith("node:")||i.includes("internal/")||i.includes("<anonymous>"))}var w="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",y="aiola-js",v="0.1.8",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:w,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?f(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let o=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(o)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let o=t._extractRequestContext(n);throw t.captureException(s,{request:o}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:y,sdk_version:v,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var E=new l;export{E as Aiola};
2
+ `);for(let n of t){let r=n.trim();if(!r||r.startsWith("Error"))continue;let s=m.exec(r);if(s){e.push({function:s[1]||"<anonymous>",filename:s[2]||s[5]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")});continue}s=g.exec(r),s&&e.push({function:s[1]||"<anonymous>",filename:s[2]||"<unknown>",lineno:parseInt(s[3],10)||0,colno:parseInt(s[4],10)||void 0,in_app:h(s[2]||"")})}return e}function h(i){return!(!i||i.includes("node_modules")||i.startsWith("node:")||i.includes("internal/")||i.includes("<anonymous>"))}var w="https://lhrsgoaselmgophvbqme.supabase.co/functions/v1/app-logs-ingest",y="aiola-js",v="0.2.1",l=class{constructor(){this.initialized=!1;this.seen=new Set;this.options={apiKey:"",environment:"production",endpoint:w,maxBreadcrumbs:30,flushInterval:5e3,captureConsoleErrors:!0},this.transport=new a(this.options.endpoint,"",5e3),this.breadcrumbs=new p(30)}init(e){if(this.initialized){if(this.options.apiKey===e.apiKey)return;this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval);return}if(this.initialized=!0,!e.release)try{let t=typeof process<"u"?process.env:{};e.release=t.NEXT_PUBLIC_GIT_SHA||t.NEXT_PUBLIC_APP_VERSION||t.VITE_APP_VERSION||t.APP_VERSION||""}catch{}this.options={...this.options,...e},this.transport=new a(this.options.endpoint,this.options.apiKey,this.options.flushInterval),this.breadcrumbs=new p(this.options.maxBreadcrumbs),this._setupGlobalHandlers(),this._instrumentConsole(),this.breadcrumbs.instrumentFetch(this.options.endpoint),this.breadcrumbs.instrumentXHR(this.options.endpoint),typeof window<"u"&&(this.breadcrumbs.instrumentClicks(),this.breadcrumbs.instrumentNavigation(),window.addEventListener("beforeunload",()=>this.transport.flush()),window.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&this.transport.flush()}))}captureException(e,t){if(!this.initialized)return;let n=e instanceof Error?e:new Error(String(e)),r=n.stack?f(n.stack):[],s=`${n.name}:${n.message}`;if(this.seen.has(s))return;this.seen.add(s),setTimeout(()=>this.seen.delete(s),5e3);let o=this._buildEvent({level:t?.level||"error",message:n.message,exception:{type:n.name||"Error",value:n.message,stacktrace:r.length>0?{frames:r}:void 0},tags:t?.tags,request:t?.request});this._send(o)}captureMessage(e,t="info",n){if(!this.initialized)return;let r=this._buildEvent({level:t,message:e,tags:n});this._send(r)}addBreadcrumb(e,t,n){this.breadcrumbs.add(e,t,n)}setUser(e){this.options.user=e||void 0}setTag(e,t){this.options.tags||(this.options.tags={}),this.options.tags[e]=t}flush(){this.transport.flush()}wrap(e){let t=this;return function(...n){try{let r=e.apply(this,n);return r instanceof Promise?r.catch(s=>{throw t.captureException(s),s}):r}catch(r){throw t.captureException(r),r}}}wrapApiHandler(e){let t=this;return async function(n,r){try{return await e(n,r)}catch(s){let o=t._extractRequestContext(n);throw t.captureException(s,{request:o}),t.transport.flush(),s}}}wrapRouteHandler(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){let s=n[0]?t._extractRequestContext(n[0]):void 0;throw t.captureException(r,{request:s}),t.transport.flush(),r}})}wrapServerAction(e){let t=this;return(async function(...n){try{return await e(...n)}catch(r){throw t.captureException(r),t.transport.flush(),r}})}_extractRequestContext(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.url=="string"&&typeof t.method=="string")return{url:t.url,method:t.method,query_string:typeof t.url=="string"&&t.url.split("?")[1]||""};if(typeof t.originalUrl=="string"&&typeof t.method=="string")return{url:t.originalUrl,method:t.method,query_string:typeof t.query=="object"?JSON.stringify(t.query):""}}_buildEvent(e){let t={...e,message:e.message||"",environment:this.options.environment,release:this.options.release,timestamp:new Date().toISOString(),user:this.options.user,tags:{sdk_name:y,sdk_version:v,...this.options.tags,...e.tags},breadcrumbs:this.breadcrumbs.getAll()};return e.request?t.request=e.request:typeof window<"u"&&(t.request={url:window.location.href,method:"GET",query_string:window.location.search}),typeof process<"u"&&process.version&&(t.contexts={runtime:{name:"Node.js",version:process.version}}),t}_send(e){if(this.options.beforeSend){let t=this.options.beforeSend(e);if(!t)return;e=t}this.transport.send(e)}_instrumentConsole(){if(typeof console>"u")return;let e={log:console.log,warn:console.warn,error:console.error,info:console.info},t=this;console.log=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.log.apply(console,n)},console.warn=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"warning"),e.warn.apply(console,n)},console.error=function(...n){let r=n.map(String).join(" ");if(t.breadcrumbs.add("console",r,void 0,"error"),t.options.captureConsoleErrors){let s=n[0]instanceof Error?n[0]:null;s?t.captureException(s,{tags:{source:"console.error"}}):t.captureMessage(r,"error",{source:"console.error"})}e.error.apply(console,n)},console.info=function(...n){t.breadcrumbs.add("console",n.map(String).join(" "),void 0,"info"),e.info.apply(console,n)}}_setupGlobalHandlers(){if(typeof window<"u"&&(window.addEventListener("error",e=>{let t=e.target;if(t&&t!==window&&t.tagName){let n=t,r=n.tagName.toLowerCase(),s=n.src||n.href||"";this.captureMessage(`Failed to load ${r}: ${s}`,"error",{source:"resource",element:r,url:s});return}e.error?this.captureException(e.error):e.message&&this.captureException(new Error(e.message))},!0),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureException(t)})),typeof process<"u"&&typeof process.on=="function"){let e=process;e.on("uncaughtException",t=>{this.captureException(t,{level:"fatal"}),this.transport.flush()}),e.on("unhandledRejection",t=>{let n=t instanceof Error?t:new Error(String(t));this.captureException(n),this.transport.flush()})}typeof process>"u"&&typeof globalThis<"u"&&"Deno"in globalThis&&(globalThis.addEventListener("error",e=>{let t=e;t.error?this.captureException(t.error):t.message&&this.captureException(new Error(t.message))}),globalThis.addEventListener("unhandledrejection",e=>{let t=e,n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureException(n),this.transport.flush()}))}};var E=new l;export{E as Aiola};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiolaapp/logger",
3
- "version": "0.1.8",
3
+ "version": "0.2.1",
4
4
  "description": "Lightweight error tracking SDK for Aiola App Logs",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",