@xcodleox/devinspector 8.1.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular.cjs +1 -1
- package/dist/angular.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +28 -9
- package/dist/index.d.ts +28 -9
- 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 +1 -1
- package/dist/svelte.d.ts +1 -1
- 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 +3 -2
package/dist/angular.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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});
|
|
1
|
+
"use strict";var ee=Object.create;var y=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.prototype.hasOwnProperty;var N=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),v=t=>{throw TypeError(t)};var ne=(t,e,r)=>e in t?y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var q=(t,e)=>y(t,"name",{value:e,configurable:!0});var se=(t,e)=>{for(var r in e)y(t,r,{get:e[r],enumerable:!0})},ie=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of te(e))!re.call(t,n)&&n!==r&&y(t,n,{get:()=>e[n],enumerable:!(s=x(e,n))||s.enumerable});return t};var oe=t=>ie(y({},"__esModule",{value:!0}),t);var C=t=>[,,,ee(t?.[N("metadata")]??null)],O=["class","method","getter","setter","accessor","field","value","get","set"],E=t=>t!==void 0&&typeof t!="function"?v("Function expected"):t,ae=(t,e,r,s,n)=>({kind:O[t],name:e,metadata:s,addInitializer:i=>r._?v("Already initialized"):n.push(E(i||null))}),ue=(t,e)=>ne(e,N("metadata"),t[3]),B=(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,h,l,o=e&7,T=!!(e&8),g=!!(e&16),M=o>3?t.length+1:o?T?1:2:0,D=O[o+5],k=o>3&&(t[M-1]=[]),Z=t[M]||(t[M]=[]),f=o&&(!g&&!T&&(n=n.prototype),o<5&&(o>3||!g)&&x(o<4?n:{get[r](){return P(this,i)},set[r](p){return Q(this,i,p)}},r));o?g&&o<4&&q(i,(o>2?"set ":o>1?"get ":"")+r):q(n,r);for(var R=s.length-1;R>=0;R--)h=ae(o,r,d={},t[3],Z),o&&(h.static=T,h.private=g,l=h.access={has:g?p=>de(n,p):p=>r in p},o^3&&(l.get=g?p=>(o^1?P:ce)(p,n,o^4?i:f.get):p=>p[r]),o>2&&(l.set=g?(p,U)=>Q(p,n,U,o^4?i:f.set):(p,U)=>p[r]=U)),u=(0,s[R])(o?o<4?g?i:f[D]:o>4?void 0:{get:f.get,set:f.set}:n,h),d._=1,o^4||u===void 0?E(u)&&(o>4?k.unshift(u):o?g?i=u:f[D]=u:n=u):typeof u!="object"||u===null?v("Object expected"):(E(a=u.get)&&(f.get=a),E(a=u.set)&&(f.set=a),E(a=u.init)&&k.unshift(a));return o||ue(t,n),f&&y(n,r,f),g?o^4?i:f:n};var S=(t,e,r)=>e.has(t)||v("Cannot "+r),de=(t,e)=>Object(e)!==e?v('Cannot use the "in" operator on this value'):t.has(e),P=(t,e,r)=>(S(t,e,"read from private field"),r?r.call(t):e.get(t));var Q=(t,e,r,s)=>(S(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r),ce=(t,e,r)=>(S(t,e,"access private method"),r);var ge={};se(ge,{AuditAngularErrorHandler:()=>w,audit:()=>c,auditInterceptor:()=>he,devInspectorInterceptor:()=>Y});module.exports=oe(ge);var J=require("@angular/core"),W=require("rxjs/operators");var G="https://api.devinspector.com.br/api/ingest/track",z="https://api.devinspector.com.br/api/ingest/apm";var pe=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function me(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return pe.some(r=>e.includes(r))}function b(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]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(i=>b(i,e+1,r));let s=t,n={};for(let[i,a]of Object.entries(s)){if(me(i)){n[i]="[REDACTED]";continue}n[i]=b(a,e+1,r)}return n}finally{r.delete(t)}}function $(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=b(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function F(t){return t&&String(t).trim().toUpperCase()||void 0}function K(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function H(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function le(t){return String(t??"").trim().slice(0,200)}function fe(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)}`}function m(t){return b(t)}var A=class{constructor(){this.apiKey="";this.endpoint=G;this.apmEndpoint=z;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||G,this.apmEndpoint=e.apmEndpoint?.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?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?b(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?b(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>m(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(this.apmEndpoint),n=new URL(e,r.origin),i=n.origin,a=n.pathname.replace(/\/$/,""),u=r.pathname.replace(/\/$/,""),d=s.pathname.replace(/\/$/,"");return i===r.origin&&a===u||i===s.origin&&a===d}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return I("req")}createTraceId(){return I("trace")}createSpanId(){return I("span")}captureRequest(e){let r=F(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=K(e.statusCode)??0,i=H(e.durationMs)??0,a={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({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:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m(a)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=H(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m(n)})}captureMetric(e,r,s={},n={}){let i=le(e);if(!i)return Promise.resolve();let a;try{a=fe(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m({...s,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return 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=F(n.method),a=K(n.statusCode??n.status),u=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...u?{url:u}:{},...i?{method:i}:{},...a!==void 0?{statusCode:a}:{},environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let s=e instanceof Error?e:new Error($(e));return this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,1e4),environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}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}).finally(()=>{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($(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"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let s={id:I("event"),endpoint:e,payload:m(r),resolve:()=>{}};return new Promise(n=>{s.resolve=n,this.sendQueue.push(s),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let s=typeof fetch=="function"?fetch:void 0;if(!s)return;let n=b(r),i,a;try{typeof AbortController<"u"&&(i=new AbortController,a=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:i?.signal};if(u&&(d.keepalive=!0),!(await s(e,d)).ok)return}catch{return}finally{a!==void 0&&clearTimeout(a)}}},j="__DEVINSPECT_AUDIT_CORE_INSTANCE__",X=typeof globalThis<"u"?globalThis:{},c=X[j]||new A;X[j]=c;var V,_;V=[(0,J.Injectable)()];var w=class{handleError(e){let r=e instanceof Error?e:new Error(String(e));c.captureError(r,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""}),console.error("[DevInspector Angular Error]:",e)}};_=C(null),w=L(_,0,"AuditAngularErrorHandler",V,w),B(_,1,w);var Y=(t,e)=>{let r=t.urlWithParams||t.url||"";if(r&&c.isIngestUrl(r))return e(t);let s=c.createRequestId(),n=c.createTraceId(),i=c.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,W.tap)({next:d=>{if(!(d&&typeof d=="object"&&"status"in d&&"clone"in d))return;let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-u)),o=Number(d.status)||0;(o>=400||l>=c.getSlowThresholdMs())&&c.captureRequest({method:t.method||"GET",url:r,statusCode:o,durationMs:l,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),c.addBreadcrumb({type:"http",message:`${t.method||"GET"} ${r} `,metadata:{statusCode:o,durationMs:l,requestId:s,traceId:n,spanId:i}})},error:d=>{let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-u)),l=Number(d?.status)||0;c.captureRequest({method:t.method||"GET",url:r,statusCode:l,durationMs:h,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),c.captureException(new Error(`HTTP Error ${l}: ${d?.message||d?.statusText||"Erro de rede no cliente"} `),{url:r,method:t.method||"GET",status:d?.status,statusText:d?.statusText,type:"angular_network_error",requestId:s,traceId:n,spanId:i}),c.addBreadcrumb({type:"http_error",message:`${t.method||"GET"} ${r} `,metadata:{statusCode:l,durationMs:h,requestId:s,traceId:n,spanId:i,error:d?.message||d?.statusText||"Network Error"}})}}))},he=Y;0&&(module.exports={AuditAngularErrorHandler,audit,auditInterceptor,devInspectorInterceptor});
|
package/dist/angular.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
var J=Object.create;var U=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var x=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),w=t=>{throw TypeError(t)};var Y=(t,e,r)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var q=(t,e)=>U(t,"name",{value:e,configurable:!0});var N=t=>[,,,J(t?.[x("metadata")]??null)],C=["class","method","getter","setter","accessor","field","value","get","set"],y=t=>t!==void 0&&typeof t!="function"?w("Function expected"):t,Z=(t,e,r,s,n)=>({kind:C[t],name:e,metadata:s,addInitializer:i=>r._?w("Already initialized"):n.push(y(i||null))}),ee=(t,e)=>Y(e,x("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},B=(t,e,r,s,n,i)=>{var a,u,d,h,l,o=e&7,I=!!(e&8),g=!!(e&16),T=o>3?t.length+1:o?I?1:2:0,D=C[o+5],k=o>3&&(t[T-1]=[]),V=t[T]||(t[T]=[]),f=o&&(!g&&!I&&(n=n.prototype),o<5&&(o>3||!g)&&W(o<4?n:{get[r](){return P(this,i)},set[r](c){return Q(this,i,c)}},r));o?g&&o<4&&q(i,(o>2?"set ":o>1?"get ":"")+r):q(n,r);for(var M=s.length-1;M>=0;M--)h=Z(o,r,d={},t[3],V),o&&(h.static=I,h.private=g,l=h.access={has:g?c=>te(n,c):c=>r in c},o^3&&(l.get=g?c=>(o^1?P:re)(c,n,o^4?i:f.get):c=>c[r]),o>2&&(l.set=g?(c,R)=>Q(c,n,R,o^4?i:f.set):(c,R)=>c[r]=R)),u=(0,s[M])(o?o<4?g?i:f[D]:o>4?void 0:{get:f.get,set:f.set}:n,h),d._=1,o^4||u===void 0?y(u)&&(o>4?k.unshift(u):o?g?i=u:f[D]=u:n=u):typeof u!="object"||u===null?w("Object expected"):(y(a=u.get)&&(f.get=a),y(a=u.set)&&(f.set=a),y(a=u.init)&&k.unshift(a));return o||ee(t,n),f&&U(n,r,f),g?o^4?i:f:n};var S=(t,e,r)=>e.has(t)||w("Cannot "+r),te=(t,e)=>Object(e)!==e?w('Cannot use the "in" operator on this value'):t.has(e),P=(t,e,r)=>(S(t,e,"read from private field"),r?r.call(t):e.get(t));var Q=(t,e,r,s)=>(S(t,e,"write to private field"),s?s.call(t,r):e.set(t,r),r),re=(t,e,r)=>(S(t,e,"access private method"),r);import{Injectable as ae}from"@angular/core";import{tap as ue}from"rxjs/operators";var L="https://api.devinspector.com.br/api/ingest/track",G="https://api.devinspector.com.br/api/ingest/apm";var ne=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function se(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return ne.some(r=>e.includes(r))}function b(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]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(i=>b(i,e+1,r));let s=t,n={};for(let[i,a]of Object.entries(s)){if(se(i)){n[i]="[REDACTED]";continue}n[i]=b(a,e+1,r)}return n}finally{r.delete(t)}}function z(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=b(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function $(t){return t&&String(t).trim().toUpperCase()||void 0}function F(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 ie(t){return String(t??"").trim().slice(0,200)}function oe(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)}`}function p(t){return b(t)}var A=class{constructor(){this.apiKey="";this.endpoint=L;this.apmEndpoint=G;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||L,this.apmEndpoint=e.apmEndpoint?.trim()||G,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?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?b(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?b(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>p(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(this.apmEndpoint),n=new URL(e,r.origin),i=n.origin,a=n.pathname.replace(/\/$/,""),u=r.pathname.replace(/\/$/,""),d=s.pathname.replace(/\/$/,"");return i===r.origin&&a===u||i===s.origin&&a===d}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}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 Promise.resolve();let n=F(e.statusCode)??0,i=K(e.durationMs)??0,a={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({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:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p(a)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=K(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p(n)})}captureMetric(e,r,s={},n={}){let i=ie(e);if(!i)return Promise.resolve();let a;try{a=oe(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...s,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return 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=F(n.statusCode??n.status),u=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...u?{url:u}:{},...i?{method:i}:{},...a!==void 0?{statusCode:a}:{},environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let s=e instanceof Error?e:new Error(z(e));return this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,1e4),environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}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}).finally(()=>{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(z(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"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let s={id:v("event"),endpoint:e,payload:p(r),resolve:()=>{}};return new Promise(n=>{s.resolve=n,this.sendQueue.push(s),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let s=typeof fetch=="function"?fetch:void 0;if(!s)return;let n=b(r),i,a;try{typeof AbortController<"u"&&(i=new AbortController,a=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:i?.signal};if(u&&(d.keepalive=!0),!(await s(e,d)).ok)return}catch{return}finally{a!==void 0&&clearTimeout(a)}}},H="__DEVINSPECT_AUDIT_CORE_INSTANCE__",j=typeof globalThis<"u"?globalThis:{},m=j[H]||new A;j[H]=m;var X,_;X=[ae()];var E=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)}};_=N(null),E=B(_,0,"AuditAngularErrorHandler",X,E),O(_,1,E);var de=(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(ue({next:d=>{if(!(d&&typeof d=="object"&&"status"in d&&"clone"in d))return;let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-u)),o=Number(d.status)||0;(o>=400||l>=m.getSlowThresholdMs())&&m.captureRequest({method:t.method||"GET",url:r,statusCode:o,durationMs:l,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),m.addBreadcrumb({type:"http",message:`${t.method||"GET"} ${r} `,metadata:{statusCode:o,durationMs:l,requestId:s,traceId:n,spanId:i}})},error:d=>{let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-u)),l=Number(d?.status)||0;m.captureRequest({method:t.method||"GET",url:r,statusCode:l,durationMs:h,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),m.captureException(new Error(`HTTP Error ${l}: ${d?.message||d?.statusText||"Erro de rede no cliente"} `),{url:r,method:t.method||"GET",status:d?.status,statusText:d?.statusText,type:"angular_network_error",requestId:s,traceId:n,spanId:i}),m.addBreadcrumb({type:"http_error",message:`${t.method||"GET"} ${r} `,metadata:{statusCode:l,durationMs:h,requestId:s,traceId:n,spanId:i,error:d?.message||d?.statusText||"Network Error"}})}}))},ge=de;export{E as AuditAngularErrorHandler,m as audit,ge as auditInterceptor,de as devInspectorInterceptor};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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});
|
|
1
|
+
"use strict";var y=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var r in e)y(t,r,{get:e[r],enumerable:!0})},Q=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _(e))!k.call(t,n)&&n!==r&&y(t,n,{get:()=>e[n],enumerable:!(i=D(e,n))||i.enumerable});return t};var C=t=>Q(y({},"__esModule",{value:!0}),t);var x={};P(x,{AuditCore:()=>f,audit:()=>a,coreAuditFetch:()=>S});module.exports=C(x);var I="https://api.devinspector.com.br/api/ingest/track",T="https://api.devinspector.com.br/api/ingest/apm";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 m(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]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(O(s)){n[s]="[REDACTED]";continue}n[s]=m(o,e+1,r)}return n}finally{r.delete(t)}}function w(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(t){return t&&String(t).trim().toUpperCase()||void 0}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function A(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 L(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)}`}function u(t){return m(t)}var f=class{constructor(){this.apiKey="";this.endpoint=I;this.apmEndpoint=T;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||I,this.apmEndpoint=e.apmEndpoint?.trim()||T,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?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?m(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>u(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,r.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),d=r.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return s===r.origin&&o===d||s===i.origin&&o===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return g("req")}createTraceId(){return g("trace")}createSpanId(){return g("span")}captureRequest(e){let r=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=M(e.statusCode)??0,s=A(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:i,statusCode:n,durationMs:s,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(o)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let i=A(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(n)})}captureMetric(e,r,i={},n={}){let s=B(e);if(!s)return Promise.resolve();let o;try{o=L(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:s,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},s=E(n.method),o=M(n.statusCode??n.status),d=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...d?{url:d}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(w(e));return this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,1e4),environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}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?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}).finally(()=>{typeof r=="function"&&r(i,n)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let i=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(i,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let i=r.reason instanceof Error?r.reason:new Error(w(r.reason));this.captureError(i,{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"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let i={id:g("event"),endpoint:e,payload:u(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=m(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let d=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(d&&(c.keepalive=!0),!(await i(e,c)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},R="__DEVINSPECT_AUDIT_CORE_INSTANCE__",U=typeof globalThis<"u"?globalThis:{},a=U[R]||new f;U[R]=a;async function S(t,e,r={}){let i=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),s=E(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return i(t,e);let o=a.createRequestId(),d=a.createTraceId(),c=a.createSpanId(),h=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));h.set("x-devinspector-request-id",o),h.set("x-devinspector-trace-id",d),h.set("x-devinspector-span-id",c);let q={...e,headers:h},v=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,q),l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-v)),b=p.status>=400||l>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:l,requestId:o,traceId:d,spanId:c}}),b&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:c}),p}catch(p){let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-v));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:l,requestId:o,traceId:d,spanId:c}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:c});let b=p instanceof Error?p:new Error(w(p));throw a.captureError(b,{url:n,method:s,type:r.errorType||"network_error"}),p}}0&&(module.exports={AuditCore,audit,coreAuditFetch});
|
package/dist/index.d.cts
CHANGED
|
@@ -14,9 +14,11 @@ interface Breadcrumb {
|
|
|
14
14
|
interface InitOptions {
|
|
15
15
|
apiKey: string;
|
|
16
16
|
endpoint?: string;
|
|
17
|
+
apmEndpoint?: string;
|
|
17
18
|
environment?: string;
|
|
18
19
|
release?: string;
|
|
19
20
|
slowThresholdMs?: number;
|
|
21
|
+
requestTimeoutMs?: number;
|
|
20
22
|
}
|
|
21
23
|
interface RequestMetricData {
|
|
22
24
|
method: string;
|
|
@@ -54,19 +56,26 @@ type AuditEventType = "error" | "message" | "request_metric" | "db_query" | "cus
|
|
|
54
56
|
declare class AuditCore {
|
|
55
57
|
private apiKey;
|
|
56
58
|
private endpoint;
|
|
59
|
+
private apmEndpoint;
|
|
57
60
|
private environment;
|
|
58
61
|
private release?;
|
|
59
62
|
private slowThresholdMs;
|
|
63
|
+
private requestTimeoutMs;
|
|
60
64
|
private user?;
|
|
61
65
|
private breadcrumbs;
|
|
62
66
|
private initialized;
|
|
63
67
|
private listenersAttached;
|
|
68
|
+
private sendQueue;
|
|
69
|
+
private isProcessingQueue;
|
|
70
|
+
private flushResolvers;
|
|
64
71
|
init(options: InitOptions): void;
|
|
65
72
|
getApiKey(): string;
|
|
66
73
|
getEndpoint(): string;
|
|
74
|
+
getApmEndpoint(): string;
|
|
67
75
|
getEnvironment(): string;
|
|
68
76
|
getRelease(): string | undefined;
|
|
69
77
|
getSlowThresholdMs(): number;
|
|
78
|
+
getRequestTimeoutMs(): number;
|
|
70
79
|
isInitialized(): boolean;
|
|
71
80
|
setUser(user?: AuditUser): void;
|
|
72
81
|
getUser(): AuditUser | undefined;
|
|
@@ -79,20 +88,30 @@ declare class AuditCore {
|
|
|
79
88
|
createRequestId(): string;
|
|
80
89
|
createTraceId(): string;
|
|
81
90
|
createSpanId(): string;
|
|
82
|
-
captureRequest(data: RequestMetricData): void
|
|
83
|
-
captureDbQuery(data: DbQueryData): void
|
|
91
|
+
captureRequest(data: RequestMetricData): Promise<void>;
|
|
92
|
+
captureDbQuery(data: DbQueryData): Promise<void>;
|
|
84
93
|
captureMetric(metricName: string, metricValue: number, metadata?: UnknownRecord, contextIds?: {
|
|
85
94
|
requestId?: string;
|
|
86
95
|
traceId?: string;
|
|
87
96
|
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
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
captureCustomMetric(data: CustomMetricData): Promise<void>;
|
|
99
|
+
captureError(error: Error, metadata?: UnknownRecord): Promise<void>;
|
|
100
|
+
captureException(error: unknown, metadata?: UnknownRecord): Promise<void>;
|
|
101
|
+
captureMessage(message: string, metadata?: UnknownRecord): Promise<void>;
|
|
102
|
+
flush(): Promise<void>;
|
|
93
103
|
private attachGlobalListeners;
|
|
94
|
-
private
|
|
104
|
+
private sendError;
|
|
105
|
+
private sendApm;
|
|
106
|
+
private enqueue;
|
|
107
|
+
private processQueue;
|
|
108
|
+
private sendToEndpoint;
|
|
95
109
|
}
|
|
96
110
|
declare const audit: AuditCore;
|
|
111
|
+
declare function coreAuditFetch(input: RequestInfo | URL, init?: RequestInit, options?: {
|
|
112
|
+
errorType?: string;
|
|
113
|
+
defaultUserAgent?: string;
|
|
114
|
+
nativeFetch?: typeof fetch;
|
|
115
|
+
}): Promise<Response>;
|
|
97
116
|
|
|
98
|
-
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit };
|
|
117
|
+
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit, coreAuditFetch };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,9 +14,11 @@ interface Breadcrumb {
|
|
|
14
14
|
interface InitOptions {
|
|
15
15
|
apiKey: string;
|
|
16
16
|
endpoint?: string;
|
|
17
|
+
apmEndpoint?: string;
|
|
17
18
|
environment?: string;
|
|
18
19
|
release?: string;
|
|
19
20
|
slowThresholdMs?: number;
|
|
21
|
+
requestTimeoutMs?: number;
|
|
20
22
|
}
|
|
21
23
|
interface RequestMetricData {
|
|
22
24
|
method: string;
|
|
@@ -54,19 +56,26 @@ type AuditEventType = "error" | "message" | "request_metric" | "db_query" | "cus
|
|
|
54
56
|
declare class AuditCore {
|
|
55
57
|
private apiKey;
|
|
56
58
|
private endpoint;
|
|
59
|
+
private apmEndpoint;
|
|
57
60
|
private environment;
|
|
58
61
|
private release?;
|
|
59
62
|
private slowThresholdMs;
|
|
63
|
+
private requestTimeoutMs;
|
|
60
64
|
private user?;
|
|
61
65
|
private breadcrumbs;
|
|
62
66
|
private initialized;
|
|
63
67
|
private listenersAttached;
|
|
68
|
+
private sendQueue;
|
|
69
|
+
private isProcessingQueue;
|
|
70
|
+
private flushResolvers;
|
|
64
71
|
init(options: InitOptions): void;
|
|
65
72
|
getApiKey(): string;
|
|
66
73
|
getEndpoint(): string;
|
|
74
|
+
getApmEndpoint(): string;
|
|
67
75
|
getEnvironment(): string;
|
|
68
76
|
getRelease(): string | undefined;
|
|
69
77
|
getSlowThresholdMs(): number;
|
|
78
|
+
getRequestTimeoutMs(): number;
|
|
70
79
|
isInitialized(): boolean;
|
|
71
80
|
setUser(user?: AuditUser): void;
|
|
72
81
|
getUser(): AuditUser | undefined;
|
|
@@ -79,20 +88,30 @@ declare class AuditCore {
|
|
|
79
88
|
createRequestId(): string;
|
|
80
89
|
createTraceId(): string;
|
|
81
90
|
createSpanId(): string;
|
|
82
|
-
captureRequest(data: RequestMetricData): void
|
|
83
|
-
captureDbQuery(data: DbQueryData): void
|
|
91
|
+
captureRequest(data: RequestMetricData): Promise<void>;
|
|
92
|
+
captureDbQuery(data: DbQueryData): Promise<void>;
|
|
84
93
|
captureMetric(metricName: string, metricValue: number, metadata?: UnknownRecord, contextIds?: {
|
|
85
94
|
requestId?: string;
|
|
86
95
|
traceId?: string;
|
|
87
96
|
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
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
captureCustomMetric(data: CustomMetricData): Promise<void>;
|
|
99
|
+
captureError(error: Error, metadata?: UnknownRecord): Promise<void>;
|
|
100
|
+
captureException(error: unknown, metadata?: UnknownRecord): Promise<void>;
|
|
101
|
+
captureMessage(message: string, metadata?: UnknownRecord): Promise<void>;
|
|
102
|
+
flush(): Promise<void>;
|
|
93
103
|
private attachGlobalListeners;
|
|
94
|
-
private
|
|
104
|
+
private sendError;
|
|
105
|
+
private sendApm;
|
|
106
|
+
private enqueue;
|
|
107
|
+
private processQueue;
|
|
108
|
+
private sendToEndpoint;
|
|
95
109
|
}
|
|
96
110
|
declare const audit: AuditCore;
|
|
111
|
+
declare function coreAuditFetch(input: RequestInfo | URL, init?: RequestInit, options?: {
|
|
112
|
+
errorType?: string;
|
|
113
|
+
defaultUserAgent?: string;
|
|
114
|
+
nativeFetch?: typeof fetch;
|
|
115
|
+
}): Promise<Response>;
|
|
97
116
|
|
|
98
|
-
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit };
|
|
117
|
+
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit, coreAuditFetch };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
var v="https://api.devinspector.com.br/api/ingest/track",I="https://api.devinspector.com.br/api/ingest/apm";var S=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function q(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return S.some(r=>e.includes(r))}function m(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]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(q(s)){n[s]="[REDACTED]";continue}n[s]=m(o,e+1,r)}return n}finally{r.delete(t)}}function y(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function w(t){return t&&String(t).trim().toUpperCase()||void 0}function T(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 D(t){return String(t??"").trim().slice(0,200)}function _(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function f(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)}`}function u(t){return m(t)}var g=class{constructor(){this.apiKey="";this.endpoint=v;this.apmEndpoint=I;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||v,this.apmEndpoint=e.apmEndpoint?.trim()||I,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?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?m(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>u(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,r.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),a=r.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return s===r.origin&&o===a||s===i.origin&&o===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return f("req")}createTraceId(){return f("trace")}createSpanId(){return f("span")}captureRequest(e){let r=w(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=T(e.statusCode)??0,s=M(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:i,statusCode:n,durationMs:s,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(o)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let i=M(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(n)})}captureMetric(e,r,i={},n={}){let s=D(e);if(!s)return Promise.resolve();let o;try{o=_(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:s,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},s=w(n.method),o=T(n.statusCode??n.status),a=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...a?{url:a}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(y(e));return this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,1e4),environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}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?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}).finally(()=>{typeof r=="function"&&r(i,n)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let i=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(i,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let i=r.reason instanceof Error?r.reason:new Error(y(r.reason));this.captureError(i,{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"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let i={id:f("event"),endpoint:e,payload:u(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=m(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(a&&(c.keepalive=!0),!(await i(e,c)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",R=typeof globalThis<"u"?globalThis:{},d=R[A]||new g;R[A]=d;async function k(t,e,r={}){let i=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),s=w(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&d.isIngestUrl(n))return i(t,e);let o=d.createRequestId(),a=d.createTraceId(),c=d.createSpanId(),h=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));h.set("x-devinspector-request-id",o),h.set("x-devinspector-trace-id",a),h.set("x-devinspector-span-id",c);let U={...e,headers:h},E=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,U),l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-E)),b=p.status>=400||l>=d.getSlowThresholdMs();return d.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:l,requestId:o,traceId:a,spanId:c}}),b&&d.captureRequest({method:s,url:n,statusCode:p.status,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:c}),p}catch(p){let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-E));d.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:l,requestId:o,traceId:a,spanId:c}}),d.captureRequest({method:s,url:n,statusCode:0,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:c});let b=p instanceof Error?p:new Error(y(p));throw d.captureError(b,{url:n,method:s,type:r.errorType||"network_error"}),p}}export{g as AuditCore,d as audit,k as coreAuditFetch};
|
package/dist/next.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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});
|
|
1
|
+
"use strict";var w=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},N=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of x(e))!C.call(t,n)&&n!==r&&w(t,n,{get:()=>e[n],enumerable:!(s=D(e,n))||s.enumerable});return t};var O=t=>N(w({},"__esModule",{value:!0}),t);var K={};P(K,{audit:()=>a,auditFetch:()=>j,captureNextError:()=>M,initNextDevInspector:()=>$,withAuditAction:()=>F,withAuditApi:()=>G});module.exports=O(K);var R="https://api.devinspector.com.br/api/ingest/track",A="https://api.devinspector.com.br/api/ingest/apm";var Q=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function B(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return Q.some(r=>e.includes(r))}function g(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]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(i=>g(i,e+1,r));let s=t,n={};for(let[i,o]of Object.entries(s)){if(B(i)){n[i]="[REDACTED]";continue}n[i]=g(o,e+1,r)}return n}finally{r.delete(t)}}function v(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=g(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function I(t){return t&&String(t).trim().toUpperCase()||void 0}function S(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function U(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function L(t){return String(t??"").trim().slice(0,200)}function z(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)}`}function p(t){return g(t)}var E=class{constructor(){this.apiKey="";this.endpoint=R;this.apmEndpoint=A;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||R,this.apmEndpoint=e.apmEndpoint?.trim()||A,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?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?g(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?g(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>p(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(this.apmEndpoint),n=new URL(e,r.origin),i=n.origin,o=n.pathname.replace(/\/$/,""),d=r.pathname.replace(/\/$/,""),u=s.pathname.replace(/\/$/,"");return i===r.origin&&o===d||i===s.origin&&o===u}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return y("req")}createTraceId(){return y("trace")}createSpanId(){return y("span")}captureRequest(e){let r=I(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=S(e.statusCode)??0,i=U(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({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:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p(o)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=U(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p(n)})}captureMetric(e,r,s={},n={}){let i=L(e);if(!i)return Promise.resolve();let o;try{o=z(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...s,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return 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=I(n.method),o=S(n.statusCode??n.status),d=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...d?{url:d}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let s=e instanceof Error?e:new Error(v(e));return this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,1e4),environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}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}).finally(()=>{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(v(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"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let s={id:y("event"),endpoint:e,payload:p(r),resolve:()=>{}};return new Promise(n=>{s.resolve=n,this.sendQueue.push(s),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let s=typeof fetch=="function"?fetch:void 0;if(!s)return;let n=g(r),i,o;try{typeof AbortController<"u"&&(i=new AbortController,o=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let d=typeof window<"u"&&typeof window.document<"u",u={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:i?.signal};if(d&&(u.keepalive=!0),!(await s(e,u)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},q="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=typeof globalThis<"u"?globalThis:{},a=_[q]||new E;_[q]=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||""),i=I(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return s(t,e);let o=a.createRequestId(),d=a.createTraceId(),u=a.createSpanId(),m=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));m.set("x-devinspector-request-id",o),m.set("x-devinspector-trace-id",d),m.set("x-devinspector-span-id",u);let f={...e,headers:m},h=typeof performance<"u"?performance.now():Date.now();try{let c=await s(t,f),l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),b=c.status>=400||l>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:l,requestId:o,traceId:d,spanId:u}}),b&&a.captureRequest({method:i,url:n,statusCode:c.status,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u}),c}catch(c){let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));a.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:l,requestId:o,traceId:d,spanId:u}}),a.captureRequest({method:i,url:n,statusCode:0,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u});let b=c instanceof Error?c:new Error(v(c));throw a.captureError(b,{url:n,method:i,type:r.errorType||"network_error"}),c}}function $(t){a.init(t)}function M(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{framework:"Next.js",...e})}async function j(t,e){return k(t,e,{errorType:"nextjs_network_error"})}function G(t){return async function(...e){let r=typeof performance<"u"?performance.now():Date.now(),s=e[0],n=e[1],i=s?.method||"GET",o=s?.url||s?.nextUrl?.href||"/api",d=typeof s?.headers?.get=="function"?s.headers.get("user-agent")||"":s?.headers?.["user-agent"]||"",u=T(s,"x-devinspector-request-id")||a.createRequestId(),m=T(s,"x-devinspector-trace-id")||a.createTraceId(),f=T(s,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"start",requestId:u,traceId:m,spanId:f}});try{let h=await t(...e),c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r)),l=Number(h?.status??n?.statusCode??200)||200;return(l>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:o,statusCode:l,durationMs:c,route:o,userAgent:d,requestId:u,traceId:m,spanId:f}),a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"complete",statusCode:l,durationMs:c,requestId:u,traceId:m,spanId:f}}),h}catch(h){let c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r));throw a.captureRequest({method:i,url:o,statusCode:500,durationMs:c,route:o,userAgent:d,requestId:u,traceId:m,spanId:f}),a.addBreadcrumb({type:"http_error",message:`${i} ${o}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:u,traceId:m,spanId:f}}),M(h,{url:o,method:i,type:"api_route_error",requestId:u,traceId:m,spanId:f}),h}}}function F(t,e){return(async(...r)=>{let s=typeof performance<"u"?performance.now():Date.now(),n=a.createRequestId(),i=a.createTraceId(),o=a.createSpanId();a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"start",requestId:n,traceId:i,spanId:o}});try{let d=await e(...r),u=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-s));return u>=a.getSlowThresholdMs()&&a.captureRequest({method:"ACTION",url:t,statusCode:200,durationMs:u,route:t,requestId:n,traceId:i,spanId:o}),a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"complete",statusCode:200,durationMs:u,requestId:n,traceId:i,spanId:o}}),d}catch(d){let u=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-s));throw a.captureRequest({method:"ACTION",url:t,statusCode:500,durationMs:u,route:t,requestId:n,traceId:i,spanId:o}),a.addBreadcrumb({type:"server_action_error",message:t,metadata:{framework:"Next.js",statusCode:500,durationMs:u,requestId:n,traceId:i,spanId:o}}),M(d,{actionName:t,type:"server_action_error",requestId:n,traceId:i,spanId:o}),d}})}function T(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 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};
|
|
1
|
+
var T="https://api.devinspector.com.br/api/ingest/track",M="https://api.devinspector.com.br/api/ingest/apm";var k=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function D(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return k.some(r=>e.includes(r))}function g(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]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(i=>g(i,e+1,r));let s=t,n={};for(let[i,o]of Object.entries(s)){if(D(i)){n[i]="[REDACTED]";continue}n[i]=g(o,e+1,r)}return n}finally{r.delete(t)}}function w(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=g(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function v(t){return t&&String(t).trim().toUpperCase()||void 0}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function A(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function x(t){return String(t??"").trim().slice(0,200)}function C(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)}`}function p(t){return g(t)}var I=class{constructor(){this.apiKey="";this.endpoint=T;this.apmEndpoint=M;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||T,this.apmEndpoint=e.apmEndpoint?.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?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?g(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?g(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>p(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(this.apmEndpoint),n=new URL(e,r.origin),i=n.origin,o=n.pathname.replace(/\/$/,""),d=r.pathname.replace(/\/$/,""),u=s.pathname.replace(/\/$/,"");return i===r.origin&&o===d||i===s.origin&&o===u}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return y("req")}createTraceId(){return y("trace")}createSpanId(){return y("span")}captureRequest(e){let r=v(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=R(e.statusCode)??0,i=A(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({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:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p(o)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=A(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p(n)})}captureMetric(e,r,s={},n={}){let i=x(e);if(!i)return Promise.resolve();let o;try{o=C(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...s,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return 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=v(n.method),o=R(n.statusCode??n.status),d=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...d?{url:d}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let s=e instanceof Error?e:new Error(w(e));return this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,1e4),environment:this.environment,release:this.release,user:p(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:p({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}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}).finally(()=>{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(w(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"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let s={id:y("event"),endpoint:e,payload:p(r),resolve:()=>{}};return new Promise(n=>{s.resolve=n,this.sendQueue.push(s),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let s=typeof fetch=="function"?fetch:void 0;if(!s)return;let n=g(r),i,o;try{typeof AbortController<"u"&&(i=new AbortController,o=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let d=typeof window<"u"&&typeof window.document<"u",u={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:i?.signal};if(d&&(u.keepalive=!0),!(await s(e,u)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},S="__DEVINSPECT_AUDIT_CORE_INSTANCE__",U=typeof globalThis<"u"?globalThis:{},a=U[S]||new I;U[S]=a;async function q(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||""),i=v(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return s(t,e);let o=a.createRequestId(),d=a.createTraceId(),u=a.createSpanId(),m=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));m.set("x-devinspector-request-id",o),m.set("x-devinspector-trace-id",d),m.set("x-devinspector-span-id",u);let f={...e,headers:m},h=typeof performance<"u"?performance.now():Date.now();try{let c=await s(t,f),l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),b=c.status>=400||l>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:l,requestId:o,traceId:d,spanId:u}}),b&&a.captureRequest({method:i,url:n,statusCode:c.status,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u}),c}catch(c){let l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));a.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:l,requestId:o,traceId:d,spanId:u}}),a.captureRequest({method:i,url:n,statusCode:0,durationMs:l,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u});let b=c instanceof Error?c:new Error(w(c));throw a.captureError(b,{url:n,method:i,type:r.errorType||"network_error"}),c}}function O(t){a.init(t)}function _(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{framework:"Next.js",...e})}async function Q(t,e){return q(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],i=s?.method||"GET",o=s?.url||s?.nextUrl?.href||"/api",d=typeof s?.headers?.get=="function"?s.headers.get("user-agent")||"":s?.headers?.["user-agent"]||"",u=E(s,"x-devinspector-request-id")||a.createRequestId(),m=E(s,"x-devinspector-trace-id")||a.createTraceId(),f=E(s,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"start",requestId:u,traceId:m,spanId:f}});try{let h=await t(...e),c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r)),l=Number(h?.status??n?.statusCode??200)||200;return(l>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:o,statusCode:l,durationMs:c,route:o,userAgent:d,requestId:u,traceId:m,spanId:f}),a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"complete",statusCode:l,durationMs:c,requestId:u,traceId:m,spanId:f}}),h}catch(h){let c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r));throw a.captureRequest({method:i,url:o,statusCode:500,durationMs:c,route:o,userAgent:d,requestId:u,traceId:m,spanId:f}),a.addBreadcrumb({type:"http_error",message:`${i} ${o}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:u,traceId:m,spanId:f}}),_(h,{url:o,method:i,type:"api_route_error",requestId:u,traceId:m,spanId:f}),h}}}function L(t,e){return(async(...r)=>{let s=typeof performance<"u"?performance.now():Date.now(),n=a.createRequestId(),i=a.createTraceId(),o=a.createSpanId();a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"start",requestId:n,traceId:i,spanId:o}});try{let d=await e(...r),u=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-s));return u>=a.getSlowThresholdMs()&&a.captureRequest({method:"ACTION",url:t,statusCode:200,durationMs:u,route:t,requestId:n,traceId:i,spanId:o}),a.addBreadcrumb({type:"server_action",message:t,metadata:{framework:"Next.js",phase:"complete",statusCode:200,durationMs:u,requestId:n,traceId:i,spanId:o}}),d}catch(d){let u=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-s));throw a.captureRequest({method:"ACTION",url:t,statusCode:500,durationMs:u,route:t,requestId:n,traceId:i,spanId:o}),a.addBreadcrumb({type:"server_action_error",message:t,metadata:{framework:"Next.js",statusCode:500,durationMs:u,requestId:n,traceId:i,spanId:o}}),_(d,{actionName:t,type:"server_action_error",requestId:n,traceId:i,spanId:o}),d}})}function E(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,Q as auditFetch,_ as captureNextError,O as initNextDevInspector,L as withAuditAction,B as withAuditApi};
|