@xcodleox/devinspector 7.5.0 → 8.1.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.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +71 -8
- package/dist/index.d.ts +71 -8
- 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.js +1 -1
- package/dist/react-native.cjs +1 -1
- 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 H=Object.create;var l=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var K=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),g=n=>{throw TypeError(n)};var z=(n,e,t)=>e in n?l(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var S=(n,e)=>l(n,"name",{value:e,configurable:!0});var W=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},B=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of $(e))!Y.call(n,r)&&r!==t&&l(n,r,{get:()=>e[r],enumerable:!(o=j(e,r))||o.enumerable});return n};var J=n=>B(l({},"__esModule",{value:!0}),n);var O=n=>[,,,H(n?.[K("metadata")]??null)],P=["class","method","getter","setter","accessor","field","value","get","set"],w=n=>n!==void 0&&typeof n!="function"?g("Function expected"):n,V=(n,e,t,o,r)=>({kind:P[n],name:e,metadata:o,addInitializer:i=>t._?g("Already initialized"):r.push(w(i||null))}),X=(n,e)=>z(e,K("metadata"),n[3]),G=(n,e,t,o)=>{for(var r=0,i=n[e>>1],c=i&&i.length;r<c;r++)e&1?i[r].call(t):o=i[r].call(t,o);return o},N=(n,e,t,o,r,i)=>{var c,a,D,y,m,s=e&7,E=!!(e&8),p=!!(e&16),b=s>3?n.length+1:s?E?1:2:0,T=P[s+5],M=s>3&&(n[b-1]=[]),F=n[b]||(n[b]=[]),d=s&&(!p&&!E&&(r=r.prototype),s<5&&(s>3||!p)&&j(s<4?r:{get[t](){return x(this,i)},set[t](u){return C(this,i,u)}},t));s?p&&s<4&&S(i,(s>2?"set ":s>1?"get ":"")+t):S(r,t);for(var v=o.length-1;v>=0;v--)y=V(s,t,D={},n[3],F),s&&(y.static=E,y.private=p,m=y.access={has:p?u=>Z(r,u):u=>t in u},s^3&&(m.get=p?u=>(s^1?x:ee)(u,r,s^4?i:d.get):u=>u[t]),s>2&&(m.set=p?(u,I)=>C(u,r,I,s^4?i:d.set):(u,I)=>u[t]=I)),a=(0,o[v])(s?s<4?p?i:d[T]:s>4?void 0:{get:d.get,set:d.set}:r,y),D._=1,s^4||a===void 0?w(a)&&(s>4?M.unshift(a):s?p?i=a:d[T]=a:r=a):typeof a!="object"||a===null?g("Object expected"):(w(c=a.get)&&(d.get=c),w(c=a.set)&&(d.set=c),w(c=a.init)&&M.unshift(c));return s||X(n,r),d&&l(r,t,d),p?s^4?i:d:r};var R=(n,e,t)=>e.has(n)||g("Cannot "+t),Z=(n,e)=>Object(e)!==e?g('Cannot use the "in" operator on this value'):n.has(e),x=(n,e,t)=>(R(n,e,"read from private field"),t?t.call(n):e.get(n));var C=(n,e,t,o)=>(R(n,e,"write to private field"),o?o.call(n,t):e.set(n,t),t),ee=(n,e,t)=>(R(n,e,"access private method"),t);var re={};W(re,{AuditAngularErrorHandler:()=>h,audit:()=>f,auditInterceptor:()=>ne,devInspectorInterceptor:()=>q});module.exports=J(re);var L=require("@angular/core"),Q=require("rxjs/operators");var A=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((o,r)=>{let i=o instanceof Error?o:new Error(String(o?.message||o||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!r}),t&&t(o,r)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let o=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(o,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",o=>{this.captureError(o,{type:"uncaught_exception"})}),t.on("unhandledRejection",o=>{let r=o instanceof Error?o:new Error(String(o));this.captureError(r,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,o=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(o.has(e))return"[Circular Reference]";o.add(e);let r={};for(let[i,c]of Object.entries(e))r[i]=this.truncate(c,t,o);return r}return e}captureError(e,t={}){let o=e.message||"Erro Desconhecido",r=e.stack||"",i={type:"error",message:this.truncate(o,500),stackTrace:this.truncate(r,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let o={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(o)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let o=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});o.ok||console.error(`[DevInspector] Erro na API (${o.status}): ${o.statusText}`)}catch(o){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",o)}}},k="__DEVINSPECT_AUDIT_CORE_INSTANCE__",te=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[k]||(n[k]=new A),n[k]},f=te();var U,_;U=[(0,L.Injectable)()];var h=class{handleError(e){let t=e instanceof Error?e:new Error(String(e));f.captureError(t,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};_=O(null),h=N(_,0,"AuditAngularErrorHandler",U,h),G(_,1,h);var q=(n,e)=>{let t=n.urlWithParams||n.url||"";if(t&&f.isIngestUrl(t))return e(n);let o=typeof performance<"u"?performance.now():Date.now();return e(n).pipe((0,Q.tap)({next:r=>{if(r&&typeof r=="object"&&"status"in r&&"clone"in r){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-o),a=r.status;(a>=400||c>=300)&&f.captureRequest({method:n.method,url:t,statusCode:a,durationMs:c,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url})}},error:r=>{let i=Math.round((typeof performance<"u"?performance.now():Date.now())-o);f.captureRequest({method:n.method,url:t,statusCode:r?.status||0,durationMs:i,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url}),f.captureException(new Error(`HTTP Error ${r?.status||0}: ${r?.message||r?.statusText||"Erro de rede no cliente"}`),{url:t,method:n.method,status:r?.status,type:"angular_network_error"})}}))},ne=q;0&&(module.exports={AuditAngularErrorHandler,audit,auditInterceptor,devInspectorInterceptor});
|
|
1
|
+
"use strict";var Y=Object.create;var g=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var N=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),y=t=>{throw TypeError(t)};var ee=(t,e,r)=>e in t?g(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var _=(t,e)=>g(t,"name",{value:e,configurable:!0});var te=(t,e)=>{for(var r in e)g(t,r,{get:e[r],enumerable:!0})},re=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of J(e))!Z.call(t,n)&&n!==r&&g(t,n,{get:()=>e[n],enumerable:!(s=C(e,n))||s.enumerable});return t};var ne=t=>re(g({},"__esModule",{value:!0}),t);var B=t=>[,,,Y(t?.[N("metadata")]??null)],O=["class","method","getter","setter","accessor","field","value","get","set"],w=t=>t!==void 0&&typeof t!="function"?y("Function expected"):t,se=(t,e,r,s,n)=>({kind:O[t],name:e,metadata:s,addInitializer:i=>r._?y("Already initialized"):n.push(w(i||null))}),ie=(t,e)=>ee(e,N("metadata"),t[3]),L=(t,e,r,s)=>{for(var n=0,i=t[e>>1],a=i&&i.length;n<a;n++)e&1?i[n].call(r):s=i[n].call(r,s);return s},z=(t,e,r,s,n,i)=>{var a,u,d,l,c,o=e&7,E=!!(e&8),h=!!(e&16),M=o>3?t.length+1:o?E?1:2:0,A=O[o+5],D=o>3&&(t[M-1]=[]),W=t[M]||(t[M]=[]),f=o&&(!h&&!E&&(n=n.prototype),o<5&&(o>3||!h)&&C(o<4?n:{get[r](){return x(this,i)},set[r](p){return q(this,i,p)}},r));o?h&&o<4&&_(i,(o>2?"set ":o>1?"get ":"")+r):_(n,r);for(var R=s.length-1;R>=0;R--)l=se(o,r,d={},t[3],W),o&&(l.static=E,l.private=h,c=l.access={has:h?p=>oe(n,p):p=>r in p},o^3&&(c.get=h?p=>(o^1?x:ae)(p,n,o^4?i:f.get):p=>p[r]),o>2&&(c.set=h?(p,S)=>q(p,n,S,o^4?i:f.set):(p,S)=>p[r]=S)),u=(0,s[R])(o?o<4?h?i:f[A]:o>4?void 0:{get:f.get,set:f.set}:n,l),d._=1,o^4||u===void 0?w(u)&&(o>4?D.unshift(u):o?h?i=u:f[A]=u:n=u):typeof u!="object"||u===null?y("Object expected"):(w(a=u.get)&&(f.get=a),w(a=u.set)&&(f.set=a),w(a=u.init)&&D.unshift(a));return o||ie(t,n),f&&g(n,r,f),h?o^4?i:f:n};var T=(t,e,r)=>e.has(t)||y("Cannot "+r),oe=(t,e)=>Object(e)!==e?y('Cannot use the "in" operator on this value'):t.has(e),x=(t,e,r)=>(T(t,e,"read from private field"),r?r.call(t):e.get(t));var q=(t,e,r,s)=>(T(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r),ae=(t,e,r)=>(T(t,e,"access private method"),r);var le={};te(le,{AuditAngularErrorHandler:()=>b,audit:()=>m,auditInterceptor:()=>me,devInspectorInterceptor:()=>X});module.exports=ne(le);var Q=require("@angular/core"),V=require("rxjs/operators");var $="https://api.devinspector.com.br/api/ingest/track";var de=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ue(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return de.some(r=>e.includes(r))}function I(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(i=>I(i,e+1,r));let s=t,n={};for(let[i,a]of Object.entries(s)){if(ue(i)){n[i]="[REDACTED]";continue}n[i]=I(a,e+1,r)}return n}function j(t){if(t)return String(t).trim().toUpperCase()}function G(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function K(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function ce(t){return String(t??"").trim().slice(0,200)}function pe(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function v(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var U=class{constructor(){this.apiKey="";this.endpoint=$;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||$,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?I(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?I(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(e,r.origin);return s.origin===r.origin&&s.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}captureRequest(e){let r=j(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=G(e.statusCode)??0,i=K(e.durationMs)??0,a={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:a})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let s=K(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,s={},n={}){let i=ce(e);if(!i)return;let a;try{a=pe(r)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let s=e?.message?.trim()||"Erro desconhecido",n={...r},i=j(n.method),a=G(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,l=n.spanId?String(n.spanId):void 0,c=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:c,method:i,statusCode:a,requestId:u,traceId:d,spanId:l,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof r=="function"&&r(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let s=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(s,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let s=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=I(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},H="__DEVINSPECT_AUDIT_CORE_INSTANCE__",F=typeof globalThis<"u"?globalThis:{},m=F[H]||new U;F[H]=m;var P,k;P=[(0,Q.Injectable)()];var b=class{handleError(e){let r=e instanceof Error?e:new Error(String(e));m.captureError(r,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};k=B(null),b=z(k,0,"AuditAngularErrorHandler",P,b),L(k,1,b);var X=(t,e)=>{let r=t.urlWithParams||t.url||"";if(r&&m.isIngestUrl(r))return e(t);let s=m.createRequestId(),n=m.createTraceId(),i=m.createSpanId(),a=t;t&&typeof t.clone=="function"&&(a=t.clone({setHeaders:{"x-devinspector-request-id":s,"x-devinspector-trace-id":n,"x-devinspector-span-id":i}}));let u=typeof performance<"u"?performance.now():Date.now();return e(a).pipe((0,V.tap)({next:d=>{if(!(d&&typeof d=="object"&&"status"in d&&"clone"in d))return;let c=Math.round((typeof performance<"u"?performance.now():Date.now())-u),o=d.status;(o>=400||c>=300)&&m.captureRequest({method:t.method,url:r,statusCode:o,durationMs:c,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),m.addBreadcrumb({type:"http",message:`${t.method} ${r}`,metadata:{statusCode:o,durationMs:c,requestId:s,traceId:n,spanId:i}})},error:d=>{let l=Math.round((typeof performance<"u"?performance.now():Date.now())-u),c=Number(d?.status)||0;m.captureRequest({method:t.method,url:r,statusCode:c,durationMs:l,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),m.captureException(new Error(`HTTP Error ${c}: ${d?.message||d?.statusText||"Erro de rede no cliente"}`),{url:r,method:t.method,status:d?.status,statusText:d?.statusText,type:"angular_network_error",requestId:s,traceId:n,spanId:i}),m.addBreadcrumb({type:"http_error",message:`${t.method} ${r}`,metadata:{statusCode:c,durationMs:l,requestId:s,traceId:n,spanId:i,error:d?.message||d?.statusText||"Network Error"}})}}))},me=X;0&&(module.exports={AuditAngularErrorHandler,audit,auditInterceptor,devInspectorInterceptor});
|
package/dist/angular.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var L=Object.create;var I=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var j=(n,e)=>(e=Symbol[n])?e:Symbol.for("Symbol."+n),y=n=>{throw TypeError(n)};var q=(n,e,t)=>e in n?I(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var S=(n,e)=>I(n,"name",{value:e,configurable:!0});var K=n=>[,,,L(n?.[j("metadata")]??null)],O=["class","method","getter","setter","accessor","field","value","get","set"],h=n=>n!==void 0&&typeof n!="function"?y("Function expected"):n,F=(n,e,t,r,o)=>({kind:O[n],name:e,metadata:r,addInitializer:i=>t._?y("Already initialized"):o.push(h(i||null))}),H=(n,e)=>q(e,j("metadata"),n[3]),P=(n,e,t,r)=>{for(var o=0,i=n[e>>1],c=i&&i.length;o<c;o++)e&1?i[o].call(t):r=i[o].call(t,r);return r},G=(n,e,t,r,o,i)=>{var c,a,D,l,g,s=e&7,m=!!(e&8),p=!!(e&16),E=s>3?n.length+1:s?m?1:2:0,T=O[s+5],M=s>3&&(n[E-1]=[]),U=n[E]||(n[E]=[]),d=s&&(!p&&!m&&(o=o.prototype),s<5&&(s>3||!p)&&Q(s<4?o:{get[t](){return x(this,i)},set[t](u){return C(this,i,u)}},t));s?p&&s<4&&S(i,(s>2?"set ":s>1?"get ":"")+t):S(o,t);for(var b=r.length-1;b>=0;b--)l=F(s,t,D={},n[3],U),s&&(l.static=m,l.private=p,g=l.access={has:p?u=>$(o,u):u=>t in u},s^3&&(g.get=p?u=>(s^1?x:Y)(u,o,s^4?i:d.get):u=>u[t]),s>2&&(g.set=p?(u,v)=>C(u,o,v,s^4?i:d.set):(u,v)=>u[t]=v)),a=(0,r[b])(s?s<4?p?i:d[T]:s>4?void 0:{get:d.get,set:d.set}:o,l),D._=1,s^4||a===void 0?h(a)&&(s>4?M.unshift(a):s?p?i=a:d[T]=a:o=a):typeof a!="object"||a===null?y("Object expected"):(h(c=a.get)&&(d.get=c),h(c=a.set)&&(d.set=c),h(c=a.init)&&M.unshift(c));return s||H(n,o),d&&I(o,t,d),p?s^4?i:d:o};var R=(n,e,t)=>e.has(n)||y("Cannot "+t),$=(n,e)=>Object(e)!==e?y('Cannot use the "in" operator on this value'):n.has(e),x=(n,e,t)=>(R(n,e,"read from private field"),t?t.call(n):e.get(n));var C=(n,e,t,r)=>(R(n,e,"write to private field"),r?r.call(n,t):e.set(n,t),t),Y=(n,e,t)=>(R(n,e,"access private method"),t);import{Injectable as W}from"@angular/core";import{tap as B}from"rxjs/operators";var A=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((r,o)=>{let i=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),t&&t(r,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let r=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(r,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",r=>{this.captureError(r,{type:"uncaught_exception"})}),t.on("unhandledRejection",r=>{let o=r instanceof Error?r:new Error(String(r));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,r=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let o={};for(let[i,c]of Object.entries(e))o[i]=this.truncate(c,t,r);return o}return e}captureError(e,t={}){let r=e.message||"Erro Desconhecido",o=e.stack||"",i={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let r={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},k="__DEVINSPECT_AUDIT_CORE_INSTANCE__",z=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[k]||(n[k]=new A),n[k]},f=z();var N,_;N=[W()];var w=class{handleError(e){let t=e instanceof Error?e:new Error(String(e));f.captureError(t,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};_=K(null),w=G(_,0,"AuditAngularErrorHandler",N,w),P(_,1,w);var J=(n,e)=>{let t=n.urlWithParams||n.url||"";if(t&&f.isIngestUrl(t))return e(n);let r=typeof performance<"u"?performance.now():Date.now();return e(n).pipe(B({next:o=>{if(o&&typeof o=="object"&&"status"in o&&"clone"in o){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-r),a=o.status;(a>=400||c>=300)&&f.captureRequest({method:n.method,url:t,statusCode:a,durationMs:c,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url})}},error:o=>{let i=Math.round((typeof performance<"u"?performance.now():Date.now())-r);f.captureRequest({method:n.method,url:t,statusCode:o?.status||0,durationMs:i,userAgent:typeof navigator<"u"?navigator.userAgent:"",route:n.url}),f.captureException(new Error(`HTTP Error ${o?.status||0}: ${o?.message||o?.statusText||"Erro de rede no cliente"}`),{url:t,method:n.method,status:o?.status,type:"angular_network_error"})}}))},re=J;export{w as AuditAngularErrorHandler,f as audit,re as auditInterceptor,J as devInspectorInterceptor};
|
|
1
|
+
var Q=Object.create;var S=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var C=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),b=t=>{throw TypeError(t)};var X=(t,e,r)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var _=(t,e)=>S(t,"name",{value:e,configurable:!0});var N=t=>[,,,Q(t?.[C("metadata")]??null)],B=["class","method","getter","setter","accessor","field","value","get","set"],g=t=>t!==void 0&&typeof t!="function"?b("Function expected"):t,W=(t,e,r,s,n)=>({kind:B[t],name:e,metadata:s,addInitializer:i=>r._?b("Already initialized"):n.push(g(i||null))}),Y=(t,e)=>X(e,C("metadata"),t[3]),O=(t,e,r,s)=>{for(var n=0,i=t[e>>1],a=i&&i.length;n<a;n++)e&1?i[n].call(r):s=i[n].call(r,s);return s},L=(t,e,r,s,n,i)=>{var a,u,d,l,c,o=e&7,I=!!(e&8),h=!!(e&16),E=o>3?t.length+1:o?I?1:2:0,A=B[o+5],D=o>3&&(t[E-1]=[]),P=t[E]||(t[E]=[]),f=o&&(!h&&!I&&(n=n.prototype),o<5&&(o>3||!h)&&V(o<4?n:{get[r](){return x(this,i)},set[r](p){return q(this,i,p)}},r));o?h&&o<4&&_(i,(o>2?"set ":o>1?"get ":"")+r):_(n,r);for(var M=s.length-1;M>=0;M--)l=W(o,r,d={},t[3],P),o&&(l.static=I,l.private=h,c=l.access={has:h?p=>J(n,p):p=>r in p},o^3&&(c.get=h?p=>(o^1?x:Z)(p,n,o^4?i:f.get):p=>p[r]),o>2&&(c.set=h?(p,R)=>q(p,n,R,o^4?i:f.set):(p,R)=>p[r]=R)),u=(0,s[M])(o?o<4?h?i:f[A]:o>4?void 0:{get:f.get,set:f.set}:n,l),d._=1,o^4||u===void 0?g(u)&&(o>4?D.unshift(u):o?h?i=u:f[A]=u:n=u):typeof u!="object"||u===null?b("Object expected"):(g(a=u.get)&&(f.get=a),g(a=u.set)&&(f.set=a),g(a=u.init)&&D.unshift(a));return o||Y(t,n),f&&S(n,r,f),h?o^4?i:f:n};var T=(t,e,r)=>e.has(t)||b("Cannot "+r),J=(t,e)=>Object(e)!==e?b('Cannot use the "in" operator on this value'):t.has(e),x=(t,e,r)=>(T(t,e,"read from private field"),r?r.call(t):e.get(t));var q=(t,e,r,s)=>(T(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r),Z=(t,e,r)=>(T(t,e,"access private method"),r);import{Injectable as se}from"@angular/core";import{tap as ie}from"rxjs/operators";var z="https://api.devinspector.com.br/api/ingest/track";var ee=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function te(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return ee.some(r=>e.includes(r))}function w(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(i=>w(i,e+1,r));let s=t,n={};for(let[i,a]of Object.entries(s)){if(te(i)){n[i]="[REDACTED]";continue}n[i]=w(a,e+1,r)}return n}function $(t){if(t)return String(t).trim().toUpperCase()}function j(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function G(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function re(t){return String(t??"").trim().slice(0,200)}function ne(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function v(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var U=class{constructor(){this.apiKey="";this.endpoint=z;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||z,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?w(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?w(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(e,r.origin);return s.origin===r.origin&&s.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}captureRequest(e){let r=$(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=j(e.statusCode)??0,i=G(e.durationMs)??0,a={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:a})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let s=G(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,s={},n={}){let i=re(e);if(!i)return;let a;try{a=ne(r)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let s=e?.message?.trim()||"Erro desconhecido",n={...r},i=$(n.method),a=j(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,l=n.spanId?String(n.spanId):void 0,c=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:c,method:i,statusCode:a,requestId:u,traceId:d,spanId:l,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof r=="function"&&r(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let s=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(s,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let s=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=w(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},K="__DEVINSPECT_AUDIT_CORE_INSTANCE__",H=typeof globalThis<"u"?globalThis:{},m=H[K]||new U;H[K]=m;var F,k;F=[se()];var y=class{handleError(e){let r=e instanceof Error?e:new Error(String(e));m.captureError(r,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};k=N(null),y=L(k,0,"AuditAngularErrorHandler",F,y),O(k,1,y);var oe=(t,e)=>{let r=t.urlWithParams||t.url||"";if(r&&m.isIngestUrl(r))return e(t);let s=m.createRequestId(),n=m.createTraceId(),i=m.createSpanId(),a=t;t&&typeof t.clone=="function"&&(a=t.clone({setHeaders:{"x-devinspector-request-id":s,"x-devinspector-trace-id":n,"x-devinspector-span-id":i}}));let u=typeof performance<"u"?performance.now():Date.now();return e(a).pipe(ie({next:d=>{if(!(d&&typeof d=="object"&&"status"in d&&"clone"in d))return;let c=Math.round((typeof performance<"u"?performance.now():Date.now())-u),o=d.status;(o>=400||c>=300)&&m.captureRequest({method:t.method,url:r,statusCode:o,durationMs:c,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),m.addBreadcrumb({type:"http",message:`${t.method} ${r}`,metadata:{statusCode:o,durationMs:c,requestId:s,traceId:n,spanId:i}})},error:d=>{let l=Math.round((typeof performance<"u"?performance.now():Date.now())-u),c=Number(d?.status)||0;m.captureRequest({method:t.method,url:r,statusCode:c,durationMs:l,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),m.captureException(new Error(`HTTP Error ${c}: ${d?.message||d?.statusText||"Erro de rede no cliente"}`),{url:r,method:t.method,status:d?.status,statusText:d?.statusText,type:"angular_network_error",requestId:s,traceId:n,spanId:i}),m.addBreadcrumb({type:"http_error",message:`${t.method} ${r}`,metadata:{statusCode:c,durationMs:l,requestId:s,traceId:n,spanId:i,error:d?.message||d?.statusText||"Network Error"}})}}))},fe=oe;export{y as AuditAngularErrorHandler,m as audit,fe as auditInterceptor,oe as devInspectorInterceptor};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var U=(r,e)=>{for(var t in e)c(r,t,{get:e[t],enumerable:!0})},A=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of S(e))!R.call(r,n)&&n!==t&&c(r,n,{get:()=>e[n],enumerable:!(s=M(e,n))||s.enumerable});return r};var T=r=>A(c({},"__esModule",{value:!0}),r);var _={};U(_,{AuditCore:()=>u,audit:()=>p});module.exports=T(_);var m="https://api.devinspector.com.br/api/ingest/track";var v=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function D(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return v.some(t=>e.includes(t))}function a(r,e=0,t=new WeakSet){if(r==null)return r;if(typeof r=="string")return r.length>1e4?`${r.slice(0,1e4)}...[truncated]`:r;if(typeof r=="number"||typeof r=="boolean")return r;if(typeof r=="bigint")return String(r);if(typeof r=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof r!="object")return String(r);if(t.has(r))return"[Circular]";if(t.add(r),Array.isArray(r))return r.slice(0,100).map(i=>a(i,e+1,t));let s=r,n={};for(let[i,o]of Object.entries(s)){if(D(i)){n[i]="[REDACTED]";continue}n[i]=a(o,e+1,t)}return n}function l(r){if(r)return String(r).trim().toUpperCase()}function f(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function h(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function k(r){return String(r??"").trim().slice(0,200)}function q(r){let e=Number(r);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function d(r){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${r}-${e.randomUUID()}`:`${r}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var u=class{constructor(){this.apiKey="";this.endpoint=m;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||m,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?a(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?a(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),s=new URL(e,t.origin);return s.origin===t.origin&&s.pathname===t.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return d("req")}createTraceId(){return d("trace")}createSpanId(){return d("span")}captureRequest(e){let t=l(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=f(e.statusCode)??0,i=h(e.durationMs)??0,o={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:t,url:s,statusCode:n,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:o})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return;let s=h(e.durationMs)??0,n={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${t}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,t,s={},n={}){let i=k(e);if(!i)return;let o;try{o=q(t)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let s=e?.message?.trim()||"Erro desconhecido",n={...t},i=l(n.method),o=f(n.statusCode??n.status),y=n.requestId?String(n.requestId):void 0,w=n.traceId?String(n.traceId):void 0,I=n.spanId?String(n.spanId):void 0,E=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:E,method:i,statusCode:o,requestId:y,traceId:w,spanId:I,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,t={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,t)}captureMessage(e,t={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...t,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof t=="function"&&t(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let s=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(s,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let s=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let t=a(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(t),keepalive:!0})}catch{}}},g="__DEVINSPECT_AUDIT_CORE_INSTANCE__",b=typeof globalThis<"u"?globalThis:{},p=b[g]||new u;b[g]=p;0&&(module.exports={AuditCore,audit});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
type UnknownRecord = Record<string, unknown>;
|
|
2
|
+
interface AuditUser {
|
|
3
|
+
id?: string;
|
|
4
|
+
email?: string;
|
|
5
|
+
username?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface Breadcrumb {
|
|
9
|
+
timestamp?: string;
|
|
10
|
+
type: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
metadata?: UnknownRecord;
|
|
13
|
+
}
|
|
1
14
|
interface InitOptions {
|
|
2
15
|
apiKey: string;
|
|
3
16
|
endpoint?: string;
|
|
4
17
|
environment?: string;
|
|
18
|
+
release?: string;
|
|
5
19
|
slowThresholdMs?: number;
|
|
6
20
|
}
|
|
7
21
|
interface RequestMetricData {
|
|
@@ -13,23 +27,72 @@ interface RequestMetricData {
|
|
|
13
27
|
route?: string;
|
|
14
28
|
dbQueriesCount?: number;
|
|
15
29
|
slowQueryMs?: number;
|
|
30
|
+
requestId?: string;
|
|
31
|
+
traceId?: string;
|
|
32
|
+
spanId?: string;
|
|
33
|
+
metadata?: UnknownRecord;
|
|
34
|
+
}
|
|
35
|
+
interface DbQueryData {
|
|
36
|
+
operation: string;
|
|
37
|
+
collection?: string;
|
|
38
|
+
durationMs: number;
|
|
39
|
+
url?: string;
|
|
40
|
+
requestId?: string;
|
|
41
|
+
traceId?: string;
|
|
42
|
+
spanId?: string;
|
|
43
|
+
metadata?: UnknownRecord;
|
|
44
|
+
}
|
|
45
|
+
interface CustomMetricData {
|
|
46
|
+
metricName: string;
|
|
47
|
+
metricValue: number;
|
|
48
|
+
metadata?: UnknownRecord;
|
|
49
|
+
requestId?: string;
|
|
50
|
+
traceId?: string;
|
|
51
|
+
spanId?: string;
|
|
16
52
|
}
|
|
53
|
+
type AuditEventType = "error" | "message" | "request_metric" | "db_query" | "custom_metric";
|
|
17
54
|
declare class AuditCore {
|
|
18
55
|
private apiKey;
|
|
19
56
|
private endpoint;
|
|
20
57
|
private environment;
|
|
21
|
-
|
|
58
|
+
private release?;
|
|
59
|
+
private slowThresholdMs;
|
|
60
|
+
private user?;
|
|
61
|
+
private breadcrumbs;
|
|
62
|
+
private initialized;
|
|
22
63
|
private listenersAttached;
|
|
23
64
|
init(options: InitOptions): void;
|
|
24
|
-
|
|
65
|
+
getApiKey(): string;
|
|
66
|
+
getEndpoint(): string;
|
|
67
|
+
getEnvironment(): string;
|
|
68
|
+
getRelease(): string | undefined;
|
|
69
|
+
getSlowThresholdMs(): number;
|
|
70
|
+
isInitialized(): boolean;
|
|
71
|
+
setUser(user?: AuditUser): void;
|
|
72
|
+
getUser(): AuditUser | undefined;
|
|
73
|
+
clearUser(): void;
|
|
74
|
+
addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
75
|
+
getBreadcrumbs(): Breadcrumb[];
|
|
76
|
+
clearBreadcrumbs(): void;
|
|
77
|
+
getContext(): UnknownRecord;
|
|
78
|
+
isIngestUrl(url: string): boolean;
|
|
79
|
+
createRequestId(): string;
|
|
80
|
+
createTraceId(): string;
|
|
81
|
+
createSpanId(): string;
|
|
25
82
|
captureRequest(data: RequestMetricData): void;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
83
|
+
captureDbQuery(data: DbQueryData): void;
|
|
84
|
+
captureMetric(metricName: string, metricValue: number, metadata?: UnknownRecord, contextIds?: {
|
|
85
|
+
requestId?: string;
|
|
86
|
+
traceId?: string;
|
|
87
|
+
spanId?: string;
|
|
88
|
+
}): void;
|
|
89
|
+
captureCustomMetric(data: CustomMetricData): void;
|
|
90
|
+
captureError(error: Error, metadata?: UnknownRecord): void;
|
|
91
|
+
captureException(error: unknown, metadata?: UnknownRecord): void;
|
|
92
|
+
captureMessage(message: string, metadata?: UnknownRecord): void;
|
|
93
|
+
private attachGlobalListeners;
|
|
31
94
|
private send;
|
|
32
95
|
}
|
|
33
96
|
declare const audit: AuditCore;
|
|
34
97
|
|
|
35
|
-
export { AuditCore, type InitOptions, type RequestMetricData, audit };
|
|
98
|
+
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
type UnknownRecord = Record<string, unknown>;
|
|
2
|
+
interface AuditUser {
|
|
3
|
+
id?: string;
|
|
4
|
+
email?: string;
|
|
5
|
+
username?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface Breadcrumb {
|
|
9
|
+
timestamp?: string;
|
|
10
|
+
type: string;
|
|
11
|
+
message?: string;
|
|
12
|
+
metadata?: UnknownRecord;
|
|
13
|
+
}
|
|
1
14
|
interface InitOptions {
|
|
2
15
|
apiKey: string;
|
|
3
16
|
endpoint?: string;
|
|
4
17
|
environment?: string;
|
|
18
|
+
release?: string;
|
|
5
19
|
slowThresholdMs?: number;
|
|
6
20
|
}
|
|
7
21
|
interface RequestMetricData {
|
|
@@ -13,23 +27,72 @@ interface RequestMetricData {
|
|
|
13
27
|
route?: string;
|
|
14
28
|
dbQueriesCount?: number;
|
|
15
29
|
slowQueryMs?: number;
|
|
30
|
+
requestId?: string;
|
|
31
|
+
traceId?: string;
|
|
32
|
+
spanId?: string;
|
|
33
|
+
metadata?: UnknownRecord;
|
|
34
|
+
}
|
|
35
|
+
interface DbQueryData {
|
|
36
|
+
operation: string;
|
|
37
|
+
collection?: string;
|
|
38
|
+
durationMs: number;
|
|
39
|
+
url?: string;
|
|
40
|
+
requestId?: string;
|
|
41
|
+
traceId?: string;
|
|
42
|
+
spanId?: string;
|
|
43
|
+
metadata?: UnknownRecord;
|
|
44
|
+
}
|
|
45
|
+
interface CustomMetricData {
|
|
46
|
+
metricName: string;
|
|
47
|
+
metricValue: number;
|
|
48
|
+
metadata?: UnknownRecord;
|
|
49
|
+
requestId?: string;
|
|
50
|
+
traceId?: string;
|
|
51
|
+
spanId?: string;
|
|
16
52
|
}
|
|
53
|
+
type AuditEventType = "error" | "message" | "request_metric" | "db_query" | "custom_metric";
|
|
17
54
|
declare class AuditCore {
|
|
18
55
|
private apiKey;
|
|
19
56
|
private endpoint;
|
|
20
57
|
private environment;
|
|
21
|
-
|
|
58
|
+
private release?;
|
|
59
|
+
private slowThresholdMs;
|
|
60
|
+
private user?;
|
|
61
|
+
private breadcrumbs;
|
|
62
|
+
private initialized;
|
|
22
63
|
private listenersAttached;
|
|
23
64
|
init(options: InitOptions): void;
|
|
24
|
-
|
|
65
|
+
getApiKey(): string;
|
|
66
|
+
getEndpoint(): string;
|
|
67
|
+
getEnvironment(): string;
|
|
68
|
+
getRelease(): string | undefined;
|
|
69
|
+
getSlowThresholdMs(): number;
|
|
70
|
+
isInitialized(): boolean;
|
|
71
|
+
setUser(user?: AuditUser): void;
|
|
72
|
+
getUser(): AuditUser | undefined;
|
|
73
|
+
clearUser(): void;
|
|
74
|
+
addBreadcrumb(breadcrumb: Breadcrumb): void;
|
|
75
|
+
getBreadcrumbs(): Breadcrumb[];
|
|
76
|
+
clearBreadcrumbs(): void;
|
|
77
|
+
getContext(): UnknownRecord;
|
|
78
|
+
isIngestUrl(url: string): boolean;
|
|
79
|
+
createRequestId(): string;
|
|
80
|
+
createTraceId(): string;
|
|
81
|
+
createSpanId(): string;
|
|
25
82
|
captureRequest(data: RequestMetricData): void;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
83
|
+
captureDbQuery(data: DbQueryData): void;
|
|
84
|
+
captureMetric(metricName: string, metricValue: number, metadata?: UnknownRecord, contextIds?: {
|
|
85
|
+
requestId?: string;
|
|
86
|
+
traceId?: string;
|
|
87
|
+
spanId?: string;
|
|
88
|
+
}): void;
|
|
89
|
+
captureCustomMetric(data: CustomMetricData): void;
|
|
90
|
+
captureError(error: Error, metadata?: UnknownRecord): void;
|
|
91
|
+
captureException(error: unknown, metadata?: UnknownRecord): void;
|
|
92
|
+
captureMessage(message: string, metadata?: UnknownRecord): void;
|
|
93
|
+
private attachGlobalListeners;
|
|
31
94
|
private send;
|
|
32
95
|
}
|
|
33
96
|
declare const audit: AuditCore;
|
|
34
97
|
|
|
35
|
-
export { AuditCore, type InitOptions, type RequestMetricData, audit };
|
|
98
|
+
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var s=class{constructor(){this.apiKey="
|
|
1
|
+
var d="https://api.devinspector.com.br/api/ingest/track";var E=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function M(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return E.some(t=>e.includes(t))}function a(r,e=0,t=new WeakSet){if(r==null)return r;if(typeof r=="string")return r.length>1e4?`${r.slice(0,1e4)}...[truncated]`:r;if(typeof r=="number"||typeof r=="boolean")return r;if(typeof r=="bigint")return String(r);if(typeof r=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof r!="object")return String(r);if(t.has(r))return"[Circular]";if(t.add(r),Array.isArray(r))return r.slice(0,100).map(i=>a(i,e+1,t));let s=r,n={};for(let[i,o]of Object.entries(s)){if(M(i)){n[i]="[REDACTED]";continue}n[i]=a(o,e+1,t)}return n}function p(r){if(r)return String(r).trim().toUpperCase()}function m(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function l(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function S(r){return String(r??"").trim().slice(0,200)}function R(r){let e=Number(r);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function c(r){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${r}-${e.randomUUID()}`:`${r}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var u=class{constructor(){this.apiKey="";this.endpoint=d;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||d,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?a(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?a(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),s=new URL(e,t.origin);return s.origin===t.origin&&s.pathname===t.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return c("req")}createTraceId(){return c("trace")}createSpanId(){return c("span")}captureRequest(e){let t=p(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=m(e.statusCode)??0,i=l(e.durationMs)??0,o={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:t,url:s,statusCode:n,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:o})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return;let s=l(e.durationMs)??0,n={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${t}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,t,s={},n={}){let i=S(e);if(!i)return;let o;try{o=R(t)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let s=e?.message?.trim()||"Erro desconhecido",n={...t},i=p(n.method),o=m(n.statusCode??n.status),b=n.requestId?String(n.requestId):void 0,y=n.traceId?String(n.traceId):void 0,w=n.spanId?String(n.spanId):void 0,I=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:I,method:i,statusCode:o,requestId:b,traceId:y,spanId:w,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,t={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,t)}captureMessage(e,t={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...t,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof t=="function"&&t(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let s=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(s,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let s=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let t=a(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(t),keepalive:!0})}catch{}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",h=typeof globalThis<"u"?globalThis:{},g=h[f]||new u;h[f]=g;export{u as AuditCore,g as audit};
|
package/dist/next.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var t in e)p(n,t,{get:e[t],enumerable:!0})},v=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!E.call(n,o)&&o!==t&&p(n,o,{get:()=>e[o],enumerable:!(r=g(e,o))||r.enumerable});return n};var A=n=>v(p({},"__esModule",{value:!0}),n);var M={};b(M,{audit:()=>i,auditFetch:()=>T,captureNextError:()=>h,initNextDevInspector:()=>I,withAuditAction:()=>D,withAuditApi:()=>_});module.exports=A(M);var l=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((r,o)=>{let s=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),t&&t(r,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let r=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(r,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",r=>{this.captureError(r,{type:"uncaught_exception"})}),t.on("unhandledRejection",r=>{let o=r instanceof Error?r:new Error(String(r));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,r=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(r.has(e))return"[Circular Reference]";r.add(e);let o={};for(let[s,c]of Object.entries(e))o[s]=this.truncate(c,t,r);return o}return e}captureError(e,t={}){let r=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let r={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(r)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",R=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[f]||(n[f]=new l),n[f]},i=R();async function w(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&i.isIngestUrl(o))return r(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let a=await r(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(a.status>=400||u>=300)&&i.captureRequest({method:s,url:o,statusCode:a.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a}catch(a){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw i.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i.captureException(a instanceof Error?a:new Error(String(a)),{url:o,method:s,type:t?.errorType||"network_error"}),a}}function I(n){i.init(n)}function h(n,e={}){let t=n instanceof Error?n:new Error(String(n));i.captureError(t,{framework:"nextjs",...e})}async function T(n,e){return w(n,e,{errorType:"nextjs_network_error"})}function _(n){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),r=e[0],o=e[1],s=r?.method||"GET",c=r?.url||r?.nextUrl?.href||"/api",a=typeof r?.headers?.get=="function"?r.headers.get("user-agent")||"":r?.headers?.["user-agent"]||"";try{let u=await n(...e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-t),y=u?.status||o?.statusCode||200;return(y>=400||d>=300)&&i.captureRequest({method:s,url:c,statusCode:y,durationMs:d,route:c,userAgent:a}),u}catch(u){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw i.captureRequest({method:s,url:c,statusCode:500,durationMs:d,route:c,userAgent:a}),h(u,{url:c,method:s,type:"api_route_error"}),u}}}function D(n,e){return(async(...t)=>{let r=typeof performance<"u"?performance.now():Date.now();try{let o=await e(...t),s=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return s>=300&&i.captureRequest({method:"ACTION",url:n,statusCode:200,durationMs:s,route:n}),o}catch(o){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-r);throw i.captureRequest({method:"ACTION",url:n,statusCode:500,durationMs:s,route:n}),h(o,{actionName:n,type:"server_action_error"}),o}})}0&&(module.exports={audit,auditFetch,captureNextError,initNextDevInspector,withAuditAction,withAuditApi});
|
|
1
|
+
"use strict";var g=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var _=(t,e)=>{for(var r in e)g(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of q(e))!D.call(t,n)&&n!==r&&g(t,n,{get:()=>e[n],enumerable:!(s=U(e,n))||s.enumerable});return t};var C=t=>x(g({},"__esModule",{value:!0}),t);var K={};_(K,{audit:()=>a,auditFetch:()=>z,captureNextError:()=>E,initNextDevInspector:()=>L,withAuditAction:()=>G,withAuditApi:()=>$});module.exports=C(K);var M="https://api.devinspector.com.br/api/ingest/track";var N=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function O(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return N.some(r=>e.includes(r))}function h(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(o=>h(o,e+1,r));let s=t,n={};for(let[o,i]of Object.entries(s)){if(O(o)){n[o]="[REDACTED]";continue}n[o]=h(i,e+1,r)}return n}function w(t){if(t)return String(t).trim().toUpperCase()}function T(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function v(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function B(t){return String(t??"").trim().slice(0,200)}function j(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var y=class{constructor(){this.apiKey="";this.endpoint=M;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||M,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?h(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?h(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(e,r.origin);return s.origin===r.origin&&s.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return b("req")}createTraceId(){return b("trace")}createSpanId(){return b("span")}captureRequest(e){let r=w(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=T(e.statusCode)??0,o=v(e.durationMs)??0,i={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:s,statusCode:n,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:i})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let s=v(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,s={},n={}){let o=B(e);if(!o)return;let i;try{i=j(r)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:i,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let s=e?.message?.trim()||"Erro desconhecido",n={...r},o=w(n.method),i=T(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,p=n.spanId?String(n.spanId):void 0,m=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:m,method:o,statusCode:i,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof r=="function"&&r(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let s=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(s,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let s=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=h(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},S="__DEVINSPECT_AUDIT_CORE_INSTANCE__",A=typeof globalThis<"u"?globalThis:{},a=A[S]||new y;A[S]=a;async function k(t,e,r={}){let s=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!s)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),o=w(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return s(t,e);let i=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",i),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let m={...e,headers:p},l=typeof performance<"u"?performance.now():Date.now();try{let c=await s(t,m),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));return(c.status>=400||f>=a.getSlowThresholdMs())&&a.captureRequest({method:o,url:n,statusCode:c.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http",message:`${o} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:f,requestId:i,traceId:u,spanId:d}}),c}catch(c){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));a.captureRequest({method:o,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${o} ${n}`,metadata:{statusCode:0,durationMs:f,requestId:i,traceId:u,spanId:d}});let R=c instanceof Error?c:new Error(String(c));throw a.captureError(R,{url:n,method:o,requestId:i,traceId:u,spanId:d,type:r.errorType||"network_error"}),c}}function L(t){a.init(t)}function E(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{framework:"Next.js",...e})}async function z(t,e){return k(t,e,{errorType:"nextjs_network_error"})}function $(t){return async function(...e){let r=typeof performance<"u"?performance.now():Date.now(),s=e[0],n=e[1],o=s?.method||"GET",i=s?.url||s?.nextUrl?.href||"/api",u=typeof s?.headers?.get=="function"?s.headers.get("user-agent")||"":s?.headers?.["user-agent"]||"",d=I(s,"x-devinspector-request-id")||a.createRequestId(),p=I(s,"x-devinspector-trace-id")||a.createTraceId(),m=I(s,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${o} ${i}`,metadata:{framework:"Next.js",phase:"start",requestId:d,traceId:p,spanId:m}});try{let l=await t(...e),c=Math.round((typeof performance<"u"?performance.now():Date.now())-r),f=l?.status||n?.statusCode||200;return(f>=400||c>=300)&&a.captureRequest({method:o,url:i,statusCode:f,durationMs:c,route:i,userAgent:u,requestId:d,traceId:p,spanId:m}),a.addBreadcrumb({type:"http",message:`${o} ${i}`,metadata:{framework:"Next.js",phase:"complete",statusCode:f,durationMs:c,requestId:d,traceId:p,spanId:m}}),l}catch(l){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-r);throw a.captureRequest({method:o,url:i,statusCode:500,durationMs:c,route:i,userAgent:u,requestId:d,traceId:p,spanId:m}),a.addBreadcrumb({type:"http_error",message:`${o} ${i}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:d,traceId:p,spanId:m}}),E(l,{url:i,method:o,type:"api_route_error",requestId:d,traceId:p,spanId:m}),l}}}function G(t,e){return(async(...r)=>{let s=typeof performance<"u"?performance.now():Date.now(),n=a.createRequestId(),o=a.createTraceId(),i=a.createSpanId();a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"start",requestId:n,traceId:o,spanId:i}});try{let u=await e(...r),d=Math.round((typeof performance<"u"?performance.now():Date.now())-s);return d>=300&&a.captureRequest({method:"ACTION",url:t,statusCode:200,durationMs:d,route:t,requestId:n,traceId:o,spanId:i}),a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"complete",statusCode:200,durationMs:d,requestId:n,traceId:o,spanId:i}}),u}catch(u){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-s);throw a.captureRequest({method:"ACTION",url:t,statusCode:500,durationMs:d,route:t,requestId:n,traceId:o,spanId:i}),a.addBreadcrumb({type:"server_action_error",message:t,metadata:{framework:"Next.js",statusCode:500,durationMs:d,requestId:n,traceId:o,spanId:i}}),E(u,{actionName:t,type:"server_action_error",requestId:n,traceId:o,spanId:i}),u}})}function I(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]||t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}0&&(module.exports={audit,auditFetch,captureNextError,initNextDevInspector,withAuditAction,withAuditApi});
|
package/dist/next.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((n,o)=>{let s=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),t&&t(n,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let o=n instanceof Error?n:new Error(String(n));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(n.has(e))return"[Circular Reference]";n.add(e);let o={};for(let[s,c]of Object.entries(e))o[s]=this.truncate(c,t,n);return o}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(n)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let n=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});n.ok||console.error(`[DevInspector] Erro na API (${n.status}): ${n.statusText}`)}catch(n){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",n)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",w=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[p]||(r[p]=new f),r[p]},a=w();async function h(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof r=="string"?o=r:r instanceof URL?o=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(o=r.url),o&&a.isIngestUrl(o))return n(r,e);let s=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let i=await n(r,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(i.status>=400||u>=300)&&a.captureRequest({method:s,url:o,statusCode:i.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),i}catch(i){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a.captureException(i instanceof Error?i:new Error(String(i)),{url:o,method:s,type:t?.errorType||"network_error"}),i}}function b(r){a.init(r)}function y(r,e={}){let t=r instanceof Error?r:new Error(String(r));a.captureError(t,{framework:"nextjs",...e})}async function v(r,e){return h(r,e,{errorType:"nextjs_network_error"})}function A(r){return async function(...e){let t=typeof performance<"u"?performance.now():Date.now(),n=e[0],o=e[1],s=n?.method||"GET",c=n?.url||n?.nextUrl?.href||"/api",i=typeof n?.headers?.get=="function"?n.headers.get("user-agent")||"":n?.headers?.["user-agent"]||"";try{let u=await r(...e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-t),l=u?.status||o?.statusCode||200;return(l>=400||d>=300)&&a.captureRequest({method:s,url:c,statusCode:l,durationMs:d,route:c,userAgent:i}),u}catch(u){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-t);throw a.captureRequest({method:s,url:c,statusCode:500,durationMs:d,route:c,userAgent:i}),y(u,{url:c,method:s,type:"api_route_error"}),u}}}function R(r,e){return(async(...t)=>{let n=typeof performance<"u"?performance.now():Date.now();try{let o=await e(...t),s=Math.round((typeof performance<"u"?performance.now():Date.now())-n);return s>=300&&a.captureRequest({method:"ACTION",url:r,statusCode:200,durationMs:s,route:r}),o}catch(o){let s=Math.round((typeof performance<"u"?performance.now():Date.now())-n);throw a.captureRequest({method:"ACTION",url:r,statusCode:500,durationMs:s,route:r}),y(o,{actionName:r,type:"server_action_error"}),o}})}export{a as audit,v as auditFetch,y as captureNextError,b as initNextDevInspector,R as withAuditAction,A as withAuditApi};
|
|
1
|
+
var E="https://api.devinspector.com.br/api/ingest/track";var k=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function U(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return k.some(r=>e.includes(r))}function h(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(o=>h(o,e+1,r));let s=t,n={};for(let[o,i]of Object.entries(s)){if(U(o)){n[o]="[REDACTED]";continue}n[o]=h(i,e+1,r)}return n}function b(t){if(t)return String(t).trim().toUpperCase()}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function q(t){return String(t??"").trim().slice(0,200)}function D(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function g(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var w=class{constructor(){this.apiKey="";this.endpoint=E;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||E,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?h(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?h(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(e,r.origin);return s.origin===r.origin&&s.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return g("req")}createTraceId(){return g("trace")}createSpanId(){return g("span")}captureRequest(e){let r=b(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=R(e.statusCode)??0,o=M(e.durationMs)??0,i={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:s,statusCode:n,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:i})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let s=M(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,s={},n={}){let o=q(e);if(!o)return;let i;try{i=D(r)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:i,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let s=e?.message?.trim()||"Erro desconhecido",n={...r},o=b(n.method),i=R(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,p=n.spanId?String(n.spanId):void 0,m=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:m,method:o,statusCode:i,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof r=="function"&&r(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let s=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(s,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let s=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=h(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},T="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=typeof globalThis<"u"?globalThis:{},a=v[T]||new w;v[T]=a;async function S(t,e,r={}){let s=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!s)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),o=b(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return s(t,e);let i=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",i),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let m={...e,headers:p},l=typeof performance<"u"?performance.now():Date.now();try{let c=await s(t,m),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));return(c.status>=400||f>=a.getSlowThresholdMs())&&a.captureRequest({method:o,url:n,statusCode:c.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http",message:`${o} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:f,requestId:i,traceId:u,spanId:d}}),c}catch(c){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));a.captureRequest({method:o,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${o} ${n}`,metadata:{statusCode:0,durationMs:f,requestId:i,traceId:u,spanId:d}});let I=c instanceof Error?c:new Error(String(c));throw a.captureError(I,{url:n,method:o,requestId:i,traceId:u,spanId:d,type:r.errorType||"network_error"}),c}}function N(t){a.init(t)}function A(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{framework:"Next.js",...e})}async function O(t,e){return S(t,e,{errorType:"nextjs_network_error"})}function B(t){return async function(...e){let r=typeof performance<"u"?performance.now():Date.now(),s=e[0],n=e[1],o=s?.method||"GET",i=s?.url||s?.nextUrl?.href||"/api",u=typeof s?.headers?.get=="function"?s.headers.get("user-agent")||"":s?.headers?.["user-agent"]||"",d=y(s,"x-devinspector-request-id")||a.createRequestId(),p=y(s,"x-devinspector-trace-id")||a.createTraceId(),m=y(s,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${o} ${i}`,metadata:{framework:"Next.js",phase:"start",requestId:d,traceId:p,spanId:m}});try{let l=await t(...e),c=Math.round((typeof performance<"u"?performance.now():Date.now())-r),f=l?.status||n?.statusCode||200;return(f>=400||c>=300)&&a.captureRequest({method:o,url:i,statusCode:f,durationMs:c,route:i,userAgent:u,requestId:d,traceId:p,spanId:m}),a.addBreadcrumb({type:"http",message:`${o} ${i}`,metadata:{framework:"Next.js",phase:"complete",statusCode:f,durationMs:c,requestId:d,traceId:p,spanId:m}}),l}catch(l){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-r);throw a.captureRequest({method:o,url:i,statusCode:500,durationMs:c,route:i,userAgent:u,requestId:d,traceId:p,spanId:m}),a.addBreadcrumb({type:"http_error",message:`${o} ${i}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:d,traceId:p,spanId:m}}),A(l,{url:i,method:o,type:"api_route_error",requestId:d,traceId:p,spanId:m}),l}}}function j(t,e){return(async(...r)=>{let s=typeof performance<"u"?performance.now():Date.now(),n=a.createRequestId(),o=a.createTraceId(),i=a.createSpanId();a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"start",requestId:n,traceId:o,spanId:i}});try{let u=await e(...r),d=Math.round((typeof performance<"u"?performance.now():Date.now())-s);return d>=300&&a.captureRequest({method:"ACTION",url:t,statusCode:200,durationMs:d,route:t,requestId:n,traceId:o,spanId:i}),a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"complete",statusCode:200,durationMs:d,requestId:n,traceId:o,spanId:i}}),u}catch(u){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-s);throw a.captureRequest({method:"ACTION",url:t,statusCode:500,durationMs:d,route:t,requestId:n,traceId:o,spanId:i}),a.addBreadcrumb({type:"server_action_error",message:t,metadata:{framework:"Next.js",statusCode:500,durationMs:d,requestId:n,traceId:o,spanId:i}}),A(u,{actionName:t,type:"server_action_error",requestId:n,traceId:o,spanId:i}),u}})}function y(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]||t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}export{a as audit,O as auditFetch,A as captureNextError,N as initNextDevInspector,j as withAuditAction,B as withAuditApi};
|
package/dist/node.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var S=(n,e)=>{for(var r in e)p(n,r,{get:e[r],enumerable:!0})},T=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of A(e))!M.call(n,o)&&o!==r&&p(n,o,{get:()=>e[o],enumerable:!(t=R(e,o))||t.enumerable});return n};var k=n=>T(p({},"__esModule",{value:!0}),n);var Q={};S(Q,{audit:()=>a,auditFetch:()=>D,auditOperation:()=>O,devInspector:()=>_,devInspectorErrorHandler:()=>P});module.exports=k(Q);var m=require("async_hooks");var h=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(r)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((t,o)=>{let s=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),r&&r(t,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let o=t instanceof Error?t:new Error(String(t));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(t.has(e))return"[Circular Reference]";t.add(e);let o={};for(let[s,i]of Object.entries(e))o[s]=this.truncate(i,r,t);return o}return e}captureError(e,r={}){let t=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(e){let r=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",x=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[f]||(n[f]=new h),n[f]},a=x();async function w(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=typeof performance<"u"?performance.now():Date.now();try{let c=await t(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);return(c.status>=400||u>=300)&&a.captureRequest({method:s,url:o,statusCode:c.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);throw a.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(c instanceof Error?c:new Error(String(c)),{url:o,method:s,type:r?.errorType||"network_error"}),c}}var y=new m.AsyncLocalStorage;function C(n){if(!n)return{};let e={...n},r=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let t of r)e[t]&&(e[t]="[REDACTED]");return e}function _(n){a.init(n);let e=n.slowThresholdMs??300,r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,o,s)=>{let i=t.originalUrl||t.url||"";if(i&&a.isIngestUrl(i)||r.some(d=>typeof d=="string"?i.startsWith(d):d.test(i)))return s();let u=performance.now();y.run({req:t,queriesCount:0,slowQueries:0},()=>{o.on("finish",()=>{let d=Math.round(performance.now()-u),l=y.getStore(),g=o.statusCode,b=g>=400,E=d>=e,v=(l?.slowQueries||0)>0;if(b||E||v){let I=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||i;a.captureRequest({method:t.method,url:i,statusCode:g,durationMs:d,userAgent:t.headers?.["user-agent"],route:I,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0})}}),s()})}}async function D(n,e){return w(n,e,{errorType:"node_network_error"})}async function O(n,e,r=300){let t=y.getStore(),o=performance.now();t&&t.queriesCount++;try{let s=await e(),i=performance.now()-o;return i>r&&t&&(t.slowQueries=Math.max(t.slowQueries,Math.round(i)),a.captureMessage(`Slow Query detectada em [${n}]`,{durationMs:Math.round(i),operationName:n,url:t.req?.originalUrl||t.req?.url})),s}catch(s){let i=performance.now()-o;throw a.captureException(s,{operationName:n,durationMs:Math.round(i)}),s}}function P(){return(n,e,r,t)=>{a.captureException(n,{url:e.originalUrl||e.url,method:e.method,headers:C(e.headers)}),t(n)}}0&&(module.exports={audit,auditFetch,auditOperation,devInspector,devInspectorErrorHandler});
|
|
1
|
+
"use strict";var I=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var B=(t,e)=>{for(var n in e)I(t,n,{get:e[n],enumerable:!0})},Q=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of N(e))!O.call(t,s)&&s!==n&&I(t,s,{get:()=>e[s],enumerable:!(r=_(e,s))||r.enumerable});return t};var L=t=>Q(I({},"__esModule",{value:!0}),t);var W={};B(W,{audit:()=>a,auditFetch:()=>F,auditOperation:()=>V,devInspector:()=>H,devInspectorErrorHandler:()=>X});module.exports=L(W);var k=require("async_hooks");var M="https://api.devinspector.com.br/api/ingest/track";var z=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function $(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return z.some(n=>e.includes(n))}function b(t,e=0,n=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(n.has(t))return"[Circular]";if(n.add(t),Array.isArray(t))return t.slice(0,100).map(i=>b(i,e+1,n));let r=t,s={};for(let[i,o]of Object.entries(r)){if($(i)){s[i]="[REDACTED]";continue}s[i]=b(o,e+1,n)}return s}function w(t){if(t)return String(t).trim().toUpperCase()}function S(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function j(t){return String(t??"").trim().slice(0,200)}function P(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function y(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var E=class{constructor(){this.apiKey="";this.endpoint=M;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||M,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?b(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let n={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?b(e.metadata):void 0};this.breadcrumbs.push(n),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let n=new URL(this.endpoint),r=new URL(e,n.origin);return r.origin===n.origin&&r.pathname===n.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return y("req")}createTraceId(){return y("trace")}createSpanId(){return y("span")}captureRequest(e){let n=w(e.method)||"GET",r=String(e.url||"").trim();if(!r)return;let s=S(e.statusCode)??0,i=R(e.durationMs)??0,o={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:n,url:r,statusCode:s,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:o})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return;let r=R(e.durationMs)??0,s={...e.metadata||{},operation:n,collection:e.collection||"Unknown",durationMs:r,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${n}`,stackTrace:"",url:e.url,method:"DB",durationMs:r,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:s})}captureMetric(e,n,r={},s={}){let i=j(e);if(!i)return;let o;try{o=P(n)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:o,requestId:s.requestId,traceId:s.traceId,spanId:s.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,n={}){let r=e?.message?.trim()||"Erro desconhecido",s={...n},i=w(s.method),o=S(s.statusCode??s.status),d=s.requestId?String(s.requestId):void 0,u=s.traceId?String(s.traceId):void 0,p=s.spanId?String(s.spanId):void 0,m=s.url?String(s.url):void 0;delete s.requestId,delete s.traceId,delete s.spanId,delete s.method,delete s.statusCode,delete s.status,this.send({type:"error",message:r,stackTrace:e?.stack||"",url:m,method:i,statusCode:o,requestId:d,traceId:u,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureException(e,n={}){let r=e instanceof Error?e:new Error(String(e));this.captureError(r,n)}captureMessage(e,n={}){let r=String(e||"").trim();r&&this.send({type:"message",message:r,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let n=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((r,s)=>{this.captureError(r,{platform:"react-native",fatal:s}),typeof n=="function"&&n(r,s)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",n=>{let r=n.error instanceof Error?n.error:new Error(n.message||"Erro global");this.captureError(r,{url:n.filename||window.location.href,line:n.lineno,column:n.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",n=>{let r=n.reason instanceof Error?n.reason:new Error(String(n.reason));this.captureError(r,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",n=>{this.captureError(n,{platform:"node"})}),process.on("unhandledRejection",n=>{this.captureException(n,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let n=b(e);try{let r=typeof fetch=="function"?fetch:void 0;if(!r)return;await r(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),keepalive:!0})}catch{}}},v="__DEVINSPECT_AUDIT_CORE_INSTANCE__",T=typeof globalThis<"u"?globalThis:{},a=T[v]||new E;T[v]=a;async function U(t,e,n={}){let r=n.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!r)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let s=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),i=w(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(s&&a.isIngestUrl(s))return r(t,e);let o=a.createRequestId(),d=a.createTraceId(),u=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",u);let m={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let c=await r(t,m),l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));return(c.status>=400||l>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:s,statusCode:c.status,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:d,spanId:u}),a.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{phase:"complete",statusCode:c.status,durationMs:l,requestId:o,traceId:d,spanId:u}}),c}catch(c){let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.captureRequest({method:i,url:s,statusCode:0,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:d,spanId:u}),a.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{statusCode:0,durationMs:l,requestId:o,traceId:d,spanId:u}});let h=c instanceof Error?c:new Error(String(c));throw a.captureError(h,{url:s,method:i,requestId:o,traceId:d,spanId:u,type:n.errorType||"network_error"}),c}}var A=new k.AsyncLocalStorage;function G(t){if(!t)return{};let e={},n=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let[r,s]of Object.entries(t)){let i=r.toLowerCase();e[r]=n.includes(i)?"[REDACTED]":s}return e}function g(t,e){if(!t?.headers)return;let n=e.toLowerCase(),r=t.headers,s=r[n]??r[e];if(Array.isArray(s))return s[0];if(s!=null)return String(s);for(let[i,o]of Object.entries(r))if(i.toLowerCase()===n)return Array.isArray(o)?o[0]:o?String(o):void 0}function K(t,e){return typeof e=="string"?t.startsWith(e):(e.lastIndex=0,e.test(t))}function H(t){a.init(t);let e=t.slowThresholdMs??a.getSlowThresholdMs(),n=t.ignorePaths??["/uploads","/favicon.ico"];return(r,s,i)=>{let o=r.originalUrl||r.url||"";if(o&&a.isIngestUrl(o)||n.some(l=>K(o,l)))return i();let u=typeof performance<"u"?performance.now():Date.now(),p=g(r,"x-devinspector-request-id")||a.createRequestId(),m=g(r,"x-devinspector-trace-id")||a.createTraceId(),f=g(r,"x-devinspector-span-id")||a.createSpanId();r.headers&&(r.headers["x-devinspector-request-id"]=p,r.headers["x-devinspector-trace-id"]=m,r.headers["x-devinspector-span-id"]=f);let c={req:r,queriesCount:0,slowQueries:0,requestId:p,traceId:m,spanId:f};A.run(c,()=>{a.addBreadcrumb({type:"http",message:`${r.method} ${o}`,metadata:{framework:"Node.js",phase:"start",requestId:p,traceId:m,spanId:f}}),s.on("finish",()=>{let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-u)),h=Number(s.statusCode)||500,D=h>=400,q=l>=e,x=c.slowQueries>0,C=r.route?.path?`${r.baseUrl||""}${r.route.path}`:r.baseUrl||o;(D||q||x)&&a.captureRequest({method:r.method||"GET",url:o,statusCode:h,durationMs:l,userAgent:r.headers?.["user-agent"],route:C,dbQueriesCount:c.queriesCount,slowQueryMs:c.slowQueries,requestId:p,traceId:m,spanId:f}),a.addBreadcrumb({type:"http",message:`${r.method} ${o}`,metadata:{framework:"Node.js",phase:"complete",statusCode:h,durationMs:l,requestId:p,traceId:m,spanId:f,dbQueriesCount:c.queriesCount,slowQueryMs:c.slowQueries}})}),i()})}}async function F(t,e){return U(t,e,{errorType:"node_network_error"})}async function V(t,e,n){let r=A.getStore(),s=n??a.getSlowThresholdMs(),i=typeof performance<"u"?performance.now():Date.now();r&&r.queriesCount++;try{let o=await e(),d=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-i));if(d>=s){r&&(r.slowQueries=Math.max(r.slowQueries,d));let u=r?.req?.originalUrl||r?.req?.url||"";a.addBreadcrumb({type:"db_query",message:`Slow Query detectada em [${t}]`,metadata:{operation:t,durationMs:d,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId,url:u}}),a.captureDbQuery({operation:t,collection:"Unknown",durationMs:d,url:u,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId,metadata:{operation:t,operationName:t}})}return o}catch(o){let d=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-i)),u=r?.req?.originalUrl||r?.req?.url||"";throw a.captureDbQuery({operation:t,collection:"Unknown",durationMs:d,url:u,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId,metadata:{operation:t,operationName:t,failed:!0,error:o instanceof Error?o.message:String(o)}}),a.captureException(o instanceof Error?o:new Error(String(o)),{operationName:t,durationMs:d,url:u,method:"DB",requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId}),a.addBreadcrumb({type:"db_query_error",message:`Erro na opera\xE7\xE3o [${t}]`,metadata:{operation:t,operationName:t,durationMs:d,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId}}),o}}function X(){return(t,e,n,r)=>{let s=g(e,"x-devinspector-request-id"),i=g(e,"x-devinspector-trace-id"),o=g(e,"x-devinspector-span-id");a.captureException(t instanceof Error?t:new Error(String(t)),{url:e.originalUrl||e.url,method:e.method,statusCode:n?.statusCode||500,headers:G(e.headers||{}),requestId:s,traceId:i,spanId:o}),a.addBreadcrumb({type:"http_error",message:`${e.method||"HTTP"} ${e.originalUrl||e.url||""}`,metadata:{framework:"Node.js",statusCode:n?.statusCode||500,requestId:s,traceId:i,spanId:o}}),r(t)}}0&&(module.exports={audit,auditFetch,auditOperation,devInspector,devInspectorErrorHandler});
|
package/dist/node.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AsyncLocalStorage as I}from"async_hooks";var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(r)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((t,o)=>{let s=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(s,{type:"react_native_error",isFatal:!!o}),r&&r(t,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let o=t instanceof Error?t:new Error(String(t));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(t.has(e))return"[Circular Reference]";t.add(e);let o={};for(let[s,i]of Object.entries(e))o[s]=this.truncate(i,r,t);return o}return e}captureError(e,r={}){let t=e.message||"Erro Desconhecido",o=e.stack||"",s={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(s)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(e){let r=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new f),n[p]},a=v();async function g(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let s=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=typeof performance<"u"?performance.now():Date.now();try{let c=await t(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);return(c.status>=400||u>=300)&&a.captureRequest({method:s,url:o,statusCode:c.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),c}catch(c){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-i);throw a.captureRequest({method:s,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(c instanceof Error?c:new Error(String(c)),{url:o,method:s,type:r?.errorType||"network_error"}),c}}var h=new I;function R(n){if(!n)return{};let e={...n},r=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let t of r)e[t]&&(e[t]="[REDACTED]");return e}function T(n){a.init(n);let e=n.slowThresholdMs??300,r=n.ignorePaths??["/uploads","/favicon.ico"];return(t,o,s)=>{let i=t.originalUrl||t.url||"";if(i&&a.isIngestUrl(i)||r.some(d=>typeof d=="string"?i.startsWith(d):d.test(i)))return s();let u=performance.now();h.run({req:t,queriesCount:0,slowQueries:0},()=>{o.on("finish",()=>{let d=Math.round(performance.now()-u),l=h.getStore(),y=o.statusCode,w=y>=400,m=d>=e,b=(l?.slowQueries||0)>0;if(w||m||b){let E=t.route?.path?`${t.baseUrl||""}${t.route.path}`:t.baseUrl||i;a.captureRequest({method:t.method,url:i,statusCode:y,durationMs:d,userAgent:t.headers?.["user-agent"],route:E,dbQueriesCount:l?.queriesCount||0,slowQueryMs:l?.slowQueries||0})}}),s()})}}async function k(n,e){return g(n,e,{errorType:"node_network_error"})}async function x(n,e,r=300){let t=h.getStore(),o=performance.now();t&&t.queriesCount++;try{let s=await e(),i=performance.now()-o;return i>r&&t&&(t.slowQueries=Math.max(t.slowQueries,Math.round(i)),a.captureMessage(`Slow Query detectada em [${n}]`,{durationMs:Math.round(i),operationName:n,url:t.req?.originalUrl||t.req?.url})),s}catch(s){let i=performance.now()-o;throw a.captureException(s,{operationName:n,durationMs:Math.round(i)}),s}}function C(){return(n,e,r,t)=>{a.captureException(n,{url:e.originalUrl||e.url,method:e.method,headers:R(e.headers)}),t(n)}}export{a as audit,k as auditFetch,x as auditOperation,T as devInspector,C as devInspectorErrorHandler};
|
|
1
|
+
import{AsyncLocalStorage as O}from"async_hooks";var E="https://api.devinspector.com.br/api/ingest/track";var x=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function C(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return x.some(n=>e.includes(n))}function b(t,e=0,n=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(n.has(t))return"[Circular]";if(n.add(t),Array.isArray(t))return t.slice(0,100).map(i=>b(i,e+1,n));let r=t,s={};for(let[i,o]of Object.entries(r)){if(C(i)){s[i]="[REDACTED]";continue}s[i]=b(o,e+1,n)}return s}function y(t){if(t)return String(t).trim().toUpperCase()}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function S(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function _(t){return String(t??"").trim().slice(0,200)}function N(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function I(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var w=class{constructor(){this.apiKey="";this.endpoint=E;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||E,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?b(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let n={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?b(e.metadata):void 0};this.breadcrumbs.push(n),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let n=new URL(this.endpoint),r=new URL(e,n.origin);return r.origin===n.origin&&r.pathname===n.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return I("req")}createTraceId(){return I("trace")}createSpanId(){return I("span")}captureRequest(e){let n=y(e.method)||"GET",r=String(e.url||"").trim();if(!r)return;let s=M(e.statusCode)??0,i=S(e.durationMs)??0,o={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:n,url:r,statusCode:s,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:o})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return;let r=S(e.durationMs)??0,s={...e.metadata||{},operation:n,collection:e.collection||"Unknown",durationMs:r,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${n}`,stackTrace:"",url:e.url,method:"DB",durationMs:r,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:s})}captureMetric(e,n,r={},s={}){let i=_(e);if(!i)return;let o;try{o=N(n)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:o,requestId:s.requestId,traceId:s.traceId,spanId:s.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,n={}){let r=e?.message?.trim()||"Erro desconhecido",s={...n},i=y(s.method),o=M(s.statusCode??s.status),d=s.requestId?String(s.requestId):void 0,u=s.traceId?String(s.traceId):void 0,p=s.spanId?String(s.spanId):void 0,m=s.url?String(s.url):void 0;delete s.requestId,delete s.traceId,delete s.spanId,delete s.method,delete s.statusCode,delete s.status,this.send({type:"error",message:r,stackTrace:e?.stack||"",url:m,method:i,statusCode:o,requestId:d,traceId:u,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureException(e,n={}){let r=e instanceof Error?e:new Error(String(e));this.captureError(r,n)}captureMessage(e,n={}){let r=String(e||"").trim();r&&this.send({type:"message",message:r,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let n=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((r,s)=>{this.captureError(r,{platform:"react-native",fatal:s}),typeof n=="function"&&n(r,s)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",n=>{let r=n.error instanceof Error?n.error:new Error(n.message||"Erro global");this.captureError(r,{url:n.filename||window.location.href,line:n.lineno,column:n.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",n=>{let r=n.reason instanceof Error?n.reason:new Error(String(n.reason));this.captureError(r,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",n=>{this.captureError(n,{platform:"node"})}),process.on("unhandledRejection",n=>{this.captureException(n,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let n=b(e);try{let r=typeof fetch=="function"?fetch:void 0;if(!r)return;await r(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),keepalive:!0})}catch{}}},R="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=typeof globalThis<"u"?globalThis:{},a=v[R]||new w;v[R]=a;async function T(t,e,n={}){let r=n.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!r)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let s=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),i=y(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(s&&a.isIngestUrl(s))return r(t,e);let o=a.createRequestId(),d=a.createTraceId(),u=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",u);let m={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let c=await r(t,m),l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));return(c.status>=400||l>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:s,statusCode:c.status,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:d,spanId:u}),a.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{phase:"complete",statusCode:c.status,durationMs:l,requestId:o,traceId:d,spanId:u}}),c}catch(c){let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.captureRequest({method:i,url:s,statusCode:0,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:d,spanId:u}),a.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{statusCode:0,durationMs:l,requestId:o,traceId:d,spanId:u}});let h=c instanceof Error?c:new Error(String(c));throw a.captureError(h,{url:s,method:i,requestId:o,traceId:d,spanId:u,type:n.errorType||"network_error"}),c}}var U=new O;function B(t){if(!t)return{};let e={},n=["authorization","cookie","set-cookie","x-api-key","proxy-authorization"];for(let[r,s]of Object.entries(t)){let i=r.toLowerCase();e[r]=n.includes(i)?"[REDACTED]":s}return e}function g(t,e){if(!t?.headers)return;let n=e.toLowerCase(),r=t.headers,s=r[n]??r[e];if(Array.isArray(s))return s[0];if(s!=null)return String(s);for(let[i,o]of Object.entries(r))if(i.toLowerCase()===n)return Array.isArray(o)?o[0]:o?String(o):void 0}function Q(t,e){return typeof e=="string"?t.startsWith(e):(e.lastIndex=0,e.test(t))}function j(t){a.init(t);let e=t.slowThresholdMs??a.getSlowThresholdMs(),n=t.ignorePaths??["/uploads","/favicon.ico"];return(r,s,i)=>{let o=r.originalUrl||r.url||"";if(o&&a.isIngestUrl(o)||n.some(l=>Q(o,l)))return i();let u=typeof performance<"u"?performance.now():Date.now(),p=g(r,"x-devinspector-request-id")||a.createRequestId(),m=g(r,"x-devinspector-trace-id")||a.createTraceId(),f=g(r,"x-devinspector-span-id")||a.createSpanId();r.headers&&(r.headers["x-devinspector-request-id"]=p,r.headers["x-devinspector-trace-id"]=m,r.headers["x-devinspector-span-id"]=f);let c={req:r,queriesCount:0,slowQueries:0,requestId:p,traceId:m,spanId:f};U.run(c,()=>{a.addBreadcrumb({type:"http",message:`${r.method} ${o}`,metadata:{framework:"Node.js",phase:"start",requestId:p,traceId:m,spanId:f}}),s.on("finish",()=>{let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-u)),h=Number(s.statusCode)||500,k=h>=400,A=l>=e,D=c.slowQueries>0,q=r.route?.path?`${r.baseUrl||""}${r.route.path}`:r.baseUrl||o;(k||A||D)&&a.captureRequest({method:r.method||"GET",url:o,statusCode:h,durationMs:l,userAgent:r.headers?.["user-agent"],route:q,dbQueriesCount:c.queriesCount,slowQueryMs:c.slowQueries,requestId:p,traceId:m,spanId:f}),a.addBreadcrumb({type:"http",message:`${r.method} ${o}`,metadata:{framework:"Node.js",phase:"complete",statusCode:h,durationMs:l,requestId:p,traceId:m,spanId:f,dbQueriesCount:c.queriesCount,slowQueryMs:c.slowQueries}})}),i()})}}async function P(t,e){return T(t,e,{errorType:"node_network_error"})}async function G(t,e,n){let r=U.getStore(),s=n??a.getSlowThresholdMs(),i=typeof performance<"u"?performance.now():Date.now();r&&r.queriesCount++;try{let o=await e(),d=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-i));if(d>=s){r&&(r.slowQueries=Math.max(r.slowQueries,d));let u=r?.req?.originalUrl||r?.req?.url||"";a.addBreadcrumb({type:"db_query",message:`Slow Query detectada em [${t}]`,metadata:{operation:t,durationMs:d,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId,url:u}}),a.captureDbQuery({operation:t,collection:"Unknown",durationMs:d,url:u,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId,metadata:{operation:t,operationName:t}})}return o}catch(o){let d=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-i)),u=r?.req?.originalUrl||r?.req?.url||"";throw a.captureDbQuery({operation:t,collection:"Unknown",durationMs:d,url:u,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId,metadata:{operation:t,operationName:t,failed:!0,error:o instanceof Error?o.message:String(o)}}),a.captureException(o instanceof Error?o:new Error(String(o)),{operationName:t,durationMs:d,url:u,method:"DB",requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId}),a.addBreadcrumb({type:"db_query_error",message:`Erro na opera\xE7\xE3o [${t}]`,metadata:{operation:t,operationName:t,durationMs:d,requestId:r?.requestId,traceId:r?.traceId,spanId:r?.spanId}}),o}}function K(){return(t,e,n,r)=>{let s=g(e,"x-devinspector-request-id"),i=g(e,"x-devinspector-trace-id"),o=g(e,"x-devinspector-span-id");a.captureException(t instanceof Error?t:new Error(String(t)),{url:e.originalUrl||e.url,method:e.method,statusCode:n?.statusCode||500,headers:B(e.headers||{}),requestId:s,traceId:i,spanId:o}),a.addBreadcrumb({type:"http_error",message:`${e.method||"HTTP"} ${e.originalUrl||e.url||""}`,metadata:{framework:"Node.js",statusCode:n?.statusCode||500,requestId:s,traceId:i,spanId:o}}),r(t)}}export{a as audit,P as auditFetch,G as auditOperation,j as devInspector,K as devInspectorErrorHandler};
|