@xcodleox/devinspector 7.4.0 → 8.0.0

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.
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var y=(n,e)=>{for(var r in e)c(n,r,{get:e[r],enumerable:!0})},m=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!g.call(n,o)&&o!==r&&c(n,o,{get:()=>e[o],enumerable:!(t=h(e,o))||t.enumerable});return n};var w=n=>m(c({},"__esModule",{value:!0}),n);var R={};y(R,{AuditErrorBoundary:()=>p,auditFetch:()=>f,enableNetworkTracing:()=>v});module.exports=w(R);var l=require("react");var d=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(r)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((t,o)=>{let i=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),r&&r(t,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let o=t instanceof Error?t:new Error(String(t));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(t.has(e))return"[Circular Reference]";t.add(e);let o={};for(let[i,s]of Object.entries(e))o[i]=this.truncate(s,r,t);return o}return e}captureError(e,r={}){let t=e.message||"Erro Desconhecido",o=e.stack||"",i={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(e){let r=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},u="__DEVINSPECT_AUDIT_CORE_INSTANCE__",b=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[u]||(n[u]=new d),n[u]},a=b();var p=class extends l.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){a.captureError(r,{platform:"react-native",componentStack:t.componentStack}),this.props.onError&&this.props.onError(r,t)}render(){if(this.state.hasError){let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido");return typeof r=="function"?r(t):r??null}return this.props.children}};async function f(n,e){let r="";if(typeof n=="string"?r=n:n instanceof URL?r=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(r=n.url),r&&(r.includes("devinspector.com.br")||r.includes("/ingest/track")))return fetch(n,e);let t=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),o=typeof performance<"u"?performance.now():Date.now();try{let i=await fetch(n,e),s=Math.round((typeof performance<"u"?performance.now():Date.now())-o);return(i.status>=400||s>=300)&&a.captureRequest({method:t,url:r,statusCode:i.status,durationMs:s,route:r,userAgent:typeof navigator<"u"?navigator.userAgent:"React-Native"}),i}catch(i){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-o);throw a.captureRequest({method:t,url:r,statusCode:0,durationMs:s,route:r,userAgent:typeof navigator<"u"?navigator.userAgent:"React-Native"}),a.captureException(i instanceof Error?i:new Error(String(i)),{url:r,method:t,type:"react_native_network_error"}),i}}function v(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return f(e,r)})}0&&(module.exports={AuditErrorBoundary,auditFetch,enableNetworkTracing});
1
+ "use strict";var h=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var T=(n,e)=>{for(var r in e)h(n,r,{get:e[r],enumerable:!0})},A=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of R(e))!_.call(n,s)&&s!==r&&h(n,s,{get:()=>e[s],enumerable:!(t=I(e,s))||t.enumerable});return n};var q=n=>A(h({},"__esModule",{value:!0}),n);var x={};T(x,{AuditErrorBoundary:()=>g,audit:()=>i,auditFetch:()=>S,enableNetworkTracing:()=>D});module.exports=q(x);var w=require("react");var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,r,t));let o={};for(let[a,c]of Object.entries(e))o[a]=this.truncate(c,r,t);return o}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),a=r.requestId,c=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},m="__DEVINSPECT_AUDIT_CORE_INSTANCE__",k=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[m]||(n[m]=new f),n[m]},i=k();async function b(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&i.isIngestUrl(s))return t(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),a=i.createRequestId(),c=i.createTraceId(),u=i.createSpanId(),l=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));l.set("x-devinspector-request-id",a),l.set("x-devinspector-trace-id",c),l.set("x-devinspector-span-id",u);let v={...e,headers:l},y=typeof performance<"u"?performance.now():Date.now();try{let d=await t(n,v),p=Math.round((typeof performance<"u"?performance.now():Date.now())-y),E=i.getSlowThresholdMs();return(d.status>=400||p>=E)&&i.captureRequest({method:o,url:s,statusCode:d.status,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:d.status,durationMs:p,requestId:a,traceId:c,spanId:u}}),d}catch(d){let p=Math.round((typeof performance<"u"?performance.now():Date.now())-y);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:o,type:r?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:p,requestId:a,traceId:c,spanId:u}}),d}}var g=class extends w.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){i.addBreadcrumb({type:"react_native_error_boundary",message:r.message||"Erro capturado pelo React Native Error Boundary",metadata:{componentStack:t.componentStack||""}}),i.captureError(r,{platform:"react-native",framework:"React Native",componentStack:t.componentStack}),this.props.onError&&this.props.onError(r,t)}render(){if(!this.state.hasError)return this.props.children;let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido");return typeof r=="function"?r(t):r??null}};async function S(n,e){return b(n,e,{errorType:"react_native_network_error",defaultUserAgent:"React-Native"})}function D(){let n=globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=function(r,t){return b(r,t,{errorType:"react_native_network_error",defaultUserAgent:"React-Native",nativeFetch:e})}}0&&(module.exports={AuditErrorBoundary,audit,auditFetch,enableNetworkTracing});
@@ -1,4 +1,5 @@
1
1
  import { Component, ReactNode, ErrorInfo } from 'react';
2
+ export { audit } from './index.cjs';
2
3
 
3
4
  interface Props {
4
5
  children: ReactNode;
@@ -1,4 +1,5 @@
1
1
  import { Component, ReactNode, ErrorInfo } from 'react';
2
+ export { audit } from './index.js';
2
3
 
3
4
  interface Props {
4
5
  children: ReactNode;
@@ -1 +1 @@
1
- import{Component as l}from"react";var u=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(r){if(!r.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=r.apiKey,r.endpoint&&(this.endpoint=r.endpoint),r.environment&&(this.environment=r.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(r){let e={type:"request_metric",method:r.method,url:r.url,statusCode:r.statusCode,durationMs:r.durationMs,browser:r.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:r.route||r.url,dbQueriesCount:r.dbQueriesCount||0,slowQueryMs:r.slowQueryMs||0}};this.send(e)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let r=globalThis;if(r.ErrorUtils&&typeof r.ErrorUtils.setGlobalHandler=="function"){let e=r.ErrorUtils.getGlobalHandler();r.ErrorUtils.setGlobalHandler((t,i)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!i}),e&&e(t,i)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",e=>{this.captureError(e.error||new Error(e.message||"Erro global desconhecido"),{filename:e.filename,lineno:e.lineno,colno:e.colno})}),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(r.process?.on){let e=r.process;e.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),e.on("unhandledRejection",t=>{let i=t instanceof Error?t:new Error(String(t));this.captureError(i,{type:"unhandled_rejection"})})}}truncate(r,e=5e3,t=new WeakSet){if(typeof r=="string")return r.length>e?r.substring(0,e)+"... [truncated]":r;if(r&&typeof r=="object"&&r!==null){if(t.has(r))return"[Circular Reference]";t.add(r);let i={};for(let[o,s]of Object.entries(r))i[o]=this.truncate(s,e,t);return i}return r}captureError(r,e={}){let t=r.message||"Erro Desconhecido",i=r.stack||"",o={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(i,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...e,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(o)}captureException(r,e={}){this.captureError(r,e)}captureMessage(r,e={}){let t={type:"message",message:this.truncate(r,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...e,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(r){let e=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":e},body:JSON.stringify(r),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},c="__DEVINSPECT_AUDIT_CORE_INSTANCE__",p=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[c]||(n[c]=new u),n[c]},a=p();var d=class extends l{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){a.captureError(e,{platform:"react-native",componentStack:t.componentStack}),this.props.onError&&this.props.onError(e,t)}render(){if(this.state.hasError){let{fallback:e}=this.props,t=this.state.error||new Error("Erro desconhecido");return typeof e=="function"?e(t):e??null}return this.props.children}};async function f(n,r){let e="";if(typeof n=="string"?e=n:n instanceof URL?e=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(e=n.url),e&&(e.includes("devinspector.com.br")||e.includes("/ingest/track")))return fetch(n,r);let t=r?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=typeof performance<"u"?performance.now():Date.now();try{let o=await fetch(n,r),s=Math.round((typeof performance<"u"?performance.now():Date.now())-i);return(o.status>=400||s>=300)&&a.captureRequest({method:t,url:e,statusCode:o.status,durationMs:s,route:e,userAgent:typeof navigator<"u"?navigator.userAgent:"React-Native"}),o}catch(o){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-i);throw a.captureRequest({method:t,url:e,statusCode:0,durationMs:s,route:e,userAgent:typeof navigator<"u"?navigator.userAgent:"React-Native"}),a.captureException(o instanceof Error?o:new Error(String(o)),{url:e,method:t,type:"react_native_network_error"}),o}}function b(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(r,e){return f(r,e)})}export{d as AuditErrorBoundary,f as auditFetch,b as enableNetworkTracing};
1
+ import{Component as E}from"react";var m=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,r,t));let o={};for(let[a,c]of Object.entries(e))o[a]=this.truncate(c,r,t);return o}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),a=r.requestId,c=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},h="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[h]||(n[h]=new m),n[h]},i=v();async function f(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&i.isIngestUrl(s))return t(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),a=i.createRequestId(),c=i.createTraceId(),u=i.createSpanId(),l=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));l.set("x-devinspector-request-id",a),l.set("x-devinspector-trace-id",c),l.set("x-devinspector-span-id",u);let y={...e,headers:l},b=typeof performance<"u"?performance.now():Date.now();try{let d=await t(n,y),p=Math.round((typeof performance<"u"?performance.now():Date.now())-b),w=i.getSlowThresholdMs();return(d.status>=400||p>=w)&&i.captureRequest({method:o,url:s,statusCode:d.status,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:d.status,durationMs:p,requestId:a,traceId:c,spanId:u}}),d}catch(d){let p=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:o,type:r?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:p,requestId:a,traceId:c,spanId:u}}),d}}var g=class extends E{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){i.addBreadcrumb({type:"react_native_error_boundary",message:r.message||"Erro capturado pelo React Native Error Boundary",metadata:{componentStack:t.componentStack||""}}),i.captureError(r,{platform:"react-native",framework:"React Native",componentStack:t.componentStack}),this.props.onError&&this.props.onError(r,t)}render(){if(!this.state.hasError)return this.props.children;let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido");return typeof r=="function"?r(t):r??null}};async function k(n,e){return f(n,e,{errorType:"react_native_network_error",defaultUserAgent:"React-Native"})}function S(){let n=globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=function(r,t){return f(r,t,{errorType:"react_native_network_error",defaultUserAgent:"React-Native",nativeFetch:e})}}export{g as AuditErrorBoundary,i as audit,k as auditFetch,S as enableNetworkTracing};
package/dist/react.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var m=(n,e)=>{for(var r in e)c(n,r,{get:e[r],enumerable:!0})},w=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of g(e))!y.call(n,o)&&o!==r&&c(n,o,{get:()=>e[o],enumerable:!(t=E(e,o))||t.enumerable});return n};var b=n=>w(c({},"__esModule",{value:!0}),n);var _={};m(_,{AuditErrorBoundary:()=>p,audit:()=>a,auditFetch:()=>f,enableNetworkTracing:()=>R});module.exports=b(_);var l=require("react");var u=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(r)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((t,o)=>{let i=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),r&&r(t,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let o=t instanceof Error?t:new Error(String(t));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(t.has(e))return"[Circular Reference]";t.add(e);let o={};for(let[i,s]of Object.entries(e))o[i]=this.truncate(s,r,t);return o}return e}captureError(e,r={}){let t=e.message||"Erro Desconhecido",o=e.stack||"",i={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(e){let r=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},d="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[d]||(n[d]=new u),n[d]},a=v();var h=require("react/jsx-runtime"),p=class extends l.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){a.captureError(r,{framework:"React",componentStack:t.componentStack,url:typeof window<"u"?window.location.href:""}),this.props.onError&&this.props.onError(r,t)}render(){if(this.state.hasError){let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido no componente");return typeof r=="function"?r(t):r??(0,h.jsx)("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function f(n,e){let r="";if(typeof n=="string"?r=n:n instanceof URL?r=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(r=n.url),r&&(r.includes("devinspector.com.br")||r.includes("/ingest/track")))return fetch(n,e);let t=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),o=typeof performance<"u"?performance.now():Date.now();try{let i=await fetch(n,e),s=Math.round((typeof performance<"u"?performance.now():Date.now())-o);return(i.status>=400||s>=300)&&a.captureRequest({method:t,url:r,statusCode:i.status,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:r}),i}catch(i){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-o);throw a.captureRequest({method:t,url:r,statusCode:0,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:r}),a.captureException(i instanceof Error?i:new Error(String(i)),{url:r,method:t,type:"network_error"}),i}}function R(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return f(e,r)})}0&&(module.exports={AuditErrorBoundary,audit,auditFetch,enableNetworkTracing});
1
+ "use strict";var h=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var q=(n,e)=>{for(var r in e)h(n,r,{get:e[r],enumerable:!0})},A=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _(e))!T.call(n,s)&&s!==r&&h(n,s,{get:()=>e[s],enumerable:!(t=R(e,s))||t.enumerable});return n};var k=n=>A(h({},"__esModule",{value:!0}),n);var x={};q(x,{AuditErrorBoundary:()=>g,audit:()=>i,auditFetch:()=>D,enableNetworkTracing:()=>M});module.exports=k(x);var w=require("react");var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,r,t));let o={};for(let[a,c]of Object.entries(e))o[a]=this.truncate(c,r,t);return o}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),a=r.requestId,c=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},m="__DEVINSPECT_AUDIT_CORE_INSTANCE__",S=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[m]||(n[m]=new f),n[m]},i=S();async function b(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&i.isIngestUrl(s))return t(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),a=i.createRequestId(),c=i.createTraceId(),u=i.createSpanId(),l=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));l.set("x-devinspector-request-id",a),l.set("x-devinspector-trace-id",c),l.set("x-devinspector-span-id",u);let I={...e,headers:l},y=typeof performance<"u"?performance.now():Date.now();try{let d=await t(n,I),p=Math.round((typeof performance<"u"?performance.now():Date.now())-y),v=i.getSlowThresholdMs();return(d.status>=400||p>=v)&&i.captureRequest({method:o,url:s,statusCode:d.status,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:d.status,durationMs:p,requestId:a,traceId:c,spanId:u}}),d}catch(d){let p=Math.round((typeof performance<"u"?performance.now():Date.now())-y);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:o,type:r?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:p,requestId:a,traceId:c,spanId:u}}),d}}var E=require("react/jsx-runtime"),g=class extends w.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){i.addBreadcrumb({type:"react_error_boundary",message:r.message||"Erro capturado pelo React Error Boundary",metadata:{componentStack:t.componentStack||""}}),i.captureError(r,{framework:"React",componentStack:t.componentStack,url:typeof window<"u"?window.location.href:""}),this.props.onError&&this.props.onError(r,t)}render(){if(this.state.hasError){let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido no componente");return typeof r=="function"?r(t):r??(0,E.jsx)("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function D(n,e){return b(n,e,{errorType:"react_network_error"})}function M(){let n=globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=function(r,t){return b(r,t,{errorType:"react_network_error",nativeFetch:e})}}0&&(module.exports={AuditErrorBoundary,audit,auditFetch,enableNetworkTracing});
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import{Component as l}from"react";var d=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(r){if(!r.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=r.apiKey,r.endpoint&&(this.endpoint=r.endpoint),r.environment&&(this.environment=r.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(r){let e={type:"request_metric",method:r.method,url:r.url,statusCode:r.statusCode,durationMs:r.durationMs,browser:r.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:r.route||r.url,dbQueriesCount:r.dbQueriesCount||0,slowQueryMs:r.slowQueryMs||0}};this.send(e)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let r=globalThis;if(r.ErrorUtils&&typeof r.ErrorUtils.setGlobalHandler=="function"){let e=r.ErrorUtils.getGlobalHandler();r.ErrorUtils.setGlobalHandler((t,i)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!i}),e&&e(t,i)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",e=>{this.captureError(e.error||new Error(e.message||"Erro global desconhecido"),{filename:e.filename,lineno:e.lineno,colno:e.colno})}),window.addEventListener("unhandledrejection",e=>{let t=e.reason instanceof Error?e.reason:new Error(String(e.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(r.process?.on){let e=r.process;e.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),e.on("unhandledRejection",t=>{let i=t instanceof Error?t:new Error(String(t));this.captureError(i,{type:"unhandled_rejection"})})}}truncate(r,e=5e3,t=new WeakSet){if(typeof r=="string")return r.length>e?r.substring(0,e)+"... [truncated]":r;if(r&&typeof r=="object"&&r!==null){if(t.has(r))return"[Circular Reference]";t.add(r);let i={};for(let[o,s]of Object.entries(r))i[o]=this.truncate(s,e,t);return i}return r}captureError(r,e={}){let t=r.message||"Erro Desconhecido",i=r.stack||"",o={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(i,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...e,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(o)}captureException(r,e={}){this.captureError(r,e)}captureMessage(r,e={}){let t={type:"message",message:this.truncate(r,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...e,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(r){let e=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":e},body:JSON.stringify(r),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},c="__DEVINSPECT_AUDIT_CORE_INSTANCE__",p=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[c]||(n[c]=new d),n[c]},a=p();import{jsx as h}from"react/jsx-runtime";var u=class extends l{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){a.captureError(e,{framework:"React",componentStack:t.componentStack,url:typeof window<"u"?window.location.href:""}),this.props.onError&&this.props.onError(e,t)}render(){if(this.state.hasError){let{fallback:e}=this.props,t=this.state.error||new Error("Erro desconhecido no componente");return typeof e=="function"?e(t):e??h("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function f(n,r){let e="";if(typeof n=="string"?e=n:n instanceof URL?e=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(e=n.url),e&&(e.includes("devinspector.com.br")||e.includes("/ingest/track")))return fetch(n,r);let t=r?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=typeof performance<"u"?performance.now():Date.now();try{let o=await fetch(n,r),s=Math.round((typeof performance<"u"?performance.now():Date.now())-i);return(o.status>=400||s>=300)&&a.captureRequest({method:t,url:e,statusCode:o.status,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:e}),o}catch(o){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-i);throw a.captureRequest({method:t,url:e,statusCode:0,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:e}),a.captureException(o instanceof Error?o:new Error(String(o)),{url:e,method:t,type:"network_error"}),o}}function v(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(r,e){return f(r,e)})}export{u as AuditErrorBoundary,a as audit,f as auditFetch,v as enableNetworkTracing};
1
+ import{Component as I}from"react";var m=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,r,t));let o={};for(let[a,c]of Object.entries(e))o[a]=this.truncate(c,r,t);return o}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),a=r.requestId,c=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},h="__DEVINSPECT_AUDIT_CORE_INSTANCE__",E=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[h]||(n[h]=new m),n[h]},i=E();async function f(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&i.isIngestUrl(s))return t(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),a=i.createRequestId(),c=i.createTraceId(),u=i.createSpanId(),l=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));l.set("x-devinspector-request-id",a),l.set("x-devinspector-trace-id",c),l.set("x-devinspector-span-id",u);let y={...e,headers:l},b=typeof performance<"u"?performance.now():Date.now();try{let d=await t(n,y),p=Math.round((typeof performance<"u"?performance.now():Date.now())-b),w=i.getSlowThresholdMs();return(d.status>=400||p>=w)&&i.captureRequest({method:o,url:s,statusCode:d.status,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:d.status,durationMs:p,requestId:a,traceId:c,spanId:u}}),d}catch(d){let p=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:p,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:o,type:r?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:p,requestId:a,traceId:c,spanId:u}}),d}}import{jsx as v}from"react/jsx-runtime";var g=class extends I{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){i.addBreadcrumb({type:"react_error_boundary",message:r.message||"Erro capturado pelo React Error Boundary",metadata:{componentStack:t.componentStack||""}}),i.captureError(r,{framework:"React",componentStack:t.componentStack,url:typeof window<"u"?window.location.href:""}),this.props.onError&&this.props.onError(r,t)}render(){if(this.state.hasError){let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido no componente");return typeof r=="function"?r(t):r??v("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function S(n,e){return f(n,e,{errorType:"react_network_error"})}function D(){let n=globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=function(r,t){return f(r,t,{errorType:"react_network_error",nativeFetch:e})}}export{g as AuditErrorBoundary,i as audit,S as auditFetch,D as enableNetworkTracing};
package/dist/svelte.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var m=(r,e)=>{for(var t in e)d(r,t,{get:e[t],enumerable:!0})},E=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of g(e))!w.call(r,o)&&o!==t&&d(r,o,{get:()=>e[o],enumerable:!(n=y(e,o))||n.enumerable});return r};var b=r=>E(d({},"__esModule",{value:!0}),r);var k={};m(k,{audit:()=>i,auditFetch:()=>l,auditHandle:()=>R,enableNetworkTracing:()=>S,handleSvelteKitError:()=>I,initSvelteDevInspector:()=>_});module.exports=b(k);var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((n,o)=>{let s=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),t&&t(n,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let o=n instanceof Error?n:new Error(String(n));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(n.has(e))return"[Circular Reference]";n.add(e);let o={};for(let[s,a]of Object.entries(e))o[s]=this.truncate(a,t,n);return o}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(n)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let n=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});n.ok||console.error(`[DevInspector] Erro na API (${n.status}): ${n.statusText}`)}catch(n){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",n)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[p]||(r[p]=new f),r[p]},i=v();function _(r){i.init(r)}async function l(r,e){let t="";if(typeof r=="string"?t=r:r instanceof URL?t=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(t=r.url),t&&(t.includes("devinspector.com.br")||t.includes("/ingest/track")))return fetch(r,e);let n=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),o=typeof performance<"u"?performance.now():Date.now();try{let s=await fetch(r,e),a=Math.round((typeof performance<"u"?performance.now():Date.now())-o);return(s.status>=400||a>=300)&&i.captureRequest({method:n,url:t,statusCode:s.status,durationMs:a,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:t}),s}catch(s){let a=Math.round((typeof performance<"u"?performance.now():Date.now())-o);throw i.captureRequest({method:n,url:t,statusCode:0,durationMs:a,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:t}),i.captureException(s instanceof Error?s:new Error(String(s)),{url:t,method:n,type:"svelte_network_error"}),s}}async function R({event:r,resolve:e}){let t=typeof performance<"u"?performance.now():Date.now(),n=r.request?.method||"GET",o=r.url?.pathname||r.url?.href||"/",s=r.route?.id||o,a=typeof r.request?.headers?.get=="function"&&r.request.headers.get("user-agent")||"";try{let c=await e(r),u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);return(c.status>=400||u>=300)&&i.captureRequest({method:n,url:o,statusCode:c.status,durationMs:u,route:s,userAgent:a}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);i.captureRequest({method:n,url:o,statusCode:500,durationMs:u,route:s,userAgent:a});let h=c instanceof Error?c:new Error(String(c));throw i.captureError(h,{framework:"sveltekit",url:o,method:n,route:s}),c}}function I({error:r,event:e,status:t,message:n}){let o=r instanceof Error?r:new Error(String(r||n||"Erro SvelteKit"));i.captureError(o,{framework:"sveltekit",status:t||500,url:e?.url?.href||"",route:e?.route?.id||""})}function S(){let r=globalThis;!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__||(r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(e,t){return l(e,t)})}0&&(module.exports={audit,auditFetch,auditHandle,enableNetworkTracing,handleSvelteKitError,initSvelteDevInspector});
1
+ "use strict";var g=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var R=(t,e)=>{for(var r in e)g(t,r,{get:e[r],enumerable:!0})},T=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of E(e))!q.call(t,s)&&s!==r&&g(t,s,{get:()=>e[s],enumerable:!(n=v(e,s))||n.enumerable});return t};var _=t=>T(g({},"__esModule",{value:!0}),t);var C={};R(C,{audit:()=>i,auditFetch:()=>S,auditHandle:()=>M,enableNetworkTracing:()=>D,handleSvelteKitError:()=>k,initSvelteDevInspector:()=>x});module.exports=_(C);var y=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},n=this.truncate(r,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let r=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let n=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),r.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,n=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(d=>this.truncate(d,r,n));let o={};for(let[d,a]of Object.entries(e))o[d]=this.truncate(a,r,n);return o}return e}captureError(e,r={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),d=r.requestId,a=r.traceId,c=r.spanId,u={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:d,traceId:a,spanId:c,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(u)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},b="__DEVINSPECT_AUDIT_CORE_INSTANCE__",A=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[b]||(t[b]=new y),t[b]},i=A();async function w(t,e,r){let n=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof t=="string"?s=t:t instanceof URL?s=t.toString():typeof t=="object"&&t!==null&&"url"in t&&(s=t.url),s&&i.isIngestUrl(s))return n(t,e);let o=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),d=i.createRequestId(),a=i.createTraceId(),c=i.createSpanId(),u=new Headers(e?.headers||(typeof t=="object"&&t!==null&&"headers"in t?t.headers:void 0));u.set("x-devinspector-request-id",d),u.set("x-devinspector-trace-id",a),u.set("x-devinspector-span-id",c);let p={...e,headers:u},f=typeof performance<"u"?performance.now():Date.now();try{let l=await n(t,p),h=Math.round((typeof performance<"u"?performance.now():Date.now())-f),I=i.getSlowThresholdMs();return(l.status>=400||h>=I)&&i.captureRequest({method:o,url:s,statusCode:l.status,durationMs:h,route:s,requestId:d,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:l.status,durationMs:h,requestId:d,traceId:a,spanId:c}}),l}catch(l){let h=Math.round((typeof performance<"u"?performance.now():Date.now())-f);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:h,route:s,requestId:d,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.captureException(l instanceof Error?l:new Error(String(l)),{url:s,method:o,type:r?.errorType||"network_error",requestId:d,traceId:a,spanId:c}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:h,requestId:d,traceId:a,spanId:c}}),l}}function x(t){i.init(t)}async function S(t,e){return w(t,e,{errorType:"svelte_network_error"})}async function M({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),n=t.request?.method||"GET",s=t.url?.pathname||t.url?.href||"/",o=t.route?.id||s;if(s&&i.isIngestUrl(s))return e(t);let d=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"",a=m(t.request,"x-devinspector-request-id")||i.createRequestId(),c=m(t.request,"x-devinspector-trace-id")||i.createTraceId(),u=m(t.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"http",message:`${n} ${s}`,metadata:{framework:"SvelteKit",phase:"start",requestId:a,traceId:c,spanId:u,route:o}});try{let p=await e(t),f=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return(p.status>=400||f>=300)&&i.captureRequest({method:n,url:s,statusCode:p.status,durationMs:f,route:o,userAgent:d,requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http",message:`${n} ${s}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:p.status,durationMs:f,requestId:a,traceId:c,spanId:u,route:o}}),p}catch(p){let f=Math.round((typeof performance<"u"?performance.now():Date.now())-r);i.captureRequest({method:n,url:s,statusCode:500,durationMs:f,route:o,userAgent:d,requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http_error",message:`${n} ${s}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:f,requestId:a,traceId:c,spanId:u,route:o}});let l=p instanceof Error?p:new Error(String(p));throw i.captureError(l,{framework:"SvelteKit",url:s,method:n,route:o,requestId:a,traceId:c,spanId:u}),p}}function k({error:t,event:e,status:r,message:n}){let s=t instanceof Error?t:new Error(String(t||n||"Erro SvelteKit")),o=m(e?.request,"x-devinspector-request-id")||i.createRequestId(),d=m(e?.request,"x-devinspector-trace-id")||i.createTraceId(),a=m(e?.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"sveltekit_error",message:s.message||"Erro SvelteKit",metadata:{status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:d,spanId:a}}),i.captureError(s,{framework:"SvelteKit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:d,spanId:a})}function D(){let t=globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=function(r,n){return w(r,n,{errorType:"svelte_network_error",nativeFetch:e})}}function m(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]||t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}0&&(module.exports={audit,auditFetch,auditHandle,enableNetworkTracing,handleSvelteKitError,initSvelteDevInspector});
package/dist/svelte.d.cts CHANGED
@@ -3,8 +3,8 @@ export { audit } from './index.cjs';
3
3
 
4
4
  declare function initSvelteDevInspector(options: InitOptions): void;
5
5
  declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
6
- declare function auditHandle({ event, resolve }: any): Promise<any>;
7
- declare function handleSvelteKitError({ error, event, status, message }: any): void;
6
+ declare function auditHandle({ event, resolve, }: any): Promise<any>;
7
+ declare function handleSvelteKitError({ error, event, status, message, }: any): void;
8
8
  declare function enableNetworkTracing(): void;
9
9
 
10
10
  export { InitOptions, auditFetch, auditHandle, enableNetworkTracing, handleSvelteKitError, initSvelteDevInspector };
package/dist/svelte.d.ts CHANGED
@@ -3,8 +3,8 @@ export { audit } from './index.js';
3
3
 
4
4
  declare function initSvelteDevInspector(options: InitOptions): void;
5
5
  declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
6
- declare function auditHandle({ event, resolve }: any): Promise<any>;
7
- declare function handleSvelteKitError({ error, event, status, message }: any): void;
6
+ declare function auditHandle({ event, resolve, }: any): Promise<any>;
7
+ declare function handleSvelteKitError({ error, event, status, message, }: any): void;
8
8
  declare function enableNetworkTracing(): void;
9
9
 
10
10
  export { InitOptions, auditFetch, auditHandle, enableNetworkTracing, handleSvelteKitError, initSvelteDevInspector };
package/dist/svelte.js CHANGED
@@ -1 +1 @@
1
- var p=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((n,o)=>{let s=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),t&&t(n,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let o=n instanceof Error?n:new Error(String(n));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(n.has(e))return"[Circular Reference]";n.add(e);let o={};for(let[s,i]of Object.entries(e))o[s]=this.truncate(i,t,n);return o}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(n)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let n=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});n.ok||console.error(`[DevInspector] Erro na API (${n.status}): ${n.statusText}`)}catch(n){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",n)}}},d="__DEVINSPECT_AUDIT_CORE_INSTANCE__",l=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[d]||(r[d]=new p),r[d]},a=l();function m(r){a.init(r)}async function h(r,e){let t="";if(typeof r=="string"?t=r:r instanceof URL?t=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(t=r.url),t&&(t.includes("devinspector.com.br")||t.includes("/ingest/track")))return fetch(r,e);let n=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),o=typeof performance<"u"?performance.now():Date.now();try{let s=await fetch(r,e),i=Math.round((typeof performance<"u"?performance.now():Date.now())-o);return(s.status>=400||i>=300)&&a.captureRequest({method:n,url:t,statusCode:s.status,durationMs:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:t}),s}catch(s){let i=Math.round((typeof performance<"u"?performance.now():Date.now())-o);throw a.captureRequest({method:n,url:t,statusCode:0,durationMs:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:t}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:t,method:n,type:"svelte_network_error"}),s}}async function E({event:r,resolve:e}){let t=typeof performance<"u"?performance.now():Date.now(),n=r.request?.method||"GET",o=r.url?.pathname||r.url?.href||"/",s=r.route?.id||o,i=typeof r.request?.headers?.get=="function"&&r.request.headers.get("user-agent")||"";try{let c=await e(r),u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);return(c.status>=400||u>=300)&&a.captureRequest({method:n,url:o,statusCode:c.status,durationMs:u,route:s,userAgent:i}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);a.captureRequest({method:n,url:o,statusCode:500,durationMs:u,route:s,userAgent:i});let f=c instanceof Error?c:new Error(String(c));throw a.captureError(f,{framework:"sveltekit",url:o,method:n,route:s}),c}}function b({error:r,event:e,status:t,message:n}){let o=r instanceof Error?r:new Error(String(r||n||"Erro SvelteKit"));a.captureError(o,{framework:"sveltekit",status:t||500,url:e?.url?.href||"",route:e?.route?.id||""})}function v(){let r=globalThis;!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__||(r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(e,t){return h(e,t)})}export{a as audit,h as auditFetch,E as auditHandle,v as enableNetworkTracing,b as handleSvelteKitError,m as initSvelteDevInspector};
1
+ var b=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},n=this.truncate(r,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let r=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let n=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),r.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,n=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(d=>this.truncate(d,r,n));let o={};for(let[d,a]of Object.entries(e))o[d]=this.truncate(a,r,n);return o}return e}captureError(e,r={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),d=r.requestId,a=r.traceId,c=r.spanId,u={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:d,traceId:a,spanId:c,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(u)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},g="__DEVINSPECT_AUDIT_CORE_INSTANCE__",I=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[g]||(t[g]=new b),t[g]},i=I();async function y(t,e,r){let n=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof t=="string"?s=t:t instanceof URL?s=t.toString():typeof t=="object"&&t!==null&&"url"in t&&(s=t.url),s&&i.isIngestUrl(s))return n(t,e);let o=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),d=i.createRequestId(),a=i.createTraceId(),c=i.createSpanId(),u=new Headers(e?.headers||(typeof t=="object"&&t!==null&&"headers"in t?t.headers:void 0));u.set("x-devinspector-request-id",d),u.set("x-devinspector-trace-id",a),u.set("x-devinspector-span-id",c);let p={...e,headers:u},f=typeof performance<"u"?performance.now():Date.now();try{let l=await n(t,p),h=Math.round((typeof performance<"u"?performance.now():Date.now())-f),w=i.getSlowThresholdMs();return(l.status>=400||h>=w)&&i.captureRequest({method:o,url:s,statusCode:l.status,durationMs:h,route:s,requestId:d,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:l.status,durationMs:h,requestId:d,traceId:a,spanId:c}}),l}catch(l){let h=Math.round((typeof performance<"u"?performance.now():Date.now())-f);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:h,route:s,requestId:d,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.captureException(l instanceof Error?l:new Error(String(l)),{url:s,method:o,type:r?.errorType||"network_error",requestId:d,traceId:a,spanId:c}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:h,requestId:d,traceId:a,spanId:c}}),l}}function R(t){i.init(t)}async function T(t,e){return y(t,e,{errorType:"svelte_network_error"})}async function _({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),n=t.request?.method||"GET",s=t.url?.pathname||t.url?.href||"/",o=t.route?.id||s;if(s&&i.isIngestUrl(s))return e(t);let d=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"",a=m(t.request,"x-devinspector-request-id")||i.createRequestId(),c=m(t.request,"x-devinspector-trace-id")||i.createTraceId(),u=m(t.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"http",message:`${n} ${s}`,metadata:{framework:"SvelteKit",phase:"start",requestId:a,traceId:c,spanId:u,route:o}});try{let p=await e(t),f=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return(p.status>=400||f>=300)&&i.captureRequest({method:n,url:s,statusCode:p.status,durationMs:f,route:o,userAgent:d,requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http",message:`${n} ${s}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:p.status,durationMs:f,requestId:a,traceId:c,spanId:u,route:o}}),p}catch(p){let f=Math.round((typeof performance<"u"?performance.now():Date.now())-r);i.captureRequest({method:n,url:s,statusCode:500,durationMs:f,route:o,userAgent:d,requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http_error",message:`${n} ${s}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:f,requestId:a,traceId:c,spanId:u,route:o}});let l=p instanceof Error?p:new Error(String(p));throw i.captureError(l,{framework:"SvelteKit",url:s,method:n,route:o,requestId:a,traceId:c,spanId:u}),p}}function A({error:t,event:e,status:r,message:n}){let s=t instanceof Error?t:new Error(String(t||n||"Erro SvelteKit")),o=m(e?.request,"x-devinspector-request-id")||i.createRequestId(),d=m(e?.request,"x-devinspector-trace-id")||i.createTraceId(),a=m(e?.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"sveltekit_error",message:s.message||"Erro SvelteKit",metadata:{status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:d,spanId:a}}),i.captureError(s,{framework:"SvelteKit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:d,spanId:a})}function x(){let t=globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=function(r,n){return y(r,n,{errorType:"svelte_network_error",nativeFetch:e})}}function m(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]||t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}export{i as audit,T as auditFetch,_ as auditHandle,x as enableNetworkTracing,A as handleSvelteKitError,R as initSvelteDevInspector};
package/dist/vanilla.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},b=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of w(e))!E.call(t,o)&&o!==n&&u(t,o,{get:()=>e[o],enumerable:!(r=g(e,o))||r.enumerable});return t};var v=t=>b(u({},"__esModule",{value:!0}),t);var R={};m(R,{audit:()=>i,auditFetch:()=>f,default:()=>I,enableNetworkTracing:()=>y});module.exports=v(R);var l=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(n)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let n=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((r,o)=>{let s=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),n&&n(r,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",n=>{this.captureError(n.error||new Error(n.message||"Erro global desconhecido"),{filename:n.filename,lineno:n.lineno,colno:n.colno})}),window.addEventListener("unhandledrejection",n=>{let r=n.reason instanceof Error?n.reason:new Error(String(n.reason));this.captureError(r,{type:"unhandled_rejection"})});else if(e.process?.on){let n=e.process;n.on("uncaughtException",r=>{this.captureError(r,{type:"uncaught_exception"})}),n.on("unhandledRejection",r=>{let o=r instanceof Error?r:new Error(String(r));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,n=5e3,r=new WeakSet){if(typeof e=="string")return e.length>n?e.substring(0,n)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let o={};for(let[s,c]of Object.entries(e))o[s]=this.truncate(c,n,r);return o}return e}captureError(e,n={}){let r=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...n,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,n={}){this.captureError(e,n)}captureMessage(e,n={}){let r={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...n,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let n=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":n},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[p]||(t[p]=new l),t[p]},i=_();var h=null;async function f(t,e,n){let r=n||h||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof t=="string"?o=t:t instanceof URL?o=t.toString():typeof t=="object"&&t!==null&&"url"in t&&(o=t.url),o&&(o.includes("devinspector.com.br")||o.includes("/ingest/track")))return r(t,e);let s=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(t,e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||d>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:d,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:o}),a}catch(a){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:d,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:o}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:"vanilla_network_error"}),a}}function y(){let t=typeof window<"u"?window:globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);h=e,t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(...n){let[r,o]=n;return f(r,o,e)}}typeof window<"u"&&(window.DevInspector={init:t=>i.init(t),captureError:(t,e)=>i.captureError(t,e),captureException:(t,e)=>i.captureException(t,e),captureMessage:(t,e)=>i.captureMessage(t,e),auditFetch:f,enableNetworkTracing:y,core:i});var I=i;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
1
+ "use strict";var h=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var t in e)h(r,t,{get:e[t],enumerable:!0})},q=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!_.call(r,s)&&s!==t&&h(r,s,{get:()=>e[s],enumerable:!(n=R(e,s))||n.enumerable});return r};var x=r=>q(h({},"__esModule",{value:!0}),r);var k={};A(k,{audit:()=>o,auditFetch:()=>g,default:()=>D,enableNetworkTracing:()=>I});module.exports=x(k);var m=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},n=this.truncate(t,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let t=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),t&&t(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,n));let i={};for(let[a,c]of Object.entries(e))i[a]=this.truncate(c,t,n);return i}return e}captureError(e,t={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),a=t.requestId,c=t.traceId,u=t.spanId,p={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...t,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",M=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[f]||(r[f]=new m),r[f]},o=M();async function y(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof r=="string"?s=r:r instanceof URL?s=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(s=r.url),s&&o.isIngestUrl(s))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),a=o.createRequestId(),c=o.createTraceId(),u=o.createSpanId(),p=new Headers(e?.headers||(typeof r=="object"&&r!==null&&"headers"in r?r.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",u);let v={...e,headers:p},b=typeof performance<"u"?performance.now():Date.now();try{let d=await n(r,v),l=Math.round((typeof performance<"u"?performance.now():Date.now())-b),E=o.getSlowThresholdMs();return(d.status>=400||l>=E)&&o.captureRequest({method:i,url:s,statusCode:d.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:d.status,durationMs:l,requestId:a,traceId:c,spanId:u}}),d}catch(d){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw o.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:i,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),o.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:u}}),d}}var w=null;async function g(r,e,t){return y(r,e,{errorType:"vanilla_network_error",nativeFetch:t||w||void 0})}function I(){let r=typeof window<"u"?window:globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);w=e,r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(...t){let[n,s]=t;return g(n,s,e)}}typeof window<"u"&&(window.DevInspector={init:r=>o.init(r),captureError:(r,e)=>o.captureError(r,e),captureException:(r,e)=>o.captureException(r,e),captureMessage:(r,e)=>o.captureMessage(r,e),auditFetch:g,enableNetworkTracing:I,core:o});var D=o;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
@@ -1 +1 @@
1
- "use strict";var DevInspector=(()=>{var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var n in e)u(t,n,{get:e[n],enumerable:!0})},b=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of w(e))!E.call(t,o)&&o!==n&&u(t,o,{get:()=>e[o],enumerable:!(r=g(e,o))||r.enumerable});return t};var v=t=>b(u({},"__esModule",{value:!0}),t);var R={};m(R,{audit:()=>i,auditFetch:()=>f,default:()=>I,enableNetworkTracing:()=>y});var l=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(n)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let n=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((r,o)=>{let s=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),n&&n(r,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",n=>{this.captureError(n.error||new Error(n.message||"Erro global desconhecido"),{filename:n.filename,lineno:n.lineno,colno:n.colno})}),window.addEventListener("unhandledrejection",n=>{let r=n.reason instanceof Error?n.reason:new Error(String(n.reason));this.captureError(r,{type:"unhandled_rejection"})});else if(e.process?.on){let n=e.process;n.on("uncaughtException",r=>{this.captureError(r,{type:"uncaught_exception"})}),n.on("unhandledRejection",r=>{let o=r instanceof Error?r:new Error(String(r));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,n=5e3,r=new WeakSet){if(typeof e=="string")return e.length>n?e.substring(0,n)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let o={};for(let[s,c]of Object.entries(e))o[s]=this.truncate(c,n,r);return o}return e}captureError(e,n={}){let r=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...n,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,n={}){this.captureError(e,n)}captureMessage(e,n={}){let r={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...n,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let n=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":n},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[p]||(t[p]=new l),t[p]},i=_();var h=null;async function f(t,e,n){let r=n||h||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof t=="string"?o=t:t instanceof URL?o=t.toString():typeof t=="object"&&t!==null&&"url"in t&&(o=t.url),o&&(o.includes("devinspector.com.br")||o.includes("/ingest/track")))return r(t,e);let s=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(t,e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||d>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:d,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:o}),a}catch(a){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:d,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:o}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:"vanilla_network_error"}),a}}function y(){let t=typeof window<"u"?window:globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);h=e,t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(...n){let[r,o]=n;return f(r,o,e)}}typeof window<"u"&&(window.DevInspector={init:t=>i.init(t),captureError:(t,e)=>i.captureError(t,e),captureException:(t,e)=>i.captureException(t,e),captureMessage:(t,e)=>i.captureMessage(t,e),auditFetch:f,enableNetworkTracing:y,core:i});var I=i;return v(R);})();
1
+ "use strict";var DevInspector=(()=>{var h=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var t in e)h(r,t,{get:e[t],enumerable:!0})},q=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!_.call(r,s)&&s!==t&&h(r,s,{get:()=>e[s],enumerable:!(n=R(e,s))||n.enumerable});return r};var x=r=>q(h({},"__esModule",{value:!0}),r);var k={};A(k,{audit:()=>o,auditFetch:()=>g,default:()=>D,enableNetworkTracing:()=>I});var m=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},n=this.truncate(t,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let t=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),t&&t(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,n));let i={};for(let[a,c]of Object.entries(e))i[a]=this.truncate(c,t,n);return i}return e}captureError(e,t={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),a=t.requestId,c=t.traceId,u=t.spanId,p={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...t,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",M=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[f]||(r[f]=new m),r[f]},o=M();async function y(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof r=="string"?s=r:r instanceof URL?s=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(s=r.url),s&&o.isIngestUrl(s))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),a=o.createRequestId(),c=o.createTraceId(),u=o.createSpanId(),p=new Headers(e?.headers||(typeof r=="object"&&r!==null&&"headers"in r?r.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",u);let v={...e,headers:p},b=typeof performance<"u"?performance.now():Date.now();try{let d=await n(r,v),l=Math.round((typeof performance<"u"?performance.now():Date.now())-b),E=o.getSlowThresholdMs();return(d.status>=400||l>=E)&&o.captureRequest({method:i,url:s,statusCode:d.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:d.status,durationMs:l,requestId:a,traceId:c,spanId:u}}),d}catch(d){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw o.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:i,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),o.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:u}}),d}}var w=null;async function g(r,e,t){return y(r,e,{errorType:"vanilla_network_error",nativeFetch:t||w||void 0})}function I(){let r=typeof window<"u"?window:globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);w=e,r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(...t){let[n,s]=t;return g(n,s,e)}}typeof window<"u"&&(window.DevInspector={init:r=>o.init(r),captureError:(r,e)=>o.captureError(r,e),captureException:(r,e)=>o.captureException(r,e),captureMessage:(r,e)=>o.captureMessage(r,e),auditFetch:g,enableNetworkTracing:I,core:o});var D=o;return x(k);})();
package/dist/vanilla.js CHANGED
@@ -1 +1 @@
1
- var p=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(n)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let n=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((r,o)=>{let s=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),n&&n(r,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",n=>{this.captureError(n.error||new Error(n.message||"Erro global desconhecido"),{filename:n.filename,lineno:n.lineno,colno:n.colno})}),window.addEventListener("unhandledrejection",n=>{let r=n.reason instanceof Error?n.reason:new Error(String(n.reason));this.captureError(r,{type:"unhandled_rejection"})});else if(e.process?.on){let n=e.process;n.on("uncaughtException",r=>{this.captureError(r,{type:"uncaught_exception"})}),n.on("unhandledRejection",r=>{let o=r instanceof Error?r:new Error(String(r));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,n=5e3,r=new WeakSet){if(typeof e=="string")return e.length>n?e.substring(0,n)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let o={};for(let[s,c]of Object.entries(e))o[s]=this.truncate(c,n,r);return o}return e}captureError(e,n={}){let r=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...n,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,n={}){this.captureError(e,n)}captureMessage(e,n={}){let r={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...n,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let n=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":n},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},u="__DEVINSPECT_AUDIT_CORE_INSTANCE__",h=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[u]||(t[u]=new p),t[u]},i=h();var l=null;async function f(t,e,n){let r=n||l||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof t=="string"?o=t:t instanceof URL?o=t.toString():typeof t=="object"&&t!==null&&"url"in t&&(o=t.url),o&&(o.includes("devinspector.com.br")||o.includes("/ingest/track")))return r(t,e);let s=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(t,e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||d>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:d,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:o}),a}catch(a){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:d,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:o}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:"vanilla_network_error"}),a}}function y(){let t=typeof window<"u"?window:globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);l=e,t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(...n){let[r,o]=n;return f(r,o,e)}}typeof window<"u"&&(window.DevInspector={init:t=>i.init(t),captureError:(t,e)=>i.captureError(t,e),captureException:(t,e)=>i.captureException(t,e),captureMessage:(t,e)=>i.captureMessage(t,e),auditFetch:f,enableNetworkTracing:y,core:i});var m=i;export{i as audit,f as auditFetch,m as default,y as enableNetworkTracing};
1
+ var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},r=this.truncate(t,2e3);this.breadcrumbs.push(r),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(r)}captureDbQuery(e){let t=this.getContext(),r=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${r}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:r,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:r,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((r,s)=>{let i=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),t&&t(r,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let r=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(r,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",r=>{this.captureError(r,{type:"uncaught_exception"})}),t.on("unhandledRejection",r=>{let s=r instanceof Error?r:new Error(String(r));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,r=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(r.has(s))return"[Circular Reference]";if(r.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,r));let i={};for(let[a,c]of Object.entries(e))i[a]=this.truncate(c,t,r);return i}return e}captureError(e,t={}){let r=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),a=t.requestId,c=t.traceId,u=t.spanId,p={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...t,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let r=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:r.environment,release:r.release,timestamp:r.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},h="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[h]||(n[h]=new f),n[h]},o=v();async function g(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&o.isIngestUrl(s))return r(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),a=o.createRequestId(),c=o.createTraceId(),u=o.createSpanId(),p=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",u);let w={...e,headers:p},m=typeof performance<"u"?performance.now():Date.now();try{let d=await r(n,w),l=Math.round((typeof performance<"u"?performance.now():Date.now())-m),I=o.getSlowThresholdMs();return(d.status>=400||l>=I)&&o.captureRequest({method:i,url:s,statusCode:d.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:d.status,durationMs:l,requestId:a,traceId:c,spanId:u}}),d}catch(d){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-m);throw o.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:i,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),o.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:u}}),d}}var b=null;async function y(n,e,t){return g(n,e,{errorType:"vanilla_network_error",nativeFetch:t||b||void 0})}function E(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);b=e,n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(...t){let[r,s]=t;return y(r,s,e)}}typeof window<"u"&&(window.DevInspector={init:n=>o.init(n),captureError:(n,e)=>o.captureError(n,e),captureException:(n,e)=>o.captureException(n,e),captureMessage:(n,e)=>o.captureMessage(n,e),auditFetch:y,enableNetworkTracing:E,core:o});var A=o;export{o as audit,y as auditFetch,A as default,E as enableNetworkTracing};
package/dist/vue.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var y=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})},w=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of g(e))!h.call(r,o)&&o!==t&&c(r,o,{get:()=>e[o],enumerable:!(n=f(e,o))||n.enumerable});return r};var m=r=>w(c({},"__esModule",{value:!0}),r);var _={};y(_,{DevInspectorVue:()=>b,audit:()=>a,auditFetch:()=>p,enableNetworkTracing:()=>v});module.exports=m(_);var d=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((n,o)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),t&&t(n,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let o=n instanceof Error?n:new Error(String(n));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(n.has(e))return"[Circular Reference]";n.add(e);let o={};for(let[i,s]of Object.entries(e))o[i]=this.truncate(s,t,n);return o}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",o=e.stack||"",i={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(n)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let n=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});n.ok||console.error(`[DevInspector] Erro na API (${n.status}): ${n.statusText}`)}catch(n){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",n)}}},u="__DEVINSPECT_AUDIT_CORE_INSTANCE__",E=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[u]||(r[u]=new d),r[u]},a=E();async function p(r,e){let t="";if(typeof r=="string"?t=r:r instanceof URL?t=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(t=r.url),t&&(t.includes("devinspector.com.br")||t.includes("/ingest/track")))return fetch(r,e);let n=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),o=typeof performance<"u"?performance.now():Date.now();try{let i=await fetch(r,e),s=Math.round((typeof performance<"u"?performance.now():Date.now())-o);return(i.status>=400||s>=300)&&a.captureRequest({method:n,url:t,statusCode:i.status,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:t}),i}catch(i){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-o);throw a.captureRequest({method:n,url:t,statusCode:0,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:void 0,route:t}),a.captureException(i instanceof Error?i:new Error(String(i)),{url:t,method:n,type:"vue_network_error"}),i}}var b={install(r,e){if(a.init(e),r.config){let t=r.config.errorHandler;r.config.errorHandler=(n,o,i)=>{let s=n instanceof Error?n:new Error(String(n)),l=o?.$options?.name||o?.$options?.__name||o?.$type?.name;a.captureError(s,{framework:"vue",vueInfo:i,component:l}),typeof t=="function"?t(n,o,i):console.error(n)}}}};function v(){let r=typeof window<"u"?window:globalThis;!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__||(r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(e,t){return p(e,t)})}0&&(module.exports={DevInspectorVue,audit,auditFetch,enableNetworkTracing});
1
+ "use strict";var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var _=(n,e)=>{for(var r in e)m(n,r,{get:e[r],enumerable:!0})},T=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of v(e))!E.call(n,s)&&s!==r&&m(n,s,{get:()=>e[s],enumerable:!(t=I(e,s))||t.enumerable});return n};var R=n=>T(m({},"__esModule",{value:!0}),n);var M={};_(M,{DevInspectorVue:()=>x,audit:()=>a,auditFetch:()=>A,enableNetworkTracing:()=>D});module.exports=R(M);var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(i=>this.truncate(i,r,t));let o={};for(let[i,c]of Object.entries(e))o[i]=this.truncate(c,r,t);return o}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),i=r.requestId,c=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:i,traceId:c,spanId:u,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},h="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[h]||(n[h]=new f),n[h]},a=q();async function g(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&a.isIngestUrl(s))return t(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=a.createRequestId(),c=a.createTraceId(),u=a.createSpanId(),l=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));l.set("x-devinspector-request-id",i),l.set("x-devinspector-trace-id",c),l.set("x-devinspector-span-id",u);let y={...e,headers:l},b=typeof performance<"u"?performance.now():Date.now();try{let d=await t(n,y),p=Math.round((typeof performance<"u"?performance.now():Date.now())-b),w=a.getSlowThresholdMs();return(d.status>=400||p>=w)&&a.captureRequest({method:o,url:s,statusCode:d.status,durationMs:p,route:s,requestId:i,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:d.status,durationMs:p,requestId:i,traceId:c,spanId:u}}),d}catch(d){let p=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw a.captureRequest({method:o,url:s,statusCode:0,durationMs:p,route:s,requestId:i,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:o,type:r?.errorType||"network_error",requestId:i,traceId:c,spanId:u}),a.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:p,requestId:i,traceId:c,spanId:u}}),d}}async function A(n,e){return g(n,e,{errorType:"vue_network_error"})}var x={install(n,e){if(a.init(e),!n.config)return;let r=n.config.errorHandler;n.config.errorHandler=(t,s,o)=>{let i=t instanceof Error?t:new Error(String(t)),c=s?.$options?.name||s?.$options?.__name||s?.$type?.name;a.addBreadcrumb({type:"vue_error",message:i.message||"Erro capturado pelo Vue",metadata:{component:c,vueInfo:o}}),a.captureError(i,{framework:"Vue",vueInfo:o,component:c}),typeof r=="function"?r(t,s,o):console.error(t)}}};function D(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=function(r,t){return g(r,t,{errorType:"vue_network_error",nativeFetch:e})}}0&&(module.exports={DevInspectorVue,audit,auditFetch,enableNetworkTracing});