@pankod/refine-supabase
Version:
refine Supabase data provider. refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.
1 lines • 75.7 kB
JavaScript
(()=>{var Lt=Object.create;var ce=Object.defineProperty,Ft=Object.defineProperties,Dt=Object.getOwnPropertyDescriptor,Mt=Object.getOwnPropertyDescriptors,Ht=Object.getOwnPropertyNames,Fe=Object.getOwnPropertySymbols,Gt=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty,Jt=Object.prototype.propertyIsEnumerable;var De=(i,e,t)=>e in i?ce(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,He=(i,e)=>{for(var t in e||(e={}))Me.call(e,t)&&De(i,t,e[t]);if(Fe)for(var t of Fe(e))Jt.call(e,t)&&De(i,t,e[t]);return i},Ge=(i,e)=>Ft(i,Mt(e));var V=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),qt=(i,e)=>{for(var t in e)ce(i,t,{get:e[t],enumerable:!0})},zt=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Ht(e))!Me.call(i,s)&&s!==t&&ce(i,s,{get:()=>e[s],enumerable:!(r=Dt(e,s))||r.enumerable});return i};var he=(i,e,t)=>(t=i!=null?Lt(Gt(i)):{},zt(e||!i||!i.__esModule?ce(t,"default",{value:i,enumerable:!0}):t,i));var pe=V((A,et)=>{var Ze=typeof self<"u"?self:A,fe=function(){function i(){this.fetch=!1,this.DOMException=Ze.DOMException}return i.prototype=Ze,new i}();(function(i){var e=function(t){var r={searchParams:"URLSearchParams"in i,iterable:"Symbol"in i&&"iterator"in Symbol,blob:"FileReader"in i&&"Blob"in i&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in i,arrayBuffer:"ArrayBuffer"in i};function s(c){return c&&DataView.prototype.isPrototypeOf(c)}if(r.arrayBuffer)var n=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(c){return c&&n.indexOf(Object.prototype.toString.call(c))>-1};function a(c){if(typeof c!="string"&&(c=String(c)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(c))throw new TypeError("Invalid character in header field name");return c.toLowerCase()}function u(c){return typeof c!="string"&&(c=String(c)),c}function d(c){var l={next:function(){var p=c.shift();return{done:p===void 0,value:p}}};return r.iterable&&(l[Symbol.iterator]=function(){return l}),l}function h(c){this.map={},c instanceof h?c.forEach(function(l,p){this.append(p,l)},this):Array.isArray(c)?c.forEach(function(l){this.append(l[0],l[1])},this):c&&Object.getOwnPropertyNames(c).forEach(function(l){this.append(l,c[l])},this)}h.prototype.append=function(c,l){c=a(c),l=u(l);var p=this.map[c];this.map[c]=p?p+", "+l:l},h.prototype.delete=function(c){delete this.map[a(c)]},h.prototype.get=function(c){return c=a(c),this.has(c)?this.map[c]:null},h.prototype.has=function(c){return this.map.hasOwnProperty(a(c))},h.prototype.set=function(c,l){this.map[a(c)]=u(l)},h.prototype.forEach=function(c,l){for(var p in this.map)this.map.hasOwnProperty(p)&&c.call(l,this.map[p],p,this)},h.prototype.keys=function(){var c=[];return this.forEach(function(l,p){c.push(p)}),d(c)},h.prototype.values=function(){var c=[];return this.forEach(function(l){c.push(l)}),d(c)},h.prototype.entries=function(){var c=[];return this.forEach(function(l,p){c.push([p,l])}),d(c)},r.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);function f(c){if(c.bodyUsed)return Promise.reject(new TypeError("Already read"));c.bodyUsed=!0}function S(c){return new Promise(function(l,p){c.onload=function(){l(c.result)},c.onerror=function(){p(c.error)}})}function T(c){var l=new FileReader,p=S(l);return l.readAsArrayBuffer(c),p}function z(c){var l=new FileReader,p=S(l);return l.readAsText(c),p}function W(c){for(var l=new Uint8Array(c),p=new Array(l.length),b=0;b<l.length;b++)p[b]=String.fromCharCode(l[b]);return p.join("")}function Be(c){if(c.slice)return c.slice(0);var l=new Uint8Array(c.byteLength);return l.set(new Uint8Array(c)),l.buffer}function Le(){return this.bodyUsed=!1,this._initBody=function(c){this._bodyInit=c,c?typeof c=="string"?this._bodyText=c:r.blob&&Blob.prototype.isPrototypeOf(c)?this._bodyBlob=c:r.formData&&FormData.prototype.isPrototypeOf(c)?this._bodyFormData=c:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(c)?this._bodyText=c.toString():r.arrayBuffer&&r.blob&&s(c)?(this._bodyArrayBuffer=Be(c.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(c)||o(c))?this._bodyArrayBuffer=Be(c):this._bodyText=c=Object.prototype.toString.call(c):this._bodyText="",this.headers.get("content-type")||(typeof c=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(c)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var c=f(this);if(c)return c;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?f(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(T)}),this.text=function(){var c=f(this);if(c)return c;if(this._bodyBlob)return z(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(W(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r.formData&&(this.formData=function(){return this.text().then(It)}),this.json=function(){return this.text().then(JSON.parse)},this}var Ct=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function Ut(c){var l=c.toUpperCase();return Ct.indexOf(l)>-1?l:c}function N(c,l){l=l||{};var p=l.body;if(c instanceof N){if(c.bodyUsed)throw new TypeError("Already read");this.url=c.url,this.credentials=c.credentials,l.headers||(this.headers=new h(c.headers)),this.method=c.method,this.mode=c.mode,this.signal=c.signal,!p&&c._bodyInit!=null&&(p=c._bodyInit,c.bodyUsed=!0)}else this.url=String(c);if(this.credentials=l.credentials||this.credentials||"same-origin",(l.headers||!this.headers)&&(this.headers=new h(l.headers)),this.method=Ut(l.method||this.method||"GET"),this.mode=l.mode||this.mode||null,this.signal=l.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&p)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(p)}N.prototype.clone=function(){return new N(this,{body:this._bodyInit})};function It(c){var l=new FormData;return c.trim().split("&").forEach(function(p){if(p){var b=p.split("="),g=b.shift().replace(/\+/g," "),m=b.join("=").replace(/\+/g," ");l.append(decodeURIComponent(g),decodeURIComponent(m))}}),l}function Nt(c){var l=new h,p=c.replace(/\r?\n[\t ]+/g," ");return p.split(/\r?\n/).forEach(function(b){var g=b.split(":"),m=g.shift().trim();if(m){var ae=g.join(":").trim();l.append(m,ae)}}),l}Le.call(N.prototype);function O(c,l){l||(l={}),this.type="default",this.status=l.status===void 0?200:l.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in l?l.statusText:"OK",this.headers=new h(l.headers),this.url=l.url||"",this._initBody(c)}Le.call(O.prototype),O.prototype.clone=function(){return new O(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},O.error=function(){var c=new O(null,{status:0,statusText:""});return c.type="error",c};var Bt=[301,302,303,307,308];O.redirect=function(c,l){if(Bt.indexOf(l)===-1)throw new RangeError("Invalid status code");return new O(null,{status:l,headers:{location:c}})},t.DOMException=i.DOMException;try{new t.DOMException}catch{t.DOMException=function(l,p){this.message=l,this.name=p;var b=Error(l);this.stack=b.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function Te(c,l){return new Promise(function(p,b){var g=new N(c,l);if(g.signal&&g.signal.aborted)return b(new t.DOMException("Aborted","AbortError"));var m=new XMLHttpRequest;function ae(){m.abort()}m.onload=function(){var K={status:m.status,statusText:m.statusText,headers:Nt(m.getAllResponseHeaders()||"")};K.url="responseURL"in m?m.responseURL:K.headers.get("X-Request-URL");var ke="response"in m?m.response:m.responseText;p(new O(ke,K))},m.onerror=function(){b(new TypeError("Network request failed"))},m.ontimeout=function(){b(new TypeError("Network request failed"))},m.onabort=function(){b(new t.DOMException("Aborted","AbortError"))},m.open(g.method,g.url,!0),g.credentials==="include"?m.withCredentials=!0:g.credentials==="omit"&&(m.withCredentials=!1),"responseType"in m&&r.blob&&(m.responseType="blob"),g.headers.forEach(function(K,ke){m.setRequestHeader(ke,K)}),g.signal&&(g.signal.addEventListener("abort",ae),m.onreadystatechange=function(){m.readyState===4&&g.signal.removeEventListener("abort",ae)}),m.send(typeof g._bodyInit>"u"?null:g._bodyInit)})}return Te.polyfill=!0,i.fetch||(i.fetch=Te,i.Headers=h,i.Request=N,i.Response=O),t.Headers=h,t.Request=N,t.Response=O,t.fetch=Te,Object.defineProperty(t,"__esModule",{value:!0}),t}({})})(fe);fe.fetch.ponyfill=!0;delete fe.fetch.polyfill;var D=fe;A=D.fetch;A.default=D.fetch;A.fetch=D.fetch;A.Headers=D.Headers;A.Request=D.Request;A.Response=D.Response;et.exports=A});var _t=V((Ss,bt)=>{var gt=function(){if(typeof self=="object"&&self)return self;if(typeof window=="object"&&window)return window;throw new Error("Unable to resolve global `this`")};bt.exports=function(){if(this)return this;if(typeof globalThis=="object"&&globalThis)return globalThis;try{Object.defineProperty(Object.prototype,"__global__",{get:function(){return this},configurable:!0})}catch{return gt()}try{return __global__||gt()}finally{delete Object.prototype.__global__}}()});var wt=V((xs,rr)=>{rr.exports={name:"websocket",description:"Websocket Client & Server Library implementing the WebSocket protocol as specified in RFC 6455.",keywords:["websocket","websockets","socket","networking","comet","push","RFC-6455","realtime","server","client"],author:"Brian McKelvey <theturtle32@gmail.com> (https://github.com/theturtle32)",contributors:["I\xF1aki Baz Castillo <ibc@aliax.net> (http://dev.sipdoc.net)"],version:"1.0.34",repository:{type:"git",url:"https://github.com/theturtle32/WebSocket-Node.git"},homepage:"https://github.com/theturtle32/WebSocket-Node",engines:{node:">=4.0.0"},dependencies:{bufferutil:"^4.0.1",debug:"^2.2.0","es5-ext":"^0.10.50","typedarray-to-buffer":"^3.1.5","utf-8-validate":"^5.0.2",yaeti:"^0.0.6"},devDependencies:{"buffer-equal":"^1.0.0",gulp:"^4.0.2","gulp-jshint":"^2.0.4","jshint-stylish":"^2.2.1",jshint:"^2.0.0",tape:"^4.9.1"},config:{verbose:!1},scripts:{test:"tape test/unit/*.js",gulp:"gulp"},main:"index",directories:{lib:"./lib"},browser:"lib/browser.js",license:"Apache-2.0"}});var St=V((Ts,Et)=>{Et.exports=wt().version});var kt=V((ks,Tt)=>{var L;if(typeof globalThis=="object")L=globalThis;else try{L=_t()}catch{}finally{if(!L&&typeof window<"u"&&(L=window),!L)throw new Error("Could not determine global this")}var se=L.WebSocket||L.MozWebSocket,sr=St();function xt(i,e){var t;return e?t=new se(i,e):t=new se(i),t}se&&["CONNECTING","OPEN","CLOSING","CLOSED"].forEach(function(i){Object.defineProperty(xt,i,{get:function(){return se[i]}})});Tt.exports={w3cwebsocket:se?xt:null,version:sr}});var Je="1.31.1";var Oe={"X-Client-Info":`supabase-js/${Je}`},qe="supabase.auth.token";function ze(i){return i.replace(/\/$/,"")}var We=()=>typeof window<"u";var Y=function(i,e,t,r){function s(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function a(h){try{d(r.next(h))}catch(f){o(f)}}function u(h){try{d(r.throw(h))}catch(f){o(f)}}function d(h){h.done?n(h.value):s(h.value).then(a,u)}d((r=r.apply(i,e||[])).next())})},Wt=i=>i.msg||i.message||i.error_description||i.error||JSON.stringify(i),Kt=(i,e)=>{if(typeof i.json!="function")return e(i);i.json().then(t=>e({message:Wt(t),status:(i==null?void 0:i.status)||500}))},Vt=(i,e,t)=>{let r={method:i,headers:(e==null?void 0:e.headers)||{}};return i==="GET"||(r.headers=Object.assign({"Content-Type":"text/plain;charset=UTF-8"},e==null?void 0:e.headers),r.body=JSON.stringify(t)),r};function ue(i,e,t,r,s){return Y(this,void 0,void 0,function*(){return new Promise((n,o)=>{i(t,Vt(e,r,s)).then(a=>{if(!a.ok)throw a;return r!=null&&r.noResolveJson?n:a.json()}).then(a=>n(a)).catch(a=>Kt(a,o))})})}function le(i,e,t){return Y(this,void 0,void 0,function*(){return ue(i,"GET",e,t)})}function _(i,e,t,r){return Y(this,void 0,void 0,function*(){return ue(i,"POST",e,r,t)})}function $e(i,e,t,r){return Y(this,void 0,void 0,function*(){return ue(i,"PUT",e,r,t)})}function Ke(i,e,t,r){return Y(this,void 0,void 0,function*(){return ue(i,"DELETE",e,r,t)})}var Ve="1.22.8";var Ye="http://localhost:9999";var Xe={"X-Client-Info":`gotrue-js/${Ve}`},Sr=60*1e3,F="supabase.auth.token",Qe={name:"sb",lifetime:60*60*8,domain:"",path:"/",sameSite:"lax"};function Yt(i,e,t){let r=t||{},s=encodeURIComponent,n=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;if(typeof s!="function")throw new TypeError("option encode is invalid");if(!n.test(i))throw new TypeError("argument name is invalid");let o=s(e);if(o&&!n.test(o))throw new TypeError("argument val is invalid");let a=i+"="+o;if(r.maxAge!=null){let u=r.maxAge-0;if(isNaN(u)||!isFinite(u))throw new TypeError("option maxAge is invalid");a+="; Max-Age="+Math.floor(u)}if(r.domain){if(!n.test(r.domain))throw new TypeError("option domain is invalid");a+="; Domain="+r.domain}if(r.path){if(!n.test(r.path))throw new TypeError("option path is invalid");a+="; Path="+r.path}if(r.expires){if(typeof r.expires.toUTCString!="function")throw new TypeError("option expires is invalid");a+="; Expires="+r.expires.toUTCString()}if(r.httpOnly&&(a+="; HttpOnly"),r.secure&&(a+="; Secure"),r.sameSite)switch(typeof r.sameSite=="string"?r.sameSite.toLowerCase():r.sameSite){case"lax":a+="; SameSite=Lax";break;case"strict":a+="; SameSite=Strict";break;case"none":a+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}return a}function Xt(i){if(!i||!i.headers||!i.headers.host)throw new Error('The "host" request header is not available');let e=i.headers.host.indexOf(":")>-1&&i.headers.host.split(":")[0]||i.headers.host;return!(["localhost","127.0.0.1"].indexOf(e)>-1||e.endsWith(".local"))}function Qt(i,e){var t,r,s;return Yt(i.name,i.value,{maxAge:i.maxAge,expires:new Date(Date.now()+i.maxAge*1e3),httpOnly:!0,secure:e,path:(t=i.path)!==null&&t!==void 0?t:"/",domain:(r=i.domain)!==null&&r!==void 0?r:"",sameSite:(s=i.sameSite)!==null&&s!==void 0?s:"lax"})}function de(i,e,t){let r=t.map(n=>Qt(n,Xt(i))),s=e.getHeader("Set-Cookie");return s&&(s instanceof Array?Array.prototype.push.apply(r,s):typeof s=="string"&&r.push(s)),r}function X(i,e,t){e.setHeader("Set-Cookie",de(i,e,t))}var tt=he(pe());function R(i){return Math.round(Date.now()/1e3)+i}function rt(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(i){let e=Math.random()*16|0;return(i=="x"?e:e&3|8).toString(16)})}var j=()=>typeof window<"u";function P(i,e){var t;e||(e=((t=window==null?void 0:window.location)===null||t===void 0?void 0:t.href)||""),i=i.replace(/[\[\]]/g,"\\$&");let r=new RegExp("[?&#]"+i+"(=([^&#]*)|&|#|$)"),s=r.exec(e);return s?s[2]?decodeURIComponent(s[2].replace(/\+/g," ")):"":null}var st=i=>{let e;return i?e=i:typeof fetch>"u"?e=tt.default:e=fetch,(...t)=>e(...t)};var y=function(i,e,t,r){function s(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function a(h){try{d(r.next(h))}catch(f){o(f)}}function u(h){try{d(r.throw(h))}catch(f){o(f)}}function d(h){h.done?n(h.value):s(h.value).then(a,u)}d((r=r.apply(i,e||[])).next())})},Q=class{constructor({url:e="",headers:t={},cookieOptions:r,fetch:s}){this.url=e,this.headers=t,this.cookieOptions=Object.assign(Object.assign({},Qe),r),this.fetch=st(s)}_createRequestHeaders(e){let t=Object.assign({},this.headers);return t.Authorization=`Bearer ${e}`,t}cookieName(){var e;return(e=this.cookieOptions.name)!==null&&e!==void 0?e:""}getUrlForProvider(e,t){let r=[`provider=${encodeURIComponent(e)}`];return t!=null&&t.redirectTo&&r.push(`redirect_to=${encodeURIComponent(t.redirectTo)}`),t!=null&&t.scopes&&r.push(`scopes=${encodeURIComponent(t.scopes)}`),`${this.url}/authorize?${r.join("&")}`}signUpWithEmail(e,t,r={}){return y(this,void 0,void 0,function*(){try{let s=Object.assign({},this.headers),n="";r.redirectTo&&(n="?redirect_to="+encodeURIComponent(r.redirectTo));let o=yield _(this.fetch,`${this.url}/signup${n}`,{email:e,password:t,data:r.data,gotrue_meta_security:{hcaptcha_token:r.captchaToken}},{headers:s}),a=Object.assign({},o);return a.expires_in&&(a.expires_at=R(o.expires_in)),{data:a,error:null}}catch(s){return{data:null,error:s}}})}signInWithEmail(e,t,r={}){return y(this,void 0,void 0,function*(){try{let s=Object.assign({},this.headers),n="?grant_type=password";r.redirectTo&&(n+="&redirect_to="+encodeURIComponent(r.redirectTo));let o=yield _(this.fetch,`${this.url}/token${n}`,{email:e,password:t},{headers:s}),a=Object.assign({},o);return a.expires_in&&(a.expires_at=R(o.expires_in)),{data:a,error:null}}catch(s){return{data:null,error:s}}})}signUpWithPhone(e,t,r={}){return y(this,void 0,void 0,function*(){try{let s=Object.assign({},this.headers),n=yield _(this.fetch,`${this.url}/signup`,{phone:e,password:t,data:r.data,gotrue_meta_security:{hcaptcha_token:r.captchaToken}},{headers:s}),o=Object.assign({},n);return o.expires_in&&(o.expires_at=R(n.expires_in)),{data:o,error:null}}catch(s){return{data:null,error:s}}})}signInWithPhone(e,t){return y(this,void 0,void 0,function*(){try{let r=Object.assign({},this.headers),s="?grant_type=password",n=yield _(this.fetch,`${this.url}/token${s}`,{phone:e,password:t},{headers:r}),o=Object.assign({},n);return o.expires_in&&(o.expires_at=R(n.expires_in)),{data:o,error:null}}catch(r){return{data:null,error:r}}})}signInWithOpenIDConnect({id_token:e,nonce:t,client_id:r,issuer:s,provider:n}){return y(this,void 0,void 0,function*(){try{let o=Object.assign({},this.headers),a="?grant_type=id_token",u=yield _(this.fetch,`${this.url}/token${a}`,{id_token:e,nonce:t,client_id:r,issuer:s,provider:n},{headers:o}),d=Object.assign({},u);return d.expires_in&&(d.expires_at=R(u.expires_in)),{data:d,error:null}}catch(o){return{data:null,error:o}}})}sendMagicLinkEmail(e,t={}){var r;return y(this,void 0,void 0,function*(){try{let s=Object.assign({},this.headers),n="";t.redirectTo&&(n+="?redirect_to="+encodeURIComponent(t.redirectTo));let o=(r=t.shouldCreateUser)!==null&&r!==void 0?r:!0;return{data:yield _(this.fetch,`${this.url}/otp${n}`,{email:e,create_user:o,gotrue_meta_security:{hcaptcha_token:t.captchaToken}},{headers:s}),error:null}}catch(s){return{data:null,error:s}}})}sendMobileOTP(e,t={}){var r;return y(this,void 0,void 0,function*(){try{let s=(r=t.shouldCreateUser)!==null&&r!==void 0?r:!0,n=Object.assign({},this.headers);return{data:yield _(this.fetch,`${this.url}/otp`,{phone:e,create_user:s,gotrue_meta_security:{hcaptcha_token:t.captchaToken}},{headers:n}),error:null}}catch(s){return{data:null,error:s}}})}signOut(e){return y(this,void 0,void 0,function*(){try{return yield _(this.fetch,`${this.url}/logout`,{},{headers:this._createRequestHeaders(e),noResolveJson:!0}),{error:null}}catch(t){return{error:t}}})}verifyMobileOTP(e,t,r={}){return y(this,void 0,void 0,function*(){try{let s=Object.assign({},this.headers),n=yield _(this.fetch,`${this.url}/verify`,{phone:e,token:t,type:"sms",redirect_to:r.redirectTo},{headers:s}),o=Object.assign({},n);return o.expires_in&&(o.expires_at=R(n.expires_in)),{data:o,error:null}}catch(s){return{data:null,error:s}}})}verifyOTP({email:e,phone:t,token:r,type:s="sms"},n={}){return y(this,void 0,void 0,function*(){try{let o=Object.assign({},this.headers),a=yield _(this.fetch,`${this.url}/verify`,{email:e,phone:t,token:r,type:s,redirect_to:n.redirectTo},{headers:o}),u=Object.assign({},a);return u.expires_in&&(u.expires_at=R(a.expires_in)),{data:u,error:null}}catch(o){return{data:null,error:o}}})}inviteUserByEmail(e,t={}){return y(this,void 0,void 0,function*(){try{let r=Object.assign({},this.headers),s="";return t.redirectTo&&(s+="?redirect_to="+encodeURIComponent(t.redirectTo)),{data:yield _(this.fetch,`${this.url}/invite${s}`,{email:e,data:t.data},{headers:r}),error:null}}catch(r){return{data:null,error:r}}})}resetPasswordForEmail(e,t={}){return y(this,void 0,void 0,function*(){try{let r=Object.assign({},this.headers),s="";return t.redirectTo&&(s+="?redirect_to="+encodeURIComponent(t.redirectTo)),{data:yield _(this.fetch,`${this.url}/recover${s}`,{email:e,gotrue_meta_security:{hcaptcha_token:t.captchaToken}},{headers:r}),error:null}}catch(r){return{data:null,error:r}}})}refreshAccessToken(e){return y(this,void 0,void 0,function*(){try{let t=yield _(this.fetch,`${this.url}/token?grant_type=refresh_token`,{refresh_token:e},{headers:this.headers}),r=Object.assign({},t);return r.expires_in&&(r.expires_at=R(t.expires_in)),{data:r,error:null}}catch(t){return{data:null,error:t}}})}setAuthCookie(e,t){e.method!=="POST"&&(t.setHeader("Allow","POST"),t.status(405).end("Method Not Allowed"));let{event:r,session:s}=e.body;if(!r)throw new Error("Auth event missing!");if(r==="SIGNED_IN"){if(!s)throw new Error("Auth session missing!");X(e,t,[{key:"access-token",value:s.access_token},{key:"refresh-token",value:s.refresh_token}].map(n=>{var o;return{name:`${this.cookieName()}-${n.key}`,value:n.value,domain:this.cookieOptions.domain,maxAge:(o=this.cookieOptions.lifetime)!==null&&o!==void 0?o:0,path:this.cookieOptions.path,sameSite:this.cookieOptions.sameSite}}))}r==="SIGNED_OUT"&&X(e,t,["access-token","refresh-token"].map(n=>({name:`${this.cookieName()}-${n}`,value:"",maxAge:-1}))),t.status(200).json({})}deleteAuthCookie(e,t,{redirectTo:r="/"}){return X(e,t,["access-token","refresh-token"].map(s=>({name:`${this.cookieName()}-${s}`,value:"",maxAge:-1}))),t.redirect(307,r)}getAuthCookieString(e,t){e.method!=="POST"&&(t.setHeader("Allow","POST"),t.status(405).end("Method Not Allowed"));let{event:r,session:s}=e.body;if(!r)throw new Error("Auth event missing!");if(r==="SIGNED_IN"){if(!s)throw new Error("Auth session missing!");return de(e,t,[{key:"access-token",value:s.access_token},{key:"refresh-token",value:s.refresh_token}].map(n=>{var o;return{name:`${this.cookieName()}-${n.key}`,value:n.value,domain:this.cookieOptions.domain,maxAge:(o=this.cookieOptions.lifetime)!==null&&o!==void 0?o:0,path:this.cookieOptions.path,sameSite:this.cookieOptions.sameSite}}))}return r==="SIGNED_OUT"?de(e,t,["access-token","refresh-token"].map(n=>({name:`${this.cookieName()}-${n}`,value:"",maxAge:-1}))):t.getHeader("Set-Cookie")}generateLink(e,t,r={}){return y(this,void 0,void 0,function*(){try{return{data:yield _(this.fetch,`${this.url}/admin/generate_link`,{type:e,email:t,password:r.password,data:r.data,redirect_to:r.redirectTo},{headers:this.headers}),error:null}}catch(s){return{data:null,error:s}}})}createUser(e){return y(this,void 0,void 0,function*(){try{let t=yield _(this.fetch,`${this.url}/admin/users`,e,{headers:this.headers});return{user:t,data:t,error:null}}catch(t){return{user:null,data:null,error:t}}})}listUsers(){return y(this,void 0,void 0,function*(){try{return{data:(yield le(this.fetch,`${this.url}/admin/users`,{headers:this.headers})).users,error:null}}catch(e){return{data:null,error:e}}})}getUserById(e){return y(this,void 0,void 0,function*(){try{return{data:yield le(this.fetch,`${this.url}/admin/users/${e}`,{headers:this.headers}),error:null}}catch(t){return{data:null,error:t}}})}getUserByCookie(e,t){return y(this,void 0,void 0,function*(){try{if(!e.cookies)throw new Error("Not able to parse cookies! When using Express make sure the cookie-parser middleware is in use!");let r=e.cookies[`${this.cookieName()}-access-token`],s=e.cookies[`${this.cookieName()}-refresh-token`];if(!r)throw new Error("No cookie found!");let{user:n,error:o}=yield this.getUser(r);if(o){if(!s)throw new Error("No refresh_token cookie found!");if(!t)throw new Error("You need to pass the res object to automatically refresh the session!");let{data:a,error:u}=yield this.refreshAccessToken(s);if(u)throw u;if(a)return X(e,t,[{key:"access-token",value:a.access_token},{key:"refresh-token",value:a.refresh_token}].map(d=>{var h;return{name:`${this.cookieName()}-${d.key}`,value:d.value,domain:this.cookieOptions.domain,maxAge:(h=this.cookieOptions.lifetime)!==null&&h!==void 0?h:0,path:this.cookieOptions.path,sameSite:this.cookieOptions.sameSite}})),{token:a.access_token,user:a.user,data:a.user,error:null}}return{token:r,user:n,data:n,error:null}}catch(r){return{token:null,user:null,data:null,error:r}}})}updateUserById(e,t){return y(this,void 0,void 0,function*(){try{let r=yield $e(this.fetch,`${this.url}/admin/users/${e}`,t,{headers:this.headers});return{user:r,data:r,error:null}}catch(r){return{user:null,data:null,error:r}}})}deleteUser(e){return y(this,void 0,void 0,function*(){try{let t=yield Ke(this.fetch,`${this.url}/admin/users/${e}`,{},{headers:this.headers});return{user:t,data:t,error:null}}catch(t){return{user:null,data:null,error:t}}})}getUser(e){return y(this,void 0,void 0,function*(){try{let t=yield le(this.fetch,`${this.url}/user`,{headers:this._createRequestHeaders(e)});return{user:t,data:t,error:null}}catch(t){return{user:null,data:null,error:t}}})}updateUser(e,t){return y(this,void 0,void 0,function*(){try{let r=yield $e(this.fetch,`${this.url}/user`,t,{headers:this._createRequestHeaders(e)});return{user:r,data:r,error:null}}catch(r){return{user:null,data:null,error:r}}})}};function it(){if(typeof globalThis!="object")try{Object.defineProperty(Object.prototype,"__magic__",{get:function(){return this},configurable:!0}),__magic__.globalThis=__magic__,delete Object.prototype.__magic__}catch{typeof self<"u"&&(self.globalThis=self)}}var E=function(i,e,t,r){function s(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function a(h){try{d(r.next(h))}catch(f){o(f)}}function u(h){try{d(r.throw(h))}catch(f){o(f)}}function d(h){h.done?n(h.value):s(h.value).then(a,u)}d((r=r.apply(i,e||[])).next())})};it();var Zt={url:Ye,autoRefreshToken:!0,persistSession:!0,detectSessionInUrl:!0,multiTab:!0,headers:Xe},Z=class{constructor(e){this.stateChangeEmitters=new Map;let t=Object.assign(Object.assign({},Zt),e);this.currentUser=null,this.currentSession=null,this.autoRefreshToken=t.autoRefreshToken,this.persistSession=t.persistSession,this.multiTab=t.multiTab,this.localStorage=t.localStorage||globalThis.localStorage,this.api=new Q({url:t.url,headers:t.headers,cookieOptions:t.cookieOptions,fetch:t.fetch}),this._recoverSession(),this._recoverAndRefresh(),this._listenForMultiTabEvents(),t.detectSessionInUrl&&j()&&!!P("access_token")&&this.getSessionFromUrl({storeSession:!0}).then(({error:r})=>{r&&console.error("Error getting session from URL.",r)})}signUp({email:e,password:t,phone:r},s={}){return E(this,void 0,void 0,function*(){try{this._removeSession();let{data:n,error:o}=r&&t?yield this.api.signUpWithPhone(r,t,{data:s.data,captchaToken:s.captchaToken}):yield this.api.signUpWithEmail(e,t,{redirectTo:s.redirectTo,data:s.data,captchaToken:s.captchaToken});if(o)throw o;if(!n)throw"An error occurred on sign up.";let a=null,u=null;return n.access_token&&(a=n,u=a.user,this._saveSession(a),this._notifyAllSubscribers("SIGNED_IN")),n.id&&(u=n),{user:u,session:a,error:null}}catch(n){return{user:null,session:null,error:n}}})}signIn({email:e,phone:t,password:r,refreshToken:s,provider:n,oidc:o},a={}){return E(this,void 0,void 0,function*(){try{if(this._removeSession(),e&&!r){let{error:u}=yield this.api.sendMagicLinkEmail(e,{redirectTo:a.redirectTo,shouldCreateUser:a.shouldCreateUser,captchaToken:a.captchaToken});return{user:null,session:null,error:u}}if(e&&r)return this._handleEmailSignIn(e,r,{redirectTo:a.redirectTo});if(t&&!r){let{error:u}=yield this.api.sendMobileOTP(t,{shouldCreateUser:a.shouldCreateUser,captchaToken:a.captchaToken});return{user:null,session:null,error:u}}if(t&&r)return this._handlePhoneSignIn(t,r);if(s){let{error:u}=yield this._callRefreshToken(s);if(u)throw u;return{user:this.currentUser,session:this.currentSession,error:null}}if(n)return this._handleProviderSignIn(n,{redirectTo:a.redirectTo,scopes:a.scopes});if(o)return this._handleOpenIDConnectSignIn(o);throw new Error("You must provide either an email, phone number, a third-party provider or OpenID Connect.")}catch(u){return{user:null,session:null,error:u}}})}verifyOTP(e,t={}){return E(this,void 0,void 0,function*(){try{this._removeSession();let{data:r,error:s}=yield this.api.verifyOTP(e,t);if(s)throw s;if(!r)throw"An error occurred on token verification.";let n=null,o=null;return r.access_token&&(n=r,o=n.user,this._saveSession(n),this._notifyAllSubscribers("SIGNED_IN")),r.id&&(o=r),{user:o,session:n,error:null}}catch(r){return{user:null,session:null,error:r}}})}user(){return this.currentUser}session(){return this.currentSession}refreshSession(){var e;return E(this,void 0,void 0,function*(){try{if(!(!((e=this.currentSession)===null||e===void 0)&&e.access_token))throw new Error("Not logged in.");let{error:t}=yield this._callRefreshToken();if(t)throw t;return{data:this.currentSession,user:this.currentUser,error:null}}catch(t){return{data:null,user:null,error:t}}})}update(e){var t;return E(this,void 0,void 0,function*(){try{if(!(!((t=this.currentSession)===null||t===void 0)&&t.access_token))throw new Error("Not logged in.");let{user:r,error:s}=yield this.api.updateUser(this.currentSession.access_token,e);if(s)throw s;if(!r)throw Error("Invalid user data.");let n=Object.assign(Object.assign({},this.currentSession),{user:r});return this._saveSession(n),this._notifyAllSubscribers("USER_UPDATED"),{data:r,user:r,error:null}}catch(r){return{data:null,user:null,error:r}}})}setSession(e){return E(this,void 0,void 0,function*(){try{if(!e)throw new Error("No current session.");let{data:t,error:r}=yield this.api.refreshAccessToken(e);return r?{session:null,error:r}:(this._saveSession(t),this._notifyAllSubscribers("SIGNED_IN"),{session:t,error:null})}catch(t){return{error:t,session:null}}})}setAuth(e){return this.currentSession=Object.assign(Object.assign({},this.currentSession),{access_token:e,token_type:"bearer",user:null}),this.currentSession}getSessionFromUrl(e){return E(this,void 0,void 0,function*(){try{if(!j())throw new Error("No browser detected.");let t=P("error_description");if(t)throw new Error(t);let r=P("provider_token"),s=P("access_token");if(!s)throw new Error("No access_token detected.");let n=P("expires_in");if(!n)throw new Error("No expires_in detected.");let o=P("refresh_token");if(!o)throw new Error("No refresh_token detected.");let a=P("token_type");if(!a)throw new Error("No token_type detected.");let d=Math.round(Date.now()/1e3)+parseInt(n),{user:h,error:f}=yield this.api.getUser(s);if(f)throw f;let S={provider_token:r,access_token:s,expires_in:parseInt(n),expires_at:d,refresh_token:o,token_type:a,user:h};if(e!=null&&e.storeSession){this._saveSession(S);let T=P("type");this._notifyAllSubscribers("SIGNED_IN"),T==="recovery"&&this._notifyAllSubscribers("PASSWORD_RECOVERY")}return window.location.hash="",{data:S,error:null}}catch(t){return{data:null,error:t}}})}signOut(){var e;return E(this,void 0,void 0,function*(){let t=(e=this.currentSession)===null||e===void 0?void 0:e.access_token;if(this._removeSession(),this._notifyAllSubscribers("SIGNED_OUT"),t){let{error:r}=yield this.api.signOut(t);if(r)return{error:r}}return{error:null}})}onAuthStateChange(e){try{let t=rt(),r={id:t,callback:e,unsubscribe:()=>{this.stateChangeEmitters.delete(t)}};return this.stateChangeEmitters.set(t,r),{data:r,error:null}}catch(t){return{data:null,error:t}}}_handleEmailSignIn(e,t,r={}){var s,n;return E(this,void 0,void 0,function*(){try{let{data:o,error:a}=yield this.api.signInWithEmail(e,t,{redirectTo:r.redirectTo});return a||!o?{data:null,user:null,session:null,error:a}:((((s=o==null?void 0:o.user)===null||s===void 0?void 0:s.confirmed_at)||((n=o==null?void 0:o.user)===null||n===void 0?void 0:n.email_confirmed_at))&&(this._saveSession(o),this._notifyAllSubscribers("SIGNED_IN")),{data:o,user:o.user,session:o,error:null})}catch(o){return{data:null,user:null,session:null,error:o}}})}_handlePhoneSignIn(e,t){var r;return E(this,void 0,void 0,function*(){try{let{data:s,error:n}=yield this.api.signInWithPhone(e,t);return n||!s?{data:null,user:null,session:null,error:n}:(!((r=s==null?void 0:s.user)===null||r===void 0)&&r.phone_confirmed_at&&(this._saveSession(s),this._notifyAllSubscribers("SIGNED_IN")),{data:s,user:s.user,session:s,error:null})}catch(s){return{data:null,user:null,session:null,error:s}}})}_handleProviderSignIn(e,t={}){let r=this.api.getUrlForProvider(e,{redirectTo:t.redirectTo,scopes:t.scopes});try{return j()&&(window.location.href=r),{provider:e,url:r,data:null,session:null,user:null,error:null}}catch(s){return r?{provider:e,url:r,data:null,session:null,user:null,error:null}:{data:null,user:null,session:null,error:s}}}_handleOpenIDConnectSignIn({id_token:e,nonce:t,client_id:r,issuer:s,provider:n}){return E(this,void 0,void 0,function*(){if(e&&t&&(r&&s||n))try{let{data:o,error:a}=yield this.api.signInWithOpenIDConnect({id_token:e,nonce:t,client_id:r,issuer:s,provider:n});return a||!o?{user:null,session:null,error:a}:(this._saveSession(o),this._notifyAllSubscribers("SIGNED_IN"),{user:o.user,session:o,error:null})}catch(o){return{user:null,session:null,error:o}}throw new Error("You must provide a OpenID Connect provider with your id token and nonce.")})}_recoverSession(){var e;try{let t=j()&&((e=this.localStorage)===null||e===void 0?void 0:e.getItem(F));if(!t||typeof t!="string")return null;let r=JSON.parse(t),{currentSession:s,expiresAt:n}=r,o=Math.round(Date.now()/1e3);n>=o&&(s==null?void 0:s.user)&&(this._saveSession(s),this._notifyAllSubscribers("SIGNED_IN"))}catch(t){console.log("error",t)}}_recoverAndRefresh(){return E(this,void 0,void 0,function*(){try{let e=j()&&(yield this.localStorage.getItem(F));if(!e)return null;let t=JSON.parse(e),{currentSession:r,expiresAt:s}=t,n=Math.round(Date.now()/1e3);if(s<n)if(this.autoRefreshToken&&r.refresh_token){let{error:o}=yield this._callRefreshToken(r.refresh_token);o&&(console.log(o.message),yield this._removeSession())}else this._removeSession();else r?(this._saveSession(r),this._notifyAllSubscribers("SIGNED_IN")):(console.log("Current session is missing data."),this._removeSession())}catch(e){return console.error(e),null}})}_callRefreshToken(e){var t;return e===void 0&&(e=(t=this.currentSession)===null||t===void 0?void 0:t.refresh_token),E(this,void 0,void 0,function*(){try{if(!e)throw new Error("No current session.");let{data:r,error:s}=yield this.api.refreshAccessToken(e);if(s)throw s;if(!r)throw Error("Invalid session data.");return this._saveSession(r),this._notifyAllSubscribers("TOKEN_REFRESHED"),this._notifyAllSubscribers("SIGNED_IN"),{data:r,error:null}}catch(r){return{data:null,error:r}}})}_notifyAllSubscribers(e){this.stateChangeEmitters.forEach(t=>t.callback(e,this.currentSession))}_saveSession(e){this.currentSession=e,this.currentUser=e.user;let t=e.expires_at;if(t){let r=Math.round(Date.now()/1e3),s=t-r,n=s>60?60:.5;this._startAutoRefreshToken((s-n)*1e3)}this.persistSession&&e.expires_at&&this._persistSession(this.currentSession)}_persistSession(e){let t={currentSession:e,expiresAt:e.expires_at};j()&&this.localStorage.setItem(F,JSON.stringify(t))}_removeSession(){return E(this,void 0,void 0,function*(){this.currentSession=null,this.currentUser=null,this.refreshTokenTimer&&clearTimeout(this.refreshTokenTimer),j()&&(yield this.localStorage.removeItem(F))})}_startAutoRefreshToken(e){this.refreshTokenTimer&&clearTimeout(this.refreshTokenTimer),!(e<=0||!this.autoRefreshToken)&&(this.refreshTokenTimer=setTimeout(()=>this._callRefreshToken(),e),typeof this.refreshTokenTimer.unref=="function"&&this.refreshTokenTimer.unref())}_listenForMultiTabEvents(){if(!this.multiTab||!j()||!(window!=null&&window.addEventListener))return!1;try{window==null||window.addEventListener("storage",e=>{var t;if(e.key===F){let r=JSON.parse(String(e.newValue));!((t=r==null?void 0:r.currentSession)===null||t===void 0)&&t.access_token?(this._recoverAndRefresh(),this._notifyAllSubscribers("SIGNED_IN")):(this._removeSession(),this._notifyAllSubscribers("SIGNED_OUT"))}})}catch(e){console.error("_listenForMultiTabEvents",e)}}};var Ae=class extends Z{constructor(e){super(e)}};var nt=he(pe()),er=function(i,e,t,r){function s(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function a(h){try{d(r.next(h))}catch(f){o(f)}}function u(h){try{d(r.throw(h))}catch(f){o(f)}}function d(h){h.done?n(h.value):s(h.value).then(a,u)}d((r=r.apply(i,e||[])).next())})},I=class{constructor(e){Object.assign(this,e);let t;e.fetch?t=e.fetch:typeof fetch>"u"?t=nt.default:t=fetch,this.fetch=(...r)=>t(...r),this.shouldThrowOnError=e.shouldThrowOnError||!1}throwOnError(e){return e==null&&(e=!0),this.shouldThrowOnError=e,this}then(e,t){typeof this.schema>"u"||(["GET","HEAD"].includes(this.method)?this.headers["Accept-Profile"]=this.schema:this.headers["Content-Profile"]=this.schema),this.method!=="GET"&&this.method!=="HEAD"&&(this.headers["Content-Type"]="application/json");let r=this.fetch(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(s=>er(this,void 0,void 0,function*(){var n,o,a;let u=null,d=null,h=null;if(s.ok){let S=(n=this.headers.Prefer)===null||n===void 0?void 0:n.split(",").includes("return=minimal");if(this.method!=="HEAD"&&!S){let W=yield s.text();W&&(this.headers.Accept==="text/csv"?d=W:d=JSON.parse(W))}let T=(o=this.headers.Prefer)===null||o===void 0?void 0:o.match(/count=(exact|planned|estimated)/),z=(a=s.headers.get("content-range"))===null||a===void 0?void 0:a.split("/");T&&z&&z.length>1&&(h=parseInt(z[1]))}else{let S=yield s.text();try{u=JSON.parse(S)}catch{u={message:S}}if(u&&this.shouldThrowOnError)throw u}return{error:u,data:d,count:h,status:s.status,statusText:s.statusText,body:d}}));return this.shouldThrowOnError||(r=r.catch(s=>({error:{message:`FetchError: ${s.message}`,details:"",hint:"",code:s.code||""},data:null,body:null,count:null,status:400,statusText:"Bad Request"}))),r.then(e,t)}};var M=class extends I{select(e="*"){let t=!1,r=e.split("").map(s=>/\s/.test(s)&&!t?"":(s==='"'&&(t=!t),s)).join("");return this.url.searchParams.set("select",r),this}order(e,{ascending:t=!0,nullsFirst:r=!1,foreignTable:s}={}){let n=typeof s>"u"?"order":`${s}.order`,o=this.url.searchParams.get(n);return this.url.searchParams.set(n,`${o?`${o},`:""}${e}.${t?"asc":"desc"}.${r?"nullsfirst":"nullslast"}`),this}limit(e,{foreignTable:t}={}){let r=typeof t>"u"?"limit":`${t}.limit`;return this.url.searchParams.set(r,`${e}`),this}range(e,t,{foreignTable:r}={}){let s=typeof r>"u"?"offset":`${r}.offset`,n=typeof r>"u"?"limit":`${r}.limit`;return this.url.searchParams.set(s,`${e}`),this.url.searchParams.set(n,`${t-e+1}`),this}abortSignal(e){return this.signal=e,this}single(){return this.headers.Accept="application/vnd.pgrst.object+json",this}maybeSingle(){this.headers.Accept="application/vnd.pgrst.object+json";let e=new M(this);return e.then=(t,r)=>this.then(s=>{var n,o;return!((o=(n=s.error)===null||n===void 0?void 0:n.details)===null||o===void 0)&&o.includes("Results contain 0 rows")?t({error:null,data:null,count:s.count,status:200,statusText:"OK",body:null}):t(s)},r),e}csv(){return this.headers.Accept="text/csv",this}};var k=class extends M{constructor(){super(...arguments);this.cs=this.contains,this.cd=this.containedBy,this.sl=this.rangeLt,this.sr=this.rangeGt,this.nxl=this.rangeGte,this.nxr=this.rangeLte,this.adj=this.rangeAdjacent,this.ov=this.overlaps}not(e,t,r){return this.url.searchParams.append(`${e}`,`not.${t}.${r}`),this}or(e,{foreignTable:t}={}){let r=typeof t>"u"?"or":`${t}.or`;return this.url.searchParams.append(r,`(${e})`),this}eq(e,t){return this.url.searchParams.append(`${e}`,`eq.${t}`),this}neq(e,t){return this.url.searchParams.append(`${e}`,`neq.${t}`),this}gt(e,t){return this.url.searchParams.append(`${e}`,`gt.${t}`),this}gte(e,t){return this.url.searchParams.append(`${e}`,`gte.${t}`),this}lt(e,t){return this.url.searchParams.append(`${e}`,`lt.${t}`),this}lte(e,t){return this.url.searchParams.append(`${e}`,`lte.${t}`),this}like(e,t){return this.url.searchParams.append(`${e}`,`like.${t}`),this}ilike(e,t){return this.url.searchParams.append(`${e}`,`ilike.${t}`),this}is(e,t){return this.url.searchParams.append(`${e}`,`is.${t}`),this}in(e,t){let r=t.map(s=>typeof s=="string"&&new RegExp("[,()]").test(s)?`"${s}"`:`${s}`).join(",");return this.url.searchParams.append(`${e}`,`in.(${r})`),this}contains(e,t){return typeof t=="string"?this.url.searchParams.append(`${e}`,`cs.${t}`):Array.isArray(t)?this.url.searchParams.append(`${e}`,`cs.{${t.join(",")}}`):this.url.searchParams.append(`${e}`,`cs.${JSON.stringify(t)}`),this}containedBy(e,t){return typeof t=="string"?this.url.searchParams.append(`${e}`,`cd.${t}`):Array.isArray(t)?this.url.searchParams.append(`${e}`,`cd.{${t.join(",")}}`):this.url.searchParams.append(`${e}`,`cd.${JSON.stringify(t)}`),this}rangeLt(e,t){return this.url.searchParams.append(`${e}`,`sl.${t}`),this}rangeGt(e,t){return this.url.searchParams.append(`${e}`,`sr.${t}`),this}rangeGte(e,t){return this.url.searchParams.append(`${e}`,`nxl.${t}`),this}rangeLte(e,t){return this.url.searchParams.append(`${e}`,`nxr.${t}`),this}rangeAdjacent(e,t){return this.url.searchParams.append(`${e}`,`adj.${t}`),this}overlaps(e,t){return typeof t=="string"?this.url.searchParams.append(`${e}`,`ov.${t}`):this.url.searchParams.append(`${e}`,`ov.{${t.join(",")}}`),this}textSearch(e,t,{config:r,type:s=null}={}){let n="";s==="plain"?n="pl":s==="phrase"?n="ph":s==="websearch"&&(n="w");let o=r===void 0?"":`(${r})`;return this.url.searchParams.append(`${e}`,`${n}fts${o}.${t}`),this}fts(e,t,{config:r}={}){let s=typeof r>"u"?"":`(${r})`;return this.url.searchParams.append(`${e}`,`fts${s}.${t}`),this}plfts(e,t,{config:r}={}){let s=typeof r>"u"?"":`(${r})`;return this.url.searchParams.append(`${e}`,`plfts${s}.${t}`),this}phfts(e,t,{config:r}={}){let s=typeof r>"u"?"":`(${r})`;return this.url.searchParams.append(`${e}`,`phfts${s}.${t}`),this}wfts(e,t,{config:r}={}){let s=typeof r>"u"?"":`(${r})`;return this.url.searchParams.append(`${e}`,`wfts${s}.${t}`),this}filter(e,t,r){return this.url.searchParams.append(`${e}`,`${t}.${r}`),this}match(e){return Object.keys(e).forEach(t=>{this.url.searchParams.append(`${t}`,`eq.${e[t]}`)}),this}};var B=class extends I{constructor(e,{headers:t={},schema:r,fetch:s,shouldThrowOnError:n}={}){super({fetch:s,shouldThrowOnError:n});this.url=new URL(e),this.headers=Object.assign({},t),this.schema=r}select(e="*",{head:t=!1,count:r=null}={}){this.method="GET";let s=!1,n=e.split("").map(o=>/\s/.test(o)&&!s?"":(o==='"'&&(s=!s),o)).join("");return this.url.searchParams.set("select",n),r&&(this.headers.Prefer=`count=${r}`),t&&(this.method="HEAD"),new k(this)}insert(e,{upsert:t=!1,onConflict:r,returning:s="representation",count:n=null}={}){this.method="POST";let o=[`return=${s}`];if(t&&o.push("resolution=merge-duplicates"),t&&r!==void 0&&this.url.searchParams.set("on_conflict",r),this.body=e,n&&o.push(`count=${n}`),this.headers.Prefer&&o.unshift(this.headers.Prefer),this.headers.Prefer=o.join(","),Array.isArray(e)){let a=e.reduce((u,d)=>u.concat(Object.keys(d)),[]);if(a.length>0){let u=[...new Set(a)].map(d=>`"${d}"`);this.url.searchParams.set("columns",u.join(","))}}return new k(this)}upsert(e,{onConflict:t,returning:r="representation",count:s=null,ignoreDuplicates:n=!1}={}){this.method="POST";let o=[`resolution=${n?"ignore":"merge"}-duplicates`,`return=${r}`];return t!==void 0&&this.url.searchParams.set("on_conflict",t),this.body=e,s&&o.push(`count=${s}`),this.headers.Prefer&&o.unshift(this.headers.Prefer),this.headers.Prefer=o.join(","),new k(this)}update(e,{returning:t="representation",count:r=null}={}){this.method="PATCH";let s=[`return=${t}`];return this.body=e,r&&s.push(`count=${r}`),this.headers.Prefer&&s.unshift(this.headers.Prefer),this.headers.Prefer=s.join(","),new k(this)}delete({returning:e="representation",count:t=null}={}){this.method="DELETE";let r=[`return=${e}`];return t&&r.push(`count=${t}`),this.headers.Prefer&&r.unshift(this.headers.Prefer),this.headers.Prefer=r.join(","),new k(this)}};var me=class extends I{constructor(e,{headers:t={},schema:r,fetch:s,shouldThrowOnError:n}={}){super({fetch:s,shouldThrowOnError:n});this.url=new URL(e),this.headers=Object.assign({},t),this.schema=r}rpc(e,{head:t=!1,count:r=null}={}){return t?(this.method="HEAD",e&&Object.entries(e).forEach(([s,n])=>{this.url.searchParams.append(s,n)})):(this.method="POST",this.body=e),r&&(this.headers.Prefer!==void 0?this.headers.Prefer+=`,count=${r}`:this.headers.Prefer=`count=${r}`),new k(this)}};var ot="0.37.1";var at={"X-Client-Info":`postgrest-js/${ot}`};var ee=class{constructor(e,{headers:t={},schema:r,fetch:s,throwOnError:n}={}){this.url=e,this.headers=Object.assign(Object.assign({},at),t),this.schema=r,this.fetch=s,this.shouldThrowOnError=n}auth(e){return this.headers.Authorization=`Bearer ${e}`,this}from(e){let t=`${this.url}/${e}`;return new B(t,{headers:this.headers,schema:this.schema,fetch:this.fetch,shouldThrowOnError:this.shouldThrowOnError})}rpc(e,t,{head:r=!1,count:s=null}={}){let n=`${this.url}/rpc/${e}`;return new me(n,{headers:this.headers,schema:this.schema,fetch:this.fetch,shouldThrowOnError:this.shouldThrowOnError}).rpc(t,{head:r,count:s})}};var te={};qt(te,{PostgresTypes:()=>v,convertCell:()=>je,convertChangeData:()=>tr,convertColumn:()=>ct,toArray:()=>dt,toBoolean:()=>ht,toJson:()=>lt,toNumber:()=>ut,toTimestampString:()=>ft});var v;(function(i){i.abstime="abstime",i.bool="bool",i.date="date",i.daterange="daterange",i.float4="float4",i.float8="float8",i.int2="int2",i.int4="int4",i.int4range="int4range",i.int8="int8",i.int8range="int8range",i.json="json",i.jsonb="jsonb",i.money="money",i.numeric="numeric",i.oid="oid",i.reltime="reltime",i.text="text",i.time="time",i.timestamp="timestamp",i.timestamptz="timestamptz",i.timetz="timetz",i.tsrange="tsrange",i.tstzrange="tstzrange"})(v||(v={}));var tr=(i,e,t={})=>{var r;let s=(r=t.skipTypes)!==null&&r!==void 0?r:[];return Object.keys(e).reduce((n,o)=>(n[o]=ct(o,i,e,s),n),{})},ct=(i,e,t,r)=>{let s=e.find(a=>a.name===i),n=s==null?void 0:s.type,o=t[i];return n&&!r.includes(n)?je(n,o):Re(o)},je=(i,e)=>{if(i.charAt(0)==="_"){let t=i.slice(1,i.length);return dt(e,t)}switch(i){case v.bool:return ht(e);case v.float4:case v.float8:case v.int2:case v.int4:case v.int8:case v.numeric:case v.oid:return ut(e);case v.json:case v.jsonb:return lt(e);case v.timestamp:return ft(e);case v.abstime:case v.date:case v.daterange:case v.int4range:case v.int8range:case v.money:case v.reltime:case v.text:case v.time:case v.timestamptz:case v.timetz:case v.tsrange:case v.tstzrange:return Re(e);default:return Re(e)}},Re=i=>i,ht=i=>{switch(i){case"t":return!0;case"f":return!1;default:return i}},ut=i=>{if(typeof i=="string"){let e=parseFloat(i);if(!Number.isNaN(e))return e}return i},lt=i=>{if(typeof i=="string")try{return JSON.parse(i)}catch(e){return console.log(`JSON parse error: ${e}`),i}return i},dt=(i,e)=>{if(typeof i!="string")return i;let t=i.length-1,r=i[t];if(i[0]==="{"&&r==="}"){let n,o=i.slice(1,t);try{n=JSON.parse("["+o+"]")}catch{n=o?o.split(","):[]}return n.map(a=>je(e,a))}return i},ft=i=>typeof i=="string"?i.replace(" ","T"):i;var pt="1.3.6";var mt={"X-Client-Info":`realtime-js/${pt}`},vt="1.0.0",ye=1e4,yt=1e3,H;(function(i){i[i.connecting=0]="connecting",i[i.open=1]="open",i[i.closing=2]="closing",i[i.closed=3]="closed"})(H||(H={}));var w;(function(i){i.closed="closed",i.errored="errored",i.joined="joined",i.joining="joining",i.leaving="leaving"})(w||(w={}));var x;(function(i){i.close="phx_close",i.error="phx_error",i.join="phx_join",i.reply="phx_reply",i.leave="phx_leave",i.access_token="access_token"})(x||(x={}));var ve;(function(i){i.websocket="websocket"})(ve||(ve={}));var G=class{constructor(e,t){this.callback=e,this.timerCalc=t,this.timer=void 0,this.tries=0,this.callback=e,this.timerCalc=t}reset(){this.tries=0,clearTimeout(this.timer)}scheduleTimeout(){clearTimeout(this.timer),this.timer=setTimeout(()=>{this.tries=this.tries+1,this.callback()},this.timerCalc(this.tries+1))}};var J=class{constructor(e,t,r={},s=ye){this.channel=e,this.event=t,this.payload=r,this.timeout=s,this.sent=!1,this.timeoutTimer=void 0,this.ref="",this.receivedResp=null,this.recHooks=[],this.refEvent=null}resend(e){this.timeout=e,this._cancelRefEvent(),this.ref="",this.refEvent=null,this.receivedResp=null,this.sent=!1,this.send()}send(){this._hasReceived("timeout")||(this.startTimeout(),this.sent=!0,this.channel.socket.push({topic:this.channel.topic,event:this.event,payload:this.payload,ref:this.ref}))}updatePayload(e){this.payload=Object.assign(Object.assign({},this.payload),e)}receive(e,t){var r;return this._hasReceived(e)&&t((r=this.receivedResp)===null||r===void 0?void 0:r.response),this.recHooks.push({status:e,callback:t}),this}startTimeout(){this.timeoutTimer||(this.ref=this.channel.socket.makeRef(),this.refEvent=this.channel.replyEventName(this.ref),this.channel.on(this.refEvent,e=>{this._cancelRefEvent(),this._cancelTimeout(),this.receivedResp=e,this._matchReceive(e)}),this.timeoutTimer=setTimeout(()=>{this.trigger("timeout",{})},this.timeout))}trigger(e,t){this.refEvent&&this.channel.trigger(this.refEvent,{status:e,response:t})}destroy(){this._cancelRefEvent(),this._cancelTimeout()}_cancelRefEvent(){!this.refEvent||this.channel.off(this.refEvent)}_cancelTimeout(){clearTimeout(this.timeoutTimer),this.timeoutTimer=void 0}_matchReceive({status:e,response:t}){this.recHooks.filter(r=>r.status===e).forEach(r=>r.callback(t))}_hasReceived