@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/svelte.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _="https://api.devinspector.com.br/api/ingest/track",S="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 k(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return D.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(k(i)){n[i]="[REDACTED]";continue}n[i]=h(o,e+1,r)}return n}finally{r.delete(t)}}function w(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=h(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 A(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function P(t){return String(t??"").trim().slice(0,200)}function C(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function y(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function m(t){return h(t)}var v=class{constructor(){this.apiKey="";this.endpoint=_;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()||_,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?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=>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(/\/$/,""),u=r.pathname.replace(/\/$/,""),d=s.pathname.replace(/\/$/,"");return i===r.origin&&o===u||i===s.origin&&o===d}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=R(e.statusCode)??0,i=I(e.durationMs)??0,o=A(e.ip),u={...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(u)})}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=P(e);if(!i)return Promise.resolve();let o;try{o=C(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user: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=T(n.method),o=R(n.statusCode??n.status),u=I(n.durationMs),d=A(n.ip),c=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,p=typeof n.requestId=="string"&&n.requestId.trim()||void 0,f=typeof n.traceId=="string"&&n.traceId.trim()||void 0,l=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}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...p?{requestId:p}:{},...f?{traceId:f}:{},...l?{spanId:l}:{},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(w(e));return this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();return s?this.sendApm({type:"message",message:s.slice(0,1e4),environment:this.environment,release:this.release,user: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(w(r.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let s={id:y("event"),endpoint:e,payload: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=h(r),i,o;try{typeof AbortController<"u"&&(i=new AbortController,o=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:i?.signal};if(u&&(d.keepalive=!0),!(await s(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},q="__DEVINSPECT_AUDIT_CORE_INSTANCE__",U=typeof globalThis<"u"?globalThis:{},a=U[q]||new v;U[q]=a;async function M(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(),u=a.createTraceId(),d=a.createSpanId(),c=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));c.set("x-devinspector-request-id",o),c.set("x-devinspector-trace-id",u),c.set("x-devinspector-span-id",d);let p={...e,headers:c},f=typeof performance<"u"?performance.now():Date.now();try{let l=await s(t,p),g=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),E=l.status>=400||g>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:l.status,durationMs:g,requestId:o,traceId:u,spanId:d}}),E&&a.captureRequest({method:i,url:n,statusCode:l.status,durationMs:g,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d}),l}catch(l){let g=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:g,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:i,url:n,statusCode:0,durationMs:g,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d});let E=l instanceof Error?l:new Error(w(l));throw a.captureError(E,{url:n,method:i,type:r.errorType||"network_error",requestId:o,traceId:u,spanId:d}),l}}function x(t){a.init(t)}async function Q(t,e){return M(t,e,{errorType:"svelte_network_error",defaultUserAgent:"SvelteKit"})}async function B({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),s=t.request?.method||"GET",n=t.url?.href||t.url?.pathname||"/",i=t.route?.id||n;if(n&&a.isIngestUrl(n))return e(t);let o=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"",u=b(t.request,"x-devinspector-request-id")||a.createRequestId(),d=b(t.request,"x-devinspector-trace-id")||a.createTraceId(),c=b(t.request,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{framework:"SvelteKit",phase:"start",requestId:u,traceId:d,spanId:c,route:i}});try{let p=await e(t),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r));return(p.status>=400||f>=a.getSlowThresholdMs())&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:f,route:i,userAgent:o,requestId:u,traceId:d,spanId:c}),a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:p.status,durationMs:f,requestId:u,traceId:d,spanId:c,route:i}}),p}catch(p){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r));a.captureRequest({method:s,url:n,statusCode:500,durationMs:f,route:i,userAgent:o,requestId:u,traceId:d,spanId:c}),a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:f,requestId:u,traceId:d,spanId:c,route:i}});let l=p instanceof Error?p:new Error(String(p));throw a.captureError(l,{framework:"SvelteKit",url:n,method:s,route:i,requestId:u,traceId:d,spanId:c}),p}}function L({error:t,event:e,status:r,message:s}){let n=t instanceof Error?t:new Error(String(t||s||"Erro SvelteKit")),i=b(e?.request,"x-devinspector-request-id")||a.createRequestId(),o=b(e?.request,"x-devinspector-trace-id")||a.createTraceId(),u=b(e?.request,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"sveltekit_error",message:n.message||"Erro SvelteKit",metadata:{statusCode:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:i,traceId:o,spanId:u}}),a.captureError(n,{framework:"SvelteKit",statusCode:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:i,traceId:o,spanId:u})}function F(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let r;try{r=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(r&&r.get&&!r.set||r&&r.writable===!1&&!r.set)return;let s=e.bind(globalThis),n=function(i,o){return M(i,o,{errorType:"svelte_network_error",defaultUserAgent:"SvelteKit",nativeFetch:s})};try{r&&r.configurable?Object.defineProperty(globalThis,"fetch",{...r,value:n}):globalThis.fetch=n}catch{return}globalThis.fetch===n&&(t.__DEVINSPECTOR_NATIVE_FETCH__=s,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}function b(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]??t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}export{a as audit,Q as auditFetch,B as auditHandle,F as enableNetworkTracing,L as handleSvelteKitError,x as initSvelteDevInspector};
|
|
1
|
+
var M="9.3.0",x=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),_="https://api.devinspector.com.br/api/ingest/track",k="https://api.devinspector.com.br/api/ingest/apm",D=50,I=1e4,N=6,A=1e4,Q=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function V(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return Q.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>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(s=>h(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(V(s)){n[s]="[REDACTED]";continue}n[s]=h(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=h(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 U(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 z(t){return String(t??"").trim().slice(0,200)}function B(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 K(t){let e=S(t,50);if(e&&x.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 m(t){return h(t)}var R=class{constructor(){this.apiKey="";this.endpoint=_;this.apmEndpoint=k;this.environment="production";this.sdkVersion=M;this.slowThresholdMs=300;this.requestTimeoutMs=A;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()||_,this.apmEndpoint=e.apmEndpoint?.trim()||k,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=K(e.technology),this.installationId=S(e.installationId,200),this.sdkVersion=S(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):A,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 r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,I),metadata:e.metadata?h(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>D&&(this.breadcrumbs=this.breadcrumbs.slice(-D))}getBreadcrumbs(){return this.breadcrumbs.map(e=>m(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:m(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(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===r.origin&&o===u||s===i.origin&&o===d}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",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=U(e.statusCode)??0,s=w(e.durationMs)??0,o=P(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:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m(u)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let i=w(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:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m(n)})}captureMetric(e,r,i={},n={}){let s=z(e);if(!s)return Promise.resolve();let o;try{o=B(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:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m({...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=U(n.statusCode??n.status),u=w(n.durationMs),d=P(n.ip),c=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0,l=typeof n.requestId=="string"&&n.requestId.trim()||void 0,f=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||"",...c?{url:c}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...l?{requestId:l}:{},...f?{traceId:f}:{},...p?{spanId:p}:{},environment:this.environment,release:this.release,user:m(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:m({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(E(e));return this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,I),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()})}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?.((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(E(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=b("event"),n={...r,...this.getIntegrationContext(),eventId:i},s={id:i,endpoint:e,payload:m(n),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 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=h(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",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},C="__DEVINSPECT_AUDIT_CORE_INSTANCE__",O=typeof globalThis<"u"?globalThis:{},a=O[C]||new R;O[C]=a;async function q(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&&a.isIngestUrl(n))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),c=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));c.set("x-devinspector-request-id",o),c.set("x-devinspector-trace-id",u),c.set("x-devinspector-span-id",d);let l={...e,headers:c},f=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,l),g=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),v=p.status>=400||g>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:g,requestId:o,traceId:u,spanId:d}}),v&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:g,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d}),p}catch(p){let g=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:g,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:g,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d});let v=p instanceof Error?p:new Error(E(p));throw a.captureError(v,{url:n,method:s,type:r.errorType||"network_error",requestId:o,traceId:u,spanId:d}),p}}function j(t){a.init(t)}async function $(t,e){return q(t,e,{errorType:"svelte_network_error",defaultUserAgent:"SvelteKit"})}async function H({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),i=t.request?.method||"GET",n=t.url?.href||t.url?.pathname||"/",s=t.route?.id||n;if(n&&a.isIngestUrl(n))return e(t);let o=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"",u=y(t.request,"x-devinspector-request-id")||a.createRequestId(),d=y(t.request,"x-devinspector-trace-id")||a.createTraceId(),c=y(t.request,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{framework:"SvelteKit",phase:"start",requestId:u,traceId:d,spanId:c,route:s}});try{let l=await e(t),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r));return(l.status>=400||f>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:n,statusCode:l.status,durationMs:f,route:s,userAgent:o,requestId:u,traceId:d,spanId:c}),a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:l.status,durationMs:f,requestId:u,traceId:d,spanId:c,route:s}}),l}catch(l){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-r));a.captureRequest({method:i,url:n,statusCode:500,durationMs:f,route:s,userAgent:o,requestId:u,traceId:d,spanId:c}),a.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:f,requestId:u,traceId:d,spanId:c,route:s}});let p=l instanceof Error?l:new Error(String(l));throw a.captureError(p,{framework:"SvelteKit",url:n,method:i,route:s,requestId:u,traceId:d,spanId:c}),l}}function G({error:t,event:e,status:r,message:i}){let n=t instanceof Error?t:new Error(String(t||i||"Erro SvelteKit")),s=y(e?.request,"x-devinspector-request-id")||a.createRequestId(),o=y(e?.request,"x-devinspector-trace-id")||a.createTraceId(),u=y(e?.request,"x-devinspector-span-id")||a.createSpanId();a.addBreadcrumb({type:"sveltekit_error",message:n.message||"Erro SvelteKit",metadata:{statusCode:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:s,traceId:o,spanId:u}}),a.captureError(n,{framework:"SvelteKit",statusCode:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:s,traceId:o,spanId:u})}function X(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let r;try{r=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(r&&r.get&&!r.set||r&&r.writable===!1&&!r.set)return;let i=e.bind(globalThis),n=function(s,o){return q(s,o,{errorType:"svelte_network_error",defaultUserAgent:"SvelteKit",nativeFetch:i})};try{r&&r.configurable?Object.defineProperty(globalThis,"fetch",{...r,value:n}):globalThis.fetch=n}catch{return}globalThis.fetch===n&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}function y(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]??t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}export{a as audit,$ as auditFetch,H as auditHandle,X as enableNetworkTracing,G as handleSvelteKitError,j as initSvelteDevInspector};
|
package/dist/vanilla.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var Q=(t,e)=>{for(var r in e)E(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!O.call(t,n)&&n!==r&&E(t,n,{get:()=>e[n],enumerable:!(i=C(e,n))||i.enumerable});return t};var F=t=>x(E({},"__esModule",{value:!0}),t);var V={};Q(V,{audit:()=>u,auditFetch:()=>M,default:()=>H,enableNetworkTracing:()=>P});module.exports=F(V);var R="https://api.devinspector.com.br/api/ingest/track",_="https://api.devinspector.com.br/api/ingest/apm";var L=["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 L.some(r=>e.includes(r))}function m(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(B(s)){n[s]="[REDACTED]";continue}n[s]=m(o,e+1,r)}return n}finally{r.delete(t)}}function w(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function T(t){return t&&String(t).trim().toUpperCase()||void 0}function A(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 S(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 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 c(t){return m(t)}var v=class{constructor(){this.apiKey="";this.endpoint=R;this.apmEndpoint=_;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||R,this.apmEndpoint=e.apmEndpoint?.trim()||_,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?m(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,r.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),a=r.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===r.origin&&o===a||s===i.origin&&o===d}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",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=A(e.statusCode)??0,s=I(e.durationMs)??0,o=S(e.ip),a={...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(a)})}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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(n)})}captureMetric(e,r,i={},n={}){let s=z(e);if(!s)return Promise.resolve();let o;try{o=G(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=A(n.statusCode??n.status),a=I(n.durationMs),d=S(n.ip),l=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,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||"",...l?{url:l}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...a!==void 0?{durationMs:a}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...h?{traceId:h}:{},...p?{spanId:p}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(w(e));return this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,1e4),environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}).finally(()=>{typeof r=="function"&&r(i,n)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let i=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(i,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let i=r.reason instanceof Error?r.reason:new Error(w(r.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let i={id:b("event"),endpoint:e,payload:c(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=m(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(a&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},U="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=typeof globalThis<"u"?globalThis:{},u=q[U]||new v;q[U]=u;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&&u.isIngestUrl(n))return i(t,e);let o=u.createRequestId(),a=u.createTraceId(),d=u.createSpanId(),l=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));l.set("x-devinspector-request-id",o),l.set("x-devinspector-trace-id",a),l.set("x-devinspector-span-id",d);let g={...e,headers:l},h=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,g),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),y=p.status>=400||f>=u.getSlowThresholdMs();return u.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:f,requestId:o,traceId:a,spanId:d}}),y&&u.captureRequest({method:s,url:n,statusCode:p.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:d}),p}catch(p){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));u.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:a,spanId:d}}),u.captureRequest({method:s,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:d});let y=p instanceof Error?p:new Error(w(p));throw u.captureError(y,{url:n,method:s,type:r.errorType||"network_error",requestId:o,traceId:a,spanId:d}),p}}var k=null;async function M(t,e,r){return D(t,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:r||k||void 0})}function P(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let r;try{r=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(r&&r.get&&!r.set||r&&r.writable===!1&&!r.set)return;let i=e.bind(globalThis);k=i;let n=function(s,o){return M(s,o,i)};try{r&&r.configurable?Object.defineProperty(globalThis,"fetch",{...r,value:n}):globalThis.fetch=n}catch{return}globalThis.fetch===n&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let t=window;t.DevInspector={init:e=>u.init(e),captureError:(e,r)=>u.captureError(e,r),captureException:(e,r)=>u.captureException(e,r),captureMessage:(e,r)=>u.captureMessage(e,r),captureMetric:(e,r,i)=>u.captureMetric(e,r,i),captureCustomMetric:e=>u.captureCustomMetric(e),auditFetch:M,enableNetworkTracing:P,core:u}}var H=u;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
|
1
|
+
"use strict";var v=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},B=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!F.call(t,r)&&r!==n&&v(t,r,{get:()=>e[r],enumerable:!(i=V(e,r))||i.enumerable});return t};var j=t=>B(v({},"__esModule",{value:!0}),t);var Z={};L(Z,{audit:()=>a,auditFetch:()=>_,default:()=>Y,enableNetworkTracing:()=>Q});module.exports=j(Z);var k="9.3.0",H=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),D="https://api.devinspector.com.br/api/ingest/track",S="https://api.devinspector.com.br/api/ingest/apm",q=50,b=1e4,K=6,U=1e4,$=["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 $.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>=K)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(G(s)){r[s]="[REDACTED]";continue}r[s]=m(o,e+1,n)}return r}finally{n.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=m(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 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 P(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function X(t){return String(t??"").trim().slice(0,200)}function J(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function R(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function W(t){let e=R(t,50);if(e&&H.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 c(t){return m(t)}var M=class{constructor(){this.apiKey="";this.endpoint=D;this.apmEndpoint=S;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()||D,this.apmEndpoint=e.apmEndpoint?.trim()||S,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=W(e.technology),this.installationId=R(e.installationId,200),this.sdkVersion=R(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?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>q&&(this.breadcrumbs=this.breadcrumbs.slice(-q))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:c(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(/\/$/,""),u=n.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===n.origin&&o===u||s===i.origin&&o===d}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=T(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=A(e.statusCode)??0,s=w(e.durationMs)??0,o=P(e.ip),u={...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(u)})}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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(r)})}captureMetric(e,n,i={},r={}){let s=X(e);if(!s)return Promise.resolve();let o;try{o=J(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=T(r.method),o=A(r.statusCode??r.status),u=w(r.durationMs),d=P(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,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}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...f?{traceId:f}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let i=e instanceof Error?e:new Error(E(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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(E(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:c(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 u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},C="__DEVINSPECT_AUDIT_CORE_INSTANCE__",O=typeof globalThis<"u"?globalThis:{},a=O[C]||new M;O[C]=a;async function N(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=T(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let g={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let l=await i(t,g),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),I=l.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:h,requestId:o,traceId:u,spanId:d}}),I&&a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d}),l}catch(l){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d});let I=l instanceof Error?l:new Error(E(l));throw a.captureError(I,{url:r,method:s,type:n.errorType||"network_error",requestId:o,traceId:u,spanId:d}),l}}var x=null;async function _(t,e,n){return N(t,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:n||x||void 0})}function Q(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let n;try{n=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(n&&n.get&&!n.set||n&&n.writable===!1&&!n.set)return;let i=e.bind(globalThis);x=i;let r=function(s,o){return _(s,o,i)};try{n&&n.configurable?Object.defineProperty(globalThis,"fetch",{...n,value:r}):globalThis.fetch=r}catch{return}globalThis.fetch===r&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let t=window;t.DevInspector={init:e=>a.init(e),captureError:(e,n)=>a.captureError(e,n),captureException:(e,n)=>a.captureException(e,n),captureMessage:(e,n)=>a.captureMessage(e,n),captureMetric:(e,n,i)=>a.captureMetric(e,n,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:_,enableNetworkTracing:Q,core:a}}var Y=a;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
package/dist/vanilla.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var DevInspector=(()=>{var E=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var Q=(t,e)=>{for(var r in e)E(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!O.call(t,n)&&n!==r&&E(t,n,{get:()=>e[n],enumerable:!(i=C(e,n))||i.enumerable});return t};var F=t=>x(E({},"__esModule",{value:!0}),t);var V={};Q(V,{audit:()=>u,auditFetch:()=>M,default:()=>H,enableNetworkTracing:()=>P});var R="https://api.devinspector.com.br/api/ingest/track",_="https://api.devinspector.com.br/api/ingest/apm";var L=["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 L.some(r=>e.includes(r))}function m(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(B(s)){n[s]="[REDACTED]";continue}n[s]=m(o,e+1,r)}return n}finally{r.delete(t)}}function w(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function T(t){return t&&String(t).trim().toUpperCase()||void 0}function A(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 S(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 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 c(t){return m(t)}var v=class{constructor(){this.apiKey="";this.endpoint=R;this.apmEndpoint=_;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||R,this.apmEndpoint=e.apmEndpoint?.trim()||_,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?m(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,r.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),a=r.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===r.origin&&o===a||s===i.origin&&o===d}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",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=A(e.statusCode)??0,s=I(e.durationMs)??0,o=S(e.ip),a={...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(a)})}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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(n)})}captureMetric(e,r,i={},n={}){let s=z(e);if(!s)return Promise.resolve();let o;try{o=G(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=A(n.statusCode??n.status),a=I(n.durationMs),d=S(n.ip),l=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,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||"",...l?{url:l}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...a!==void 0?{durationMs:a}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...h?{traceId:h}:{},...p?{spanId:p}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(w(e));return this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,1e4),environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}).finally(()=>{typeof r=="function"&&r(i,n)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let i=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(i,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let i=r.reason instanceof Error?r.reason:new Error(w(r.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let i={id:b("event"),endpoint:e,payload:c(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=m(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(a&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},U="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=typeof globalThis<"u"?globalThis:{},u=q[U]||new v;q[U]=u;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&&u.isIngestUrl(n))return i(t,e);let o=u.createRequestId(),a=u.createTraceId(),d=u.createSpanId(),l=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));l.set("x-devinspector-request-id",o),l.set("x-devinspector-trace-id",a),l.set("x-devinspector-span-id",d);let g={...e,headers:l},h=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,g),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),y=p.status>=400||f>=u.getSlowThresholdMs();return u.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:f,requestId:o,traceId:a,spanId:d}}),y&&u.captureRequest({method:s,url:n,statusCode:p.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:d}),p}catch(p){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));u.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:a,spanId:d}}),u.captureRequest({method:s,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:d});let y=p instanceof Error?p:new Error(w(p));throw u.captureError(y,{url:n,method:s,type:r.errorType||"network_error",requestId:o,traceId:a,spanId:d}),p}}var k=null;async function M(t,e,r){return D(t,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:r||k||void 0})}function P(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let r;try{r=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(r&&r.get&&!r.set||r&&r.writable===!1&&!r.set)return;let i=e.bind(globalThis);k=i;let n=function(s,o){return M(s,o,i)};try{r&&r.configurable?Object.defineProperty(globalThis,"fetch",{...r,value:n}):globalThis.fetch=n}catch{return}globalThis.fetch===n&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let t=window;t.DevInspector={init:e=>u.init(e),captureError:(e,r)=>u.captureError(e,r),captureException:(e,r)=>u.captureException(e,r),captureMessage:(e,r)=>u.captureMessage(e,r),captureMetric:(e,r,i)=>u.captureMetric(e,r,i),captureCustomMetric:e=>u.captureCustomMetric(e),auditFetch:M,enableNetworkTracing:P,core:u}}var H=u;return F(V);})();
|
|
1
|
+
"use strict";var DevInspector=(()=>{var v=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},B=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!F.call(t,r)&&r!==n&&v(t,r,{get:()=>e[r],enumerable:!(i=V(e,r))||i.enumerable});return t};var j=t=>B(v({},"__esModule",{value:!0}),t);var Z={};L(Z,{audit:()=>a,auditFetch:()=>_,default:()=>Y,enableNetworkTracing:()=>Q});var k="9.3.0",H=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),D="https://api.devinspector.com.br/api/ingest/track",S="https://api.devinspector.com.br/api/ingest/apm",q=50,b=1e4,K=6,U=1e4,$=["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 $.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>=K)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(G(s)){r[s]="[REDACTED]";continue}r[s]=m(o,e+1,n)}return r}finally{n.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=m(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 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 P(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function X(t){return String(t??"").trim().slice(0,200)}function J(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function R(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function W(t){let e=R(t,50);if(e&&H.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 c(t){return m(t)}var M=class{constructor(){this.apiKey="";this.endpoint=D;this.apmEndpoint=S;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()||D,this.apmEndpoint=e.apmEndpoint?.trim()||S,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=W(e.technology),this.installationId=R(e.installationId,200),this.sdkVersion=R(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?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>q&&(this.breadcrumbs=this.breadcrumbs.slice(-q))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:c(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(/\/$/,""),u=n.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===n.origin&&o===u||s===i.origin&&o===d}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=T(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=A(e.statusCode)??0,s=w(e.durationMs)??0,o=P(e.ip),u={...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(u)})}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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(r)})}captureMetric(e,n,i={},r={}){let s=X(e);if(!s)return Promise.resolve();let o;try{o=J(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=T(r.method),o=A(r.statusCode??r.status),u=w(r.durationMs),d=P(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,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}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...f?{traceId:f}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let i=e instanceof Error?e:new Error(E(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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(E(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:c(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 u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},C="__DEVINSPECT_AUDIT_CORE_INSTANCE__",O=typeof globalThis<"u"?globalThis:{},a=O[C]||new M;O[C]=a;async function N(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=T(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let g={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let l=await i(t,g),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),I=l.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:h,requestId:o,traceId:u,spanId:d}}),I&&a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d}),l}catch(l){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d});let I=l instanceof Error?l:new Error(E(l));throw a.captureError(I,{url:r,method:s,type:n.errorType||"network_error",requestId:o,traceId:u,spanId:d}),l}}var x=null;async function _(t,e,n){return N(t,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:n||x||void 0})}function Q(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let n;try{n=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(n&&n.get&&!n.set||n&&n.writable===!1&&!n.set)return;let i=e.bind(globalThis);x=i;let r=function(s,o){return _(s,o,i)};try{n&&n.configurable?Object.defineProperty(globalThis,"fetch",{...n,value:r}):globalThis.fetch=r}catch{return}globalThis.fetch===r&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let t=window;t.DevInspector={init:e=>a.init(e),captureError:(e,n)=>a.captureError(e,n),captureException:(e,n)=>a.captureException(e,n),captureMessage:(e,n)=>a.captureMessage(e,n),captureMetric:(e,n,i)=>a.captureMetric(e,n,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:_,enableNetworkTracing:Q,core:a}}var Y=a;return j(Z);})();
|
package/dist/vanilla.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var v="https://api.devinspector.com.br/api/ingest/track",M="https://api.devinspector.com.br/api/ingest/apm";var k=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function P(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return k.some(t=>e.includes(t))}function m(r,e=0,t=new WeakSet){if(r==null)return r;if(typeof r=="string")return r.length>1e4?`${r.slice(0,1e4)}...[truncated]`:r;if(typeof r=="number"||typeof r=="boolean")return r;if(typeof r=="bigint")return String(r);if(typeof r=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof r!="object")return String(r);if(t.has(r))return"[Circular]";t.add(r);try{if(Array.isArray(r))return r.slice(0,100).map(s=>m(s,e+1,t));let i=r,n={};for(let[s,o]of Object.entries(i)){if(P(s)){n[s]="[REDACTED]";continue}n[s]=m(o,e+1,t)}return n}finally{t.delete(r)}}function I(r){if(r instanceof Error)return r.message||"Erro desconhecido";if(typeof r=="string")return r||"Erro desconhecido";try{let e=m(r);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function w(r){return r&&String(r).trim().toUpperCase()||void 0}function R(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function E(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function _(r){return r==null?void 0:String(r).trim().slice(0,100)||void 0}function C(r){return String(r??"").trim().slice(0,200)}function N(r){let e=Number(r);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(r){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${r}-${e.randomUUID()}`:`${r}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function c(r){return m(r)}var T=class{constructor(){this.apiKey="";this.endpoint=v;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()||v,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?m(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,t.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),a=t.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===t.origin&&o===a||s===i.origin&&o===d}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 t=w(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=R(e.statusCode)??0,s=E(e.durationMs)??0,o=_(e.ip),a={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:t,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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(a)})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return Promise.resolve();let i=E(e.durationMs)??0,n={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(n)})}captureMetric(e,t,i={},n={}){let s=C(e);if(!s)return Promise.resolve();let o;try{o=N(t)}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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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,t={}){let i=e?.message?.trim()||"Erro desconhecido",n={...t},s=w(n.method),o=R(n.statusCode??n.status),a=E(n.durationMs),d=_(n.ip),l=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,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||"",...l?{url:l}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...a!==void 0?{durationMs:a}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...h?{traceId:h}:{},...p?{spanId:p}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...n,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(I(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,1e4),environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...t,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 t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}).finally(()=>{typeof t=="function"&&t(i,n)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let i=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(i,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(I(t.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,t){if(!this.initialized||!this.apiKey)return Promise.resolve();let i={id:b("event"),endpoint:e,payload:c(t),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 t of e)t()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=m(t),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(a&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",S=typeof globalThis<"u"?globalThis:{},u=S[A]||new T;S[A]=u;async function U(r,e,t={}){let i=t.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof r=="string"?r:r instanceof URL?r.toString():String(r.url||""),s=w(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(n&&u.isIngestUrl(n))return i(r,e);let o=u.createRequestId(),a=u.createTraceId(),d=u.createSpanId(),l=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.headers:void 0));l.set("x-devinspector-request-id",o),l.set("x-devinspector-trace-id",a),l.set("x-devinspector-span-id",d);let g={...e,headers:l},h=typeof performance<"u"?performance.now():Date.now();try{let p=await i(r,g),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),y=p.status>=400||f>=u.getSlowThresholdMs();return u.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:f,requestId:o,traceId:a,spanId:d}}),y&&u.captureRequest({method:s,url:n,statusCode:p.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:a,spanId:d}),p}catch(p){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));u.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:a,spanId:d}}),u.captureRequest({method:s,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:a,spanId:d});let y=p instanceof Error?p:new Error(I(p));throw u.captureError(y,{url:n,method:s,type:t.errorType||"network_error",requestId:o,traceId:a,spanId:d}),p}}var q=null;async function D(r,e,t){return U(r,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||q||void 0})}function O(){if(typeof globalThis>"u")return;let r=globalThis;if(r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let t;try{t=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(t&&t.get&&!t.set||t&&t.writable===!1&&!t.set)return;let i=e.bind(globalThis);q=i;let n=function(s,o){return D(s,o,i)};try{t&&t.configurable?Object.defineProperty(globalThis,"fetch",{...t,value:n}):globalThis.fetch=n}catch{return}globalThis.fetch===n&&(r.__DEVINSPECTOR_NATIVE_FETCH__=i,r.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let r=window;r.DevInspector={init:e=>u.init(e),captureError:(e,t)=>u.captureError(e,t),captureException:(e,t)=>u.captureException(e,t),captureMessage:(e,t)=>u.captureMessage(e,t),captureMetric:(e,t,i)=>u.captureMetric(e,t,i),captureCustomMetric:e=>u.captureCustomMetric(e),auditFetch:D,enableNetworkTracing:O,core:u}}var F=u;export{u as audit,D as auditFetch,F as default,O as enableNetworkTracing};
|
|
1
|
+
var M="9.3.0",x=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),_="https://api.devinspector.com.br/api/ingest/track",k="https://api.devinspector.com.br/api/ingest/apm",D=50,b=1e4,Q=6,S=1e4,V=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function z(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return V.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>=Q)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(z(s)){r[s]="[REDACTED]";continue}r[s]=m(o,e+1,n)}return r}finally{n.delete(t)}}function w(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(t){return t&&String(t).trim().toUpperCase()||void 0}function 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 U(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function F(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 B(t){let e=T(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 c(t){return m(t)}var R=class{constructor(){this.apiKey="";this.endpoint=_;this.apmEndpoint=k;this.environment="production";this.sdkVersion=M;this.slowThresholdMs=300;this.requestTimeoutMs=S;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()||_,this.apmEndpoint=e.apmEndpoint?.trim()||k,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=B(e.technology),this.installationId=T(e.installationId,200),this.sdkVersion=T(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):S,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=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:c(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(/\/$/,""),u=n.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===n.origin&&o===u||s===i.origin&&o===d}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=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=q(e.statusCode)??0,s=v(e.durationMs)??0,o=U(e.ip),u={...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(u)})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return Promise.resolve();let i=v(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(r)})}captureMetric(e,n,i={},r={}){let s=F(e);if(!s)return Promise.resolve();let o;try{o=L(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=E(r.method),o=q(r.statusCode??r.status),u=v(r.durationMs),d=U(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,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}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...f?{traceId:f}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let i=e instanceof Error?e:new Error(w(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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(w(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:c(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 u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",P=typeof globalThis<"u"?globalThis:{},a=P[A]||new R;P[A]=a;async function C(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=E(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let g={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let l=await i(t,g),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),I=l.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:h,requestId:o,traceId:u,spanId:d}}),I&&a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d}),l}catch(l){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d});let I=l instanceof Error?l:new Error(w(l));throw a.captureError(I,{url:r,method:s,type:n.errorType||"network_error",requestId:o,traceId:u,spanId:d}),l}}var O=null;async function N(t,e,n){return C(t,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:n||O||void 0})}function j(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let n;try{n=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(n&&n.get&&!n.set||n&&n.writable===!1&&!n.set)return;let i=e.bind(globalThis);O=i;let r=function(s,o){return N(s,o,i)};try{n&&n.configurable?Object.defineProperty(globalThis,"fetch",{...n,value:r}):globalThis.fetch=r}catch{return}globalThis.fetch===r&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let t=window;t.DevInspector={init:e=>a.init(e),captureError:(e,n)=>a.captureError(e,n),captureException:(e,n)=>a.captureException(e,n),captureMessage:(e,n)=>a.captureMessage(e,n),captureMetric:(e,n,i)=>a.captureMetric(e,n,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:N,enableNetworkTracing:j,core:a}}var $=a;export{a as audit,N as auditFetch,$ as default,j as enableNetworkTracing};
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var r in e)E(t,r,{get:e[r],enumerable:!0})},O=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of P(e))!k.call(t,n)&&n!==r&&E(t,n,{get:()=>e[n],enumerable:!(i=D(e,n))||i.enumerable});return t};var N=t=>O(E({},"__esModule",{value:!0}),t);var G={};C(G,{DevInspectorVue:()=>z,audit:()=>a,auditFetch:()=>F,enableNetworkTracing:()=>H});module.exports=N(G);var M="https://api.devinspector.com.br/api/ingest/track",R="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 L(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return Q.some(r=>e.includes(r))}function m(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(L(s)){n[s]="[REDACTED]";continue}n[s]=m(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=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function w(t){return t&&String(t).trim().toUpperCase()||void 0}function A(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 S(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function B(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 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 c(t){return m(t)}var T=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?m(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:c(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(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===r.origin&&o===u||s===i.origin&&o===d}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=w(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=A(e.statusCode)??0,s=I(e.durationMs)??0,o=S(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(n)})}captureMetric(e,r,i={},n={}){let s=B(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},s=w(n.method),o=A(n.statusCode??n.status),u=I(n.durationMs),d=S(n.ip),l=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,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||"",...l?{url:l}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...h?{traceId:h}:{},...p?{spanId:p}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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:b("event"),endpoint:e,payload:c(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=m(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},U="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=typeof globalThis<"u"?globalThis:{},a=q[U]||new T;q[U]=a;async function _(t,e,r={}){let i=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),s=w(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),l=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));l.set("x-devinspector-request-id",o),l.set("x-devinspector-trace-id",u),l.set("x-devinspector-span-id",d);let g={...e,headers:l},h=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,g),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),y=p.status>=400||f>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:f,requestId:o,traceId:u,spanId:d}}),y&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d}),p}catch(p){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d});let y=p instanceof Error?p:new Error(v(p));throw a.captureError(y,{url:n,method:s,type:r.errorType||"network_error",requestId:o,traceId:u,spanId:d}),p}}async function F(t,e){return _(t,e,{errorType:"vue_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vue"})}var z={install(t,e){if(a.init(e),!t?.config)return;let r=t.config.errorHandler;t.config.errorHandler=(i,n,s)=>{let o=i instanceof Error?i:new Error(String(i)),u=n?.$options?.name||n?.$options?.__name||n?.$type?.name;a.addBreadcrumb({type:"vue_error",message:o.message||"Erro capturado pelo Vue",metadata:{component:u,vueInfo:s}}),a.captureError(o,{framework:"Vue",vueInfo:s,component:u}),typeof r=="function"?r(i,n,s):console.error(i)}}};function H(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let r;try{r=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(r&&r.get&&!r.set||r&&r.writable===!1&&!r.set)return;let i=e.bind(globalThis),n=function(s,o){return _(s,o,{errorType:"vue_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vue",nativeFetch:i})};try{r&&r.configurable?Object.defineProperty(globalThis,"fetch",{...r,value:n}):globalThis.fetch=n}catch{return}globalThis.fetch===n&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}0&&(module.exports={DevInspectorVue,audit,auditFetch,enableNetworkTracing});
|
|
1
|
+
"use strict";var v=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var L=(t,e)=>{for(var n in e)v(t,n,{get:e[n],enumerable:!0})},B=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!F.call(t,r)&&r!==n&&v(t,r,{get:()=>e[r],enumerable:!(i=V(e,r))||i.enumerable});return t};var j=t=>B(v({},"__esModule",{value:!0}),t);var Z={};L(Z,{audit:()=>a,auditFetch:()=>_,default:()=>Y,enableNetworkTracing:()=>Q});module.exports=j(Z);var k="9.3.0",H=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),D="https://api.devinspector.com.br/api/ingest/track",S="https://api.devinspector.com.br/api/ingest/apm",q=50,b=1e4,K=6,U=1e4,$=["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 $.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>=K)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(G(s)){r[s]="[REDACTED]";continue}r[s]=m(o,e+1,n)}return r}finally{n.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=m(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 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 P(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function X(t){return String(t??"").trim().slice(0,200)}function J(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function R(t,e=200){return t==null?void 0:String(t).trim().slice(0,e)||void 0}function W(t){let e=R(t,50);if(e&&H.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 c(t){return m(t)}var M=class{constructor(){this.apiKey="";this.endpoint=D;this.apmEndpoint=S;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()||D,this.apmEndpoint=e.apmEndpoint?.trim()||S,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=W(e.technology),this.installationId=R(e.installationId,200),this.sdkVersion=R(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?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>q&&(this.breadcrumbs=this.breadcrumbs.slice(-q))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:c(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(/\/$/,""),u=n.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===n.origin&&o===u||s===i.origin&&o===d}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=T(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=A(e.statusCode)??0,s=w(e.durationMs)??0,o=P(e.ip),u={...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(u)})}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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(r)})}captureMetric(e,n,i={},r={}){let s=X(e);if(!s)return Promise.resolve();let o;try{o=J(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=T(r.method),o=A(r.statusCode??r.status),u=w(r.durationMs),d=P(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,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}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...f?{traceId:f}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let i=e instanceof Error?e:new Error(E(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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(E(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:c(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 u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},C="__DEVINSPECT_AUDIT_CORE_INSTANCE__",O=typeof globalThis<"u"?globalThis:{},a=O[C]||new M;O[C]=a;async function N(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=T(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let g={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let l=await i(t,g),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),I=l.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:h,requestId:o,traceId:u,spanId:d}}),I&&a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d}),l}catch(l){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d});let I=l instanceof Error?l:new Error(E(l));throw a.captureError(I,{url:r,method:s,type:n.errorType||"network_error",requestId:o,traceId:u,spanId:d}),l}}var x=null;async function _(t,e,n){return N(t,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:n||x||void 0})}function Q(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let n;try{n=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(n&&n.get&&!n.set||n&&n.writable===!1&&!n.set)return;let i=e.bind(globalThis);x=i;let r=function(s,o){return _(s,o,i)};try{n&&n.configurable?Object.defineProperty(globalThis,"fetch",{...n,value:r}):globalThis.fetch=r}catch{return}globalThis.fetch===r&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let t=window;t.DevInspector={init:e=>a.init(e),captureError:(e,n)=>a.captureError(e,n),captureException:(e,n)=>a.captureException(e,n),captureMessage:(e,n)=>a.captureMessage(e,n),captureMetric:(e,n,i)=>a.captureMetric(e,n,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:_,enableNetworkTracing:Q,core:a}}var Y=a;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
package/dist/vue.d.cts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { audit } from './index.cjs';
|
|
2
|
+
export { InitOptions } from './index.cjs';
|
|
3
3
|
|
|
4
|
-
declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
5
|
-
declare const DevInspectorVue: {
|
|
6
|
-
install(app: any, options: InitOptions): void;
|
|
7
|
-
};
|
|
4
|
+
declare function auditFetch(input: RequestInfo | URL, init?: RequestInit, fetchImpl?: typeof fetch): Promise<Response>;
|
|
8
5
|
declare function enableNetworkTracing(): void;
|
|
9
6
|
|
|
10
|
-
export {
|
|
7
|
+
export { audit, auditFetch, audit as default, enableNetworkTracing };
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { audit } from './index.js';
|
|
2
|
+
export { InitOptions } from './index.js';
|
|
3
3
|
|
|
4
|
-
declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
5
|
-
declare const DevInspectorVue: {
|
|
6
|
-
install(app: any, options: InitOptions): void;
|
|
7
|
-
};
|
|
4
|
+
declare function auditFetch(input: RequestInfo | URL, init?: RequestInit, fetchImpl?: typeof fetch): Promise<Response>;
|
|
8
5
|
declare function enableNetworkTracing(): void;
|
|
9
6
|
|
|
10
|
-
export {
|
|
7
|
+
export { audit, auditFetch, audit as default, enableNetworkTracing };
|
package/dist/vue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var _="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 m(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>m(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(D(s)){n[s]="[REDACTED]";continue}n[s]=m(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=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function v(t){return t&&String(t).trim().toUpperCase()||void 0}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function E(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 P(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 c(t){return m(t)}var w=class{constructor(){this.apiKey="";this.endpoint=_;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()||_,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?m(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?m(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:c(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(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===r.origin&&o===u||s===i.origin&&o===d}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=R(e.statusCode)??0,s=E(e.durationMs)??0,o=A(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(n)})}captureMetric(e,r,i={},n={}){let s=P(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=R(n.statusCode??n.status),u=E(n.durationMs),d=A(n.ip),l=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,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||"",...l?{url:l}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...h?{traceId:h}:{},...p?{spanId:p}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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:c(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=m(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},S="__DEVINSPECT_AUDIT_CORE_INSTANCE__",U=typeof globalThis<"u"?globalThis:{},a=U[S]||new w;U[S]=a;async function T(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&&a.isIngestUrl(n))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),l=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));l.set("x-devinspector-request-id",o),l.set("x-devinspector-trace-id",u),l.set("x-devinspector-span-id",d);let g={...e,headers:l},h=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,g),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h)),y=p.status>=400||f>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:f,requestId:o,traceId:u,spanId:d}}),y&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d}),p}catch(p){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-h));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d});let y=p instanceof Error?p:new Error(I(p));throw a.captureError(y,{url:n,method:s,type:r.errorType||"network_error",requestId:o,traceId:u,spanId:d}),p}}async function N(t,e){return T(t,e,{errorType:"vue_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vue"})}var Q={install(t,e){if(a.init(e),!t?.config)return;let r=t.config.errorHandler;t.config.errorHandler=(i,n,s)=>{let o=i instanceof Error?i:new Error(String(i)),u=n?.$options?.name||n?.$options?.__name||n?.$type?.name;a.addBreadcrumb({type:"vue_error",message:o.message||"Erro capturado pelo Vue",metadata:{component:u,vueInfo:s}}),a.captureError(o,{framework:"Vue",vueInfo:s,component:u}),typeof r=="function"?r(i,n,s):console.error(i)}}};function L(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let r;try{r=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(r&&r.get&&!r.set||r&&r.writable===!1&&!r.set)return;let i=e.bind(globalThis),n=function(s,o){return T(s,o,{errorType:"vue_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vue",nativeFetch:i})};try{r&&r.configurable?Object.defineProperty(globalThis,"fetch",{...r,value:n}):globalThis.fetch=n}catch{return}globalThis.fetch===n&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}export{Q as DevInspectorVue,a as audit,N as auditFetch,L as enableNetworkTracing};
|
|
1
|
+
var M="9.3.0",x=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),_="https://api.devinspector.com.br/api/ingest/track",k="https://api.devinspector.com.br/api/ingest/apm",D=50,b=1e4,Q=6,S=1e4,V=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function z(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return V.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>=Q)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(z(s)){r[s]="[REDACTED]";continue}r[s]=m(o,e+1,n)}return r}finally{n.delete(t)}}function w(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=m(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(t){return t&&String(t).trim().toUpperCase()||void 0}function 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 U(t){return t==null?void 0:String(t).trim().slice(0,100)||void 0}function F(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 B(t){let e=T(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 c(t){return m(t)}var R=class{constructor(){this.apiKey="";this.endpoint=_;this.apmEndpoint=k;this.environment="production";this.sdkVersion=M;this.slowThresholdMs=300;this.requestTimeoutMs=S;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()||_,this.apmEndpoint=e.apmEndpoint?.trim()||k,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=B(e.technology),this.installationId=T(e.installationId,200),this.sdkVersion=T(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):S,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=>c(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:c(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(/\/$/,""),u=n.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===n.origin&&o===u||s===i.origin&&o===d}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=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=q(e.statusCode)??0,s=v(e.durationMs)??0,o=U(e.ip),u={...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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(u)})}captureDbQuery(e){let n=String(e.operation||"").trim();if(!n)return Promise.resolve();let i=v(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(r)})}captureMetric(e,n,i={},r={}){let s=F(e);if(!s)return Promise.resolve();let o;try{o=L(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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=E(r.method),o=q(r.statusCode??r.status),u=v(r.durationMs),d=U(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,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}:{},...u!==void 0?{durationMs:u}:{},...d?{ip:d}:{},...g?{requestId:g}:{},...f?{traceId:f}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...r,timestamp:new Date().toISOString()})})}captureException(e,n={}){let i=e instanceof Error?e:new Error(w(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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(w(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:c(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 u=typeof window<"u"&&typeof window.document<"u",d={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};if(u&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",P=typeof globalThis<"u"?globalThis:{},a=P[A]||new R;P[A]=a;async function C(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=E(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let g={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let l=await i(t,g),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),I=l.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:h,requestId:o,traceId:u,spanId:d}}),I&&a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d}),l}catch(l){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f));a.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:u,spanId:d}}),a.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:n.defaultUserAgent,requestId:o,traceId:u,spanId:d});let I=l instanceof Error?l:new Error(w(l));throw a.captureError(I,{url:r,method:s,type:n.errorType||"network_error",requestId:o,traceId:u,spanId:d}),l}}var O=null;async function N(t,e,n){return C(t,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:n||O||void 0})}function j(){if(typeof globalThis>"u")return;let t=globalThis;if(t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let n;try{n=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(n&&n.get&&!n.set||n&&n.writable===!1&&!n.set)return;let i=e.bind(globalThis);O=i;let r=function(s,o){return N(s,o,i)};try{n&&n.configurable?Object.defineProperty(globalThis,"fetch",{...n,value:r}):globalThis.fetch=r}catch{return}globalThis.fetch===r&&(t.__DEVINSPECTOR_NATIVE_FETCH__=i,t.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let t=window;t.DevInspector={init:e=>a.init(e),captureError:(e,n)=>a.captureError(e,n),captureException:(e,n)=>a.captureException(e,n),captureMessage:(e,n)=>a.captureMessage(e,n),captureMetric:(e,n,i)=>a.captureMetric(e,n,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:N,enableNetworkTracing:j,core:a}}var $=a;export{a as audit,N as auditFetch,$ as default,j as enableNetworkTracing};
|