"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[117],{5973:function(e,t,s){s.r(t),s.d(t,{Headers:function(){return n},Request:function(){return a},Response:function(){return o},fetch:function(){return i}});var r="undefined"!=typeof self?self:window;let i=r.fetch;t.default=r.fetch.bind(r);let n=r.Headers,a=r.Request,o=r.Response},3175:function(e,t){/*!
 * cookie
 * Copyright(c) 2012-2014 Roman Shtylman
 * Copyright(c) 2015 Douglas Christopher Wilson
 * MIT Licensed
 */t.Q=function(e,t){if("string"!=typeof e)throw TypeError("argument str must be a string");for(var s={},r=(t||{}).decode||i,n=0;n<e.length;){var a=e.indexOf("=",n);if(-1===a)break;var o=e.indexOf(";",n);if(-1===o)o=e.length;else if(o<a){n=e.lastIndexOf(";",a-1)+1;continue}var c=e.slice(n,a).trim();if(void 0===s[c]){var l=e.slice(a+1,o).trim();34===l.charCodeAt(0)&&(l=l.slice(1,-1)),s[c]=function(e,t){try{return t(e)}catch(t){return e}}(l,r)}n=o+1}return s},t.q=function(e,t,i){var a=i||{},o=a.encode||n;if("function"!=typeof o)throw TypeError("option encode is invalid");if(!r.test(e))throw TypeError("argument name is invalid");var c=o(t);if(c&&!r.test(c))throw TypeError("argument val is invalid");var l=e+"="+c;if(null!=a.maxAge){var h=a.maxAge-0;if(isNaN(h)||!isFinite(h))throw TypeError("option maxAge is invalid");l+="; Max-Age="+Math.floor(h)}if(a.domain){if(!r.test(a.domain))throw TypeError("option domain is invalid");l+="; Domain="+a.domain}if(a.path){if(!r.test(a.path))throw TypeError("option path is invalid");l+="; Path="+a.path}if(a.expires){var u=a.expires;if("[object Date]"!==s.call(u)&&!(u instanceof Date)||isNaN(u.valueOf()))throw TypeError("option expires is invalid");l+="; Expires="+u.toUTCString()}if(a.httpOnly&&(l+="; HttpOnly"),a.secure&&(l+="; Secure"),a.priority)switch("string"==typeof a.priority?a.priority.toLowerCase():a.priority){case"low":l+="; Priority=Low";break;case"medium":l+="; Priority=Medium";break;case"high":l+="; Priority=High";break;default:throw TypeError("option priority is invalid")}if(a.sameSite)switch("string"==typeof a.sameSite?a.sameSite.toLowerCase():a.sameSite){case!0:case"strict":l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"none":l+="; SameSite=None";break;default:throw TypeError("option sameSite is invalid")}return l};var s=Object.prototype.toString,r=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function i(e){return -1!==e.indexOf("%")?decodeURIComponent(e):e}function n(e){return encodeURIComponent(e)}},7907:function(e,t,s){var r=s(5313);s.o(r,"usePathname")&&s.d(t,{usePathname:function(){return r.usePathname}}),s.o(r,"useRouter")&&s.d(t,{useRouter:function(){return r.useRouter}}),s.o(r,"useSearchParams")&&s.d(t,{useSearchParams:function(){return r.useSearchParams}})},9079:function(e,t,s){var r,i;e.exports=(null==(r=s.g.process)?void 0:r.env)&&"object"==typeof(null==(i=s.g.process)?void 0:i.env)?s.g.process:s(3127)},3472:function(e,t,s){Object.defineProperty(t,"$",{enumerable:!0,get:function(){return i}});let r=s(5355);function i(e){let{createServerReference:t}=s(7355);return t(e,r.callServer)}},3127:function(e){!function(){var t={229:function(e){var t,s,r,i=e.exports={};function n(){throw Error("setTimeout has not been defined")}function a(){throw Error("clearTimeout has not been defined")}function o(e){if(t===setTimeout)return setTimeout(e,0);if((t===n||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(s){try{return t.call(null,e,0)}catch(s){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:n}catch(e){t=n}try{s="function"==typeof clearTimeout?clearTimeout:a}catch(e){s=a}}();var c=[],l=!1,h=-1;function u(){l&&r&&(l=!1,r.length?c=r.concat(c):h=-1,c.length&&d())}function d(){if(!l){var e=o(u);l=!0;for(var t=c.length;t;){for(r=c,c=[];++h<t;)r&&r[h].run();h=-1,t=c.length}r=null,l=!1,function(e){if(s===clearTimeout)return clearTimeout(e);if((s===a||!s)&&clearTimeout)return s=clearTimeout,clearTimeout(e);try{s(e)}catch(t){try{return s.call(null,e)}catch(t){return s.call(this,e)}}}(e)}}function f(e,t){this.fun=e,this.array=t}function p(){}i.nextTick=function(e){var t=Array(arguments.length-1);if(arguments.length>1)for(var s=1;s<arguments.length;s++)t[s-1]=arguments[s];c.push(new f(e,t)),1!==c.length||l||o(d)},f.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=p,i.addListener=p,i.once=p,i.off=p,i.removeListener=p,i.removeAllListeners=p,i.emit=p,i.prependListener=p,i.prependOnceListener=p,i.listeners=function(e){return[]},i.binding=function(e){throw Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw Error("process.chdir is not supported")},i.umask=function(){return 0}}},s={};function r(e){var i=s[e];if(void 0!==i)return i.exports;var n=s[e]={exports:{}},a=!0;try{t[e](n,n.exports,r),a=!1}finally{a&&delete s[e]}return n.exports}r.ab="//";var i=r(229);e.exports=i}()},1880:function(e,t,s){s.d(t,{AY:function(){return tH}});let r=e=>{let t;return t=e||("undefined"==typeof fetch?function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve().then(s.bind(s,5973)).then(e=>{let{default:s}=e;return s(...t)})}:fetch),function(){for(var e=arguments.length,s=Array(e),r=0;r<e;r++)s[r]=arguments[r];return t(...s)}};class i extends Error{constructor(e,t="FunctionsError",s){super(e),this.name=t,this.context=s}}class n extends i{constructor(e){super("Failed to send a request to the Edge Function","FunctionsFetchError",e)}}class a extends i{constructor(e){super("Relay Error invoking the Edge Function","FunctionsRelayError",e)}}class o extends i{constructor(e){super("Edge Function returned a non-2xx status code","FunctionsHttpError",e)}}(l=h||(h={})).Any="any",l.ApNortheast1="ap-northeast-1",l.ApNortheast2="ap-northeast-2",l.ApSouth1="ap-south-1",l.ApSoutheast1="ap-southeast-1",l.ApSoutheast2="ap-southeast-2",l.CaCentral1="ca-central-1",l.EuCentral1="eu-central-1",l.EuWest1="eu-west-1",l.EuWest2="eu-west-2",l.EuWest3="eu-west-3",l.SaEast1="sa-east-1",l.UsEast1="us-east-1",l.UsWest1="us-west-1",l.UsWest2="us-west-2";class c{setAuth(e){this.headers.Authorization="Bearer ".concat(e)}invoke(e){var t,s,r,i,c;let l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return s=this,r=void 0,i=void 0,c=function*(){try{let s;let{headers:r,method:i,body:c}=l,h={},{region:u}=l;u||(u=this.region),u&&"any"!==u&&(h["x-region"]=u),c&&(r&&!Object.prototype.hasOwnProperty.call(r,"Content-Type")||!r)&&("undefined"!=typeof Blob&&c instanceof Blob||c instanceof ArrayBuffer?(h["Content-Type"]="application/octet-stream",s=c):"string"==typeof c?(h["Content-Type"]="text/plain",s=c):"undefined"!=typeof FormData&&c instanceof FormData?s=c:(h["Content-Type"]="application/json",s=JSON.stringify(c)));let d=yield this.fetch("".concat(this.url,"/").concat(e),{method:i||"POST",headers:Object.assign(Object.assign(Object.assign({},h),this.headers),r),body:s}).catch(e=>{throw new n(e)}),f=d.headers.get("x-relay-error");if(f&&"true"===f)throw new a(d);if(!d.ok)throw new o(d);let p=(null!==(t=d.headers.get("Content-Type"))&&void 0!==t?t:"text/plain").split(";")[0].trim();return{data:"application/json"===p?yield d.json():"application/octet-stream"===p?yield d.blob():"text/event-stream"===p?d:"multipart/form-data"===p?yield d.formData():yield d.text(),error:null}}catch(e){return{data:null,error:e}}},new(i||(i=Promise))(function(e,t){function n(e){try{o(c.next(e))}catch(e){t(e)}}function a(e){try{o(c.throw(e))}catch(e){t(e)}}function o(t){var s;t.done?e(t.value):((s=t.value)instanceof i?s:new i(function(e){e(s)})).then(n,a)}o((c=c.apply(s,r||[])).next())})}constructor(e,{headers:t={},customFetch:s,region:i=h.Any}={}){this.url=e,this.headers=t,this.region=i,this.fetch=r(s)}}var l,h,u,d,f,p,g,v,m,y,w,_,b,k,S,T,j,E,O,P,A,x,C=s(5973);class R extends Error{constructor(e){super(e.message),this.name="PostgrestError",this.details=e.details,this.hint=e.hint,this.code=e.code}}class I{throwOnError(){return this.shouldThrowOnError=!0,this}then(e,t){void 0===this.schema||(["GET","HEAD"].includes(this.method)?this.headers["Accept-Profile"]=this.schema:this.headers["Content-Profile"]=this.schema),"GET"!==this.method&&"HEAD"!==this.method&&(this.headers["Content-Type"]="application/json");let s=(0,this.fetch)(this.url.toString(),{method:this.method,headers:this.headers,body:JSON.stringify(this.body),signal:this.signal}).then(async e=>{var t,s,r;let i=null,n=null,a=null,o=e.status,c=e.statusText;if(e.ok){if("HEAD"!==this.method){let t=await e.text();""===t||(n="text/csv"===this.headers.Accept?t:this.headers.Accept&&this.headers.Accept.includes("application/vnd.pgrst.plan+text")?t:JSON.parse(t))}let r=null===(t=this.headers.Prefer)||void 0===t?void 0:t.match(/count=(exact|planned|estimated)/),l=null===(s=e.headers.get("content-range"))||void 0===s?void 0:s.split("/");r&&l&&l.length>1&&(a=parseInt(l[1])),this.isMaybeSingle&&"GET"===this.method&&Array.isArray(n)&&(n.length>1?(i={code:"PGRST116",details:"Results contain ".concat(n.length," rows, application/vnd.pgrst.object+json requires 1 row"),hint:null,message:"JSON object requested, multiple (or no) rows returned"},n=null,a=null,o=406,c="Not Acceptable"):n=1===n.length?n[0]:null)}else{let t=await e.text();try{i=JSON.parse(t),Array.isArray(i)&&404===e.status&&(n=[],i=null,o=200,c="OK")}catch(s){404===e.status&&""===t?(o=204,c="No Content"):i={message:t}}if(i&&this.isMaybeSingle&&(null===(r=null==i?void 0:i.details)||void 0===r?void 0:r.includes("0 rows"))&&(i=null,o=200,c="OK"),i&&this.shouldThrowOnError)throw new R(i)}return{error:i,data:n,count:a,status:o,statusText:c}});return this.shouldThrowOnError||(s=s.catch(e=>{var t,s,r;return{error:{message:"".concat(null!==(t=null==e?void 0:e.name)&&void 0!==t?t:"FetchError",": ").concat(null==e?void 0:e.message),details:"".concat(null!==(s=null==e?void 0:e.stack)&&void 0!==s?s:""),hint:"",code:"".concat(null!==(r=null==e?void 0:e.code)&&void 0!==r?r:"")},data:null,count:null,status:0,statusText:""}})),s.then(e,t)}constructor(e){this.shouldThrowOnError=!1,this.method=e.method,this.url=e.url,this.headers=e.headers,this.schema=e.schema,this.body=e.body,this.shouldThrowOnError=e.shouldThrowOnError,this.signal=e.signal,this.isMaybeSingle=e.isMaybeSingle,e.fetch?this.fetch=e.fetch:"undefined"==typeof fetch?this.fetch=C.default:this.fetch=fetch}}class L extends I{select(e){let t=!1,s=(null!=e?e:"*").split("").map(e=>/\s/.test(e)&&!t?"":('"'===e&&(t=!t),e)).join("");return this.url.searchParams.set("select",s),this.headers.Prefer&&(this.headers.Prefer+=","),this.headers.Prefer+="return=representation",this}order(e){let{ascending:t=!0,nullsFirst:s,foreignTable:r,referencedTable:i=r}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=i?"".concat(i,".order"):"order",a=this.url.searchParams.get(n);return this.url.searchParams.set(n,"".concat(a?"".concat(a,","):"").concat(e,".").concat(t?"asc":"desc").concat(void 0===s?"":s?".nullsfirst":".nullslast")),this}limit(e){let{foreignTable:t,referencedTable:s=t}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.url.searchParams.set(void 0===s?"limit":"".concat(s,".limit"),"".concat(e)),this}range(e,t){let{foreignTable:s,referencedTable:r=s}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=void 0===r?"offset":"".concat(r,".offset"),n=void 0===r?"limit":"".concat(r,".limit");return this.url.searchParams.set(i,"".concat(e)),this.url.searchParams.set(n,"".concat(t-e+1)),this}abortSignal(e){return this.signal=e,this}single(){return this.headers.Accept="application/vnd.pgrst.object+json",this}maybeSingle(){return"GET"===this.method?this.headers.Accept="application/json":this.headers.Accept="application/vnd.pgrst.object+json",this.isMaybeSingle=!0,this}csv(){return this.headers.Accept="text/csv",this}geojson(){return this.headers.Accept="application/geo+json",this}explain(){var e;let{analyze:t=!1,verbose:s=!1,settings:r=!1,buffers:i=!1,wal:n=!1,format:a="text"}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=[t?"analyze":null,s?"verbose":null,r?"settings":null,i?"buffers":null,n?"wal":null].filter(Boolean).join("|"),c=null!==(e=this.headers.Accept)&&void 0!==e?e:"application/json";return this.headers.Accept="application/vnd.pgrst.plan+".concat(a,'; for="').concat(c,'"; options=').concat(o,";"),this}rollback(){var e;return(null!==(e=this.headers.Prefer)&&void 0!==e?e:"").trim().length>0?this.headers.Prefer+=",tx=rollback":this.headers.Prefer="tx=rollback",this}returns(){return this}}class U extends L{eq(e,t){return this.url.searchParams.append(e,"eq.".concat(t)),this}neq(e,t){return this.url.searchParams.append(e,"neq.".concat(t)),this}gt(e,t){return this.url.searchParams.append(e,"gt.".concat(t)),this}gte(e,t){return this.url.searchParams.append(e,"gte.".concat(t)),this}lt(e,t){return this.url.searchParams.append(e,"lt.".concat(t)),this}lte(e,t){return this.url.searchParams.append(e,"lte.".concat(t)),this}like(e,t){return this.url.searchParams.append(e,"like.".concat(t)),this}likeAllOf(e,t){return this.url.searchParams.append(e,"like(all).{".concat(t.join(","),"}")),this}likeAnyOf(e,t){return this.url.searchParams.append(e,"like(any).{".concat(t.join(","),"}")),this}ilike(e,t){return this.url.searchParams.append(e,"ilike.".concat(t)),this}ilikeAllOf(e,t){return this.url.searchParams.append(e,"ilike(all).{".concat(t.join(","),"}")),this}ilikeAnyOf(e,t){return this.url.searchParams.append(e,"ilike(any).{".concat(t.join(","),"}")),this}is(e,t){return this.url.searchParams.append(e,"is.".concat(t)),this}in(e,t){let s=Array.from(new Set(t)).map(e=>"string"==typeof e&&RegExp("[,()]").test(e)?'"'.concat(e,'"'):"".concat(e)).join(",");return this.url.searchParams.append(e,"in.(".concat(s,")")),this}contains(e,t){return"string"==typeof t?this.url.searchParams.append(e,"cs.".concat(t)):Array.isArray(t)?this.url.searchParams.append(e,"cs.{".concat(t.join(","),"}")):this.url.searchParams.append(e,"cs.".concat(JSON.stringify(t))),this}containedBy(e,t){return"string"==typeof t?this.url.searchParams.append(e,"cd.".concat(t)):Array.isArray(t)?this.url.searchParams.append(e,"cd.{".concat(t.join(","),"}")):this.url.searchParams.append(e,"cd.".concat(JSON.stringify(t))),this}rangeGt(e,t){return this.url.searchParams.append(e,"sr.".concat(t)),this}rangeGte(e,t){return this.url.searchParams.append(e,"nxl.".concat(t)),this}rangeLt(e,t){return this.url.searchParams.append(e,"sl.".concat(t)),this}rangeLte(e,t){return this.url.searchParams.append(e,"nxr.".concat(t)),this}rangeAdjacent(e,t){return this.url.searchParams.append(e,"adj.".concat(t)),this}overlaps(e,t){return"string"==typeof t?this.url.searchParams.append(e,"ov.".concat(t)):this.url.searchParams.append(e,"ov.{".concat(t.join(","),"}")),this}textSearch(e,t){let{config:s,type:r}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i="";return"plain"===r?i="pl":"phrase"===r?i="ph":"websearch"===r&&(i="w"),this.url.searchParams.append(e,"".concat(i,"fts").concat(void 0===s?"":"(".concat(s,")"),".").concat(t)),this}match(e){return Object.entries(e).forEach(e=>{let[t,s]=e;this.url.searchParams.append(t,"eq.".concat(s))}),this}not(e,t,s){return this.url.searchParams.append(e,"not.".concat(t,".").concat(s)),this}or(e){let{foreignTable:t,referencedTable:s=t}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.url.searchParams.append(s?"".concat(s,".or"):"or","(".concat(e,")")),this}filter(e,t,s){return this.url.searchParams.append(e,"".concat(t,".").concat(s)),this}}class N{select(e){let{head:t=!1,count:s}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1,i=(null!=e?e:"*").split("").map(e=>/\s/.test(e)&&!r?"":('"'===e&&(r=!r),e)).join("");return this.url.searchParams.set("select",i),s&&(this.headers.Prefer="count=".concat(s)),new U({method:t?"HEAD":"GET",url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch,allowEmpty:!1})}insert(e){let{count:t,defaultToNull:s=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=[];if(this.headers.Prefer&&r.push(this.headers.Prefer),t&&r.push("count=".concat(t)),s||r.push("missing=default"),this.headers.Prefer=r.join(","),Array.isArray(e)){let t=e.reduce((e,t)=>e.concat(Object.keys(t)),[]);if(t.length>0){let e=[...new Set(t)].map(e=>'"'.concat(e,'"'));this.url.searchParams.set("columns",e.join(","))}}return new U({method:"POST",url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:this.fetch,allowEmpty:!1})}upsert(e){let{onConflict:t,ignoreDuplicates:s=!1,count:r,defaultToNull:i=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=["resolution=".concat(s?"ignore":"merge","-duplicates")];if(void 0!==t&&this.url.searchParams.set("on_conflict",t),this.headers.Prefer&&n.push(this.headers.Prefer),r&&n.push("count=".concat(r)),i||n.push("missing=default"),this.headers.Prefer=n.join(","),Array.isArray(e)){let t=e.reduce((e,t)=>e.concat(Object.keys(t)),[]);if(t.length>0){let e=[...new Set(t)].map(e=>'"'.concat(e,'"'));this.url.searchParams.set("columns",e.join(","))}}return new U({method:"POST",url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:this.fetch,allowEmpty:!1})}update(e){let{count:t}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=[];return this.headers.Prefer&&s.push(this.headers.Prefer),t&&s.push("count=".concat(t)),this.headers.Prefer=s.join(","),new U({method:"PATCH",url:this.url,headers:this.headers,schema:this.schema,body:e,fetch:this.fetch,allowEmpty:!1})}delete(){let{count:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=[];return e&&t.push("count=".concat(e)),this.headers.Prefer&&t.unshift(this.headers.Prefer),this.headers.Prefer=t.join(","),new U({method:"DELETE",url:this.url,headers:this.headers,schema:this.schema,fetch:this.fetch,allowEmpty:!1})}constructor(e,{headers:t={},schema:s,fetch:r}){this.url=e,this.headers=t,this.schema=s,this.fetch=r}}let D={"X-Client-Info":"postgrest-js/".concat("1.15.2")};class q{from(e){return new N(new URL("".concat(this.url,"/").concat(e)),{headers:Object.assign({},this.headers),schema:this.schemaName,fetch:this.fetch})}schema(e){return new q(this.url,{headers:this.headers,schema:e,fetch:this.fetch})}rpc(e){let t,s,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},{head:i=!1,get:n=!1,count:a}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=new URL("".concat(this.url,"/rpc/").concat(e));i||n?(t=i?"HEAD":"GET",Object.entries(r).filter(e=>{let[t,s]=e;return void 0!==s}).map(e=>{let[t,s]=e;return[t,Array.isArray(s)?"{".concat(s.join(","),"}"):"".concat(s)]}).forEach(e=>{let[t,s]=e;o.searchParams.append(t,s)})):(t="POST",s=r);let c=Object.assign({},this.headers);return a&&(c.Prefer="count=".concat(a)),new U({method:t,url:o,headers:c,schema:this.schemaName,body:s,fetch:this.fetch,allowEmpty:!1})}constructor(e,{headers:t={},schema:s,fetch:r}={}){this.url=e,this.headers=Object.assign(Object.assign({},D),t),this.schemaName=s,this.fetch=r}}let F={"X-Client-Info":"realtime-js/".concat("2.9.5")};(k=u||(u={}))[k.connecting=0]="connecting",k[k.open=1]="open",k[k.closing=2]="closing",k[k.closed=3]="closed",(S=d||(d={})).closed="closed",S.errored="errored",S.joined="joined",S.joining="joining",S.leaving="leaving",(T=f||(f={})).close="phx_close",T.error="phx_error",T.join="phx_join",T.reply="phx_reply",T.leave="phx_leave",T.access_token="access_token",(p||(p={})).websocket="websocket",(j=g||(g={})).Connecting="connecting",j.Open="open",j.Closing="closing",j.Closed="closed";class z{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))}constructor(e,t){this.callback=e,this.timerCalc=t,this.timer=void 0,this.tries=0,this.callback=e,this.timerCalc=t}}class B{decode(e,t){return e.constructor===ArrayBuffer?t(this._binaryDecode(e)):"string"==typeof e?t(JSON.parse(e)):t({})}_binaryDecode(e){let t=new DataView(e),s=new TextDecoder;return this._decodeBroadcast(e,t,s)}_decodeBroadcast(e,t,s){let r=t.getUint8(1),i=t.getUint8(2),n=this.HEADER_LENGTH+2,a=s.decode(e.slice(n,n+r));n+=r;let o=s.decode(e.slice(n,n+i));return n+=i,{ref:null,topic:a,event:o,payload:JSON.parse(s.decode(e.slice(n,e.byteLength)))}}constructor(){this.HEADER_LENGTH=1}}class M{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,join_ref:this.channel._joinRef()}))}updatePayload(e){this.payload=Object.assign(Object.assign({},this.payload),e)}receive(e,t){var s;return this._hasReceived(e)&&t(null===(s=this.receivedResp)||void 0===s?void 0:s.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(e){let{status:t,response:s}=e;this.recHooks.filter(e=>e.status===t).forEach(e=>e.callback(s))}_hasReceived(e){return this.receivedResp&&this.receivedResp.status===e}constructor(e,t,s={},r=1e4){this.channel=e,this.event=t,this.payload=s,this.timeout=r,this.sent=!1,this.timeoutTimer=void 0,this.ref="",this.receivedResp=null,this.recHooks=[],this.refEvent=null}}(E=v||(v={})).SYNC="sync",E.JOIN="join",E.LEAVE="leave";class J{static syncState(e,t,s,r){let i=this.cloneDeep(e),n=this.transformState(t),a={},o={};return this.map(i,(e,t)=>{n[e]||(o[e]=t)}),this.map(n,(e,t)=>{let s=i[e];if(s){let r=t.map(e=>e.presence_ref),i=s.map(e=>e.presence_ref),n=t.filter(e=>0>i.indexOf(e.presence_ref)),c=s.filter(e=>0>r.indexOf(e.presence_ref));n.length>0&&(a[e]=n),c.length>0&&(o[e]=c)}else a[e]=t}),this.syncDiff(i,{joins:a,leaves:o},s,r)}static syncDiff(e,t,s,r){let{joins:i,leaves:n}={joins:this.transformState(t.joins),leaves:this.transformState(t.leaves)};return s||(s=()=>{}),r||(r=()=>{}),this.map(i,(t,r)=>{var i;let n=null!==(i=e[t])&&void 0!==i?i:[];if(e[t]=this.cloneDeep(r),n.length>0){let s=e[t].map(e=>e.presence_ref),r=n.filter(e=>0>s.indexOf(e.presence_ref));e[t].unshift(...r)}s(t,n,r)}),this.map(n,(t,s)=>{let i=e[t];if(!i)return;let n=s.map(e=>e.presence_ref);i=i.filter(e=>0>n.indexOf(e.presence_ref)),e[t]=i,r(t,i,s),0===i.length&&delete e[t]}),e}static map(e,t){return Object.getOwnPropertyNames(e).map(s=>t(s,e[s]))}static transformState(e){return Object.getOwnPropertyNames(e=this.cloneDeep(e)).reduce((t,s)=>{let r=e[s];return"metas"in r?t[s]=r.metas.map(e=>(e.presence_ref=e.phx_ref,delete e.phx_ref,delete e.phx_ref_prev,e)):t[s]=r,t},{})}static cloneDeep(e){return JSON.parse(JSON.stringify(e))}onJoin(e){this.caller.onJoin=e}onLeave(e){this.caller.onLeave=e}onSync(e){this.caller.onSync=e}inPendingSyncState(){return!this.joinRef||this.joinRef!==this.channel._joinRef()}constructor(e,t){this.channel=e,this.state={},this.pendingDiffs=[],this.joinRef=null,this.caller={onJoin:()=>{},onLeave:()=>{},onSync:()=>{}};let s=(null==t?void 0:t.events)||{state:"presence_state",diff:"presence_diff"};this.channel._on(s.state,{},e=>{let{onJoin:t,onLeave:s,onSync:r}=this.caller;this.joinRef=this.channel._joinRef(),this.state=J.syncState(this.state,e,t,s),this.pendingDiffs.forEach(e=>{this.state=J.syncDiff(this.state,e,t,s)}),this.pendingDiffs=[],r()}),this.channel._on(s.diff,{},e=>{let{onJoin:t,onLeave:s,onSync:r}=this.caller;this.inPendingSyncState()?this.pendingDiffs.push(e):(this.state=J.syncDiff(this.state,e,t,s),r())}),this.onJoin((e,t,s)=>{this.channel._trigger("presence",{event:"join",key:e,currentPresences:t,newPresences:s})}),this.onLeave((e,t,s)=>{this.channel._trigger("presence",{event:"leave",key:e,currentPresences:t,leftPresences:s})}),this.onSync(()=>{this.channel._trigger("presence",{event:"sync"})})}}(O=m||(m={})).abstime="abstime",O.bool="bool",O.date="date",O.daterange="daterange",O.float4="float4",O.float8="float8",O.int2="int2",O.int4="int4",O.int4range="int4range",O.int8="int8",O.int8range="int8range",O.json="json",O.jsonb="jsonb",O.money="money",O.numeric="numeric",O.oid="oid",O.reltime="reltime",O.text="text",O.time="time",O.timestamp="timestamp",O.timestamptz="timestamptz",O.timetz="timetz",O.tsrange="tsrange",O.tstzrange="tstzrange";let K=function(e,t){var s;let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=null!==(s=r.skipTypes)&&void 0!==s?s:[];return Object.keys(t).reduce((s,r)=>(s[r]=H(r,e,t,i),s),{})},H=(e,t,s,r)=>{let i=t.find(t=>t.name===e),n=null==i?void 0:i.type,a=s[e];return n&&!r.includes(n)?G(n,a):V(a)},G=(e,t)=>{if("_"===e.charAt(0))return X(t,e.slice(1,e.length));switch(e){case m.bool:return W(t);case m.float4:case m.float8:case m.int2:case m.int4:case m.int8:case m.numeric:case m.oid:return Y(t);case m.json:case m.jsonb:return $(t);case m.timestamp:return Q(t);case m.abstime:case m.date:case m.daterange:case m.int4range:case m.int8range:case m.money:case m.reltime:case m.text:case m.time:case m.timestamptz:case m.timetz:case m.tsrange:case m.tstzrange:default:return V(t)}},V=e=>e,W=e=>{switch(e){case"t":return!0;case"f":return!1;default:return e}},Y=e=>{if("string"==typeof e){let t=parseFloat(e);if(!Number.isNaN(t))return t}return e},$=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch(e){console.log("JSON parse error: ".concat(e))}return e},X=(e,t)=>{if("string"!=typeof e)return e;let s=e.length-1,r=e[s];if("{"===e[0]&&"}"===r){let r;let i=e.slice(1,s);try{r=JSON.parse("["+i+"]")}catch(e){r=i?i.split(","):[]}return r.map(e=>G(t,e))}return e},Q=e=>"string"==typeof e?e.replace(" ","T"):e;(P=y||(y={})).ALL="*",P.INSERT="INSERT",P.UPDATE="UPDATE",P.DELETE="DELETE",(A=w||(w={})).BROADCAST="broadcast",A.PRESENCE="presence",A.POSTGRES_CHANGES="postgres_changes",(x=_||(_={})).SUBSCRIBED="SUBSCRIBED",x.TIMED_OUT="TIMED_OUT",x.CLOSED="CLOSED",x.CHANNEL_ERROR="CHANNEL_ERROR";class Z{subscribe(e){var t,s;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.timeout;if(this.socket.isConnected()||this.socket.connect(),this.joinedOnce)throw"tried to subscribe multiple times. 'subscribe' can only be called a single time per channel instance";{let{config:{broadcast:i,presence:n}}=this.params;this._onError(t=>e&&e("CHANNEL_ERROR",t)),this._onClose(()=>e&&e("CLOSED"));let a={},o={broadcast:i,presence:n,postgres_changes:null!==(s=null===(t=this.bindings.postgres_changes)||void 0===t?void 0:t.map(e=>e.filter))&&void 0!==s?s:[]};this.socket.accessToken&&(a.access_token=this.socket.accessToken),this.updateJoinPayload(Object.assign({config:o},a)),this.joinedOnce=!0,this._rejoin(r),this.joinPush.receive("ok",t=>{var s;let{postgres_changes:r}=t;if(this.socket.accessToken&&this.socket.setAuth(this.socket.accessToken),void 0===r){e&&e("SUBSCRIBED");return}{let t=this.bindings.postgres_changes,i=null!==(s=null==t?void 0:t.length)&&void 0!==s?s:0,n=[];for(let s=0;s<i;s++){let i=t[s],{filter:{event:a,schema:o,table:c,filter:l}}=i,h=r&&r[s];if(h&&h.event===a&&h.schema===o&&h.table===c&&h.filter===l)n.push(Object.assign(Object.assign({},i),{id:h.id}));else{this.unsubscribe(),e&&e("CHANNEL_ERROR",Error("mismatch between server and client bindings for postgres changes"));return}}this.bindings.postgres_changes=n,e&&e("SUBSCRIBED");return}}).receive("error",t=>{e&&e("CHANNEL_ERROR",Error(JSON.stringify(Object.values(t).join(", ")||"error")))}).receive("timeout",()=>{e&&e("TIMED_OUT")})}return this}presenceState(){return this.presence.state}async track(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return await this.send({type:"presence",event:"track",payload:e},t.timeout||this.timeout)}async untrack(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return await this.send({type:"presence",event:"untrack"},e)}on(e,t,s){return this._on(e,t,s)}async send(e){var t,s;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this._canPush()||"broadcast"!==e.type)return new Promise(t=>{var s,i,n;let a=this._push(e.type,e,r.timeout||this.timeout);"broadcast"!==e.type||(null===(n=null===(i=null===(s=this.params)||void 0===s?void 0:s.config)||void 0===i?void 0:i.broadcast)||void 0===n?void 0:n.ack)||t("ok"),a.receive("ok",()=>t("ok")),a.receive("error",()=>t("error")),a.receive("timeout",()=>t("timed out"))});{let{event:i,payload:n}=e,a={method:"POST",headers:{apikey:null!==(t=this.socket.apiKey)&&void 0!==t?t:"","Content-Type":"application/json"},body:JSON.stringify({messages:[{topic:this.subTopic,event:i,payload:n}]})};try{if((await this._fetchWithTimeout(this.broadcastEndpointURL,a,null!==(s=r.timeout)&&void 0!==s?s:this.timeout)).ok)return"ok";return"error"}catch(e){if("AbortError"===e.name)return"timed out";return"error"}}}updateJoinPayload(e){this.joinPush.updatePayload(e)}unsubscribe(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.timeout;this.state=d.leaving;let t=()=>{this.socket.log("channel","leave ".concat(this.topic)),this._trigger(f.close,"leave",this._joinRef())};return this.rejoinTimer.reset(),this.joinPush.destroy(),new Promise(s=>{let r=new M(this,f.leave,{},e);r.receive("ok",()=>{t(),s("ok")}).receive("timeout",()=>{t(),s("timed out")}).receive("error",()=>{s("error")}),r.send(),this._canPush()||r.trigger("ok",{})})}_broadcastEndpointURL(){let e=this.socket.endPoint;return(e=(e=e.replace(/^ws/i,"http")).replace(/(\/socket\/websocket|\/socket|\/websocket)\/?$/i,"")).replace(/\/+$/,"")+"/api/broadcast"}async _fetchWithTimeout(e,t,s){let r=new AbortController,i=setTimeout(()=>r.abort(),s),n=await this.socket.fetch(e,Object.assign(Object.assign({},t),{signal:r.signal}));return clearTimeout(i),n}_push(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.timeout;if(!this.joinedOnce)throw"tried to push '".concat(e,"' to '").concat(this.topic,"' before joining. Use channel.subscribe() before pushing events");let r=new M(this,e,t,s);return this._canPush()?r.send():(r.startTimeout(),this.pushBuffer.push(r)),r}_onMessage(e,t,s){return t}_isMember(e){return this.topic===e}_joinRef(){return this.joinPush.ref}_trigger(e,t,s){var r,i;let n=e.toLocaleLowerCase(),{close:a,error:o,leave:c,join:l}=f;if(s&&[a,o,c,l].indexOf(n)>=0&&s!==this._joinRef())return;let h=this._onMessage(n,t,s);if(t&&!h)throw"channel onMessage callbacks must return the payload, modified or unmodified";["insert","update","delete"].includes(n)?null===(r=this.bindings.postgres_changes)||void 0===r||r.filter(e=>{var t,s,r;return(null===(t=e.filter)||void 0===t?void 0:t.event)==="*"||(null===(r=null===(s=e.filter)||void 0===s?void 0:s.event)||void 0===r?void 0:r.toLocaleLowerCase())===n}).map(e=>e.callback(h,s)):null===(i=this.bindings[n])||void 0===i||i.filter(e=>{var s,r,i,a,o,c;if(!["broadcast","presence","postgres_changes"].includes(n))return e.type.toLocaleLowerCase()===n;if("id"in e){let n=e.id,a=null===(s=e.filter)||void 0===s?void 0:s.event;return n&&(null===(r=t.ids)||void 0===r?void 0:r.includes(n))&&("*"===a||(null==a?void 0:a.toLocaleLowerCase())===(null===(i=t.data)||void 0===i?void 0:i.type.toLocaleLowerCase()))}{let s=null===(o=null===(a=null==e?void 0:e.filter)||void 0===a?void 0:a.event)||void 0===o?void 0:o.toLocaleLowerCase();return"*"===s||s===(null===(c=null==t?void 0:t.event)||void 0===c?void 0:c.toLocaleLowerCase())}}).map(e=>{if("object"==typeof h&&"ids"in h){let e=h.data,{schema:t,table:s,commit_timestamp:r,type:i,errors:n}=e;h=Object.assign(Object.assign({},{schema:t,table:s,commit_timestamp:r,eventType:i,new:{},old:{},errors:n}),this._getPayloadRecords(e))}e.callback(h,s)})}_isClosed(){return this.state===d.closed}_isJoined(){return this.state===d.joined}_isJoining(){return this.state===d.joining}_isLeaving(){return this.state===d.leaving}_replyEventName(e){return"chan_reply_".concat(e)}_on(e,t,s){let r=e.toLocaleLowerCase(),i={type:r,filter:t,callback:s};return this.bindings[r]?this.bindings[r].push(i):this.bindings[r]=[i],this}_off(e,t){let s=e.toLocaleLowerCase();return this.bindings[s]=this.bindings[s].filter(e=>{var r;return!((null===(r=e.type)||void 0===r?void 0:r.toLocaleLowerCase())===s&&Z.isEqual(e.filter,t))}),this}static isEqual(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let s in e)if(e[s]!==t[s])return!1;return!0}_rejoinUntilConnected(){this.rejoinTimer.scheduleTimeout(),this.socket.isConnected()&&this._rejoin()}_onClose(e){this._on(f.close,{},e)}_onError(e){this._on(f.error,{},t=>e(t))}_canPush(){return this.socket.isConnected()&&this._isJoined()}_rejoin(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.timeout;this._isLeaving()||(this.socket._leaveOpenTopic(this.topic),this.state=d.joining,this.joinPush.resend(e))}_getPayloadRecords(e){let t={new:{},old:{}};return("INSERT"===e.type||"UPDATE"===e.type)&&(t.new=K(e.columns,e.record)),("UPDATE"===e.type||"DELETE"===e.type)&&(t.old=K(e.columns,e.old_record)),t}constructor(e,t={config:{}},s){this.topic=e,this.params=t,this.socket=s,this.bindings={},this.state=d.closed,this.joinedOnce=!1,this.pushBuffer=[],this.subTopic=e.replace(/^realtime:/i,""),this.params.config=Object.assign({broadcast:{ack:!1,self:!1},presence:{key:""}},t.config),this.timeout=this.socket.timeout,this.joinPush=new M(this,f.join,this.params,this.timeout),this.rejoinTimer=new z(()=>this._rejoinUntilConnected(),this.socket.reconnectAfterMs),this.joinPush.receive("ok",()=>{this.state=d.joined,this.rejoinTimer.reset(),this.pushBuffer.forEach(e=>e.send()),this.pushBuffer=[]}),this._onClose(()=>{this.rejoinTimer.reset(),this.socket.log("channel","close ".concat(this.topic," ").concat(this._joinRef())),this.state=d.closed,this.socket._remove(this)}),this._onError(e=>{this._isLeaving()||this._isClosed()||(this.socket.log("channel","error ".concat(this.topic),e),this.state=d.errored,this.rejoinTimer.scheduleTimeout())}),this.joinPush.receive("timeout",()=>{this._isJoining()&&(this.socket.log("channel","timeout ".concat(this.topic),this.joinPush.timeout),this.state=d.errored,this.rejoinTimer.scheduleTimeout())}),this._on(f.reply,{},(e,t)=>{this._trigger(this._replyEventName(t),e)}),this.presence=new J(this),this.broadcastEndpointURL=this._broadcastEndpointURL()}}let ee=()=>{},et="undefined"!=typeof WebSocket;class es{connect(){if(!this.conn){if(this.transport){this.conn=new this.transport(this._endPointURL(),void 0,{headers:this.headers});return}if(et){this.conn=new WebSocket(this._endPointURL()),this.setupConnection();return}this.conn=new er(this._endPointURL(),void 0,{close:()=>{this.conn=null}}),s.e(212).then(s.t.bind(s,8212,23)).then(e=>{let{default:t}=e;this.conn=new t(this._endPointURL(),void 0,{headers:this.headers}),this.setupConnection()})}}disconnect(e,t){this.conn&&(this.conn.onclose=function(){},e?this.conn.close(e,null!=t?t:""):this.conn.close(),this.conn=null,this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.reconnectTimer.reset())}getChannels(){return this.channels}async removeChannel(e){let t=await e.unsubscribe();return 0===this.channels.length&&this.disconnect(),t}async removeAllChannels(){let e=await Promise.all(this.channels.map(e=>e.unsubscribe()));return this.disconnect(),e}log(e,t,s){this.logger(e,t,s)}connectionState(){switch(this.conn&&this.conn.readyState){case u.connecting:return g.Connecting;case u.open:return g.Open;case u.closing:return g.Closing;default:return g.Closed}}isConnected(){return this.connectionState()===g.Open}channel(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:{}},s=new Z("realtime:".concat(e),t,this);return this.channels.push(s),s}push(e){let{topic:t,event:s,payload:r,ref:i}=e,n=()=>{this.encode(e,e=>{var t;null===(t=this.conn)||void 0===t||t.send(e)})};this.log("push","".concat(t," ").concat(s," (").concat(i,")"),r),this.isConnected()?n():this.sendBuffer.push(n)}setAuth(e){this.accessToken=e,this.channels.forEach(t=>{e&&t.updateJoinPayload({access_token:e}),t.joinedOnce&&t._isJoined()&&t._push(f.access_token,{access_token:e})})}_makeRef(){let e=this.ref+1;return e===this.ref?this.ref=0:this.ref=e,this.ref.toString()}_leaveOpenTopic(e){let t=this.channels.find(t=>t.topic===e&&(t._isJoined()||t._isJoining()));t&&(this.log("transport",'leaving duplicate topic "'.concat(e,'"')),t.unsubscribe())}_remove(e){this.channels=this.channels.filter(t=>t._joinRef()!==e._joinRef())}setupConnection(){this.conn&&(this.conn.binaryType="arraybuffer",this.conn.onopen=()=>this._onConnOpen(),this.conn.onerror=e=>this._onConnError(e),this.conn.onmessage=e=>this._onConnMessage(e),this.conn.onclose=e=>this._onConnClose(e))}_endPointURL(){return this._appendParams(this.endPoint,Object.assign({},this.params,{vsn:"1.0.0"}))}_onConnMessage(e){this.decode(e.data,e=>{let{topic:t,event:s,payload:r,ref:i}=e;(i&&i===this.pendingHeartbeatRef||s===(null==r?void 0:r.type))&&(this.pendingHeartbeatRef=null),this.log("receive","".concat(r.status||""," ").concat(t," ").concat(s," ").concat(i&&"("+i+")"||""),r),this.channels.filter(e=>e._isMember(t)).forEach(e=>e._trigger(s,r,i)),this.stateChangeCallbacks.message.forEach(t=>t(e))})}_onConnOpen(){this.log("transport","connected to ".concat(this._endPointURL())),this._flushSendBuffer(),this.reconnectTimer.reset(),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.heartbeatTimer=setInterval(()=>this._sendHeartbeat(),this.heartbeatIntervalMs),this.stateChangeCallbacks.open.forEach(e=>e())}_onConnClose(e){this.log("transport","close",e),this._triggerChanError(),this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.reconnectTimer.scheduleTimeout(),this.stateChangeCallbacks.close.forEach(t=>t(e))}_onConnError(e){this.log("transport",e.message),this._triggerChanError(),this.stateChangeCallbacks.error.forEach(t=>t(e))}_triggerChanError(){this.channels.forEach(e=>e._trigger(f.error))}_appendParams(e,t){if(0===Object.keys(t).length)return e;let s=e.match(/\?/)?"&":"?",r=new URLSearchParams(t);return"".concat(e).concat(s).concat(r)}_flushSendBuffer(){this.isConnected()&&this.sendBuffer.length>0&&(this.sendBuffer.forEach(e=>e()),this.sendBuffer=[])}_sendHeartbeat(){var e;if(this.isConnected()){if(this.pendingHeartbeatRef){this.pendingHeartbeatRef=null,this.log("transport","heartbeat timeout. Attempting to re-establish connection"),null===(e=this.conn)||void 0===e||e.close(1e3,"hearbeat timeout");return}this.pendingHeartbeatRef=this._makeRef(),this.push({topic:"phoenix",event:"heartbeat",payload:{},ref:this.pendingHeartbeatRef}),this.setAuth(this.accessToken)}}constructor(e,t){var r;this.accessToken=null,this.apiKey=null,this.channels=[],this.endPoint="",this.headers=F,this.params={},this.timeout=1e4,this.heartbeatIntervalMs=3e4,this.heartbeatTimer=void 0,this.pendingHeartbeatRef=null,this.ref=0,this.logger=ee,this.conn=null,this.sendBuffer=[],this.serializer=new B,this.stateChangeCallbacks={open:[],close:[],error:[],message:[]},this._resolveFetch=e=>{let t;return t=e||("undefined"==typeof fetch?function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve().then(s.bind(s,5973)).then(e=>{let{default:s}=e;return s(...t)})}:fetch),function(){for(var e=arguments.length,s=Array(e),r=0;r<e;r++)s[r]=arguments[r];return t(...s)}},this.endPoint="".concat(e,"/").concat(p.websocket),(null==t?void 0:t.transport)?this.transport=t.transport:this.transport=null,(null==t?void 0:t.params)&&(this.params=t.params),(null==t?void 0:t.headers)&&(this.headers=Object.assign(Object.assign({},this.headers),t.headers)),(null==t?void 0:t.timeout)&&(this.timeout=t.timeout),(null==t?void 0:t.logger)&&(this.logger=t.logger),(null==t?void 0:t.heartbeatIntervalMs)&&(this.heartbeatIntervalMs=t.heartbeatIntervalMs);let i=null===(r=null==t?void 0:t.params)||void 0===r?void 0:r.apikey;i&&(this.accessToken=i,this.apiKey=i),this.reconnectAfterMs=(null==t?void 0:t.reconnectAfterMs)?t.reconnectAfterMs:e=>[1e3,2e3,5e3,1e4][e-1]||1e4,this.encode=(null==t?void 0:t.encode)?t.encode:(e,t)=>t(JSON.stringify(e)),this.decode=(null==t?void 0:t.decode)?t.decode:this.serializer.decode.bind(this.serializer),this.reconnectTimer=new z(async()=>{this.disconnect(),this.connect()},this.reconnectAfterMs),this.fetch=this._resolveFetch(null==t?void 0:t.fetch)}}class er{constructor(e,t,s){this.binaryType="arraybuffer",this.onclose=()=>{},this.onerror=()=>{},this.onmessage=()=>{},this.onopen=()=>{},this.readyState=u.connecting,this.send=()=>{},this.url=null,this.url=e,this.close=s.close}}class ei extends Error{constructor(e){super(e),this.__isStorageError=!0,this.name="StorageError"}}function en(e){return"object"==typeof e&&null!==e&&"__isStorageError"in e}class ea extends ei{toJSON(){return{name:this.name,message:this.message,status:this.status}}constructor(e,t){super(e),this.name="StorageApiError",this.status=t}}class eo extends ei{constructor(e,t){super(e),this.name="StorageUnknownError",this.originalError=t}}let ec=e=>{let t;return t=e||("undefined"==typeof fetch?function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve().then(s.bind(s,5973)).then(e=>{let{default:s}=e;return s(...t)})}:fetch),function(){for(var e=arguments.length,s=Array(e),r=0;r<e;r++)s[r]=arguments[r];return t(...s)}},el=()=>{var e,t,r,i;return e=void 0,t=void 0,r=void 0,i=function*(){return"undefined"==typeof Response?(yield Promise.resolve().then(s.bind(s,5973))).Response:Response},new(r||(r=Promise))(function(s,n){function a(e){try{c(i.next(e))}catch(e){n(e)}}function o(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?s(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(a,o)}c((i=i.apply(e,t||[])).next())})};var eh=function(e,t,s,r){return new(s||(s=Promise))(function(i,n){function a(e){try{c(r.next(e))}catch(e){n(e)}}function o(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(a,o)}c((r=r.apply(e,t||[])).next())})};let eu=e=>e.msg||e.message||e.error_description||e.error||JSON.stringify(e),ed=(e,t)=>eh(void 0,void 0,void 0,function*(){e instanceof(yield el())?e.json().then(s=>{t(new ea(eu(s),e.status||500))}).catch(e=>{t(new eo(eu(e),e))}):t(new eo(eu(e),e))}),ef=(e,t,s,r)=>{let i={method:e,headers:(null==t?void 0:t.headers)||{}};return"GET"===e?i:(i.headers=Object.assign({"Content-Type":"application/json"},null==t?void 0:t.headers),i.body=JSON.stringify(r),Object.assign(Object.assign({},i),s))};function ep(e,t,s,r,i,n){return eh(this,void 0,void 0,function*(){return new Promise((a,o)=>{e(s,ef(t,r,i,n)).then(e=>{if(!e.ok)throw e;return(null==r?void 0:r.noResolveJson)?e:e.json()}).then(e=>a(e)).catch(e=>ed(e,o))})})}function eg(e,t,s,r){return eh(this,void 0,void 0,function*(){return ep(e,"GET",t,s,r)})}function ev(e,t,s,r,i){return eh(this,void 0,void 0,function*(){return ep(e,"POST",t,r,i,s)})}function em(e,t,s,r,i){return eh(this,void 0,void 0,function*(){return ep(e,"DELETE",t,r,i,s)})}var ey=function(e,t,s,r){return new(s||(s=Promise))(function(i,n){function a(e){try{c(r.next(e))}catch(e){n(e)}}function o(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(a,o)}c((r=r.apply(e,t||[])).next())})};let ew={limit:100,offset:0,sortBy:{column:"name",order:"asc"}},e_={cacheControl:"3600",contentType:"text/plain;charset=UTF-8",upsert:!1};class eb{uploadOrUpdate(e,t,s,r){return ey(this,void 0,void 0,function*(){try{let i;let n=Object.assign(Object.assign({},e_),r),a=Object.assign(Object.assign({},this.headers),"POST"===e&&{"x-upsert":String(n.upsert)});"undefined"!=typeof Blob&&s instanceof Blob?((i=new FormData).append("cacheControl",n.cacheControl),i.append("",s)):"undefined"!=typeof FormData&&s instanceof FormData?(i=s).append("cacheControl",n.cacheControl):(i=s,a["cache-control"]="max-age=".concat(n.cacheControl),a["content-type"]=n.contentType);let o=this._removeEmptyFolders(t),c=this._getFinalPath(o),l=yield this.fetch("".concat(this.url,"/object/").concat(c),Object.assign({method:e,body:i,headers:a},(null==n?void 0:n.duplex)?{duplex:n.duplex}:{})),h=yield l.json();if(l.ok)return{data:{path:o,id:h.Id,fullPath:h.Key},error:null};return{data:null,error:h}}catch(e){if(en(e))return{data:null,error:e};throw e}})}upload(e,t,s){return ey(this,void 0,void 0,function*(){return this.uploadOrUpdate("POST",e,t,s)})}uploadToSignedUrl(e,t,s,r){return ey(this,void 0,void 0,function*(){let i=this._removeEmptyFolders(e),n=this._getFinalPath(i),a=new URL(this.url+"/object/upload/sign/".concat(n));a.searchParams.set("token",t);try{let e;let t=Object.assign({upsert:e_.upsert},r),n=Object.assign(Object.assign({},this.headers),{"x-upsert":String(t.upsert)});"undefined"!=typeof Blob&&s instanceof Blob?((e=new FormData).append("cacheControl",t.cacheControl),e.append("",s)):"undefined"!=typeof FormData&&s instanceof FormData?(e=s).append("cacheControl",t.cacheControl):(e=s,n["cache-control"]="max-age=".concat(t.cacheControl),n["content-type"]=t.contentType);let o=yield this.fetch(a.toString(),{method:"PUT",body:e,headers:n}),c=yield o.json();if(o.ok)return{data:{path:i,fullPath:c.Key},error:null};return{data:null,error:c}}catch(e){if(en(e))return{data:null,error:e};throw e}})}createSignedUploadUrl(e){return ey(this,void 0,void 0,function*(){try{let t=this._getFinalPath(e),s=yield ev(this.fetch,"".concat(this.url,"/object/upload/sign/").concat(t),{},{headers:this.headers}),r=new URL(this.url+s.url),i=r.searchParams.get("token");if(!i)throw new ei("No token returned by API");return{data:{signedUrl:r.toString(),path:e,token:i},error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}update(e,t,s){return ey(this,void 0,void 0,function*(){return this.uploadOrUpdate("PUT",e,t,s)})}move(e,t){return ey(this,void 0,void 0,function*(){try{return{data:yield ev(this.fetch,"".concat(this.url,"/object/move"),{bucketId:this.bucketId,sourceKey:e,destinationKey:t},{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}copy(e,t){return ey(this,void 0,void 0,function*(){try{return{data:{path:(yield ev(this.fetch,"".concat(this.url,"/object/copy"),{bucketId:this.bucketId,sourceKey:e,destinationKey:t},{headers:this.headers})).Key},error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}createSignedUrl(e,t,s){return ey(this,void 0,void 0,function*(){try{let r=this._getFinalPath(e),i=yield ev(this.fetch,"".concat(this.url,"/object/sign/").concat(r),Object.assign({expiresIn:t},(null==s?void 0:s.transform)?{transform:s.transform}:{}),{headers:this.headers}),n=(null==s?void 0:s.download)?"&download=".concat(!0===s.download?"":s.download):"";return{data:i={signedUrl:encodeURI("".concat(this.url).concat(i.signedURL).concat(n))},error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}createSignedUrls(e,t,s){return ey(this,void 0,void 0,function*(){try{let r=yield ev(this.fetch,"".concat(this.url,"/object/sign/").concat(this.bucketId),{expiresIn:t,paths:e},{headers:this.headers}),i=(null==s?void 0:s.download)?"&download=".concat(!0===s.download?"":s.download):"";return{data:r.map(e=>Object.assign(Object.assign({},e),{signedUrl:e.signedURL?encodeURI("".concat(this.url).concat(e.signedURL).concat(i)):null})),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}download(e,t){return ey(this,void 0,void 0,function*(){let s=void 0!==(null==t?void 0:t.transform),r=this.transformOptsToQueryString((null==t?void 0:t.transform)||{});try{let t=this._getFinalPath(e),i=yield eg(this.fetch,"".concat(this.url,"/").concat(s?"render/image/authenticated":"object","/").concat(t).concat(r?"?".concat(r):""),{headers:this.headers,noResolveJson:!0});return{data:yield i.blob(),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}getPublicUrl(e,t){let s=this._getFinalPath(e),r=[],i=(null==t?void 0:t.download)?"download=".concat(!0===t.download?"":t.download):"";""!==i&&r.push(i);let n=void 0!==(null==t?void 0:t.transform),a=this.transformOptsToQueryString((null==t?void 0:t.transform)||{});""!==a&&r.push(a);let o=r.join("&");return""!==o&&(o="?".concat(o)),{data:{publicUrl:encodeURI("".concat(this.url,"/").concat(n?"render/image":"object","/public/").concat(s).concat(o))}}}remove(e){return ey(this,void 0,void 0,function*(){try{return{data:yield em(this.fetch,"".concat(this.url,"/object/").concat(this.bucketId),{prefixes:e},{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}list(e,t,s){return ey(this,void 0,void 0,function*(){try{let r=Object.assign(Object.assign(Object.assign({},ew),t),{prefix:e||""});return{data:yield ev(this.fetch,"".concat(this.url,"/object/list/").concat(this.bucketId),r,{headers:this.headers},s),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}_getFinalPath(e){return"".concat(this.bucketId,"/").concat(e)}_removeEmptyFolders(e){return e.replace(/^\/|\/$/g,"").replace(/\/+/g,"/")}transformOptsToQueryString(e){let t=[];return e.width&&t.push("width=".concat(e.width)),e.height&&t.push("height=".concat(e.height)),e.resize&&t.push("resize=".concat(e.resize)),e.format&&t.push("format=".concat(e.format)),e.quality&&t.push("quality=".concat(e.quality)),t.join("&")}constructor(e,t={},s,r){this.url=e,this.headers=t,this.bucketId=s,this.fetch=ec(r)}}let ek={"X-Client-Info":"storage-js/".concat("2.5.5")};var eS=function(e,t,s,r){return new(s||(s=Promise))(function(i,n){function a(e){try{c(r.next(e))}catch(e){n(e)}}function o(e){try{c(r.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?i(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(a,o)}c((r=r.apply(e,t||[])).next())})};class eT{listBuckets(){return eS(this,void 0,void 0,function*(){try{return{data:yield eg(this.fetch,"".concat(this.url,"/bucket"),{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}getBucket(e){return eS(this,void 0,void 0,function*(){try{return{data:yield eg(this.fetch,"".concat(this.url,"/bucket/").concat(e),{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}createBucket(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{public:!1};return eS(this,void 0,void 0,function*(){try{return{data:yield ev(this.fetch,"".concat(this.url,"/bucket"),{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}updateBucket(e,t){return eS(this,void 0,void 0,function*(){try{return{data:yield function(e,t,s,r,i){return eh(this,void 0,void 0,function*(){return ep(e,"PUT",t,r,void 0,s)})}(this.fetch,"".concat(this.url,"/bucket/").concat(e),{id:e,name:e,public:t.public,file_size_limit:t.fileSizeLimit,allowed_mime_types:t.allowedMimeTypes},{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}emptyBucket(e){return eS(this,void 0,void 0,function*(){try{return{data:yield ev(this.fetch,"".concat(this.url,"/bucket/").concat(e,"/empty"),{},{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}deleteBucket(e){return eS(this,void 0,void 0,function*(){try{return{data:yield em(this.fetch,"".concat(this.url,"/bucket/").concat(e),{},{headers:this.headers}),error:null}}catch(e){if(en(e))return{data:null,error:e};throw e}})}constructor(e,t={},s){this.url=e,this.headers=Object.assign(Object.assign({},ek),t),this.fetch=ec(s)}}class ej extends eT{from(e){return new eb(this.url,this.headers,e,this.fetch)}constructor(e,t={},s){super(e,t,s)}}let eE="";eE="undefined"!=typeof Deno?"deno":"undefined"!=typeof document?"web":"undefined"!=typeof navigator&&"ReactNative"===navigator.product?"react-native":"node";let eO={headers:{"X-Client-Info":"supabase-js-".concat(eE,"/").concat("2.43.0")}},eP={schema:"public"},eA={autoRefreshToken:!0,persistSession:!0,detectSessionInUrl:!0,flowType:"implicit"},ex={},eC=e=>{let t;return t=e||("undefined"==typeof fetch?C.default:fetch),function(){for(var e=arguments.length,s=Array(e),r=0;r<e;r++)s[r]=arguments[r];return t(...s)}},eR=()=>"undefined"==typeof Headers?C.Headers:Headers,eI=(e,t,s)=>{let r=eC(s),i=eR();return(s,n)=>{var a,o,c,l;return a=void 0,o=void 0,c=void 0,l=function*(){var a;let o=null!==(a=yield t())&&void 0!==a?a:e,c=new i(null==n?void 0:n.headers);return c.has("apikey")||c.set("apikey",e),c.has("Authorization")||c.set("Authorization","Bearer ".concat(o)),r(s,Object.assign(Object.assign({},n),{headers:c}))},new(c||(c=Promise))(function(e,t){function s(e){try{i(l.next(e))}catch(e){t(e)}}function r(e){try{i(l.throw(e))}catch(e){t(e)}}function i(t){var i;t.done?e(t.value):((i=t.value)instanceof c?i:new c(function(e){e(i)})).then(s,r)}i((l=l.apply(a,o||[])).next())})}},eL="2.64.1",eU="X-Supabase-Api-Version",eN={"2024-01-01":{timestamp:Date.parse("2024-01-01T00:00:00.0Z"),name:"2024-01-01"}},eD=()=>"undefined"!=typeof document,eq={tested:!1,writable:!1},eF=()=>{if(!eD())return!1;try{if("object"!=typeof globalThis.localStorage)return!1}catch(e){return!1}if(eq.tested)return eq.writable;let e="lswt-".concat(Math.random()).concat(Math.random());try{globalThis.localStorage.setItem(e,e),globalThis.localStorage.removeItem(e),eq.tested=!0,eq.writable=!0}catch(e){eq.tested=!0,eq.writable=!1}return eq.writable};function ez(e){let t={},s=new URL(e);if(s.hash&&"#"===s.hash[0])try{new URLSearchParams(s.hash.substring(1)).forEach((e,s)=>{t[s]=e})}catch(e){}return s.searchParams.forEach((e,s)=>{t[s]=e}),t}let eB=e=>{let t;return t=e||("undefined"==typeof fetch?function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve().then(s.bind(s,5973)).then(e=>{let{default:s}=e;return s(...t)})}:fetch),function(){for(var e=arguments.length,s=Array(e),r=0;r<e;r++)s[r]=arguments[r];return t(...s)}},eM=e=>"object"==typeof e&&null!==e&&"status"in e&&"ok"in e&&"json"in e&&"function"==typeof e.json,eJ=async(e,t,s)=>{await e.setItem(t,JSON.stringify(s))},eK=async(e,t)=>{let s=await e.getItem(t);if(!s)return null;try{return JSON.parse(s)}catch(e){return s}},eH=async(e,t)=>{await e.removeItem(t)};class eG{constructor(){this.promise=new eG.promiseConstructor((e,t)=>{this.resolve=e,this.reject=t})}}function eV(e){let t=e.split(".");if(3!==t.length)throw Error("JWT is not valid: not a JWT structure");if(!/^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}=?$|[a-z0-9_-]{2}(==)?$)$/i.test(t[1]))throw Error("JWT is not valid: payload is not in base64url format");return JSON.parse(function(e){let t,s,r,i,n,a,o;let c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",l="",h=0;for(e=e.replace("-","+").replace("_","/");h<e.length;)i=c.indexOf(e.charAt(h++)),n=c.indexOf(e.charAt(h++)),a=c.indexOf(e.charAt(h++)),o=c.indexOf(e.charAt(h++)),t=i<<2|n>>4,s=(15&n)<<4|a>>2,r=(3&a)<<6|o,l+=String.fromCharCode(t),64!=a&&0!=s&&(l+=String.fromCharCode(s)),64!=o&&0!=r&&(l+=String.fromCharCode(r));return l}(t[1]))}async function eW(e){return await new Promise(t=>{setTimeout(()=>t(null),e)})}function eY(e){return("0"+e.toString(16)).substr(-2)}async function e$(e){let t=new TextEncoder().encode(e),s=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(s)).map(e=>String.fromCharCode(e)).join("")}async function eX(e){return"undefined"!=typeof crypto&&void 0!==crypto.subtle&&"undefined"!=typeof TextEncoder?btoa(await e$(e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""):(console.warn("WebCrypto API is not supported. Code challenge method will default to use plain instead of sha256."),e)}async function eQ(e,t){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=function(){let e=new Uint32Array(56);if("undefined"==typeof crypto){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",t=e.length,s="";for(let r=0;r<56;r++)s+=e.charAt(Math.floor(Math.random()*t));return s}return crypto.getRandomValues(e),Array.from(e,eY).join("")}(),i=r;s&&(i+="/PASSWORD_RECOVERY"),await eJ(e,"".concat(t,"-code-verifier"),i);let n=await eX(r),a=r===n?"plain":"s256";return[n,a]}eG.promiseConstructor=Promise;let eZ=/^2[0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/i;class e0 extends Error{constructor(e,t,s){super(e),this.__isAuthError=!0,this.name="AuthError",this.status=t,this.code=s}}function e1(e){return"object"==typeof e&&null!==e&&"__isAuthError"in e}class e2 extends e0{constructor(e,t,s){super(e,t,s),this.name="AuthApiError",this.status=t,this.code=s}}class e3 extends e0{constructor(e,t){super(e),this.name="AuthUnknownError",this.originalError=t}}class e4 extends e0{constructor(e,t,s,r){super(e,s,r),this.name=t,this.status=s}}class e5 extends e4{constructor(){super("Auth session missing!","AuthSessionMissingError",400,void 0)}}class e9 extends e4{constructor(){super("Auth session or user missing","AuthInvalidTokenResponseError",500,void 0)}}class e8 extends e4{constructor(e){super(e,"AuthInvalidCredentialsError",400,void 0)}}class e6 extends e4{toJSON(){return{name:this.name,message:this.message,status:this.status,details:this.details}}constructor(e,t=null){super(e,"AuthImplicitGrantRedirectError",500,void 0),this.details=null,this.details=t}}class e7 extends e4{toJSON(){return{name:this.name,message:this.message,status:this.status,details:this.details}}constructor(e,t=null){super(e,"AuthPKCEGrantCodeExchangeError",500,void 0),this.details=null,this.details=t}}class te extends e4{constructor(e,t){super(e,"AuthRetryableFetchError",t,void 0)}}function tt(e){return e1(e)&&"AuthRetryableFetchError"===e.name}class ts extends e4{constructor(e,t,s){super(e,"AuthWeakPasswordError",t,"weak_password"),this.reasons=s}}var tr=function(e,t){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&0>t.indexOf(r)&&(s[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)0>t.indexOf(r[i])&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(s[r[i]]=e[r[i]]);return s};let ti=e=>e.msg||e.message||e.error_description||e.error||JSON.stringify(e),tn=[502,503,504];async function ta(e){var t;let s,r;if(!eM(e))throw new te(ti(e),0);if(tn.includes(e.status))throw new te(ti(e),e.status);try{s=await e.json()}catch(e){throw new e3(ti(e),e)}let i=function(e){let t=e.headers.get(eU);if(!t||!t.match(eZ))return null;try{return new Date("".concat(t,"T00:00:00.0Z"))}catch(e){return null}}(e);if(i&&i.getTime()>=eN["2024-01-01"].timestamp&&"object"==typeof s&&s&&"string"==typeof s.code?r=s.code:"object"==typeof s&&s&&"string"==typeof s.error_code&&(r=s.error_code),r){if("weak_password"===r)throw new ts(ti(s),e.status,(null===(t=s.weak_password)||void 0===t?void 0:t.reasons)||[])}else if("object"==typeof s&&s&&"object"==typeof s.weak_password&&s.weak_password&&Array.isArray(s.weak_password.reasons)&&s.weak_password.reasons.length&&s.weak_password.reasons.reduce((e,t)=>e&&"string"==typeof t,!0))throw new ts(ti(s),e.status,s.weak_password.reasons);throw new e2(ti(s),e.status||500,r)}let to=(e,t,s,r)=>{let i={method:e,headers:(null==t?void 0:t.headers)||{}};return"GET"===e?i:(i.headers=Object.assign({"Content-Type":"application/json;charset=UTF-8"},null==t?void 0:t.headers),i.body=JSON.stringify(r),Object.assign(Object.assign({},i),s))};async function tc(e,t,s,r){var i;let n=Object.assign({},null==r?void 0:r.headers);n[eU]||(n[eU]=eN["2024-01-01"].name),(null==r?void 0:r.jwt)&&(n.Authorization="Bearer ".concat(r.jwt));let a=null!==(i=null==r?void 0:r.query)&&void 0!==i?i:{};(null==r?void 0:r.redirectTo)&&(a.redirect_to=r.redirectTo);let o=Object.keys(a).length?"?"+new URLSearchParams(a).toString():"",c=await tl(e,t,s+o,{headers:n,noResolveJson:null==r?void 0:r.noResolveJson},{},null==r?void 0:r.body);return(null==r?void 0:r.xform)?null==r?void 0:r.xform(c):{data:Object.assign({},c),error:null}}async function tl(e,t,s,r,i,n){let a;let o=to(t,r,i,n);try{a=await e(s,Object.assign({},o))}catch(e){throw console.error(e),new te(ti(e),0)}if(a.ok||await ta(a),null==r?void 0:r.noResolveJson)return a;try{return await a.json()}catch(e){await ta(e)}}function th(e){var t,s;let r=null;return e.access_token&&e.refresh_token&&e.expires_in&&(r=Object.assign({},e),!e.expires_at)&&(r.expires_at=(s=e.expires_in,Math.round(Date.now()/1e3)+s)),{data:{session:r,user:null!==(t=e.user)&&void 0!==t?t:e},error:null}}function tu(e){let t=th(e);return!t.error&&e.weak_password&&"object"==typeof e.weak_password&&Array.isArray(e.weak_password.reasons)&&e.weak_password.reasons.length&&e.weak_password.message&&"string"==typeof e.weak_password.message&&e.weak_password.reasons.reduce((e,t)=>e&&"string"==typeof t,!0)&&(t.data.weak_password=e.weak_password),t}function td(e){var t;return{data:{user:null!==(t=e.user)&&void 0!==t?t:e},error:null}}function tf(e){return{data:e,error:null}}function tp(e){let{action_link:t,email_otp:s,hashed_token:r,redirect_to:i,verification_type:n}=e;return{data:{properties:{action_link:t,email_otp:s,hashed_token:r,redirect_to:i,verification_type:n},user:Object.assign({},tr(e,["action_link","email_otp","hashed_token","redirect_to","verification_type"]))},error:null}}function tg(e){return e}var tv=function(e,t){var s={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&0>t.indexOf(r)&&(s[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)0>t.indexOf(r[i])&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(s[r[i]]=e[r[i]]);return s};class tm{async signOut(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"global";try{return await tc(this.fetch,"POST","".concat(this.url,"/logout?scope=").concat(t),{headers:this.headers,jwt:e,noResolveJson:!0}),{data:null,error:null}}catch(e){if(e1(e))return{data:null,error:e};throw e}}async inviteUserByEmail(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{return await tc(this.fetch,"POST","".concat(this.url,"/invite"),{body:{email:e,data:t.data},headers:this.headers,redirectTo:t.redirectTo,xform:td})}catch(e){if(e1(e))return{data:{user:null},error:e};throw e}}async generateLink(e){try{let{options:t}=e,s=tv(e,["options"]),r=Object.assign(Object.assign({},s),t);return"newEmail"in s&&(r.new_email=null==s?void 0:s.newEmail,delete r.newEmail),await tc(this.fetch,"POST","".concat(this.url,"/admin/generate_link"),{body:r,headers:this.headers,xform:tp,redirectTo:null==t?void 0:t.redirectTo})}catch(e){if(e1(e))return{data:{properties:null,user:null},error:e};throw e}}async createUser(e){try{return await tc(this.fetch,"POST","".concat(this.url,"/admin/users"),{body:e,headers:this.headers,xform:td})}catch(e){if(e1(e))return{data:{user:null},error:e};throw e}}async listUsers(e){var t,s,r,i,n,a,o;try{let c={nextPage:null,lastPage:0,total:0},l=await tc(this.fetch,"GET","".concat(this.url,"/admin/users"),{headers:this.headers,noResolveJson:!0,query:{page:null!==(s=null===(t=null==e?void 0:e.page)||void 0===t?void 0:t.toString())&&void 0!==s?s:"",per_page:null!==(i=null===(r=null==e?void 0:e.perPage)||void 0===r?void 0:r.toString())&&void 0!==i?i:""},xform:tg});if(l.error)throw l.error;let h=await l.json(),u=null!==(n=l.headers.get("x-total-count"))&&void 0!==n?n:0,d=null!==(o=null===(a=l.headers.get("link"))||void 0===a?void 0:a.split(","))&&void 0!==o?o:[];return d.length>0&&(d.forEach(e=>{let t=parseInt(e.split(";")[0].split("=")[1].substring(0,1)),s=JSON.parse(e.split(";")[1].split("=")[1]);c["".concat(s,"Page")]=t}),c.total=parseInt(u)),{data:Object.assign(Object.assign({},h),c),error:null}}catch(e){if(e1(e))return{data:{users:[]},error:e};throw e}}async getUserById(e){try{return await tc(this.fetch,"GET","".concat(this.url,"/admin/users/").concat(e),{headers:this.headers,xform:td})}catch(e){if(e1(e))return{data:{user:null},error:e};throw e}}async updateUserById(e,t){try{return await tc(this.fetch,"PUT","".concat(this.url,"/admin/users/").concat(e),{body:t,headers:this.headers,xform:td})}catch(e){if(e1(e))return{data:{user:null},error:e};throw e}}async deleteUser(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{return await tc(this.fetch,"DELETE","".concat(this.url,"/admin/users/").concat(e),{headers:this.headers,body:{should_soft_delete:t},xform:td})}catch(e){if(e1(e))return{data:{user:null},error:e};throw e}}async _listFactors(e){try{let{data:t,error:s}=await tc(this.fetch,"GET","".concat(this.url,"/admin/users/").concat(e.userId,"/factors"),{headers:this.headers,xform:e=>({data:{factors:e},error:null})});return{data:t,error:s}}catch(e){if(e1(e))return{data:null,error:e};throw e}}async _deleteFactor(e){try{return{data:await tc(this.fetch,"DELETE","".concat(this.url,"/admin/users/").concat(e.userId,"/factors/").concat(e.id),{headers:this.headers}),error:null}}catch(e){if(e1(e))return{data:null,error:e};throw e}}constructor({url:e="",headers:t={},fetch:s}){this.url=e,this.headers=t,this.fetch=eB(s),this.mfa={listFactors:this._listFactors.bind(this),deleteFactor:this._deleteFactor.bind(this)}}}let ty={getItem:e=>eF()?globalThis.localStorage.getItem(e):null,setItem:(e,t)=>{eF()&&globalThis.localStorage.setItem(e,t)},removeItem:e=>{eF()&&globalThis.localStorage.removeItem(e)}};function tw(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return{getItem:t=>e[t]||null,setItem:(t,s)=>{e[t]=s},removeItem:t=>{delete e[t]}}}let t_={debug:!!(globalThis&&eF()&&globalThis.localStorage&&"true"===globalThis.localStorage.getItem("supabase.gotrue-js.locks.debug"))};class tb extends Error{constructor(e){super(e),this.isAcquireTimeout=!0}}class tk extends tb{}async function tS(e,t,s){t_.debug&&console.log("@supabase/gotrue-js: navigatorLock: acquire lock",e,t);let r=new globalThis.AbortController;return t>0&&setTimeout(()=>{r.abort(),t_.debug&&console.log("@supabase/gotrue-js: navigatorLock acquire timed out",e)},t),await globalThis.navigator.locks.request(e,0===t?{mode:"exclusive",ifAvailable:!0}:{mode:"exclusive",signal:r.signal},async r=>{if(r){t_.debug&&console.log("@supabase/gotrue-js: navigatorLock: acquired",e,r.name);try{return await s()}finally{t_.debug&&console.log("@supabase/gotrue-js: navigatorLock: released",e,r.name)}}else{if(0===t)throw t_.debug&&console.log("@supabase/gotrue-js: navigatorLock: not immediately available",e),new tk('Acquiring an exclusive Navigator LockManager lock "'.concat(e,'" immediately failed'));if(t_.debug)try{let e=await globalThis.navigator.locks.query();console.log("@supabase/gotrue-js: Navigator LockManager state",JSON.stringify(e,null,"  "))}catch(e){console.warn("@supabase/gotrue-js: Error when querying Navigator LockManager state",e)}return console.warn("@supabase/gotrue-js: Navigator LockManager returned a null lock when using #request without ifAvailable set to true, it appears this browser is not following the LockManager spec https://developer.mozilla.org/en-US/docs/Web/API/LockManager/request"),await s()}})}!function(){if("object"!=typeof globalThis)try{Object.defineProperty(Object.prototype,"__magic__",{get:function(){return this},configurable:!0}),__magic__.globalThis=__magic__,delete Object.prototype.__magic__}catch(e){"undefined"!=typeof self&&(self.globalThis=self)}}();let tT={url:"http://localhost:9999",storageKey:"supabase.auth.token",autoRefreshToken:!0,persistSession:!0,detectSessionInUrl:!0,headers:{"X-Client-Info":"gotrue-js/".concat(eL)},flowType:"implicit",debug:!1,hasCustomAuthorizationHeader:!1};async function tj(e,t,s){return await s()}class tE{_debug(){for(var e=arguments.length,t=Array(e),s=0;s<e;s++)t[s]=arguments[s];return this.logDebugMessages&&this.logger("GoTrueClient@".concat(this.instanceID," (").concat(eL,") ").concat(new Date().toISOString()),...t),this}async initialize(){return this.initializePromise||(this.initializePromise=(async()=>await this._acquireLock(-1,async()=>await this._initialize()))()),await this.initializePromise}async _initialize(){try{let e=!!eD()&&await this._isPKCEFlow();if(this._debug("#_initialize()","begin","is PKCE flow",e),e||this.detectSessionInUrl&&this._isImplicitGrantFlow()){let{data:t,error:s}=await this._getSessionFromURL(e);if(s){if(this._debug("#_initialize()","error detecting session from URL",s),(null==s?void 0:s.message)==="Identity is already linked"||(null==s?void 0:s.message)==="Identity is already linked to another user")return{error:s};return await this._removeSession(),{error:s}}let{session:r,redirectType:i}=t;return this._debug("#_initialize()","detected session in URL",r,"redirect type",i),await this._saveSession(r),setTimeout(async()=>{"recovery"===i?await this._notifyAllSubscribers("PASSWORD_RECOVERY",r):await this._notifyAllSubscribers("SIGNED_IN",r)},0),{error:null}}return await this._recoverAndRefresh(),{error:null}}catch(e){if(e1(e))return{error:e};return{error:new e3("Unexpected error during initialization",e)}}finally{await this._handleVisibilityChange(),this._debug("#_initialize()","end")}}async signInAnonymously(e){var t,s,r;try{await this._removeSession();let{data:i,error:n}=await tc(this.fetch,"POST","".concat(this.url,"/signup"),{headers:this.headers,body:{data:null!==(s=null===(t=null==e?void 0:e.options)||void 0===t?void 0:t.data)&&void 0!==s?s:{},gotrue_meta_security:{captcha_token:null===(r=null==e?void 0:e.options)||void 0===r?void 0:r.captchaToken}},xform:th});if(n||!i)return{data:{user:null,session:null},error:n};let a=i.session,o=i.user;return i.session&&(await this._saveSession(i.session),await this._notifyAllSubscribers("SIGNED_IN",a)),{data:{user:o,session:a},error:null}}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async signUp(e){var t,s,r;try{let i;if(await this._removeSession(),"email"in e){let{email:s,password:r,options:n}=e,a=null,o=null;"pkce"===this.flowType&&([a,o]=await eQ(this.storage,this.storageKey)),i=await tc(this.fetch,"POST","".concat(this.url,"/signup"),{headers:this.headers,redirectTo:null==n?void 0:n.emailRedirectTo,body:{email:s,password:r,data:null!==(t=null==n?void 0:n.data)&&void 0!==t?t:{},gotrue_meta_security:{captcha_token:null==n?void 0:n.captchaToken},code_challenge:a,code_challenge_method:o},xform:th})}else if("phone"in e){let{phone:t,password:n,options:a}=e;i=await tc(this.fetch,"POST","".concat(this.url,"/signup"),{headers:this.headers,body:{phone:t,password:n,data:null!==(s=null==a?void 0:a.data)&&void 0!==s?s:{},channel:null!==(r=null==a?void 0:a.channel)&&void 0!==r?r:"sms",gotrue_meta_security:{captcha_token:null==a?void 0:a.captchaToken}},xform:th})}else throw new e8("You must provide either an email or phone number and a password");let{data:n,error:a}=i;if(a||!n)return{data:{user:null,session:null},error:a};let o=n.session,c=n.user;return n.session&&(await this._saveSession(n.session),await this._notifyAllSubscribers("SIGNED_IN",o)),{data:{user:c,session:o},error:null}}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async signInWithPassword(e){try{let t;if(await this._removeSession(),"email"in e){let{email:s,password:r,options:i}=e;t=await tc(this.fetch,"POST","".concat(this.url,"/token?grant_type=password"),{headers:this.headers,body:{email:s,password:r,gotrue_meta_security:{captcha_token:null==i?void 0:i.captchaToken}},xform:tu})}else if("phone"in e){let{phone:s,password:r,options:i}=e;t=await tc(this.fetch,"POST","".concat(this.url,"/token?grant_type=password"),{headers:this.headers,body:{phone:s,password:r,gotrue_meta_security:{captcha_token:null==i?void 0:i.captchaToken}},xform:tu})}else throw new e8("You must provide either an email or phone number and a password");let{data:s,error:r}=t;if(r)return{data:{user:null,session:null},error:r};if(!s||!s.session||!s.user)return{data:{user:null,session:null},error:new e9};return s.session&&(await this._saveSession(s.session),await this._notifyAllSubscribers("SIGNED_IN",s.session)),{data:Object.assign({user:s.user,session:s.session},s.weak_password?{weakPassword:s.weak_password}:null),error:r}}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async signInWithOAuth(e){var t,s,r,i;return await this._removeSession(),await this._handleProviderSignIn(e.provider,{redirectTo:null===(t=e.options)||void 0===t?void 0:t.redirectTo,scopes:null===(s=e.options)||void 0===s?void 0:s.scopes,queryParams:null===(r=e.options)||void 0===r?void 0:r.queryParams,skipBrowserRedirect:null===(i=e.options)||void 0===i?void 0:i.skipBrowserRedirect})}async exchangeCodeForSession(e){return await this.initializePromise,this._acquireLock(-1,async()=>this._exchangeCodeForSession(e))}async _exchangeCodeForSession(e){let t=await eK(this.storage,"".concat(this.storageKey,"-code-verifier")),[s,r]=(null!=t?t:"").split("/"),{data:i,error:n}=await tc(this.fetch,"POST","".concat(this.url,"/token?grant_type=pkce"),{headers:this.headers,body:{auth_code:e,code_verifier:s},xform:th});return(await eH(this.storage,"".concat(this.storageKey,"-code-verifier")),n)?{data:{user:null,session:null,redirectType:null},error:n}:i&&i.session&&i.user?(i.session&&(await this._saveSession(i.session),await this._notifyAllSubscribers("SIGNED_IN",i.session)),{data:Object.assign(Object.assign({},i),{redirectType:null!=r?r:null}),error:n}):{data:{user:null,session:null,redirectType:null},error:new e9}}async signInWithIdToken(e){await this._removeSession();try{let{options:t,provider:s,token:r,access_token:i,nonce:n}=e,{data:a,error:o}=await tc(this.fetch,"POST","".concat(this.url,"/token?grant_type=id_token"),{headers:this.headers,body:{provider:s,id_token:r,access_token:i,nonce:n,gotrue_meta_security:{captcha_token:null==t?void 0:t.captchaToken}},xform:th});if(o)return{data:{user:null,session:null},error:o};if(!a||!a.session||!a.user)return{data:{user:null,session:null},error:new e9};return a.session&&(await this._saveSession(a.session),await this._notifyAllSubscribers("SIGNED_IN",a.session)),{data:a,error:o}}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async signInWithOtp(e){var t,s,r,i,n;try{if(await this._removeSession(),"email"in e){let{email:r,options:i}=e,n=null,a=null;"pkce"===this.flowType&&([n,a]=await eQ(this.storage,this.storageKey));let{error:o}=await tc(this.fetch,"POST","".concat(this.url,"/otp"),{headers:this.headers,body:{email:r,data:null!==(t=null==i?void 0:i.data)&&void 0!==t?t:{},create_user:null===(s=null==i?void 0:i.shouldCreateUser)||void 0===s||s,gotrue_meta_security:{captcha_token:null==i?void 0:i.captchaToken},code_challenge:n,code_challenge_method:a},redirectTo:null==i?void 0:i.emailRedirectTo});return{data:{user:null,session:null},error:o}}if("phone"in e){let{phone:t,options:s}=e,{data:a,error:o}=await tc(this.fetch,"POST","".concat(this.url,"/otp"),{headers:this.headers,body:{phone:t,data:null!==(r=null==s?void 0:s.data)&&void 0!==r?r:{},create_user:null===(i=null==s?void 0:s.shouldCreateUser)||void 0===i||i,gotrue_meta_security:{captcha_token:null==s?void 0:s.captchaToken},channel:null!==(n=null==s?void 0:s.channel)&&void 0!==n?n:"sms"}});return{data:{user:null,session:null,messageId:null==a?void 0:a.message_id},error:o}}throw new e8("You must provide either an email or phone number.")}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async verifyOtp(e){var t,s;try{let r,i;"email_change"!==e.type&&"phone_change"!==e.type&&await this._removeSession(),"options"in e&&(r=null===(t=e.options)||void 0===t?void 0:t.redirectTo,i=null===(s=e.options)||void 0===s?void 0:s.captchaToken);let{data:n,error:a}=await tc(this.fetch,"POST","".concat(this.url,"/verify"),{headers:this.headers,body:Object.assign(Object.assign({},e),{gotrue_meta_security:{captcha_token:i}}),redirectTo:r,xform:th});if(a)throw a;if(!n)throw Error("An error occurred on token verification.");let o=n.session,c=n.user;return(null==o?void 0:o.access_token)&&(await this._saveSession(o),await this._notifyAllSubscribers("recovery"==e.type?"PASSWORD_RECOVERY":"SIGNED_IN",o)),{data:{user:c,session:o},error:null}}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async signInWithSSO(e){var t,s,r;try{await this._removeSession();let i=null,n=null;return"pkce"===this.flowType&&([i,n]=await eQ(this.storage,this.storageKey)),await tc(this.fetch,"POST","".concat(this.url,"/sso"),{body:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},"providerId"in e?{provider_id:e.providerId}:null),"domain"in e?{domain:e.domain}:null),{redirect_to:null!==(s=null===(t=e.options)||void 0===t?void 0:t.redirectTo)&&void 0!==s?s:void 0}),(null===(r=null==e?void 0:e.options)||void 0===r?void 0:r.captchaToken)?{gotrue_meta_security:{captcha_token:e.options.captchaToken}}:null),{skip_http_redirect:!0,code_challenge:i,code_challenge_method:n}),headers:this.headers,xform:tf})}catch(e){if(e1(e))return{data:null,error:e};throw e}}async reauthenticate(){return await this.initializePromise,await this._acquireLock(-1,async()=>await this._reauthenticate())}async _reauthenticate(){try{return await this._useSession(async e=>{let{data:{session:t},error:s}=e;if(s)throw s;if(!t)throw new e5;let{error:r}=await tc(this.fetch,"GET","".concat(this.url,"/reauthenticate"),{headers:this.headers,jwt:t.access_token});return{data:{user:null,session:null},error:r}})}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async resend(e){try{"email_change"!=e.type&&"phone_change"!=e.type&&await this._removeSession();let t="".concat(this.url,"/resend");if("email"in e){let{email:s,type:r,options:i}=e,{error:n}=await tc(this.fetch,"POST",t,{headers:this.headers,body:{email:s,type:r,gotrue_meta_security:{captcha_token:null==i?void 0:i.captchaToken}},redirectTo:null==i?void 0:i.emailRedirectTo});return{data:{user:null,session:null},error:n}}if("phone"in e){let{phone:s,type:r,options:i}=e,{data:n,error:a}=await tc(this.fetch,"POST",t,{headers:this.headers,body:{phone:s,type:r,gotrue_meta_security:{captcha_token:null==i?void 0:i.captchaToken}}});return{data:{user:null,session:null,messageId:null==n?void 0:n.message_id},error:a}}throw new e8("You must provide either an email or phone number and a type")}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async getSession(){return await this.initializePromise,await this._acquireLock(-1,async()=>this._useSession(async e=>e))}async _acquireLock(e,t){this._debug("#_acquireLock","begin",e);try{if(this.lockAcquired){let e=this.pendingInLock.length?this.pendingInLock[this.pendingInLock.length-1]:Promise.resolve(),s=(async()=>(await e,await t()))();return this.pendingInLock.push((async()=>{try{await s}catch(e){}})()),s}return await this.lock("lock:".concat(this.storageKey),e,async()=>{this._debug("#_acquireLock","lock acquired for storage key",this.storageKey);try{this.lockAcquired=!0;let e=t();for(this.pendingInLock.push((async()=>{try{await e}catch(e){}})()),await e;this.pendingInLock.length;){let e=[...this.pendingInLock];await Promise.all(e),this.pendingInLock.splice(0,e.length)}return await e}finally{this._debug("#_acquireLock","lock released for storage key",this.storageKey),this.lockAcquired=!1}})}finally{this._debug("#_acquireLock","end")}}async _useSession(e){this._debug("#_useSession","begin");try{let t=await this.__loadSession();return await e(t)}finally{this._debug("#_useSession","end")}}async __loadSession(){this._debug("#__loadSession()","begin"),this.lockAcquired||this._debug("#__loadSession()","used outside of an acquired lock!",Error().stack);try{let e=null,t=await eK(this.storage,this.storageKey);if(this._debug("#getSession()","session from storage",t),null!==t&&(this._isValidSession(t)?e=t:(this._debug("#getSession()","session from storage is not valid"),await this._removeSession())),!e)return{data:{session:null},error:null};let s=!!e.expires_at&&e.expires_at<=Date.now()/1e3;if(this._debug("#__loadSession()","session has".concat(s?"":" not"," expired"),"expires_at",e.expires_at),!s)return this.storage.isServer&&(e=new Proxy(e,{get:(e,t,s)=>("user"===t&&console.warn("Using the user object as returned from supabase.auth.getSession() or from some supabase.auth.onAuthStateChange() events could be insecure! This value comes directly from the storage medium (usually cookies on the server) and many not be authentic. Use supabase.auth.getUser() instead which authenticates the data by contacting the Supabase Auth server."),Reflect.get(e,t,s))})),{data:{session:e},error:null};let{session:r,error:i}=await this._callRefreshToken(e.refresh_token);if(i)return{data:{session:null},error:i};return{data:{session:r},error:null}}finally{this._debug("#__loadSession()","end")}}async getUser(e){return e?await this._getUser(e):(await this.initializePromise,await this._acquireLock(-1,async()=>await this._getUser()))}async _getUser(e){try{if(e)return await tc(this.fetch,"GET","".concat(this.url,"/user"),{headers:this.headers,jwt:e,xform:td});return await this._useSession(async e=>{var t,s,r;let{data:i,error:n}=e;if(n)throw n;return(null===(t=i.session)||void 0===t?void 0:t.access_token)||this.hasCustomAuthorizationHeader?await tc(this.fetch,"GET","".concat(this.url,"/user"),{headers:this.headers,jwt:null!==(r=null===(s=i.session)||void 0===s?void 0:s.access_token)&&void 0!==r?r:void 0,xform:td}):{data:{user:null},error:new e5}})}catch(e){if(e1(e))return{data:{user:null},error:e};throw e}}async updateUser(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return await this.initializePromise,await this._acquireLock(-1,async()=>await this._updateUser(e,t))}async _updateUser(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{return await this._useSession(async s=>{let{data:r,error:i}=s;if(i)throw i;if(!r.session)throw new e5;let n=r.session,a=null,o=null;"pkce"===this.flowType&&null!=e.email&&([a,o]=await eQ(this.storage,this.storageKey));let{data:c,error:l}=await tc(this.fetch,"PUT","".concat(this.url,"/user"),{headers:this.headers,redirectTo:null==t?void 0:t.emailRedirectTo,body:Object.assign(Object.assign({},e),{code_challenge:a,code_challenge_method:o}),jwt:n.access_token,xform:td});if(l)throw l;return n.user=c.user,await this._saveSession(n),await this._notifyAllSubscribers("USER_UPDATED",n),{data:{user:n.user},error:null}})}catch(e){if(e1(e))return{data:{user:null},error:e};throw e}}_decodeJWT(e){return eV(e)}async setSession(e){return await this.initializePromise,await this._acquireLock(-1,async()=>await this._setSession(e))}async _setSession(e){try{if(!e.access_token||!e.refresh_token)throw new e5;let t=Date.now()/1e3,s=t,r=!0,i=null,n=eV(e.access_token);if(n.exp&&(r=(s=n.exp)<=t),r){let{session:t,error:s}=await this._callRefreshToken(e.refresh_token);if(s)return{data:{user:null,session:null},error:s};if(!t)return{data:{user:null,session:null},error:null};i=t}else{let{data:r,error:n}=await this._getUser(e.access_token);if(n)throw n;i={access_token:e.access_token,refresh_token:e.refresh_token,user:r.user,token_type:"bearer",expires_in:s-t,expires_at:s},await this._saveSession(i),await this._notifyAllSubscribers("SIGNED_IN",i)}return{data:{user:i.user,session:i},error:null}}catch(e){if(e1(e))return{data:{session:null,user:null},error:e};throw e}}async refreshSession(e){return await this.initializePromise,await this._acquireLock(-1,async()=>await this._refreshSession(e))}async _refreshSession(e){try{return await this._useSession(async t=>{var s;if(!e){let{data:r,error:i}=t;if(i)throw i;e=null!==(s=r.session)&&void 0!==s?s:void 0}if(!(null==e?void 0:e.refresh_token))throw new e5;let{session:r,error:i}=await this._callRefreshToken(e.refresh_token);return i?{data:{user:null,session:null},error:i}:r?{data:{user:r.user,session:r},error:null}:{data:{user:null,session:null},error:null}})}catch(e){if(e1(e))return{data:{user:null,session:null},error:e};throw e}}async _getSessionFromURL(e){try{if(!eD())throw new e6("No browser detected.");if("implicit"!==this.flowType||this._isImplicitGrantFlow()){if("pkce"==this.flowType&&!e)throw new e7("Not a valid PKCE flow url.")}else throw new e6("Not a valid implicit grant flow url.");let t=ez(window.location.href);if(e){if(!t.code)throw new e7("No code detected.");let{data:e,error:s}=await this._exchangeCodeForSession(t.code);if(s)throw s;let r=new URL(window.location.href);return r.searchParams.delete("code"),window.history.replaceState(window.history.state,"",r.toString()),{data:{session:e.session,redirectType:null},error:null}}if(t.error||t.error_description||t.error_code)throw new e6(t.error_description||"Error in URL with unspecified error_description",{error:t.error||"unspecified_error",code:t.error_code||"unspecified_code"});let{provider_token:s,provider_refresh_token:r,access_token:i,refresh_token:n,expires_in:a,expires_at:o,token_type:c}=t;if(!i||!a||!n||!c)throw new e6("No session defined in URL");let l=Math.round(Date.now()/1e3),h=parseInt(a),u=l+h;o&&(u=parseInt(o));let d=u-l;1e3*d<=3e4&&console.warn("@supabase/gotrue-js: Session as retrieved from URL expires in ".concat(d,"s, should have been closer to ").concat(h,"s"));let f=u-h;l-f>=120?console.warn("@supabase/gotrue-js: Session as retrieved from URL was issued over 120s ago, URL could be stale",f,u,l):l-f<0&&console.warn("@supabase/gotrue-js: Session as retrieved from URL was issued in the future? Check the device clok for skew",f,u,l);let{data:p,error:g}=await this._getUser(i);if(g)throw g;let v={provider_token:s,provider_refresh_token:r,access_token:i,expires_in:h,expires_at:u,refresh_token:n,token_type:c,user:p.user};return window.location.hash="",this._debug("#_getSessionFromURL()","clearing window.location.hash"),{data:{session:v,redirectType:t.type},error:null}}catch(e){if(e1(e))return{data:{session:null,redirectType:null},error:e};throw e}}_isImplicitGrantFlow(){let e=ez(window.location.href);return!!(eD()&&(e.access_token||e.error_description))}async _isPKCEFlow(){let e=ez(window.location.href),t=await eK(this.storage,"".concat(this.storageKey,"-code-verifier"));return!!(e.code&&t)}async signOut(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{scope:"global"};return await this.initializePromise,await this._acquireLock(-1,async()=>await this._signOut(e))}async _signOut(){let{scope:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{scope:"global"};return await this._useSession(async t=>{var s;let{data:r,error:i}=t;if(i)return{error:i};let n=null===(s=r.session)||void 0===s?void 0:s.access_token;if(n){let{error:t}=await this.admin.signOut(n,e);if(t&&!(e1(t)&&"AuthApiError"===t.name&&(404===t.status||401===t.status)))return{error:t}}return"others"!==e&&(await this._removeSession(),await eH(this.storage,"".concat(this.storageKey,"-code-verifier")),await this._notifyAllSubscribers("SIGNED_OUT",null)),{error:null}})}onAuthStateChange(e){let t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){let t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}),s={id:t,callback:e,unsubscribe:()=>{this._debug("#unsubscribe()","state change callback with id removed",t),this.stateChangeEmitters.delete(t)}};return this._debug("#onAuthStateChange()","registered callback with id",t),this.stateChangeEmitters.set(t,s),(async()=>{await this.initializePromise,await this._acquireLock(-1,async()=>{this._emitInitialSession(t)})})(),{data:{subscription:s}}}async _emitInitialSession(e){return await this._useSession(async t=>{var s,r;try{let{data:{session:r},error:i}=t;if(i)throw i;await (null===(s=this.stateChangeEmitters.get(e))||void 0===s?void 0:s.callback("INITIAL_SESSION",r)),this._debug("INITIAL_SESSION","callback id",e,"session",r)}catch(t){await (null===(r=this.stateChangeEmitters.get(e))||void 0===r?void 0:r.callback("INITIAL_SESSION",null)),this._debug("INITIAL_SESSION","callback id",e,"error",t),console.error(t)}})}async resetPasswordForEmail(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=null,r=null;"pkce"===this.flowType&&([s,r]=await eQ(this.storage,this.storageKey,!0));try{return await tc(this.fetch,"POST","".concat(this.url,"/recover"),{body:{email:e,code_challenge:s,code_challenge_method:r,gotrue_meta_security:{captcha_token:t.captchaToken}},headers:this.headers,redirectTo:t.redirectTo})}catch(e){if(e1(e))return{data:null,error:e};throw e}}async getUserIdentities(){var e;try{let{data:t,error:s}=await this.getUser();if(s)throw s;return{data:{identities:null!==(e=t.user.identities)&&void 0!==e?e:[]},error:null}}catch(e){if(e1(e))return{data:null,error:e};throw e}}async linkIdentity(e){var t;try{let{data:s,error:r}=await this._useSession(async t=>{var s,r,i,n,a;let{data:o,error:c}=t;if(c)throw c;let l=await this._getUrlForProvider("".concat(this.url,"/user/identities/authorize"),e.provider,{redirectTo:null===(s=e.options)||void 0===s?void 0:s.redirectTo,scopes:null===(r=e.options)||void 0===r?void 0:r.scopes,queryParams:null===(i=e.options)||void 0===i?void 0:i.queryParams,skipBrowserRedirect:!0});return await tc(this.fetch,"GET",l,{headers:this.headers,jwt:null!==(a=null===(n=o.session)||void 0===n?void 0:n.access_token)&&void 0!==a?a:void 0})});if(r)throw r;return!eD()||(null===(t=e.options)||void 0===t?void 0:t.skipBrowserRedirect)||window.location.assign(null==s?void 0:s.url),{data:{provider:e.provider,url:null==s?void 0:s.url},error:null}}catch(t){if(e1(t))return{data:{provider:e.provider,url:null},error:t};throw t}}async unlinkIdentity(e){try{return await this._useSession(async t=>{var s,r;let{data:i,error:n}=t;if(n)throw n;return await tc(this.fetch,"DELETE","".concat(this.url,"/user/identities/").concat(e.identity_id),{headers:this.headers,jwt:null!==(r=null===(s=i.session)||void 0===s?void 0:s.access_token)&&void 0!==r?r:void 0})})}catch(e){if(e1(e))return{data:null,error:e};throw e}}async _refreshAccessToken(e){let t="#_refreshAccessToken(".concat(e.substring(0,5),"...)");this._debug(t,"begin");try{var s,r;let i=Date.now();return await (s=async s=>(s>0&&await eW(200*Math.pow(2,s-1)),this._debug(t,"refreshing attempt",s),await tc(this.fetch,"POST","".concat(this.url,"/token?grant_type=refresh_token"),{body:{refresh_token:e},headers:this.headers,xform:th})),r=(e,t)=>t&&tt(t)&&Date.now()+200*Math.pow(2,e)-i<3e4,new Promise((e,t)=>{(async()=>{for(let i=0;i<1/0;i++)try{let t=await s(i);if(!r(i,null,t)){e(t);return}}catch(e){if(!r(i,e)){t(e);return}}})()}))}catch(e){if(this._debug(t,"error",e),e1(e))return{data:{session:null,user:null},error:e};throw e}finally{this._debug(t,"end")}}_isValidSession(e){return"object"==typeof e&&null!==e&&"access_token"in e&&"refresh_token"in e&&"expires_at"in e}async _handleProviderSignIn(e,t){let s=await this._getUrlForProvider("".concat(this.url,"/authorize"),e,{redirectTo:t.redirectTo,scopes:t.scopes,queryParams:t.queryParams});return this._debug("#_handleProviderSignIn()","provider",e,"options",t,"url",s),eD()&&!t.skipBrowserRedirect&&window.location.assign(s),{data:{provider:e,url:s},error:null}}async _recoverAndRefresh(){var e;let t="#_recoverAndRefresh()";this._debug(t,"begin");try{let s=await eK(this.storage,this.storageKey);if(this._debug(t,"session from storage",s),!this._isValidSession(s)){this._debug(t,"session is not valid"),null!==s&&await this._removeSession();return}let r=Math.round(Date.now()/1e3),i=(null!==(e=s.expires_at)&&void 0!==e?e:1/0)<r+10;if(this._debug(t,"session has".concat(i?"":" not"," expired with margin of ").concat(10,"s")),i){if(this.autoRefreshToken&&s.refresh_token){let{error:e}=await this._callRefreshToken(s.refresh_token);e&&(console.error(e),tt(e)||(this._debug(t,"refresh failed with a non-retryable error, removing the session",e),await this._removeSession()))}}else await this._notifyAllSubscribers("SIGNED_IN",s)}catch(e){this._debug(t,"error",e),console.error(e);return}finally{this._debug(t,"end")}}async _callRefreshToken(e){var t,s;if(!e)throw new e5;if(this.refreshingDeferred)return this.refreshingDeferred.promise;let r="#_callRefreshToken(".concat(e.substring(0,5),"...)");this._debug(r,"begin");try{this.refreshingDeferred=new eG;let{data:t,error:s}=await this._refreshAccessToken(e);if(s)throw s;if(!t.session)throw new e5;await this._saveSession(t.session),await this._notifyAllSubscribers("TOKEN_REFRESHED",t.session);let r={session:t.session,error:null};return this.refreshingDeferred.resolve(r),r}catch(e){if(this._debug(r,"error",e),e1(e)){let s={session:null,error:e};return tt(e)||(await this._removeSession(),await this._notifyAllSubscribers("SIGNED_OUT",null)),null===(t=this.refreshingDeferred)||void 0===t||t.resolve(s),s}throw null===(s=this.refreshingDeferred)||void 0===s||s.reject(e),e}finally{this.refreshingDeferred=null,this._debug(r,"end")}}async _notifyAllSubscribers(e,t){let s=!(arguments.length>2)||void 0===arguments[2]||arguments[2],r="#_notifyAllSubscribers(".concat(e,")");this._debug(r,"begin",t,"broadcast = ".concat(s));try{this.broadcastChannel&&s&&this.broadcastChannel.postMessage({event:e,session:t});let r=[],i=Array.from(this.stateChangeEmitters.values()).map(async s=>{try{await s.callback(e,t)}catch(e){r.push(e)}});if(await Promise.all(i),r.length>0){for(let e=0;e<r.length;e+=1)console.error(r[e]);throw r[0]}}finally{this._debug(r,"end")}}async _saveSession(e){this._debug("#_saveSession()",e),await eJ(this.storage,this.storageKey,e)}async _removeSession(){this._debug("#_removeSession()"),await eH(this.storage,this.storageKey)}_removeVisibilityChangedCallback(){this._debug("#_removeVisibilityChangedCallback()");let e=this.visibilityChangedCallback;this.visibilityChangedCallback=null;try{e&&eD()&&(null==window?void 0:window.removeEventListener)&&window.removeEventListener("visibilitychange",e)}catch(e){console.error("removing visibilitychange callback failed",e)}}async _startAutoRefresh(){await this._stopAutoRefresh(),this._debug("#_startAutoRefresh()");let e=setInterval(()=>this._autoRefreshTokenTick(),3e4);this.autoRefreshTicker=e,e&&"object"==typeof e&&"function"==typeof e.unref?e.unref():"undefined"!=typeof Deno&&"function"==typeof Deno.unrefTimer&&Deno.unrefTimer(e),setTimeout(async()=>{await this.initializePromise,await this._autoRefreshTokenTick()},0)}async _stopAutoRefresh(){this._debug("#_stopAutoRefresh()");let e=this.autoRefreshTicker;this.autoRefreshTicker=null,e&&clearInterval(e)}async startAutoRefresh(){this._removeVisibilityChangedCallback(),await this._startAutoRefresh()}async stopAutoRefresh(){this._removeVisibilityChangedCallback(),await this._stopAutoRefresh()}async _autoRefreshTokenTick(){this._debug("#_autoRefreshTokenTick()","begin");try{await this._acquireLock(0,async()=>{try{let e=Date.now();try{return await this._useSession(async t=>{let{data:{session:s}}=t;if(!s||!s.refresh_token||!s.expires_at){this._debug("#_autoRefreshTokenTick()","no session");return}let r=Math.floor((1e3*s.expires_at-e)/3e4);this._debug("#_autoRefreshTokenTick()","access token expires in ".concat(r," ticks, a tick lasts ").concat(3e4,"ms, refresh threshold is ").concat(3," ticks")),r<=3&&await this._callRefreshToken(s.refresh_token)})}catch(e){console.error("Auto refresh tick failed with error. This is likely a transient error.",e)}}finally{this._debug("#_autoRefreshTokenTick()","end")}})}catch(e){if(e.isAcquireTimeout||e instanceof tb)this._debug("auto refresh token tick lock not available");else throw e}}async _handleVisibilityChange(){if(this._debug("#_handleVisibilityChange()"),!eD()||!(null==window?void 0:window.addEventListener))return this.autoRefreshToken&&this.startAutoRefresh(),!1;try{this.visibilityChangedCallback=async()=>await this._onVisibilityChanged(!1),null==window||window.addEventListener("visibilitychange",this.visibilityChangedCallback),await this._onVisibilityChanged(!0)}catch(e){console.error("_handleVisibilityChange",e)}}async _onVisibilityChanged(e){let t="#_onVisibilityChanged(".concat(e,")");this._debug(t,"visibilityState",document.visibilityState),"visible"===document.visibilityState?(this.autoRefreshToken&&this._startAutoRefresh(),e||(await this.initializePromise,await this._acquireLock(-1,async()=>{if("visible"!==document.visibilityState){this._debug(t,"acquired the lock to recover the session, but the browser visibilityState is no longer visible, aborting");return}await this._recoverAndRefresh()}))):"hidden"===document.visibilityState&&this.autoRefreshToken&&this._stopAutoRefresh()}async _getUrlForProvider(e,t,s){let r=["provider=".concat(encodeURIComponent(t))];if((null==s?void 0:s.redirectTo)&&r.push("redirect_to=".concat(encodeURIComponent(s.redirectTo))),(null==s?void 0:s.scopes)&&r.push("scopes=".concat(encodeURIComponent(s.scopes))),"pkce"===this.flowType){let[e,t]=await eQ(this.storage,this.storageKey),s=new URLSearchParams({code_challenge:"".concat(encodeURIComponent(e)),code_challenge_method:"".concat(encodeURIComponent(t))});r.push(s.toString())}if(null==s?void 0:s.queryParams){let e=new URLSearchParams(s.queryParams);r.push(e.toString())}return(null==s?void 0:s.skipBrowserRedirect)&&r.push("skip_http_redirect=".concat(s.skipBrowserRedirect)),"".concat(e,"?").concat(r.join("&"))}async _unenroll(e){try{return await this._useSession(async t=>{var s;let{data:r,error:i}=t;return i?{data:null,error:i}:await tc(this.fetch,"DELETE","".concat(this.url,"/factors/").concat(e.factorId),{headers:this.headers,jwt:null===(s=null==r?void 0:r.session)||void 0===s?void 0:s.access_token})})}catch(e){if(e1(e))return{data:null,error:e};throw e}}async _enroll(e){try{return await this._useSession(async t=>{var s,r;let{data:i,error:n}=t;if(n)return{data:null,error:n};let{data:a,error:o}=await tc(this.fetch,"POST","".concat(this.url,"/factors"),{body:{friendly_name:e.friendlyName,factor_type:e.factorType,issuer:e.issuer},headers:this.headers,jwt:null===(s=null==i?void 0:i.session)||void 0===s?void 0:s.access_token});return o?{data:null,error:o}:((null===(r=null==a?void 0:a.totp)||void 0===r?void 0:r.qr_code)&&(a.totp.qr_code="data:image/svg+xml;utf-8,".concat(a.totp.qr_code)),{data:a,error:null})})}catch(e){if(e1(e))return{data:null,error:e};throw e}}async _verify(e){return this._acquireLock(-1,async()=>{try{return await this._useSession(async t=>{var s;let{data:r,error:i}=t;if(i)return{data:null,error:i};let{data:n,error:a}=await tc(this.fetch,"POST","".concat(this.url,"/factors/").concat(e.factorId,"/verify"),{body:{code:e.code,challenge_id:e.challengeId},headers:this.headers,jwt:null===(s=null==r?void 0:r.session)||void 0===s?void 0:s.access_token});return a?{data:null,error:a}:(await this._saveSession(Object.assign({expires_at:Math.round(Date.now()/1e3)+n.expires_in},n)),await this._notifyAllSubscribers("MFA_CHALLENGE_VERIFIED",n),{data:n,error:a})})}catch(e){if(e1(e))return{data:null,error:e};throw e}})}async _challenge(e){return this._acquireLock(-1,async()=>{try{return await this._useSession(async t=>{var s;let{data:r,error:i}=t;return i?{data:null,error:i}:await tc(this.fetch,"POST","".concat(this.url,"/factors/").concat(e.factorId,"/challenge"),{headers:this.headers,jwt:null===(s=null==r?void 0:r.session)||void 0===s?void 0:s.access_token})})}catch(e){if(e1(e))return{data:null,error:e};throw e}})}async _challengeAndVerify(e){let{data:t,error:s}=await this._challenge({factorId:e.factorId});return s?{data:null,error:s}:await this._verify({factorId:e.factorId,challengeId:t.id,code:e.code})}async _listFactors(){let{data:{user:e},error:t}=await this.getUser();if(t)return{data:null,error:t};let s=(null==e?void 0:e.factors)||[],r=s.filter(e=>"totp"===e.factor_type&&"verified"===e.status);return{data:{all:s,totp:r},error:null}}async _getAuthenticatorAssuranceLevel(){return this._acquireLock(-1,async()=>await this._useSession(async e=>{var t,s;let{data:{session:r},error:i}=e;if(i)return{data:null,error:i};if(!r)return{data:{currentLevel:null,nextLevel:null,currentAuthenticationMethods:[]},error:null};let n=this._decodeJWT(r.access_token),a=null;n.aal&&(a=n.aal);let o=a;return(null!==(s=null===(t=r.user.factors)||void 0===t?void 0:t.filter(e=>"verified"===e.status))&&void 0!==s?s:[]).length>0&&(o="aal2"),{data:{currentLevel:a,nextLevel:o,currentAuthenticationMethods:n.amr||[]},error:null}}))}constructor(e){var t,s;this.memoryStorage=null,this.stateChangeEmitters=new Map,this.autoRefreshTicker=null,this.visibilityChangedCallback=null,this.refreshingDeferred=null,this.initializePromise=null,this.detectSessionInUrl=!0,this.hasCustomAuthorizationHeader=!1,this.lockAcquired=!1,this.pendingInLock=[],this.broadcastChannel=null,this.logger=console.log,this.instanceID=tE.nextInstanceID,tE.nextInstanceID+=1,this.instanceID>0&&eD()&&console.warn("Multiple GoTrueClient instances detected in the same browser context. It is not an error, but this should be avoided as it may produce undefined behavior when used concurrently under the same storage key.");let r=Object.assign(Object.assign({},tT),e);if(this.logDebugMessages=!!r.debug,"function"==typeof r.debug&&(this.logger=r.debug),this.persistSession=r.persistSession,this.storageKey=r.storageKey,this.autoRefreshToken=r.autoRefreshToken,this.admin=new tm({url:r.url,headers:r.headers,fetch:r.fetch}),this.url=r.url,this.headers=r.headers,this.fetch=eB(r.fetch),this.lock=r.lock||tj,this.detectSessionInUrl=r.detectSessionInUrl,this.flowType=r.flowType,this.hasCustomAuthorizationHeader=r.hasCustomAuthorizationHeader,r.lock?this.lock=r.lock:eD()&&(null===(t=null==globalThis?void 0:globalThis.navigator)||void 0===t?void 0:t.locks)?this.lock=tS:this.lock=tj,this.mfa={verify:this._verify.bind(this),enroll:this._enroll.bind(this),unenroll:this._unenroll.bind(this),challenge:this._challenge.bind(this),listFactors:this._listFactors.bind(this),challengeAndVerify:this._challengeAndVerify.bind(this),getAuthenticatorAssuranceLevel:this._getAuthenticatorAssuranceLevel.bind(this)},this.persistSession?r.storage?this.storage=r.storage:eF()?this.storage=ty:(this.memoryStorage={},this.storage=tw(this.memoryStorage)):(this.memoryStorage={},this.storage=tw(this.memoryStorage)),eD()&&globalThis.BroadcastChannel&&this.persistSession&&this.storageKey){try{this.broadcastChannel=new globalThis.BroadcastChannel(this.storageKey)}catch(e){console.error("Failed to create a new BroadcastChannel, multi-tab state changes will not be available",e)}null===(s=this.broadcastChannel)||void 0===s||s.addEventListener("message",async e=>{this._debug("received broadcast notification from other tab or client",e),await this._notifyAllSubscribers(e.data.event,e.data.session,!1)})}this.initialize()}}tE.nextInstanceID=0;var tO=tE;class tP extends tO{constructor(e){super(e)}}class tA{get functions(){return new c(this.functionsUrl,{headers:this.headers,customFetch:this.fetch})}get storage(){return new ej(this.storageUrl,this.headers,this.fetch)}from(e){return this.rest.from(e)}schema(e){return this.rest.schema(e)}rpc(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this.rest.rpc(e,t,s)}channel(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{config:{}};return this.realtime.channel(e,t)}getChannels(){return this.realtime.getChannels()}removeChannel(e){return this.realtime.removeChannel(e)}removeAllChannels(){return this.realtime.removeAllChannels()}_getAccessToken(){var e,t,s,r,i,n;return s=this,r=void 0,i=void 0,n=function*(){let{data:s}=yield this.auth.getSession();return null!==(t=null===(e=s.session)||void 0===e?void 0:e.access_token)&&void 0!==t?t:null},new(i||(i=Promise))(function(e,t){function a(e){try{c(n.next(e))}catch(e){t(e)}}function o(e){try{c(n.throw(e))}catch(e){t(e)}}function c(t){var s;t.done?e(t.value):((s=t.value)instanceof i?s:new i(function(e){e(s)})).then(a,o)}c((n=n.apply(s,r||[])).next())})}_initSupabaseAuthClient(e,t,s){var r;let{autoRefreshToken:i,persistSession:n,detectSessionInUrl:a,storage:o,storageKey:c,flowType:l,debug:h}=e,u={Authorization:"Bearer ".concat(this.supabaseKey),apikey:"".concat(this.supabaseKey)};return new tP({url:this.authUrl,headers:Object.assign(Object.assign({},u),t),storageKey:c,autoRefreshToken:i,persistSession:n,detectSessionInUrl:a,storage:o,flowType:l,debug:h,fetch:s,hasCustomAuthorizationHeader:"Authorization"in this.headers})}_initRealtimeClient(e){return new es(this.realtimeUrl,Object.assign(Object.assign({},e),{params:Object.assign({apikey:this.supabaseKey},null==e?void 0:e.params)}))}_listenForAuthEvents(){return this.auth.onAuthStateChange((e,t)=>{this._handleTokenChanged(e,"CLIENT",null==t?void 0:t.access_token)})}_handleTokenChanged(e,t,s){("TOKEN_REFRESHED"===e||"SIGNED_IN"===e)&&this.changedAccessToken!==s?(this.realtime.setAuth(null!=s?s:null),this.changedAccessToken=s):"SIGNED_OUT"===e&&(this.realtime.setAuth(this.supabaseKey),"STORAGE"==t&&this.auth.signOut(),this.changedAccessToken=void 0)}constructor(e,t,s){var r,i,n,a,o,c,l,h;if(this.supabaseUrl=e,this.supabaseKey=t,!e)throw Error("supabaseUrl is required.");if(!t)throw Error("supabaseKey is required.");let u=e.replace(/\/$/,"");this.realtimeUrl="".concat(u,"/realtime/v1").replace(/^http/i,"ws"),this.authUrl="".concat(u,"/auth/v1"),this.storageUrl="".concat(u,"/storage/v1"),this.functionsUrl="".concat(u,"/functions/v1");let d="sb-".concat(new URL(this.authUrl).hostname.split(".")[0],"-auth-token"),f=function(e,t){let{db:s,auth:r,realtime:i,global:n}=e,{db:a,auth:o,realtime:c,global:l}=t;return{db:Object.assign(Object.assign({},a),s),auth:Object.assign(Object.assign({},o),r),realtime:Object.assign(Object.assign({},c),i),global:Object.assign(Object.assign({},l),n)}}(null!=s?s:{},{db:eP,realtime:ex,auth:Object.assign(Object.assign({},eA),{storageKey:d}),global:eO});this.storageKey=null!==(i=null===(r=f.auth)||void 0===r?void 0:r.storageKey)&&void 0!==i?i:"",this.headers=null!==(a=null===(n=f.global)||void 0===n?void 0:n.headers)&&void 0!==a?a:{},this.auth=this._initSupabaseAuthClient(null!==(o=f.auth)&&void 0!==o?o:{},this.headers,null===(c=f.global)||void 0===c?void 0:c.fetch),this.fetch=eI(t,this._getAccessToken.bind(this),null===(l=f.global)||void 0===l?void 0:l.fetch),this.realtime=this._initRealtimeClient(Object.assign({headers:this.headers},f.realtime)),this.rest=new q("".concat(u,"/rest/v1"),{headers:this.headers,schema:null===(h=f.db)||void 0===h?void 0:h.schema,fetch:this.fetch}),this._listenForAuthEvents()}}let tx=(e,t,s)=>new tA(e,t,s);function tC(e){return null!=e&&"object"==typeof e&&!0===e["@@functional/placeholder"]}function tR(e){return function t(s){return 0==arguments.length||tC(s)?t:e.apply(this,arguments)}}function tI(e){return function t(s,r){switch(arguments.length){case 0:return t;case 1:return tC(s)?t:tR(function(t){return e(s,t)});default:return tC(s)&&tC(r)?t:tC(s)?tR(function(t){return e(t,r)}):tC(r)?tR(function(t){return e(s,t)}):e(s,r)}}}function tL(e){return function t(s,r,i){switch(arguments.length){case 0:return t;case 1:return tC(s)?t:tI(function(t,r){return e(s,t,r)});case 2:return tC(s)&&tC(r)?t:tC(s)?tI(function(t,s){return e(t,r,s)}):tC(r)?tI(function(t,r){return e(s,t,r)}):tR(function(t){return e(s,r,t)});default:return tC(s)&&tC(r)&&tC(i)?t:tC(s)&&tC(r)?tI(function(t,s){return e(t,s,i)}):tC(s)&&tC(i)?tI(function(t,s){return e(t,r,s)}):tC(r)&&tC(i)?tI(function(t,r){return e(s,t,r)}):tC(s)?tR(function(t){return e(t,r,i)}):tC(r)?tR(function(t){return e(s,t,i)}):tC(i)?tR(function(t){return e(s,r,t)}):e(s,r,i)}}}function tU(e){return"[object Object]"===Object.prototype.toString.call(e)}function tN(e,t){return Object.prototype.hasOwnProperty.call(t,e)}var tD=tL(function(e,t,s){var r,i={};for(r in s=s||{},t=t||{})tN(r,t)&&(i[r]=tN(r,s)?e(r,t[r],s[r]):t[r]);for(r in s)tN(r,s)&&!tN(r,i)&&(i[r]=s[r]);return i}),tq=tL(function e(t,s,r){return tD(function(s,r,i){return tU(r)&&tU(i)?e(t,r,i):t(s,r,i)},s,r)}),tF=tI(function(e,t){return tq(function(e,t,s){return s},e,t)}),tz=s(3175);function tB(){return void 0!==window.document}var tM={path:"/",sameSite:"lax",httpOnly:!1,maxAge:31536e6};async function tJ(e,t){let s=await t(e);if(s)return s;let r=[];for(let s=0;;s++){let i="".concat(e,".").concat(s),n=await t(i);if(!n)break;r.push(n)}if(r.length>0)return r.join("")}async function tK(e,t,s){if(await t(e)){await s(e);return}for(let r=0;;r++){let i="".concat(e,".").concat(r);if(!await t(i))break;await s(i)}}function tH(e,t,s){let r,i;if(!e||!t)throw Error("Your project's URL and Key are required to create a Supabase client!\n\nCheck your Supabase project's API settings to find these values\n\nhttps://supabase.com/dashboard/project/_/settings/api");let n={},a=!0;s&&({cookies:n,isSingleton:a=!0,cookieOptions:r,...i}=s);let o=tF({global:{headers:{"X-Client-Info":"supabase-ssr/0.1.0"}},auth:{flowType:"pkce",autoRefreshToken:tB(),detectSessionInUrl:tB(),persistSession:!0,storage:{isServer:!1,getItem:async e=>await tJ(e,async e=>"function"==typeof n.get?await n.get(e):tB()?(0,tz.Q)(document.cookie)[e]:void 0),setItem:async(e,t)=>{let s=await function(e,t,s){let r=null!=s?s:3180,i=encodeURIComponent(t);if(i.length<=r)return[{name:e,value:t}];let n=[];for(;i.length>0;){let e=i.slice(0,r),t=e.lastIndexOf("%");t>r-3&&(e=e.slice(0,t));let s="";for(;e.length>0;)try{s=decodeURIComponent(e);break}catch(t){if(t instanceof URIError&&"%"===e.at(-3)&&e.length>3)e=e.slice(0,e.length-3);else throw t}n.push(s),i=i.slice(e.length)}return n.map((t,s)=>({name:"".concat(e,".").concat(s),value:t}))}(e,t);await Promise.all(s.map(async e=>{"function"==typeof n.set?await n.set(e.name,e.value,{...tM,...r,maxAge:tM.maxAge}):tB()&&(document.cookie=(0,tz.q)(e.name,e.value,{...tM,...r,maxAge:tM.maxAge}))}))},removeItem:async e=>{if("function"==typeof n.remove&&"function"!=typeof n.get){console.log("Removing chunked cookie without a `get` method is not supported.\n\n	When you call the `createBrowserClient` function from the `@supabase/ssr` package, make sure you declare both a `get` and `remove` method on the `cookies` object.\n\nhttps://supabase.com/docs/guides/auth/server-side/creating-a-client");return}await tK(e,async e=>"function"==typeof n.get?await n.get(e):tB()?(0,tz.Q)(document.cookie)[e]:void 0,async e=>{"function"==typeof n.remove?await n.remove(e,{...tM,...r,maxAge:0}):tB()&&(document.cookie=(0,tz.q)(e,"",{...tM,...r,maxAge:0}))})}}}},i);if(a){let s=tB();if(s&&b)return b;let r=tx(e,t,o);return s&&(b=r),r}return tx(e,t,o)}}}]);