@nvwa-app/sdk-core 0.4.4 → 0.4.5
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/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Wt=Object.create;var ge=Object.defineProperty;var Gt=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var Vt=Object.getPrototypeOf,Kt=Object.prototype.hasOwnProperty;var Jt=(r,e)=>()=>(r&&(e=r(r=0)),e);var F=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Yt=(r,e)=>{for(var t in e)ge(r,t,{get:e[t],enumerable:!0})},st=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of zt(e))!Kt.call(r,n)&&n!==t&&ge(r,n,{get:()=>e[n],enumerable:!(s=Gt(e,n))||s.enumerable});return r};var Qt=(r,e,t)=>(t=r!=null?Wt(Vt(r)):{},st(e||!r||!r.__esModule?ge(t,"default",{value:r,enumerable:!0}):t,r)),Xt=r=>st(ge({},"__esModule",{value:!0}),r);var a=Jt(()=>{"use strict"});var se=F(T=>{"use strict";a();Object.defineProperty(T,"__esModule",{value:!0});T.File=T.FormData=T.Blob=T.FetchResponse=T.URL=T.URLSearchParams=T.FetchHeaders=void 0;var te=class{constructor(e){if(this.map=new Map,e)for(let[t,s]of Object.entries(e))this.set(t,s)}get(e){var t;return(t=this.map.get(e))!==null&&t!==void 0?t:null}set(e,t){this.map.set(e,t)}has(e){return this.map.has(e)}append(e,t){let s=this.map.get(e);s?this.map.set(e,`${s}${t}`):this.map.set(e,t)}delete(e){this.map.delete(e)}forEach(e){this.map.forEach(e)}size(){return this.map.size}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}headers(){return Object.fromEntries(this.map.entries())}[Symbol.iterator](){return this.map[Symbol.iterator]()}};T.FetchHeaders=te;var Se=class r{constructor(e){if(this.params=new Map,e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}};T.URLSearchParams=Se;var _e=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new Se(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let I=d[1];h=d[2];let y=I.match(/^([^:]*):?(.*)$/);y&&(u=y[1]||"",l=y[2]||"")}let p=h.match(/^([^:]+):?(\d*)$/),R=p?p[1]:h,E=p&&p[2]?p[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:R,port:E,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};T.URL=_e;var Fe=class r{constructor(e,t){var s,n;this.status=(s=t?.status)!==null&&s!==void 0?s:200,this.statusText=(n=t?.statusText)!==null&&n!==void 0?n:"",this.headers=new te(t?.headers),this.ok=this.status>=200&&this.status<300,this.redirected=!1,this.url="",this.bodyUsed=!1,this.body=e||null}async arrayBuffer(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?new ArrayBuffer(0):new TextEncoder().encode(this.body).buffer}async blob(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new re([this.body||""])}async formData(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new Pe}async json(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?null:JSON.parse(this.body)}async text(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body||""}clone(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return new r(this.body,{status:this.status,statusText:this.statusText,headers:this.headers.headers()})}static error(){let e=new r(null,{status:0,statusText:""});return Object.defineProperty(e,"type",{value:"error",writable:!1}),e}static redirect(e,t=302){let s=e instanceof _e?e.href:e,n=new r(null,{status:t,statusText:"Found"});return n.headers.set("Location",s),n}static json(e,t){let s=JSON.stringify(e),n=new te(t?.headers);return n.set("Content-Type","application/json"),new r(s,Object.assign(Object.assign({},t),{headers:n.headers()}))}};T.FetchResponse=Fe;var re=class r{constructor(e,t){this._content=e||[],this.type=t?.type||"";let s=0;for(let n of this._content)typeof n=="string"?s+=new TextEncoder().encode(n).length:n instanceof ArrayBuffer?s+=n.byteLength:n instanceof Uint8Array&&(s+=n.length);this.size=s}async text(){let e="";for(let t of this._content)typeof t=="string"?e+=t:t instanceof ArrayBuffer?e+=new TextDecoder().decode(t):t instanceof Uint8Array&&(e+=new TextDecoder().decode(t));return e}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}slice(e,t,s){return new r(this._content.slice(e,t),{type:s})}};T.Blob=re;var Pe=class{constructor(){this._entries=[]}append(e,t,s){this._entries.push([e,t])}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}get(e){let t=this._entries.find(([s])=>s===e);return t?t[1]:null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,t])=>t)}has(e){return this._entries.some(([t])=>t===e)}set(e,t,s){this.delete(e),this.append(e,t,s)}forEach(e){for(let[t,s]of this._entries)e(s,t,this)}keys(){return this._entries.map(([e])=>e)[Symbol.iterator]()}values(){return this._entries.map(([,e])=>e)[Symbol.iterator]()}entries(){return this._entries[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}};T.FormData=Pe;var He=class extends re{constructor(e,t,s){super(e,s),this.name=t,this.lastModified=s?.lastModified||Date.now()}};T.File=He});var Ge=F(We=>{"use strict";a();Object.defineProperty(We,"__esModule",{value:!0});var qe=class extends Error{constructor(e){super(e.message),this.name="PostgrestError",this.details=e.details,this.hint=e.hint,this.code=e.code}};We.default=qe});var Ve=F(ne=>{"use strict";a();var ss=ne&&ne.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ne,"__esModule",{value:!0});var ns=ss(Ge()),Ot=se(),ze=class{constructor(e){var t,s;this.shouldThrowOnError=!1,this.method=e.method,this.url=e.url,this.headers=new Ot.FetchHeaders(e.headers),this.schema=e.schema,this.body=e.body,this.shouldThrowOnError=(t=e.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=e.signal,this.isMaybeSingle=(s=e.isMaybeSingle)!==null&&s!==void 0?s:!1,e.fetch?this.fetch=e.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers=new Ot.FetchHeaders(this.headers),this.headers.set(e,t),this}then(e,t){this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,n=s(this.url.toString(),{method:this.method,headers:this.headers.headers(),body:JSON.stringify(this.body),signal:this.signal}).then(async o=>{var i,c,d,u;let l=null,h=null,p=null,R=o.status,E=o.statusText;if(o.ok){if(this.method!=="HEAD"){let _=await o.text();_===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&(!((i=this.headers.get("Accept"))===null||i===void 0)&&i.includes("application/vnd.pgrst.plan+text"))?h=_:h=JSON.parse(_))}let y=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),O=(d=o.headers.get("content-range"))===null||d===void 0?void 0:d.split("/");y&&O&&O.length>1&&(p=parseInt(O[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(h)&&(h.length>1?(l={code:"PGRST116",details:`Results contain ${h.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},h=null,p=null,R=406,E="Not Acceptable"):h.length===1?h=h[0]:h=null)}else{let y=await o.text();try{l=JSON.parse(y),Array.isArray(l)&&o.status===404&&(h=[],l=null,R=200,E="OK")}catch{o.status===404&&y===""?(R=204,E="No Content"):l={message:y}}if(l&&this.isMaybeSingle&&(!((u=l?.details)===null||u===void 0)&&u.includes("0 rows"))&&(l=null,R=200,E="OK"),l&&this.shouldThrowOnError)throw new ns.default(l)}return{error:l,data:h,count:p,status:R,statusText:E}});return this.shouldThrowOnError||(n=n.catch(o=>{var i,c,d;return{error:{message:`${(i=o?.name)!==null&&i!==void 0?i:"FetchError"}: ${o?.message}`,details:`${(c=o?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(d=o?.code)!==null&&d!==void 0?d:""}`},data:null,count:null,status:0,statusText:""}})),n.then(e,t)}returns(){return this}overrideTypes(){return this}};ne.default=ze});var Je=F(oe=>{"use strict";a();var os=oe&&oe.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(oe,"__esModule",{value:!0});var as=os(Ve()),Ke=class extends as.default{select(e){let t=!1,s=(e??"*").split("").map(n=>/\s/.test(n)&&!t?"":(n==='"'&&(t=!t),n)).join("");return this.url.searchParams.set("select",s),this.headers.append("Prefer","return=representation"),this}order(e,{ascending:t=!0,nullsFirst:s,foreignTable:n,referencedTable:o=n}={}){let i=o?`${o}.order`:"order",c=this.url.searchParams.get(i);return this.url.searchParams.set(i,`${c?`${c},`:""}${e}.${t?"asc":"desc"}${s===void 0?"":s?".nullsfirst":".nullslast"}`),this}limit(e,{foreignTable:t,referencedTable:s=t}={}){let n=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(n,`${e}`),this}range(e,t,{foreignTable:s,referencedTable:n=s}={}){let o=typeof n>"u"?"offset":`${n}.offset`,i=typeof n>"u"?"limit":`${n}.limit`;return this.url.searchParams.set(o,`${e}`),this.url.searchParams.set(i,`${t-e+1}`),this}abortSignal(e){return this.signal=e,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.method==="GET"?this.headers.set("Accept","application/json"):this.headers.set("Accept","application/vnd.pgrst.object+json"),this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:e=!1,verbose:t=!1,settings:s=!1,buffers:n=!1,wal:o=!1,format:i="text"}={}){var c;let d=[e?"analyze":null,t?"verbose":null,s?"settings":null,n?"buffers":null,o?"wal":null].filter(Boolean).join("|"),u=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${i}; for="${u}"; options=${d};`),i==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(e){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${e}`),this}};oe.default=Ke});var Ae=F(ae=>{"use strict";a();var is=ae&&ae.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ae,"__esModule",{value:!0});var ls=is(Je()),Ye=class extends ls.default{eq(e,t){return this.url.searchParams.append(e,`eq.${t}`),this}neq(e,t){return this.url.searchParams.append(e,`neq.${t}`),this}gt(e,t){return this.url.searchParams.append(e,`gt.${t}`),this}gte(e,t){return this.url.searchParams.append(e,`gte.${t}`),this}lt(e,t){return this.url.searchParams.append(e,`lt.${t}`),this}lte(e,t){return this.url.searchParams.append(e,`lte.${t}`),this}like(e,t){return this.url.searchParams.append(e,`like.${t}`),this}likeAllOf(e,t){return this.url.searchParams.append(e,`like(all).{${t.join(",")}}`),this}likeAnyOf(e,t){return this.url.searchParams.append(e,`like(any).{${t.join(",")}}`),this}ilike(e,t){return this.url.searchParams.append(e,`ilike.${t}`),this}ilikeAllOf(e,t){return this.url.searchParams.append(e,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(e,t){return this.url.searchParams.append(e,`ilike(any).{${t.join(",")}}`),this}is(e,t){return this.url.searchParams.append(e,`is.${t}`),this}in(e,t){let s=Array.from(new Set(t)).map(n=>typeof n=="string"&&new RegExp("[,()]").test(n)?`"${n}"`:`${n}`).join(",");return this.url.searchParams.append(e,`in.(${s})`),this}contains(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cs.{${t.join(",")}}`):this.url.searchParams.append(e,`cs.${JSON.stringify(t)}`),this}containedBy(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cd.{${t.join(",")}}`):this.url.searchParams.append(e,`cd.${JSON.stringify(t)}`),this}rangeGt(e,t){return this.url.searchParams.append(e,`sr.${t}`),this}rangeGte(e,t){return this.url.searchParams.append(e,`nxl.${t}`),this}rangeLt(e,t){return this.url.searchParams.append(e,`sl.${t}`),this}rangeLte(e,t){return this.url.searchParams.append(e,`nxr.${t}`),this}rangeAdjacent(e,t){return this.url.searchParams.append(e,`adj.${t}`),this}overlaps(e,t){return typeof t=="string"?this.url.searchParams.append(e,`ov.${t}`):this.url.searchParams.append(e,`ov.{${t.join(",")}}`),this}textSearch(e,t,{config:s,type:n}={}){let o="";n==="plain"?o="pl":n==="phrase"?o="ph":n==="websearch"&&(o="w");let i=s===void 0?"":`(${s})`;return this.url.searchParams.append(e,`${o}fts${i}.${t}`),this}match(e){return Object.entries(e).forEach(([t,s])=>{this.url.searchParams.append(t,`eq.${s}`)}),this}not(e,t,s){return this.url.searchParams.append(e,`not.${t}.${s}`),this}or(e,{foreignTable:t,referencedTable:s=t}={}){let n=s?`${s}.or`:"or";return this.url.searchParams.append(n,`(${e})`),this}filter(e,t,s){return this.url.searchParams.append(e,`${t}.${s}`),this}};ae.default=Ye});var Xe=F(le=>{"use strict";a();var cs=le&&le.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(le,"__esModule",{value:!0});var us=se(),ie=cs(Ae()),Qe=class{constructor(e,{headers:t={},schema:s,fetch:n}){this.url=e,this.headers=new us.FetchHeaders(t),this.schema=s,this.fetch=n}select(e,t){let{head:s=!1,count:n}=t??{},o=s?"HEAD":"GET",i=!1,c=(e??"*").split("").map(d=>/\s/.test(d)&&!i?"":(d==='"'&&(i=!i),d)).join("");return this.url.searchParams.set("select",c),n&&this.headers.append("Prefer",`count=${n}`),new ie.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(e,{count:t,defaultToNull:s=!0}={}){var n;let o="POST";if(t&&this.headers.append("Prefer",`count=${t}`),s||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let i=e.reduce((c,d)=>c.concat(Object.keys(d)),[]);if(i.length>0){let c=[...new Set(i)].map(d=>`"${d}"`);this.url.searchParams.set("columns",c.join(","))}}return new ie.default({method:o,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}upsert(e,{onConflict:t,ignoreDuplicates:s=!1,count:n,defaultToNull:o=!0}={}){var i;let c="POST";if(this.headers.append("Prefer",`resolution=${s?"ignore":"merge"}-duplicates`),t!==void 0&&this.url.searchParams.set("on_conflict",t),n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let d=e.reduce((u,l)=>u.concat(Object.keys(l)),[]);if(d.length>0){let u=[...new Set(d)].map(l=>`"${l}"`);this.url.searchParams.set("columns",u.join(","))}}return new ie.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}update(e,{count:t}={}){var s;let n="PATCH";return t&&this.headers.append("Prefer",`count=${t}`),new ie.default({method:n,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch})}delete({count:e}={}){var t;let s="DELETE";return e&&this.headers.append("Prefer",`count=${e}`),new ie.default({method:s,url:this.url,headers:this.headers,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch})}};le.default=Qe});var It=F(ue=>{"use strict";a();var Ut=ue&&ue.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ue,"__esModule",{value:!0});var ds=Ut(Xe()),hs=Ut(Ae()),ce=se(),Ze=class r{constructor(e,{headers:t={},schema:s,fetch:n}={}){this.url=e,this.headers=new ce.FetchHeaders(t),this.schemaName=s,this.fetch=n}from(e){let t=new ce.URL(`${this.url}/${e}`);return new ds.default(t,{headers:new ce.FetchHeaders(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(e){return new r(this.url,{headers:this.headers,schema:e,fetch:this.fetch})}rpc(e,t={},{head:s=!1,get:n=!1,count:o}={}){var i;let c,d=new ce.URL(`${this.url}/rpc/${e}`),u;s||n?(c=s?"HEAD":"GET",Object.entries(t).filter(([h,p])=>p!==void 0).map(([h,p])=>[h,Array.isArray(p)?`{${p.join(",")}}`:`${p}`]).forEach(([h,p])=>{d.searchParams.append(h,p)})):(c="POST",u=t);let l=new ce.FetchHeaders(this.headers);return o&&l.set("Prefer",`count=${o}`),new hs.default({method:c,url:d,headers:l,schema:this.schemaName,body:u,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}};ue.default=Ze});var kt=F(g=>{"use strict";a();var z=g&&g.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(g,"__esModule",{value:!0});g.File=g.FormData=g.Blob=g.FetchResponse=g.FetchHeaders=g.URLSearchParams=g.URL=g.PostgrestError=g.PostgrestBuilder=g.PostgrestTransformBuilder=g.PostgrestFilterBuilder=g.PostgrestQueryBuilder=g.PostgrestClient=void 0;var xt=z(It());g.PostgrestClient=xt.default;var Ct=z(Xe());g.PostgrestQueryBuilder=Ct.default;var Nt=z(Ae());g.PostgrestFilterBuilder=Nt.default;var Lt=z(Je());g.PostgrestTransformBuilder=Lt.default;var $t=z(Ve());g.PostgrestBuilder=$t.default;var Dt=z(Ge());g.PostgrestError=Dt.default;var k=se();Object.defineProperty(g,"FetchHeaders",{enumerable:!0,get:function(){return k.FetchHeaders}});Object.defineProperty(g,"FetchResponse",{enumerable:!0,get:function(){return k.FetchResponse}});Object.defineProperty(g,"URL",{enumerable:!0,get:function(){return k.URL}});Object.defineProperty(g,"URLSearchParams",{enumerable:!0,get:function(){return k.URLSearchParams}});Object.defineProperty(g,"Blob",{enumerable:!0,get:function(){return k.Blob}});Object.defineProperty(g,"FormData",{enumerable:!0,get:function(){return k.FormData}});Object.defineProperty(g,"File",{enumerable:!0,get:function(){return k.File}});g.default={PostgrestClient:xt.default,PostgrestQueryBuilder:Ct.default,PostgrestFilterBuilder:Nt.default,PostgrestTransformBuilder:Lt.default,PostgrestBuilder:$t.default,PostgrestError:Dt.default,URLSearchParams:k.URLSearchParams,FetchHeaders:k.FetchHeaders,FetchResponse:k.FetchResponse}});var ys={};Yt(ys,{AUTH_BASE_PATH:()=>rs,AbortController:()=>pe,AbortSignal:()=>K,ENTITIES_BASE_PATH:()=>jt,FILE_STORAGE_BASE_PATH:()=>Pt,FetchResponse:()=>Me,GENERATE_UPLOAD_URL_PATH:()=>At,Headers:()=>N,LOGIN_TOKEN_KEY:()=>ee,LOGIN_USER_PROFILE_KEY:()=>Te,NvwaAuthClient:()=>De,NvwaEdgeFunctions:()=>ke,NvwaFileStorage:()=>je,NvwaHttpClient:()=>Be,Request:()=>he,Response:()=>fe,URL:()=>de,URLSearchParams:()=>V,createPostgrestClient:()=>ps,polyfill:()=>gs});module.exports=Xt(ys);a();a();a();a();a();a();var Zt=Object.defineProperty,er=Object.defineProperties,tr=Object.getOwnPropertyDescriptors,nt=Object.getOwnPropertySymbols,rr=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable,ot=(r,e,t)=>e in r?Zt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,x=(r,e)=>{for(var t in e||(e={}))rr.call(e,t)&&ot(r,t,e[t]);if(nt)for(var t of nt(e))sr.call(e,t)&&ot(r,t,e[t]);return r},L=(r,e)=>er(r,tr(e)),nr=class extends Error{constructor(r,e,t){super(e||r.toString(),{cause:t}),this.status=r,this.statusText=e,this.error=t}},or=async(r,e)=>{var t,s,n,o,i,c;let d=e||{},u={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:r,options:d,hooks:u};for(let l of e?.plugins||[]){if(l.init){let h=await((t=l.init)==null?void 0:t.call(l,r.toString(),e));d=h.options||d,r=h.url}u.onRequest.push((s=l.hooks)==null?void 0:s.onRequest),u.onResponse.push((n=l.hooks)==null?void 0:n.onResponse),u.onSuccess.push((o=l.hooks)==null?void 0:o.onSuccess),u.onError.push((i=l.hooks)==null?void 0:i.onError),u.onRetry.push((c=l.hooks)==null?void 0:c.onRetry)}return{url:r,options:d,hooks:u}},at=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(){return this.options.delay}},ar=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(r){return Math.min(this.options.maxDelay,this.options.baseDelay*2**r)}};function ir(r){if(typeof r=="number")return new at({type:"linear",attempts:r,delay:1e3});switch(r.type){case"linear":return new at(r);case"exponential":return new ar(r);default:throw new Error("Invalid retry strategy")}}var lr=async r=>{let e={},t=async s=>typeof s=="function"?await s():s;if(r?.auth){if(r.auth.type==="Bearer"){let s=await t(r.auth.token);if(!s)return e;e.authorization=`Bearer ${s}`}else if(r.auth.type==="Basic"){let s=t(r.auth.username),n=t(r.auth.password);if(!s||!n)return e;e.authorization=`Basic ${btoa(`${s}:${n}`)}`}else if(r.auth.type==="Custom"){let s=t(r.auth.value);if(!s)return e;e.authorization=`${t(r.auth.prefix)} ${s}`}}return e},cr=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function ur(r){let e=r.headers.get("content-type"),t=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let s=e.split(";").shift()||"";return cr.test(s)?"json":t.has(s)||s.startsWith("text/")?"text":"blob"}function dr(r){try{return JSON.parse(r),!0}catch{return!1}}function ct(r){if(r===void 0)return!1;let e=typeof r;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(r)?!0:r.buffer?!1:r.constructor&&r.constructor.name==="Object"||typeof r.toJSON=="function"}function it(r){try{return JSON.parse(r)}catch{return r}}function lt(r){return typeof r=="function"}function hr(r){if(r?.customFetchImpl)return r.customFetchImpl;if(typeof globalThis<"u"&<(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&<(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function fr(r){let e=new Headers(r?.headers),t=await lr(r);for(let[s,n]of Object.entries(t||{}))e.set(s,n);if(!e.has("content-type")){let s=pr(r?.body);s&&e.set("content-type",s)}return e}function pr(r){return ct(r)?"application/json":null}function mr(r){if(!r?.body)return null;let e=new Headers(r?.headers);if(ct(r.body)&&!e.has("content-type")){for(let[t,s]of Object.entries(r?.body))s instanceof Date&&(r.body[t]=s.toISOString());return JSON.stringify(r.body)}return r.body}function gr(r,e){var t;if(e?.method)return e.method.toUpperCase();if(r.startsWith("@")){let s=(t=r.split("@")[1])==null?void 0:t.split("/")[0];return dt.includes(s)?s.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function yr(r,e){let t;return!r?.signal&&r?.timeout&&(t=setTimeout(()=>e?.abort(),r?.timeout)),{abortTimeout:t,clearTimeout:()=>{t&&clearTimeout(t)}}}var br=class ut extends Error{constructor(e,t){super(t||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,ut.prototype)}};async function ye(r,e){let t=await r["~standard"].validate(e);if(t.issues)throw new br(t.issues);return t.value}var dt=["get","post","put","patch","delete"];var Rr=r=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(e,t){var s,n,o,i;let c=((n=(s=r.plugins)==null?void 0:s.find(d=>{var u;return(u=d.schema)!=null&&u.config?e.startsWith(d.schema.config.baseURL||"")||e.startsWith(d.schema.config.prefix||""):!1}))==null?void 0:n.schema)||r.schema;if(c){let d=e;(o=c.config)!=null&&o.prefix&&d.startsWith(c.config.prefix)&&(d=d.replace(c.config.prefix,""),c.config.baseURL&&(e=e.replace(c.config.prefix,c.config.baseURL))),(i=c.config)!=null&&i.baseURL&&d.startsWith(c.config.baseURL)&&(d=d.replace(c.config.baseURL,""));let u=c.schema[d];if(u){let l=L(x({},t),{method:u.method,output:u.output});return t?.disableValidation||(l=L(x({},l),{body:u.input?await ye(u.input,t?.body):t?.body,params:u.params?await ye(u.params,t?.params):t?.params,query:u.query?await ye(u.query,t?.query):t?.query})),{url:e,options:l}}}return{url:e,options:t}}}),ht=r=>{async function e(t,s){let n=L(x(x({},r),s),{plugins:[...r?.plugins||[],Rr(r||{})]});if(r?.catchAllError)try{return await Ue(t,n)}catch(o){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:o}}}return await Ue(t,n)}return e};function wr(r,e){let{baseURL:t,params:s,query:n}=e||{query:{},params:{},baseURL:""},o=r.startsWith("http")?r.split("/").slice(0,3).join("/"):t||"";if(r.startsWith("@")){let h=r.toString().split("@")[1].split("/")[0];dt.includes(h)&&(r=r.replace(`@${h}/`,"/"))}o.endsWith("/")||(o+="/");let[i,c]=r.replace(o,"").split("?"),d=new URLSearchParams(c);for(let[h,p]of Object.entries(n||{}))p!=null&&d.set(h,String(p));if(s)if(Array.isArray(s)){let h=i.split("/").filter(p=>p.startsWith(":"));for(let[p,R]of h.entries()){let E=s[p];i=i.replace(R,E)}}else for(let[h,p]of Object.entries(s))i=i.replace(`:${h}`,String(p));i=i.split("/").map(encodeURIComponent).join("/"),i.startsWith("/")&&(i=i.slice(1));let u=d.toString();return u=u.length>0?`?${u}`.replace(/\+/g,"%20"):"",o.startsWith("http")?new URL(`${i}${u}`,o):`${o}${i}${u}`}var Ue=async(r,e)=>{var t,s,n,o,i,c,d,u;let{hooks:l,url:h,options:p}=await or(r,e),R=hr(p),E=new AbortController,I=(t=p.signal)!=null?t:E.signal,y=wr(h,p),O=mr(p),_=await fr(p),M=gr(h,p),m=L(x({},p),{url:y,headers:_,body:O,method:M,signal:I});for(let U of l.onRequest)if(U){let S=await U(m);S instanceof Object&&(m=S)}("pipeTo"in m&&typeof m.pipeTo=="function"||typeof((s=e?.body)==null?void 0:s.pipe)=="function")&&("duplex"in m||(m.duplex="half"));let{clearTimeout:q}=yr(p,E),w=await R(m.url,m);q();let tt={response:w,request:m};for(let U of l.onResponse)if(U){let S=await U(L(x({},tt),{response:(n=e?.hookOptions)!=null&&n.cloneResponse?w.clone():w}));S instanceof Response?w=S:S instanceof Object&&(w=S.response)}if(w.ok){if(!(m.method!=="HEAD"))return{data:"",error:null};let S=ur(w),B={data:"",response:w,request:m};if(S==="json"||S==="text"){let j=await w.text(),qt=await((o=m.jsonParser)!=null?o:it)(j);B.data=qt}else B.data=await w[S]();m?.output&&m.output&&!m.disableValidation&&(B.data=await ye(m.output,B.data));for(let j of l.onSuccess)j&&await j(L(x({},B),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?w.clone():w}));return e?.throw?B.data:{data:B.data,error:null}}let Ft=(c=e?.jsonParser)!=null?c:it,me=await w.text(),rt=dr(me),Oe=rt?await Ft(me):null,Ht={response:w,responseText:me,request:m,error:L(x({},Oe),{status:w.status,statusText:w.statusText})};for(let U of l.onError)U&&await U(L(x({},Ht),{response:(d=e?.hookOptions)!=null&&d.cloneResponse?w.clone():w}));if(e?.retry){let U=ir(e.retry),S=(u=e.retryAttempt)!=null?u:0;if(await U.shouldAttemptRetry(S,w)){for(let j of l.onRetry)j&&await j(tt);let B=U.getDelay(S);return await new Promise(j=>setTimeout(j,B)),await Ue(r,L(x({},e),{retryAttempt:S+1}))}}if(e?.throw)throw new nr(w.status,w.statusText,rt?Oe:me);return{data:null,error:L(x({},Oe),{status:w.status,statusText:w.statusText})}};a();a();var be=Object.create(null),J=r=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(r?be:globalThis),A=new Proxy(be,{get(r,e){return J()[e]??be[e]},has(r,e){let t=J();return e in t||e in be},set(r,e,t){let s=J(!0);return s[e]=t,!0},deleteProperty(r,e){if(!e)return!1;let t=J(!0);return delete t[e],!0},ownKeys(){let r=J(!0);return Object.keys(r)}});var Ps=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function b(r,e){return typeof process<"u"&&process.env?process.env[r]??e:typeof Deno<"u"?Deno.env.get(r)??e:typeof Bun<"u"?Bun.env[r]??e:e}var As=Object.freeze({get BETTER_AUTH_SECRET(){return b("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return b("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return b("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return b("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return b("NODE_ENV","development")},get PACKAGE_VERSION(){return b("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return b("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),Y=1,v=4,$=8,P=24,ft={eterm:v,cons25:v,console:v,cygwin:v,dtterm:v,gnome:v,hurd:v,jfbterm:v,konsole:v,kterm:v,mlterm:v,mosh:P,putty:v,st:v,"rxvt-unicode-24bit":P,terminator:P,"xterm-kitty":P},Er=new Map(Object.entries({APPVEYOR:$,BUILDKITE:$,CIRCLECI:P,DRONE:$,GITEA_ACTIONS:P,GITHUB_ACTIONS:P,GITLAB_CI:$,TRAVIS:$})),vr=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function Tr(){if(b("FORCE_COLOR")!==void 0)switch(b("FORCE_COLOR")){case"":case"1":case"true":return v;case"2":return $;case"3":return P;default:return Y}if(b("NODE_DISABLE_COLORS")!==void 0&&b("NODE_DISABLE_COLORS")!==""||b("NO_COLOR")!==void 0&&b("NO_COLOR")!==""||b("TERM")==="dumb")return Y;if(b("TMUX"))return P;if("TF_BUILD"in A&&"AGENT_NAME"in A)return v;if("CI"in A){for(let{0:r,1:e}of Er)if(r in A)return e;return b("CI_NAME")==="codeship"?$:Y}if("TEAMCITY_VERSION"in A)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(b("TEAMCITY_VERSION"))!==null?v:Y;switch(b("TERM_PROGRAM")){case"iTerm.app":return!b("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(b("TERM_PROGRAM_VERSION"))!==null?$:P;case"HyperTerm":case"MacTerm":return P;case"Apple_Terminal":return $}if(b("COLORTERM")==="truecolor"||b("COLORTERM")==="24bit")return P;if(b("TERM")){if(/truecolor/.exec(b("TERM"))!==null)return P;if(/^xterm-256/.exec(b("TERM"))!==null)return $;let r=b("TERM").toLowerCase();if(ft[r])return ft[r];if(vr.some(e=>e.exec(r)!==null))return v}return b("COLORTERM")?v:Y}var D={reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",undim:"\x1B[22m",underscore:"\x1B[4m",blink:"\x1B[5m",reverse:"\x1B[7m",hidden:"\x1B[8m",fg:{black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"},bg:{black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m"}},Ie=["info","success","warn","error","debug"];function Sr(r,e){return Ie.indexOf(e)<=Ie.indexOf(r)}var _r={info:D.fg.blue,success:D.fg.green,warn:D.fg.yellow,error:D.fg.red,debug:D.fg.magenta},Pr=(r,e,t)=>{let s=new Date().toISOString();return t?`${D.dim}${s}${D.reset} ${_r[r]}${r.toUpperCase()}${D.reset} ${D.bright}[Better Auth]:${D.reset} ${e}`:`${s} ${r.toUpperCase()} [Better Auth]: ${e}`},Ar=r=>{let e=r?.disabled!==!0,t=r?.level??"error",n=r?.disableColors!==void 0?!r.disableColors:Tr()!==1,o=(c,d,u=[])=>{if(!e||!Sr(t,c))return;let l=Pr(c,d,n);if(!r||typeof r.log!="function"){c==="error"?console.error(l,...u):c==="warn"?console.warn(l,...u):console.log(l,...u);return}r.log(c==="success"?"info":c,d,...u)};return{...Object.fromEntries(Ie.map(c=>[c,(...[d,...u])=>o(c,d,u)])),get level(){return t}}},Os=Ar();a();a();var $s={USER_NOT_FOUND:"User not found",FAILED_TO_CREATE_USER:"Failed to create user",FAILED_TO_CREATE_SESSION:"Failed to create session",FAILED_TO_UPDATE_USER:"Failed to update user",FAILED_TO_GET_SESSION:"Failed to get session",INVALID_PASSWORD:"Invalid password",INVALID_EMAIL:"Invalid email",INVALID_EMAIL_OR_PASSWORD:"Invalid email or password",SOCIAL_ACCOUNT_ALREADY_LINKED:"Social account already linked",PROVIDER_NOT_FOUND:"Provider not found",INVALID_TOKEN:"Invalid token",ID_TOKEN_NOT_SUPPORTED:"id_token not supported",FAILED_TO_GET_USER_INFO:"Failed to get user info",USER_EMAIL_NOT_FOUND:"User email not found",EMAIL_NOT_VERIFIED:"Email not verified",PASSWORD_TOO_SHORT:"Password too short",PASSWORD_TOO_LONG:"Password too long",USER_ALREADY_EXISTS:"User already exists.",USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:"User already exists. Use another email.",EMAIL_CAN_NOT_BE_UPDATED:"Email can not be updated",CREDENTIAL_ACCOUNT_NOT_FOUND:"Credential account not found",SESSION_EXPIRED:"Session expired. Re-authenticate to perform this action.",FAILED_TO_UNLINK_LAST_ACCOUNT:"You can't unlink your last account",ACCOUNT_NOT_FOUND:"Account not found",USER_ALREADY_HAS_PASSWORD:"User already has a password. Provide that to delete the account."},W=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function Or(r){try{return(new URL(r).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new W(`Invalid base URL: ${r}. Please provide a valid base URL.`)}}function Q(r,e="/api/auth"){if(Or(r))return r;let s=r.replace(/\/+$/,"");return!e||e==="/"?s:(e=e.startsWith("/")?e:`/${e}`,`${s}${e}`)}function pt(r,e,t,s){if(r)return Q(r,e);if(s!==!1){let i=A.BETTER_AUTH_URL||A.NEXT_PUBLIC_BETTER_AUTH_URL||A.PUBLIC_BETTER_AUTH_URL||A.NUXT_PUBLIC_BETTER_AUTH_URL||A.NUXT_PUBLIC_AUTH_URL||(A.BASE_URL!=="/"?A.BASE_URL:void 0);if(i)return Q(i,e)}let n=t?.headers.get("x-forwarded-host"),o=t?.headers.get("x-forwarded-proto");if(n&&o)return Q(`${o}://${n}`,e);if(t){let i=Ur(t.url);if(!i)throw new W("Could not get origin from request. Please provide a valid base URL.");return Q(i,e)}if(typeof window<"u"&&window.location)return Q(window.location.origin,e)}function Ur(r){try{return new URL(r).origin}catch{return null}}a();a();a();var X=Symbol("clean");var C=[],H=0,Re=4,Ir=0,Z=r=>{let e=[],t={get(){return t.lc||t.listen(()=>{})(),t.value},lc:0,listen(s){return t.lc=e.push(s),()=>{for(let o=H+Re;o<C.length;)C[o]===s?C.splice(o,Re):o+=Re;let n=e.indexOf(s);~n&&(e.splice(n,1),--t.lc||t.off())}},notify(s,n){Ir++;let o=!C.length;for(let i of e)C.push(i,t.value,s,n);if(o){for(H=0;H<C.length;H+=Re)C[H](C[H+1],C[H+2],C[H+3]);C.length=0}},off(){},set(s){let n=t.value;n!==s&&(t.value=s,t.notify(n))},subscribe(s){let n=t.listen(s);return s(t.value),n},value:r};return process.env.NODE_ENV!=="production"&&(t[X]=()=>{e=[],t.lc=0,t.off()}),t};a();var xr=5,G=6,we=10,Cr=(r,e,t,s)=>(r.events=r.events||{},r.events[t+we]||(r.events[t+we]=s(n=>{r.events[t].reduceRight((o,i)=>(i(o),o),{shared:{},...n})})),r.events[t]=r.events[t]||[],r.events[t].push(e),()=>{let n=r.events[t],o=n.indexOf(e);n.splice(o,1),n.length||(delete r.events[t],r.events[t+we](),delete r.events[t+we])});var mt=1e3,xe=(r,e)=>Cr(r,s=>{let n=e(s);n&&r.events[G].push(n)},xr,s=>{let n=r.listen;r.listen=(...i)=>(!r.lc&&!r.active&&(r.active=!0,s()),n(...i));let o=r.off;if(r.events[G]=[],r.off=()=>{o(),setTimeout(()=>{if(r.active&&!r.lc){r.active=!1;for(let i of r.events[G])i();r.events[G]=[]}},mt)},process.env.NODE_ENV!=="production"){let i=r[X];r[X]=()=>{for(let c of r.events[G])c();r.events[G]=[],r.active=!1,i()}}return()=>{r.listen=n,r.off=o}});a();var Nr=typeof window>"u",Ee=(r,e,t,s)=>{let n=Z({data:null,error:null,isPending:!0,isRefetching:!1,refetch:c=>o(c)}),o=c=>{let d=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;t(e,{...d,query:{...d?.query,...c?.query},async onSuccess(u){n.set({data:u.data,error:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onSuccess?.(u)},async onError(u){let{request:l}=u,h=typeof l.retry=="number"?l.retry:l.retry?.attempts,p=l.retryAttempt||0;h&&p<h||(n.set({error:u.error,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onError?.(u))},async onRequest(u){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0,refetch:n.value.refetch}),await d?.onRequest?.(u)}}).catch(u=>{n.set({error:u,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch})})};r=Array.isArray(r)?r:[r];let i=!1;for(let c of r)c.subscribe(()=>{Nr||(i?o():xe(n,()=>{let d=setTimeout(()=>{i||(o(),i=!0)},0);return()=>{n.off(),c.off(),clearTimeout(d)}}))});return n};a();var Lr={proto:/"(?:_|\\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*:/,constructor:/"(?: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*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},$r=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,gt={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Dr=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function kr(r){return r instanceof Date&&!isNaN(r.getTime())}function Mr(r){let e=Dr.exec(r);if(!e)return null;let[,t,s,n,o,i,c,d,u,l,h]=e,p=new Date(Date.UTC(parseInt(t,10),parseInt(s,10)-1,parseInt(n,10),parseInt(o,10),parseInt(i,10),parseInt(c,10),d?parseInt(d.padEnd(3,"0"),10):0));if(u){let R=(parseInt(l,10)*60+parseInt(h,10))*(u==="+"?-1:1);p.setUTCMinutes(p.getUTCMinutes()+R)}return kr(p)?p:null}function Br(r,e={}){let{strict:t=!1,warnings:s=!1,reviver:n,parseDates:o=!0}=e;if(typeof r!="string")return r;let i=r.trim();if(i.length>0&&i[0]==='"'&&i.endsWith('"')&&!i.slice(1,-1).includes('"'))return i.slice(1,-1);let c=i.toLowerCase();if(c.length<=9&&c in gt)return gt[c];if(!$r.test(i)){if(t)throw new SyntaxError("[better-json] Invalid JSON");return r}if(Object.entries(Lr).some(([u,l])=>{let h=l.test(i);return h&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),h})&&t)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(i,(l,h)=>{if(l==="__proto__"||l==="constructor"&&h&&typeof h=="object"&&"prototype"in h){s&&console.warn(`[better-json] Dropping "${l}" key to prevent prototype pollution`);return}if(o&&typeof h=="string"){let p=Mr(h);if(p)return p}return n?n(l,h):h})}catch(u){if(t)throw u;return r}}function yt(r,e={strict:!0}){return Br(r,e)}var jr={id:"redirect",name:"Redirect",hooks:{onSuccess(r){if(r.data?.url&&r.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=r.data.url}catch{}}}};function Fr(r){let e=Z(!1);return{session:Ee(e,"/get-session",r,{method:"GET"}),$sessionSignal:e}}var bt=(r,e)=>{let t="credentials"in Request.prototype,s=pt(r?.baseURL,r?.basePath,void 0,e)??"/api/auth",n=r?.plugins?.flatMap(m=>m.fetchPlugins).filter(m=>m!==void 0)||[],o={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:r?.fetchOptions?.onSuccess,onError:r?.fetchOptions?.onError,onRequest:r?.fetchOptions?.onRequest,onResponse:r?.fetchOptions?.onResponse}},{onSuccess:i,onError:c,onRequest:d,onResponse:u,...l}=r?.fetchOptions||{},h=ht({baseURL:s,...t?{credentials:"include"}:{},method:"GET",jsonParser(m){return m?yt(m,{strict:!1}):null},customFetchImpl:fetch,...l,plugins:[o,...l.plugins||[],...r?.disableDefaultFetchPlugins?[]:[jr],...n]}),{$sessionSignal:p,session:R}=Fr(h),E=r?.plugins||[],I={},y={$sessionSignal:p,session:R},O={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},_=[{signal:"$sessionSignal",matcher(m){return m==="/sign-out"||m==="/update-user"||m.startsWith("/sign-in")||m.startsWith("/sign-up")||m==="/delete-user"||m==="/verify-email"}}];for(let m of E)m.getAtoms&&Object.assign(y,m.getAtoms?.(h)),m.pathMethods&&Object.assign(O,m.pathMethods),m.atomListeners&&_.push(...m.atomListeners);let M={notify:m=>{y[m].set(!y[m].get())},listen:(m,q)=>{y[m].subscribe(q)},atoms:y};for(let m of E)m.getActions&&Object.assign(I,m.getActions?.(h,M,r));return{get baseURL(){return s},pluginsActions:I,pluginsAtoms:y,pluginPathMethods:O,atomListeners:_,$fetch:h,$store:M}};function Hr(r){return typeof r=="object"&&r!==null&&"get"in r&&typeof r.get=="function"&&"lc"in r&&typeof r.lc=="number"}function qr(r,e,t){let s=e[r],{fetchOptions:n,query:o,...i}=t||{};return s||(n?.method?n.method:i&&Object.keys(i).length>0?"POST":"GET")}function Rt(r,e,t,s,n){function o(i=[]){return new Proxy(function(){},{get(c,d){if(typeof d!="string"||d==="then"||d==="catch"||d==="finally")return;let u=[...i,d],l=r;for(let h of u)if(l&&typeof l=="object"&&h in l)l=l[h];else{l=void 0;break}return typeof l=="function"||Hr(l)?l:o(u)},apply:async(c,d,u)=>{let l="/"+i.map(_=>_.replace(/[A-Z]/g,M=>`-${M.toLowerCase()}`)).join("/"),h=u[0]||{},p=u[1]||{},{query:R,fetchOptions:E,...I}=h,y={...p,...E},O=qr(l,t,h);return await e(l,{...y,body:O==="GET"?void 0:{...I,...y?.body||{}},query:R||y?.query,method:O,async onSuccess(_){if(await y?.onSuccess?.(_),!n)return;let M=n.filter(m=>m.matcher(l));if(M.length)for(let m of M){let q=s[m.signal];if(!q)return;let w=q.get();setTimeout(()=>{q.set(!w)},10)}}})}})}return o()}a();function wt(r){return r.charAt(0).toUpperCase()+r.slice(1)}function Ce(r){let{pluginPathMethods:e,pluginsActions:t,pluginsAtoms:s,$fetch:n,atomListeners:o,$store:i}=bt(r),c={};for(let[l,h]of Object.entries(s))c[`use${wt(l)}`]=h;let d={...t,...c,$fetch:n,$store:i};return Rt(d,n,e,s,o)}a();a();a();function Wr(r){return{authorize(e,t="AND"){let s=!1;for(let[n,o]of Object.entries(e)){let i=r[n];if(!i)return{success:!1,error:`You are not allowed to access resource: ${n}`};if(Array.isArray(o))s=o.every(c=>i.includes(c));else if(typeof o=="object"){let c=o;c.connector==="OR"?s=c.actions.some(d=>i.includes(d)):s=c.actions.every(d=>i.includes(d))}else throw new W("Invalid access control request");if(s&&t==="OR")return{success:s};if(!s&&t==="AND")return{success:!1,error:`unauthorized to access resource "${n}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:r}}function ve(r){return{newRole(e){return Wr(e)},statements:r}}var Gr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},Ne=ve(Gr),zr=Ne.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),Vr=Ne.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),Kr=Ne.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});a();a();a();a();a();a();a();a();a();a();a();var Le=class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let t=new Error("Cancelling existing WebAuthn API call for new one");t.name="AbortError",this.controller.abort(t)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=new Error("Manually cancelling existing WebAuthn API call");e.name="AbortError",this.controller.abort(e),this.controller=void 0}}},Tt=new Le;a();a();a();a();a();a();a();a();var Zr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},St=ve(Zr),es=St.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),ts=St.newRole({user:[],session:[]});a();a();var _t=()=>({id:"username",$InferServerPlugin:{}});var rs="/auth",ee="nvwa_login_token",Te="nvwa_user_profile",De=class{constructor(e,t,s){this.storage=s,this.authClient=Ce({baseUrl:e,fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:()=>s.get(ee)},onSuccess:n=>{let o=n.response.headers.get("set-auth-token");o&&s.set(ee,o)}},plugins:[_t()]})}async currentUser(){return await this.storage.get(Te)}async signUp(e,t){let s=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:t});this.saveSession(s)}async signInWithUsername(e,t){let s=await this.authClient.signIn.username({username:e,password:t});this.saveSession(s)}saveSession(e){if(e.error)throw new Error(e.error.message);this.storage.set(ee,e.data?.token),this.storage.set(Te,e.data?.user)}async signOut(){await this.storage.remove(ee),await this.storage.remove(Te)}async updateUserPassword(e,t,s=!1){let n=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:s});this.saveSession(n)}};a();var ke=class{constructor(e){this.http=e}async invoke(e,t){return(await this.http.request("/functions/"+e,{method:t.method||"POST",data:t.body,headers:t.headers})).body}};a();var Me=class{constructor(e,t,s,n,o){this.ok=e,this.status=t,this.statusText=s,this.headers=n,this.body=o}async text(){return typeof this.body=="string"?this.body:JSON.stringify(this.body)}async json(){if(typeof this.body=="string")try{return JSON.parse(this.body)}catch{return this.body}return this.body}async arrayBuffer(){if(this.body instanceof ArrayBuffer)return this.body;if(typeof this.body=="string")return new TextEncoder().encode(this.body).buffer;throw new Error("Cannot convert body to ArrayBuffer")}async blob(){if(this.body instanceof Blob)return this.body;if(typeof this.body=="string")return new Blob([this.body],{type:this.headers["content-type"]||"text/plain"});throw new Error("Cannot convert body to Blob")}},Be=class{async jsonRequest(e,t){let s={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.request(e,s)}async jsonRequestWithAuth(e,t,s){let n={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.requestWithAuth(e,n,s)}};a();var Pt="/storage",At=Pt+"/generateUploadUrl",je=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.request(this.baseUrl+At,{method:"POST",data:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:s}=t.body;if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");return{url:(await this.http.request(s,{method:"PUT",data:e,headers:{"Content-Type":e.type||e.fileType||"application/octet-stream"}})).body.url.split("?")[0]}}};a();a();a();var Mt=Qt(kt(),1),{PostgrestClient:Bt,PostgrestQueryBuilder:ii,PostgrestFilterBuilder:li,PostgrestTransformBuilder:ci,PostgrestBuilder:ui,PostgrestError:di,FetchHeaders:hi,FetchResponse:et,PostgrestFetch:fi,URL:pi,URLSearchParams:mi}=Mt.default;var jt="/entities",fs=(r,e)=>async(s,n)=>{console.log("customFetch",s,n);let o;if(typeof s=="string")o=s;else if(s&&typeof s=="object")if(typeof s.toString=="function"&&!s.url)o=s.toString();else if(s.url)o=s.url,n||(n={}),n.method=s.method,n.headers=s.headers,n.body=s.body;else throw new Error("Unsupported input type for fetch");else throw new Error("Unsupported input type for fetch");let i=(n?.method||"GET").toUpperCase(),c={};if(n?.headers)if(n.headers&&typeof n.headers.forEach=="function")n.headers.forEach((R,E)=>{c[E]=R});else if(Array.isArray(n.headers))for(let[R,E]of n.headers)c[R]=E;else Object.assign(c,n.headers);let d=n?.body,u;try{u=await r.requestWithAuth(o,{method:i,data:d,headers:c},e)}catch(R){return new et(R?.message||"Internal Error",{status:500,statusText:"Internal Error"})}let l=u.body,h=null;return(u.headers["content-type"]||u.headers["Content-Type"]||"").startsWith("application/json")&&typeof l!="string"?h=JSON.stringify(l):typeof l=="string"||l&&(l.constructor===Blob||l.constructor===ArrayBuffer||typeof l.getReader=="function")?h=l:h=JSON.stringify(l),new et(h,{status:u.status,headers:u.headers})},ps=(r,e,t)=>new Bt(r+jt,{fetch:fs(e,t)});a();a();var N=class r{constructor(e){this.headerMap=new Map;if(e){if(e instanceof r)e.forEach((t,s)=>this.set(s,t));else if(Array.isArray(e))for(let[t,s]of e)this.set(t,String(s));else if(typeof e=="object")for(let t of Object.keys(e))this.set(t,String(e[t]))}}append(e,t){let s=e.toLowerCase(),n=this.headerMap.get(s);this.headerMap.set(s,n?`${n}, ${t}`:t)}set(e,t){this.headerMap.set(e.toLowerCase(),String(t))}get(e){let t=this.headerMap.get(e.toLowerCase());return t??null}has(e){return this.headerMap.has(e.toLowerCase())}delete(e){this.headerMap.delete(e.toLowerCase())}forEach(e){for(let[t,s]of this.headerMap.entries())e(s,t,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}},V=class r{constructor(e){this.params=new Map;if(e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}},de=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new V(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let I=d[1];h=d[2];let y=I.match(/^([^:]*):?(.*)$/);y&&(u=y[1]||"",l=y[2]||"")}let p=h.match(/^([^:]+):?(\d*)$/),R=p?p[1]:h,E=p&&p[2]?p[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:R,port:E,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};a();var he=class r{constructor(e,t){if(typeof e=="string")this.url=e;else if(e?.url)this.url=String(e.url);else if(typeof e?.toString=="function")this.url=String(e.toString());else throw new Error("Invalid input for Request");this.method=(t?.method||"GET").toUpperCase(),this.headers=t?.headers instanceof N?t.headers:new N(t?.headers),this.body=t?.body,this.timeout=t?.timeout,this.signal=t?.signal||void 0}clone(){return new r(this.url,{method:this.method,headers:this.headers,body:this.body,timeout:this.timeout})}toString(){return this.url}};a();var fe=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=ms(t?.headers),this.ok=this.status>=200&&this.status<300}async text(){return typeof this.bodyData=="string"?this.bodyData:this.bodyData==null?"":typeof this.bodyData=="object"?JSON.stringify(this.bodyData):String(this.bodyData)}async json(){if(typeof this.bodyData=="string")try{return JSON.parse(this.bodyData)}catch{}return this.bodyData}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}};function ms(r){return r?new N(r):new N}a();var K=class{constructor(){this._aborted=!1;this.listeners=new Set;this.onabort=null}get aborted(){return this._aborted}_trigger(){if(!this._aborted){if(this._aborted=!0,typeof this.onabort=="function")try{this.onabort()}catch{}for(let e of Array.from(this.listeners))try{e()}catch{}this.listeners.clear()}}addEventListener(e,t){if(this._aborted){try{t()}catch{}return}this.listeners.add(t)}removeEventListener(e,t){this.listeners.delete(t)}toString(){return"[object AbortSignal]"}},pe=class{constructor(){this._signal=new K}get signal(){return this._signal}abort(){this._signal._trigger()}toString(){return"[object AbortController]"}};a();function gs(r){r.URL=de,r.URLSearchParams=V,r.Headers=N,r.Request=he,r.Response=fe,r.AbortController=pe,r.AbortSignal=K}0&&(module.exports={AUTH_BASE_PATH,AbortController,AbortSignal,ENTITIES_BASE_PATH,FILE_STORAGE_BASE_PATH,FetchResponse,GENERATE_UPLOAD_URL_PATH,Headers,LOGIN_TOKEN_KEY,LOGIN_USER_PROFILE_KEY,NvwaAuthClient,NvwaEdgeFunctions,NvwaFileStorage,NvwaHttpClient,Request,Response,URL,URLSearchParams,createPostgrestClient,polyfill});
|
|
1
|
+
"use strict";var Gt=Object.create;var ge=Object.defineProperty;var zt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Kt=Object.getPrototypeOf,Jt=Object.prototype.hasOwnProperty;var Yt=(r,e)=>()=>(r&&(e=r(r=0)),e);var F=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Qt=(r,e)=>{for(var t in e)ge(r,t,{get:e[t],enumerable:!0})},st=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Vt(e))!Jt.call(r,n)&&n!==t&&ge(r,n,{get:()=>e[n],enumerable:!(s=zt(e,n))||s.enumerable});return r};var Xt=(r,e,t)=>(t=r!=null?Gt(Kt(r)):{},st(e||!r||!r.__esModule?ge(t,"default",{value:r,enumerable:!0}):t,r)),Zt=r=>st(ge({},"__esModule",{value:!0}),r);var a=Yt(()=>{"use strict"});var se=F(T=>{"use strict";a();Object.defineProperty(T,"__esModule",{value:!0});T.File=T.FormData=T.Blob=T.FetchResponse=T.URL=T.URLSearchParams=T.FetchHeaders=void 0;var te=class{constructor(e){if(this.map=new Map,e)for(let[t,s]of Object.entries(e))this.set(t,s)}get(e){var t;return(t=this.map.get(e))!==null&&t!==void 0?t:null}set(e,t){this.map.set(e,t)}has(e){return this.map.has(e)}append(e,t){let s=this.map.get(e);s?this.map.set(e,`${s}${t}`):this.map.set(e,t)}delete(e){this.map.delete(e)}forEach(e){this.map.forEach(e)}size(){return this.map.size}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}headers(){return Object.fromEntries(this.map.entries())}[Symbol.iterator](){return this.map[Symbol.iterator]()}};T.FetchHeaders=te;var Se=class r{constructor(e){if(this.params=new Map,e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}};T.URLSearchParams=Se;var _e=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new Se(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let I=d[1];h=d[2];let y=I.match(/^([^:]*):?(.*)$/);y&&(u=y[1]||"",l=y[2]||"")}let p=h.match(/^([^:]+):?(\d*)$/),R=p?p[1]:h,E=p&&p[2]?p[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:R,port:E,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};T.URL=_e;var Fe=class r{constructor(e,t){var s,n;this.status=(s=t?.status)!==null&&s!==void 0?s:200,this.statusText=(n=t?.statusText)!==null&&n!==void 0?n:"",this.headers=new te(t?.headers),this.ok=this.status>=200&&this.status<300,this.redirected=!1,this.url="",this.bodyUsed=!1,this.body=e||null}async arrayBuffer(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?new ArrayBuffer(0):new TextEncoder().encode(this.body).buffer}async blob(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new re([this.body||""])}async formData(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new Pe}async json(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?null:JSON.parse(this.body)}async text(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body||""}clone(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return new r(this.body,{status:this.status,statusText:this.statusText,headers:this.headers.headers()})}static error(){let e=new r(null,{status:0,statusText:""});return Object.defineProperty(e,"type",{value:"error",writable:!1}),e}static redirect(e,t=302){let s=e instanceof _e?e.href:e,n=new r(null,{status:t,statusText:"Found"});return n.headers.set("Location",s),n}static json(e,t){let s=JSON.stringify(e),n=new te(t?.headers);return n.set("Content-Type","application/json"),new r(s,Object.assign(Object.assign({},t),{headers:n.headers()}))}};T.FetchResponse=Fe;var re=class r{constructor(e,t){this._content=e||[],this.type=t?.type||"";let s=0;for(let n of this._content)typeof n=="string"?s+=new TextEncoder().encode(n).length:n instanceof ArrayBuffer?s+=n.byteLength:n instanceof Uint8Array&&(s+=n.length);this.size=s}async text(){let e="";for(let t of this._content)typeof t=="string"?e+=t:t instanceof ArrayBuffer?e+=new TextDecoder().decode(t):t instanceof Uint8Array&&(e+=new TextDecoder().decode(t));return e}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}slice(e,t,s){return new r(this._content.slice(e,t),{type:s})}};T.Blob=re;var Pe=class{constructor(){this._entries=[]}append(e,t,s){this._entries.push([e,t])}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}get(e){let t=this._entries.find(([s])=>s===e);return t?t[1]:null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,t])=>t)}has(e){return this._entries.some(([t])=>t===e)}set(e,t,s){this.delete(e),this.append(e,t,s)}forEach(e){for(let[t,s]of this._entries)e(s,t,this)}keys(){return this._entries.map(([e])=>e)[Symbol.iterator]()}values(){return this._entries.map(([,e])=>e)[Symbol.iterator]()}entries(){return this._entries[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}};T.FormData=Pe;var He=class extends re{constructor(e,t,s){super(e,s),this.name=t,this.lastModified=s?.lastModified||Date.now()}};T.File=He});var Ge=F(We=>{"use strict";a();Object.defineProperty(We,"__esModule",{value:!0});var qe=class extends Error{constructor(e){super(e.message),this.name="PostgrestError",this.details=e.details,this.hint=e.hint,this.code=e.code}};We.default=qe});var Ve=F(ne=>{"use strict";a();var ss=ne&&ne.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ne,"__esModule",{value:!0});var ns=ss(Ge()),Ut=se(),ze=class{constructor(e){var t,s;this.shouldThrowOnError=!1,this.method=e.method,this.url=e.url,this.headers=new Ut.FetchHeaders(e.headers),this.schema=e.schema,this.body=e.body,this.shouldThrowOnError=(t=e.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=e.signal,this.isMaybeSingle=(s=e.isMaybeSingle)!==null&&s!==void 0?s:!1,e.fetch?this.fetch=e.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers=new Ut.FetchHeaders(this.headers),this.headers.set(e,t),this}then(e,t){this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,n=s(this.url.toString(),{method:this.method,headers:this.headers.headers(),body:JSON.stringify(this.body),signal:this.signal}).then(async o=>{var i,c,d,u;let l=null,h=null,p=null,R=o.status,E=o.statusText;if(o.ok){if(this.method!=="HEAD"){let _=await o.text();_===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&(!((i=this.headers.get("Accept"))===null||i===void 0)&&i.includes("application/vnd.pgrst.plan+text"))?h=_:h=JSON.parse(_))}let y=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),O=(d=o.headers.get("content-range"))===null||d===void 0?void 0:d.split("/");y&&O&&O.length>1&&(p=parseInt(O[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(h)&&(h.length>1?(l={code:"PGRST116",details:`Results contain ${h.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},h=null,p=null,R=406,E="Not Acceptable"):h.length===1?h=h[0]:h=null)}else{let y=await o.text();try{l=JSON.parse(y),Array.isArray(l)&&o.status===404&&(h=[],l=null,R=200,E="OK")}catch{o.status===404&&y===""?(R=204,E="No Content"):l={message:y}}if(l&&this.isMaybeSingle&&(!((u=l?.details)===null||u===void 0)&&u.includes("0 rows"))&&(l=null,R=200,E="OK"),l&&this.shouldThrowOnError)throw new ns.default(l)}return{error:l,data:h,count:p,status:R,statusText:E}});return this.shouldThrowOnError||(n=n.catch(o=>{var i,c,d;return{error:{message:`${(i=o?.name)!==null&&i!==void 0?i:"FetchError"}: ${o?.message}`,details:`${(c=o?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(d=o?.code)!==null&&d!==void 0?d:""}`},data:null,count:null,status:0,statusText:""}})),n.then(e,t)}returns(){return this}overrideTypes(){return this}};ne.default=ze});var Je=F(oe=>{"use strict";a();var os=oe&&oe.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(oe,"__esModule",{value:!0});var as=os(Ve()),Ke=class extends as.default{select(e){let t=!1,s=(e??"*").split("").map(n=>/\s/.test(n)&&!t?"":(n==='"'&&(t=!t),n)).join("");return this.url.searchParams.set("select",s),this.headers.append("Prefer","return=representation"),this}order(e,{ascending:t=!0,nullsFirst:s,foreignTable:n,referencedTable:o=n}={}){let i=o?`${o}.order`:"order",c=this.url.searchParams.get(i);return this.url.searchParams.set(i,`${c?`${c},`:""}${e}.${t?"asc":"desc"}${s===void 0?"":s?".nullsfirst":".nullslast"}`),this}limit(e,{foreignTable:t,referencedTable:s=t}={}){let n=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(n,`${e}`),this}range(e,t,{foreignTable:s,referencedTable:n=s}={}){let o=typeof n>"u"?"offset":`${n}.offset`,i=typeof n>"u"?"limit":`${n}.limit`;return this.url.searchParams.set(o,`${e}`),this.url.searchParams.set(i,`${t-e+1}`),this}abortSignal(e){return this.signal=e,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.method==="GET"?this.headers.set("Accept","application/json"):this.headers.set("Accept","application/vnd.pgrst.object+json"),this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:e=!1,verbose:t=!1,settings:s=!1,buffers:n=!1,wal:o=!1,format:i="text"}={}){var c;let d=[e?"analyze":null,t?"verbose":null,s?"settings":null,n?"buffers":null,o?"wal":null].filter(Boolean).join("|"),u=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${i}; for="${u}"; options=${d};`),i==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(e){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${e}`),this}};oe.default=Ke});var Ae=F(ae=>{"use strict";a();var is=ae&&ae.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ae,"__esModule",{value:!0});var ls=is(Je()),Ye=class extends ls.default{eq(e,t){return this.url.searchParams.append(e,`eq.${t}`),this}neq(e,t){return this.url.searchParams.append(e,`neq.${t}`),this}gt(e,t){return this.url.searchParams.append(e,`gt.${t}`),this}gte(e,t){return this.url.searchParams.append(e,`gte.${t}`),this}lt(e,t){return this.url.searchParams.append(e,`lt.${t}`),this}lte(e,t){return this.url.searchParams.append(e,`lte.${t}`),this}like(e,t){return this.url.searchParams.append(e,`like.${t}`),this}likeAllOf(e,t){return this.url.searchParams.append(e,`like(all).{${t.join(",")}}`),this}likeAnyOf(e,t){return this.url.searchParams.append(e,`like(any).{${t.join(",")}}`),this}ilike(e,t){return this.url.searchParams.append(e,`ilike.${t}`),this}ilikeAllOf(e,t){return this.url.searchParams.append(e,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(e,t){return this.url.searchParams.append(e,`ilike(any).{${t.join(",")}}`),this}is(e,t){return this.url.searchParams.append(e,`is.${t}`),this}in(e,t){let s=Array.from(new Set(t)).map(n=>typeof n=="string"&&new RegExp("[,()]").test(n)?`"${n}"`:`${n}`).join(",");return this.url.searchParams.append(e,`in.(${s})`),this}contains(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cs.{${t.join(",")}}`):this.url.searchParams.append(e,`cs.${JSON.stringify(t)}`),this}containedBy(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cd.{${t.join(",")}}`):this.url.searchParams.append(e,`cd.${JSON.stringify(t)}`),this}rangeGt(e,t){return this.url.searchParams.append(e,`sr.${t}`),this}rangeGte(e,t){return this.url.searchParams.append(e,`nxl.${t}`),this}rangeLt(e,t){return this.url.searchParams.append(e,`sl.${t}`),this}rangeLte(e,t){return this.url.searchParams.append(e,`nxr.${t}`),this}rangeAdjacent(e,t){return this.url.searchParams.append(e,`adj.${t}`),this}overlaps(e,t){return typeof t=="string"?this.url.searchParams.append(e,`ov.${t}`):this.url.searchParams.append(e,`ov.{${t.join(",")}}`),this}textSearch(e,t,{config:s,type:n}={}){let o="";n==="plain"?o="pl":n==="phrase"?o="ph":n==="websearch"&&(o="w");let i=s===void 0?"":`(${s})`;return this.url.searchParams.append(e,`${o}fts${i}.${t}`),this}match(e){return Object.entries(e).forEach(([t,s])=>{this.url.searchParams.append(t,`eq.${s}`)}),this}not(e,t,s){return this.url.searchParams.append(e,`not.${t}.${s}`),this}or(e,{foreignTable:t,referencedTable:s=t}={}){let n=s?`${s}.or`:"or";return this.url.searchParams.append(n,`(${e})`),this}filter(e,t,s){return this.url.searchParams.append(e,`${t}.${s}`),this}};ae.default=Ye});var Xe=F(le=>{"use strict";a();var cs=le&&le.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(le,"__esModule",{value:!0});var us=se(),ie=cs(Ae()),Qe=class{constructor(e,{headers:t={},schema:s,fetch:n}){this.url=e,this.headers=new us.FetchHeaders(t),this.schema=s,this.fetch=n}select(e,t){let{head:s=!1,count:n}=t??{},o=s?"HEAD":"GET",i=!1,c=(e??"*").split("").map(d=>/\s/.test(d)&&!i?"":(d==='"'&&(i=!i),d)).join("");return this.url.searchParams.set("select",c),n&&this.headers.append("Prefer",`count=${n}`),new ie.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(e,{count:t,defaultToNull:s=!0}={}){var n;let o="POST";if(t&&this.headers.append("Prefer",`count=${t}`),s||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let i=e.reduce((c,d)=>c.concat(Object.keys(d)),[]);if(i.length>0){let c=[...new Set(i)].map(d=>`"${d}"`);this.url.searchParams.set("columns",c.join(","))}}return new ie.default({method:o,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}upsert(e,{onConflict:t,ignoreDuplicates:s=!1,count:n,defaultToNull:o=!0}={}){var i;let c="POST";if(this.headers.append("Prefer",`resolution=${s?"ignore":"merge"}-duplicates`),t!==void 0&&this.url.searchParams.set("on_conflict",t),n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let d=e.reduce((u,l)=>u.concat(Object.keys(l)),[]);if(d.length>0){let u=[...new Set(d)].map(l=>`"${l}"`);this.url.searchParams.set("columns",u.join(","))}}return new ie.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}update(e,{count:t}={}){var s;let n="PATCH";return t&&this.headers.append("Prefer",`count=${t}`),new ie.default({method:n,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch})}delete({count:e}={}){var t;let s="DELETE";return e&&this.headers.append("Prefer",`count=${e}`),new ie.default({method:s,url:this.url,headers:this.headers,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch})}};le.default=Qe});var xt=F(ue=>{"use strict";a();var It=ue&&ue.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ue,"__esModule",{value:!0});var ds=It(Xe()),hs=It(Ae()),ce=se(),Ze=class r{constructor(e,{headers:t={},schema:s,fetch:n}={}){this.url=e,this.headers=new ce.FetchHeaders(t),this.schemaName=s,this.fetch=n}from(e){let t=new ce.URL(`${this.url}/${e}`);return new ds.default(t,{headers:new ce.FetchHeaders(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(e){return new r(this.url,{headers:this.headers,schema:e,fetch:this.fetch})}rpc(e,t={},{head:s=!1,get:n=!1,count:o}={}){var i;let c,d=new ce.URL(`${this.url}/rpc/${e}`),u;s||n?(c=s?"HEAD":"GET",Object.entries(t).filter(([h,p])=>p!==void 0).map(([h,p])=>[h,Array.isArray(p)?`{${p.join(",")}}`:`${p}`]).forEach(([h,p])=>{d.searchParams.append(h,p)})):(c="POST",u=t);let l=new ce.FetchHeaders(this.headers);return o&&l.set("Prefer",`count=${o}`),new hs.default({method:c,url:d,headers:l,schema:this.schemaName,body:u,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}};ue.default=Ze});var Mt=F(g=>{"use strict";a();var z=g&&g.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(g,"__esModule",{value:!0});g.File=g.FormData=g.Blob=g.FetchResponse=g.FetchHeaders=g.URLSearchParams=g.URL=g.PostgrestError=g.PostgrestBuilder=g.PostgrestTransformBuilder=g.PostgrestFilterBuilder=g.PostgrestQueryBuilder=g.PostgrestClient=void 0;var Ct=z(xt());g.PostgrestClient=Ct.default;var Nt=z(Xe());g.PostgrestQueryBuilder=Nt.default;var Lt=z(Ae());g.PostgrestFilterBuilder=Lt.default;var $t=z(Je());g.PostgrestTransformBuilder=$t.default;var Dt=z(Ve());g.PostgrestBuilder=Dt.default;var kt=z(Ge());g.PostgrestError=kt.default;var k=se();Object.defineProperty(g,"FetchHeaders",{enumerable:!0,get:function(){return k.FetchHeaders}});Object.defineProperty(g,"FetchResponse",{enumerable:!0,get:function(){return k.FetchResponse}});Object.defineProperty(g,"URL",{enumerable:!0,get:function(){return k.URL}});Object.defineProperty(g,"URLSearchParams",{enumerable:!0,get:function(){return k.URLSearchParams}});Object.defineProperty(g,"Blob",{enumerable:!0,get:function(){return k.Blob}});Object.defineProperty(g,"FormData",{enumerable:!0,get:function(){return k.FormData}});Object.defineProperty(g,"File",{enumerable:!0,get:function(){return k.File}});g.default={PostgrestClient:Ct.default,PostgrestQueryBuilder:Nt.default,PostgrestFilterBuilder:Lt.default,PostgrestTransformBuilder:$t.default,PostgrestBuilder:Dt.default,PostgrestError:kt.default,URLSearchParams:k.URLSearchParams,FetchHeaders:k.FetchHeaders,FetchResponse:k.FetchResponse}});var ys={};Qt(ys,{AUTH_BASE_PATH:()=>Pt,AbortController:()=>pe,AbortSignal:()=>K,ENTITIES_BASE_PATH:()=>Ft,FILE_STORAGE_BASE_PATH:()=>At,FetchResponse:()=>Me,GENERATE_UPLOAD_URL_PATH:()=>Ot,Headers:()=>N,LOGIN_TOKEN_KEY:()=>ee,LOGIN_USER_PROFILE_KEY:()=>Te,NvwaAuthClient:()=>De,NvwaEdgeFunctions:()=>ke,NvwaFileStorage:()=>je,NvwaHttpClient:()=>Be,Request:()=>he,Response:()=>fe,URL:()=>de,URLSearchParams:()=>V,createPostgrestClient:()=>ps,polyfill:()=>gs});module.exports=Zt(ys);a();a();a();a();a();a();var er=Object.defineProperty,tr=Object.defineProperties,rr=Object.getOwnPropertyDescriptors,nt=Object.getOwnPropertySymbols,sr=Object.prototype.hasOwnProperty,nr=Object.prototype.propertyIsEnumerable,ot=(r,e,t)=>e in r?er(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,x=(r,e)=>{for(var t in e||(e={}))sr.call(e,t)&&ot(r,t,e[t]);if(nt)for(var t of nt(e))nr.call(e,t)&&ot(r,t,e[t]);return r},L=(r,e)=>tr(r,rr(e)),or=class extends Error{constructor(r,e,t){super(e||r.toString(),{cause:t}),this.status=r,this.statusText=e,this.error=t}},ar=async(r,e)=>{var t,s,n,o,i,c;let d=e||{},u={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:r,options:d,hooks:u};for(let l of e?.plugins||[]){if(l.init){let h=await((t=l.init)==null?void 0:t.call(l,r.toString(),e));d=h.options||d,r=h.url}u.onRequest.push((s=l.hooks)==null?void 0:s.onRequest),u.onResponse.push((n=l.hooks)==null?void 0:n.onResponse),u.onSuccess.push((o=l.hooks)==null?void 0:o.onSuccess),u.onError.push((i=l.hooks)==null?void 0:i.onError),u.onRetry.push((c=l.hooks)==null?void 0:c.onRetry)}return{url:r,options:d,hooks:u}},at=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(){return this.options.delay}},ir=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(r){return Math.min(this.options.maxDelay,this.options.baseDelay*2**r)}};function lr(r){if(typeof r=="number")return new at({type:"linear",attempts:r,delay:1e3});switch(r.type){case"linear":return new at(r);case"exponential":return new ir(r);default:throw new Error("Invalid retry strategy")}}var cr=async r=>{let e={},t=async s=>typeof s=="function"?await s():s;if(r?.auth){if(r.auth.type==="Bearer"){let s=await t(r.auth.token);if(!s)return e;e.authorization=`Bearer ${s}`}else if(r.auth.type==="Basic"){let s=t(r.auth.username),n=t(r.auth.password);if(!s||!n)return e;e.authorization=`Basic ${btoa(`${s}:${n}`)}`}else if(r.auth.type==="Custom"){let s=t(r.auth.value);if(!s)return e;e.authorization=`${t(r.auth.prefix)} ${s}`}}return e},ur=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function dr(r){let e=r.headers.get("content-type"),t=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let s=e.split(";").shift()||"";return ur.test(s)?"json":t.has(s)||s.startsWith("text/")?"text":"blob"}function hr(r){try{return JSON.parse(r),!0}catch{return!1}}function ct(r){if(r===void 0)return!1;let e=typeof r;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(r)?!0:r.buffer?!1:r.constructor&&r.constructor.name==="Object"||typeof r.toJSON=="function"}function it(r){try{return JSON.parse(r)}catch{return r}}function lt(r){return typeof r=="function"}function fr(r){if(r?.customFetchImpl)return r.customFetchImpl;if(typeof globalThis<"u"&<(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&<(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function pr(r){let e=new Headers(r?.headers),t=await cr(r);for(let[s,n]of Object.entries(t||{}))e.set(s,n);if(!e.has("content-type")){let s=mr(r?.body);s&&e.set("content-type",s)}return e}function mr(r){return ct(r)?"application/json":null}function gr(r){if(!r?.body)return null;let e=new Headers(r?.headers);if(ct(r.body)&&!e.has("content-type")){for(let[t,s]of Object.entries(r?.body))s instanceof Date&&(r.body[t]=s.toISOString());return JSON.stringify(r.body)}return r.body}function yr(r,e){var t;if(e?.method)return e.method.toUpperCase();if(r.startsWith("@")){let s=(t=r.split("@")[1])==null?void 0:t.split("/")[0];return dt.includes(s)?s.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function br(r,e){let t;return!r?.signal&&r?.timeout&&(t=setTimeout(()=>e?.abort(),r?.timeout)),{abortTimeout:t,clearTimeout:()=>{t&&clearTimeout(t)}}}var Rr=class ut extends Error{constructor(e,t){super(t||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,ut.prototype)}};async function ye(r,e){let t=await r["~standard"].validate(e);if(t.issues)throw new Rr(t.issues);return t.value}var dt=["get","post","put","patch","delete"];var wr=r=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(e,t){var s,n,o,i;let c=((n=(s=r.plugins)==null?void 0:s.find(d=>{var u;return(u=d.schema)!=null&&u.config?e.startsWith(d.schema.config.baseURL||"")||e.startsWith(d.schema.config.prefix||""):!1}))==null?void 0:n.schema)||r.schema;if(c){let d=e;(o=c.config)!=null&&o.prefix&&d.startsWith(c.config.prefix)&&(d=d.replace(c.config.prefix,""),c.config.baseURL&&(e=e.replace(c.config.prefix,c.config.baseURL))),(i=c.config)!=null&&i.baseURL&&d.startsWith(c.config.baseURL)&&(d=d.replace(c.config.baseURL,""));let u=c.schema[d];if(u){let l=L(x({},t),{method:u.method,output:u.output});return t?.disableValidation||(l=L(x({},l),{body:u.input?await ye(u.input,t?.body):t?.body,params:u.params?await ye(u.params,t?.params):t?.params,query:u.query?await ye(u.query,t?.query):t?.query})),{url:e,options:l}}}return{url:e,options:t}}}),ht=r=>{async function e(t,s){let n=L(x(x({},r),s),{plugins:[...r?.plugins||[],wr(r||{})]});if(r?.catchAllError)try{return await Ue(t,n)}catch(o){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:o}}}return await Ue(t,n)}return e};function Er(r,e){let{baseURL:t,params:s,query:n}=e||{query:{},params:{},baseURL:""},o=r.startsWith("http")?r.split("/").slice(0,3).join("/"):t||"";if(r.startsWith("@")){let h=r.toString().split("@")[1].split("/")[0];dt.includes(h)&&(r=r.replace(`@${h}/`,"/"))}o.endsWith("/")||(o+="/");let[i,c]=r.replace(o,"").split("?"),d=new URLSearchParams(c);for(let[h,p]of Object.entries(n||{}))p!=null&&d.set(h,String(p));if(s)if(Array.isArray(s)){let h=i.split("/").filter(p=>p.startsWith(":"));for(let[p,R]of h.entries()){let E=s[p];i=i.replace(R,E)}}else for(let[h,p]of Object.entries(s))i=i.replace(`:${h}`,String(p));i=i.split("/").map(encodeURIComponent).join("/"),i.startsWith("/")&&(i=i.slice(1));let u=d.toString();return u=u.length>0?`?${u}`.replace(/\+/g,"%20"):"",o.startsWith("http")?new URL(`${i}${u}`,o):`${o}${i}${u}`}var Ue=async(r,e)=>{var t,s,n,o,i,c,d,u;let{hooks:l,url:h,options:p}=await ar(r,e),R=fr(p),E=new AbortController,I=(t=p.signal)!=null?t:E.signal,y=Er(h,p),O=gr(p),_=await pr(p),M=yr(h,p),m=L(x({},p),{url:y,headers:_,body:O,method:M,signal:I});for(let U of l.onRequest)if(U){let S=await U(m);S instanceof Object&&(m=S)}("pipeTo"in m&&typeof m.pipeTo=="function"||typeof((s=e?.body)==null?void 0:s.pipe)=="function")&&("duplex"in m||(m.duplex="half"));let{clearTimeout:q}=br(p,E),w=await R(m.url,m);q();let tt={response:w,request:m};for(let U of l.onResponse)if(U){let S=await U(L(x({},tt),{response:(n=e?.hookOptions)!=null&&n.cloneResponse?w.clone():w}));S instanceof Response?w=S:S instanceof Object&&(w=S.response)}if(w.ok){if(!(m.method!=="HEAD"))return{data:"",error:null};let S=dr(w),B={data:"",response:w,request:m};if(S==="json"||S==="text"){let j=await w.text(),Wt=await((o=m.jsonParser)!=null?o:it)(j);B.data=Wt}else B.data=await w[S]();m?.output&&m.output&&!m.disableValidation&&(B.data=await ye(m.output,B.data));for(let j of l.onSuccess)j&&await j(L(x({},B),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?w.clone():w}));return e?.throw?B.data:{data:B.data,error:null}}let Ht=(c=e?.jsonParser)!=null?c:it,me=await w.text(),rt=hr(me),Oe=rt?await Ht(me):null,qt={response:w,responseText:me,request:m,error:L(x({},Oe),{status:w.status,statusText:w.statusText})};for(let U of l.onError)U&&await U(L(x({},qt),{response:(d=e?.hookOptions)!=null&&d.cloneResponse?w.clone():w}));if(e?.retry){let U=lr(e.retry),S=(u=e.retryAttempt)!=null?u:0;if(await U.shouldAttemptRetry(S,w)){for(let j of l.onRetry)j&&await j(tt);let B=U.getDelay(S);return await new Promise(j=>setTimeout(j,B)),await Ue(r,L(x({},e),{retryAttempt:S+1}))}}if(e?.throw)throw new or(w.status,w.statusText,rt?Oe:me);return{data:null,error:L(x({},Oe),{status:w.status,statusText:w.statusText})}};a();a();var be=Object.create(null),J=r=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(r?be:globalThis),A=new Proxy(be,{get(r,e){return J()[e]??be[e]},has(r,e){let t=J();return e in t||e in be},set(r,e,t){let s=J(!0);return s[e]=t,!0},deleteProperty(r,e){if(!e)return!1;let t=J(!0);return delete t[e],!0},ownKeys(){let r=J(!0);return Object.keys(r)}});var Ps=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function b(r,e){return typeof process<"u"&&process.env?process.env[r]??e:typeof Deno<"u"?Deno.env.get(r)??e:typeof Bun<"u"?Bun.env[r]??e:e}var As=Object.freeze({get BETTER_AUTH_SECRET(){return b("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return b("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return b("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return b("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return b("NODE_ENV","development")},get PACKAGE_VERSION(){return b("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return b("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),Y=1,v=4,$=8,P=24,ft={eterm:v,cons25:v,console:v,cygwin:v,dtterm:v,gnome:v,hurd:v,jfbterm:v,konsole:v,kterm:v,mlterm:v,mosh:P,putty:v,st:v,"rxvt-unicode-24bit":P,terminator:P,"xterm-kitty":P},vr=new Map(Object.entries({APPVEYOR:$,BUILDKITE:$,CIRCLECI:P,DRONE:$,GITEA_ACTIONS:P,GITHUB_ACTIONS:P,GITLAB_CI:$,TRAVIS:$})),Tr=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function Sr(){if(b("FORCE_COLOR")!==void 0)switch(b("FORCE_COLOR")){case"":case"1":case"true":return v;case"2":return $;case"3":return P;default:return Y}if(b("NODE_DISABLE_COLORS")!==void 0&&b("NODE_DISABLE_COLORS")!==""||b("NO_COLOR")!==void 0&&b("NO_COLOR")!==""||b("TERM")==="dumb")return Y;if(b("TMUX"))return P;if("TF_BUILD"in A&&"AGENT_NAME"in A)return v;if("CI"in A){for(let{0:r,1:e}of vr)if(r in A)return e;return b("CI_NAME")==="codeship"?$:Y}if("TEAMCITY_VERSION"in A)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(b("TEAMCITY_VERSION"))!==null?v:Y;switch(b("TERM_PROGRAM")){case"iTerm.app":return!b("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(b("TERM_PROGRAM_VERSION"))!==null?$:P;case"HyperTerm":case"MacTerm":return P;case"Apple_Terminal":return $}if(b("COLORTERM")==="truecolor"||b("COLORTERM")==="24bit")return P;if(b("TERM")){if(/truecolor/.exec(b("TERM"))!==null)return P;if(/^xterm-256/.exec(b("TERM"))!==null)return $;let r=b("TERM").toLowerCase();if(ft[r])return ft[r];if(Tr.some(e=>e.exec(r)!==null))return v}return b("COLORTERM")?v:Y}var D={reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",undim:"\x1B[22m",underscore:"\x1B[4m",blink:"\x1B[5m",reverse:"\x1B[7m",hidden:"\x1B[8m",fg:{black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"},bg:{black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m"}},Ie=["info","success","warn","error","debug"];function _r(r,e){return Ie.indexOf(e)<=Ie.indexOf(r)}var Pr={info:D.fg.blue,success:D.fg.green,warn:D.fg.yellow,error:D.fg.red,debug:D.fg.magenta},Ar=(r,e,t)=>{let s=new Date().toISOString();return t?`${D.dim}${s}${D.reset} ${Pr[r]}${r.toUpperCase()}${D.reset} ${D.bright}[Better Auth]:${D.reset} ${e}`:`${s} ${r.toUpperCase()} [Better Auth]: ${e}`},Or=r=>{let e=r?.disabled!==!0,t=r?.level??"error",n=r?.disableColors!==void 0?!r.disableColors:Sr()!==1,o=(c,d,u=[])=>{if(!e||!_r(t,c))return;let l=Ar(c,d,n);if(!r||typeof r.log!="function"){c==="error"?console.error(l,...u):c==="warn"?console.warn(l,...u):console.log(l,...u);return}r.log(c==="success"?"info":c,d,...u)};return{...Object.fromEntries(Ie.map(c=>[c,(...[d,...u])=>o(c,d,u)])),get level(){return t}}},Os=Or();a();a();var $s={USER_NOT_FOUND:"User not found",FAILED_TO_CREATE_USER:"Failed to create user",FAILED_TO_CREATE_SESSION:"Failed to create session",FAILED_TO_UPDATE_USER:"Failed to update user",FAILED_TO_GET_SESSION:"Failed to get session",INVALID_PASSWORD:"Invalid password",INVALID_EMAIL:"Invalid email",INVALID_EMAIL_OR_PASSWORD:"Invalid email or password",SOCIAL_ACCOUNT_ALREADY_LINKED:"Social account already linked",PROVIDER_NOT_FOUND:"Provider not found",INVALID_TOKEN:"Invalid token",ID_TOKEN_NOT_SUPPORTED:"id_token not supported",FAILED_TO_GET_USER_INFO:"Failed to get user info",USER_EMAIL_NOT_FOUND:"User email not found",EMAIL_NOT_VERIFIED:"Email not verified",PASSWORD_TOO_SHORT:"Password too short",PASSWORD_TOO_LONG:"Password too long",USER_ALREADY_EXISTS:"User already exists.",USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:"User already exists. Use another email.",EMAIL_CAN_NOT_BE_UPDATED:"Email can not be updated",CREDENTIAL_ACCOUNT_NOT_FOUND:"Credential account not found",SESSION_EXPIRED:"Session expired. Re-authenticate to perform this action.",FAILED_TO_UNLINK_LAST_ACCOUNT:"You can't unlink your last account",ACCOUNT_NOT_FOUND:"Account not found",USER_ALREADY_HAS_PASSWORD:"User already has a password. Provide that to delete the account."},W=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function Ur(r){try{return(new URL(r).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new W(`Invalid base URL: ${r}. Please provide a valid base URL.`)}}function Q(r,e="/api/auth"){if(Ur(r))return r;let s=r.replace(/\/+$/,"");return!e||e==="/"?s:(e=e.startsWith("/")?e:`/${e}`,`${s}${e}`)}function pt(r,e,t,s){if(r)return Q(r,e);if(s!==!1){let i=A.BETTER_AUTH_URL||A.NEXT_PUBLIC_BETTER_AUTH_URL||A.PUBLIC_BETTER_AUTH_URL||A.NUXT_PUBLIC_BETTER_AUTH_URL||A.NUXT_PUBLIC_AUTH_URL||(A.BASE_URL!=="/"?A.BASE_URL:void 0);if(i)return Q(i,e)}let n=t?.headers.get("x-forwarded-host"),o=t?.headers.get("x-forwarded-proto");if(n&&o)return Q(`${o}://${n}`,e);if(t){let i=Ir(t.url);if(!i)throw new W("Could not get origin from request. Please provide a valid base URL.");return Q(i,e)}if(typeof window<"u"&&window.location)return Q(window.location.origin,e)}function Ir(r){try{return new URL(r).origin}catch{return null}}a();a();a();var X=Symbol("clean");var C=[],H=0,Re=4,xr=0,Z=r=>{let e=[],t={get(){return t.lc||t.listen(()=>{})(),t.value},lc:0,listen(s){return t.lc=e.push(s),()=>{for(let o=H+Re;o<C.length;)C[o]===s?C.splice(o,Re):o+=Re;let n=e.indexOf(s);~n&&(e.splice(n,1),--t.lc||t.off())}},notify(s,n){xr++;let o=!C.length;for(let i of e)C.push(i,t.value,s,n);if(o){for(H=0;H<C.length;H+=Re)C[H](C[H+1],C[H+2],C[H+3]);C.length=0}},off(){},set(s){let n=t.value;n!==s&&(t.value=s,t.notify(n))},subscribe(s){let n=t.listen(s);return s(t.value),n},value:r};return process.env.NODE_ENV!=="production"&&(t[X]=()=>{e=[],t.lc=0,t.off()}),t};a();var Cr=5,G=6,we=10,Nr=(r,e,t,s)=>(r.events=r.events||{},r.events[t+we]||(r.events[t+we]=s(n=>{r.events[t].reduceRight((o,i)=>(i(o),o),{shared:{},...n})})),r.events[t]=r.events[t]||[],r.events[t].push(e),()=>{let n=r.events[t],o=n.indexOf(e);n.splice(o,1),n.length||(delete r.events[t],r.events[t+we](),delete r.events[t+we])});var mt=1e3,xe=(r,e)=>Nr(r,s=>{let n=e(s);n&&r.events[G].push(n)},Cr,s=>{let n=r.listen;r.listen=(...i)=>(!r.lc&&!r.active&&(r.active=!0,s()),n(...i));let o=r.off;if(r.events[G]=[],r.off=()=>{o(),setTimeout(()=>{if(r.active&&!r.lc){r.active=!1;for(let i of r.events[G])i();r.events[G]=[]}},mt)},process.env.NODE_ENV!=="production"){let i=r[X];r[X]=()=>{for(let c of r.events[G])c();r.events[G]=[],r.active=!1,i()}}return()=>{r.listen=n,r.off=o}});a();var Lr=typeof window>"u",Ee=(r,e,t,s)=>{let n=Z({data:null,error:null,isPending:!0,isRefetching:!1,refetch:c=>o(c)}),o=c=>{let d=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;t(e,{...d,query:{...d?.query,...c?.query},async onSuccess(u){n.set({data:u.data,error:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onSuccess?.(u)},async onError(u){let{request:l}=u,h=typeof l.retry=="number"?l.retry:l.retry?.attempts,p=l.retryAttempt||0;h&&p<h||(n.set({error:u.error,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onError?.(u))},async onRequest(u){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0,refetch:n.value.refetch}),await d?.onRequest?.(u)}}).catch(u=>{n.set({error:u,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch})})};r=Array.isArray(r)?r:[r];let i=!1;for(let c of r)c.subscribe(()=>{Lr||(i?o():xe(n,()=>{let d=setTimeout(()=>{i||(o(),i=!0)},0);return()=>{n.off(),c.off(),clearTimeout(d)}}))});return n};a();var $r={proto:/"(?:_|\\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*:/,constructor:/"(?: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*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},Dr=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,gt={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},kr=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Mr(r){return r instanceof Date&&!isNaN(r.getTime())}function Br(r){let e=kr.exec(r);if(!e)return null;let[,t,s,n,o,i,c,d,u,l,h]=e,p=new Date(Date.UTC(parseInt(t,10),parseInt(s,10)-1,parseInt(n,10),parseInt(o,10),parseInt(i,10),parseInt(c,10),d?parseInt(d.padEnd(3,"0"),10):0));if(u){let R=(parseInt(l,10)*60+parseInt(h,10))*(u==="+"?-1:1);p.setUTCMinutes(p.getUTCMinutes()+R)}return Mr(p)?p:null}function jr(r,e={}){let{strict:t=!1,warnings:s=!1,reviver:n,parseDates:o=!0}=e;if(typeof r!="string")return r;let i=r.trim();if(i.length>0&&i[0]==='"'&&i.endsWith('"')&&!i.slice(1,-1).includes('"'))return i.slice(1,-1);let c=i.toLowerCase();if(c.length<=9&&c in gt)return gt[c];if(!Dr.test(i)){if(t)throw new SyntaxError("[better-json] Invalid JSON");return r}if(Object.entries($r).some(([u,l])=>{let h=l.test(i);return h&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),h})&&t)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(i,(l,h)=>{if(l==="__proto__"||l==="constructor"&&h&&typeof h=="object"&&"prototype"in h){s&&console.warn(`[better-json] Dropping "${l}" key to prevent prototype pollution`);return}if(o&&typeof h=="string"){let p=Br(h);if(p)return p}return n?n(l,h):h})}catch(u){if(t)throw u;return r}}function yt(r,e={strict:!0}){return jr(r,e)}var Fr={id:"redirect",name:"Redirect",hooks:{onSuccess(r){if(r.data?.url&&r.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=r.data.url}catch{}}}};function Hr(r){let e=Z(!1);return{session:Ee(e,"/get-session",r,{method:"GET"}),$sessionSignal:e}}var bt=(r,e)=>{let t="credentials"in Request.prototype,s=pt(r?.baseURL,r?.basePath,void 0,e)??"/api/auth",n=r?.plugins?.flatMap(m=>m.fetchPlugins).filter(m=>m!==void 0)||[],o={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:r?.fetchOptions?.onSuccess,onError:r?.fetchOptions?.onError,onRequest:r?.fetchOptions?.onRequest,onResponse:r?.fetchOptions?.onResponse}},{onSuccess:i,onError:c,onRequest:d,onResponse:u,...l}=r?.fetchOptions||{},h=ht({baseURL:s,...t?{credentials:"include"}:{},method:"GET",jsonParser(m){return m?yt(m,{strict:!1}):null},customFetchImpl:fetch,...l,plugins:[o,...l.plugins||[],...r?.disableDefaultFetchPlugins?[]:[Fr],...n]}),{$sessionSignal:p,session:R}=Hr(h),E=r?.plugins||[],I={},y={$sessionSignal:p,session:R},O={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},_=[{signal:"$sessionSignal",matcher(m){return m==="/sign-out"||m==="/update-user"||m.startsWith("/sign-in")||m.startsWith("/sign-up")||m==="/delete-user"||m==="/verify-email"}}];for(let m of E)m.getAtoms&&Object.assign(y,m.getAtoms?.(h)),m.pathMethods&&Object.assign(O,m.pathMethods),m.atomListeners&&_.push(...m.atomListeners);let M={notify:m=>{y[m].set(!y[m].get())},listen:(m,q)=>{y[m].subscribe(q)},atoms:y};for(let m of E)m.getActions&&Object.assign(I,m.getActions?.(h,M,r));return{get baseURL(){return s},pluginsActions:I,pluginsAtoms:y,pluginPathMethods:O,atomListeners:_,$fetch:h,$store:M}};function qr(r){return typeof r=="object"&&r!==null&&"get"in r&&typeof r.get=="function"&&"lc"in r&&typeof r.lc=="number"}function Wr(r,e,t){let s=e[r],{fetchOptions:n,query:o,...i}=t||{};return s||(n?.method?n.method:i&&Object.keys(i).length>0?"POST":"GET")}function Rt(r,e,t,s,n){function o(i=[]){return new Proxy(function(){},{get(c,d){if(typeof d!="string"||d==="then"||d==="catch"||d==="finally")return;let u=[...i,d],l=r;for(let h of u)if(l&&typeof l=="object"&&h in l)l=l[h];else{l=void 0;break}return typeof l=="function"||qr(l)?l:o(u)},apply:async(c,d,u)=>{let l="/"+i.map(_=>_.replace(/[A-Z]/g,M=>`-${M.toLowerCase()}`)).join("/"),h=u[0]||{},p=u[1]||{},{query:R,fetchOptions:E,...I}=h,y={...p,...E},O=Wr(l,t,h);return await e(l,{...y,body:O==="GET"?void 0:{...I,...y?.body||{}},query:R||y?.query,method:O,async onSuccess(_){if(await y?.onSuccess?.(_),!n)return;let M=n.filter(m=>m.matcher(l));if(M.length)for(let m of M){let q=s[m.signal];if(!q)return;let w=q.get();setTimeout(()=>{q.set(!w)},10)}}})}})}return o()}a();function wt(r){return r.charAt(0).toUpperCase()+r.slice(1)}function Ce(r){let{pluginPathMethods:e,pluginsActions:t,pluginsAtoms:s,$fetch:n,atomListeners:o,$store:i}=bt(r),c={};for(let[l,h]of Object.entries(s))c[`use${wt(l)}`]=h;let d={...t,...c,$fetch:n,$store:i};return Rt(d,n,e,s,o)}a();a();a();function Gr(r){return{authorize(e,t="AND"){let s=!1;for(let[n,o]of Object.entries(e)){let i=r[n];if(!i)return{success:!1,error:`You are not allowed to access resource: ${n}`};if(Array.isArray(o))s=o.every(c=>i.includes(c));else if(typeof o=="object"){let c=o;c.connector==="OR"?s=c.actions.some(d=>i.includes(d)):s=c.actions.every(d=>i.includes(d))}else throw new W("Invalid access control request");if(s&&t==="OR")return{success:s};if(!s&&t==="AND")return{success:!1,error:`unauthorized to access resource "${n}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:r}}function ve(r){return{newRole(e){return Gr(e)},statements:r}}var zr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},Ne=ve(zr),Vr=Ne.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),Kr=Ne.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),Jr=Ne.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});a();a();a();a();a();a();a();a();a();a();a();var Le=class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let t=new Error("Cancelling existing WebAuthn API call for new one");t.name="AbortError",this.controller.abort(t)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=new Error("Manually cancelling existing WebAuthn API call");e.name="AbortError",this.controller.abort(e),this.controller=void 0}}},Tt=new Le;a();a();a();a();a();a();a();a();var es={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},St=ve(es),ts=St.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),rs=St.newRole({user:[],session:[]});a();a();var _t=()=>({id:"username",$InferServerPlugin:{}});var Pt="/auth",ee="nvwa_login_token",Te="nvwa_user_profile",De=class{constructor(e,t,s){this.storage=s,this.authClient=Ce({baseURL:e,basePath:Pt,fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:()=>s.get(ee)},onSuccess:n=>{let o=n.response.headers.get("set-auth-token");o&&s.set(ee,o)}},plugins:[_t()]})}async currentUser(){return await this.storage.get(Te)}async signUp(e,t){let s=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:t});this.saveSession(s)}async signInWithUsername(e,t){let s=await this.authClient.signIn.username({username:e,password:t});this.saveSession(s)}saveSession(e){if(e.error)throw new Error(e.error.message);this.storage.set(ee,e.data?.token),this.storage.set(Te,e.data?.user)}async signOut(){await this.storage.remove(ee),await this.storage.remove(Te)}async updateUserPassword(e,t,s=!1){let n=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:s});this.saveSession(n)}};a();var ke=class{constructor(e){this.http=e}async invoke(e,t){return(await this.http.request("/functions/"+e,{method:t.method||"POST",data:t.body,headers:t.headers})).body}};a();var Me=class{constructor(e,t,s,n,o){this.ok=e,this.status=t,this.statusText=s,this.headers=n,this.body=o}async text(){return typeof this.body=="string"?this.body:JSON.stringify(this.body)}async json(){if(typeof this.body=="string")try{return JSON.parse(this.body)}catch{return this.body}return this.body}async arrayBuffer(){if(this.body instanceof ArrayBuffer)return this.body;if(typeof this.body=="string")return new TextEncoder().encode(this.body).buffer;throw new Error("Cannot convert body to ArrayBuffer")}async blob(){if(this.body instanceof Blob)return this.body;if(typeof this.body=="string")return new Blob([this.body],{type:this.headers["content-type"]||"text/plain"});throw new Error("Cannot convert body to Blob")}},Be=class{async jsonRequest(e,t){let s={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.request(e,s)}async jsonRequestWithAuth(e,t,s){let n={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.requestWithAuth(e,n,s)}};a();var At="/storage",Ot=At+"/generateUploadUrl",je=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.request(this.baseUrl+Ot,{method:"POST",data:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:s}=t.body;if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");return{url:(await this.http.request(s,{method:"PUT",data:e,headers:{"Content-Type":e.type||e.fileType||"application/octet-stream"}})).body.url.split("?")[0]}}};a();a();a();var Bt=Xt(Mt(),1),{PostgrestClient:jt,PostgrestQueryBuilder:ii,PostgrestFilterBuilder:li,PostgrestTransformBuilder:ci,PostgrestBuilder:ui,PostgrestError:di,FetchHeaders:hi,FetchResponse:et,PostgrestFetch:fi,URL:pi,URLSearchParams:mi}=Bt.default;var Ft="/entities",fs=(r,e)=>async(s,n)=>{console.log("customFetch",s,n);let o;if(typeof s=="string")o=s;else if(s&&typeof s=="object")if(typeof s.toString=="function"&&!s.url)o=s.toString();else if(s.url)o=s.url,n||(n={}),n.method=s.method,n.headers=s.headers,n.body=s.body;else throw new Error("Unsupported input type for fetch");else throw new Error("Unsupported input type for fetch");let i=(n?.method||"GET").toUpperCase(),c={};if(n?.headers)if(n.headers&&typeof n.headers.forEach=="function")n.headers.forEach((R,E)=>{c[E]=R});else if(Array.isArray(n.headers))for(let[R,E]of n.headers)c[R]=E;else Object.assign(c,n.headers);let d=n?.body,u;try{u=await r.requestWithAuth(o,{method:i,data:d,headers:c},e)}catch(R){return new et(R?.message||"Internal Error",{status:500,statusText:"Internal Error"})}let l=u.body,h=null;return(u.headers["content-type"]||u.headers["Content-Type"]||"").startsWith("application/json")&&typeof l!="string"?h=JSON.stringify(l):typeof l=="string"||l&&(l.constructor===Blob||l.constructor===ArrayBuffer||typeof l.getReader=="function")?h=l:h=JSON.stringify(l),new et(h,{status:u.status,headers:u.headers})},ps=(r,e,t)=>new jt(r+Ft,{fetch:fs(e,t)});a();a();var N=class r{constructor(e){this.headerMap=new Map;if(e){if(e instanceof r)e.forEach((t,s)=>this.set(s,t));else if(Array.isArray(e))for(let[t,s]of e)this.set(t,String(s));else if(typeof e=="object")for(let t of Object.keys(e))this.set(t,String(e[t]))}}append(e,t){let s=e.toLowerCase(),n=this.headerMap.get(s);this.headerMap.set(s,n?`${n}, ${t}`:t)}set(e,t){this.headerMap.set(e.toLowerCase(),String(t))}get(e){let t=this.headerMap.get(e.toLowerCase());return t??null}has(e){return this.headerMap.has(e.toLowerCase())}delete(e){this.headerMap.delete(e.toLowerCase())}forEach(e){for(let[t,s]of this.headerMap.entries())e(s,t,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}},V=class r{constructor(e){this.params=new Map;if(e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}},de=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new V(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let I=d[1];h=d[2];let y=I.match(/^([^:]*):?(.*)$/);y&&(u=y[1]||"",l=y[2]||"")}let p=h.match(/^([^:]+):?(\d*)$/),R=p?p[1]:h,E=p&&p[2]?p[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:R,port:E,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};a();var he=class r{constructor(e,t){if(typeof e=="string")this.url=e;else if(e?.url)this.url=String(e.url);else if(typeof e?.toString=="function")this.url=String(e.toString());else throw new Error("Invalid input for Request");this.method=(t?.method||"GET").toUpperCase(),this.headers=t?.headers instanceof N?t.headers:new N(t?.headers),this.body=t?.body,this.timeout=t?.timeout,this.signal=t?.signal||void 0}clone(){return new r(this.url,{method:this.method,headers:this.headers,body:this.body,timeout:this.timeout})}toString(){return this.url}};a();var fe=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=ms(t?.headers),this.ok=this.status>=200&&this.status<300}async text(){return typeof this.bodyData=="string"?this.bodyData:this.bodyData==null?"":typeof this.bodyData=="object"?JSON.stringify(this.bodyData):String(this.bodyData)}async json(){if(typeof this.bodyData=="string")try{return JSON.parse(this.bodyData)}catch{}return this.bodyData}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}};function ms(r){return r?new N(r):new N}a();var K=class{constructor(){this._aborted=!1;this.listeners=new Set;this.onabort=null}get aborted(){return this._aborted}_trigger(){if(!this._aborted){if(this._aborted=!0,typeof this.onabort=="function")try{this.onabort()}catch{}for(let e of Array.from(this.listeners))try{e()}catch{}this.listeners.clear()}}addEventListener(e,t){if(this._aborted){try{t()}catch{}return}this.listeners.add(t)}removeEventListener(e,t){this.listeners.delete(t)}toString(){return"[object AbortSignal]"}},pe=class{constructor(){this._signal=new K}get signal(){return this._signal}abort(){this._signal._trigger()}toString(){return"[object AbortController]"}};a();function gs(r){r.URL=de,r.URLSearchParams=V,r.Headers=N,r.Request=he,r.Response=fe,r.AbortController=pe,r.AbortSignal=K}0&&(module.exports={AUTH_BASE_PATH,AbortController,AbortSignal,ENTITIES_BASE_PATH,FILE_STORAGE_BASE_PATH,FetchResponse,GENERATE_UPLOAD_URL_PATH,Headers,LOGIN_TOKEN_KEY,LOGIN_USER_PROFILE_KEY,NvwaAuthClient,NvwaEdgeFunctions,NvwaFileStorage,NvwaHttpClient,Request,Response,URL,URLSearchParams,createPostgrestClient,polyfill});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ft=Object.create;var Xe=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Wt=Object.getPrototypeOf,Gt=Object.prototype.hasOwnProperty;var zt=(r,e)=>()=>(r&&(e=r(r=0)),e);var H=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Vt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of qt(e))!Gt.call(r,n)&&n!==t&&Xe(r,n,{get:()=>e[n],enumerable:!(s=Ht(e,n))||s.enumerable});return r};var Kt=(r,e,t)=>(t=r!=null?Ft(Wt(r)):{},Vt(e||!r||!r.__esModule?Xe(t,"default",{value:r,enumerable:!0}):t,r));import gs from"path";import{fileURLToPath as bs}from"url";var a=zt(()=>{"use strict"});var te=H(_=>{"use strict";a();Object.defineProperty(_,"__esModule",{value:!0});_.File=_.FormData=_.Blob=_.FetchResponse=_.URL=_.URLSearchParams=_.FetchHeaders=void 0;var Z=class{constructor(e){if(this.map=new Map,e)for(let[t,s]of Object.entries(e))this.set(t,s)}get(e){var t;return(t=this.map.get(e))!==null&&t!==void 0?t:null}set(e,t){this.map.set(e,t)}has(e){return this.map.has(e)}append(e,t){let s=this.map.get(e);s?this.map.set(e,`${s}${t}`):this.map.set(e,t)}delete(e){this.map.delete(e)}forEach(e){this.map.forEach(e)}size(){return this.map.size}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}headers(){return Object.fromEntries(this.map.entries())}[Symbol.iterator](){return this.map[Symbol.iterator]()}};_.FetchHeaders=Z;var Re=class r{constructor(e){if(this.params=new Map,e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}};_.URLSearchParams=Re;var we=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new Re(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let x=d[1];h=d[2];let b=x.match(/^([^:]*):?(.*)$/);b&&(u=b[1]||"",l=b[2]||"")}let m=h.match(/^([^:]+):?(\d*)$/),w=m?m[1]:h,v=m&&m[2]?m[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:w,port:v,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};_.URL=we;var De=class r{constructor(e,t){var s,n;this.status=(s=t?.status)!==null&&s!==void 0?s:200,this.statusText=(n=t?.statusText)!==null&&n!==void 0?n:"",this.headers=new Z(t?.headers),this.ok=this.status>=200&&this.status<300,this.redirected=!1,this.url="",this.bodyUsed=!1,this.body=e||null}async arrayBuffer(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?new ArrayBuffer(0):new TextEncoder().encode(this.body).buffer}async blob(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new ee([this.body||""])}async formData(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new Ee}async json(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?null:JSON.parse(this.body)}async text(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body||""}clone(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return new r(this.body,{status:this.status,statusText:this.statusText,headers:this.headers.headers()})}static error(){let e=new r(null,{status:0,statusText:""});return Object.defineProperty(e,"type",{value:"error",writable:!1}),e}static redirect(e,t=302){let s=e instanceof we?e.href:e,n=new r(null,{status:t,statusText:"Found"});return n.headers.set("Location",s),n}static json(e,t){let s=JSON.stringify(e),n=new Z(t?.headers);return n.set("Content-Type","application/json"),new r(s,Object.assign(Object.assign({},t),{headers:n.headers()}))}};_.FetchResponse=De;var ee=class r{constructor(e,t){this._content=e||[],this.type=t?.type||"";let s=0;for(let n of this._content)typeof n=="string"?s+=new TextEncoder().encode(n).length:n instanceof ArrayBuffer?s+=n.byteLength:n instanceof Uint8Array&&(s+=n.length);this.size=s}async text(){let e="";for(let t of this._content)typeof t=="string"?e+=t:t instanceof ArrayBuffer?e+=new TextDecoder().decode(t):t instanceof Uint8Array&&(e+=new TextDecoder().decode(t));return e}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}slice(e,t,s){return new r(this._content.slice(e,t),{type:s})}};_.Blob=ee;var Ee=class{constructor(){this._entries=[]}append(e,t,s){this._entries.push([e,t])}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}get(e){let t=this._entries.find(([s])=>s===e);return t?t[1]:null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,t])=>t)}has(e){return this._entries.some(([t])=>t===e)}set(e,t,s){this.delete(e),this.append(e,t,s)}forEach(e){for(let[t,s]of this._entries)e(s,t,this)}keys(){return this._entries.map(([e])=>e)[Symbol.iterator]()}values(){return this._entries.map(([,e])=>e)[Symbol.iterator]()}entries(){return this._entries[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}};_.FormData=Ee;var ke=class extends ee{constructor(e,t,s){super(e,s),this.name=t,this.lastModified=s?.lastModified||Date.now()}};_.File=ke});var je=H(Be=>{"use strict";a();Object.defineProperty(Be,"__esModule",{value:!0});var Me=class extends Error{constructor(e){super(e.message),this.name="PostgrestError",this.details=e.details,this.hint=e.hint,this.code=e.code}};Be.default=Me});var He=H(re=>{"use strict";a();var es=re&&re.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(re,"__esModule",{value:!0});var ts=es(je()),Pt=te(),Fe=class{constructor(e){var t,s;this.shouldThrowOnError=!1,this.method=e.method,this.url=e.url,this.headers=new Pt.FetchHeaders(e.headers),this.schema=e.schema,this.body=e.body,this.shouldThrowOnError=(t=e.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=e.signal,this.isMaybeSingle=(s=e.isMaybeSingle)!==null&&s!==void 0?s:!1,e.fetch?this.fetch=e.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers=new Pt.FetchHeaders(this.headers),this.headers.set(e,t),this}then(e,t){this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,n=s(this.url.toString(),{method:this.method,headers:this.headers.headers(),body:JSON.stringify(this.body),signal:this.signal}).then(async o=>{var i,c,d,u;let l=null,h=null,m=null,w=o.status,v=o.statusText;if(o.ok){if(this.method!=="HEAD"){let P=await o.text();P===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&(!((i=this.headers.get("Accept"))===null||i===void 0)&&i.includes("application/vnd.pgrst.plan+text"))?h=P:h=JSON.parse(P))}let b=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),U=(d=o.headers.get("content-range"))===null||d===void 0?void 0:d.split("/");b&&U&&U.length>1&&(m=parseInt(U[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(h)&&(h.length>1?(l={code:"PGRST116",details:`Results contain ${h.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},h=null,m=null,w=406,v="Not Acceptable"):h.length===1?h=h[0]:h=null)}else{let b=await o.text();try{l=JSON.parse(b),Array.isArray(l)&&o.status===404&&(h=[],l=null,w=200,v="OK")}catch{o.status===404&&b===""?(w=204,v="No Content"):l={message:b}}if(l&&this.isMaybeSingle&&(!((u=l?.details)===null||u===void 0)&&u.includes("0 rows"))&&(l=null,w=200,v="OK"),l&&this.shouldThrowOnError)throw new ts.default(l)}return{error:l,data:h,count:m,status:w,statusText:v}});return this.shouldThrowOnError||(n=n.catch(o=>{var i,c,d;return{error:{message:`${(i=o?.name)!==null&&i!==void 0?i:"FetchError"}: ${o?.message}`,details:`${(c=o?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(d=o?.code)!==null&&d!==void 0?d:""}`},data:null,count:null,status:0,statusText:""}})),n.then(e,t)}returns(){return this}overrideTypes(){return this}};re.default=Fe});var We=H(se=>{"use strict";a();var rs=se&&se.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(se,"__esModule",{value:!0});var ss=rs(He()),qe=class extends ss.default{select(e){let t=!1,s=(e??"*").split("").map(n=>/\s/.test(n)&&!t?"":(n==='"'&&(t=!t),n)).join("");return this.url.searchParams.set("select",s),this.headers.append("Prefer","return=representation"),this}order(e,{ascending:t=!0,nullsFirst:s,foreignTable:n,referencedTable:o=n}={}){let i=o?`${o}.order`:"order",c=this.url.searchParams.get(i);return this.url.searchParams.set(i,`${c?`${c},`:""}${e}.${t?"asc":"desc"}${s===void 0?"":s?".nullsfirst":".nullslast"}`),this}limit(e,{foreignTable:t,referencedTable:s=t}={}){let n=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(n,`${e}`),this}range(e,t,{foreignTable:s,referencedTable:n=s}={}){let o=typeof n>"u"?"offset":`${n}.offset`,i=typeof n>"u"?"limit":`${n}.limit`;return this.url.searchParams.set(o,`${e}`),this.url.searchParams.set(i,`${t-e+1}`),this}abortSignal(e){return this.signal=e,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.method==="GET"?this.headers.set("Accept","application/json"):this.headers.set("Accept","application/vnd.pgrst.object+json"),this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:e=!1,verbose:t=!1,settings:s=!1,buffers:n=!1,wal:o=!1,format:i="text"}={}){var c;let d=[e?"analyze":null,t?"verbose":null,s?"settings":null,n?"buffers":null,o?"wal":null].filter(Boolean).join("|"),u=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${i}; for="${u}"; options=${d};`),i==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(e){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${e}`),this}};se.default=qe});var ve=H(ne=>{"use strict";a();var ns=ne&&ne.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ne,"__esModule",{value:!0});var os=ns(We()),Ge=class extends os.default{eq(e,t){return this.url.searchParams.append(e,`eq.${t}`),this}neq(e,t){return this.url.searchParams.append(e,`neq.${t}`),this}gt(e,t){return this.url.searchParams.append(e,`gt.${t}`),this}gte(e,t){return this.url.searchParams.append(e,`gte.${t}`),this}lt(e,t){return this.url.searchParams.append(e,`lt.${t}`),this}lte(e,t){return this.url.searchParams.append(e,`lte.${t}`),this}like(e,t){return this.url.searchParams.append(e,`like.${t}`),this}likeAllOf(e,t){return this.url.searchParams.append(e,`like(all).{${t.join(",")}}`),this}likeAnyOf(e,t){return this.url.searchParams.append(e,`like(any).{${t.join(",")}}`),this}ilike(e,t){return this.url.searchParams.append(e,`ilike.${t}`),this}ilikeAllOf(e,t){return this.url.searchParams.append(e,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(e,t){return this.url.searchParams.append(e,`ilike(any).{${t.join(",")}}`),this}is(e,t){return this.url.searchParams.append(e,`is.${t}`),this}in(e,t){let s=Array.from(new Set(t)).map(n=>typeof n=="string"&&new RegExp("[,()]").test(n)?`"${n}"`:`${n}`).join(",");return this.url.searchParams.append(e,`in.(${s})`),this}contains(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cs.{${t.join(",")}}`):this.url.searchParams.append(e,`cs.${JSON.stringify(t)}`),this}containedBy(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cd.{${t.join(",")}}`):this.url.searchParams.append(e,`cd.${JSON.stringify(t)}`),this}rangeGt(e,t){return this.url.searchParams.append(e,`sr.${t}`),this}rangeGte(e,t){return this.url.searchParams.append(e,`nxl.${t}`),this}rangeLt(e,t){return this.url.searchParams.append(e,`sl.${t}`),this}rangeLte(e,t){return this.url.searchParams.append(e,`nxr.${t}`),this}rangeAdjacent(e,t){return this.url.searchParams.append(e,`adj.${t}`),this}overlaps(e,t){return typeof t=="string"?this.url.searchParams.append(e,`ov.${t}`):this.url.searchParams.append(e,`ov.{${t.join(",")}}`),this}textSearch(e,t,{config:s,type:n}={}){let o="";n==="plain"?o="pl":n==="phrase"?o="ph":n==="websearch"&&(o="w");let i=s===void 0?"":`(${s})`;return this.url.searchParams.append(e,`${o}fts${i}.${t}`),this}match(e){return Object.entries(e).forEach(([t,s])=>{this.url.searchParams.append(t,`eq.${s}`)}),this}not(e,t,s){return this.url.searchParams.append(e,`not.${t}.${s}`),this}or(e,{foreignTable:t,referencedTable:s=t}={}){let n=s?`${s}.or`:"or";return this.url.searchParams.append(n,`(${e})`),this}filter(e,t,s){return this.url.searchParams.append(e,`${t}.${s}`),this}};ne.default=Ge});var Ve=H(ae=>{"use strict";a();var as=ae&&ae.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ae,"__esModule",{value:!0});var is=te(),oe=as(ve()),ze=class{constructor(e,{headers:t={},schema:s,fetch:n}){this.url=e,this.headers=new is.FetchHeaders(t),this.schema=s,this.fetch=n}select(e,t){let{head:s=!1,count:n}=t??{},o=s?"HEAD":"GET",i=!1,c=(e??"*").split("").map(d=>/\s/.test(d)&&!i?"":(d==='"'&&(i=!i),d)).join("");return this.url.searchParams.set("select",c),n&&this.headers.append("Prefer",`count=${n}`),new oe.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(e,{count:t,defaultToNull:s=!0}={}){var n;let o="POST";if(t&&this.headers.append("Prefer",`count=${t}`),s||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let i=e.reduce((c,d)=>c.concat(Object.keys(d)),[]);if(i.length>0){let c=[...new Set(i)].map(d=>`"${d}"`);this.url.searchParams.set("columns",c.join(","))}}return new oe.default({method:o,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}upsert(e,{onConflict:t,ignoreDuplicates:s=!1,count:n,defaultToNull:o=!0}={}){var i;let c="POST";if(this.headers.append("Prefer",`resolution=${s?"ignore":"merge"}-duplicates`),t!==void 0&&this.url.searchParams.set("on_conflict",t),n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let d=e.reduce((u,l)=>u.concat(Object.keys(l)),[]);if(d.length>0){let u=[...new Set(d)].map(l=>`"${l}"`);this.url.searchParams.set("columns",u.join(","))}}return new oe.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}update(e,{count:t}={}){var s;let n="PATCH";return t&&this.headers.append("Prefer",`count=${t}`),new oe.default({method:n,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch})}delete({count:e}={}){var t;let s="DELETE";return e&&this.headers.append("Prefer",`count=${e}`),new oe.default({method:s,url:this.url,headers:this.headers,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch})}};ae.default=ze});var Ot=H(le=>{"use strict";a();var At=le&&le.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(le,"__esModule",{value:!0});var ls=At(Ve()),cs=At(ve()),ie=te(),Ke=class r{constructor(e,{headers:t={},schema:s,fetch:n}={}){this.url=e,this.headers=new ie.FetchHeaders(t),this.schemaName=s,this.fetch=n}from(e){let t=new ie.URL(`${this.url}/${e}`);return new ls.default(t,{headers:new ie.FetchHeaders(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(e){return new r(this.url,{headers:this.headers,schema:e,fetch:this.fetch})}rpc(e,t={},{head:s=!1,get:n=!1,count:o}={}){var i;let c,d=new ie.URL(`${this.url}/rpc/${e}`),u;s||n?(c=s?"HEAD":"GET",Object.entries(t).filter(([h,m])=>m!==void 0).map(([h,m])=>[h,Array.isArray(m)?`{${m.join(",")}}`:`${m}`]).forEach(([h,m])=>{d.searchParams.append(h,m)})):(c="POST",u=t);let l=new ie.FetchHeaders(this.headers);return o&&l.set("Prefer",`count=${o}`),new cs.default({method:c,url:d,headers:l,schema:this.schemaName,body:u,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}};le.default=Ke});var $t=H(y=>{"use strict";a();var V=y&&y.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(y,"__esModule",{value:!0});y.File=y.FormData=y.Blob=y.FetchResponse=y.FetchHeaders=y.URLSearchParams=y.URL=y.PostgrestError=y.PostgrestBuilder=y.PostgrestTransformBuilder=y.PostgrestFilterBuilder=y.PostgrestQueryBuilder=y.PostgrestClient=void 0;var Ut=V(Ot());y.PostgrestClient=Ut.default;var It=V(Ve());y.PostgrestQueryBuilder=It.default;var xt=V(ve());y.PostgrestFilterBuilder=xt.default;var Ct=V(We());y.PostgrestTransformBuilder=Ct.default;var Nt=V(He());y.PostgrestBuilder=Nt.default;var Lt=V(je());y.PostgrestError=Lt.default;var k=te();Object.defineProperty(y,"FetchHeaders",{enumerable:!0,get:function(){return k.FetchHeaders}});Object.defineProperty(y,"FetchResponse",{enumerable:!0,get:function(){return k.FetchResponse}});Object.defineProperty(y,"URL",{enumerable:!0,get:function(){return k.URL}});Object.defineProperty(y,"URLSearchParams",{enumerable:!0,get:function(){return k.URLSearchParams}});Object.defineProperty(y,"Blob",{enumerable:!0,get:function(){return k.Blob}});Object.defineProperty(y,"FormData",{enumerable:!0,get:function(){return k.FormData}});Object.defineProperty(y,"File",{enumerable:!0,get:function(){return k.File}});y.default={PostgrestClient:Ut.default,PostgrestQueryBuilder:It.default,PostgrestFilterBuilder:xt.default,PostgrestTransformBuilder:Ct.default,PostgrestBuilder:Nt.default,PostgrestError:Lt.default,URLSearchParams:k.URLSearchParams,FetchHeaders:k.FetchHeaders,FetchResponse:k.FetchResponse}});a();a();a();a();a();a();var Jt=Object.defineProperty,Yt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertySymbols,Xt=Object.prototype.hasOwnProperty,Zt=Object.prototype.propertyIsEnumerable,et=(r,e,t)=>e in r?Jt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e)=>{for(var t in e||(e={}))Xt.call(e,t)&&et(r,t,e[t]);if(Ze)for(var t of Ze(e))Zt.call(e,t)&&et(r,t,e[t]);return r},L=(r,e)=>Yt(r,Qt(e)),er=class extends Error{constructor(r,e,t){super(e||r.toString(),{cause:t}),this.status=r,this.statusText=e,this.error=t}},tr=async(r,e)=>{var t,s,n,o,i,c;let d=e||{},u={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:r,options:d,hooks:u};for(let l of e?.plugins||[]){if(l.init){let h=await((t=l.init)==null?void 0:t.call(l,r.toString(),e));d=h.options||d,r=h.url}u.onRequest.push((s=l.hooks)==null?void 0:s.onRequest),u.onResponse.push((n=l.hooks)==null?void 0:n.onResponse),u.onSuccess.push((o=l.hooks)==null?void 0:o.onSuccess),u.onError.push((i=l.hooks)==null?void 0:i.onError),u.onRetry.push((c=l.hooks)==null?void 0:c.onRetry)}return{url:r,options:d,hooks:u}},tt=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(){return this.options.delay}},rr=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(r){return Math.min(this.options.maxDelay,this.options.baseDelay*2**r)}};function sr(r){if(typeof r=="number")return new tt({type:"linear",attempts:r,delay:1e3});switch(r.type){case"linear":return new tt(r);case"exponential":return new rr(r);default:throw new Error("Invalid retry strategy")}}var nr=async r=>{let e={},t=async s=>typeof s=="function"?await s():s;if(r?.auth){if(r.auth.type==="Bearer"){let s=await t(r.auth.token);if(!s)return e;e.authorization=`Bearer ${s}`}else if(r.auth.type==="Basic"){let s=t(r.auth.username),n=t(r.auth.password);if(!s||!n)return e;e.authorization=`Basic ${btoa(`${s}:${n}`)}`}else if(r.auth.type==="Custom"){let s=t(r.auth.value);if(!s)return e;e.authorization=`${t(r.auth.prefix)} ${s}`}}return e},or=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function ar(r){let e=r.headers.get("content-type"),t=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let s=e.split(";").shift()||"";return or.test(s)?"json":t.has(s)||s.startsWith("text/")?"text":"blob"}function ir(r){try{return JSON.parse(r),!0}catch{return!1}}function nt(r){if(r===void 0)return!1;let e=typeof r;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(r)?!0:r.buffer?!1:r.constructor&&r.constructor.name==="Object"||typeof r.toJSON=="function"}function rt(r){try{return JSON.parse(r)}catch{return r}}function st(r){return typeof r=="function"}function lr(r){if(r?.customFetchImpl)return r.customFetchImpl;if(typeof globalThis<"u"&&st(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&st(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function cr(r){let e=new Headers(r?.headers),t=await nr(r);for(let[s,n]of Object.entries(t||{}))e.set(s,n);if(!e.has("content-type")){let s=ur(r?.body);s&&e.set("content-type",s)}return e}function ur(r){return nt(r)?"application/json":null}function dr(r){if(!r?.body)return null;let e=new Headers(r?.headers);if(nt(r.body)&&!e.has("content-type")){for(let[t,s]of Object.entries(r?.body))s instanceof Date&&(r.body[t]=s.toISOString());return JSON.stringify(r.body)}return r.body}function hr(r,e){var t;if(e?.method)return e.method.toUpperCase();if(r.startsWith("@")){let s=(t=r.split("@")[1])==null?void 0:t.split("/")[0];return at.includes(s)?s.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function fr(r,e){let t;return!r?.signal&&r?.timeout&&(t=setTimeout(()=>e?.abort(),r?.timeout)),{abortTimeout:t,clearTimeout:()=>{t&&clearTimeout(t)}}}var pr=class ot extends Error{constructor(e,t){super(t||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,ot.prototype)}};async function he(r,e){let t=await r["~standard"].validate(e);if(t.issues)throw new pr(t.issues);return t.value}var at=["get","post","put","patch","delete"];var mr=r=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(e,t){var s,n,o,i;let c=((n=(s=r.plugins)==null?void 0:s.find(d=>{var u;return(u=d.schema)!=null&&u.config?e.startsWith(d.schema.config.baseURL||"")||e.startsWith(d.schema.config.prefix||""):!1}))==null?void 0:n.schema)||r.schema;if(c){let d=e;(o=c.config)!=null&&o.prefix&&d.startsWith(c.config.prefix)&&(d=d.replace(c.config.prefix,""),c.config.baseURL&&(e=e.replace(c.config.prefix,c.config.baseURL))),(i=c.config)!=null&&i.baseURL&&d.startsWith(c.config.baseURL)&&(d=d.replace(c.config.baseURL,""));let u=c.schema[d];if(u){let l=L(C({},t),{method:u.method,output:u.output});return t?.disableValidation||(l=L(C({},l),{body:u.input?await he(u.input,t?.body):t?.body,params:u.params?await he(u.params,t?.params):t?.params,query:u.query?await he(u.query,t?.query):t?.query})),{url:e,options:l}}}return{url:e,options:t}}}),it=r=>{async function e(t,s){let n=L(C(C({},r),s),{plugins:[...r?.plugins||[],mr(r||{})]});if(r?.catchAllError)try{return await Oe(t,n)}catch(o){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:o}}}return await Oe(t,n)}return e};function gr(r,e){let{baseURL:t,params:s,query:n}=e||{query:{},params:{},baseURL:""},o=r.startsWith("http")?r.split("/").slice(0,3).join("/"):t||"";if(r.startsWith("@")){let h=r.toString().split("@")[1].split("/")[0];at.includes(h)&&(r=r.replace(`@${h}/`,"/"))}o.endsWith("/")||(o+="/");let[i,c]=r.replace(o,"").split("?"),d=new URLSearchParams(c);for(let[h,m]of Object.entries(n||{}))m!=null&&d.set(h,String(m));if(s)if(Array.isArray(s)){let h=i.split("/").filter(m=>m.startsWith(":"));for(let[m,w]of h.entries()){let v=s[m];i=i.replace(w,v)}}else for(let[h,m]of Object.entries(s))i=i.replace(`:${h}`,String(m));i=i.split("/").map(encodeURIComponent).join("/"),i.startsWith("/")&&(i=i.slice(1));let u=d.toString();return u=u.length>0?`?${u}`.replace(/\+/g,"%20"):"",o.startsWith("http")?new URL(`${i}${u}`,o):`${o}${i}${u}`}var Oe=async(r,e)=>{var t,s,n,o,i,c,d,u;let{hooks:l,url:h,options:m}=await tr(r,e),w=lr(m),v=new AbortController,x=(t=m.signal)!=null?t:v.signal,b=gr(h,m),U=dr(m),P=await cr(m),B=hr(h,m),g=L(C({},m),{url:b,headers:P,body:U,method:B,signal:x});for(let I of l.onRequest)if(I){let S=await I(g);S instanceof Object&&(g=S)}("pipeTo"in g&&typeof g.pipeTo=="function"||typeof((s=e?.body)==null?void 0:s.pipe)=="function")&&("duplex"in g||(g.duplex="half"));let{clearTimeout:W}=fr(m,v),E=await w(g.url,g);W();let Ye={response:E,request:g};for(let I of l.onResponse)if(I){let S=await I(L(C({},Ye),{response:(n=e?.hookOptions)!=null&&n.cloneResponse?E.clone():E}));S instanceof Response?E=S:S instanceof Object&&(E=S.response)}if(E.ok){if(!(g.method!=="HEAD"))return{data:"",error:null};let S=ar(E),j={data:"",response:E,request:g};if(S==="json"||S==="text"){let F=await E.text(),jt=await((o=g.jsonParser)!=null?o:rt)(F);j.data=jt}else j.data=await E[S]();g?.output&&g.output&&!g.disableValidation&&(j.data=await he(g.output,j.data));for(let F of l.onSuccess)F&&await F(L(C({},j),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?E.clone():E}));return e?.throw?j.data:{data:j.data,error:null}}let Mt=(c=e?.jsonParser)!=null?c:rt,de=await E.text(),Qe=ir(de),Ae=Qe?await Mt(de):null,Bt={response:E,responseText:de,request:g,error:L(C({},Ae),{status:E.status,statusText:E.statusText})};for(let I of l.onError)I&&await I(L(C({},Bt),{response:(d=e?.hookOptions)!=null&&d.cloneResponse?E.clone():E}));if(e?.retry){let I=sr(e.retry),S=(u=e.retryAttempt)!=null?u:0;if(await I.shouldAttemptRetry(S,E)){for(let F of l.onRetry)F&&await F(Ye);let j=I.getDelay(S);return await new Promise(F=>setTimeout(F,j)),await Oe(r,L(C({},e),{retryAttempt:S+1}))}}if(e?.throw)throw new er(E.status,E.statusText,Qe?Ae:de);return{data:null,error:L(C({},Ae),{status:E.status,statusText:E.statusText})}};a();a();var fe=Object.create(null),K=r=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(r?fe:globalThis),O=new Proxy(fe,{get(r,e){return K()[e]??fe[e]},has(r,e){let t=K();return e in t||e in fe},set(r,e,t){let s=K(!0);return s[e]=t,!0},deleteProperty(r,e){if(!e)return!1;let t=K(!0);return delete t[e],!0},ownKeys(){let r=K(!0);return Object.keys(r)}});var Ss=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function R(r,e){return typeof process<"u"&&process.env?process.env[r]??e:typeof Deno<"u"?Deno.env.get(r)??e:typeof Bun<"u"?Bun.env[r]??e:e}var Ps=Object.freeze({get BETTER_AUTH_SECRET(){return R("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return R("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return R("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return R("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return R("NODE_ENV","development")},get PACKAGE_VERSION(){return R("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return R("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),J=1,T=4,$=8,A=24,lt={eterm:T,cons25:T,console:T,cygwin:T,dtterm:T,gnome:T,hurd:T,jfbterm:T,konsole:T,kterm:T,mlterm:T,mosh:A,putty:T,st:T,"rxvt-unicode-24bit":A,terminator:A,"xterm-kitty":A},yr=new Map(Object.entries({APPVEYOR:$,BUILDKITE:$,CIRCLECI:A,DRONE:$,GITEA_ACTIONS:A,GITHUB_ACTIONS:A,GITLAB_CI:$,TRAVIS:$})),br=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function Rr(){if(R("FORCE_COLOR")!==void 0)switch(R("FORCE_COLOR")){case"":case"1":case"true":return T;case"2":return $;case"3":return A;default:return J}if(R("NODE_DISABLE_COLORS")!==void 0&&R("NODE_DISABLE_COLORS")!==""||R("NO_COLOR")!==void 0&&R("NO_COLOR")!==""||R("TERM")==="dumb")return J;if(R("TMUX"))return A;if("TF_BUILD"in O&&"AGENT_NAME"in O)return T;if("CI"in O){for(let{0:r,1:e}of yr)if(r in O)return e;return R("CI_NAME")==="codeship"?$:J}if("TEAMCITY_VERSION"in O)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(R("TEAMCITY_VERSION"))!==null?T:J;switch(R("TERM_PROGRAM")){case"iTerm.app":return!R("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(R("TERM_PROGRAM_VERSION"))!==null?$:A;case"HyperTerm":case"MacTerm":return A;case"Apple_Terminal":return $}if(R("COLORTERM")==="truecolor"||R("COLORTERM")==="24bit")return A;if(R("TERM")){if(/truecolor/.exec(R("TERM"))!==null)return A;if(/^xterm-256/.exec(R("TERM"))!==null)return $;let r=R("TERM").toLowerCase();if(lt[r])return lt[r];if(br.some(e=>e.exec(r)!==null))return T}return R("COLORTERM")?T:J}var D={reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",undim:"\x1B[22m",underscore:"\x1B[4m",blink:"\x1B[5m",reverse:"\x1B[7m",hidden:"\x1B[8m",fg:{black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"},bg:{black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m"}},Ue=["info","success","warn","error","debug"];function wr(r,e){return Ue.indexOf(e)<=Ue.indexOf(r)}var Er={info:D.fg.blue,success:D.fg.green,warn:D.fg.yellow,error:D.fg.red,debug:D.fg.magenta},vr=(r,e,t)=>{let s=new Date().toISOString();return t?`${D.dim}${s}${D.reset} ${Er[r]}${r.toUpperCase()}${D.reset} ${D.bright}[Better Auth]:${D.reset} ${e}`:`${s} ${r.toUpperCase()} [Better Auth]: ${e}`},Tr=r=>{let e=r?.disabled!==!0,t=r?.level??"error",n=r?.disableColors!==void 0?!r.disableColors:Rr()!==1,o=(c,d,u=[])=>{if(!e||!wr(t,c))return;let l=vr(c,d,n);if(!r||typeof r.log!="function"){c==="error"?console.error(l,...u):c==="warn"?console.warn(l,...u):console.log(l,...u);return}r.log(c==="success"?"info":c,d,...u)};return{...Object.fromEntries(Ue.map(c=>[c,(...[d,...u])=>o(c,d,u)])),get level(){return t}}},As=Tr();a();a();var Ls={USER_NOT_FOUND:"User not found",FAILED_TO_CREATE_USER:"Failed to create user",FAILED_TO_CREATE_SESSION:"Failed to create session",FAILED_TO_UPDATE_USER:"Failed to update user",FAILED_TO_GET_SESSION:"Failed to get session",INVALID_PASSWORD:"Invalid password",INVALID_EMAIL:"Invalid email",INVALID_EMAIL_OR_PASSWORD:"Invalid email or password",SOCIAL_ACCOUNT_ALREADY_LINKED:"Social account already linked",PROVIDER_NOT_FOUND:"Provider not found",INVALID_TOKEN:"Invalid token",ID_TOKEN_NOT_SUPPORTED:"id_token not supported",FAILED_TO_GET_USER_INFO:"Failed to get user info",USER_EMAIL_NOT_FOUND:"User email not found",EMAIL_NOT_VERIFIED:"Email not verified",PASSWORD_TOO_SHORT:"Password too short",PASSWORD_TOO_LONG:"Password too long",USER_ALREADY_EXISTS:"User already exists.",USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:"User already exists. Use another email.",EMAIL_CAN_NOT_BE_UPDATED:"Email can not be updated",CREDENTIAL_ACCOUNT_NOT_FOUND:"Credential account not found",SESSION_EXPIRED:"Session expired. Re-authenticate to perform this action.",FAILED_TO_UNLINK_LAST_ACCOUNT:"You can't unlink your last account",ACCOUNT_NOT_FOUND:"Account not found",USER_ALREADY_HAS_PASSWORD:"User already has a password. Provide that to delete the account."},G=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function _r(r){try{return(new URL(r).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new G(`Invalid base URL: ${r}. Please provide a valid base URL.`)}}function Y(r,e="/api/auth"){if(_r(r))return r;let s=r.replace(/\/+$/,"");return!e||e==="/"?s:(e=e.startsWith("/")?e:`/${e}`,`${s}${e}`)}function ct(r,e,t,s){if(r)return Y(r,e);if(s!==!1){let i=O.BETTER_AUTH_URL||O.NEXT_PUBLIC_BETTER_AUTH_URL||O.PUBLIC_BETTER_AUTH_URL||O.NUXT_PUBLIC_BETTER_AUTH_URL||O.NUXT_PUBLIC_AUTH_URL||(O.BASE_URL!=="/"?O.BASE_URL:void 0);if(i)return Y(i,e)}let n=t?.headers.get("x-forwarded-host"),o=t?.headers.get("x-forwarded-proto");if(n&&o)return Y(`${o}://${n}`,e);if(t){let i=Sr(t.url);if(!i)throw new G("Could not get origin from request. Please provide a valid base URL.");return Y(i,e)}if(typeof window<"u"&&window.location)return Y(window.location.origin,e)}function Sr(r){try{return new URL(r).origin}catch{return null}}a();a();a();var Q=Symbol("clean");var N=[],q=0,pe=4,Pr=0,X=r=>{let e=[],t={get(){return t.lc||t.listen(()=>{})(),t.value},lc:0,listen(s){return t.lc=e.push(s),()=>{for(let o=q+pe;o<N.length;)N[o]===s?N.splice(o,pe):o+=pe;let n=e.indexOf(s);~n&&(e.splice(n,1),--t.lc||t.off())}},notify(s,n){Pr++;let o=!N.length;for(let i of e)N.push(i,t.value,s,n);if(o){for(q=0;q<N.length;q+=pe)N[q](N[q+1],N[q+2],N[q+3]);N.length=0}},off(){},set(s){let n=t.value;n!==s&&(t.value=s,t.notify(n))},subscribe(s){let n=t.listen(s);return s(t.value),n},value:r};return process.env.NODE_ENV!=="production"&&(t[Q]=()=>{e=[],t.lc=0,t.off()}),t};a();var Ar=5,z=6,me=10,Or=(r,e,t,s)=>(r.events=r.events||{},r.events[t+me]||(r.events[t+me]=s(n=>{r.events[t].reduceRight((o,i)=>(i(o),o),{shared:{},...n})})),r.events[t]=r.events[t]||[],r.events[t].push(e),()=>{let n=r.events[t],o=n.indexOf(e);n.splice(o,1),n.length||(delete r.events[t],r.events[t+me](),delete r.events[t+me])});var ut=1e3,Ie=(r,e)=>Or(r,s=>{let n=e(s);n&&r.events[z].push(n)},Ar,s=>{let n=r.listen;r.listen=(...i)=>(!r.lc&&!r.active&&(r.active=!0,s()),n(...i));let o=r.off;if(r.events[z]=[],r.off=()=>{o(),setTimeout(()=>{if(r.active&&!r.lc){r.active=!1;for(let i of r.events[z])i();r.events[z]=[]}},ut)},process.env.NODE_ENV!=="production"){let i=r[Q];r[Q]=()=>{for(let c of r.events[z])c();r.events[z]=[],r.active=!1,i()}}return()=>{r.listen=n,r.off=o}});a();var Ur=typeof window>"u",ge=(r,e,t,s)=>{let n=X({data:null,error:null,isPending:!0,isRefetching:!1,refetch:c=>o(c)}),o=c=>{let d=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;t(e,{...d,query:{...d?.query,...c?.query},async onSuccess(u){n.set({data:u.data,error:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onSuccess?.(u)},async onError(u){let{request:l}=u,h=typeof l.retry=="number"?l.retry:l.retry?.attempts,m=l.retryAttempt||0;h&&m<h||(n.set({error:u.error,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onError?.(u))},async onRequest(u){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0,refetch:n.value.refetch}),await d?.onRequest?.(u)}}).catch(u=>{n.set({error:u,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch})})};r=Array.isArray(r)?r:[r];let i=!1;for(let c of r)c.subscribe(()=>{Ur||(i?o():Ie(n,()=>{let d=setTimeout(()=>{i||(o(),i=!0)},0);return()=>{n.off(),c.off(),clearTimeout(d)}}))});return n};a();var Ir={proto:/"(?:_|\\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*:/,constructor:/"(?: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*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},xr=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,dt={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Cr=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Nr(r){return r instanceof Date&&!isNaN(r.getTime())}function Lr(r){let e=Cr.exec(r);if(!e)return null;let[,t,s,n,o,i,c,d,u,l,h]=e,m=new Date(Date.UTC(parseInt(t,10),parseInt(s,10)-1,parseInt(n,10),parseInt(o,10),parseInt(i,10),parseInt(c,10),d?parseInt(d.padEnd(3,"0"),10):0));if(u){let w=(parseInt(l,10)*60+parseInt(h,10))*(u==="+"?-1:1);m.setUTCMinutes(m.getUTCMinutes()+w)}return Nr(m)?m:null}function $r(r,e={}){let{strict:t=!1,warnings:s=!1,reviver:n,parseDates:o=!0}=e;if(typeof r!="string")return r;let i=r.trim();if(i.length>0&&i[0]==='"'&&i.endsWith('"')&&!i.slice(1,-1).includes('"'))return i.slice(1,-1);let c=i.toLowerCase();if(c.length<=9&&c in dt)return dt[c];if(!xr.test(i)){if(t)throw new SyntaxError("[better-json] Invalid JSON");return r}if(Object.entries(Ir).some(([u,l])=>{let h=l.test(i);return h&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),h})&&t)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(i,(l,h)=>{if(l==="__proto__"||l==="constructor"&&h&&typeof h=="object"&&"prototype"in h){s&&console.warn(`[better-json] Dropping "${l}" key to prevent prototype pollution`);return}if(o&&typeof h=="string"){let m=Lr(h);if(m)return m}return n?n(l,h):h})}catch(u){if(t)throw u;return r}}function ht(r,e={strict:!0}){return $r(r,e)}var Dr={id:"redirect",name:"Redirect",hooks:{onSuccess(r){if(r.data?.url&&r.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=r.data.url}catch{}}}};function kr(r){let e=X(!1);return{session:ge(e,"/get-session",r,{method:"GET"}),$sessionSignal:e}}var ft=(r,e)=>{let t="credentials"in Request.prototype,s=ct(r?.baseURL,r?.basePath,void 0,e)??"/api/auth",n=r?.plugins?.flatMap(g=>g.fetchPlugins).filter(g=>g!==void 0)||[],o={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:r?.fetchOptions?.onSuccess,onError:r?.fetchOptions?.onError,onRequest:r?.fetchOptions?.onRequest,onResponse:r?.fetchOptions?.onResponse}},{onSuccess:i,onError:c,onRequest:d,onResponse:u,...l}=r?.fetchOptions||{},h=it({baseURL:s,...t?{credentials:"include"}:{},method:"GET",jsonParser(g){return g?ht(g,{strict:!1}):null},customFetchImpl:fetch,...l,plugins:[o,...l.plugins||[],...r?.disableDefaultFetchPlugins?[]:[Dr],...n]}),{$sessionSignal:m,session:w}=kr(h),v=r?.plugins||[],x={},b={$sessionSignal:m,session:w},U={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},P=[{signal:"$sessionSignal",matcher(g){return g==="/sign-out"||g==="/update-user"||g.startsWith("/sign-in")||g.startsWith("/sign-up")||g==="/delete-user"||g==="/verify-email"}}];for(let g of v)g.getAtoms&&Object.assign(b,g.getAtoms?.(h)),g.pathMethods&&Object.assign(U,g.pathMethods),g.atomListeners&&P.push(...g.atomListeners);let B={notify:g=>{b[g].set(!b[g].get())},listen:(g,W)=>{b[g].subscribe(W)},atoms:b};for(let g of v)g.getActions&&Object.assign(x,g.getActions?.(h,B,r));return{get baseURL(){return s},pluginsActions:x,pluginsAtoms:b,pluginPathMethods:U,atomListeners:P,$fetch:h,$store:B}};function Mr(r){return typeof r=="object"&&r!==null&&"get"in r&&typeof r.get=="function"&&"lc"in r&&typeof r.lc=="number"}function Br(r,e,t){let s=e[r],{fetchOptions:n,query:o,...i}=t||{};return s||(n?.method?n.method:i&&Object.keys(i).length>0?"POST":"GET")}function pt(r,e,t,s,n){function o(i=[]){return new Proxy(function(){},{get(c,d){if(typeof d!="string"||d==="then"||d==="catch"||d==="finally")return;let u=[...i,d],l=r;for(let h of u)if(l&&typeof l=="object"&&h in l)l=l[h];else{l=void 0;break}return typeof l=="function"||Mr(l)?l:o(u)},apply:async(c,d,u)=>{let l="/"+i.map(P=>P.replace(/[A-Z]/g,B=>`-${B.toLowerCase()}`)).join("/"),h=u[0]||{},m=u[1]||{},{query:w,fetchOptions:v,...x}=h,b={...m,...v},U=Br(l,t,h);return await e(l,{...b,body:U==="GET"?void 0:{...x,...b?.body||{}},query:w||b?.query,method:U,async onSuccess(P){if(await b?.onSuccess?.(P),!n)return;let B=n.filter(g=>g.matcher(l));if(B.length)for(let g of B){let W=s[g.signal];if(!W)return;let E=W.get();setTimeout(()=>{W.set(!E)},10)}}})}})}return o()}a();function mt(r){return r.charAt(0).toUpperCase()+r.slice(1)}function xe(r){let{pluginPathMethods:e,pluginsActions:t,pluginsAtoms:s,$fetch:n,atomListeners:o,$store:i}=ft(r),c={};for(let[l,h]of Object.entries(s))c[`use${mt(l)}`]=h;let d={...t,...c,$fetch:n,$store:i};return pt(d,n,e,s,o)}a();a();a();function jr(r){return{authorize(e,t="AND"){let s=!1;for(let[n,o]of Object.entries(e)){let i=r[n];if(!i)return{success:!1,error:`You are not allowed to access resource: ${n}`};if(Array.isArray(o))s=o.every(c=>i.includes(c));else if(typeof o=="object"){let c=o;c.connector==="OR"?s=c.actions.some(d=>i.includes(d)):s=c.actions.every(d=>i.includes(d))}else throw new G("Invalid access control request");if(s&&t==="OR")return{success:s};if(!s&&t==="AND")return{success:!1,error:`unauthorized to access resource "${n}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:r}}function ye(r){return{newRole(e){return jr(e)},statements:r}}var Fr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},Ce=ye(Fr),Hr=Ce.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),qr=Ce.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),Wr=Ce.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});a();a();a();a();a();a();a();a();a();a();a();var Ne=class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let t=new Error("Cancelling existing WebAuthn API call for new one");t.name="AbortError",this.controller.abort(t)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=new Error("Manually cancelling existing WebAuthn API call");e.name="AbortError",this.controller.abort(e),this.controller=void 0}}},bt=new Ne;a();a();a();a();a();a();a();a();var Jr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},Rt=ye(Jr),Yr=Rt.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),Qr=Rt.newRole({user:[],session:[]});a();a();var wt=()=>({id:"username",$InferServerPlugin:{}});var $a="/auth",be="nvwa_login_token",$e="nvwa_user_profile",Et=class{constructor(e,t,s){this.storage=s,this.authClient=xe({baseUrl:e,fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:()=>s.get(be)},onSuccess:n=>{let o=n.response.headers.get("set-auth-token");o&&s.set(be,o)}},plugins:[wt()]})}async currentUser(){return await this.storage.get($e)}async signUp(e,t){let s=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:t});this.saveSession(s)}async signInWithUsername(e,t){let s=await this.authClient.signIn.username({username:e,password:t});this.saveSession(s)}saveSession(e){if(e.error)throw new Error(e.error.message);this.storage.set(be,e.data?.token),this.storage.set($e,e.data?.user)}async signOut(){await this.storage.remove(be),await this.storage.remove($e)}async updateUserPassword(e,t,s=!1){let n=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:s});this.saveSession(n)}};a();var vt=class{constructor(e){this.http=e}async invoke(e,t){return(await this.http.request("/functions/"+e,{method:t.method||"POST",data:t.body,headers:t.headers})).body}};a();var Tt=class{constructor(e,t,s,n,o){this.ok=e,this.status=t,this.statusText=s,this.headers=n,this.body=o}async text(){return typeof this.body=="string"?this.body:JSON.stringify(this.body)}async json(){if(typeof this.body=="string")try{return JSON.parse(this.body)}catch{return this.body}return this.body}async arrayBuffer(){if(this.body instanceof ArrayBuffer)return this.body;if(typeof this.body=="string")return new TextEncoder().encode(this.body).buffer;throw new Error("Cannot convert body to ArrayBuffer")}async blob(){if(this.body instanceof Blob)return this.body;if(typeof this.body=="string")return new Blob([this.body],{type:this.headers["content-type"]||"text/plain"});throw new Error("Cannot convert body to Blob")}},_t=class{async jsonRequest(e,t){let s={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.request(e,s)}async jsonRequestWithAuth(e,t,s){let n={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.requestWithAuth(e,n,s)}};a();var Xr="/storage",Zr=Xr+"/generateUploadUrl",St=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.request(this.baseUrl+Zr,{method:"POST",data:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:s}=t.body;if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");return{url:(await this.http.request(s,{method:"PUT",data:e,headers:{"Content-Type":e.type||e.fileType||"application/octet-stream"}})).body.url.split("?")[0]}}};a();a();a();var Dt=Kt($t(),1),{PostgrestClient:kt,PostgrestQueryBuilder:ii,PostgrestFilterBuilder:li,PostgrestTransformBuilder:ci,PostgrestBuilder:ui,PostgrestError:di,FetchHeaders:hi,FetchResponse:Je,PostgrestFetch:fi,URL:pi,URLSearchParams:mi}=Dt.default;var us="/entities",ds=(r,e)=>async(s,n)=>{console.log("customFetch",s,n);let o;if(typeof s=="string")o=s;else if(s&&typeof s=="object")if(typeof s.toString=="function"&&!s.url)o=s.toString();else if(s.url)o=s.url,n||(n={}),n.method=s.method,n.headers=s.headers,n.body=s.body;else throw new Error("Unsupported input type for fetch");else throw new Error("Unsupported input type for fetch");let i=(n?.method||"GET").toUpperCase(),c={};if(n?.headers)if(n.headers&&typeof n.headers.forEach=="function")n.headers.forEach((w,v)=>{c[v]=w});else if(Array.isArray(n.headers))for(let[w,v]of n.headers)c[w]=v;else Object.assign(c,n.headers);let d=n?.body,u;try{u=await r.requestWithAuth(o,{method:i,data:d,headers:c},e)}catch(w){return new Je(w?.message||"Internal Error",{status:500,statusText:"Internal Error"})}let l=u.body,h=null;return(u.headers["content-type"]||u.headers["Content-Type"]||"").startsWith("application/json")&&typeof l!="string"?h=JSON.stringify(l):typeof l=="string"||l&&(l.constructor===Blob||l.constructor===ArrayBuffer||typeof l.getReader=="function")?h=l:h=JSON.stringify(l),new Je(h,{status:u.status,headers:u.headers})},Ei=(r,e,t)=>new kt(r+us,{fetch:ds(e,t)});a();a();var M=class r{constructor(e){this.headerMap=new Map;if(e){if(e instanceof r)e.forEach((t,s)=>this.set(s,t));else if(Array.isArray(e))for(let[t,s]of e)this.set(t,String(s));else if(typeof e=="object")for(let t of Object.keys(e))this.set(t,String(e[t]))}}append(e,t){let s=e.toLowerCase(),n=this.headerMap.get(s);this.headerMap.set(s,n?`${n}, ${t}`:t)}set(e,t){this.headerMap.set(e.toLowerCase(),String(t))}get(e){let t=this.headerMap.get(e.toLowerCase());return t??null}has(e){return this.headerMap.has(e.toLowerCase())}delete(e){this.headerMap.delete(e.toLowerCase())}forEach(e){for(let[t,s]of this.headerMap.entries())e(s,t,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}},ce=class r{constructor(e){this.params=new Map;if(e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}},Te=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new ce(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let x=d[1];h=d[2];let b=x.match(/^([^:]*):?(.*)$/);b&&(u=b[1]||"",l=b[2]||"")}let m=h.match(/^([^:]+):?(\d*)$/),w=m?m[1]:h,v=m&&m[2]?m[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:w,port:v,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};a();var _e=class r{constructor(e,t){if(typeof e=="string")this.url=e;else if(e?.url)this.url=String(e.url);else if(typeof e?.toString=="function")this.url=String(e.toString());else throw new Error("Invalid input for Request");this.method=(t?.method||"GET").toUpperCase(),this.headers=t?.headers instanceof M?t.headers:new M(t?.headers),this.body=t?.body,this.timeout=t?.timeout,this.signal=t?.signal||void 0}clone(){return new r(this.url,{method:this.method,headers:this.headers,body:this.body,timeout:this.timeout})}toString(){return this.url}};a();var Se=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=hs(t?.headers),this.ok=this.status>=200&&this.status<300}async text(){return typeof this.bodyData=="string"?this.bodyData:this.bodyData==null?"":typeof this.bodyData=="object"?JSON.stringify(this.bodyData):String(this.bodyData)}async json(){if(typeof this.bodyData=="string")try{return JSON.parse(this.bodyData)}catch{}return this.bodyData}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}};function hs(r){return r?new M(r):new M}a();var ue=class{constructor(){this._aborted=!1;this.listeners=new Set;this.onabort=null}get aborted(){return this._aborted}_trigger(){if(!this._aborted){if(this._aborted=!0,typeof this.onabort=="function")try{this.onabort()}catch{}for(let e of Array.from(this.listeners))try{e()}catch{}this.listeners.clear()}}addEventListener(e,t){if(this._aborted){try{t()}catch{}return}this.listeners.add(t)}removeEventListener(e,t){this.listeners.delete(t)}toString(){return"[object AbortSignal]"}},Pe=class{constructor(){this._signal=new ue}get signal(){return this._signal}abort(){this._signal._trigger()}toString(){return"[object AbortController]"}};a();function Mi(r){r.URL=Te,r.URLSearchParams=ce,r.Headers=M,r.Request=_e,r.Response=Se,r.AbortController=Pe,r.AbortSignal=ue}export{$a as AUTH_BASE_PATH,Pe as AbortController,ue as AbortSignal,us as ENTITIES_BASE_PATH,Xr as FILE_STORAGE_BASE_PATH,Tt as FetchResponse,Zr as GENERATE_UPLOAD_URL_PATH,M as Headers,be as LOGIN_TOKEN_KEY,$e as LOGIN_USER_PROFILE_KEY,Et as NvwaAuthClient,vt as NvwaEdgeFunctions,St as NvwaFileStorage,_t as NvwaHttpClient,_e as Request,Se as Response,Te as URL,ce as URLSearchParams,Ei as createPostgrestClient,Mi as polyfill};
|
|
1
|
+
var Ft=Object.create;var Xe=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames;var Wt=Object.getPrototypeOf,Gt=Object.prototype.hasOwnProperty;var zt=(r,e)=>()=>(r&&(e=r(r=0)),e);var H=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var Vt=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of qt(e))!Gt.call(r,n)&&n!==t&&Xe(r,n,{get:()=>e[n],enumerable:!(s=Ht(e,n))||s.enumerable});return r};var Kt=(r,e,t)=>(t=r!=null?Ft(Wt(r)):{},Vt(e||!r||!r.__esModule?Xe(t,"default",{value:r,enumerable:!0}):t,r));import ys from"path";import{fileURLToPath as Rs}from"url";var a=zt(()=>{"use strict"});var te=H(_=>{"use strict";a();Object.defineProperty(_,"__esModule",{value:!0});_.File=_.FormData=_.Blob=_.FetchResponse=_.URL=_.URLSearchParams=_.FetchHeaders=void 0;var Z=class{constructor(e){if(this.map=new Map,e)for(let[t,s]of Object.entries(e))this.set(t,s)}get(e){var t;return(t=this.map.get(e))!==null&&t!==void 0?t:null}set(e,t){this.map.set(e,t)}has(e){return this.map.has(e)}append(e,t){let s=this.map.get(e);s?this.map.set(e,`${s}${t}`):this.map.set(e,t)}delete(e){this.map.delete(e)}forEach(e){this.map.forEach(e)}size(){return this.map.size}keys(){return this.map.keys()}values(){return this.map.values()}entries(){return this.map.entries()}headers(){return Object.fromEntries(this.map.entries())}[Symbol.iterator](){return this.map[Symbol.iterator]()}};_.FetchHeaders=Z;var Re=class r{constructor(e){if(this.params=new Map,e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}};_.URLSearchParams=Re;var we=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new Re(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let x=d[1];h=d[2];let b=x.match(/^([^:]*):?(.*)$/);b&&(u=b[1]||"",l=b[2]||"")}let m=h.match(/^([^:]+):?(\d*)$/),w=m?m[1]:h,v=m&&m[2]?m[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:w,port:v,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};_.URL=we;var De=class r{constructor(e,t){var s,n;this.status=(s=t?.status)!==null&&s!==void 0?s:200,this.statusText=(n=t?.statusText)!==null&&n!==void 0?n:"",this.headers=new Z(t?.headers),this.ok=this.status>=200&&this.status<300,this.redirected=!1,this.url="",this.bodyUsed=!1,this.body=e||null}async arrayBuffer(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?new ArrayBuffer(0):new TextEncoder().encode(this.body).buffer}async blob(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new ee([this.body||""])}async formData(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,new Ee}async json(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body===null?null:JSON.parse(this.body)}async text(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return this.bodyUsed=!0,this.body||""}clone(){if(this.bodyUsed)throw new TypeError("Body has already been consumed");return new r(this.body,{status:this.status,statusText:this.statusText,headers:this.headers.headers()})}static error(){let e=new r(null,{status:0,statusText:""});return Object.defineProperty(e,"type",{value:"error",writable:!1}),e}static redirect(e,t=302){let s=e instanceof we?e.href:e,n=new r(null,{status:t,statusText:"Found"});return n.headers.set("Location",s),n}static json(e,t){let s=JSON.stringify(e),n=new Z(t?.headers);return n.set("Content-Type","application/json"),new r(s,Object.assign(Object.assign({},t),{headers:n.headers()}))}};_.FetchResponse=De;var ee=class r{constructor(e,t){this._content=e||[],this.type=t?.type||"";let s=0;for(let n of this._content)typeof n=="string"?s+=new TextEncoder().encode(n).length:n instanceof ArrayBuffer?s+=n.byteLength:n instanceof Uint8Array&&(s+=n.length);this.size=s}async text(){let e="";for(let t of this._content)typeof t=="string"?e+=t:t instanceof ArrayBuffer?e+=new TextDecoder().decode(t):t instanceof Uint8Array&&(e+=new TextDecoder().decode(t));return e}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}slice(e,t,s){return new r(this._content.slice(e,t),{type:s})}};_.Blob=ee;var Ee=class{constructor(){this._entries=[]}append(e,t,s){this._entries.push([e,t])}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}get(e){let t=this._entries.find(([s])=>s===e);return t?t[1]:null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,t])=>t)}has(e){return this._entries.some(([t])=>t===e)}set(e,t,s){this.delete(e),this.append(e,t,s)}forEach(e){for(let[t,s]of this._entries)e(s,t,this)}keys(){return this._entries.map(([e])=>e)[Symbol.iterator]()}values(){return this._entries.map(([,e])=>e)[Symbol.iterator]()}entries(){return this._entries[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}};_.FormData=Ee;var ke=class extends ee{constructor(e,t,s){super(e,s),this.name=t,this.lastModified=s?.lastModified||Date.now()}};_.File=ke});var je=H(Be=>{"use strict";a();Object.defineProperty(Be,"__esModule",{value:!0});var Me=class extends Error{constructor(e){super(e.message),this.name="PostgrestError",this.details=e.details,this.hint=e.hint,this.code=e.code}};Be.default=Me});var He=H(re=>{"use strict";a();var ts=re&&re.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(re,"__esModule",{value:!0});var rs=ts(je()),Pt=te(),Fe=class{constructor(e){var t,s;this.shouldThrowOnError=!1,this.method=e.method,this.url=e.url,this.headers=new Pt.FetchHeaders(e.headers),this.schema=e.schema,this.body=e.body,this.shouldThrowOnError=(t=e.shouldThrowOnError)!==null&&t!==void 0?t:!1,this.signal=e.signal,this.isMaybeSingle=(s=e.isMaybeSingle)!==null&&s!==void 0?s:!1,e.fetch?this.fetch=e.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(e,t){return this.headers=new Pt.FetchHeaders(this.headers),this.headers.set(e,t),this}then(e,t){this.schema===void 0||(["GET","HEAD"].includes(this.method)?this.headers.set("Accept-Profile",this.schema):this.headers.set("Content-Profile",this.schema)),this.method!=="GET"&&this.method!=="HEAD"&&this.headers.set("Content-Type","application/json");let s=this.fetch,n=s(this.url.toString(),{method:this.method,headers:this.headers.headers(),body:JSON.stringify(this.body),signal:this.signal}).then(async o=>{var i,c,d,u;let l=null,h=null,m=null,w=o.status,v=o.statusText;if(o.ok){if(this.method!=="HEAD"){let P=await o.text();P===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&(!((i=this.headers.get("Accept"))===null||i===void 0)&&i.includes("application/vnd.pgrst.plan+text"))?h=P:h=JSON.parse(P))}let b=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),U=(d=o.headers.get("content-range"))===null||d===void 0?void 0:d.split("/");b&&U&&U.length>1&&(m=parseInt(U[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(h)&&(h.length>1?(l={code:"PGRST116",details:`Results contain ${h.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},h=null,m=null,w=406,v="Not Acceptable"):h.length===1?h=h[0]:h=null)}else{let b=await o.text();try{l=JSON.parse(b),Array.isArray(l)&&o.status===404&&(h=[],l=null,w=200,v="OK")}catch{o.status===404&&b===""?(w=204,v="No Content"):l={message:b}}if(l&&this.isMaybeSingle&&(!((u=l?.details)===null||u===void 0)&&u.includes("0 rows"))&&(l=null,w=200,v="OK"),l&&this.shouldThrowOnError)throw new rs.default(l)}return{error:l,data:h,count:m,status:w,statusText:v}});return this.shouldThrowOnError||(n=n.catch(o=>{var i,c,d;return{error:{message:`${(i=o?.name)!==null&&i!==void 0?i:"FetchError"}: ${o?.message}`,details:`${(c=o?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(d=o?.code)!==null&&d!==void 0?d:""}`},data:null,count:null,status:0,statusText:""}})),n.then(e,t)}returns(){return this}overrideTypes(){return this}};re.default=Fe});var We=H(se=>{"use strict";a();var ss=se&&se.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(se,"__esModule",{value:!0});var ns=ss(He()),qe=class extends ns.default{select(e){let t=!1,s=(e??"*").split("").map(n=>/\s/.test(n)&&!t?"":(n==='"'&&(t=!t),n)).join("");return this.url.searchParams.set("select",s),this.headers.append("Prefer","return=representation"),this}order(e,{ascending:t=!0,nullsFirst:s,foreignTable:n,referencedTable:o=n}={}){let i=o?`${o}.order`:"order",c=this.url.searchParams.get(i);return this.url.searchParams.set(i,`${c?`${c},`:""}${e}.${t?"asc":"desc"}${s===void 0?"":s?".nullsfirst":".nullslast"}`),this}limit(e,{foreignTable:t,referencedTable:s=t}={}){let n=typeof s>"u"?"limit":`${s}.limit`;return this.url.searchParams.set(n,`${e}`),this}range(e,t,{foreignTable:s,referencedTable:n=s}={}){let o=typeof n>"u"?"offset":`${n}.offset`,i=typeof n>"u"?"limit":`${n}.limit`;return this.url.searchParams.set(o,`${e}`),this.url.searchParams.set(i,`${t-e+1}`),this}abortSignal(e){return this.signal=e,this}single(){return this.headers.set("Accept","application/vnd.pgrst.object+json"),this}maybeSingle(){return this.method==="GET"?this.headers.set("Accept","application/json"):this.headers.set("Accept","application/vnd.pgrst.object+json"),this.isMaybeSingle=!0,this}csv(){return this.headers.set("Accept","text/csv"),this}geojson(){return this.headers.set("Accept","application/geo+json"),this}explain({analyze:e=!1,verbose:t=!1,settings:s=!1,buffers:n=!1,wal:o=!1,format:i="text"}={}){var c;let d=[e?"analyze":null,t?"verbose":null,s?"settings":null,n?"buffers":null,o?"wal":null].filter(Boolean).join("|"),u=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${i}; for="${u}"; options=${d};`),i==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(e){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${e}`),this}};se.default=qe});var ve=H(ne=>{"use strict";a();var os=ne&&ne.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ne,"__esModule",{value:!0});var as=os(We()),Ge=class extends as.default{eq(e,t){return this.url.searchParams.append(e,`eq.${t}`),this}neq(e,t){return this.url.searchParams.append(e,`neq.${t}`),this}gt(e,t){return this.url.searchParams.append(e,`gt.${t}`),this}gte(e,t){return this.url.searchParams.append(e,`gte.${t}`),this}lt(e,t){return this.url.searchParams.append(e,`lt.${t}`),this}lte(e,t){return this.url.searchParams.append(e,`lte.${t}`),this}like(e,t){return this.url.searchParams.append(e,`like.${t}`),this}likeAllOf(e,t){return this.url.searchParams.append(e,`like(all).{${t.join(",")}}`),this}likeAnyOf(e,t){return this.url.searchParams.append(e,`like(any).{${t.join(",")}}`),this}ilike(e,t){return this.url.searchParams.append(e,`ilike.${t}`),this}ilikeAllOf(e,t){return this.url.searchParams.append(e,`ilike(all).{${t.join(",")}}`),this}ilikeAnyOf(e,t){return this.url.searchParams.append(e,`ilike(any).{${t.join(",")}}`),this}is(e,t){return this.url.searchParams.append(e,`is.${t}`),this}in(e,t){let s=Array.from(new Set(t)).map(n=>typeof n=="string"&&new RegExp("[,()]").test(n)?`"${n}"`:`${n}`).join(",");return this.url.searchParams.append(e,`in.(${s})`),this}contains(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cs.{${t.join(",")}}`):this.url.searchParams.append(e,`cs.${JSON.stringify(t)}`),this}containedBy(e,t){return typeof t=="string"?this.url.searchParams.append(e,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(e,`cd.{${t.join(",")}}`):this.url.searchParams.append(e,`cd.${JSON.stringify(t)}`),this}rangeGt(e,t){return this.url.searchParams.append(e,`sr.${t}`),this}rangeGte(e,t){return this.url.searchParams.append(e,`nxl.${t}`),this}rangeLt(e,t){return this.url.searchParams.append(e,`sl.${t}`),this}rangeLte(e,t){return this.url.searchParams.append(e,`nxr.${t}`),this}rangeAdjacent(e,t){return this.url.searchParams.append(e,`adj.${t}`),this}overlaps(e,t){return typeof t=="string"?this.url.searchParams.append(e,`ov.${t}`):this.url.searchParams.append(e,`ov.{${t.join(",")}}`),this}textSearch(e,t,{config:s,type:n}={}){let o="";n==="plain"?o="pl":n==="phrase"?o="ph":n==="websearch"&&(o="w");let i=s===void 0?"":`(${s})`;return this.url.searchParams.append(e,`${o}fts${i}.${t}`),this}match(e){return Object.entries(e).forEach(([t,s])=>{this.url.searchParams.append(t,`eq.${s}`)}),this}not(e,t,s){return this.url.searchParams.append(e,`not.${t}.${s}`),this}or(e,{foreignTable:t,referencedTable:s=t}={}){let n=s?`${s}.or`:"or";return this.url.searchParams.append(n,`(${e})`),this}filter(e,t,s){return this.url.searchParams.append(e,`${t}.${s}`),this}};ne.default=Ge});var Ve=H(ae=>{"use strict";a();var is=ae&&ae.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(ae,"__esModule",{value:!0});var ls=te(),oe=is(ve()),ze=class{constructor(e,{headers:t={},schema:s,fetch:n}){this.url=e,this.headers=new ls.FetchHeaders(t),this.schema=s,this.fetch=n}select(e,t){let{head:s=!1,count:n}=t??{},o=s?"HEAD":"GET",i=!1,c=(e??"*").split("").map(d=>/\s/.test(d)&&!i?"":(d==='"'&&(i=!i),d)).join("");return this.url.searchParams.set("select",c),n&&this.headers.append("Prefer",`count=${n}`),new oe.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(e,{count:t,defaultToNull:s=!0}={}){var n;let o="POST";if(t&&this.headers.append("Prefer",`count=${t}`),s||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let i=e.reduce((c,d)=>c.concat(Object.keys(d)),[]);if(i.length>0){let c=[...new Set(i)].map(d=>`"${d}"`);this.url.searchParams.set("columns",c.join(","))}}return new oe.default({method:o,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}upsert(e,{onConflict:t,ignoreDuplicates:s=!1,count:n,defaultToNull:o=!0}={}){var i;let c="POST";if(this.headers.append("Prefer",`resolution=${s?"ignore":"merge"}-duplicates`),t!==void 0&&this.url.searchParams.set("on_conflict",t),n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(e)){let d=e.reduce((u,l)=>u.concat(Object.keys(l)),[]);if(d.length>0){let u=[...new Set(d)].map(l=>`"${l}"`);this.url.searchParams.set("columns",u.join(","))}}return new oe.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}update(e,{count:t}={}){var s;let n="PATCH";return t&&this.headers.append("Prefer",`count=${t}`),new oe.default({method:n,url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:(s=this.fetch)!==null&&s!==void 0?s:fetch})}delete({count:e}={}){var t;let s="DELETE";return e&&this.headers.append("Prefer",`count=${e}`),new oe.default({method:s,url:this.url,headers:this.headers,schema:this.schema,fetch:(t=this.fetch)!==null&&t!==void 0?t:fetch})}};ae.default=ze});var Ot=H(le=>{"use strict";a();var At=le&&le.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(le,"__esModule",{value:!0});var cs=At(Ve()),us=At(ve()),ie=te(),Ke=class r{constructor(e,{headers:t={},schema:s,fetch:n}={}){this.url=e,this.headers=new ie.FetchHeaders(t),this.schemaName=s,this.fetch=n}from(e){let t=new ie.URL(`${this.url}/${e}`);return new cs.default(t,{headers:new ie.FetchHeaders(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(e){return new r(this.url,{headers:this.headers,schema:e,fetch:this.fetch})}rpc(e,t={},{head:s=!1,get:n=!1,count:o}={}){var i;let c,d=new ie.URL(`${this.url}/rpc/${e}`),u;s||n?(c=s?"HEAD":"GET",Object.entries(t).filter(([h,m])=>m!==void 0).map(([h,m])=>[h,Array.isArray(m)?`{${m.join(",")}}`:`${m}`]).forEach(([h,m])=>{d.searchParams.append(h,m)})):(c="POST",u=t);let l=new ie.FetchHeaders(this.headers);return o&&l.set("Prefer",`count=${o}`),new us.default({method:c,url:d,headers:l,schema:this.schemaName,body:u,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}};le.default=Ke});var $t=H(y=>{"use strict";a();var V=y&&y.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(y,"__esModule",{value:!0});y.File=y.FormData=y.Blob=y.FetchResponse=y.FetchHeaders=y.URLSearchParams=y.URL=y.PostgrestError=y.PostgrestBuilder=y.PostgrestTransformBuilder=y.PostgrestFilterBuilder=y.PostgrestQueryBuilder=y.PostgrestClient=void 0;var Ut=V(Ot());y.PostgrestClient=Ut.default;var It=V(Ve());y.PostgrestQueryBuilder=It.default;var xt=V(ve());y.PostgrestFilterBuilder=xt.default;var Ct=V(We());y.PostgrestTransformBuilder=Ct.default;var Nt=V(He());y.PostgrestBuilder=Nt.default;var Lt=V(je());y.PostgrestError=Lt.default;var k=te();Object.defineProperty(y,"FetchHeaders",{enumerable:!0,get:function(){return k.FetchHeaders}});Object.defineProperty(y,"FetchResponse",{enumerable:!0,get:function(){return k.FetchResponse}});Object.defineProperty(y,"URL",{enumerable:!0,get:function(){return k.URL}});Object.defineProperty(y,"URLSearchParams",{enumerable:!0,get:function(){return k.URLSearchParams}});Object.defineProperty(y,"Blob",{enumerable:!0,get:function(){return k.Blob}});Object.defineProperty(y,"FormData",{enumerable:!0,get:function(){return k.FormData}});Object.defineProperty(y,"File",{enumerable:!0,get:function(){return k.File}});y.default={PostgrestClient:Ut.default,PostgrestQueryBuilder:It.default,PostgrestFilterBuilder:xt.default,PostgrestTransformBuilder:Ct.default,PostgrestBuilder:Nt.default,PostgrestError:Lt.default,URLSearchParams:k.URLSearchParams,FetchHeaders:k.FetchHeaders,FetchResponse:k.FetchResponse}});a();a();a();a();a();a();var Jt=Object.defineProperty,Yt=Object.defineProperties,Qt=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertySymbols,Xt=Object.prototype.hasOwnProperty,Zt=Object.prototype.propertyIsEnumerable,et=(r,e,t)=>e in r?Jt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e)=>{for(var t in e||(e={}))Xt.call(e,t)&&et(r,t,e[t]);if(Ze)for(var t of Ze(e))Zt.call(e,t)&&et(r,t,e[t]);return r},L=(r,e)=>Yt(r,Qt(e)),er=class extends Error{constructor(r,e,t){super(e||r.toString(),{cause:t}),this.status=r,this.statusText=e,this.error=t}},tr=async(r,e)=>{var t,s,n,o,i,c;let d=e||{},u={onRequest:[e?.onRequest],onResponse:[e?.onResponse],onSuccess:[e?.onSuccess],onError:[e?.onError],onRetry:[e?.onRetry]};if(!e||!e?.plugins)return{url:r,options:d,hooks:u};for(let l of e?.plugins||[]){if(l.init){let h=await((t=l.init)==null?void 0:t.call(l,r.toString(),e));d=h.options||d,r=h.url}u.onRequest.push((s=l.hooks)==null?void 0:s.onRequest),u.onResponse.push((n=l.hooks)==null?void 0:n.onResponse),u.onSuccess.push((o=l.hooks)==null?void 0:o.onSuccess),u.onError.push((i=l.hooks)==null?void 0:i.onError),u.onRetry.push((c=l.hooks)==null?void 0:c.onRetry)}return{url:r,options:d,hooks:u}},tt=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(){return this.options.delay}},rr=class{constructor(r){this.options=r}shouldAttemptRetry(r,e){return this.options.shouldRetry?Promise.resolve(r<this.options.attempts&&this.options.shouldRetry(e)):Promise.resolve(r<this.options.attempts)}getDelay(r){return Math.min(this.options.maxDelay,this.options.baseDelay*2**r)}};function sr(r){if(typeof r=="number")return new tt({type:"linear",attempts:r,delay:1e3});switch(r.type){case"linear":return new tt(r);case"exponential":return new rr(r);default:throw new Error("Invalid retry strategy")}}var nr=async r=>{let e={},t=async s=>typeof s=="function"?await s():s;if(r?.auth){if(r.auth.type==="Bearer"){let s=await t(r.auth.token);if(!s)return e;e.authorization=`Bearer ${s}`}else if(r.auth.type==="Basic"){let s=t(r.auth.username),n=t(r.auth.password);if(!s||!n)return e;e.authorization=`Basic ${btoa(`${s}:${n}`)}`}else if(r.auth.type==="Custom"){let s=t(r.auth.value);if(!s)return e;e.authorization=`${t(r.auth.prefix)} ${s}`}}return e},or=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function ar(r){let e=r.headers.get("content-type"),t=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!e)return"json";let s=e.split(";").shift()||"";return or.test(s)?"json":t.has(s)||s.startsWith("text/")?"text":"blob"}function ir(r){try{return JSON.parse(r),!0}catch{return!1}}function nt(r){if(r===void 0)return!1;let e=typeof r;return e==="string"||e==="number"||e==="boolean"||e===null?!0:e!=="object"?!1:Array.isArray(r)?!0:r.buffer?!1:r.constructor&&r.constructor.name==="Object"||typeof r.toJSON=="function"}function rt(r){try{return JSON.parse(r)}catch{return r}}function st(r){return typeof r=="function"}function lr(r){if(r?.customFetchImpl)return r.customFetchImpl;if(typeof globalThis<"u"&&st(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&st(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function cr(r){let e=new Headers(r?.headers),t=await nr(r);for(let[s,n]of Object.entries(t||{}))e.set(s,n);if(!e.has("content-type")){let s=ur(r?.body);s&&e.set("content-type",s)}return e}function ur(r){return nt(r)?"application/json":null}function dr(r){if(!r?.body)return null;let e=new Headers(r?.headers);if(nt(r.body)&&!e.has("content-type")){for(let[t,s]of Object.entries(r?.body))s instanceof Date&&(r.body[t]=s.toISOString());return JSON.stringify(r.body)}return r.body}function hr(r,e){var t;if(e?.method)return e.method.toUpperCase();if(r.startsWith("@")){let s=(t=r.split("@")[1])==null?void 0:t.split("/")[0];return at.includes(s)?s.toUpperCase():e?.body?"POST":"GET"}return e?.body?"POST":"GET"}function fr(r,e){let t;return!r?.signal&&r?.timeout&&(t=setTimeout(()=>e?.abort(),r?.timeout)),{abortTimeout:t,clearTimeout:()=>{t&&clearTimeout(t)}}}var pr=class ot extends Error{constructor(e,t){super(t||JSON.stringify(e,null,2)),this.issues=e,Object.setPrototypeOf(this,ot.prototype)}};async function he(r,e){let t=await r["~standard"].validate(e);if(t.issues)throw new pr(t.issues);return t.value}var at=["get","post","put","patch","delete"];var mr=r=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(e,t){var s,n,o,i;let c=((n=(s=r.plugins)==null?void 0:s.find(d=>{var u;return(u=d.schema)!=null&&u.config?e.startsWith(d.schema.config.baseURL||"")||e.startsWith(d.schema.config.prefix||""):!1}))==null?void 0:n.schema)||r.schema;if(c){let d=e;(o=c.config)!=null&&o.prefix&&d.startsWith(c.config.prefix)&&(d=d.replace(c.config.prefix,""),c.config.baseURL&&(e=e.replace(c.config.prefix,c.config.baseURL))),(i=c.config)!=null&&i.baseURL&&d.startsWith(c.config.baseURL)&&(d=d.replace(c.config.baseURL,""));let u=c.schema[d];if(u){let l=L(C({},t),{method:u.method,output:u.output});return t?.disableValidation||(l=L(C({},l),{body:u.input?await he(u.input,t?.body):t?.body,params:u.params?await he(u.params,t?.params):t?.params,query:u.query?await he(u.query,t?.query):t?.query})),{url:e,options:l}}}return{url:e,options:t}}}),it=r=>{async function e(t,s){let n=L(C(C({},r),s),{plugins:[...r?.plugins||[],mr(r||{})]});if(r?.catchAllError)try{return await Oe(t,n)}catch(o){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:o}}}return await Oe(t,n)}return e};function gr(r,e){let{baseURL:t,params:s,query:n}=e||{query:{},params:{},baseURL:""},o=r.startsWith("http")?r.split("/").slice(0,3).join("/"):t||"";if(r.startsWith("@")){let h=r.toString().split("@")[1].split("/")[0];at.includes(h)&&(r=r.replace(`@${h}/`,"/"))}o.endsWith("/")||(o+="/");let[i,c]=r.replace(o,"").split("?"),d=new URLSearchParams(c);for(let[h,m]of Object.entries(n||{}))m!=null&&d.set(h,String(m));if(s)if(Array.isArray(s)){let h=i.split("/").filter(m=>m.startsWith(":"));for(let[m,w]of h.entries()){let v=s[m];i=i.replace(w,v)}}else for(let[h,m]of Object.entries(s))i=i.replace(`:${h}`,String(m));i=i.split("/").map(encodeURIComponent).join("/"),i.startsWith("/")&&(i=i.slice(1));let u=d.toString();return u=u.length>0?`?${u}`.replace(/\+/g,"%20"):"",o.startsWith("http")?new URL(`${i}${u}`,o):`${o}${i}${u}`}var Oe=async(r,e)=>{var t,s,n,o,i,c,d,u;let{hooks:l,url:h,options:m}=await tr(r,e),w=lr(m),v=new AbortController,x=(t=m.signal)!=null?t:v.signal,b=gr(h,m),U=dr(m),P=await cr(m),B=hr(h,m),g=L(C({},m),{url:b,headers:P,body:U,method:B,signal:x});for(let I of l.onRequest)if(I){let S=await I(g);S instanceof Object&&(g=S)}("pipeTo"in g&&typeof g.pipeTo=="function"||typeof((s=e?.body)==null?void 0:s.pipe)=="function")&&("duplex"in g||(g.duplex="half"));let{clearTimeout:W}=fr(m,v),E=await w(g.url,g);W();let Ye={response:E,request:g};for(let I of l.onResponse)if(I){let S=await I(L(C({},Ye),{response:(n=e?.hookOptions)!=null&&n.cloneResponse?E.clone():E}));S instanceof Response?E=S:S instanceof Object&&(E=S.response)}if(E.ok){if(!(g.method!=="HEAD"))return{data:"",error:null};let S=ar(E),j={data:"",response:E,request:g};if(S==="json"||S==="text"){let F=await E.text(),jt=await((o=g.jsonParser)!=null?o:rt)(F);j.data=jt}else j.data=await E[S]();g?.output&&g.output&&!g.disableValidation&&(j.data=await he(g.output,j.data));for(let F of l.onSuccess)F&&await F(L(C({},j),{response:(i=e?.hookOptions)!=null&&i.cloneResponse?E.clone():E}));return e?.throw?j.data:{data:j.data,error:null}}let Mt=(c=e?.jsonParser)!=null?c:rt,de=await E.text(),Qe=ir(de),Ae=Qe?await Mt(de):null,Bt={response:E,responseText:de,request:g,error:L(C({},Ae),{status:E.status,statusText:E.statusText})};for(let I of l.onError)I&&await I(L(C({},Bt),{response:(d=e?.hookOptions)!=null&&d.cloneResponse?E.clone():E}));if(e?.retry){let I=sr(e.retry),S=(u=e.retryAttempt)!=null?u:0;if(await I.shouldAttemptRetry(S,E)){for(let F of l.onRetry)F&&await F(Ye);let j=I.getDelay(S);return await new Promise(F=>setTimeout(F,j)),await Oe(r,L(C({},e),{retryAttempt:S+1}))}}if(e?.throw)throw new er(E.status,E.statusText,Qe?Ae:de);return{data:null,error:L(C({},Ae),{status:E.status,statusText:E.statusText})}};a();a();var fe=Object.create(null),K=r=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(r?fe:globalThis),O=new Proxy(fe,{get(r,e){return K()[e]??fe[e]},has(r,e){let t=K();return e in t||e in fe},set(r,e,t){let s=K(!0);return s[e]=t,!0},deleteProperty(r,e){if(!e)return!1;let t=K(!0);return delete t[e],!0},ownKeys(){let r=K(!0);return Object.keys(r)}});var Ps=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function R(r,e){return typeof process<"u"&&process.env?process.env[r]??e:typeof Deno<"u"?Deno.env.get(r)??e:typeof Bun<"u"?Bun.env[r]??e:e}var As=Object.freeze({get BETTER_AUTH_SECRET(){return R("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return R("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return R("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return R("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return R("NODE_ENV","development")},get PACKAGE_VERSION(){return R("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return R("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),J=1,T=4,$=8,A=24,lt={eterm:T,cons25:T,console:T,cygwin:T,dtterm:T,gnome:T,hurd:T,jfbterm:T,konsole:T,kterm:T,mlterm:T,mosh:A,putty:T,st:T,"rxvt-unicode-24bit":A,terminator:A,"xterm-kitty":A},yr=new Map(Object.entries({APPVEYOR:$,BUILDKITE:$,CIRCLECI:A,DRONE:$,GITEA_ACTIONS:A,GITHUB_ACTIONS:A,GITLAB_CI:$,TRAVIS:$})),br=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function Rr(){if(R("FORCE_COLOR")!==void 0)switch(R("FORCE_COLOR")){case"":case"1":case"true":return T;case"2":return $;case"3":return A;default:return J}if(R("NODE_DISABLE_COLORS")!==void 0&&R("NODE_DISABLE_COLORS")!==""||R("NO_COLOR")!==void 0&&R("NO_COLOR")!==""||R("TERM")==="dumb")return J;if(R("TMUX"))return A;if("TF_BUILD"in O&&"AGENT_NAME"in O)return T;if("CI"in O){for(let{0:r,1:e}of yr)if(r in O)return e;return R("CI_NAME")==="codeship"?$:J}if("TEAMCITY_VERSION"in O)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(R("TEAMCITY_VERSION"))!==null?T:J;switch(R("TERM_PROGRAM")){case"iTerm.app":return!R("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(R("TERM_PROGRAM_VERSION"))!==null?$:A;case"HyperTerm":case"MacTerm":return A;case"Apple_Terminal":return $}if(R("COLORTERM")==="truecolor"||R("COLORTERM")==="24bit")return A;if(R("TERM")){if(/truecolor/.exec(R("TERM"))!==null)return A;if(/^xterm-256/.exec(R("TERM"))!==null)return $;let r=R("TERM").toLowerCase();if(lt[r])return lt[r];if(br.some(e=>e.exec(r)!==null))return T}return R("COLORTERM")?T:J}var D={reset:"\x1B[0m",bright:"\x1B[1m",dim:"\x1B[2m",undim:"\x1B[22m",underscore:"\x1B[4m",blink:"\x1B[5m",reverse:"\x1B[7m",hidden:"\x1B[8m",fg:{black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m"},bg:{black:"\x1B[40m",red:"\x1B[41m",green:"\x1B[42m",yellow:"\x1B[43m",blue:"\x1B[44m",magenta:"\x1B[45m",cyan:"\x1B[46m",white:"\x1B[47m"}},Ue=["info","success","warn","error","debug"];function wr(r,e){return Ue.indexOf(e)<=Ue.indexOf(r)}var Er={info:D.fg.blue,success:D.fg.green,warn:D.fg.yellow,error:D.fg.red,debug:D.fg.magenta},vr=(r,e,t)=>{let s=new Date().toISOString();return t?`${D.dim}${s}${D.reset} ${Er[r]}${r.toUpperCase()}${D.reset} ${D.bright}[Better Auth]:${D.reset} ${e}`:`${s} ${r.toUpperCase()} [Better Auth]: ${e}`},Tr=r=>{let e=r?.disabled!==!0,t=r?.level??"error",n=r?.disableColors!==void 0?!r.disableColors:Rr()!==1,o=(c,d,u=[])=>{if(!e||!wr(t,c))return;let l=vr(c,d,n);if(!r||typeof r.log!="function"){c==="error"?console.error(l,...u):c==="warn"?console.warn(l,...u):console.log(l,...u);return}r.log(c==="success"?"info":c,d,...u)};return{...Object.fromEntries(Ue.map(c=>[c,(...[d,...u])=>o(c,d,u)])),get level(){return t}}},Os=Tr();a();a();var $s={USER_NOT_FOUND:"User not found",FAILED_TO_CREATE_USER:"Failed to create user",FAILED_TO_CREATE_SESSION:"Failed to create session",FAILED_TO_UPDATE_USER:"Failed to update user",FAILED_TO_GET_SESSION:"Failed to get session",INVALID_PASSWORD:"Invalid password",INVALID_EMAIL:"Invalid email",INVALID_EMAIL_OR_PASSWORD:"Invalid email or password",SOCIAL_ACCOUNT_ALREADY_LINKED:"Social account already linked",PROVIDER_NOT_FOUND:"Provider not found",INVALID_TOKEN:"Invalid token",ID_TOKEN_NOT_SUPPORTED:"id_token not supported",FAILED_TO_GET_USER_INFO:"Failed to get user info",USER_EMAIL_NOT_FOUND:"User email not found",EMAIL_NOT_VERIFIED:"Email not verified",PASSWORD_TOO_SHORT:"Password too short",PASSWORD_TOO_LONG:"Password too long",USER_ALREADY_EXISTS:"User already exists.",USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:"User already exists. Use another email.",EMAIL_CAN_NOT_BE_UPDATED:"Email can not be updated",CREDENTIAL_ACCOUNT_NOT_FOUND:"Credential account not found",SESSION_EXPIRED:"Session expired. Re-authenticate to perform this action.",FAILED_TO_UNLINK_LAST_ACCOUNT:"You can't unlink your last account",ACCOUNT_NOT_FOUND:"Account not found",USER_ALREADY_HAS_PASSWORD:"User already has a password. Provide that to delete the account."},G=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function _r(r){try{return(new URL(r).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new G(`Invalid base URL: ${r}. Please provide a valid base URL.`)}}function Y(r,e="/api/auth"){if(_r(r))return r;let s=r.replace(/\/+$/,"");return!e||e==="/"?s:(e=e.startsWith("/")?e:`/${e}`,`${s}${e}`)}function ct(r,e,t,s){if(r)return Y(r,e);if(s!==!1){let i=O.BETTER_AUTH_URL||O.NEXT_PUBLIC_BETTER_AUTH_URL||O.PUBLIC_BETTER_AUTH_URL||O.NUXT_PUBLIC_BETTER_AUTH_URL||O.NUXT_PUBLIC_AUTH_URL||(O.BASE_URL!=="/"?O.BASE_URL:void 0);if(i)return Y(i,e)}let n=t?.headers.get("x-forwarded-host"),o=t?.headers.get("x-forwarded-proto");if(n&&o)return Y(`${o}://${n}`,e);if(t){let i=Sr(t.url);if(!i)throw new G("Could not get origin from request. Please provide a valid base URL.");return Y(i,e)}if(typeof window<"u"&&window.location)return Y(window.location.origin,e)}function Sr(r){try{return new URL(r).origin}catch{return null}}a();a();a();var Q=Symbol("clean");var N=[],q=0,pe=4,Pr=0,X=r=>{let e=[],t={get(){return t.lc||t.listen(()=>{})(),t.value},lc:0,listen(s){return t.lc=e.push(s),()=>{for(let o=q+pe;o<N.length;)N[o]===s?N.splice(o,pe):o+=pe;let n=e.indexOf(s);~n&&(e.splice(n,1),--t.lc||t.off())}},notify(s,n){Pr++;let o=!N.length;for(let i of e)N.push(i,t.value,s,n);if(o){for(q=0;q<N.length;q+=pe)N[q](N[q+1],N[q+2],N[q+3]);N.length=0}},off(){},set(s){let n=t.value;n!==s&&(t.value=s,t.notify(n))},subscribe(s){let n=t.listen(s);return s(t.value),n},value:r};return process.env.NODE_ENV!=="production"&&(t[Q]=()=>{e=[],t.lc=0,t.off()}),t};a();var Ar=5,z=6,me=10,Or=(r,e,t,s)=>(r.events=r.events||{},r.events[t+me]||(r.events[t+me]=s(n=>{r.events[t].reduceRight((o,i)=>(i(o),o),{shared:{},...n})})),r.events[t]=r.events[t]||[],r.events[t].push(e),()=>{let n=r.events[t],o=n.indexOf(e);n.splice(o,1),n.length||(delete r.events[t],r.events[t+me](),delete r.events[t+me])});var ut=1e3,Ie=(r,e)=>Or(r,s=>{let n=e(s);n&&r.events[z].push(n)},Ar,s=>{let n=r.listen;r.listen=(...i)=>(!r.lc&&!r.active&&(r.active=!0,s()),n(...i));let o=r.off;if(r.events[z]=[],r.off=()=>{o(),setTimeout(()=>{if(r.active&&!r.lc){r.active=!1;for(let i of r.events[z])i();r.events[z]=[]}},ut)},process.env.NODE_ENV!=="production"){let i=r[Q];r[Q]=()=>{for(let c of r.events[z])c();r.events[z]=[],r.active=!1,i()}}return()=>{r.listen=n,r.off=o}});a();var Ur=typeof window>"u",ge=(r,e,t,s)=>{let n=X({data:null,error:null,isPending:!0,isRefetching:!1,refetch:c=>o(c)}),o=c=>{let d=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;t(e,{...d,query:{...d?.query,...c?.query},async onSuccess(u){n.set({data:u.data,error:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onSuccess?.(u)},async onError(u){let{request:l}=u,h=typeof l.retry=="number"?l.retry:l.retry?.attempts,m=l.retryAttempt||0;h&&m<h||(n.set({error:u.error,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch}),await d?.onError?.(u))},async onRequest(u){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0,refetch:n.value.refetch}),await d?.onRequest?.(u)}}).catch(u=>{n.set({error:u,data:null,isPending:!1,isRefetching:!1,refetch:n.value.refetch})})};r=Array.isArray(r)?r:[r];let i=!1;for(let c of r)c.subscribe(()=>{Ur||(i?o():Ie(n,()=>{let d=setTimeout(()=>{i||(o(),i=!0)},0);return()=>{n.off(),c.off(),clearTimeout(d)}}))});return n};a();var Ir={proto:/"(?:_|\\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*:/,constructor:/"(?: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*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},xr=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,dt={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Cr=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Nr(r){return r instanceof Date&&!isNaN(r.getTime())}function Lr(r){let e=Cr.exec(r);if(!e)return null;let[,t,s,n,o,i,c,d,u,l,h]=e,m=new Date(Date.UTC(parseInt(t,10),parseInt(s,10)-1,parseInt(n,10),parseInt(o,10),parseInt(i,10),parseInt(c,10),d?parseInt(d.padEnd(3,"0"),10):0));if(u){let w=(parseInt(l,10)*60+parseInt(h,10))*(u==="+"?-1:1);m.setUTCMinutes(m.getUTCMinutes()+w)}return Nr(m)?m:null}function $r(r,e={}){let{strict:t=!1,warnings:s=!1,reviver:n,parseDates:o=!0}=e;if(typeof r!="string")return r;let i=r.trim();if(i.length>0&&i[0]==='"'&&i.endsWith('"')&&!i.slice(1,-1).includes('"'))return i.slice(1,-1);let c=i.toLowerCase();if(c.length<=9&&c in dt)return dt[c];if(!xr.test(i)){if(t)throw new SyntaxError("[better-json] Invalid JSON");return r}if(Object.entries(Ir).some(([u,l])=>{let h=l.test(i);return h&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),h})&&t)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(i,(l,h)=>{if(l==="__proto__"||l==="constructor"&&h&&typeof h=="object"&&"prototype"in h){s&&console.warn(`[better-json] Dropping "${l}" key to prevent prototype pollution`);return}if(o&&typeof h=="string"){let m=Lr(h);if(m)return m}return n?n(l,h):h})}catch(u){if(t)throw u;return r}}function ht(r,e={strict:!0}){return $r(r,e)}var Dr={id:"redirect",name:"Redirect",hooks:{onSuccess(r){if(r.data?.url&&r.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=r.data.url}catch{}}}};function kr(r){let e=X(!1);return{session:ge(e,"/get-session",r,{method:"GET"}),$sessionSignal:e}}var ft=(r,e)=>{let t="credentials"in Request.prototype,s=ct(r?.baseURL,r?.basePath,void 0,e)??"/api/auth",n=r?.plugins?.flatMap(g=>g.fetchPlugins).filter(g=>g!==void 0)||[],o={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:r?.fetchOptions?.onSuccess,onError:r?.fetchOptions?.onError,onRequest:r?.fetchOptions?.onRequest,onResponse:r?.fetchOptions?.onResponse}},{onSuccess:i,onError:c,onRequest:d,onResponse:u,...l}=r?.fetchOptions||{},h=it({baseURL:s,...t?{credentials:"include"}:{},method:"GET",jsonParser(g){return g?ht(g,{strict:!1}):null},customFetchImpl:fetch,...l,plugins:[o,...l.plugins||[],...r?.disableDefaultFetchPlugins?[]:[Dr],...n]}),{$sessionSignal:m,session:w}=kr(h),v=r?.plugins||[],x={},b={$sessionSignal:m,session:w},U={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},P=[{signal:"$sessionSignal",matcher(g){return g==="/sign-out"||g==="/update-user"||g.startsWith("/sign-in")||g.startsWith("/sign-up")||g==="/delete-user"||g==="/verify-email"}}];for(let g of v)g.getAtoms&&Object.assign(b,g.getAtoms?.(h)),g.pathMethods&&Object.assign(U,g.pathMethods),g.atomListeners&&P.push(...g.atomListeners);let B={notify:g=>{b[g].set(!b[g].get())},listen:(g,W)=>{b[g].subscribe(W)},atoms:b};for(let g of v)g.getActions&&Object.assign(x,g.getActions?.(h,B,r));return{get baseURL(){return s},pluginsActions:x,pluginsAtoms:b,pluginPathMethods:U,atomListeners:P,$fetch:h,$store:B}};function Mr(r){return typeof r=="object"&&r!==null&&"get"in r&&typeof r.get=="function"&&"lc"in r&&typeof r.lc=="number"}function Br(r,e,t){let s=e[r],{fetchOptions:n,query:o,...i}=t||{};return s||(n?.method?n.method:i&&Object.keys(i).length>0?"POST":"GET")}function pt(r,e,t,s,n){function o(i=[]){return new Proxy(function(){},{get(c,d){if(typeof d!="string"||d==="then"||d==="catch"||d==="finally")return;let u=[...i,d],l=r;for(let h of u)if(l&&typeof l=="object"&&h in l)l=l[h];else{l=void 0;break}return typeof l=="function"||Mr(l)?l:o(u)},apply:async(c,d,u)=>{let l="/"+i.map(P=>P.replace(/[A-Z]/g,B=>`-${B.toLowerCase()}`)).join("/"),h=u[0]||{},m=u[1]||{},{query:w,fetchOptions:v,...x}=h,b={...m,...v},U=Br(l,t,h);return await e(l,{...b,body:U==="GET"?void 0:{...x,...b?.body||{}},query:w||b?.query,method:U,async onSuccess(P){if(await b?.onSuccess?.(P),!n)return;let B=n.filter(g=>g.matcher(l));if(B.length)for(let g of B){let W=s[g.signal];if(!W)return;let E=W.get();setTimeout(()=>{W.set(!E)},10)}}})}})}return o()}a();function mt(r){return r.charAt(0).toUpperCase()+r.slice(1)}function xe(r){let{pluginPathMethods:e,pluginsActions:t,pluginsAtoms:s,$fetch:n,atomListeners:o,$store:i}=ft(r),c={};for(let[l,h]of Object.entries(s))c[`use${mt(l)}`]=h;let d={...t,...c,$fetch:n,$store:i};return pt(d,n,e,s,o)}a();a();a();function jr(r){return{authorize(e,t="AND"){let s=!1;for(let[n,o]of Object.entries(e)){let i=r[n];if(!i)return{success:!1,error:`You are not allowed to access resource: ${n}`};if(Array.isArray(o))s=o.every(c=>i.includes(c));else if(typeof o=="object"){let c=o;c.connector==="OR"?s=c.actions.some(d=>i.includes(d)):s=c.actions.every(d=>i.includes(d))}else throw new G("Invalid access control request");if(s&&t==="OR")return{success:s};if(!s&&t==="AND")return{success:!1,error:`unauthorized to access resource "${n}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:r}}function ye(r){return{newRole(e){return jr(e)},statements:r}}var Fr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},Ce=ye(Fr),Hr=Ce.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),qr=Ce.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),Wr=Ce.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});a();a();a();a();a();a();a();a();a();a();a();var Ne=class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let t=new Error("Cancelling existing WebAuthn API call for new one");t.name="AbortError",this.controller.abort(t)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=new Error("Manually cancelling existing WebAuthn API call");e.name="AbortError",this.controller.abort(e),this.controller=void 0}}},bt=new Ne;a();a();a();a();a();a();a();a();var Jr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},Rt=ye(Jr),Yr=Rt.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),Qr=Rt.newRole({user:[],session:[]});a();a();var wt=()=>({id:"username",$InferServerPlugin:{}});var Xr="/auth",be="nvwa_login_token",$e="nvwa_user_profile",Et=class{constructor(e,t,s){this.storage=s,this.authClient=xe({baseURL:e,basePath:Xr,fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:()=>s.get(be)},onSuccess:n=>{let o=n.response.headers.get("set-auth-token");o&&s.set(be,o)}},plugins:[wt()]})}async currentUser(){return await this.storage.get($e)}async signUp(e,t){let s=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:t});this.saveSession(s)}async signInWithUsername(e,t){let s=await this.authClient.signIn.username({username:e,password:t});this.saveSession(s)}saveSession(e){if(e.error)throw new Error(e.error.message);this.storage.set(be,e.data?.token),this.storage.set($e,e.data?.user)}async signOut(){await this.storage.remove(be),await this.storage.remove($e)}async updateUserPassword(e,t,s=!1){let n=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:s});this.saveSession(n)}};a();var vt=class{constructor(e){this.http=e}async invoke(e,t){return(await this.http.request("/functions/"+e,{method:t.method||"POST",data:t.body,headers:t.headers})).body}};a();var Tt=class{constructor(e,t,s,n,o){this.ok=e,this.status=t,this.statusText=s,this.headers=n,this.body=o}async text(){return typeof this.body=="string"?this.body:JSON.stringify(this.body)}async json(){if(typeof this.body=="string")try{return JSON.parse(this.body)}catch{return this.body}return this.body}async arrayBuffer(){if(this.body instanceof ArrayBuffer)return this.body;if(typeof this.body=="string")return new TextEncoder().encode(this.body).buffer;throw new Error("Cannot convert body to ArrayBuffer")}async blob(){if(this.body instanceof Blob)return this.body;if(typeof this.body=="string")return new Blob([this.body],{type:this.headers["content-type"]||"text/plain"});throw new Error("Cannot convert body to Blob")}},_t=class{async jsonRequest(e,t){let s={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.request(e,s)}async jsonRequestWithAuth(e,t,s){let n={...t,headers:{"Content-Type":"application/json",...t.headers},data:typeof t.data=="object"?JSON.stringify(t.data):t.data};return this.requestWithAuth(e,n,s)}};a();var Zr="/storage",es=Zr+"/generateUploadUrl",St=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.request(this.baseUrl+es,{method:"POST",data:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:s}=t.body;if(!s)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");return{url:(await this.http.request(s,{method:"PUT",data:e,headers:{"Content-Type":e.type||e.fileType||"application/octet-stream"}})).body.url.split("?")[0]}}};a();a();a();var Dt=Kt($t(),1),{PostgrestClient:kt,PostgrestQueryBuilder:ii,PostgrestFilterBuilder:li,PostgrestTransformBuilder:ci,PostgrestBuilder:ui,PostgrestError:di,FetchHeaders:hi,FetchResponse:Je,PostgrestFetch:fi,URL:pi,URLSearchParams:mi}=Dt.default;var ds="/entities",hs=(r,e)=>async(s,n)=>{console.log("customFetch",s,n);let o;if(typeof s=="string")o=s;else if(s&&typeof s=="object")if(typeof s.toString=="function"&&!s.url)o=s.toString();else if(s.url)o=s.url,n||(n={}),n.method=s.method,n.headers=s.headers,n.body=s.body;else throw new Error("Unsupported input type for fetch");else throw new Error("Unsupported input type for fetch");let i=(n?.method||"GET").toUpperCase(),c={};if(n?.headers)if(n.headers&&typeof n.headers.forEach=="function")n.headers.forEach((w,v)=>{c[v]=w});else if(Array.isArray(n.headers))for(let[w,v]of n.headers)c[w]=v;else Object.assign(c,n.headers);let d=n?.body,u;try{u=await r.requestWithAuth(o,{method:i,data:d,headers:c},e)}catch(w){return new Je(w?.message||"Internal Error",{status:500,statusText:"Internal Error"})}let l=u.body,h=null;return(u.headers["content-type"]||u.headers["Content-Type"]||"").startsWith("application/json")&&typeof l!="string"?h=JSON.stringify(l):typeof l=="string"||l&&(l.constructor===Blob||l.constructor===ArrayBuffer||typeof l.getReader=="function")?h=l:h=JSON.stringify(l),new Je(h,{status:u.status,headers:u.headers})},Ei=(r,e,t)=>new kt(r+ds,{fetch:hs(e,t)});a();a();var M=class r{constructor(e){this.headerMap=new Map;if(e){if(e instanceof r)e.forEach((t,s)=>this.set(s,t));else if(Array.isArray(e))for(let[t,s]of e)this.set(t,String(s));else if(typeof e=="object")for(let t of Object.keys(e))this.set(t,String(e[t]))}}append(e,t){let s=e.toLowerCase(),n=this.headerMap.get(s);this.headerMap.set(s,n?`${n}, ${t}`:t)}set(e,t){this.headerMap.set(e.toLowerCase(),String(t))}get(e){let t=this.headerMap.get(e.toLowerCase());return t??null}has(e){return this.headerMap.has(e.toLowerCase())}delete(e){this.headerMap.delete(e.toLowerCase())}forEach(e){for(let[t,s]of this.headerMap.entries())e(s,t,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}},ce=class r{constructor(e){this.params=new Map;if(e){if(typeof e=="string")this.parseString(e);else if(e instanceof r)this.params=new Map(e.params);else if(Array.isArray(e))for(let[t,s]of e)this.append(t,s);else if(e&&typeof e=="object")for(let[t,s]of Object.entries(e))this.set(t,s)}}parseString(e){e.startsWith("?")&&(e=e.slice(1));let t=e.split("&");for(let s of t)if(s){let[n,o]=s.split("=");n&&this.append(decodeURIComponent(n),o?decodeURIComponent(o):"")}}append(e,t){let s=this.params.get(e)||[];s.push(t),this.params.set(e,s)}delete(e){this.params.delete(e)}get(e){let t=this.params.get(e);return t?t[0]:null}getAll(e){return this.params.get(e)||[]}has(e){return this.params.has(e)}set(e,t){this.params.set(e,[t])}sort(){let e=Array.from(this.params.entries()).sort(([t],[s])=>t.localeCompare(s));this.params=new Map(e)}toString(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push(`${encodeURIComponent(t)}=${encodeURIComponent(n)}`);return e.join("&")}forEach(e){for(let[t,s]of this.params.entries())for(let n of s)e(n,t,this)}keys(){return this.params.keys()}values(){let e=[];for(let t of this.params.values())e.push(...t);return e[Symbol.iterator]()}entries(){let e=[];for(let[t,s]of this.params.entries())for(let n of s)e.push([t,n]);return e[Symbol.iterator]()}[Symbol.iterator](){return this.entries()}get size(){return this.params.size}},Te=class r{constructor(e,t){let s;if(e instanceof r)s=e.href;else if(t){let o=t instanceof r?t.href:t;s=this.resolve(o,e)}else s=e;let n=this.parseUrl(s);this.href=s,this.origin=`${n.protocol}//${n.host}`,this.protocol=n.protocol,this.username=n.username,this.password=n.password,this.host=n.host,this.hostname=n.hostname,this.port=n.port,this.pathname=n.pathname,this.search=n.search,this.searchParams=new ce(n.search),this.hash=n.hash}resolve(e,t){if(t.startsWith("http://")||t.startsWith("https://"))return t;if(t.startsWith("//"))return`${this.parseUrl(e).protocol}${t}`;if(t.startsWith("/")){let o=this.parseUrl(e);return`${o.protocol}//${o.host}${t}`}let s=this.parseUrl(e),n=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";return`${s.protocol}//${s.host}${n}${t}`}parseUrl(e){let t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)throw new TypeError("Invalid URL");let s=t[2]||"",n=t[4]||"",o=t[5]||"/",i=t[7]?`?${t[7]}`:"",c=t[9]?`#${t[9]}`:"";if(!s&&!n&&!o.startsWith("/")&&!o.includes("/")&&!o.includes("."))throw new TypeError("Invalid URL");let d=n.match(/^([^@]*)@(.+)$/),u="",l="",h=n;if(d){let x=d[1];h=d[2];let b=x.match(/^([^:]*):?(.*)$/);b&&(u=b[1]||"",l=b[2]||"")}let m=h.match(/^([^:]+):?(\d*)$/),w=m?m[1]:h,v=m&&m[2]?m[2]:"";return{protocol:s?`${s}:`:"",username:u,password:l,host:h,hostname:w,port:v,pathname:o,search:i,hash:c}}toString(){let e=this.searchParams.toString(),t=e?`?${e}`:"";return`${this.protocol}//${this.host}${this.pathname}${t}${this.hash}`}toJSON(){return this.toString()}};a();var _e=class r{constructor(e,t){if(typeof e=="string")this.url=e;else if(e?.url)this.url=String(e.url);else if(typeof e?.toString=="function")this.url=String(e.toString());else throw new Error("Invalid input for Request");this.method=(t?.method||"GET").toUpperCase(),this.headers=t?.headers instanceof M?t.headers:new M(t?.headers),this.body=t?.body,this.timeout=t?.timeout,this.signal=t?.signal||void 0}clone(){return new r(this.url,{method:this.method,headers:this.headers,body:this.body,timeout:this.timeout})}toString(){return this.url}};a();var Se=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=fs(t?.headers),this.ok=this.status>=200&&this.status<300}async text(){return typeof this.bodyData=="string"?this.bodyData:this.bodyData==null?"":typeof this.bodyData=="object"?JSON.stringify(this.bodyData):String(this.bodyData)}async json(){if(typeof this.bodyData=="string")try{return JSON.parse(this.bodyData)}catch{}return this.bodyData}async arrayBuffer(){let e=await this.text();return new TextEncoder().encode(e).buffer}};function fs(r){return r?new M(r):new M}a();var ue=class{constructor(){this._aborted=!1;this.listeners=new Set;this.onabort=null}get aborted(){return this._aborted}_trigger(){if(!this._aborted){if(this._aborted=!0,typeof this.onabort=="function")try{this.onabort()}catch{}for(let e of Array.from(this.listeners))try{e()}catch{}this.listeners.clear()}}addEventListener(e,t){if(this._aborted){try{t()}catch{}return}this.listeners.add(t)}removeEventListener(e,t){this.listeners.delete(t)}toString(){return"[object AbortSignal]"}},Pe=class{constructor(){this._signal=new ue}get signal(){return this._signal}abort(){this._signal._trigger()}toString(){return"[object AbortController]"}};a();function Mi(r){r.URL=Te,r.URLSearchParams=ce,r.Headers=M,r.Request=_e,r.Response=Se,r.AbortController=Pe,r.AbortSignal=ue}export{Xr as AUTH_BASE_PATH,Pe as AbortController,ue as AbortSignal,ds as ENTITIES_BASE_PATH,Zr as FILE_STORAGE_BASE_PATH,Tt as FetchResponse,es as GENERATE_UPLOAD_URL_PATH,M as Headers,be as LOGIN_TOKEN_KEY,$e as LOGIN_USER_PROFILE_KEY,Et as NvwaAuthClient,vt as NvwaEdgeFunctions,St as NvwaFileStorage,_t as NvwaHttpClient,_e as Request,Se as Response,Te as URL,ce as URLSearchParams,Ei as createPostgrestClient,Mi as polyfill};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nvwa-app/sdk-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "NVWA跨端通用工具类核心接口",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.mjs",
|
|
11
|
-
"require": "./dist/index.
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
}
|
|
14
14
|
},
|