@xcodleox/devinspector 8.0.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular.cjs +1 -1
- package/dist/angular.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +59 -23
- package/dist/index.d.ts +59 -23
- package/dist/index.js +1 -1
- package/dist/next.cjs +1 -1
- package/dist/next.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.js +1 -1
- package/dist/react-native.cjs +1 -1
- package/dist/react-native.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/svelte.cjs +1 -1
- package/dist/svelte.d.cts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +1 -1
- package/dist/vanilla.cjs +1 -1
- package/dist/vanilla.global.js +1 -1
- package/dist/vanilla.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +1 -1
- package/package.json +3 -2
package/dist/svelte.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var b=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},n=this.truncate(r,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let r=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let o=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let n=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),r.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,n=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(d=>this.truncate(d,r,n));let o={};for(let[d,a]of Object.entries(e))o[d]=this.truncate(a,r,n);return o}return e}captureError(e,r={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),d=r.requestId,a=r.traceId,c=r.spanId,u={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:d,traceId:a,spanId:c,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(u)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},g="__DEVINSPECT_AUDIT_CORE_INSTANCE__",I=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[g]||(t[g]=new b),t[g]},i=I();async function y(t,e,r){let n=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof t=="string"?s=t:t instanceof URL?s=t.toString():typeof t=="object"&&t!==null&&"url"in t&&(s=t.url),s&&i.isIngestUrl(s))return n(t,e);let o=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),d=i.createRequestId(),a=i.createTraceId(),c=i.createSpanId(),u=new Headers(e?.headers||(typeof t=="object"&&t!==null&&"headers"in t?t.headers:void 0));u.set("x-devinspector-request-id",d),u.set("x-devinspector-trace-id",a),u.set("x-devinspector-span-id",c);let p={...e,headers:u},f=typeof performance<"u"?performance.now():Date.now();try{let l=await n(t,p),h=Math.round((typeof performance<"u"?performance.now():Date.now())-f),w=i.getSlowThresholdMs();return(l.status>=400||h>=w)&&i.captureRequest({method:o,url:s,statusCode:l.status,durationMs:h,route:s,requestId:d,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:l.status,durationMs:h,requestId:d,traceId:a,spanId:c}}),l}catch(l){let h=Math.round((typeof performance<"u"?performance.now():Date.now())-f);throw i.captureRequest({method:o,url:s,statusCode:0,durationMs:h,route:s,requestId:d,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),i.captureException(l instanceof Error?l:new Error(String(l)),{url:s,method:o,type:r?.errorType||"network_error",requestId:d,traceId:a,spanId:c}),i.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:h,requestId:d,traceId:a,spanId:c}}),l}}function R(t){i.init(t)}async function T(t,e){return y(t,e,{errorType:"svelte_network_error"})}async function _({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),n=t.request?.method||"GET",s=t.url?.pathname||t.url?.href||"/",o=t.route?.id||s;if(s&&i.isIngestUrl(s))return e(t);let d=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"",a=m(t.request,"x-devinspector-request-id")||i.createRequestId(),c=m(t.request,"x-devinspector-trace-id")||i.createTraceId(),u=m(t.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"http",message:`${n} ${s}`,metadata:{framework:"SvelteKit",phase:"start",requestId:a,traceId:c,spanId:u,route:o}});try{let p=await e(t),f=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return(p.status>=400||f>=300)&&i.captureRequest({method:n,url:s,statusCode:p.status,durationMs:f,route:o,userAgent:d,requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http",message:`${n} ${s}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:p.status,durationMs:f,requestId:a,traceId:c,spanId:u,route:o}}),p}catch(p){let f=Math.round((typeof performance<"u"?performance.now():Date.now())-r);i.captureRequest({method:n,url:s,statusCode:500,durationMs:f,route:o,userAgent:d,requestId:a,traceId:c,spanId:u}),i.addBreadcrumb({type:"http_error",message:`${n} ${s}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:f,requestId:a,traceId:c,spanId:u,route:o}});let l=p instanceof Error?p:new Error(String(p));throw i.captureError(l,{framework:"SvelteKit",url:s,method:n,route:o,requestId:a,traceId:c,spanId:u}),p}}function A({error:t,event:e,status:r,message:n}){let s=t instanceof Error?t:new Error(String(t||n||"Erro SvelteKit")),o=m(e?.request,"x-devinspector-request-id")||i.createRequestId(),d=m(e?.request,"x-devinspector-trace-id")||i.createTraceId(),a=m(e?.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"sveltekit_error",message:s.message||"Erro SvelteKit",metadata:{status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:d,spanId:a}}),i.captureError(s,{framework:"SvelteKit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:d,spanId:a})}function x(){let t=globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=function(r,n){return y(r,n,{errorType:"svelte_network_error",nativeFetch:e})}}function m(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]||t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}export{i as audit,T as auditFetch,_ as auditHandle,x as enableNetworkTracing,A as handleSvelteKitError,R as initSvelteDevInspector};
|
|
1
|
+
var _="https://api.devinspector.com.br/api/ingest/track",M="https://api.devinspector.com.br/api/ingest/apm";var U=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function D(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return U.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(D(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 I(t){return t&&String(t).trim().toUpperCase()||void 0}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function S(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function k(t){return String(t??"").trim().slice(0,200)}function P(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function y(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function c(t){return h(t)}var T=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?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=>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),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=I(e.method)||"GET",s=String(e.url||"").trim();if(!s)return Promise.resolve();let n=R(e.statusCode)??0,i=S(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(o)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let s=S(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:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c(n)})}captureMetric(e,r,s={},n={}){let i=k(e);if(!i)return Promise.resolve();let o;try{o=P(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:i,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...s,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let s=e?.message?.trim()||"Erro desconhecido",n={...r},i=I(n.method),o=R(n.statusCode??n.status),u=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:s,stackTrace:e?.stack||"",...u?{url:u}:{},...i?{method:i}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:c(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:c({...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: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?.((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:c(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)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=typeof globalThis<"u"?globalThis:{},a=q[A]||new T;q[A]=a;async function v(t,e,r={}){let s=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!s)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),i=I(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return s(t,e);let o=a.createRequestId(),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 l={...e,headers:p},f=typeof performance<"u"?performance.now():Date.now();try{let m=await s(t,l),g=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-f)),E=m.status>=400||g>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:m.status,durationMs:g,requestId:o,traceId:u,spanId:d}}),E&&a.captureRequest({method:i,url:n,statusCode:m.status,durationMs:g,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:d}),m}catch(m){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=m instanceof Error?m:new Error(w(m));throw a.captureError(E,{url:n,method:i,type:r.errorType||"network_error"}),m}}function N(t){a.init(t)}async function x(t,e){return v(t,e,{errorType:"svelte_network_error",defaultUserAgent:"SvelteKit"})}async function Q({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(),p=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:p,route:i}});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:s,url:n,statusCode:l.status,durationMs:f,route:i,userAgent:o,requestId:u,traceId:d,spanId:p}),a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:l.status,durationMs:f,requestId:u,traceId:d,spanId:p,route:i}}),l}catch(l){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:p}),a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:f,requestId:u,traceId:d,spanId:p,route:i}});let m=l instanceof Error?l:new Error(String(l));throw a.captureError(m,{framework:"SvelteKit",url:n,method:s,route:i,requestId:u,traceId:d,spanId:p}),l}}function B({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:{status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:i,traceId:o,spanId:u}}),a.captureError(n,{framework:"SvelteKit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:i,traceId:o,spanId:u})}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 s=e.bind(globalThis),n=function(i,o){return v(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,x as auditFetch,Q as auditHandle,L as enableNetworkTracing,B as handleSvelteKitError,N as initSvelteDevInspector};
|
package/dist/vanilla.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var h=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var t in e)h(r,t,{get:e[t],enumerable:!0})},q=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!_.call(r,s)&&s!==t&&h(r,s,{get:()=>e[s],enumerable:!(n=R(e,s))||n.enumerable});return r};var x=r=>q(h({},"__esModule",{value:!0}),r);var k={};A(k,{audit:()=>o,auditFetch:()=>g,default:()=>D,enableNetworkTracing:()=>I});module.exports=x(k);var m=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},n=this.truncate(t,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let t=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),t&&t(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,n));let i={};for(let[a,c]of Object.entries(e))i[a]=this.truncate(c,t,n);return i}return e}captureError(e,t={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),a=t.requestId,c=t.traceId,u=t.spanId,p={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...t,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",M=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[f]||(r[f]=new m),r[f]},o=M();async function y(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof r=="string"?s=r:r instanceof URL?s=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(s=r.url),s&&o.isIngestUrl(s))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),a=o.createRequestId(),c=o.createTraceId(),u=o.createSpanId(),p=new Headers(e?.headers||(typeof r=="object"&&r!==null&&"headers"in r?r.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",u);let v={...e,headers:p},b=typeof performance<"u"?performance.now():Date.now();try{let d=await n(r,v),l=Math.round((typeof performance<"u"?performance.now():Date.now())-b),E=o.getSlowThresholdMs();return(d.status>=400||l>=E)&&o.captureRequest({method:i,url:s,statusCode:d.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:d.status,durationMs:l,requestId:a,traceId:c,spanId:u}}),d}catch(d){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw o.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:i,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),o.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:u}}),d}}var w=null;async function g(r,e,t){return y(r,e,{errorType:"vanilla_network_error",nativeFetch:t||w||void 0})}function I(){let r=typeof window<"u"?window:globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);w=e,r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(...t){let[n,s]=t;return g(n,s,e)}}typeof window<"u"&&(window.DevInspector={init:r=>o.init(r),captureError:(r,e)=>o.captureError(r,e),captureException:(r,e)=>o.captureException(r,e),captureMessage:(r,e)=>o.captureMessage(r,e),auditFetch:g,enableNetworkTracing:I,core:o});var D=o;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
|
1
|
+
"use strict";var b=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var O=(r,e)=>{for(var t in e)b(r,t,{get:e[t],enumerable:!0})},Q=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of C(e))!N.call(r,n)&&n!==t&&b(r,n,{get:()=>e[n],enumerable:!(i=k(e,n))||i.enumerable});return r};var x=r=>Q(b({},"__esModule",{value:!0}),r);var H={};O(H,{audit:()=>a,auditFetch:()=>T,default:()=>G,enableNetworkTracing:()=>q});module.exports=x(H);var v="https://api.devinspector.com.br/api/ingest/track",M="https://api.devinspector.com.br/api/ingest/apm";var F=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function L(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return F.some(t=>e.includes(t))}function l(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=>l(s,e+1,t));let i=r,n={};for(let[s,o]of Object.entries(i)){if(L(s)){n[s]="[REDACTED]";continue}n[s]=l(o,e+1,t)}return n}finally{t.delete(r)}}function y(r){if(r instanceof Error)return r.message||"Erro desconhecido";if(typeof r=="string")return r||"Erro desconhecido";try{let e=l(r);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(r){return r&&String(r).trim().toUpperCase()||void 0}function R(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function _(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function B(r){return String(r??"").trim().slice(0,200)}function z(r){let e=Number(r);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function h(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 u(r){return l(r)}var w=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?l(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?l(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>u(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,t.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),c=t.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===t.origin&&o===c||s===i.origin&&o===d}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let t=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=R(e.statusCode)??0,s=_(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:t,url:i,statusCode:n,durationMs:s,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(o)})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return Promise.resolve();let i=_(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(n)})}captureMetric(e,t,i={},n={}){let s=B(e);if(!s)return Promise.resolve();let o;try{o=z(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let i=e?.message?.trim()||"Erro desconhecido",n={...t},s=E(n.method),o=R(n.statusCode??n.status),c=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...c?{url:c}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...n,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(y(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...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(y(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:h("event"),endpoint:e,payload:u(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=l(t),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let c=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(c&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",U=typeof globalThis<"u"?globalThis:{},a=U[A]||new w;U[A]=a;async function S(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=E(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return i(r,e);let o=a.createRequestId(),c=a.createTraceId(),d=a.createSpanId(),f=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.headers:void 0));f.set("x-devinspector-request-id",o),f.set("x-devinspector-trace-id",c),f.set("x-devinspector-span-id",d);let P={...e,headers:f},I=typeof performance<"u"?performance.now():Date.now();try{let p=await i(r,P),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I)),g=p.status>=400||m>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:m,requestId:o,traceId:c,spanId:d}}),g&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:d}),p}catch(p){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:o,traceId:c,spanId:d}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:d});let g=p instanceof Error?p:new Error(y(p));throw a.captureError(g,{url:n,method:s,type:t.errorType||"network_error"}),p}}var D=null;async function T(r,e,t){return S(r,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||D||void 0})}function q(){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);D=i;let n=function(s,o){return T(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=>a.init(e),captureError:(e,t)=>a.captureError(e,t),captureException:(e,t)=>a.captureException(e,t),captureMessage:(e,t)=>a.captureMessage(e,t),captureMetric:(e,t,i)=>a.captureMetric(e,t,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:T,enableNetworkTracing:q,core:a}}var G=a;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
package/dist/vanilla.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var DevInspector=(()=>{var h=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var t in e)h(r,t,{get:e[t],enumerable:!0})},q=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!_.call(r,s)&&s!==t&&h(r,s,{get:()=>e[s],enumerable:!(n=R(e,s))||n.enumerable});return r};var x=r=>q(h({},"__esModule",{value:!0}),r);var k={};A(k,{audit:()=>o,auditFetch:()=>g,default:()=>D,enableNetworkTracing:()=>I});var m=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},n=this.truncate(t,2e3);this.breadcrumbs.push(n),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),n={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(n)}captureDbQuery(e){let t=this.getContext(),n=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${n}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:n,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:n,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((n,s)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),t&&t(n,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let s=n instanceof Error?n:new Error(String(n));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(n.has(s))return"[Circular Reference]";if(n.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,n));let i={};for(let[a,c]of Object.entries(e))i[a]=this.truncate(c,t,n);return i}return e}captureError(e,t={}){let n=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),a=t.requestId,c=t.traceId,u=t.spanId,p={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...t,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:n.environment,release:n.release,user:n.user,breadcrumbs:n.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:n.environment,release:n.release,timestamp:n.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},f="__DEVINSPECT_AUDIT_CORE_INSTANCE__",M=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[f]||(r[f]=new m),r[f]},o=M();async function y(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof r=="string"?s=r:r instanceof URL?s=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(s=r.url),s&&o.isIngestUrl(s))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),a=o.createRequestId(),c=o.createTraceId(),u=o.createSpanId(),p=new Headers(e?.headers||(typeof r=="object"&&r!==null&&"headers"in r?r.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",u);let v={...e,headers:p},b=typeof performance<"u"?performance.now():Date.now();try{let d=await n(r,v),l=Math.round((typeof performance<"u"?performance.now():Date.now())-b),E=o.getSlowThresholdMs();return(d.status>=400||l>=E)&&o.captureRequest({method:i,url:s,statusCode:d.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:d.status,durationMs:l,requestId:a,traceId:c,spanId:u}}),d}catch(d){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw o.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:i,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),o.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:u}}),d}}var w=null;async function g(r,e,t){return y(r,e,{errorType:"vanilla_network_error",nativeFetch:t||w||void 0})}function I(){let r=typeof window<"u"?window:globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);w=e,r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(...t){let[n,s]=t;return g(n,s,e)}}typeof window<"u"&&(window.DevInspector={init:r=>o.init(r),captureError:(r,e)=>o.captureError(r,e),captureException:(r,e)=>o.captureException(r,e),captureMessage:(r,e)=>o.captureMessage(r,e),auditFetch:g,enableNetworkTracing:I,core:o});var D=o;return x(k);})();
|
|
1
|
+
"use strict";var DevInspector=(()=>{var b=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var O=(r,e)=>{for(var t in e)b(r,t,{get:e[t],enumerable:!0})},Q=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of C(e))!N.call(r,n)&&n!==t&&b(r,n,{get:()=>e[n],enumerable:!(i=k(e,n))||i.enumerable});return r};var x=r=>Q(b({},"__esModule",{value:!0}),r);var H={};O(H,{audit:()=>a,auditFetch:()=>T,default:()=>G,enableNetworkTracing:()=>q});var v="https://api.devinspector.com.br/api/ingest/track",M="https://api.devinspector.com.br/api/ingest/apm";var F=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function L(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return F.some(t=>e.includes(t))}function l(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=>l(s,e+1,t));let i=r,n={};for(let[s,o]of Object.entries(i)){if(L(s)){n[s]="[REDACTED]";continue}n[s]=l(o,e+1,t)}return n}finally{t.delete(r)}}function y(r){if(r instanceof Error)return r.message||"Erro desconhecido";if(typeof r=="string")return r||"Erro desconhecido";try{let e=l(r);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(r){return r&&String(r).trim().toUpperCase()||void 0}function R(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function _(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function B(r){return String(r??"").trim().slice(0,200)}function z(r){let e=Number(r);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function h(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 u(r){return l(r)}var w=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?l(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?l(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>u(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,t.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),c=t.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===t.origin&&o===c||s===i.origin&&o===d}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let t=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=R(e.statusCode)??0,s=_(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:t,url:i,statusCode:n,durationMs:s,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(o)})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return Promise.resolve();let i=_(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(n)})}captureMetric(e,t,i={},n={}){let s=B(e);if(!s)return Promise.resolve();let o;try{o=z(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let i=e?.message?.trim()||"Erro desconhecido",n={...t},s=E(n.method),o=R(n.statusCode??n.status),c=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...c?{url:c}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...n,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(y(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...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(y(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:h("event"),endpoint:e,payload:u(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=l(t),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let c=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(c&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",U=typeof globalThis<"u"?globalThis:{},a=U[A]||new w;U[A]=a;async function S(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=E(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return i(r,e);let o=a.createRequestId(),c=a.createTraceId(),d=a.createSpanId(),f=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.headers:void 0));f.set("x-devinspector-request-id",o),f.set("x-devinspector-trace-id",c),f.set("x-devinspector-span-id",d);let P={...e,headers:f},I=typeof performance<"u"?performance.now():Date.now();try{let p=await i(r,P),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I)),g=p.status>=400||m>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:m,requestId:o,traceId:c,spanId:d}}),g&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:d}),p}catch(p){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:o,traceId:c,spanId:d}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:d});let g=p instanceof Error?p:new Error(y(p));throw a.captureError(g,{url:n,method:s,type:t.errorType||"network_error"}),p}}var D=null;async function T(r,e,t){return S(r,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||D||void 0})}function q(){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);D=i;let n=function(s,o){return T(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=>a.init(e),captureError:(e,t)=>a.captureError(e,t),captureException:(e,t)=>a.captureException(e,t),captureMessage:(e,t)=>a.captureMessage(e,t),captureMetric:(e,t,i)=>a.captureMetric(e,t,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:T,enableNetworkTracing:q,core:a}}var G=a;return x(H);})();
|
package/dist/vanilla.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let t={...e,timestamp:new Date().toISOString()},r=this.truncate(t,2e3);this.breadcrumbs.push(r),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let t=this.getContext(),r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({environment:t.environment,timestamp:t.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(r)}captureDbQuery(e){let t=this.getContext(),r=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",i={type:"db_query",message:`Database operation [${r}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:r,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:r,durationMs:e.durationMs,environment:t.environment,timestamp:t.timestamp},5e3)};this.send(i)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((r,s)=>{let i=r instanceof Error?r:new Error(String(r?.message||r||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!s}),t&&t(r,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let r=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(r,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",r=>{this.captureError(r,{type:"uncaught_exception"})}),t.on("unhandledRejection",r=>{let s=r instanceof Error?r:new Error(String(r));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,r=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(r.has(s))return"[Circular Reference]";if(r.add(s),Array.isArray(e))return e.map(a=>this.truncate(a,t,r));let i={};for(let[a,c]of Object.entries(e))i[a]=this.truncate(c,t,r);return i}return e}captureError(e,t={}){let r=e?.message||"Erro Desconhecido",s=e?.stack||"",i=this.getContext(),a=t.requestId,c=t.traceId,u=t.spanId,p={type:"error",message:this.truncate(r,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:a,traceId:c,spanId:u,environment:i.environment,release:i.release,user:i.user,breadcrumbs:i.breadcrumbs,metadata:this.truncate({...t,environment:i.environment,release:i.release,timestamp:i.timestamp},5e3)};this.send(p)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let r=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:t.requestId,traceId:t.traceId,spanId:t.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...t,level:"info",environment:r.environment,release:r.release,timestamp:r.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},h="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[h]||(n[h]=new f),n[h]},o=v();async function g(n,e,t){let r=t?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&o.isIngestUrl(s))return r(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),a=o.createRequestId(),c=o.createTraceId(),u=o.createSpanId(),p=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",u);let w={...e,headers:p},m=typeof performance<"u"?performance.now():Date.now();try{let d=await r(n,w),l=Math.round((typeof performance<"u"?performance.now():Date.now())-m),I=o.getSlowThresholdMs();return(d.status>=400||l>=I)&&o.captureRequest({method:i,url:s,statusCode:d.status,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{statusCode:d.status,durationMs:l,requestId:a,traceId:c,spanId:u}}),d}catch(d){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-m);throw o.captureRequest({method:i,url:s,statusCode:0,durationMs:l,route:s,requestId:a,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),o.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:i,type:t?.errorType||"network_error",requestId:a,traceId:c,spanId:u}),o.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{durationMs:l,requestId:a,traceId:c,spanId:u}}),d}}var b=null;async function y(n,e,t){return g(n,e,{errorType:"vanilla_network_error",nativeFetch:t||b||void 0})}function E(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);b=e,n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(...t){let[r,s]=t;return y(r,s,e)}}typeof window<"u"&&(window.DevInspector={init:n=>o.init(n),captureError:(n,e)=>o.captureError(n,e),captureException:(n,e)=>o.captureException(n,e),captureMessage:(n,e)=>o.captureMessage(n,e),auditFetch:y,enableNetworkTracing:E,core:o});var A=o;export{o as audit,y as auditFetch,A as default,E as enableNetworkTracing};
|
|
1
|
+
var T="https://api.devinspector.com.br/api/ingest/track",I="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 P(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return q.some(t=>e.includes(t))}function l(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=>l(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]=l(o,e+1,t)}return n}finally{t.delete(r)}}function b(r){if(r instanceof Error)return r.message||"Erro desconhecido";if(typeof r=="string")return r||"Erro desconhecido";try{let e=l(r);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function y(r){return r&&String(r).trim().toUpperCase()||void 0}function v(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function M(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function k(r){return String(r??"").trim().slice(0,200)}function C(r){let e=Number(r);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function h(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 u(r){return l(r)}var E=class{constructor(){this.apiKey="";this.endpoint=T;this.apmEndpoint=I;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||T,this.apmEndpoint=e.apmEndpoint?.trim()||I,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(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?l(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>u(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,t.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),c=t.pathname.replace(/\/$/,""),d=i.pathname.replace(/\/$/,"");return s===t.origin&&o===c||s===i.origin&&o===d}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let t=y(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=v(e.statusCode)??0,s=M(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:t,url:i,statusCode:n,durationMs:s,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(o)})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return Promise.resolve();let i=M(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u(n)})}captureMetric(e,t,i={},n={}){let s=k(e);if(!s)return Promise.resolve();let o;try{o=C(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let i=e?.message?.trim()||"Erro desconhecido",n={...t},s=y(n.method),o=v(n.statusCode??n.status),c=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...c?{url:c}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...n,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(b(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:u(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:u({...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(b(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:h("event"),endpoint:e,payload:u(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=l(t),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let c=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(c&&(d.keepalive=!0),!(await i(e,d)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},R="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=typeof globalThis<"u"?globalThis:{},a=_[R]||new E;_[R]=a;async function A(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=y(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return i(r,e);let o=a.createRequestId(),c=a.createTraceId(),d=a.createSpanId(),f=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.headers:void 0));f.set("x-devinspector-request-id",o),f.set("x-devinspector-trace-id",c),f.set("x-devinspector-span-id",d);let D={...e,headers:f},w=typeof performance<"u"?performance.now():Date.now();try{let p=await i(r,D),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-w)),g=p.status>=400||m>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:m,requestId:o,traceId:c,spanId:d}}),g&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:d}),p}catch(p){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-w));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:o,traceId:c,spanId:d}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:d});let g=p instanceof Error?p:new Error(b(p));throw a.captureError(g,{url:n,method:s,type:t.errorType||"network_error"}),p}}var U=null;async function S(r,e,t){return A(r,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||U||void 0})}function N(){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);U=i;let n=function(s,o){return S(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=>a.init(e),captureError:(e,t)=>a.captureError(e,t),captureException:(e,t)=>a.captureException(e,t),captureMessage:(e,t)=>a.captureMessage(e,t),captureMetric:(e,t,i)=>a.captureMetric(e,t,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:S,enableNetworkTracing:N,core:a}}var x=a;export{a as audit,S as auditFetch,x as default,N as enableNetworkTracing};
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var _=(n,e)=>{for(var r in e)m(n,r,{get:e[r],enumerable:!0})},T=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of v(e))!E.call(n,s)&&s!==r&&m(n,s,{get:()=>e[s],enumerable:!(t=I(e,s))||t.enumerable});return n};var R=n=>T(m({},"__esModule",{value:!0}),n);var M={};_(M,{DevInspectorVue:()=>x,audit:()=>a,auditFetch:()=>A,enableNetworkTracing:()=>D});module.exports=R(M);var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(i=>this.truncate(i,r,t));let o={};for(let[i,c]of Object.entries(e))o[i]=this.truncate(c,r,t);return o}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),i=r.requestId,c=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:i,traceId:c,spanId:u,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},h="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[h]||(n[h]=new f),n[h]},a=q();async function g(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&a.isIngestUrl(s))return t(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=a.createRequestId(),c=a.createTraceId(),u=a.createSpanId(),l=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));l.set("x-devinspector-request-id",i),l.set("x-devinspector-trace-id",c),l.set("x-devinspector-span-id",u);let y={...e,headers:l},b=typeof performance<"u"?performance.now():Date.now();try{let d=await t(n,y),p=Math.round((typeof performance<"u"?performance.now():Date.now())-b),w=a.getSlowThresholdMs();return(d.status>=400||p>=w)&&a.captureRequest({method:o,url:s,statusCode:d.status,durationMs:p,route:s,requestId:i,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:d.status,durationMs:p,requestId:i,traceId:c,spanId:u}}),d}catch(d){let p=Math.round((typeof performance<"u"?performance.now():Date.now())-b);throw a.captureRequest({method:o,url:s,statusCode:0,durationMs:p,route:s,requestId:i,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:o,type:r?.errorType||"network_error",requestId:i,traceId:c,spanId:u}),a.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:p,requestId:i,traceId:c,spanId:u}}),d}}async function A(n,e){return g(n,e,{errorType:"vue_network_error"})}var x={install(n,e){if(a.init(e),!n.config)return;let r=n.config.errorHandler;n.config.errorHandler=(t,s,o)=>{let i=t instanceof Error?t:new Error(String(t)),c=s?.$options?.name||s?.$options?.__name||s?.$type?.name;a.addBreadcrumb({type:"vue_error",message:i.message||"Erro capturado pelo Vue",metadata:{component:c,vueInfo:o}}),a.captureError(i,{framework:"Vue",vueInfo:o,component:c}),typeof r=="function"?r(t,s,o):console.error(t)}}};function D(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=function(r,t){return g(r,t,{errorType:"vue_network_error",nativeFetch:e})}}0&&(module.exports={DevInspectorVue,audit,auditFetch,enableNetworkTracing});
|
|
1
|
+
"use strict";var b=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var k=(t,e)=>{for(var r in e)b(t,r,{get:e[r],enumerable:!0})},C=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of q(e))!P.call(t,n)&&n!==r&&b(t,n,{get:()=>e[n],enumerable:!(i=D(e,n))||i.enumerable});return t};var O=t=>C(b({},"__esModule",{value:!0}),t);var z={};k(z,{DevInspectorVue:()=>F,audit:()=>a,auditFetch:()=>x,enableNetworkTracing:()=>H});module.exports=O(z);var I="https://api.devinspector.com.br/api/ingest/track",_="https://api.devinspector.com.br/api/ingest/apm";var N=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function Q(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return N.some(r=>e.includes(r))}function l(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>l(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(Q(s)){n[s]="[REDACTED]";continue}n[s]=l(o,e+1,r)}return n}finally{r.delete(t)}}function y(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=l(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(t){return t&&String(t).trim().toUpperCase()||void 0}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function L(t){return String(t??"").trim().slice(0,200)}function B(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function h(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function d(t){return l(t)}var w=class{constructor(){this.apiKey="";this.endpoint=I;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()||I,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?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,r.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),u=r.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return s===r.origin&&o===u||s===i.origin&&o===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let r=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=M(e.statusCode)??0,s=R(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:i,statusCode:n,durationMs:s,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(o)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let i=R(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(n)})}captureMetric(e,r,i={},n={}){let s=L(e);if(!s)return Promise.resolve();let o;try{o=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:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},s=E(n.method),o=M(n.statusCode??n.status),u=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...u?{url:u}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(y(e));return this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,1e4),environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}).finally(()=>{typeof r=="function"&&r(i,n)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let i=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(i,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let i=r.reason instanceof Error?r.reason:new Error(y(r.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,r){if(!this.initialized||!this.apiKey)return Promise.resolve();let i={id:h("event"),endpoint:e,payload:d(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=l(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(u&&(c.keepalive=!0),!(await i(e,c)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},A="__DEVINSPECT_AUDIT_CORE_INSTANCE__",U=typeof globalThis<"u"?globalThis:{},a=U[A]||new w;U[A]=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=E(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return i(t,e);let o=a.createRequestId(),u=a.createTraceId(),c=a.createSpanId(),f=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));f.set("x-devinspector-request-id",o),f.set("x-devinspector-trace-id",u),f.set("x-devinspector-span-id",c);let S={...e,headers:f},v=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,S),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-v)),g=p.status>=400||m>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:m,requestId:o,traceId:u,spanId:c}}),g&&a.captureRequest({method:s,url:n,statusCode:p.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:c}),p}catch(p){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-v));a.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:o,traceId:u,spanId:c}}),a.captureRequest({method:s,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:u,spanId:c});let g=p instanceof Error?p:new Error(y(p));throw a.captureError(g,{url:n,method:s,type:r.errorType||"network_error"}),p}}async function x(t,e){return T(t,e,{errorType:"vue_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vue"})}var F={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 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)}0&&(module.exports={DevInspectorVue,audit,auditFetch,enableNetworkTracing});
|
package/dist/vue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var h=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.maxBreadcrumbs=50;this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),e.release&&(this.release=e.release),typeof e.slowThresholdMs=="number"&&e.slowThresholdMs>=0&&(this.slowThresholdMs=e.slowThresholdMs),this.initialized=!0,this.listenGlobalErrors()}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}generateId(e){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return`${e}_${crypto.randomUUID()}`}catch{}return`${e}_${Date.now()}_${Math.random().toString(36).substring(2,12)}`}createRequestId(){return this.generateId("req")}createTraceId(){return this.generateId("trace")}createSpanId(){return this.generateId("span")}setUser(e){this.user=this.truncate(e,2e3)}clearUser(){this.user=void 0}getUser(){return this.user}addBreadcrumb(e){let r={...e,timestamp:new Date().toISOString()},t=this.truncate(r,2e3);this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}clearBreadcrumbs(){this.breadcrumbs=[]}getBreadcrumbs(){return[...this.breadcrumbs]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs.length>0?[...this.breadcrumbs]:void 0,timestamp:new Date().toISOString()}}captureRequest(e){let r=this.getContext(),t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({environment:r.environment,timestamp:r.timestamp,route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0},5e3)};this.send(t)}captureDbQuery(e){let r=this.getContext(),t=e.operation?.trim()||"query",s=e.collection?.trim()||"Unknown",o={type:"db_query",message:`Database operation [${t}]`,stackTrace:"",url:e.url||(typeof window<"u"?window.location.href:""),browser:typeof navigator<"u"?navigator.userAgent:"",method:t,durationMs:e.durationMs,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:r.environment,release:r.release,user:r.user,breadcrumbs:r.breadcrumbs,metadata:this.truncate({...e.metadata,collection:s,operation:t,durationMs:e.durationMs,environment:r.environment,timestamp:r.timestamp},5e3)};this.send(o)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=typeof e.ErrorUtils.getGlobalHandler=="function"?e.ErrorUtils.getGlobalHandler():void 0;e.ErrorUtils.setGlobalHandler((t,s)=>{let o=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(o,{type:"react_native_error",isFatal:!!s}),r&&r(t,s)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let s=t instanceof Error?t:new Error(String(t));this.captureError(s,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"){let s=e;if(t.has(s))return"[Circular Reference]";if(t.add(s),Array.isArray(e))return e.map(i=>this.truncate(i,r,t));let o={};for(let[i,c]of Object.entries(e))o[i]=this.truncate(c,r,t);return o}return e}captureError(e,r={}){let t=e?.message||"Erro Desconhecido",s=e?.stack||"",o=this.getContext(),i=r.requestId,c=r.traceId,u=r.spanId,l={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(s,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:i,traceId:c,spanId:u,environment:o.environment,release:o.release,user:o.user,breadcrumbs:o.breadcrumbs,metadata:this.truncate({...r,environment:o.environment,release:o.release,timestamp:o.timestamp},5e3)};this.send(l)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t=this.getContext(),s={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:t.environment,release:t.release,user:t.user,breadcrumbs:t.breadcrumbs,metadata:this.truncate({...r,level:"info",environment:t.environment,release:t.release,timestamp:t.timestamp},5e3)};this.send(s)}async send(e){if(this.initialized&&!(!this.apiKey||this.apiKey==="PENDING_API_KEY"))try{let r=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(e),keepalive:!0});r.ok||console.error(`[DevInspector] Erro na API (${r.status}): ${r.statusText}`)}catch(r){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",r)}}},m="__DEVINSPECT_AUDIT_CORE_INSTANCE__",w=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[m]||(n[m]=new h),n[m]},a=w();async function f(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch.bind(window):typeof globalThis<"u"?globalThis.fetch:fetch),s="";if(typeof n=="string"?s=n:n instanceof URL?s=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(s=n.url),s&&a.isIngestUrl(s))return t(n,e);let o=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),i=a.createRequestId(),c=a.createTraceId(),u=a.createSpanId(),l=new Headers(e?.headers||(typeof n=="object"&&n!==null&&"headers"in n?n.headers:void 0));l.set("x-devinspector-request-id",i),l.set("x-devinspector-trace-id",c),l.set("x-devinspector-span-id",u);let b={...e,headers:l},g=typeof performance<"u"?performance.now():Date.now();try{let d=await t(n,b),p=Math.round((typeof performance<"u"?performance.now():Date.now())-g),y=a.getSlowThresholdMs();return(d.status>=400||p>=y)&&a.captureRequest({method:o,url:s,statusCode:d.status,durationMs:p,route:s,requestId:i,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{statusCode:d.status,durationMs:p,requestId:i,traceId:c,spanId:u}}),d}catch(d){let p=Math.round((typeof performance<"u"?performance.now():Date.now())-g);throw a.captureRequest({method:o,url:s,statusCode:0,durationMs:p,route:s,requestId:i,traceId:c,spanId:u,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(d instanceof Error?d:new Error(String(d)),{url:s,method:o,type:r?.errorType||"network_error",requestId:i,traceId:c,spanId:u}),a.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{durationMs:p,requestId:i,traceId:c,spanId:u}}),d}}async function _(n,e){return f(n,e,{errorType:"vue_network_error"})}var T={install(n,e){if(a.init(e),!n.config)return;let r=n.config.errorHandler;n.config.errorHandler=(t,s,o)=>{let i=t instanceof Error?t:new Error(String(t)),c=s?.$options?.name||s?.$options?.__name||s?.$type?.name;a.addBreadcrumb({type:"vue_error",message:i.message||"Erro capturado pelo Vue",metadata:{component:c,vueInfo:o}}),a.captureError(i,{framework:"Vue",vueInfo:o,component:c}),typeof r=="function"?r(t,s,o):console.error(t)}}};function R(){let n=typeof window<"u"?window:globalThis;if(!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=n.fetch.bind(n);n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=function(r,t){return f(r,t,{errorType:"vue_network_error",nativeFetch:e})}}export{T as DevInspectorVue,a as audit,_ as auditFetch,R as enableNetworkTracing};
|
|
1
|
+
var v="https://api.devinspector.com.br/api/ingest/track",I="https://api.devinspector.com.br/api/ingest/apm";var S=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function D(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return S.some(r=>e.includes(r))}function l(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";r.add(t);try{if(Array.isArray(t))return t.slice(0,100).map(s=>l(s,e+1,r));let i=t,n={};for(let[s,o]of Object.entries(i)){if(D(s)){n[s]="[REDACTED]";continue}n[s]=l(o,e+1,r)}return n}finally{r.delete(t)}}function b(t){if(t instanceof Error)return t.message||"Erro desconhecido";if(typeof t=="string")return t||"Erro desconhecido";try{let e=l(t);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function y(t){return t&&String(t).trim().toUpperCase()||void 0}function _(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function q(t){return String(t??"").trim().slice(0,200)}function P(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function h(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function d(t){return l(t)}var E=class{constructor(){this.apiKey="";this.endpoint=v;this.apmEndpoint=I;this.environment="production";this.slowThresholdMs=300;this.requestTimeoutMs=1e4;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[]}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||v,this.apmEndpoint=e.apmEndpoint?.trim()||I,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):1e4,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,1e4),metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(this.apmEndpoint),n=new URL(e,r.origin),s=n.origin,o=n.pathname.replace(/\/$/,""),a=r.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return s===r.origin&&o===a||s===i.origin&&o===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let r=y(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let n=_(e.statusCode)??0,s=M(e.durationMs)??0,o={...e.metadata||{},...e.route!==void 0?{route:e.route}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:r,url:i,statusCode:n,durationMs:s,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(o)})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return Promise.resolve();let i=M(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${r}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(n)})}captureMetric(e,r,i={},n={}){let s=q(e);if(!s)return Promise.resolve();let o;try{o=P(r)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:s,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},s=y(n.method),o=_(n.statusCode??n.status),a=n.url!==void 0&&n.url!==null?String(n.url).trim():void 0;return delete n.method,delete n.statusCode,delete n.status,delete n.requestId,delete n.traceId,delete n.spanId,delete n.durationMs,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...a?{url:a}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...n,timestamp:new Date().toISOString()})})}captureException(e,r={}){let i=e instanceof Error?e:new Error(b(e));return this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,1e4),environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...r,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}).finally(()=>{typeof r=="function"&&r(i,n)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let i=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(i,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let i=r.reason instanceof Error?r.reason:new Error(b(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:h("event"),endpoint:e,payload:d(r),resolve:()=>{}};return new Promise(n=>{i.resolve=n,this.sendQueue.push(i),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.sendToEndpoint(e.endpoint,e.payload)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let r of e)r()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,r){let i=typeof fetch=="function"?fetch:void 0;if(!i)return;let n=l(r),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(n),signal:s?.signal};if(a&&(c.keepalive=!0),!(await i(e,c)).ok)return}catch{return}finally{o!==void 0&&clearTimeout(o)}}},R="__DEVINSPECT_AUDIT_CORE_INSTANCE__",A=typeof globalThis<"u"?globalThis:{},u=A[R]||new E;A[R]=u;async function w(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=y(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(),c=u.createSpanId(),f=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));f.set("x-devinspector-request-id",o),f.set("x-devinspector-trace-id",a),f.set("x-devinspector-span-id",c);let U={...e,headers:f},T=typeof performance<"u"?performance.now():Date.now();try{let p=await i(t,U),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-T)),g=p.status>=400||m>=u.getSlowThresholdMs();return u.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{phase:"complete",statusCode:p.status,durationMs:m,requestId:o,traceId:a,spanId:c}}),g&&u.captureRequest({method:s,url:n,statusCode:p.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:c}),p}catch(p){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-T));u.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:o,traceId:a,spanId:c}}),u.captureRequest({method:s,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:o,traceId:a,spanId:c});let g=p instanceof Error?p:new Error(b(p));throw u.captureError(g,{url:n,method:s,type:r.errorType||"network_error"}),p}}async function O(t,e){return w(t,e,{errorType:"vue_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vue"})}var N={install(t,e){if(u.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)),a=n?.$options?.name||n?.$options?.__name||n?.$type?.name;u.addBreadcrumb({type:"vue_error",message:o.message||"Erro capturado pelo Vue",metadata:{component:a,vueInfo:s}}),u.captureError(o,{framework:"Vue",vueInfo:s,component:a}),typeof r=="function"?r(i,n,s):console.error(i)}}};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 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 w(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{N as DevInspectorVue,u as audit,O as auditFetch,Q as enableNetworkTracing};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xcodleox/devinspector",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "SDK de monitoramento e auditoria de erros em tempo real | Dev Inspector",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -135,7 +135,8 @@
|
|
|
135
135
|
"default": "./dist/vanilla.cjs"
|
|
136
136
|
},
|
|
137
137
|
"default": "./dist/vanilla.js"
|
|
138
|
-
}
|
|
138
|
+
},
|
|
139
|
+
"./package.json": "./package.json"
|
|
139
140
|
},
|
|
140
141
|
"typesVersions": {
|
|
141
142
|
"*": {
|