@xcodleox/devinspector 9.3.5 → 9.3.6
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/next.cjs +1 -1
- package/dist/next.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.js +1 -1
- package/dist/react-native.cjs +1 -1
- package/dist/react-native.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/svelte.cjs +1 -1
- package/dist/svelte.js +1 -1
- package/dist/vanilla.cjs +1 -1
- package/dist/vanilla.global.js +1 -1
- package/dist/vanilla.js +1 -1
- package/dist/vue.cjs +1 -1
- package/dist/vue.js +1 -1
- package/package.json +1 -1
package/dist/vanilla.global.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var DevInspector=(()=>{var w=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(n,e)=>{for(var t in e)w(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of te(e))!ne.call(n,r)&&r!==t&&w(n,r,{get:()=>e[r],enumerable:!(i=ee(e,r))||i.enumerable});return n};var se=n=>ie(w({},"__esModule",{value:!0}),n);var ve={};re(ve,{audit:()=>a,auditFetch:()=>k,default:()=>Ee,enableNetworkTracing:()=>Z});var P="9.3.4",oe=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),ce=new Set(["frontend","backend","fullstack","mobile"]),x="https://api.devinspector.com.br/api/ingest/track",N="https://api.devinspector.com.br/api/ingest/apm",O=50,E=1e4,ae=5e4,A=4e3,L=4e3,Q=2e3,z=1e3,V=200,I=200,ue=100,de=200,pe=100,le=6,B=1e4,he=5e3,G=3,fe=1e3,me=1e4,ge=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ye(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ge.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>E?`${n.slice(0,E)}...[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>=le)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ye(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function _(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 M(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function H(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function R(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function F(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function Te(n){return String(n??"").trim().slice(0,200)}function Ie(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function j(n){let e=b(n,50);if(e&&oe.has(e))return e}function K(n){let e=b(n,50);if(e&&ce.has(e))return e}function v(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 h(n){return f(n)}function X(n){let e=Math.max(0,n-1);return Math.min(fe*2**e,me)}function be(n,e){return setTimeout(n,Math.max(0,e))}var D=class{constructor(){this.apiKey="";this.endpoint=x;this.apmEndpoint=N;this.environment="production";this.sdkVersion=P;this.slowThresholdMs=300;this.requestTimeoutMs=B;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()||x,this.apmEndpoint=e.apmEndpoint?.trim()||N,this.environment=d(e.environment,ue)||"production",this.release=d(e.release,de),this.technology=j(e.technology),this.category=K(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,pe)||P,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):B,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>O&&(this.breadcrumbs=this.breadcrumbs.slice(-O))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),u=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===u||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=M(e.method)||"GET",i=d(e.url,A);if(!i)return;let r=H(e.statusCode)??0,o=R(e.durationMs)??0,s=F(e.ip),u=d(e.path,L),c=d(e.route,Q),p=d(e.userAgent,z),y=d(e.contentType,V),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...u?{path:u}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=R(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,A),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=Te(e);if(!o)return Promise.resolve();let s;try{s=Ie(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=M(r.method),s=H(r.statusCode??r.status),u=R(r.durationMs),c=F(r.ip),p=d(r.url,A),y=d(r.path,L),g=d(r.route,Q),l=d(r.userAgent,z),m=d(r.contentType,V),T=d(r.requestId,I),C=d(r.traceId,I),q=d(r.spanId,I),S=r.query!==void 0?f(r.query):void 0,U=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ae)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...u!==void 0?{durationMs:u}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...S?{query:S}:{},...U!==void 0?{requestBody:U}:{},...T?{requestId:T}:{},...C?{traceId:C}:{},...q?{spanId:q}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(_(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<he){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),u=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=j(s.technology)),s.category&&!this.category&&(this.category=K(s.category)),!u){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=u;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(_(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let s=X(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let i=X(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=be(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.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:o?.signal};return u&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},$="__DEVINSPECT_AUDIT_CORE_INSTANCE__",Y=typeof globalThis<"u"?globalThis:{},a=Y[$]||new D;Y[$]=a;async function J(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||""),o=M(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(n,e);let s=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",s),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return a.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:u,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));a.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:u,spanId:c});let T=l instanceof Error?l:new Error(_(l));throw a.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:u,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var W=null;async function k(n,e,t){return J(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||W||void 0})}function Z(){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);W=i;let r=function(o,s){return k(o,s,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:k,enableNetworkTracing:Z,core:a}}var Ee=a;return se(ve);})();
|
|
1
|
+
"use strict";var DevInspector=(()=>{var w=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(n,e)=>{for(var t in e)w(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of te(e))!ne.call(n,r)&&r!==t&&w(n,r,{get:()=>e[r],enumerable:!(i=ee(e,r))||i.enumerable});return n};var se=n=>ie(w({},"__esModule",{value:!0}),n);var ve={};re(ve,{audit:()=>a,auditFetch:()=>k,default:()=>Ee,enableNetworkTracing:()=>Z});var P="9.3.6",oe=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),ce=new Set(["frontend","backend","fullstack","mobile"]),x="https://api.devinspector.com.br/api/ingest/track",N="https://api.devinspector.com.br/api/ingest/apm",O=50,E=1e4,ae=5e4,A=4e3,L=4e3,Q=2e3,z=1e3,V=200,I=200,ue=100,de=200,pe=100,le=6,B=1e4,he=5e3,G=3,fe=1e3,me=1e4,ge=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ye(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ge.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>E?`${n.slice(0,E)}...[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>=le)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ye(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function _(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 M(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function H(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function R(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function F(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function Te(n){return String(n??"").trim().slice(0,200)}function Ie(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function j(n){let e=b(n,50);if(e&&oe.has(e))return e}function K(n){let e=b(n,50);if(e&&ce.has(e))return e}function v(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 h(n){return f(n)}function X(n){let e=Math.max(0,n-1);return Math.min(fe*2**e,me)}function be(n,e){return setTimeout(n,Math.max(0,e))}var D=class{constructor(){this.apiKey="";this.endpoint=x;this.apmEndpoint=N;this.environment="production";this.sdkVersion=P;this.slowThresholdMs=300;this.requestTimeoutMs=B;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()||x,this.apmEndpoint=e.apmEndpoint?.trim()||N,this.environment=d(e.environment,ue)||"production",this.release=d(e.release,de),this.technology=j(e.technology),this.category=K(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,pe)||P,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):B,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>O&&(this.breadcrumbs=this.breadcrumbs.slice(-O))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),u=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===u||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=M(e.method)||"GET",i=d(e.url,A);if(!i)return;let r=H(e.statusCode)??0,o=R(e.durationMs)??0,s=F(e.ip),u=d(e.path,L),c=d(e.route,Q),p=d(e.userAgent,z),y=d(e.contentType,V),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...u?{path:u}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=R(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,A),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=Te(e);if(!o)return Promise.resolve();let s;try{s=Ie(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=M(r.method),s=H(r.statusCode??r.status),u=R(r.durationMs),c=F(r.ip),p=d(r.url,A),y=d(r.path,L),g=d(r.route,Q),l=d(r.userAgent,z),m=d(r.contentType,V),T=d(r.requestId,I),C=d(r.traceId,I),q=d(r.spanId,I),S=r.query!==void 0?f(r.query):void 0,U=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ae)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...u!==void 0?{durationMs:u}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...S?{query:S}:{},...U!==void 0?{requestBody:U}:{},...T?{requestId:T}:{},...C?{traceId:C}:{},...q?{spanId:q}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(_(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<he){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),u=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=j(s.technology)),s.category&&!this.category&&(this.category=K(s.category)),!u){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=u;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(_(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let s=X(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let i=X(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=be(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.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:o?.signal};return u&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},$="__DEVINSPECT_AUDIT_CORE_INSTANCE__",Y=typeof globalThis<"u"?globalThis:{},a=Y[$]||new D;Y[$]=a;async function J(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||""),o=M(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(n,e);let s=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",s),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return a.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:u,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));a.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:u,spanId:c});let T=l instanceof Error?l:new Error(_(l));throw a.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:u,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var W=null;async function k(n,e,t){return J(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||W||void 0})}function Z(){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);W=i;let r=function(o,s){return k(o,s,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:k,enableNetworkTracing:Z,core:a}}var Ee=a;return se(ve);})();
|
package/dist/vanilla.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var S="9.3.4",W=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),Z=new Set(["frontend","backend","fullstack","mobile"]),U="https://api.devinspector.com.br/api/ingest/track",P="https://api.devinspector.com.br/api/ingest/apm",x=50,E=1e4,ee=5e4,w=4e3,N=4e3,O=2e3,L=1e3,Q=200,I=200,te=100,ne=200,re=100,ie=6,z=1e4,se=5e3,V=3,oe=1e3,ce=1e4,ae=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ue(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ae.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>E?`${n.slice(0,E)}...[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>=ie)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ue(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function R(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 _(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function B(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function A(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function G(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function de(n){return String(n??"").trim().slice(0,200)}function pe(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function H(n){let e=b(n,50);if(e&&W.has(e))return e}function F(n){let e=b(n,50);if(e&&Z.has(e))return e}function v(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 h(n){return f(n)}function j(n){let e=Math.max(0,n-1);return Math.min(oe*2**e,ce)}function le(n,e){return setTimeout(n,Math.max(0,e))}var M=class{constructor(){this.apiKey="";this.endpoint=U;this.apmEndpoint=P;this.environment="production";this.sdkVersion=S;this.slowThresholdMs=300;this.requestTimeoutMs=z;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()||U,this.apmEndpoint=e.apmEndpoint?.trim()||P,this.environment=d(e.environment,te)||"production",this.release=d(e.release,ne),this.technology=H(e.technology),this.category=F(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,re)||S,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):z,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>x&&(this.breadcrumbs=this.breadcrumbs.slice(-x))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),a=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===a||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=_(e.method)||"GET",i=d(e.url,w);if(!i)return;let r=B(e.statusCode)??0,o=A(e.durationMs)??0,s=G(e.ip),a=d(e.path,N),c=d(e.route,O),p=d(e.userAgent,L),y=d(e.contentType,Q),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...a?{path:a}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=A(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,w),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=de(e);if(!o)return Promise.resolve();let s;try{s=pe(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=_(r.method),s=B(r.statusCode??r.status),a=A(r.durationMs),c=G(r.ip),p=d(r.url,w),y=d(r.path,N),g=d(r.route,O),l=d(r.userAgent,L),m=d(r.contentType,Q),T=d(r.requestId,I),D=d(r.traceId,I),k=d(r.spanId,I),C=r.query!==void 0?f(r.query):void 0,q=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ee)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...a!==void 0?{durationMs:a}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...C?{query:C}:{},...q!==void 0?{requestBody:q}:{},...T?{requestId:T}:{},...D?{traceId:D}:{},...k?{spanId:k}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(R(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<se){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),a=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=H(s.technology)),s.category&&!this.category&&(this.category=F(s.category)),!a){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=a;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(R(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let s=j(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let i=j(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=le(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:o?.signal};return a&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},K="__DEVINSPECT_AUDIT_CORE_INSTANCE__",X=typeof globalThis<"u"?globalThis:{},u=X[K]||new M;X[K]=u;async function $(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||""),o=_(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&u.isIngestUrl(r))return i(n,e);let s=u.createRequestId(),a=u.createTraceId(),c=u.createSpanId(),p=new Headers(e?.headers||(typeof n!="string"&&!(n instanceof URL)?n.headers:void 0));p.set("x-devinspector-request-id",s),p.set("x-devinspector-trace-id",a),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return u.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:a,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));u.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:a,spanId:c});let T=l instanceof Error?l:new Error(R(l));throw u.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var Y=null;async function J(n,e,t){return $(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||Y||void 0})}function he(){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);Y=i;let r=function(o,s){return J(o,s,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=>u.init(e),captureError:(e,t)=>u.captureError(e,t),captureException:(e,t)=>u.captureException(e,t),captureMessage:(e,t)=>u.captureMessage(e,t),captureMetric:(e,t,i)=>u.captureMetric(e,t,i),captureCustomMetric:e=>u.captureCustomMetric(e),auditFetch:J,enableNetworkTracing:he,core:u}}var ge=u;export{u as audit,J as auditFetch,ge as default,he as enableNetworkTracing};
|
|
1
|
+
var S="9.3.6",W=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),Z=new Set(["frontend","backend","fullstack","mobile"]),U="https://api.devinspector.com.br/api/ingest/track",P="https://api.devinspector.com.br/api/ingest/apm",x=50,E=1e4,ee=5e4,w=4e3,N=4e3,O=2e3,L=1e3,Q=200,I=200,te=100,ne=200,re=100,ie=6,z=1e4,se=5e3,V=3,oe=1e3,ce=1e4,ae=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ue(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ae.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>E?`${n.slice(0,E)}...[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>=ie)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ue(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function R(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 _(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function B(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function A(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function G(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function de(n){return String(n??"").trim().slice(0,200)}function pe(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function H(n){let e=b(n,50);if(e&&W.has(e))return e}function F(n){let e=b(n,50);if(e&&Z.has(e))return e}function v(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 h(n){return f(n)}function j(n){let e=Math.max(0,n-1);return Math.min(oe*2**e,ce)}function le(n,e){return setTimeout(n,Math.max(0,e))}var M=class{constructor(){this.apiKey="";this.endpoint=U;this.apmEndpoint=P;this.environment="production";this.sdkVersion=S;this.slowThresholdMs=300;this.requestTimeoutMs=z;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()||U,this.apmEndpoint=e.apmEndpoint?.trim()||P,this.environment=d(e.environment,te)||"production",this.release=d(e.release,ne),this.technology=H(e.technology),this.category=F(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,re)||S,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):z,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>x&&(this.breadcrumbs=this.breadcrumbs.slice(-x))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),a=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===a||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=_(e.method)||"GET",i=d(e.url,w);if(!i)return;let r=B(e.statusCode)??0,o=A(e.durationMs)??0,s=G(e.ip),a=d(e.path,N),c=d(e.route,O),p=d(e.userAgent,L),y=d(e.contentType,Q),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...a?{path:a}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=A(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,w),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=de(e);if(!o)return Promise.resolve();let s;try{s=pe(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=_(r.method),s=B(r.statusCode??r.status),a=A(r.durationMs),c=G(r.ip),p=d(r.url,w),y=d(r.path,N),g=d(r.route,O),l=d(r.userAgent,L),m=d(r.contentType,Q),T=d(r.requestId,I),D=d(r.traceId,I),k=d(r.spanId,I),C=r.query!==void 0?f(r.query):void 0,q=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ee)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...a!==void 0?{durationMs:a}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...C?{query:C}:{},...q!==void 0?{requestBody:q}:{},...T?{requestId:T}:{},...D?{traceId:D}:{},...k?{spanId:k}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(R(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<se){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),a=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=H(s.technology)),s.category&&!this.category&&(this.category=F(s.category)),!a){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=a;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(R(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let s=j(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let i=j(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=le(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:o?.signal};return a&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},K="__DEVINSPECT_AUDIT_CORE_INSTANCE__",X=typeof globalThis<"u"?globalThis:{},u=X[K]||new M;X[K]=u;async function $(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||""),o=_(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&u.isIngestUrl(r))return i(n,e);let s=u.createRequestId(),a=u.createTraceId(),c=u.createSpanId(),p=new Headers(e?.headers||(typeof n!="string"&&!(n instanceof URL)?n.headers:void 0));p.set("x-devinspector-request-id",s),p.set("x-devinspector-trace-id",a),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return u.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:a,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));u.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:a,spanId:c});let T=l instanceof Error?l:new Error(R(l));throw u.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var Y=null;async function J(n,e,t){return $(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||Y||void 0})}function he(){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);Y=i;let r=function(o,s){return J(o,s,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=>u.init(e),captureError:(e,t)=>u.captureError(e,t),captureException:(e,t)=>u.captureException(e,t),captureMessage:(e,t)=>u.captureMessage(e,t),captureMetric:(e,t,i)=>u.captureMetric(e,t,i),captureCustomMetric:e=>u.captureCustomMetric(e),auditFetch:J,enableNetworkTracing:he,core:u}}var ge=u;export{u as audit,J as auditFetch,ge as default,he as enableNetworkTracing};
|
package/dist/vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(n,e)=>{for(var t in e)w(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of te(e))!ne.call(n,r)&&r!==t&&w(n,r,{get:()=>e[r],enumerable:!(i=ee(e,r))||i.enumerable});return n};var se=n=>ie(w({},"__esModule",{value:!0}),n);var ve={};re(ve,{audit:()=>a,auditFetch:()=>k,default:()=>Ee,enableNetworkTracing:()=>Z});module.exports=se(ve);var P="9.3.4",oe=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),ce=new Set(["frontend","backend","fullstack","mobile"]),x="https://api.devinspector.com.br/api/ingest/track",N="https://api.devinspector.com.br/api/ingest/apm",O=50,E=1e4,ae=5e4,A=4e3,L=4e3,Q=2e3,z=1e3,V=200,I=200,ue=100,de=200,pe=100,le=6,B=1e4,he=5e3,G=3,fe=1e3,me=1e4,ge=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ye(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ge.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>E?`${n.slice(0,E)}...[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>=le)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ye(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function _(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 M(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function H(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function R(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function F(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function Te(n){return String(n??"").trim().slice(0,200)}function Ie(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function j(n){let e=b(n,50);if(e&&oe.has(e))return e}function K(n){let e=b(n,50);if(e&&ce.has(e))return e}function v(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 h(n){return f(n)}function X(n){let e=Math.max(0,n-1);return Math.min(fe*2**e,me)}function be(n,e){return setTimeout(n,Math.max(0,e))}var D=class{constructor(){this.apiKey="";this.endpoint=x;this.apmEndpoint=N;this.environment="production";this.sdkVersion=P;this.slowThresholdMs=300;this.requestTimeoutMs=B;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()||x,this.apmEndpoint=e.apmEndpoint?.trim()||N,this.environment=d(e.environment,ue)||"production",this.release=d(e.release,de),this.technology=j(e.technology),this.category=K(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,pe)||P,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):B,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>O&&(this.breadcrumbs=this.breadcrumbs.slice(-O))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),u=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===u||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=M(e.method)||"GET",i=d(e.url,A);if(!i)return;let r=H(e.statusCode)??0,o=R(e.durationMs)??0,s=F(e.ip),u=d(e.path,L),c=d(e.route,Q),p=d(e.userAgent,z),y=d(e.contentType,V),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...u?{path:u}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=R(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,A),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=Te(e);if(!o)return Promise.resolve();let s;try{s=Ie(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=M(r.method),s=H(r.statusCode??r.status),u=R(r.durationMs),c=F(r.ip),p=d(r.url,A),y=d(r.path,L),g=d(r.route,Q),l=d(r.userAgent,z),m=d(r.contentType,V),T=d(r.requestId,I),C=d(r.traceId,I),q=d(r.spanId,I),S=r.query!==void 0?f(r.query):void 0,U=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ae)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...u!==void 0?{durationMs:u}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...S?{query:S}:{},...U!==void 0?{requestBody:U}:{},...T?{requestId:T}:{},...C?{traceId:C}:{},...q?{spanId:q}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(_(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<he){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),u=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=j(s.technology)),s.category&&!this.category&&(this.category=K(s.category)),!u){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=u;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(_(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let s=X(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let i=X(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=be(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.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:o?.signal};return u&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},$="__DEVINSPECT_AUDIT_CORE_INSTANCE__",Y=typeof globalThis<"u"?globalThis:{},a=Y[$]||new D;Y[$]=a;async function J(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||""),o=M(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(n,e);let s=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",s),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return a.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:u,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));a.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:u,spanId:c});let T=l instanceof Error?l:new Error(_(l));throw a.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:u,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var W=null;async function k(n,e,t){return J(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||W||void 0})}function Z(){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);W=i;let r=function(o,s){return k(o,s,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:k,enableNetworkTracing:Z,core:a}}var Ee=a;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
|
1
|
+
"use strict";var w=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(n,e)=>{for(var t in e)w(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of te(e))!ne.call(n,r)&&r!==t&&w(n,r,{get:()=>e[r],enumerable:!(i=ee(e,r))||i.enumerable});return n};var se=n=>ie(w({},"__esModule",{value:!0}),n);var ve={};re(ve,{audit:()=>a,auditFetch:()=>k,default:()=>Ee,enableNetworkTracing:()=>Z});module.exports=se(ve);var P="9.3.6",oe=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),ce=new Set(["frontend","backend","fullstack","mobile"]),x="https://api.devinspector.com.br/api/ingest/track",N="https://api.devinspector.com.br/api/ingest/apm",O=50,E=1e4,ae=5e4,A=4e3,L=4e3,Q=2e3,z=1e3,V=200,I=200,ue=100,de=200,pe=100,le=6,B=1e4,he=5e3,G=3,fe=1e3,me=1e4,ge=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ye(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ge.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>E?`${n.slice(0,E)}...[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>=le)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ye(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function _(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 M(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function H(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function R(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function F(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function Te(n){return String(n??"").trim().slice(0,200)}function Ie(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function j(n){let e=b(n,50);if(e&&oe.has(e))return e}function K(n){let e=b(n,50);if(e&&ce.has(e))return e}function v(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 h(n){return f(n)}function X(n){let e=Math.max(0,n-1);return Math.min(fe*2**e,me)}function be(n,e){return setTimeout(n,Math.max(0,e))}var D=class{constructor(){this.apiKey="";this.endpoint=x;this.apmEndpoint=N;this.environment="production";this.sdkVersion=P;this.slowThresholdMs=300;this.requestTimeoutMs=B;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()||x,this.apmEndpoint=e.apmEndpoint?.trim()||N,this.environment=d(e.environment,ue)||"production",this.release=d(e.release,de),this.technology=j(e.technology),this.category=K(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,pe)||P,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):B,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>O&&(this.breadcrumbs=this.breadcrumbs.slice(-O))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),u=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===u||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=M(e.method)||"GET",i=d(e.url,A);if(!i)return;let r=H(e.statusCode)??0,o=R(e.durationMs)??0,s=F(e.ip),u=d(e.path,L),c=d(e.route,Q),p=d(e.userAgent,z),y=d(e.contentType,V),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...u?{path:u}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=R(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,A),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=Te(e);if(!o)return Promise.resolve();let s;try{s=Ie(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=M(r.method),s=H(r.statusCode??r.status),u=R(r.durationMs),c=F(r.ip),p=d(r.url,A),y=d(r.path,L),g=d(r.route,Q),l=d(r.userAgent,z),m=d(r.contentType,V),T=d(r.requestId,I),C=d(r.traceId,I),q=d(r.spanId,I),S=r.query!==void 0?f(r.query):void 0,U=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ae)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...u!==void 0?{durationMs:u}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...S?{query:S}:{},...U!==void 0?{requestBody:U}:{},...T?{requestId:T}:{},...C?{traceId:C}:{},...q?{spanId:q}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(_(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<he){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),u=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=j(s.technology)),s.category&&!this.category&&(this.category=K(s.category)),!u){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=u;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(_(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let s=X(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=G){this.sendQueue.shift(),e.resolve();continue}let i=X(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=be(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.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:o?.signal};return u&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},$="__DEVINSPECT_AUDIT_CORE_INSTANCE__",Y=typeof globalThis<"u"?globalThis:{},a=Y[$]||new D;Y[$]=a;async function J(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||""),o=M(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&a.isIngestUrl(r))return i(n,e);let s=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",s),p.set("x-devinspector-trace-id",u),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return a.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:u,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));a.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:u,spanId:c}}),a.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:u,spanId:c});let T=l instanceof Error?l:new Error(_(l));throw a.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:u,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var W=null;async function k(n,e,t){return J(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||W||void 0})}function Z(){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);W=i;let r=function(o,s){return k(o,s,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:k,enableNetworkTracing:Z,core:a}}var Ee=a;0&&(module.exports={audit,auditFetch,enableNetworkTracing});
|
package/dist/vue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var S="9.3.4",W=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),Z=new Set(["frontend","backend","fullstack","mobile"]),U="https://api.devinspector.com.br/api/ingest/track",P="https://api.devinspector.com.br/api/ingest/apm",x=50,E=1e4,ee=5e4,w=4e3,N=4e3,O=2e3,L=1e3,Q=200,I=200,te=100,ne=200,re=100,ie=6,z=1e4,se=5e3,V=3,oe=1e3,ce=1e4,ae=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ue(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ae.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>E?`${n.slice(0,E)}...[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>=ie)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ue(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function R(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 _(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function B(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function A(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function G(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function de(n){return String(n??"").trim().slice(0,200)}function pe(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function H(n){let e=b(n,50);if(e&&W.has(e))return e}function F(n){let e=b(n,50);if(e&&Z.has(e))return e}function v(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 h(n){return f(n)}function j(n){let e=Math.max(0,n-1);return Math.min(oe*2**e,ce)}function le(n,e){return setTimeout(n,Math.max(0,e))}var M=class{constructor(){this.apiKey="";this.endpoint=U;this.apmEndpoint=P;this.environment="production";this.sdkVersion=S;this.slowThresholdMs=300;this.requestTimeoutMs=z;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()||U,this.apmEndpoint=e.apmEndpoint?.trim()||P,this.environment=d(e.environment,te)||"production",this.release=d(e.release,ne),this.technology=H(e.technology),this.category=F(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,re)||S,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):z,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>x&&(this.breadcrumbs=this.breadcrumbs.slice(-x))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),a=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===a||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=_(e.method)||"GET",i=d(e.url,w);if(!i)return;let r=B(e.statusCode)??0,o=A(e.durationMs)??0,s=G(e.ip),a=d(e.path,N),c=d(e.route,O),p=d(e.userAgent,L),y=d(e.contentType,Q),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...a?{path:a}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=A(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,w),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=de(e);if(!o)return Promise.resolve();let s;try{s=pe(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=_(r.method),s=B(r.statusCode??r.status),a=A(r.durationMs),c=G(r.ip),p=d(r.url,w),y=d(r.path,N),g=d(r.route,O),l=d(r.userAgent,L),m=d(r.contentType,Q),T=d(r.requestId,I),D=d(r.traceId,I),k=d(r.spanId,I),C=r.query!==void 0?f(r.query):void 0,q=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ee)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...a!==void 0?{durationMs:a}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...C?{query:C}:{},...q!==void 0?{requestBody:q}:{},...T?{requestId:T}:{},...D?{traceId:D}:{},...k?{spanId:k}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(R(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<se){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),a=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=H(s.technology)),s.category&&!this.category&&(this.category=F(s.category)),!a){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=a;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(R(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let s=j(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let i=j(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=le(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:o?.signal};return a&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},K="__DEVINSPECT_AUDIT_CORE_INSTANCE__",X=typeof globalThis<"u"?globalThis:{},u=X[K]||new M;X[K]=u;async function $(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||""),o=_(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&u.isIngestUrl(r))return i(n,e);let s=u.createRequestId(),a=u.createTraceId(),c=u.createSpanId(),p=new Headers(e?.headers||(typeof n!="string"&&!(n instanceof URL)?n.headers:void 0));p.set("x-devinspector-request-id",s),p.set("x-devinspector-trace-id",a),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return u.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:a,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));u.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:a,spanId:c});let T=l instanceof Error?l:new Error(R(l));throw u.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var Y=null;async function J(n,e,t){return $(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||Y||void 0})}function he(){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);Y=i;let r=function(o,s){return J(o,s,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=>u.init(e),captureError:(e,t)=>u.captureError(e,t),captureException:(e,t)=>u.captureException(e,t),captureMessage:(e,t)=>u.captureMessage(e,t),captureMetric:(e,t,i)=>u.captureMetric(e,t,i),captureCustomMetric:e=>u.captureCustomMetric(e),auditFetch:J,enableNetworkTracing:he,core:u}}var ge=u;export{u as audit,J as auditFetch,ge as default,he as enableNetworkTracing};
|
|
1
|
+
var S="9.3.6",W=new Set(["angular","vanilla-js","react","vue","svelte","node","python","java","csharp","php","nextjs","react-native"]),Z=new Set(["frontend","backend","fullstack","mobile"]),U="https://api.devinspector.com.br/api/ingest/track",P="https://api.devinspector.com.br/api/ingest/apm",x=50,E=1e4,ee=5e4,w=4e3,N=4e3,O=2e3,L=1e3,Q=200,I=200,te=100,ne=200,re=100,ie=6,z=1e4,se=5e3,V=3,oe=1e3,ce=1e4,ae=["password","senha","token","authorization","auth","bearer","credit_card","creditcard","cartao","cvv","cpf","rg","secret","private_key","privatekey"];function ue(n){let e=n.toLowerCase().replace(/[\s-]/g,"_");return ae.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>E?`${n.slice(0,E)}...[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>=ie)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(o=>f(o,e+1,t));let i=n,r={};for(let[o,s]of Object.entries(i)){if(ue(o)){r[o]="[REDACTED]";continue}r[o]=f(s,e+1,t)}return r}finally{t.delete(n)}}function R(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 _(n){return n&&String(n).trim().toUpperCase().slice(0,20)||void 0}function B(n){if(typeof n!="number"||!Number.isFinite(n))return;let e=Math.round(n);if(!(e<100||e>599))return e}function A(n){if(!(typeof n!="number"||!Number.isFinite(n)))return Math.max(0,Math.round(n))}function G(n){return n==null?void 0:String(n).trim().slice(0,100)||void 0}function d(n,e=E){return n==null?void 0:String(n).trim().slice(0,e)||void 0}function de(n){return String(n??"").trim().slice(0,200)}function pe(n){let e=Number(n);if(!Number.isFinite(e))throw new Error("metricValue deve ser um n\xFAmero finito.");return e}function b(n,e=I){return d(n,e)}function H(n){let e=b(n,50);if(e&&W.has(e))return e}function F(n){let e=b(n,50);if(e&&Z.has(e))return e}function v(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 h(n){return f(n)}function j(n){let e=Math.max(0,n-1);return Math.min(oe*2**e,ce)}function le(n,e){return setTimeout(n,Math.max(0,e))}var M=class{constructor(){this.apiKey="";this.endpoint=U;this.apmEndpoint=P;this.environment="production";this.sdkVersion=S;this.slowThresholdMs=300;this.requestTimeoutMs=z;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()||U,this.apmEndpoint=e.apmEndpoint?.trim()||P,this.environment=d(e.environment,te)||"production",this.release=d(e.release,ne),this.technology=H(e.technology),this.category=F(e.category),this.installationId=b(e.installationId,I),this.sdkVersion=b(e.sdkVersion,re)||S,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):z,this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0,this.connectionTestLastCheckedAt=0,this.connectionTestRequest=void 0,this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=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}getCategory(){return this.category}getInstallationId(){return this.installationId}getSdkVersion(){return this.sdkVersion}getSlowThresholdMs(){return this.slowThresholdMs}getRequestTimeoutMs(){return this.requestTimeoutMs}getConnectionTestId(){return this.connectionTestId}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,2e3),metadata:e.metadata?f(e.metadata):void 0};this.breadcrumbs.push(t),this.breadcrumbs.length>x&&(this.breadcrumbs=this.breadcrumbs.slice(-x))}getBreadcrumbs(){return this.breadcrumbs.map(e=>h(e))}clearBreadcrumbs(){this.breadcrumbs=[]}getContext(){return{environment:this.environment,release:this.release,technology:this.technology,category:this.category,installationId:this.installationId,sdkVersion:this.sdkVersion,user:h(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),o=r.origin,s=r.pathname.replace(/\/$/,""),a=t.pathname.replace(/\/$/,""),c=i.pathname.replace(/\/$/,"");return o===t.origin&&s===a||o===i.origin&&s===c}catch{return e.includes(this.endpoint)||e.includes(this.apmEndpoint)}}createRequestId(){return v("req")}createTraceId(){return v("trace")}createSpanId(){return v("span")}async captureRequest(e){let t=_(e.method)||"GET",i=d(e.url,w);if(!i)return;let r=B(e.statusCode)??0,o=A(e.durationMs)??0,s=G(e.ip),a=d(e.path,N),c=d(e.route,O),p=d(e.userAgent,L),y=d(e.contentType,Q),g=e.query?f(e.query):void 0,l=e.requestBody!==void 0?f(e.requestBody):void 0,m={...e.metadata||{},timestamp:new Date().toISOString()};!(r>=400||o>=this.getSlowThresholdMs())&&(await this.refreshPendingConnectionTest(!0),!this.connectionTestId)||await this.sendApm({type:"request_metric",method:t,url:i,statusCode:r,durationMs:o,...a?{path:a}:{},...c?{route:c}:{},...p?{userAgent:p}:{},...y?{contentType:y}:{},...s?{ip:s}:{},...g?{query:g}:{},...l!==void 0?{requestBody:l}:{},...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:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(m)})}captureDbQuery(e){let t=String(e.operation||"").trim().slice(0,500);if(!t)return Promise.resolve();let i=A(e.durationMs)??0,r={...e.metadata||{},operation:t,collection:d(e.collection,200)||"Unknown",durationMs:i,timestamp:new Date().toISOString()};return this.sendApm({type:"db_query",message:`Database operation: ${t}`,url:d(e.url,w),method:"DB",durationMs:i,requestId:e.requestId,traceId:e.traceId,spanId:e.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h(r)})}captureMetric(e,t,i={},r={}){let o=de(e);if(!o)return Promise.resolve();let s;try{s=pe(t)}catch{return Promise.resolve()}return this.sendApm({type:"custom_metric",metricName:o,metricValue:s,requestId:r.requestId,traceId:r.traceId,spanId:r.spanId,environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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},o=_(r.method),s=B(r.statusCode??r.status),a=A(r.durationMs),c=G(r.ip),p=d(r.url,w),y=d(r.path,N),g=d(r.route,O),l=d(r.userAgent,L),m=d(r.contentType,Q),T=d(r.requestId,I),D=d(r.traceId,I),k=d(r.spanId,I),C=r.query!==void 0?f(r.query):void 0,q=r.requestBody!==void 0?f(r.requestBody):void 0;return delete r.method,delete r.statusCode,delete r.status,delete r.durationMs,delete r.ip,delete r.url,delete r.path,delete r.route,delete r.userAgent,delete r.contentType,delete r.requestId,delete r.traceId,delete r.spanId,delete r.query,delete r.requestBody,this.sendError({type:"error",message:i.slice(0,E),stackTrace:e?.stack?.slice(0,ee)||"",...p?{url:p}:{},...y?{path:y}:{},...g?{route:g}:{},...o?{method:o}:{},...s!==void 0?{statusCode:s}:{},...a!==void 0?{durationMs:a}:{},...c?{ip:c}:{},...l?{userAgent:l}:{},...m?{contentType:m}:{},...C?{query:C}:{},...q!==void 0?{requestBody:q}:{},...T?{requestId:T}:{},...D?{traceId:D}:{},...k?{spanId:k}:{},environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...r,timestamp:new Date().toISOString()})})}captureException(e,t={}){let i=e instanceof Error?e:new Error(R(e));return this.captureError(i,t)}captureMessage(e,t={}){let i=String(e||"").trim();return i?this.sendApm({type:"message",message:i.slice(0,E),environment:this.environment,release:this.release,user:h(this.user),breadcrumbs:this.getBreadcrumbs(),metadata:h({...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.category?{category:this.category}:{},...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<se){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 o=await t(e,{method:"GET",headers:{"x-api-key":this.apiKey},signal:i?.signal});if(!o.ok)return;let s=await o.json(),a=b(s.connectionTestId??s.testId,I),c=b(s.installationId,I);if(c&&!this.installationId&&(this.installationId=c),s.technology&&!this.technology&&(this.technology=H(s.technology)),s.category&&!this.category&&(this.category=F(s.category)),!a){this.connectionTestExpiresAt&&Date.now()>=this.connectionTestExpiresAt&&(this.connectionTestId=void 0,this.connectionTestExpiresAt=void 0);return}this.connectionTestId=a;let p=s.expiresAt?new Date(s.expiresAt).getTime():void 0;this.connectionTestExpiresAt=p&&Number.isFinite(p)?p: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,path:typeof window.location<"u"?window.location.pathname:void 0,line:t.lineno,column:t.colno,platform:"browser",userAgent:typeof navigator<"u"?navigator.userAgent:void 0})}),window.addEventListener("unhandledrejection",t=>{let i=t.reason instanceof Error?t.reason:new Error(R(t.reason));this.captureError(i,{platform:"browser",url:window.location.href,path:window.location.pathname,userAgent:typeof navigator<"u"?navigator.userAgent:void 0})});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=v("event"),r={...t,...this.getIntegrationContext(),eventId:i},o={id:i,endpoint:e,payload:h(r),resolve:()=>{},attempts:0,nextAttemptAt:0};return new Promise(s=>{o.resolve=s,this.sendQueue.push(o),this.processQueue()})}async processQueue(){if(!(this.isProcessingQueue||!this.initialized||!this.apiKey)){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0),this.isProcessingQueue=!0;try{for(;this.sendQueue.length>0;){let e=this.sendQueue[0];if(!e){this.sendQueue.shift();continue}let t=Date.now();if(e.nextAttemptAt>t){this.scheduleQueueRetry(e.nextAttemptAt-t);break}try{await this.refreshPendingConnectionTest();let i={...e.payload,...this.getIntegrationContext(),eventId:e.id},r=typeof i.connectionTestId=="string"?i.connectionTestId:void 0;if(await this.sendToEndpoint(e.endpoint,h(i))){this.sendQueue.shift(),r&&this.clearConnectionTest(r),e.resolve();continue}if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let s=j(e.attempts);e.nextAttemptAt=Date.now()+s,this.scheduleQueueRetry(s);break}catch{if(e.attempts+=1,e.attempts>=V){this.sendQueue.shift(),e.resolve();continue}let i=j(e.attempts);e.nextAttemptAt=Date.now()+i,this.scheduleQueueRetry(i);break}}}finally{if(this.isProcessingQueue=!1,this.sendQueue.length===0){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=void 0);let e=this.flushResolvers.splice(0);for(let t of e)t();return}if(!this.retryTimer&&this.sendQueue.length>0){let e=this.sendQueue[0];if(e){let t=Math.max(0,e.nextAttemptAt-Date.now());t>0?this.scheduleQueueRetry(t):queueMicrotask(()=>{this.processQueue()})}}}}}scheduleQueueRetry(e){this.retryTimer||(this.retryTimer=le(()=>{this.retryTimer=void 0,this.processQueue()},e))}async sendToEndpoint(e,t){let i=typeof fetch=="function"?fetch:void 0;if(!i)return!1;let r=f(t),o,s;try{typeof AbortController<"u"&&(o=new AbortController,s=setTimeout(()=>{o?.abort()},this.requestTimeoutMs));let a=typeof window<"u"&&typeof window.document<"u",c={method:"POST",headers:{"content-type":"application/json","x-api-key":this.apiKey},body:JSON.stringify(r),signal:o?.signal};return a&&(c.keepalive=!0),(await i(e,c)).ok}catch{return!1}finally{s!==void 0&&clearTimeout(s)}}},K="__DEVINSPECT_AUDIT_CORE_INSTANCE__",X=typeof globalThis<"u"?globalThis:{},u=X[K]||new M;X[K]=u;async function $(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||""),o=_(e?.method||(typeof n!="string"&&!(n instanceof URL)?n.method:"GET"))||"GET";if(r&&u.isIngestUrl(r))return i(n,e);let s=u.createRequestId(),a=u.createTraceId(),c=u.createSpanId(),p=new Headers(e?.headers||(typeof n!="string"&&!(n instanceof URL)?n.headers:void 0));p.set("x-devinspector-request-id",s),p.set("x-devinspector-trace-id",a),p.set("x-devinspector-span-id",c);let y={...e,headers:p},g=typeof performance<"u"?performance.now():Date.now();try{let l=await i(n,y),m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g)),T=l.headers.get("content-type")||void 0;return u.addBreadcrumb({type:"http",message:`${o} ${r}`,metadata:{phase:"complete",statusCode:l.status,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:l.status,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,contentType:T,requestId:s,traceId:a,spanId:c}),l}catch(l){let m=Math.max(0,Math.round((typeof performance<"u"?performance.now():Date.now())-g));u.addBreadcrumb({type:"http_error",message:`${o} ${r}`,metadata:{phase:"error",statusCode:0,durationMs:m,requestId:s,traceId:a,spanId:c}}),u.captureRequest({method:o,url:r,statusCode:0,durationMs:m,path:(()=>{try{return new URL(r).pathname}catch{return}})(),userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent,requestId:s,traceId:a,spanId:c});let T=l instanceof Error?l:new Error(R(l));throw u.captureError(T,{url:r,method:o,path:(()=>{try{return new URL(r).pathname}catch{return}})(),type:t.errorType||"network_error",requestId:s,traceId:a,spanId:c,userAgent:typeof navigator<"u"?navigator.userAgent:t.defaultUserAgent}),l}}var Y=null;async function J(n,e,t){return $(n,e,{errorType:"vanilla_network_error",defaultUserAgent:typeof navigator<"u"?navigator.userAgent:"Vanilla",nativeFetch:t||Y||void 0})}function he(){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);Y=i;let r=function(o,s){return J(o,s,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=>u.init(e),captureError:(e,t)=>u.captureError(e,t),captureException:(e,t)=>u.captureException(e,t),captureMessage:(e,t)=>u.captureMessage(e,t),captureMetric:(e,t,i)=>u.captureMetric(e,t,i),captureCustomMetric:e=>u.captureCustomMetric(e),auditFetch:J,enableNetworkTracing:he,core:u}}var ge=u;export{u as audit,J as auditFetch,ge as default,he as enableNetworkTracing};
|