@xcodleox/devinspector 7.4.0 → 7.5.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.
package/dist/angular.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var L=Object.create;var l=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var x=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),y=t=>{throw TypeError(t)};var B=(t,e,n)=>e in t?l(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var A=(t,e)=>l(t,"name",{value:e,configurable:!0});var F=(t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Y(e))!z.call(t,o)&&o!==n&&l(t,o,{get:()=>e[o],enumerable:!(r=P(e,o))||r.enumerable});return t};var V=t=>J(l({},"__esModule",{value:!0}),t);var O=t=>[,,,L(t?.[x("metadata")]??null)],j=["class","method","getter","setter","accessor","field","value","get","set"],m=t=>t!==void 0&&typeof t!="function"?y("Function expected"):t,X=(t,e,n,r,o)=>({kind:j[t],name:e,metadata:r,addInitializer:s=>n._?y("Already initialized"):o.push(m(s||null))}),Z=(t,e)=>B(e,x("metadata"),t[3]),G=(t,e,n,r)=>{for(var o=0,s=t[e>>1],a=s&&s.length;o<a;o++)e&1?s[o].call(n):r=s[o].call(n,r);return r},N=(t,e,n,r,o,s)=>{var a,u,M,h,g,i=e&7,E=!!(e&8),p=!!(e&16),b=i>3?t.length+1:i?E?1:2:0,R=j[i+5],T=i>3&&(t[b-1]=[]),$=t[b]||(t[b]=[]),d=i&&(!p&&!E&&(o=o.prototype),i<5&&(i>3||!p)&&P(i<4?o:{get[n](){return K(this,s)},set[n](c){return C(this,s,c)}},n));i?p&&i<4&&A(s,(i>2?"set ":i>1?"get ":"")+n):A(o,n);for(var v=r.length-1;v>=0;v--)h=X(i,n,M={},t[3],$),i&&(h.static=E,h.private=p,g=h.access={has:p?c=>q(o,c):c=>n in c},i^3&&(g.get=p?c=>(i^1?K:ee)(c,o,i^4?s:d.get):c=>c[n]),i>2&&(g.set=p?(c,I)=>C(c,o,I,i^4?s:d.set):(c,I)=>c[n]=I)),u=(0,r[v])(i?i<4?p?s:d[R]:i>4?void 0:{get:d.get,set:d.set}:o,h),M._=1,i^4||u===void 0?m(u)&&(i>4?T.unshift(u):i?p?s=u:d[R]=u:o=u):typeof u!="object"||u===null?y("Object expected"):(m(a=u.get)&&(d.get=a),m(a=u.set)&&(d.set=a),m(a=u.init)&&T.unshift(a));return i||Z(t,o),d&&l(o,n,d),p?i^4?s:d:o};var k=(t,e,n)=>e.has(t)||y("Cannot "+n),q=(t,e)=>Object(e)!==e?y('Cannot use the "in" operator on this value'):t.has(e),K=(t,e,n)=>(k(t,e,"read from private field"),n?n.call(t):e.get(t));var C=(t,e,n,r)=>(k(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),ee=(t,e,n)=>(k(t,e,"access private method"),n);var re={};F(re,{AuditAngularErrorHandler:()=>f,auditInterceptor:()=>ne,devInspectorInterceptor:()=>W});module.exports=V(re);var H=require("@angular/core"),U=require("rxjs/operators");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 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,a]of Object.entries(e))o[s]=this.truncate(a,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)}}},_="__DEVINSPECT_AUDIT_CORE_INSTANCE__",te=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[_]||(t[_]=new D),t[_]},w=te();var Q,S;Q=[(0,H.Injectable)()];var f=class{handleError(e){let n=e instanceof Error?e:new Error(String(e));w.captureError(n,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};S=O(null),f=N(S,0,"AuditAngularErrorHandler",Q,f),G(S,1,f);var W=(t,e)=>{if(t.url&&(t.url.includes("devinspector.com.br")||t.url.includes("/ingest/track")))return e(t);let n=typeof performance<"u"?performance.now():Date.now();return e(t).pipe((0,U.tap)({next:r=>{if(r&&typeof r=="object"&&"status"in r&&"clone"in r){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-n),a=r.status;(a>=400||s>=300)&&w.captureRequest({method:t.method,url:t.urlWithParams||t.url,statusCode:a,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:t.url})}},error:r=>{let o=Math.round((typeof performance<"u"?performance.now():Date.now())-n);w.captureRequest({method:t.method,url:t.urlWithParams||t.url,statusCode:r?.status||0,durationMs:o,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:t.url}),w.captureException(new Error(`HTTP Error ${r?.status||0}: ${r?.message||r?.statusText||"Erro de rede no cliente"}`),{url:t.urlWithParams||t.url,method:t.method,status:r?.status})}}))},ne=W;0&&(module.exports={AuditAngularErrorHandler,auditInterceptor,devInspectorInterceptor});
1
+ "use strict";var H=Object.create;var l=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var K=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),g=n=>{throw TypeError(n)};var z=(n,e,t)=>e in n?l(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var S=(n,e)=>l(n,"name",{value:e,configurable:!0});var W=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},B=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of $(e))!Y.call(n,r)&&r!==t&&l(n,r,{get:()=>e[r],enumerable:!(o=j(e,r))||o.enumerable});return n};var J=n=>B(l({},"__esModule",{value:!0}),n);var O=n=>[,,,H(n?.[K("metadata")]??null)],P=["class","method","getter","setter","accessor","field","value","get","set"],w=n=>n!==void 0&&typeof n!="function"?g("Function expected"):n,V=(n,e,t,o,r)=>({kind:P[n],name:e,metadata:o,addInitializer:i=>t._?g("Already initialized"):r.push(w(i||null))}),X=(n,e)=>z(e,K("metadata"),n[3]),G=(n,e,t,o)=>{for(var r=0,i=n[e>>1],c=i&&i.length;r<c;r++)e&1?i[r].call(t):o=i[r].call(t,o);return o},N=(n,e,t,o,r,i)=>{var c,a,D,y,m,s=e&7,E=!!(e&8),p=!!(e&16),b=s>3?n.length+1:s?E?1:2:0,T=P[s+5],M=s>3&&(n[b-1]=[]),F=n[b]||(n[b]=[]),d=s&&(!p&&!E&&(r=r.prototype),s<5&&(s>3||!p)&&j(s<4?r:{get[t](){return x(this,i)},set[t](u){return C(this,i,u)}},t));s?p&&s<4&&S(i,(s>2?"set ":s>1?"get ":"")+t):S(r,t);for(var v=o.length-1;v>=0;v--)y=V(s,t,D={},n[3],F),s&&(y.static=E,y.private=p,m=y.access={has:p?u=>Z(r,u):u=>t in u},s^3&&(m.get=p?u=>(s^1?x:ee)(u,r,s^4?i:d.get):u=>u[t]),s>2&&(m.set=p?(u,I)=>C(u,r,I,s^4?i:d.set):(u,I)=>u[t]=I)),a=(0,o[v])(s?s<4?p?i:d[T]:s>4?void 0:{get:d.get,set:d.set}:r,y),D._=1,s^4||a===void 0?w(a)&&(s>4?M.unshift(a):s?p?i=a:d[T]=a:r=a):typeof a!="object"||a===null?g("Object expected"):(w(c=a.get)&&(d.get=c),w(c=a.set)&&(d.set=c),w(c=a.init)&&M.unshift(c));return s||X(n,r),d&&l(r,t,d),p?s^4?i:d:r};var R=(n,e,t)=>e.has(n)||g("Cannot "+t),Z=(n,e)=>Object(e)!==e?g('Cannot use the "in" operator on this value'):n.has(e),x=(n,e,t)=>(R(n,e,"read from private field"),t?t.call(n):e.get(n));var C=(n,e,t,o)=>(R(n,e,"write to private field"),o?o.call(n,t):e.set(n,t),t),ee=(n,e,t)=>(R(n,e,"access private method"),t);var re={};W(re,{AuditAngularErrorHandler:()=>h,audit:()=>f,auditInterceptor:()=>ne,devInspectorInterceptor:()=>q});module.exports=J(re);var L=require("@angular/core"),Q=require("rxjs/operators");var A=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()}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")}}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((o,r)=>{let i=o instanceof Error?o:new Error(String(o?.message||o||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!r}),t&&t(o,r)})}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 o=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(o,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",o=>{this.captureError(o,{type:"uncaught_exception"})}),t.on("unhandledRejection",o=>{let r=o instanceof Error?o:new Error(String(o));this.captureError(r,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,o=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(o.has(e))return"[Circular Reference]";o.add(e);let r={};for(let[i,c]of Object.entries(e))r[i]=this.truncate(c,t,o);return r}return e}captureError(e,t={}){let o=e.message||"Erro Desconhecido",r=e.stack||"",i={type:"error",message:this.truncate(o,500),stackTrace:this.truncate(r,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 o={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(o)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let o=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});o.ok||console.error(`[DevInspector] Erro na API (${o.status}): ${o.statusText}`)}catch(o){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",o)}}},k="__DEVINSPECT_AUDIT_CORE_INSTANCE__",te=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[k]||(n[k]=new A),n[k]},f=te();var U,_;U=[(0,L.Injectable)()];var h=class{handleError(e){let t=e instanceof Error?e:new Error(String(e));f.captureError(t,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};_=O(null),h=N(_,0,"AuditAngularErrorHandler",U,h),G(_,1,h);var q=(n,e)=>{let t=n.urlWithParams||n.url||"";if(t&&f.isIngestUrl(t))return e(n);let o=typeof performance<"u"?performance.now():Date.now();return e(n).pipe((0,Q.tap)({next:r=>{if(r&&typeof r=="object"&&"status"in r&&"clone"in r){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-o),a=r.status;(a>=400||c>=300)&&f.captureRequest({method:n.method,url:t,statusCode:a,durationMs:c,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url})}},error:r=>{let i=Math.round((typeof performance<"u"?performance.now():Date.now())-o);f.captureRequest({method:n.method,url:t,statusCode:r?.status||0,durationMs:i,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url}),f.captureException(new Error(`HTTP Error ${r?.status||0}: ${r?.message||r?.statusText||"Erro de rede no cliente"}`),{url:t,method:n.method,status:r?.status,type:"angular_network_error"})}}))},ne=q;0&&(module.exports={AuditAngularErrorHandler,audit,auditInterceptor,devInspectorInterceptor});
@@ -1,4 +1,5 @@
1
1
  import { ErrorHandler } from '@angular/core';
2
+ export { audit } from './index.cjs';
2
3
 
3
4
  declare class AuditAngularErrorHandler implements ErrorHandler {
4
5
  handleError(error: unknown): void;
package/dist/angular.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ErrorHandler } from '@angular/core';
2
+ export { audit } from './index.js';
2
3
 
3
4
  declare class AuditAngularErrorHandler implements ErrorHandler {
4
5
  handleError(error: unknown): void;
package/dist/angular.js CHANGED
@@ -1 +1 @@
1
- var H=Object.create;var I=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var P=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),h=t=>{throw TypeError(t)};var W=(t,e,n)=>e in t?I(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var A=(t,e)=>I(t,"name",{value:e,configurable:!0});var x=t=>[,,,H(t?.[P("metadata")]??null)],O=["class","method","getter","setter","accessor","field","value","get","set"],f=t=>t!==void 0&&typeof t!="function"?h("Function expected"):t,$=(t,e,n,r,o)=>({kind:O[t],name:e,metadata:r,addInitializer:s=>n._?h("Already initialized"):o.push(f(s||null))}),L=(t,e)=>W(e,P("metadata"),t[3]),j=(t,e,n,r)=>{for(var o=0,s=t[e>>1],a=s&&s.length;o<a;o++)e&1?s[o].call(n):r=s[o].call(n,r);return r},G=(t,e,n,r,o,s)=>{var a,u,M,l,w,i=e&7,g=!!(e&8),p=!!(e&16),E=i>3?t.length+1:i?g?1:2:0,R=O[i+5],T=i>3&&(t[E-1]=[]),Q=t[E]||(t[E]=[]),d=i&&(!p&&!g&&(o=o.prototype),i<5&&(i>3||!p)&&U(i<4?o:{get[n](){return K(this,s)},set[n](c){return C(this,s,c)}},n));i?p&&i<4&&A(s,(i>2?"set ":i>1?"get ":"")+n):A(o,n);for(var b=r.length-1;b>=0;b--)l=$(i,n,M={},t[3],Q),i&&(l.static=g,l.private=p,w=l.access={has:p?c=>Y(o,c):c=>n in c},i^3&&(w.get=p?c=>(i^1?K:z)(c,o,i^4?s:d.get):c=>c[n]),i>2&&(w.set=p?(c,v)=>C(c,o,v,i^4?s:d.set):(c,v)=>c[n]=v)),u=(0,r[b])(i?i<4?p?s:d[R]:i>4?void 0:{get:d.get,set:d.set}:o,l),M._=1,i^4||u===void 0?f(u)&&(i>4?T.unshift(u):i?p?s=u:d[R]=u:o=u):typeof u!="object"||u===null?h("Object expected"):(f(a=u.get)&&(d.get=a),f(a=u.set)&&(d.set=a),f(a=u.init)&&T.unshift(a));return i||L(t,o),d&&I(o,n,d),p?i^4?s:d:o};var k=(t,e,n)=>e.has(t)||h("Cannot "+n),Y=(t,e)=>Object(e)!==e?h('Cannot use the "in" operator on this value'):t.has(e),K=(t,e,n)=>(k(t,e,"read from private field"),n?n.call(t):e.get(t));var C=(t,e,n,r)=>(k(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),z=(t,e,n)=>(k(t,e,"access private method"),n);import{Injectable as F}from"@angular/core";import{tap as J}from"rxjs/operators";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 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,a]of Object.entries(e))o[s]=this.truncate(a,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)}}},_="__DEVINSPECT_AUDIT_CORE_INSTANCE__",B=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[_]||(t[_]=new D),t[_]},m=B();var N,S;N=[F()];var y=class{handleError(e){let n=e instanceof Error?e:new Error(String(e));m.captureError(n,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};S=x(null),y=G(S,0,"AuditAngularErrorHandler",N,y),j(S,1,y);var V=(t,e)=>{if(t.url&&(t.url.includes("devinspector.com.br")||t.url.includes("/ingest/track")))return e(t);let n=typeof performance<"u"?performance.now():Date.now();return e(t).pipe(J({next:r=>{if(r&&typeof r=="object"&&"status"in r&&"clone"in r){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-n),a=r.status;(a>=400||s>=300)&&m.captureRequest({method:t.method,url:t.urlWithParams||t.url,statusCode:a,durationMs:s,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:t.url})}},error:r=>{let o=Math.round((typeof performance<"u"?performance.now():Date.now())-n);m.captureRequest({method:t.method,url:t.urlWithParams||t.url,statusCode:r?.status||0,durationMs:o,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:t.url}),m.captureException(new Error(`HTTP Error ${r?.status||0}: ${r?.message||r?.statusText||"Erro de rede no cliente"}`),{url:t.urlWithParams||t.url,method:t.method,status:r?.status})}}))},re=V;export{y as AuditAngularErrorHandler,re as auditInterceptor,V as devInspectorInterceptor};
1
+ var L=Object.create;var I=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var j=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),y=n=>{throw TypeError(n)};var q=(n,e,t)=>e in n?I(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var S=(n,e)=>I(n,"name",{value:e,configurable:!0});var K=n=>[,,,L(n?.[j("metadata")]??null)],O=["class","method","getter","setter","accessor","field","value","get","set"],h=n=>n!==void 0&&typeof n!="function"?y("Function expected"):n,F=(n,e,t,r,o)=>({kind:O[n],name:e,metadata:r,addInitializer:i=>t._?y("Already initialized"):o.push(h(i||null))}),H=(n,e)=>q(e,j("metadata"),n[3]),P=(n,e,t,r)=>{for(var o=0,i=n[e>>1],c=i&&i.length;o<c;o++)e&1?i[o].call(t):r=i[o].call(t,r);return r},G=(n,e,t,r,o,i)=>{var c,a,D,l,g,s=e&7,m=!!(e&8),p=!!(e&16),E=s>3?n.length+1:s?m?1:2:0,T=O[s+5],M=s>3&&(n[E-1]=[]),U=n[E]||(n[E]=[]),d=s&&(!p&&!m&&(o=o.prototype),s<5&&(s>3||!p)&&Q(s<4?o:{get[t](){return x(this,i)},set[t](u){return C(this,i,u)}},t));s?p&&s<4&&S(i,(s>2?"set ":s>1?"get ":"")+t):S(o,t);for(var b=r.length-1;b>=0;b--)l=F(s,t,D={},n[3],U),s&&(l.static=m,l.private=p,g=l.access={has:p?u=>$(o,u):u=>t in u},s^3&&(g.get=p?u=>(s^1?x:Y)(u,o,s^4?i:d.get):u=>u[t]),s>2&&(g.set=p?(u,v)=>C(u,o,v,s^4?i:d.set):(u,v)=>u[t]=v)),a=(0,r[b])(s?s<4?p?i:d[T]:s>4?void 0:{get:d.get,set:d.set}:o,l),D._=1,s^4||a===void 0?h(a)&&(s>4?M.unshift(a):s?p?i=a:d[T]=a:o=a):typeof a!="object"||a===null?y("Object expected"):(h(c=a.get)&&(d.get=c),h(c=a.set)&&(d.set=c),h(c=a.init)&&M.unshift(c));return s||H(n,o),d&&I(o,t,d),p?s^4?i:d:o};var R=(n,e,t)=>e.has(n)||y("Cannot "+t),$=(n,e)=>Object(e)!==e?y('Cannot use the "in" operator on this value'):n.has(e),x=(n,e,t)=>(R(n,e,"read from private field"),t?t.call(n):e.get(n));var C=(n,e,t,r)=>(R(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),Y=(n,e,t)=>(R(n,e,"access private method"),t);import{Injectable as W}from"@angular/core";import{tap as B}from"rxjs/operators";var A=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()}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")}}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((r,o)=>{let i=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),t&&t(r,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 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 o=r instanceof Error?r:new Error(String(r));this.captureError(o,{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"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let o={};for(let[i,c]of Object.entries(e))o[i]=this.truncate(c,t,r);return o}return e}captureError(e,t={}){let r=e.message||"Erro Desconhecido",o=e.stack||"",i={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({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){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({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=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":t},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)}}},k="__DEVINSPECT_AUDIT_CORE_INSTANCE__",z=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[k]||(n[k]=new A),n[k]},f=z();var N,_;N=[W()];var w=class{handleError(e){let t=e instanceof Error?e:new Error(String(e));f.captureError(t,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};_=K(null),w=G(_,0,"AuditAngularErrorHandler",N,w),P(_,1,w);var J=(n,e)=>{let t=n.urlWithParams||n.url||"";if(t&&f.isIngestUrl(t))return e(n);let r=typeof performance<"u"?performance.now():Date.now();return e(n).pipe(B({next:o=>{if(o&&typeof o=="object"&&"status"in o&&"clone"in o){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-r),a=o.status;(a>=400||c>=300)&&f.captureRequest({method:n.method,url:t,statusCode:a,durationMs:c,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url})}},error:o=>{let i=Math.round((typeof performance<"u"?performance.now():Date.now())-r);f.captureRequest({method:n.method,url:t,statusCode:o?.status||0,durationMs:i,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url}),f.captureException(new Error(`HTTP Error ${o?.status||0}: ${o?.message||o?.statusText||"Erro de rede no cliente"}`),{url:t,method:n.method,status:o?.status,type:"angular_network_error"})}}))},re=J;export{w as AuditAngularErrorHandler,f as audit,re as auditInterceptor,J as devInspectorInterceptor};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var f=(i,e)=>{for(var t in e)a(i,t,{get:e[t],enumerable:!0})},y=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!h.call(i,r)&&r!==t&&a(i,r,{get:()=>e[r],enumerable:!(n=p(e,r))||n.enumerable});return i};var g=i=>y(a({},"__esModule",{value:!0}),i);var m={};f(m,{AuditCore:()=>s,audit:()=>d});module.exports=g(m);var s=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,r)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!r}),t&&t(n,r)})}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 r=n instanceof Error?n:new Error(String(n));this.captureError(r,{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 r={};for(let[o,u]of Object.entries(e))r[o]=this.truncate(u,t,n);return r}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",r=e.stack||"",o={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(r,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(o)}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)}}},c="__DEVINSPECT_AUDIT_CORE_INSTANCE__",w=()=>{let i=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return i[c]||(i[c]=new s),i[c]},d=w();0&&(module.exports={AuditCore,audit});
1
+ "use strict";var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(o,e)=>{for(var t in e)a(o,t,{get:e[t],enumerable:!0})},y=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of l(e))!f.call(o,r)&&r!==t&&a(o,r,{get:()=>e[r],enumerable:!(n=p(e,r))||n.enumerable});return o};var g=o=>y(a({},"__esModule",{value:!0}),o);var m={};h(m,{AuditCore:()=>s,audit:()=>d});module.exports=g(m);var s=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()}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")}}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,r)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!r}),t&&t(n,r)})}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 r=n instanceof Error?n:new Error(String(n));this.captureError(r,{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 r={};for(let[i,u]of Object.entries(e))r[i]=this.truncate(u,t,n);return r}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",r=e.stack||"",i={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(r,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)}}},c="__DEVINSPECT_AUDIT_CORE_INSTANCE__",w=()=>{let o=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return o[c]||(o[c]=new s),o[c]},d=w();0&&(module.exports={AuditCore,audit});
package/dist/index.d.cts CHANGED
@@ -21,6 +21,7 @@ declare class AuditCore {
21
21
  initialized: boolean;
22
22
  private listenersAttached;
23
23
  init(options: InitOptions): void;
24
+ isIngestUrl(targetUrl: string): boolean;
24
25
  captureRequest(data: RequestMetricData): void;
25
26
  private listenGlobalErrors;
26
27
  private truncate;
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ declare class AuditCore {
21
21
  initialized: boolean;
22
22
  private listenersAttached;
23
23
  init(options: InitOptions): void;
24
+ isIngestUrl(targetUrl: string): boolean;
24
25
  captureRequest(data: RequestMetricData): void;
25
26
  private listenGlobalErrors;
26
27
  private truncate;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var s=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,r)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!r}),t&&t(n,r)})}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 r=n instanceof Error?n:new Error(String(n));this.captureError(r,{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 r={};for(let[i,c]of Object.entries(e))r[i]=this.truncate(c,t,n);return r}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",r=e.stack||"",i={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(r,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)}}},a="__DEVINSPECT_AUDIT_CORE_INSTANCE__",d=()=>{let o=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return o[a]||(o[a]=new s),o[a]},u=d();export{s as AuditCore,u as audit};
1
+ var s=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()}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")}}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,r)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!r}),t&&t(n,r)})}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 r=n instanceof Error?n:new Error(String(n));this.captureError(r,{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 r={};for(let[o,c]of Object.entries(e))r[o]=this.truncate(c,t,n);return r}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",r=e.stack||"",o={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(r,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(o)}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)}}},a="__DEVINSPECT_AUDIT_CORE_INSTANCE__",d=()=>{let i=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return i[a]||(i[a]=new s),i[a]},u=d();export{s as AuditCore,u as audit};
package/dist/next.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var E=(n,e)=>{for(var t in e)d(n,t,{get:e[t],enumerable:!0})},b=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of g(e))!m.call(n,o)&&o!==t&&d(n,o,{get:()=>e[o],enumerable:!(r=w(e,o))||r.enumerable});return n};var v=n=>b(d({},"__esModule",{value:!0}),n);var M={};E(M,{audit:()=>a,auditFetch:()=>I,captureNextError:()=>l,initNextDevInspector:()=>R,withAuditAction:()=>D,withAuditApi:()=>_});module.exports=v(M);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((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}),t&&t(r,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 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 o=r instanceof Error?r:new Error(String(r));this.captureError(o,{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"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let o={};for(let[s,i]of Object.entries(e))o[s]=this.truncate(i,t,r);return o}return e}captureError(e,t={}){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({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){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({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=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":t},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__",A=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new f),n[p]},a=A();function R(n){a.init(n)}function l(n,e={}){let t=n instanceof Error?n:new Error(String(n));a.captureError(t,{framework:"nextjs",...e})}async function I(n,e){let t="";if(typeof n=="string"?t=n:n instanceof URL?t=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(t=n.url),t&&(t.includes("devinspector.com.br")||t.includes("/ingest/track")))return fetch(n,e);let r=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),o=typeof performance<"u"?performance.now():Date.now();try{let s=await fetch(n,e),i=Math.round((typeof performance<"u"?performance.now():Date.now())-o);return(s.status>=400||i>=300)&&a.captureRequest({method:r,url:t,statusCode:s.status,durationMs:i,route:t,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),s}catch(s){let i=Math.round((typeof performance<"u"?performance.now():Date.now())-o);throw a.captureRequest({method:r,url:t,statusCode:0,durationMs:i,route:t,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:t,method:r,type:"nextjs_network_error"}),s}}function _(n){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),r=e[0],o=e[1],s=r?.method||"GET",i=r?.url||r?.nextUrl?.href||"/api",h=typeof r?.headers?.get=="function"?r.headers.get("user-agent")||"":r?.headers?.["user-agent"]||"";try{let c=await n(...e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-t),y=c?.status||o?.statusCode||200;return(y>=400||u>=300)&&a.captureRequest({method:s,url:i,statusCode:y,durationMs:u,route:i,userAgent:h}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw a.captureRequest({method:s,url:i,statusCode:500,durationMs:u,route:i,userAgent:h}),l(c,{url:i,method:s,type:"api_route_error"}),c}}}function D(n,e){return(async(...t)=>{let r=typeof performance<"u"?performance.now():Date.now();try{let o=await e(...t),s=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return s>=300&&a.captureRequest({method:"ACTION",url:n,statusCode:200,durationMs:s,route:n}),o}catch(o){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-r);throw a.captureRequest({method:"ACTION",url:n,statusCode:500,durationMs:s,route:n}),l(o,{actionName:n,type:"server_action_error"}),o}})}0&&(module.exports={audit,auditFetch,captureNextError,initNextDevInspector,withAuditAction,withAuditApi});
1
+ "use strict";var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var t in e)p(n,t,{get:e[t],enumerable:!0})},v=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!E.call(n,o)&&o!==t&&p(n,o,{get:()=>e[o],enumerable:!(r=g(e,o))||r.enumerable});return n};var A=n=>v(p({},"__esModule",{value:!0}),n);var M={};b(M,{audit:()=>i,auditFetch:()=>T,captureNextError:()=>h,initNextDevInspector:()=>I,withAuditAction:()=>D,withAuditApi:()=>_});module.exports=A(M);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()}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")}}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((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}),t&&t(r,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 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 o=r instanceof Error?r:new Error(String(r));this.captureError(o,{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"&&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,t,r);return o}return e}captureError(e,t={}){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({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){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({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=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":t},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)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",R=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[f]||(n[f]=new l),n[f]},i=R();async function w(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&i.isIngestUrl(o))return r(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||u>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a}catch(a){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:t?.errorType||"network_error"}),a}}function I(n){i.init(n)}function h(n,e={}){let t=n instanceof Error?n:new Error(String(n));i.captureError(t,{framework:"nextjs",...e})}async function T(n,e){return w(n,e,{errorType:"nextjs_network_error"})}function _(n){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),r=e[0],o=e[1],s=r?.method||"GET",c=r?.url||r?.nextUrl?.href||"/api",a=typeof r?.headers?.get=="function"?r.headers.get("user-agent")||"":r?.headers?.["user-agent"]||"";try{let u=await n(...e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-t),y=u?.status||o?.statusCode||200;return(y>=400||d>=300)&&i.captureRequest({method:s,url:c,statusCode:y,durationMs:d,route:c,userAgent:a}),u}catch(u){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw i.captureRequest({method:s,url:c,statusCode:500,durationMs:d,route:c,userAgent:a}),h(u,{url:c,method:s,type:"api_route_error"}),u}}}function D(n,e){return(async(...t)=>{let r=typeof performance<"u"?performance.now():Date.now();try{let o=await e(...t),s=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return s>=300&&i.captureRequest({method:"ACTION",url:n,statusCode:200,durationMs:s,route:n}),o}catch(o){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-r);throw i.captureRequest({method:"ACTION",url:n,statusCode:500,durationMs:s,route:n}),h(o,{actionName:n,type:"server_action_error"}),o}})}0&&(module.exports={audit,auditFetch,captureNextError,initNextDevInspector,withAuditAction,withAuditApi});
package/dist/next.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((r,s)=>{let o=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(o,{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"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let s={};for(let[o,i]of Object.entries(e))s[o]=this.truncate(i,t,r);return s}return e}captureError(e,t={}){let r=e.message||"Erro Desconhecido",s=e.stack||"",o={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:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(o)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){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({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=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":t},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)}}},d="__DEVINSPECT_AUDIT_CORE_INSTANCE__",y=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[d]||(n[d]=new p),n[d]},a=y();function E(n){a.init(n)}function h(n,e={}){let t=n instanceof Error?n:new Error(String(n));a.captureError(t,{framework:"nextjs",...e})}async function b(n,e){let t="";if(typeof n=="string"?t=n:n instanceof URL?t=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(t=n.url),t&&(t.includes("devinspector.com.br")||t.includes("/ingest/track")))return fetch(n,e);let r=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),s=typeof performance<"u"?performance.now():Date.now();try{let o=await fetch(n,e),i=Math.round((typeof performance<"u"?performance.now():Date.now())-s);return(o.status>=400||i>=300)&&a.captureRequest({method:r,url:t,statusCode:o.status,durationMs:i,route:t,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),o}catch(o){let i=Math.round((typeof performance<"u"?performance.now():Date.now())-s);throw a.captureRequest({method:r,url:t,statusCode:0,durationMs:i,route:t,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),a.captureException(o instanceof Error?o:new Error(String(o)),{url:t,method:r,type:"nextjs_network_error"}),o}}function v(n){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),r=e[0],s=e[1],o=r?.method||"GET",i=r?.url||r?.nextUrl?.href||"/api",f=typeof r?.headers?.get=="function"?r.headers.get("user-agent")||"":r?.headers?.["user-agent"]||"";try{let c=await n(...e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-t),l=c?.status||s?.statusCode||200;return(l>=400||u>=300)&&a.captureRequest({method:o,url:i,statusCode:l,durationMs:u,route:i,userAgent:f}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw a.captureRequest({method:o,url:i,statusCode:500,durationMs:u,route:i,userAgent:f}),h(c,{url:i,method:o,type:"api_route_error"}),c}}}function A(n,e){return(async(...t)=>{let r=typeof performance<"u"?performance.now():Date.now();try{let s=await e(...t),o=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return o>=300&&a.captureRequest({method:"ACTION",url:n,statusCode:200,durationMs:o,route:n}),s}catch(s){let o=Math.round((typeof performance<"u"?performance.now():Date.now())-r);throw a.captureRequest({method:"ACTION",url:n,statusCode:500,durationMs:o,route:n}),h(s,{actionName:n,type:"server_action_error"}),s}})}export{a as audit,b as auditFetch,h as captureNextError,E as initNextDevInspector,A as withAuditAction,v as withAuditApi};
1
+ 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()}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")}}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,c]of Object.entries(e))o[s]=this.truncate(c,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__",w=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[p]||(r[p]=new f),r[p]},a=w();async function h(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof r=="string"?o=r:r instanceof URL?o=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(o=r.url),o&&a.isIngestUrl(o))return n(r,e);let s=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let i=await n(r,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(i.status>=400||u>=300)&&a.captureRequest({method:s,url:o,statusCode:i.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i}catch(i){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a.captureException(i instanceof Error?i:new Error(String(i)),{url:o,method:s,type:t?.errorType||"network_error"}),i}}function b(r){a.init(r)}function y(r,e={}){let t=r instanceof Error?r:new Error(String(r));a.captureError(t,{framework:"nextjs",...e})}async function v(r,e){return h(r,e,{errorType:"nextjs_network_error"})}function A(r){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),n=e[0],o=e[1],s=n?.method||"GET",c=n?.url||n?.nextUrl?.href||"/api",i=typeof n?.headers?.get=="function"?n.headers.get("user-agent")||"":n?.headers?.["user-agent"]||"";try{let u=await r(...e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-t),l=u?.status||o?.statusCode||200;return(l>=400||d>=300)&&a.captureRequest({method:s,url:c,statusCode:l,durationMs:d,route:c,userAgent:i}),u}catch(u){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw a.captureRequest({method:s,url:c,statusCode:500,durationMs:d,route:c,userAgent:i}),y(u,{url:c,method:s,type:"api_route_error"}),u}}}function R(r,e){return(async(...t)=>{let n=typeof performance<"u"?performance.now():Date.now();try{let o=await e(...t),s=Math.round((typeof performance<"u"?performance.now():Date.now())-n);return s>=300&&a.captureRequest({method:"ACTION",url:r,statusCode:200,durationMs:s,route:r}),o}catch(o){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-n);throw a.captureRequest({method:"ACTION",url:r,statusCode:500,durationMs:s,route:r}),y(o,{actionName:r,type:"server_action_error"}),o}})}export{a as audit,v as auditFetch,y as captureNextError,b as initNextDevInspector,R as withAuditAction,A as withAuditApi};
package/dist/node.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var r in e)d(n,r,{get:e[r],enumerable:!0})},k=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of I(e))!M.call(n,o)&&o!==r&&d(n,o,{get:()=>e[o],enumerable:!(t=v(e,o))||t.enumerable});return n};var C=n=>k(d({},"__esModule",{value:!0}),n);var D={};S(D,{auditOperation:()=>x,devInspector:()=>T,devInspectorErrorHandler:()=>_});module.exports=C(D);var y=require("async_hooks");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 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)}}},l="__DEVINSPECT_AUDIT_CORE_INSTANCE__",A=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[l]||(n[l]=new p),n[l]},c=A();var h=new y.AsyncLocalStorage;function R(n){if(!n)return{};let e={...n},r=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let t of r)e[t]&&(e[t]="[REDACTED]");return e}function T(n){c.init(n);let e=n.slowThresholdMs??300,r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,o,i)=>{let s=t.originalUrl||t.url||"";if(r.some(a=>typeof a=="string"?s.startsWith(a):a.test(s)))return i();let g=performance.now();h.run({req:t,queriesCount:0,slowQueries:0},()=>{o.on("finish",()=>{let a=Math.round(performance.now()-g),u=h.getStore(),f=o.statusCode,w=f>=400,m=a>=e,E=(u?.slowQueries||0)>0;if(w||m||E){let b=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||s;c.captureRequest({method:t.method,url:s,statusCode:f,durationMs:a,userAgent:t.headers["user-agent"],route:b,dbQueriesCount:u?.queriesCount||0,slowQueryMs:u?.slowQueries||0})}}),i()})}}async function x(n,e,r=300){let t=h.getStore(),o=performance.now();t&&t.queriesCount++;try{let i=await e(),s=performance.now()-o;return s>r&&t&&(t.slowQueries=Math.max(t.slowQueries,Math.round(s)),c.captureMessage(`Slow Query detectada em [${n}]`,{durationMs:Math.round(s),operationName:n,url:t.req?.originalUrl||t.req?.url})),i}catch(i){let s=performance.now()-o;throw c.captureException(i,{operationName:n,durationMs:Math.round(s)}),i}}function _(){return(n,e,r,t)=>{c.captureException(n,{url:e.originalUrl||e.url,method:e.method,headers:R(e.headers)}),t(n)}}0&&(module.exports={auditOperation,devInspector,devInspectorErrorHandler});
1
+ "use strict";var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var r in e)p(n,r,{get:e[r],enumerable:!0})},T=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!M.call(n,o)&&o!==r&&p(n,o,{get:()=>e[o],enumerable:!(t=R(e,o))||t.enumerable});return n};var k=n=>T(p({},"__esModule",{value:!0}),n);var Q={};S(Q,{audit:()=>a,auditFetch:()=>D,auditOperation:()=>O,devInspector:()=>_,devInspectorErrorHandler:()=>P});module.exports=k(Q);var m=require("async_hooks");var h=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()}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")}}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 s=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(s,{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[s,i]of Object.entries(e))o[s]=this.truncate(i,r,t);return o}return e}captureError(e,r={}){let t=e.message||"Erro Desconhecido",o=e.stack||"",s={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(s)}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)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",x=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[f]||(n[f]=new h),n[f]},a=x();async function w(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=typeof performance<"u"?performance.now():Date.now();try{let c=await t(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);return(c.status>=400||u>=300)&&a.captureRequest({method:s,url:o,statusCode:c.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);throw a.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(c instanceof Error?c:new Error(String(c)),{url:o,method:s,type:r?.errorType||"network_error"}),c}}var y=new m.AsyncLocalStorage;function C(n){if(!n)return{};let e={...n},r=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let t of r)e[t]&&(e[t]="[REDACTED]");return e}function _(n){a.init(n);let e=n.slowThresholdMs??300,r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,o,s)=>{let i=t.originalUrl||t.url||"";if(i&&a.isIngestUrl(i)||r.some(d=>typeof d=="string"?i.startsWith(d):d.test(i)))return s();let u=performance.now();y.run({req:t,queriesCount:0,slowQueries:0},()=>{o.on("finish",()=>{let d=Math.round(performance.now()-u),l=y.getStore(),g=o.statusCode,b=g>=400,E=d>=e,v=(l?.slowQueries||0)>0;if(b||E||v){let I=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||i;a.captureRequest({method:t.method,url:i,statusCode:g,durationMs:d,userAgent:t.headers?.["user-agent"],route:I,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0})}}),s()})}}async function D(n,e){return w(n,e,{errorType:"node_network_error"})}async function O(n,e,r=300){let t=y.getStore(),o=performance.now();t&&t.queriesCount++;try{let s=await e(),i=performance.now()-o;return i>r&&t&&(t.slowQueries=Math.max(t.slowQueries,Math.round(i)),a.captureMessage(`Slow Query detectada em [${n}]`,{durationMs:Math.round(i),operationName:n,url:t.req?.originalUrl||t.req?.url})),s}catch(s){let i=performance.now()-o;throw a.captureException(s,{operationName:n,durationMs:Math.round(i)}),s}}function P(){return(n,e,r,t)=>{a.captureException(n,{url:e.originalUrl||e.url,method:e.method,headers:C(e.headers)}),t(n)}}0&&(module.exports={audit,auditFetch,auditOperation,devInspector,devInspectorErrorHandler});
package/dist/node.d.cts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { InitOptions } from './index.cjs';
2
+ export { audit } from './index.cjs';
2
3
 
3
4
  interface DevInspectorNodeOptions extends InitOptions {
4
5
  slowThresholdMs?: number;
5
6
  ignorePaths?: (string | RegExp)[];
6
7
  }
7
8
  declare function devInspector(options: DevInspectorNodeOptions): (req: any, res: any, next: any) => any;
9
+ declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
8
10
  declare function auditOperation<T>(name: string, operation: () => Promise<T>, thresholdMs?: number): Promise<T>;
9
11
  declare function devInspectorErrorHandler(): (err: any, req: any, res: any, next: any) => void;
10
12
 
11
- export { type DevInspectorNodeOptions, auditOperation, devInspector, devInspectorErrorHandler };
13
+ export { type DevInspectorNodeOptions, InitOptions, auditFetch, auditOperation, devInspector, devInspectorErrorHandler };
package/dist/node.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { InitOptions } from './index.js';
2
+ export { audit } from './index.js';
2
3
 
3
4
  interface DevInspectorNodeOptions extends InitOptions {
4
5
  slowThresholdMs?: number;
5
6
  ignorePaths?: (string | RegExp)[];
6
7
  }
7
8
  declare function devInspector(options: DevInspectorNodeOptions): (req: any, res: any, next: any) => any;
9
+ declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
8
10
  declare function auditOperation<T>(name: string, operation: () => Promise<T>, thresholdMs?: number): Promise<T>;
9
11
  declare function devInspectorErrorHandler(): (err: any, req: any, res: any, next: any) => void;
10
12
 
11
- export { type DevInspectorNodeOptions, auditOperation, devInspector, devInspectorErrorHandler };
13
+ export { type DevInspectorNodeOptions, InitOptions, auditFetch, auditOperation, devInspector, devInspectorErrorHandler };
package/dist/node.js CHANGED
@@ -1 +1 @@
1
- import{AsyncLocalStorage as b}from"async_hooks";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 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__",E=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[d]||(n[d]=new l),n[d]},c=E();var p=new b;function v(n){if(!n)return{};let e={...n},r=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let t of r)e[t]&&(e[t]="[REDACTED]");return e}function C(n){c.init(n);let e=n.slowThresholdMs??300,r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,o,i)=>{let s=t.originalUrl||t.url||"";if(r.some(a=>typeof a=="string"?s.startsWith(a):a.test(s)))return i();let f=performance.now();p.run({req:t,queriesCount:0,slowQueries:0},()=>{o.on("finish",()=>{let a=Math.round(performance.now()-f),u=p.getStore(),h=o.statusCode,y=h>=400,g=a>=e,w=(u?.slowQueries||0)>0;if(y||g||w){let m=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||s;c.captureRequest({method:t.method,url:s,statusCode:h,durationMs:a,userAgent:t.headers["user-agent"],route:m,dbQueriesCount:u?.queriesCount||0,slowQueryMs:u?.slowQueries||0})}}),i()})}}async function A(n,e,r=300){let t=p.getStore(),o=performance.now();t&&t.queriesCount++;try{let i=await e(),s=performance.now()-o;return s>r&&t&&(t.slowQueries=Math.max(t.slowQueries,Math.round(s)),c.captureMessage(`Slow Query detectada em [${n}]`,{durationMs:Math.round(s),operationName:n,url:t.req?.originalUrl||t.req?.url})),i}catch(i){let s=performance.now()-o;throw c.captureException(i,{operationName:n,durationMs:Math.round(s)}),i}}function R(){return(n,e,r,t)=>{c.captureException(n,{url:e.originalUrl||e.url,method:e.method,headers:v(e.headers)}),t(n)}}export{A as auditOperation,C as devInspector,R as devInspectorErrorHandler};
1
+ import{AsyncLocalStorage as I}from"async_hooks";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()}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")}}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 s=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(s,{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[s,i]of Object.entries(e))o[s]=this.truncate(i,r,t);return o}return e}captureError(e,r={}){let t=e.message||"Erro Desconhecido",o=e.stack||"",s={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(s)}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)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new f),n[p]},a=v();async function g(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=typeof performance<"u"?performance.now():Date.now();try{let c=await t(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);return(c.status>=400||u>=300)&&a.captureRequest({method:s,url:o,statusCode:c.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);throw a.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(c instanceof Error?c:new Error(String(c)),{url:o,method:s,type:r?.errorType||"network_error"}),c}}var h=new I;function R(n){if(!n)return{};let e={...n},r=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let t of r)e[t]&&(e[t]="[REDACTED]");return e}function T(n){a.init(n);let e=n.slowThresholdMs??300,r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,o,s)=>{let i=t.originalUrl||t.url||"";if(i&&a.isIngestUrl(i)||r.some(d=>typeof d=="string"?i.startsWith(d):d.test(i)))return s();let u=performance.now();h.run({req:t,queriesCount:0,slowQueries:0},()=>{o.on("finish",()=>{let d=Math.round(performance.now()-u),l=h.getStore(),y=o.statusCode,w=y>=400,m=d>=e,b=(l?.slowQueries||0)>0;if(w||m||b){let E=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||i;a.captureRequest({method:t.method,url:i,statusCode:y,durationMs:d,userAgent:t.headers?.["user-agent"],route:E,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0})}}),s()})}}async function k(n,e){return g(n,e,{errorType:"node_network_error"})}async function x(n,e,r=300){let t=h.getStore(),o=performance.now();t&&t.queriesCount++;try{let s=await e(),i=performance.now()-o;return i>r&&t&&(t.slowQueries=Math.max(t.slowQueries,Math.round(i)),a.captureMessage(`Slow Query detectada em [${n}]`,{durationMs:Math.round(i),operationName:n,url:t.req?.originalUrl||t.req?.url})),s}catch(s){let i=performance.now()-o;throw a.captureException(s,{operationName:n,durationMs:Math.round(i)}),s}}function C(){return(n,e,r,t)=>{a.captureException(n,{url:e.originalUrl||e.url,method:e.method,headers:R(e.headers)}),t(n)}}export{a as audit,k as auditFetch,x as auditOperation,T as devInspector,C as devInspectorErrorHandler};
@@ -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 d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var r in e)d(n,r,{get:e[r],enumerable:!0})},v=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!w.call(n,o)&&o!==r&&d(n,o,{get:()=>e[o],enumerable:!(t=E(e,o))||t.enumerable});return n};var R=n=>v(d({},"__esModule",{value:!0}),n);var A={};b(A,{AuditErrorBoundary:()=>f,audit:()=>a,auditFetch:()=>y,enableNetworkTracing:()=>I});module.exports=R(A);var g=require("react");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()}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")}}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,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",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)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new l),n[p]},a=_();async function h(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await t(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||u>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}var f=class extends g.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 y(n,e){return h(n,e,{errorType:"react_native_network_error",defaultUserAgent:"React-Native"})}function I(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return y(e,r)})}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 g}from"react";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()}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")}}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,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",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__",h=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[d]||(n[d]=new p),n[d]},a=h();async function l(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await t(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||u>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}var f=class extends g{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 y(n,e){return l(n,e,{errorType:"react_native_network_error",defaultUserAgent:"React-Native"})}function _(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return y(e,r)})}export{f as AuditErrorBoundary,a as audit,y as auditFetch,_ 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 u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(n,e)=>{for(var r in e)u(n,r,{get:e[r],enumerable:!0})},R=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!b.call(n,o)&&o!==r&&u(n,o,{get:()=>e[o],enumerable:!(t=w(e,o))||t.enumerable});return n};var _=n=>R(u({},"__esModule",{value:!0}),n);var S={};v(S,{AuditErrorBoundary:()=>f,audit:()=>a,auditFetch:()=>g,enableNetworkTracing:()=>A});module.exports=_(S);var y=require("react");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()}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")}}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,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",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)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",I=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new l),n[p]},a=I();async function h(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await t(n,e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||d>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:d,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:d,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}var E=require("react/jsx-runtime"),f=class extends y.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,E.jsx)("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function g(n,e){return h(n,e,{errorType:"react_network_error"})}function A(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return g(e,r)})}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 y}from"react";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()}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")}}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,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",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__",h=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[u]||(n[u]=new p),n[u]},a=h();async function l(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await t(n,e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||d>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:d,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:d,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}import{jsx as E}from"react/jsx-runtime";var f=class extends y{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??E("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function g(n,e){return l(n,e,{errorType:"react_network_error"})}function I(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return g(e,r)})}export{f as AuditErrorBoundary,a as audit,g as auditFetch,I 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 d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},b=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of w(e))!m.call(t,o)&&o!==r&&d(t,o,{get:()=>e[o],enumerable:!(n=g(e,o))||n.enumerable});return t};var v=t=>b(d({},"__esModule",{value:!0}),t);var k={};E(k,{audit:()=>a,auditFetch:()=>h,auditHandle:()=>I,enableNetworkTracing:()=>T,handleSvelteKitError:()=>A,initSvelteDevInspector:()=>_});module.exports=v(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()}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")}}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((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}),r&&r(n,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 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 o=n instanceof Error?n:new Error(String(n));this.captureError(o,{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"&&e!==null){if(n.has(e))return"[Circular Reference]";n.add(e);let o={};for(let[i,u]of Object.entries(e))o[i]=this.truncate(u,r,n);return o}return e}captureError(e,r={}){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({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){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({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(n)}async send(e){let r=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":r},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__",R=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[p]||(t[p]=new f),t[p]},a=R();async function l(t,e,r){let n=r?.nativeFetch||(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&&a.isIngestUrl(o))return n(t,e);let i=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),u=typeof performance<"u"?performance.now():Date.now();try{let s=await n(t,e),c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);return(s.status>=400||c>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}function _(t){a.init(t)}async function h(t,e){return l(t,e,{errorType:"svelte_network_error"})}async function I({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),n=t.request?.method||"GET",o=t.url?.pathname||t.url?.href||"/",i=t.route?.id||o;if(o&&a.isIngestUrl(o))return e(t);let u=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"";try{let s=await e(t),c=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return(s.status>=400||c>=300)&&a.captureRequest({method:n,url:o,statusCode:s.status,durationMs:c,route:i,userAgent:u}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-r);a.captureRequest({method:n,url:o,statusCode:500,durationMs:c,route:i,userAgent:u});let y=s instanceof Error?s:new Error(String(s));throw a.captureError(y,{framework:"sveltekit",url:o,method:n,route:i}),s}}function A({error:t,event:e,status:r,message:n}){let o=t instanceof Error?t:new Error(String(t||n||"Erro SvelteKit"));a.captureError(o,{framework:"sveltekit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||""})}function T(){let t=globalThis;!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__||(t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(e,r){return h(e,r)})}0&&(module.exports={audit,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 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()}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")}}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,u]of Object.entries(e))o[i]=this.truncate(u,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)}}},d="__DEVINSPECT_AUDIT_CORE_INSTANCE__",h=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[d]||(r[d]=new p),r[d]},a=h();async function f(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof r=="string"?o=r:r instanceof URL?o=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(o=r.url),o&&a.isIngestUrl(o))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),u=typeof performance<"u"?performance.now():Date.now();try{let s=await n(r,e),c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);return(s.status>=400||c>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:t?.errorType||"network_error"}),s}}function E(r){a.init(r)}async function y(r,e){return f(r,e,{errorType:"svelte_network_error"})}async function b({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||"/",i=r.route?.id||o;if(o&&a.isIngestUrl(o))return e(r);let u=typeof r.request?.headers?.get=="function"&&r.request.headers.get("user-agent")||"";try{let s=await e(r),c=Math.round((typeof performance<"u"?performance.now():Date.now())-t);return(s.status>=400||c>=300)&&a.captureRequest({method:n,url:o,statusCode:s.status,durationMs:c,route:i,userAgent:u}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-t);a.captureRequest({method:n,url:o,statusCode:500,durationMs:c,route:i,userAgent:u});let l=s instanceof Error?s:new Error(String(s));throw a.captureError(l,{framework:"sveltekit",url:o,method:n,route:i}),s}}function v({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 R(){let r=globalThis;!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__||(r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(e,t){return y(e,t)})}export{a as audit,y as auditFetch,b as auditHandle,R as enableNetworkTracing,v as handleSvelteKitError,E 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 d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var t in e)d(n,t,{get:e[t],enumerable:!0})},v=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!m.call(n,o)&&o!==t&&d(n,o,{get:()=>e[o],enumerable:!(r=w(e,o))||r.enumerable});return n};var _=n=>v(d({},"__esModule",{value:!0}),n);var A={};b(A,{audit:()=>i,auditFetch:()=>l,default:()=>I,enableNetworkTracing:()=>g});module.exports=_(A);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()}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")}}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((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}),t&&t(r,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 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 o=r instanceof Error?r:new Error(String(r));this.captureError(o,{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"&&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,t,r);return o}return e}captureError(e,t={}){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({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){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({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=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":t},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__",R=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new f),n[p]},i=R();async function h(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&i.isIngestUrl(o))return r(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||u>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a}catch(a){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:t?.errorType||"network_error"}),a}}var y=null;async function l(n,e,t){return h(n,e,{errorType:"vanilla_network_error",nativeFetch:t||y||void 0})}function g(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);y=e,n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(...t){let[r,o]=t;return l(r,o,e)}}typeof window<"u"&&(window.DevInspector={init:n=>i.init(n),captureError:(n,e)=>i.captureError(n,e),captureException:(n,e)=>i.captureException(n,e),captureMessage:(n,e)=>i.captureMessage(n,e),auditFetch:l,enableNetworkTracing:g,core:i});var I=i;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 d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var t in e)d(n,t,{get:e[t],enumerable:!0})},v=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of E(e))!m.call(n,o)&&o!==t&&d(n,o,{get:()=>e[o],enumerable:!(r=w(e,o))||r.enumerable});return n};var _=n=>v(d({},"__esModule",{value:!0}),n);var A={};b(A,{audit:()=>i,auditFetch:()=>l,default:()=>I,enableNetworkTracing:()=>g});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()}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")}}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((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}),t&&t(r,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 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 o=r instanceof Error?r:new Error(String(r));this.captureError(o,{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"&&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,t,r);return o}return e}captureError(e,t={}){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({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){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({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=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":t},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__",R=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new f),n[p]},i=R();async function h(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&i.isIngestUrl(o))return r(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||u>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a}catch(a){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:t?.errorType||"network_error"}),a}}var y=null;async function l(n,e,t){return h(n,e,{errorType:"vanilla_network_error",nativeFetch:t||y||void 0})}function g(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);y=e,n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(...t){let[r,o]=t;return l(r,o,e)}}typeof window<"u"&&(window.DevInspector={init:n=>i.init(n),captureError:(n,e)=>i.captureError(n,e),captureException:(n,e)=>i.captureException(n,e),captureMessage:(n,e)=>i.captureMessage(n,e),auditFetch:l,enableNetworkTracing:g,core:i});var I=i;return _(A);})();
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 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()}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")}}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((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}),t&&t(r,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 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 o=r instanceof Error?r:new Error(String(r));this.captureError(o,{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"&&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,t,r);return o}return e}captureError(e,t={}){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({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){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({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=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":t},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)}}},d="__DEVINSPECT_AUDIT_CORE_INSTANCE__",y=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[d]||(n[d]=new p),n[d]},i=y();async function f(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&i.isIngestUrl(o))return r(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||u>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a}catch(a){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:t?.errorType||"network_error"}),a}}var l=null;async function h(n,e,t){return f(n,e,{errorType:"vanilla_network_error",nativeFetch:t||l||void 0})}function g(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);l=e,n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(...t){let[r,o]=t;return h(r,o,e)}}typeof window<"u"&&(window.DevInspector={init:n=>i.init(n),captureError:(n,e)=>i.captureError(n,e),captureException:(n,e)=>i.captureException(n,e),captureMessage:(n,e)=>i.captureMessage(n,e),auditFetch:h,enableNetworkTracing:g,core:i});var b=i;export{i as audit,h as auditFetch,b as default,g 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 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 R={};m(R,{DevInspectorVue:()=>_,audit:()=>a,auditFetch:()=>h,enableNetworkTracing:()=>I});module.exports=b(R);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()}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")}}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,c]of Object.entries(e))o[i]=this.truncate(c,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)}}},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]},a=v();async function l(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof r=="string"?o=r:r instanceof URL?o=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(o=r.url),o&&a.isIngestUrl(o))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await n(r,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||u>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),s}catch(s){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:t?.errorType||"network_error"}),s}}async function h(r,e){return l(r,e,{errorType:"vue_network_error"})}var _={install(r,e){if(a.init(e),r.config){let t=r.config.errorHandler;r.config.errorHandler=(n,o,i)=>{let c=n instanceof Error?n:new Error(String(n)),s=o?.$options?.name||o?.$options?.__name||o?.$type?.name;a.captureError(c,{framework:"vue",vueInfo:i,component:s}),typeof t=="function"?t(n,o,i):console.error(n)}}}};function I(){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 h(e,t)})}0&&(module.exports={DevInspectorVue,audit,auditFetch,enableNetworkTracing});
package/dist/vue.js CHANGED
@@ -1 +1 @@
1
- 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 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)}}},c="__DEVINSPECT_AUDIT_CORE_INSTANCE__",p=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[c]||(r[c]=new u),r[c]},a=p();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 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 y={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)),d=o?.$options?.name||o?.$options?.__name||o?.$type?.name;a.captureError(s,{framework:"vue",vueInfo:i,component:d}),typeof t=="function"?t(n,o,i):console.error(n)}}}};function w(){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 l(e,t)})}export{y as DevInspectorVue,a as audit,l as auditFetch,w as enableNetworkTracing};
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()}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")}}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,c]of Object.entries(e))o[i]=this.truncate(c,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)}}},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();async function f(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof r=="string"?o=r:r instanceof URL?o=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(o=r.url),o&&a.isIngestUrl(o))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await n(r,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||u>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),s}catch(s){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:t?.errorType||"network_error"}),s}}async function h(r,e){return f(r,e,{errorType:"vue_network_error"})}var m={install(r,e){if(a.init(e),r.config){let t=r.config.errorHandler;r.config.errorHandler=(n,o,i)=>{let c=n instanceof Error?n:new Error(String(n)),s=o?.$options?.name||o?.$options?.__name||o?.$type?.name;a.captureError(c,{framework:"vue",vueInfo:i,component:s}),typeof t=="function"?t(n,o,i):console.error(n)}}}};function E(){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 h(e,t)})}export{m as DevInspectorVue,a as audit,h as auditFetch,E as enableNetworkTracing};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcodleox/devinspector",
3
- "version": "7.4.0",
3
+ "version": "7.5.0",
4
4
  "description": "SDK de monitoramento e auditoria de erros em tempo real | Dev Inspector",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",