@xcodleox/devinspector 9.3.1 → 9.3.2

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/vue.js CHANGED
@@ -1 +1 @@
1
- var A="9.3.1",N=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),k="https://api.devinspector.com.br/api/ingest/track",M="https://api.devinspector.com.br/api/ingest/apm",D=50,T=1e4,Q=6,q=1e4,L=5e3,V=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function z(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return V.some(t=>e.includes(t))}function h(n,e=0,t=new WeakSet){if(n==null)return n;if(typeof n=="string")return n.length>T?`${n.slice(0,T)}...[truncated]`:n;if(typeof n=="number"||typeof n=="boolean")return n;if(typeof n=="bigint")return String(n);if(typeof n=="function")return"[Function]";if(e>=Q)return"[MaxDepth]";if(typeof n!="object")return String(n);if(t.has(n))return"[Circular]";t.add(n);try{if(Array.isArray(n))return n.slice(0,100).map(s=>h(s,e+1,t));let i=n,r={};for(let[s,o]of Object.entries(i)){if(z(s)){r[s]="[REDACTED]";continue}r[s]=h(o,e+1,t)}return r}finally{t.delete(n)}}function w(n){if(n instanceof Error)return n.message||"Erro desconhecido";if(typeof n=="string")return n||"Erro desconhecido";try{let e=h(n);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(n){return n&&String(n).trim().toUpperCase()||void 0}function C(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.round(n)}function v(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function _(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function F(n){return String(n??"").trim().slice(0,200)}function B(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function I(n,e=200){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function j(n){let e=I(n,50);if(e&&N.has(e))return e}function y(n){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${n}-${e.randomUUID()}`:`${n}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function d(n){return h(n)}var R=class{constructor(){this.apiKey="";this.endpoint=k;this.apmEndpoint=M;this.environment="production";this.sdkVersion=A;this.slowThresholdMs=300;this.requestTimeoutMs=q;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[];this.connectionTestLastCheckedAt=0}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||k,this.apmEndpoint=e.apmEndpoint?.trim()||M,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=j(e.technology),this.installationId=I(e.installationId,200),this.sdkVersion=I(e.sdkVersion,100)||A,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):q,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?h(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,T),metadata:e.metadata?h(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>D&&(this.breadcrumbs=this.breadcrumbs.slice(-D))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:d(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),i=new URL(this.apmEndpoint),r=new URL(e,t.origin),s=r.origin,o=r.pathname.replace(/\/$/,""),c=t.pathname.replace(/\/$/,""),u=i.pathname.replace(/\/$/,"");return s===t.origin&&o===c||s===i.origin&&o===u}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return y("req")}createTraceId(){return y("trace")}createSpanId(){return y("span")}captureRequest(e){let t=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return Promise.resolve();let r=C(e.statusCode)??0,s=v(e.durationMs)??0,o=_(e.ip),c={...e.metadata||{},timestamp:new Date().toISOString()};return this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:s,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(c)})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return Promise.resolve();let i=v(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(r)})}captureMetric(e,t,i={},r={}){let s=F(e);if(!s)return Promise.resolve();let o;try{o=B(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:s,metricValue:o,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let i=e?.message?.trim()||"Erro desconhecido",r={...t},s=E(r.method),o=C(r.statusCode??r.status),c=v(r.durationMs),u=_(r.ip),p=r.url!==void 0&&r.url!==null?String(r.url).trim():void 0,g=typeof r.requestId=="string"&&r.requestId.trim()||void 0,m=typeof r.traceId=="string"&&r.traceId.trim()||void 0,l=typeof r.spanId=="string"&&r.spanId.trim()||void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.requestId,delete r.traceId,delete r.spanId,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...p?{url:p}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...c!==void 0?{durationMs:c}:{},...u?{ip:u}:{},...g?{requestId:g}:{},...m?{traceId:m}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(w(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,T),environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...t,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},...this.connectionTestId?{connectionTestId:this.connectionTestId}:{},sdkVersion:this.sdkVersion}}getPendingConnectionTestEndpoint(){try{let e=new URL(this.endpoint),t=new URL("/api/integrations/sdk/pending-test",e.origin);return this.technology&&t.searchParams.set("technology",this.technology),t.toString()}catch{return}}async refreshPendingConnectionTest(e=!1){if(!this.initialized||!this.apiKey||!this.technology)return;let t=Date.now();if(!e&&this.connectionTestLastCheckedAt>0&&t-this.connectionTestLastCheckedAt<L){this.connectionTestExpiresAt&&t>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}if(this.connectionTestRequest)return this.connectionTestRequest;let i=this.getPendingConnectionTestEndpoint();if(i)return this.connectionTestRequest=this.fetchPendingConnectionTest(i).finally(()=>{this.connectionTestRequest=void 0}),this.connectionTestRequest}async fetchPendingConnectionTest(e){this.connectionTestLastCheckedAt=Date.now();let t=typeof fetch=="function"?fetch:void 0;if(!t)return;let i,r;try{typeof AbortController<"u"&&(i=new AbortController,r=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let s=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!s.ok)return;let o=await s.json(),c=I(o.connectionTestId??o.testId,200);if(!c){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=c;let u=o.expiresAt?new Date(o.expiresAt).getTime():void 0;this.connectionTestExpiresAt=u&&Number.isFinite(u)?u:void 0}catch{return}finally{r!==void 0&&clearTimeout(r)}}clearConnectionTest(e){e&&this.connectionTestId!==e||(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=Date.now())}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,r)=>{this.captureError(i,{platform:"react-native",fatal:r}).finally(()=>{typeof t=="function"&&t(i,r)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let i=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(i,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(w(t.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,t){if(!this.initialized||!this.apiKey)return Promise.resolve();let i=y("event"),r={...t,...this.getIntegrationContext(),eventId:i},s={id:i,endpoint:e,payload:d(r),resolve:()=>{}};return new Promise(o=>{s.resolve=o,this.sendQueue.push(s),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.refreshPendingConnectionTest();let t={...e.payload,...this.getIntegrationContext()},i=typeof t.connectionTestId=="string"?t.connectionTestId:void 0;await this.sendToEndpoint(e.endpoint,d(t))&&i&&this.clearConnectionTest(i)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let t of e)t()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=h(t),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let c=typeof window<"u"&&typeof window.document<"u",u={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};return c&&(u.keepalive=!0),(await i(e,u)).ok}catch{return!1}finally{o!==void 0&&clearTimeout(o)}}},S="__DEVINSPECT_AUDIT_CORE_INSTANCE__",P=typeof globalThis<"u"?globalThis:{},a=P[S]||new R;P[S]=a;async function U(n,e,t={}){let i=t.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let r=typeof n=="string"?n:n instanceof URL?n.toString():String(n.url||""),s=E(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(n,e);let o=a.createRequestId(),c=a.createTraceId(),u=a.createSpanId(),p=new Headers(e?.headers||(typeof n!="string"&&!(n instanceof URL)?n.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",c),p.set("x-devinspector-span-id",u);let g={...e,headers:p},m=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,g),f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-m)),b=l.status>=400||f>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:f,requestId:o,traceId:c,spanId:u}}),b&&a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:u}),l}catch(l){let f=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-m));a.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:f,requestId:o,traceId:c,spanId:u}}),a.captureRequest({method:s,url:r,statusCode:0,durationMs:f,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:c,spanId:u});let b=l instanceof Error?l:new Error(w(l));throw a.captureError(b,{url:r,method:s,type:t.errorType||"network_error",requestId:o,traceId:c,spanId:u}),l}}var x=null;async function O(n,e,t){return U(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||x||void 0})}function K(){if(typeof globalThis>"u")return;let n=globalThis;if(n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let t;try{t=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(t&&t.get&&!t.set||t&&t.writable===!1&&!t.set)return;let i=e.bind(globalThis);x=i;let r=function(s,o){return O(s,o,i)};try{t&&t.configurable?Object.defineProperty(globalThis,"fetch",{...t,value:r}):globalThis.fetch=r}catch{return}globalThis.fetch===r&&(n.__DEVINSPECTOR_NATIVE_FETCH__=i,n.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let n=window;n.DevInspector={init:e=>a.init(e),captureError:(e,t)=>a.captureError(e,t),captureException:(e,t)=>a.captureException(e,t),captureMessage:(e,t)=>a.captureMessage(e,t),captureMetric:(e,t,i)=>a.captureMetric(e,t,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:O,enableNetworkTracing:K,core:a}}var $=a;export{a as audit,O as auditFetch,$ as default,K as enableNetworkTracing};
1
+ var A="9.3.2",N=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),M="https://api.devinspector.com.br/api/ingest/track",k="https://api.devinspector.com.br/api/ingest/apm",C=50,T=1e4,Q=6,D=1e4,L=5e3,V=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function z(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return V.some(t=>e.includes(t))}function f(n,e=0,t=new WeakSet){if(n==null)return n;if(typeof n=="string")return n.length>T?`${n.slice(0,T)}...[truncated]`:n;if(typeof n=="number"||typeof n=="boolean")return n;if(typeof n=="bigint")return String(n);if(typeof n=="function")return"[Function]";if(e>=Q)return"[MaxDepth]";if(typeof n!="object")return String(n);if(t.has(n))return"[Circular]";t.add(n);try{if(Array.isArray(n))return n.slice(0,100).map(s=>f(s,e+1,t));let i=n,r={};for(let[s,o]of Object.entries(i)){if(z(s)){r[s]="[REDACTED]";continue}r[s]=f(o,e+1,t)}return r}finally{t.delete(n)}}function w(n){if(n instanceof Error)return n.message||"Erro desconhecido";if(typeof n=="string")return n||"Erro desconhecido";try{let e=f(n);return typeof e=="string"?e||"Erro desconhecido":JSON.stringify(e)||"Erro desconhecido"}catch{return"Erro desconhecido"}}function E(n){return n&&String(n).trim().toUpperCase()||void 0}function q(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.round(n)}function v(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function S(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function F(n){return String(n??"").trim().slice(0,200)}function B(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function I(n,e=200){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function j(n){let e=I(n,50);if(e&&N.has(e))return e}function y(n){let e=typeof globalThis<"u"?globalThis.crypto:void 0;return e&&typeof e.randomUUID=="function"?`${n}-${e.randomUUID()}`:`${n}-${Date.now()}-${Math.random().toString(36).slice(2,12)}`}function d(n){return f(n)}var R=class{constructor(){this.apiKey="";this.endpoint=M;this.apmEndpoint=k;this.environment="production";this.sdkVersion=A;this.slowThresholdMs=300;this.requestTimeoutMs=D;this.breadcrumbs=[];this.initialized=!1;this.listenersAttached=!1;this.sendQueue=[];this.isProcessingQueue=!1;this.flushResolvers=[];this.connectionTestLastCheckedAt=0}init(e){if(!e?.apiKey?.trim())throw new Error("DevInspector: apiKey \xE9 obrigat\xF3rio.");this.apiKey=e.apiKey.trim(),this.endpoint=e.endpoint?.trim()||M,this.apmEndpoint=e.apmEndpoint?.trim()||k,this.environment=e.environment?.trim()||"production",this.release=e.release?.trim()||void 0,this.technology=j(e.technology),this.installationId=I(e.installationId,200),this.sdkVersion=I(e.sdkVersion,100)||A,this.slowThresholdMs=typeof e.slowThresholdMs=="number"&&Number.isFinite(e.slowThresholdMs)&&e.slowThresholdMs>=0?Math.round(e.slowThresholdMs):300,this.requestTimeoutMs=typeof e.requestTimeoutMs=="number"&&Number.isFinite(e.requestTimeoutMs)&&e.requestTimeoutMs>0?Math.round(e.requestTimeoutMs):D,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.initialized=!0,this.attachGlobalListeners(),this.processQueue()}getApiKey(){return this.apiKey}getEndpoint(){return this.endpoint}getApmEndpoint(){return this.apmEndpoint}getEnvironment(){return this.environment}getRelease(){return this.release}getTechnology(){return this.technology}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}isInitialized(){return this.initialized}setUser(e){this.user=e?f(e):void 0}getUser(){return this.user}clearUser(){this.user=void 0}addBreadcrumb(e){if(!e||!e.type?.trim())return;let t={timestamp:e.timestamp||new Date().toISOString(),type:e.type.trim().slice(0,200),message:e.message?.slice(0,T),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>C&&(this.breadcrumbs=this.breadcrumbs.slice(-C))}getBreadcrumbs(){return this.breadcrumbs.map(e=>d(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,installationId:this.installationId,sdkVersion:this.sdkVersion,user:d(this.user),breadcrumbs:this.getBreadcrumbs()}}isIngestUrl(e){if(!e)return!1;try{let t=new URL(this.endpoint),i=new URL(this.apmEndpoint),r=new URL(e,t.origin),s=r.origin,o=r.pathname.replace(/\/$/,""),u=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return s===t.origin&&o===u||s===i.origin&&o===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return y("req")}createTraceId(){return y("trace")}createSpanId(){return y("span")}async captureRequest(e){let t=E(e.method)||"GET",i=String(e.url||"").trim();if(!i)return;let r=q(e.statusCode)??0,s=v(e.durationMs)??0,o=S(e.ip),u={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||s>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:s,...e.userAgent?{userAgent:e.userAgent}:{},...e.route!==void 0?{route:e.route}:{},...o?{ip:o}:{},...e.dbQueriesCount!==void 0?{dbQueriesCount:e.dbQueriesCount}:{},...e.slowQueryMs!==void 0?{slowQueryMs:e.slowQueryMs}:{},...e.requestId?{requestId:e.requestId}:{},...e.traceId?{traceId:e.traceId}:{},...e.spanId?{spanId:e.spanId}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(u)})}captureDbQuery(e){let t=String(e.operation||"").trim();if(!t)return Promise.resolve();let i=v(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:e.collection||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:e.url,method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d(r)})}captureMetric(e,t,i={},r={}){let s=F(e);if(!s)return Promise.resolve();let o;try{o=B(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:s,metricValue:o,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...i,timestamp:new Date().toISOString()})})}captureCustomMetric(e){return this.captureMetric(e.metricName,e.metricValue,e.metadata||{},{requestId:e.requestId,traceId:e.traceId,spanId:e.spanId})}captureError(e,t={}){let i=e?.message?.trim()||"Erro desconhecido",r={...t},s=E(r.method),o=q(r.statusCode??r.status),u=v(r.durationMs),c=S(r.ip),p=r.url!==void 0&&r.url!==null?String(r.url).trim():void 0,g=typeof r.requestId=="string"&&r.requestId.trim()||void 0,m=typeof r.traceId=="string"&&r.traceId.trim()||void 0,l=typeof r.spanId=="string"&&r.spanId.trim()||void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.requestId,delete r.traceId,delete r.spanId,this.sendError({type:"error",message:i,stackTrace:e?.stack||"",...p?{url:p}:{},...s?{method:s}:{},...o!==void 0?{statusCode:o}:{},...u!==void 0?{durationMs:u}:{},...c?{ip:c}:{},...g?{requestId:g}:{},...m?{traceId:m}:{},...l?{spanId:l}:{},environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(w(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,T),environment:this.environment,release:this.release,user:d(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:d({...t,timestamp:new Date().toISOString()})}):Promise.resolve()}async flush(){if(!(this.sendQueue.length===0&&!this.isProcessingQueue))return new Promise(e=>{this.flushResolvers.push(e),this.processQueue()})}getIntegrationContext(){return{...this.technology?{technology:this.technology}:{},...this.installationId?{installationId:this.installationId}:{},...this.connectionTestId?{connectionTestId:this.connectionTestId}:{},sdkVersion:this.sdkVersion}}getPendingConnectionTestEndpoint(){try{let e=new URL(this.endpoint),t=new URL("/api/integrations/sdk/pending-test",e.origin);return this.technology&&t.searchParams.set("technology",this.technology),t.toString()}catch{return}}async refreshPendingConnectionTest(e=!1){if(!this.initialized||!this.apiKey||!this.technology)return;let t=Date.now();if(!e&&this.connectionTestLastCheckedAt>0&&t-this.connectionTestLastCheckedAt<L){this.connectionTestExpiresAt&&t>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}if(this.connectionTestRequest)return this.connectionTestRequest;let i=this.getPendingConnectionTestEndpoint();if(i)return this.connectionTestRequest=this.fetchPendingConnectionTest(i).finally(()=>{this.connectionTestRequest=void 0}),this.connectionTestRequest}async fetchPendingConnectionTest(e){this.connectionTestLastCheckedAt=Date.now();let t=typeof fetch=="function"?fetch:void 0;if(!t)return;let i,r;try{typeof AbortController<"u"&&(i=new AbortController,r=setTimeout(()=>{i?.abort()},this.requestTimeoutMs));let s=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!s.ok)return;let o=await s.json(),u=I(o.connectionTestId??o.testId,200);if(!u){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=u;let c=o.expiresAt?new Date(o.expiresAt).getTime():void 0;this.connectionTestExpiresAt=c&&Number.isFinite(c)?c:void 0}catch{return}finally{r!==void 0&&clearTimeout(r)}}clearConnectionTest(e){e&&this.connectionTestId!==e||(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=Date.now())}attachGlobalListeners(){if(this.listenersAttached||typeof globalThis>"u")return;this.listenersAttached=!0;let e=globalThis;if(typeof e.ErrorUtils<"u"){let t=e.ErrorUtils.getGlobalHandler?.();e.ErrorUtils.setGlobalHandler?.((i,r)=>{this.captureError(i,{platform:"react-native",fatal:r}).finally(()=>{typeof t=="function"&&t(i,r)})})}if(typeof window<"u"&&typeof window.addEventListener=="function"){window.addEventListener("error",t=>{let i=t.error instanceof Error?t.error:new Error(t.message||"Erro global");this.captureError(i,{url:t.filename||window.location.href,line:t.lineno,column:t.colno,platform:"browser"})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(w(t.reason));this.captureError(i,{platform:"browser",url:window.location.href})});return}typeof process<"u"&&typeof process.on=="function"&&(process.on("uncaughtException",t=>{this.captureError(t,{platform:"node"})}),process.on("unhandledRejection",t=>{this.captureException(t,{platform:"node"})}))}sendError(e){return this.enqueue(this.endpoint,e)}sendApm(e){return this.enqueue(this.apmEndpoint,e)}enqueue(e,t){if(!this.initialized||!this.apiKey)return Promise.resolve();let i=y("event"),r={...t,...this.getIntegrationContext(),eventId:i},s={id:i,endpoint:e,payload:d(r),resolve:()=>{}};return new Promise(o=>{s.resolve=o,this.sendQueue.push(s),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue.shift();if(e)try{await this.refreshPendingConnectionTest();let t={...e.payload,...this.getIntegrationContext()},i=typeof t.connectionTestId=="string"?t.connectionTestId:void 0;await this.sendToEndpoint(e.endpoint,d(t))&&i&&this.clearConnectionTest(i)}finally{e.resolve()}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){let e=this.flushResolvers.splice(0);for(let t of e)t()}this.sendQueue.length>0&&this.processQueue()}}}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),s,o;try{typeof AbortController<"u"&&(s=new AbortController,o=setTimeout(()=>{s?.abort()},this.requestTimeoutMs));let u=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:s?.signal};return u&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{o!==void 0&&clearTimeout(o)}}},_="__DEVINSPECT_AUDIT_CORE_INSTANCE__",P=typeof globalThis<"u"?globalThis:{},a=P[_]||new R;P[_]=a;async function U(n,e,t={}){let i=t.nativeFetch||(typeof fetch=="function"?fetch:void 0);if(!i)throw new Error("fetch n\xE3o est\xE1 dispon\xEDvel.");let r=typeof n=="string"?n:n instanceof URL?n.toString():String(n.url||""),s=E(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(n,e);let o=a.createRequestId(),u=a.createTraceId(),c=a.createSpanId(),p=new Headers(e?.headers||(typeof n!="string"&&!(n instanceof URL)?n.headers:void 0));p.set("x-devinspector-request-id",o),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",c);let g={...e,headers:p},m=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,g),h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-m)),b=l.status>=400||h>=a.getSlowThresholdMs();return a.addBreadcrumb({type:"http",message:`${s} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:h,requestId:o,traceId:u,spanId:c}}),b?a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:u,spanId:c}):a.captureRequest({method:s,url:r,statusCode:l.status,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:u,spanId:c}),l}catch(l){let h=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-m));a.addBreadcrumb({type:"http_error",message:`${s} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:h,requestId:o,traceId:u,spanId:c}}),a.captureRequest({method:s,url:r,statusCode:0,durationMs:h,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:o,traceId:u,spanId:c});let b=l instanceof Error?l:new Error(w(l));throw a.captureError(b,{url:r,method:s,type:t.errorType||"network_error",requestId:o,traceId:u,spanId:c}),l}}var x=null;async function O(n,e,t){return U(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||x||void 0})}function K(){if(typeof globalThis>"u")return;let n=globalThis;if(n.__DEVINSPECTOR_FETCH_PATCHED__)return;let e=globalThis.fetch;if(typeof e!="function")return;let t;try{t=Object.getOwnPropertyDescriptor(globalThis,"fetch")}catch{return}if(t&&t.get&&!t.set||t&&t.writable===!1&&!t.set)return;let i=e.bind(globalThis);x=i;let r=function(s,o){return O(s,o,i)};try{t&&t.configurable?Object.defineProperty(globalThis,"fetch",{...t,value:r}):globalThis.fetch=r}catch{return}globalThis.fetch===r&&(n.__DEVINSPECTOR_NATIVE_FETCH__=i,n.__DEVINSPECTOR_FETCH_PATCHED__=!0)}if(typeof window<"u"){let n=window;n.DevInspector={init:e=>a.init(e),captureError:(e,t)=>a.captureError(e,t),captureException:(e,t)=>a.captureException(e,t),captureMessage:(e,t)=>a.captureMessage(e,t),captureMetric:(e,t,i)=>a.captureMetric(e,t,i),captureCustomMetric:e=>a.captureCustomMetric(e),auditFetch:O,enableNetworkTracing:K,core:a}}var $=a;export{a as audit,O as auditFetch,$ as default,K as enableNetworkTracing};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xcodleox/devinspector",
3
- "version": "9.3.1",
3
+ "version": "9.3.2",
4
4
  "description": "SDK de monitoramento e auditoria de erros em tempo real | Dev Inspector",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",