@xcodleox/devinspector 7.4.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +1 -0
- package/dist/angular.d.ts +1 -0
- package/dist/angular.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +48 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.js +1 -1
- package/dist/next.cjs +1 -1
- package/dist/next.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +3 -1
- package/dist/node.d.ts +3 -1
- package/dist/node.js +1 -1
- package/dist/react-native.cjs +1 -1
- package/dist/react-native.d.cts +1 -0
- package/dist/react-native.d.ts +1 -0
- package/dist/react-native.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/svelte.cjs +1 -1
- package/dist/svelte.d.cts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +1 -1
- package/dist/vanilla.cjs +1 -1
- package/dist/vanilla.global.js +1 -1
- package/dist/vanilla.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +1 -1
- package/package.json +11 -9
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 g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var C=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),w=r=>{throw TypeError(r)};var z=(r,e,t)=>e in r?g(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _=(r,e)=>g(r,"name",{value:e,configurable:!0});var Y=(r,e)=>{for(var t in e)g(r,t,{get:e[t],enumerable:!0})},V=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of F(e))!L.call(r,s)&&s!==t&&g(r,s,{get:()=>e[s],enumerable:!(n=S(e,s))||n.enumerable});return r};var W=r=>V(g({},"__esModule",{value:!0}),r);var j=r=>[,,,H(r?.[C("metadata")]??null)],B=["class","method","getter","setter","accessor","field","value","get","set"],y=r=>r!==void 0&&typeof r!="function"?w("Function expected"):r,J=(r,e,t,n,s)=>({kind:B[r],name:e,metadata:n,addInitializer:o=>t._?w("Already initialized"):s.push(y(o||null))}),X=(r,e)=>z(e,C("metadata"),r[3]),$=(r,e,t,n)=>{for(var s=0,o=r[e>>1],c=o&&o.length;s<c;s++)e&1?o[s].call(t):n=o[s].call(t,n);return n},K=(r,e,t,n,s,o)=>{var c,a,d,l,m,i=e&7,I=!!(e&8),h=!!(e&16),v=i>3?r.length+1:i?I?1:2:0,D=B[i+5],k=i>3&&(r[v-1]=[]),Q=r[v]||(r[v]=[]),f=i&&(!h&&!I&&(s=s.prototype),i<5&&(i>3||!h)&&S(i<4?s:{get[t](){return q(this,o)},set[t](u){return U(this,o,u)}},t));i?h&&i<4&&_(o,(i>2?"set ":i>1?"get ":"")+t):_(s,t);for(var E=n.length-1;E>=0;E--)l=J(i,t,d={},r[3],Q),i&&(l.static=I,l.private=h,m=l.access={has:h?u=>Z(s,u):u=>t in u},i^3&&(m.get=h?u=>(i^1?q:ee)(u,s,i^4?o:f.get):u=>u[t]),i>2&&(m.set=h?(u,x)=>U(u,s,x,i^4?o:f.set):(u,x)=>u[t]=x)),a=(0,n[E])(i?i<4?h?o:f[D]:i>4?void 0:{get:f.get,set:f.set}:s,l),d._=1,i^4||a===void 0?y(a)&&(i>4?k.unshift(a):i?h?o=a:f[D]=a:s=a):typeof a!="object"||a===null?w("Object expected"):(y(c=a.get)&&(f.get=c),y(c=a.set)&&(f.set=c),y(c=a.init)&&k.unshift(c));return i||X(r,s),f&&g(s,t,f),h?i^4?o:f:s};var T=(r,e,t)=>e.has(r)||w("Cannot "+t),Z=(r,e)=>Object(e)!==e?w('Cannot use the "in" operator on this value'):r.has(e),q=(r,e,t)=>(T(r,e,"read from private field"),t?t.call(r):e.get(r));var U=(r,e,t,n)=>(T(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),ee=(r,e,t)=>(T(r,e,"access private method"),t);var ne={};Y(ne,{AuditAngularErrorHandler:()=>b,audit:()=>p,auditInterceptor:()=>re,devInspectorInterceptor:()=>N});module.exports=W(ne);var P=require("@angular/core"),G=require("rxjs/operators");var M=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},n=this.truncate(t,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let t=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),t&&t(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(c=>this.truncate(c,t,n));let o={};for(let[c,a]of Object.entries(e))o[c]=this.truncate(a,t,n);return o}return e}captureError(e,t={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),c=t.requestId,a=t.traceId,d=t.spanId,l={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:c,traceId:a,spanId:d,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...t,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},R="__DEVINSPECT_AUDIT_CORE_INSTANCE__",te=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[R]||(r[R]=new M),r[R]},p=te();var O,A;O=[(0,P.Injectable)()];var b=class{handleError(e){let t=e instanceof Error?e:new Error(String(e));p.captureError(t,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};A=j(null),b=K(A,0,"AuditAngularErrorHandler",O,b),$(A,1,b);var N=(r,e)=>{let t=r.urlWithParams||r.url||"";if(t&&p.isIngestUrl(t))return e(r);let n=p.createRequestId(),s=p.createTraceId(),o=p.createSpanId(),c=r;r&&typeof r.clone=="function"&&(c=r.clone({setHeaders:{"x-devinspector-request-id":n,"x-devinspector-trace-id":s,"x-devinspector-span-id":o}}));let a=typeof performance<"u"?performance.now():Date.now();return e(c).pipe((0,G.tap)({next:d=>{if(!(d&&typeof d=="object"&&"status"in d&&"clone"in d))return;let m=Math.round((typeof performance<"u"?performance.now():Date.now())-a),i=d.status;(i>=400||m>=300)&&p.captureRequest({method:r.method,url:t,statusCode:i,durationMs:m,route:r.url,requestId:n,traceId:s,spanId:o,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),p.addBreadcrumb({type:"http",message:`${r.method} ${t}`,metadata:{statusCode:i,durationMs:m,requestId:n,traceId:s,spanId:o}})},error:d=>{let l=Math.round((typeof performance<"u"?performance.now():Date.now())-a),m=Number(d?.status)||0;p.captureRequest({method:r.method,url:t,statusCode:m,durationMs:l,route:r.url,requestId:n,traceId:s,spanId:o,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),p.captureException(new Error(`HTTP Error ${m}: ${d?.message||d?.statusText||"Erro de rede no cliente"}`),{url:t,method:r.method,status:d?.status,statusText:d?.statusText,type:"angular_network_error",requestId:n,traceId:s,spanId:o}),p.addBreadcrumb({type:"http_error",message:`${r.method} ${t}`,metadata:{statusCode:m,durationMs:l,requestId:n,traceId:s,spanId:o,error:d?.message||d?.statusText||"Network Error"}})}}))},re=N;0&&(module.exports={AuditAngularErrorHandler,audit,auditInterceptor,devInspectorInterceptor});
|
package/dist/angular.d.cts
CHANGED
package/dist/angular.d.ts
CHANGED
package/dist/angular.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var P=Object.create;var x=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var S=(r,e)=>(e=Symbol[r])?e:Symbol.for("Symbol."+r),b=r=>{throw TypeError(r)};var N=(r,e,t)=>e in r?x(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var _=(r,e)=>x(r,"name",{value:e,configurable:!0});var C=r=>[,,,P(r?.[S("metadata")]??null)],j=["class","method","getter","setter","accessor","field","value","get","set"],g=r=>r!==void 0&&typeof r!="function"?b("Function expected"):r,Q=(r,e,t,n,s)=>({kind:j[r],name:e,metadata:n,addInitializer:o=>t._?b("Already initialized"):s.push(g(o||null))}),H=(r,e)=>N(e,S("metadata"),r[3]),B=(r,e,t,n)=>{for(var s=0,o=r[e>>1],c=o&&o.length;s<c;s++)e&1?o[s].call(t):n=o[s].call(t,n);return n},$=(r,e,t,n,s,o)=>{var c,a,d,p,l,i=e&7,w=!!(e&8),h=!!(e&16),I=i>3?r.length+1:i?w?1:2:0,D=j[i+5],k=i>3&&(r[I-1]=[]),O=r[I]||(r[I]=[]),m=i&&(!h&&!w&&(s=s.prototype),i<5&&(i>3||!h)&&G(i<4?s:{get[t](){return q(this,o)},set[t](u){return U(this,o,u)}},t));i?h&&i<4&&_(o,(i>2?"set ":i>1?"get ":"")+t):_(s,t);for(var v=n.length-1;v>=0;v--)p=Q(i,t,d={},r[3],O),i&&(p.static=w,p.private=h,l=p.access={has:h?u=>F(s,u):u=>t in u},i^3&&(l.get=h?u=>(i^1?q:L)(u,s,i^4?o:m.get):u=>u[t]),i>2&&(l.set=h?(u,E)=>U(u,s,E,i^4?o:m.set):(u,E)=>u[t]=E)),a=(0,n[v])(i?i<4?h?o:m[D]:i>4?void 0:{get:m.get,set:m.set}:s,p),d._=1,i^4||a===void 0?g(a)&&(i>4?k.unshift(a):i?h?o=a:m[D]=a:s=a):typeof a!="object"||a===null?b("Object expected"):(g(c=a.get)&&(m.get=c),g(c=a.set)&&(m.set=c),g(c=a.init)&&k.unshift(c));return i||H(r,s),m&&x(s,t,m),h?i^4?o:m:s};var T=(r,e,t)=>e.has(r)||b("Cannot "+t),F=(r,e)=>Object(e)!==e?b('Cannot use the "in" operator on this value'):r.has(e),q=(r,e,t)=>(T(r,e,"read from private field"),t?t.call(r):e.get(r));var U=(r,e,t,n)=>(T(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t),L=(r,e,t)=>(T(r,e,"access private method"),t);import{Injectable as Y}from"@angular/core";import{tap as V}from"rxjs/operators";var M=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},n=this.truncate(t,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let t=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),t&&t(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(c=>this.truncate(c,t,n));let o={};for(let[c,a]of Object.entries(e))o[c]=this.truncate(a,t,n);return o}return e}captureError(e,t={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),c=t.requestId,a=t.traceId,d=t.spanId,p={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:c,traceId:a,spanId:d,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...t,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},R="__DEVINSPECT_AUDIT_CORE_INSTANCE__",z=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[R]||(r[R]=new M),r[R]},f=z();var K,A;K=[Y()];var y=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)}};A=C(null),y=$(A,0,"AuditAngularErrorHandler",K,y),B(A,1,y);var W=(r,e)=>{let t=r.urlWithParams||r.url||"";if(t&&f.isIngestUrl(t))return e(r);let n=f.createRequestId(),s=f.createTraceId(),o=f.createSpanId(),c=r;r&&typeof r.clone=="function"&&(c=r.clone({setHeaders:{"x-devinspector-request-id":n,"x-devinspector-trace-id":s,"x-devinspector-span-id":o}}));let a=typeof performance<"u"?performance.now():Date.now();return e(c).pipe(V({next:d=>{if(!(d&&typeof d=="object"&&"status"in d&&"clone"in d))return;let l=Math.round((typeof performance<"u"?performance.now():Date.now())-a),i=d.status;(i>=400||l>=300)&&f.captureRequest({method:r.method,url:t,statusCode:i,durationMs:l,route:r.url,requestId:n,traceId:s,spanId:o,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),f.addBreadcrumb({type:"http",message:`${r.method} ${t}`,metadata:{statusCode:i,durationMs:l,requestId:n,traceId:s,spanId:o}})},error:d=>{let p=Math.round((typeof performance<"u"?performance.now():Date.now())-a),l=Number(d?.status)||0;f.captureRequest({method:r.method,url:t,statusCode:l,durationMs:p,route:r.url,requestId:n,traceId:s,spanId:o,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),f.captureException(new Error(`HTTP Error ${l}: ${d?.message||d?.statusText||"Erro de rede no cliente"}`),{url:t,method:r.method,status:d?.status,statusText:d?.statusText,type:"angular_network_error",requestId:n,traceId:s,spanId:o}),f.addBreadcrumb({type:"http_error",message:`${r.method} ${t}`,metadata:{statusCode:l,durationMs:p,requestId:n,traceId:s,spanId:o,error:d?.message||d?.statusText||"Network Error"}})}}))},se=W;export{y as AuditAngularErrorHandler,f as audit,se as auditInterceptor,W as devInspectorInterceptor};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var g=(i,e)=>{for(var r in e)c(i,r,{get:e[r],enumerable:!0})},y=(i,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of b(e))!f.call(i,n)&&n!==r&&c(i,n,{get:()=>e[n],enumerable:!(t=h(e,n))||t.enumerable});return i};var w=i=>y(c({},"__esModule",{value:!0}),i);var I={};g(I,{AuditCore:()=>a,audit:()=>l});module.exports=w(I);var a=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",n=e.collection?.trim()||"Unknown",s={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:n,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(s)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,n)=>{let s=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!n}),r&&r(t,n)})}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 n=t instanceof Error?t:new Error(String(t));this.captureError(n,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let n=e;if(t.has(n))return"[Circular Reference]";if(t.add(n),Array.isArray(e))return e.map(o=>this.truncate(o,r,t));let s={};for(let[o,d]of Object.entries(e))s[o]=this.truncate(d,r,t);return s}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",n=e?.stack||"",s=this.getContext(),o=r.requestId,d=r.traceId,p=r.spanId,m={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(n,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:o,traceId:d,spanId:p,environment:s.environment,release:s.release,user:s.user,breadcrumbs:s.breadcrumbs,metadata:this.truncate({...r,environment:s.environment,release:s.release,timestamp:s.timestamp},5e3)};this.send(m)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),n={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(n)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},u="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let i=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return i[u]||(i[u]=new a),i[u]},l=v();0&&(module.exports={AuditCore,audit});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
interface AuditUser {
|
|
2
|
+
id?: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
username?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
interface Breadcrumb {
|
|
8
|
+
timestamp: string;
|
|
9
|
+
type: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
1
13
|
interface InitOptions {
|
|
2
14
|
apiKey: string;
|
|
3
15
|
endpoint?: string;
|
|
4
16
|
environment?: string;
|
|
17
|
+
release?: string;
|
|
5
18
|
slowThresholdMs?: number;
|
|
6
19
|
}
|
|
7
20
|
interface RequestMetricData {
|
|
@@ -13,15 +26,49 @@ interface RequestMetricData {
|
|
|
13
26
|
route?: string;
|
|
14
27
|
dbQueriesCount?: number;
|
|
15
28
|
slowQueryMs?: number;
|
|
29
|
+
requestId?: string;
|
|
30
|
+
traceId?: string;
|
|
31
|
+
spanId?: string;
|
|
32
|
+
}
|
|
33
|
+
interface DbQueryData {
|
|
34
|
+
operation: string;
|
|
35
|
+
collection?: string;
|
|
36
|
+
durationMs: number;
|
|
37
|
+
url?: string;
|
|
38
|
+
requestId?: string;
|
|
39
|
+
traceId?: string;
|
|
40
|
+
spanId?: string;
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
16
42
|
}
|
|
17
43
|
declare class AuditCore {
|
|
18
44
|
private apiKey;
|
|
19
45
|
private endpoint;
|
|
20
46
|
private environment;
|
|
47
|
+
private release?;
|
|
48
|
+
private slowThresholdMs;
|
|
49
|
+
private user?;
|
|
50
|
+
private breadcrumbs;
|
|
51
|
+
private readonly maxBreadcrumbs;
|
|
21
52
|
initialized: boolean;
|
|
22
53
|
private listenersAttached;
|
|
23
54
|
init(options: InitOptions): void;
|
|
55
|
+
getEnvironment(): string;
|
|
56
|
+
getRelease(): string | undefined;
|
|
57
|
+
getSlowThresholdMs(): number;
|
|
58
|
+
isIngestUrl(targetUrl: string): boolean;
|
|
59
|
+
private generateId;
|
|
60
|
+
createRequestId(): string;
|
|
61
|
+
createTraceId(): string;
|
|
62
|
+
createSpanId(): string;
|
|
63
|
+
setUser(user: AuditUser): void;
|
|
64
|
+
clearUser(): void;
|
|
65
|
+
getUser(): AuditUser | undefined;
|
|
66
|
+
addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
|
|
67
|
+
clearBreadcrumbs(): void;
|
|
68
|
+
getBreadcrumbs(): Breadcrumb[];
|
|
69
|
+
private getContext;
|
|
24
70
|
captureRequest(data: RequestMetricData): void;
|
|
71
|
+
captureDbQuery(data: DbQueryData): void;
|
|
25
72
|
private listenGlobalErrors;
|
|
26
73
|
private truncate;
|
|
27
74
|
captureError(error: Error, metadata?: Record<string, any>): void;
|
|
@@ -31,4 +78,4 @@ declare class AuditCore {
|
|
|
31
78
|
}
|
|
32
79
|
declare const audit: AuditCore;
|
|
33
80
|
|
|
34
|
-
export { AuditCore, type InitOptions, type RequestMetricData, audit };
|
|
81
|
+
export { AuditCore, type AuditUser, type Breadcrumb, type InitOptions, type RequestMetricData, audit };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
interface AuditUser {
|
|
2
|
+
id?: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
username?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
interface Breadcrumb {
|
|
8
|
+
timestamp: string;
|
|
9
|
+
type: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
1
13
|
interface InitOptions {
|
|
2
14
|
apiKey: string;
|
|
3
15
|
endpoint?: string;
|
|
4
16
|
environment?: string;
|
|
17
|
+
release?: string;
|
|
5
18
|
slowThresholdMs?: number;
|
|
6
19
|
}
|
|
7
20
|
interface RequestMetricData {
|
|
@@ -13,15 +26,49 @@ interface RequestMetricData {
|
|
|
13
26
|
route?: string;
|
|
14
27
|
dbQueriesCount?: number;
|
|
15
28
|
slowQueryMs?: number;
|
|
29
|
+
requestId?: string;
|
|
30
|
+
traceId?: string;
|
|
31
|
+
spanId?: string;
|
|
32
|
+
}
|
|
33
|
+
interface DbQueryData {
|
|
34
|
+
operation: string;
|
|
35
|
+
collection?: string;
|
|
36
|
+
durationMs: number;
|
|
37
|
+
url?: string;
|
|
38
|
+
requestId?: string;
|
|
39
|
+
traceId?: string;
|
|
40
|
+
spanId?: string;
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
16
42
|
}
|
|
17
43
|
declare class AuditCore {
|
|
18
44
|
private apiKey;
|
|
19
45
|
private endpoint;
|
|
20
46
|
private environment;
|
|
47
|
+
private release?;
|
|
48
|
+
private slowThresholdMs;
|
|
49
|
+
private user?;
|
|
50
|
+
private breadcrumbs;
|
|
51
|
+
private readonly maxBreadcrumbs;
|
|
21
52
|
initialized: boolean;
|
|
22
53
|
private listenersAttached;
|
|
23
54
|
init(options: InitOptions): void;
|
|
55
|
+
getEnvironment(): string;
|
|
56
|
+
getRelease(): string | undefined;
|
|
57
|
+
getSlowThresholdMs(): number;
|
|
58
|
+
isIngestUrl(targetUrl: string): boolean;
|
|
59
|
+
private generateId;
|
|
60
|
+
createRequestId(): string;
|
|
61
|
+
createTraceId(): string;
|
|
62
|
+
createSpanId(): string;
|
|
63
|
+
setUser(user: AuditUser): void;
|
|
64
|
+
clearUser(): void;
|
|
65
|
+
getUser(): AuditUser | undefined;
|
|
66
|
+
addBreadcrumb(breadcrumb: Omit<Breadcrumb, "timestamp">): void;
|
|
67
|
+
clearBreadcrumbs(): void;
|
|
68
|
+
getBreadcrumbs(): Breadcrumb[];
|
|
69
|
+
private getContext;
|
|
24
70
|
captureRequest(data: RequestMetricData): void;
|
|
71
|
+
captureDbQuery(data: DbQueryData): void;
|
|
25
72
|
private listenGlobalErrors;
|
|
26
73
|
private truncate;
|
|
27
74
|
captureError(error: Error, metadata?: Record<string, any>): void;
|
|
@@ -31,4 +78,4 @@ declare class AuditCore {
|
|
|
31
78
|
}
|
|
32
79
|
declare const audit: AuditCore;
|
|
33
80
|
|
|
34
|
-
export { AuditCore, type InitOptions, type RequestMetricData, audit };
|
|
81
|
+
export { AuditCore, type AuditUser, type Breadcrumb, type InitOptions, type RequestMetricData, audit };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",n={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(n)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let n=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(n,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(i=>this.truncate(i,r,t));let n={};for(let[i,d]of Object.entries(e))n[i]=this.truncate(d,r,t);return n}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",n=this.getContext(),i=r.requestId,d=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:i,traceId:d,spanId:u,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...r,environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},c="__DEVINSPECT_AUDIT_CORE_INSTANCE__",p=()=>{let o=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return o[c]||(o[c]=new a),o[c]},m=p();export{a as AuditCore,m 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 h=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var q=(r,e)=>{for(var t in e)h(r,t,{get:e[t],enumerable:!0})},R=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of x(e))!A.call(r,s)&&s!==t&&h(r,s,{get:()=>e[s],enumerable:!(n=E(e,s))||n.enumerable});return r};var T=r=>R(h({},"__esModule",{value:!0}),r);var j={};q(j,{audit:()=>i,auditFetch:()=>k,captureNextError:()=>w,initNextDevInspector:()=>_,withAuditAction:()=>C,withAuditApi:()=>D});module.exports=T(j);var b=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},n=this.truncate(t,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let t=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),t&&t(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,n));let o={};for(let[a,c]of Object.entries(e))o[a]=this.truncate(c,t,n);return o}return e}captureError(e,t={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),a=t.requestId,c=t.traceId,d=t.spanId,p={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:d,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...t,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},g="__DEVINSPECT_AUDIT_CORE_INSTANCE__",M=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[g]||(r[g]=new b),r[g]},i=M();async function I(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof r=="string"?s=r:r instanceof URL?s=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(s=r.url),s&&i.isIngestUrl(s))return n(r,e);let o=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),a=i.createRequestId(),c=i.createTraceId(),d=i.createSpanId(),p=new Headers(e?.headers||(typeof r=="object"&&r!==null&&"headers"in r?r.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",d);let f={...e,headers:p},m=typeof performance<"u"?performance.now():Date.now();try{let u=await n(r,f),l=Math.round((typeof performance<"u"?performance.now():Date.now())-m),v=i.getSlowThresholdMs();return(u.status>=400||l>=v)&&i.captureRequest({method:o,url:s,statusCode:u.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:d,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:u.status,durationMs:l,requestId:a,traceId:c,spanId:d}}),u}catch(u){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-m);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:d,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.captureException(u instanceof Error?u:new Error(String(u)),{url:s,method:o,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:d}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:d}}),u}}function _(r){i.init(r)}function w(r,e={}){let t=r instanceof Error?r:new Error(String(r));i.captureError(t,{framework:"Next.js",...e})}async function k(r,e){return I(r,e,{errorType:"nextjs_network_error"})}function D(r){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),n=e[0],s=e[1],o=n?.method||"GET",a=n?.url||n?.nextUrl?.href||"/api",c=typeof n?.headers?.get=="function"?n.headers.get("user-agent")||"":n?.headers?.["user-agent"]||"",d=y(n,"x-devinspector-request-id")||i.createRequestId(),p=y(n,"x-devinspector-trace-id")||i.createTraceId(),f=y(n,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"http",message:`${o} ${a}`,metadata:{framework:"Next.js",phase:"start",requestId:d,traceId:p,spanId:f}});try{let m=await r(...e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-t),l=m?.status||s?.statusCode||200;return(l>=400||u>=300)&&i.captureRequest({method:o,url:a,statusCode:l,durationMs:u,route:a,userAgent:c,requestId:d,traceId:p,spanId:f}),i.addBreadcrumb({type:"http",message:`${o} ${a}`,metadata:{framework:"Next.js",phase:"complete",statusCode:l,durationMs:u,requestId:d,traceId:p,spanId:f}}),m}catch(m){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw i.captureRequest({method:o,url:a,statusCode:500,durationMs:u,route:a,userAgent:c,requestId:d,traceId:p,spanId:f}),i.addBreadcrumb({type:"http_error",message:`${o} ${a}`,metadata:{framework:"Next.js",statusCode:500,durationMs:u,requestId:d,traceId:p,spanId:f}}),w(m,{url:a,method:o,type:"api_route_error",requestId:d,traceId:p,spanId:f}),m}}}function C(r,e){return(async(...t)=>{let n=typeof performance<"u"?performance.now():Date.now(),s=i.createRequestId(),o=i.createTraceId(),a=i.createSpanId();i.addBreadcrumb({type:"server_action",message:r,metadata:{framework:"Next.js",phase:"start",requestId:s,traceId:o,spanId:a}});try{let c=await e(...t),d=Math.round((typeof performance<"u"?performance.now():Date.now())-n);return d>=300&&i.captureRequest({method:"ACTION",url:r,statusCode:200,durationMs:d,route:r,requestId:s,traceId:o,spanId:a}),i.addBreadcrumb({type:"server_action",message:r,metadata:{framework:"Next.js",phase:"complete",statusCode:200,durationMs:d,requestId:s,traceId:o,spanId:a}}),c}catch(c){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-n);throw i.captureRequest({method:"ACTION",url:r,statusCode:500,durationMs:d,route:r,requestId:s,traceId:o,spanId:a}),i.addBreadcrumb({type:"server_action_error",message:r,metadata:{framework:"Next.js",statusCode:500,durationMs:d,requestId:s,traceId:o,spanId:a}}),w(c,{actionName:r,type:"server_action_error",requestId:s,traceId:o,spanId:a}),c}})}function y(r,e){if(!r?.headers)return;if(typeof r.headers.get=="function")return r.headers.get(e)||void 0;let t=r.headers[e]||r.headers[e.toLowerCase()];return Array.isArray(t)?t[0]:t?String(t):void 0}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 g=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},r=this.truncate(t,2e3);this.breadcrumbs.push(r),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(r)}captureDbQuery(e){let t=this.getContext(),r=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${r}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:r,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:r,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((r,s)=>{let 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"){let s=e;if(r.has(s))return"[Circular Reference]";if(r.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,r));let o={};for(let[a,c]of Object.entries(e))o[a]=this.truncate(c,t,r);return o}return e}captureError(e,t={}){let r=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),a=t.requestId,c=t.traceId,d=t.spanId,p={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:d,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...t,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let r=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:r.environment,release:r.release,timestamp:r.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},h="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[h]||(n[h]=new g),n[h]},i=v();async function y(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&i.isIngestUrl(s))return r(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),a=i.createRequestId(),c=i.createTraceId(),d=i.createSpanId(),p=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",d);let f={...e,headers:p},m=typeof performance<"u"?performance.now():Date.now();try{let u=await r(n,f),l=Math.round((typeof performance<"u"?performance.now():Date.now())-m),I=i.getSlowThresholdMs();return(u.status>=400||l>=I)&&i.captureRequest({method:o,url:s,statusCode:u.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:d,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:u.status,durationMs:l,requestId:a,traceId:c,spanId:d}}),u}catch(u){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-m);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:d,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.captureException(u instanceof Error?u:new Error(String(u)),{url:s,method:o,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:d}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:d}}),u}}function q(n){i.init(n)}function w(n,e={}){let t=n instanceof Error?n:new Error(String(n));i.captureError(t,{framework:"Next.js",...e})}async function R(n,e){return y(n,e,{errorType:"nextjs_network_error"})}function T(n){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),r=e[0],s=e[1],o=r?.method||"GET",a=r?.url||r?.nextUrl?.href||"/api",c=typeof r?.headers?.get=="function"?r.headers.get("user-agent")||"":r?.headers?.["user-agent"]||"",d=b(r,"x-devinspector-request-id")||i.createRequestId(),p=b(r,"x-devinspector-trace-id")||i.createTraceId(),f=b(r,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"http",message:`${o} ${a}`,metadata:{framework:"Next.js",phase:"start",requestId:d,traceId:p,spanId:f}});try{let m=await n(...e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-t),l=m?.status||s?.statusCode||200;return(l>=400||u>=300)&&i.captureRequest({method:o,url:a,statusCode:l,durationMs:u,route:a,userAgent:c,requestId:d,traceId:p,spanId:f}),i.addBreadcrumb({type:"http",message:`${o} ${a}`,metadata:{framework:"Next.js",phase:"complete",statusCode:l,durationMs:u,requestId:d,traceId:p,spanId:f}}),m}catch(m){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw i.captureRequest({method:o,url:a,statusCode:500,durationMs:u,route:a,userAgent:c,requestId:d,traceId:p,spanId:f}),i.addBreadcrumb({type:"http_error",message:`${o} ${a}`,metadata:{framework:"Next.js",statusCode:500,durationMs:u,requestId:d,traceId:p,spanId:f}}),w(m,{url:a,method:o,type:"api_route_error",requestId:d,traceId:p,spanId:f}),m}}}function M(n,e){return(async(...t)=>{let r=typeof performance<"u"?performance.now():Date.now(),s=i.createRequestId(),o=i.createTraceId(),a=i.createSpanId();i.addBreadcrumb({type:"server_action",message:n,metadata:{framework:"Next.js",phase:"start",requestId:s,traceId:o,spanId:a}});try{let c=await e(...t),d=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return d>=300&&i.captureRequest({method:"ACTION",url:n,statusCode:200,durationMs:d,route:n,requestId:s,traceId:o,spanId:a}),i.addBreadcrumb({type:"server_action",message:n,metadata:{framework:"Next.js",phase:"complete",statusCode:200,durationMs:d,requestId:s,traceId:o,spanId:a}}),c}catch(c){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-r);throw i.captureRequest({method:"ACTION",url:n,statusCode:500,durationMs:d,route:n,requestId:s,traceId:o,spanId:a}),i.addBreadcrumb({type:"server_action_error",message:n,metadata:{framework:"Next.js",statusCode:500,durationMs:d,requestId:s,traceId:o,spanId:a}}),w(c,{actionName:n,type:"server_action_error",requestId:s,traceId:o,spanId:a}),c}})}function b(n,e){if(!n?.headers)return;if(typeof n.headers.get=="function")return n.headers.get(e)||void 0;let t=n.headers[e]||n.headers[e.toLowerCase()];return Array.isArray(t)?t[0]:t?String(t):void 0}export{i as audit,R as auditFetch,w as captureNextError,q as initNextDevInspector,M as withAuditAction,T 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 y=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var D=(n,e)=>{for(var r in e)y(n,r,{get:e[r],enumerable:!0})},C=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of q(e))!S.call(n,s)&&s!==r&&y(n,s,{get:()=>e[s],enumerable:!(t=A(e,s))||t.enumerable});return n};var U=n=>C(y({},"__esModule",{value:!0}),n);var O={};D(O,{audit:()=>a,auditFetch:()=>$,auditOperation:()=>B,devInspector:()=>Q,devInspectorErrorHandler:()=>j});module.exports=U(O);var E=require("async_hooks");var I=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let i=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(o=>this.truncate(o,r,t));let i={};for(let[o,d]of Object.entries(e))i[o]=this.truncate(d,r,t);return i}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),o=r.requestId,d=r.traceId,c=r.spanId,p={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:o,traceId:d,spanId:c,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...r,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},w="__DEVINSPECT_AUDIT_CORE_INSTANCE__",k=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[w]||(n[w]=new I),n[w]},a=k();async function v(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&a.isIngestUrl(s))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),o=a.createRequestId(),d=a.createTraceId(),c=a.createSpanId(),p=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",c);let m={...e,headers:p},h=typeof performance<"u"?performance.now():Date.now();try{let u=await t(n,m),l=Math.round((typeof performance<"u"?performance.now():Date.now())-h),g=a.getSlowThresholdMs();return(u.status>=400||l>=g)&&a.captureRequest({method:i,url:s,statusCode:u.status,durationMs:l,route:s,requestId:o,traceId:d,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:u.status,durationMs:l,requestId:o,traceId:d,spanId:c}}),u}catch(u){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-h);throw a.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:o,traceId:d,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(u instanceof Error?u:new Error(String(u)),{url:s,method:i,type:r?.errorType||"network_error",requestId:o,traceId:d,spanId:c}),a.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:o,traceId:d,spanId:c}}),u}}var b=new E.AsyncLocalStorage;function _(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 f(n,e){if(!n?.headers)return;let r=n.headers[e]||n.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}function Q(n){a.init(n);let e=n.slowThresholdMs??a.getSlowThresholdMs(),r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,s,i)=>{let o=t.originalUrl||t.url||"";if(o&&a.isIngestUrl(o)||r.some(u=>typeof u=="string"?o.startsWith(u):u.test(o)))return i();let c=typeof performance<"u"?performance.now():Date.now(),p=f(t,"x-devinspector-request-id")||a.createRequestId(),m=f(t,"x-devinspector-trace-id")||a.createTraceId(),h=f(t,"x-devinspector-span-id")||a.createSpanId();t.headers&&(t.headers["x-devinspector-request-id"]=p,t.headers["x-devinspector-trace-id"]=m,t.headers["x-devinspector-span-id"]=h),b.run({req:t,queriesCount:0,slowQueries:0,requestId:p,traceId:m,spanId:h},()=>{a.addBreadcrumb({type:"http",message:`${t.method} ${o}`,metadata:{framework:"Node.js",phase:"start",requestId:p,traceId:m,spanId:h}}),s.on("finish",()=>{let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c),l=b.getStore(),g=s.statusCode,x=g>=400,M=u>=e,T=(l?.slowQueries||0)>0,R=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||o;(x||M||T)&&a.captureRequest({method:t.method,url:o,statusCode:g,durationMs:u,userAgent:t.headers?.["user-agent"],route:R,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0,requestId:p,traceId:m,spanId:h}),a.addBreadcrumb({type:"http",message:`${t.method} ${o}`,metadata:{framework:"Node.js",phase:"complete",statusCode:g,durationMs:u,requestId:p,traceId:m,spanId:h,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0}})}),i()})}}async function $(n,e){return v(n,e,{errorType:"node_network_error"})}async function B(n,e,r){let t=b.getStore(),s=r??a.getSlowThresholdMs(),i=typeof performance<"u"?performance.now():Date.now();t&&t.queriesCount++;try{let o=await e(),d=(typeof performance<"u"?performance.now():Date.now())-i,c=Math.round(d);if(d>=s&&t){t.slowQueries=Math.max(t.slowQueries,c);let p=t.req?.originalUrl||t.req?.url||"";a.addBreadcrumb({type:"db_query",message:`Slow Query detectada em [${n}]`,metadata:{operationName:n,durationMs:c,requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,url:p}}),a.captureDbQuery({operation:n,collection:"Unknown",durationMs:c,url:p,requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,metadata:{operationName:n}})}return o}catch(o){let d=(typeof performance<"u"?performance.now():Date.now())-i,c=Math.round(d);throw a.captureException(o instanceof Error?o:new Error(String(o)),{operationName:n,durationMs:c,requestId:t?.requestId,traceId:t?.traceId,spanId:t?.spanId}),a.addBreadcrumb({type:"db_query_error",message:`Erro na opera\xE7\xE3o [${n}]`,metadata:{operationName:n,durationMs:c,requestId:t?.requestId,traceId:t?.traceId,spanId:t?.spanId}}),o}}function j(){return(n,e,r,t)=>{let s=b.getStore(),i=s?.requestId||f(e,"x-devinspector-request-id"),o=s?.traceId||f(e,"x-devinspector-trace-id"),d=s?.spanId||f(e,"x-devinspector-span-id");a.captureException(n instanceof Error?n:new Error(String(n)),{url:e.originalUrl||e.url,method:e.method,headers:_(e.headers),requestId:i,traceId:o,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${e.method||"HTTP"} ${e.originalUrl||e.url||""}`,metadata:{framework:"Node.js",statusCode:r?.statusCode||500,requestId:i,traceId:o,spanId:d}}),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 R}from"async_hooks";var w=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let i=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(o=>this.truncate(o,r,t));let i={};for(let[o,d]of Object.entries(e))i[o]=this.truncate(d,r,t);return i}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),o=r.requestId,d=r.traceId,c=r.spanId,p={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:o,traceId:d,spanId:c,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...r,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},y="__DEVINSPECT_AUDIT_CORE_INSTANCE__",T=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[y]||(n[y]=new w),n[y]},a=T();async function I(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&a.isIngestUrl(s))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),o=a.createRequestId(),d=a.createTraceId(),c=a.createSpanId(),p=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",c);let m={...e,headers:p},h=typeof performance<"u"?performance.now():Date.now();try{let u=await t(n,m),l=Math.round((typeof performance<"u"?performance.now():Date.now())-h),g=a.getSlowThresholdMs();return(u.status>=400||l>=g)&&a.captureRequest({method:i,url:s,statusCode:u.status,durationMs:l,route:s,requestId:o,traceId:d,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:u.status,durationMs:l,requestId:o,traceId:d,spanId:c}}),u}catch(u){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-h);throw a.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:o,traceId:d,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(u instanceof Error?u:new Error(String(u)),{url:s,method:i,type:r?.errorType||"network_error",requestId:o,traceId:d,spanId:c}),a.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:o,traceId:d,spanId:c}}),u}}var b=new R;function A(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 f(n,e){if(!n?.headers)return;let r=n.headers[e]||n.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}function C(n){a.init(n);let e=n.slowThresholdMs??a.getSlowThresholdMs(),r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,s,i)=>{let o=t.originalUrl||t.url||"";if(o&&a.isIngestUrl(o)||r.some(u=>typeof u=="string"?o.startsWith(u):u.test(o)))return i();let c=typeof performance<"u"?performance.now():Date.now(),p=f(t,"x-devinspector-request-id")||a.createRequestId(),m=f(t,"x-devinspector-trace-id")||a.createTraceId(),h=f(t,"x-devinspector-span-id")||a.createSpanId();t.headers&&(t.headers["x-devinspector-request-id"]=p,t.headers["x-devinspector-trace-id"]=m,t.headers["x-devinspector-span-id"]=h),b.run({req:t,queriesCount:0,slowQueries:0,requestId:p,traceId:m,spanId:h},()=>{a.addBreadcrumb({type:"http",message:`${t.method} ${o}`,metadata:{framework:"Node.js",phase:"start",requestId:p,traceId:m,spanId:h}}),s.on("finish",()=>{let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c),l=b.getStore(),g=s.statusCode,v=g>=400,E=u>=e,x=(l?.slowQueries||0)>0,M=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||o;(v||E||x)&&a.captureRequest({method:t.method,url:o,statusCode:g,durationMs:u,userAgent:t.headers?.["user-agent"],route:M,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0,requestId:p,traceId:m,spanId:h}),a.addBreadcrumb({type:"http",message:`${t.method} ${o}`,metadata:{framework:"Node.js",phase:"complete",statusCode:g,durationMs:u,requestId:p,traceId:m,spanId:h,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0}})}),i()})}}async function U(n,e){return I(n,e,{errorType:"node_network_error"})}async function k(n,e,r){let t=b.getStore(),s=r??a.getSlowThresholdMs(),i=typeof performance<"u"?performance.now():Date.now();t&&t.queriesCount++;try{let o=await e(),d=(typeof performance<"u"?performance.now():Date.now())-i,c=Math.round(d);if(d>=s&&t){t.slowQueries=Math.max(t.slowQueries,c);let p=t.req?.originalUrl||t.req?.url||"";a.addBreadcrumb({type:"db_query",message:`Slow Query detectada em [${n}]`,metadata:{operationName:n,durationMs:c,requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,url:p}}),a.captureDbQuery({operation:n,collection:"Unknown",durationMs:c,url:p,requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,metadata:{operationName:n}})}return o}catch(o){let d=(typeof performance<"u"?performance.now():Date.now())-i,c=Math.round(d);throw a.captureException(o instanceof Error?o:new Error(String(o)),{operationName:n,durationMs:c,requestId:t?.requestId,traceId:t?.traceId,spanId:t?.spanId}),a.addBreadcrumb({type:"db_query_error",message:`Erro na opera\xE7\xE3o [${n}]`,metadata:{operationName:n,durationMs:c,requestId:t?.requestId,traceId:t?.traceId,spanId:t?.spanId}}),o}}function _(){return(n,e,r,t)=>{let s=b.getStore(),i=s?.requestId||f(e,"x-devinspector-request-id"),o=s?.traceId||f(e,"x-devinspector-trace-id"),d=s?.spanId||f(e,"x-devinspector-span-id");a.captureException(n instanceof Error?n:new Error(String(n)),{url:e.originalUrl||e.url,method:e.method,headers:A(e.headers),requestId:i,traceId:o,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${e.method||"HTTP"} ${e.originalUrl||e.url||""}`,metadata:{framework:"Node.js",statusCode:r?.statusCode||500,requestId:i,traceId:o,spanId:d}}),t(n)}}export{a as audit,U as auditFetch,k as auditOperation,C as devInspector,_ as devInspectorErrorHandler};
|