@nvwa-app/sdk-web 0.7.0 → 0.7.2

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var ue=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var xt=Object.prototype.hasOwnProperty;var Ut=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})},Ct=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Nt(t))!xt.call(e,a)&&a!==r&&ue(e,a,{get:()=>t[a],enumerable:!(s=It(t,a))||s.enumerable});return e};var Lt=e=>Ct(ue({},"__esModule",{value:!0}),e);var is={};Ut(is,{default:()=>ie,localStorage:()=>_e});module.exports=Lt(is);var Dt=Object.create,ae=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,Bt=Object.getOwnPropertyNames,Mt=Object.getPrototypeOf,Ft=Object.prototype.hasOwnProperty,Ne=(e,t)=>()=>(e&&(t=e(e=0)),t),D=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ht=(e,t)=>{for(var r in t)ae(e,r,{get:t[r],enumerable:!0})},xe=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Bt(t))!Ft.call(e,a)&&a!==r&&ae(e,a,{get:()=>t[a],enumerable:!(s=kt(t,a))||s.enumerable});return e},qt=(e,t,r)=>(r=e!=null?Dt(Mt(e)):{},xe(t||!e||!e.__esModule?ae(r,"default",{value:e,enumerable:!0}):r,e)),q=e=>xe(ae({},"__esModule",{value:!0}),e),f=Ne(()=>{"use strict"}),k={};Ht(k,{__addDisposableResource:()=>nt,__assign:()=>V,__asyncDelegator:()=>Je,__asyncGenerator:()=>Ye,__asyncValues:()=>Xe,__await:()=>H,__awaiter:()=>qe,__classPrivateFieldGet:()=>tt,__classPrivateFieldIn:()=>st,__classPrivateFieldSet:()=>rt,__createBinding:()=>Y,__decorate:()=>Le,__disposeResources:()=>at,__esDecorate:()=>ke,__exportStar:()=>Ge,__extends:()=>Ue,__generator:()=>We,__importDefault:()=>et,__importStar:()=>Ze,__makeTemplateObject:()=>Qe,__metadata:()=>He,__param:()=>De,__propKey:()=>Me,__read:()=>ye,__rest:()=>Ce,__rewriteRelativeImportExtension:()=>ot,__runInitializers:()=>Be,__setFunctionName:()=>Fe,__spread:()=>Ke,__spreadArray:()=>Ve,__spreadArrays:()=>ze,__values:()=>ne,default:()=>ut});function Ue(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Z(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function Ce(e,t){var r={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,s=Object.getOwnPropertySymbols(e);a<s.length;a++)t.indexOf(s[a])<0&&Object.prototype.propertyIsEnumerable.call(e,s[a])&&(r[s[a]]=e[s[a]]);return r}function Le(e,t,r,s){var a=arguments.length,n=a<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,r):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(n=(a<3?o(n):a>3?o(t,r,n):o(t,r))||n);return a>3&&n&&Object.defineProperty(t,r,n),n}function De(e,t){return function(r,s){t(r,s,e)}}function ke(e,t,r,s,a,n){function o(v){if(v!==void 0&&typeof v!="function")throw new TypeError("Function expected");return v}for(var i=s.kind,u=i==="getter"?"get":i==="setter"?"set":"value",l=!t&&e?s.static?e:e.prototype:null,c=t||(l?Object.getOwnPropertyDescriptor(l,s.name):{}),h,m=!1,d=r.length-1;d>=0;d--){var y={};for(var b in s)y[b]=b==="access"?{}:s[b];for(var b in s.access)y.access[b]=s.access[b];y.addInitializer=function(v){if(m)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(v||null))};var g=(0,r[d])(i==="accessor"?{get:c.get,set:c.set}:c[u],y);if(i==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(h=o(g.get))&&(c.get=h),(h=o(g.set))&&(c.set=h),(h=o(g.init))&&a.unshift(h)}else(h=o(g))&&(i==="field"?a.unshift(h):c[u]=h)}l&&Object.defineProperty(l,s.name,c),m=!0}function Be(e,t,r){for(var s=arguments.length>2,a=0;a<t.length;a++)r=s?t[a].call(e,r):t[a].call(e);return s?r:void 0}function Me(e){return typeof e=="symbol"?e:"".concat(e)}function Fe(e,t,r){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:r?"".concat(r," ",t):t})}function He(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function qe(e,t,r,s){function a(n){return n instanceof r?n:new r(function(o){o(n)})}return new(r||(r=Promise))(function(n,o){function i(c){try{l(s.next(c))}catch(h){o(h)}}function u(c){try{l(s.throw(c))}catch(h){o(h)}}function l(c){c.done?n(c.value):a(c.value).then(i,u)}l((s=s.apply(e,t||[])).next())})}function We(e,t){var r={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},s,a,n,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=i(0),o.throw=i(1),o.return=i(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function i(l){return function(c){return u([l,c])}}function u(l){if(s)throw new TypeError("Generator is already executing.");for(;o&&(o=0,l[0]&&(r=0)),r;)try{if(s=1,a&&(n=l[0]&2?a.return:l[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,l[1])).done)return n;switch(a=0,n&&(l=[l[0]&2,n.value]),l[0]){case 0:case 1:n=l;break;case 4:return r.label++,{value:l[1],done:!1};case 5:r.label++,a=l[1],l=[0];continue;case 7:l=r.ops.pop(),r.trys.pop();continue;default:if(n=r.trys,!(n=n.length>0&&n[n.length-1])&&(l[0]===6||l[0]===2)){r=0;continue}if(l[0]===3&&(!n||l[1]>n[0]&&l[1]<n[3])){r.label=l[1];break}if(l[0]===6&&r.label<n[1]){r.label=n[1],n=l;break}if(n&&r.label<n[2]){r.label=n[2],r.ops.push(l);break}n[2]&&r.ops.pop(),r.trys.pop();continue}l=t.call(e,r)}catch(c){l=[6,c],a=0}finally{s=n=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}function Ge(e,t){for(var r in e)r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r)&&Y(t,e,r)}function ne(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],s=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&s>=e.length&&(e=void 0),{value:e&&e[s++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function ye(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var s=r.call(e),a,n=[],o;try{for(;(t===void 0||t-- >0)&&!(a=s.next()).done;)n.push(a.value)}catch(i){o={error:i}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return n}function Ke(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(ye(arguments[t]));return e}function ze(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;for(var s=Array(e),a=0,t=0;t<r;t++)for(var n=arguments[t],o=0,i=n.length;o<i;o++,a++)s[a]=n[o];return s}function Ve(e,t,r){if(r||arguments.length===2)for(var s=0,a=t.length,n;s<a;s++)(n||!(s in t))&&(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}function H(e){return this instanceof H?(this.v=e,this):new H(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=r.apply(e,t||[]),a,n=[];return a=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),i("next"),i("throw"),i("return",o),a[Symbol.asyncIterator]=function(){return this},a;function o(d){return function(y){return Promise.resolve(y).then(d,h)}}function i(d,y){s[d]&&(a[d]=function(b){return new Promise(function(g,v){n.push([d,b,g,v])>1||u(d,b)})},y&&(a[d]=y(a[d])))}function u(d,y){try{l(s[d](y))}catch(b){m(n[0][3],b)}}function l(d){d.value instanceof H?Promise.resolve(d.value.v).then(c,h):m(n[0][2],d)}function c(d){u("next",d)}function h(d){u("throw",d)}function m(d,y){d(y),n.shift(),n.length&&u(n[0][0],n[0][1])}}function Je(e){var t,r;return t={},s("next"),s("throw",function(a){throw a}),s("return"),t[Symbol.iterator]=function(){return this},t;function s(a,n){t[a]=e[a]?function(o){return(r=!r)?{value:H(e[a](o)),done:!1}:n?n(o):o}:n}}function Xe(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof ne=="function"?ne(e):e[Symbol.iterator](),r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r);function s(n){r[n]=e[n]&&function(o){return new Promise(function(i,u){o=e[n](o),a(i,u,o.done,o.value)})}}function a(n,o,i,u){Promise.resolve(u).then(function(l){n({value:l,done:i})},o)}}function Qe(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function Ze(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=ee(e),s=0;s<r.length;s++)r[s]!=="default"&&Y(t,e,r[s]);return it(t,e),t}function et(e){return e&&e.__esModule?e:{default:e}}function tt(e,t,r,s){if(r==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?s:r==="a"?s.call(e):s?s.value:t.get(e)}function rt(e,t,r,s,a){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!a)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?a.call(e,r):a?a.value=r:t.set(e,r),r}function st(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function nt(e,t,r){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var s,a;if(r){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");s=t[Symbol.asyncDispose]}if(s===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");s=t[Symbol.dispose],r&&(a=s)}if(typeof s!="function")throw new TypeError("Object not disposable.");a&&(s=function(){try{a.call(this)}catch(n){return Promise.reject(n)}}),e.stack.push({value:t,dispose:s,async:r})}else r&&e.stack.push({async:!0});return t}function at(e){function t(n){e.error=e.hasError?new lt(n,e.error,"An error was suppressed during disposal."):n,e.hasError=!0}var r,s=0;function a(){for(;r=e.stack.pop();)try{if(!r.async&&s===1)return s=0,e.stack.push(r),Promise.resolve().then(a);if(r.dispose){var n=r.dispose.call(r.value);if(r.async)return s|=2,Promise.resolve(n).then(a,function(o){return t(o),a()})}else s|=1}catch(o){t(o)}if(s===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return a()}function ot(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(r,s,a,n,o){return s?t?".jsx":".js":a&&(!n||!o)?r:a+n+"."+o.toLowerCase()+"js"}):e}var Z,V,Y,it,ee,lt,ut,W=Ne(()=>{"use strict";f(),Z=function(e,t){return Z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,s){r.__proto__=s}||function(r,s){for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(r[a]=s[a])},Z(e,t)},V=function(){return V=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},V.apply(this,arguments)},Y=Object.create?(function(e,t,r,s){s===void 0&&(s=r);var a=Object.getOwnPropertyDescriptor(t,r);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,a)}):(function(e,t,r,s){s===void 0&&(s=r),e[s]=t[r]}),it=Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t},ee=function(e){return ee=Object.getOwnPropertyNames||function(t){var r=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(r[r.length]=s);return r},ee(e)},lt=typeof SuppressedError=="function"?SuppressedError:function(e,t,r){var s=new Error(r);return s.name="SuppressedError",s.error=e,s.suppressed=t,s},ut={__extends:Ue,__assign:V,__rest:Ce,__decorate:Le,__param:De,__esDecorate:ke,__runInitializers:Be,__propKey:Me,__setFunctionName:Fe,__metadata:He,__awaiter:qe,__generator:We,__createBinding:Y,__exportStar:Ge,__values:ne,__read:ye,__spread:Ke,__spreadArrays:ze,__spreadArray:Ve,__await:H,__asyncGenerator:Ye,__asyncDelegator:Je,__asyncValues:Xe,__makeTemplateObject:Qe,__importStar:Ze,__importDefault:et,__classPrivateFieldGet:tt,__classPrivateFieldSet:rt,__classPrivateFieldIn:st,__addDisposableResource:nt,__disposeResources:at,__rewriteRelativeImportExtension:ot}}),ct=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}};e.default=t}),ht=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ct()),s=class{constructor(a){var n,o;this.shouldThrowOnError=!1,this.method=a.method,this.url=a.url,this.headers=new Headers(a.headers),this.schema=a.schema,this.body=a.body,this.shouldThrowOnError=(n=a.shouldThrowOnError)!==null&&n!==void 0?n:!1,this.signal=a.signal,this.isMaybeSingle=(o=a.isMaybeSingle)!==null&&o!==void 0?o:!1,a.fetch?this.fetch=a.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(a,n){return this.headers=new Headers(this.headers),this.headers.set(a,n),this}then(a,n){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 o=this.fetch,i=o(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async u=>{var l,c,h,m;let d=null,y=null,b=null,g=u.status,v=u.statusText;if(u.ok){if(this.method!=="HEAD"){let p=await u.text();p===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&!((l=this.headers.get("Accept"))===null||l===void 0)&&l.includes("application/vnd.pgrst.plan+text")?y=p:y=JSON.parse(p))}let P=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),S=(h=u.headers.get("content-range"))===null||h===void 0?void 0:h.split("/");P&&S&&S.length>1&&(b=parseInt(S[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(y)&&(y.length>1?(d={code:"PGRST116",details:`Results contain ${y.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},y=null,b=null,g=406,v="Not Acceptable"):y.length===1?y=y[0]:y=null)}else{let P=await u.text();try{d=JSON.parse(P),Array.isArray(d)&&u.status===404&&(y=[],d=null,g=200,v="OK")}catch{u.status===404&&P===""?(g=204,v="No Content"):d={message:P}}if(d&&this.isMaybeSingle&&!((m=d?.details)===null||m===void 0)&&m.includes("0 rows")&&(d=null,g=200,v="OK"),d&&this.shouldThrowOnError)throw new r.default(d)}return{error:d,data:y,count:b,status:g,statusText:v}});return this.shouldThrowOnError||(i=i.catch(u=>{var l,c,h;return{error:{message:`${(l=u?.name)!==null&&l!==void 0?l:"FetchError"}: ${u?.message}`,details:`${(c=u?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(h=u?.code)!==null&&h!==void 0?h:""}`},data:null,count:null,status:0,statusText:""}})),i.then(a,n)}returns(){return this}overrideTypes(){return this}};e.default=s}),ft=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ht()),s=class extends r.default{select(a){let n=!1,o=(a??"*").split("").map(i=>/\s/.test(i)&&!n?"":(i==='"'&&(n=!n),i)).join("");return this.url.searchParams.set("select",o),this.headers.append("Prefer","return=representation"),this}order(a,{ascending:n=!0,nullsFirst:o,foreignTable:i,referencedTable:u=i}={}){let l=u?`${u}.order`:"order",c=this.url.searchParams.get(l);return this.url.searchParams.set(l,`${c?`${c},`:""}${a}.${n?"asc":"desc"}${o===void 0?"":o?".nullsfirst":".nullslast"}`),this}limit(a,{foreignTable:n,referencedTable:o=n}={}){let i=typeof o>"u"?"limit":`${o}.limit`;return this.url.searchParams.set(i,`${a}`),this}range(a,n,{foreignTable:o,referencedTable:i=o}={}){let u=typeof i>"u"?"offset":`${i}.offset`,l=typeof i>"u"?"limit":`${i}.limit`;return this.url.searchParams.set(u,`${a}`),this.url.searchParams.set(l,`${n-a+1}`),this}abortSignal(a){return this.signal=a,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:a=!1,verbose:n=!1,settings:o=!1,buffers:i=!1,wal:u=!1,format:l="text"}={}){var c;let h=[a?"analyze":null,n?"verbose":null,o?"settings":null,i?"buffers":null,u?"wal":null].filter(Boolean).join("|"),m=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${l}; for="${m}"; options=${h};`),l==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(a){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${a}`),this}};e.default=s}),ge=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ft()),s=new RegExp("[,()]"),a=class extends r.default{eq(n,o){return this.url.searchParams.append(n,`eq.${o}`),this}neq(n,o){return this.url.searchParams.append(n,`neq.${o}`),this}gt(n,o){return this.url.searchParams.append(n,`gt.${o}`),this}gte(n,o){return this.url.searchParams.append(n,`gte.${o}`),this}lt(n,o){return this.url.searchParams.append(n,`lt.${o}`),this}lte(n,o){return this.url.searchParams.append(n,`lte.${o}`),this}like(n,o){return this.url.searchParams.append(n,`like.${o}`),this}likeAllOf(n,o){return this.url.searchParams.append(n,`like(all).{${o.join(",")}}`),this}likeAnyOf(n,o){return this.url.searchParams.append(n,`like(any).{${o.join(",")}}`),this}ilike(n,o){return this.url.searchParams.append(n,`ilike.${o}`),this}ilikeAllOf(n,o){return this.url.searchParams.append(n,`ilike(all).{${o.join(",")}}`),this}ilikeAnyOf(n,o){return this.url.searchParams.append(n,`ilike(any).{${o.join(",")}}`),this}is(n,o){return this.url.searchParams.append(n,`is.${o}`),this}in(n,o){let i=Array.from(new Set(o)).map(u=>typeof u=="string"&&s.test(u)?`"${u}"`:`${u}`).join(",");return this.url.searchParams.append(n,`in.(${i})`),this}contains(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cs.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cs.{${o.join(",")}}`):this.url.searchParams.append(n,`cs.${JSON.stringify(o)}`),this}containedBy(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cd.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cd.{${o.join(",")}}`):this.url.searchParams.append(n,`cd.${JSON.stringify(o)}`),this}rangeGt(n,o){return this.url.searchParams.append(n,`sr.${o}`),this}rangeGte(n,o){return this.url.searchParams.append(n,`nxl.${o}`),this}rangeLt(n,o){return this.url.searchParams.append(n,`sl.${o}`),this}rangeLte(n,o){return this.url.searchParams.append(n,`nxr.${o}`),this}rangeAdjacent(n,o){return this.url.searchParams.append(n,`adj.${o}`),this}overlaps(n,o){return typeof o=="string"?this.url.searchParams.append(n,`ov.${o}`):this.url.searchParams.append(n,`ov.{${o.join(",")}}`),this}textSearch(n,o,{config:i,type:u}={}){let l="";u==="plain"?l="pl":u==="phrase"?l="ph":u==="websearch"&&(l="w");let c=i===void 0?"":`(${i})`;return this.url.searchParams.append(n,`${l}fts${c}.${o}`),this}match(n){return Object.entries(n).forEach(([o,i])=>{this.url.searchParams.append(o,`eq.${i}`)}),this}not(n,o,i){return this.url.searchParams.append(n,`not.${o}.${i}`),this}or(n,{foreignTable:o,referencedTable:i=o}={}){let u=i?`${i}.or`:"or";return this.url.searchParams.append(u,`(${n})`),this}filter(n,o,i){return this.url.searchParams.append(n,`${o}.${i}`),this}};e.default=a}),pt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ge()),s=class{constructor(a,{headers:n={},schema:o,fetch:i}){this.url=a,this.headers=new Headers(n),this.schema=o,this.fetch=i}select(a,n){let{head:o=!1,count:i}=n??{},u=o?"HEAD":"GET",l=!1,c=(a??"*").split("").map(h=>/\s/.test(h)&&!l?"":(h==='"'&&(l=!l),h)).join("");return this.url.searchParams.set("select",c),i&&this.headers.append("Prefer",`count=${i}`),new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(a,{count:n,defaultToNull:o=!0}={}){var i;let u="POST";if(n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let l=a.reduce((c,h)=>c.concat(Object.keys(h)),[]);if(l.length>0){let c=[...new Set(l)].map(h=>`"${h}"`);this.url.searchParams.set("columns",c.join(","))}}return new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}upsert(a,{onConflict:n,ignoreDuplicates:o=!1,count:i,defaultToNull:u=!0}={}){var l;let c="POST";if(this.headers.append("Prefer",`resolution=${o?"ignore":"merge"}-duplicates`),n!==void 0&&this.url.searchParams.set("on_conflict",n),i&&this.headers.append("Prefer",`count=${i}`),u||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let h=a.reduce((m,d)=>m.concat(Object.keys(d)),[]);if(h.length>0){let m=[...new Set(h)].map(d=>`"${d}"`);this.url.searchParams.set("columns",m.join(","))}}return new r.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(l=this.fetch)!==null&&l!==void 0?l:fetch})}update(a,{count:n}={}){var o;let i="PATCH";return n&&this.headers.append("Prefer",`count=${n}`),new r.default({method:i,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(o=this.fetch)!==null&&o!==void 0?o:fetch})}delete({count:a}={}){var n;let o="DELETE";return a&&this.headers.append("Prefer",`count=${a}`),new r.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}};e.default=s}),Wt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(pt()),s=t.__importDefault(ge()),a=class dt{constructor(o,{headers:i={},schema:u,fetch:l}={}){this.url=o,this.headers=new Headers(i),this.schemaName=u,this.fetch=l}from(o){let i=new URL(`${this.url}/${o}`);return new r.default(i,{headers:new Headers(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(o){return new dt(this.url,{headers:this.headers,schema:o,fetch:this.fetch})}rpc(o,i={},{head:u=!1,get:l=!1,count:c}={}){var h;let m,d=new URL(`${this.url}/rpc/${o}`),y;u||l?(m=u?"HEAD":"GET",Object.entries(i).filter(([g,v])=>v!==void 0).map(([g,v])=>[g,Array.isArray(v)?`{${v.join(",")}}`:`${v}`]).forEach(([g,v])=>{d.searchParams.append(g,v)})):(m="POST",y=i);let b=new Headers(this.headers);return c&&b.set("Prefer",`count=${c}`),new s.default({method:m,url:d,headers:b,schema:this.schemaName,body:y,fetch:(h=this.fetch)!==null&&h!==void 0?h:fetch})}};e.default=a}),Gt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0}),e.PostgrestError=e.PostgrestBuilder=e.PostgrestTransformBuilder=e.PostgrestFilterBuilder=e.PostgrestQueryBuilder=e.PostgrestClient=void 0;var t=(W(),q(k)),r=t.__importDefault(Wt());e.PostgrestClient=r.default;var s=t.__importDefault(pt());e.PostgrestQueryBuilder=s.default;var a=t.__importDefault(ge());e.PostgrestFilterBuilder=a.default;var n=t.__importDefault(ft());e.PostgrestTransformBuilder=n.default;var o=t.__importDefault(ht());e.PostgrestBuilder=o.default;var i=t.__importDefault(ct());e.PostgrestError=i.default,e.default={PostgrestClient:r.default,PostgrestQueryBuilder:s.default,PostgrestFilterBuilder:a.default,PostgrestTransformBuilder:n.default,PostgrestBuilder:o.default,PostgrestError:i.default}});f();f();f();f();f();f();var Kt=Object.defineProperty,zt=Object.defineProperties,Vt=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,Yt=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable,Pe=(e,t,r)=>t in e?Kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,j=(e,t)=>{for(var r in t||(t={}))Yt.call(t,r)&&Pe(e,r,t[r]);if(Te)for(var r of Te(t))Jt.call(t,r)&&Pe(e,r,t[r]);return e},I=(e,t)=>zt(e,Vt(t)),Xt=class extends Error{constructor(e,t,r){super(t||e.toString(),{cause:r}),this.status=e,this.statusText=t,this.error=r}},Qt=async(e,t)=>{var r,s,a,n,o,i;let u=t||{},l={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:u,hooks:l};for(let c of t?.plugins||[]){if(c.init){let h=await((r=c.init)==null?void 0:r.call(c,e.toString(),t));u=h.options||u,e=h.url}l.onRequest.push((s=c.hooks)==null?void 0:s.onRequest),l.onResponse.push((a=c.hooks)==null?void 0:a.onResponse),l.onSuccess.push((n=c.hooks)==null?void 0:n.onSuccess),l.onError.push((o=c.hooks)==null?void 0:o.onError),l.onRetry.push((i=c.hooks)==null?void 0:i.onRetry)}return{url:e,options:u,hooks:l}},Se=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},Zt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function er(e){if(typeof e=="number")return new Se({type:"linear",attempts:e,delay:1e3});switch(e.type){case"linear":return new Se(e);case"exponential":return new Zt(e);default:throw new Error("Invalid retry strategy")}}var tr=async e=>{let t={},r=async s=>typeof s=="function"?await s():s;if(e?.auth){if(e.auth.type==="Bearer"){let s=await r(e.auth.token);if(!s)return t;t.authorization=`Bearer ${s}`}else if(e.auth.type==="Basic"){let s=r(e.auth.username),a=r(e.auth.password);if(!s||!a)return t;t.authorization=`Basic ${btoa(`${s}:${a}`)}`}else if(e.auth.type==="Custom"){let s=r(e.auth.value);if(!s)return t;t.authorization=`${r(e.auth.prefix)} ${s}`}}return t},rr=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function sr(e){let t=e.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!t)return"json";let s=t.split(";").shift()||"";return rr.test(s)?"json":r.has(s)||s.startsWith("text/")?"text":"blob"}function nr(e){try{return JSON.parse(e),!0}catch{return!1}}function mt(e){if(e===void 0)return!1;let t=typeof e;return t==="string"||t==="number"||t==="boolean"||t===null?!0:t!=="object"?!1:Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name==="Object"||typeof e.toJSON=="function"}function Ae(e){try{return JSON.parse(e)}catch{return e}}function Re(e){return typeof e=="function"}function ar(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<"u"&&Re(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&Re(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function or(e){let t=new Headers(e?.headers),r=await tr(e);for(let[s,a]of Object.entries(r||{}))t.set(s,a);if(!t.has("content-type")){let s=ir(e?.body);s&&t.set("content-type",s)}return t}function ir(e){return mt(e)?"application/json":null}function lr(e){if(!e?.body)return null;let t=new Headers(e?.headers);if(mt(e.body)&&!t.has("content-type")){for(let[r,s]of Object.entries(e?.body))s instanceof Date&&(e.body[r]=s.toISOString());return JSON.stringify(e.body)}return e.body}function ur(e,t){var r;if(t?.method)return t.method.toUpperCase();if(e.startsWith("@")){let s=(r=e.split("@")[1])==null?void 0:r.split("/")[0];return gt.includes(s)?s.toUpperCase():t?.body?"POST":"GET"}return t?.body?"POST":"GET"}function cr(e,t){let r;return!e?.signal&&e?.timeout&&(r=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var hr=class yt extends Error{constructor(t,r){super(r||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,yt.prototype)}};async function te(e,t){let r=await e["~standard"].validate(t);if(r.issues)throw new hr(r.issues);return r.value}var gt=["get","post","put","patch","delete"],fr=e=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(t,r){var s,a,n,o;let i=((a=(s=e.plugins)==null?void 0:s.find(u=>{var l;return(l=u.schema)!=null&&l.config?t.startsWith(u.schema.config.baseURL||"")||t.startsWith(u.schema.config.prefix||""):!1}))==null?void 0:a.schema)||e.schema;if(i){let u=t;(n=i.config)!=null&&n.prefix&&u.startsWith(i.config.prefix)&&(u=u.replace(i.config.prefix,""),i.config.baseURL&&(t=t.replace(i.config.prefix,i.config.baseURL))),(o=i.config)!=null&&o.baseURL&&u.startsWith(i.config.baseURL)&&(u=u.replace(i.config.baseURL,""));let l=i.schema[u];if(l){let c=I(j({},r),{method:l.method,output:l.output});return r?.disableValidation||(c=I(j({},c),{body:l.input?await te(l.input,r?.body):r?.body,params:l.params?await te(l.params,r?.params):r?.params,query:l.query?await te(l.query,r?.query):r?.query})),{url:t,options:c}}}return{url:t,options:r}}}),pr=e=>{async function t(r,s){let a=I(j(j({},e),s),{plugins:[...e?.plugins||[],fr(e||{})]});if(e?.catchAllError)try{return await fe(r,a)}catch(n){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:n}}}return await fe(r,a)}return t};function dr(e,t){let{baseURL:r,params:s,query:a}=t||{query:{},params:{},baseURL:""},n=e.startsWith("http")?e.split("/").slice(0,3).join("/"):r||"";if(e.startsWith("@")){let c=e.toString().split("@")[1].split("/")[0];gt.includes(c)&&(e=e.replace(`@${c}/`,"/"))}n.endsWith("/")||(n+="/");let[o,i]=e.replace(n,"").split("?"),u=new URLSearchParams(i);for(let[c,h]of Object.entries(a||{}))h!=null&&u.set(c,String(h));if(s)if(Array.isArray(s)){let c=o.split("/").filter(h=>h.startsWith(":"));for(let[h,m]of c.entries()){let d=s[h];o=o.replace(m,d)}}else for(let[c,h]of Object.entries(s))o=o.replace(`:${c}`,String(h));o=o.split("/").map(encodeURIComponent).join("/"),o.startsWith("/")&&(o=o.slice(1));let l=u.toString();return l=l.length>0?`?${l}`.replace(/\+/g,"%20"):"",n.startsWith("http")?new URL(`${o}${l}`,n):`${n}${o}${l}`}var fe=async(e,t)=>{var r,s,a,n,o,i,u,l;let{hooks:c,url:h,options:m}=await Qt(e,t),d=ar(m),y=new AbortController,b=(r=m.signal)!=null?r:y.signal,g=dr(h,m),v=lr(m),P=await or(m),S=ur(h,m),p=I(j({},m),{url:g,headers:P,body:v,method:S,signal:b});for(let T of c.onRequest)if(T){let E=await T(p);E instanceof Object&&(p=E)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((s=t?.body)==null?void 0:s.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:C}=cr(m,y),_=await d(p.url,p);C();let Ee={response:_,request:p};for(let T of c.onResponse)if(T){let E=await T(I(j({},Ee),{response:(a=t?.hookOptions)!=null&&a.cloneResponse?_.clone():_}));E instanceof Response?_=E:E instanceof Object&&(_=E.response)}if(_.ok){if(p.method==="HEAD")return{data:"",error:null};let T=sr(_),E={data:"",response:_,request:p};if(T==="json"||T==="text"){let B=await _.text(),M=await((n=p.jsonParser)!=null?n:Ae)(B);E.data=M}else E.data=await _[T]();p?.output&&p.output&&!p.disableValidation&&(E.data=await te(p.output,E.data));for(let B of c.onSuccess)B&&await B(I(j({},E),{response:(o=t?.hookOptions)!=null&&o.cloneResponse?_.clone():_}));return t?.throw?E.data:{data:E.data,error:null}}let $t=(i=t?.jsonParser)!=null?i:Ae,J=await _.text(),Oe=nr(J),le=Oe?await $t(J):null,jt={response:_,responseText:J,request:p,error:I(j({},le),{status:_.status,statusText:_.statusText})};for(let T of c.onError)T&&await T(I(j({},jt),{response:(u=t?.hookOptions)!=null&&u.cloneResponse?_.clone():_}));if(t?.retry){let T=er(t.retry),E=(l=t.retryAttempt)!=null?l:0;if(await T.shouldAttemptRetry(E,_)){for(let M of c.onRetry)M&&await M(Ee);let B=T.getDelay(E);return await new Promise(M=>setTimeout(M,B)),await fe(e,I(j({},t),{retryAttempt:E+1}))}}if(t?.throw)throw new Xt(_.status,_.statusText,Oe?le:J);return{data:null,error:I(j({},le),{status:_.status,statusText:_.statusText})}};f();f();var re=Object.create(null),G=e=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?re:globalThis),R=new Proxy(re,{get(e,t){return G()[t]??re[t]},has(e,t){let r=G();return t in r||t in re},set(e,t,r){let s=G(!0);return s[t]=r,!0},deleteProperty(e,t){if(!t)return!1;let r=G(!0);return delete r[t],!0},ownKeys(){let e=G(!0);return Object.keys(e)}}),us=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function w(e,t){return typeof process<"u"&&process.env?process.env[e]??t:typeof Deno<"u"?Deno.env.get(e)??t:typeof Bun<"u"?Bun.env[e]??t:t}var cs=Object.freeze({get BETTER_AUTH_SECRET(){return w("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return w("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return w("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return w("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return w("NODE_ENV","development")},get PACKAGE_VERSION(){return w("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return w("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),K=1,O=4,N=8,A=24,$e={eterm:O,cons25:O,console:O,cygwin:O,dtterm:O,gnome:O,hurd:O,jfbterm:O,konsole:O,kterm:O,mlterm:O,mosh:A,putty:O,st:O,"rxvt-unicode-24bit":A,terminator:A,"xterm-kitty":A},mr=new Map(Object.entries({APPVEYOR:N,BUILDKITE:N,CIRCLECI:A,DRONE:N,GITEA_ACTIONS:A,GITHUB_ACTIONS:A,GITLAB_CI:N,TRAVIS:N})),yr=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function gr(){if(w("FORCE_COLOR")!==void 0)switch(w("FORCE_COLOR")){case"":case"1":case"true":return O;case"2":return N;case"3":return A;default:return K}if(w("NODE_DISABLE_COLORS")!==void 0&&w("NODE_DISABLE_COLORS")!==""||w("NO_COLOR")!==void 0&&w("NO_COLOR")!==""||w("TERM")==="dumb")return K;if(w("TMUX"))return A;if("TF_BUILD"in R&&"AGENT_NAME"in R)return O;if("CI"in R){for(let{0:e,1:t}of mr)if(e in R)return t;return w("CI_NAME")==="codeship"?N:K}if("TEAMCITY_VERSION"in R)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(w("TEAMCITY_VERSION"))!==null?O:K;switch(w("TERM_PROGRAM")){case"iTerm.app":return!w("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(w("TERM_PROGRAM_VERSION"))!==null?N:A;case"HyperTerm":case"MacTerm":return A;case"Apple_Terminal":return N}if(w("COLORTERM")==="truecolor"||w("COLORTERM")==="24bit")return A;if(w("TERM")){if(/truecolor/.exec(w("TERM"))!==null)return A;if(/^xterm-256/.exec(w("TERM"))!==null)return N;let e=w("TERM").toLowerCase();if($e[e])return $e[e];if(yr.some(t=>t.exec(e)!==null))return O}return w("COLORTERM")?O:K}var x={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"}},pe=["info","success","warn","error","debug"];function vr(e,t){return pe.indexOf(t)<=pe.indexOf(e)}var wr={info:x.fg.blue,success:x.fg.green,warn:x.fg.yellow,error:x.fg.red,debug:x.fg.magenta},br=(e,t,r)=>{let s=new Date().toISOString();return r?`${x.dim}${s}${x.reset} ${wr[e]}${e.toUpperCase()}${x.reset} ${x.bright}[Better Auth]:${x.reset} ${t}`:`${s} ${e.toUpperCase()} [Better Auth]: ${t}`},_r=e=>{let t=e?.disabled!==!0,r=e?.level??"error",s=e?.disableColors!==void 0?!e.disableColors:gr()!==1,a=(n,o,i=[])=>{if(!t||!vr(r,n))return;let u=br(n,o,s);if(!e||typeof e.log!="function"){n==="error"?console.error(u,...i):n==="warn"?console.warn(u,...i):console.log(u,...i);return}e.log(n==="success"?"info":n,o,...i)};return{...Object.fromEntries(pe.map(n=>[n,(...[o,...i])=>a(n,o,i)])),get level(){return r}}},hs=_r();f();f();var ve=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function Er(e){try{return(new URL(e).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new ve(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function z(e,t="/api/auth"){if(Er(e))return e;let r=e.replace(/\/+$/,"");return!t||t==="/"?r:(t=t.startsWith("/")?t:`/${t}`,`${r}${t}`)}function Or(e,t,r,s){if(e)return z(e,t);if(s!==!1){let o=R.BETTER_AUTH_URL||R.NEXT_PUBLIC_BETTER_AUTH_URL||R.PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_AUTH_URL||(R.BASE_URL!=="/"?R.BASE_URL:void 0);if(o)return z(o,t)}let a=r?.headers.get("x-forwarded-host"),n=r?.headers.get("x-forwarded-proto");if(a&&n)return z(`${n}://${a}`,t);if(r){let o=Tr(r.url);if(!o)throw new ve("Could not get origin from request. Please provide a valid base URL.");return z(o,t)}if(typeof window<"u"&&window.location)return z(window.location.origin,t)}function Tr(e){try{return new URL(e).origin}catch{return null}}f();f();f();var de=Symbol("clean"),$=[],U=0,X=4,Pr=0,vt=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(s){return r.lc=t.push(s),()=>{for(let n=U+X;n<$.length;)$[n]===s?$.splice(n,X):n+=X;let a=t.indexOf(s);~a&&(t.splice(a,1),--r.lc||r.off())}},notify(s,a){Pr++;let n=!$.length;for(let o of t)$.push(o,r.value,s,a);if(n){for(U=0;U<$.length;U+=X)$[U]($[U+1],$[U+2],$[U+3]);$.length=0}},off(){},set(s){let a=r.value;a!==s&&(r.value=s,r.notify(a))},subscribe(s){let a=r.listen(s);return s(r.value),a},value:e};return process.env.NODE_ENV!=="production"&&(r[de]=()=>{t=[],r.lc=0,r.off()}),r};f();var Sr=5,F=6,Q=10,Ar=(e,t,r,s)=>(e.events=e.events||{},e.events[r+Q]||(e.events[r+Q]=s(a=>{e.events[r].reduceRight((n,o)=>(o(n),n),{shared:{},...a})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let a=e.events[r],n=a.indexOf(t);a.splice(n,1),a.length||(delete e.events[r],e.events[r+Q](),delete e.events[r+Q])}),Rr=1e3,$r=(e,t)=>Ar(e,r=>{let s=t(r);s&&e.events[F].push(s)},Sr,r=>{let s=e.listen;e.listen=(...n)=>(!e.lc&&!e.active&&(e.active=!0,r()),s(...n));let a=e.off;if(e.events[F]=[],e.off=()=>{a(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let n of e.events[F])n();e.events[F]=[]}},Rr)},process.env.NODE_ENV!=="production"){let n=e[de];e[de]=()=>{for(let o of e.events[F])o();e.events[F]=[],e.active=!1,n()}}return()=>{e.listen=s,e.off=a}});f();var jr=typeof window>"u",Ir=(e,t,r,s)=>{let a=vt({data:null,error:null,isPending:!0,isRefetching:!1,refetch:i=>n(i)}),n=i=>{let u=typeof s=="function"?s({data:a.get().data,error:a.get().error,isPending:a.get().isPending}):s;r(t,{...u,query:{...u?.query,...i?.query},async onSuccess(l){a.set({data:l.data,error:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onSuccess?.(l)},async onError(l){let{request:c}=l,h=typeof c.retry=="number"?c.retry:c.retry?.attempts,m=c.retryAttempt||0;h&&m<h||(a.set({error:l.error,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onError?.(l))},async onRequest(l){let c=a.get();a.set({isPending:c.data===null,data:c.data,error:null,isRefetching:!0,refetch:a.value.refetch}),await u?.onRequest?.(l)}}).catch(l=>{a.set({error:l,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch})})};e=Array.isArray(e)?e:[e];let o=!1;for(let i of e)i.subscribe(()=>{jr||(o?n():$r(a,()=>{let u=setTimeout(()=>{o||(n(),o=!0)},0);return()=>{a.off(),i.off(),clearTimeout(u)}}))});return a};f();var Nr={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*$/,je={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Ur=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Cr(e){return e instanceof Date&&!isNaN(e.getTime())}function Lr(e){let t=Ur.exec(e);if(!t)return null;let[,r,s,a,n,o,i,u,l,c,h]=t,m=new Date(Date.UTC(parseInt(r,10),parseInt(s,10)-1,parseInt(a,10),parseInt(n,10),parseInt(o,10),parseInt(i,10),u?parseInt(u.padEnd(3,"0"),10):0));if(l){let d=(parseInt(c,10)*60+parseInt(h,10))*(l==="+"?-1:1);m.setUTCMinutes(m.getUTCMinutes()+d)}return Cr(m)?m:null}function Dr(e,t={}){let{strict:r=!1,warnings:s=!1,reviver:a,parseDates:n=!0}=t;if(typeof e!="string")return e;let o=e.trim();if(o.length>0&&o[0]==='"'&&o.endsWith('"')&&!o.slice(1,-1).includes('"'))return o.slice(1,-1);let i=o.toLowerCase();if(i.length<=9&&i in je)return je[i];if(!xr.test(o)){if(r)throw new SyntaxError("[better-json] Invalid JSON");return e}if(Object.entries(Nr).some(([u,l])=>{let c=l.test(o);return c&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),c})&&r)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(o,(u,l)=>{if(u==="__proto__"||u==="constructor"&&l&&typeof l=="object"&&"prototype"in l){s&&console.warn(`[better-json] Dropping "${u}" key to prevent prototype pollution`);return}if(n&&typeof l=="string"){let c=Lr(l);if(c)return c}return a?a(u,l):l})}catch(u){if(r)throw u;return e}}function kr(e,t={strict:!0}){return Dr(e,t)}var Br={id:"redirect",name:"Redirect",hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}};function Mr(e){let t=vt(!1);return{session:Ir(t,"/get-session",e,{method:"GET"}),$sessionSignal:t}}var Fr=(e,t)=>{let r="credentials"in Request.prototype,s=Or(e?.baseURL,e?.basePath,void 0,t)??"/api/auth",a=e?.plugins?.flatMap(p=>p.fetchPlugins).filter(p=>p!==void 0)||[],n={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:i,onRequest:u,onResponse:l,...c}=e?.fetchOptions||{},h=pr({baseURL:s,...r?{credentials:"include"}:{},method:"GET",jsonParser(p){return p?kr(p,{strict:!1}):null},customFetchImpl:fetch,...c,plugins:[n,...c.plugins||[],...e?.disableDefaultFetchPlugins?[]:[Br],...a]}),{$sessionSignal:m,session:d}=Mr(h),y=e?.plugins||[],b={},g={$sessionSignal:m,session:d},v={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},P=[{signal:"$sessionSignal",matcher(p){return p==="/sign-out"||p==="/update-user"||p.startsWith("/sign-in")||p.startsWith("/sign-up")||p==="/delete-user"||p==="/verify-email"}}];for(let p of y)p.getAtoms&&Object.assign(g,p.getAtoms?.(h)),p.pathMethods&&Object.assign(v,p.pathMethods),p.atomListeners&&P.push(...p.atomListeners);let S={notify:p=>{g[p].set(!g[p].get())},listen:(p,C)=>{g[p].subscribe(C)},atoms:g};for(let p of y)p.getActions&&Object.assign(b,p.getActions?.(h,S,e));return{get baseURL(){return s},pluginsActions:b,pluginsAtoms:g,pluginPathMethods:v,atomListeners:P,$fetch:h,$store:S}};function Hr(e){return typeof e=="object"&&e!==null&&"get"in e&&typeof e.get=="function"&&"lc"in e&&typeof e.lc=="number"}function qr(e,t,r){let s=t[e],{fetchOptions:a,query:n,...o}=r||{};return s||(a?.method?a.method:o&&Object.keys(o).length>0?"POST":"GET")}function Wr(e,t,r,s,a){function n(o=[]){return new Proxy(function(){},{get(i,u){if(typeof u!="string"||u==="then"||u==="catch"||u==="finally")return;let l=[...o,u],c=e;for(let h of l)if(c&&typeof c=="object"&&h in c)c=c[h];else{c=void 0;break}return typeof c=="function"||Hr(c)?c:n(l)},apply:async(i,u,l)=>{let c="/"+o.map(P=>P.replace(/[A-Z]/g,S=>`-${S.toLowerCase()}`)).join("/"),h=l[0]||{},m=l[1]||{},{query:d,fetchOptions:y,...b}=h,g={...m,...y},v=qr(c,r,h);return await t(c,{...g,body:v==="GET"?void 0:{...b,...g?.body||{}},query:d||g?.query,method:v,async onSuccess(P){if(await g?.onSuccess?.(P),!a)return;let S=a.filter(p=>p.matcher(c));if(S.length)for(let p of S){let C=s[p.signal];if(!C)return;let _=C.get();setTimeout(()=>{C.set(!_)},10)}}})}})}return n()}f();function Gr(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Kr(e){let{pluginPathMethods:t,pluginsActions:r,pluginsAtoms:s,$fetch:a,atomListeners:n,$store:o}=Fr(e),i={};for(let[l,c]of Object.entries(s))i[`use${Gr(l)}`]=c;let u={...r,...i,$fetch:a,$store:o};return Wr(u,a,t,s,n)}f();f();f();function zr(e){return{authorize(t,r="AND"){let s=!1;for(let[a,n]of Object.entries(t)){let o=e[a];if(!o)return{success:!1,error:`You are not allowed to access resource: ${a}`};if(Array.isArray(n))s=n.every(i=>o.includes(i));else if(typeof n=="object"){let i=n;i.connector==="OR"?s=i.actions.some(u=>o.includes(u)):s=i.actions.every(u=>o.includes(u))}else throw new ve("Invalid access control request");if(s&&r==="OR")return{success:s};if(!s&&r==="AND")return{success:!1,error:`unauthorized to access resource "${a}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:e}}function wt(e){return{newRole(t){return zr(t)},statements:e}}var Vr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},we=wt(Vr),fs=we.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),ps=we.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),ds=we.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});f();f();f();f();f();f();f();f();f();f();f();var Yr=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}}},ms=new Yr;f();f();f();f();f();f();f();f();var Jr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},bt=wt(Jr),ys=bt.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),gs=bt.newRole({user:[],session:[]});f();f();var Xr=()=>({id:"username",$InferServerPlugin:{}}),Qr=()=>({id:"phoneNumber",$InferServerPlugin:{},atomListeners:[{matcher(e){return e==="/phone-number/update"||e==="/phone-number/verify"},signal:"$sessionSignal"}]}),Zr=()=>({id:"better-auth-client",$InferServerPlugin:{}}),es="/auth",ce="nvwa_login_token",se="nvwa_current_jwt",he="nvwa_user_profile",_t=class{constructor(e,t,r){this.storage=r;let s=Kr({baseURL:e,basePath:es,plugins:[Xr(),Qr(),Zr()],fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:async()=>{let a=await this.storage.get(se);if(console.log("jwt",a),a)return a;let n=await this.storage.get(ce);return console.log("loginToken",n),n}}}});this.authClient=s}async currentUser(){return await this.storage.get(he)}async getCurrentJwt(){return await this.storage.get(se)}async signUp(e){let t=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:e.password});this.handleLogin(t)}async sendPhoneNumberCode(e){await this.authClient.phoneNumber.sendOtp({phoneNumber:e})}async signInWithPhoneNumberCode(e,t){let r=await this.authClient.phoneNumber.verify({phoneNumber:e,code:t});this.handleLogin(r)}async signInWithPhoneNumber(e,t,r=!1){let s=await this.authClient.signIn.phoneNumber({phoneNumber:e,password:t,rememberMe:r});this.handleLogin(s)}async signInWithUsername(e,t){let r=await this.authClient.signIn.username({username:e,password:t});this.handleLogin(r)}async handleLogin(e){if(e.error)throw new Error(e.error.message);await this.storage.set(ce,e.data?.token),await this.storage.set(he,e.data?.user);let{data:t,error:r}=await this.authClient.token();if(r)throw new Error(r.message);await this.storage.set(se,t.token)}async signOut(){await this.storage.remove(ce),await this.storage.remove(he)}async updateUserPassword(e,t,r=!1){let s=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:r});this.handleLogin(s)}};f();var Et=class{constructor(e){this.http=e}async invoke(e,t){return await(await this.http.fetch("/functions/"+e,{method:t.method||"POST",body:t.body,headers:t.headers})).json()}};f();f();f();var L=class Ot{constructor(t){if(this.headerMap=new Map,t){if(t instanceof Ot)t.forEach((r,s)=>this.set(s,r));else if(Array.isArray(t))for(let[r,s]of t)this.set(r,String(s));else if(typeof t=="object")for(let r of Object.keys(t))this.set(r,String(t[r]))}}append(t,r){let s=t.toLowerCase(),a=this.headerMap.get(s);this.headerMap.set(s,a?`${a}, ${r}`:r)}set(t,r){this.headerMap.set(t.toLowerCase(),String(r))}get(t){return this.headerMap.get(t.toLowerCase())??null}has(t){return this.headerMap.has(t.toLowerCase())}delete(t){this.headerMap.delete(t.toLowerCase())}forEach(t){for(let[r,s]of this.headerMap.entries())t(s,r,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}};f();f();var Tt=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=ts(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 ts(e){return e?new L(e):new L}f();f();var Pt=class{constructor(e,t,r){console.log("NvwaHttpClient constructor",e,t,r),this.storage=e,this.customFetch=t,this.handleUnauthorized=r}async fetch(e,t){return await this.customFetch(e,t)}async fetchWithAuth(e,t){let r=await this.storage.get(se),s=new L(t?.headers);r&&s.set("Authorization",`Bearer ${r}`);let a=await this.customFetch(e,{...t,headers:s});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};f();var rs="/storage",ss=rs+"/generateUploadUrl",St=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.fetch(this.baseUrl+ss,{method:"POST",body:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:r}=await t.json();if(!r)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let s=await this.http.fetch(r,{method:"PUT",body:e,headers:new L({"Content-Type":e.type||e.fileType||"application/octet-stream"})}),{url:a}=await s.json();return{url:a.split("?")[0]}}};f();f();f();var Ie=qt(Gt(),1),{PostgrestClient:ns,PostgrestQueryBuilder:vs,PostgrestFilterBuilder:ws,PostgrestTransformBuilder:bs,PostgrestBuilder:_s,PostgrestError:Es}=Ie.default||Ie,as="/entities",At=(e,t)=>new ns(e+as,{fetch:t.fetchWithAuth.bind(t)});f();var Rt=class{constructor(e,t){this.baseUrl=e,this.http=t}async execute(e,t){let r=`${this.baseUrl}/skill/${e}/execute`;return await(await this.http.fetchWithAuth(r,{method:"POST",body:t})).json()}};var oe=class{constructor(){this.prefix="nvwa_"}getKey(t){return`${this.prefix}${t}`}async get(t){try{let r=this.getKey(t),s=localStorage.getItem(r);if(!s)return null;let a=JSON.parse(s);return a.expires&&Date.now()>a.expires?(await this.remove(t),null):a.value}catch(r){return console.error("WebStorageService get error:",r),null}}async set(t,r,s){try{let a=this.getKey(t),n={value:r,expires:s?Date.now()+s*1e3:null,timestamp:Date.now()};localStorage.setItem(a,JSON.stringify(n))}catch(a){throw console.error("WebStorageService set error:",a),a}}async remove(t){try{let r=this.getKey(t);localStorage.removeItem(r)}catch(r){throw console.error("WebStorageService remove error:",r),r}}async clear(){try{Object.keys(localStorage).filter(s=>s.startsWith(this.prefix)).forEach(s=>{localStorage.removeItem(s)})}catch(t){throw console.error("WebStorageService clear error:",t),t}}};var os=(e,t)=>{let r;if(typeof e=="string")r=e;else if(e&&typeof e.toString=="function")r=e.toString();else if(e?.url)r=e.url;else throw new Error("Invalid input for webFetch");let s;if(t?.headers){let n=t.headers;if(n instanceof L){let o={};n.forEach((i,u)=>{o[u]=i}),s=o}else if(Array.isArray(n)){let o=[];for(let i of n)Array.isArray(i)&&i.length>=2&&o.push([String(i[0]),String(i[1])]);s=o}else typeof n=="object"&&(s=n)}let a={method:t?.method||"GET",headers:s,body:t?.body};return t?.signal&&(a.signal=t.signal),globalThis.fetch(r,a).then(async n=>{let o=n.headers.get("content-type")||"",i;if(o.includes("application/json"))i=await n.json();else{let l=await n.text();try{i=JSON.parse(l)}catch{i=l}}let u=new L;return n.headers.forEach((l,c)=>{u.set(c,l)}),new Tt(i,{status:n.status,statusText:n.statusText,headers:u})})},be=os;var _e=new oe,ie=class{constructor(t,r){this.auth=new _t(t,be,_e),this.httpClient=new Pt(_e,be,r),this.fileStorage=new St(t,this.httpClient),this.entities=At(t,this.httpClient),this.functions=new Et(this.httpClient),this.skill=new Rt(t,this.httpClient)}};0&&(module.exports={localStorage});
1
+ "use strict";var ue=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var Nt=Object.getOwnPropertyNames;var xt=Object.prototype.hasOwnProperty;var Ut=(e,t)=>{for(var r in t)ue(e,r,{get:t[r],enumerable:!0})},Ct=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Nt(t))!xt.call(e,a)&&a!==r&&ue(e,a,{get:()=>t[a],enumerable:!(s=It(t,a))||s.enumerable});return e};var Lt=e=>Ct(ue({},"__esModule",{value:!0}),e);var is={};Ut(is,{default:()=>ie,localStorage:()=>_e});module.exports=Lt(is);var Dt=Object.create,ae=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,Bt=Object.getOwnPropertyNames,Mt=Object.getPrototypeOf,Ft=Object.prototype.hasOwnProperty,Ne=(e,t)=>()=>(e&&(t=e(e=0)),t),D=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ht=(e,t)=>{for(var r in t)ae(e,r,{get:t[r],enumerable:!0})},xe=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Bt(t))!Ft.call(e,a)&&a!==r&&ae(e,a,{get:()=>t[a],enumerable:!(s=kt(t,a))||s.enumerable});return e},qt=(e,t,r)=>(r=e!=null?Dt(Mt(e)):{},xe(t||!e||!e.__esModule?ae(r,"default",{value:e,enumerable:!0}):r,e)),q=e=>xe(ae({},"__esModule",{value:!0}),e),f=Ne(()=>{"use strict"}),k={};Ht(k,{__addDisposableResource:()=>nt,__assign:()=>V,__asyncDelegator:()=>Je,__asyncGenerator:()=>Ye,__asyncValues:()=>Xe,__await:()=>H,__awaiter:()=>qe,__classPrivateFieldGet:()=>tt,__classPrivateFieldIn:()=>st,__classPrivateFieldSet:()=>rt,__createBinding:()=>Y,__decorate:()=>Le,__disposeResources:()=>at,__esDecorate:()=>ke,__exportStar:()=>Ge,__extends:()=>Ue,__generator:()=>We,__importDefault:()=>et,__importStar:()=>Ze,__makeTemplateObject:()=>Qe,__metadata:()=>He,__param:()=>De,__propKey:()=>Me,__read:()=>ye,__rest:()=>Ce,__rewriteRelativeImportExtension:()=>ot,__runInitializers:()=>Be,__setFunctionName:()=>Fe,__spread:()=>Ke,__spreadArray:()=>Ve,__spreadArrays:()=>ze,__values:()=>ne,default:()=>ut});function Ue(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Z(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function Ce(e,t){var r={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,s=Object.getOwnPropertySymbols(e);a<s.length;a++)t.indexOf(s[a])<0&&Object.prototype.propertyIsEnumerable.call(e,s[a])&&(r[s[a]]=e[s[a]]);return r}function Le(e,t,r,s){var a=arguments.length,n=a<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,r):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(n=(a<3?o(n):a>3?o(t,r,n):o(t,r))||n);return a>3&&n&&Object.defineProperty(t,r,n),n}function De(e,t){return function(r,s){t(r,s,e)}}function ke(e,t,r,s,a,n){function o(w){if(w!==void 0&&typeof w!="function")throw new TypeError("Function expected");return w}for(var i=s.kind,u=i==="getter"?"get":i==="setter"?"set":"value",l=!t&&e?s.static?e:e.prototype:null,c=t||(l?Object.getOwnPropertyDescriptor(l,s.name):{}),h,m=!1,d=r.length-1;d>=0;d--){var y={};for(var b in s)y[b]=b==="access"?{}:s[b];for(var b in s.access)y.access[b]=s.access[b];y.addInitializer=function(w){if(m)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(w||null))};var g=(0,r[d])(i==="accessor"?{get:c.get,set:c.set}:c[u],y);if(i==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(h=o(g.get))&&(c.get=h),(h=o(g.set))&&(c.set=h),(h=o(g.init))&&a.unshift(h)}else(h=o(g))&&(i==="field"?a.unshift(h):c[u]=h)}l&&Object.defineProperty(l,s.name,c),m=!0}function Be(e,t,r){for(var s=arguments.length>2,a=0;a<t.length;a++)r=s?t[a].call(e,r):t[a].call(e);return s?r:void 0}function Me(e){return typeof e=="symbol"?e:"".concat(e)}function Fe(e,t,r){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:r?"".concat(r," ",t):t})}function He(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function qe(e,t,r,s){function a(n){return n instanceof r?n:new r(function(o){o(n)})}return new(r||(r=Promise))(function(n,o){function i(c){try{l(s.next(c))}catch(h){o(h)}}function u(c){try{l(s.throw(c))}catch(h){o(h)}}function l(c){c.done?n(c.value):a(c.value).then(i,u)}l((s=s.apply(e,t||[])).next())})}function We(e,t){var r={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},s,a,n,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=i(0),o.throw=i(1),o.return=i(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function i(l){return function(c){return u([l,c])}}function u(l){if(s)throw new TypeError("Generator is already executing.");for(;o&&(o=0,l[0]&&(r=0)),r;)try{if(s=1,a&&(n=l[0]&2?a.return:l[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,l[1])).done)return n;switch(a=0,n&&(l=[l[0]&2,n.value]),l[0]){case 0:case 1:n=l;break;case 4:return r.label++,{value:l[1],done:!1};case 5:r.label++,a=l[1],l=[0];continue;case 7:l=r.ops.pop(),r.trys.pop();continue;default:if(n=r.trys,!(n=n.length>0&&n[n.length-1])&&(l[0]===6||l[0]===2)){r=0;continue}if(l[0]===3&&(!n||l[1]>n[0]&&l[1]<n[3])){r.label=l[1];break}if(l[0]===6&&r.label<n[1]){r.label=n[1],n=l;break}if(n&&r.label<n[2]){r.label=n[2],r.ops.push(l);break}n[2]&&r.ops.pop(),r.trys.pop();continue}l=t.call(e,r)}catch(c){l=[6,c],a=0}finally{s=n=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}function Ge(e,t){for(var r in e)r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r)&&Y(t,e,r)}function ne(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],s=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&s>=e.length&&(e=void 0),{value:e&&e[s++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function ye(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var s=r.call(e),a,n=[],o;try{for(;(t===void 0||t-- >0)&&!(a=s.next()).done;)n.push(a.value)}catch(i){o={error:i}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return n}function Ke(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(ye(arguments[t]));return e}function ze(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;for(var s=Array(e),a=0,t=0;t<r;t++)for(var n=arguments[t],o=0,i=n.length;o<i;o++,a++)s[a]=n[o];return s}function Ve(e,t,r){if(r||arguments.length===2)for(var s=0,a=t.length,n;s<a;s++)(n||!(s in t))&&(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}function H(e){return this instanceof H?(this.v=e,this):new H(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=r.apply(e,t||[]),a,n=[];return a=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),i("next"),i("throw"),i("return",o),a[Symbol.asyncIterator]=function(){return this},a;function o(d){return function(y){return Promise.resolve(y).then(d,h)}}function i(d,y){s[d]&&(a[d]=function(b){return new Promise(function(g,w){n.push([d,b,g,w])>1||u(d,b)})},y&&(a[d]=y(a[d])))}function u(d,y){try{l(s[d](y))}catch(b){m(n[0][3],b)}}function l(d){d.value instanceof H?Promise.resolve(d.value.v).then(c,h):m(n[0][2],d)}function c(d){u("next",d)}function h(d){u("throw",d)}function m(d,y){d(y),n.shift(),n.length&&u(n[0][0],n[0][1])}}function Je(e){var t,r;return t={},s("next"),s("throw",function(a){throw a}),s("return"),t[Symbol.iterator]=function(){return this},t;function s(a,n){t[a]=e[a]?function(o){return(r=!r)?{value:H(e[a](o)),done:!1}:n?n(o):o}:n}}function Xe(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof ne=="function"?ne(e):e[Symbol.iterator](),r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r);function s(n){r[n]=e[n]&&function(o){return new Promise(function(i,u){o=e[n](o),a(i,u,o.done,o.value)})}}function a(n,o,i,u){Promise.resolve(u).then(function(l){n({value:l,done:i})},o)}}function Qe(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function Ze(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=ee(e),s=0;s<r.length;s++)r[s]!=="default"&&Y(t,e,r[s]);return it(t,e),t}function et(e){return e&&e.__esModule?e:{default:e}}function tt(e,t,r,s){if(r==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?s:r==="a"?s.call(e):s?s.value:t.get(e)}function rt(e,t,r,s,a){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!a)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?a.call(e,r):a?a.value=r:t.set(e,r),r}function st(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function nt(e,t,r){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var s,a;if(r){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");s=t[Symbol.asyncDispose]}if(s===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");s=t[Symbol.dispose],r&&(a=s)}if(typeof s!="function")throw new TypeError("Object not disposable.");a&&(s=function(){try{a.call(this)}catch(n){return Promise.reject(n)}}),e.stack.push({value:t,dispose:s,async:r})}else r&&e.stack.push({async:!0});return t}function at(e){function t(n){e.error=e.hasError?new lt(n,e.error,"An error was suppressed during disposal."):n,e.hasError=!0}var r,s=0;function a(){for(;r=e.stack.pop();)try{if(!r.async&&s===1)return s=0,e.stack.push(r),Promise.resolve().then(a);if(r.dispose){var n=r.dispose.call(r.value);if(r.async)return s|=2,Promise.resolve(n).then(a,function(o){return t(o),a()})}else s|=1}catch(o){t(o)}if(s===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return a()}function ot(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(r,s,a,n,o){return s?t?".jsx":".js":a&&(!n||!o)?r:a+n+"."+o.toLowerCase()+"js"}):e}var Z,V,Y,it,ee,lt,ut,W=Ne(()=>{"use strict";f(),Z=function(e,t){return Z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,s){r.__proto__=s}||function(r,s){for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(r[a]=s[a])},Z(e,t)},V=function(){return V=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},V.apply(this,arguments)},Y=Object.create?(function(e,t,r,s){s===void 0&&(s=r);var a=Object.getOwnPropertyDescriptor(t,r);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,a)}):(function(e,t,r,s){s===void 0&&(s=r),e[s]=t[r]}),it=Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t},ee=function(e){return ee=Object.getOwnPropertyNames||function(t){var r=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(r[r.length]=s);return r},ee(e)},lt=typeof SuppressedError=="function"?SuppressedError:function(e,t,r){var s=new Error(r);return s.name="SuppressedError",s.error=e,s.suppressed=t,s},ut={__extends:Ue,__assign:V,__rest:Ce,__decorate:Le,__param:De,__esDecorate:ke,__runInitializers:Be,__propKey:Me,__setFunctionName:Fe,__metadata:He,__awaiter:qe,__generator:We,__createBinding:Y,__exportStar:Ge,__values:ne,__read:ye,__spread:Ke,__spreadArrays:ze,__spreadArray:Ve,__await:H,__asyncGenerator:Ye,__asyncDelegator:Je,__asyncValues:Xe,__makeTemplateObject:Qe,__importStar:Ze,__importDefault:et,__classPrivateFieldGet:tt,__classPrivateFieldSet:rt,__classPrivateFieldIn:st,__addDisposableResource:nt,__disposeResources:at,__rewriteRelativeImportExtension:ot}}),ct=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}};e.default=t}),ht=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ct()),s=class{constructor(a){var n,o;this.shouldThrowOnError=!1,this.method=a.method,this.url=a.url,this.headers=new Headers(a.headers),this.schema=a.schema,this.body=a.body,this.shouldThrowOnError=(n=a.shouldThrowOnError)!==null&&n!==void 0?n:!1,this.signal=a.signal,this.isMaybeSingle=(o=a.isMaybeSingle)!==null&&o!==void 0?o:!1,a.fetch?this.fetch=a.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(a,n){return this.headers=new Headers(this.headers),this.headers.set(a,n),this}then(a,n){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 o=this.fetch,i=o(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async u=>{var l,c,h,m;let d=null,y=null,b=null,g=u.status,w=u.statusText;if(u.ok){if(this.method!=="HEAD"){let p=await u.text();p===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&!((l=this.headers.get("Accept"))===null||l===void 0)&&l.includes("application/vnd.pgrst.plan+text")?y=p:y=JSON.parse(p))}let P=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),S=(h=u.headers.get("content-range"))===null||h===void 0?void 0:h.split("/");P&&S&&S.length>1&&(b=parseInt(S[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(y)&&(y.length>1?(d={code:"PGRST116",details:`Results contain ${y.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},y=null,b=null,g=406,w="Not Acceptable"):y.length===1?y=y[0]:y=null)}else{let P=await u.text();try{d=JSON.parse(P),Array.isArray(d)&&u.status===404&&(y=[],d=null,g=200,w="OK")}catch{u.status===404&&P===""?(g=204,w="No Content"):d={message:P}}if(d&&this.isMaybeSingle&&!((m=d?.details)===null||m===void 0)&&m.includes("0 rows")&&(d=null,g=200,w="OK"),d&&this.shouldThrowOnError)throw new r.default(d)}return{error:d,data:y,count:b,status:g,statusText:w}});return this.shouldThrowOnError||(i=i.catch(u=>{var l,c,h;return{error:{message:`${(l=u?.name)!==null&&l!==void 0?l:"FetchError"}: ${u?.message}`,details:`${(c=u?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(h=u?.code)!==null&&h!==void 0?h:""}`},data:null,count:null,status:0,statusText:""}})),i.then(a,n)}returns(){return this}overrideTypes(){return this}};e.default=s}),ft=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ht()),s=class extends r.default{select(a){let n=!1,o=(a??"*").split("").map(i=>/\s/.test(i)&&!n?"":(i==='"'&&(n=!n),i)).join("");return this.url.searchParams.set("select",o),this.headers.append("Prefer","return=representation"),this}order(a,{ascending:n=!0,nullsFirst:o,foreignTable:i,referencedTable:u=i}={}){let l=u?`${u}.order`:"order",c=this.url.searchParams.get(l);return this.url.searchParams.set(l,`${c?`${c},`:""}${a}.${n?"asc":"desc"}${o===void 0?"":o?".nullsfirst":".nullslast"}`),this}limit(a,{foreignTable:n,referencedTable:o=n}={}){let i=typeof o>"u"?"limit":`${o}.limit`;return this.url.searchParams.set(i,`${a}`),this}range(a,n,{foreignTable:o,referencedTable:i=o}={}){let u=typeof i>"u"?"offset":`${i}.offset`,l=typeof i>"u"?"limit":`${i}.limit`;return this.url.searchParams.set(u,`${a}`),this.url.searchParams.set(l,`${n-a+1}`),this}abortSignal(a){return this.signal=a,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:a=!1,verbose:n=!1,settings:o=!1,buffers:i=!1,wal:u=!1,format:l="text"}={}){var c;let h=[a?"analyze":null,n?"verbose":null,o?"settings":null,i?"buffers":null,u?"wal":null].filter(Boolean).join("|"),m=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${l}; for="${m}"; options=${h};`),l==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(a){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${a}`),this}};e.default=s}),ge=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ft()),s=new RegExp("[,()]"),a=class extends r.default{eq(n,o){return this.url.searchParams.append(n,`eq.${o}`),this}neq(n,o){return this.url.searchParams.append(n,`neq.${o}`),this}gt(n,o){return this.url.searchParams.append(n,`gt.${o}`),this}gte(n,o){return this.url.searchParams.append(n,`gte.${o}`),this}lt(n,o){return this.url.searchParams.append(n,`lt.${o}`),this}lte(n,o){return this.url.searchParams.append(n,`lte.${o}`),this}like(n,o){return this.url.searchParams.append(n,`like.${o}`),this}likeAllOf(n,o){return this.url.searchParams.append(n,`like(all).{${o.join(",")}}`),this}likeAnyOf(n,o){return this.url.searchParams.append(n,`like(any).{${o.join(",")}}`),this}ilike(n,o){return this.url.searchParams.append(n,`ilike.${o}`),this}ilikeAllOf(n,o){return this.url.searchParams.append(n,`ilike(all).{${o.join(",")}}`),this}ilikeAnyOf(n,o){return this.url.searchParams.append(n,`ilike(any).{${o.join(",")}}`),this}is(n,o){return this.url.searchParams.append(n,`is.${o}`),this}in(n,o){let i=Array.from(new Set(o)).map(u=>typeof u=="string"&&s.test(u)?`"${u}"`:`${u}`).join(",");return this.url.searchParams.append(n,`in.(${i})`),this}contains(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cs.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cs.{${o.join(",")}}`):this.url.searchParams.append(n,`cs.${JSON.stringify(o)}`),this}containedBy(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cd.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cd.{${o.join(",")}}`):this.url.searchParams.append(n,`cd.${JSON.stringify(o)}`),this}rangeGt(n,o){return this.url.searchParams.append(n,`sr.${o}`),this}rangeGte(n,o){return this.url.searchParams.append(n,`nxl.${o}`),this}rangeLt(n,o){return this.url.searchParams.append(n,`sl.${o}`),this}rangeLte(n,o){return this.url.searchParams.append(n,`nxr.${o}`),this}rangeAdjacent(n,o){return this.url.searchParams.append(n,`adj.${o}`),this}overlaps(n,o){return typeof o=="string"?this.url.searchParams.append(n,`ov.${o}`):this.url.searchParams.append(n,`ov.{${o.join(",")}}`),this}textSearch(n,o,{config:i,type:u}={}){let l="";u==="plain"?l="pl":u==="phrase"?l="ph":u==="websearch"&&(l="w");let c=i===void 0?"":`(${i})`;return this.url.searchParams.append(n,`${l}fts${c}.${o}`),this}match(n){return Object.entries(n).forEach(([o,i])=>{this.url.searchParams.append(o,`eq.${i}`)}),this}not(n,o,i){return this.url.searchParams.append(n,`not.${o}.${i}`),this}or(n,{foreignTable:o,referencedTable:i=o}={}){let u=i?`${i}.or`:"or";return this.url.searchParams.append(u,`(${n})`),this}filter(n,o,i){return this.url.searchParams.append(n,`${o}.${i}`),this}};e.default=a}),pt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ge()),s=class{constructor(a,{headers:n={},schema:o,fetch:i}){this.url=a,this.headers=new Headers(n),this.schema=o,this.fetch=i}select(a,n){let{head:o=!1,count:i}=n??{},u=o?"HEAD":"GET",l=!1,c=(a??"*").split("").map(h=>/\s/.test(h)&&!l?"":(h==='"'&&(l=!l),h)).join("");return this.url.searchParams.set("select",c),i&&this.headers.append("Prefer",`count=${i}`),new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(a,{count:n,defaultToNull:o=!0}={}){var i;let u="POST";if(n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let l=a.reduce((c,h)=>c.concat(Object.keys(h)),[]);if(l.length>0){let c=[...new Set(l)].map(h=>`"${h}"`);this.url.searchParams.set("columns",c.join(","))}}return new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}upsert(a,{onConflict:n,ignoreDuplicates:o=!1,count:i,defaultToNull:u=!0}={}){var l;let c="POST";if(this.headers.append("Prefer",`resolution=${o?"ignore":"merge"}-duplicates`),n!==void 0&&this.url.searchParams.set("on_conflict",n),i&&this.headers.append("Prefer",`count=${i}`),u||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let h=a.reduce((m,d)=>m.concat(Object.keys(d)),[]);if(h.length>0){let m=[...new Set(h)].map(d=>`"${d}"`);this.url.searchParams.set("columns",m.join(","))}}return new r.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(l=this.fetch)!==null&&l!==void 0?l:fetch})}update(a,{count:n}={}){var o;let i="PATCH";return n&&this.headers.append("Prefer",`count=${n}`),new r.default({method:i,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(o=this.fetch)!==null&&o!==void 0?o:fetch})}delete({count:a}={}){var n;let o="DELETE";return a&&this.headers.append("Prefer",`count=${a}`),new r.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}};e.default=s}),Wt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(pt()),s=t.__importDefault(ge()),a=class dt{constructor(o,{headers:i={},schema:u,fetch:l}={}){this.url=o,this.headers=new Headers(i),this.schemaName=u,this.fetch=l}from(o){let i=new URL(`${this.url}/${o}`);return new r.default(i,{headers:new Headers(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(o){return new dt(this.url,{headers:this.headers,schema:o,fetch:this.fetch})}rpc(o,i={},{head:u=!1,get:l=!1,count:c}={}){var h;let m,d=new URL(`${this.url}/rpc/${o}`),y;u||l?(m=u?"HEAD":"GET",Object.entries(i).filter(([g,w])=>w!==void 0).map(([g,w])=>[g,Array.isArray(w)?`{${w.join(",")}}`:`${w}`]).forEach(([g,w])=>{d.searchParams.append(g,w)})):(m="POST",y=i);let b=new Headers(this.headers);return c&&b.set("Prefer",`count=${c}`),new s.default({method:m,url:d,headers:b,schema:this.schemaName,body:y,fetch:(h=this.fetch)!==null&&h!==void 0?h:fetch})}};e.default=a}),Gt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0}),e.PostgrestError=e.PostgrestBuilder=e.PostgrestTransformBuilder=e.PostgrestFilterBuilder=e.PostgrestQueryBuilder=e.PostgrestClient=void 0;var t=(W(),q(k)),r=t.__importDefault(Wt());e.PostgrestClient=r.default;var s=t.__importDefault(pt());e.PostgrestQueryBuilder=s.default;var a=t.__importDefault(ge());e.PostgrestFilterBuilder=a.default;var n=t.__importDefault(ft());e.PostgrestTransformBuilder=n.default;var o=t.__importDefault(ht());e.PostgrestBuilder=o.default;var i=t.__importDefault(ct());e.PostgrestError=i.default,e.default={PostgrestClient:r.default,PostgrestQueryBuilder:s.default,PostgrestFilterBuilder:a.default,PostgrestTransformBuilder:n.default,PostgrestBuilder:o.default,PostgrestError:i.default}});f();f();f();f();f();f();var Kt=Object.defineProperty,zt=Object.defineProperties,Vt=Object.getOwnPropertyDescriptors,Te=Object.getOwnPropertySymbols,Yt=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable,Pe=(e,t,r)=>t in e?Kt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,j=(e,t)=>{for(var r in t||(t={}))Yt.call(t,r)&&Pe(e,r,t[r]);if(Te)for(var r of Te(t))Jt.call(t,r)&&Pe(e,r,t[r]);return e},I=(e,t)=>zt(e,Vt(t)),Xt=class extends Error{constructor(e,t,r){super(t||e.toString(),{cause:r}),this.status=e,this.statusText=t,this.error=r}},Qt=async(e,t)=>{var r,s,a,n,o,i;let u=t||{},l={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:u,hooks:l};for(let c of t?.plugins||[]){if(c.init){let h=await((r=c.init)==null?void 0:r.call(c,e.toString(),t));u=h.options||u,e=h.url}l.onRequest.push((s=c.hooks)==null?void 0:s.onRequest),l.onResponse.push((a=c.hooks)==null?void 0:a.onResponse),l.onSuccess.push((n=c.hooks)==null?void 0:n.onSuccess),l.onError.push((o=c.hooks)==null?void 0:o.onError),l.onRetry.push((i=c.hooks)==null?void 0:i.onRetry)}return{url:e,options:u,hooks:l}},Se=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},Zt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function er(e){if(typeof e=="number")return new Se({type:"linear",attempts:e,delay:1e3});switch(e.type){case"linear":return new Se(e);case"exponential":return new Zt(e);default:throw new Error("Invalid retry strategy")}}var tr=async e=>{let t={},r=async s=>typeof s=="function"?await s():s;if(e?.auth){if(e.auth.type==="Bearer"){let s=await r(e.auth.token);if(!s)return t;t.authorization=`Bearer ${s}`}else if(e.auth.type==="Basic"){let s=r(e.auth.username),a=r(e.auth.password);if(!s||!a)return t;t.authorization=`Basic ${btoa(`${s}:${a}`)}`}else if(e.auth.type==="Custom"){let s=r(e.auth.value);if(!s)return t;t.authorization=`${r(e.auth.prefix)} ${s}`}}return t},rr=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function sr(e){let t=e.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!t)return"json";let s=t.split(";").shift()||"";return rr.test(s)?"json":r.has(s)||s.startsWith("text/")?"text":"blob"}function nr(e){try{return JSON.parse(e),!0}catch{return!1}}function mt(e){if(e===void 0)return!1;let t=typeof e;return t==="string"||t==="number"||t==="boolean"||t===null?!0:t!=="object"?!1:Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name==="Object"||typeof e.toJSON=="function"}function Ae(e){try{return JSON.parse(e)}catch{return e}}function Re(e){return typeof e=="function"}function ar(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<"u"&&Re(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&Re(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function or(e){let t=new Headers(e?.headers),r=await tr(e);for(let[s,a]of Object.entries(r||{}))t.set(s,a);if(!t.has("content-type")){let s=ir(e?.body);s&&t.set("content-type",s)}return t}function ir(e){return mt(e)?"application/json":null}function lr(e){if(!e?.body)return null;let t=new Headers(e?.headers);if(mt(e.body)&&!t.has("content-type")){for(let[r,s]of Object.entries(e?.body))s instanceof Date&&(e.body[r]=s.toISOString());return JSON.stringify(e.body)}return e.body}function ur(e,t){var r;if(t?.method)return t.method.toUpperCase();if(e.startsWith("@")){let s=(r=e.split("@")[1])==null?void 0:r.split("/")[0];return gt.includes(s)?s.toUpperCase():t?.body?"POST":"GET"}return t?.body?"POST":"GET"}function cr(e,t){let r;return!e?.signal&&e?.timeout&&(r=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var hr=class yt extends Error{constructor(t,r){super(r||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,yt.prototype)}};async function te(e,t){let r=await e["~standard"].validate(t);if(r.issues)throw new hr(r.issues);return r.value}var gt=["get","post","put","patch","delete"],fr=e=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(t,r){var s,a,n,o;let i=((a=(s=e.plugins)==null?void 0:s.find(u=>{var l;return(l=u.schema)!=null&&l.config?t.startsWith(u.schema.config.baseURL||"")||t.startsWith(u.schema.config.prefix||""):!1}))==null?void 0:a.schema)||e.schema;if(i){let u=t;(n=i.config)!=null&&n.prefix&&u.startsWith(i.config.prefix)&&(u=u.replace(i.config.prefix,""),i.config.baseURL&&(t=t.replace(i.config.prefix,i.config.baseURL))),(o=i.config)!=null&&o.baseURL&&u.startsWith(i.config.baseURL)&&(u=u.replace(i.config.baseURL,""));let l=i.schema[u];if(l){let c=I(j({},r),{method:l.method,output:l.output});return r?.disableValidation||(c=I(j({},c),{body:l.input?await te(l.input,r?.body):r?.body,params:l.params?await te(l.params,r?.params):r?.params,query:l.query?await te(l.query,r?.query):r?.query})),{url:t,options:c}}}return{url:t,options:r}}}),pr=e=>{async function t(r,s){let a=I(j(j({},e),s),{plugins:[...e?.plugins||[],fr(e||{})]});if(e?.catchAllError)try{return await fe(r,a)}catch(n){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:n}}}return await fe(r,a)}return t};function dr(e,t){let{baseURL:r,params:s,query:a}=t||{query:{},params:{},baseURL:""},n=e.startsWith("http")?e.split("/").slice(0,3).join("/"):r||"";if(e.startsWith("@")){let c=e.toString().split("@")[1].split("/")[0];gt.includes(c)&&(e=e.replace(`@${c}/`,"/"))}n.endsWith("/")||(n+="/");let[o,i]=e.replace(n,"").split("?"),u=new URLSearchParams(i);for(let[c,h]of Object.entries(a||{}))h!=null&&u.set(c,String(h));if(s)if(Array.isArray(s)){let c=o.split("/").filter(h=>h.startsWith(":"));for(let[h,m]of c.entries()){let d=s[h];o=o.replace(m,d)}}else for(let[c,h]of Object.entries(s))o=o.replace(`:${c}`,String(h));o=o.split("/").map(encodeURIComponent).join("/"),o.startsWith("/")&&(o=o.slice(1));let l=u.toString();return l=l.length>0?`?${l}`.replace(/\+/g,"%20"):"",n.startsWith("http")?new URL(`${o}${l}`,n):`${n}${o}${l}`}var fe=async(e,t)=>{var r,s,a,n,o,i,u,l;let{hooks:c,url:h,options:m}=await Qt(e,t),d=ar(m),y=new AbortController,b=(r=m.signal)!=null?r:y.signal,g=dr(h,m),w=lr(m),P=await or(m),S=ur(h,m),p=I(j({},m),{url:g,headers:P,body:w,method:S,signal:b});for(let T of c.onRequest)if(T){let E=await T(p);E instanceof Object&&(p=E)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((s=t?.body)==null?void 0:s.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:C}=cr(m,y),_=await d(p.url,p);C();let Ee={response:_,request:p};for(let T of c.onResponse)if(T){let E=await T(I(j({},Ee),{response:(a=t?.hookOptions)!=null&&a.cloneResponse?_.clone():_}));E instanceof Response?_=E:E instanceof Object&&(_=E.response)}if(_.ok){if(p.method==="HEAD")return{data:"",error:null};let T=sr(_),E={data:"",response:_,request:p};if(T==="json"||T==="text"){let B=await _.text(),M=await((n=p.jsonParser)!=null?n:Ae)(B);E.data=M}else E.data=await _[T]();p?.output&&p.output&&!p.disableValidation&&(E.data=await te(p.output,E.data));for(let B of c.onSuccess)B&&await B(I(j({},E),{response:(o=t?.hookOptions)!=null&&o.cloneResponse?_.clone():_}));return t?.throw?E.data:{data:E.data,error:null}}let $t=(i=t?.jsonParser)!=null?i:Ae,J=await _.text(),Oe=nr(J),le=Oe?await $t(J):null,jt={response:_,responseText:J,request:p,error:I(j({},le),{status:_.status,statusText:_.statusText})};for(let T of c.onError)T&&await T(I(j({},jt),{response:(u=t?.hookOptions)!=null&&u.cloneResponse?_.clone():_}));if(t?.retry){let T=er(t.retry),E=(l=t.retryAttempt)!=null?l:0;if(await T.shouldAttemptRetry(E,_)){for(let M of c.onRetry)M&&await M(Ee);let B=T.getDelay(E);return await new Promise(M=>setTimeout(M,B)),await fe(e,I(j({},t),{retryAttempt:E+1}))}}if(t?.throw)throw new Xt(_.status,_.statusText,Oe?le:J);return{data:null,error:I(j({},le),{status:_.status,statusText:_.statusText})}};f();f();var re=Object.create(null),G=e=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?re:globalThis),R=new Proxy(re,{get(e,t){return G()[t]??re[t]},has(e,t){let r=G();return t in r||t in re},set(e,t,r){let s=G(!0);return s[t]=r,!0},deleteProperty(e,t){if(!t)return!1;let r=G(!0);return delete r[t],!0},ownKeys(){let e=G(!0);return Object.keys(e)}}),us=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function v(e,t){return typeof process<"u"&&process.env?process.env[e]??t:typeof Deno<"u"?Deno.env.get(e)??t:typeof Bun<"u"?Bun.env[e]??t:t}var cs=Object.freeze({get BETTER_AUTH_SECRET(){return v("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return v("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return v("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return v("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return v("NODE_ENV","development")},get PACKAGE_VERSION(){return v("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return v("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),K=1,O=4,N=8,A=24,$e={eterm:O,cons25:O,console:O,cygwin:O,dtterm:O,gnome:O,hurd:O,jfbterm:O,konsole:O,kterm:O,mlterm:O,mosh:A,putty:O,st:O,"rxvt-unicode-24bit":A,terminator:A,"xterm-kitty":A},mr=new Map(Object.entries({APPVEYOR:N,BUILDKITE:N,CIRCLECI:A,DRONE:N,GITEA_ACTIONS:A,GITHUB_ACTIONS:A,GITLAB_CI:N,TRAVIS:N})),yr=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function gr(){if(v("FORCE_COLOR")!==void 0)switch(v("FORCE_COLOR")){case"":case"1":case"true":return O;case"2":return N;case"3":return A;default:return K}if(v("NODE_DISABLE_COLORS")!==void 0&&v("NODE_DISABLE_COLORS")!==""||v("NO_COLOR")!==void 0&&v("NO_COLOR")!==""||v("TERM")==="dumb")return K;if(v("TMUX"))return A;if("TF_BUILD"in R&&"AGENT_NAME"in R)return O;if("CI"in R){for(let{0:e,1:t}of mr)if(e in R)return t;return v("CI_NAME")==="codeship"?N:K}if("TEAMCITY_VERSION"in R)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(v("TEAMCITY_VERSION"))!==null?O:K;switch(v("TERM_PROGRAM")){case"iTerm.app":return!v("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(v("TERM_PROGRAM_VERSION"))!==null?N:A;case"HyperTerm":case"MacTerm":return A;case"Apple_Terminal":return N}if(v("COLORTERM")==="truecolor"||v("COLORTERM")==="24bit")return A;if(v("TERM")){if(/truecolor/.exec(v("TERM"))!==null)return A;if(/^xterm-256/.exec(v("TERM"))!==null)return N;let e=v("TERM").toLowerCase();if($e[e])return $e[e];if(yr.some(t=>t.exec(e)!==null))return O}return v("COLORTERM")?O:K}var x={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"}},pe=["info","success","warn","error","debug"];function wr(e,t){return pe.indexOf(t)<=pe.indexOf(e)}var vr={info:x.fg.blue,success:x.fg.green,warn:x.fg.yellow,error:x.fg.red,debug:x.fg.magenta},br=(e,t,r)=>{let s=new Date().toISOString();return r?`${x.dim}${s}${x.reset} ${vr[e]}${e.toUpperCase()}${x.reset} ${x.bright}[Better Auth]:${x.reset} ${t}`:`${s} ${e.toUpperCase()} [Better Auth]: ${t}`},_r=e=>{let t=e?.disabled!==!0,r=e?.level??"error",s=e?.disableColors!==void 0?!e.disableColors:gr()!==1,a=(n,o,i=[])=>{if(!t||!wr(r,n))return;let u=br(n,o,s);if(!e||typeof e.log!="function"){n==="error"?console.error(u,...i):n==="warn"?console.warn(u,...i):console.log(u,...i);return}e.log(n==="success"?"info":n,o,...i)};return{...Object.fromEntries(pe.map(n=>[n,(...[o,...i])=>a(n,o,i)])),get level(){return r}}},hs=_r();f();f();var we=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function Er(e){try{return(new URL(e).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new we(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function z(e,t="/api/auth"){if(Er(e))return e;let r=e.replace(/\/+$/,"");return!t||t==="/"?r:(t=t.startsWith("/")?t:`/${t}`,`${r}${t}`)}function Or(e,t,r,s){if(e)return z(e,t);if(s!==!1){let o=R.BETTER_AUTH_URL||R.NEXT_PUBLIC_BETTER_AUTH_URL||R.PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_AUTH_URL||(R.BASE_URL!=="/"?R.BASE_URL:void 0);if(o)return z(o,t)}let a=r?.headers.get("x-forwarded-host"),n=r?.headers.get("x-forwarded-proto");if(a&&n)return z(`${n}://${a}`,t);if(r){let o=Tr(r.url);if(!o)throw new we("Could not get origin from request. Please provide a valid base URL.");return z(o,t)}if(typeof window<"u"&&window.location)return z(window.location.origin,t)}function Tr(e){try{return new URL(e).origin}catch{return null}}f();f();f();var de=Symbol("clean"),$=[],U=0,X=4,Pr=0,wt=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(s){return r.lc=t.push(s),()=>{for(let n=U+X;n<$.length;)$[n]===s?$.splice(n,X):n+=X;let a=t.indexOf(s);~a&&(t.splice(a,1),--r.lc||r.off())}},notify(s,a){Pr++;let n=!$.length;for(let o of t)$.push(o,r.value,s,a);if(n){for(U=0;U<$.length;U+=X)$[U]($[U+1],$[U+2],$[U+3]);$.length=0}},off(){},set(s){let a=r.value;a!==s&&(r.value=s,r.notify(a))},subscribe(s){let a=r.listen(s);return s(r.value),a},value:e};return process.env.NODE_ENV!=="production"&&(r[de]=()=>{t=[],r.lc=0,r.off()}),r};f();var Sr=5,F=6,Q=10,Ar=(e,t,r,s)=>(e.events=e.events||{},e.events[r+Q]||(e.events[r+Q]=s(a=>{e.events[r].reduceRight((n,o)=>(o(n),n),{shared:{},...a})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let a=e.events[r],n=a.indexOf(t);a.splice(n,1),a.length||(delete e.events[r],e.events[r+Q](),delete e.events[r+Q])}),Rr=1e3,$r=(e,t)=>Ar(e,r=>{let s=t(r);s&&e.events[F].push(s)},Sr,r=>{let s=e.listen;e.listen=(...n)=>(!e.lc&&!e.active&&(e.active=!0,r()),s(...n));let a=e.off;if(e.events[F]=[],e.off=()=>{a(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let n of e.events[F])n();e.events[F]=[]}},Rr)},process.env.NODE_ENV!=="production"){let n=e[de];e[de]=()=>{for(let o of e.events[F])o();e.events[F]=[],e.active=!1,n()}}return()=>{e.listen=s,e.off=a}});f();var jr=typeof window>"u",Ir=(e,t,r,s)=>{let a=wt({data:null,error:null,isPending:!0,isRefetching:!1,refetch:i=>n(i)}),n=i=>{let u=typeof s=="function"?s({data:a.get().data,error:a.get().error,isPending:a.get().isPending}):s;r(t,{...u,query:{...u?.query,...i?.query},async onSuccess(l){a.set({data:l.data,error:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onSuccess?.(l)},async onError(l){let{request:c}=l,h=typeof c.retry=="number"?c.retry:c.retry?.attempts,m=c.retryAttempt||0;h&&m<h||(a.set({error:l.error,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onError?.(l))},async onRequest(l){let c=a.get();a.set({isPending:c.data===null,data:c.data,error:null,isRefetching:!0,refetch:a.value.refetch}),await u?.onRequest?.(l)}}).catch(l=>{a.set({error:l,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch})})};e=Array.isArray(e)?e:[e];let o=!1;for(let i of e)i.subscribe(()=>{jr||(o?n():$r(a,()=>{let u=setTimeout(()=>{o||(n(),o=!0)},0);return()=>{a.off(),i.off(),clearTimeout(u)}}))});return a};f();var Nr={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*$/,je={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Ur=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function Cr(e){return e instanceof Date&&!isNaN(e.getTime())}function Lr(e){let t=Ur.exec(e);if(!t)return null;let[,r,s,a,n,o,i,u,l,c,h]=t,m=new Date(Date.UTC(parseInt(r,10),parseInt(s,10)-1,parseInt(a,10),parseInt(n,10),parseInt(o,10),parseInt(i,10),u?parseInt(u.padEnd(3,"0"),10):0));if(l){let d=(parseInt(c,10)*60+parseInt(h,10))*(l==="+"?-1:1);m.setUTCMinutes(m.getUTCMinutes()+d)}return Cr(m)?m:null}function Dr(e,t={}){let{strict:r=!1,warnings:s=!1,reviver:a,parseDates:n=!0}=t;if(typeof e!="string")return e;let o=e.trim();if(o.length>0&&o[0]==='"'&&o.endsWith('"')&&!o.slice(1,-1).includes('"'))return o.slice(1,-1);let i=o.toLowerCase();if(i.length<=9&&i in je)return je[i];if(!xr.test(o)){if(r)throw new SyntaxError("[better-json] Invalid JSON");return e}if(Object.entries(Nr).some(([u,l])=>{let c=l.test(o);return c&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),c})&&r)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(o,(u,l)=>{if(u==="__proto__"||u==="constructor"&&l&&typeof l=="object"&&"prototype"in l){s&&console.warn(`[better-json] Dropping "${u}" key to prevent prototype pollution`);return}if(n&&typeof l=="string"){let c=Lr(l);if(c)return c}return a?a(u,l):l})}catch(u){if(r)throw u;return e}}function kr(e,t={strict:!0}){return Dr(e,t)}var Br={id:"redirect",name:"Redirect",hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}};function Mr(e){let t=wt(!1);return{session:Ir(t,"/get-session",e,{method:"GET"}),$sessionSignal:t}}var Fr=(e,t)=>{let r="credentials"in Request.prototype,s=Or(e?.baseURL,e?.basePath,void 0,t)??"/api/auth",a=e?.plugins?.flatMap(p=>p.fetchPlugins).filter(p=>p!==void 0)||[],n={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:i,onRequest:u,onResponse:l,...c}=e?.fetchOptions||{},h=pr({baseURL:s,...r?{credentials:"include"}:{},method:"GET",jsonParser(p){return p?kr(p,{strict:!1}):null},customFetchImpl:fetch,...c,plugins:[n,...c.plugins||[],...e?.disableDefaultFetchPlugins?[]:[Br],...a]}),{$sessionSignal:m,session:d}=Mr(h),y=e?.plugins||[],b={},g={$sessionSignal:m,session:d},w={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},P=[{signal:"$sessionSignal",matcher(p){return p==="/sign-out"||p==="/update-user"||p.startsWith("/sign-in")||p.startsWith("/sign-up")||p==="/delete-user"||p==="/verify-email"}}];for(let p of y)p.getAtoms&&Object.assign(g,p.getAtoms?.(h)),p.pathMethods&&Object.assign(w,p.pathMethods),p.atomListeners&&P.push(...p.atomListeners);let S={notify:p=>{g[p].set(!g[p].get())},listen:(p,C)=>{g[p].subscribe(C)},atoms:g};for(let p of y)p.getActions&&Object.assign(b,p.getActions?.(h,S,e));return{get baseURL(){return s},pluginsActions:b,pluginsAtoms:g,pluginPathMethods:w,atomListeners:P,$fetch:h,$store:S}};function Hr(e){return typeof e=="object"&&e!==null&&"get"in e&&typeof e.get=="function"&&"lc"in e&&typeof e.lc=="number"}function qr(e,t,r){let s=t[e],{fetchOptions:a,query:n,...o}=r||{};return s||(a?.method?a.method:o&&Object.keys(o).length>0?"POST":"GET")}function Wr(e,t,r,s,a){function n(o=[]){return new Proxy(function(){},{get(i,u){if(typeof u!="string"||u==="then"||u==="catch"||u==="finally")return;let l=[...o,u],c=e;for(let h of l)if(c&&typeof c=="object"&&h in c)c=c[h];else{c=void 0;break}return typeof c=="function"||Hr(c)?c:n(l)},apply:async(i,u,l)=>{let c="/"+o.map(P=>P.replace(/[A-Z]/g,S=>`-${S.toLowerCase()}`)).join("/"),h=l[0]||{},m=l[1]||{},{query:d,fetchOptions:y,...b}=h,g={...m,...y},w=qr(c,r,h);return await t(c,{...g,body:w==="GET"?void 0:{...b,...g?.body||{}},query:d||g?.query,method:w,async onSuccess(P){if(await g?.onSuccess?.(P),!a)return;let S=a.filter(p=>p.matcher(c));if(S.length)for(let p of S){let C=s[p.signal];if(!C)return;let _=C.get();setTimeout(()=>{C.set(!_)},10)}}})}})}return n()}f();function Gr(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Kr(e){let{pluginPathMethods:t,pluginsActions:r,pluginsAtoms:s,$fetch:a,atomListeners:n,$store:o}=Fr(e),i={};for(let[l,c]of Object.entries(s))i[`use${Gr(l)}`]=c;let u={...r,...i,$fetch:a,$store:o};return Wr(u,a,t,s,n)}f();f();f();function zr(e){return{authorize(t,r="AND"){let s=!1;for(let[a,n]of Object.entries(t)){let o=e[a];if(!o)return{success:!1,error:`You are not allowed to access resource: ${a}`};if(Array.isArray(n))s=n.every(i=>o.includes(i));else if(typeof n=="object"){let i=n;i.connector==="OR"?s=i.actions.some(u=>o.includes(u)):s=i.actions.every(u=>o.includes(u))}else throw new we("Invalid access control request");if(s&&r==="OR")return{success:s};if(!s&&r==="AND")return{success:!1,error:`unauthorized to access resource "${a}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:e}}function vt(e){return{newRole(t){return zr(t)},statements:e}}var Vr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},ve=vt(Vr),fs=ve.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),ps=ve.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),ds=ve.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});f();f();f();f();f();f();f();f();f();f();f();var Yr=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}}},ms=new Yr;f();f();f();f();f();f();f();f();var Jr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},bt=vt(Jr),ys=bt.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),gs=bt.newRole({user:[],session:[]});f();f();var Xr=()=>({id:"username",$InferServerPlugin:{}}),Qr=()=>({id:"phoneNumber",$InferServerPlugin:{},atomListeners:[{matcher(e){return e==="/phone-number/update"||e==="/phone-number/verify"},signal:"$sessionSignal"}]}),Zr=()=>({id:"better-auth-client",$InferServerPlugin:{}}),es="/auth",ce="nvwa_login_token",se="nvwa_current_jwt",he="nvwa_user_profile",_t=class{constructor(e,t,r){this.storage=r;let s=Kr({baseURL:e,basePath:es,plugins:[Xr(),Qr(),Zr()],fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:async()=>{let a=await this.storage.get(se);if(console.log("jwt",a),a)return a;let n=await this.storage.get(ce);return console.log("loginToken",n),n}}}});this.authClient=s}async currentUser(){return await this.storage.get(he)}async getCurrentJwt(){return await this.storage.get(se)}async signUp(e){let t=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:e.password});this.handleLogin(t)}async sendPhoneNumberCode(e){await this.authClient.phoneNumber.sendOtp({phoneNumber:e})}async signInWithPhoneNumberCode(e,t){let r=await this.authClient.phoneNumber.verify({phoneNumber:e,code:t});this.handleLogin(r)}async signInWithPhoneNumber(e,t,r=!1){let s=await this.authClient.signIn.phoneNumber({phoneNumber:e,password:t,rememberMe:r});this.handleLogin(s)}async signInWithUsername(e,t){let r=await this.authClient.signIn.username({username:e,password:t});this.handleLogin(r)}async handleLogin(e){if(e.error)throw new Error(e.error.message);await this.storage.set(ce,e.data?.token),await this.storage.set(he,e.data?.user);let{data:t,error:r}=await this.authClient.token();if(r)throw new Error(r.message);await this.storage.set(se,t.token)}async signOut(){await this.storage.remove(ce),await this.storage.remove(he)}async updateUserPassword(e,t,r=!1){let s=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:r});this.handleLogin(s)}};f();var Et=class{constructor(e){this.http=e}async invoke(e,t){return await(await this.http.fetch("/functions/"+e,{method:t.method||"POST",body:t.body,headers:t.headers})).json()}};f();f();f();var L=class Ot{constructor(t){if(this.headerMap=new Map,t){if(t instanceof Ot)t.forEach((r,s)=>this.set(s,r));else if(Array.isArray(t))for(let[r,s]of t)this.set(r,String(s));else if(typeof t=="object")for(let r of Object.keys(t))this.set(r,String(t[r]))}}append(t,r){let s=t.toLowerCase(),a=this.headerMap.get(s);this.headerMap.set(s,a?`${a}, ${r}`:r)}set(t,r){this.headerMap.set(t.toLowerCase(),String(r))}get(t){return this.headerMap.get(t.toLowerCase())??null}has(t){return this.headerMap.has(t.toLowerCase())}delete(t){this.headerMap.delete(t.toLowerCase())}forEach(t){for(let[r,s]of this.headerMap.entries())t(s,r,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}};f();f();var Tt=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=ts(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 ts(e){return e?new L(e):new L}f();f();var Pt=class{constructor(e,t,r){console.log("NvwaHttpClient constructor",e,t,r),this.storage=e,this.customFetch=t,this.handleUnauthorized=r}async fetch(e,t){return await this.customFetch(e,t)}async fetchWithAuth(e,t){let r=await this.storage.get(se),s=new L(t?.headers);r&&s.set("Authorization",`Bearer ${r}`);let a=await this.customFetch(e,{...t,headers:s});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};f();var rs="/storage",ss=rs+"/generateUploadUrl",St=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.fetch(this.baseUrl+ss,{method:"POST",body:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:r}=await t.json();if(!r)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let s=await this.http.fetch(r,{method:"PUT",body:e,headers:new L({"Content-Type":e.type||e.fileType||"application/octet-stream"})}),{url:a}=await s.json();return{url:a.split("?")[0]}}};f();f();f();var Ie=qt(Gt(),1),{PostgrestClient:ns,PostgrestQueryBuilder:ws,PostgrestFilterBuilder:vs,PostgrestTransformBuilder:bs,PostgrestBuilder:_s,PostgrestError:Es}=Ie.default||Ie,as="/entities",At=(e,t)=>new ns(e+as,{fetch:t.fetchWithAuth.bind(t)});f();var Rt=class{constructor(e,t){this.baseUrl=e,this.http=t}async execute(e,t){let r=`${this.baseUrl}/skill/${e}/execute`,s=await(await this.http.fetchWithAuth(r,{method:"POST",body:t,timeout:6e5})).json();if(s.status!==200)throw new Error(s.message);return s.data}};var oe=class{constructor(){this.prefix="nvwa_"}getKey(t){return`${this.prefix}${t}`}async get(t){try{let r=this.getKey(t),s=localStorage.getItem(r);if(!s)return null;let a=JSON.parse(s);return a.expires&&Date.now()>a.expires?(await this.remove(t),null):a.value}catch(r){return console.error("WebStorageService get error:",r),null}}async set(t,r,s){try{let a=this.getKey(t),n={value:r,expires:s?Date.now()+s*1e3:null,timestamp:Date.now()};localStorage.setItem(a,JSON.stringify(n))}catch(a){throw console.error("WebStorageService set error:",a),a}}async remove(t){try{let r=this.getKey(t);localStorage.removeItem(r)}catch(r){throw console.error("WebStorageService remove error:",r),r}}async clear(){try{Object.keys(localStorage).filter(s=>s.startsWith(this.prefix)).forEach(s=>{localStorage.removeItem(s)})}catch(t){throw console.error("WebStorageService clear error:",t),t}}};var os=(e,t)=>{let r;if(typeof e=="string")r=e;else if(e&&typeof e.toString=="function")r=e.toString();else if(e?.url)r=e.url;else throw new Error("Invalid input for webFetch");let s;if(t?.headers){let n=t.headers;if(n instanceof L){let o={};n.forEach((i,u)=>{o[u]=i}),s=o}else if(Array.isArray(n)){let o=[];for(let i of n)Array.isArray(i)&&i.length>=2&&o.push([String(i[0]),String(i[1])]);s=o}else typeof n=="object"&&(s=n)}let a={method:t?.method||"GET",headers:s,body:t?.body};return t?.signal&&(a.signal=t.signal),globalThis.fetch(r,a).then(async n=>{let o=n.headers.get("content-type")||"",i;if(o.includes("application/json"))i=await n.json();else{let l=await n.text();try{i=JSON.parse(l)}catch{i=l}}let u=new L;return n.headers.forEach((l,c)=>{u.set(c,l)}),new Tt(i,{status:n.status,statusText:n.statusText,headers:u})})},be=os;var _e=new oe,ie=class{constructor(t,r){this.auth=new _t(t,be,_e),this.httpClient=new Pt(_e,be,r),this.fileStorage=new St(t,this.httpClient),this.entities=At(t,this.httpClient),this.functions=new Et(this.httpClient),this.skill=new Rt(t,this.httpClient)}};0&&(module.exports={localStorage});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var It=Object.create,ae=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,xt=Object.getOwnPropertyNames,Ut=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty,Ie=(e,t)=>()=>(e&&(t=e(e=0)),t),D=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Lt=(e,t)=>{for(var r in t)ae(e,r,{get:t[r],enumerable:!0})},Ne=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of xt(t))!Ct.call(e,a)&&a!==r&&ae(e,a,{get:()=>t[a],enumerable:!(s=Nt(t,a))||s.enumerable});return e},Dt=(e,t,r)=>(r=e!=null?It(Ut(e)):{},Ne(t||!e||!e.__esModule?ae(r,"default",{value:e,enumerable:!0}):r,e)),q=e=>Ne(ae({},"__esModule",{value:!0}),e),f=Ie(()=>{"use strict"}),k={};Lt(k,{__addDisposableResource:()=>st,__assign:()=>V,__asyncDelegator:()=>Ye,__asyncGenerator:()=>Ve,__asyncValues:()=>Je,__await:()=>H,__awaiter:()=>He,__classPrivateFieldGet:()=>et,__classPrivateFieldIn:()=>rt,__classPrivateFieldSet:()=>tt,__createBinding:()=>Y,__decorate:()=>Ce,__disposeResources:()=>nt,__esDecorate:()=>De,__exportStar:()=>We,__extends:()=>xe,__generator:()=>qe,__importDefault:()=>Ze,__importStar:()=>Qe,__makeTemplateObject:()=>Xe,__metadata:()=>Fe,__param:()=>Le,__propKey:()=>Be,__read:()=>me,__rest:()=>Ue,__rewriteRelativeImportExtension:()=>at,__runInitializers:()=>ke,__setFunctionName:()=>Me,__spread:()=>Ge,__spreadArray:()=>ze,__spreadArrays:()=>Ke,__values:()=>ne,default:()=>lt});function xe(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Z(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function Ue(e,t){var r={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,s=Object.getOwnPropertySymbols(e);a<s.length;a++)t.indexOf(s[a])<0&&Object.prototype.propertyIsEnumerable.call(e,s[a])&&(r[s[a]]=e[s[a]]);return r}function Ce(e,t,r,s){var a=arguments.length,n=a<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,r):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(n=(a<3?o(n):a>3?o(t,r,n):o(t,r))||n);return a>3&&n&&Object.defineProperty(t,r,n),n}function Le(e,t){return function(r,s){t(r,s,e)}}function De(e,t,r,s,a,n){function o(v){if(v!==void 0&&typeof v!="function")throw new TypeError("Function expected");return v}for(var i=s.kind,u=i==="getter"?"get":i==="setter"?"set":"value",l=!t&&e?s.static?e:e.prototype:null,c=t||(l?Object.getOwnPropertyDescriptor(l,s.name):{}),h,m=!1,d=r.length-1;d>=0;d--){var y={};for(var b in s)y[b]=b==="access"?{}:s[b];for(var b in s.access)y.access[b]=s.access[b];y.addInitializer=function(v){if(m)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(v||null))};var g=(0,r[d])(i==="accessor"?{get:c.get,set:c.set}:c[u],y);if(i==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(h=o(g.get))&&(c.get=h),(h=o(g.set))&&(c.set=h),(h=o(g.init))&&a.unshift(h)}else(h=o(g))&&(i==="field"?a.unshift(h):c[u]=h)}l&&Object.defineProperty(l,s.name,c),m=!0}function ke(e,t,r){for(var s=arguments.length>2,a=0;a<t.length;a++)r=s?t[a].call(e,r):t[a].call(e);return s?r:void 0}function Be(e){return typeof e=="symbol"?e:"".concat(e)}function Me(e,t,r){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:r?"".concat(r," ",t):t})}function Fe(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function He(e,t,r,s){function a(n){return n instanceof r?n:new r(function(o){o(n)})}return new(r||(r=Promise))(function(n,o){function i(c){try{l(s.next(c))}catch(h){o(h)}}function u(c){try{l(s.throw(c))}catch(h){o(h)}}function l(c){c.done?n(c.value):a(c.value).then(i,u)}l((s=s.apply(e,t||[])).next())})}function qe(e,t){var r={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},s,a,n,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=i(0),o.throw=i(1),o.return=i(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function i(l){return function(c){return u([l,c])}}function u(l){if(s)throw new TypeError("Generator is already executing.");for(;o&&(o=0,l[0]&&(r=0)),r;)try{if(s=1,a&&(n=l[0]&2?a.return:l[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,l[1])).done)return n;switch(a=0,n&&(l=[l[0]&2,n.value]),l[0]){case 0:case 1:n=l;break;case 4:return r.label++,{value:l[1],done:!1};case 5:r.label++,a=l[1],l=[0];continue;case 7:l=r.ops.pop(),r.trys.pop();continue;default:if(n=r.trys,!(n=n.length>0&&n[n.length-1])&&(l[0]===6||l[0]===2)){r=0;continue}if(l[0]===3&&(!n||l[1]>n[0]&&l[1]<n[3])){r.label=l[1];break}if(l[0]===6&&r.label<n[1]){r.label=n[1],n=l;break}if(n&&r.label<n[2]){r.label=n[2],r.ops.push(l);break}n[2]&&r.ops.pop(),r.trys.pop();continue}l=t.call(e,r)}catch(c){l=[6,c],a=0}finally{s=n=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}function We(e,t){for(var r in e)r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r)&&Y(t,e,r)}function ne(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],s=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&s>=e.length&&(e=void 0),{value:e&&e[s++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function me(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var s=r.call(e),a,n=[],o;try{for(;(t===void 0||t-- >0)&&!(a=s.next()).done;)n.push(a.value)}catch(i){o={error:i}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return n}function Ge(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(me(arguments[t]));return e}function Ke(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;for(var s=Array(e),a=0,t=0;t<r;t++)for(var n=arguments[t],o=0,i=n.length;o<i;o++,a++)s[a]=n[o];return s}function ze(e,t,r){if(r||arguments.length===2)for(var s=0,a=t.length,n;s<a;s++)(n||!(s in t))&&(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}function H(e){return this instanceof H?(this.v=e,this):new H(e)}function Ve(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=r.apply(e,t||[]),a,n=[];return a=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),i("next"),i("throw"),i("return",o),a[Symbol.asyncIterator]=function(){return this},a;function o(d){return function(y){return Promise.resolve(y).then(d,h)}}function i(d,y){s[d]&&(a[d]=function(b){return new Promise(function(g,v){n.push([d,b,g,v])>1||u(d,b)})},y&&(a[d]=y(a[d])))}function u(d,y){try{l(s[d](y))}catch(b){m(n[0][3],b)}}function l(d){d.value instanceof H?Promise.resolve(d.value.v).then(c,h):m(n[0][2],d)}function c(d){u("next",d)}function h(d){u("throw",d)}function m(d,y){d(y),n.shift(),n.length&&u(n[0][0],n[0][1])}}function Ye(e){var t,r;return t={},s("next"),s("throw",function(a){throw a}),s("return"),t[Symbol.iterator]=function(){return this},t;function s(a,n){t[a]=e[a]?function(o){return(r=!r)?{value:H(e[a](o)),done:!1}:n?n(o):o}:n}}function Je(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof ne=="function"?ne(e):e[Symbol.iterator](),r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r);function s(n){r[n]=e[n]&&function(o){return new Promise(function(i,u){o=e[n](o),a(i,u,o.done,o.value)})}}function a(n,o,i,u){Promise.resolve(u).then(function(l){n({value:l,done:i})},o)}}function Xe(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function Qe(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=ee(e),s=0;s<r.length;s++)r[s]!=="default"&&Y(t,e,r[s]);return ot(t,e),t}function Ze(e){return e&&e.__esModule?e:{default:e}}function et(e,t,r,s){if(r==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?s:r==="a"?s.call(e):s?s.value:t.get(e)}function tt(e,t,r,s,a){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!a)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?a.call(e,r):a?a.value=r:t.set(e,r),r}function rt(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function st(e,t,r){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var s,a;if(r){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");s=t[Symbol.asyncDispose]}if(s===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");s=t[Symbol.dispose],r&&(a=s)}if(typeof s!="function")throw new TypeError("Object not disposable.");a&&(s=function(){try{a.call(this)}catch(n){return Promise.reject(n)}}),e.stack.push({value:t,dispose:s,async:r})}else r&&e.stack.push({async:!0});return t}function nt(e){function t(n){e.error=e.hasError?new it(n,e.error,"An error was suppressed during disposal."):n,e.hasError=!0}var r,s=0;function a(){for(;r=e.stack.pop();)try{if(!r.async&&s===1)return s=0,e.stack.push(r),Promise.resolve().then(a);if(r.dispose){var n=r.dispose.call(r.value);if(r.async)return s|=2,Promise.resolve(n).then(a,function(o){return t(o),a()})}else s|=1}catch(o){t(o)}if(s===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return a()}function at(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(r,s,a,n,o){return s?t?".jsx":".js":a&&(!n||!o)?r:a+n+"."+o.toLowerCase()+"js"}):e}var Z,V,Y,ot,ee,it,lt,W=Ie(()=>{"use strict";f(),Z=function(e,t){return Z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,s){r.__proto__=s}||function(r,s){for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(r[a]=s[a])},Z(e,t)},V=function(){return V=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},V.apply(this,arguments)},Y=Object.create?(function(e,t,r,s){s===void 0&&(s=r);var a=Object.getOwnPropertyDescriptor(t,r);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,a)}):(function(e,t,r,s){s===void 0&&(s=r),e[s]=t[r]}),ot=Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t},ee=function(e){return ee=Object.getOwnPropertyNames||function(t){var r=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(r[r.length]=s);return r},ee(e)},it=typeof SuppressedError=="function"?SuppressedError:function(e,t,r){var s=new Error(r);return s.name="SuppressedError",s.error=e,s.suppressed=t,s},lt={__extends:xe,__assign:V,__rest:Ue,__decorate:Ce,__param:Le,__esDecorate:De,__runInitializers:ke,__propKey:Be,__setFunctionName:Me,__metadata:Fe,__awaiter:He,__generator:qe,__createBinding:Y,__exportStar:We,__values:ne,__read:me,__spread:Ge,__spreadArrays:Ke,__spreadArray:ze,__await:H,__asyncGenerator:Ve,__asyncDelegator:Ye,__asyncValues:Je,__makeTemplateObject:Xe,__importStar:Qe,__importDefault:Ze,__classPrivateFieldGet:et,__classPrivateFieldSet:tt,__classPrivateFieldIn:rt,__addDisposableResource:st,__disposeResources:nt,__rewriteRelativeImportExtension:at}}),ut=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}};e.default=t}),ct=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ut()),s=class{constructor(a){var n,o;this.shouldThrowOnError=!1,this.method=a.method,this.url=a.url,this.headers=new Headers(a.headers),this.schema=a.schema,this.body=a.body,this.shouldThrowOnError=(n=a.shouldThrowOnError)!==null&&n!==void 0?n:!1,this.signal=a.signal,this.isMaybeSingle=(o=a.isMaybeSingle)!==null&&o!==void 0?o:!1,a.fetch?this.fetch=a.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(a,n){return this.headers=new Headers(this.headers),this.headers.set(a,n),this}then(a,n){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 o=this.fetch,i=o(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async u=>{var l,c,h,m;let d=null,y=null,b=null,g=u.status,v=u.statusText;if(u.ok){if(this.method!=="HEAD"){let p=await u.text();p===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&!((l=this.headers.get("Accept"))===null||l===void 0)&&l.includes("application/vnd.pgrst.plan+text")?y=p:y=JSON.parse(p))}let P=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),S=(h=u.headers.get("content-range"))===null||h===void 0?void 0:h.split("/");P&&S&&S.length>1&&(b=parseInt(S[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(y)&&(y.length>1?(d={code:"PGRST116",details:`Results contain ${y.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},y=null,b=null,g=406,v="Not Acceptable"):y.length===1?y=y[0]:y=null)}else{let P=await u.text();try{d=JSON.parse(P),Array.isArray(d)&&u.status===404&&(y=[],d=null,g=200,v="OK")}catch{u.status===404&&P===""?(g=204,v="No Content"):d={message:P}}if(d&&this.isMaybeSingle&&!((m=d?.details)===null||m===void 0)&&m.includes("0 rows")&&(d=null,g=200,v="OK"),d&&this.shouldThrowOnError)throw new r.default(d)}return{error:d,data:y,count:b,status:g,statusText:v}});return this.shouldThrowOnError||(i=i.catch(u=>{var l,c,h;return{error:{message:`${(l=u?.name)!==null&&l!==void 0?l:"FetchError"}: ${u?.message}`,details:`${(c=u?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(h=u?.code)!==null&&h!==void 0?h:""}`},data:null,count:null,status:0,statusText:""}})),i.then(a,n)}returns(){return this}overrideTypes(){return this}};e.default=s}),ht=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ct()),s=class extends r.default{select(a){let n=!1,o=(a??"*").split("").map(i=>/\s/.test(i)&&!n?"":(i==='"'&&(n=!n),i)).join("");return this.url.searchParams.set("select",o),this.headers.append("Prefer","return=representation"),this}order(a,{ascending:n=!0,nullsFirst:o,foreignTable:i,referencedTable:u=i}={}){let l=u?`${u}.order`:"order",c=this.url.searchParams.get(l);return this.url.searchParams.set(l,`${c?`${c},`:""}${a}.${n?"asc":"desc"}${o===void 0?"":o?".nullsfirst":".nullslast"}`),this}limit(a,{foreignTable:n,referencedTable:o=n}={}){let i=typeof o>"u"?"limit":`${o}.limit`;return this.url.searchParams.set(i,`${a}`),this}range(a,n,{foreignTable:o,referencedTable:i=o}={}){let u=typeof i>"u"?"offset":`${i}.offset`,l=typeof i>"u"?"limit":`${i}.limit`;return this.url.searchParams.set(u,`${a}`),this.url.searchParams.set(l,`${n-a+1}`),this}abortSignal(a){return this.signal=a,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:a=!1,verbose:n=!1,settings:o=!1,buffers:i=!1,wal:u=!1,format:l="text"}={}){var c;let h=[a?"analyze":null,n?"verbose":null,o?"settings":null,i?"buffers":null,u?"wal":null].filter(Boolean).join("|"),m=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${l}; for="${m}"; options=${h};`),l==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(a){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${a}`),this}};e.default=s}),ye=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ht()),s=new RegExp("[,()]"),a=class extends r.default{eq(n,o){return this.url.searchParams.append(n,`eq.${o}`),this}neq(n,o){return this.url.searchParams.append(n,`neq.${o}`),this}gt(n,o){return this.url.searchParams.append(n,`gt.${o}`),this}gte(n,o){return this.url.searchParams.append(n,`gte.${o}`),this}lt(n,o){return this.url.searchParams.append(n,`lt.${o}`),this}lte(n,o){return this.url.searchParams.append(n,`lte.${o}`),this}like(n,o){return this.url.searchParams.append(n,`like.${o}`),this}likeAllOf(n,o){return this.url.searchParams.append(n,`like(all).{${o.join(",")}}`),this}likeAnyOf(n,o){return this.url.searchParams.append(n,`like(any).{${o.join(",")}}`),this}ilike(n,o){return this.url.searchParams.append(n,`ilike.${o}`),this}ilikeAllOf(n,o){return this.url.searchParams.append(n,`ilike(all).{${o.join(",")}}`),this}ilikeAnyOf(n,o){return this.url.searchParams.append(n,`ilike(any).{${o.join(",")}}`),this}is(n,o){return this.url.searchParams.append(n,`is.${o}`),this}in(n,o){let i=Array.from(new Set(o)).map(u=>typeof u=="string"&&s.test(u)?`"${u}"`:`${u}`).join(",");return this.url.searchParams.append(n,`in.(${i})`),this}contains(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cs.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cs.{${o.join(",")}}`):this.url.searchParams.append(n,`cs.${JSON.stringify(o)}`),this}containedBy(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cd.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cd.{${o.join(",")}}`):this.url.searchParams.append(n,`cd.${JSON.stringify(o)}`),this}rangeGt(n,o){return this.url.searchParams.append(n,`sr.${o}`),this}rangeGte(n,o){return this.url.searchParams.append(n,`nxl.${o}`),this}rangeLt(n,o){return this.url.searchParams.append(n,`sl.${o}`),this}rangeLte(n,o){return this.url.searchParams.append(n,`nxr.${o}`),this}rangeAdjacent(n,o){return this.url.searchParams.append(n,`adj.${o}`),this}overlaps(n,o){return typeof o=="string"?this.url.searchParams.append(n,`ov.${o}`):this.url.searchParams.append(n,`ov.{${o.join(",")}}`),this}textSearch(n,o,{config:i,type:u}={}){let l="";u==="plain"?l="pl":u==="phrase"?l="ph":u==="websearch"&&(l="w");let c=i===void 0?"":`(${i})`;return this.url.searchParams.append(n,`${l}fts${c}.${o}`),this}match(n){return Object.entries(n).forEach(([o,i])=>{this.url.searchParams.append(o,`eq.${i}`)}),this}not(n,o,i){return this.url.searchParams.append(n,`not.${o}.${i}`),this}or(n,{foreignTable:o,referencedTable:i=o}={}){let u=i?`${i}.or`:"or";return this.url.searchParams.append(u,`(${n})`),this}filter(n,o,i){return this.url.searchParams.append(n,`${o}.${i}`),this}};e.default=a}),ft=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ye()),s=class{constructor(a,{headers:n={},schema:o,fetch:i}){this.url=a,this.headers=new Headers(n),this.schema=o,this.fetch=i}select(a,n){let{head:o=!1,count:i}=n??{},u=o?"HEAD":"GET",l=!1,c=(a??"*").split("").map(h=>/\s/.test(h)&&!l?"":(h==='"'&&(l=!l),h)).join("");return this.url.searchParams.set("select",c),i&&this.headers.append("Prefer",`count=${i}`),new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(a,{count:n,defaultToNull:o=!0}={}){var i;let u="POST";if(n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let l=a.reduce((c,h)=>c.concat(Object.keys(h)),[]);if(l.length>0){let c=[...new Set(l)].map(h=>`"${h}"`);this.url.searchParams.set("columns",c.join(","))}}return new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}upsert(a,{onConflict:n,ignoreDuplicates:o=!1,count:i,defaultToNull:u=!0}={}){var l;let c="POST";if(this.headers.append("Prefer",`resolution=${o?"ignore":"merge"}-duplicates`),n!==void 0&&this.url.searchParams.set("on_conflict",n),i&&this.headers.append("Prefer",`count=${i}`),u||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let h=a.reduce((m,d)=>m.concat(Object.keys(d)),[]);if(h.length>0){let m=[...new Set(h)].map(d=>`"${d}"`);this.url.searchParams.set("columns",m.join(","))}}return new r.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(l=this.fetch)!==null&&l!==void 0?l:fetch})}update(a,{count:n}={}){var o;let i="PATCH";return n&&this.headers.append("Prefer",`count=${n}`),new r.default({method:i,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(o=this.fetch)!==null&&o!==void 0?o:fetch})}delete({count:a}={}){var n;let o="DELETE";return a&&this.headers.append("Prefer",`count=${a}`),new r.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}};e.default=s}),kt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ft()),s=t.__importDefault(ye()),a=class pt{constructor(o,{headers:i={},schema:u,fetch:l}={}){this.url=o,this.headers=new Headers(i),this.schemaName=u,this.fetch=l}from(o){let i=new URL(`${this.url}/${o}`);return new r.default(i,{headers:new Headers(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(o){return new pt(this.url,{headers:this.headers,schema:o,fetch:this.fetch})}rpc(o,i={},{head:u=!1,get:l=!1,count:c}={}){var h;let m,d=new URL(`${this.url}/rpc/${o}`),y;u||l?(m=u?"HEAD":"GET",Object.entries(i).filter(([g,v])=>v!==void 0).map(([g,v])=>[g,Array.isArray(v)?`{${v.join(",")}}`:`${v}`]).forEach(([g,v])=>{d.searchParams.append(g,v)})):(m="POST",y=i);let b=new Headers(this.headers);return c&&b.set("Prefer",`count=${c}`),new s.default({method:m,url:d,headers:b,schema:this.schemaName,body:y,fetch:(h=this.fetch)!==null&&h!==void 0?h:fetch})}};e.default=a}),Bt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0}),e.PostgrestError=e.PostgrestBuilder=e.PostgrestTransformBuilder=e.PostgrestFilterBuilder=e.PostgrestQueryBuilder=e.PostgrestClient=void 0;var t=(W(),q(k)),r=t.__importDefault(kt());e.PostgrestClient=r.default;var s=t.__importDefault(ft());e.PostgrestQueryBuilder=s.default;var a=t.__importDefault(ye());e.PostgrestFilterBuilder=a.default;var n=t.__importDefault(ht());e.PostgrestTransformBuilder=n.default;var o=t.__importDefault(ct());e.PostgrestBuilder=o.default;var i=t.__importDefault(ut());e.PostgrestError=i.default,e.default={PostgrestClient:r.default,PostgrestQueryBuilder:s.default,PostgrestFilterBuilder:a.default,PostgrestTransformBuilder:n.default,PostgrestBuilder:o.default,PostgrestError:i.default}});f();f();f();f();f();f();var Mt=Object.defineProperty,Ft=Object.defineProperties,Ht=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,Wt=Object.prototype.propertyIsEnumerable,Te=(e,t,r)=>t in e?Mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,j=(e,t)=>{for(var r in t||(t={}))qt.call(t,r)&&Te(e,r,t[r]);if(Oe)for(var r of Oe(t))Wt.call(t,r)&&Te(e,r,t[r]);return e},I=(e,t)=>Ft(e,Ht(t)),Gt=class extends Error{constructor(e,t,r){super(t||e.toString(),{cause:r}),this.status=e,this.statusText=t,this.error=r}},Kt=async(e,t)=>{var r,s,a,n,o,i;let u=t||{},l={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:u,hooks:l};for(let c of t?.plugins||[]){if(c.init){let h=await((r=c.init)==null?void 0:r.call(c,e.toString(),t));u=h.options||u,e=h.url}l.onRequest.push((s=c.hooks)==null?void 0:s.onRequest),l.onResponse.push((a=c.hooks)==null?void 0:a.onResponse),l.onSuccess.push((n=c.hooks)==null?void 0:n.onSuccess),l.onError.push((o=c.hooks)==null?void 0:o.onError),l.onRetry.push((i=c.hooks)==null?void 0:i.onRetry)}return{url:e,options:u,hooks:l}},Pe=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},zt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function Vt(e){if(typeof e=="number")return new Pe({type:"linear",attempts:e,delay:1e3});switch(e.type){case"linear":return new Pe(e);case"exponential":return new zt(e);default:throw new Error("Invalid retry strategy")}}var Yt=async e=>{let t={},r=async s=>typeof s=="function"?await s():s;if(e?.auth){if(e.auth.type==="Bearer"){let s=await r(e.auth.token);if(!s)return t;t.authorization=`Bearer ${s}`}else if(e.auth.type==="Basic"){let s=r(e.auth.username),a=r(e.auth.password);if(!s||!a)return t;t.authorization=`Basic ${btoa(`${s}:${a}`)}`}else if(e.auth.type==="Custom"){let s=r(e.auth.value);if(!s)return t;t.authorization=`${r(e.auth.prefix)} ${s}`}}return t},Jt=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Xt(e){let t=e.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!t)return"json";let s=t.split(";").shift()||"";return Jt.test(s)?"json":r.has(s)||s.startsWith("text/")?"text":"blob"}function Qt(e){try{return JSON.parse(e),!0}catch{return!1}}function dt(e){if(e===void 0)return!1;let t=typeof e;return t==="string"||t==="number"||t==="boolean"||t===null?!0:t!=="object"?!1:Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name==="Object"||typeof e.toJSON=="function"}function Se(e){try{return JSON.parse(e)}catch{return e}}function Ae(e){return typeof e=="function"}function Zt(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<"u"&&Ae(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&Ae(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function er(e){let t=new Headers(e?.headers),r=await Yt(e);for(let[s,a]of Object.entries(r||{}))t.set(s,a);if(!t.has("content-type")){let s=tr(e?.body);s&&t.set("content-type",s)}return t}function tr(e){return dt(e)?"application/json":null}function rr(e){if(!e?.body)return null;let t=new Headers(e?.headers);if(dt(e.body)&&!t.has("content-type")){for(let[r,s]of Object.entries(e?.body))s instanceof Date&&(e.body[r]=s.toISOString());return JSON.stringify(e.body)}return e.body}function sr(e,t){var r;if(t?.method)return t.method.toUpperCase();if(e.startsWith("@")){let s=(r=e.split("@")[1])==null?void 0:r.split("/")[0];return yt.includes(s)?s.toUpperCase():t?.body?"POST":"GET"}return t?.body?"POST":"GET"}function nr(e,t){let r;return!e?.signal&&e?.timeout&&(r=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var ar=class mt extends Error{constructor(t,r){super(r||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,mt.prototype)}};async function te(e,t){let r=await e["~standard"].validate(t);if(r.issues)throw new ar(r.issues);return r.value}var yt=["get","post","put","patch","delete"],or=e=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(t,r){var s,a,n,o;let i=((a=(s=e.plugins)==null?void 0:s.find(u=>{var l;return(l=u.schema)!=null&&l.config?t.startsWith(u.schema.config.baseURL||"")||t.startsWith(u.schema.config.prefix||""):!1}))==null?void 0:a.schema)||e.schema;if(i){let u=t;(n=i.config)!=null&&n.prefix&&u.startsWith(i.config.prefix)&&(u=u.replace(i.config.prefix,""),i.config.baseURL&&(t=t.replace(i.config.prefix,i.config.baseURL))),(o=i.config)!=null&&o.baseURL&&u.startsWith(i.config.baseURL)&&(u=u.replace(i.config.baseURL,""));let l=i.schema[u];if(l){let c=I(j({},r),{method:l.method,output:l.output});return r?.disableValidation||(c=I(j({},c),{body:l.input?await te(l.input,r?.body):r?.body,params:l.params?await te(l.params,r?.params):r?.params,query:l.query?await te(l.query,r?.query):r?.query})),{url:t,options:c}}}return{url:t,options:r}}}),ir=e=>{async function t(r,s){let a=I(j(j({},e),s),{plugins:[...e?.plugins||[],or(e||{})]});if(e?.catchAllError)try{return await ce(r,a)}catch(n){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:n}}}return await ce(r,a)}return t};function lr(e,t){let{baseURL:r,params:s,query:a}=t||{query:{},params:{},baseURL:""},n=e.startsWith("http")?e.split("/").slice(0,3).join("/"):r||"";if(e.startsWith("@")){let c=e.toString().split("@")[1].split("/")[0];yt.includes(c)&&(e=e.replace(`@${c}/`,"/"))}n.endsWith("/")||(n+="/");let[o,i]=e.replace(n,"").split("?"),u=new URLSearchParams(i);for(let[c,h]of Object.entries(a||{}))h!=null&&u.set(c,String(h));if(s)if(Array.isArray(s)){let c=o.split("/").filter(h=>h.startsWith(":"));for(let[h,m]of c.entries()){let d=s[h];o=o.replace(m,d)}}else for(let[c,h]of Object.entries(s))o=o.replace(`:${c}`,String(h));o=o.split("/").map(encodeURIComponent).join("/"),o.startsWith("/")&&(o=o.slice(1));let l=u.toString();return l=l.length>0?`?${l}`.replace(/\+/g,"%20"):"",n.startsWith("http")?new URL(`${o}${l}`,n):`${n}${o}${l}`}var ce=async(e,t)=>{var r,s,a,n,o,i,u,l;let{hooks:c,url:h,options:m}=await Kt(e,t),d=Zt(m),y=new AbortController,b=(r=m.signal)!=null?r:y.signal,g=lr(h,m),v=rr(m),P=await er(m),S=sr(h,m),p=I(j({},m),{url:g,headers:P,body:v,method:S,signal:b});for(let T of c.onRequest)if(T){let E=await T(p);E instanceof Object&&(p=E)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((s=t?.body)==null?void 0:s.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:C}=nr(m,y),_=await d(p.url,p);C();let _e={response:_,request:p};for(let T of c.onResponse)if(T){let E=await T(I(j({},_e),{response:(a=t?.hookOptions)!=null&&a.cloneResponse?_.clone():_}));E instanceof Response?_=E:E instanceof Object&&(_=E.response)}if(_.ok){if(p.method==="HEAD")return{data:"",error:null};let T=Xt(_),E={data:"",response:_,request:p};if(T==="json"||T==="text"){let B=await _.text(),M=await((n=p.jsonParser)!=null?n:Se)(B);E.data=M}else E.data=await _[T]();p?.output&&p.output&&!p.disableValidation&&(E.data=await te(p.output,E.data));for(let B of c.onSuccess)B&&await B(I(j({},E),{response:(o=t?.hookOptions)!=null&&o.cloneResponse?_.clone():_}));return t?.throw?E.data:{data:E.data,error:null}}let $t=(i=t?.jsonParser)!=null?i:Se,J=await _.text(),Ee=Qt(J),ie=Ee?await $t(J):null,jt={response:_,responseText:J,request:p,error:I(j({},ie),{status:_.status,statusText:_.statusText})};for(let T of c.onError)T&&await T(I(j({},jt),{response:(u=t?.hookOptions)!=null&&u.cloneResponse?_.clone():_}));if(t?.retry){let T=Vt(t.retry),E=(l=t.retryAttempt)!=null?l:0;if(await T.shouldAttemptRetry(E,_)){for(let M of c.onRetry)M&&await M(_e);let B=T.getDelay(E);return await new Promise(M=>setTimeout(M,B)),await ce(e,I(j({},t),{retryAttempt:E+1}))}}if(t?.throw)throw new Gt(_.status,_.statusText,Ee?ie:J);return{data:null,error:I(j({},ie),{status:_.status,statusText:_.statusText})}};f();f();var re=Object.create(null),G=e=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?re:globalThis),R=new Proxy(re,{get(e,t){return G()[t]??re[t]},has(e,t){let r=G();return t in r||t in re},set(e,t,r){let s=G(!0);return s[t]=r,!0},deleteProperty(e,t){if(!t)return!1;let r=G(!0);return delete r[t],!0},ownKeys(){let e=G(!0);return Object.keys(e)}}),ts=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function w(e,t){return typeof process<"u"&&process.env?process.env[e]??t:typeof Deno<"u"?Deno.env.get(e)??t:typeof Bun<"u"?Bun.env[e]??t:t}var rs=Object.freeze({get BETTER_AUTH_SECRET(){return w("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return w("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return w("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return w("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return w("NODE_ENV","development")},get PACKAGE_VERSION(){return w("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return w("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),K=1,O=4,N=8,A=24,Re={eterm:O,cons25:O,console:O,cygwin:O,dtterm:O,gnome:O,hurd:O,jfbterm:O,konsole:O,kterm:O,mlterm:O,mosh:A,putty:O,st:O,"rxvt-unicode-24bit":A,terminator:A,"xterm-kitty":A},ur=new Map(Object.entries({APPVEYOR:N,BUILDKITE:N,CIRCLECI:A,DRONE:N,GITEA_ACTIONS:A,GITHUB_ACTIONS:A,GITLAB_CI:N,TRAVIS:N})),cr=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function hr(){if(w("FORCE_COLOR")!==void 0)switch(w("FORCE_COLOR")){case"":case"1":case"true":return O;case"2":return N;case"3":return A;default:return K}if(w("NODE_DISABLE_COLORS")!==void 0&&w("NODE_DISABLE_COLORS")!==""||w("NO_COLOR")!==void 0&&w("NO_COLOR")!==""||w("TERM")==="dumb")return K;if(w("TMUX"))return A;if("TF_BUILD"in R&&"AGENT_NAME"in R)return O;if("CI"in R){for(let{0:e,1:t}of ur)if(e in R)return t;return w("CI_NAME")==="codeship"?N:K}if("TEAMCITY_VERSION"in R)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(w("TEAMCITY_VERSION"))!==null?O:K;switch(w("TERM_PROGRAM")){case"iTerm.app":return!w("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(w("TERM_PROGRAM_VERSION"))!==null?N:A;case"HyperTerm":case"MacTerm":return A;case"Apple_Terminal":return N}if(w("COLORTERM")==="truecolor"||w("COLORTERM")==="24bit")return A;if(w("TERM")){if(/truecolor/.exec(w("TERM"))!==null)return A;if(/^xterm-256/.exec(w("TERM"))!==null)return N;let e=w("TERM").toLowerCase();if(Re[e])return Re[e];if(cr.some(t=>t.exec(e)!==null))return O}return w("COLORTERM")?O:K}var x={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"}},he=["info","success","warn","error","debug"];function fr(e,t){return he.indexOf(t)<=he.indexOf(e)}var pr={info:x.fg.blue,success:x.fg.green,warn:x.fg.yellow,error:x.fg.red,debug:x.fg.magenta},dr=(e,t,r)=>{let s=new Date().toISOString();return r?`${x.dim}${s}${x.reset} ${pr[e]}${e.toUpperCase()}${x.reset} ${x.bright}[Better Auth]:${x.reset} ${t}`:`${s} ${e.toUpperCase()} [Better Auth]: ${t}`},mr=e=>{let t=e?.disabled!==!0,r=e?.level??"error",s=e?.disableColors!==void 0?!e.disableColors:hr()!==1,a=(n,o,i=[])=>{if(!t||!fr(r,n))return;let u=dr(n,o,s);if(!e||typeof e.log!="function"){n==="error"?console.error(u,...i):n==="warn"?console.warn(u,...i):console.log(u,...i);return}e.log(n==="success"?"info":n,o,...i)};return{...Object.fromEntries(he.map(n=>[n,(...[o,...i])=>a(n,o,i)])),get level(){return r}}},ss=mr();f();f();var ge=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function yr(e){try{return(new URL(e).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new ge(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function z(e,t="/api/auth"){if(yr(e))return e;let r=e.replace(/\/+$/,"");return!t||t==="/"?r:(t=t.startsWith("/")?t:`/${t}`,`${r}${t}`)}function gr(e,t,r,s){if(e)return z(e,t);if(s!==!1){let o=R.BETTER_AUTH_URL||R.NEXT_PUBLIC_BETTER_AUTH_URL||R.PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_AUTH_URL||(R.BASE_URL!=="/"?R.BASE_URL:void 0);if(o)return z(o,t)}let a=r?.headers.get("x-forwarded-host"),n=r?.headers.get("x-forwarded-proto");if(a&&n)return z(`${n}://${a}`,t);if(r){let o=vr(r.url);if(!o)throw new ge("Could not get origin from request. Please provide a valid base URL.");return z(o,t)}if(typeof window<"u"&&window.location)return z(window.location.origin,t)}function vr(e){try{return new URL(e).origin}catch{return null}}f();f();f();var fe=Symbol("clean"),$=[],U=0,X=4,wr=0,gt=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(s){return r.lc=t.push(s),()=>{for(let n=U+X;n<$.length;)$[n]===s?$.splice(n,X):n+=X;let a=t.indexOf(s);~a&&(t.splice(a,1),--r.lc||r.off())}},notify(s,a){wr++;let n=!$.length;for(let o of t)$.push(o,r.value,s,a);if(n){for(U=0;U<$.length;U+=X)$[U]($[U+1],$[U+2],$[U+3]);$.length=0}},off(){},set(s){let a=r.value;a!==s&&(r.value=s,r.notify(a))},subscribe(s){let a=r.listen(s);return s(r.value),a},value:e};return process.env.NODE_ENV!=="production"&&(r[fe]=()=>{t=[],r.lc=0,r.off()}),r};f();var br=5,F=6,Q=10,_r=(e,t,r,s)=>(e.events=e.events||{},e.events[r+Q]||(e.events[r+Q]=s(a=>{e.events[r].reduceRight((n,o)=>(o(n),n),{shared:{},...a})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let a=e.events[r],n=a.indexOf(t);a.splice(n,1),a.length||(delete e.events[r],e.events[r+Q](),delete e.events[r+Q])}),Er=1e3,Or=(e,t)=>_r(e,r=>{let s=t(r);s&&e.events[F].push(s)},br,r=>{let s=e.listen;e.listen=(...n)=>(!e.lc&&!e.active&&(e.active=!0,r()),s(...n));let a=e.off;if(e.events[F]=[],e.off=()=>{a(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let n of e.events[F])n();e.events[F]=[]}},Er)},process.env.NODE_ENV!=="production"){let n=e[fe];e[fe]=()=>{for(let o of e.events[F])o();e.events[F]=[],e.active=!1,n()}}return()=>{e.listen=s,e.off=a}});f();var Tr=typeof window>"u",Pr=(e,t,r,s)=>{let a=gt({data:null,error:null,isPending:!0,isRefetching:!1,refetch:i=>n(i)}),n=i=>{let u=typeof s=="function"?s({data:a.get().data,error:a.get().error,isPending:a.get().isPending}):s;r(t,{...u,query:{...u?.query,...i?.query},async onSuccess(l){a.set({data:l.data,error:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onSuccess?.(l)},async onError(l){let{request:c}=l,h=typeof c.retry=="number"?c.retry:c.retry?.attempts,m=c.retryAttempt||0;h&&m<h||(a.set({error:l.error,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onError?.(l))},async onRequest(l){let c=a.get();a.set({isPending:c.data===null,data:c.data,error:null,isRefetching:!0,refetch:a.value.refetch}),await u?.onRequest?.(l)}}).catch(l=>{a.set({error:l,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch})})};e=Array.isArray(e)?e:[e];let o=!1;for(let i of e)i.subscribe(()=>{Tr||(o?n():Or(a,()=>{let u=setTimeout(()=>{o||(n(),o=!0)},0);return()=>{a.off(),i.off(),clearTimeout(u)}}))});return a};f();var Sr={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*:/},Ar=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,$e={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Rr=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function $r(e){return e instanceof Date&&!isNaN(e.getTime())}function jr(e){let t=Rr.exec(e);if(!t)return null;let[,r,s,a,n,o,i,u,l,c,h]=t,m=new Date(Date.UTC(parseInt(r,10),parseInt(s,10)-1,parseInt(a,10),parseInt(n,10),parseInt(o,10),parseInt(i,10),u?parseInt(u.padEnd(3,"0"),10):0));if(l){let d=(parseInt(c,10)*60+parseInt(h,10))*(l==="+"?-1:1);m.setUTCMinutes(m.getUTCMinutes()+d)}return $r(m)?m:null}function Ir(e,t={}){let{strict:r=!1,warnings:s=!1,reviver:a,parseDates:n=!0}=t;if(typeof e!="string")return e;let o=e.trim();if(o.length>0&&o[0]==='"'&&o.endsWith('"')&&!o.slice(1,-1).includes('"'))return o.slice(1,-1);let i=o.toLowerCase();if(i.length<=9&&i in $e)return $e[i];if(!Ar.test(o)){if(r)throw new SyntaxError("[better-json] Invalid JSON");return e}if(Object.entries(Sr).some(([u,l])=>{let c=l.test(o);return c&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),c})&&r)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(o,(u,l)=>{if(u==="__proto__"||u==="constructor"&&l&&typeof l=="object"&&"prototype"in l){s&&console.warn(`[better-json] Dropping "${u}" key to prevent prototype pollution`);return}if(n&&typeof l=="string"){let c=jr(l);if(c)return c}return a?a(u,l):l})}catch(u){if(r)throw u;return e}}function Nr(e,t={strict:!0}){return Ir(e,t)}var xr={id:"redirect",name:"Redirect",hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}};function Ur(e){let t=gt(!1);return{session:Pr(t,"/get-session",e,{method:"GET"}),$sessionSignal:t}}var Cr=(e,t)=>{let r="credentials"in Request.prototype,s=gr(e?.baseURL,e?.basePath,void 0,t)??"/api/auth",a=e?.plugins?.flatMap(p=>p.fetchPlugins).filter(p=>p!==void 0)||[],n={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:i,onRequest:u,onResponse:l,...c}=e?.fetchOptions||{},h=ir({baseURL:s,...r?{credentials:"include"}:{},method:"GET",jsonParser(p){return p?Nr(p,{strict:!1}):null},customFetchImpl:fetch,...c,plugins:[n,...c.plugins||[],...e?.disableDefaultFetchPlugins?[]:[xr],...a]}),{$sessionSignal:m,session:d}=Ur(h),y=e?.plugins||[],b={},g={$sessionSignal:m,session:d},v={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},P=[{signal:"$sessionSignal",matcher(p){return p==="/sign-out"||p==="/update-user"||p.startsWith("/sign-in")||p.startsWith("/sign-up")||p==="/delete-user"||p==="/verify-email"}}];for(let p of y)p.getAtoms&&Object.assign(g,p.getAtoms?.(h)),p.pathMethods&&Object.assign(v,p.pathMethods),p.atomListeners&&P.push(...p.atomListeners);let S={notify:p=>{g[p].set(!g[p].get())},listen:(p,C)=>{g[p].subscribe(C)},atoms:g};for(let p of y)p.getActions&&Object.assign(b,p.getActions?.(h,S,e));return{get baseURL(){return s},pluginsActions:b,pluginsAtoms:g,pluginPathMethods:v,atomListeners:P,$fetch:h,$store:S}};function Lr(e){return typeof e=="object"&&e!==null&&"get"in e&&typeof e.get=="function"&&"lc"in e&&typeof e.lc=="number"}function Dr(e,t,r){let s=t[e],{fetchOptions:a,query:n,...o}=r||{};return s||(a?.method?a.method:o&&Object.keys(o).length>0?"POST":"GET")}function kr(e,t,r,s,a){function n(o=[]){return new Proxy(function(){},{get(i,u){if(typeof u!="string"||u==="then"||u==="catch"||u==="finally")return;let l=[...o,u],c=e;for(let h of l)if(c&&typeof c=="object"&&h in c)c=c[h];else{c=void 0;break}return typeof c=="function"||Lr(c)?c:n(l)},apply:async(i,u,l)=>{let c="/"+o.map(P=>P.replace(/[A-Z]/g,S=>`-${S.toLowerCase()}`)).join("/"),h=l[0]||{},m=l[1]||{},{query:d,fetchOptions:y,...b}=h,g={...m,...y},v=Dr(c,r,h);return await t(c,{...g,body:v==="GET"?void 0:{...b,...g?.body||{}},query:d||g?.query,method:v,async onSuccess(P){if(await g?.onSuccess?.(P),!a)return;let S=a.filter(p=>p.matcher(c));if(S.length)for(let p of S){let C=s[p.signal];if(!C)return;let _=C.get();setTimeout(()=>{C.set(!_)},10)}}})}})}return n()}f();function Br(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Mr(e){let{pluginPathMethods:t,pluginsActions:r,pluginsAtoms:s,$fetch:a,atomListeners:n,$store:o}=Cr(e),i={};for(let[l,c]of Object.entries(s))i[`use${Br(l)}`]=c;let u={...r,...i,$fetch:a,$store:o};return kr(u,a,t,s,n)}f();f();f();function Fr(e){return{authorize(t,r="AND"){let s=!1;for(let[a,n]of Object.entries(t)){let o=e[a];if(!o)return{success:!1,error:`You are not allowed to access resource: ${a}`};if(Array.isArray(n))s=n.every(i=>o.includes(i));else if(typeof n=="object"){let i=n;i.connector==="OR"?s=i.actions.some(u=>o.includes(u)):s=i.actions.every(u=>o.includes(u))}else throw new ge("Invalid access control request");if(s&&r==="OR")return{success:s};if(!s&&r==="AND")return{success:!1,error:`unauthorized to access resource "${a}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:e}}function vt(e){return{newRole(t){return Fr(t)},statements:e}}var Hr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},ve=vt(Hr),ns=ve.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),as=ve.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),os=ve.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});f();f();f();f();f();f();f();f();f();f();f();var qr=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}}},is=new qr;f();f();f();f();f();f();f();f();var Wr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},wt=vt(Wr),ls=wt.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),us=wt.newRole({user:[],session:[]});f();f();var Gr=()=>({id:"username",$InferServerPlugin:{}}),Kr=()=>({id:"phoneNumber",$InferServerPlugin:{},atomListeners:[{matcher(e){return e==="/phone-number/update"||e==="/phone-number/verify"},signal:"$sessionSignal"}]}),zr=()=>({id:"better-auth-client",$InferServerPlugin:{}}),Vr="/auth",le="nvwa_login_token",se="nvwa_current_jwt",ue="nvwa_user_profile",bt=class{constructor(e,t,r){this.storage=r;let s=Mr({baseURL:e,basePath:Vr,plugins:[Gr(),Kr(),zr()],fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:async()=>{let a=await this.storage.get(se);if(console.log("jwt",a),a)return a;let n=await this.storage.get(le);return console.log("loginToken",n),n}}}});this.authClient=s}async currentUser(){return await this.storage.get(ue)}async getCurrentJwt(){return await this.storage.get(se)}async signUp(e){let t=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:e.password});this.handleLogin(t)}async sendPhoneNumberCode(e){await this.authClient.phoneNumber.sendOtp({phoneNumber:e})}async signInWithPhoneNumberCode(e,t){let r=await this.authClient.phoneNumber.verify({phoneNumber:e,code:t});this.handleLogin(r)}async signInWithPhoneNumber(e,t,r=!1){let s=await this.authClient.signIn.phoneNumber({phoneNumber:e,password:t,rememberMe:r});this.handleLogin(s)}async signInWithUsername(e,t){let r=await this.authClient.signIn.username({username:e,password:t});this.handleLogin(r)}async handleLogin(e){if(e.error)throw new Error(e.error.message);await this.storage.set(le,e.data?.token),await this.storage.set(ue,e.data?.user);let{data:t,error:r}=await this.authClient.token();if(r)throw new Error(r.message);await this.storage.set(se,t.token)}async signOut(){await this.storage.remove(le),await this.storage.remove(ue)}async updateUserPassword(e,t,r=!1){let s=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:r});this.handleLogin(s)}};f();var _t=class{constructor(e){this.http=e}async invoke(e,t){return await(await this.http.fetch("/functions/"+e,{method:t.method||"POST",body:t.body,headers:t.headers})).json()}};f();f();f();var L=class Et{constructor(t){if(this.headerMap=new Map,t){if(t instanceof Et)t.forEach((r,s)=>this.set(s,r));else if(Array.isArray(t))for(let[r,s]of t)this.set(r,String(s));else if(typeof t=="object")for(let r of Object.keys(t))this.set(r,String(t[r]))}}append(t,r){let s=t.toLowerCase(),a=this.headerMap.get(s);this.headerMap.set(s,a?`${a}, ${r}`:r)}set(t,r){this.headerMap.set(t.toLowerCase(),String(r))}get(t){return this.headerMap.get(t.toLowerCase())??null}has(t){return this.headerMap.has(t.toLowerCase())}delete(t){this.headerMap.delete(t.toLowerCase())}forEach(t){for(let[r,s]of this.headerMap.entries())t(s,r,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}};f();f();var Ot=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=Yr(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 Yr(e){return e?new L(e):new L}f();f();var Tt=class{constructor(e,t,r){console.log("NvwaHttpClient constructor",e,t,r),this.storage=e,this.customFetch=t,this.handleUnauthorized=r}async fetch(e,t){return await this.customFetch(e,t)}async fetchWithAuth(e,t){let r=await this.storage.get(se),s=new L(t?.headers);r&&s.set("Authorization",`Bearer ${r}`);let a=await this.customFetch(e,{...t,headers:s});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};f();var Jr="/storage",Xr=Jr+"/generateUploadUrl",Pt=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.fetch(this.baseUrl+Xr,{method:"POST",body:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:r}=await t.json();if(!r)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let s=await this.http.fetch(r,{method:"PUT",body:e,headers:new L({"Content-Type":e.type||e.fileType||"application/octet-stream"})}),{url:a}=await s.json();return{url:a.split("?")[0]}}};f();f();f();var je=Dt(Bt(),1),{PostgrestClient:Qr,PostgrestQueryBuilder:cs,PostgrestFilterBuilder:hs,PostgrestTransformBuilder:fs,PostgrestBuilder:ps,PostgrestError:ds}=je.default||je,Zr="/entities",St=(e,t)=>new Qr(e+Zr,{fetch:t.fetchWithAuth.bind(t)});f();var At=class{constructor(e,t){this.baseUrl=e,this.http=t}async execute(e,t){let r=`${this.baseUrl}/skill/${e}/execute`;return await(await this.http.fetchWithAuth(r,{method:"POST",body:t})).json()}};var oe=class{constructor(){this.prefix="nvwa_"}getKey(t){return`${this.prefix}${t}`}async get(t){try{let r=this.getKey(t),s=localStorage.getItem(r);if(!s)return null;let a=JSON.parse(s);return a.expires&&Date.now()>a.expires?(await this.remove(t),null):a.value}catch(r){return console.error("WebStorageService get error:",r),null}}async set(t,r,s){try{let a=this.getKey(t),n={value:r,expires:s?Date.now()+s*1e3:null,timestamp:Date.now()};localStorage.setItem(a,JSON.stringify(n))}catch(a){throw console.error("WebStorageService set error:",a),a}}async remove(t){try{let r=this.getKey(t);localStorage.removeItem(r)}catch(r){throw console.error("WebStorageService remove error:",r),r}}async clear(){try{Object.keys(localStorage).filter(s=>s.startsWith(this.prefix)).forEach(s=>{localStorage.removeItem(s)})}catch(t){throw console.error("WebStorageService clear error:",t),t}}};var es=(e,t)=>{let r;if(typeof e=="string")r=e;else if(e&&typeof e.toString=="function")r=e.toString();else if(e?.url)r=e.url;else throw new Error("Invalid input for webFetch");let s;if(t?.headers){let n=t.headers;if(n instanceof L){let o={};n.forEach((i,u)=>{o[u]=i}),s=o}else if(Array.isArray(n)){let o=[];for(let i of n)Array.isArray(i)&&i.length>=2&&o.push([String(i[0]),String(i[1])]);s=o}else typeof n=="object"&&(s=n)}let a={method:t?.method||"GET",headers:s,body:t?.body};return t?.signal&&(a.signal=t.signal),globalThis.fetch(r,a).then(async n=>{let o=n.headers.get("content-type")||"",i;if(o.includes("application/json"))i=await n.json();else{let l=await n.text();try{i=JSON.parse(l)}catch{i=l}}let u=new L;return n.headers.forEach((l,c)=>{u.set(c,l)}),new Ot(i,{status:n.status,statusText:n.statusText,headers:u})})},we=es;var Rt=new oe,be=class{constructor(t,r){this.auth=new bt(t,we,Rt),this.httpClient=new Tt(Rt,we,r),this.fileStorage=new Pt(t,this.httpClient),this.entities=St(t,this.httpClient),this.functions=new _t(this.httpClient),this.skill=new At(t,this.httpClient)}};export{be as default,Rt as localStorage};
1
+ var It=Object.create,ae=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,xt=Object.getOwnPropertyNames,Ut=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty,Ie=(e,t)=>()=>(e&&(t=e(e=0)),t),D=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Lt=(e,t)=>{for(var r in t)ae(e,r,{get:t[r],enumerable:!0})},Ne=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of xt(t))!Ct.call(e,a)&&a!==r&&ae(e,a,{get:()=>t[a],enumerable:!(s=Nt(t,a))||s.enumerable});return e},Dt=(e,t,r)=>(r=e!=null?It(Ut(e)):{},Ne(t||!e||!e.__esModule?ae(r,"default",{value:e,enumerable:!0}):r,e)),q=e=>Ne(ae({},"__esModule",{value:!0}),e),f=Ie(()=>{"use strict"}),k={};Lt(k,{__addDisposableResource:()=>st,__assign:()=>V,__asyncDelegator:()=>Ye,__asyncGenerator:()=>Ve,__asyncValues:()=>Je,__await:()=>H,__awaiter:()=>He,__classPrivateFieldGet:()=>et,__classPrivateFieldIn:()=>rt,__classPrivateFieldSet:()=>tt,__createBinding:()=>Y,__decorate:()=>Ce,__disposeResources:()=>nt,__esDecorate:()=>De,__exportStar:()=>We,__extends:()=>xe,__generator:()=>qe,__importDefault:()=>Ze,__importStar:()=>Qe,__makeTemplateObject:()=>Xe,__metadata:()=>Fe,__param:()=>Le,__propKey:()=>Be,__read:()=>me,__rest:()=>Ue,__rewriteRelativeImportExtension:()=>at,__runInitializers:()=>ke,__setFunctionName:()=>Me,__spread:()=>Ge,__spreadArray:()=>ze,__spreadArrays:()=>Ke,__values:()=>ne,default:()=>lt});function xe(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Z(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}function Ue(e,t){var r={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(r[s]=e[s]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,s=Object.getOwnPropertySymbols(e);a<s.length;a++)t.indexOf(s[a])<0&&Object.prototype.propertyIsEnumerable.call(e,s[a])&&(r[s[a]]=e[s[a]]);return r}function Ce(e,t,r,s){var a=arguments.length,n=a<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,r):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(e,t,r,s);else for(var i=e.length-1;i>=0;i--)(o=e[i])&&(n=(a<3?o(n):a>3?o(t,r,n):o(t,r))||n);return a>3&&n&&Object.defineProperty(t,r,n),n}function Le(e,t){return function(r,s){t(r,s,e)}}function De(e,t,r,s,a,n){function o(w){if(w!==void 0&&typeof w!="function")throw new TypeError("Function expected");return w}for(var i=s.kind,u=i==="getter"?"get":i==="setter"?"set":"value",l=!t&&e?s.static?e:e.prototype:null,c=t||(l?Object.getOwnPropertyDescriptor(l,s.name):{}),h,m=!1,d=r.length-1;d>=0;d--){var y={};for(var b in s)y[b]=b==="access"?{}:s[b];for(var b in s.access)y.access[b]=s.access[b];y.addInitializer=function(w){if(m)throw new TypeError("Cannot add initializers after decoration has completed");n.push(o(w||null))};var g=(0,r[d])(i==="accessor"?{get:c.get,set:c.set}:c[u],y);if(i==="accessor"){if(g===void 0)continue;if(g===null||typeof g!="object")throw new TypeError("Object expected");(h=o(g.get))&&(c.get=h),(h=o(g.set))&&(c.set=h),(h=o(g.init))&&a.unshift(h)}else(h=o(g))&&(i==="field"?a.unshift(h):c[u]=h)}l&&Object.defineProperty(l,s.name,c),m=!0}function ke(e,t,r){for(var s=arguments.length>2,a=0;a<t.length;a++)r=s?t[a].call(e,r):t[a].call(e);return s?r:void 0}function Be(e){return typeof e=="symbol"?e:"".concat(e)}function Me(e,t,r){return typeof t=="symbol"&&(t=t.description?"[".concat(t.description,"]"):""),Object.defineProperty(e,"name",{configurable:!0,value:r?"".concat(r," ",t):t})}function Fe(e,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(e,t)}function He(e,t,r,s){function a(n){return n instanceof r?n:new r(function(o){o(n)})}return new(r||(r=Promise))(function(n,o){function i(c){try{l(s.next(c))}catch(h){o(h)}}function u(c){try{l(s.throw(c))}catch(h){o(h)}}function l(c){c.done?n(c.value):a(c.value).then(i,u)}l((s=s.apply(e,t||[])).next())})}function qe(e,t){var r={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},s,a,n,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=i(0),o.throw=i(1),o.return=i(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function i(l){return function(c){return u([l,c])}}function u(l){if(s)throw new TypeError("Generator is already executing.");for(;o&&(o=0,l[0]&&(r=0)),r;)try{if(s=1,a&&(n=l[0]&2?a.return:l[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,l[1])).done)return n;switch(a=0,n&&(l=[l[0]&2,n.value]),l[0]){case 0:case 1:n=l;break;case 4:return r.label++,{value:l[1],done:!1};case 5:r.label++,a=l[1],l=[0];continue;case 7:l=r.ops.pop(),r.trys.pop();continue;default:if(n=r.trys,!(n=n.length>0&&n[n.length-1])&&(l[0]===6||l[0]===2)){r=0;continue}if(l[0]===3&&(!n||l[1]>n[0]&&l[1]<n[3])){r.label=l[1];break}if(l[0]===6&&r.label<n[1]){r.label=n[1],n=l;break}if(n&&r.label<n[2]){r.label=n[2],r.ops.push(l);break}n[2]&&r.ops.pop(),r.trys.pop();continue}l=t.call(e,r)}catch(c){l=[6,c],a=0}finally{s=n=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}function We(e,t){for(var r in e)r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r)&&Y(t,e,r)}function ne(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],s=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&s>=e.length&&(e=void 0),{value:e&&e[s++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function me(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var s=r.call(e),a,n=[],o;try{for(;(t===void 0||t-- >0)&&!(a=s.next()).done;)n.push(a.value)}catch(i){o={error:i}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return n}function Ge(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(me(arguments[t]));return e}function Ke(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;for(var s=Array(e),a=0,t=0;t<r;t++)for(var n=arguments[t],o=0,i=n.length;o<i;o++,a++)s[a]=n[o];return s}function ze(e,t,r){if(r||arguments.length===2)for(var s=0,a=t.length,n;s<a;s++)(n||!(s in t))&&(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}function H(e){return this instanceof H?(this.v=e,this):new H(e)}function Ve(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=r.apply(e,t||[]),a,n=[];return a=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),i("next"),i("throw"),i("return",o),a[Symbol.asyncIterator]=function(){return this},a;function o(d){return function(y){return Promise.resolve(y).then(d,h)}}function i(d,y){s[d]&&(a[d]=function(b){return new Promise(function(g,w){n.push([d,b,g,w])>1||u(d,b)})},y&&(a[d]=y(a[d])))}function u(d,y){try{l(s[d](y))}catch(b){m(n[0][3],b)}}function l(d){d.value instanceof H?Promise.resolve(d.value.v).then(c,h):m(n[0][2],d)}function c(d){u("next",d)}function h(d){u("throw",d)}function m(d,y){d(y),n.shift(),n.length&&u(n[0][0],n[0][1])}}function Ye(e){var t,r;return t={},s("next"),s("throw",function(a){throw a}),s("return"),t[Symbol.iterator]=function(){return this},t;function s(a,n){t[a]=e[a]?function(o){return(r=!r)?{value:H(e[a](o)),done:!1}:n?n(o):o}:n}}function Je(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof ne=="function"?ne(e):e[Symbol.iterator](),r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r);function s(n){r[n]=e[n]&&function(o){return new Promise(function(i,u){o=e[n](o),a(i,u,o.done,o.value)})}}function a(n,o,i,u){Promise.resolve(u).then(function(l){n({value:l,done:i})},o)}}function Xe(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function Qe(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r=ee(e),s=0;s<r.length;s++)r[s]!=="default"&&Y(t,e,r[s]);return ot(t,e),t}function Ze(e){return e&&e.__esModule?e:{default:e}}function et(e,t,r,s){if(r==="a"&&!s)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?s:r==="a"?s.call(e):s?s.value:t.get(e)}function tt(e,t,r,s,a){if(s==="m")throw new TypeError("Private method is not writable");if(s==="a"&&!a)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return s==="a"?a.call(e,r):a?a.value=r:t.set(e,r),r}function rt(e,t){if(t===null||typeof t!="object"&&typeof t!="function")throw new TypeError("Cannot use 'in' operator on non-object");return typeof e=="function"?t===e:e.has(t)}function st(e,t,r){if(t!=null){if(typeof t!="object"&&typeof t!="function")throw new TypeError("Object expected.");var s,a;if(r){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");s=t[Symbol.asyncDispose]}if(s===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");s=t[Symbol.dispose],r&&(a=s)}if(typeof s!="function")throw new TypeError("Object not disposable.");a&&(s=function(){try{a.call(this)}catch(n){return Promise.reject(n)}}),e.stack.push({value:t,dispose:s,async:r})}else r&&e.stack.push({async:!0});return t}function nt(e){function t(n){e.error=e.hasError?new it(n,e.error,"An error was suppressed during disposal."):n,e.hasError=!0}var r,s=0;function a(){for(;r=e.stack.pop();)try{if(!r.async&&s===1)return s=0,e.stack.push(r),Promise.resolve().then(a);if(r.dispose){var n=r.dispose.call(r.value);if(r.async)return s|=2,Promise.resolve(n).then(a,function(o){return t(o),a()})}else s|=1}catch(o){t(o)}if(s===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return a()}function at(e,t){return typeof e=="string"&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(r,s,a,n,o){return s?t?".jsx":".js":a&&(!n||!o)?r:a+n+"."+o.toLowerCase()+"js"}):e}var Z,V,Y,ot,ee,it,lt,W=Ie(()=>{"use strict";f(),Z=function(e,t){return Z=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,s){r.__proto__=s}||function(r,s){for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(r[a]=s[a])},Z(e,t)},V=function(){return V=Object.assign||function(e){for(var t,r=1,s=arguments.length;r<s;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},V.apply(this,arguments)},Y=Object.create?(function(e,t,r,s){s===void 0&&(s=r);var a=Object.getOwnPropertyDescriptor(t,r);(!a||("get"in a?!t.__esModule:a.writable||a.configurable))&&(a={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,s,a)}):(function(e,t,r,s){s===void 0&&(s=r),e[s]=t[r]}),ot=Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t},ee=function(e){return ee=Object.getOwnPropertyNames||function(t){var r=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(r[r.length]=s);return r},ee(e)},it=typeof SuppressedError=="function"?SuppressedError:function(e,t,r){var s=new Error(r);return s.name="SuppressedError",s.error=e,s.suppressed=t,s},lt={__extends:xe,__assign:V,__rest:Ue,__decorate:Ce,__param:Le,__esDecorate:De,__runInitializers:ke,__propKey:Be,__setFunctionName:Me,__metadata:Fe,__awaiter:He,__generator:qe,__createBinding:Y,__exportStar:We,__values:ne,__read:me,__spread:Ge,__spreadArrays:Ke,__spreadArray:ze,__await:H,__asyncGenerator:Ve,__asyncDelegator:Ye,__asyncValues:Je,__makeTemplateObject:Xe,__importStar:Qe,__importDefault:Ze,__classPrivateFieldGet:et,__classPrivateFieldSet:tt,__classPrivateFieldIn:rt,__addDisposableResource:st,__disposeResources:nt,__rewriteRelativeImportExtension:at}}),ut=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=class extends Error{constructor(r){super(r.message),this.name="PostgrestError",this.details=r.details,this.hint=r.hint,this.code=r.code}};e.default=t}),ct=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ut()),s=class{constructor(a){var n,o;this.shouldThrowOnError=!1,this.method=a.method,this.url=a.url,this.headers=new Headers(a.headers),this.schema=a.schema,this.body=a.body,this.shouldThrowOnError=(n=a.shouldThrowOnError)!==null&&n!==void 0?n:!1,this.signal=a.signal,this.isMaybeSingle=(o=a.isMaybeSingle)!==null&&o!==void 0?o:!1,a.fetch?this.fetch=a.fetch:this.fetch=fetch}throwOnError(){return this.shouldThrowOnError=!0,this}setHeader(a,n){return this.headers=new Headers(this.headers),this.headers.set(a,n),this}then(a,n){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 o=this.fetch,i=o(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async u=>{var l,c,h,m;let d=null,y=null,b=null,g=u.status,w=u.statusText;if(u.ok){if(this.method!=="HEAD"){let p=await u.text();p===""||(this.headers.get("Accept")==="text/csv"||this.headers.get("Accept")&&!((l=this.headers.get("Accept"))===null||l===void 0)&&l.includes("application/vnd.pgrst.plan+text")?y=p:y=JSON.parse(p))}let P=(c=this.headers.get("Prefer"))===null||c===void 0?void 0:c.match(/count=(exact|planned|estimated)/),S=(h=u.headers.get("content-range"))===null||h===void 0?void 0:h.split("/");P&&S&&S.length>1&&(b=parseInt(S[1])),this.isMaybeSingle&&this.method==="GET"&&Array.isArray(y)&&(y.length>1?(d={code:"PGRST116",details:`Results contain ${y.length} rows, application/vnd.pgrst.object+json requires 1 row`,hint:null,message:"JSON object requested, multiple (or no) rows returned"},y=null,b=null,g=406,w="Not Acceptable"):y.length===1?y=y[0]:y=null)}else{let P=await u.text();try{d=JSON.parse(P),Array.isArray(d)&&u.status===404&&(y=[],d=null,g=200,w="OK")}catch{u.status===404&&P===""?(g=204,w="No Content"):d={message:P}}if(d&&this.isMaybeSingle&&!((m=d?.details)===null||m===void 0)&&m.includes("0 rows")&&(d=null,g=200,w="OK"),d&&this.shouldThrowOnError)throw new r.default(d)}return{error:d,data:y,count:b,status:g,statusText:w}});return this.shouldThrowOnError||(i=i.catch(u=>{var l,c,h;return{error:{message:`${(l=u?.name)!==null&&l!==void 0?l:"FetchError"}: ${u?.message}`,details:`${(c=u?.stack)!==null&&c!==void 0?c:""}`,hint:"",code:`${(h=u?.code)!==null&&h!==void 0?h:""}`},data:null,count:null,status:0,statusText:""}})),i.then(a,n)}returns(){return this}overrideTypes(){return this}};e.default=s}),ht=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ct()),s=class extends r.default{select(a){let n=!1,o=(a??"*").split("").map(i=>/\s/.test(i)&&!n?"":(i==='"'&&(n=!n),i)).join("");return this.url.searchParams.set("select",o),this.headers.append("Prefer","return=representation"),this}order(a,{ascending:n=!0,nullsFirst:o,foreignTable:i,referencedTable:u=i}={}){let l=u?`${u}.order`:"order",c=this.url.searchParams.get(l);return this.url.searchParams.set(l,`${c?`${c},`:""}${a}.${n?"asc":"desc"}${o===void 0?"":o?".nullsfirst":".nullslast"}`),this}limit(a,{foreignTable:n,referencedTable:o=n}={}){let i=typeof o>"u"?"limit":`${o}.limit`;return this.url.searchParams.set(i,`${a}`),this}range(a,n,{foreignTable:o,referencedTable:i=o}={}){let u=typeof i>"u"?"offset":`${i}.offset`,l=typeof i>"u"?"limit":`${i}.limit`;return this.url.searchParams.set(u,`${a}`),this.url.searchParams.set(l,`${n-a+1}`),this}abortSignal(a){return this.signal=a,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:a=!1,verbose:n=!1,settings:o=!1,buffers:i=!1,wal:u=!1,format:l="text"}={}){var c;let h=[a?"analyze":null,n?"verbose":null,o?"settings":null,i?"buffers":null,u?"wal":null].filter(Boolean).join("|"),m=(c=this.headers.get("Accept"))!==null&&c!==void 0?c:"application/json";return this.headers.set("Accept",`application/vnd.pgrst.plan+${l}; for="${m}"; options=${h};`),l==="json"?this:this}rollback(){return this.headers.append("Prefer","tx=rollback"),this}returns(){return this}maxAffected(a){return this.headers.append("Prefer","handling=strict"),this.headers.append("Prefer",`max-affected=${a}`),this}};e.default=s}),ye=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ht()),s=new RegExp("[,()]"),a=class extends r.default{eq(n,o){return this.url.searchParams.append(n,`eq.${o}`),this}neq(n,o){return this.url.searchParams.append(n,`neq.${o}`),this}gt(n,o){return this.url.searchParams.append(n,`gt.${o}`),this}gte(n,o){return this.url.searchParams.append(n,`gte.${o}`),this}lt(n,o){return this.url.searchParams.append(n,`lt.${o}`),this}lte(n,o){return this.url.searchParams.append(n,`lte.${o}`),this}like(n,o){return this.url.searchParams.append(n,`like.${o}`),this}likeAllOf(n,o){return this.url.searchParams.append(n,`like(all).{${o.join(",")}}`),this}likeAnyOf(n,o){return this.url.searchParams.append(n,`like(any).{${o.join(",")}}`),this}ilike(n,o){return this.url.searchParams.append(n,`ilike.${o}`),this}ilikeAllOf(n,o){return this.url.searchParams.append(n,`ilike(all).{${o.join(",")}}`),this}ilikeAnyOf(n,o){return this.url.searchParams.append(n,`ilike(any).{${o.join(",")}}`),this}is(n,o){return this.url.searchParams.append(n,`is.${o}`),this}in(n,o){let i=Array.from(new Set(o)).map(u=>typeof u=="string"&&s.test(u)?`"${u}"`:`${u}`).join(",");return this.url.searchParams.append(n,`in.(${i})`),this}contains(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cs.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cs.{${o.join(",")}}`):this.url.searchParams.append(n,`cs.${JSON.stringify(o)}`),this}containedBy(n,o){return typeof o=="string"?this.url.searchParams.append(n,`cd.${o}`):Array.isArray(o)?this.url.searchParams.append(n,`cd.{${o.join(",")}}`):this.url.searchParams.append(n,`cd.${JSON.stringify(o)}`),this}rangeGt(n,o){return this.url.searchParams.append(n,`sr.${o}`),this}rangeGte(n,o){return this.url.searchParams.append(n,`nxl.${o}`),this}rangeLt(n,o){return this.url.searchParams.append(n,`sl.${o}`),this}rangeLte(n,o){return this.url.searchParams.append(n,`nxr.${o}`),this}rangeAdjacent(n,o){return this.url.searchParams.append(n,`adj.${o}`),this}overlaps(n,o){return typeof o=="string"?this.url.searchParams.append(n,`ov.${o}`):this.url.searchParams.append(n,`ov.{${o.join(",")}}`),this}textSearch(n,o,{config:i,type:u}={}){let l="";u==="plain"?l="pl":u==="phrase"?l="ph":u==="websearch"&&(l="w");let c=i===void 0?"":`(${i})`;return this.url.searchParams.append(n,`${l}fts${c}.${o}`),this}match(n){return Object.entries(n).forEach(([o,i])=>{this.url.searchParams.append(o,`eq.${i}`)}),this}not(n,o,i){return this.url.searchParams.append(n,`not.${o}.${i}`),this}or(n,{foreignTable:o,referencedTable:i=o}={}){let u=i?`${i}.or`:"or";return this.url.searchParams.append(u,`(${n})`),this}filter(n,o,i){return this.url.searchParams.append(n,`${o}.${i}`),this}};e.default=a}),ft=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ye()),s=class{constructor(a,{headers:n={},schema:o,fetch:i}){this.url=a,this.headers=new Headers(n),this.schema=o,this.fetch=i}select(a,n){let{head:o=!1,count:i}=n??{},u=o?"HEAD":"GET",l=!1,c=(a??"*").split("").map(h=>/\s/.test(h)&&!l?"":(h==='"'&&(l=!l),h)).join("");return this.url.searchParams.set("select",c),i&&this.headers.append("Prefer",`count=${i}`),new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch})}insert(a,{count:n,defaultToNull:o=!0}={}){var i;let u="POST";if(n&&this.headers.append("Prefer",`count=${n}`),o||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let l=a.reduce((c,h)=>c.concat(Object.keys(h)),[]);if(l.length>0){let c=[...new Set(l)].map(h=>`"${h}"`);this.url.searchParams.set("columns",c.join(","))}}return new r.default({method:u,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(i=this.fetch)!==null&&i!==void 0?i:fetch})}upsert(a,{onConflict:n,ignoreDuplicates:o=!1,count:i,defaultToNull:u=!0}={}){var l;let c="POST";if(this.headers.append("Prefer",`resolution=${o?"ignore":"merge"}-duplicates`),n!==void 0&&this.url.searchParams.set("on_conflict",n),i&&this.headers.append("Prefer",`count=${i}`),u||this.headers.append("Prefer","missing=default"),Array.isArray(a)){let h=a.reduce((m,d)=>m.concat(Object.keys(d)),[]);if(h.length>0){let m=[...new Set(h)].map(d=>`"${d}"`);this.url.searchParams.set("columns",m.join(","))}}return new r.default({method:c,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(l=this.fetch)!==null&&l!==void 0?l:fetch})}update(a,{count:n}={}){var o;let i="PATCH";return n&&this.headers.append("Prefer",`count=${n}`),new r.default({method:i,url:this.url,headers:this.headers,schema:this.schema,body:a,fetch:(o=this.fetch)!==null&&o!==void 0?o:fetch})}delete({count:a}={}){var n;let o="DELETE";return a&&this.headers.append("Prefer",`count=${a}`),new r.default({method:o,url:this.url,headers:this.headers,schema:this.schema,fetch:(n=this.fetch)!==null&&n!==void 0?n:fetch})}};e.default=s}),kt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0});var t=(W(),q(k)),r=t.__importDefault(ft()),s=t.__importDefault(ye()),a=class pt{constructor(o,{headers:i={},schema:u,fetch:l}={}){this.url=o,this.headers=new Headers(i),this.schemaName=u,this.fetch=l}from(o){let i=new URL(`${this.url}/${o}`);return new r.default(i,{headers:new Headers(this.headers),schema:this.schemaName,fetch:this.fetch})}schema(o){return new pt(this.url,{headers:this.headers,schema:o,fetch:this.fetch})}rpc(o,i={},{head:u=!1,get:l=!1,count:c}={}){var h;let m,d=new URL(`${this.url}/rpc/${o}`),y;u||l?(m=u?"HEAD":"GET",Object.entries(i).filter(([g,w])=>w!==void 0).map(([g,w])=>[g,Array.isArray(w)?`{${w.join(",")}}`:`${w}`]).forEach(([g,w])=>{d.searchParams.append(g,w)})):(m="POST",y=i);let b=new Headers(this.headers);return c&&b.set("Prefer",`count=${c}`),new s.default({method:m,url:d,headers:b,schema:this.schemaName,body:y,fetch:(h=this.fetch)!==null&&h!==void 0?h:fetch})}};e.default=a}),Bt=D(e=>{"use strict";f(),Object.defineProperty(e,"__esModule",{value:!0}),e.PostgrestError=e.PostgrestBuilder=e.PostgrestTransformBuilder=e.PostgrestFilterBuilder=e.PostgrestQueryBuilder=e.PostgrestClient=void 0;var t=(W(),q(k)),r=t.__importDefault(kt());e.PostgrestClient=r.default;var s=t.__importDefault(ft());e.PostgrestQueryBuilder=s.default;var a=t.__importDefault(ye());e.PostgrestFilterBuilder=a.default;var n=t.__importDefault(ht());e.PostgrestTransformBuilder=n.default;var o=t.__importDefault(ct());e.PostgrestBuilder=o.default;var i=t.__importDefault(ut());e.PostgrestError=i.default,e.default={PostgrestClient:r.default,PostgrestQueryBuilder:s.default,PostgrestFilterBuilder:a.default,PostgrestTransformBuilder:n.default,PostgrestBuilder:o.default,PostgrestError:i.default}});f();f();f();f();f();f();var Mt=Object.defineProperty,Ft=Object.defineProperties,Ht=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertySymbols,qt=Object.prototype.hasOwnProperty,Wt=Object.prototype.propertyIsEnumerable,Te=(e,t,r)=>t in e?Mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,j=(e,t)=>{for(var r in t||(t={}))qt.call(t,r)&&Te(e,r,t[r]);if(Oe)for(var r of Oe(t))Wt.call(t,r)&&Te(e,r,t[r]);return e},I=(e,t)=>Ft(e,Ht(t)),Gt=class extends Error{constructor(e,t,r){super(t||e.toString(),{cause:r}),this.status=e,this.statusText=t,this.error=r}},Kt=async(e,t)=>{var r,s,a,n,o,i;let u=t||{},l={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:u,hooks:l};for(let c of t?.plugins||[]){if(c.init){let h=await((r=c.init)==null?void 0:r.call(c,e.toString(),t));u=h.options||u,e=h.url}l.onRequest.push((s=c.hooks)==null?void 0:s.onRequest),l.onResponse.push((a=c.hooks)==null?void 0:a.onResponse),l.onSuccess.push((n=c.hooks)==null?void 0:n.onSuccess),l.onError.push((o=c.hooks)==null?void 0:o.onError),l.onRetry.push((i=c.hooks)==null?void 0:i.onRetry)}return{url:e,options:u,hooks:l}},Pe=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},zt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function Vt(e){if(typeof e=="number")return new Pe({type:"linear",attempts:e,delay:1e3});switch(e.type){case"linear":return new Pe(e);case"exponential":return new zt(e);default:throw new Error("Invalid retry strategy")}}var Yt=async e=>{let t={},r=async s=>typeof s=="function"?await s():s;if(e?.auth){if(e.auth.type==="Bearer"){let s=await r(e.auth.token);if(!s)return t;t.authorization=`Bearer ${s}`}else if(e.auth.type==="Basic"){let s=r(e.auth.username),a=r(e.auth.password);if(!s||!a)return t;t.authorization=`Basic ${btoa(`${s}:${a}`)}`}else if(e.auth.type==="Custom"){let s=r(e.auth.value);if(!s)return t;t.authorization=`${r(e.auth.prefix)} ${s}`}}return t},Jt=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function Xt(e){let t=e.headers.get("content-type"),r=new Set(["image/svg","application/xml","application/xhtml","application/html"]);if(!t)return"json";let s=t.split(";").shift()||"";return Jt.test(s)?"json":r.has(s)||s.startsWith("text/")?"text":"blob"}function Qt(e){try{return JSON.parse(e),!0}catch{return!1}}function dt(e){if(e===void 0)return!1;let t=typeof e;return t==="string"||t==="number"||t==="boolean"||t===null?!0:t!=="object"?!1:Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name==="Object"||typeof e.toJSON=="function"}function Se(e){try{return JSON.parse(e)}catch{return e}}function Ae(e){return typeof e=="function"}function Zt(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<"u"&&Ae(globalThis.fetch))return globalThis.fetch;if(typeof window<"u"&&Ae(window.fetch))return window.fetch;throw new Error("No fetch implementation found")}async function er(e){let t=new Headers(e?.headers),r=await Yt(e);for(let[s,a]of Object.entries(r||{}))t.set(s,a);if(!t.has("content-type")){let s=tr(e?.body);s&&t.set("content-type",s)}return t}function tr(e){return dt(e)?"application/json":null}function rr(e){if(!e?.body)return null;let t=new Headers(e?.headers);if(dt(e.body)&&!t.has("content-type")){for(let[r,s]of Object.entries(e?.body))s instanceof Date&&(e.body[r]=s.toISOString());return JSON.stringify(e.body)}return e.body}function sr(e,t){var r;if(t?.method)return t.method.toUpperCase();if(e.startsWith("@")){let s=(r=e.split("@")[1])==null?void 0:r.split("/")[0];return yt.includes(s)?s.toUpperCase():t?.body?"POST":"GET"}return t?.body?"POST":"GET"}function nr(e,t){let r;return!e?.signal&&e?.timeout&&(r=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:r,clearTimeout:()=>{r&&clearTimeout(r)}}}var ar=class mt extends Error{constructor(t,r){super(r||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,mt.prototype)}};async function te(e,t){let r=await e["~standard"].validate(t);if(r.issues)throw new ar(r.issues);return r.value}var yt=["get","post","put","patch","delete"],or=e=>({id:"apply-schema",name:"Apply Schema",version:"1.0.0",async init(t,r){var s,a,n,o;let i=((a=(s=e.plugins)==null?void 0:s.find(u=>{var l;return(l=u.schema)!=null&&l.config?t.startsWith(u.schema.config.baseURL||"")||t.startsWith(u.schema.config.prefix||""):!1}))==null?void 0:a.schema)||e.schema;if(i){let u=t;(n=i.config)!=null&&n.prefix&&u.startsWith(i.config.prefix)&&(u=u.replace(i.config.prefix,""),i.config.baseURL&&(t=t.replace(i.config.prefix,i.config.baseURL))),(o=i.config)!=null&&o.baseURL&&u.startsWith(i.config.baseURL)&&(u=u.replace(i.config.baseURL,""));let l=i.schema[u];if(l){let c=I(j({},r),{method:l.method,output:l.output});return r?.disableValidation||(c=I(j({},c),{body:l.input?await te(l.input,r?.body):r?.body,params:l.params?await te(l.params,r?.params):r?.params,query:l.query?await te(l.query,r?.query):r?.query})),{url:t,options:c}}}return{url:t,options:r}}}),ir=e=>{async function t(r,s){let a=I(j(j({},e),s),{plugins:[...e?.plugins||[],or(e||{})]});if(e?.catchAllError)try{return await ce(r,a)}catch(n){return{data:null,error:{status:500,statusText:"Fetch Error",message:"Fetch related error. Captured by catchAllError option. See error property for more details.",error:n}}}return await ce(r,a)}return t};function lr(e,t){let{baseURL:r,params:s,query:a}=t||{query:{},params:{},baseURL:""},n=e.startsWith("http")?e.split("/").slice(0,3).join("/"):r||"";if(e.startsWith("@")){let c=e.toString().split("@")[1].split("/")[0];yt.includes(c)&&(e=e.replace(`@${c}/`,"/"))}n.endsWith("/")||(n+="/");let[o,i]=e.replace(n,"").split("?"),u=new URLSearchParams(i);for(let[c,h]of Object.entries(a||{}))h!=null&&u.set(c,String(h));if(s)if(Array.isArray(s)){let c=o.split("/").filter(h=>h.startsWith(":"));for(let[h,m]of c.entries()){let d=s[h];o=o.replace(m,d)}}else for(let[c,h]of Object.entries(s))o=o.replace(`:${c}`,String(h));o=o.split("/").map(encodeURIComponent).join("/"),o.startsWith("/")&&(o=o.slice(1));let l=u.toString();return l=l.length>0?`?${l}`.replace(/\+/g,"%20"):"",n.startsWith("http")?new URL(`${o}${l}`,n):`${n}${o}${l}`}var ce=async(e,t)=>{var r,s,a,n,o,i,u,l;let{hooks:c,url:h,options:m}=await Kt(e,t),d=Zt(m),y=new AbortController,b=(r=m.signal)!=null?r:y.signal,g=lr(h,m),w=rr(m),P=await er(m),S=sr(h,m),p=I(j({},m),{url:g,headers:P,body:w,method:S,signal:b});for(let T of c.onRequest)if(T){let E=await T(p);E instanceof Object&&(p=E)}("pipeTo"in p&&typeof p.pipeTo=="function"||typeof((s=t?.body)==null?void 0:s.pipe)=="function")&&("duplex"in p||(p.duplex="half"));let{clearTimeout:C}=nr(m,y),_=await d(p.url,p);C();let _e={response:_,request:p};for(let T of c.onResponse)if(T){let E=await T(I(j({},_e),{response:(a=t?.hookOptions)!=null&&a.cloneResponse?_.clone():_}));E instanceof Response?_=E:E instanceof Object&&(_=E.response)}if(_.ok){if(p.method==="HEAD")return{data:"",error:null};let T=Xt(_),E={data:"",response:_,request:p};if(T==="json"||T==="text"){let B=await _.text(),M=await((n=p.jsonParser)!=null?n:Se)(B);E.data=M}else E.data=await _[T]();p?.output&&p.output&&!p.disableValidation&&(E.data=await te(p.output,E.data));for(let B of c.onSuccess)B&&await B(I(j({},E),{response:(o=t?.hookOptions)!=null&&o.cloneResponse?_.clone():_}));return t?.throw?E.data:{data:E.data,error:null}}let $t=(i=t?.jsonParser)!=null?i:Se,J=await _.text(),Ee=Qt(J),ie=Ee?await $t(J):null,jt={response:_,responseText:J,request:p,error:I(j({},ie),{status:_.status,statusText:_.statusText})};for(let T of c.onError)T&&await T(I(j({},jt),{response:(u=t?.hookOptions)!=null&&u.cloneResponse?_.clone():_}));if(t?.retry){let T=Vt(t.retry),E=(l=t.retryAttempt)!=null?l:0;if(await T.shouldAttemptRetry(E,_)){for(let M of c.onRetry)M&&await M(_e);let B=T.getDelay(E);return await new Promise(M=>setTimeout(M,B)),await ce(e,I(j({},t),{retryAttempt:E+1}))}}if(t?.throw)throw new Gt(_.status,_.statusText,Ee?ie:J);return{data:null,error:I(j({},ie),{status:_.status,statusText:_.statusText})}};f();f();var re=Object.create(null),G=e=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?re:globalThis),R=new Proxy(re,{get(e,t){return G()[t]??re[t]},has(e,t){let r=G();return t in r||t in re},set(e,t,r){let s=G(!0);return s[t]=r,!0},deleteProperty(e,t){if(!t)return!1;let r=G(!0);return delete r[t],!0},ownKeys(){let e=G(!0);return Object.keys(e)}}),ts=typeof process<"u"&&process.env&&process.env.NODE_ENV||"";function v(e,t){return typeof process<"u"&&process.env?process.env[e]??t:typeof Deno<"u"?Deno.env.get(e)??t:typeof Bun<"u"?Bun.env[e]??t:t}var rs=Object.freeze({get BETTER_AUTH_SECRET(){return v("BETTER_AUTH_SECRET")},get AUTH_SECRET(){return v("AUTH_SECRET")},get BETTER_AUTH_TELEMETRY(){return v("BETTER_AUTH_TELEMETRY")},get BETTER_AUTH_TELEMETRY_ID(){return v("BETTER_AUTH_TELEMETRY_ID")},get NODE_ENV(){return v("NODE_ENV","development")},get PACKAGE_VERSION(){return v("PACKAGE_VERSION","0.0.0")},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return v("BETTER_AUTH_TELEMETRY_ENDPOINT","https://telemetry.better-auth.com/v1/track")}}),K=1,O=4,N=8,A=24,Re={eterm:O,cons25:O,console:O,cygwin:O,dtterm:O,gnome:O,hurd:O,jfbterm:O,konsole:O,kterm:O,mlterm:O,mosh:A,putty:O,st:O,"rxvt-unicode-24bit":A,terminator:A,"xterm-kitty":A},ur=new Map(Object.entries({APPVEYOR:N,BUILDKITE:N,CIRCLECI:A,DRONE:N,GITEA_ACTIONS:A,GITHUB_ACTIONS:A,GITLAB_CI:N,TRAVIS:N})),cr=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function hr(){if(v("FORCE_COLOR")!==void 0)switch(v("FORCE_COLOR")){case"":case"1":case"true":return O;case"2":return N;case"3":return A;default:return K}if(v("NODE_DISABLE_COLORS")!==void 0&&v("NODE_DISABLE_COLORS")!==""||v("NO_COLOR")!==void 0&&v("NO_COLOR")!==""||v("TERM")==="dumb")return K;if(v("TMUX"))return A;if("TF_BUILD"in R&&"AGENT_NAME"in R)return O;if("CI"in R){for(let{0:e,1:t}of ur)if(e in R)return t;return v("CI_NAME")==="codeship"?N:K}if("TEAMCITY_VERSION"in R)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(v("TEAMCITY_VERSION"))!==null?O:K;switch(v("TERM_PROGRAM")){case"iTerm.app":return!v("TERM_PROGRAM_VERSION")||/^[0-2]\./.exec(v("TERM_PROGRAM_VERSION"))!==null?N:A;case"HyperTerm":case"MacTerm":return A;case"Apple_Terminal":return N}if(v("COLORTERM")==="truecolor"||v("COLORTERM")==="24bit")return A;if(v("TERM")){if(/truecolor/.exec(v("TERM"))!==null)return A;if(/^xterm-256/.exec(v("TERM"))!==null)return N;let e=v("TERM").toLowerCase();if(Re[e])return Re[e];if(cr.some(t=>t.exec(e)!==null))return O}return v("COLORTERM")?O:K}var x={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"}},he=["info","success","warn","error","debug"];function fr(e,t){return he.indexOf(t)<=he.indexOf(e)}var pr={info:x.fg.blue,success:x.fg.green,warn:x.fg.yellow,error:x.fg.red,debug:x.fg.magenta},dr=(e,t,r)=>{let s=new Date().toISOString();return r?`${x.dim}${s}${x.reset} ${pr[e]}${e.toUpperCase()}${x.reset} ${x.bright}[Better Auth]:${x.reset} ${t}`:`${s} ${e.toUpperCase()} [Better Auth]: ${t}`},mr=e=>{let t=e?.disabled!==!0,r=e?.level??"error",s=e?.disableColors!==void 0?!e.disableColors:hr()!==1,a=(n,o,i=[])=>{if(!t||!fr(r,n))return;let u=dr(n,o,s);if(!e||typeof e.log!="function"){n==="error"?console.error(u,...i):n==="warn"?console.warn(u,...i):console.log(u,...i);return}e.log(n==="success"?"info":n,o,...i)};return{...Object.fromEntries(he.map(n=>[n,(...[o,...i])=>a(n,o,i)])),get level(){return r}}},ss=mr();f();f();var ge=class extends Error{constructor(e,t){super(e),this.name="BetterAuthError",this.message=e,this.cause=t,this.stack=""}};function yr(e){try{return(new URL(e).pathname.replace(/\/+$/,"")||"/")!=="/"}catch{throw new ge(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function z(e,t="/api/auth"){if(yr(e))return e;let r=e.replace(/\/+$/,"");return!t||t==="/"?r:(t=t.startsWith("/")?t:`/${t}`,`${r}${t}`)}function gr(e,t,r,s){if(e)return z(e,t);if(s!==!1){let o=R.BETTER_AUTH_URL||R.NEXT_PUBLIC_BETTER_AUTH_URL||R.PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_BETTER_AUTH_URL||R.NUXT_PUBLIC_AUTH_URL||(R.BASE_URL!=="/"?R.BASE_URL:void 0);if(o)return z(o,t)}let a=r?.headers.get("x-forwarded-host"),n=r?.headers.get("x-forwarded-proto");if(a&&n)return z(`${n}://${a}`,t);if(r){let o=wr(r.url);if(!o)throw new ge("Could not get origin from request. Please provide a valid base URL.");return z(o,t)}if(typeof window<"u"&&window.location)return z(window.location.origin,t)}function wr(e){try{return new URL(e).origin}catch{return null}}f();f();f();var fe=Symbol("clean"),$=[],U=0,X=4,vr=0,gt=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(s){return r.lc=t.push(s),()=>{for(let n=U+X;n<$.length;)$[n]===s?$.splice(n,X):n+=X;let a=t.indexOf(s);~a&&(t.splice(a,1),--r.lc||r.off())}},notify(s,a){vr++;let n=!$.length;for(let o of t)$.push(o,r.value,s,a);if(n){for(U=0;U<$.length;U+=X)$[U]($[U+1],$[U+2],$[U+3]);$.length=0}},off(){},set(s){let a=r.value;a!==s&&(r.value=s,r.notify(a))},subscribe(s){let a=r.listen(s);return s(r.value),a},value:e};return process.env.NODE_ENV!=="production"&&(r[fe]=()=>{t=[],r.lc=0,r.off()}),r};f();var br=5,F=6,Q=10,_r=(e,t,r,s)=>(e.events=e.events||{},e.events[r+Q]||(e.events[r+Q]=s(a=>{e.events[r].reduceRight((n,o)=>(o(n),n),{shared:{},...a})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let a=e.events[r],n=a.indexOf(t);a.splice(n,1),a.length||(delete e.events[r],e.events[r+Q](),delete e.events[r+Q])}),Er=1e3,Or=(e,t)=>_r(e,r=>{let s=t(r);s&&e.events[F].push(s)},br,r=>{let s=e.listen;e.listen=(...n)=>(!e.lc&&!e.active&&(e.active=!0,r()),s(...n));let a=e.off;if(e.events[F]=[],e.off=()=>{a(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let n of e.events[F])n();e.events[F]=[]}},Er)},process.env.NODE_ENV!=="production"){let n=e[fe];e[fe]=()=>{for(let o of e.events[F])o();e.events[F]=[],e.active=!1,n()}}return()=>{e.listen=s,e.off=a}});f();var Tr=typeof window>"u",Pr=(e,t,r,s)=>{let a=gt({data:null,error:null,isPending:!0,isRefetching:!1,refetch:i=>n(i)}),n=i=>{let u=typeof s=="function"?s({data:a.get().data,error:a.get().error,isPending:a.get().isPending}):s;r(t,{...u,query:{...u?.query,...i?.query},async onSuccess(l){a.set({data:l.data,error:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onSuccess?.(l)},async onError(l){let{request:c}=l,h=typeof c.retry=="number"?c.retry:c.retry?.attempts,m=c.retryAttempt||0;h&&m<h||(a.set({error:l.error,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch}),await u?.onError?.(l))},async onRequest(l){let c=a.get();a.set({isPending:c.data===null,data:c.data,error:null,isRefetching:!0,refetch:a.value.refetch}),await u?.onRequest?.(l)}}).catch(l=>{a.set({error:l,data:null,isPending:!1,isRefetching:!1,refetch:a.value.refetch})})};e=Array.isArray(e)?e:[e];let o=!1;for(let i of e)i.subscribe(()=>{Tr||(o?n():Or(a,()=>{let u=setTimeout(()=>{o||(n(),o=!0)},0);return()=>{a.off(),i.off(),clearTimeout(u)}}))});return a};f();var Sr={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*:/},Ar=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,$e={true:!0,false:!1,null:null,undefined:void 0,nan:Number.NaN,infinity:Number.POSITIVE_INFINITY,"-infinity":Number.NEGATIVE_INFINITY},Rr=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function $r(e){return e instanceof Date&&!isNaN(e.getTime())}function jr(e){let t=Rr.exec(e);if(!t)return null;let[,r,s,a,n,o,i,u,l,c,h]=t,m=new Date(Date.UTC(parseInt(r,10),parseInt(s,10)-1,parseInt(a,10),parseInt(n,10),parseInt(o,10),parseInt(i,10),u?parseInt(u.padEnd(3,"0"),10):0));if(l){let d=(parseInt(c,10)*60+parseInt(h,10))*(l==="+"?-1:1);m.setUTCMinutes(m.getUTCMinutes()+d)}return $r(m)?m:null}function Ir(e,t={}){let{strict:r=!1,warnings:s=!1,reviver:a,parseDates:n=!0}=t;if(typeof e!="string")return e;let o=e.trim();if(o.length>0&&o[0]==='"'&&o.endsWith('"')&&!o.slice(1,-1).includes('"'))return o.slice(1,-1);let i=o.toLowerCase();if(i.length<=9&&i in $e)return $e[i];if(!Ar.test(o)){if(r)throw new SyntaxError("[better-json] Invalid JSON");return e}if(Object.entries(Sr).some(([u,l])=>{let c=l.test(o);return c&&s&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${u} pattern`),c})&&r)throw new Error("[better-json] Potential prototype pollution attempt detected");try{return JSON.parse(o,(u,l)=>{if(u==="__proto__"||u==="constructor"&&l&&typeof l=="object"&&"prototype"in l){s&&console.warn(`[better-json] Dropping "${u}" key to prevent prototype pollution`);return}if(n&&typeof l=="string"){let c=jr(l);if(c)return c}return a?a(u,l):l})}catch(u){if(r)throw u;return e}}function Nr(e,t={strict:!0}){return Ir(e,t)}var xr={id:"redirect",name:"Redirect",hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&typeof window<"u"&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}};function Ur(e){let t=gt(!1);return{session:Pr(t,"/get-session",e,{method:"GET"}),$sessionSignal:t}}var Cr=(e,t)=>{let r="credentials"in Request.prototype,s=gr(e?.baseURL,e?.basePath,void 0,t)??"/api/auth",a=e?.plugins?.flatMap(p=>p.fetchPlugins).filter(p=>p!==void 0)||[],n={id:"lifecycle-hooks",name:"lifecycle-hooks",hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:i,onRequest:u,onResponse:l,...c}=e?.fetchOptions||{},h=ir({baseURL:s,...r?{credentials:"include"}:{},method:"GET",jsonParser(p){return p?Nr(p,{strict:!1}):null},customFetchImpl:fetch,...c,plugins:[n,...c.plugins||[],...e?.disableDefaultFetchPlugins?[]:[xr],...a]}),{$sessionSignal:m,session:d}=Ur(h),y=e?.plugins||[],b={},g={$sessionSignal:m,session:d},w={"/sign-out":"POST","/revoke-sessions":"POST","/revoke-other-sessions":"POST","/delete-user":"POST"},P=[{signal:"$sessionSignal",matcher(p){return p==="/sign-out"||p==="/update-user"||p.startsWith("/sign-in")||p.startsWith("/sign-up")||p==="/delete-user"||p==="/verify-email"}}];for(let p of y)p.getAtoms&&Object.assign(g,p.getAtoms?.(h)),p.pathMethods&&Object.assign(w,p.pathMethods),p.atomListeners&&P.push(...p.atomListeners);let S={notify:p=>{g[p].set(!g[p].get())},listen:(p,C)=>{g[p].subscribe(C)},atoms:g};for(let p of y)p.getActions&&Object.assign(b,p.getActions?.(h,S,e));return{get baseURL(){return s},pluginsActions:b,pluginsAtoms:g,pluginPathMethods:w,atomListeners:P,$fetch:h,$store:S}};function Lr(e){return typeof e=="object"&&e!==null&&"get"in e&&typeof e.get=="function"&&"lc"in e&&typeof e.lc=="number"}function Dr(e,t,r){let s=t[e],{fetchOptions:a,query:n,...o}=r||{};return s||(a?.method?a.method:o&&Object.keys(o).length>0?"POST":"GET")}function kr(e,t,r,s,a){function n(o=[]){return new Proxy(function(){},{get(i,u){if(typeof u!="string"||u==="then"||u==="catch"||u==="finally")return;let l=[...o,u],c=e;for(let h of l)if(c&&typeof c=="object"&&h in c)c=c[h];else{c=void 0;break}return typeof c=="function"||Lr(c)?c:n(l)},apply:async(i,u,l)=>{let c="/"+o.map(P=>P.replace(/[A-Z]/g,S=>`-${S.toLowerCase()}`)).join("/"),h=l[0]||{},m=l[1]||{},{query:d,fetchOptions:y,...b}=h,g={...m,...y},w=Dr(c,r,h);return await t(c,{...g,body:w==="GET"?void 0:{...b,...g?.body||{}},query:d||g?.query,method:w,async onSuccess(P){if(await g?.onSuccess?.(P),!a)return;let S=a.filter(p=>p.matcher(c));if(S.length)for(let p of S){let C=s[p.signal];if(!C)return;let _=C.get();setTimeout(()=>{C.set(!_)},10)}}})}})}return n()}f();function Br(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Mr(e){let{pluginPathMethods:t,pluginsActions:r,pluginsAtoms:s,$fetch:a,atomListeners:n,$store:o}=Cr(e),i={};for(let[l,c]of Object.entries(s))i[`use${Br(l)}`]=c;let u={...r,...i,$fetch:a,$store:o};return kr(u,a,t,s,n)}f();f();f();function Fr(e){return{authorize(t,r="AND"){let s=!1;for(let[a,n]of Object.entries(t)){let o=e[a];if(!o)return{success:!1,error:`You are not allowed to access resource: ${a}`};if(Array.isArray(n))s=n.every(i=>o.includes(i));else if(typeof n=="object"){let i=n;i.connector==="OR"?s=i.actions.some(u=>o.includes(u)):s=i.actions.every(u=>o.includes(u))}else throw new ge("Invalid access control request");if(s&&r==="OR")return{success:s};if(!s&&r==="AND")return{success:!1,error:`unauthorized to access resource "${a}"`}}return s?{success:s}:{success:!1,error:"Not authorized"}},statements:e}}function wt(e){return{newRole(t){return Fr(t)},statements:e}}var Hr={organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]},we=wt(Hr),ns=we.newRole({organization:["update"],invitation:["create","cancel"],member:["create","update","delete"],team:["create","update","delete"],ac:["create","read","update","delete"]}),as=we.newRole({organization:["update","delete"],member:["create","update","delete"],invitation:["create","cancel"],team:["create","update","delete"],ac:["create","read","update","delete"]}),os=we.newRole({organization:[],member:[],invitation:[],team:[],ac:["read"]});f();f();f();f();f();f();f();f();f();f();f();var qr=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}}},is=new qr;f();f();f();f();f();f();f();f();var Wr={user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]},vt=wt(Wr),ls=vt.newRole({user:["create","list","set-role","ban","impersonate","delete","set-password","get","update"],session:["list","revoke","delete"]}),us=vt.newRole({user:[],session:[]});f();f();var Gr=()=>({id:"username",$InferServerPlugin:{}}),Kr=()=>({id:"phoneNumber",$InferServerPlugin:{},atomListeners:[{matcher(e){return e==="/phone-number/update"||e==="/phone-number/verify"},signal:"$sessionSignal"}]}),zr=()=>({id:"better-auth-client",$InferServerPlugin:{}}),Vr="/auth",le="nvwa_login_token",se="nvwa_current_jwt",ue="nvwa_user_profile",bt=class{constructor(e,t,r){this.storage=r;let s=Mr({baseURL:e,basePath:Vr,plugins:[Gr(),Kr(),zr()],fetchOptions:{customFetchImpl:t,auth:{type:"Bearer",token:async()=>{let a=await this.storage.get(se);if(console.log("jwt",a),a)return a;let n=await this.storage.get(le);return console.log("loginToken",n),n}}}});this.authClient=s}async currentUser(){return await this.storage.get(ue)}async getCurrentJwt(){return await this.storage.get(se)}async signUp(e){let t=await this.authClient.signUp.email({email:e.email??`${e.username}@nvwa.app`,name:e.name,username:e.username,displayUsername:e.displayUsername,password:e.password});this.handleLogin(t)}async sendPhoneNumberCode(e){await this.authClient.phoneNumber.sendOtp({phoneNumber:e})}async signInWithPhoneNumberCode(e,t){let r=await this.authClient.phoneNumber.verify({phoneNumber:e,code:t});this.handleLogin(r)}async signInWithPhoneNumber(e,t,r=!1){let s=await this.authClient.signIn.phoneNumber({phoneNumber:e,password:t,rememberMe:r});this.handleLogin(s)}async signInWithUsername(e,t){let r=await this.authClient.signIn.username({username:e,password:t});this.handleLogin(r)}async handleLogin(e){if(e.error)throw new Error(e.error.message);await this.storage.set(le,e.data?.token),await this.storage.set(ue,e.data?.user);let{data:t,error:r}=await this.authClient.token();if(r)throw new Error(r.message);await this.storage.set(se,t.token)}async signOut(){await this.storage.remove(le),await this.storage.remove(ue)}async updateUserPassword(e,t,r=!1){let s=await this.authClient.changePassword({currentPassword:e,newPassword:t,revokeOtherSessions:r});this.handleLogin(s)}};f();var _t=class{constructor(e){this.http=e}async invoke(e,t){return await(await this.http.fetch("/functions/"+e,{method:t.method||"POST",body:t.body,headers:t.headers})).json()}};f();f();f();var L=class Et{constructor(t){if(this.headerMap=new Map,t){if(t instanceof Et)t.forEach((r,s)=>this.set(s,r));else if(Array.isArray(t))for(let[r,s]of t)this.set(r,String(s));else if(typeof t=="object")for(let r of Object.keys(t))this.set(r,String(t[r]))}}append(t,r){let s=t.toLowerCase(),a=this.headerMap.get(s);this.headerMap.set(s,a?`${a}, ${r}`:r)}set(t,r){this.headerMap.set(t.toLowerCase(),String(r))}get(t){return this.headerMap.get(t.toLowerCase())??null}has(t){return this.headerMap.has(t.toLowerCase())}delete(t){this.headerMap.delete(t.toLowerCase())}forEach(t){for(let[r,s]of this.headerMap.entries())t(s,r,this)}entries(){return this.headerMap.entries()}keys(){return this.headerMap.keys()}values(){return this.headerMap.values()}[Symbol.iterator](){return this.entries()}};f();f();var Ot=class{constructor(e,t){this.bodyData=e,this.status=t?.status??200,this.statusText=t?.statusText??"",this.headers=Yr(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 Yr(e){return e?new L(e):new L}f();f();var Tt=class{constructor(e,t,r){console.log("NvwaHttpClient constructor",e,t,r),this.storage=e,this.customFetch=t,this.handleUnauthorized=r}async fetch(e,t){return await this.customFetch(e,t)}async fetchWithAuth(e,t){let r=await this.storage.get(se),s=new L(t?.headers);r&&s.set("Authorization",`Bearer ${r}`);let a=await this.customFetch(e,{...t,headers:s});if(a.status===401)throw this.handleUnauthorized(),new Error("\u672A\u767B\u5F55");return a}};f();var Jr="/storage",Xr=Jr+"/generateUploadUrl",Pt=class{constructor(e,t){this.baseUrl=e,this.http=t}async uploadFile(e){let t=await this.http.fetch(this.baseUrl+Xr,{method:"POST",body:{fileName:e.name||e.fileName,fileSize:e.size||e.fileSize,fileType:e.type||e.fileType}}),{url:r}=await t.json();if(!r)throw new Error("\u83B7\u53D6\u4E0A\u4F20URL\u5931\u8D25");let s=await this.http.fetch(r,{method:"PUT",body:e,headers:new L({"Content-Type":e.type||e.fileType||"application/octet-stream"})}),{url:a}=await s.json();return{url:a.split("?")[0]}}};f();f();f();var je=Dt(Bt(),1),{PostgrestClient:Qr,PostgrestQueryBuilder:cs,PostgrestFilterBuilder:hs,PostgrestTransformBuilder:fs,PostgrestBuilder:ps,PostgrestError:ds}=je.default||je,Zr="/entities",St=(e,t)=>new Qr(e+Zr,{fetch:t.fetchWithAuth.bind(t)});f();var At=class{constructor(e,t){this.baseUrl=e,this.http=t}async execute(e,t){let r=`${this.baseUrl}/skill/${e}/execute`,s=await(await this.http.fetchWithAuth(r,{method:"POST",body:t,timeout:6e5})).json();if(s.status!==200)throw new Error(s.message);return s.data}};var oe=class{constructor(){this.prefix="nvwa_"}getKey(t){return`${this.prefix}${t}`}async get(t){try{let r=this.getKey(t),s=localStorage.getItem(r);if(!s)return null;let a=JSON.parse(s);return a.expires&&Date.now()>a.expires?(await this.remove(t),null):a.value}catch(r){return console.error("WebStorageService get error:",r),null}}async set(t,r,s){try{let a=this.getKey(t),n={value:r,expires:s?Date.now()+s*1e3:null,timestamp:Date.now()};localStorage.setItem(a,JSON.stringify(n))}catch(a){throw console.error("WebStorageService set error:",a),a}}async remove(t){try{let r=this.getKey(t);localStorage.removeItem(r)}catch(r){throw console.error("WebStorageService remove error:",r),r}}async clear(){try{Object.keys(localStorage).filter(s=>s.startsWith(this.prefix)).forEach(s=>{localStorage.removeItem(s)})}catch(t){throw console.error("WebStorageService clear error:",t),t}}};var es=(e,t)=>{let r;if(typeof e=="string")r=e;else if(e&&typeof e.toString=="function")r=e.toString();else if(e?.url)r=e.url;else throw new Error("Invalid input for webFetch");let s;if(t?.headers){let n=t.headers;if(n instanceof L){let o={};n.forEach((i,u)=>{o[u]=i}),s=o}else if(Array.isArray(n)){let o=[];for(let i of n)Array.isArray(i)&&i.length>=2&&o.push([String(i[0]),String(i[1])]);s=o}else typeof n=="object"&&(s=n)}let a={method:t?.method||"GET",headers:s,body:t?.body};return t?.signal&&(a.signal=t.signal),globalThis.fetch(r,a).then(async n=>{let o=n.headers.get("content-type")||"",i;if(o.includes("application/json"))i=await n.json();else{let l=await n.text();try{i=JSON.parse(l)}catch{i=l}}let u=new L;return n.headers.forEach((l,c)=>{u.set(c,l)}),new Ot(i,{status:n.status,statusText:n.statusText,headers:u})})},ve=es;var Rt=new oe,be=class{constructor(t,r){this.auth=new bt(t,ve,Rt),this.httpClient=new Tt(Rt,ve,r),this.fileStorage=new Pt(t,this.httpClient),this.entities=St(t,this.httpClient),this.functions=new _t(this.httpClient),this.skill=new At(t,this.httpClient)}};export{be as default,Rt as localStorage};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nvwa-app/sdk-web",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "NVWA跨端通用工具类Web端实现",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",