@bereasoftware/nexa 1.4.0 → 1.5.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.umd.js CHANGED
@@ -1,12 +1,14 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Nexa={}))})(this,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 ae=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 w(e,t,n,r={}){return{ok:e>=200&&e<300,data:t,error:n,status:e,headers:r}}function T(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 oe(e){return{request:async(t,n,r)=>{let i=e[n];return await T(i)(t,r)}}}var se=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 E(e){return t=>{if(!e(t))throw TypeError(`Value does not match expected type`);return t}}function D(e){return e}function O(e){return D(e)}var k=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 A(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 j(r,i)}function j(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 ce(e,t){let n=await A(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 M(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=j(r,i);t.response.body=o,t.state.streaming=!0,t.state.streamedBytes=i}finally{n.releaseLock()}}}}var le=M({onProgress:(e,t)=>{if(t>0){let n=Math.round(e/t*100);console.warn(`Streaming: ${n}% (${e}/${t} bytes)`)}}}),N=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()}},P={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)})}},F=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}}},I=class{name=`cache`;ttlMs;constructor(e=6e4){this.ttlMs=e}setup(e){e.addMiddleware(b({ttlMs:this.ttlMs}))}},L=class{name=`dedupe`;setup(e){e.addMiddleware(S())}},R=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()}},z=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)}},B=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 V(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 H(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 U=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 R,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 B(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=H(e.url,e.params),i=this.buildUrl(r,e.query),{serialized:a,contentType:o}=V(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=H(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=H(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}=V(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 z(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)}},W=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 ue(e){return e instanceof W}function de(e){return new U(e)}function G(){return typeof window>`u`&&typeof process<`u`&&process.versions?.node!==void 0}var fe=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 N}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()}},K=class extends fe{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}},pe=class extends K{async connect(){if(G())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 me(e,t={}){return G()?new pe(e,t):new K(e,t)}function q(){return typeof window>`u`&&typeof process<`u`&&process.versions?.node!==void 0}var J=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 N}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}}},he=class extends J{async connect(){if(q())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 ge(e,t={}){return q()?new he(e,t):new J(e,t)}var _e=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 ve(){return new _e}var Y=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`}}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}generateId(){return`${Date.now()}-${Math.random().toString(36).slice(2,8)}`}},X={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>`},Z={bg:`#09090b`,bgElevated:`#18181b`,border:`#27272a`,borderFocus:`#3f3f46`,text:`#fafafa`,textMuted:`#a1a1aa`,textDim:`#71717a`,accent:`#3b82f6`,accentHover:`#2563eb`,success:`#22c55e`,successBg:`rgba(34, 197, 94, 0.1)`,error:`#ef4444`,errorBg:`rgba(239, 68, 68, 0.1)`,warning:`#f59e0b`,get:`#22c55e`,post:`#3b82f6`,put:`#f59e0b`,patch:`#a855f7`,delete:`#ef4444`},ye=`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Nexa={}))})(this,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">
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=`
2
4
  #nexa-dev-overlay * { margin: 0; padding: 0; box-sizing: border-box; }
3
5
  #nexa-dev-overlay {
4
6
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
5
- background: ${Z.bg};
6
- color: ${Z.text};
7
- border: 1px solid ${Z.border};
7
+ background: ${J.bg};
8
+ color: ${J.text};
9
+ border: 1px solid ${J.border};
8
10
  border-radius: 16px;
9
- box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.03);
11
+ box-shadow: 0 28px 60px -24px rgba(2, 6, 23, 0.78), 0 0 0 1px rgba(148, 163, 184, 0.08);
10
12
  overflow: hidden;
11
13
  }
12
14
  #nexa-dev-overlay .nexa-header {
@@ -14,8 +16,8 @@
14
16
  align-items: center;
15
17
  justify-content: space-between;
16
18
  padding: 16px 20px;
17
- border-bottom: 1px solid ${Z.border};
18
- background: ${Z.bgElevated};
19
+ border-bottom: 1px solid ${J.border};
20
+ background: ${J.bgElevated};
19
21
  }
20
22
  #nexa-dev-overlay .nexa-header-left {
21
23
  display: flex;
@@ -28,7 +30,7 @@
28
30
  display: flex;
29
31
  align-items: center;
30
32
  justify-content: center;
31
- background: ${Z.bgElevated};
33
+ background: linear-gradient(135deg, ${J.accentSoft}, rgba(255,255,255,0.02));
32
34
  border-radius: 8px;
33
35
  overflow: hidden;
34
36
  }
@@ -50,20 +52,20 @@
50
52
  background: transparent;
51
53
  border: none;
52
54
  border-radius: 8px;
53
- color: ${Z.textMuted};
55
+ color: ${J.textMuted};
54
56
  cursor: pointer;
55
57
  transition: all 0.15s;
56
58
  }
57
59
  #nexa-dev-overlay .nexa-icon-btn:hover {
58
- background: ${Z.border};
59
- color: ${Z.text};
60
+ background: ${J.bgSurface};
61
+ color: ${J.text};
60
62
  }
61
63
  #nexa-dev-overlay .nexa-metrics-bar {
62
64
  display: flex;
63
65
  gap: 4px;
64
66
  padding: 12px 16px;
65
- background: ${Z.bg};
66
- border-bottom: 1px solid ${Z.border};
67
+ background: ${J.bg};
68
+ border-bottom: 1px solid ${J.border};
67
69
  }
68
70
  #nexa-dev-overlay .nexa-metric {
69
71
  flex: 1;
@@ -72,30 +74,30 @@
72
74
  align-items: center;
73
75
  gap: 2px;
74
76
  padding: 8px 12px;
75
- background: ${Z.bgElevated};
77
+ background: ${J.bgSurface};
76
78
  border-radius: 10px;
77
79
  transition: all 0.2s;
78
80
  }
79
81
  #nexa-dev-overlay .nexa-metric:hover {
80
- background: ${Z.border};
82
+ background: rgba(53, 80, 122, 0.3);
81
83
  }
82
84
  #nexa-dev-overlay .nexa-metric-value {
83
85
  font-size: 18px;
84
86
  font-weight: 700;
85
87
  letter-spacing: -0.03em;
86
- color: ${Z.text};
88
+ color: ${J.text};
87
89
  }
88
- #nexa-dev-overlay .nexa-metric-ok .nexa-metric-value { color: ${Z.success}; }
89
- #nexa-dev-overlay .nexa-metric-err .nexa-metric-value { color: ${Z.error}; }
90
+ #nexa-dev-overlay .nexa-metric-ok .nexa-metric-value { color: ${J.success}; }
91
+ #nexa-dev-overlay .nexa-metric-err .nexa-metric-value { color: ${J.error}; }
90
92
  #nexa-dev-overlay .nexa-metric-label {
91
93
  font-size: 11px;
92
- color: ${Z.textDim};
94
+ color: ${J.textDim};
93
95
  text-transform: uppercase;
94
96
  letter-spacing: 0.05em;
95
97
  }
96
98
  #nexa-dev-overlay .nexa-search {
97
99
  padding: 12px 16px;
98
- border-bottom: 1px solid ${Z.border};
100
+ border-bottom: 1px solid ${J.border};
99
101
  position: relative;
100
102
  }
101
103
  #nexa-dev-overlay .nexa-search-icon {
@@ -103,29 +105,29 @@
103
105
  left: 28px;
104
106
  top: 50%;
105
107
  transform: translateY(-50%);
106
- color: ${Z.textDim};
108
+ color: ${J.textDim};
107
109
  }
108
110
  #nexa-dev-overlay .nexa-search-input {
109
111
  width: 100%;
110
112
  padding: 10px 12px 10px 38px;
111
- background: ${Z.bg};
112
- border: 1px solid ${Z.border};
113
+ background: ${J.bg};
114
+ border: 1px solid ${J.border};
113
115
  border-radius: 10px;
114
- color: ${Z.text};
116
+ color: ${J.text};
115
117
  font-size: 13px;
116
118
  outline: none;
117
119
  transition: all 0.15s;
118
120
  }
119
121
  #nexa-dev-overlay .nexa-search-input:focus {
120
- border-color: ${Z.accent};
121
- box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
122
+ border-color: ${J.accent};
123
+ box-shadow: 0 0 0 3px ${J.accentSoft};
122
124
  }
123
- #nexa-dev-overlay .nexa-search-input::placeholder { color: ${Z.textDim}; }
125
+ #nexa-dev-overlay .nexa-search-input::placeholder { color: ${J.textDim}; }
124
126
  #nexa-dev-overlay .nexa-tabs {
125
127
  display: flex;
126
128
  gap: 4px;
127
129
  padding: 8px 16px;
128
- border-bottom: 1px solid ${Z.border};
130
+ border-bottom: 1px solid ${J.border};
129
131
  }
130
132
  #nexa-dev-overlay .nexa-tab {
131
133
  display: flex;
@@ -135,18 +137,18 @@
135
137
  background: transparent;
136
138
  border: none;
137
139
  border-radius: 8px;
138
- color: ${Z.textMuted};
140
+ color: ${J.textMuted};
139
141
  font-size: 13px;
140
142
  font-weight: 500;
141
143
  cursor: pointer;
142
144
  transition: all 0.15s;
143
145
  }
144
- #nexa-dev-overlay .nexa-tab:hover { color: ${Z.text}; background: ${Z.bgElevated}; }
145
- #nexa-dev-overlay .nexa-tab-active { color: ${Z.text}; background: ${Z.accent} !important; }
146
+ #nexa-dev-overlay .nexa-tab:hover { color: ${J.text}; background: ${J.bgElevated}; }
147
+ #nexa-dev-overlay .nexa-tab-active { color: ${J.text}; background: ${J.accent} !important; }
146
148
  #nexa-dev-overlay .nexa-tab-count {
147
149
  font-size: 11px;
148
150
  padding: 2px 6px;
149
- background: rgba(255,255,255,0.1);
151
+ background: rgba(148, 163, 184, 0.14);
150
152
  border-radius: 10px;
151
153
  }
152
154
  #nexa-dev-overlay .nexa-body { flex: 1; overflow: hidden; display: flex; }
@@ -163,7 +165,7 @@
163
165
  align-items: center;
164
166
  justify-content: space-between;
165
167
  padding: 12px 14px;
166
- background: ${Z.bgElevated};
168
+ background: ${J.bgSurface};
167
169
  border: 1px solid transparent;
168
170
  border-radius: 12px;
169
171
  cursor: pointer;
@@ -173,8 +175,8 @@
173
175
  }
174
176
  @keyframes nexaFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
175
177
  #nexa-dev-overlay .nexa-request-item:hover {
176
- background: ${Z.border};
177
- border-color: ${Z.borderFocus};
178
+ background: rgba(23, 32, 51, 0.92);
179
+ border-color: ${J.borderFocus};
178
180
  transform: translateX(2px);
179
181
  }
180
182
  #nexa-dev-overlay .nexa-req-left {
@@ -190,11 +192,11 @@
190
192
  text-transform: uppercase;
191
193
  letter-spacing: 0.03em;
192
194
  }
193
- #nexa-dev-overlay .nexa-method-get { background: ${Z.successBg}; color: ${Z.get}; }
194
- #nexa-dev-overlay .nexa-method-post { background: rgba(59, 130, 246, 0.15); color: ${Z.post}; }
195
- #nexa-dev-overlay .nexa-method-put { background: rgba(245, 158, 11, 0.15); color: ${Z.put}; }
196
- #nexa-dev-overlay .nexa-method-patch { background: rgba(168, 85, 247, 0.15); color: ${Z.patch}; }
197
- #nexa-dev-overlay .nexa-method-delete { background: ${Z.errorBg}; color: ${Z.delete}; }
195
+ #nexa-dev-overlay .nexa-method-get { background: ${J.successBg}; color: ${J.get}; }
196
+ #nexa-dev-overlay .nexa-method-post { background: ${J.accentSoft}; color: ${J.post}; }
197
+ #nexa-dev-overlay .nexa-method-put { background: ${J.warningBg}; color: ${J.put}; }
198
+ #nexa-dev-overlay .nexa-method-patch { background: ${J.infoBg}; color: ${J.patch}; }
199
+ #nexa-dev-overlay .nexa-method-delete { background: ${J.errorBg}; color: ${J.delete}; }
198
200
  #nexa-dev-overlay .nexa-status {
199
201
  font-size: 12px;
200
202
  font-weight: 600;
@@ -203,11 +205,11 @@
203
205
  min-width: 36px;
204
206
  text-align: center;
205
207
  }
206
- #nexa-dev-overlay .nexa-ok { background: ${Z.successBg}; color: ${Z.success}; }
207
- #nexa-dev-overlay .nexa-err { background: ${Z.errorBg}; color: ${Z.error}; }
208
+ #nexa-dev-overlay .nexa-ok { background: ${J.successBg}; color: ${J.success}; }
209
+ #nexa-dev-overlay .nexa-err { background: ${J.errorBg}; color: ${J.error}; }
208
210
  #nexa-dev-overlay .nexa-url {
209
211
  font-size: 13px;
210
- color: ${Z.textMuted};
212
+ color: ${J.textMuted};
211
213
  max-width: 180px;
212
214
  overflow: hidden;
213
215
  text-overflow: ellipsis;
@@ -226,15 +228,15 @@
226
228
  text-transform: uppercase;
227
229
  letter-spacing: 0.03em;
228
230
  }
229
- #nexa-dev-overlay .nexa-badge-cache { background: rgba(168, 85, 247, 0.15); color: #a855f7; }
230
- #nexa-dev-overlay .nexa-badge-retry { background: rgba(245, 158, 11, 0.15); color: ${Z.warning}; }
231
+ #nexa-dev-overlay .nexa-badge-cache { background: ${J.infoBg}; color: ${J.info}; }
232
+ #nexa-dev-overlay .nexa-badge-retry { background: ${J.warningBg}; color: ${J.warning}; }
231
233
  #nexa-dev-overlay .nexa-duration {
232
234
  font-size: 12px;
233
235
  font-weight: 600;
234
- color: ${Z.textDim};
236
+ color: ${J.textDim};
235
237
  font-variant-numeric: tabular-nums;
236
238
  }
237
- #nexa-dev-overlay .nexa-slow { color: ${Z.warning}; }
239
+ #nexa-dev-overlay .nexa-slow { color: ${J.warning}; }
238
240
  #nexa-dev-overlay .nexa-empty {
239
241
  display: flex;
240
242
  flex-direction: column;
@@ -242,11 +244,11 @@
242
244
  justify-content: center;
243
245
  padding: 48px 24px;
244
246
  text-align: center;
245
- color: ${Z.textDim};
247
+ color: ${J.textDim};
246
248
  }
247
249
  #nexa-dev-overlay .nexa-empty svg { margin-bottom: 16px; opacity: 0.4; }
248
- #nexa-dev-overlay .nexa-empty p { font-size: 14px; color: ${Z.textMuted}; margin-bottom: 4px; }
249
- #nexa-dev-overlay .nexa-empty span { font-size: 12px; color: ${Z.textDim}; }
250
+ #nexa-dev-overlay .nexa-empty p { font-size: 14px; color: ${J.textMuted}; margin-bottom: 4px; }
251
+ #nexa-dev-overlay .nexa-empty span { font-size: 12px; color: ${J.textDim}; }
250
252
  #nexa-dev-overlay .nexa-detail {
251
253
  flex-direction: column;
252
254
  padding: 16px;
@@ -266,21 +268,21 @@
266
268
  align-items: center;
267
269
  gap: 6px;
268
270
  padding: 8px 14px;
269
- background: ${Z.bgElevated};
270
- border: 1px solid ${Z.border};
271
+ background: ${J.bgSurface};
272
+ border: 1px solid ${J.border};
271
273
  border-radius: 8px;
272
- color: ${Z.textMuted};
274
+ color: ${J.textMuted};
273
275
  font-size: 13px;
274
276
  font-weight: 500;
275
277
  cursor: pointer;
276
278
  transition: all 0.15s;
277
279
  }
278
- #nexa-dev-overlay .nexa-btn:hover { background: ${Z.border}; color: ${Z.text}; }
279
- #nexa-dev-overlay .nexa-btn-retry { background: ${Z.successBg}; border-color: transparent; color: ${Z.success}; }
280
- #nexa-dev-overlay .nexa-btn-retry:hover { background: ${Z.success}; color: white; }
280
+ #nexa-dev-overlay .nexa-btn:hover { background: rgba(53, 80, 122, 0.24); color: ${J.text}; }
281
+ #nexa-dev-overlay .nexa-btn-retry { background: ${J.successBg}; border-color: transparent; color: ${J.success}; }
282
+ #nexa-dev-overlay .nexa-btn-retry:hover { background: ${J.success}; color: #052e26; }
281
283
  #nexa-dev-overlay .nexa-card {
282
- background: ${Z.bgElevated};
283
- border: 1px solid ${Z.border};
284
+ background: ${J.bgSurface};
285
+ border: 1px solid ${J.border};
284
286
  border-radius: 12px;
285
287
  padding: 16px;
286
288
  margin-bottom: 12px;
@@ -288,7 +290,7 @@
288
290
  #nexa-dev-overlay .nexa-card h3 {
289
291
  font-size: 12px;
290
292
  font-weight: 600;
291
- color: ${Z.textDim};
293
+ color: ${J.textDim};
292
294
  text-transform: uppercase;
293
295
  letter-spacing: 0.05em;
294
296
  margin-bottom: 12px;
@@ -299,20 +301,20 @@
299
301
  align-items: center;
300
302
  padding: 6px 0;
301
303
  font-size: 13px;
302
- border-bottom: 1px solid ${Z.border};
304
+ border-bottom: 1px solid ${J.border};
303
305
  }
304
306
  #nexa-dev-overlay .nexa-row:last-child { border-bottom: none; }
305
- #nexa-dev-overlay .nexa-row span { color: ${Z.textMuted}; }
306
- #nexa-dev-overlay .nexa-row strong { color: ${Z.text}; font-weight: 500; font-variant-numeric: tabular-nums; }
307
- #nexa-dev-overlay .nexa-row .nexa-ok { color: ${Z.success}; }
308
- #nexa-dev-overlay .nexa-row .nexa-err { color: ${Z.error}; }
307
+ #nexa-dev-overlay .nexa-row span { color: ${J.textMuted}; }
308
+ #nexa-dev-overlay .nexa-row strong { color: ${J.text}; font-weight: 500; font-variant-numeric: tabular-nums; }
309
+ #nexa-dev-overlay .nexa-row .nexa-ok { color: ${J.success}; }
310
+ #nexa-dev-overlay .nexa-row .nexa-err { color: ${J.error}; }
309
311
  #nexa-dev-overlay .nexa-code {
310
- background: ${Z.bg};
312
+ background: ${J.bg};
311
313
  border-radius: 8px;
312
314
  padding: 12px;
313
315
  font-size: 11px;
314
316
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
315
- color: ${Z.textMuted};
317
+ color: ${J.textMuted};
316
318
  overflow-x: auto;
317
319
  white-space: pre;
318
320
  max-height: 200px;
@@ -321,7 +323,7 @@
321
323
  #nexa-dev-overlay .nexa-url-full {
322
324
  font-size: 12px;
323
325
  word-break: break-all;
324
- color: ${Z.accent};
326
+ color: ${J.accent};
325
327
  }
326
328
  #nexa-dev-overlay .nexa-metrics-content {
327
329
  padding: 16px;
@@ -329,33 +331,157 @@
329
331
  flex-direction: column;
330
332
  gap: 12px;
331
333
  }
334
+ /* Settings modal (overlays the content area without shifting layout) */
335
+ #nexa-dev-overlay .nexa-settings-panel {
336
+ position: absolute;
337
+ top: 72px;
338
+ left: 16px;
339
+ right: 16px;
340
+ bottom: 16px;
341
+ z-index: 2147483650;
342
+ display: none;
343
+ flex-direction: column;
344
+ gap: 12px;
345
+ padding: 16px;
346
+ border-radius: 12px;
347
+ background: ${J.bgElevated};
348
+ border: 1px solid ${J.border};
349
+ box-shadow: 0 28px 60px -24px rgba(2, 6, 23, 0.76);
350
+ overflow: auto;
351
+ }
352
+ #nexa-dev-overlay .nexa-settings-row { display:flex;align-items:center;gap:8px;margin-bottom:8px }
353
+ #nexa-dev-overlay .nexa-settings-row label{font-size:13px;color:${J.textDim};min-width:70px}
354
+ #nexa-dev-overlay .nexa-settings-row select{padding:6px 8px;border-radius:8px;border:1px solid ${J.border};background:${J.bg};color:${J.text}}
355
+
356
+ #nexa-dev-overlay.nexa-theme-light {
357
+ background: #f8fbff;
358
+ color: #0f172a;
359
+ border-color: #d8e4f2;
360
+ box-shadow: 0 28px 60px -24px rgba(15, 23, 42, 0.18), 0 0 0 1px rgba(148, 163, 184, 0.16);
361
+ }
362
+ #nexa-dev-overlay.nexa-theme-light .nexa-header,
363
+ #nexa-dev-overlay.nexa-theme-light .nexa-metrics-bar,
364
+ #nexa-dev-overlay.nexa-theme-light .nexa-search,
365
+ #nexa-dev-overlay.nexa-theme-light .nexa-tabs {
366
+ background: #f8fbff;
367
+ border-color: #d8e4f2;
368
+ }
369
+ #nexa-dev-overlay.nexa-theme-light .nexa-logo,
370
+ #nexa-dev-overlay.nexa-theme-light .nexa-metric,
371
+ #nexa-dev-overlay.nexa-theme-light .nexa-request-item,
372
+ #nexa-dev-overlay.nexa-theme-light .nexa-btn,
373
+ #nexa-dev-overlay.nexa-theme-light .nexa-card,
374
+ #nexa-dev-overlay.nexa-theme-light .nexa-settings-panel {
375
+ background: #ffffff;
376
+ border-color: #d8e4f2;
377
+ }
378
+ #nexa-dev-overlay.nexa-theme-light .nexa-metric:hover,
379
+ #nexa-dev-overlay.nexa-theme-light .nexa-icon-btn:hover,
380
+ #nexa-dev-overlay.nexa-theme-light .nexa-btn:hover,
381
+ #nexa-dev-overlay.nexa-theme-light .nexa-tab:hover,
382
+ #nexa-dev-overlay.nexa-theme-light .nexa-request-item:hover {
383
+ background: #eef6ff;
384
+ }
385
+ #nexa-dev-overlay.nexa-theme-light .nexa-request-item:hover {
386
+ border-color: #93c5fd;
387
+ }
388
+ #nexa-dev-overlay.nexa-theme-light .nexa-search-icon,
389
+ #nexa-dev-overlay.nexa-theme-light .nexa-metric-label,
390
+ #nexa-dev-overlay.nexa-theme-light .nexa-duration,
391
+ #nexa-dev-overlay.nexa-theme-light .nexa-empty,
392
+ #nexa-dev-overlay.nexa-theme-light .nexa-empty span,
393
+ #nexa-dev-overlay.nexa-theme-light .nexa-row span,
394
+ #nexa-dev-overlay.nexa-theme-light .nexa-settings-row label {
395
+ color: #64748b;
396
+ }
397
+ #nexa-dev-overlay.nexa-theme-light .nexa-url,
398
+ #nexa-dev-overlay.nexa-theme-light .nexa-empty p,
399
+ #nexa-dev-overlay.nexa-theme-light .nexa-icon-btn,
400
+ #nexa-dev-overlay.nexa-theme-light .nexa-tab,
401
+ #nexa-dev-overlay.nexa-theme-light .nexa-btn,
402
+ #nexa-dev-overlay.nexa-theme-light .nexa-code {
403
+ color: #334155;
404
+ }
405
+ #nexa-dev-overlay.nexa-theme-light .nexa-metric-value,
406
+ #nexa-dev-overlay.nexa-theme-light .nexa-title,
407
+ #nexa-dev-overlay.nexa-theme-light .nexa-row strong {
408
+ color: #0f172a;
409
+ }
410
+ #nexa-dev-overlay.nexa-theme-light .nexa-search-input,
411
+ #nexa-dev-overlay.nexa-theme-light .nexa-settings-row select,
412
+ #nexa-dev-overlay.nexa-theme-light .nexa-code {
413
+ background: #ffffff;
414
+ color: #0f172a;
415
+ border-color: #d8e4f2;
416
+ }
417
+ #nexa-dev-overlay.nexa-theme-light .nexa-search-input:focus {
418
+ border-color: #38bdf8;
419
+ box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.16);
420
+ }
421
+ #nexa-dev-overlay.nexa-theme-light .nexa-tab-active {
422
+ color: #ffffff;
423
+ background: #0ea5e9 !important;
424
+ }
425
+ #nexa-dev-overlay.nexa-theme-light .nexa-tab-count {
426
+ background: rgba(14, 165, 233, 0.12);
427
+ color: #075985;
428
+ }
429
+ #nexa-dev-overlay.nexa-theme-light .nexa-code,
430
+ #nexa-dev-overlay.nexa-theme-light .nexa-detail,
431
+ #nexa-dev-overlay.nexa-theme-light .nexa-row {
432
+ border-color: #d8e4f2;
433
+ }
332
434
  #nexa-dev-overlay .nexa-slow-req {
333
435
  display: flex;
334
436
  align-items: center;
335
437
  gap: 8px;
336
438
  }
337
- `,be=class{panel=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)}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)}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}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;this.panel=document.createElement(`div`),this.panel.id=`nexa-dev-overlay`;let e=this.config.position,t=e.includes(`bottom`),n=e.includes(`right`);this.panel.style.cssText=`
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=`
338
440
  position: fixed;
339
- ${t?`bottom: 24px;`:`top: 24px;`}
340
- ${n?`right: 24px;`:`left: 24px;`}
441
+ ${t?`bottom: ${r};`:`top: ${r};`}
442
+ ${n?`right: ${r};`:`left: ${r};`}
341
443
  width: 420px;
342
444
  max-height: 70vh;
343
- z-index: 2147483647;
445
+ z-index: 2147483649;
344
446
  display: flex;
345
447
  flex-direction: column;
346
448
  overflow: hidden;
347
- `,this.panel.innerHTML=`<style>${ye}</style>
449
+ `,this.panel.innerHTML=`<style>${Y}</style>
348
450
 
349
451
  <div class="nexa-header">
350
- <div class="nexa-header-left">
452
+ <div class="nexa-header-left">
351
453
  <div class="nexa-logo">
352
- <span style="display:flex;align-items:center;justify-content:center;font-size:14px;font-weight:700;color:#fff;background:linear-gradient(135deg,#3b82f6,#238636);width:18px;height:18px;border-radius:4px;">N</span>
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;" />
353
455
  </div>
354
456
  <span class="nexa-title">Nexa DevTools</span>
355
457
  </div>
356
458
  <div class="nexa-header-actions">
357
- <button class="nexa-icon-btn nexa-btn-clear" title="Clear history">${X.clear}</button>
358
- <button class="nexa-icon-btn nexa-btn-close" title="Close (Esc)">${X.close}</button>
459
+ <button class="nexa-icon-btn nexa-btn-settings" title="Settings">${q.gear}</button>
460
+ <button class="nexa-icon-btn nexa-btn-clear" title="Clear history">${q.clear}</button>
461
+ <button class="nexa-icon-btn nexa-btn-close" title="Close (Esc)">${q.close}</button>
462
+ </div>
463
+ </div>
464
+
465
+ <div class="nexa-settings-panel" style="display:none">
466
+ <div class="nexa-settings-row">
467
+ <label for="nexa-pos">Position</label>
468
+ <select id="nexa-pos" data-setting="position">
469
+ <option value="top-right">Top Right</option>
470
+ <option value="top-left">Top Left</option>
471
+ <option value="bottom-right">Bottom Right</option>
472
+ <option value="bottom-left">Bottom Left</option>
473
+ </select>
474
+ </div>
475
+ <div class="nexa-settings-row">
476
+ <label for="nexa-theme">Theme</label>
477
+ <select id="nexa-theme" data-setting="theme">
478
+ <option value="dark">Dark</option>
479
+ <option value="light">Light</option>
480
+ </select>
481
+ </div>
482
+ <div style="display:flex;gap:8px;margin-top:8px">
483
+ <button class="nexa-btn nexa-btn-save">Save</button>
484
+ <button class="nexa-btn nexa-btn-cancel">Cancel</button>
359
485
  </div>
360
486
  </div>
361
487
 
@@ -368,7 +494,7 @@
368
494
  </div>
369
495
 
370
496
  <div class="nexa-search">
371
- <span class="nexa-search-icon">${X.search}</span>
497
+ <span class="nexa-search-icon">${q.search}</span>
372
498
  <input type="text" class="nexa-search-input" placeholder="Filter by URL, method, or status..." />
373
499
  </div>
374
500
 
@@ -384,12 +510,12 @@
384
510
 
385
511
  <div class="nexa-detail" style="display:none">
386
512
  <div class="nexa-detail-header">
387
- <button class="nexa-btn nexa-btn-back">${X.back} Back</button>
388
- <button class="nexa-btn nexa-btn-retry">${X.retry} Retry</button>
513
+ <button class="nexa-btn nexa-btn-back">${q.back} Back</button>
514
+ <button class="nexa-btn nexa-btn-retry">${q.retry} Retry</button>
389
515
  </div>
390
516
  <div class="nexa-detail-body"></div>
391
517
  </div>
392
- `,document.body.appendChild(this.panel),this.bindEvents(),this.removeTrackerListener=this.tracker.onChange(()=>this.render()),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()})}))}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=`
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=`
393
519
  <div class="nexa-empty">
394
520
  <svg width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
395
521
  <circle cx="12" cy="12" r="10"/><path d="M8 12h8M12 8v8"/>
@@ -407,7 +533,7 @@
407
533
  ${e.cached?`<span class="nexa-badge nexa-badge-cache">Cache</span>`:``}
408
534
  ${e.retryCount>0?`<span class="nexa-badge nexa-badge-retry">${e.retryCount}R</span>`:``}
409
535
  <span class="nexa-duration ${e.duration>500?`nexa-slow`:``}">${e.duration.toFixed(0)}ms</span>
410
- ${X.chevron}
536
+ ${q.chevron}
411
537
  </div>
412
538
  </div>
413
539
  `).join(``),e.querySelectorAll(`.nexa-request-item`).forEach(e=>{e.addEventListener(`click`,()=>{let n=e.dataset.id,r=t.find(e=>e.id===n);r&&this.showDetail(r)})})}renderMetrics(){let e=this.tracker.getMetrics(),t=this.panel?.querySelector(`.nexa-metrics-content`);if(!t)return;let n=e.totalRequests>0?(e.successfulRequests/e.totalRequests*100).toFixed(1):`0`;t.innerHTML=`
@@ -439,7 +565,7 @@
439
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=`
440
566
  <div class="nexa-card">
441
567
  <h3>Request</h3>
442
- <div class="nexa-row"><span>Method</span><strong style="color:${e.method===`GET`?Z.get:e.method===`POST`?Z.post:e.method===`DELETE`?Z.delete:Z.warning}">${e.method}</strong></div>
568
+ <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>
443
569
  <div class="nexa-row"><span>URL</span><span class="nexa-url-full">${e.url}</span></div>
444
570
  <div class="nexa-row"><span>Status</span><strong class="${e.ok?`nexa-ok`:`nexa-err`}">${e.status||`N/A`}</strong></div>
445
571
  <div class="nexa-row"><span>Duration</span><strong>${e.duration.toFixed(1)}ms</strong></div>
@@ -458,5 +584,22 @@
458
584
  <h3>Headers</h3>
459
585
  <pre class="nexa-code">${this.formatJson(e.headers)}</pre>
460
586
  </div>
461
- `:``}`)}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}},Q=null,$=null;function xe(e={}){return Q?{tracker:$,ui:Q}:($=new Y(e),Q=new be($),Q.show(),{tracker:$,ui:Q})}function Se(){return{tracker:$,ui:Q}}function Ce(){Q?.destroy(),Q=null,$=null}e.AggressiveRetry=f,e.CachePlugin=I,e.CacheStore=y,e.CircuitBreakerRetry=ee,e.ConservativeRetry=p,e.DedupePlugin=L,e.Defer=k,e.Err=n,e.HttpClient=U,e.HttpError=W,e.LoggerPlugin=P,e.MetricsPlugin=F,e.MiddlewarePipeline=ae,e.Ok=t,e.PluginManager=N,e.RequestDeduplicator=x,e.RequestTracker=Y,e.TypedObservable=se,e.cacheMiddleware=re,e.createApiUrl=O,e.createCacheMiddleware=b,e.createDedupeMiddleware=S,e.createDevOverlay=xe,e.createHttpClient=de,e.createPipeline=C,e.createProjectionTransformer=u,e.createRealtimePlugin=ve,e.createRequiredFieldsValidator=i,e.createSSEClient=ge,e.createSchemaValidator=r,e.createStreamingMiddleware=M,e.createTypeGuard=E,e.createTypedApiClient=oe,e.createTypedRequest=T,e.createTypedResponse=w,e.createUrl=D,e.createWebSocketClient=me,e.createWrapperTransformer=d,e.dedupeMiddleware=ie,e.destroyDevOverlay=Ce,e.getDevOverlay=Se,e.handleStream=A,e.isHttpError=ue,e.retry=v,e.streamToFile=ce,e.streamingMiddleware=le,e.transformCamelToSnake=c,e.transformFlatten=l,e.transformSnakeToCamel=s,e.validatorIsArray=a,e.validatorIsObject=o,e.withTimeout=ne});
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=`
588
+ position: fixed;
589
+ ${o}
590
+ width: ${t}px;
591
+ height: ${t}px;
592
+ border-radius: 50%;
593
+ border: ${d};
594
+ display: flex;
595
+ align-items: center;
596
+ justify-content: center;
597
+ z-index: 2147483648;
598
+ cursor: pointer;
599
+ box-shadow: ${u};
600
+ background: ${c};
601
+ color: ${l};
602
+ font-weight: 700;
603
+ 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}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});
462
605
  //# sourceMappingURL=nexa.umd.js.map