@xcodleox/devinspector 7.5.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular.cjs +1 -1
- package/dist/angular.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +71 -8
- package/dist/index.d.ts +71 -8
- package/dist/index.js +1 -1
- package/dist/next.cjs +1 -1
- package/dist/next.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.js +1 -1
- package/dist/react-native.cjs +1 -1
- package/dist/react-native.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/svelte.cjs +1 -1
- package/dist/svelte.d.cts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +1 -1
- package/dist/vanilla.cjs +1 -1
- package/dist/vanilla.global.js +1 -1
- package/dist/vanilla.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +1 -1
- package/package.json +11 -9
package/dist/react-native.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var r in e)d(n,r,{get:e[r],enumerable:!0})},v=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!w.call(n,o)&&o!==r&&d(n,o,{get:()=>e[o],enumerable:!(t=E(e,o))||t.enumerable});return n};var R=n=>v(d({},"__esModule",{value:!0}),n);var A={};b(A,{AuditErrorBoundary:()=>f,audit:()=>a,auditFetch:()=>y,enableNetworkTracing:()=>I});module.exports=R(A);var g=require("react");var l=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(r)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((t,o)=>{let i=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),r&&r(t,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let o=t instanceof Error?t:new Error(String(t));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(t.has(e))return"[Circular Reference]";t.add(e);let o={};for(let[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",o=e.stack||"",i={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(e){let r=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new l),n[p]},a=_();async function h(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await t(n,e),u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||u>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let u=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:u,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}var f=class extends g.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){a.captureError(r,{platform:"react-native",componentStack:t.componentStack}),this.props.onError&&this.props.onError(r,t)}render(){if(this.state.hasError){let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido");return typeof r=="function"?r(t):r??null}return this.props.children}};async function y(n,e){return h(n,e,{errorType:"react_native_network_error",defaultUserAgent:"React-Native"})}function I(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return y(e,r)})}0&&(module.exports={AuditErrorBoundary,audit,auditFetch,enableNetworkTracing});
|
|
1
|
+
"use strict";var h=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var q=(r,e)=>{for(var t in e)h(r,t,{get:e[t],enumerable:!0})},C=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of A(e))!D.call(r,n)&&n!==t&&h(r,n,{get:()=>e[n],enumerable:!(s=k(e,n))||s.enumerable});return r};var N=r=>C(h({},"__esModule",{value:!0}),r);var F={};q(F,{AuditErrorBoundary:()=>E,audit:()=>a,auditFetch:()=>z,enableNetworkTracing:()=>P});module.exports=N(F);var U=require("react");var S="https://api.devinspector.com.br/api/ingest/track";var x=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function O(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return x.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]";if(t.add(r),Array.isArray(r))return r.slice(0,100).map(i=>l(i,e+1,t));let s=r,n={};for(let[i,o]of Object.entries(s)){if(O(i)){n[i]="[REDACTED]";continue}n[i]=l(o,e+1,t)}return n}function b(r){if(r)return String(r).trim().toUpperCase()}function v(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function T(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function L(r){return String(r??"").trim().slice(0,200)}function B(r){let e=Number(r);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function g(r){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${r}-${e.randomUUID()}`:`${r}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var y=class{constructor(){this.apiKey="";this.endpoint=S;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||S,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),s=new URL(e,t.origin);return s.origin===t.origin&&s.pathname===t.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return g("req")}createTraceId(){return g("trace")}createSpanId(){return g("span")}captureRequest(e){let t=b(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=v(e.statusCode)??0,i=T(e.durationMs)??0,o={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:t,url:s,statusCode:n,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:o})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return;let s=T(e.durationMs)??0,n={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${t}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,t,s={},n={}){let i=L(e);if(!i)return;let o;try{o=B(t)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:o,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let s=e?.message?.trim()||"Erro desconhecido",n={...t},i=b(n.method),o=v(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,p=n.spanId?String(n.spanId):void 0,f=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:f,method:i,statusCode:o,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,t={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,t)}captureMessage(e,t={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...t,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof t=="function"&&t(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let s=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(s,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let s=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let t=l(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(t),keepalive:!0})}catch{}}},_="__DEVINSPECT_AUDIT_CORE_INSTANCE__",M=typeof globalThis<"u"?globalThis:{},a=M[_]||new y;M[_]=a;async function w(r,e,t={}){let s=t.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!s)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof r=="string"?r:r instanceof URL?r.toString():String(r.url||""),i=b(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return s(r,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.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 f={...e,headers:p},I=typeof performance<"u"?performance.now():Date.now();try{let c=await s(r,f),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));return(c.status>=400||m>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:n,statusCode:c.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:u,spanId:d}),a.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:m,requestId:o,traceId:u,spanId:d}}),c}catch(c){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));a.captureRequest({method:i,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:u,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{statusCode:0,durationMs:m,requestId:o,traceId:u,spanId:d}});let R=c instanceof Error?c:new Error(String(c));throw a.captureError(R,{url:n,method:i,requestId:o,traceId:u,spanId:d,type:t.errorType||"network_error"}),c}}var E=class extends U.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,s){a.addBreadcrumb({type:"react_native_error_boundary",message:t.message||"Erro capturado pelo React Native Error Boundary",metadata:{componentStack:s.componentStack||""}}),a.captureError(t,{platform:"react-native",framework:"React Native",componentStack:s.componentStack}),this.props.onError&&this.props.onError(t,s)}render(){if(!this.state.hasError)return this.props.children;let{fallback:t}=this.props,s=this.state.error||new Error("Erro desconhecido");return typeof t=="function"?t(s):t??null}};async function z(r,e){return w(r,e,{errorType:"react_native_network_error",defaultUserAgent:"React-Native"})}function P(){let r=globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=function(t,s){return w(t,s,{errorType:"react_native_network_error",defaultUserAgent:"React-Native",nativeFetch:e})}}0&&(module.exports={AuditErrorBoundary,audit,auditFetch,enableNetworkTracing});
|
package/dist/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Component as
|
|
1
|
+
import{Component as D}from"react";var I="https://api.devinspector.com.br/api/ingest/track";var M=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function U(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return M.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]";if(t.add(r),Array.isArray(r))return r.slice(0,100).map(i=>l(i,e+1,t));let n=r,s={};for(let[i,o]of Object.entries(n)){if(U(i)){s[i]="[REDACTED]";continue}s[i]=l(o,e+1,t)}return s}function g(r){if(r)return String(r).trim().toUpperCase()}function R(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function S(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 A(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)}`}var b=class{constructor(){this.apiKey="";this.endpoint=I;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||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?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),n=new URL(e,t.origin);return n.origin===t.origin&&n.pathname===t.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let t=g(e.method)||"GET",n=String(e.url||"").trim();if(!n)return;let s=R(e.statusCode)??0,i=S(e.durationMs)??0,o={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:t,url:n,statusCode:s,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:o})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return;let n=S(e.durationMs)??0,s={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:n,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${t}`,stackTrace:"",url:e.url,method:"DB",durationMs:n,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:s})}captureMetric(e,t,n={},s={}){let i=k(e);if(!i)return;let o;try{o=A(t)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:o,requestId:s.requestId,traceId:s.traceId,spanId:s.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let n=e?.message?.trim()||"Erro desconhecido",s={...t},i=g(s.method),o=R(s.statusCode??s.status),u=s.requestId?String(s.requestId):void 0,d=s.traceId?String(s.traceId):void 0,p=s.spanId?String(s.spanId):void 0,f=s.url?String(s.url):void 0;delete s.requestId,delete s.traceId,delete s.spanId,delete s.method,delete s.statusCode,delete s.status,this.send({type:"error",message:n,stackTrace:e?.stack||"",url:f,method:i,statusCode:o,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureException(e,t={}){let n=e instanceof Error?e:new Error(String(e));this.captureError(n,t)}captureMessage(e,t={}){let n=String(e||"").trim();n&&this.send({type:"message",message:n,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...t,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((n,s)=>{this.captureError(n,{platform:"react-native",fatal:s}),typeof t=="function"&&t(n,s)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let n=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(n,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let t=l(e);try{let n=typeof fetch=="function"?fetch:void 0;if(!n)return;await n(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(t),keepalive:!0})}catch{}}},v="__DEVINSPECT_AUDIT_CORE_INSTANCE__",T=typeof globalThis<"u"?globalThis:{},a=T[v]||new b;T[v]=a;async function y(r,e,t={}){let n=t.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!n)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let s=typeof r=="string"?r:r instanceof URL?r.toString():String(r.url||""),i=g(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(s&&a.isIngestUrl(s))return n(r,e);let o=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.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 f={...e,headers:p},w=typeof performance<"u"?performance.now():Date.now();try{let c=await n(r,f),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-w));return(c.status>=400||m>=a.getSlowThresholdMs())&&a.captureRequest({method:i,url:s,statusCode:c.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:u,spanId:d}),a.addBreadcrumb({type:"http",message:`${i} ${s}`,metadata:{phase:"complete",statusCode:c.status,durationMs:m,requestId:o,traceId:u,spanId:d}}),c}catch(c){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-w));a.captureRequest({method:i,url:s,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:u,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${i} ${s}`,metadata:{statusCode:0,durationMs:m,requestId:o,traceId:u,spanId:d}});let E=c instanceof Error?c:new Error(String(c));throw a.captureError(E,{url:s,method:i,requestId:o,traceId:u,spanId:d,type:t.errorType||"network_error"}),c}}var _=class extends D{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){a.addBreadcrumb({type:"react_native_error_boundary",message:t.message||"Erro capturado pelo React Native Error Boundary",metadata:{componentStack:n.componentStack||""}}),a.captureError(t,{platform:"react-native",framework:"React Native",componentStack:n.componentStack}),this.props.onError&&this.props.onError(t,n)}render(){if(!this.state.hasError)return this.props.children;let{fallback:t}=this.props,n=this.state.error||new Error("Erro desconhecido");return typeof t=="function"?t(n):t??null}};async function B(r,e){return y(r,e,{errorType:"react_native_network_error",defaultUserAgent:"React-Native"})}function z(){let r=globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=function(t,n){return y(t,n,{errorType:"react_native_network_error",defaultUserAgent:"React-Native",nativeFetch:e})}}export{_ as AuditErrorBoundary,a as audit,B as auditFetch,z as enableNetworkTracing};
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(n,e)=>{for(var r in e)u(n,r,{get:e[r],enumerable:!0})},R=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of m(e))!b.call(n,o)&&o!==r&&u(n,o,{get:()=>e[o],enumerable:!(t=w(e,o))||t.enumerable});return n};var _=n=>R(u({},"__esModule",{value:!0}),n);var S={};v(S,{AuditErrorBoundary:()=>f,audit:()=>a,auditFetch:()=>g,enableNetworkTracing:()=>A});module.exports=_(S);var y=require("react");var l=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(r)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((t,o)=>{let i=t instanceof Error?t:new Error(String(t?.message||t||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),r&&r(t,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let t=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(t,{type:"unhandled_rejection"})});else if(e.process?.on){let r=e.process;r.on("uncaughtException",t=>{this.captureError(t,{type:"uncaught_exception"})}),r.on("unhandledRejection",t=>{let o=t instanceof Error?t:new Error(String(t));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,r=5e3,t=new WeakSet){if(typeof e=="string")return e.length>r?e.substring(0,r)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(t.has(e))return"[Circular Reference]";t.add(e);let o={};for(let[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",o=e.stack||"",i={type:"error",message:this.truncate(t,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let t={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(t)}async send(e){let r=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify(e),keepalive:!0});t.ok||console.error(`[DevInspector] Erro na API (${t.status}): ${t.statusText}`)}catch(t){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",t)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",I=()=>{let n=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return n[p]||(n[p]=new l),n[p]},a=I();async function h(n,e,r){let t=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof n=="string"?o=n:n instanceof URL?o=n.toString():typeof n=="object"&&n!==null&&"url"in n&&(o=n.url),o&&a.isIngestUrl(o))return t(n,e);let i=e?.method||(typeof n=="object"&&n!==null&&"method"in n?n.method:"GET"),c=typeof performance<"u"?performance.now():Date.now();try{let s=await t(n,e),d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);return(s.status>=400||d>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:d,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let d=Math.round((typeof performance<"u"?performance.now():Date.now())-c);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:d,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}var E=require("react/jsx-runtime"),f=class extends y.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,t){a.captureError(r,{framework:"React",componentStack:t.componentStack,url:typeof window<"u"?window.location.href:""}),this.props.onError&&this.props.onError(r,t)}render(){if(this.state.hasError){let{fallback:r}=this.props,t=this.state.error||new Error("Erro desconhecido no componente");return typeof r=="function"?r(t):r??(0,E.jsx)("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function g(n,e){return h(n,e,{errorType:"react_network_error"})}function A(){let n=globalThis;!n.fetch||n.__DEVINSPECTOR_FETCH_PATCHED__||(n.__DEVINSPECTOR_FETCH_PATCHED__=!0,n.fetch=async function(e,r){return g(e,r)})}0&&(module.exports={AuditErrorBoundary,audit,auditFetch,enableNetworkTracing});
|
|
1
|
+
"use strict";var h=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var C=(r,e)=>{for(var t in e)h(r,t,{get:e[t],enumerable:!0})},N=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of D(e))!q.call(r,n)&&n!==t&&h(r,n,{get:()=>e[n],enumerable:!(s=A(e,n))||s.enumerable});return r};var x=r=>N(h({},"__esModule",{value:!0}),r);var G={};C(G,{AuditErrorBoundary:()=>E,audit:()=>a,auditFetch:()=>P,enableNetworkTracing:()=>F});module.exports=x(G);var v=require("react");var S="https://api.devinspector.com.br/api/ingest/track";var O=["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 O.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]";if(t.add(r),Array.isArray(r))return r.slice(0,100).map(o=>l(o,e+1,t));let s=r,n={};for(let[o,i]of Object.entries(s)){if(L(o)){n[o]="[REDACTED]";continue}n[o]=l(i,e+1,t)}return n}function b(r){if(r)return String(r).trim().toUpperCase()}function T(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 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 g(r){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${r}-${e.randomUUID()}`:`${r}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var w=class{constructor(){this.apiKey="";this.endpoint=S;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||S,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),s=new URL(e,t.origin);return s.origin===t.origin&&s.pathname===t.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return g("req")}createTraceId(){return g("trace")}createSpanId(){return g("span")}captureRequest(e){let t=b(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=T(e.statusCode)??0,o=M(e.durationMs)??0,i={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:t,url:s,statusCode:n,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:i})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return;let s=M(e.durationMs)??0,n={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${t}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,t,s={},n={}){let o=B(e);if(!o)return;let i;try{i=z(t)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:i,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let s=e?.message?.trim()||"Erro desconhecido",n={...t},o=b(n.method),i=T(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,p=n.spanId?String(n.spanId):void 0,f=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:f,method:o,statusCode:i,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,t={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,t)}captureMessage(e,t={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...t,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof t=="function"&&t(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let s=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(s,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let s=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let t=l(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(t),keepalive:!0})}catch{}}},k="__DEVINSPECT_AUDIT_CORE_INSTANCE__",_=typeof globalThis<"u"?globalThis:{},a=_[k]||new w;_[k]=a;async function y(r,e,t={}){let s=t.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!s)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof r=="string"?r:r instanceof URL?r.toString():String(r.url||""),o=b(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(n&&a.isIngestUrl(n))return s(r,e);let i=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.headers:void 0));p.set("x-devinspector-request-id",i),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let f={...e,headers:p},I=typeof performance<"u"?performance.now():Date.now();try{let c=await s(r,f),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));return(c.status>=400||m>=a.getSlowThresholdMs())&&a.captureRequest({method:o,url:n,statusCode:c.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http",message:`${o} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:m,requestId:i,traceId:u,spanId:d}}),c}catch(c){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));a.captureRequest({method:o,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${o} ${n}`,metadata:{statusCode:0,durationMs:m,requestId:i,traceId:u,spanId:d}});let R=c instanceof Error?c:new Error(String(c));throw a.captureError(R,{url:n,method:o,requestId:i,traceId:u,spanId:d,type:t.errorType||"network_error"}),c}}var U=require("react/jsx-runtime"),E=class extends v.Component{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,s){a.addBreadcrumb({type:"react_error_boundary",message:t.message||"Erro capturado pelo React Error Boundary",metadata:{componentStack:s.componentStack||""}}),a.captureError(t,{framework:"React",componentStack:s.componentStack,url:typeof window<"u"?window.location.href:""}),this.props.onError&&this.props.onError(t,s)}render(){if(this.state.hasError){let{fallback:t}=this.props,s=this.state.error||new Error("Erro desconhecido no componente");return typeof t=="function"?t(s):t??(0,U.jsx)("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function P(r,e){return y(r,e,{errorType:"react_network_error"})}function F(){let r=globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=function(t,s){return y(t,s,{errorType:"react_network_error",nativeFetch:e})}}0&&(module.exports={AuditErrorBoundary,audit,auditFetch,enableNetworkTracing});
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Component as
|
|
1
|
+
import{Component as D}from"react";var I="https://api.devinspector.com.br/api/ingest/track";var _=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function v(r){let e=r.toLowerCase().replace(/[\s-]/g,"_");return _.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]";if(t.add(r),Array.isArray(r))return r.slice(0,100).map(o=>l(o,e+1,t));let n=r,s={};for(let[o,i]of Object.entries(n)){if(v(o)){s[o]="[REDACTED]";continue}s[o]=l(i,e+1,t)}return s}function g(r){if(r)return String(r).trim().toUpperCase()}function R(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.round(r)}function S(r){if(!(typeof r!="number"||!Number.isFinite(r)))return Math.max(0,Math.round(r))}function U(r){return String(r??"").trim().slice(0,200)}function A(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)}`}var b=class{constructor(){this.apiKey="";this.endpoint=I;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||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?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),n=new URL(e,t.origin);return n.origin===t.origin&&n.pathname===t.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let t=g(e.method)||"GET",n=String(e.url||"").trim();if(!n)return;let s=R(e.statusCode)??0,o=S(e.durationMs)??0,i={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:t,url:n,statusCode:s,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:i})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return;let n=S(e.durationMs)??0,s={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:n,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${t}`,stackTrace:"",url:e.url,method:"DB",durationMs:n,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:s})}captureMetric(e,t,n={},s={}){let o=U(e);if(!o)return;let i;try{i=A(t)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:i,requestId:s.requestId,traceId:s.traceId,spanId:s.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let n=e?.message?.trim()||"Erro desconhecido",s={...t},o=g(s.method),i=R(s.statusCode??s.status),u=s.requestId?String(s.requestId):void 0,d=s.traceId?String(s.traceId):void 0,p=s.spanId?String(s.spanId):void 0,f=s.url?String(s.url):void 0;delete s.requestId,delete s.traceId,delete s.spanId,delete s.method,delete s.statusCode,delete s.status,this.send({type:"error",message:n,stackTrace:e?.stack||"",url:f,method:o,statusCode:i,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureException(e,t={}){let n=e instanceof Error?e:new Error(String(e));this.captureError(n,t)}captureMessage(e,t={}){let n=String(e||"").trim();n&&this.send({type:"message",message:n,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...t,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((n,s)=>{this.captureError(n,{platform:"react-native",fatal:s}),typeof t=="function"&&t(n,s)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let n=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(n,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let t=l(e);try{let n=typeof fetch=="function"?fetch:void 0;if(!n)return;await n(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(t),keepalive:!0})}catch{}}},T="__DEVINSPECT_AUDIT_CORE_INSTANCE__",M=typeof globalThis<"u"?globalThis:{},a=M[T]||new b;M[T]=a;async function w(r,e,t={}){let n=t.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!n)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let s=typeof r=="string"?r:r instanceof URL?r.toString():String(r.url||""),o=g(e?.method||(typeof r!="string"&&!(r instanceof URL)?r.method:"GET"))||"GET";if(s&&a.isIngestUrl(s))return n(r,e);let i=a.createRequestId(),u=a.createTraceId(),d=a.createSpanId(),p=new Headers(e?.headers||(typeof r!="string"&&!(r instanceof URL)?r.headers:void 0));p.set("x-devinspector-request-id",i),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let f={...e,headers:p},y=typeof performance<"u"?performance.now():Date.now();try{let c=await n(r,f),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-y));return(c.status>=400||m>=a.getSlowThresholdMs())&&a.captureRequest({method:o,url:s,statusCode:c.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http",message:`${o} ${s}`,metadata:{phase:"complete",statusCode:c.status,durationMs:m,requestId:i,traceId:u,spanId:d}}),c}catch(c){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-y));a.captureRequest({method:o,url:s,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:i,traceId:u,spanId:d}),a.addBreadcrumb({type:"http_error",message:`${o} ${s}`,metadata:{statusCode:0,durationMs:m,requestId:i,traceId:u,spanId:d}});let E=c instanceof Error?c:new Error(String(c));throw a.captureError(E,{url:s,method:o,requestId:i,traceId:u,spanId:d,type:t.errorType||"network_error"}),c}}import{jsx as q}from"react/jsx-runtime";var k=class extends D{constructor(){super(...arguments);this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){a.addBreadcrumb({type:"react_error_boundary",message:t.message||"Erro capturado pelo React Error Boundary",metadata:{componentStack:n.componentStack||""}}),a.captureError(t,{framework:"React",componentStack:n.componentStack,url:typeof window<"u"?window.location.href:""}),this.props.onError&&this.props.onError(t,n)}render(){if(this.state.hasError){let{fallback:t}=this.props,n=this.state.error||new Error("Erro desconhecido no componente");return typeof t=="function"?t(n):t??q("h1",{children:"Algo deu errado na aplica\xE7\xE3o."})}return this.props.children}};async function z(r,e){return w(r,e,{errorType:"react_network_error"})}function P(){let r=globalThis;if(!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=r.fetch.bind(r);r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=function(t,n){return w(t,n,{errorType:"react_network_error",nativeFetch:e})}}export{k as AuditErrorBoundary,a as audit,z as auditFetch,P as enableNetworkTracing};
|
package/dist/svelte.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},b=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of w(e))!m.call(t,o)&&o!==r&&d(t,o,{get:()=>e[o],enumerable:!(n=g(e,o))||n.enumerable});return t};var v=t=>b(d({},"__esModule",{value:!0}),t);var k={};E(k,{audit:()=>a,auditFetch:()=>h,auditHandle:()=>I,enableNetworkTracing:()=>T,handleSvelteKitError:()=>A,initSvelteDevInspector:()=>_});module.exports=v(k);var f=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let r=new URL(this.endpoint);return e.includes(r.host)||e.includes(r.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let r={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(r)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let r=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((n,o)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),r&&r(n,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",r=>{this.captureError(r.error||new Error(r.message||"Erro global desconhecido"),{filename:r.filename,lineno:r.lineno,colno:r.colno})}),window.addEventListener("unhandledrejection",r=>{let 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 o=n instanceof Error?n:new Error(String(n));this.captureError(o,{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"&&e!==null){if(n.has(e))return"[Circular Reference]";n.add(e);let o={};for(let[i,u]of Object.entries(e))o[i]=this.truncate(u,r,n);return o}return e}captureError(e,r={}){let n=e.message||"Erro Desconhecido",o=e.stack||"",i={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,r={}){this.captureError(e,r)}captureMessage(e,r={}){let n={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...r,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(n)}async send(e){let r=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let n=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":r},body:JSON.stringify(e),keepalive:!0});n.ok||console.error(`[DevInspector] Erro na API (${n.status}): ${n.statusText}`)}catch(n){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",n)}}},p="__DEVINSPECT_AUDIT_CORE_INSTANCE__",R=()=>{let t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return t[p]||(t[p]=new f),t[p]},a=R();async function l(t,e,r){let n=r?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof t=="string"?o=t:t instanceof URL?o=t.toString():typeof t=="object"&&t!==null&&"url"in t&&(o=t.url),o&&a.isIngestUrl(o))return n(t,e);let i=e?.method||(typeof t=="object"&&t!==null&&"method"in t?t.method:"GET"),u=typeof performance<"u"?performance.now():Date.now();try{let s=await n(t,e),c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);return(s.status>=400||c>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:r?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:r?.errorType||"network_error"}),s}}function _(t){a.init(t)}async function h(t,e){return l(t,e,{errorType:"svelte_network_error"})}async function I({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),n=t.request?.method||"GET",o=t.url?.pathname||t.url?.href||"/",i=t.route?.id||o;if(o&&a.isIngestUrl(o))return e(t);let u=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"";try{let s=await e(t),c=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return(s.status>=400||c>=300)&&a.captureRequest({method:n,url:o,statusCode:s.status,durationMs:c,route:i,userAgent:u}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-r);a.captureRequest({method:n,url:o,statusCode:500,durationMs:c,route:i,userAgent:u});let y=s instanceof Error?s:new Error(String(s));throw a.captureError(y,{framework:"sveltekit",url:o,method:n,route:i}),s}}function A({error:t,event:e,status:r,message:n}){let o=t instanceof Error?t:new Error(String(t||n||"Erro SvelteKit"));a.captureError(o,{framework:"sveltekit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||""})}function T(){let t=globalThis;!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__||(t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(e,r){return h(e,r)})}0&&(module.exports={audit,auditFetch,auditHandle,enableNetworkTracing,handleSvelteKitError,initSvelteDevInspector});
|
|
1
|
+
"use strict";var b=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var A=(t,e)=>{for(var r in e)b(t,r,{get:e[r],enumerable:!0})},D=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of _(e))!k.call(t,n)&&n!==r&&b(t,n,{get:()=>e[n],enumerable:!(s=U(e,n))||s.enumerable});return t};var C=t=>D(b({},"__esModule",{value:!0}),t);var H={};A(H,{audit:()=>i,auditFetch:()=>L,auditHandle:()=>z,enableNetworkTracing:()=>G,handleSvelteKitError:()=>$,initSvelteDevInspector:()=>K});module.exports=C(H);var R="https://api.devinspector.com.br/api/ingest/track";var x=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function N(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return x.some(r=>e.includes(r))}function g(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(o=>g(o,e+1,r));let s=t,n={};for(let[o,a]of Object.entries(s)){if(N(o)){n[o]="[REDACTED]";continue}n[o]=g(a,e+1,r)}return n}function w(t){if(t)return String(t).trim().toUpperCase()}function T(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function O(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 y(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var I=class{constructor(){this.apiKey="";this.endpoint=R;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||R,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?g(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?g(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(e,r.origin);return s.origin===r.origin&&s.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return y("req")}createTraceId(){return y("trace")}createSpanId(){return y("span")}captureRequest(e){let r=w(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=T(e.statusCode)??0,o=M(e.durationMs)??0,a={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:s,statusCode:n,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:a})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let s=M(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,s={},n={}){let o=O(e);if(!o)return;let a;try{a=B(r)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let s=e?.message?.trim()||"Erro desconhecido",n={...r},o=w(n.method),a=T(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,c=n.spanId?String(n.spanId):void 0,p=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:p,method:o,statusCode:a,requestId:u,traceId:d,spanId:c,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof r=="function"&&r(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let s=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(s,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let s=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=g(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},q="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=typeof globalThis<"u"?globalThis:{},i=v[q]||new I;v[q]=i;async function E(t,e,r={}){let s=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!s)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),o=w(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&i.isIngestUrl(n))return s(t,e);let a=i.createRequestId(),u=i.createTraceId(),d=i.createSpanId(),c=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));c.set("x-devinspector-request-id",a),c.set("x-devinspector-trace-id",u),c.set("x-devinspector-span-id",d);let p={...e,headers:c},l=typeof performance<"u"?performance.now():Date.now();try{let m=await s(t,p),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));return(m.status>=400||f>=i.getSlowThresholdMs())&&i.captureRequest({method:o,url:n,statusCode:m.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),i.addBreadcrumb({type:"http",message:`${o} ${n}`,metadata:{phase:"complete",statusCode:m.status,durationMs:f,requestId:a,traceId:u,spanId:d}}),m}catch(m){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));i.captureRequest({method:o,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),i.addBreadcrumb({type:"http_error",message:`${o} ${n}`,metadata:{statusCode:0,durationMs:f,requestId:a,traceId:u,spanId:d}});let S=m instanceof Error?m:new Error(String(m));throw i.captureError(S,{url:n,method:o,requestId:a,traceId:u,spanId:d,type:r.errorType||"network_error"}),m}}function K(t){i.init(t)}async function L(t,e){return E(t,e,{errorType:"svelte_network_error"})}async function z({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),s=t.request?.method||"GET",n=t.url?.pathname||t.url?.href||"/",o=t.route?.id||n;if(n&&i.isIngestUrl(n))return e(t);let a=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"",u=h(t.request,"x-devinspector-request-id")||i.createRequestId(),d=h(t.request,"x-devinspector-trace-id")||i.createTraceId(),c=h(t.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{framework:"SvelteKit",phase:"start",requestId:u,traceId:d,spanId:c,route:o}});try{let p=await e(t),l=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return(p.status>=400||l>=300)&&i.captureRequest({method:s,url:n,statusCode:p.status,durationMs:l,route:o,userAgent:a,requestId:u,traceId:d,spanId:c}),i.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:p.status,durationMs:l,requestId:u,traceId:d,spanId:c,route:o}}),p}catch(p){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-r);i.captureRequest({method:s,url:n,statusCode:500,durationMs:l,route:o,userAgent:a,requestId:u,traceId:d,spanId:c}),i.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:l,requestId:u,traceId:d,spanId:c,route:o}});let m=p instanceof Error?p:new Error(String(p));throw i.captureError(m,{framework:"SvelteKit",url:n,method:s,route:o,requestId:u,traceId:d,spanId:c}),p}}function $({error:t,event:e,status:r,message:s}){let n=t instanceof Error?t:new Error(String(t||s||"Erro SvelteKit")),o=h(e?.request,"x-devinspector-request-id")||i.createRequestId(),a=h(e?.request,"x-devinspector-trace-id")||i.createTraceId(),u=h(e?.request,"x-devinspector-span-id")||i.createSpanId();i.addBreadcrumb({type:"sveltekit_error",message:n.message||"Erro SvelteKit",metadata:{status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:a,spanId:u}}),i.captureError(n,{framework:"SvelteKit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:o,traceId:a,spanId:u})}function G(){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,s){return E(r,s,{errorType:"svelte_network_error",nativeFetch:e})}}function h(t,e){if(!t?.headers)return;if(typeof t.headers.get=="function")return t.headers.get(e)||void 0;let r=t.headers[e]||t.headers[e.toLowerCase()];return Array.isArray(r)?r[0]:r?String(r):void 0}0&&(module.exports={audit,auditFetch,auditHandle,enableNetworkTracing,handleSvelteKitError,initSvelteDevInspector});
|
package/dist/svelte.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ export { audit } from './index.cjs';
|
|
|
3
3
|
|
|
4
4
|
declare function initSvelteDevInspector(options: InitOptions): void;
|
|
5
5
|
declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
6
|
-
declare function auditHandle({ event, resolve }: any): Promise<any>;
|
|
7
|
-
declare function handleSvelteKitError({ error, event, status, message }: any): void;
|
|
6
|
+
declare function auditHandle({ event, resolve, }: any): Promise<any>;
|
|
7
|
+
declare function handleSvelteKitError({ error, event, status, message, }: any): void;
|
|
8
8
|
declare function enableNetworkTracing(): void;
|
|
9
9
|
|
|
10
10
|
export { InitOptions, auditFetch, auditHandle, enableNetworkTracing, handleSvelteKitError, initSvelteDevInspector };
|
package/dist/svelte.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export { audit } from './index.js';
|
|
|
3
3
|
|
|
4
4
|
declare function initSvelteDevInspector(options: InitOptions): void;
|
|
5
5
|
declare function auditFetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
6
|
-
declare function auditHandle({ event, resolve }: any): Promise<any>;
|
|
7
|
-
declare function handleSvelteKitError({ error, event, status, message }: any): void;
|
|
6
|
+
declare function auditHandle({ event, resolve, }: any): Promise<any>;
|
|
7
|
+
declare function handleSvelteKitError({ error, event, status, message, }: any): void;
|
|
8
8
|
declare function enableNetworkTracing(): void;
|
|
9
9
|
|
|
10
10
|
export { InitOptions, auditFetch, auditHandle, enableNetworkTracing, handleSvelteKitError, initSvelteDevInspector };
|
package/dist/svelte.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var p=class{constructor(){this.apiKey="PENDING_API_KEY";this.endpoint="https://api.devinspector.com.br/api/ingest/track";this.environment="production";this.initialized=!1;this.listenersAttached=!1}init(e){if(!e.apiKey){console.warn("[AuditSDK] API Key n\xE3o fornecida no init().");return}this.apiKey=e.apiKey,e.endpoint&&(this.endpoint=e.endpoint),e.environment&&(this.environment=e.environment),this.initialized=!0,this.listenGlobalErrors()}isIngestUrl(e){if(!e)return!1;try{if(this.endpoint&&e.includes(this.endpoint))return!0;let t=new URL(this.endpoint);return e.includes(t.host)||e.includes(t.pathname)}catch{return e.includes("devinspector.com.br")||e.includes("/ingest/track")}}captureRequest(e){let t={type:"request_metric",method:e.method,url:e.url,statusCode:e.statusCode,durationMs:e.durationMs,browser:e.userAgent||"",metadata:{environment:this.environment,timestamp:new Date().toISOString(),route:e.route||e.url,dbQueriesCount:e.dbQueriesCount||0,slowQueryMs:e.slowQueryMs||0}};this.send(t)}listenGlobalErrors(){if(this.listenersAttached)return;this.listenersAttached=!0;let e=globalThis;if(e.ErrorUtils&&typeof e.ErrorUtils.setGlobalHandler=="function"){let t=e.ErrorUtils.getGlobalHandler();e.ErrorUtils.setGlobalHandler((n,o)=>{let i=n instanceof Error?n:new Error(String(n?.message||n||"Erro React Native desconhecido"));this.captureError(i,{type:"react_native_error",isFatal:!!o}),t&&t(n,o)})}else if(typeof window<"u"&&window.addEventListener)window.addEventListener("error",t=>{this.captureError(t.error||new Error(t.message||"Erro global desconhecido"),{filename:t.filename,lineno:t.lineno,colno:t.colno})}),window.addEventListener("unhandledrejection",t=>{let n=t.reason instanceof Error?t.reason:new Error(String(t.reason));this.captureError(n,{type:"unhandled_rejection"})});else if(e.process?.on){let t=e.process;t.on("uncaughtException",n=>{this.captureError(n,{type:"uncaught_exception"})}),t.on("unhandledRejection",n=>{let o=n instanceof Error?n:new Error(String(n));this.captureError(o,{type:"unhandled_rejection"})})}}truncate(e,t=5e3,n=new WeakSet){if(typeof e=="string")return e.length>t?e.substring(0,t)+"... [truncated]":e;if(e&&typeof e=="object"&&e!==null){if(n.has(e))return"[Circular Reference]";n.add(e);let o={};for(let[i,u]of Object.entries(e))o[i]=this.truncate(u,t,n);return o}return e}captureError(e,t={}){let n=e.message||"Erro Desconhecido",o=e.stack||"",i={type:"error",message:this.truncate(n,500),stackTrace:this.truncate(o,1e4),url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(i)}captureException(e,t={}){this.captureError(e,t)}captureMessage(e,t={}){let n={type:"message",message:this.truncate(e,500),stackTrace:"",url:typeof window<"u"?window.location.href:"",browser:typeof navigator<"u"?navigator.userAgent:"",metadata:this.truncate({...t,level:"info",environment:this.environment,timestamp:new Date().toISOString()},5e3)};this.send(n)}async send(e){let t=this.apiKey&&this.apiKey!=="PENDING_API_KEY"?this.apiKey:"dev-fallback-key";try{let n=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":t},body:JSON.stringify(e),keepalive:!0});n.ok||console.error(`[DevInspector] Erro na API (${n.status}): ${n.statusText}`)}catch(n){console.error("[DevInspector] Falha ao enviar requisi\xE7\xE3o para o painel:",n)}}},d="__DEVINSPECT_AUDIT_CORE_INSTANCE__",h=()=>{let r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};return r[d]||(r[d]=new p),r[d]},a=h();async function f(r,e,t){let n=t?.nativeFetch||(typeof window<"u"?window.fetch:typeof globalThis<"u"?globalThis.fetch:fetch),o="";if(typeof r=="string"?o=r:r instanceof URL?o=r.toString():typeof r=="object"&&r!==null&&"url"in r&&(o=r.url),o&&a.isIngestUrl(o))return n(r,e);let i=e?.method||(typeof r=="object"&&r!==null&&"method"in r?r.method:"GET"),u=typeof performance<"u"?performance.now():Date.now();try{let s=await n(r,e),c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);return(s.status>=400||c>=300)&&a.captureRequest({method:i,url:o,statusCode:s.status,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-u);throw a.captureRequest({method:i,url:o,statusCode:0,durationMs:c,route:o,userAgent:typeof navigator<"u"?navigator.userAgent:t?.defaultUserAgent}),a.captureException(s instanceof Error?s:new Error(String(s)),{url:o,method:i,type:t?.errorType||"network_error"}),s}}function E(r){a.init(r)}async function y(r,e){return f(r,e,{errorType:"svelte_network_error"})}async function b({event:r,resolve:e}){let t=typeof performance<"u"?performance.now():Date.now(),n=r.request?.method||"GET",o=r.url?.pathname||r.url?.href||"/",i=r.route?.id||o;if(o&&a.isIngestUrl(o))return e(r);let u=typeof r.request?.headers?.get=="function"&&r.request.headers.get("user-agent")||"";try{let s=await e(r),c=Math.round((typeof performance<"u"?performance.now():Date.now())-t);return(s.status>=400||c>=300)&&a.captureRequest({method:n,url:o,statusCode:s.status,durationMs:c,route:i,userAgent:u}),s}catch(s){let c=Math.round((typeof performance<"u"?performance.now():Date.now())-t);a.captureRequest({method:n,url:o,statusCode:500,durationMs:c,route:i,userAgent:u});let l=s instanceof Error?s:new Error(String(s));throw a.captureError(l,{framework:"sveltekit",url:o,method:n,route:i}),s}}function v({error:r,event:e,status:t,message:n}){let o=r instanceof Error?r:new Error(String(r||n||"Erro SvelteKit"));a.captureError(o,{framework:"sveltekit",status:t||500,url:e?.url?.href||"",route:e?.route?.id||""})}function R(){let r=globalThis;!r.fetch||r.__DEVINSPECTOR_FETCH_PATCHED__||(r.__DEVINSPECTOR_FETCH_PATCHED__=!0,r.fetch=async function(e,t){return y(e,t)})}export{a as audit,y as auditFetch,b as auditHandle,R as enableNetworkTracing,v as handleSvelteKitError,E as initSvelteDevInspector};
|
|
1
|
+
var S="https://api.devinspector.com.br/api/ingest/track";var v=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function U(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return v.some(r=>e.includes(r))}function g(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(i=>g(i,e+1,r));let s=t,n={};for(let[i,a]of Object.entries(s)){if(U(i)){n[i]="[REDACTED]";continue}n[i]=g(a,e+1,r)}return n}function y(t){if(t)return String(t).trim().toUpperCase()}function R(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function T(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function _(t){return String(t??"").trim().slice(0,200)}function k(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var w=class{constructor(){this.apiKey="";this.endpoint=S;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||S,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?g(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?g(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),s=new URL(e,r.origin);return s.origin===r.origin&&s.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return b("req")}createTraceId(){return b("trace")}createSpanId(){return b("span")}captureRequest(e){let r=y(e.method)||"GET",s=String(e.url||"").trim();if(!s)return;let n=R(e.statusCode)??0,i=T(e.durationMs)??0,a={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:s,statusCode:n,durationMs:i,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:a})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let s=T(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:s,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:s,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,s={},n={}){let i=_(e);if(!i)return;let a;try{a=k(r)}catch{return}this.send({type:"custom_metric",metricName:i,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...s,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let s=e?.message?.trim()||"Erro desconhecido",n={...r},i=y(n.method),a=R(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,c=n.spanId?String(n.spanId):void 0,p=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:s,stackTrace:e?.stack||"",url:p,method:i,statusCode:a,requestId:u,traceId:d,spanId:c,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let s=e instanceof Error?e:new Error(String(e));this.captureError(s,r)}captureMessage(e,r={}){let s=String(e||"").trim();s&&this.send({type:"message",message:s,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((s,n)=>{this.captureError(s,{platform:"react-native",fatal:n}),typeof r=="function"&&r(s,n)})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",r=>{let s=r.error instanceof Error?r.error:new Error(r.message||"Erro global");this.captureError(s,{url:r.filename||window.location.href,line:r.lineno,column:r.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",r=>{let s=r.reason instanceof Error?r.reason:new Error(String(r.reason));this.captureError(s,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",r=>{this.captureError(r,{platform:"node"})}),process.on("unhandledRejection",r=>{this.captureException(r,{platform:"node"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=g(e);try{let s=typeof fetch=="function"?fetch:void 0;if(!s)return;await s(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},M="__DEVINSPECT_AUDIT_CORE_INSTANCE__",q=typeof globalThis<"u"?globalThis:{},o=q[M]||new w;q[M]=o;async function I(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=y(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&o.isIngestUrl(n))return s(t,e);let a=o.createRequestId(),u=o.createTraceId(),d=o.createSpanId(),c=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));c.set("x-devinspector-request-id",a),c.set("x-devinspector-trace-id",u),c.set("x-devinspector-span-id",d);let p={...e,headers:c},l=typeof performance<"u"?performance.now():Date.now();try{let m=await s(t,p),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));return(m.status>=400||f>=o.getSlowThresholdMs())&&o.captureRequest({method:i,url:n,statusCode:m.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),o.addBreadcrumb({type:"http",message:`${i} ${n}`,metadata:{phase:"complete",statusCode:m.status,durationMs:f,requestId:a,traceId:u,spanId:d}}),m}catch(m){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-l));o.captureRequest({method:i,url:n,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),o.addBreadcrumb({type:"http_error",message:`${i} ${n}`,metadata:{statusCode:0,durationMs:f,requestId:a,traceId:u,spanId:d}});let E=m instanceof Error?m:new Error(String(m));throw o.captureError(E,{url:n,method:i,requestId:a,traceId:u,spanId:d,type:r.errorType||"network_error"}),m}}function x(t){o.init(t)}async function N(t,e){return I(t,e,{errorType:"svelte_network_error"})}async function O({event:t,resolve:e}){let r=typeof performance<"u"?performance.now():Date.now(),s=t.request?.method||"GET",n=t.url?.pathname||t.url?.href||"/",i=t.route?.id||n;if(n&&o.isIngestUrl(n))return e(t);let a=typeof t.request?.headers?.get=="function"&&t.request.headers.get("user-agent")||"",u=h(t.request,"x-devinspector-request-id")||o.createRequestId(),d=h(t.request,"x-devinspector-trace-id")||o.createTraceId(),c=h(t.request,"x-devinspector-span-id")||o.createSpanId();o.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{framework:"SvelteKit",phase:"start",requestId:u,traceId:d,spanId:c,route:i}});try{let p=await e(t),l=Math.round((typeof performance<"u"?performance.now():Date.now())-r);return(p.status>=400||l>=300)&&o.captureRequest({method:s,url:n,statusCode:p.status,durationMs:l,route:i,userAgent:a,requestId:u,traceId:d,spanId:c}),o.addBreadcrumb({type:"http",message:`${s} ${n}`,metadata:{framework:"SvelteKit",phase:"complete",statusCode:p.status,durationMs:l,requestId:u,traceId:d,spanId:c,route:i}}),p}catch(p){let l=Math.round((typeof performance<"u"?performance.now():Date.now())-r);o.captureRequest({method:s,url:n,statusCode:500,durationMs:l,route:i,userAgent:a,requestId:u,traceId:d,spanId:c}),o.addBreadcrumb({type:"http_error",message:`${s} ${n}`,metadata:{framework:"SvelteKit",statusCode:500,durationMs:l,requestId:u,traceId:d,spanId:c,route:i}});let m=p instanceof Error?p:new Error(String(p));throw o.captureError(m,{framework:"SvelteKit",url:n,method:s,route:i,requestId:u,traceId:d,spanId:c}),p}}function B({error:t,event:e,status:r,message:s}){let n=t instanceof Error?t:new Error(String(t||s||"Erro SvelteKit")),i=h(e?.request,"x-devinspector-request-id")||o.createRequestId(),a=h(e?.request,"x-devinspector-trace-id")||o.createTraceId(),u=h(e?.request,"x-devinspector-span-id")||o.createSpanId();o.addBreadcrumb({type:"sveltekit_error",message:n.message||"Erro SvelteKit",metadata:{status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:i,traceId:a,spanId:u}}),o.captureError(n,{framework:"SvelteKit",status:r||500,url:e?.url?.href||"",route:e?.route?.id||"",requestId:i,traceId:a,spanId:u})}function K(){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,s){return I(r,s,{errorType:"svelte_network_error",nativeFetch:e})}}function h(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{o as audit,N as auditFetch,O as auditHandle,K as enableNetworkTracing,B as handleSvelteKitError,x as initSvelteDevInspector};
|
package/dist/vanilla.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var r in e)h(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of D(e))!q.call(t,n)&&n!==r&&h(t,n,{get:()=>e[n],enumerable:!(i=k(e,n))||i.enumerable});return t};var N=t=>x(h({},"__esModule",{value:!0}),t);var G={};C(G,{audit:()=>s,auditFetch:()=>y,default:()=>F,enableNetworkTracing:()=>_});module.exports=N(G);var R="https://api.devinspector.com.br/api/ingest/track";var O=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function L(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return O.some(r=>e.includes(r))}function l(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(o=>l(o,e+1,r));let i=t,n={};for(let[o,a]of Object.entries(i)){if(L(o)){n[o]="[REDACTED]";continue}n[o]=l(a,e+1,r)}return n}function b(t){if(t)return String(t).trim().toUpperCase()}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function T(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function B(t){return String(t??"").trim().slice(0,200)}function z(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function g(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var w=class{constructor(){this.apiKey="";this.endpoint=R;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||R,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(e,r.origin);return i.origin===r.origin&&i.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return g("req")}createTraceId(){return g("trace")}createSpanId(){return g("span")}captureRequest(e){let r=b(e.method)||"GET",i=String(e.url||"").trim();if(!i)return;let n=M(e.statusCode)??0,o=T(e.durationMs)??0,a={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:i,statusCode:n,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:a})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let i=T(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,i={},n={}){let o=B(e);if(!o)return;let a;try{a=z(r)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...i,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},o=b(n.method),a=M(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,p=n.spanId?String(n.spanId):void 0,f=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:i,stackTrace:e?.stack||"",url:f,method:o,statusCode:a,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let i=e instanceof Error?e:new Error(String(e));this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();i&&this.send({type:"message",message:i,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}),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(String(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"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=l(e);try{let i=typeof fetch=="function"?fetch:void 0;if(!i)return;await i(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},S="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=typeof globalThis<"u"?globalThis:{},s=v[S]||new w;v[S]=s;async function U(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||""),o=b(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&s.isIngestUrl(n))return i(t,e);let a=s.createRequestId(),u=s.createTraceId(),d=s.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let f={...e,headers:p},I=typeof performance<"u"?performance.now():Date.now();try{let c=await i(t,f),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));return(c.status>=400||m>=s.getSlowThresholdMs())&&s.captureRequest({method:o,url:n,statusCode:c.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),s.addBreadcrumb({type:"http",message:`${o} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:m,requestId:a,traceId:u,spanId:d}}),c}catch(c){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));s.captureRequest({method:o,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),s.addBreadcrumb({type:"http_error",message:`${o} ${n}`,metadata:{statusCode:0,durationMs:m,requestId:a,traceId:u,spanId:d}});let E=c instanceof Error?c:new Error(String(c));throw s.captureError(E,{url:n,method:o,requestId:a,traceId:u,spanId:d,type:r.errorType||"network_error"}),c}}var A=null;async function y(t,e,r){return U(t,e,{errorType:"vanilla_network_error",nativeFetch:r||A||void 0})}function _(){let t=typeof window<"u"?window:globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);A=e,t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(...r){let[i,n]=r;return y(i,n,e)}}typeof window<"u"&&(window.DevInspector={init:t=>s.init(t),captureError:(t,e)=>s.captureError(t,e),captureException:(t,e)=>s.captureException(t,e),captureMessage:(t,e)=>s.captureMessage(t,e),captureMetric:(t,e,r)=>s.captureMetric(t,e,r),captureCustomMetric:t=>s.captureCustomMetric(t),auditFetch:y,enableNetworkTracing:_,core:s});var F=s;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
package/dist/vanilla.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var DevInspector=(()=>{var
|
|
1
|
+
"use strict";var DevInspector=(()=>{var h=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var r in e)h(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of D(e))!q.call(t,n)&&n!==r&&h(t,n,{get:()=>e[n],enumerable:!(i=k(e,n))||i.enumerable});return t};var N=t=>x(h({},"__esModule",{value:!0}),t);var G={};C(G,{audit:()=>s,auditFetch:()=>y,default:()=>F,enableNetworkTracing:()=>_});var R="https://api.devinspector.com.br/api/ingest/track";var O=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function L(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return O.some(r=>e.includes(r))}function l(t,e=0,r=new WeakSet){if(t==null)return t;if(typeof t=="string")return t.length>1e4?`${t.slice(0,1e4)}...[truncated]`:t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="bigint")return String(t);if(typeof t=="function")return"[Function]";if(e>=6)return"[MaxDepth]";if(typeof t!="object")return String(t);if(r.has(t))return"[Circular]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(o=>l(o,e+1,r));let i=t,n={};for(let[o,a]of Object.entries(i)){if(L(o)){n[o]="[REDACTED]";continue}n[o]=l(a,e+1,r)}return n}function b(t){if(t)return String(t).trim().toUpperCase()}function M(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.round(t)}function T(t){if(!(typeof t!="number"||!Number.isFinite(t)))return Math.max(0,Math.round(t))}function B(t){return String(t??"").trim().slice(0,200)}function z(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function g(t){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${t}-${e.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}var w=class{constructor(){this.apiKey="";this.endpoint=R;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||R,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(e,r.origin);return i.origin===r.origin&&i.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return g("req")}createTraceId(){return g("trace")}createSpanId(){return g("span")}captureRequest(e){let r=b(e.method)||"GET",i=String(e.url||"").trim();if(!i)return;let n=M(e.statusCode)??0,o=T(e.durationMs)??0,a={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:i,statusCode:n,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:a})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let i=T(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,i={},n={}){let o=B(e);if(!o)return;let a;try{a=z(r)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...i,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},o=b(n.method),a=M(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,p=n.spanId?String(n.spanId):void 0,f=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:i,stackTrace:e?.stack||"",url:f,method:o,statusCode:a,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let i=e instanceof Error?e:new Error(String(e));this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();i&&this.send({type:"message",message:i,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}),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(String(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"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=l(e);try{let i=typeof fetch=="function"?fetch:void 0;if(!i)return;await i(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},S="__DEVINSPECT_AUDIT_CORE_INSTANCE__",v=typeof globalThis<"u"?globalThis:{},s=v[S]||new w;v[S]=s;async function U(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||""),o=b(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&s.isIngestUrl(n))return i(t,e);let a=s.createRequestId(),u=s.createTraceId(),d=s.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let f={...e,headers:p},I=typeof performance<"u"?performance.now():Date.now();try{let c=await i(t,f),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));return(c.status>=400||m>=s.getSlowThresholdMs())&&s.captureRequest({method:o,url:n,statusCode:c.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),s.addBreadcrumb({type:"http",message:`${o} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:m,requestId:a,traceId:u,spanId:d}}),c}catch(c){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-I));s.captureRequest({method:o,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),s.addBreadcrumb({type:"http_error",message:`${o} ${n}`,metadata:{statusCode:0,durationMs:m,requestId:a,traceId:u,spanId:d}});let E=c instanceof Error?c:new Error(String(c));throw s.captureError(E,{url:n,method:o,requestId:a,traceId:u,spanId:d,type:r.errorType||"network_error"}),c}}var A=null;async function y(t,e,r){return U(t,e,{errorType:"vanilla_network_error",nativeFetch:r||A||void 0})}function _(){let t=typeof window<"u"?window:globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);A=e,t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(...r){let[i,n]=r;return y(i,n,e)}}typeof window<"u"&&(window.DevInspector={init:t=>s.init(t),captureError:(t,e)=>s.captureError(t,e),captureException:(t,e)=>s.captureException(t,e),captureMessage:(t,e)=>s.captureMessage(t,e),captureMetric:(t,e,r)=>s.captureMetric(t,e,r),captureCustomMetric:t=>s.captureCustomMetric(t),auditFetch:y,enableNetworkTracing:_,core:s});var F=s;return N(G);})();
|
package/dist/vanilla.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var I="https://api.devinspector.com.br/api/ingest/track";var A=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function _(t){let e=t.toLowerCase().replace(/[\s-]/g,"_");return A.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]";if(r.add(t),Array.isArray(t))return t.slice(0,100).map(o=>l(o,e+1,r));let i=t,n={};for(let[o,a]of Object.entries(i)){if(_(o)){n[o]="[REDACTED]";continue}n[o]=l(a,e+1,r)}return n}function g(t){if(t)return String(t).trim().toUpperCase()}function E(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 k(t){return String(t??"").trim().slice(0,200)}function D(t){let e=Number(t);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function 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)}`}var b=class{constructor(){this.apiKey="";this.endpoint=I;this.environment="production";this.slowThresholdMs=300;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1}init(e){if(!e?.apiKey)throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey,this.endpoint=e.endpoint?.trim()||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?e.slowThresholdMs:300,this.initialized=!0,this.attachGlobalListeners()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getSlowThresholdMs(){return this.slowThresholdMs}isInitialized(){return this.initialized}setUser(e){this.user=e?l(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){let r={timestamp:e.timestamp||new Date().toISOString(),type:e.type,message:e.message,metadata:e.metadata?l(e.metadata):void 0};this.breadcrumbs.push(r),this.breadcrumbs.length>50&&(this.breadcrumbs=this.breadcrumbs.slice(-50))}getBreadcrumbs(){return[...this.breadcrumbs]}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs}}isIngestUrl(e){if(!e)return!1;try{let r=new URL(this.endpoint),i=new URL(e,r.origin);return i.origin===r.origin&&i.pathname===r.pathname}catch{return e.includes(this.endpoint)}}createRequestId(){return h("req")}createTraceId(){return h("trace")}createSpanId(){return h("span")}captureRequest(e){let r=g(e.method)||"GET",i=String(e.url||"").trim();if(!i)return;let n=E(e.statusCode)??0,o=R(e.durationMs)??0,a={...e.metadata||{},route:e.route,dbQueriesCount:e.dbQueriesCount,slowQueryMs:e.slowQueryMs,timestamp:new Date().toISOString()};this.send({type:"request_metric",method:r,url:i,statusCode:n,durationMs:o,browser:e.userAgent,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:a})}captureDbQuery(e){let r=String(e.operation||"").trim();if(!r)return;let i=R(e.durationMs)??0,n={...e.metadata||{},operation:r,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};this.send({type:"db_query",message:`Database operation: ${r}`,stackTrace:"",url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:n})}captureMetric(e,r,i={},n={}){let o=k(e);if(!o)return;let a;try{a=D(r)}catch{return}this.send({type:"custom_metric",metricName:o,metricValue:a,requestId:n.requestId,traceId:n.traceId,spanId:n.spanId,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...i,timestamp:new Date().toISOString()}})}captureCustomMetric(e){this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,r={}){let i=e?.message?.trim()||"Erro desconhecido",n={...r},o=g(n.method),a=E(n.statusCode??n.status),u=n.requestId?String(n.requestId):void 0,d=n.traceId?String(n.traceId):void 0,p=n.spanId?String(n.spanId):void 0,f=n.url?String(n.url):void 0;delete n.requestId,delete n.traceId,delete n.spanId,delete n.method,delete n.statusCode,delete n.status,this.send({type:"error",message:i,stackTrace:e?.stack||"",url:f,method:o,statusCode:a,requestId:u,traceId:d,spanId:p,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...n,timestamp:new Date().toISOString()}})}captureException(e,r={}){let i=e instanceof Error?e:new Error(String(e));this.captureError(i,r)}captureMessage(e,r={}){let i=String(e||"").trim();i&&this.send({type:"message",message:i,environment:this.environment,release:this.release,user:this.user,breadcrumbs:this.breadcrumbs,metadata:{...r,timestamp:new Date().toISOString()}})}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let r=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,n)=>{this.captureError(i,{platform:"react-native",fatal:n}),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(String(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"})}))}async send(e){if(!this.initialized||!this.apiKey)return;let r=l(e);try{let i=typeof fetch=="function"?fetch:void 0;if(!i)return;await i(this.endpoint,{method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),keepalive:!0})}catch{}}},M="__DEVINSPECT_AUDIT_CORE_INSTANCE__",T=typeof globalThis<"u"?globalThis:{},s=T[M]||new b;T[M]=s;async function S(t,e,r={}){let i=r.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let n=typeof t=="string"?t:t instanceof URL?t.toString():String(t.url||""),o=g(e?.method||(typeof t!="string"&&!(t instanceof URL)?t.method:"GET"))||"GET";if(n&&s.isIngestUrl(n))return i(t,e);let a=s.createRequestId(),u=s.createTraceId(),d=s.createSpanId(),p=new Headers(e?.headers||(typeof t!="string"&&!(t instanceof URL)?t.headers:void 0));p.set("x-devinspector-request-id",a),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",d);let f={...e,headers:p},w=typeof performance<"u"?performance.now():Date.now();try{let c=await i(t,f),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-w));return(c.status>=400||m>=s.getSlowThresholdMs())&&s.captureRequest({method:o,url:n,statusCode:c.status,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),s.addBreadcrumb({type:"http",message:`${o} ${n}`,metadata:{phase:"complete",statusCode:c.status,durationMs:m,requestId:a,traceId:u,spanId:d}}),c}catch(c){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-w));s.captureRequest({method:o,url:n,statusCode:0,durationMs:m,userAgent:typeof navigator<"u"?navigator.userAgent:r.defaultUserAgent,requestId:a,traceId:u,spanId:d}),s.addBreadcrumb({type:"http_error",message:`${o} ${n}`,metadata:{statusCode:0,durationMs:m,requestId:a,traceId:u,spanId:d}});let y=c instanceof Error?c:new Error(String(c));throw s.captureError(y,{url:n,method:o,requestId:a,traceId:u,spanId:d,type:r.errorType||"network_error"}),c}}var v=null;async function U(t,e,r){return S(t,e,{errorType:"vanilla_network_error",nativeFetch:r||v||void 0})}function q(){let t=typeof window<"u"?window:globalThis;if(!t.fetch||t.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=t.fetch.bind(t);v=e,t.__DEVINSPECTOR_FETCH_PATCHED__=!0,t.fetch=async function(...r){let[i,n]=r;return U(i,n,e)}}typeof window<"u"&&(window.DevInspector={init:t=>s.init(t),captureError:(t,e)=>s.captureError(t,e),captureException:(t,e)=>s.captureException(t,e),captureMessage:(t,e)=>s.captureMessage(t,e),captureMetric:(t,e,r)=>s.captureMetric(t,e,r),captureCustomMetric:t=>s.captureCustomMetric(t),auditFetch:U,enableNetworkTracing:q,core:s});var O=s;export{s as audit,U as auditFetch,O as default,q as enableNetworkTracing};
|