@xcodleox/devinspector 9.2.3 → 9.3.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 +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +1 -1
- package/dist/next.cjs +1 -1
- package/dist/next.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.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.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.d.cts +4 -7
- package/dist/vue.d.ts +4 -7
- package/dist/vue.js +1 -1
- package/package.json +1 -1
package/dist/angular.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var C=(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 Q(e))!x.call(t,n)&&n!==r&&w(t,n,{get:()=>e[n],enumerable:!(s=P(e,n))||s.enumerable});return t};var O=t=>N(w({},"__esModule",{value:!0}),t);var $={};C($,{AuditAngularErrorHandler:()=>l,audit:()=>a,auditInterceptor:()=>z,devInspectorInterceptor:()=>D});module.exports=O($);var q=require("@angular/core"),y=require("@angular/common/http"),_=require("rxjs/operators");var I="https://api.devinspector.com.br/api/ingest/track",T="https://api.devinspector.com.br/api/ingest/apm";var B=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function H(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return B.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]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(i=>h(i,e+1,r));let s=t,n={};for(let[i,o]of Object.entries(s)){if(H(i)){n[i]="[REDACTED]";continue}n[i]=h(o,e+1,r)}return n}finally{r.delete(t)}}function M(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=h(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function R(t){return t&&String(t).trim().toUpperCase()||void 0}function A(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function E(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function S(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function L(t){return String(t??"").trim().slice(0,200)}function G(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)}`}function d(t){return h(t)}var v=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?h(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?h(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:d(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(/\/$/,""),p=r.pathname.replace(/\/$/,""),u=s.pathname.replace(/\/$/,"");return i===r.origin&&o===p||i===s.origin&&o===u}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return b("req")}createTraceId(){return b("trace")}createSpanId(){return b("span")}captureRequest(e){let r=R(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=A(e.statusCode)??0,i=E(e.durationMs)??0,o=S(e.ip),p={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(p)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=E(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(n)})}captureMetric(e,r,s={},n={}){let i=L(e);if(!i)return Promise.resolve();let o;try{o=G(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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=R(n.method),o=A(n.statusCode??n.status),p=E(n.durationMs),u=S(n.ip),c=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,m=typeof n.requestId=="string"&&n.requestId.trim()||void 0,f=typeof n.traceId=="string"&&n.traceId.trim()||void 0,g=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...c?{url:c}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...p!==void 0?{durationMs:p}:{},...u?{ip:u}:{},...m?{requestId:m}:{},...f?{traceId:f}:{},...g?{spanId:g}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let s=e instanceof Error?e:new Error(M(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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(M(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:b("event"),endpoint:e,payload:d(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=h(r),i,o;try{typeof AbortController<"u"&&(i=new AbortController,o=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let p=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(p&&(u.keepalive=!0),!(await s(e,u)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},U="__DEVINSPECT_AUDIT_CORE_INSTANCE__",k=typeof globalThis<"u"?globalThis:{},a=k[U]||new v;k[U]=a;var l=class{handleError(e){let r=e instanceof Error?e:new Error(String(e));a.captureError(r,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""})}};l.\u0275fac=t=>new(t||l);l.\u0275prov=(0,q.\u0275\u0275defineInjectable)({token:l,factory:l.\u0275fac,providedIn:"root"});var D=(t,e)=>{let r=t.urlWithParams||t.url||"";if(r&&a.isIngestUrl(r))return e(t);let s=a.createRequestId(),n=a.createTraceId(),i=a.createSpanId(),o=t.clone({setHeaders:{"x-devinspector-request-id":s,"x-devinspector-trace-id":n,"x-devinspector-span-id":i}}),p=typeof performance<"u"?performance.now():Date.now();return e(o).pipe((0,_.tap)({next:u=>{if(!(u instanceof y.HttpResponse))return;let c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),m=u.status||0;(m>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:t.method||"GET",url:r,statusCode:m,durationMs:c,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),a.addBreadcrumb({type:"http",message:`${t.method||"GET"} ${r}`,metadata:{statusCode:m,durationMs:c,requestId:s,traceId:n,spanId:i}})},error:u=>{let c=u instanceof y.HttpErrorResponse?u:null,m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),f=c?.status||0,g=c?.message||c?.statusText||"Erro de rede no cliente";a.captureRequest({method:t.method||"GET",url:r,statusCode:f,durationMs:m,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),a.captureException(new Error(`HTTP Error ${f}: ${g}`),{url:r,method:t.method||"GET",statusCode:f,statusText:c?.statusText||"",type:"angular_network_error",requestId:s,traceId:n,spanId:i}),a.addBreadcrumb({type:"http_error",message:`${t.method||"GET"} ${r}`,metadata:{statusCode:f,durationMs:m,requestId:s,traceId:n,spanId:i,error:g}})}}))},z=D;0&&(module.exports={AuditAngularErrorHandler,audit,auditInterceptor,devInspectorInterceptor});
|
|
1
|
+
"use strict";var I=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var H=(t,e)=>{for(var n in e)I(t,n,{get:e[n],enumerable:!0})},V=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of N(e))!B.call(t,r)&&r!==n&&I(t,r,{get:()=>e[r],enumerable:!(s=z(e,r))||s.enumerable});return t};var L=t=>V(I({},"__esModule",{value:!0}),t);var Y={};H(Y,{AuditAngularErrorHandler:()=>m,audit:()=>a,auditInterceptor:()=>W,devInspectorInterceptor:()=>Q});module.exports=L(Y);var C=require("@angular/core"),v=require("@angular/common/http"),O=require("rxjs/operators");var M="9.3.0",$=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),k="https://api.devinspector.com.br/api/ingest/track",R="https://api.devinspector.com.br/api/ingest/apm",S=50,b=1e4,j=6,U=1e4,F=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function G(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return F.some(n=>e.includes(n))}function h(t,e=0,n=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>b?`${t.slice(0,b)}...[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>=j)return"[MaxDepth]";if(typeof t!="object")return String(t);if(n.has(t))return"[Circular]";n.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(i=>h(i,e+1,n));let s=t,r={};for(let[i,o]of Object.entries(s)){if(G(i)){r[i]="[REDACTED]";continue}r[i]=h(o,e+1,n)}return r}finally{n.delete(t)}}function q(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=h(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function A(t){return t&&String(t).trim().toUpperCase()||void 0}function D(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function w(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function P(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function K(t){return String(t??"").trim().slice(0,200)}function X(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function E(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function J(t){let e=E(t,50);if(e&&$.has(e))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 d(t){return h(t)}var T=class{constructor(){this.apiKey="";this.endpoint=k;this.apmEndpoint=R;this.environment="production";this.sdkVersion=M;this.slowThresholdMs=300;this.requestTimeoutMs=U;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()||k,this.apmEndpoint=e.apmEndpoint?.trim()||R,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=J(e.technology),this.installationId=E(e.installationId,200),this.sdkVersion=E(e.sdkVersion,100)||M,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):U,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}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?h(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let n={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,b),metadata:e.metadata?h(e.metadata):void 0};this.breadcrumbs.push(n),this.breadcrumbs.length>S&&(this.breadcrumbs=this.breadcrumbs.slice(-S))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:d(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let n=new URL(this.endpoint),s=new URL(this.apmEndpoint),r=new URL(e,n.origin),i=r.origin,o=r.pathname.replace(/\/$/,""),p=n.pathname.replace(/\/$/,""),u=s.pathname.replace(/\/$/,"");return i===n.origin&&o===p||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 n=A(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let r=D(e.statusCode)??0,i=w(e.durationMs)??0,o=P(e.ip),p={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:n,url:s,statusCode:r,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(p)})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return Promise.resolve();let s=w(e.durationMs)??0,r={...e.metadata||{},operation:n,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${n}`,url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(r)})}captureMetric(e,n,s={},r={}){let i=K(e);if(!i)return Promise.resolve();let o;try{o=X(n)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:o,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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,n={}){let s=e?.message?.trim()||"Erro desconhecido",r={...n},i=A(r.method),o=D(r.statusCode??r.status),p=w(r.durationMs),u=P(r.ip),c=r.url!==void 0&&r.url!==null?String(r.url).trim():void 0,l=typeof r.requestId=="string"&&r.requestId.trim()||void 0,f=typeof r.traceId=="string"&&r.traceId.trim()||void 0,g=typeof r.spanId=="string"&&r.spanId.trim()||void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.requestId,delete r.traceId,delete r.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...c?{url:c}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...p!==void 0?{durationMs:p}:{},...u?{ip:u}:{},...l?{requestId:l}:{},...f?{traceId:f}:{},...g?{spanId:g}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let s=e instanceof Error?e:new Error(q(e));return this.captureError(s,n)}captureMessage(e,n={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,b),environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,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()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},sdkVersion:this.sdkVersion}}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let n=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,r)=>{this.captureError(s,{platform:"react-native",fatal:r}).finally(()=>{typeof n=="function"&&n(s,r)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",n=>{let s=n.error instanceof Error?n.error:new Error(n.message||"Erro global");this.captureError(s,{url:n.filename||window.location.href,line:n.lineno,column:n.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",n=>{let s=n.reason instanceof Error?n.reason:new Error(q(n.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",n=>{this.captureError(n,{platform:"node"})}),process.on("unhandledRejection",n=>{this.captureException(n,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,n){if(!this.initialized||!this.apiKey)return Promise.resolve();let s=y("event"),r={...n,...this.getIntegrationContext(),eventId:s},i={id:s,endpoint:e,payload:d(r),resolve:()=>{}};return new Promise(o=>{i.resolve=o,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 n of e)n()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,n){let s=typeof fetch=="function"?fetch:void 0;if(!s)return;let r=h(n),i,o;try{typeof AbortController<"u"&&(i=new AbortController,o=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let p=typeof window<"u"&&typeof window.document<"u",u={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:i?.signal};if(p&&(u.keepalive=!0),!(await s(e,u)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},x="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=typeof globalThis<"u"?globalThis:{},a=_[x]||new T;_[x]=a;var m=class{handleError(e){let n=e instanceof Error?e:new Error(String(e));a.captureError(n,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""})}};m.\u0275fac=t=>new(t||m);m.\u0275prov=(0,C.\u0275\u0275defineInjectable)({token:m,factory:m.\u0275fac,providedIn:"root"});var Q=(t,e)=>{let n=t.urlWithParams||t.url||"";if(n&&a.isIngestUrl(n))return e(t);let s=a.createRequestId(),r=a.createTraceId(),i=a.createSpanId(),o=t.clone({setHeaders:{"x-devinspector-request-id":s,"x-devinspector-trace-id":r,"x-devinspector-span-id":i}}),p=typeof performance<"u"?performance.now():Date.now();return e(o).pipe((0,O.tap)({next:u=>{if(!(u instanceof v.HttpResponse))return;let c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),l=u.status||0;(l>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:t.method||"GET",url:n,statusCode:l,durationMs:c,route:t.url,requestId:s,traceId:r,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),a.addBreadcrumb({type:"http",message:`${t.method||"GET"} ${n}`,metadata:{statusCode:l,durationMs:c,requestId:s,traceId:r,spanId:i}})},error:u=>{let c=u instanceof v.HttpErrorResponse?u:null,l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),f=c?.status||0,g=c?.message||c?.statusText||"Erro de rede no cliente";a.captureRequest({method:t.method||"GET",url:n,statusCode:f,durationMs:l,route:t.url,requestId:s,traceId:r,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),a.captureException(new Error(`HTTP Error ${f}: ${g}`),{url:n,method:t.method||"GET",statusCode:f,statusText:c?.statusText||"",type:"angular_network_error",requestId:s,traceId:r,spanId:i}),a.addBreadcrumb({type:"http_error",message:`${t.method||"GET"} ${n}`,metadata:{statusCode:f,durationMs:l,requestId:s,traceId:r,spanId:i,error:g}})}}))},W=Q;0&&(module.exports={AuditAngularErrorHandler,audit,auditInterceptor,devInspectorInterceptor});
|
package/dist/angular.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{\u0275\u0275defineInjectable as D}from"@angular/core";import{HttpResponse as P,HttpErrorResponse as Q}from"@angular/common/http";import{tap as x}from"rxjs/operators";var E="https://api.devinspector.com.br/api/ingest/track",v="https://api.devinspector.com.br/api/ingest/apm";var U=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function k(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return U.some(r=>e.includes(r))}function f(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=>f(i,e+1,r));let s=t,n={};for(let[i,o]of Object.entries(s)){if(k(i)){n[i]="[REDACTED]";continue}n[i]=f(o,e+1,r)}return n}finally{r.delete(t)}}function I(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=f(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function T(t){return t&&String(t).trim().toUpperCase()||void 0}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function y(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function R(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function q(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 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)}`}function u(t){return f(t)}var w=class{constructor(){this.apiKey="";this.endpoint=E;this.apmEndpoint=v;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()||E,this.apmEndpoint=e.apmEndpoint?.trim()||v,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?f(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?f(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),s=new URL(this.apmEndpoint),n=new URL(e,r.origin),i=n.origin,o=n.pathname.replace(/\/$/,""),p=r.pathname.replace(/\/$/,""),a=s.pathname.replace(/\/$/,"");return i===r.origin&&o===p||i===s.origin&&o===a}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return b("req")}createTraceId(){return b("trace")}createSpanId(){return b("span")}captureRequest(e){let r=T(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=M(e.statusCode)??0,i=y(e.durationMs)??0,o=R(e.ip),p={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(p)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=y(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(n)})}captureMetric(e,r,s={},n={}){let i=q(e);if(!i)return Promise.resolve();let o;try{o=_(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...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=T(n.method),o=M(n.statusCode??n.status),p=y(n.durationMs),a=R(n.ip),c=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,m=typeof n.requestId=="string"&&n.requestId.trim()||void 0,l=typeof n.traceId=="string"&&n.traceId.trim()||void 0,g=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...c?{url:c}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...p!==void 0?{durationMs:p}:{},...a?{ip:a}:{},...m?{requestId:m}:{},...l?{traceId:l}:{},...g?{spanId:g}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let s=e instanceof Error?e:new Error(I(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: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?.((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(I(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:b("event"),endpoint:e,payload:u(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=f(r),i,o;try{typeof AbortController<"u"&&(i=new AbortController,o=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let p=typeof window<"u"&&typeof window.document<"u",a={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:i?.signal};if(p&&(a.keepalive=!0),!(await s(e,a)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",S=typeof globalThis<"u"?globalThis:{},d=S[A]||new w;S[A]=d;var h=class{handleError(e){let r=e instanceof Error?e:new Error(String(e));d.captureError(r,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""})}};h.\u0275fac=t=>new(t||h);h.\u0275prov=D({token:h,factory:h.\u0275fac,providedIn:"root"});var C=(t,e)=>{let r=t.urlWithParams||t.url||"";if(r&&d.isIngestUrl(r))return e(t);let s=d.createRequestId(),n=d.createTraceId(),i=d.createSpanId(),o=t.clone({setHeaders:{"x-devinspector-request-id":s,"x-devinspector-trace-id":n,"x-devinspector-span-id":i}}),p=typeof performance<"u"?performance.now():Date.now();return e(o).pipe(x({next:a=>{if(!(a instanceof P))return;let c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),m=a.status||0;(m>=400||c>=d.getSlowThresholdMs())&&d.captureRequest({method:t.method||"GET",url:r,statusCode:m,durationMs:c,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),d.addBreadcrumb({type:"http",message:`${t.method||"GET"} ${r}`,metadata:{statusCode:m,durationMs:c,requestId:s,traceId:n,spanId:i}})},error:a=>{let c=a instanceof Q?a:null,m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),l=c?.status||0,g=c?.message||c?.statusText||"Erro de rede no cliente";d.captureRequest({method:t.method||"GET",url:r,statusCode:l,durationMs:m,route:t.url,requestId:s,traceId:n,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),d.captureException(new Error(`HTTP Error ${l}: ${g}`),{url:r,method:t.method||"GET",statusCode:l,statusText:c?.statusText||"",type:"angular_network_error",requestId:s,traceId:n,spanId:i}),d.addBreadcrumb({type:"http_error",message:`${t.method||"GET"} ${r}`,metadata:{statusCode:l,durationMs:m,requestId:s,traceId:n,spanId:i,error:g}})}}))},j=C;export{h as AuditAngularErrorHandler,d as audit,j as auditInterceptor,C as devInspectorInterceptor};
|
|
1
|
+
import{\u0275\u0275defineInjectable as B}from"@angular/core";import{HttpResponse as H,HttpErrorResponse as V}from"@angular/common/http";import{tap as L}from"rxjs/operators";var E="9.3.0",x=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),T="https://api.devinspector.com.br/api/ingest/track",M="https://api.devinspector.com.br/api/ingest/apm",k=50,b=1e4,_=6,R=1e4,C=["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 C.some(n=>e.includes(n))}function f(t,e=0,n=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>b?`${t.slice(0,b)}...[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>=_)return"[MaxDepth]";if(typeof t!="object")return String(t);if(n.has(t))return"[Circular]";n.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(i=>f(i,e+1,n));let s=t,r={};for(let[i,o]of Object.entries(s)){if(O(i)){r[i]="[REDACTED]";continue}r[i]=f(o,e+1,n)}return r}finally{n.delete(t)}}function S(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=f(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function U(t){return t&&String(t).trim().toUpperCase()||void 0}function q(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 A(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function Q(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 I(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function N(t){let e=I(t,50);if(e&&x.has(e))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 u(t){return f(t)}var w=class{constructor(){this.apiKey="";this.endpoint=T;this.apmEndpoint=M;this.environment="production";this.sdkVersion=E;this.slowThresholdMs=300;this.requestTimeoutMs=R;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.technology=N(e.technology),this.installationId=I(e.installationId,200),this.sdkVersion=I(e.sdkVersion,100)||E,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):R,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}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?f(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let n={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,b),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(n),this.breadcrumbs.length>k&&(this.breadcrumbs=this.breadcrumbs.slice(-k))}getBreadcrumbs(){return this.breadcrumbs.map(e=>u(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:u(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let n=new URL(this.endpoint),s=new URL(this.apmEndpoint),r=new URL(e,n.origin),i=r.origin,o=r.pathname.replace(/\/$/,""),p=n.pathname.replace(/\/$/,""),a=s.pathname.replace(/\/$/,"");return i===n.origin&&o===p||i===s.origin&&o===a}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 n=U(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let r=q(e.statusCode)??0,i=v(e.durationMs)??0,o=A(e.ip),p={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:n,url:s,statusCode:r,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(p)})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return Promise.resolve();let s=v(e.durationMs)??0,r={...e.metadata||{},operation:n,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${n}`,url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(r)})}captureMetric(e,n,s={},r={}){let i=Q(e);if(!i)return Promise.resolve();let o;try{o=z(n)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:o,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...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,n={}){let s=e?.message?.trim()||"Erro desconhecido",r={...n},i=U(r.method),o=q(r.statusCode??r.status),p=v(r.durationMs),a=A(r.ip),c=r.url!==void 0&&r.url!==null?String(r.url).trim():void 0,l=typeof r.requestId=="string"&&r.requestId.trim()||void 0,m=typeof r.traceId=="string"&&r.traceId.trim()||void 0,g=typeof r.spanId=="string"&&r.spanId.trim()||void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.requestId,delete r.traceId,delete r.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...c?{url:c}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...p!==void 0?{durationMs:p}:{},...a?{ip:a}:{},...l?{requestId:l}:{},...m?{traceId:m}:{},...g?{spanId:g}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let s=e instanceof Error?e:new Error(S(e));return this.captureError(s,n)}captureMessage(e,n={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,b),environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...n,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()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},sdkVersion:this.sdkVersion}}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let n=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,r)=>{this.captureError(s,{platform:"react-native",fatal:r}).finally(()=>{typeof n=="function"&&n(s,r)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",n=>{let s=n.error instanceof Error?n.error:new Error(n.message||"Erro global");this.captureError(s,{url:n.filename||window.location.href,line:n.lineno,column:n.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",n=>{let s=n.reason instanceof Error?n.reason:new Error(S(n.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",n=>{this.captureError(n,{platform:"node"})}),process.on("unhandledRejection",n=>{this.captureException(n,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,n){if(!this.initialized||!this.apiKey)return Promise.resolve();let s=y("event"),r={...n,...this.getIntegrationContext(),eventId:s},i={id:s,endpoint:e,payload:u(r),resolve:()=>{}};return new Promise(o=>{i.resolve=o,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 n of e)n()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,n){let s=typeof fetch=="function"?fetch:void 0;if(!s)return;let r=f(n),i,o;try{typeof AbortController<"u"&&(i=new AbortController,o=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let p=typeof window<"u"&&typeof window.document<"u",a={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:i?.signal};if(p&&(a.keepalive=!0),!(await s(e,a)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},D="__DEVINSPECT_AUDIT_CORE_INSTANCE__",P=typeof globalThis<"u"?globalThis:{},d=P[D]||new w;P[D]=d;var h=class{handleError(e){let n=e instanceof Error?e:new Error(String(e));d.captureError(n,{framework:"Angular",platform:typeof window<"u"?"browser":"server",url:typeof window<"u"?window.location.href:""})}};h.\u0275fac=t=>new(t||h);h.\u0275prov=B({token:h,factory:h.\u0275fac,providedIn:"root"});var $=(t,e)=>{let n=t.urlWithParams||t.url||"";if(n&&d.isIngestUrl(n))return e(t);let s=d.createRequestId(),r=d.createTraceId(),i=d.createSpanId(),o=t.clone({setHeaders:{"x-devinspector-request-id":s,"x-devinspector-trace-id":r,"x-devinspector-span-id":i}}),p=typeof performance<"u"?performance.now():Date.now();return e(o).pipe(L({next:a=>{if(!(a instanceof H))return;let c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),l=a.status||0;(l>=400||c>=d.getSlowThresholdMs())&&d.captureRequest({method:t.method||"GET",url:n,statusCode:l,durationMs:c,route:t.url,requestId:s,traceId:r,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),d.addBreadcrumb({type:"http",message:`${t.method||"GET"} ${n}`,metadata:{statusCode:l,durationMs:c,requestId:s,traceId:r,spanId:i}})},error:a=>{let c=a instanceof V?a:null,l=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-p)),m=c?.status||0,g=c?.message||c?.statusText||"Erro de rede no cliente";d.captureRequest({method:t.method||"GET",url:n,statusCode:m,durationMs:l,route:t.url,requestId:s,traceId:r,spanId:i,userAgent:typeof navigator<"u"?navigator.userAgent:void 0}),d.captureException(new Error(`HTTP Error ${m}: ${g}`),{url:n,method:t.method||"GET",statusCode:m,statusText:c?.statusText||"",type:"angular_network_error",requestId:s,traceId:r,spanId:i}),d.addBreadcrumb({type:"http_error",message:`${t.method||"GET"} ${n}`,metadata:{statusCode:m,durationMs:l,requestId:s,traceId:r,spanId:i,error:g}})}}))},te=$;export{h as AuditAngularErrorHandler,d as audit,te as auditInterceptor,$ as devInspectorInterceptor};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var Q=(t,e)=>{for(var r in e)E(t,r,{get:e[r],enumerable:!0})},C=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of k(e))!P.call(t,n)&&n!==r&&E(t,n,{get:()=>e[n],enumerable:!(i=_(e,n))||i.enumerable});return t};var N=t=>C(E({},"__esModule",{value:!0}),t);var z={};Q(z,{AuditCore:()=>g,audit:()=>c,coreAuditFetch:()=>D});module.exports=N(z);var M="https://api.devinspector.com.br/api/ingest/track",A="https://api.devinspector.com.br/api/ingest/apm";var O=["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 O.some(r=>e.includes(r))}function l(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=>l(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(B(s)){n[s]="[REDACTED]";continue}n[s]=l(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=l(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function T(t){return t&&String(t).trim().toUpperCase()||void 0}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function I(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function U(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function L(t){return String(t??"").trim().slice(0,200)}function x(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 d(t){return l(t)}var g=class{constructor(){this.apiKey="";this.endpoint=M;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()||M,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?l(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?l(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:d(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(/\/$/,""),u=r.pathname.replace(/\/$/,""),a=i.pathname.replace(/\/$/,"");return s===r.origin&&o===u||s===i.origin&&o===a}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=T(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=R(e.statusCode)??0,s=I(e.durationMs)??0,o=U(e.ip),u={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:i,statusCode:n,durationMs:s,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(u)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let i=I(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(n)})}captureMetric(e,r,i={},n={}){let s=L(e);if(!s)return Promise.resolve();let o;try{o=x(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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=T(n.method),o=R(n.statusCode??n.status),u=I(n.durationMs),a=U(n.ip),m=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,b=typeof n.requestId=="string"&&n.requestId.trim()||void 0,h=typeof n.traceId=="string"&&n.traceId.trim()||void 0,p=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...m?{url:m}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...u!==void 0?{durationMs:u}:{},...a?{ip:a}:{},...b?{requestId:b}:{},...h?{traceId:h}:{},...p?{spanId:p}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(v(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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(v(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:y("event"),endpoint:e,payload:d(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=l(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",a={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(u&&(a.keepalive=!0),!(await i(e,a)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},S="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=typeof globalThis<"u"?globalThis:{},c=q[S]||new g;q[S]=c;async function D(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=T(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&c.isIngestUrl(n))return i(t,e);let o=c.createRequestId(),u=c.createTraceId(),a=c.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",u),m.set("x-devinspector-span-id",a);let b={...e,headers:m},h=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,b),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),w=p.status>=400||f>=c.getSlowThresholdMs();return c.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:f,requestId:o,traceId:u,spanId:a}}),w&&c.captureRequest({method:s,url:n,statusCode:p.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:a}),p}catch(p){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));c.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:u,spanId:a}}),c.captureRequest({method:s,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:a});let w=p instanceof Error?p:new Error(v(p));throw c.captureError(w,{url:n,method:s,type:r.errorType||"network_error",requestId:o,traceId:u,spanId:a}),p}}0&&(module.exports={AuditCore,audit,coreAuditFetch});
|
|
1
|
+
"use strict";var E=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var z=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},V=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of x(e))!N.call(t,r)&&r!==n&&E(t,r,{get:()=>e[r],enumerable:!(i=Q(e,r))||i.enumerable});return t};var B=t=>V(E({},"__esModule",{value:!0}),t);var X={};z(X,{AuditCore:()=>g,DEVINSPECTOR_SDK_VERSION:()=>I,audit:()=>c,coreAuditFetch:()=>_});module.exports=B(X);var I="9.3.0",L=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),k="https://api.devinspector.com.br/api/ingest/track",D="https://api.devinspector.com.br/api/ingest/apm",U=50,v=1e4,j=6,q=1e4,K=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function F(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return K.some(n=>e.includes(n))}function m(t,e=0,n=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>v?`${t.slice(0,v)}...[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>=j)return"[MaxDepth]";if(typeof t!="object")return String(t);if(n.has(t))return"[Circular]";n.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,n));let i=t,r={};for(let[s,o]of Object.entries(i)){if(F(s)){r[s]="[REDACTED]";continue}r[s]=m(o,e+1,n)}return r}finally{n.delete(t)}}function M(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 S(t){return t&&String(t).trim().toUpperCase()||void 0}function A(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function T(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function P(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function $(t){return String(t??"").trim().slice(0,200)}function G(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function R(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function H(t){let e=R(t,50);if(e&&L.has(e))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)}`}function d(t){return m(t)}var g=class{constructor(){this.apiKey="";this.endpoint=k;this.apmEndpoint=D;this.environment="production";this.sdkVersion=I;this.slowThresholdMs=300;this.requestTimeoutMs=q;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()||k,this.apmEndpoint=e.apmEndpoint?.trim()||D,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=H(e.technology),this.installationId=R(e.installationId,200),this.sdkVersion=R(e.sdkVersion,100)||I,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):q,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}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}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 n={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,v),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(n),this.breadcrumbs.length>U&&(this.breadcrumbs=this.breadcrumbs.slice(-U))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:d(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let n=new URL(this.endpoint),i=new URL(this.apmEndpoint),r=new URL(e,n.origin),s=r.origin,o=r.pathname.replace(/\/$/,""),a=n.pathname.replace(/\/$/,""),u=i.pathname.replace(/\/$/,"");return s===n.origin&&o===a||s===i.origin&&o===u}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return b("req")}createTraceId(){return b("trace")}createSpanId(){return b("span")}captureRequest(e){let n=S(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=A(e.statusCode)??0,s=T(e.durationMs)??0,o=P(e.ip),a={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:n,url:i,statusCode:r,durationMs:s,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(a)})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return Promise.resolve();let i=T(e.durationMs)??0,r={...e.metadata||{},operation:n,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${n}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(r)})}captureMetric(e,n,i={},r={}){let s=$(e);if(!s)return Promise.resolve();let o;try{o=G(n)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:s,metricValue:o,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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,n={}){let i=e?.message?.trim()||"Erro desconhecido",r={...n},s=S(r.method),o=A(r.statusCode??r.status),a=T(r.durationMs),u=P(r.ip),p=r.url!==void 0&&r.url!==null?String(r.url).trim():void 0,y=typeof r.requestId=="string"&&r.requestId.trim()||void 0,f=typeof r.traceId=="string"&&r.traceId.trim()||void 0,l=typeof r.spanId=="string"&&r.spanId.trim()||void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.requestId,delete r.traceId,delete r.spanId,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...p?{url:p}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...a!==void 0?{durationMs:a}:{},...u?{ip:u}:{},...y?{requestId:y}:{},...f?{traceId:f}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let i=e instanceof Error?e:new Error(M(e));return this.captureError(i,n)}captureMessage(e,n={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,v),environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,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()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},sdkVersion:this.sdkVersion}}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let n=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,r)=>{this.captureError(i,{platform:"react-native",fatal:r}).finally(()=>{typeof n=="function"&&n(i,r)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",n=>{let i=n.error instanceof Error?n.error:new Error(n.message||"Erro global");this.captureError(i,{url:n.filename||window.location.href,line:n.lineno,column:n.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",n=>{let i=n.reason instanceof Error?n.reason:new Error(M(n.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",n=>{this.captureError(n,{platform:"node"})}),process.on("unhandledRejection",n=>{this.captureException(n,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,n){if(!this.initialized||!this.apiKey)return Promise.resolve();let i=b("event"),r={...n,...this.getIntegrationContext(),eventId:i},s={id:i,endpoint:e,payload:d(r),resolve:()=>{}};return new Promise(o=>{s.resolve=o,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 n of e)n()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,n){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let r=m(n),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",u={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};if(a&&(u.keepalive=!0),!(await i(e,u)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},C="__DEVINSPECT_AUDIT_CORE_INSTANCE__",O=typeof globalThis<"u"?globalThis:{},c=O[C]||new g;O[C]=c;async function _(t,e,n={}){let i=n.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let r=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),s=S(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(r&&c.isIngestUrl(r))return i(t,e);let o=c.createRequestId(),a=c.createTraceId(),u=c.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",a),p.set("x-devinspector-span-id",u);let y={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let l=await i(t,y),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),w=l.status>=400||h>=c.getSlowThresholdMs();return c.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:h,requestId:o,traceId:a,spanId:u}}),w&&c.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:a,spanId:u}),l}catch(l){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));c.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:a,spanId:u}}),c.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:a,spanId:u});let w=l instanceof Error?l:new Error(M(l));throw c.captureError(w,{url:r,method:s,type:n.errorType||"network_error",requestId:o,traceId:a,spanId:u}),l}}0&&(module.exports={AuditCore,DEVINSPECTOR_SDK_VERSION,audit,coreAuditFetch});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
type UnknownRecord = Record<string, unknown>;
|
|
2
|
+
type DevInspectorTechnology = "angular" | "vanilla-js" | "react" | "vue" | "svelte" | "node" | "python" | "java" | "csharp" | "php" | "nextjs" | "react-native";
|
|
3
|
+
declare const DEVINSPECTOR_SDK_VERSION = "9.3.0";
|
|
2
4
|
interface AuditUser {
|
|
3
5
|
id?: string;
|
|
4
6
|
email?: string;
|
|
@@ -17,6 +19,9 @@ interface InitOptions {
|
|
|
17
19
|
apmEndpoint?: string;
|
|
18
20
|
environment?: string;
|
|
19
21
|
release?: string;
|
|
22
|
+
technology?: DevInspectorTechnology;
|
|
23
|
+
installationId?: string;
|
|
24
|
+
sdkVersion?: string;
|
|
20
25
|
slowThresholdMs?: number;
|
|
21
26
|
requestTimeoutMs?: number;
|
|
22
27
|
}
|
|
@@ -60,6 +65,9 @@ declare class AuditCore {
|
|
|
60
65
|
private apmEndpoint;
|
|
61
66
|
private environment;
|
|
62
67
|
private release?;
|
|
68
|
+
private technology?;
|
|
69
|
+
private installationId?;
|
|
70
|
+
private sdkVersion;
|
|
63
71
|
private slowThresholdMs;
|
|
64
72
|
private requestTimeoutMs;
|
|
65
73
|
private user?;
|
|
@@ -75,6 +83,9 @@ declare class AuditCore {
|
|
|
75
83
|
getApmEndpoint(): string;
|
|
76
84
|
getEnvironment(): string;
|
|
77
85
|
getRelease(): string | undefined;
|
|
86
|
+
getTechnology(): DevInspectorTechnology | undefined;
|
|
87
|
+
getInstallationId(): string | undefined;
|
|
88
|
+
getSdkVersion(): string;
|
|
78
89
|
getSlowThresholdMs(): number;
|
|
79
90
|
getRequestTimeoutMs(): number;
|
|
80
91
|
isInitialized(): boolean;
|
|
@@ -101,6 +112,7 @@ declare class AuditCore {
|
|
|
101
112
|
captureException(error: unknown, metadata?: UnknownRecord): Promise<void>;
|
|
102
113
|
captureMessage(message: string, metadata?: UnknownRecord): Promise<void>;
|
|
103
114
|
flush(): Promise<void>;
|
|
115
|
+
private getIntegrationContext;
|
|
104
116
|
private attachGlobalListeners;
|
|
105
117
|
private sendError;
|
|
106
118
|
private sendApm;
|
|
@@ -115,4 +127,4 @@ declare function coreAuditFetch(input: RequestInfo | URL, init?: RequestInit, op
|
|
|
115
127
|
nativeFetch?: typeof fetch;
|
|
116
128
|
}): Promise<Response>;
|
|
117
129
|
|
|
118
|
-
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit, coreAuditFetch };
|
|
130
|
+
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, DEVINSPECTOR_SDK_VERSION, type DbQueryData, type DevInspectorTechnology, type InitOptions, type RequestMetricData, audit, coreAuditFetch };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
type UnknownRecord = Record<string, unknown>;
|
|
2
|
+
type DevInspectorTechnology = "angular" | "vanilla-js" | "react" | "vue" | "svelte" | "node" | "python" | "java" | "csharp" | "php" | "nextjs" | "react-native";
|
|
3
|
+
declare const DEVINSPECTOR_SDK_VERSION = "9.3.0";
|
|
2
4
|
interface AuditUser {
|
|
3
5
|
id?: string;
|
|
4
6
|
email?: string;
|
|
@@ -17,6 +19,9 @@ interface InitOptions {
|
|
|
17
19
|
apmEndpoint?: string;
|
|
18
20
|
environment?: string;
|
|
19
21
|
release?: string;
|
|
22
|
+
technology?: DevInspectorTechnology;
|
|
23
|
+
installationId?: string;
|
|
24
|
+
sdkVersion?: string;
|
|
20
25
|
slowThresholdMs?: number;
|
|
21
26
|
requestTimeoutMs?: number;
|
|
22
27
|
}
|
|
@@ -60,6 +65,9 @@ declare class AuditCore {
|
|
|
60
65
|
private apmEndpoint;
|
|
61
66
|
private environment;
|
|
62
67
|
private release?;
|
|
68
|
+
private technology?;
|
|
69
|
+
private installationId?;
|
|
70
|
+
private sdkVersion;
|
|
63
71
|
private slowThresholdMs;
|
|
64
72
|
private requestTimeoutMs;
|
|
65
73
|
private user?;
|
|
@@ -75,6 +83,9 @@ declare class AuditCore {
|
|
|
75
83
|
getApmEndpoint(): string;
|
|
76
84
|
getEnvironment(): string;
|
|
77
85
|
getRelease(): string | undefined;
|
|
86
|
+
getTechnology(): DevInspectorTechnology | undefined;
|
|
87
|
+
getInstallationId(): string | undefined;
|
|
88
|
+
getSdkVersion(): string;
|
|
78
89
|
getSlowThresholdMs(): number;
|
|
79
90
|
getRequestTimeoutMs(): number;
|
|
80
91
|
isInitialized(): boolean;
|
|
@@ -101,6 +112,7 @@ declare class AuditCore {
|
|
|
101
112
|
captureException(error: unknown, metadata?: UnknownRecord): Promise<void>;
|
|
102
113
|
captureMessage(message: string, metadata?: UnknownRecord): Promise<void>;
|
|
103
114
|
flush(): Promise<void>;
|
|
115
|
+
private getIntegrationContext;
|
|
104
116
|
private attachGlobalListeners;
|
|
105
117
|
private sendError;
|
|
106
118
|
private sendApm;
|
|
@@ -115,4 +127,4 @@ declare function coreAuditFetch(input: RequestInfo | URL, init?: RequestInit, op
|
|
|
115
127
|
nativeFetch?: typeof fetch;
|
|
116
128
|
}): Promise<Response>;
|
|
117
129
|
|
|
118
|
-
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, type DbQueryData, type InitOptions, type RequestMetricData, audit, coreAuditFetch };
|
|
130
|
+
export { AuditCore, type AuditEventType, type AuditUser, type Breadcrumb, type CustomMetricData, DEVINSPECTOR_SDK_VERSION, type DbQueryData, type DevInspectorTechnology, type InitOptions, type RequestMetricData, audit, coreAuditFetch };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var T="https://api.devinspector.com.br/api/ingest/track",M="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 D(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return q.some(r=>e.includes(r))}function l(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=>l(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(D(s)){n[s]="[REDACTED]";continue}n[s]=l(o,e+1,r)}return n}finally{r.delete(t)}}function I(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=l(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 A(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function E(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function R(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function _(t){return String(t??"").trim().slice(0,200)}function k(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)}`}function d(t){return l(t)}var y=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?l(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?l(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:d(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(/\/$/,""),u=r.pathname.replace(/\/$/,""),a=i.pathname.replace(/\/$/,"");return s===r.origin&&o===u||s===i.origin&&o===a}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return b("req")}createTraceId(){return b("trace")}createSpanId(){return b("span")}captureRequest(e){let r=v(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=A(e.statusCode)??0,s=E(e.durationMs)??0,o=R(e.ip),u={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:i,statusCode:n,durationMs:s,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(u)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let i=E(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(n)})}captureMetric(e,r,i={},n={}){let s=_(e);if(!s)return Promise.resolve();let o;try{o=k(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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=v(n.method),o=A(n.statusCode??n.status),u=E(n.durationMs),a=R(n.ip),m=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,g=typeof n.requestId=="string"&&n.requestId.trim()||void 0,h=typeof n.traceId=="string"&&n.traceId.trim()||void 0,c=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...m?{url:m}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...u!==void 0?{durationMs:u}:{},...a?{ip:a}:{},...g?{requestId:g}:{},...h?{traceId:h}:{},...c?{spanId:c}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(I(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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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(I(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:b("event"),endpoint:e,payload:d(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=l(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",a={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(u&&(a.keepalive=!0),!(await i(e,a)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},U="__DEVINSPECT_AUDIT_CORE_INSTANCE__",S=typeof globalThis<"u"?globalThis:{},p=S[U]||new y;S[U]=p;async function P(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=v(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&p.isIngestUrl(n))return i(t,e);let o=p.createRequestId(),u=p.createTraceId(),a=p.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",u),m.set("x-devinspector-span-id",a);let g={...e,headers:m},h=typeof performance<"u"?performance.now():Date.now();try{let c=await i(t,g),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),w=c.status>=400||f>=p.getSlowThresholdMs();return p.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:f,requestId:o,traceId:u,spanId:a}}),w&&p.captureRequest({method:s,url:n,statusCode:c.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:a}),c}catch(c){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));p.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:u,spanId:a}}),p.captureRequest({method:s,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:a});let w=c instanceof Error?c:new Error(I(c));throw p.captureError(w,{url:n,method:s,type:r.errorType||"network_error",requestId:o,traceId:u,spanId:a}),c}}export{y as AuditCore,p as audit,P as coreAuditFetch};
|
|
1
|
+
var E="9.3.0",O=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),R="https://api.devinspector.com.br/api/ingest/track",k="https://api.devinspector.com.br/api/ingest/apm",D=50,b=1e4,_=6,U=1e4,Q=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function x(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return Q.some(n=>e.includes(n))}function m(t,e=0,n=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>b?`${t.slice(0,b)}...[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>=_)return"[MaxDepth]";if(typeof t!="object")return String(t);if(n.has(t))return"[Circular]";n.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,n));let i=t,r={};for(let[s,o]of Object.entries(i)){if(x(s)){r[s]="[REDACTED]";continue}r[s]=m(o,e+1,n)}return r}finally{n.delete(t)}}function T(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 M(t){return t&&String(t).trim().toUpperCase()||void 0}function q(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function w(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function A(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function N(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 S(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function V(t){let e=S(t,50);if(e&&O.has(e))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 d(t){return m(t)}var I=class{constructor(){this.apiKey="";this.endpoint=R;this.apmEndpoint=k;this.environment="production";this.sdkVersion=E;this.slowThresholdMs=300;this.requestTimeoutMs=U;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()||k,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=V(e.technology),this.installationId=S(e.installationId,200),this.sdkVersion=S(e.sdkVersion,100)||E,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):U,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}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}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 n={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,b),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(n),this.breadcrumbs.length>D&&(this.breadcrumbs=this.breadcrumbs.slice(-D))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:d(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let n=new URL(this.endpoint),i=new URL(this.apmEndpoint),r=new URL(e,n.origin),s=r.origin,o=r.pathname.replace(/\/$/,""),a=n.pathname.replace(/\/$/,""),u=i.pathname.replace(/\/$/,"");return s===n.origin&&o===a||s===i.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 n=M(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=q(e.statusCode)??0,s=w(e.durationMs)??0,o=A(e.ip),a={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:n,url:i,statusCode:r,durationMs:s,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(a)})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return Promise.resolve();let i=w(e.durationMs)??0,r={...e.metadata||{},operation:n,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${n}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(r)})}captureMetric(e,n,i={},r={}){let s=N(e);if(!s)return Promise.resolve();let o;try{o=z(n)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:s,metricValue:o,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...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,n={}){let i=e?.message?.trim()||"Erro desconhecido",r={...n},s=M(r.method),o=q(r.statusCode??r.status),a=w(r.durationMs),u=A(r.ip),p=r.url!==void 0&&r.url!==null?String(r.url).trim():void 0,g=typeof r.requestId=="string"&&r.requestId.trim()||void 0,f=typeof r.traceId=="string"&&r.traceId.trim()||void 0,c=typeof r.spanId=="string"&&r.spanId.trim()||void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.requestId,delete r.traceId,delete r.spanId,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...p?{url:p}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...a!==void 0?{durationMs:a}:{},...u?{ip:u}:{},...g?{requestId:g}:{},...f?{traceId:f}:{},...c?{spanId:c}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let i=e instanceof Error?e:new Error(T(e));return this.captureError(i,n)}captureMessage(e,n={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,b),environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,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()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},sdkVersion:this.sdkVersion}}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let n=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,r)=>{this.captureError(i,{platform:"react-native",fatal:r}).finally(()=>{typeof n=="function"&&n(i,r)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",n=>{let i=n.error instanceof Error?n.error:new Error(n.message||"Erro global");this.captureError(i,{url:n.filename||window.location.href,line:n.lineno,column:n.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",n=>{let i=n.reason instanceof Error?n.reason:new Error(T(n.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",n=>{this.captureError(n,{platform:"node"})}),process.on("unhandledRejection",n=>{this.captureException(n,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,n){if(!this.initialized||!this.apiKey)return Promise.resolve();let i=y("event"),r={...n,...this.getIntegrationContext(),eventId:i},s={id:i,endpoint:e,payload:d(r),resolve:()=>{}};return new Promise(o=>{s.resolve=o,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 n of e)n()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,n){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let r=m(n),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",u={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};if(a&&(u.keepalive=!0),!(await i(e,u)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},P="__DEVINSPECT_AUDIT_CORE_INSTANCE__",C=typeof globalThis<"u"?globalThis:{},l=C[P]||new I;C[P]=l;async function B(t,e,n={}){let i=n.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let r=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),s=M(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(r&&l.isIngestUrl(r))return i(t,e);let o=l.createRequestId(),a=l.createTraceId(),u=l.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",a),p.set("x-devinspector-span-id",u);let g={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let c=await i(t,g),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),v=c.status>=400||h>=l.getSlowThresholdMs();return l.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:c.status,durationMs:h,requestId:o,traceId:a,spanId:u}}),v&&l.captureRequest({method:s,url:r,statusCode:c.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:a,spanId:u}),c}catch(c){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));l.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:a,spanId:u}}),l.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:a,spanId:u});let v=c instanceof Error?c:new Error(T(c));throw l.captureError(v,{url:r,method:s,type:n.errorType||"network_error",requestId:o,traceId:a,spanId:u}),c}}export{I as AuditCore,E as DEVINSPECTOR_SDK_VERSION,l as audit,B as coreAuditFetch};
|
package/dist/next.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},O=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of C(e))!P.call(t,n)&&n!==r&&w(t,n,{get:()=>e[n],enumerable:!(s=x(e,n))||s.enumerable});return t};var Q=t=>O(w({},"__esModule",{value:!0}),t);var H={};N(H,{audit:()=>a,auditFetch:()=>G,captureNextError:()=>R,initNextDevInspector:()=>j,withAuditAction:()=>K,withAuditApi:()=>F});module.exports=Q(H);var A="https://api.devinspector.com.br/api/ingest/track",S="https://api.devinspector.com.br/api/ingest/apm";var B=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function L(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return B.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(L(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 E(t){return t&&String(t).trim().toUpperCase()||void 0}function q(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function I(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function U(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function z(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 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 m(t){return g(t)}var T=class{constructor(){this.apiKey="";this.endpoint=A;this.apmEndpoint=S;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()||A,this.apmEndpoint=e.apmEndpoint?.trim()||S,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=>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,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=E(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=q(e.statusCode)??0,i=I(e.durationMs)??0,o=U(e.ip),d={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m(d)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=I(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=z(e);if(!i)return Promise.resolve();let o;try{o=$(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: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=E(n.method),o=q(n.statusCode??n.status),d=I(n.durationMs),u=U(n.ip),p=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,f=typeof n.requestId=="string"&&n.requestId.trim()||void 0,l=typeof n.traceId=="string"&&n.traceId.trim()||void 0,c=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...p?{url:p}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...d!==void 0?{durationMs:d}:{},...u?{ip:u}:{},...f?{requestId:f}:{},...l?{traceId:l}:{},...c?{spanId:c}:{},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(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: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(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: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=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)}}},_="__DEVINSPECT_AUDIT_CORE_INSTANCE__",k=typeof globalThis<"u"?globalThis:{},a=k[_]||new T;k[_]=a;async function D(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=E(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(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",u);let f={...e,headers:p},l=typeof performance<"u"?performance.now():Date.now();try{let c=await s(t,f),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l)),b=c.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:h,requestId:o,traceId:d,spanId:u}}),b&&a.captureRequest({method:i,url:n,statusCode:c.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u}),c}catch(c){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));a.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:d,spanId:u}}),a.captureRequest({method:i,url:n,statusCode:0,durationMs:h,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",requestId:o,traceId:d,spanId:u}),c}}function j(t){a.init(t)}function R(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{...e,framework:"Next.js"})}async function G(t,e){return D(t,e,{errorType:"nextjs_network_error"})}function F(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=M(s,"x-devinspector-request-id")||a.createRequestId(),p=M(s,"x-devinspector-trace-id")||a.createTraceId(),f=M(s,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"start",requestId:u,traceId:p,spanId:f}});try{let l=await t(...e),c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r)),h=Number(l?.status??n?.statusCode??200)||200;return(h>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:o,statusCode:h,durationMs:c,route:o,userAgent:d,requestId:u,traceId:p,spanId:f}),a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"complete",statusCode:h,durationMs:c,requestId:u,traceId:p,spanId:f}}),l}catch(l){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:p,spanId:f}),a.addBreadcrumb({type:"http_error",message:`${i} ${o}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:u,traceId:p,spanId:f}}),R(l,{url:o,method:i,type:"api_route_error",requestId:u,traceId:p,spanId:f}),l}}}function K(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}}),R(d,{actionName:t,type:"server_action_error",requestId:n,traceId:i,spanId:o}),d}})}function M(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]??t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}0&&(module.exports={audit,auditFetch,captureNextError,initNextDevInspector,withAuditAction,withAuditApi});
|
|
1
|
+
"use strict";var w=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var j=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},L=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of z(e))!B.call(t,n)&&n!==r&&w(t,n,{get:()=>e[n],enumerable:!(s=N(e,n))||s.enumerable});return t};var V=t=>L(w({},"__esModule",{value:!0}),t);var te={};j(te,{audit:()=>a,auditFetch:()=>W,captureNextError:()=>S,initNextDevInspector:()=>Y,withAuditAction:()=>ee,withAuditApi:()=>Z});module.exports=V(te);var q="9.3.0",$=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),A="https://api.devinspector.com.br/api/ingest/track",U="https://api.devinspector.com.br/api/ingest/apm",D=50,I=1e4,F=6,x=1e4,K=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function G(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>I?`${t.slice(0,I)}...[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>=F)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(G(i)){n[i]="[REDACTED]";continue}n[i]=g(o,e+1,r)}return n}finally{r.delete(t)}}function E(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 T(t){return t&&String(t).trim().toUpperCase()||void 0}function _(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 C(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function H(t){return String(t??"").trim().slice(0,200)}function X(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function M(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function J(t){let e=M(t,50);if(e&&$.has(e))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 l(t){return g(t)}var R=class{constructor(){this.apiKey="";this.endpoint=A;this.apmEndpoint=U;this.environment="production";this.sdkVersion=q;this.slowThresholdMs=300;this.requestTimeoutMs=x;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()||A,this.apmEndpoint=e.apmEndpoint?.trim()||U,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=J(e.technology),this.installationId=M(e.installationId,200),this.sdkVersion=M(e.sdkVersion,100)||q,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):x,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}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}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,I),metadata:e.metadata?g(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>D&&(this.breadcrumbs=this.breadcrumbs.slice(-D))}getBreadcrumbs(){return this.breadcrumbs.map(e=>l(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:l(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=T(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=_(e.statusCode)??0,i=v(e.durationMs)??0,o=C(e.ip),d={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l(d)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=v(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:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l(n)})}captureMetric(e,r,s={},n={}){let i=H(e);if(!i)return Promise.resolve();let o;try{o=X(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:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l({...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=T(n.method),o=_(n.statusCode??n.status),d=v(n.durationMs),u=C(n.ip),p=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,m=typeof n.requestId=="string"&&n.requestId.trim()||void 0,h=typeof n.traceId=="string"&&n.traceId.trim()||void 0,c=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...p?{url:p}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...d!==void 0?{durationMs:d}:{},...u?{ip:u}:{},...m?{requestId:m}:{},...h?{traceId:h}:{},...c?{spanId:c}:{},environment:this.environment,release:this.release,user:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let s=e instanceof Error?e:new Error(E(e));return this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,I),environment:this.environment,release:this.release,user:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l({...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()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},sdkVersion:this.sdkVersion}}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(E(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=y("event"),n={...r,...this.getIntegrationContext(),eventId:s},i={id:s,endpoint:e,payload:l(n),resolve:()=>{}};return new Promise(o=>{i.resolve=o,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 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)}}},P="__DEVINSPECT_AUDIT_CORE_INSTANCE__",O=typeof globalThis<"u"?globalThis:{},a=O[P]||new R;O[P]=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=T(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(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",u);let m={...e,headers:p},h=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())-h)),b=c.status>=400||f>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:f,requestId:o,traceId:d,spanId:u}}),b&&a.captureRequest({method:i,url:n,statusCode:c.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u}),c}catch(c){let f=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:f,requestId:o,traceId:d,spanId:u}}),a.captureRequest({method:i,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u});let b=c instanceof Error?c:new Error(E(c));throw a.captureError(b,{url:n,method:i,type:r.errorType||"network_error",requestId:o,traceId:d,spanId:u}),c}}function Y(t){a.init(t)}function S(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{...e,framework:"Next.js"})}async function W(t,e){return Q(t,e,{errorType:"nextjs_network_error"})}function Z(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=k(s,"x-devinspector-request-id")||a.createRequestId(),p=k(s,"x-devinspector-trace-id")||a.createTraceId(),m=k(s,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"start",requestId:u,traceId:p,spanId:m}});try{let h=await t(...e),c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r)),f=Number(h?.status??n?.statusCode??200)||200;return(f>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:o,statusCode:f,durationMs:c,route:o,userAgent:d,requestId:u,traceId:p,spanId:m}),a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"complete",statusCode:f,durationMs:c,requestId:u,traceId:p,spanId:m}}),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:p,spanId:m}),a.addBreadcrumb({type:"http_error",message:`${i} ${o}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:u,traceId:p,spanId:m}}),S(h,{url:o,method:i,type:"api_route_error",requestId:u,traceId:p,spanId:m}),h}}}function ee(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}}),S(d,{actionName:t,type:"server_action_error",requestId:n,traceId:i,spanId:o}),d}})}function k(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 M="https://api.devinspector.com.br/api/ingest/track",R="https://api.devinspector.com.br/api/ingest/apm";var D=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function x(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return D.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(x(i)){n[i]="[REDACTED]";continue}n[i]=g(o,e+1,r)}return n}finally{r.delete(t)}}function I(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 A(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function w(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function S(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function C(t){return String(t??"").trim().slice(0,200)}function P(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function y(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function m(t){return g(t)}var E=class{constructor(){this.apiKey="";this.endpoint=M;this.apmEndpoint=R;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()||M,this.apmEndpoint=e.apmEndpoint?.trim()||R,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=>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,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=A(e.statusCode)??0,i=w(e.durationMs)??0,o=S(e.ip),d={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m(d)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=w(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=C(e);if(!i)return Promise.resolve();let o;try{o=P(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: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=v(n.method),o=A(n.statusCode??n.status),d=w(n.durationMs),u=S(n.ip),p=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,f=typeof n.requestId=="string"&&n.requestId.trim()||void 0,l=typeof n.traceId=="string"&&n.traceId.trim()||void 0,c=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...p?{url:p}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...d!==void 0?{durationMs:d}:{},...u?{ip:u}:{},...f?{requestId:f}:{},...l?{traceId:l}:{},...c?{spanId:c}:{},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(I(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(I(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: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=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__",U=typeof globalThis<"u"?globalThis:{},a=U[q]||new E;U[q]=a;async function _(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(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",u);let f={...e,headers:p},l=typeof performance<"u"?performance.now():Date.now();try{let c=await s(t,f),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l)),b=c.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:h,requestId:o,traceId:d,spanId:u}}),b&&a.captureRequest({method:i,url:n,statusCode:c.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u}),c}catch(c){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));a.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:d,spanId:u}}),a.captureRequest({method:i,url:n,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u});let b=c instanceof Error?c:new Error(I(c));throw a.captureError(b,{url:n,method:i,type:r.errorType||"network_error",requestId:o,traceId:d,spanId:u}),c}}function Q(t){a.init(t)}function k(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{...e,framework:"Next.js"})}async function B(t,e){return _(t,e,{errorType:"nextjs_network_error"})}function L(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(),p=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:p,spanId:f}});try{let l=await t(...e),c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r)),h=Number(l?.status??n?.statusCode??200)||200;return(h>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:o,statusCode:h,durationMs:c,route:o,userAgent:d,requestId:u,traceId:p,spanId:f}),a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"complete",statusCode:h,durationMs:c,requestId:u,traceId:p,spanId:f}}),l}catch(l){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:p,spanId:f}),a.addBreadcrumb({type:"http_error",message:`${i} ${o}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:u,traceId:p,spanId:f}}),k(l,{url:o,method:i,type:"api_route_error",requestId:u,traceId:p,spanId:f}),l}}}function z(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}}),k(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}export{a as audit,B as auditFetch,k as captureNextError,Q as initNextDevInspector,z as withAuditAction,L as withAuditApi};
|
|
1
|
+
var k="9.3.0",Q=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),S="https://api.devinspector.com.br/api/ingest/track",q="https://api.devinspector.com.br/api/ingest/apm",A=50,I=1e4,N=6,U=1e4,z=["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 z.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>I?`${t.slice(0,I)}...[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>=N)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 E(t){return t&&String(t).trim().toUpperCase()||void 0}function D(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function w(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function x(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function j(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 T(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function V(t){let e=T(t,50);if(e&&Q.has(e))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 l(t){return g(t)}var M=class{constructor(){this.apiKey="";this.endpoint=S;this.apmEndpoint=q;this.environment="production";this.sdkVersion=k;this.slowThresholdMs=300;this.requestTimeoutMs=U;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()||S,this.apmEndpoint=e.apmEndpoint?.trim()||q,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=V(e.technology),this.installationId=T(e.installationId,200),this.sdkVersion=T(e.sdkVersion,100)||k,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):U,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}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}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,I),metadata:e.metadata?g(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>A&&(this.breadcrumbs=this.breadcrumbs.slice(-A))}getBreadcrumbs(){return this.breadcrumbs.map(e=>l(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:l(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=E(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=D(e.statusCode)??0,i=w(e.durationMs)??0,o=x(e.ip),d={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l(d)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=w(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:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l(n)})}captureMetric(e,r,s={},n={}){let i=j(e);if(!i)return Promise.resolve();let o;try{o=L(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:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l({...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=E(n.method),o=D(n.statusCode??n.status),d=w(n.durationMs),u=x(n.ip),p=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,m=typeof n.requestId=="string"&&n.requestId.trim()||void 0,h=typeof n.traceId=="string"&&n.traceId.trim()||void 0,c=typeof n.spanId=="string"&&n.spanId.trim()||void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.durationMs,delete n.ip,delete n.requestId,delete n.traceId,delete n.spanId,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...p?{url:p}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},...d!==void 0?{durationMs:d}:{},...u?{ip:u}:{},...m?{requestId:m}:{},...h?{traceId:h}:{},...c?{spanId:c}:{},environment:this.environment,release:this.release,user:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l({...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,I),environment:this.environment,release:this.release,user:l(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:l({...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()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},sdkVersion:this.sdkVersion}}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=y("event"),n={...r,...this.getIntegrationContext(),eventId:s},i={id:s,endpoint:e,payload:l(n),resolve:()=>{}};return new Promise(o=>{i.resolve=o,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 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)}}},_="__DEVINSPECT_AUDIT_CORE_INSTANCE__",C=typeof globalThis<"u"?globalThis:{},a=C[_]||new M;C[_]=a;async function P(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=E(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(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",d),p.set("x-devinspector-span-id",u);let m={...e,headers:p},h=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())-h)),b=c.status>=400||f>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:f,requestId:o,traceId:d,spanId:u}}),b&&a.captureRequest({method:i,url:n,statusCode:c.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:d,spanId:u}),c}catch(c){let f=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:f,requestId:o,traceId:d,spanId:u}}),a.captureRequest({method:i,url:n,statusCode:0,durationMs:f,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",requestId:o,traceId:d,spanId:u}),c}}function K(t){a.init(t)}function O(t,e={}){let r=t instanceof Error?t:new Error(String(t));a.captureError(r,{...e,framework:"Next.js"})}async function G(t,e){return P(t,e,{errorType:"nextjs_network_error"})}function H(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=R(s,"x-devinspector-request-id")||a.createRequestId(),p=R(s,"x-devinspector-trace-id")||a.createTraceId(),m=R(s,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"start",requestId:u,traceId:p,spanId:m}});try{let h=await t(...e),c=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r)),f=Number(h?.status??n?.statusCode??200)||200;return(f>=400||c>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:o,statusCode:f,durationMs:c,route:o,userAgent:d,requestId:u,traceId:p,spanId:m}),a.addBreadcrumb({type:"http",message:`${i} ${o}`,metadata:{framework:"Next.js",phase:"complete",statusCode:f,durationMs:c,requestId:u,traceId:p,spanId:m}}),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:p,spanId:m}),a.addBreadcrumb({type:"http_error",message:`${i} ${o}`,metadata:{framework:"Next.js",statusCode:500,durationMs:c,requestId:u,traceId:p,spanId:m}}),O(h,{url:o,method:i,type:"api_route_error",requestId:u,traceId:p,spanId:m}),h}}}function X(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}}),O(d,{actionName:t,type:"server_action_error",requestId:n,traceId:i,spanId:o}),d}})}function R(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,G as auditFetch,O as captureNextError,K as initNextDevInspector,X as withAuditAction,H as withAuditApi};
|