!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).flyapi={})}(this,(function(t){"use strict";const e=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,o=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,r=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function n(t,e){if(!("__proto__"===t||"constructor"===t&&e&&"object"==typeof e&&"prototype"in e))return e;!function(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}(t)}function s(t,s={}){if("string"!=typeof t)return t;const i=t.trim();if('"'===t[0]&&t.endsWith('"')&&!t.includes("\\"))return i.slice(1,-1);if(i.length<=9){const t=i.toLowerCase();if("true"===t)return!0;if("false"===t)return!1;if("undefined"===t)return;if("null"===t)return null;if("nan"===t)return Number.NaN;if("infinity"===t)return Number.POSITIVE_INFINITY;if("-infinity"===t)return Number.NEGATIVE_INFINITY}if(!r.test(t)){if(s.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(e.test(t)||o.test(t)){if(s.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,n)}return JSON.parse(t)}catch(e){if(s.strict)throw e;return t}}const i=/#/g,a=/&/g,c=/\//g,u=/=/g,p=/\+/g,f=/%5e/gi,l=/%60/gi,h=/%7c/gi,d=/%20/gi;function y(t){return(e="string"==typeof t?t:JSON.stringify(t),encodeURI(""+e).replace(h,"|")).replace(p,"%2B").replace(d,"+").replace(i,"%23").replace(a,"%26").replace(l,"`").replace(f,"^").replace(c,"%2F");var e}function b(t){return y(t).replace(u,"%3D")}function m(t=""){try{return decodeURIComponent(""+t)}catch{return""+t}}function g(t){return m(t.replace(p," "))}function w(t=""){const e={};"?"===t[0]&&(t=t.slice(1));for(const o of t.split("&")){const t=o.match(/([^=]+)=?(.*)/)||[];if(t.length<2)continue;const r=m(t[1].replace(p," "));if("__proto__"===r||"constructor"===r)continue;const n=g(t[2]||"");void 0===e[r]?e[r]=n:Array.isArray(e[r])?e[r].push(n):e[r]=[e[r],n]}return e}function T(t){return Object.keys(t).filter((e=>void 0!==t[e])).map((e=>{return o=e,"number"!=typeof(r=t[e])&&"boolean"!=typeof r||(r=String(r)),r?Array.isArray(r)?r.map((t=>`${b(o)}=${y(t)}`)).join("&"):`${b(o)}=${y(r)}`:b(o);var o,r})).filter(Boolean).join("&")}const S=/^[\s\w\0+.-]{2,}:([/\\]{1,2})/,E=/^[\s\w\0+.-]{2,}:([/\\]{2})?/,_=/^([/\\]\s*){2,}[^/\\]/,x=/\/$|\/\?|\/#/,q=/^\.?\//;function j(t,e={}){return"boolean"==typeof e&&(e={acceptRelative:e}),e.strict?S.test(t):E.test(t)||!!e.acceptRelative&&_.test(t)}function v(t="",e){return e?x.test(t):t.endsWith("/")}function R(t="",e){if(!e)return t.endsWith("/")?t:t+"/";if(v(t,!0))return t||"/";let o=t,r="";const n=t.indexOf("#");if(n>=0&&(o=t.slice(0,n),r=t.slice(n),!o))return r;const[s,...i]=o.split("?");return s+"/"+(i.length>0?`?${i.join("?")}`:"")+r}function $(t,e){if(!(o=e)||"/"===o||j(t))return t;var o;const r=function(t="",e){if(!e)return(v(t)?t.slice(0,-1):t)||"/";if(!v(t,!0))return t||"/";let o=t,r="";const n=t.indexOf("#");n>=0&&(o=t.slice(0,n),r=t.slice(n));const[s,...i]=o.split("?");return((s.endsWith("/")?s.slice(0,-1):s)||"/")+(i.length>0?`?${i.join("?")}`:"")+r}(e);return t.startsWith(r)?t:N(r,t)}function A(t,e){const o=C(t),r={...w(o.search),...e};return o.search=T(r),function(t){const e=t.pathname||"",o=t.search?(t.search.startsWith("?")?"":"?")+t.search:"",r=t.hash||"",n=t.auth?t.auth+"@":"",s=t.host||"",i=t.protocol||t[O]?(t.protocol||"")+"//":"";return i+n+s+e+o+r}(o)}function N(t,...e){let o=t||"";for(const t of e.filter((t=>function(t){return t&&"/"!==t}(t))))if(o){const e=t.replace(q,"");o=R(o)+e}else o=t;return o}const O=Symbol.for("ufo:protocolRelative");function C(t="",e){const o=t.match(/^[\s\0]*(blob:|data:|javascript:|vbscript:)(.*)/i);if(o){const[,t,e=""]=o;return{protocol:t.toLowerCase(),pathname:e,href:t+e,auth:"",host:"",search:"",hash:""}}if(!j(t,{acceptRelative:!0}))return e?C(e+t):P(t);const[,r="",n,s=""]=t.replace(/\\/g,"/").match(/^[\s\0]*([\w+.-]{2,}:)?\/\/([^/@]+@)?(.*)/)||[],[,i="",a=""]=s.match(/([^#/?]*)(.*)?/)||[],{pathname:c,search:u,hash:p}=P(a.replace(/\/(?=[A-Za-z]:)/,""));return{protocol:r.toLowerCase(),auth:n?n.slice(0,Math.max(0,n.length-1)):"",host:i,pathname:c,search:u,hash:p,[O]:!r}}function P(t=""){const[e="",o="",r=""]=(t.match(/([^#?]*)(\?[^#]*)?(#.*)?/)||[]).splice(1);return{pathname:e,search:o,hash:r}}class I extends Error{constructor(t,e){super(t,e),this.name="FetchError",e?.cause&&!this.cause&&(this.cause=e.cause)}}const k=new Set(Object.freeze(["PATCH","POST","PUT","DELETE"]));function F(t="GET"){return k.has(t.toUpperCase())}const H=new Set(["image/svg","application/xml","application/xhtml","application/html"]),J=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function U(t,e,o=globalThis.Headers){const r={...e,...t};if(e?.params&&t?.params&&(r.params={...e?.params,...t?.params}),e?.query&&t?.query&&(r.query={...e?.query,...t?.query}),e?.headers&&t?.headers){r.headers=new o(e?.headers||{});for(const[e,n]of new o(t?.headers||{}))r.headers.set(e,n)}return r}const W=new Set([408,409,425,429,500,502,503,504]),L=new Set([101,204,205,304]);const D=function(){if("undefined"!=typeof globalThis)return globalThis;if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}(),G=function t(e={}){const{fetch:o=globalThis.fetch,Headers:r=globalThis.Headers,AbortController:n=globalThis.AbortController}=e;async function i(t){const e=t.error&&"AbortError"===t.error.name&&!t.options.timeout||!1;if(!1!==t.options.retry&&!e){let e;e="number"==typeof t.options.retry?t.options.retry:F(t.options.method)?0:1;const o=t.response&&t.response.status||500;if(e>0&&(Array.isArray(t.options.retryStatusCodes)?t.options.retryStatusCodes.includes(o):W.has(o))){const o=t.options.retryDelay||0;return o>0&&await new Promise((t=>setTimeout(t,o))),a(t.request,{...t.options,retry:e-1})}}const o=function(t){const e=t.error?.message||t.error?.toString()||"",o=t.request?.method||t.options?.method||"GET",r=t.request?.url||String(t.request)||"/",n=`[${o}] ${JSON.stringify(r)}`,s=t.response?`${t.response.status} ${t.response.statusText}`:"",i=new I(`${n}: ${s}${e?` ${e}`:""}`,t.error?{cause:t.error}:void 0);for(const e of["request","options","response"])Object.defineProperty(i,e,{get:()=>t[e]});for(const[e,o]of[["data","_data"],["status","status"],["statusCode","status"],["statusText","statusText"],["statusMessage","statusText"]])Object.defineProperty(i,e,{get:()=>t.response&&t.response[o]});return i}(t);throw Error.captureStackTrace&&Error.captureStackTrace(o,a),o}const a=async function(t,a={}){const c={request:t,options:U(a,e.defaults,r),response:void 0,error:void 0};let u;if(c.options.method=c.options.method?.toUpperCase(),c.options.onRequest&&await c.options.onRequest(c),"string"==typeof c.request&&(c.options.baseURL&&(c.request=$(c.request,c.options.baseURL)),(c.options.query||c.options.params)&&(c.request=A(c.request,{...c.options.params,...c.options.query}))),c.options.body&&F(c.options.method)&&(!function(t){if(void 0===t)return!1;const e=typeof t;return"string"===e||"number"===e||"boolean"===e||null===e||"object"===e&&(!!Array.isArray(t)||!t.buffer&&(t.constructor&&"Object"===t.constructor.name||"function"==typeof t.toJSON))}(c.options.body)?("pipeTo"in c.options.body&&"function"==typeof c.options.body.pipeTo||"function"==typeof c.options.body.pipe)&&("duplex"in c.options||(c.options.duplex="half")):(c.options.body="string"==typeof c.options.body?c.options.body:JSON.stringify(c.options.body),c.options.headers=new r(c.options.headers||{}),c.options.headers.has("content-type")||c.options.headers.set("content-type","application/json"),c.options.headers.has("accept")||c.options.headers.set("accept","application/json"))),!c.options.signal&&c.options.timeout){const t=new n;u=setTimeout((()=>t.abort()),c.options.timeout),c.options.signal=t.signal}try{c.response=await o(c.request,c.options)}catch(t){return c.error=t,c.options.onRequestError&&await c.options.onRequestError(c),await i(c)}finally{u&&clearTimeout(u)}if(c.response.body&&!L.has(c.response.status)&&"HEAD"!==c.options.method){const t=(c.options.parseResponse?"json":c.options.responseType)||function(t=""){if(!t)return"json";const e=t.split(";").shift()||"";return J.test(e)?"json":H.has(e)||e.startsWith("text/")?"text":"blob"}(c.response.headers.get("content-type")||"");switch(t){case"json":{const t=await c.response.text(),e=c.options.parseResponse||s;c.response._data=e(t);break}case"stream":c.response._data=c.response.body;break;default:c.response._data=await c.response[t]()}}return c.options.onResponse&&await c.options.onResponse(c),!c.options.ignoreResponseError&&c.response.status>=400&&c.response.status<600?(c.options.onResponseError&&await c.options.onResponseError(c),await i(c)):c.response},c=async function(t,e){return(await a(t,e))._data};return c.raw=a,c.native=(...t)=>o(...t),c.create=(o={})=>t({...e,defaults:{...e.defaults,...o}}),c}({fetch:D.fetch||(()=>Promise.reject(new Error("[ofetch] global.fetch is not supported!"))),Headers:D.Headers,AbortController:D.AbortController}),z=t=>null==t,B=function(t,e,o){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};const{caseTransform:n,urlParams:s={},...i}=r,a=[],c=n??e;for(const t of o)a.push((z(c)?t:c(t)).trim()),!z(s[t])&&a.push(String(s[t]));return t(N("",...a),i)};t.flyapi=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const{fetchOptions:e={},caseTransform:o,executeHandler:r}=t,n=G.create(e),s=(r??B).bind(null,n,o),i=(t,e)=>s(t,e),a={get(t,e){if("string"!=typeof e)throw new Error("Properties must be a string");return z(t.__callStack)?new Proxy({__callStack:[e]},a):"exec"===e?i.bind(null,t.__callStack):(t.__callStack.push(e),new Proxy(t,a))}};return new Proxy({},a)}}));