@bereasoftware/nexa 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nexa.iife.js CHANGED
@@ -1,6 +1,6 @@
1
- var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=e=>({ok:!0,value:e}),n=e=>({ok:!1,error:e});function r(e){return{validate(r){let i=r;for(let[t,r]of Object.entries(e))if(!r(i[t]))return n({message:`Validation failed: field "${t}" is invalid`,code:`VALIDATION_ERROR`});return t(r)}}}function i(e){return{validate(r){let i=r,a=e.filter(e=>!(e in i));return a.length>0?n({message:`Validation failed: missing fields: ${a.join(`, `)}`,code:`VALIDATION_ERROR`}):t(r)}}}var a={validate(e){return Array.isArray(e)?t(e):n({message:`Expected array response`,code:`VALIDATION_ERROR`})}},o={validate(e){return e&&typeof e==`object`&&!Array.isArray(e)?t(e):n({message:`Expected object response`,code:`VALIDATION_ERROR`})}},s={transform(e){return h(e,te)}},c={transform(e){return h(e,m)}},l={transform(e){return g(e)}};function u(e){return{transform(t){return Array.isArray(t)?t.map(t=>_(t,e)):_(t,e)}}}function d(e){return{transform(t){return{[e]:t}}}}var f=class{maxAttempts;constructor(e=5){this.maxAttempts=e}shouldRetry(e){return e<this.maxAttempts}delayMs(e){return e*50}},p=class{retryableStatuses=[408,429,500,502,503,504];maxAttempts;constructor(e=3){this.maxAttempts=e}shouldRetry(e,t){return e>=this.maxAttempts?!1:this.retryableStatuses.includes(t.status??0)||t.code===`TIMEOUT`}delayMs(e){return Math.min(1e3*2**(e-1),1e4)}},ee=class{failureCount=0;lastFailureTime=0;maxAttempts;failureThreshold;resetTimeMs;constructor(e=3,t=5,n=6e4){this.maxAttempts=e,this.failureThreshold=t,this.resetTimeMs=n}shouldRetry(e){return e>=this.maxAttempts||(Date.now()-this.lastFailureTime>this.resetTimeMs&&(this.failureCount=0),this.failureCount>=this.failureThreshold)?!1:(this.failureCount++,this.lastFailureTime=Date.now(),!0)}delayMs(e){return 100*2**(e-1)}reset(){this.failureCount=0,this.lastFailureTime=0}};function te(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function m(e){return e.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}function h(e,t){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>h(e,t));let n={};for(let[r,i]of Object.entries(e))n[t(r)]=h(i,t);return n}function g(e,t=``){let n={};if(Array.isArray(e))e.forEach((e,r)=>{let i=t?`${t}[${r}]`:`[${r}]`;Object.assign(n,g(e,i))});else if(e&&typeof e==`object`)for(let[r,i]of Object.entries(e)){let e=t?`${t}.${r}`:r;i&&typeof i==`object`&&!Array.isArray(i)?Object.assign(n,g(i,e)):n[e]=i}return n}function _(e,t){if(!e||typeof e!=`object`)return{};let n=e,r={};for(let e of t)e in n&&(r[e]=n[e]);return r}function ne(e){let t=new AbortController,n=setTimeout(()=>t.abort(),e);return t.signal.addEventListener(`abort`,()=>clearTimeout(n),{once:!0}),t}async function v(e,t=3){try{return await e()}catch(n){if(t<=0)throw n;return v(e,t-1)}}var y=class{cache=new Map;get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>t.ttlMs?(this.cache.delete(e),null):t.data:null}set(e,t,n=6e4){this.cache.set(e,{data:t,timestamp:Date.now(),ttlMs:n})}clear(){this.cache.clear()}has(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>t.ttlMs?(this.cache.delete(e),!1):!0:!1}delete(e){this.cache.delete(e)}};function b(e={}){let t=e.cache||new y,n=e.ttlMs||6e4,r=e.cacheableStatuses||[200,304];return async(e,i)=>{let a=(e.request.method||`GET`).toUpperCase(),o=a===`GET`,s=`${a}:${e.request.url}`;if(o&&t.has(s)){let n=t.get(s);if(n){e.response=n,e.state.cacheHit=!0;return}}await i(),o&&e.response&&r.includes(e.response.status)&&(t.set(s,e.response,n),e.state.cacheMiss=!0)}}var re=b(),x=class{pending=new Map;async execute(e,t){if(this.pending.has(e))return this.pending.get(e);let n=t().finally(()=>{this.pending.delete(e)});return this.pending.set(e,n),n}clear(){this.pending.clear()}};function S(e={}){let t=e.deduplicator||new x,n=e.includeBody??!1,r=e.methods||[`GET`];return async(e,i)=>{let a=(e.request.method||`GET`).toUpperCase();if(!r.includes(a)){await i();return}let o=`${a}:${e.request.url}`;n&&e.request.body&&(o+=`:${JSON.stringify(e.request.body)}`);try{e.response=await t.execute(o,async()=>(await i(),e.response)),e.state.deduped=!0}catch(t){throw e.error=t,t}}}var ie=S();function C(e){return async t=>{let n=-1;async function r(i){if(i<=n)throw Error(`next() called multiple times`);n=i;let a=e[i];a&&await a(t,()=>r(i+1))}await r(0)}}var w=class{middlewares=[];use(e){return this.middlewares.push(e),this}async execute(e){if(e&&typeof e==`object`&&`request`in e&&`response`in e){let t=e;return await C(this.middlewares.map(e=>typeof e==`function`&&e.length===2?e:async(t,n)=>{let r=e;t.response.body=await r(t.response.body),await n()}))(t),t.response.body}let t=e;for(let e of this.middlewares)t=await e(t);return t}clear(){this.middlewares=[]}};function T(e,t,n,r={}){return{ok:e>=200&&e<300,data:t,error:n,status:e,headers:r}}function E(e){return async(t,n)=>{let r=e.path,i;switch(e.method){case`GET`:i=await t.get(r);break;case`POST`:i=await t.post(r,n);break;case`PUT`:i=await t.put(r,n);break;case`PATCH`:i=await t.patch(r,n);break;case`DELETE`:i=await t.delete(r);break;default:throw Error(`Unsupported method: ${e.method}`)}return i}}function D(e){return{request:async(t,n,r)=>{let i=e[n];return await E(i)(t,r)}}}var ae=class e{subscribers=[];errorSubscribers=[];completeSubscribers=[];subscribe(e,t,n){return e&&this.subscribers.push(e),t&&this.errorSubscribers.push(t),n&&this.completeSubscribers.push(n),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(t=>t!==e),this.errorSubscribers=this.errorSubscribers.filter(e=>e!==t),this.completeSubscribers=this.completeSubscribers.filter(e=>e!==n)}}}next(e){this.subscribers.forEach(t=>t(e))}error(e){this.errorSubscribers.forEach(t=>t(e))}complete(){this.completeSubscribers.forEach(e=>e())}map(t){let n=new e;return this.subscribe(e=>n.next(t(e)),e=>n.error(e),()=>n.complete()),n}filter(t){let n=new e;return this.subscribe(e=>{t(e)&&n.next(e)},e=>n.error(e),()=>n.complete()),n}};function oe(e){return t=>{if(!e(t))throw TypeError(`Value does not match expected type`);return t}}function O(e){return e}function se(e){return O(e)}var ce=class{_promise;resolveFunc;rejectFunc;constructor(){this._promise=new Promise((e,t)=>{this.resolveFunc=e,this.rejectFunc=t})}resolve(e){this.resolveFunc(e)}reject(e){this.rejectFunc(e)}get promise(){return this._promise}promise_(){return this._promise}};async function k(e,t={}){let n=e.body?.getReader();if(!n)throw Error(`Response body is not readable`);let r=[],i=0,a=parseInt(e.headers.get(`content-length`)||`0`,10);for(;;){let{done:e,value:o}=await n.read();if(e)break;r.push(o),i+=o.length,t.onChunk&&await t.onChunk(o),t.onProgress&&a>0&&t.onProgress(i,a)}return A(r,i)}function A(e,t){let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n}async function le(e,t){let n=await k(e);if(typeof window>`u`)await(await import(`fs`).then(e=>e.promises)).writeFile(t,n);else{let e=new Blob([n.buffer],{type:`application/octet-stream`}),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}}function j(e={}){return async(t,n)=>{if(await n(),t.response&&t.response.body&&typeof t.response.body==`object`&&`getReader`in t.response.body){let n=t.response.body.getReader(),r=[],i=0,a=parseInt(t.response.headers?.[`content-length`]||`0`,10);try{for(;;){let{done:o,value:s}=await n.read();if(o)break;r.push(s),i+=s.length,e.onChunk&&await e.onChunk(s),e.onProgress&&a>0&&e.onProgress(i,a),t.state.streamedChunks=t.state.streamedChunks||[],t.state.streamedChunks.push(s)}let o=A(r,i);t.response.body=o,t.state.streaming=!0,t.state.streamedBytes=i}finally{n.releaseLock()}}}}var ue=j({onProgress:(e,t)=>{if(t>0){let n=Math.round(e/t*100);console.warn(`Streaming: ${n}% (${e}/${t} bytes)`)}}}),M=class{plugins=[];cache=new y;deduplicator=new x;middlewares=[];listeners=new Map;register(e){return this.plugins.push(e),e.setup(this),this.emit(`plugin:registered`,e.name),this}addMiddleware(e){return this.middlewares.push(e),this}getCache(){return this.cache}getDeduplicator(){return this.deduplicator}getPipeline(){return C(this.middlewares)}async executePipeline(e){await this.getPipeline()(e)}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set);let n=this.listeners.get(e),r=t;return n&&n.add(r),this}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of n)e(...t)}off(e,t){return this.listeners.get(e)?.delete(t),this}getPlugins(){return[...this.plugins]}clear(){this.plugins=[],this.middlewares=[],this.listeners.clear(),this.cache.clear(),this.deduplicator.clear()}},de={name:`logger`,setup(e){e.on(`request:start`,(...e)=>{let t=e[0];console.warn(`Request started: ${t}`)}),e.on(`request:success`,(...e)=>{let t=e[0],n=e[1];console.warn(`Request succeeded: ${t} (${n})`)}),e.on(`request:error`,(...e)=>{let t=e[0],n=e[1];console.error(`❌ Request failed: ${t}`,n)})}},fe=class{name=`metrics`;metrics={requests:0,errors:0,totalTime:0,avgTime:0};setup(e){e.on(`request:complete`,(...e)=>{let t=e[0],n=e[1];this.metrics.requests++,this.metrics.totalTime+=t,this.metrics.avgTime=this.metrics.totalTime/this.metrics.requests,n||this.metrics.errors++})}getMetrics(){return{...this.metrics}}},pe=class{name=`cache`;ttlMs;constructor(e=6e4){this.ttlMs=e}setup(e){e.addMiddleware(b({ttlMs:this.ttlMs}))}},me=class{name=`dedupe`;setup(e){e.addMiddleware(S())}},N=class{store=new y;get(e){return this.store.get(e)}set(e,t,n=6e4){this.store.set(e,t,n)}has(e){return this.store.has(e)}clear(){this.store.clear()}},P=class{maxAttempts;baseDelayMs;constructor(e=3,t=100){this.maxAttempts=e,this.baseDelayMs=t}shouldRetry(e,t){let n=t.status!==void 0&&t.status>=500,r=t.code===`NETWORK_ERROR`;return e<this.maxAttempts&&(n||r||t.code===`TIMEOUT`)}delayMs(e){let t=this.baseDelayMs*2**(e-1),n=Math.random()*t*.1;return Math.min(t+n,3e4)}},F=class{running=0;queue=[];maxConcurrent;constructor(e){this.maxConcurrent=e}async acquire(){if(this.running<this.maxConcurrent){this.running++;return}return new Promise(e=>{this.queue.push(()=>{this.running++,e()})})}release(){this.running--;let e=this.queue.shift();e&&e()}get pending(){return this.queue.length}get active(){return this.running}};function I(e){return e==null?{serialized:void 0,contentType:null}:typeof e==`string`?{serialized:e,contentType:`text/plain`}:typeof FormData<`u`&&e instanceof FormData?{serialized:e,contentType:null}:typeof URLSearchParams<`u`&&e instanceof URLSearchParams?{serialized:e,contentType:`application/x-www-form-urlencoded`}:typeof Blob<`u`&&e instanceof Blob?{serialized:e,contentType:e.type||`application/octet-stream`}:e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof ReadableStream<`u`&&e instanceof ReadableStream?{serialized:e,contentType:`application/octet-stream`}:{serialized:JSON.stringify(e),contentType:`application/json`}}function L(e,t){return t?e.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(e,n)=>{let r=t[n];if(r===void 0)throw Error(`Missing path parameter: :${n}`);return encodeURIComponent(String(r))}):e}var R=class e{requestInterceptors=[];responseInterceptors=[];cache;devTracker;config;requestQueue;pendingRequests=new Set;constructor(e={}){this.config={baseURL:e.baseURL??``,defaultHeaders:e.defaultHeaders??{"Content-Type":`application/json`},defaultTimeout:e.defaultTimeout??3e4,validateStatus:e.validateStatus??(e=>e>=200&&e<300),cacheStrategy:e.cacheStrategy??new N,maxConcurrent:e.maxConcurrent??0,defaultResponseType:e.defaultResponseType??`auto`,defaultHooks:e.defaultHooks??{},adapter:e.adapter},this.cache=this.config.cacheStrategy,this.requestQueue=this.config.maxConcurrent>0?new F(this.config.maxConcurrent):null,this.devTracker=e.devTracker??null}async request(e){if(!this.requestInterceptors.length&&!this.responseInterceptors.length&&!e.cache?.enabled&&!e.hooks&&!Object.keys(this.config.defaultHooks).length&&!e.retry&&!e.validate&&!e.transform&&!this.requestQueue&&!e.onDownloadProgress&&!e.signal)return this.fastPath(e);let r=e.hooks?{...this.config.defaultHooks,...e.hooks}:this.config.defaultHooks,i=this.getMaxAttempts(e.retry),a=this.getRetryStrategy(e.retry),o=this.buildRequest(e);r.onStart?.(o),this.requestQueue&&await this.requestQueue.acquire();try{for(let s=1;s<=i;s++){let c;try{if((e.method===`GET`||!e.method)&&e.cache?.enabled){let n=this.getCacheKey(e),i=this.cache.get(n);if(i){let n=i;return this.trackDev({method:e.method??`GET`,url:o.url,status:n.status,duration:n.duration,cached:!0,ok:!0,headers:{...o.headers},body:e.body,retryCount:0}),r.onSuccess?.(n),r.onFinally?.(),t(n)}}let n=o;for(let e of this.requestInterceptors)n=await e.onRequest(n);c=new AbortController,this.pendingRequests.add(c),e.signal&&e.signal.addEventListener(`abort`,()=>c.abort(),{once:!0});let i=performance.now(),a=await this.fetchWithTimeout(n,this.resolveTimeoutMs(e.timeout??this.config.defaultTimeout),c),l=performance.now()-i,u=a;e.onDownloadProgress&&a.body&&(u=this.trackDownloadProgress(a,e.onDownloadProgress));let d=e.responseType??this.config.defaultResponseType,f=await this.parseResponse(u,n,l,d);if(!this.config.validateStatus(f.status))throw{message:`Request failed with status ${f.status}`,status:f.status,statusText:f.statusText,code:`HTTP_ERROR`};if(e.validate){let t=e.validate.validate(f.data);if(!t.ok)return t}e.transform&&(f.data=e.transform.transform(f.data));let p=f;for(let e of this.responseInterceptors)p=await e.onResponse(p);if((e.method===`GET`||!e.method)&&e.cache?.enabled){let t=this.getCacheKey(e);this.cache.set(t,p,e.cache.ttlMs)}return r.onSuccess?.(p),this.pendingRequests.delete(c),this.trackDev({method:e.method??`GET`,url:o.url,status:p.status,duration:p.duration,cached:!1,ok:!0,headers:{...o.headers},body:e.body,retryCount:s-1}),t(p)}catch(t){let l;if(l=t instanceof DOMException?t.name===`TimeoutError`?{message:`Request timed out`,code:`TIMEOUT`}:t.name===`AbortError`?{message:`Request aborted`,code:`ABORTED`}:{message:t.message,code:`UNKNOWN_ERROR`,originalError:t}:this.isHttpErrorDetails(t)?t:this.normalizeError(t),s<i&&a.shouldRetry(s,l)){r.onRetry?.(s,l);let e=a.delayMs(s);await this.delay(e);continue}let u=l;for(let e of this.responseInterceptors)e.onError&&(u=await e.onError(u));return r.onError?.(u),c&&this.pendingRequests.delete(c),this.trackDev({method:e.method??`GET`,url:o.url,status:u.status,duration:0,cached:!1,ok:!1,code:u.code,headers:{...o.headers},body:e.body,retryCount:s-1}),n(u)}}let s={message:`Max retries exceeded`,code:`MAX_RETRIES`};return r.onError?.(s),this.trackDev({method:e.method??`GET`,url:o.url,duration:0,cached:!1,ok:!1,code:`MAX_RETRIES`,headers:{...o.headers},body:e.body,retryCount:i}),n(s)}finally{r.onFinally?.(),this.requestQueue&&this.requestQueue.release()}}async fastPath(e){let r=L(e.url,e.params),i=this.buildUrl(r,e.query),{serialized:a,contentType:o}=I(e.body),s={...this.config.defaultHeaders,...e.headers};o?s[`Content-Type`]=o:a instanceof FormData&&delete s[`Content-Type`];let c=new AbortController,l=this.resolveTimeoutMs(e.timeout??this.config.defaultTimeout);this.pendingRequests.add(c);try{let r=performance.now(),a=await this.fetchWithTimeout({url:i,method:e.method??`GET`,headers:s,body:e.body,params:e.params},l,c),o=performance.now()-r,u=await this.parseBody(a,e.responseType??this.config.defaultResponseType);if(!this.config.validateStatus(a.status)){let t=n({message:`Request failed with status ${a.status}`,status:a.status,statusText:a.statusText,code:`HTTP_ERROR`});return this.trackDev({method:e.method??`GET`,url:i,status:a.status,duration:o,cached:!1,ok:!1,code:`HTTP_ERROR`,headers:s,body:e.body,retryCount:0}),this.pendingRequests.delete(c),t}return this.pendingRequests.delete(c),this.trackDev({method:e.method??`GET`,url:i,status:a.status,duration:o,cached:!1,ok:!0,headers:s,body:e.body,retryCount:0}),t({status:a.status,statusText:a.statusText,headers:a.headers,data:u,request:{url:i,method:e.method??`GET`,headers:s,body:e.body,params:e.params},duration:o})}catch(t){this.pendingRequests.delete(c);let r=`UNKNOWN_ERROR`;if(t instanceof DOMException?t.name===`TimeoutError`?r=`TIMEOUT`:t.name===`AbortError`&&(r=`ABORTED`):t instanceof Error&&(t.name===`TimeoutError`?r=`TIMEOUT`:t.name===`AbortError`||t.message.includes(`abort`)?r=`ABORTED`:t.name===`TypeError`&&(r=`NETWORK_ERROR`)),this.trackDev({method:e.method??`GET`,url:i,duration:performance.now()-(performance.now()-0),cached:!1,ok:!1,code:r,headers:s,body:e.body,retryCount:0}),t instanceof DOMException){if(t.name===`TimeoutError`)return n({message:`Request timed out`,code:`TIMEOUT`});if(t.name===`AbortError`)return n({message:`Request aborted`,code:`ABORTED`})}return t instanceof Error?t.name===`TimeoutError`?n({message:`Request timed out`,code:`TIMEOUT`}):t.name===`AbortError`||t.message.includes(`abort`)?n({message:`Request aborted`,code:`ABORTED`}):n({message:t.message,code:t.name===`TypeError`?`NETWORK_ERROR`:`UNKNOWN_ERROR`}):n({message:String(t),code:`UNKNOWN_ERROR`})}}get(e,t){return this.request({...t,url:e,method:`GET`})}post(e,t,n){return this.request({...n,url:e,method:`POST`,body:t})}put(e,t,n){return this.request({...n,url:e,method:`PUT`,body:t})}patch(e,t,n){return this.request({...n,url:e,method:`PATCH`,body:t})}delete(e,t){return this.request({...t,url:e,method:`DELETE`})}head(e,t){return this.request({...t,url:e,method:`HEAD`})}options(e,t){return this.request({...t,url:e,method:`OPTIONS`})}addRequestInterceptor(e){return this.requestInterceptors.push(e),()=>{let t=this.requestInterceptors.indexOf(e);t!==-1&&this.requestInterceptors.splice(t,1)}}addResponseInterceptor(e){return this.responseInterceptors.push(e),()=>{let t=this.responseInterceptors.indexOf(e);t!==-1&&this.responseInterceptors.splice(t,1)}}clearInterceptors(){this.requestInterceptors=[],this.responseInterceptors=[]}clearCache(){this.cache.clear()}cancelAll(){for(let e of this.pendingRequests)e.abort();this.pendingRequests.clear()}get activeRequests(){return this.pendingRequests.size}get queueStats(){return{active:this.requestQueue?.active??this.pendingRequests.size,pending:this.requestQueue?.pending??0}}extend(t={}){let n=new e({baseURL:t.baseURL??this.config.baseURL,defaultHeaders:{...this.config.defaultHeaders,...t.defaultHeaders},defaultTimeout:t.defaultTimeout??this.config.defaultTimeout,validateStatus:t.validateStatus??this.config.validateStatus,cacheStrategy:t.cacheStrategy??this.cache,maxConcurrent:t.maxConcurrent??this.config.maxConcurrent,defaultResponseType:t.defaultResponseType??this.config.defaultResponseType,defaultHooks:{...this.config.defaultHooks,...t.defaultHooks},adapter:t.adapter});for(let e of this.requestInterceptors)n.addRequestInterceptor(e);for(let e of this.responseInterceptors)n.addResponseInterceptor(e);return n}async*paginate(e,t,n={}){let r={...n};for(;;){let n=await this.get(e,r);if(!n.ok)break;yield t.getItems(n.value.data);let i=t.getNextPage(n.value.data,r);if(!i)break;r=i}}async poll(e,t,r={}){let i=t.maxAttempts??0;for(let n=1;i===0||n<=i;n++){let a=await this.get(e,r);if(!a.ok||(t.onPoll?.(a.value.data,n),t.until(a.value.data)))return a;if(i>0&&n>=i)break;await this.delay(t.intervalMs)}return n({message:`Polling exhausted after ${i} attempts`,code:`POLL_EXHAUSTED`})}buildRequest(e){let t=L(e.url,e.params);return{url:this.buildUrl(t,e.query),method:e.method??`GET`,headers:{...this.config.defaultHeaders,...e.headers},body:e.body,params:e.params}}buildUrl(e,t){let n=this.config.baseURL+e;if(t){let e=Object.keys(t);if(e.length>0){let r=new URLSearchParams;for(let n=0;n<e.length;n++)r.append(e[n],String(t[e[n]]));n+=`?${r.toString()}`}}return n}getCacheKey(e){let t=L(e.url,e.params),n=e.query?JSON.stringify(e.query):``;return`${e.method??`GET`}:${t}${n?`:`+n:``}`}fetchWithTimeout(e,t,n){let{serialized:r,contentType:i}=I(e.body),a={...e.headers};return i?a[`Content-Type`]=i:r instanceof FormData&&delete a[`Content-Type`],new Promise((i,o)=>{let s=setTimeout(()=>{n.abort(),o(new DOMException(`Request timed out`,`TimeoutError`))},t);(this.config.adapter??fetch)(e.url,{method:e.method,headers:a,body:r,signal:n.signal}).then(e=>{clearTimeout(s),i(e)},e=>{clearTimeout(s),o(e)})})}trackDownloadProgress(e,t){let n=parseInt(e.headers.get(`content-length`)||`0`,10),r=e.body?.getReader();if(!r)return e;let i=0,a=new ReadableStream({async pull(e){let{done:a,value:o}=await r.read();if(a){e.close();return}i+=o.byteLength,t({loaded:i,total:n,percent:n>0?Math.round(i/n*100):0}),e.enqueue(o)}});return new Response(a,{headers:e.headers,status:e.status,statusText:e.statusText})}async parseResponse(e,t,n,r){let i=await this.parseBody(e,r);return{status:e.status,statusText:e.statusText,headers:e.headers,data:i,request:t,duration:n}}async parseBody(e,t){switch(t){case`json`:return await e.json();case`text`:return await e.text();case`blob`:return await e.blob();case`arrayBuffer`:return await e.arrayBuffer();case`formData`:return await e.formData();case`stream`:return e.body;default:{let t=e.headers.get(`content-type`)??``;if(t.includes(`application/json`))return await e.json();if(t.includes(`text/`))return await e.text();if(t.includes(`multipart/form-data`))return await e.formData();if(t.includes(`application/octet-stream`)||t.includes(`image/`)||t.includes(`audio/`)||t.includes(`video/`))return await e.blob();try{return await e.json()}catch{return await e.text()}}}}normalizeError(e){if(e instanceof DOMException){if(e.name===`TimeoutError`)return{message:`Request timed out`,code:`TIMEOUT`};if(e.name===`AbortError`)return{message:`Request aborted`,code:`ABORTED`}}return e instanceof Error?e.name===`TimeoutError`?{message:`Request timed out`,code:`TIMEOUT`}:e.name===`AbortError`||e.message.includes(`abort`)?{message:`Request aborted`,code:`ABORTED`}:{message:e.message,code:e.name===`TypeError`?`NETWORK_ERROR`:`UNKNOWN_ERROR`,originalError:e}:{message:String(e),code:`UNKNOWN_ERROR`,originalError:e}}isHttpErrorDetails(e){return typeof e==`object`&&!!e&&`message`in e&&`code`in e}getMaxAttempts(e){return e?`maxAttempts`in e?e.maxAttempts??1:100:1}getRetryStrategy(e){return e?`shouldRetry`in e?e:new P(e.maxAttempts,e.backoffMs):{shouldRetry:()=>!1,delayMs:()=>0}}resolveTimeoutMs(e){return typeof e==`number`?e:e.total??e.response??e.connection??3e4}delay(e){return new Promise(t=>setTimeout(t,e))}trackDev(e){this.devTracker&&this.devTracker.track(e)}},z=class extends Error{status;code;response;constructor(e,t,n,r){super(e),this.name=`HttpError`,this.status=t,this.code=n,this.response=r}};function he(e){return e instanceof z}function ge(e){return new R(e)}function B(){return typeof window>`u`&&typeof process<`u`&&process.versions?.node!==void 0}var _e=class{url;options;pluginManager;status=`closed`;reconnectAttempt=0;reconnectTimer=null;heartbeatTimer=null;stats={messagesSent:0,messagesReceived:0,connectionTime:0,reconnectAttempts:0};connectionStartTime=0;listeners={open:new Set,close:new Set,error:new Set,message:new Set};constructor(e,t={}){this.url=e,this.options=t,this.pluginManager=new M}updateStatus(e){this.status=e,e===`open`?this.connectionStartTime=Date.now():e===`closed`&&this.connectionStartTime>0&&(this.stats.connectionTime+=Date.now()-this.connectionStartTime,this.connectionStartTime=0)}emitOpen(e){this.pluginManager.emit(`websocket:open`,this.url,e);for(let t of this.listeners.open)t(e)}emitClose(e){this.pluginManager.emit(`websocket:close`,this.url,e);for(let t of this.listeners.close)t(e)}emitError(e){let t;e instanceof Error?(t=new Event(`error`),t.error=e):t=e,this.pluginManager.emit(`websocket:error`,this.url,t);for(let e of this.listeners.error)e(t)}emitMessage(e){this.pluginManager.emit(`websocket:message`,this.url,e);for(let t of this.listeners.message)t(e)}onOpen(e){return this.listeners.open.add(e),()=>this.listeners.open.delete(e)}onClose(e){return this.listeners.close.add(e),()=>this.listeners.close.delete(e)}onError(e){return this.listeners.error.add(e),()=>this.listeners.error.delete(e)}onMessage(e){return this.listeners.message.add(e),()=>this.listeners.message.delete(e)}getStatus(){return this.status}getStats(){return{...this.stats,connectionTime:this.stats.connectionTime+(this.connectionStartTime>0?Date.now()-this.connectionStartTime:0)}}scheduleReconnect(){if(this.options.reconnect?.enabled===!1)return;let e=this.options.reconnect?.maxAttempts??1/0;if(this.reconnectAttempt>=e){this.pluginManager.emit(`websocket:reconnect:failed`,this.url,this.reconnectAttempt);return}let t=this.options.reconnect?.baseDelay??1e3,n=this.options.reconnect?.maxDelay??3e4,r=Math.min(n,t*2**this.reconnectAttempt);this.reconnectAttempt++,this.stats.reconnectAttempts=this.reconnectAttempt,this.options.reconnect?.onReconnecting?.(this.reconnectAttempt,r),this.pluginManager.emit(`websocket:reconnecting`,this.url,this.reconnectAttempt,r),this.reconnectTimer=setTimeout(()=>{this.connect().catch(e=>{this.emitError(e instanceof Error?e:Error(String(e)))})},r)}startHeartbeat(){if(!this.options.heartbeat)return;let e=this.options.heartbeat.interval??3e4,t=this.options.heartbeat.pingMessage??`ping`,n=this.options.heartbeat.pongMessage??`pong`,r=!0,i=()=>{if(!r){this.pluginManager.emit(`websocket:heartbeat:timeout`,this.url),this.disconnect();return}r=!1,this.send(t),this.heartbeatTimer=setTimeout(i,e)};this.onMessage(e=>{let t=e.raw;typeof t==`string`&&t===n&&(r=!0)}),this.heartbeatTimer=setTimeout(i,e)}stopHeartbeat(){this.heartbeatTimer&&=(clearTimeout(this.heartbeatTimer),null)}cleanup(){this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.stopHeartbeat()}},V=class extends _e{socket=null;messageTypeListeners=new Map;constructor(e,t={}){super(e,t)}async connect(){if(!(this.status===`connecting`||this.status===`open`))return this.updateStatus(`connecting`),this.pluginManager.emit(`websocket:connect:start`,this.url),new Promise((e,t)=>{let n=this.options.timeout??1e4,r=setTimeout(()=>{this.updateStatus(`closed`),this.socket?.close(),this.socket=null;let e=Error(`WebSocket connection timeout after ${n}ms`);this.emitError(e),t(e)},n);try{this.socket=new WebSocket(this.url,this.options.protocols),this.socket.onopen=t=>{clearTimeout(r),this.updateStatus(`open`),this.reconnectAttempt=0,this.emitOpen(t),this.options.onOpen?.(t),this.startHeartbeat(),this.pluginManager.emit(`websocket:connect:success`,this.url),e()},this.socket.onclose=e=>{clearTimeout(r),this.updateStatus(`closed`),this.emitClose(e),this.options.onClose?.(e),this.stopHeartbeat(),this.pluginManager.emit(`websocket:disconnected`,this.url,e.code,e.reason),e.code!==1e3&&!e.wasClean&&this.scheduleReconnect()},this.socket.onerror=e=>{clearTimeout(r),this.updateStatus(`closed`),this.emitError(e),this.options.onError?.(e),this.pluginManager.emit(`websocket:connect:error`,this.url,e),t(e)},this.socket.onmessage=e=>{this.stats.messagesReceived++;let t={data:this.tryParseData(e.data),raw:e.data,type:`message`,timestamp:Date.now()};this.emitMessage(t),this.pluginManager.emit(`websocket:message:received`,this.url,t)}}catch(e){clearTimeout(r),this.updateStatus(`closed`),this.pluginManager.emit(`websocket:connect:error`,this.url,e),t(e)}})}disconnect(){this.cleanup(),this.socket&&(this.updateStatus(`closing`),this.socket.close(1e3,`Client disconnected`),this.socket=null,this.updateStatus(`closed`))}send(e){if(!this.socket||this.socket.readyState!==WebSocket.OPEN)throw Error(`WebSocket is not connected`);this.socket.send(e),this.stats.messagesSent++,this.pluginManager.emit(`websocket:message:sent`,this.url,e)}sendJson(e){this.send(JSON.stringify(e))}onMessageType(e,t){return this.messageTypeListeners.has(e)||this.messageTypeListeners.set(e,new Set),this.messageTypeListeners.get(e).add(t),()=>{let n=this.messageTypeListeners.get(e);n&&(n.delete(t),n.size===0&&this.messageTypeListeners.delete(e))}}tryParseData(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return e}return e}},ve=class extends V{async connect(){if(B())try{let{default:e}=await import(`ws`);return super.connect()}catch{throw Error(`WebSocket client for Node.js requires the "ws" package. Please install it: npm install ws`)}return super.connect()}};function ye(e,t={}){return B()?new ve(e,t):new V(e,t)}function H(){return typeof window>`u`&&typeof process<`u`&&process.versions?.node!==void 0}var U=class{url;options;_source=null;pluginManager;status=`closed`;reconnectAttempt=0;reconnectTimer=null;stats={messagesSent:0,messagesReceived:0,connectionTime:0,reconnectAttempts:0};connectionStartTime=0;listeners={open:new Set,close:new Set,error:new Set,message:new Set,event:new Map};_lastEventId=null;constructor(e,t={}){this.url=e,this.options=t,this.pluginManager=new M}updateStatus(e){this.status=e,e===`open`?this.connectionStartTime=Date.now():e===`closed`&&this.connectionStartTime>0&&(this.stats.connectionTime+=Date.now()-this.connectionStartTime,this.connectionStartTime=0)}async connect(){if(!(this.status===`connecting`||this.status===`open`))return this.updateStatus(`connecting`),this.pluginManager.emit(`sse:connect:start`,this.url),new Promise((e,t)=>{let n=this.options.timeout??1e4,r=setTimeout(()=>{this.updateStatus(`closed`),this._source?.close(),this._source=null;let e=Error(`SSE connection timeout after ${n}ms`);this.emitError(e),t(e)},n);try{this._source=new EventSource(this.url),this._source.onopen=t=>{clearTimeout(r),this.updateStatus(`open`),this.reconnectAttempt=0,this.emitOpen(t),this.options.onOpen?.(t),this.pluginManager.emit(`sse:connect:success`,this.url),e()},this._source.onerror=e=>{clearTimeout(r),this.updateStatus(`closed`),this.emitError(e),this.options.onError?.(e),this.pluginManager.emit(`sse:connect:error`,this.url,e),this._source?.readyState===EventSource.CLOSED&&(this.emitClose(),this.options.onClose?.(),this.scheduleReconnect()),t(e)},this._source.onmessage=e=>{this.stats.messagesReceived++,this._lastEventId=e.lastEventId||this._lastEventId;let t={data:this.tryParseData(e.data),raw:e.data,type:e.type||`message`,timestamp:Date.now()};this.emitMessage(t),this.pluginManager.emit(`sse:message:received`,this.url,t);let n=e.type||`message`,r=this.listeners.event.get(n);if(r)for(let e of r)e(t.data)},this._source.addEventListener=this._source.addEventListener.bind(this._source)}catch(e){clearTimeout(r),this.updateStatus(`closed`),this.pluginManager.emit(`sse:connect:error`,this.url,e),t(e)}})}disconnect(){this.cleanup(),this._source&&(this.updateStatus(`closing`),this._source.close(),this._source=null,this.updateStatus(`closed`),this.emitClose(),this.options.onClose?.())}send(e){throw Error(`SSE is a receive-only protocol. Use HTTP requests to send data to server.`)}onMessage(e){return this.listeners.message.add(e),()=>this.listeners.message.delete(e)}onOpen(e){return this.listeners.open.add(e),()=>this.listeners.open.delete(e)}onClose(e){return this.listeners.close.add(e),()=>this.listeners.close.delete(e)}onError(e){return this.listeners.error.add(e),()=>this.listeners.error.delete(e)}onEvent(e,t){return this.listeners.event.has(e)||this.listeners.event.set(e,new Set),this.listeners.event.get(e).add(t),this._source&&!this._source[`on${e}`]&&this._source.addEventListener(e,n=>{t({data:this.tryParseData(n.data),raw:n.data,type:e,timestamp:Date.now()}.data)}),()=>{let n=this.listeners.event.get(e);n&&(n.delete(t),n.size===0&&this.listeners.event.delete(e))}}getStatus(){return this.status}getStats(){return{...this.stats,connectionTime:this.stats.connectionTime+(this.connectionStartTime>0?Date.now()-this.connectionStartTime:0)}}get lastEventId(){return this._lastEventId}get source(){return this._source}emitOpen(e){this.pluginManager.emit(`sse:open`,this.url,e);for(let t of this.listeners.open)t(e)}emitClose(){this.pluginManager.emit(`sse:close`,this.url);for(let e of this.listeners.close)e()}emitError(e){let t;e instanceof Error?(t=new Event(`error`),t.error=e):t=e,this.pluginManager.emit(`sse:error`,this.url,t);for(let e of this.listeners.error)e(t)}emitMessage(e){this.pluginManager.emit(`sse:message`,this.url,e);for(let t of this.listeners.message)t(e)}scheduleReconnect(){if(this.options.reconnect?.enabled===!1)return;let e=this.options.reconnect?.maxAttempts??1/0;if(this.reconnectAttempt>=e){this.pluginManager.emit(`sse:reconnect:failed`,this.url,this.reconnectAttempt);return}let t=this.options.reconnect?.baseDelay??1e3,n=this.options.reconnect?.maxDelay??3e4,r=Math.min(n,t*2**this.reconnectAttempt);this.reconnectAttempt++,this.stats.reconnectAttempts=this.reconnectAttempt,this.options.reconnect?.onReconnecting?.(this.reconnectAttempt,r),this.pluginManager.emit(`sse:reconnecting`,this.url,this.reconnectAttempt,r),this.reconnectTimer=setTimeout(()=>{this.connect().catch(e=>{this.emitError(e instanceof Error?e:Error(String(e)))})},r)}cleanup(){this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}tryParseData(e){try{return JSON.parse(e)}catch{return e}}},be=class extends U{async connect(){if(H())throw Error(`SSE client for Node.js requires a polyfill or custom implementation. Consider using a library like "eventsource" or implement using fetch with streaming.`);return super.connect()}};function xe(e,t={}){return H()?new be(e,t):new U(e,t)}var Se=class{name=`realtime`;setup(e){e.on(`websocket:connect:start`,(...t)=>{let n=t[0];e.emit(`realtime:connect:start`,`websocket`,n)}),e.on(`websocket:connect:success`,(...t)=>{let n=t[0];e.emit(`realtime:connect:success`,`websocket`,n)}),e.on(`websocket:message:received`,(...t)=>{let n=t[0],r=t[1];e.emit(`realtime:message`,`websocket`,n,r)}),e.on(`sse:connect:start`,(...t)=>{let n=t[0];e.emit(`realtime:connect:start`,`sse`,n)}),e.on(`sse:connect:success`,(...t)=>{let n=t[0];e.emit(`realtime:connect:success`,`sse`,n)}),e.on(`sse:message:received`,(...t)=>{let n=t[0],r=t[1];e.emit(`realtime:message`,`sse`,n,r)})}};function Ce(){return new Se}var W=`nexa.devOverlay.config`;function G(){try{if(typeof localStorage>`u`)return{};let e=localStorage.getItem(W);return e?JSON.parse(e):{}}catch{return{}}}function we(e){try{if(typeof localStorage>`u`)return;localStorage.setItem(W,JSON.stringify(e))}catch{}}var K=class{history=[];maxHistory;listeners=new Set;startTime=Date.now();config;constructor(e={}){this.maxHistory=e.maxHistory??500,this.config={enabled:e.enabled??!0,maxHistory:this.maxHistory,keyboardShortcut:e.keyboardShortcut??`ctrl+shift+n`,position:e.position??`bottom-right`,theme:e.theme??`dark`,devOnly:e.devOnly??!0,floatingButtonSize:e.floatingButtonSize??48,floatingButtonOffset:e.floatingButtonOffset??24,floatingButtonTheme:e.floatingButtonTheme??`inherit`}}track(e){let t={...e,id:this.generateId(),timestamp:Date.now()};this.history.unshift(t),this.history.length>this.maxHistory&&this.history.pop();for(let e of this.listeners)e(t);return t}getHistory(){return this.history}getMetrics(){let e=this.history.map(e=>e.duration),t=(Date.now()-this.startTime)/1e3;return{totalRequests:this.history.length,successfulRequests:this.history.filter(e=>e.ok).length,failedRequests:this.history.filter(e=>!e.ok).length,cachedRequests:this.history.filter(e=>e.cached).length,avgDuration:e.length?e.reduce((e,t)=>e+t,0)/e.length:0,maxDuration:e.length?Math.max(...e):0,minDuration:e.length?Math.min(...e):0,requestsPerSecond:t>0?this.history.length/t:0,slowestRequests:[...this.history].sort((e,t)=>t.duration-e.duration).slice(0,5)}}clear(){this.history=[],this.startTime=Date.now()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}getConfig(){return this.config}updateConfig(e){this.config={...this.config,...e},this.maxHistory=this.config.maxHistory;try{we(this.config)}catch{}return this.config}generateId(){return`${Date.now()}-${Math.random().toString(36).slice(2,8)}`}},q={gear:`<svg width="16" height="16" viewBox="0 0 48 48" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
1
+ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=e=>({ok:!0,value:e}),n=e=>({ok:!1,error:e});function r(e){return{validate(r){let i=r;for(let[t,r]of Object.entries(e))if(!r(i[t]))return n({message:`Validation failed: field "${t}" is invalid`,code:`VALIDATION_ERROR`});return t(r)}}}function i(e){return{validate(r){let i=r,a=e.filter(e=>!(e in i));return a.length>0?n({message:`Validation failed: missing fields: ${a.join(`, `)}`,code:`VALIDATION_ERROR`}):t(r)}}}var a={validate(e){return Array.isArray(e)?t(e):n({message:`Expected array response`,code:`VALIDATION_ERROR`})}},o={validate(e){return e&&typeof e==`object`&&!Array.isArray(e)?t(e):n({message:`Expected object response`,code:`VALIDATION_ERROR`})}},s={transform(e){return h(e,te)}},c={transform(e){return h(e,m)}},l={transform(e){return g(e)}};function u(e){return{transform(t){return Array.isArray(t)?t.map(t=>_(t,e)):_(t,e)}}}function d(e){return{transform(t){return{[e]:t}}}}var f=class{maxAttempts;constructor(e=5){this.maxAttempts=e}shouldRetry(e){return e<this.maxAttempts}delayMs(e){return e*50}},p=class{retryableStatuses=[408,429,500,502,503,504];maxAttempts;constructor(e=3){this.maxAttempts=e}shouldRetry(e,t){return e>=this.maxAttempts?!1:this.retryableStatuses.includes(t.status??0)||t.code===`TIMEOUT`}delayMs(e){return Math.min(1e3*2**(e-1),1e4)}},ee=class{failureCount=0;lastFailureTime=0;maxAttempts;failureThreshold;resetTimeMs;constructor(e=3,t=5,n=6e4){this.maxAttempts=e,this.failureThreshold=t,this.resetTimeMs=n}shouldRetry(e){return e>=this.maxAttempts||(Date.now()-this.lastFailureTime>this.resetTimeMs&&(this.failureCount=0),this.failureCount>=this.failureThreshold)?!1:(this.failureCount++,this.lastFailureTime=Date.now(),!0)}delayMs(e){return 100*2**(e-1)}reset(){this.failureCount=0,this.lastFailureTime=0}};function te(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())}function m(e){return e.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}function h(e,t){if(!e||typeof e!=`object`)return e;if(Array.isArray(e))return e.map(e=>h(e,t));let n={};for(let[r,i]of Object.entries(e))n[t(r)]=h(i,t);return n}function g(e,t=``){let n={};if(Array.isArray(e))e.forEach((e,r)=>{let i=t?`${t}[${r}]`:`[${r}]`;Object.assign(n,g(e,i))});else if(e&&typeof e==`object`)for(let[r,i]of Object.entries(e)){let e=t?`${t}.${r}`:r;i&&typeof i==`object`&&!Array.isArray(i)?Object.assign(n,g(i,e)):n[e]=i}return n}function _(e,t){if(!e||typeof e!=`object`)return{};let n=e,r={};for(let e of t)e in n&&(r[e]=n[e]);return r}function ne(e){let t=new AbortController,n=setTimeout(()=>t.abort(),e);return t.signal.addEventListener(`abort`,()=>clearTimeout(n),{once:!0}),t}async function v(e,t=3){try{return await e()}catch(n){if(t<=0)throw n;return v(e,t-1)}}var y=class{cache=new Map;get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>t.ttlMs?(this.cache.delete(e),null):t.data:null}set(e,t,n=6e4){this.cache.set(e,{data:t,timestamp:Date.now(),ttlMs:n})}clear(){this.cache.clear()}has(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>t.ttlMs?(this.cache.delete(e),!1):!0:!1}delete(e){this.cache.delete(e)}};function b(e={}){let t=e.cache||new y,n=e.ttlMs||6e4,r=e.cacheableStatuses||[200,304];return async(e,i)=>{let a=(e.request.method||`GET`).toUpperCase(),o=a===`GET`,s=`${a}:${e.request.url}`;if(o&&t.has(s)){let n=t.get(s);if(n){e.response=n,e.state.cacheHit=!0;return}}await i(),o&&e.response&&r.includes(e.response.status)&&(t.set(s,e.response,n),e.state.cacheMiss=!0)}}var re=b(),x=class{pending=new Map;async execute(e,t){if(this.pending.has(e))return this.pending.get(e);let n=t().finally(()=>{this.pending.delete(e)});return this.pending.set(e,n),n}clear(){this.pending.clear()}};function S(e={}){let t=e.deduplicator||new x,n=e.includeBody??!1,r=e.methods||[`GET`];return async(e,i)=>{let a=(e.request.method||`GET`).toUpperCase();if(!r.includes(a)){await i();return}let o=`${a}:${e.request.url}`;n&&e.request.body&&(o+=`:${JSON.stringify(e.request.body)}`);try{e.response=await t.execute(o,async()=>(await i(),e.response)),e.state.deduped=!0}catch(t){throw e.error=t,t}}}var ie=S();function C(e){return async t=>{let n=-1;async function r(i){if(i<=n)throw Error(`next() called multiple times`);n=i;let a=e[i];a&&await a(t,()=>r(i+1))}await r(0)}}var w=class{middlewares=[];use(e){return this.middlewares.push(e),this}async execute(e){if(e&&typeof e==`object`&&`request`in e&&`response`in e){let t=e;return await C(this.middlewares.map(e=>typeof e==`function`&&e.length===2?e:async(t,n)=>{let r=e;t.response.body=await r(t.response.body),await n()}))(t),t.response.body}let t=e;for(let e of this.middlewares)t=await e(t);return t}clear(){this.middlewares=[]}};function T(e,t,n,r={}){return{ok:e>=200&&e<300,data:t,error:n,status:e,headers:r}}function E(e){return async(t,n)=>{let r=e.path,i;switch(e.method){case`GET`:i=await t.get(r);break;case`POST`:i=await t.post(r,n);break;case`PUT`:i=await t.put(r,n);break;case`PATCH`:i=await t.patch(r,n);break;case`DELETE`:i=await t.delete(r);break;default:throw Error(`Unsupported method: ${e.method}`)}return i}}function D(e){return{request:async(t,n,r)=>{let i=e[n];return await E(i)(t,r)}}}var ae=class e{subscribers=[];errorSubscribers=[];completeSubscribers=[];subscribe(e,t,n){return e&&this.subscribers.push(e),t&&this.errorSubscribers.push(t),n&&this.completeSubscribers.push(n),{unsubscribe:()=>{this.subscribers=this.subscribers.filter(t=>t!==e),this.errorSubscribers=this.errorSubscribers.filter(e=>e!==t),this.completeSubscribers=this.completeSubscribers.filter(e=>e!==n)}}}next(e){this.subscribers.forEach(t=>t(e))}error(e){this.errorSubscribers.forEach(t=>t(e))}complete(){this.completeSubscribers.forEach(e=>e())}map(t){let n=new e;return this.subscribe(e=>n.next(t(e)),e=>n.error(e),()=>n.complete()),n}filter(t){let n=new e;return this.subscribe(e=>{t(e)&&n.next(e)},e=>n.error(e),()=>n.complete()),n}};function oe(e){return t=>{if(!e(t))throw TypeError(`Value does not match expected type`);return t}}function O(e){return e}function se(e){return O(e)}var ce=class{_promise;resolveFunc;rejectFunc;constructor(){this._promise=new Promise((e,t)=>{this.resolveFunc=e,this.rejectFunc=t})}resolve(e){this.resolveFunc(e)}reject(e){this.rejectFunc(e)}get promise(){return this._promise}promise_(){return this._promise}};async function k(e,t={}){let n=e.body?.getReader();if(!n)throw Error(`Response body is not readable`);let r=[],i=0,a=parseInt(e.headers.get(`content-length`)||`0`,10);for(;;){let{done:e,value:o}=await n.read();if(e)break;r.push(o),i+=o.length,t.onChunk&&await t.onChunk(o),t.onProgress&&a>0&&t.onProgress(i,a)}return A(r,i)}function A(e,t){let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n}async function le(e,t){let n=await k(e);if(typeof window>`u`)await(await import(`fs`).then(e=>e.promises)).writeFile(t,n);else{let e=new Blob([n.buffer],{type:`application/octet-stream`}),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=t,i.click(),URL.revokeObjectURL(r)}}function j(e={}){return async(t,n)=>{if(await n(),t.response&&t.response.body&&typeof t.response.body==`object`&&`getReader`in t.response.body){let n=t.response.body.getReader(),r=[],i=0,a=parseInt(t.response.headers?.[`content-length`]||`0`,10);try{for(;;){let{done:o,value:s}=await n.read();if(o)break;r.push(s),i+=s.length,e.onChunk&&await e.onChunk(s),e.onProgress&&a>0&&e.onProgress(i,a),t.state.streamedChunks=t.state.streamedChunks||[],t.state.streamedChunks.push(s)}let o=A(r,i);t.response.body=o,t.state.streaming=!0,t.state.streamedBytes=i}finally{n.releaseLock()}}}}var ue=j({onProgress:(e,t)=>{if(t>0){let n=Math.round(e/t*100);console.warn(`Streaming: ${n}% (${e}/${t} bytes)`)}}}),M=class{plugins=[];cache=new y;deduplicator=new x;middlewares=[];listeners=new Map;register(e){return this.plugins.push(e),e.setup(this),this.emit(`plugin:registered`,e.name),this}addMiddleware(e){return this.middlewares.push(e),this}getCache(){return this.cache}getDeduplicator(){return this.deduplicator}getPipeline(){return C(this.middlewares)}async executePipeline(e){await this.getPipeline()(e)}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set);let n=this.listeners.get(e),r=t;return n&&n.add(r),this}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of n)e(...t)}off(e,t){return this.listeners.get(e)?.delete(t),this}getPlugins(){return[...this.plugins]}clear(){this.plugins=[],this.middlewares=[],this.listeners.clear(),this.cache.clear(),this.deduplicator.clear()}},de={name:`logger`,setup(e){e.on(`request:start`,(...e)=>{let t=e[0];console.warn(`Request started: ${t}`)}),e.on(`request:success`,(...e)=>{let t=e[0],n=e[1];console.warn(`Request succeeded: ${t} (${n})`)}),e.on(`request:error`,(...e)=>{let t=e[0],n=e[1];console.error(`❌ Request failed: ${t}`,n)})}},fe=class{name=`metrics`;metrics={requests:0,errors:0,totalTime:0,avgTime:0};setup(e){e.on(`request:complete`,(...e)=>{let t=e[0],n=e[1];this.metrics.requests++,this.metrics.totalTime+=t,this.metrics.avgTime=this.metrics.totalTime/this.metrics.requests,n||this.metrics.errors++})}getMetrics(){return{...this.metrics}}},pe=class{name=`cache`;ttlMs;constructor(e=6e4){this.ttlMs=e}setup(e){e.addMiddleware(b({ttlMs:this.ttlMs}))}},me=class{name=`dedupe`;setup(e){e.addMiddleware(S())}},N=class{store=new y;get(e){return this.store.get(e)}set(e,t,n=6e4){this.store.set(e,t,n)}has(e){return this.store.has(e)}clear(){this.store.clear()}},P=class{maxAttempts;baseDelayMs;constructor(e=3,t=100){this.maxAttempts=e,this.baseDelayMs=t}shouldRetry(e,t){let n=t.status!==void 0&&t.status>=500,r=t.code===`NETWORK_ERROR`;return e<this.maxAttempts&&(n||r||t.code===`TIMEOUT`)}delayMs(e){let t=this.baseDelayMs*2**(e-1),n=Math.random()*t*.1;return Math.min(t+n,3e4)}},F=class{running=0;queue=[];maxConcurrent;constructor(e){this.maxConcurrent=e}async acquire(){if(this.running<this.maxConcurrent){this.running++;return}return new Promise(e=>{this.queue.push(()=>{this.running++,e()})})}release(){this.running--;let e=this.queue.shift();e&&e()}get pending(){return this.queue.length}get active(){return this.running}};function I(e){return e==null?{serialized:void 0,contentType:null}:typeof e==`string`?{serialized:e,contentType:`text/plain`}:typeof FormData<`u`&&e instanceof FormData?{serialized:e,contentType:null}:typeof URLSearchParams<`u`&&e instanceof URLSearchParams?{serialized:e,contentType:`application/x-www-form-urlencoded`}:typeof Blob<`u`&&e instanceof Blob?{serialized:e,contentType:e.type||`application/octet-stream`}:e instanceof ArrayBuffer||ArrayBuffer.isView(e)||typeof ReadableStream<`u`&&e instanceof ReadableStream?{serialized:e,contentType:`application/octet-stream`}:{serialized:JSON.stringify(e),contentType:`application/json`}}function L(e,t){return t?e.replace(/:([a-zA-Z_][a-zA-Z0-9_]*)/g,(e,n)=>{let r=t[n];if(r===void 0)throw Error(`Missing path parameter: :${n}`);return encodeURIComponent(String(r))}):e}var R=class e{requestInterceptors=[];responseInterceptors=[];cache;devTracker;config;requestQueue;pendingRequests=new Set;constructor(e={}){this.config={baseURL:e.baseURL??``,defaultHeaders:e.defaultHeaders??{"Content-Type":`application/json`},defaultTimeout:e.defaultTimeout??3e4,validateStatus:e.validateStatus??(e=>e>=200&&e<300),cacheStrategy:e.cacheStrategy??new N,maxConcurrent:e.maxConcurrent??0,defaultResponseType:e.defaultResponseType??`auto`,defaultHooks:e.defaultHooks??{},adapter:e.adapter},this.cache=this.config.cacheStrategy,this.requestQueue=this.config.maxConcurrent>0?new F(this.config.maxConcurrent):null,this.devTracker=e.devTracker??null}async request(e){if(!this.requestInterceptors.length&&!this.responseInterceptors.length&&!e.cache?.enabled&&!e.hooks&&!Object.keys(this.config.defaultHooks).length&&!e.retry&&!e.validate&&!e.transform&&!this.requestQueue&&!e.onDownloadProgress&&!e.signal)return this.fastPath(e);let r=e.hooks?{...this.config.defaultHooks,...e.hooks}:this.config.defaultHooks,i=this.getMaxAttempts(e.retry),a=this.getRetryStrategy(e.retry),o=this.buildRequest(e);r.onStart?.(o),this.requestQueue&&await this.requestQueue.acquire();try{for(let s=1;s<=i;s++){let c;try{if((e.method===`GET`||!e.method)&&e.cache?.enabled){let n=this.getCacheKey(e),i=this.cache.get(n);if(i){let n=i;return this.trackDev({method:e.method??`GET`,url:o.url,status:n.status,duration:n.duration,cached:!0,ok:!0,headers:{...o.headers},body:e.body,retryCount:0}),r.onSuccess?.(n),r.onFinally?.(),t(n)}}let n=o;for(let e of this.requestInterceptors)n=await e.onRequest(n);c=new AbortController,this.pendingRequests.add(c),e.signal&&e.signal.addEventListener(`abort`,()=>c.abort(),{once:!0});let i=performance.now(),a=await this.fetchWithTimeout(n,this.resolveTimeoutMs(e.timeout??this.config.defaultTimeout),c),l=performance.now()-i,u=a;e.onDownloadProgress&&a.body&&(u=this.trackDownloadProgress(a,e.onDownloadProgress));let d=e.responseType??this.config.defaultResponseType,f=await this.parseResponse(u,n,l,d);if(!this.config.validateStatus(f.status))throw{message:`Request failed with status ${f.status}`,status:f.status,statusText:f.statusText,code:`HTTP_ERROR`};if(e.validate){let t=e.validate.validate(f.data);if(!t.ok)return t}e.transform&&(f.data=e.transform.transform(f.data));let p=f;for(let e of this.responseInterceptors)p=await e.onResponse(p);if((e.method===`GET`||!e.method)&&e.cache?.enabled){let t=this.getCacheKey(e);this.cache.set(t,p,e.cache.ttlMs)}return r.onSuccess?.(p),this.pendingRequests.delete(c),this.trackDev({method:e.method??`GET`,url:o.url,status:p.status,duration:p.duration,cached:!1,ok:!0,headers:{...o.headers},body:e.body,retryCount:s-1}),t(p)}catch(t){let l;if(l=t instanceof DOMException?t.name===`TimeoutError`?{message:`Request timed out`,code:`TIMEOUT`}:t.name===`AbortError`?{message:`Request aborted`,code:`ABORTED`}:{message:t.message,code:`UNKNOWN_ERROR`,originalError:t}:this.isHttpErrorDetails(t)?t:this.normalizeError(t),s<i&&a.shouldRetry(s,l)){r.onRetry?.(s,l);let e=a.delayMs(s);await this.delay(e);continue}let u=l;for(let e of this.responseInterceptors)e.onError&&(u=await e.onError(u));return r.onError?.(u),c&&this.pendingRequests.delete(c),this.trackDev({method:e.method??`GET`,url:o.url,status:u.status,duration:0,cached:!1,ok:!1,code:u.code,headers:{...o.headers},body:e.body,retryCount:s-1}),n(u)}}let s={message:`Max retries exceeded`,code:`MAX_RETRIES`};return r.onError?.(s),this.trackDev({method:e.method??`GET`,url:o.url,duration:0,cached:!1,ok:!1,code:`MAX_RETRIES`,headers:{...o.headers},body:e.body,retryCount:i}),n(s)}finally{r.onFinally?.(),this.requestQueue&&this.requestQueue.release()}}async fastPath(e){let r=L(e.url,e.params),i=this.buildUrl(r,e.query),{serialized:a,contentType:o}=I(e.body),s={...this.config.defaultHeaders,...e.headers};o?s[`Content-Type`]=o:a instanceof FormData&&delete s[`Content-Type`];let c=new AbortController,l=this.resolveTimeoutMs(e.timeout??this.config.defaultTimeout);this.pendingRequests.add(c);try{let r=performance.now(),a=await this.fetchWithTimeout({url:i,method:e.method??`GET`,headers:s,body:e.body,params:e.params},l,c),o=performance.now()-r,u=await this.parseBody(a,e.responseType??this.config.defaultResponseType);if(!this.config.validateStatus(a.status)){let t=n({message:`Request failed with status ${a.status}`,status:a.status,statusText:a.statusText,code:`HTTP_ERROR`});return this.trackDev({method:e.method??`GET`,url:i,status:a.status,duration:o,cached:!1,ok:!1,code:`HTTP_ERROR`,headers:s,body:e.body,retryCount:0}),this.pendingRequests.delete(c),t}return this.pendingRequests.delete(c),this.trackDev({method:e.method??`GET`,url:i,status:a.status,duration:o,cached:!1,ok:!0,headers:s,body:e.body,retryCount:0}),t({status:a.status,statusText:a.statusText,headers:a.headers,data:u,request:{url:i,method:e.method??`GET`,headers:s,body:e.body,params:e.params},duration:o})}catch(t){this.pendingRequests.delete(c);let r=`UNKNOWN_ERROR`;if(t instanceof DOMException?t.name===`TimeoutError`?r=`TIMEOUT`:t.name===`AbortError`&&(r=`ABORTED`):t instanceof Error&&(t.name===`TimeoutError`?r=`TIMEOUT`:t.name===`AbortError`||t.message.includes(`abort`)?r=`ABORTED`:t.name===`TypeError`&&(r=`NETWORK_ERROR`)),this.trackDev({method:e.method??`GET`,url:i,duration:performance.now()-(performance.now()-0),cached:!1,ok:!1,code:r,headers:s,body:e.body,retryCount:0}),t instanceof DOMException){if(t.name===`TimeoutError`)return n({message:`Request timed out`,code:`TIMEOUT`});if(t.name===`AbortError`)return n({message:`Request aborted`,code:`ABORTED`})}return t instanceof Error?t.name===`TimeoutError`?n({message:`Request timed out`,code:`TIMEOUT`}):t.name===`AbortError`||t.message.includes(`abort`)?n({message:`Request aborted`,code:`ABORTED`}):n({message:t.message,code:t.name===`TypeError`?`NETWORK_ERROR`:`UNKNOWN_ERROR`}):n({message:String(t),code:`UNKNOWN_ERROR`})}}get(e,t){return this.request({...t,url:e,method:`GET`})}post(e,t,n){return this.request({...n,url:e,method:`POST`,body:t})}put(e,t,n){return this.request({...n,url:e,method:`PUT`,body:t})}patch(e,t,n){return this.request({...n,url:e,method:`PATCH`,body:t})}delete(e,t){return this.request({...t,url:e,method:`DELETE`})}head(e,t){return this.request({...t,url:e,method:`HEAD`})}options(e,t){return this.request({...t,url:e,method:`OPTIONS`})}addRequestInterceptor(e){return this.requestInterceptors.push(e),()=>{let t=this.requestInterceptors.indexOf(e);t!==-1&&this.requestInterceptors.splice(t,1)}}addResponseInterceptor(e){return this.responseInterceptors.push(e),()=>{let t=this.responseInterceptors.indexOf(e);t!==-1&&this.responseInterceptors.splice(t,1)}}clearInterceptors(){this.requestInterceptors=[],this.responseInterceptors=[]}clearCache(){this.cache.clear()}cancelAll(){for(let e of this.pendingRequests)e.abort();this.pendingRequests.clear()}get activeRequests(){return this.pendingRequests.size}get queueStats(){return{active:this.requestQueue?.active??this.pendingRequests.size,pending:this.requestQueue?.pending??0}}extend(t={}){let n=new e({baseURL:t.baseURL??this.config.baseURL,defaultHeaders:{...this.config.defaultHeaders,...t.defaultHeaders},defaultTimeout:t.defaultTimeout??this.config.defaultTimeout,validateStatus:t.validateStatus??this.config.validateStatus,cacheStrategy:t.cacheStrategy??this.cache,maxConcurrent:t.maxConcurrent??this.config.maxConcurrent,defaultResponseType:t.defaultResponseType??this.config.defaultResponseType,defaultHooks:{...this.config.defaultHooks,...t.defaultHooks},adapter:t.adapter});for(let e of this.requestInterceptors)n.addRequestInterceptor(e);for(let e of this.responseInterceptors)n.addResponseInterceptor(e);return n}async*paginate(e,t,n={}){let r={...n};for(;;){let n=await this.get(e,r);if(!n.ok)break;yield t.getItems(n.value.data);let i=t.getNextPage(n.value.data,r);if(!i)break;r=i}}async poll(e,t,r={}){let i=t.maxAttempts??0;for(let n=1;i===0||n<=i;n++){let a=await this.get(e,r);if(!a.ok||(t.onPoll?.(a.value.data,n),t.until(a.value.data)))return a;if(i>0&&n>=i)break;await this.delay(t.intervalMs)}return n({message:`Polling exhausted after ${i} attempts`,code:`POLL_EXHAUSTED`})}buildRequest(e){let t=L(e.url,e.params);return{url:this.buildUrl(t,e.query),method:e.method??`GET`,headers:{...this.config.defaultHeaders,...e.headers},body:e.body,params:e.params}}buildUrl(e,t){let n=this.config.baseURL+e;if(t){let e=Object.keys(t);if(e.length>0){let r=new URLSearchParams;for(let n=0;n<e.length;n++)r.append(e[n],String(t[e[n]]));n+=`?${r.toString()}`}}return n}getCacheKey(e){let t=L(e.url,e.params),n=e.query?JSON.stringify(e.query):``;return`${e.method??`GET`}:${t}${n?`:`+n:``}`}fetchWithTimeout(e,t,n){let{serialized:r,contentType:i}=I(e.body),a={...e.headers};return i?a[`Content-Type`]=i:r instanceof FormData&&delete a[`Content-Type`],new Promise((i,o)=>{let s=setTimeout(()=>{n.abort(),o(new DOMException(`Request timed out`,`TimeoutError`))},t);(this.config.adapter??fetch)(e.url,{method:e.method,headers:a,body:r,signal:n.signal}).then(e=>{clearTimeout(s),i(e)},e=>{clearTimeout(s),o(e)})})}trackDownloadProgress(e,t){let n=parseInt(e.headers.get(`content-length`)||`0`,10),r=e.body?.getReader();if(!r)return e;let i=0,a=new ReadableStream({async pull(e){let{done:a,value:o}=await r.read();if(a){e.close();return}i+=o.byteLength,t({loaded:i,total:n,percent:n>0?Math.round(i/n*100):0}),e.enqueue(o)}});return new Response(a,{headers:e.headers,status:e.status,statusText:e.statusText})}async parseResponse(e,t,n,r){let i=await this.parseBody(e,r);return{status:e.status,statusText:e.statusText,headers:e.headers,data:i,request:t,duration:n}}async parseBody(e,t){switch(t){case`json`:return await e.json();case`text`:return await e.text();case`blob`:return await e.blob();case`arrayBuffer`:return await e.arrayBuffer();case`formData`:return await e.formData();case`stream`:return e.body;default:{let t=e.headers.get(`content-type`)??``;if(t.includes(`application/json`))return await e.json();if(t.includes(`text/`))return await e.text();if(t.includes(`multipart/form-data`))return await e.formData();if(t.includes(`application/octet-stream`)||t.includes(`image/`)||t.includes(`audio/`)||t.includes(`video/`))return await e.blob();try{return await e.json()}catch{return await e.text()}}}}normalizeError(e){if(e instanceof DOMException){if(e.name===`TimeoutError`)return{message:`Request timed out`,code:`TIMEOUT`};if(e.name===`AbortError`)return{message:`Request aborted`,code:`ABORTED`}}return e instanceof Error?e.name===`TimeoutError`?{message:`Request timed out`,code:`TIMEOUT`}:e.name===`AbortError`||e.message.includes(`abort`)?{message:`Request aborted`,code:`ABORTED`}:{message:e.message,code:e.name===`TypeError`?`NETWORK_ERROR`:`UNKNOWN_ERROR`,originalError:e}:{message:String(e),code:`UNKNOWN_ERROR`,originalError:e}}isHttpErrorDetails(e){return typeof e==`object`&&!!e&&`message`in e&&`code`in e}getMaxAttempts(e){return e?`maxAttempts`in e?e.maxAttempts??1:100:1}getRetryStrategy(e){return e?`shouldRetry`in e?e:new P(e.maxAttempts,e.backoffMs):{shouldRetry:()=>!1,delayMs:()=>0}}resolveTimeoutMs(e){return typeof e==`number`?e:e.total??e.response??e.connection??3e4}delay(e){return new Promise(t=>setTimeout(t,e))}trackDev(e){this.devTracker&&this.devTracker.track(e)}},z=class extends Error{status;code;response;constructor(e,t,n,r){super(e),this.name=`HttpError`,this.status=t,this.code=n,this.response=r}};function he(e){return e instanceof z}function ge(e){return new R(e)}function B(){return typeof window>`u`&&typeof process<`u`&&process.versions?.node!==void 0}var _e=class{url;options;pluginManager;status=`closed`;reconnectAttempt=0;reconnectTimer=null;heartbeatTimer=null;stats={messagesSent:0,messagesReceived:0,connectionTime:0,reconnectAttempts:0};connectionStartTime=0;listeners={open:new Set,close:new Set,error:new Set,message:new Set};constructor(e,t={}){this.url=e,this.options=t,this.pluginManager=new M}updateStatus(e){this.status=e,e===`open`?this.connectionStartTime=Date.now():e===`closed`&&this.connectionStartTime>0&&(this.stats.connectionTime+=Date.now()-this.connectionStartTime,this.connectionStartTime=0)}emitOpen(e){this.pluginManager.emit(`websocket:open`,this.url,e);for(let t of this.listeners.open)t(e)}emitClose(e){this.pluginManager.emit(`websocket:close`,this.url,e);for(let t of this.listeners.close)t(e)}emitError(e){let t;e instanceof Error?(t=new Event(`error`),t.error=e):t=e,this.pluginManager.emit(`websocket:error`,this.url,t);for(let e of this.listeners.error)e(t)}emitMessage(e){this.pluginManager.emit(`websocket:message`,this.url,e);for(let t of this.listeners.message)t(e)}onOpen(e){return this.listeners.open.add(e),()=>this.listeners.open.delete(e)}onClose(e){return this.listeners.close.add(e),()=>this.listeners.close.delete(e)}onError(e){return this.listeners.error.add(e),()=>this.listeners.error.delete(e)}onMessage(e){return this.listeners.message.add(e),()=>this.listeners.message.delete(e)}getStatus(){return this.status}getStats(){return{...this.stats,connectionTime:this.stats.connectionTime+(this.connectionStartTime>0?Date.now()-this.connectionStartTime:0)}}scheduleReconnect(){if(this.options.reconnect?.enabled===!1)return;let e=this.options.reconnect?.maxAttempts??1/0;if(this.reconnectAttempt>=e){this.pluginManager.emit(`websocket:reconnect:failed`,this.url,this.reconnectAttempt);return}let t=this.options.reconnect?.baseDelay??1e3,n=this.options.reconnect?.maxDelay??3e4,r=Math.min(n,t*2**this.reconnectAttempt);this.reconnectAttempt++,this.stats.reconnectAttempts=this.reconnectAttempt,this.options.reconnect?.onReconnecting?.(this.reconnectAttempt,r),this.pluginManager.emit(`websocket:reconnecting`,this.url,this.reconnectAttempt,r),this.reconnectTimer=setTimeout(()=>{this.connect().catch(e=>{this.emitError(e instanceof Error?e:Error(String(e)))})},r)}startHeartbeat(){if(!this.options.heartbeat)return;let e=this.options.heartbeat.interval??3e4,t=this.options.heartbeat.pingMessage??`ping`,n=this.options.heartbeat.pongMessage??`pong`,r=!0,i=()=>{if(!r){this.pluginManager.emit(`websocket:heartbeat:timeout`,this.url),this.disconnect();return}r=!1,this.send(t),this.heartbeatTimer=setTimeout(i,e)};this.onMessage(e=>{let t=e.raw;typeof t==`string`&&t===n&&(r=!0)}),this.heartbeatTimer=setTimeout(i,e)}stopHeartbeat(){this.heartbeatTimer&&=(clearTimeout(this.heartbeatTimer),null)}cleanup(){this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.stopHeartbeat()}},V=class extends _e{socket=null;messageTypeListeners=new Map;constructor(e,t={}){super(e,t)}async connect(){if(!(this.status===`connecting`||this.status===`open`))return this.updateStatus(`connecting`),this.pluginManager.emit(`websocket:connect:start`,this.url),new Promise((e,t)=>{let n=this.options.timeout??1e4,r=setTimeout(()=>{this.updateStatus(`closed`),this.socket?.close(),this.socket=null;let e=Error(`WebSocket connection timeout after ${n}ms`);this.emitError(e),t(e)},n);try{this.socket=new WebSocket(this.url,this.options.protocols),this.socket.onopen=t=>{clearTimeout(r),this.updateStatus(`open`),this.reconnectAttempt=0,this.emitOpen(t),this.options.onOpen?.(t),this.startHeartbeat(),this.pluginManager.emit(`websocket:connect:success`,this.url),e()},this.socket.onclose=e=>{clearTimeout(r),this.updateStatus(`closed`),this.emitClose(e),this.options.onClose?.(e),this.stopHeartbeat(),this.pluginManager.emit(`websocket:disconnected`,this.url,e.code,e.reason),e.code!==1e3&&!e.wasClean&&this.scheduleReconnect()},this.socket.onerror=e=>{clearTimeout(r),this.updateStatus(`closed`),this.emitError(e),this.options.onError?.(e),this.pluginManager.emit(`websocket:connect:error`,this.url,e),t(e)},this.socket.onmessage=e=>{this.stats.messagesReceived++;let t={data:this.tryParseData(e.data),raw:e.data,type:`message`,timestamp:Date.now()};this.emitMessage(t),this.pluginManager.emit(`websocket:message:received`,this.url,t)}}catch(e){clearTimeout(r),this.updateStatus(`closed`),this.pluginManager.emit(`websocket:connect:error`,this.url,e),t(e)}})}disconnect(){this.cleanup(),this.socket&&(this.updateStatus(`closing`),this.socket.close(1e3,`Client disconnected`),this.socket=null,this.updateStatus(`closed`))}send(e){if(!this.socket||this.socket.readyState!==WebSocket.OPEN)throw Error(`WebSocket is not connected`);this.socket.send(e),this.stats.messagesSent++,this.pluginManager.emit(`websocket:message:sent`,this.url,e)}sendJson(e){this.send(JSON.stringify(e))}onMessageType(e,t){return this.messageTypeListeners.has(e)||this.messageTypeListeners.set(e,new Set),this.messageTypeListeners.get(e).add(t),()=>{let n=this.messageTypeListeners.get(e);n&&(n.delete(t),n.size===0&&this.messageTypeListeners.delete(e))}}tryParseData(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return e}return e}},ve=class extends V{async connect(){if(B())try{let{default:e}=await import(`ws`);return super.connect()}catch{throw Error(`WebSocket client for Node.js requires the "ws" package. Please install it: npm install ws`)}return super.connect()}};function ye(e,t={}){return B()?new ve(e,t):new V(e,t)}function H(){return typeof window>`u`&&typeof process<`u`&&process.versions?.node!==void 0}var U=class{url;options;_source=null;pluginManager;status=`closed`;reconnectAttempt=0;reconnectTimer=null;stats={messagesSent:0,messagesReceived:0,connectionTime:0,reconnectAttempts:0};connectionStartTime=0;listeners={open:new Set,close:new Set,error:new Set,message:new Set,event:new Map};_lastEventId=null;constructor(e,t={}){this.url=e,this.options=t,this.pluginManager=new M}updateStatus(e){this.status=e,e===`open`?this.connectionStartTime=Date.now():e===`closed`&&this.connectionStartTime>0&&(this.stats.connectionTime+=Date.now()-this.connectionStartTime,this.connectionStartTime=0)}async connect(){if(!(this.status===`connecting`||this.status===`open`))return this.updateStatus(`connecting`),this.pluginManager.emit(`sse:connect:start`,this.url),new Promise((e,t)=>{let n=this.options.timeout??1e4,r=setTimeout(()=>{this.updateStatus(`closed`),this._source?.close(),this._source=null;let e=Error(`SSE connection timeout after ${n}ms`);this.emitError(e),t(e)},n);try{this._source=new EventSource(this.url),this._source.onopen=t=>{clearTimeout(r),this.updateStatus(`open`),this.reconnectAttempt=0,this.emitOpen(t),this.options.onOpen?.(t),this.pluginManager.emit(`sse:connect:success`,this.url),e()},this._source.onerror=e=>{clearTimeout(r),this.updateStatus(`closed`),this.emitError(e),this.options.onError?.(e),this.pluginManager.emit(`sse:connect:error`,this.url,e),this._source?.readyState===EventSource.CLOSED&&(this.emitClose(),this.options.onClose?.(),this.scheduleReconnect()),t(e)},this._source.onmessage=e=>{this.stats.messagesReceived++,this._lastEventId=e.lastEventId||this._lastEventId;let t={data:this.tryParseData(e.data),raw:e.data,type:e.type||`message`,timestamp:Date.now()};this.emitMessage(t),this.pluginManager.emit(`sse:message:received`,this.url,t);let n=e.type||`message`,r=this.listeners.event.get(n);if(r)for(let e of r)e(t.data)},this._source.addEventListener=this._source.addEventListener.bind(this._source)}catch(e){clearTimeout(r),this.updateStatus(`closed`),this.pluginManager.emit(`sse:connect:error`,this.url,e),t(e)}})}disconnect(){this.cleanup(),this._source&&(this.updateStatus(`closing`),this._source.close(),this._source=null,this.updateStatus(`closed`),this.emitClose(),this.options.onClose?.())}send(e){throw Error(`SSE is a receive-only protocol. Use HTTP requests to send data to server.`)}onMessage(e){return this.listeners.message.add(e),()=>this.listeners.message.delete(e)}onOpen(e){return this.listeners.open.add(e),()=>this.listeners.open.delete(e)}onClose(e){return this.listeners.close.add(e),()=>this.listeners.close.delete(e)}onError(e){return this.listeners.error.add(e),()=>this.listeners.error.delete(e)}onEvent(e,t){return this.listeners.event.has(e)||this.listeners.event.set(e,new Set),this.listeners.event.get(e).add(t),this._source&&!this._source[`on${e}`]&&this._source.addEventListener(e,n=>{t({data:this.tryParseData(n.data),raw:n.data,type:e,timestamp:Date.now()}.data)}),()=>{let n=this.listeners.event.get(e);n&&(n.delete(t),n.size===0&&this.listeners.event.delete(e))}}getStatus(){return this.status}getStats(){return{...this.stats,connectionTime:this.stats.connectionTime+(this.connectionStartTime>0?Date.now()-this.connectionStartTime:0)}}get lastEventId(){return this._lastEventId}get source(){return this._source}emitOpen(e){this.pluginManager.emit(`sse:open`,this.url,e);for(let t of this.listeners.open)t(e)}emitClose(){this.pluginManager.emit(`sse:close`,this.url);for(let e of this.listeners.close)e()}emitError(e){let t;e instanceof Error?(t=new Event(`error`),t.error=e):t=e,this.pluginManager.emit(`sse:error`,this.url,t);for(let e of this.listeners.error)e(t)}emitMessage(e){this.pluginManager.emit(`sse:message`,this.url,e);for(let t of this.listeners.message)t(e)}scheduleReconnect(){if(this.options.reconnect?.enabled===!1)return;let e=this.options.reconnect?.maxAttempts??1/0;if(this.reconnectAttempt>=e){this.pluginManager.emit(`sse:reconnect:failed`,this.url,this.reconnectAttempt);return}let t=this.options.reconnect?.baseDelay??1e3,n=this.options.reconnect?.maxDelay??3e4,r=Math.min(n,t*2**this.reconnectAttempt);this.reconnectAttempt++,this.stats.reconnectAttempts=this.reconnectAttempt,this.options.reconnect?.onReconnecting?.(this.reconnectAttempt,r),this.pluginManager.emit(`sse:reconnecting`,this.url,this.reconnectAttempt,r),this.reconnectTimer=setTimeout(()=>{this.connect().catch(e=>{this.emitError(e instanceof Error?e:Error(String(e)))})},r)}cleanup(){this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}tryParseData(e){try{return JSON.parse(e)}catch{return e}}},be=class extends U{async connect(){if(H())throw Error(`SSE client for Node.js requires a polyfill or custom implementation. Consider using a library like "eventsource" or implement using fetch with streaming.`);return super.connect()}};function xe(e,t={}){return H()?new be(e,t):new U(e,t)}var Se=class{name=`realtime`;setup(e){e.on(`websocket:connect:start`,(...t)=>{let n=t[0];e.emit(`realtime:connect:start`,`websocket`,n)}),e.on(`websocket:connect:success`,(...t)=>{let n=t[0];e.emit(`realtime:connect:success`,`websocket`,n)}),e.on(`websocket:message:received`,(...t)=>{let n=t[0],r=t[1];e.emit(`realtime:message`,`websocket`,n,r)}),e.on(`sse:connect:start`,(...t)=>{let n=t[0];e.emit(`realtime:connect:start`,`sse`,n)}),e.on(`sse:connect:success`,(...t)=>{let n=t[0];e.emit(`realtime:connect:success`,`sse`,n)}),e.on(`sse:message:received`,(...t)=>{let n=t[0],r=t[1];e.emit(`realtime:message`,`sse`,n,r)})}};function Ce(){return new Se}var W=`nexa.devOverlay.config`;function G(){try{if(typeof localStorage>`u`)return{};let e=localStorage.getItem(W);return e?JSON.parse(e):{}}catch{return{}}}function we(e){try{if(typeof localStorage>`u`)return;localStorage.setItem(W,JSON.stringify(e))}catch{}}var K=class{history=[];maxHistory;listeners=new Set;startTime=Date.now();config;constructor(e={}){this.maxHistory=e.maxHistory??500,this.config={enabled:e.enabled??!0,maxHistory:this.maxHistory,keyboardShortcut:e.keyboardShortcut??`ctrl+shift+n`,position:e.position??`bottom-right`,theme:e.theme??`dark`,devOnly:e.devOnly??!0,floatingButtonSize:e.floatingButtonSize??48,floatingButtonOffset:e.floatingButtonOffset??24,floatingButtonTheme:e.floatingButtonTheme??`inherit`,branding:e.branding??`Nexa DevTools`,icon:e.icon??`https://raw.githubusercontent.com/Berea-Soft/nexa/refs/heads/main/src/assets/faviconNew.png`}}track(e){let t={...e,id:this.generateId(),timestamp:Date.now()};this.history.unshift(t),this.history.length>this.maxHistory&&this.history.pop();for(let e of this.listeners)e(t);return t}getHistory(){return this.history}getMetrics(){let e=this.history.map(e=>e.duration),t=(Date.now()-this.startTime)/1e3;return{totalRequests:this.history.length,successfulRequests:this.history.filter(e=>e.ok).length,failedRequests:this.history.filter(e=>!e.ok).length,cachedRequests:this.history.filter(e=>e.cached).length,avgDuration:e.length?e.reduce((e,t)=>e+t,0)/e.length:0,maxDuration:e.length?Math.max(...e):0,minDuration:e.length?Math.min(...e):0,requestsPerSecond:t>0?this.history.length/t:0,slowestRequests:[...this.history].sort((e,t)=>t.duration-e.duration).slice(0,5)}}clear(){this.history=[],this.startTime=Date.now()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}getConfig(){return this.config}updateConfig(e){this.config={...this.config,...e},this.maxHistory=this.config.maxHistory;try{we(this.config)}catch{}return this.config}generateId(){return`${Date.now()}-${Math.random().toString(36).slice(2,8)}`}},q={gear:`<svg width="16" height="16" viewBox="0 0 48 48" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
2
2
  <path d="M 24 4 C 22.423103 4 20.902664 4.1994284 19.451172 4.5371094 A 1.50015 1.50015 0 0 0 18.300781 5.8359375 L 17.982422 8.7382812 C 17.878304 9.6893592 17.328913 10.530853 16.5 11.009766 C 15.672739 11.487724 14.66862 11.540667 13.792969 11.15625 L 13.791016 11.15625 L 11.125 9.9824219 A 1.50015 1.50015 0 0 0 9.4257812 10.330078 C 7.3532865 12.539588 5.7626807 15.215064 4.859375 18.201172 A 1.50015 1.50015 0 0 0 5.4082031 19.845703 L 7.7734375 21.580078 C 8.5457929 22.147918 9 23.042801 9 24 C 9 24.95771 8.5458041 25.853342 7.7734375 26.419922 L 5.4082031 28.152344 A 1.50015 1.50015 0 0 0 4.859375 29.796875 C 5.7625845 32.782665 7.3519262 35.460112 9.4257812 37.669922 A 1.50015 1.50015 0 0 0 11.125 38.015625 L 13.791016 36.841797 C 14.667094 36.456509 15.672169 36.511947 16.5 36.990234 C 17.328913 37.469147 17.878304 38.310641 17.982422 39.261719 L 18.300781 42.164062 A 1.50015 1.50015 0 0 0 19.449219 43.460938 C 20.901371 43.799844 22.423103 44 24 44 C 25.576897 44 27.097336 43.800572 28.548828 43.462891 A 1.50015 1.50015 0 0 0 29.699219 42.164062 L 30.017578 39.261719 C 30.121696 38.310641 30.671087 37.469147 31.5 36.990234 C 32.327261 36.512276 33.33138 36.45738 34.207031 36.841797 L 36.875 38.015625 A 1.50015 1.50015 0 0 0 38.574219 37.669922 C 40.646713 35.460412 42.237319 32.782983 43.140625 29.796875 A 1.50015 1.50015 0 0 0 42.591797 28.152344 L 40.226562 26.419922 C 39.454197 25.853342 39 24.95771 39 24 C 39 23.04229 39.454197 22.146658 40.226562 21.580078 L 42.591797 19.847656 A 1.50015 1.50015 0 0 0 43.140625 18.203125 C 42.237319 15.217017 40.646713 12.539588 38.574219 10.330078 A 1.50015 1.50015 0 0 0 36.875 9.984375 L 34.207031 11.158203 C 33.33138 11.54262 32.327261 11.487724 31.5 11.009766 C 30.671087 10.530853 30.121696 9.6893592 30.017578 8.7382812 L 29.699219 5.8359375 A 1.50015 1.50015 0 0 0 28.550781 4.5390625 C 27.098629 4.2001555 25.576897 4 24 4 z M 24 7 C 24.974302 7 25.90992 7.1748796 26.847656 7.3398438 L 27.035156 9.0644531 C 27.243038 10.963375 28.346913 12.652335 30 13.607422 C 31.654169 14.563134 33.668094 14.673009 35.416016 13.904297 L 37.001953 13.207031 C 38.219788 14.669402 39.183985 16.321182 39.857422 18.130859 L 38.451172 19.162109 C 36.911538 20.291529 36 22.08971 36 24 C 36 25.91029 36.911538 27.708471 38.451172 28.837891 L 39.857422 29.869141 C 39.183985 31.678818 38.219788 33.330598 37.001953 34.792969 L 35.416016 34.095703 C 33.668094 33.326991 31.654169 33.436866 30 34.392578 C 28.346913 35.347665 27.243038 37.036625 27.035156 38.935547 L 26.847656 40.660156 C 25.910002 40.82466 24.973817 41 24 41 C 23.025698 41 22.09008 40.82512 21.152344 40.660156 L 20.964844 38.935547 C 20.756962 37.036625 19.653087 35.347665 18 34.392578 C 16.345831 33.436866 14.331906 33.326991 12.583984 34.095703 L 10.998047 34.792969 C 9.7799772 33.330806 8.8159425 31.678964 8.1425781 29.869141 L 9.5488281 28.837891 C 11.088462 27.708471 12 25.91029 12 24 C 12 22.08971 11.087719 20.290363 9.5488281 19.160156 L 8.1425781 18.128906 C 8.8163325 16.318532 9.7814501 14.667839 11 13.205078 L 12.583984 13.902344 C 14.331906 14.671056 16.345831 14.563134 18 13.607422 C 19.653087 12.652335 20.756962 10.963375 20.964844 9.0644531 L 21.152344 7.3398438 C 22.089998 7.1753403 23.026183 7 24 7 z M 24 16 C 19.599487 16 16 19.59949 16 24 C 16 28.40051 19.599487 32 24 32 C 28.400513 32 32 28.40051 32 24 C 32 19.59949 28.400513 16 24 16 z M 24 19 C 26.779194 19 29 21.220808 29 24 C 29 26.779192 26.779194 29 24 29 C 21.220806 29 19 26.779192 19 24 C 19 21.220808 21.220806 19 24 19 z"></path>
3
- </svg>`,close:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6L6 18M6 6l12 12"/></svg>`,chevron:`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>`,back:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>`,retry:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 4v6h6M23 20v-6h-6"/><path d="M20.49 9A9 9 0 005.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 013.51 15"/></svg>`,clear:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/></svg>`,search:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="M21 21l-4.35-4.35"/></svg>`,clock:`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>`,zap:`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>`},J={bg:`#0b1120`,bgElevated:`#111827`,bgSurface:`#172033`,border:`#24324a`,borderFocus:`#35507a`,text:`#e5eefb`,textMuted:`#b4c4dd`,textDim:`#7f93b3`,accent:`#38bdf8`,accentHover:`#0ea5e9`,accentSoft:`rgba(56, 189, 248, 0.18)`,success:`#34d399`,successBg:`rgba(52, 211, 153, 0.16)`,error:`#fb7185`,errorBg:`rgba(251, 113, 133, 0.16)`,warning:`#fbbf24`,warningBg:`rgba(251, 191, 36, 0.16)`,info:`#a78bfa`,infoBg:`rgba(167, 139, 250, 0.16)`,get:`#34d399`,post:`#38bdf8`,put:`#fbbf24`,patch:`#a78bfa`,delete:`#fb7185`},Y=`
3
+ </svg>`,close:`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6L6 18M6 6l12 12"/></svg>`,chevron:`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>`,back:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>`,retry:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 4v6h6M23 20v-6h-6"/><path d="M20.49 9A9 9 0 005.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 013.51 15"/></svg>`,clear:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 6h18M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/></svg>`,search:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="M21 21l-4.35-4.35"/></svg>`,clock:`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>`,zap:`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>`,download:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>`,copy:`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>`},J={bg:`#0b1120`,bgElevated:`#111827`,bgSurface:`#172033`,border:`#24324a`,borderFocus:`#35507a`,text:`#e5eefb`,textMuted:`#b4c4dd`,textDim:`#7f93b3`,accent:`#38bdf8`,accentHover:`#0ea5e9`,accentSoft:`rgba(56, 189, 248, 0.18)`,success:`#34d399`,successBg:`rgba(52, 211, 153, 0.16)`,error:`#fb7185`,errorBg:`rgba(251, 113, 133, 0.16)`,warning:`#fbbf24`,warningBg:`rgba(251, 191, 36, 0.16)`,info:`#a78bfa`,infoBg:`rgba(167, 139, 250, 0.16)`,get:`#34d399`,post:`#38bdf8`,put:`#fbbf24`,patch:`#a78bfa`,delete:`#fb7185`},Y=`
4
4
  #nexa-dev-overlay * { margin: 0; padding: 0; box-sizing: border-box; }
5
5
  #nexa-dev-overlay {
6
6
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
@@ -123,6 +123,34 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
123
123
  box-shadow: 0 0 0 3px ${J.accentSoft};
124
124
  }
125
125
  #nexa-dev-overlay .nexa-search-input::placeholder { color: ${J.textDim}; }
126
+ #nexa-dev-overlay .nexa-filters {
127
+ display: flex;
128
+ gap: 6px;
129
+ padding: 12px 16px 12px 16px;
130
+ border-bottom: 1px solid ${J.border};
131
+ overflow-x: auto;
132
+ scrollbar-width: none;
133
+ min-height: 50px;
134
+ }
135
+ #nexa-dev-overlay .nexa-filters::-webkit-scrollbar { display: none; }
136
+ #nexa-dev-overlay .nexa-filter-chip {
137
+ padding: 4px 10px;
138
+ background: ${J.bgSurface};
139
+ border: 1px solid ${J.border};
140
+ border-radius: 20px;
141
+ color: ${J.textDim};
142
+ font-size: 11px;
143
+ font-weight: 600;
144
+ white-space: nowrap;
145
+ cursor: pointer;
146
+ transition: all 0.15s;
147
+ }
148
+ #nexa-dev-overlay .nexa-filter-chip:hover { border-color: ${J.borderFocus}; color: ${J.textMuted}; }
149
+ #nexa-dev-overlay .nexa-filter-chip-active {
150
+ background: ${J.accentSoft};
151
+ border-color: ${J.accent};
152
+ color: ${J.accent};
153
+ }
126
154
  #nexa-dev-overlay .nexa-tabs {
127
155
  display: flex;
128
156
  gap: 4px;
@@ -263,6 +291,10 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
263
291
  justify-content: space-between;
264
292
  margin-bottom: 16px;
265
293
  }
294
+ #nexa-dev-overlay .nexa-btn-group {
295
+ display: flex;
296
+ gap: 8px;
297
+ }
266
298
  #nexa-dev-overlay .nexa-btn {
267
299
  display: flex;
268
300
  align-items: center;
@@ -280,6 +312,8 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
280
312
  #nexa-dev-overlay .nexa-btn:hover { background: rgba(53, 80, 122, 0.24); color: ${J.text}; }
281
313
  #nexa-dev-overlay .nexa-btn-retry { background: ${J.successBg}; border-color: transparent; color: ${J.success}; }
282
314
  #nexa-dev-overlay .nexa-btn-retry:hover { background: ${J.success}; color: #052e26; }
315
+ #nexa-dev-overlay .nexa-btn-copy { background: ${J.accentSoft}; border-color: transparent; color: ${J.accent}; }
316
+ #nexa-dev-overlay .nexa-btn-copy:hover { background: ${J.accent}; color: #ffffff; }
283
317
  #nexa-dev-overlay .nexa-card {
284
318
  background: ${J.bgSurface};
285
319
  border: 1px solid ${J.border};
@@ -295,6 +329,28 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
295
329
  letter-spacing: 0.05em;
296
330
  margin-bottom: 12px;
297
331
  }
332
+ #nexa-dev-overlay .nexa-notification {
333
+ position: absolute;
334
+ bottom: 24px;
335
+ left: 50%;
336
+ transform: translateX(-50%) translateY(20px);
337
+ background: ${J.bgElevated};
338
+ color: ${J.text};
339
+ padding: 10px 18px;
340
+ border-radius: 12px;
341
+ border: 1px solid ${J.borderFocus};
342
+ font-size: 13px;
343
+ font-weight: 500;
344
+ box-shadow: 0 12px 32px rgba(0,0,0,0.4);
345
+ z-index: 2147483651;
346
+ opacity: 0;
347
+ pointer-events: none;
348
+ transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
349
+ }
350
+ #nexa-dev-overlay .nexa-notification-show {
351
+ opacity: 1;
352
+ transform: translateX(-50%) translateY(0);
353
+ }
298
354
  #nexa-dev-overlay .nexa-row {
299
355
  display: flex;
300
356
  justify-content: space-between;
@@ -331,7 +387,6 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
331
387
  flex-direction: column;
332
388
  gap: 12px;
333
389
  }
334
- /* Settings modal (overlays the content area without shifting layout) */
335
390
  #nexa-dev-overlay .nexa-settings-panel {
336
391
  position: absolute;
337
392
  top: 72px;
@@ -371,7 +426,8 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
371
426
  #nexa-dev-overlay.nexa-theme-light .nexa-request-item,
372
427
  #nexa-dev-overlay.nexa-theme-light .nexa-btn,
373
428
  #nexa-dev-overlay.nexa-theme-light .nexa-card,
374
- #nexa-dev-overlay.nexa-theme-light .nexa-settings-panel {
429
+ #nexa-dev-overlay.nexa-theme-light .nexa-settings-panel,
430
+ #nexa-dev-overlay.nexa-theme-light .nexa-notification {
375
431
  background: #ffffff;
376
432
  border-color: #d8e4f2;
377
433
  }
@@ -391,9 +447,14 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
391
447
  #nexa-dev-overlay.nexa-theme-light .nexa-empty,
392
448
  #nexa-dev-overlay.nexa-theme-light .nexa-empty span,
393
449
  #nexa-dev-overlay.nexa-theme-light .nexa-row span,
394
- #nexa-dev-overlay.nexa-theme-light .nexa-settings-row label {
450
+ #nexa-dev-overlay.nexa-theme-light .nexa-settings-row label,
451
+ #nexa-dev-overlay.nexa-theme-light .nexa-notification {
395
452
  color: #64748b;
396
453
  }
454
+ #nexa-dev-overlay.nexa-theme-light .nexa-notification {
455
+ box-shadow: 0 12px 32px rgba(15,23,42,0.12);
456
+ border-color: #e2e8f0;
457
+ }
397
458
  #nexa-dev-overlay.nexa-theme-light .nexa-url,
398
459
  #nexa-dev-overlay.nexa-theme-light .nexa-empty p,
399
460
  #nexa-dev-overlay.nexa-theme-light .nexa-icon-btn,
@@ -436,7 +497,14 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
436
497
  align-items: center;
437
498
  gap: 8px;
438
499
  }
439
- `;function X(){try{if(typeof process<`u`){let e=process;if(e.env&&typeof e.env.NODE_ENV==`string`)return e.env.NODE_ENV===`development`}}catch{}try{if(typeof location<`u`&&location.hostname){let e=location.hostname;if(e===`localhost`||e===`127.0.0.1`||e===`0.0.0.0`)return!0}}catch{}return!1}var Te=class{panel=null;floatingIcon=null;tracker;visible=!1;selectedRequest=null;config;searchQuery=``;removeTrackerListener=null;keyboardShortcutHandler=null;globalKeyboardHandler=null;constructor(e){this.tracker=e,this.config=e.getConfig(),this.canUseDOM()&&(this.setupKeyboardShortcut(),this.createPanel())}show(){this.panel&&(this.panel.style.display=`flex`,this.panel.style.opacity=`0`,this.panel.style.transform=`scale(0.96) translateY(8px)`,(typeof requestAnimationFrame==`function`?requestAnimationFrame:e=>setTimeout(e,0))(()=>{this.panel.style.transition=`all 0.25s cubic-bezier(0.16, 1, 0.3, 1)`,this.panel.style.opacity=`1`,this.panel.style.transform=`scale(1) translateY(0)`}),this.visible=!0,this.hideFloatingIcon())}hide(){this.panel&&(this.panel.style.transition=`all 0.15s ease-out`,this.panel.style.opacity=`0`,this.panel.style.transform=`scale(0.96) translateY(8px)`,setTimeout(()=>{this.panel&&(this.panel.style.display=`none`)},150),this.visible=!1,this.config.enabled&&(!this.config.devOnly||X())&&this.showFloatingIcon())}toggle(){this.visible?this.hide():this.show()}destroy(){this.keyboardShortcutHandler&&=(document.removeEventListener(`keydown`,this.keyboardShortcutHandler),null),this.globalKeyboardHandler&&=(document.removeEventListener(`keydown`,this.globalKeyboardHandler),null),this.removeTrackerListener?.(),this.removeTrackerListener=null,this.panel?.remove(),this.panel=null,this.visible=!1,this.selectedRequest=null,this.floatingIcon&&=(this.floatingIcon.remove(),null)}setupKeyboardShortcut(){let e=this.config.keyboardShortcut.split(`+`),t=new Set(e.map(e=>e.toLowerCase()));this.keyboardShortcutHandler=e=>{let n=new Set;e.ctrlKey&&n.add(`ctrl`),e.metaKey&&(n.add(`meta`),n.add(`cmd`),n.add(`ctrl`)),e.shiftKey&&n.add(`shift`),e.altKey&&n.add(`alt`),(e.key&&e.key.length===1||e.key.length>1)&&n.add(e.key.toLowerCase());let r=!0;for(let e of t)if(!n.has(e)){r=!1;break}r&&n.size===t.size&&(e.preventDefault(),this.toggle())},document.addEventListener(`keydown`,this.keyboardShortcutHandler)}createPanel(){if(!this.canUseDOM())return;try{let e=document.getElementById(`nexa-dev-overlay`);e&&e.remove()}catch{}this.panel=document.createElement(`div`),this.panel.id=`nexa-dev-overlay`;let e=this.config.position,t=e.includes(`bottom`),n=e.includes(`right`),r=`${this.config.floatingButtonOffset??24}px`;this.panel.style.cssText=`
500
+ #nexa-dev-overlay.nexa-view-detail .nexa-metrics-bar,
501
+ #nexa-dev-overlay.nexa-view-detail .nexa-search,
502
+ #nexa-dev-overlay.nexa-view-detail .nexa-filters,
503
+ #nexa-dev-overlay.nexa-view-detail .nexa-tabs,
504
+ #nexa-dev-overlay.nexa-view-detail .nexa-body {
505
+ display: none !important;
506
+ }
507
+ `;function X(){try{if(typeof process<`u`){let e=process;if(e.env&&typeof e.env.NODE_ENV==`string`)return e.env.NODE_ENV===`development`}}catch{}try{if(typeof location<`u`&&location.hostname){let e=location.hostname;if(e===`localhost`||e===`127.0.0.1`||e===`0.0.0.0`)return!0}}catch{}return!1}var Te=class{panel=null;floatingIcon=null;tracker;visible=!1;selectedRequest=null;config;searchQuery=``;filterType=`all`;removeTrackerListener=null;keyboardShortcutHandler=null;globalKeyboardHandler=null;constructor(e){this.tracker=e,this.config=e.getConfig(),this.canUseDOM()&&(this.setupKeyboardShortcut(),this.createPanel())}show(){this.panel&&(this.panel.style.display=`flex`,this.panel.style.opacity=`0`,this.panel.style.transform=`scale(0.96) translateY(8px)`,(typeof requestAnimationFrame==`function`?requestAnimationFrame:e=>setTimeout(e,0))(()=>{this.panel.style.transition=`all 0.25s cubic-bezier(0.16, 1, 0.3, 1)`,this.panel.style.opacity=`1`,this.panel.style.transform=`scale(1) translateY(0)`}),this.visible=!0,this.hideFloatingIcon())}hide(){this.panel&&(this.panel.style.transition=`all 0.15s ease-out`,this.panel.style.opacity=`0`,this.panel.style.transform=`scale(0.96) translateY(8px)`,setTimeout(()=>{this.panel&&(this.panel.style.display=`none`)},150),this.visible=!1,this.config.enabled&&(!this.config.devOnly||X())&&this.showFloatingIcon())}toggle(){this.visible?this.hide():this.show()}destroy(){this.keyboardShortcutHandler&&=(document.removeEventListener(`keydown`,this.keyboardShortcutHandler),null),this.globalKeyboardHandler&&=(document.removeEventListener(`keydown`,this.globalKeyboardHandler),null),this.removeTrackerListener?.(),this.removeTrackerListener=null,this.panel?.remove(),this.panel=null,this.visible=!1,this.selectedRequest=null,this.floatingIcon&&=(this.floatingIcon.remove(),null)}setupKeyboardShortcut(){let e=this.config.keyboardShortcut.split(`+`),t=new Set(e.map(e=>e.toLowerCase()));this.keyboardShortcutHandler=e=>{let n=new Set;e.ctrlKey&&n.add(`ctrl`),e.metaKey&&(n.add(`meta`),n.add(`cmd`),n.add(`ctrl`)),e.shiftKey&&n.add(`shift`),e.altKey&&n.add(`alt`),(e.key&&e.key.length===1||e.key.length>1)&&n.add(e.key.toLowerCase());let r=!0;for(let e of t)if(!n.has(e)){r=!1;break}r&&n.size===t.size&&(e.preventDefault(),this.toggle())},document.addEventListener(`keydown`,this.keyboardShortcutHandler)}createPanel(){if(!this.canUseDOM())return;try{let e=document.getElementById(`nexa-dev-overlay`);e&&e.remove()}catch{}this.panel=document.createElement(`div`),this.panel.id=`nexa-dev-overlay`;let e=this.config.position,t=e.includes(`bottom`),n=e.includes(`right`),r=`${this.config.floatingButtonOffset??24}px`,i=this.config.branding||`Nexa DevTools`,a=this.config.icon||`https://raw.githubusercontent.com/Berea-Soft/nexa/refs/heads/main/src/assets/faviconNew.png`;this.panel.style.cssText=`
440
508
  position: fixed;
441
509
  ${t?`bottom: ${r};`:`top: ${r};`}
442
510
  ${n?`right: ${r};`:`left: ${r};`}
@@ -451,17 +519,20 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
451
519
  <div class="nexa-header">
452
520
  <div class="nexa-header-left">
453
521
  <div class="nexa-logo">
454
- <img src="https://raw.githubusercontent.com/Berea-Soft/nexa/refs/heads/main/src/assets/faviconNew.png" alt="Nexa" style="width:100%;height:auto;object-fit:cover;border-radius:8px;display:block;" />
522
+ <img src="${a}" alt="${i}" style="width:100%;height:auto;object-fit:cover;border-radius:8px;display:block;" />
455
523
  </div>
456
- <span class="nexa-title">Nexa DevTools</span>
524
+ <span class="nexa-title">${i}</span>
457
525
  </div>
458
526
  <div class="nexa-header-actions">
459
- <button class="nexa-icon-btn nexa-btn-settings" title="Settings">${q.gear}</button>
527
+ <button class="nexa-icon-btn nexa-btn-export" title="Export history (JSON)">${q.download}</button>
528
+ <button class="nexa-icon-btn nexa-btn-settings" title="Settings">${q.gear}</button>
460
529
  <button class="nexa-icon-btn nexa-btn-clear" title="Clear history">${q.clear}</button>
461
530
  <button class="nexa-icon-btn nexa-btn-close" title="Close (Esc)">${q.close}</button>
462
531
  </div>
463
532
  </div>
464
533
 
534
+ <div class="nexa-notification"></div>
535
+
465
536
  <div class="nexa-settings-panel" style="display:none">
466
537
  <div class="nexa-settings-row">
467
538
  <label for="nexa-pos">Position</label>
@@ -498,6 +569,13 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
498
569
  <input type="text" class="nexa-search-input" placeholder="Filter by URL, method, or status..." />
499
570
  </div>
500
571
 
572
+ <div class="nexa-filters">
573
+ <div class="nexa-filter-chip nexa-filter-chip-active" data-filter="all">All</div>
574
+ <div class="nexa-filter-chip" data-filter="err">Errors</div>
575
+ <div class="nexa-filter-chip" data-filter="xhr">JSON</div>
576
+ <div class="nexa-filter-chip" data-filter="slow">Slow</div>
577
+ </div>
578
+
501
579
  <div class="nexa-tabs">
502
580
  <button class="nexa-tab nexa-tab-active" data-tab="requests"><span>Requests</span><span class="nexa-tab-count" data-count="requests">0</span></button>
503
581
  <button class="nexa-tab" data-tab="metrics"><span>Metrics</span></button>
@@ -511,11 +589,14 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
511
589
  <div class="nexa-detail" style="display:none">
512
590
  <div class="nexa-detail-header">
513
591
  <button class="nexa-btn nexa-btn-back">${q.back} Back</button>
514
- <button class="nexa-btn nexa-btn-retry">${q.retry} Retry</button>
592
+ <div class="nexa-btn-group">
593
+ <button class="nexa-btn nexa-btn-copy">${q.copy} Copy as fetch</button>
594
+ <button class="nexa-btn nexa-btn-retry">${q.retry} Retry</button>
595
+ </div>
515
596
  </div>
516
597
  <div class="nexa-detail-body"></div>
517
598
  </div>
518
- `,document.body.appendChild(this.panel),this.config.theme===`light`?this.panel.classList.add(`nexa-theme-light`):this.panel.classList.remove(`nexa-theme-light`),this.bindEvents(),this.removeTrackerListener=this.tracker.onChange(()=>this.render());let i=!this.config.devOnly||X();this.config.enabled&&i&&this.createFloatingIcon(),this.hide(),this.globalKeyboardHandler=e=>{if(e.key===`Escape`&&this.visible){this.hide();return}if(this.visible&&(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`f`){e.preventDefault();let t=this.panel?.querySelector(`.nexa-search-input`);t?.focus(),t?.select()}},document.addEventListener(`keydown`,this.globalKeyboardHandler)}bindEvents(){this.panel&&(this.panel.querySelector(`.nexa-btn-close`)?.addEventListener(`click`,()=>this.hide()),this.panel.querySelector(`.nexa-btn-clear`)?.addEventListener(`click`,()=>{this.tracker.clear(),this.render()}),this.panel.querySelector(`.nexa-btn-back`)?.addEventListener(`click`,()=>this.showMainView()),this.panel.querySelector(`.nexa-btn-retry`)?.addEventListener(`click`,()=>this.retrySelected()),this.panel.querySelector(`.nexa-search-input`)?.addEventListener(`input`,e=>{this.searchQuery=e.target.value.toLowerCase(),this.renderRequestList()}),this.panel.querySelectorAll(`.nexa-tab`).forEach(e=>{e.addEventListener(`click`,()=>{this.panel.querySelectorAll(`.nexa-tab`).forEach(e=>e.classList.remove(`nexa-tab-active`)),this.panel.querySelectorAll(`.nexa-panel`).forEach(e=>e.classList.remove(`nexa-panel-active`)),e.classList.add(`nexa-tab-active`),this.panel.querySelector(`[data-panel="${e.dataset.tab}"]`)?.classList.add(`nexa-panel-active`),e.dataset.tab===`metrics`&&this.renderMetrics()})}),this.panel.querySelector(`.nexa-btn-settings`)?.addEventListener(`click`,()=>{let e=this.panel.querySelector(`.nexa-settings-panel`);if(!e)return;let t=this.panel.querySelector(`[data-setting="position"]`),n=this.panel.querySelector(`[data-setting="theme"]`),r=e.style.display===`flex`;e.style.display=r?`none`:`flex`,r||(this.hideFloatingIcon(),t&&(t.value=this.config.position),n&&(n.value=this.config.theme),t?.focus())}),this.panel.querySelector(`.nexa-btn-save`)?.addEventListener(`click`,()=>{let e=this.panel.querySelector(`[data-setting="position"]`),t=this.panel.querySelector(`[data-setting="theme"]`),n=e?.value,r=t?.value,i={};n!==void 0&&(i.position=n),r!==void 0&&(i.theme=r);let a=this.tracker.updateConfig(i);this.applyConfigToUI(a);let o=this.panel.querySelector(`.nexa-settings-panel`);o&&(o.style.display=`none`)}),this.panel.querySelector(`.nexa-btn-cancel`)?.addEventListener(`click`,()=>{let e=this.panel.querySelector(`.nexa-settings-panel`);e&&(e.style.display=`none`)}))}render(){!this.panel||!this.visible||(this.renderMetricsBar(),this.renderRequestList())}renderMetricsBar(){let e=this.tracker.getMetrics(),t=this.panel;t&&(t.querySelector(`[data-metric="total"]`).textContent=String(e.totalRequests),t.querySelector(`[data-metric="avg"]`).textContent=`${e.avgDuration.toFixed(0)}ms`,t.querySelector(`[data-metric="rate"]`).textContent=`${e.requestsPerSecond.toFixed(1)}`,t.querySelector(`[data-metric="success"]`).textContent=String(e.successfulRequests),t.querySelector(`[data-metric="fail"]`).textContent=String(e.failedRequests),t.querySelector(`[data-count="requests"]`).textContent=String(e.totalRequests))}renderRequestList(){let e=this.panel?.querySelector(`.nexa-request-list`);if(!e)return;let t=this.tracker.getHistory();if(this.searchQuery&&(t=t.filter(e=>e.url.toLowerCase().includes(this.searchQuery)||e.method.toLowerCase().includes(this.searchQuery)||String(e.status).includes(this.searchQuery))),t.length===0){e.innerHTML=`
599
+ `,document.body.appendChild(this.panel),this.config.theme===`light`?this.panel.classList.add(`nexa-theme-light`):this.panel.classList.remove(`nexa-theme-light`),this.bindEvents(),this.removeTrackerListener=this.tracker.onChange(()=>this.render());let o=!this.config.devOnly||X();this.config.enabled&&o&&this.createFloatingIcon(),this.updateHeaderActionsVisibility(),this.hide(),this.globalKeyboardHandler=e=>{if(e.key===`Escape`&&this.visible){this.hide();return}if(this.visible&&(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`f`){e.preventDefault();let t=this.panel?.querySelector(`.nexa-search-input`);t?.focus(),t?.select()}},document.addEventListener(`keydown`,this.globalKeyboardHandler)}bindEvents(){this.panel&&(this.panel.querySelector(`.nexa-btn-close`)?.addEventListener(`click`,()=>this.hide()),this.panel.querySelector(`.nexa-btn-export`)?.addEventListener(`click`,()=>this.exportHistory()),this.panel.querySelector(`.nexa-btn-copy`)?.addEventListener(`click`,()=>this.copyAsFetch()),this.panel.querySelector(`.nexa-btn-clear`)?.addEventListener(`click`,()=>{this.tracker.clear(),this.render()}),this.panel.querySelector(`.nexa-btn-back`)?.addEventListener(`click`,()=>this.showMainView()),this.panel.querySelector(`.nexa-btn-retry`)?.addEventListener(`click`,()=>this.retrySelected()),this.panel.querySelector(`.nexa-search-input`)?.addEventListener(`input`,e=>{this.searchQuery=e.target.value.toLowerCase(),this.renderRequestList()}),this.panel.querySelectorAll(`.nexa-filter-chip`).forEach(e=>{e.addEventListener(`click`,()=>{this.panel.querySelectorAll(`.nexa-filter-chip`).forEach(e=>e.classList.remove(`nexa-filter-chip-active`)),e.classList.add(`nexa-filter-chip-active`),this.filterType=e.dataset.filter,this.renderRequestList()})}),this.panel.querySelectorAll(`.nexa-tab`).forEach(e=>{e.addEventListener(`click`,()=>{this.panel.querySelectorAll(`.nexa-tab`).forEach(e=>e.classList.remove(`nexa-tab-active`)),this.panel.querySelectorAll(`.nexa-panel`).forEach(e=>e.classList.remove(`nexa-panel-active`)),e.classList.add(`nexa-tab-active`),this.panel.querySelector(`[data-panel="${e.dataset.tab}"]`)?.classList.add(`nexa-panel-active`),e.dataset.tab===`metrics`&&this.renderMetrics()})}),this.panel.querySelector(`.nexa-btn-settings`)?.addEventListener(`click`,()=>{let e=this.panel.querySelector(`.nexa-settings-panel`);if(!e)return;let t=this.panel.querySelector(`[data-setting="position"]`),n=this.panel.querySelector(`[data-setting="theme"]`),r=e.style.display===`flex`;e.style.display=r?`none`:`flex`,r||(this.hideFloatingIcon(),t&&(t.value=this.config.position),n&&(n.value=this.config.theme),t?.focus())}),this.panel.querySelector(`.nexa-btn-save`)?.addEventListener(`click`,()=>{let e=this.panel.querySelector(`[data-setting="position"]`),t=this.panel.querySelector(`[data-setting="theme"]`),n=e?.value,r=t?.value,i={};n!==void 0&&(i.position=n),r!==void 0&&(i.theme=r);let a=this.tracker.updateConfig(i);this.applyConfigToUI(a);let o=this.panel.querySelector(`.nexa-settings-panel`);o&&(o.style.display=`none`)}),this.panel.querySelector(`.nexa-btn-cancel`)?.addEventListener(`click`,()=>{let e=this.panel.querySelector(`.nexa-settings-panel`);e&&(e.style.display=`none`)}))}render(){!this.panel||!this.visible||(this.renderMetricsBar(),this.renderRequestList())}renderMetricsBar(){let e=this.tracker.getMetrics(),t=this.panel;t&&(t.querySelector(`[data-metric="total"]`).textContent=String(e.totalRequests),t.querySelector(`[data-metric="avg"]`).textContent=`${e.avgDuration.toFixed(0)}ms`,t.querySelector(`[data-metric="rate"]`).textContent=`${e.requestsPerSecond.toFixed(1)}`,t.querySelector(`[data-metric="success"]`).textContent=String(e.successfulRequests),t.querySelector(`[data-metric="fail"]`).textContent=String(e.failedRequests),t.querySelector(`[data-count="requests"]`).textContent=String(e.totalRequests),this.updateHeaderActionsVisibility())}updateHeaderActionsVisibility(){let e=this.tracker.getHistory().length>0,t=this.panel?.querySelector(`.nexa-btn-export`),n=this.panel?.querySelector(`.nexa-btn-clear`);t&&(t.style.display=e?`flex`:`none`),n&&(n.style.display=e?`flex`:`none`)}renderRequestList(){let e=this.panel?.querySelector(`.nexa-request-list`);if(!e)return;let t=this.tracker.getHistory();if(this.filterType===`err`?t=t.filter(e=>!e.ok):this.filterType===`xhr`?t=t.filter(e=>e.headers[`content-type`]&&e.headers[`content-type`].includes(`json`)||e.responseHeaders&&e.responseHeaders[`content-type`]&&e.responseHeaders[`content-type`].includes(`json`)):this.filterType===`slow`&&(t=t.filter(e=>e.duration>500)),this.searchQuery&&(t=t.filter(e=>e.url.toLowerCase().includes(this.searchQuery)||e.method.toLowerCase().includes(this.searchQuery)||String(e.status).includes(this.searchQuery))),t.length===0){e.innerHTML=`
519
600
  <div class="nexa-empty">
520
601
  <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
521
602
  <circle cx="12" cy="12" r="10"/><path d="M8 12h8M12 8v8"/>
@@ -562,7 +643,7 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
562
643
  </div>
563
644
  `).join(``)}
564
645
  </div>
565
- `:``}`}showDetail(e){this.selectedRequest=e;let t=this.panel?.querySelector(`.nexa-body`),n=this.panel?.querySelector(`.nexa-detail`),r=this.panel?.querySelector(`.nexa-detail-body`);!t||!n||!r||(t.style.display=`none`,n.style.display=`flex`,r.innerHTML=`
646
+ `:``}`}showDetail(e){if(this.selectedRequest=e,!this.panel)return;let t=this.panel.querySelector(`.nexa-body`),n=this.panel.querySelector(`.nexa-detail`),r=this.panel.querySelector(`.nexa-detail-body`);!t||!n||!r||(this.panel.classList.add(`nexa-view-detail`),t.style.display=`none`,n.style.display=`flex`,r.innerHTML=`
566
647
  <div class="nexa-card">
567
648
  <h3>Request</h3>
568
649
  <div class="nexa-row"><span>Method</span><strong style="color:${e.method===`GET`?J.get:e.method===`POST`?J.post:e.method===`DELETE`?J.delete:J.warning}">${e.method}</strong></div>
@@ -584,7 +665,9 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
584
665
  <h3>Headers</h3>
585
666
  <pre class="nexa-code">${this.formatJson(e.headers)}</pre>
586
667
  </div>
587
- `:``}`)}showMainView(){let e=this.panel?.querySelector(`.nexa-body`),t=this.panel?.querySelector(`.nexa-detail`);e&&(e.style.display=`flex`),t&&(t.style.display=`none`),this.selectedRequest=null}retrySelected(){if(!this.selectedRequest)return;let{method:e,url:t,body:n,headers:r}=this.selectedRequest;fetch(t,{method:e,headers:r,body:n?JSON.stringify(n):void 0}).then(async e=>{this.selectedRequest&&(this.selectedRequest={...this.selectedRequest,status:e.status,ok:e.ok,duration:this.selectedRequest.duration,timestamp:Date.now()},this.showDetail(this.selectedRequest))}).catch(()=>{})}truncateUrl(e,t=35){try{let t=new URL(e);return t.pathname+(t.search||``)}catch{return e.length>t?e.slice(0,t)+`...`:e}}formatJson(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}canUseDOM(){return typeof document<`u`&&typeof document.createElement==`function`&&!!document.body}createFloatingIcon(){if(!this.canUseDOM())return;try{let e=document.getElementById(`nexa-dev-overlay-floating`);e&&e.remove()}catch{}this.floatingIcon&&=(this.floatingIcon.remove(),null);let e=document.createElement(`button`);e.id=`nexa-dev-overlay-floating`,e.title=`Toggle Nexa DevTools`;let t=this.config.floatingButtonSize??48,n=this.config.floatingButtonOffset??24,r=this.config.position||`bottom-right`,i=r.includes(`bottom`),a=r.includes(`right`),o=`${i?`bottom: ${n}px;`:`top: ${n}px;`} ${a?`right: ${n}px;`:`left: ${n}px;`}`,s=this.config.floatingButtonTheme===`inherit`?this.config.theme:this.config.floatingButtonTheme,c=`linear-gradient(135deg,#0ea5e9,#8b5cf6)`,l=`#ffffff`,u=`0 16px 36px rgba(2,6,23,0.34)`,d=`none`;s===`light`&&(c=`linear-gradient(135deg,#f8fbff,#e0f2fe)`,l=`#0f172a`,u=`0 14px 30px rgba(15,23,42,0.16)`,d=`1px solid #d8e4f2`),e.style.cssText=`
668
+ `:``}`)}showMainView(){this.panel&&this.panel.classList.remove(`nexa-view-detail`);let e=this.panel?.querySelector(`.nexa-body`),t=this.panel?.querySelector(`.nexa-detail`);e&&(e.style.display=`flex`),t&&(t.style.display=`none`),this.selectedRequest=null}retrySelected(){if(!this.selectedRequest)return;let{method:e,url:t,body:n,headers:r}=this.selectedRequest;fetch(t,{method:e,headers:r,body:n?JSON.stringify(n):void 0}).then(async e=>{this.selectedRequest&&(this.selectedRequest={...this.selectedRequest,status:e.status,ok:e.ok,duration:this.selectedRequest.duration,timestamp:Date.now()},this.showDetail(this.selectedRequest))}).catch(()=>{})}exportHistory(){let e=this.tracker.getHistory(),t=JSON.stringify(e,null,2),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`nexa-history-${new Date().toISOString().slice(0,19).replace(/[:]/g,`-`)}.json`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r),this.showNotification(`History exported as JSON`)}copyAsFetch(){if(!this.selectedRequest)return;let e=this.selectedRequest,t={...e.headers};delete t.host;let n=`fetch("${e.url}", {\n`;n+=` "method": "${e.method}",\n`,Object.keys(t).length>0&&(n+=` "headers": ${JSON.stringify(t,null,4).replace(/\n/g,`
669
+ `)},\n`),e.body&&(n+=` "body": ${JSON.stringify(e.body,null,4).replace(/\n/g,`
670
+ `)},\n`),n+=`});`,navigator.clipboard.writeText(n).then(()=>{this.showNotification(`Copied as fetch to clipboard`)}).catch(()=>{this.showNotification(`Failed to copy to clipboard`)})}showNotification(e){let t=this.panel?.querySelector(`.nexa-notification`);t&&(t.textContent=e,t.classList.add(`nexa-notification-show`),setTimeout(()=>{t.classList.remove(`nexa-notification-show`)},2500))}truncateUrl(e,t=35){try{let t=new URL(e);return t.pathname+(t.search||``)}catch{return e.length>t?e.slice(0,t)+`...`:e}}formatJson(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}canUseDOM(){return typeof document<`u`&&typeof document.createElement==`function`&&!!document.body}createFloatingIcon(){if(!this.canUseDOM())return;try{let e=document.getElementById(`nexa-dev-overlay-floating`);e&&e.remove()}catch{}this.floatingIcon&&=(this.floatingIcon.remove(),null);let e=document.createElement(`button`);e.id=`nexa-dev-overlay-floating`,e.title=`Toggle Nexa DevTools`;let t=this.config.floatingButtonSize??48,n=this.config.floatingButtonOffset??24,r=this.config.position||`bottom-right`,i=r.includes(`bottom`),a=r.includes(`right`),o=`${i?`bottom: ${n}px;`:`top: ${n}px;`} ${a?`right: ${n}px;`:`left: ${n}px;`}`,s=this.config.floatingButtonTheme===`inherit`?this.config.theme:this.config.floatingButtonTheme,c=`linear-gradient(135deg,#0ea5e9,#8b5cf6)`,l=`#ffffff`,u=`0 16px 36px rgba(2,6,23,0.34)`,d=`none`;s===`light`&&(c=`linear-gradient(135deg,#f8fbff,#e0f2fe)`,l=`#0f172a`,u=`0 14px 30px rgba(15,23,42,0.16)`,d=`1px solid #d8e4f2`);let f=this.config.branding||`Nexa DevTools`,p=this.config.icon||`https://raw.githubusercontent.com/Berea-Soft/nexa/refs/heads/main/src/assets/faviconNew.png`;e.style.cssText=`
588
671
  position: fixed;
589
672
  ${o}
590
673
  width: ${t}px;
@@ -601,5 +684,5 @@ var Nexa=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`
601
684
  color: ${l};
602
685
  font-weight: 700;
603
686
  font-size: ${Math.max(12,Math.floor(t/3))}px;
604
- `,e.innerHTML=`<img src="https://raw.githubusercontent.com/Berea-Soft/nexa/refs/heads/main/src/assets/faviconNew.png" alt="Nexa" style="width:${t-10}px;height:auto;object-fit:cover;border-radius:999px;display:block;" />`,e.addEventListener(`click`,e=>{e.stopPropagation(),this.toggle()}),e.addEventListener(`mousedown`,e=>e.preventDefault()),document.body.appendChild(e),e.style.display=this.visible?`none`:`flex`,this.floatingIcon=e}showFloatingIcon(){if(!this.floatingIcon){this.config.enabled&&this.createFloatingIcon();return}this.floatingIcon.style.display=`flex`}hideFloatingIcon(){this.floatingIcon&&(this.floatingIcon.style.display=`none`)}applyConfigToUI(e){this.config=e??this.tracker.getConfig();let t=this.config.position,n=t.includes(`bottom`),r=t.includes(`right`),i=`${this.config.floatingButtonOffset??24}px`;this.panel&&(this.panel.style.bottom=n?i:``,this.panel.style.top=n?``:i,this.panel.style.right=r?i:``,this.panel.style.left=r?``:i,this.config.theme===`light`?this.panel.classList.add(`nexa-theme-light`):this.panel.classList.remove(`nexa-theme-light`)),this.floatingIcon&&=(this.floatingIcon.remove(),null),this.config.enabled&&(!this.config.devOnly||X())&&this.createFloatingIcon()}refreshConfig(e){this.applyConfigToUI(e)}},Z=null,Q=null,$={enabled:!0,maxHistory:500,keyboardShortcut:`ctrl+shift+n`,position:`bottom-right`,theme:`dark`,devOnly:!0,floatingButtonSize:48,floatingButtonOffset:24,floatingButtonTheme:`inherit`};function Ee(e={}){if(Z&&Q){let t=G(),n={...$,...e,...t},r=Q.updateConfig(n);try{Z.refreshConfig(r)}catch{}return{tracker:Q,ui:Z,config:r}}let t=G();return Q=new K({...$,...e,...t}),Z=new Te(Q),{tracker:Q,ui:Z,config:Q.getConfig()}}function De(){return{tracker:Q,ui:Z}}function Oe(){Z?.destroy(),Z=null,Q=null}return e.AggressiveRetry=f,e.CachePlugin=pe,e.CacheStore=y,e.CircuitBreakerRetry=ee,e.ConservativeRetry=p,e.DedupePlugin=me,e.Defer=ce,e.Err=n,e.HttpClient=R,e.HttpError=z,e.LoggerPlugin=de,e.MetricsPlugin=fe,e.MiddlewarePipeline=w,e.Ok=t,e.PluginManager=M,e.RequestDeduplicator=x,e.RequestTracker=K,e.TypedObservable=ae,e.cacheMiddleware=re,e.createApiUrl=se,e.createCacheMiddleware=b,e.createDedupeMiddleware=S,e.createDevOverlay=Ee,e.createHttpClient=ge,e.createPipeline=C,e.createProjectionTransformer=u,e.createRealtimePlugin=Ce,e.createRequiredFieldsValidator=i,e.createSSEClient=xe,e.createSchemaValidator=r,e.createStreamingMiddleware=j,e.createTypeGuard=oe,e.createTypedApiClient=D,e.createTypedRequest=E,e.createTypedResponse=T,e.createUrl=O,e.createWebSocketClient=ye,e.createWrapperTransformer=d,e.dedupeMiddleware=ie,e.destroyDevOverlay=Oe,e.getDevOverlay=De,e.handleStream=k,e.isHttpError=he,e.retry=v,e.streamToFile=le,e.streamingMiddleware=ue,e.transformCamelToSnake=c,e.transformFlatten=l,e.transformSnakeToCamel=s,e.validatorIsArray=a,e.validatorIsObject=o,e.withTimeout=ne,e})({});
687
+ `,e.innerHTML=`<img src="${p}" alt="${f}" style="width:${t-10}px;height:auto;object-fit:cover;border-radius:999px;display:block;" />`,e.addEventListener(`click`,e=>{e.stopPropagation(),this.toggle()}),e.addEventListener(`mousedown`,e=>e.preventDefault()),document.body.appendChild(e),e.style.display=this.visible?`none`:`flex`,this.floatingIcon=e}showFloatingIcon(){if(!this.floatingIcon){this.config.enabled&&this.createFloatingIcon();return}this.floatingIcon.style.display=`flex`}hideFloatingIcon(){this.floatingIcon&&(this.floatingIcon.style.display=`none`)}applyConfigToUI(e){this.config=e??this.tracker.getConfig();let t=this.config.position,n=t.includes(`bottom`),r=t.includes(`right`),i=`${this.config.floatingButtonOffset??24}px`;if(this.panel){this.panel.style.bottom=n?i:``,this.panel.style.top=n?``:i,this.panel.style.right=r?i:``,this.panel.style.left=r?``:i,this.config.theme===`light`?this.panel.classList.add(`nexa-theme-light`):this.panel.classList.remove(`nexa-theme-light`);let e=this.panel.querySelector(`.nexa-logo img`),t=this.panel.querySelector(`.nexa-title`),a=this.config.branding||`Nexa DevTools`,o=this.config.icon||`https://raw.githubusercontent.com/Berea-Soft/nexa/refs/heads/main/src/assets/faviconNew.png`;e&&(e.src=o,e.alt=a),t&&(t.textContent=a)}this.floatingIcon&&=(this.floatingIcon.remove(),null),this.config.enabled&&(!this.config.devOnly||X())&&this.createFloatingIcon()}refreshConfig(e){this.applyConfigToUI(e)}},Z=null,Q=null,$={enabled:!0,maxHistory:500,keyboardShortcut:`ctrl+shift+n`,position:`bottom-right`,theme:`dark`,devOnly:!0,floatingButtonSize:48,floatingButtonOffset:24,floatingButtonTheme:`inherit`,branding:`Nexa DevTools`,icon:`https://raw.githubusercontent.com/Berea-Soft/nexa/refs/heads/main/src/assets/faviconNew.png`};function Ee(e={}){if(Z&&Q){let t=G(),n={...$,...e,...t},r=Q.updateConfig(n);try{Z.refreshConfig(r)}catch{}return{tracker:Q,ui:Z,config:r}}let t=G();return Q=new K({...$,...e,...t}),Z=new Te(Q),{tracker:Q,ui:Z,config:Q.getConfig()}}function De(){return{tracker:Q,ui:Z}}function Oe(){Z?.destroy(),Z=null,Q=null}return e.AggressiveRetry=f,e.CachePlugin=pe,e.CacheStore=y,e.CircuitBreakerRetry=ee,e.ConservativeRetry=p,e.DedupePlugin=me,e.Defer=ce,e.Err=n,e.HttpClient=R,e.HttpError=z,e.LoggerPlugin=de,e.MetricsPlugin=fe,e.MiddlewarePipeline=w,e.Ok=t,e.PluginManager=M,e.RequestDeduplicator=x,e.RequestTracker=K,e.TypedObservable=ae,e.cacheMiddleware=re,e.createApiUrl=se,e.createCacheMiddleware=b,e.createDedupeMiddleware=S,e.createDevOverlay=Ee,e.createHttpClient=ge,e.createPipeline=C,e.createProjectionTransformer=u,e.createRealtimePlugin=Ce,e.createRequiredFieldsValidator=i,e.createSSEClient=xe,e.createSchemaValidator=r,e.createStreamingMiddleware=j,e.createTypeGuard=oe,e.createTypedApiClient=D,e.createTypedRequest=E,e.createTypedResponse=T,e.createUrl=O,e.createWebSocketClient=ye,e.createWrapperTransformer=d,e.dedupeMiddleware=ie,e.destroyDevOverlay=Oe,e.getDevOverlay=De,e.handleStream=k,e.isHttpError=he,e.retry=v,e.streamToFile=le,e.streamingMiddleware=ue,e.transformCamelToSnake=c,e.transformFlatten=l,e.transformSnakeToCamel=s,e.validatorIsArray=a,e.validatorIsObject=o,e.withTimeout=ne,e})({});
605
688
  //# sourceMappingURL=nexa.iife.js.map