@nhost/nhost-js 1.4.12 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(R,U){typeof exports=="object"&&typeof module!="undefined"?U(exports,require("graphql")):typeof define=="function"&&define.amd?define(["exports","graphql"],U):(R=typeof globalThis!="undefined"?globalThis:R||self,U(R["@nhost/nhost-js"]={},R.graphql))})(this,function(R,U){"use strict";var da=Object.defineProperty,ha=Object.defineProperties;var pa=Object.getOwnPropertyDescriptors;var It=Object.getOwnPropertySymbols;var Ln=Object.prototype.hasOwnProperty,Mn=Object.prototype.propertyIsEnumerable;var jn=(R,U,j)=>U in R?da(R,U,{enumerable:!0,configurable:!0,writable:!0,value:j}):R[U]=j,ve=(R,U)=>{for(var j in U||(U={}))Ln.call(U,j)&&jn(R,j,U[j]);if(It)for(var j of It(U))Mn.call(U,j)&&jn(R,j,U[j]);return R},mr=(R,U)=>ha(R,pa(U));var Bn=(R,U)=>{var j={};for(var J in R)Ln.call(R,J)&&U.indexOf(J)<0&&(j[J]=R[J]);if(R!=null&&It)for(var J of It(R))U.indexOf(J)<0&&Mn.call(R,J)&&(j[J]=R[J]);return j};function j(t){this.message=t}j.prototype=new Error,j.prototype.name="InvalidCharacterError";var J=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new j("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,i=0,s=0,o="";n=e.charAt(s++);~n&&(r=i%4?64*r+n:n,i++%4)?o+=String.fromCharCode(255&r>>(-2*i&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return o};function Fn(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(r){return decodeURIComponent(J(r).replace(/(.)/g,function(n,i){var s=i.charCodeAt(0).toString(16).toUpperCase();return s.length<2&&(s="0"+s),"%"+s}))}(e)}catch{return J(e)}}function Ge(t){this.message=t}function qn(t,e){if(typeof t!="string")throw new Ge("Invalid token specified");var r=(e=e||{}).header===!0?0:1;try{return JSON.parse(Fn(t.split(".")[r]))}catch(n){throw new Ge("Invalid token specified: "+n.message)}}Ge.prototype=new Error,Ge.prototype.name="InvalidTokenError";/*! *****************************************************************************
1
+ (function(R,U){typeof exports=="object"&&typeof module!="undefined"?U(exports,require("graphql")):typeof define=="function"&&define.amd?define(["exports","graphql"],U):(R=typeof globalThis!="undefined"?globalThis:R||self,U(R["@nhost/nhost-js"]={},R.graphql))})(this,function(R,U){"use strict";var ha=Object.defineProperty,pa=Object.defineProperties;var va=Object.getOwnPropertyDescriptors;var Nt=Object.getOwnPropertySymbols;var Mn=Object.prototype.hasOwnProperty,Bn=Object.prototype.propertyIsEnumerable;var Ln=(R,U,j)=>U in R?ha(R,U,{enumerable:!0,configurable:!0,writable:!0,value:j}):R[U]=j,ye=(R,U)=>{for(var j in U||(U={}))Mn.call(U,j)&&Ln(R,j,U[j]);if(Nt)for(var j of Nt(U))Bn.call(U,j)&&Ln(R,j,U[j]);return R},mr=(R,U)=>pa(R,va(U));var Fn=(R,U)=>{var j={};for(var J in R)Mn.call(R,J)&&U.indexOf(J)<0&&(j[J]=R[J]);if(R!=null&&Nt)for(var J of Nt(R))U.indexOf(J)<0&&Bn.call(R,J)&&(j[J]=R[J]);return j};function j(t){this.message=t}j.prototype=new Error,j.prototype.name="InvalidCharacterError";var J=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new j("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,i=0,s=0,o="";n=e.charAt(s++);~n&&(r=i%4?64*r+n:n,i++%4)?o+=String.fromCharCode(255&r>>(-2*i&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return o};function qn(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(r){return decodeURIComponent(J(r).replace(/(.)/g,function(n,i){var s=i.charCodeAt(0).toString(16).toUpperCase();return s.length<2&&(s="0"+s),"%"+s}))}(e)}catch{return J(e)}}function Ge(t){this.message=t}function Vn(t,e){if(typeof t!="string")throw new Ge("Invalid token specified");var r=(e=e||{}).header===!0?0:1;try{return JSON.parse(qn(t.split(".")[r]))}catch(n){throw new Ge("Invalid token specified: "+n.message)}}Ge.prototype=new Error,Ge.prototype.name="InvalidTokenError";/*! *****************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -11,9 +11,9 @@
11
11
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
12
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
13
  PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */var m=function(){return m=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},m.apply(this,arguments)};function Nt(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function x(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function A(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}function D(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return t.concat(s||Array.prototype.slice.call(e))}var P;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(P||(P={}));var Ce;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(Ce||(Ce={}));var Ct=P.Start,Dt=P.Stop,Je=P.Raise,Ye=P.Send,gr=P.Cancel,Vn=P.NullEvent,Ut=P.Assign;P.After,P.DoneState;var Er=P.Log,Hn=P.Init,$t=P.Invoke;P.ErrorExecution;var wr=P.ErrorPlatform,Kn=P.ErrorCustom,Sr=P.Update,zn=P.Choose,Wn=P.Pure,br=".",Tr={},jt="xstate.guard",Gn="",De=!0,Qe;function Lt(t,e,r){r===void 0&&(r=br);var n=Ue(t,r),i=Ue(e,r);return O(i)?O(n)?i===n:!1:O(n)?n in i:Object.keys(n).every(function(s){return s in i?Lt(n[s],i[s]):!1})}function xr(t){try{return O(t)||typeof t=="number"?"".concat(t):t.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function Mt(t,e){try{return ye(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function Jn(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function Ue(t,e){if(Jn(t))return t.value;if(ye(t))return Xe(t);if(typeof t!="string")return t;var r=Mt(t,e);return Xe(r)}function Xe(t){if(t.length===1)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function $e(t,e){for(var r={},n=Object.keys(t),i=0;i<n.length;i++){var s=n[i];r[s]=e(t[s],s,t,i)}return r}function _r(t,e,r){var n,i,s={};try{for(var o=x(Object.keys(t)),a=o.next();!a.done;a=o.next()){var c=a.value,f=t[c];!r(f)||(s[c]=e(f,c,t))}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}var Yn=function(t){return function(e){var r,n,i=e;try{for(var s=x(t),o=s.next();!o.done;o=s.next()){var a=o.value;i=i[a]}}catch(c){r={error:c}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function Qn(t,e){return function(r){var n,i,s=r;try{for(var o=x(t),a=o.next();!a.done;a=o.next()){var c=a.value;s=s[e][c]}}catch(f){n={error:f}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}}function Ze(t){if(!t)return[[]];if(O(t))return[[t]];var e=N(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Ze(t[r]).map(function(i){return[r].concat(i)})}));return e}function N(t){var e;return(e=[]).concat.apply(e,D([],A(t),!1))}function Or(t){return ye(t)?t:[t]}function Q(t){return t===void 0?[]:Or(t)}function et(t,e,r){var n,i;if(k(t))return t(e,r.data);var s={};try{for(var o=x(Object.keys(t)),a=o.next();!a.done;a=o.next()){var c=a.value,f=t[c];k(f)?s[c]=f(e,r.data):s[c]=f}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}function Xn(t){return/^(done|error)\./.test(t)}function Ar(t){return!!(t instanceof Promise||t!==null&&(k(t)||typeof t=="object")&&k(t.then))}function Zn(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function Rr(t,e){var r,n,i=A([[],[]],2),s=i[0],o=i[1];try{for(var a=x(t),c=a.next();!c.done;c=a.next()){var f=c.value;e(f)?s.push(f):o.push(f)}}catch(u){r={error:u}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}return[s,o]}function Pr(t,e){return $e(t.states,function(r,n){if(!!r){var i=(O(e)?void 0:e[n])||(r?r.current:void 0);if(!!i)return{current:i,states:Pr(r,i)}}})}function ei(t,e){return{current:e,states:Pr(t,e)}}function kr(t,e,r,n){var i=t&&r.reduce(function(s,o){var a,c,f=o.assignment,u={state:n,action:o,_event:e},p={};if(k(f))p=f(s,e.data,u);else try{for(var d=x(Object.keys(f)),l=d.next();!l.done;l=d.next()){var h=l.value,v=f[h];p[h]=k(v)?v(s,e.data,u):v}}catch(y){a={error:y}}finally{try{l&&!l.done&&(c=d.return)&&c.call(d)}finally{if(a)throw a.error}}return Object.assign({},s,p)},t);return i}var je=function(){};function ye(t){return Array.isArray(t)}function k(t){return typeof t=="function"}function O(t){return typeof t=="string"}function Ir(t,e){if(!!t)return O(t)?{type:jt,name:t,predicate:e?e[t]:void 0}:k(t)?{type:jt,name:t.name,predicate:t}:t}function ti(t){try{return"subscribe"in t&&k(t.subscribe)}catch{return!1}}var se=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();Qe={},Qe[se]=function(){return this},Qe[Symbol.observable]=function(){return this};function le(t){return!!t&&"__xstatenode"in t}function ri(t){return!!t&&typeof t.send=="function"}function Bt(t,e){return O(t)||typeof t=="number"?m({type:t},e):t}function V(t,e){if(!O(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=Bt(t);return m({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function me(t,e){var r=Or(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||le(n)?{target:n,event:t}:m(m({},n),{event:t})});return r}function ni(t){if(!(t===void 0||t===Gn))return Q(t)}function Nr(t,e,r,n,i){var s=t.options.guards,o={state:i,cond:e,_event:n};if(e.type===jt)return((s==null?void 0:s[e.name])||e.predicate)(r,n.data,o);var a=s==null?void 0:s[e.type];if(!a)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return a(r,n.data,o)}function Cr(t){return typeof t=="string"?{type:t}:t}function Ft(t,e,r){if(typeof t=="object")return t;var n=function(){};return{next:t,error:e||n,complete:r||n}}function tt(t,e){return"".concat(t,":invocation[").concat(e,"]")}var rt=V({type:Hn});function qt(t,e){return e&&e[t]||void 0}function Le(t,e){var r;if(O(t)||typeof t=="number"){var n=qt(t,e);k(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(k(t))r={type:t.name||t.toString(),exec:t};else{var n=qt(t.type,e);if(k(n))r=m(m({},t),{exec:n});else if(n){var i=n.type||t.type;r=m(m(m({},n),t),{type:i})}else r=t}return r}var nt=function(t,e){if(!t)return[];var r=ye(t)?t:[t];return r.map(function(n){return Le(n,e)})};function Vt(t){var e=Le(t);return m(m({id:O(t)?t:e.id},e),{type:e.type})}function ii(t){return O(t)?{type:Je,event:t}:Ht(t,{to:Ce.Internal})}function si(t){return{type:Je,_event:V(t.event)}}function Ht(t,e){return{to:e?e.to:void 0,type:Ye,event:k(t)?t:Bt(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:k(t)?t.name:xr(t)}}function oi(t,e,r,n){var i={_event:r},s=V(k(t.event)?t.event(e,r.data,i):t.event),o;if(O(t.delay)){var a=n&&n[t.delay];o=k(a)?a(e,r.data,i):a}else o=k(t.delay)?t.delay(e,r.data,i):t.delay;var c=k(t.to)?t.to(e,r.data,i):t.to;return m(m({},t),{to:c,_event:s,event:s.data,delay:o})}var ai=function(t,e,r){return m(m({},t),{value:O(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},ui=function(t){return{type:gr,sendId:t}};function ci(t){var e=Vt(t);return{type:P.Start,activity:e,exec:void 0}}function li(t){var e=k(t)?t:Vt(t);return{type:P.Stop,activity:e,exec:void 0}}function fi(t,e,r){var n=k(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:P.Stop,activity:i};return s}var di=function(t){return{type:Ut,assignment:t}};function hi(t,e){var r=e?"#".concat(e):"";return"".concat(P.After,"(").concat(t,")").concat(r)}function it(t,e){var r="".concat(P.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function st(t,e){var r="".concat(P.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Me(t,e){var r="".concat(P.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Kt(t,e,r,n,i,s){s===void 0&&(s=!1);var o=A(s?[[],i]:Rr(i,function(d){return d.type===Ut}),2),a=o[0],c=o[1],f=a.length?kr(r,n,a,e):r,u=s?[r]:void 0,p=N(c.map(function(d){var l;switch(d.type){case Je:return si(d);case Ye:var h=oi(d,f,n,t.options.delays);return h;case Er:return ai(d,f,n);case zn:{var v=d,y=(l=v.conds.find(function(C){var q=Ir(C.cond,t.options.guards);return!q||Nr(t,q,f,n,e)}))===null||l===void 0?void 0:l.actions;if(!y)return[];var E=A(Kt(t,e,f,n,nt(Q(y),t.options.actions),s),2),g=E[0],S=E[1];return f=S,u==null||u.push(f),g}case Wn:{var y=d.get(f,n.data);if(!y)return[];var I=A(Kt(t,e,f,n,nt(Q(y),t.options.actions),s),2),_=I[0],$=I[1];return f=$,u==null||u.push(f),_}case Dt:return fi(d,f,n);case Ut:{f=kr(f,n,[d],e),u==null||u.push(f);break}default:var b=Le(d,t.options.actions),w=b.exec;if(w&&u){var T=u.length-1;b=m(m({},b),{exec:function(C){for(var q=[],W=1;W<arguments.length;W++)q[W-1]=arguments[W];w.apply(void 0,D([u[T]],A(q),!1))}})}return b}}).filter(function(d){return!!d}));return[p,f]}var Be=function(t,e){var r=e(t);return r};function Dr(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[se]=function(){return this},e}function pi(t,e,r,n){var i,s=Cr(t.src),o=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],a=t.data?et(t.data,r,n):void 0,c=o?vi(o,t.id,a):Dr(t.id);return c.meta=t,c}function vi(t,e,r){var n=Dr(e);if(n.deferred=!0,le(t)){var i=n.state=Be(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function yi(t){try{return typeof t.send=="function"}catch{return!1}}function mi(t){return yi(t)&&"id"in t}function gi(t){var e;return m((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[se]=function(){return this},e),t)}var ot=function(t){return t.type==="atomic"||t.type==="final"};function ge(t){return Object.keys(t.states).map(function(e){return t.states[e]}).filter(function(e){return e.type!=="history"})}function Ur(t){var e=[t];return ot(t)?e:e.concat(N(ge(t).map(Ur)))}function Ee(t,e){var r,n,i,s,o,a,c,f,u=new Set(t),p=zt(u),d=new Set(e);try{for(var l=x(d),h=l.next();!h.done;h=l.next())for(var v=h.value,y=v.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(T){r={error:T}}finally{try{h&&!h.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}var E=zt(d);try{for(var g=x(d),S=g.next();!S.done;S=g.next()){var v=S.value;if(v.type==="compound"&&(!E.get(v)||!E.get(v).length))p.get(v)?p.get(v).forEach(function(C){return d.add(C)}):v.initialStateNodes.forEach(function(C){return d.add(C)});else if(v.type==="parallel")try{for(var I=(o=void 0,x(ge(v))),_=I.next();!_.done;_=I.next()){var $=_.value;d.has($)||(d.add($),p.get($)?p.get($).forEach(function(C){return d.add(C)}):$.initialStateNodes.forEach(function(C){return d.add(C)}))}}catch(C){o={error:C}}finally{try{_&&!_.done&&(a=I.return)&&a.call(I)}finally{if(o)throw o.error}}}}catch(T){i={error:T}}finally{try{S&&!S.done&&(s=g.return)&&s.call(g)}finally{if(i)throw i.error}}try{for(var b=x(d),w=b.next();!w.done;w=b.next())for(var v=w.value,y=v.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(T){c={error:T}}finally{try{w&&!w.done&&(f=b.return)&&f.call(b)}finally{if(c)throw c.error}}return d}function $r(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(ot(n))return n.key}else return{}}var i={};return r.forEach(function(s){i[s.key]=$r(s,e)}),i}function zt(t){var e,r,n=new Map;try{for(var i=x(t),s=i.next();!s.done;s=i.next()){var o=s.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(a){e={error:a}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n}function Ei(t,e){var r=Ee([t],e);return $r(t,zt(r))}function at(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function wi(t){return D([],A(new Set(N(D([],A(t.map(function(e){return e.ownEvents})),!1)))),!1)}function Fe(t,e){return e.type==="compound"?ge(e).some(function(r){return r.type==="final"&&at(t,r)}):e.type==="parallel"?ge(e).every(function(r){return Fe(t,r)}):!1}function Si(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function jr(t){return new Set(N(t.map(function(e){return e.tags})))}function Lr(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(O(t)||O(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(i){return Lr(t[i],e[i])})}function bi(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function Ti(t,e){var r=t.exec,n=m(m({},t),{exec:r!==void 0?function(){return r(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0});return n}var re=function(){function t(e){var r=this,n;this.actions=[],this.activities=Tr,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||Tr,this.meta=Si(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=(n=Array.isArray(e.tags)?new Set(e.tags):e.tags)!==null&&n!==void 0?n:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:function(){return wi(r.configuration)}})}return t.from=function(e,r){if(e instanceof t)return e.context!==r?new t({value:e.value,context:r,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e;var n=rt;return new t({value:e,context:r,_event:n,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,r){if(e instanceof t){if(!e.actions.length)return e;var n=rt;return new t({value:e.value,context:r,_event:n,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,r)},t.prototype.toStrings=function(e,r){var n=this;if(e===void 0&&(e=this.value),r===void 0&&(r="."),O(e))return[e];var i=Object.keys(e);return i.concat.apply(i,D([],A(i.map(function(s){return n.toStrings(e[s],r).map(function(o){return s+r+o})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=Nt(e,["configuration","transitions","tags","machine"]);return m(m({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Lt(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;je(!!this.machine);var n=(r=this.machine)===null||r===void 0?void 0:r.getTransitionData(this,e);return!!(n!=null&&n.transitions.length)&&n.transitions.some(function(i){return i.target!==void 0||i.actions.length})},t}(),xi={deferEvents:!1},Mr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=m(m({},xi),e)}return t.prototype.initialize=function(e){if(this.initialized=!0,e){if(!this.options.deferEvents){this.schedule(e);return}this.process(e)}this.flushEvents()},t.prototype.schedule=function(e){if(!this.initialized||this.processingEvent){this.queue.push(e);return}if(this.queue.length!==0)throw new Error("Event queue should be empty when it is not processing events");this.process(e),this.flushEvents()},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var e=this.queue.shift();e;)this.process(e),e=this.queue.shift()},t.prototype.process=function(e){this.processingEvent=!0;try{e()}catch(r){throw this.clear(),r}finally{this.processingEvent=!1}},t}(),Wt=new Map,_i=0,ut={bookId:function(){return"x:".concat(_i++)},register:function(t,e){return Wt.set(t,e),t},get:function(t){return Wt.get(t)},free:function(t){Wt.delete(t)}};function Gt(){if(typeof globalThis!="undefined")return globalThis;if(typeof self!="undefined")return self;if(typeof window!="undefined")return window;if(typeof global!="undefined")return global}function Oi(){var t=Gt();if(t&&"__xstate__"in t)return t.__xstate__}function Ai(t){if(!!Gt()){var e=Oi();e&&e.register(t)}}function Ri(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,o=function(){if(!s){for(s=!0;i.length>0;){var f=i.shift();r=t.transition(r,f,c),n.forEach(function(u){return u.next(r)})}s=!1}},a=gi({id:e.id,send:function(f){i.push(f),o()},getSnapshot:function(){return r},subscribe:function(f,u,p){var d=Ft(f,u,p);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),c={parent:e.parent,self:a,id:e.id||"anonymous",observers:n};return r=t.start?t.start(c):r,a}var Pi={sync:!1,autoForward:!1},H;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(H||(H={}));var ki=function(){function t(e,r){var n=this;r===void 0&&(r=t.defaultOptions),this.machine=e,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=H.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(u,p){if(ye(u))return n.batch(u),n.state;var d=V(Bt(u,p));if(n.status===H.Stopped)return n.state;if(n.status!==H.Running&&!n.options.deferEvents)throw new Error('Event "'.concat(d.name,'" was sent to uninitialized service "').concat(n.machine.id,`". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
15
- Event: `).concat(JSON.stringify(d.data)));return n.scheduler.schedule(function(){n.forward(d);var l=n.nextState(d);n.update(l,d)}),n._state},this.sendTo=function(u,p){var d=n.parent&&(p===Ce.Parent||n.parent.id===p),l=d?n.parent:O(p)?n.children.get(p)||ut.get(p):ri(p)?p:void 0;if(!l){if(!d)throw new Error("Unable to send event to child '".concat(p,"' from service '").concat(n.id,"'."));return}"machine"in l?l.send(m(m({},u),{name:u.name===Kn?"".concat(Me(n.id)):u.name,origin:n.sessionId})):l.send(u.data)};var i=m(m({},t.defaultOptions),r),s=i.clock,o=i.logger,a=i.parent,c=i.id,f=c!==void 0?c:e.id;this.id=f,this.logger=o,this.clock=s,this.parent=a,this.options=i,this.scheduler=new Mr({deferEvents:this.options.deferEvents}),this.sessionId=ut.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Be(this,function(){return e._initialState=e.machine.initialState,e._initialState})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),t.prototype.execute=function(e,r){var n,i;try{for(var s=x(e.actions),o=s.next();!o.done;o=s.next()){var a=o.value;this.exec(a,e,r)}}catch(c){n={error:c}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,o,a,c,f,u,p=this;if(e._sessionid=this.sessionId,this._state=e,this.options.execute&&this.execute(this.state),this.children.forEach(function(T){p.state.children[T.id]=T}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var d=x(this.eventListeners),l=d.next();!l.done;l=d.next()){var h=l.value;h(e.event)}}catch(T){n={error:T}}finally{try{l&&!l.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var v=x(this.listeners),y=v.next();!y.done;y=v.next()){var h=y.value;h(e,e.event)}}catch(T){s={error:T}}finally{try{y&&!y.done&&(o=v.return)&&o.call(v)}finally{if(s)throw s.error}}try{for(var E=x(this.contextListeners),g=E.next();!g.done;g=E.next()){var S=g.value;S(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(T){a={error:T}}finally{try{g&&!g.done&&(c=E.return)&&c.call(E)}finally{if(a)throw a.error}}var I=Fe(e.configuration||[],this.machine);if(this.state.configuration&&I){var _=e.configuration.find(function(T){return T.type==="final"&&T.parent===p.machine}),$=_&&_.doneData?et(_.doneData,e.context,r):void 0;try{for(var b=x(this.doneListeners),w=b.next();!w.done;w=b.next()){var h=w.value;h(st(this.id,$))}}catch(T){f={error:T}}finally{try{w&&!w.done&&(u=b.return)&&u.call(b)}finally{if(f)throw f.error}}this.stop()}},t.prototype.onTransition=function(e){return this.listeners.add(e),this.status===H.Running&&e(this.state,this.state.event),this},t.prototype.subscribe=function(e,r,n){var i=this;if(!e)return{unsubscribe:function(){}};var s,o=n;return typeof e=="function"?s=e:(s=e.next.bind(e),o=e.complete.bind(e)),this.listeners.add(s),this.status!==H.NotStarted&&s(this.state),o&&(this.status===H.Stopped?o():this.onDone(o)),{unsubscribe:function(){s&&i.listeners.delete(s),o&&i.doneListeners.delete(o)}}},t.prototype.onEvent=function(e){return this.eventListeners.add(e),this},t.prototype.onSend=function(e){return this.sendListeners.add(e),this},t.prototype.onChange=function(e){return this.contextListeners.add(e),this},t.prototype.onStop=function(e){return this.stopListeners.add(e),this},t.prototype.onDone=function(e){return this.doneListeners.add(e),this},t.prototype.off=function(e){return this.listeners.delete(e),this.eventListeners.delete(e),this.sendListeners.delete(e),this.stopListeners.delete(e),this.doneListeners.delete(e),this.contextListeners.delete(e),this},t.prototype.start=function(e){var r=this;if(this.status===H.Running)return this;this.machine._init(),ut.register(this.sessionId,this),this.initialized=!0,this.status=H.Running;var n=e===void 0?this.initialState:Be(this,function(){return bi(e)?r.machine.resolveState(e):r.machine.resolveState(re.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,rt)}),this},t.prototype.stop=function(){var e,r,n,i,s,o,a,c,f,u,p=this;try{for(var d=x(this.listeners),l=d.next();!l.done;l=d.next()){var h=l.value;this.listeners.delete(h)}}catch(w){e={error:w}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}try{for(var v=x(this.stopListeners),y=v.next();!y.done;y=v.next()){var h=y.value;h(),this.stopListeners.delete(h)}}catch(w){n={error:w}}finally{try{y&&!y.done&&(i=v.return)&&i.call(v)}finally{if(n)throw n.error}}try{for(var E=x(this.contextListeners),g=E.next();!g.done;g=E.next()){var h=g.value;this.contextListeners.delete(h)}}catch(w){s={error:w}}finally{try{g&&!g.done&&(o=E.return)&&o.call(E)}finally{if(s)throw s.error}}try{for(var S=x(this.doneListeners),I=S.next();!I.done;I=S.next()){var h=I.value;this.doneListeners.delete(h)}}catch(w){a={error:w}}finally{try{I&&!I.done&&(c=S.return)&&c.call(S)}finally{if(a)throw a.error}}if(!this.initialized)return this;D([],A(this.state.configuration),!1).sort(function(w,T){return T.order-w.order}).forEach(function(w){var T,C;try{for(var q=x(w.definition.exit),W=q.next();!W.done;W=q.next()){var ce=W.value;p.exec(ce,p.state)}}catch(kt){T={error:kt}}finally{try{W&&!W.done&&(C=q.return)&&C.call(q)}finally{if(T)throw T.error}}}),this.children.forEach(function(w){k(w.stop)&&w.stop()}),this.children.clear();try{for(var _=x(Object.keys(this.delayedEventsMap)),$=_.next();!$.done;$=_.next()){var b=$.value;this.clock.clearTimeout(this.delayedEventsMap[b])}}catch(w){f={error:w}}finally{try{$&&!$.done&&(u=_.return)&&u.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.scheduler=new Mr({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=H.Stopped,this._initialState=void 0,ut.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(!(this.status===H.NotStarted&&this.options.deferEvents)){if(this.status!==H.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'))}this.scheduler.schedule(function(){var n,i,s=r.state,o=!1,a=[],c=function(d){var l=V(d);r.forward(l),s=Be(r,function(){return r.machine.transition(s,l)}),a.push.apply(a,D([],A(s.actions.map(function(h){return Ti(h,s)})),!1)),o=o||!!s.changed};try{for(var f=x(e),u=f.next();!u.done;u=f.next()){var p=u.value;c(p)}}catch(d){n={error:d}}finally{try{u&&!u.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}s.changed=o,s.actions=a,r.update(s,V(e[e.length-1]))})},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype.nextState=function(e){var r=this,n=V(e);if(n.name.indexOf(wr)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(wr)===0}))throw n.data.data;var i=Be(this,function(){return r.machine.transition(r.state,n)});return i},t.prototype.forward=function(e){var r,n;try{for(var i=x(this.forwardTo),s=i.next();!s.done;s=i.next()){var o=s.value,a=this.children.get(o);if(!a)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(o,"'."));a.send(e)}}catch(c){r={error:c}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}},t.prototype.defer=function(e){var r=this;this.delayedEventsMap[e.id]=this.clock.setTimeout(function(){e.to?r.sendTo(e._event,e.to):r.send(e._event)},e.delay)},t.prototype.cancel=function(e){this.clock.clearTimeout(this.delayedEventsMap[e]),delete this.delayedEventsMap[e]},t.prototype.exec=function(e,r,n){n===void 0&&(n=this.machine.options.actions);var i=r.context,s=r._event,o=e.exec||qt(e.type,n),a=k(o)?o:o?o.exec:e.exec;if(a)try{return a(i,s.data,{action:e,state:this.state,_event:s})}catch(I){throw this.parent&&this.parent.send({type:"xstate.error",data:I}),I}switch(e.type){case Ye:var c=e;if(typeof c.delay=="number"){this.defer(c);return}else c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case gr:this.cancel(e.sendId);break;case Ct:{if(this.status!==H.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===P.Invoke){var u=Cr(f.src),p=this.machine.options.services?this.machine.options.services[u.type]:void 0,d=f.id,l=f.data,h="autoForward"in f?f.autoForward:!!f.forward;if(!p)return;var v=l?et(l,i,s):void 0;if(typeof p=="string")return;var y=k(p)?p(i,s.data,{data:v,src:u,meta:f.meta}):p;if(!y)return;var E=void 0;le(y)&&(y=v?y.withContext(v):y,E={autoForward:h}),this.spawn(y,d,E)}else this.spawnActivity(f);break}case Dt:{this.stopChild(e.activity.id);break}case Er:var g=e.label,S=e.value;g?this.logger(g,S):this.logger(S);break}},t.prototype.removeChild=function(e){var r;this.children.delete(e),this.forwardTo.delete(e),(r=this.state)===null||r===void 0||delete r.children[e]},t.prototype.stopChild=function(e){var r=this.children.get(e);!r||(this.removeChild(e),k(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(Ar(e))return this.spawnPromise(Promise.resolve(e),r);if(k(e))return this.spawnCallback(e,r);if(mi(e))return this.spawnActor(e,r);if(ti(e))return this.spawnObservable(e,r);if(le(e))return this.spawnMachine(e,m(m({},n),{id:r}));if(Zn(e))return this.spawnBehavior(e,r);throw new Error('Unable to spawn entity "'.concat(r,'" of type "').concat(typeof e,'".'))},t.prototype.spawnMachine=function(e,r){var n=this;r===void 0&&(r={});var i=new t(e,m(m({},this.options),{parent:this,id:r.id||e.id})),s=m(m({},Pi),r);s.sync&&i.onTransition(function(a){n.send(Sr,{state:a,id:i.id})});var o=i;return this.children.set(i.id,o),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(a){n.removeChild(i.id),n.send(V(a,{origin:i.id}))}).start(),o},t.prototype.spawnBehavior=function(e,r){var n=Ri(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,o;e.then(function(c){s||(o=c,i.removeChild(r),i.send(V(st(r,c),{origin:r})))},function(c){if(!s){i.removeChild(r);var f=Me(r,c);try{i.send(V(f,{origin:r}))}catch{i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var a=(n={id:r,send:function(){},subscribe:function(c,f,u){var p=Ft(c,f,u),d=!1;return e.then(function(l){d||(p.next(l),!d&&p.complete())},function(l){d||p.error(l)}),{unsubscribe:function(){return d=!0}}},stop:function(){s=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return o}},n[se]=function(){return this},n);return this.children.set(r,a),a},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,o=new Set,a=new Set,c,f=function(d){c=d,a.forEach(function(l){return l(d)}),!s&&i.send(V(d,{origin:r}))},u;try{u=e(f,function(d){o.add(d)})}catch(d){this.send(Me(r,d))}if(Ar(u))return this.spawnPromise(u,r);var p=(n={id:r,send:function(d){return o.forEach(function(l){return l(d)})},subscribe:function(d){var l=Ft(d);return a.add(l.next),{unsubscribe:function(){a.delete(l.next)}}},stop:function(){s=!0,k(u)&&u()},toJSON:function(){return{id:r}},getSnapshot:function(){return c}},n[se]=function(){return this},n);return this.children.set(r,p),p},t.prototype.spawnObservable=function(e,r){var n,i=this,s,o=e.subscribe(function(c){s=c,i.send(V(c,{origin:r}))},function(c){i.removeChild(r),i.send(V(Me(r,c),{origin:r}))},function(){i.removeChild(r),i.send(V(st(r),{origin:r}))}),a=(n={id:r,send:function(){},subscribe:function(c,f,u){return e.subscribe(c,f,u)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[se]=function(){return this},n);return this.children.set(r,a),a},t.prototype.spawnActor=function(e,r){return this.children.set(r,e),e},t.prototype.spawnActivity=function(e){var r=this.machine.options&&this.machine.options.activities?this.machine.options.activities[e.type]:void 0;if(!!r){var n=r(this.state.context,e);this.spawnEffect(e.id,n)}},t.prototype.spawnEffect=function(e,r){var n;this.children.set(e,(n={id:e,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:r||void 0,getSnapshot:function(){},toJSON:function(){return{id:e}}},n[se]=function(){return this},n))},t.prototype.attachDev=function(){var e=Gt();if(this.options.devTools&&e){if(e.__REDUX_DEVTOOLS_EXTENSION__){var r=typeof this.options.devTools=="object"?this.options.devTools:void 0;this.devTools=e.__REDUX_DEVTOOLS_EXTENSION__.connect(m(m({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:m({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}Ai(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[se]=function(){return this},t.prototype.getSnapshot=function(){return this.status===H.NotStarted?this.initialState:this._state},t.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(e,r){return setTimeout(e,r)},clearTimeout:function(e){return clearTimeout(e)}},logger:console.log.bind(console),devTools:!1},t.interpret=we,t}();function we(t,e){var r=new ki(t,e);return r}function Ii(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function ct(t){return m(m({type:$t},t),{toJSON:function(){t.onDone,t.onError;var e=Nt(t,["onDone","onError"]);return m(m({},e),{type:$t,src:Ii(t.src)})}})}var Se="",Jt="#",qe="*",be={},Te=function(t){return t[0]===Jt},Ni=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Ci=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(O(s.target)||le(s.target))}),i=e===Se?"the transient event":"event '".concat(e,"'");je(!n,"One or more transitions for ".concat(i," on state '").concat(t.id,"' are unreachable. ")+"Make sure that the default transition is the last one defined.")},Di=function(){function t(e,r,n,i){var s=this;n===void 0&&(n="context"in e?e.context:void 0);var o;this.config=e,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign(Ni(),r),this.parent=i==null?void 0:i.parent,this.key=this.config.key||(i==null?void 0:i.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:br),this.id=this.config.id||D([this.machine.key],A(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:(o=this.config.schema)!==null&&o!==void 0?o:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?$e(this.config.states,function(f,u){var p,d=new t(f,{},void 0,{parent:s,key:u});return Object.assign(s.idMap,m((p={},p[d.id]=d,p),d.idMap)),d}):be;var a=0;function c(f){var u,p;f.order=a++;try{for(var d=x(ge(f)),l=d.next();!l.done;l=d.next()){var h=l.value;c(h)}}catch(v){u={error:v}}finally{try{l&&!l.done&&(p=d.return)&&p.call(d)}finally{if(u)throw u.error}}}c(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(f){var u=f.event;return u===Se}):Se in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=Q(this.config.entry||this.config.onEntry).map(function(f){return Le(f)}),this.onExit=Q(this.config.exit||this.config.onExit).map(function(f){return Le(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=Q(this.config.invoke).map(function(f,u){var p,d;if(le(f)){var l=tt(s.id,u);return s.machine.options.services=m((p={},p[l]=f,p),s.machine.options.services),ct({src:l,id:l})}else if(O(f.src)){var l=f.id||tt(s.id,u);return ct(m(m({},f),{id:l,src:f.src}))}else if(le(f.src)||k(f.src)){var l=f.id||tt(s.id,u);return s.machine.options.services=m((d={},d[l]=f.src,d),s.machine.options.services),ct(m(m({id:l},f),{src:l}))}else{var h=f.src;return ct(m(m({id:tt(s.id,u)},f),{src:h}))}}),this.activities=Q(this.config.activities).concat(this.invoke).map(function(f){return Vt(f)}),this.transition=this.transition.bind(this),this.tags=Q(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||Ur(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,o=n.guards,a=n.services,c=n.delays;return new t(this.config,{actions:m(m({},i),e.actions),activities:m(m({},s),e.activities),guards:m(m({},o),e.guards),services:m(m({},a),e.services),delays:m(m({},c),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return k(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:$e(this.states,function(e){return e.definition}),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var e=this.transitions;return this.__cache.on=e.reduce(function(r,n){return r[n.eventType]=r[n.eventType]||[],r[n.eventType].push(n),r},{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(e){if(this.__cache.candidates[e])return this.__cache.candidates[e];var r=e===Se,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===qe});return this.__cache.candidates[e]=n,n},t.prototype.getDelayedTransitions=function(){var e=this,r=this.config.after;if(!r)return[];var n=function(s,o){var a=k(s)?"".concat(e.id,":delay[").concat(o,"]"):s,c=hi(a,e.id);return e.onEntry.push(Ht(c,{delay:s})),e.onExit.push(ui(c)),c},i=ye(r)?r.map(function(s,o){var a=n(s.delay,o);return m(m({},s),{event:a})}):N(Object.keys(r).map(function(s,o){var a=r[s],c=O(a)?{target:a}:a,f=isNaN(+s)?s:+s,u=n(f,o);return Q(c).map(function(p){return m(m({},p),{event:u,delay:f})})}));return i.map(function(s){var o=s.delay;return m(m({},e.formatTransition(s)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof re?e.value:Ue(e,this.delimiter);if(O(i)){var s=this.getStateNode(i).initial;return s!==void 0?this.getStateNodes((r={},r[i]=s,r)):[this,this.states[i]]}var o=Object.keys(i),a=[this];return a.push.apply(a,D([],A(N(o.map(function(c){return n.getStateNode(c).getStateNodes(i[c])}))),!1)),a},t.prototype.handles=function(e){var r=xr(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof re?e:re.create(e),n=Array.from(Ee([],this.getStateNodes(r.value)));return new re(m(m({},r),{value:this.resolve(r.value),configuration:n,done:Fe(n,this),tags:jr(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var i=this.getStateNode(e),s=i.next(r,n);return!s||!s.transitions.length?this.next(r,n):s},t.prototype.transitionCompoundNode=function(e,r,n){var i=Object.keys(e),s=this.getStateNode(i[0]),o=s._transition(e[i[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},t.prototype.transitionParallelNode=function(e,r,n){var i,s,o={};try{for(var a=x(Object.keys(e)),c=a.next();!c.done;c=a.next()){var f=c.value,u=e[f];if(!!u){var p=this.getStateNode(f),d=p._transition(u,r,n);d&&(o[f]=d)}}}catch(g){i={error:g}}finally{try{c&&!c.done&&(s=a.return)&&s.call(a)}finally{if(i)throw i.error}}var l=Object.keys(o).map(function(g){return o[g]}),h=N(l.map(function(g){return g.transitions})),v=l.some(function(g){return g.transitions.length>0});if(!v)return this.next(r,n);var y=N(l.map(function(g){return g.entrySet})),E=N(Object.keys(o).map(function(g){return o[g].configuration}));return{transitions:h,entrySet:y,exitSet:N(l.map(function(g){return g.exitSet})),configuration:E,source:r,actions:N(Object.keys(o).map(function(g){return o[g].actions}))}},t.prototype._transition=function(e,r,n){return O(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,V(r))},t.prototype.next=function(e,r){var n,i,s=this,o=r.name,a=[],c=[],f;try{for(var u=x(this.getCandidates(o)),p=u.next();!p.done;p=u.next()){var d=p.value,l=d.cond,h=d.in,v=e.context,y=h?O(h)&&Te(h)?e.matches(Ue(this.getStateNodeById(h).path,this.delimiter)):Lt(Ue(h,this.delimiter),Yn(this.path.slice(0,-2))(e.value)):!0,E=!1;try{E=!l||Nr(this.machine,l,v,r,e)}catch(_){throw new Error("Unable to evaluate guard '".concat(l.name||l.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,`':
16
- `).concat(_.message))}if(E&&y){d.target!==void 0&&(c=d.target),a.push.apply(a,D([],A(d.actions),!1)),f=d;break}}}catch(_){n={error:_}}finally{try{p&&!p.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}if(!!f){if(!c.length)return{transitions:[f],entrySet:[],exitSet:[],configuration:e.value?[this]:[],source:e,actions:a};var g=N(c.map(function(_){return s.getRelativeStateNodes(_,e.historyValue)})),S=!!f.internal,I=S?[]:N(g.map(function(_){return s.nodesFromChild(_)}));return{transitions:[f],entrySet:I,exitSet:S?[]:[this],configuration:g,source:e,actions:a}}},t.prototype.nodesFromChild=function(e){if(e.escapes(this))return[];for(var r=[],n=e;n&&n!==this;)r.push(n),n=n.parent;return r.push(this),r},t.prototype.escapes=function(e){if(this===e)return!1;for(var r=this.parent;r;){if(r===e)return!1;r=r.parent}return!0},t.prototype.getActions=function(e,r,n,i){var s,o,a,c,f=Ee([],i?this.getStateNodes(i.value):[this]),u=e.configuration.length?Ee(f,e.configuration):f;try{for(var p=x(u),d=p.next();!d.done;d=p.next()){var l=d.value;at(f,l)||e.entrySet.push(l)}}catch(b){s={error:b}}finally{try{d&&!d.done&&(o=p.return)&&o.call(p)}finally{if(s)throw s.error}}try{for(var h=x(f),v=h.next();!v.done;v=h.next()){var l=v.value;(!at(u,l)||at(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(b){a={error:b}}finally{try{v&&!v.done&&(c=h.return)&&c.call(h)}finally{if(a)throw a.error}}var y=N(e.entrySet.map(function(b){var w=[];if(b.type!=="final")return w;var T=b.parent;if(!T.parent)return w;w.push(it(b.id,b.doneData),it(T.id,b.doneData?et(b.doneData,r,n):void 0));var C=T.parent;return C.type==="parallel"&&ge(C).every(function(q){return Fe(e.configuration,q)})&&w.push(it(C.id)),w}));e.exitSet.sort(function(b,w){return w.order-b.order}),e.entrySet.sort(function(b,w){return b.order-w.order});var E=new Set(e.entrySet),g=new Set(e.exitSet),S=A([N(Array.from(E).map(function(b){return D(D([],A(b.activities.map(function(w){return ci(w)})),!1),A(b.onEntry),!1)})).concat(y.map(ii)),N(Array.from(g).map(function(b){return D(D([],A(b.onExit),!1),A(b.activities.map(function(w){return li(w)})),!1)}))],2),I=S[0],_=S[1],$=nt(_.concat(e.actions).concat(I),this.machine.options.actions);return $},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=V(r),s;if(e instanceof re)s=n===void 0?e:this.resolveState(re.from(e,n));else{var o=O(e)?this.resolve(Xe(this.getResolvedPath(e))):this.resolve(e),a=n!=null?n:this.machine.context;s=this.resolveState(re.from(o,a))}if(!De&&i.name===qe)throw new Error("An event cannot have the wildcard type ('".concat(qe,"')"));if(this.strict&&!this.events.includes(i.name)&&!Xn(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var c=this._transition(s.value,s,i)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},f=Ee([],this.getStateNodes(s.value)),u=c.configuration.length?Ee(f,c.configuration):f;return c.configuration=D([],A(u),!1),this.resolveTransition(c,s,s.context,i)},t.prototype.resolveRaisedTransition=function(e,r,n){var i,s=e.actions;return e=this.transition(e,r),e._event=n,e.event=n.data,(i=e.actions).unshift.apply(i,D([],A(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,o,a=this;i===void 0&&(i=rt);var c=e.configuration,f=!r||e.transitions.length>0,u=f?Ei(this.machine,c):void 0,p=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,d=this.getActions(e,n,i,r),l=r?m({},r.activities):{};try{for(var h=x(d),v=h.next();!v.done;v=h.next()){var y=v.value;y.type===Ct?l[y.activity.id||y.activity.type]=y:y.type===Dt&&(l[y.activity.id||y.activity.type]=!1)}}catch(G){s={error:G}}finally{try{v&&!v.done&&(o=h.return)&&o.call(h)}finally{if(s)throw s.error}}var E=A(Kt(this,r,n,i,d,this.machine.config.preserveActionOrder),2),g=E[0],S=E[1],I=A(Rr(g,function(G){return G.type===Je||G.type===Ye&&G.to===Ce.Internal}),2),_=I[0],$=I[1],b=g.filter(function(G){var Ne;return G.type===Ct&&((Ne=G.activity)===null||Ne===void 0?void 0:Ne.type)===$t}),w=b.reduce(function(G,Ne){return G[Ne.activity.id]=pi(Ne.activity,a.machine,S,i),G},r?m({},r.children):{}),T=f?e.configuration:r?r.configuration:[],C=Fe(T,this),q=new re({value:u||r.value,context:S,_event:i,_sessionid:r?r._sessionid:null,historyValue:u?p?ei(p,u):void 0:r?r.historyValue:void 0,history:!u||e.source?r:void 0,actions:u?$:[],activities:u?l:r?r.activities:{},events:[],configuration:T,transitions:e.transitions,children:w,done:C,tags:jr(T),machine:this}),W=n!==S;q.changed=i.name===Sr||W;var ce=q.history;ce&&delete ce.history;var kt=!C&&(this._transient||c.some(function(G){return G._transient}));if(!f&&(!kt||i.name===Se))return q;var ee=q;if(!C)for(kt&&(ee=this.resolveRaisedTransition(ee,{type:Vn},i));_.length;){var la=_.shift();ee=this.resolveRaisedTransition(ee,la._event,i)}var fa=ee.changed||(ce?!!ee.actions.length||W||typeof ce.value!=typeof ee.value||!Lr(ee.value,ce.value):void 0);return ee.changed=fa,ee.history=ce,ee},t.prototype.getStateNode=function(e){if(Te(e))return this.machine.getStateNodeById(e);if(!this.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(this.id,"'; no child states exist."));var r=this.states[e];if(!r)throw new Error("Child state '".concat(e,"' does not exist on '").concat(this.id,"'"));return r},t.prototype.getStateNodeById=function(e){var r=Te(e)?e.slice(Jt.length):e;if(r===this.id)return this;var n=this.machine.idMap[r];if(!n)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return n},t.prototype.getStateNodeByPath=function(e){if(typeof e=="string"&&Te(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=Mt(e,this.delimiter).slice(),n=this;r.length;){var i=r.shift();if(!i.length)break;n=n.getStateNode(i)}return n},t.prototype.resolve=function(e){var r,n=this;if(!e)return this.initialStateValue||be;switch(this.type){case"parallel":return $e(this.initialStateValue,function(s,o){return s?n.getStateNode(o).resolve(e[o]||s):be});case"compound":if(O(e)){var i=this.getStateNode(e);return i.type==="parallel"||i.type==="compound"?(r={},r[e]=i.initialStateValue,r):e}return Object.keys(e).length?$e(e,function(s,o){return s?n.getStateNode(o).resolve(s):be}):this.initialStateValue||{};default:return e||be}},t.prototype.getResolvedPath=function(e){if(Te(e)){var r=this.machine.idMap[e.slice(Jt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return Mt(e,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){var e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;var r;if(this.type==="parallel")r=_r(this.states,function(n){return n.initialStateValue||be},function(n){return n.type!=="history"});else if(this.initial!==void 0){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));r=ot(this.states[this.initial])?this.initial:(e={},e[this.initial]=this.states[this.initial].initialStateValue,e)}else r={};return this.__cache.initialStateValue=r,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),t.prototype.getInitialState=function(e,r){this._init();var n=this.getStateNodes(e);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,r!=null?r:this.machine.context,void 0)},Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this.initialStateValue;if(!e)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var e;if(this.type==="history"){var r=this.config;O(r.target)?e=Te(r.target)?Xe(this.machine.getStateNodeById(r.target).path.slice(this.path.length-1)):r.target:e=r.target}return e},enumerable:!1,configurable:!0}),t.prototype.getRelativeStateNodes=function(e,r,n){return n===void 0&&(n=!0),n?e.type==="history"?e.resolveHistory(r):e.initialStateNodes:[e]},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var e=this;if(ot(this))return[this];if(this.type==="compound"&&!this.initial)return De||je(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Ze(this.initialStateValue);return N(r.map(function(n){return e.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(e){if(!e.length)return[this];var r=A(e),n=r[0],i=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var s=this.getStateNode(n);if(s.type==="history")return s.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(i)},t.prototype.historyValue=function(e){if(!!Object.keys(this.states).length)return{current:e||this.initialStateValue,states:_r(this.states,function(r,n){if(!e)return r.historyValue();var i=O(e)?void 0:e[n];return r.historyValue(i||r.initialStateValue)},function(r){return!r.history})}},t.prototype.resolveHistory=function(e){var r=this;if(this.type!=="history")return[this];var n=this.parent;if(!e){var i=this.target;return i?N(Ze(i).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var s=Qn(n.path,"states")(e).current;return O(s)?[n.getStateNode(s)]:N(Ze(s).map(function(o){return r.history==="deep"?n.getFromRelativePath(o):[n.states[o[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=N(Object.keys(this.states).map(function(n){return e.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var e,r,n,i;if(this.__cache.events)return this.__cache.events;var s=this.states,o=new Set(this.ownEvents);if(s)try{for(var a=x(Object.keys(s)),c=a.next();!c.done;c=a.next()){var f=c.value,u=s[f];if(u.states)try{for(var p=(n=void 0,x(u.events)),d=p.next();!d.done;d=p.next()){var l=d.value;o.add("".concat(l))}}catch(h){n={error:h}}finally{try{d&&!d.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}}}catch(h){e={error:h}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!O(n))return n;var i=n[0]===r.delimiter;if(i&&!r.parent)return r.getStateNodeByPath(n.slice(1));var s=i?r.key+n:n;if(r.parent)try{var o=r.parent.getStateNodeByPath(s);return o}catch(a){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
17
- `).concat(a.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=ni(e.target),i="internal"in e?e.internal:n?n.some(function(c){return O(c)&&c[0]===r.delimiter}):!0,s=this.machine.options.guards,o=this.resolveTarget(n),a=m(m({},e),{actions:nt(Q(e.actions)),cond:Ir(e.cond,s),target:o,source:this,internal:i,eventType:e.event,toJSON:function(){return m(m({},a),{target:a.target?a.target.map(function(c){return"#".concat(c.id)}):void 0,source:"#".concat(r.id)})}});return a},t.prototype.formatTransitions=function(){var e,r,n=this,i;if(!this.config.on)i=[];else if(Array.isArray(this.config.on))i=this.config.on;else{var s=this.config.on,o=qe,a=s[o],c=a===void 0?[]:a,f=Nt(s,[typeof o=="symbol"?o:o+""]);i=N(Object.keys(f).map(function(g){!De&&g===Se&&je(!1,"Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. "+'Please check the `on` configuration for "#'.concat(n.id,'".'));var S=me(g,f[g]);return De||Ci(n,g,S),S}).concat(me(qe,c)))}var u=this.config.always?me("",this.config.always):[],p=this.config.onDone?me(String(it(this.id)),this.config.onDone):[];De||je(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var d=N(this.invoke.map(function(g){var S=[];return g.onDone&&S.push.apply(S,D([],A(me(String(st(g.id)),g.onDone)),!1)),g.onError&&S.push.apply(S,D([],A(me(String(Me(g.id)),g.onError)),!1)),S})),l=this.after,h=N(D(D(D(D([],A(p),!1),A(d),!1),A(i),!1),A(u),!1).map(function(g){return Q(g).map(function(S){return n.formatTransition(S)})}));try{for(var v=x(l),y=v.next();!y.done;y=v.next()){var E=y.value;h.push(E)}}catch(g){e={error:g}}finally{try{y&&!y.done&&(r=v.return)&&r.call(v)}finally{if(e)throw e.error}}return h},t}();function Ve(t,e){return new Di(t,e)}var L=di,X=Ht,Yt={exports:{}},Br=function(e,r){return function(){for(var i=new Array(arguments.length),s=0;s<i.length;s++)i[s]=arguments[s];return e.apply(r,i)}},Ui=Br,Qt=Object.prototype.toString,Xt=function(t){return function(e){var r=Qt.call(e);return t[r]||(t[r]=r.slice(8,-1).toLowerCase())}}(Object.create(null));function fe(t){return t=t.toLowerCase(),function(r){return Xt(r)===t}}function Zt(t){return Array.isArray(t)}function lt(t){return typeof t=="undefined"}function $i(t){return t!==null&&!lt(t)&&t.constructor!==null&&!lt(t.constructor)&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}var Fr=fe("ArrayBuffer");function ji(t){var e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&Fr(t.buffer),e}function Li(t){return typeof t=="string"}function Mi(t){return typeof t=="number"}function qr(t){return t!==null&&typeof t=="object"}function ft(t){if(Xt(t)!=="object")return!1;var e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}var Bi=fe("Date"),Fi=fe("File"),qi=fe("Blob"),Vi=fe("FileList");function er(t){return Qt.call(t)==="[object Function]"}function Hi(t){return qr(t)&&er(t.pipe)}function Ki(t){var e="[object FormData]";return t&&(typeof FormData=="function"&&t instanceof FormData||Qt.call(t)===e||er(t.toString)&&t.toString()===e)}var zi=fe("URLSearchParams");function Wi(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function Gi(){return typeof navigator!="undefined"&&(navigator.product==="ReactNative"||navigator.product==="NativeScript"||navigator.product==="NS")?!1:typeof window!="undefined"&&typeof document!="undefined"}function tr(t,e){if(!(t===null||typeof t=="undefined"))if(typeof t!="object"&&(t=[t]),Zt(t))for(var r=0,n=t.length;r<n;r++)e.call(null,t[r],r,t);else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.call(null,t[i],i,t)}function rr(){var t={};function e(i,s){ft(t[s])&&ft(i)?t[s]=rr(t[s],i):ft(i)?t[s]=rr({},i):Zt(i)?t[s]=i.slice():t[s]=i}for(var r=0,n=arguments.length;r<n;r++)tr(arguments[r],e);return t}function Ji(t,e,r){return tr(e,function(i,s){r&&typeof i=="function"?t[s]=Ui(i,r):t[s]=i}),t}function Yi(t){return t.charCodeAt(0)===65279&&(t=t.slice(1)),t}function Qi(t,e,r,n){t.prototype=Object.create(e.prototype,n),t.prototype.constructor=t,r&&Object.assign(t.prototype,r)}function Xi(t,e,r){var n,i,s,o={};e=e||{};do{for(n=Object.getOwnPropertyNames(t),i=n.length;i-- >0;)s=n[i],o[s]||(e[s]=t[s],o[s]=!0);t=Object.getPrototypeOf(t)}while(t&&(!r||r(t,e))&&t!==Object.prototype);return e}function Zi(t,e,r){t=String(t),(r===void 0||r>t.length)&&(r=t.length),r-=e.length;var n=t.indexOf(e,r);return n!==-1&&n===r}function es(t){if(!t)return null;var e=t.length;if(lt(e))return null;for(var r=new Array(e);e-- >0;)r[e]=t[e];return r}var ts=function(t){return function(e){return t&&e instanceof t}}(typeof Uint8Array!="undefined"&&Object.getPrototypeOf(Uint8Array)),B={isArray:Zt,isArrayBuffer:Fr,isBuffer:$i,isFormData:Ki,isArrayBufferView:ji,isString:Li,isNumber:Mi,isObject:qr,isPlainObject:ft,isUndefined:lt,isDate:Bi,isFile:Fi,isBlob:qi,isFunction:er,isStream:Hi,isURLSearchParams:zi,isStandardBrowserEnv:Gi,forEach:tr,merge:rr,extend:Ji,trim:Wi,stripBOM:Yi,inherits:Qi,toFlatObject:Xi,kindOf:Xt,kindOfTest:fe,endsWith:Zi,toArray:es,isTypedArray:ts,isFileList:Vi},xe=B;function Vr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var Hr=function(e,r,n){if(!r)return e;var i;if(n)i=n(r);else if(xe.isURLSearchParams(r))i=r.toString();else{var s=[];xe.forEach(r,function(c,f){c===null||typeof c=="undefined"||(xe.isArray(c)?f=f+"[]":c=[c],xe.forEach(c,function(p){xe.isDate(p)?p=p.toISOString():xe.isObject(p)&&(p=JSON.stringify(p)),s.push(Vr(f)+"="+Vr(p))}))}),i=s.join("&")}if(i){var o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+i}return e},rs=B;function dt(){this.handlers=[]}dt.prototype.use=function(e,r,n){return this.handlers.push({fulfilled:e,rejected:r,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1},dt.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},dt.prototype.forEach=function(e){rs.forEach(this.handlers,function(n){n!==null&&e(n)})};var ns=dt,is=B,ss=function(e,r){is.forEach(e,function(i,s){s!==r&&s.toUpperCase()===r.toUpperCase()&&(e[r]=i,delete e[s])})},Kr=B;function _e(t,e,r,n,i){Error.call(this),this.message=t,this.name="AxiosError",e&&(this.code=e),r&&(this.config=r),n&&(this.request=n),i&&(this.response=i)}Kr.inherits(_e,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var zr=_e.prototype,Wr={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED"].forEach(function(t){Wr[t]={value:t}}),Object.defineProperties(_e,Wr),Object.defineProperty(zr,"isAxiosError",{value:!0}),_e.from=function(t,e,r,n,i,s){var o=Object.create(zr);return Kr.toFlatObject(t,o,function(c){return c!==Error.prototype}),_e.call(o,t.message,e,r,n,i),o.name=t.name,s&&Object.assign(o,s),o};var Oe=_e,Gr={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Z=B;function os(t,e){e=e||new FormData;var r=[];function n(s){return s===null?"":Z.isDate(s)?s.toISOString():Z.isArrayBuffer(s)||Z.isTypedArray(s)?typeof Blob=="function"?new Blob([s]):Buffer.from(s):s}function i(s,o){if(Z.isPlainObject(s)||Z.isArray(s)){if(r.indexOf(s)!==-1)throw Error("Circular reference detected in "+o);r.push(s),Z.forEach(s,function(c,f){if(!Z.isUndefined(c)){var u=o?o+"."+f:f,p;if(c&&!o&&typeof c=="object"){if(Z.endsWith(f,"{}"))c=JSON.stringify(c);else if(Z.endsWith(f,"[]")&&(p=Z.toArray(c))){p.forEach(function(d){!Z.isUndefined(d)&&e.append(u,n(d))});return}}i(c,u)}}),r.pop()}else e.append(o,n(s))}return i(t),e}var Jr=os,nr=Oe,as=function(e,r,n){var i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):r(new nr("Request failed with status code "+n.status,[nr.ERR_BAD_REQUEST,nr.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))},ht=B,us=ht.isStandardBrowserEnv()?function(){return{write:function(r,n,i,s,o,a){var c=[];c.push(r+"="+encodeURIComponent(n)),ht.isNumber(i)&&c.push("expires="+new Date(i).toGMTString()),ht.isString(s)&&c.push("path="+s),ht.isString(o)&&c.push("domain="+o),a===!0&&c.push("secure"),document.cookie=c.join("; ")},read:function(r){var n=document.cookie.match(new RegExp("(^|;\\s*)("+r+")=([^;]*)"));return n?decodeURIComponent(n[3]):null},remove:function(r){this.write(r,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}(),cs=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},ls=function(e,r){return r?e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""):e},fs=cs,ds=ls,Yr=function(e,r){return e&&!fs(r)?ds(e,r):r},ir=B,hs=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"],ps=function(e){var r={},n,i,s;return e&&ir.forEach(e.split(`
18
- `),function(a){if(s=a.indexOf(":"),n=ir.trim(a.substr(0,s)).toLowerCase(),i=ir.trim(a.substr(s+1)),n){if(r[n]&&hs.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([i]):r[n]=r[n]?r[n]+", "+i:i}}),r},Qr=B,vs=Qr.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function i(s){var o=s;return e&&(r.setAttribute("href",o),o=r.href),r.setAttribute("href",o),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:r.pathname.charAt(0)==="/"?r.pathname:"/"+r.pathname}}return n=i(window.location.href),function(o){var a=Qr.isString(o)?i(o):o;return a.protocol===n.protocol&&a.host===n.host}}():function(){return function(){return!0}}(),sr=Oe,ys=B;function Xr(t){sr.call(this,t==null?"canceled":t,sr.ERR_CANCELED),this.name="CanceledError"}ys.inherits(Xr,sr,{__CANCEL__:!0});var pt=Xr,ms=function(e){var r=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return r&&r[1]||""},He=B,gs=as,Es=us,ws=Hr,Ss=Yr,bs=ps,Ts=vs,xs=Gr,ne=Oe,_s=pt,Os=ms,Zr=function(e){return new Promise(function(n,i){var s=e.data,o=e.headers,a=e.responseType,c;function f(){e.cancelToken&&e.cancelToken.unsubscribe(c),e.signal&&e.signal.removeEventListener("abort",c)}He.isFormData(s)&&He.isStandardBrowserEnv()&&delete o["Content-Type"];var u=new XMLHttpRequest;if(e.auth){var p=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(p+":"+d)}var l=Ss(e.baseURL,e.url);u.open(e.method.toUpperCase(),ws(l,e.params,e.paramsSerializer),!0),u.timeout=e.timeout;function h(){if(!!u){var E="getAllResponseHeaders"in u?bs(u.getAllResponseHeaders()):null,g=!a||a==="text"||a==="json"?u.responseText:u.response,S={data:g,status:u.status,statusText:u.statusText,headers:E,config:e,request:u};gs(function(_){n(_),f()},function(_){i(_),f()},S),u=null}}if("onloadend"in u?u.onloadend=h:u.onreadystatechange=function(){!u||u.readyState!==4||u.status===0&&!(u.responseURL&&u.responseURL.indexOf("file:")===0)||setTimeout(h)},u.onabort=function(){!u||(i(new ne("Request aborted",ne.ECONNABORTED,e,u)),u=null)},u.onerror=function(){i(new ne("Network Error",ne.ERR_NETWORK,e,u,u)),u=null},u.ontimeout=function(){var g=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded",S=e.transitional||xs;e.timeoutErrorMessage&&(g=e.timeoutErrorMessage),i(new ne(g,S.clarifyTimeoutError?ne.ETIMEDOUT:ne.ECONNABORTED,e,u)),u=null},He.isStandardBrowserEnv()){var v=(e.withCredentials||Ts(l))&&e.xsrfCookieName?Es.read(e.xsrfCookieName):void 0;v&&(o[e.xsrfHeaderName]=v)}"setRequestHeader"in u&&He.forEach(o,function(g,S){typeof s=="undefined"&&S.toLowerCase()==="content-type"?delete o[S]:u.setRequestHeader(S,g)}),He.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),a&&a!=="json"&&(u.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&u.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&u.upload&&u.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(c=function(E){!u||(i(!E||E&&E.type?new _s:E),u.abort(),u=null)},e.cancelToken&&e.cancelToken.subscribe(c),e.signal&&(e.signal.aborted?c():e.signal.addEventListener("abort",c))),s||(s=null);var y=Os(l);if(y&&["http","https","file"].indexOf(y)===-1){i(new ne("Unsupported protocol "+y+":",ne.ERR_BAD_REQUEST,e));return}u.send(s)})},As=null,M=B,en=ss,tn=Oe,Rs=Gr,Ps=Jr,ks={"Content-Type":"application/x-www-form-urlencoded"};function rn(t,e){!M.isUndefined(t)&&M.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function Is(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Zr),t}function Ns(t,e,r){if(M.isString(t))try{return(e||JSON.parse)(t),M.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var vt={transitional:Rs,adapter:Is(),transformRequest:[function(e,r){if(en(r,"Accept"),en(r,"Content-Type"),M.isFormData(e)||M.isArrayBuffer(e)||M.isBuffer(e)||M.isStream(e)||M.isFile(e)||M.isBlob(e))return e;if(M.isArrayBufferView(e))return e.buffer;if(M.isURLSearchParams(e))return rn(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n=M.isObject(e),i=r&&r["Content-Type"],s;if((s=M.isFileList(e))||n&&i==="multipart/form-data"){var o=this.env&&this.env.FormData;return Ps(s?{"files[]":e}:e,o&&new o)}else if(n||i==="application/json")return rn(r,"application/json"),Ns(e);return e}],transformResponse:[function(e){var r=this.transitional||vt.transitional,n=r&&r.silentJSONParsing,i=r&&r.forcedJSONParsing,s=!n&&this.responseType==="json";if(s||i&&M.isString(e)&&e.length)try{return JSON.parse(e)}catch(o){if(s)throw o.name==="SyntaxError"?tn.from(o,tn.ERR_BAD_RESPONSE,this,null,this.response):o}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:As},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};M.forEach(["delete","get","head"],function(e){vt.headers[e]={}}),M.forEach(["post","put","patch"],function(e){vt.headers[e]=M.merge(ks)});var or=vt,Cs=B,Ds=or,Us=function(e,r,n){var i=this||Ds;return Cs.forEach(n,function(o){e=o.call(i,e,r)}),e},nn=function(e){return!!(e&&e.__CANCEL__)},sn=B,ar=Us,$s=nn,js=or,Ls=pt;function ur(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new Ls}var Ms=function(e){ur(e),e.headers=e.headers||{},e.data=ar.call(e,e.data,e.headers,e.transformRequest),e.headers=sn.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),sn.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||js.adapter;return r(e).then(function(i){return ur(e),i.data=ar.call(e,i.data,i.headers,e.transformResponse),i},function(i){return $s(i)||(ur(e),i&&i.response&&(i.response.data=ar.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},z=B,on=function(e,r){r=r||{};var n={};function i(u,p){return z.isPlainObject(u)&&z.isPlainObject(p)?z.merge(u,p):z.isPlainObject(p)?z.merge({},p):z.isArray(p)?p.slice():p}function s(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(e[u],r[u])}function o(u){if(!z.isUndefined(r[u]))return i(void 0,r[u])}function a(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(void 0,r[u])}function c(u){if(u in r)return i(e[u],r[u]);if(u in e)return i(void 0,e[u])}var f={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:c};return z.forEach(Object.keys(e).concat(Object.keys(r)),function(p){var d=f[p]||s,l=d(p);z.isUndefined(l)&&d!==c||(n[p]=l)}),n},an={version:"0.27.2"},Bs=an.version,oe=Oe,cr={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){cr[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var un={};cr.transitional=function(e,r,n){function i(s,o){return"[Axios v"+Bs+"] Transitional option '"+s+"'"+o+(n?". "+n:"")}return function(s,o,a){if(e===!1)throw new oe(i(o," has been removed"+(r?" in "+r:"")),oe.ERR_DEPRECATED);return r&&!un[o]&&(un[o]=!0,console.warn(i(o," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,o,a):!0}};function Fs(t,e,r){if(typeof t!="object")throw new oe("options must be an object",oe.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],o=e[s];if(o){var a=t[s],c=a===void 0||o(a,s,t);if(c!==!0)throw new oe("option "+s+" must be "+c,oe.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new oe("Unknown option "+s,oe.ERR_BAD_OPTION)}}var qs={assertOptions:Fs,validators:cr},cn=B,Vs=Hr,ln=ns,fn=Ms,yt=on,Hs=Yr,dn=qs,Ae=dn.validators;function Re(t){this.defaults=t,this.interceptors={request:new ln,response:new ln}}Re.prototype.request=function(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=yt(this.defaults,r),r.method?r.method=r.method.toLowerCase():this.defaults.method?r.method=this.defaults.method.toLowerCase():r.method="get";var n=r.transitional;n!==void 0&&dn.assertOptions(n,{silentJSONParsing:Ae.transitional(Ae.boolean),forcedJSONParsing:Ae.transitional(Ae.boolean),clarifyTimeoutError:Ae.transitional(Ae.boolean)},!1);var i=[],s=!0;this.interceptors.request.forEach(function(l){typeof l.runWhen=="function"&&l.runWhen(r)===!1||(s=s&&l.synchronous,i.unshift(l.fulfilled,l.rejected))});var o=[];this.interceptors.response.forEach(function(l){o.push(l.fulfilled,l.rejected)});var a;if(!s){var c=[fn,void 0];for(Array.prototype.unshift.apply(c,i),c=c.concat(o),a=Promise.resolve(r);c.length;)a=a.then(c.shift(),c.shift());return a}for(var f=r;i.length;){var u=i.shift(),p=i.shift();try{f=u(f)}catch(d){p(d);break}}try{a=fn(f)}catch(d){return Promise.reject(d)}for(;o.length;)a=a.then(o.shift(),o.shift());return a},Re.prototype.getUri=function(e){e=yt(this.defaults,e);var r=Hs(e.baseURL,e.url);return Vs(r,e.params,e.paramsSerializer)},cn.forEach(["delete","get","head","options"],function(e){Re.prototype[e]=function(r,n){return this.request(yt(n||{},{method:e,url:r,data:(n||{}).data}))}}),cn.forEach(["post","put","patch"],function(e){function r(n){return function(s,o,a){return this.request(yt(a||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Re.prototype[e]=r(),Re.prototype[e+"Form"]=r(!0)});var Ks=Re,zs=pt;function Pe(t){if(typeof t!="function")throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(i){e=i});var r=this;this.promise.then(function(n){if(!!r._listeners){var i,s=r._listeners.length;for(i=0;i<s;i++)r._listeners[i](n);r._listeners=null}}),this.promise.then=function(n){var i,s=new Promise(function(o){r.subscribe(o),i=o}).then(n);return s.cancel=function(){r.unsubscribe(i)},s},t(function(i){r.reason||(r.reason=new zs(i),e(r.reason))})}Pe.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},Pe.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},Pe.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},Pe.source=function(){var e,r=new Pe(function(i){e=i});return{token:r,cancel:e}};var Ws=Pe,Gs=function(e){return function(n){return e.apply(null,n)}},Js=B,Ys=function(e){return Js.isObject(e)&&e.isAxiosError===!0},hn=B,Qs=Br,mt=Ks,Xs=on,Zs=or;function pn(t){var e=new mt(t),r=Qs(mt.prototype.request,e);return hn.extend(r,mt.prototype,e),hn.extend(r,e),r.create=function(i){return pn(Xs(t,i))},r}var K=pn(Zs);K.Axios=mt,K.CanceledError=pt,K.CancelToken=Ws,K.isCancel=nn,K.VERSION=an.version,K.toFormData=Jr,K.AxiosError=Oe,K.Cancel=K.CanceledError,K.all=function(e){return Promise.all(e)},K.spread=Gs,K.isAxiosError=Ys,Yt.exports=K,Yt.exports.default=K;var gt=Yt.exports;/*! js-cookie v3.0.1 | MIT */function Et(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}var eo={read:function(t){return t[0]==='"'&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function lr(t,e){function r(i,s,o){if(typeof document!="undefined"){o=Et({},e,o),typeof o.expires=="number"&&(o.expires=new Date(Date.now()+o.expires*864e5)),o.expires&&(o.expires=o.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in o)!o[c]||(a+="; "+c,o[c]!==!0&&(a+="="+o[c].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+a}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],o={},a=0;a<s.length;a++){var c=s[a].split("="),f=c.slice(1).join("=");try{var u=decodeURIComponent(c[0]);if(o[u]=t.read(f,u),i===u)break}catch{}}return i?o[i]:o}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",Et({},s,{expires:-1}))},withAttributes:function(i){return lr(this.converter,Et({},this.attributes,i))},withConverter:function(i){return lr(Et({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var fr=lr(eo,{path:"/"}),to=Object.defineProperty,ro=Object.defineProperties,no=Object.getOwnPropertyDescriptors,wt=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,mn=(t,e,r)=>e in t?to(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Y=(t,e)=>{for(var r in e||(e={}))vn.call(e,r)&&mn(t,r,e[r]);if(wt)for(var r of wt(e))yn.call(e,r)&&mn(t,r,e[r]);return t},ie=(t,e)=>ro(t,no(e)),gn=(t,e)=>{var r={};for(var n in t)vn.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&wt)for(var n of wt(t))e.indexOf(n)<0&&yn.call(t,n)&&(r[n]=t[n]);return r};function io(t){return new TextEncoder().encode(t)}function de(t){const e=new Uint8Array(t);let r="";for(const i of e)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function dr(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),r=(4-e.length%4)%4,n=e.padEnd(e.length+r,"="),i=atob(n),s=new ArrayBuffer(i.length),o=new Uint8Array(s);for(let a=0;a<i.length;a++)o[a]=i.charCodeAt(a);return s}function En(){return(window==null?void 0:window.PublicKeyCredential)!==void 0&&typeof window.PublicKeyCredential=="function"}function wn(t){const{id:e}=t;return ie(Y({},t),{id:dr(e),transports:t.transports})}function Sn(t){return t==="localhost"||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(t)}class F extends Error{constructor(e,r="WebAuthnError"){super(e),this.name=r}}function so({error:t,options:e}){var r,n;const{publicKey:i}=e;if(!i)throw Error("options was missing required publicKey property");if(t.name==="AbortError"){if(e.signal===new AbortController().signal)return new F("Registration ceremony was sent an abort signal","AbortError")}else if(t.name==="ConstraintError"){if(((r=i.authenticatorSelection)===null||r===void 0?void 0:r.requireResidentKey)===!0)return new F("Discoverable credentials were required but no available authenticator supported it","ConstraintError");if(((n=i.authenticatorSelection)===null||n===void 0?void 0:n.userVerification)==="required")return new F("User verification was required but no available authenticator supported it","ConstraintError")}else{if(t.name==="InvalidStateError")return new F("The authenticator was previously registered","InvalidStateError");if(t.name==="NotAllowedError")return new F("User clicked cancel, or the registration ceremony timed out","NotAllowedError");if(t.name==="NotSupportedError")return i.pubKeyCredParams.filter(o=>o.type==="public-key").length===0?new F('No entry in pubKeyCredParams was of type "public-key"',"NotSupportedError"):new F("No available authenticator supported any of the specified pubKeyCredParams algorithms","NotSupportedError");if(t.name==="SecurityError"){const s=window.location.hostname;if(Sn(s)){if(i.rp.id!==s)return new F(`The RP ID "${i.rp.id}" is invalid for this domain`,"SecurityError")}else return new F(`${window.location.hostname} is an invalid domain`,"SecurityError")}else if(t.name==="TypeError"){if(i.user.id.byteLength<1||i.user.id.byteLength>64)return new F("User ID was not between 1 and 64 characters","TypeError")}else if(t.name==="UnknownError")return new F("The authenticator was unable to process the specified options, or could not create a new credential","UnknownError")}return t}class oo{createNewAbortSignal(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal}reset(){this.controller=void 0}}const St=new oo;async function ao(t){if(!En())throw new Error("WebAuthn is not supported in this browser");const r={publicKey:ie(Y({},t),{challenge:dr(t.challenge),user:ie(Y({},t.user),{id:io(t.user.id)}),excludeCredentials:t.excludeCredentials.map(wn)})};r.signal=St.createNewAbortSignal();let n;try{n=await navigator.credentials.create(r)}catch(f){throw so({error:f,options:r})}finally{St.reset()}if(!n)throw new Error("Registration was not completed");const{id:i,rawId:s,response:o,type:a}=n,c={id:i,rawId:de(s),response:{attestationObject:de(o.attestationObject),clientDataJSON:de(o.clientDataJSON)},type:a,clientExtensionResults:n.getClientExtensionResults(),authenticatorAttachment:n.authenticatorAttachment};return typeof o.getTransports=="function"&&(c.transports=o.getTransports()),c}function uo(t){return new TextDecoder("utf-8").decode(t)}async function co(){if(navigator.credentials.conditionalMediationSupported)return!0;const t=window.PublicKeyCredential;return t.isConditionalMediationAvailable!==void 0&&t.isConditionalMediationAvailable()}function lo({error:t,options:e}){var r;const{publicKey:n}=e;if(!n)throw Error("options was missing required publicKey property");if(t.name==="AbortError"){if(e.signal===new AbortController().signal)return new F("Authentication ceremony was sent an abort signal","AbortError")}else{if(t.name==="NotAllowedError")return!((r=n.allowCredentials)===null||r===void 0)&&r.length?new F("No available authenticator recognized any of the allowed credentials","NotAllowedError"):new F("User clicked cancel, or the authentication ceremony timed out","NotAllowedError");if(t.name==="SecurityError"){const i=window.location.hostname;if(Sn(i)){if(n.rpId!==i)return new F(`The RP ID "${n.rpId}" is invalid for this domain`,"SecurityError")}else return new F(`${window.location.hostname} is an invalid domain`,"SecurityError")}else if(t.name==="UnknownError")return new F("The authenticator was unable to process the specified options, or could not create a new assertion signature","UnknownError")}return t}async function fo(t,e=!1){var r,n;if(!En())throw new Error("WebAuthn is not supported in this browser");let i;((r=t.allowCredentials)===null||r===void 0?void 0:r.length)!==0&&(i=(n=t.allowCredentials)===null||n===void 0?void 0:n.map(wn));const s=ie(Y({},t),{challenge:dr(t.challenge),allowCredentials:i}),o={};if(e){if(!await co())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete*='webauthn']").length<1)throw Error('No <input> with `"webauthn"` in its `autocomplete` attribute was detected');o.mediation="conditional",s.allowCredentials=[]}o.publicKey=s,o.signal=St.createNewAbortSignal();let a;try{a=await navigator.credentials.get(o)}catch(l){throw lo({error:l,options:o})}finally{St.reset()}if(!a)throw new Error("Authentication was not completed");const{id:c,rawId:f,response:u,type:p}=a;let d;return u.userHandle&&(d=uo(u.userHandle)),{id:c,rawId:de(f),response:{authenticatorData:de(u.authenticatorData),clientDataJSON:de(u.clientDataJSON),signature:de(u.signature),userHandle:d},type:p,clientExtensionResults:a.getClientExtensionResults(),authenticatorAttachment:a.authenticatorAttachment}}const bt="nhostRefreshToken",Tt="nhostRefreshTokenExpiresAt",ho=3,po=300,vo=5,yo=0,mo=1,ae=10,xt=20;class hr extends Error{constructor(e){super(e.message),Error.captureStackTrace(this,this.constructor),e instanceof Error?(this.name=e.name,this.error={error:e.name,status:mo,message:e.message}):(this.name=e.error,this.error=e)}}const he={status:ae,error:"invalid-email",message:"Email is incorrectly formatted"},pr={status:ae,error:"invalid-password",message:"Password is incorrectly formatted"},bn={status:ae,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},go={status:ae,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},Eo={status:ae,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},wo={status:ae,error:"no-refresh-token",message:"No refresh token has been provided"},So={status:xt,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},ue={status:xt,error:"already-signed-in",message:"User is already signed in"},bo={status:xt,error:"unauthenticated-user",message:"User is not authenticated"},To={status:xt,error:"unverified-user",message:"Email needs verification"},xo={status:ae,error:"invalid-refresh-token",message:"Invalid or expired refresh token"},ke=t=>{const e=gt.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,o,a,c,f,u,p,d;return Promise.reject({error:{message:(a=(o=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?o:r.request.responseText)!=null?a:JSON.stringify(r),status:(p=(u=(c=r.response)==null?void 0:c.status)!=null?u:(f=r.response)==null?void 0:f.data.statusCode)!=null?p:yo,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},_t=typeof window!="undefined",Ot=new Map,_o=t=>{var e;return _t&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=Ot.get(t))!=null?e:null},Oo=(t,e)=>{_t&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?Ot.set(t,e):Ot.has(t)&&Ot.delete(t)},Ao=(t,e)=>{if(t==="localStorage"||t==="web")return _o;if(t==="cookie")return r=>{var n;return _t&&(n=fr.get(r))!=null?n:null};if(!e)throw Error(`clientStorageType is set to '${t}' but no clientStorage has been given`);if(t==="react-native")return r=>{var n;return(n=e.getItem)==null?void 0:n.call(e,r)};if(t==="capacitor")return r=>{var n;return(n=e.get)==null?void 0:n.call(e,{key:r})};if(t==="expo-secure-storage")return r=>{var n;return(n=e.getItemAsync)==null?void 0:n.call(e,r)};if(t==="custom"){if(e.getItem&&e.removeItem)return e.getItem;if(e.getItemAsync)return e.getItemAsync;throw Error(`clientStorageType is set to 'custom' but clientStorage is missing either "getItem" and "removeItem" properties or "getItemAsync" property`)}throw Error(`Unknown storage type: ${t}`)},Ro=(t,e)=>{if(t==="localStorage"||t==="web")return Oo;if(t==="cookie")return(r,n)=>{_t&&(n?fr.set(r,n,{expires:30}):fr.remove(r))};if(!e)throw Error(`clientStorageType is set to '${t}' but no clienStorage has been given`);if(t==="react-native")return(r,n)=>{var i,s;return n?(i=e.setItem)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};if(t==="capacitor")return(r,n)=>{var i,s;return n?(i=e.set)==null?void 0:i.call(e,{key:r,value:n}):(s=e.remove)==null?void 0:s.call(e,{key:r})};if(t==="expo-secure-storage")return async(r,n)=>{var i,s;return n?(i=e.setItemAsync)==null?void 0:i.call(e,r,n):(s=e.deleteItemAsync)==null?void 0:s.call(e,r)};if(t==="custom"){if(!e.removeItem)throw Error("clientStorageType is set to 'custom' but clientStorage is missing a removeItem property");if(e.setItem)return(r,n)=>{var i,s;return n?(i=e.setItem)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};if(e.setItemAsync)return async(r,n)=>{var i,s;return n?(i=e.setItemAsync)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};throw Error("clientStorageType is set to 'custom' but clientStorage is missing setItem or setItemAsync property")}throw Error(`Unknown storage type: ${t}`)},Tn=(t,e)=>{const r=e&&Object.entries(e).map(([n,i])=>{const s=Array.isArray(i)?i.join(","):typeof i=="object"?JSON.stringify(i):i;return`${n}=${encodeURIComponent(s)}`}).join("&");return r?`${t}?${r}`:t},te=(t,e)=>{if(!(e!=null&&e.redirectTo))return e;const r=e,{redirectTo:n}=r,i=gn(r,["redirectTo"]);if(!t)return n.startsWith("/")?i:e;const s=new URL(t),o=Object.fromEntries(new URLSearchParams(s.search)),a=new URL(n.startsWith("/")?s.origin+n:n),c=new URLSearchParams(a.search);let f=Object.fromEntries(c);n.startsWith("/")&&(f=Y(Y({},o),f));let u=s.pathname;return a.pathname.length>1&&(u+=a.pathname.slice(1)),ie(Y({},i),{redirectTo:Tn(a.origin+u,f)})};function At(t,e){var r;if(!e){if(typeof window=="undefined")return;e=((r=window.location)==null?void 0:r.href)||""}t=t.replace(/[\[\]]/g,"\\$&");const n=new RegExp("[?&#]"+t+"(=([^&#]*)|&|#|$)"),i=n.exec(e);return i?i[2]?decodeURIComponent(i[2].replace(/\+/g," ")):"":null}function xn(t){var e;if(typeof window=="undefined")return;const r=window==null?void 0:window.location;if(!!r&&r){const n=new URLSearchParams(r.search),i=new URLSearchParams((e=r.hash)==null?void 0:e.slice(1));n.delete(t),i.delete(t);let s=window.location.pathname;Array.from(n).length&&(s+=`?${n.toString()}`),Array.from(i).length&&(s+=`#${i.toString()}`),window.history.pushState({},"",s)}}const pe=t=>!!t&&typeof t=="string"&&!!String(t).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),vr=t=>!!t&&typeof t=="string"&&t.length>=ho,_n=t=>!!t&&typeof t=="string",Po=t=>t&&typeof t=="string"&&t.match(/^mfaTotp:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),yr={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},ko=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=ke(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"changeEmail",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:L({error:i=>he}),saveRequestError:L({error:(i,{data:{error:s}})=>s}),reportError:X(i=>({type:"ERROR",error:i.error})),reportSuccess:X("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!pe(s)},services:{requestChange:async(i,{email:s,options:o})=>(await n.post("/user/email/change",{newEmail:s,options:te(e,o)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},Io=({backendUrl:t,interpreter:e})=>{const r=ke(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidPassword",actions:"saveInvalidPasswordError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidPasswordError:L({error:n=>pr}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:X(n=>({type:"ERROR",error:n.error})),reportSuccess:X("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!vr(i)},services:{requestChange:(n,{password:i,ticket:s})=>r.post("/user/password",{newPassword:i,ticket:s},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},No=({backendUrl:t,clientUrl:e})=>{const r=ke(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:L({error:n=>he}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:X(n=>({type:"ERROR",error:n.error})),reportSuccess:X("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!pe(i)},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:te(e,s)})}})},Co=({backendUrl:t,clientUrl:e})=>{const r=ke(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"sendVerificationEmail",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"request",id:"request",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:L({error:n=>he}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:X(n=>({type:"ERROR",error:n.error})),reportSuccess:X("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!pe(i)},services:{request:async(n,{email:i,options:s})=>(await r.post("/user/email/send-verification-email",{email:i,options:te(e,s)})).data}})},Do=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:o,autoRefreshToken:a=!0,autoSignIn:c=!0})=>{const f=r||Ao(i,s),u=n||Ro(i,s),p=ke(t),d=async(l,h,v)=>(await p.post(l,h,v)).data;return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},context:yr,preserveActionOrder:!0,id:"nhost",type:"parallel",states:{authentication:{initial:"starting",on:{SESSION_UPDATE:[{cond:"hasSession",actions:["saveSession","resetTimer","reportTokenChanged"],target:".signedIn"}]},states:{starting:{entry:"resetErrors",tags:["loading"],always:{cond:"isSignedIn",target:"signedIn"},invoke:{id:"importRefreshToken",src:"importRefreshToken",onDone:{actions:["saveSession","reportTokenChanged"],target:"signedIn"},onError:{actions:["saveAuthenticationError"],target:"signedOut"}}},signedOut:{initial:"noErrors",entry:"reportSignedOut",states:{noErrors:{},success:{},needsSmsOtp:{},needsMfa:{},failed:{},signingOut:{entry:["clearContextExceptRefreshToken"],exit:["destroyRefreshToken","reportTokenChanged"],invoke:{src:"signout",id:"signingOut",onDone:{target:"success"},onError:{target:"failed",actions:["saveAuthenticationError"]}}}},on:{SIGNIN_PASSWORD:"authenticating.password",SIGNIN_ANONYMOUS:"authenticating.anonymous",SIGNIN_SECURITY_KEY_EMAIL:"authenticating.securityKeyEmail",SIGNIN_MFA_TOTP:"authenticating.mfa.totp"}},authenticating:{entry:"resetErrors",states:{password:{invoke:{src:"signInPassword",id:"authenticateUserWithPassword",onDone:[{cond:"hasMfaTicket",actions:["saveMfaTicket"],target:"#nhost.authentication.signedOut.needsMfa"},{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"}],onError:[{cond:"unverified",target:["#nhost.authentication.signedOut","#nhost.registration.incomplete.needsEmailVerification"]},{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}]}},anonymous:{invoke:{src:"signInAnonymous",id:"authenticateAnonymously",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}}},mfa:{states:{totp:{invoke:{src:"signInMfaTotp",id:"signInMfaTotp",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:["saveAuthenticationError"],target:"#nhost.authentication.signedOut.failed"}}}}},securityKeyEmail:{invoke:{src:"signInSecurityKeyEmail",id:"authenticateUserWithSecurityKey",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:[{cond:"unverified",target:["#nhost.authentication.signedOut","#nhost.registration.incomplete.needsEmailVerification"]},{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}]}}}},signedIn:{type:"parallel",entry:["reportSignedIn","cleanUrl","broadcastToken","resetErrors"],on:{SIGNOUT:"signedOut.signingOut"},states:{refreshTimer:{id:"timer",initial:"idle",states:{disabled:{type:"final"},stopped:{always:{cond:"noToken",target:"idle"}},idle:{always:[{cond:"isAutoRefreshDisabled",target:"disabled"},{cond:"hasRefreshToken",target:"running"}]},running:{initial:"pending",entry:"resetTimer",states:{pending:{after:{"1000":{internal:!1,target:"pending"}},always:{cond:"refreshTimerShouldRefresh",target:"refreshing"}},refreshing:{invoke:{src:"refreshToken",id:"refreshToken",onDone:{actions:["saveSession","resetTimer","reportTokenChanged"],target:"pending"},onError:[{actions:"saveRefreshAttempt",target:"pending"}]}}}}}}}}}},token:{initial:"idle",states:{idle:{on:{TRY_TOKEN:"running"},initial:"noErrors",states:{noErrors:{},error:{}}},running:{invoke:{src:"refreshToken",id:"authenticateWithToken",onDone:{actions:["saveSession","reportTokenChanged"],target:["#nhost.authentication.signedIn","idle.noErrors"]},onError:[{cond:"isSignedIn",target:"idle.error"},{actions:"saveAuthenticationError",target:["#nhost.authentication.signedOut.failed","idle.error"]}]}}}},registration:{initial:"incomplete",on:{SIGNED_IN:[{cond:"isAnonymous",target:".incomplete"},".complete"]},states:{incomplete:{on:{SIGNUP_EMAIL_PASSWORD:"emailPassword",PASSWORDLESS_EMAIL:"passwordlessEmail",PASSWORDLESS_SMS:"passwordlessSms",PASSWORDLESS_SMS_OTP:"passwordlessSmsOtp"},initial:"noErrors",states:{noErrors:{},needsEmailVerification:{},needsOtp:{},failed:{}}},emailPassword:{entry:["resetErrors"],invoke:{src:"signUpEmailPassword",id:"signUpEmailPassword",onDone:[{cond:"hasSession",actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},{actions:"clearContext",target:["#nhost.authentication.signedOut","incomplete.needsEmailVerification"]}],onError:[{cond:"unverified",target:"incomplete.needsEmailVerification"},{actions:"saveRegistrationError",target:"incomplete.failed"}]}},passwordlessEmail:{entry:["resetErrors"],invoke:{src:"passwordlessEmail",id:"passwordlessEmail",onDone:{actions:"clearContext",target:["#nhost.authentication.signedOut","incomplete.needsEmailVerification"]},onError:{actions:"saveRegistrationError",target:"incomplete.failed"}}},passwordlessSms:{entry:["resetErrors"],invoke:{src:"passwordlessSms",id:"passwordlessSms",onDone:{actions:"clearContext",target:["#nhost.authentication.signedOut","incomplete.needsOtp"]},onError:{actions:"saveRegistrationError",target:"incomplete.failed"}}},passwordlessSmsOtp:{entry:["resetErrors"],invoke:{src:"passwordlessSmsOtp",id:"passwordlessSmsOtp",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveRegistrationError",target:"incomplete.failed"}}},complete:{on:{SIGNED_OUT:"incomplete"}}}}}},{actions:{reportSignedIn:X("SIGNED_IN"),reportSignedOut:X("SIGNED_OUT"),reportTokenChanged:X("TOKEN_CHANGED"),clearContext:L(()=>(u(Tt,null),u(bt,null),Y({},yr))),clearContextExceptRefreshToken:L(({refreshToken:{value:l}})=>(u(Tt,null),ie(Y({},yr),{refreshToken:{value:l}}))),saveSession:L({user:(l,{data:h})=>{var v;return((v=h==null?void 0:h.session)==null?void 0:v.user)||null},accessToken:(l,{data:h})=>{if(h.session){const{accessTokenExpiresIn:v,accessToken:y}=h.session,E=new Date(Date.now()+v*1e3);return u(Tt,E.toISOString()),{value:y,expiresAt:E}}return u(Tt,null),{value:null,expiresAt:null}},refreshToken:(l,{data:h})=>{var v;const y=((v=h.session)==null?void 0:v.refreshToken)||null;return y&&u(bt,y),{value:y}}}),saveMfaTicket:L({mfa:(l,h)=>{var v;return(v=h.data)==null?void 0:v.mfa}}),resetTimer:L({refreshTimer:l=>({startedAt:new Date,attempts:0,lastAttempt:null})}),saveRefreshAttempt:L({refreshTimer:(l,h)=>({startedAt:l.refreshTimer.startedAt,attempts:l.refreshTimer.attempts+1,lastAttempt:new Date})}),saveAuthenticationError:L({errors:({errors:l},{data:{error:h}})=>ie(Y({},l),{authentication:h})}),resetErrors:L({errors:l=>({})}),saveRegistrationError:L({errors:({errors:l},{data:{error:h}})=>ie(Y({},l),{registration:h})}),destroyRefreshToken:L({refreshToken:l=>(u(bt,null),{value:null})}),cleanUrl:()=>{c&&At("refreshToken")&&(xn("refreshToken"),xn("type"))},broadcastToken:l=>{if(c)try{new BroadcastChannel("nhost").postMessage(l.refreshToken.value)}catch{}}},guards:{isAnonymous:(l,h)=>{var v;return!!((v=l.user)!=null&&v.isAnonymous)},isSignedIn:l=>!!l.user&&!!l.refreshToken.value&&!!l.accessToken.value,noToken:l=>!l.refreshToken.value,hasRefreshToken:l=>!!l.refreshToken.value,isAutoRefreshDisabled:()=>!a,refreshTimerShouldRefresh:l=>{const{expiresAt:h}=l.accessToken;return h?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>vo*1e3:o&&Date.now()-l.refreshTimer.startedAt.getTime()>o*1e3?!0:h.getTime()-Date.now()-1e3*po<=0:!1},unverified:(l,{data:{error:h}})=>h.status===401&&(h.message==="Email is not verified"||h.error==="unverified-user"),hasSession:(l,h)=>{var v;return!!((v=h.data)!=null&&v.session)},hasMfaTicket:(l,h)=>{var v;return!!((v=h.data)!=null&&v.mfa)}},services:{signInPassword:(l,{email:h,password:v})=>pe(h)?vr(v)?d("/signin/email-password",{email:h,password:v}):Promise.reject({error:pr}):Promise.reject({error:he}),passwordlessSms:(l,{phoneNumber:h,options:v})=>{var y;return _n(h)?(y=l.user)!=null&&y.isAnonymous?(console.warn("Deanonymisation from a phone number is not yet implemented in hasura-auth"),d("/user/deanonymize",{signInMethod:"passwordless",connection:"sms",phoneNumber:h,options:te(e,v)},{headers:{authorization:`Bearer ${l.accessToken.value}`}})):d("/signin/passwordless/sms",{phoneNumber:h,options:te(e,v)}):Promise.reject({error:bn})},passwordlessSmsOtp:(l,{phoneNumber:h,otp:v})=>_n(h)?d("/signin/passwordless/sms/otp",{phoneNumber:h,otp:v}):Promise.reject({error:bn}),passwordlessEmail:(l,{email:h,options:v})=>{var y;return pe(h)?(y=l.user)!=null&&y.isAnonymous?d("/user/deanonymize",{signInMethod:"passwordless",connection:"email",email:h,options:te(e,v)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signin/passwordless/email",{email:h,options:te(e,v)}):Promise.reject({error:he})},signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,h)=>{var v;const y=h.ticket||((v=l.mfa)==null?void 0:v.ticket);return y?Po(y)?d("/signin/mfa/totp",{ticket:y,otp:h.otp}):Promise.reject({error:go}):Promise.reject({error:Eo})},signInSecurityKeyEmail:async(l,{email:h})=>{if(!pe(h))throw new hr(he);const v=await d("/signin/webauthn",{email:h});let y;try{y=await fo(v)}catch(E){throw new hr(E)}return d("/signin/webauthn/verify",{email:h,credential:y})},refreshToken:async(l,h)=>{const v=h.type==="TRY_TOKEN"?h.token:l.refreshToken.value;return{session:await d("/token",{refreshToken:v}),error:null}},signout:(l,h)=>d("/signout",{refreshToken:l.refreshToken.value,all:!!h.all}),signUpEmailPassword:async(l,{email:h,password:v,options:y})=>{var E;return pe(h)?vr(v)?(E=l.user)!=null&&E.isAnonymous?d("/user/deanonymize",{signInMethod:"email-password",email:h,password:v,options:te(e,y)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signup/email-password",{email:h,password:v,options:te(e,y)}):Promise.reject({error:pr}):Promise.reject({error:he})},importRefreshToken:async()=>{let l=null;if(c){const v=At("refreshToken")||null;if(v)try{return{session:await d("/token",{refreshToken:v}),error:null}}catch(y){l=y.error}else{const y=At("error");if(y)return Promise.reject({session:null,error:{status:ae,error:y,message:At("errorDescription")||y}})}}const h=await f(bt);if(h)try{return{session:await d("/token",{refreshToken:h}),error:null}}catch(v){l=v.error}return Promise.reject({error:l})}}})};class Uo{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:o=!0,backendUrl:a,clientUrl:c,devTools:f}=r,u=gn(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl","devTools"]);if(this._subscriptions=new Set,this.backendUrl=a,this.clientUrl=c,this.machine=Do(ie(Y({},u),{backendUrl:a,clientUrl:c,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),o&&(this.interpreter=we(this.machine,{devTools:f}),this.interpreter.start()),typeof window!="undefined"&&i)try{this._channel=new BroadcastChannel("nhost"),this._channel.addEventListener("message",p=>{var d;const l=(d=this.interpreter)==null?void 0:d.state.context.refreshToken.value;this.interpreter&&p.data!==l&&this.interpreter.send("TRY_TOKEN",{token:p.data})})}catch{}}get interpreter(){return this._interpreter}set interpreter(e){this._interpreter=e,e&&this._subscriptions.forEach(r=>r(this))}onStart(e){this.interpreter?e(this):this._subscriptions.add(e)}}const $o=async({backendUrl:t,interpreter:e},r)=>{const n=ke(t);try{const{data:i}=await n.post("/user/webauthn/add",{},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}});let s;try{s=await ao(i)}catch(a){throw new hr(a)}const{data:o}=await n.post("/user/webauthn/verify",{credential:s,nickname:r},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}});return{key:o,isError:!1,error:null,isSuccess:!0}}catch(i){const{error:s}=i;return{isError:!0,error:s,isSuccess:!1}}},jo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,needsEmailVerification:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,needsEmailVerification:!0})})}),Lo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{password:e,ticket:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSuccess:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSuccess:!0})})}),Mo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSent:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSent:!0})})}),Bo=(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSent:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSent:!0})})}),Fo=t=>new Promise(e=>{const{changed:r}=t.send("SIGNIN_ANONYMOUS");r||e({isSuccess:!1,isError:!0,error:ue,user:null,accessToken:null}),t.onTransition(n=>{n.matches({authentication:"signedIn"})&&e({isSuccess:!0,isError:!1,error:null,user:n.context.user,accessToken:n.context.accessToken.value}),n.matches({authentication:{signedOut:"failed"}})&&e({isSuccess:!1,isError:!0,error:n.context.errors.authentication||null,user:null,accessToken:null})})}),qo=(t,e,r)=>new Promise(n=>{const{changed:i,context:s}=t.send("SIGNIN_PASSWORD",{email:e,password:r});if(!i)return n({accessToken:s.accessToken.value,error:ue,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:{signedOut:"needsMfa"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!0,mfa:o.context.mfa,user:null}):o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:o.context.user})})}),On=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_EMAIL",{email:e,options:r});if(!i)return n({error:ue,isError:!0,isSuccess:!1});t.onTransition(s=>{s.matches("registration.incomplete.failed")?n({error:s.context.errors.registration||null,isError:!0,isSuccess:!1}):s.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})&&n({error:null,isError:!1,isSuccess:!0})})}),Vo=(t,e,r)=>new Promise(n=>{const{changed:i,context:s}=t.send("SIGNIN_MFA_TOTP",{otp:e,ticket:r});if(!i)return n({accessToken:s.accessToken.value,error:ue,isError:!0,isSuccess:!1,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,user:o.context.user})})}),Ho=(t,e)=>new Promise(r=>{const{changed:n,context:i}=t.send({type:"SIGNIN_SECURITY_KEY_EMAIL",email:e});if(!n)return r({accessToken:i.accessToken.value,error:ue,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:i.user});t.onTransition(s=>{s.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?r({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):s.matches({authentication:{signedOut:"failed"}})?r({accessToken:null,error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):s.matches({authentication:"signedIn"})&&r({accessToken:s.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:s.context.user})})}),An=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_SMS",{phoneNumber:e,options:r});if(!i)return n({error:ue,isError:!0,isSuccess:!1,needsOtp:!1});t.onTransition(s=>{s.matches("registration.incomplete.needsOtp")?n({error:null,isError:!1,isSuccess:!1,needsOtp:!0}):s.matches("registration.incomplete.failed")&&n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,needsOtp:!1})})}),Ko=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send({type:"PASSWORDLESS_SMS_OTP",phoneNumber:e,otp:r});if(!i)return n({error:ue,isError:!0,isSuccess:!1,user:null,accessToken:null});t.onTransition(s=>{s.matches({authentication:"signedIn"})?n({error:null,isError:!1,isSuccess:!0,user:s.context.user,accessToken:s.context.accessToken.value}):s.matches({registration:{incomplete:"failed"}})&&n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null,accessToken:null})})}),zo=async(t,e)=>new Promise(r=>{const{event:n}=t.send("SIGNOUT",{all:e});if(n.type!=="SIGNED_OUT")return r({isSuccess:!1,isError:!0,error:bo});t.onTransition(i=>{i.matches({authentication:{signedOut:"success"}})?r({isSuccess:!0,isError:!1,error:null}):i.matches("authentication.signedOut.failed")&&r({isSuccess:!1,isError:!0,error:i.context.errors.signout||null})})}),Rn=(t,e,r,n)=>new Promise(i=>{const{changed:s,context:o}=t.send("SIGNUP_EMAIL_PASSWORD",{email:e,password:r,options:n});if(!s)return i({error:ue,accessToken:o.accessToken.value,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:o.user});t.onTransition(a=>{a.matches("registration.incomplete.failed")?i({accessToken:null,error:a.context.errors.registration||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):a.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?i({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):a.matches({authentication:"signedIn",registration:"complete"})&&i({accessToken:a.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:a.context.user})})});var Wo=Object.defineProperty,Go=Object.defineProperties,Jo=Object.getOwnPropertyDescriptors,Pn=Object.getOwnPropertySymbols,Yo=Object.prototype.hasOwnProperty,Qo=Object.prototype.propertyIsEnumerable,kn=(t,e,r)=>e in t?Wo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ke=(t,e)=>{for(var r in e||(e={}))Yo.call(e,r)&&kn(t,r,e[r]);if(Pn)for(var r of Pn(e))Qo.call(e,r)&&kn(t,r,e[r]);return t},ze=(t,e)=>Go(t,Jo(e));const Xo=()=>typeof window!="undefined",Rt=t=>!t||!t.accessToken.value||!t.refreshToken.value||!t.accessToken.expiresAt||!t.user?null:{accessToken:t.accessToken.value,accessTokenExpiresIn:(t.accessToken.expiresAt.getTime()-Date.now())/1e3,refreshToken:t.refreshToken.value,user:t.user},Ie=({accessToken:t,isError:e,user:r,error:n})=>e?{session:null,error:n}:r&&t?{session:{accessToken:t,accessTokenExpiresIn:0,refreshToken:"",user:r},error:null}:{session:null,error:null};class Zo{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f,start:u=!0}){var p;this.url=e,this._client=new Uo({backendUrl:e,clientUrl:typeof window!="undefined"&&((p=window.location)==null?void 0:p.origin)||"",autoRefreshToken:r,autoSignIn:typeof i=="boolean"?i:n,start:u,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f})}async signUp({email:e,password:r,options:n}){const i=await this.waitUntilReady();return Ie(await Rn(i,e,r,n))}async signIn(e){const r=await this.waitUntilReady();if("provider"in e){const{provider:i,options:s}=e,o=Tn(`${this._client.backendUrl}/signin/provider/${i}`,te(this._client.clientUrl,s));return Xo()&&(window.location.href=o),{providerUrl:o,provider:i,session:null,mfa:null,error:null}}if("email"in e&&"password"in e){const i=await qo(r,e.email,e.password);return i.needsEmailVerification?{session:null,mfa:null,error:To}:i.needsMfaOtp?{session:null,mfa:i.mfa,error:null}:ze(Ke({},Ie(i)),{mfa:null})}if("email"in e&&"securityKey"in e){if(e.securityKey!==!0)throw Error("securityKey must be true");const i=await Ho(r,e.email);return ze(Ke({},Ie(i)),{mfa:null})}if("email"in e){const{email:i,options:s}=e,{error:o}=await On(r,i,s);return{session:null,mfa:null,error:o}}if("phoneNumber"in e&&"otp"in e){const i=await Ko(r,e.phoneNumber,e.otp);return ze(Ke({},Ie(i)),{mfa:null})}if("phoneNumber"in e){const{error:i}=await An(r,e.phoneNumber,e.options);return{error:i,mfa:null,session:null}}if("otp"in e){const i=await Vo(r,e.otp,e.ticket);return ze(Ke({},Ie(i)),{mfa:null})}const n=await Fo(r);return ze(Ke({},Ie(n)),{mfa:null})}async signOut(e){const r=await this.waitUntilReady(),{error:n}=await zo(r,e==null?void 0:e.all);return{error:n}}async resetPassword({email:e,options:r}){const n=we(No(this._client)).start(),{error:i}=await Mo(n,e,r);return{error:i}}async changePassword({newPassword:e,ticket:r}){const n=we(Io(this._client)).start(),{error:i}=await Lo(n,e,r);return{error:i}}async sendVerificationEmail({email:e,options:r}){const n=we(Co(this._client)).start(),{error:i}=await Bo(n,e,r);return{error:i}}async changeEmail({newEmail:e,options:r}){const n=we(ko(this._client)).start(),{error:i}=await jo(n,e,r);return{error:i}}async deanonymize(e){const r=await this.waitUntilReady();if(e.signInMethod==="passwordless"){if(e.connection==="email"){const{error:n}=await On(r,e.email,e.options);return{error:n}}if(e.connection==="sms"){const{error:n}=await An(r,e.phoneNumber,e.options);return{error:n}}}if(e.signInMethod==="email-password"){const{error:n}=await Rn(r,e.email,e.password,e.options);return{error:n}}throw Error("Unknown deanonymization method")}async addSecurityKey(e){const{error:r,key:n}=await $o(this._client,e);return{error:r,key:n}}onTokenChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{i.type==="TOKEN_CHANGED"&&e(Rt(s))});if(this._client.interpreter){const n=r(this._client.interpreter);return()=>n.stop()}else return this._client.onStart(n=>{r(n.interpreter)}),()=>{console.log("onTokenChanged was added before the interpreter started. Cannot unsubscribe listener.")}}onAuthStateChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{(i.type==="SIGNED_IN"||i.type==="SIGNED_OUT")&&e(i.type,Rt(s))});if(this._client.interpreter){const n=r(this._client.interpreter);return()=>n.stop()}else return this._client.onStart(n=>{r(n.interpreter)}),()=>{console.log("onAuthStateChanged was added before the interpreter started. Cannot unsubscribe listener.")}}isAuthenticated(){var e;return!!((e=this._client.interpreter)!=null&&e.state.matches({authentication:"signedIn"}))}async isAuthenticatedAsync(){return(await this.waitUntilReady()).state.matches({authentication:"signedIn"})}getAuthenticationStatus(){return this.isReady()?{isAuthenticated:this.isAuthenticated(),isLoading:!1}:{isAuthenticated:!1,isLoading:!0}}getJWTToken(){return this.getAccessToken()}getAccessToken(){var e,r;return(r=(e=this._client.interpreter)==null?void 0:e.state.context.accessToken.value)!=null?r:void 0}getDecodedAccessToken(){const e=this.getAccessToken();return e?qn(e):null}getHasuraClaims(){var e;return((e=this.getDecodedAccessToken())==null?void 0:e["https://hasura.io/jwt/claims"])||null}getHasuraClaim(e){var r;return((r=this.getHasuraClaims())==null?void 0:r[e.startsWith("x-hasura-")?e:`x-hasura-${e}`])||null}async refreshSession(e){try{const r=await this.waitUntilReady();return new Promise(n=>{const i=e||r.state.context.refreshToken.value;if(!i)return n({session:null,error:wo});const{changed:s}=r.send("TRY_TOKEN",{token:i});if(!s)return n({session:null,error:So});r.onTransition(o=>{o.matches({token:{idle:"error"}})?n({session:null,error:xo}):o.event.type==="TOKEN_CHANGED"&&n({session:Rt(o.context),error:null})})})}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return Rt((r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)}getUser(){var e,r,n;return((n=(r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)==null?void 0:n.user)||null}waitUntilReady(){const r=this._client.interpreter;if(!r)throw Error("Auth interpreter not set");return r.state.hasTag("loading")?new Promise((n,i)=>{let s=setTimeout(()=>i(`The state machine is not yet ready after ${15} seconds.`),15e3);r.onTransition(o=>{if(!o.hasTag("loading"))return clearTimeout(s),n(r)})}):Promise.resolve(r)}isReady(){var e,r;return!((r=(e=this._client.interpreter)==null?void 0:e.state)!=null&&r.hasTag("loading"))}get client(){return this._client}}var ea=typeof self=="object"?self.FormData:window.FormData,ta=Object.defineProperty,ra=Object.defineProperties,na=Object.getOwnPropertyDescriptors,In=Object.getOwnPropertySymbols,ia=Object.prototype.hasOwnProperty,sa=Object.prototype.propertyIsEnumerable,Nn=(t,e,r)=>e in t?ta(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e)=>{for(var r in e||(e={}))ia.call(e,r)&&Nn(t,r,e[r]);if(In)for(var r of In(e))sa.call(e,r)&&Nn(t,r,e[r]);return t},Cn=(t,e)=>ra(t,na(e));class oa{constructor({url:e}){this.url=e,this.httpClient=gt.create({baseURL:this.url})}async upload(e){const{formData:r}=e;try{return{fileMetadata:(await this.httpClient.post("/files",r,{headers:Cn(We(We({},this.generateUploadHeaders(e)),this.generateAuthHeaders()),{"Content-Type":"multipart/form-data"})})).data,error:null}}catch(n){return{fileMetadata:null,error:n}}}async getPresignedUrl(e){try{const{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:We({},this.generateAuthHeaders())})).data,error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r}=e;return await this.httpClient.delete(`/files/${r}`,{headers:We({},this.generateAuthHeaders())}),{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}generateUploadHeaders(e){const{bucketId:r,name:n,id:i}=e,s={};return r&&(s["x-nhost-bucket-id"]=r),i&&(s["x-nhost-file-id"]=i),n&&(s["x-nhost-file-name"]=n),s}generateAuthHeaders(){return!this.adminSecret&&!this.accessToken?null:this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}class aa{constructor({url:e,adminSecret:r}){this.url=e,this.api=new oa({url:e}),this.setAdminSecret(r)}async upload(e){let r;"file"in e?(r=new ea,r.append("file",e.file)):r=e.formData;const{fileMetadata:n,error:i}=await this.api.upload(Cn(We({},e),{formData:r}));return i?{fileMetadata:null,error:i}:n?{fileMetadata:n,error:null}:{fileMetadata:null,error:new Error("Invalid file returned")}}getUrl(e){return this.getPublicUrl(e)}getPublicUrl(e){const{fileId:r}=e;return`${this.url}/files/${r}`}async getPresignedUrl(e){const{presignedUrl:r,error:n}=await this.api.getPresignedUrl(e);return n?{presignedUrl:null,error:n}:r?{presignedUrl:r,error:null}:{presignedUrl:null,error:new Error("Invalid file id")}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}class Dn{constructor(e){const{url:r,adminSecret:n}=e;this.accessToken=null,this.adminSecret=n,this.instance=gt.create({baseURL:r})}async call(e,r,n){const i=ve(ve({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,mr(ve({},n),{headers:i}))}catch(o){if(o instanceof Error)return{res:null,error:o}}return s?{res:s,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}class Un{constructor(e){const{url:r,adminSecret:n}=e;this.url=r,this.accessToken=null,this.adminSecret=n,this.instance=gt.create({baseURL:r})}async request(e,r,n){const i=ve(ve({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);try{const s="",a=(await this.instance.post("",{operationName:s||void 0,query:typeof e=="string"?e:U.print(e),variables:r},mr(ve({},n),{headers:i}))).data,{data:c}=a;return a.errors?{data:null,error:a.errors}:typeof c!="object"||Array.isArray(c)||c===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:c,error:null}}catch(s){return s instanceof Error?{data:null,error:s}:(console.error(s),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}const ua=/^localhost(:\d+)*$/g;function Pt(t,e){const{backendUrl:r,subdomain:n,region:i}=t;if(!r&&!n)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(r)return`${r}/v1/${e}`;if(!n)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const s=n.match(ua);if(s&&s.length>0){const o=s[0];return o==="localhost"?`http://localhost:1337/v1/${e}`:`http://${o}/v1/${e}`}if(!i)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${n}.${e}.${i}.nhost.run/v1`}class $n{constructor(d){var l=d,{refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,adminSecret:c,devTools:f,start:u=!0}=l,p=Bn(l,["refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","adminSecret","devTools","start"]);var h;this.auth=new Zo({url:Pt(p,"auth"),refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,start:u}),this.storage=new aa({url:Pt(p,"storage"),adminSecret:c}),this.functions=new Dn({url:Pt(p,"functions"),adminSecret:c}),this.graphql=new Un({url:Pt(p,"graphql"),adminSecret:c}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(h=this.auth.client)==null||h.onStart(()=>{this.auth.onAuthStateChanged((v,y)=>{v==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(v=>{this.storage.setAccessToken(v==null?void 0:v.accessToken),this.functions.setAccessToken(v==null?void 0:v.accessToken),this.graphql.setAccessToken(v==null?void 0:v.accessToken)})}),this._adminSecret=c,this.devTools=f}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const ca=t=>new $n(t);R.NhostClient=$n,R.NhostFunctionsClient=Dn,R.NhostGraphqlClient=Un,R.createClient=ca,Object.defineProperties(R,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
14
+ ***************************************************************************** */var m=function(){return m=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},m.apply(this,arguments)};function Ct(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function x(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function A(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}function D(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return t.concat(s||Array.prototype.slice.call(e))}var k;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(k||(k={}));var Ce;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(Ce||(Ce={}));var Dt=k.Start,Ut=k.Stop,Je=k.Raise,Ye=k.Send,gr=k.Cancel,Kn=k.NullEvent,$t=k.Assign;k.After,k.DoneState;var Er=k.Log,Hn=k.Init,jt=k.Invoke;k.ErrorExecution;var wr=k.ErrorPlatform,zn=k.ErrorCustom,Sr=k.Update,Wn=k.Choose,Gn=k.Pure,Tr=".",br={},Lt="xstate.guard",Jn="",De=!0,Qe;function Mt(t,e,r){r===void 0&&(r=Tr);var n=Ue(t,r),i=Ue(e,r);return O(i)?O(n)?i===n:!1:O(n)?n in i:Object.keys(n).every(function(s){return s in i?Mt(n[s],i[s]):!1})}function xr(t){try{return O(t)||typeof t=="number"?"".concat(t):t.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function Bt(t,e){try{return me(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function Yn(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function Ue(t,e){if(Yn(t))return t.value;if(me(t))return Xe(t);if(typeof t!="string")return t;var r=Bt(t,e);return Xe(r)}function Xe(t){if(t.length===1)return t[0];for(var e={},r=e,n=0;n<t.length-1;n++)n===t.length-2?r[t[n]]=t[n+1]:(r[t[n]]={},r=r[t[n]]);return e}function $e(t,e){for(var r={},n=Object.keys(t),i=0;i<n.length;i++){var s=n[i];r[s]=e(t[s],s,t,i)}return r}function _r(t,e,r){var n,i,s={};try{for(var o=x(Object.keys(t)),a=o.next();!a.done;a=o.next()){var c=a.value,f=t[c];!r(f)||(s[c]=e(f,c,t))}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}var Qn=function(t){return function(e){var r,n,i=e;try{for(var s=x(t),o=s.next();!o.done;o=s.next()){var a=o.value;i=i[a]}}catch(c){r={error:c}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function Xn(t,e){return function(r){var n,i,s=r;try{for(var o=x(t),a=o.next();!a.done;a=o.next()){var c=a.value;s=s[e][c]}}catch(f){n={error:f}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}}function Ze(t){if(!t)return[[]];if(O(t))return[[t]];var e=N(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Ze(t[r]).map(function(i){return[r].concat(i)})}));return e}function N(t){var e;return(e=[]).concat.apply(e,D([],A(t),!1))}function Or(t){return me(t)?t:[t]}function Q(t){return t===void 0?[]:Or(t)}function et(t,e,r){var n,i;if(P(t))return t(e,r.data);var s={};try{for(var o=x(Object.keys(t)),a=o.next();!a.done;a=o.next()){var c=a.value,f=t[c];P(f)?s[c]=f(e,r.data):s[c]=f}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}function Zn(t){return/^(done|error)\./.test(t)}function Ar(t){return!!(t instanceof Promise||t!==null&&(P(t)||typeof t=="object")&&P(t.then))}function ei(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function Rr(t,e){var r,n,i=A([[],[]],2),s=i[0],o=i[1];try{for(var a=x(t),c=a.next();!c.done;c=a.next()){var f=c.value;e(f)?s.push(f):o.push(f)}}catch(u){r={error:u}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}return[s,o]}function kr(t,e){return $e(t.states,function(r,n){if(!!r){var i=(O(e)?void 0:e[n])||(r?r.current:void 0);if(!!i)return{current:i,states:kr(r,i)}}})}function ti(t,e){return{current:e,states:kr(t,e)}}function Pr(t,e,r,n){var i=t&&r.reduce(function(s,o){var a,c,f=o.assignment,u={state:n,action:o,_event:e},v={};if(P(f))v=f(s,e.data,u);else try{for(var d=x(Object.keys(f)),l=d.next();!l.done;l=d.next()){var h=l.value,p=f[h];v[h]=P(p)?p(s,e.data,u):p}}catch(y){a={error:y}}finally{try{l&&!l.done&&(c=d.return)&&c.call(d)}finally{if(a)throw a.error}}return Object.assign({},s,v)},t);return i}var je=function(){};function me(t){return Array.isArray(t)}function P(t){return typeof t=="function"}function O(t){return typeof t=="string"}function Ir(t,e){if(!!t)return O(t)?{type:Lt,name:t,predicate:e?e[t]:void 0}:P(t)?{type:Lt,name:t.name,predicate:t}:t}function ri(t){try{return"subscribe"in t&&P(t.subscribe)}catch{return!1}}var oe=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();Qe={},Qe[oe]=function(){return this},Qe[Symbol.observable]=function(){return this};function de(t){return!!t&&"__xstatenode"in t}function ni(t){return!!t&&typeof t.send=="function"}function Ft(t,e){return O(t)||typeof t=="number"?m({type:t},e):t}function V(t,e){if(!O(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=Ft(t);return m({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function ge(t,e){var r=Or(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||de(n)?{target:n,event:t}:m(m({},n),{event:t})});return r}function ii(t){if(!(t===void 0||t===Jn))return Q(t)}function Nr(t,e,r,n,i){var s=t.options.guards,o={state:i,cond:e,_event:n};if(e.type===Lt)return((s==null?void 0:s[e.name])||e.predicate)(r,n.data,o);var a=s==null?void 0:s[e.type];if(!a)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return a(r,n.data,o)}function Cr(t){return typeof t=="string"?{type:t}:t}function qt(t,e,r){if(typeof t=="object")return t;var n=function(){};return{next:t,error:e||n,complete:r||n}}function tt(t,e){return"".concat(t,":invocation[").concat(e,"]")}var rt=V({type:Hn});function Vt(t,e){return e&&e[t]||void 0}function Le(t,e){var r;if(O(t)||typeof t=="number"){var n=Vt(t,e);P(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(P(t))r={type:t.name||t.toString(),exec:t};else{var n=Vt(t.type,e);if(P(n))r=m(m({},t),{exec:n});else if(n){var i=n.type||t.type;r=m(m(m({},n),t),{type:i})}else r=t}return r}var nt=function(t,e){if(!t)return[];var r=me(t)?t:[t];return r.map(function(n){return Le(n,e)})};function Kt(t){var e=Le(t);return m(m({id:O(t)?t:e.id},e),{type:e.type})}function si(t){return O(t)?{type:Je,event:t}:Ht(t,{to:Ce.Internal})}function oi(t){return{type:Je,_event:V(t.event)}}function Ht(t,e){return{to:e?e.to:void 0,type:Ye,event:P(t)?t:Ft(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:P(t)?t.name:xr(t)}}function ai(t,e,r,n){var i={_event:r},s=V(P(t.event)?t.event(e,r.data,i):t.event),o;if(O(t.delay)){var a=n&&n[t.delay];o=P(a)?a(e,r.data,i):a}else o=P(t.delay)?t.delay(e,r.data,i):t.delay;var c=P(t.to)?t.to(e,r.data,i):t.to;return m(m({},t),{to:c,_event:s,event:s.data,delay:o})}var ui=function(t,e,r){return m(m({},t),{value:O(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},ci=function(t){return{type:gr,sendId:t}};function li(t){var e=Kt(t);return{type:k.Start,activity:e,exec:void 0}}function fi(t){var e=P(t)?t:Kt(t);return{type:k.Stop,activity:e,exec:void 0}}function di(t,e,r){var n=P(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:k.Stop,activity:i};return s}var hi=function(t){return{type:$t,assignment:t}};function pi(t,e){var r=e?"#".concat(e):"";return"".concat(k.After,"(").concat(t,")").concat(r)}function it(t,e){var r="".concat(k.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function st(t,e){var r="".concat(k.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Me(t,e){var r="".concat(k.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function zt(t,e,r,n,i,s){s===void 0&&(s=!1);var o=A(s?[[],i]:Rr(i,function(d){return d.type===$t}),2),a=o[0],c=o[1],f=a.length?Pr(r,n,a,e):r,u=s?[r]:void 0,v=N(c.map(function(d){var l;switch(d.type){case Je:return oi(d);case Ye:var h=ai(d,f,n,t.options.delays);return h;case Er:return ui(d,f,n);case Wn:{var p=d,y=(l=p.conds.find(function(C){var q=Ir(C.cond,t.options.guards);return!q||Nr(t,q,f,n,e)}))===null||l===void 0?void 0:l.actions;if(!y)return[];var E=A(zt(t,e,f,n,nt(Q(y),t.options.actions),s),2),g=E[0],w=E[1];return f=w,u==null||u.push(f),g}case Gn:{var y=d.get(f,n.data);if(!y)return[];var I=A(zt(t,e,f,n,nt(Q(y),t.options.actions),s),2),_=I[0],$=I[1];return f=$,u==null||u.push(f),_}case Ut:return di(d,f,n);case $t:{f=Pr(f,n,[d],e),u==null||u.push(f);break}default:var T=Le(d,t.options.actions),S=T.exec;if(S&&u){var b=u.length-1;T=m(m({},T),{exec:function(C){for(var q=[],W=1;W<arguments.length;W++)q[W-1]=arguments[W];S.apply(void 0,D([u[b]],A(q),!1))}})}return T}}).filter(function(d){return!!d}));return[v,f]}var Be=function(t,e){var r=e(t);return r};function Dr(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[oe]=function(){return this},e}function vi(t,e,r,n){var i,s=Cr(t.src),o=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],a=t.data?et(t.data,r,n):void 0,c=o?yi(o,t.id,a):Dr(t.id);return c.meta=t,c}function yi(t,e,r){var n=Dr(e);if(n.deferred=!0,de(t)){var i=n.state=Be(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function mi(t){try{return typeof t.send=="function"}catch{return!1}}function gi(t){return mi(t)&&"id"in t}function Ei(t){var e;return m((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[oe]=function(){return this},e),t)}var ot=function(t){return t.type==="atomic"||t.type==="final"};function Ee(t){return Object.keys(t.states).map(function(e){return t.states[e]}).filter(function(e){return e.type!=="history"})}function Ur(t){var e=[t];return ot(t)?e:e.concat(N(Ee(t).map(Ur)))}function we(t,e){var r,n,i,s,o,a,c,f,u=new Set(t),v=Wt(u),d=new Set(e);try{for(var l=x(d),h=l.next();!h.done;h=l.next())for(var p=h.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(b){r={error:b}}finally{try{h&&!h.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}var E=Wt(d);try{for(var g=x(d),w=g.next();!w.done;w=g.next()){var p=w.value;if(p.type==="compound"&&(!E.get(p)||!E.get(p).length))v.get(p)?v.get(p).forEach(function(C){return d.add(C)}):p.initialStateNodes.forEach(function(C){return d.add(C)});else if(p.type==="parallel")try{for(var I=(o=void 0,x(Ee(p))),_=I.next();!_.done;_=I.next()){var $=_.value;d.has($)||(d.add($),v.get($)?v.get($).forEach(function(C){return d.add(C)}):$.initialStateNodes.forEach(function(C){return d.add(C)}))}}catch(C){o={error:C}}finally{try{_&&!_.done&&(a=I.return)&&a.call(I)}finally{if(o)throw o.error}}}}catch(b){i={error:b}}finally{try{w&&!w.done&&(s=g.return)&&s.call(g)}finally{if(i)throw i.error}}try{for(var T=x(d),S=T.next();!S.done;S=T.next())for(var p=S.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(b){c={error:b}}finally{try{S&&!S.done&&(f=T.return)&&f.call(T)}finally{if(c)throw c.error}}return d}function $r(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(ot(n))return n.key}else return{}}var i={};return r.forEach(function(s){i[s.key]=$r(s,e)}),i}function Wt(t){var e,r,n=new Map;try{for(var i=x(t),s=i.next();!s.done;s=i.next()){var o=s.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(a){e={error:a}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n}function wi(t,e){var r=we([t],e);return $r(t,Wt(r))}function at(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function Si(t){return D([],A(new Set(N(D([],A(t.map(function(e){return e.ownEvents})),!1)))),!1)}function Fe(t,e){return e.type==="compound"?Ee(e).some(function(r){return r.type==="final"&&at(t,r)}):e.type==="parallel"?Ee(e).every(function(r){return Fe(t,r)}):!1}function Ti(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function jr(t){return new Set(N(t.map(function(e){return e.tags})))}function Lr(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(O(t)||O(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(i){return Lr(t[i],e[i])})}function bi(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function xi(t,e){var r=t.exec,n=m(m({},t),{exec:r!==void 0?function(){return r(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0});return n}var re=function(){function t(e){var r=this,n;this.actions=[],this.activities=br,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||br,this.meta=Ti(e.configuration),this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=(n=Array.isArray(e.tags)?new Set(e.tags):e.tags)!==null&&n!==void 0?n:new Set,this.machine=e.machine,Object.defineProperty(this,"nextEvents",{get:function(){return Si(r.configuration)}})}return t.from=function(e,r){if(e instanceof t)return e.context!==r?new t({value:e.value,context:r,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e;var n=rt;return new t({value:e,context:r,_event:n,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,r){if(e instanceof t){if(!e.actions.length)return e;var n=rt;return new t({value:e.value,context:r,_event:n,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,r)},t.prototype.toStrings=function(e,r){var n=this;if(e===void 0&&(e=this.value),r===void 0&&(r="."),O(e))return[e];var i=Object.keys(e);return i.concat.apply(i,D([],A(i.map(function(s){return n.toStrings(e[s],r).map(function(o){return s+r+o})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=Ct(e,["configuration","transitions","tags","machine"]);return m(m({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Mt(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;je(!!this.machine);var n=(r=this.machine)===null||r===void 0?void 0:r.getTransitionData(this,e);return!!(n!=null&&n.transitions.length)&&n.transitions.some(function(i){return i.target!==void 0||i.actions.length})},t}(),_i={deferEvents:!1},Mr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=m(m({},_i),e)}return t.prototype.initialize=function(e){if(this.initialized=!0,e){if(!this.options.deferEvents){this.schedule(e);return}this.process(e)}this.flushEvents()},t.prototype.schedule=function(e){if(!this.initialized||this.processingEvent){this.queue.push(e);return}if(this.queue.length!==0)throw new Error("Event queue should be empty when it is not processing events");this.process(e),this.flushEvents()},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var e=this.queue.shift();e;)this.process(e),e=this.queue.shift()},t.prototype.process=function(e){this.processingEvent=!0;try{e()}catch(r){throw this.clear(),r}finally{this.processingEvent=!1}},t}(),Gt=new Map,Oi=0,ut={bookId:function(){return"x:".concat(Oi++)},register:function(t,e){return Gt.set(t,e),t},get:function(t){return Gt.get(t)},free:function(t){Gt.delete(t)}};function Jt(){if(typeof globalThis!="undefined")return globalThis;if(typeof self!="undefined")return self;if(typeof window!="undefined")return window;if(typeof global!="undefined")return global}function Ai(){var t=Jt();if(t&&"__xstate__"in t)return t.__xstate__}function Ri(t){if(!!Jt()){var e=Ai();e&&e.register(t)}}function ki(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,o=function(){if(!s){for(s=!0;i.length>0;){var f=i.shift();r=t.transition(r,f,c),n.forEach(function(u){return u.next(r)})}s=!1}},a=Ei({id:e.id,send:function(f){i.push(f),o()},getSnapshot:function(){return r},subscribe:function(f,u,v){var d=qt(f,u,v);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),c={parent:e.parent,self:a,id:e.id||"anonymous",observers:n};return r=t.start?t.start(c):r,a}var Pi={sync:!1,autoForward:!1},K;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(K||(K={}));var Ii=function(){function t(e,r){var n=this;r===void 0&&(r=t.defaultOptions),this.machine=e,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=K.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(u,v){if(me(u))return n.batch(u),n.state;var d=V(Ft(u,v));if(n.status===K.Stopped)return n.state;if(n.status!==K.Running&&!n.options.deferEvents)throw new Error('Event "'.concat(d.name,'" was sent to uninitialized service "').concat(n.machine.id,`". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
15
+ Event: `).concat(JSON.stringify(d.data)));return n.scheduler.schedule(function(){n.forward(d);var l=n.nextState(d);n.update(l,d)}),n._state},this.sendTo=function(u,v){var d=n.parent&&(v===Ce.Parent||n.parent.id===v),l=d?n.parent:O(v)?n.children.get(v)||ut.get(v):ni(v)?v:void 0;if(!l){if(!d)throw new Error("Unable to send event to child '".concat(v,"' from service '").concat(n.id,"'."));return}"machine"in l?l.send(m(m({},u),{name:u.name===zn?"".concat(Me(n.id)):u.name,origin:n.sessionId})):l.send(u.data)};var i=m(m({},t.defaultOptions),r),s=i.clock,o=i.logger,a=i.parent,c=i.id,f=c!==void 0?c:e.id;this.id=f,this.logger=o,this.clock=s,this.parent=a,this.options=i,this.scheduler=new Mr({deferEvents:this.options.deferEvents}),this.sessionId=ut.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Be(this,function(){return e._initialState=e.machine.initialState,e._initialState})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),t.prototype.execute=function(e,r){var n,i;try{for(var s=x(e.actions),o=s.next();!o.done;o=s.next()){var a=o.value;this.exec(a,e,r)}}catch(c){n={error:c}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,o,a,c,f,u,v=this;if(e._sessionid=this.sessionId,this._state=e,this.options.execute&&this.execute(this.state),this.children.forEach(function(b){v.state.children[b.id]=b}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var d=x(this.eventListeners),l=d.next();!l.done;l=d.next()){var h=l.value;h(e.event)}}catch(b){n={error:b}}finally{try{l&&!l.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var p=x(this.listeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(e,e.event)}}catch(b){s={error:b}}finally{try{y&&!y.done&&(o=p.return)&&o.call(p)}finally{if(s)throw s.error}}try{for(var E=x(this.contextListeners),g=E.next();!g.done;g=E.next()){var w=g.value;w(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(b){a={error:b}}finally{try{g&&!g.done&&(c=E.return)&&c.call(E)}finally{if(a)throw a.error}}var I=Fe(e.configuration||[],this.machine);if(this.state.configuration&&I){var _=e.configuration.find(function(b){return b.type==="final"&&b.parent===v.machine}),$=_&&_.doneData?et(_.doneData,e.context,r):void 0;try{for(var T=x(this.doneListeners),S=T.next();!S.done;S=T.next()){var h=S.value;h(st(this.id,$))}}catch(b){f={error:b}}finally{try{S&&!S.done&&(u=T.return)&&u.call(T)}finally{if(f)throw f.error}}this.stop()}},t.prototype.onTransition=function(e){return this.listeners.add(e),this.status===K.Running&&e(this.state,this.state.event),this},t.prototype.subscribe=function(e,r,n){var i=this;if(!e)return{unsubscribe:function(){}};var s,o=n;return typeof e=="function"?s=e:(s=e.next.bind(e),o=e.complete.bind(e)),this.listeners.add(s),this.status!==K.NotStarted&&s(this.state),o&&(this.status===K.Stopped?o():this.onDone(o)),{unsubscribe:function(){s&&i.listeners.delete(s),o&&i.doneListeners.delete(o)}}},t.prototype.onEvent=function(e){return this.eventListeners.add(e),this},t.prototype.onSend=function(e){return this.sendListeners.add(e),this},t.prototype.onChange=function(e){return this.contextListeners.add(e),this},t.prototype.onStop=function(e){return this.stopListeners.add(e),this},t.prototype.onDone=function(e){return this.doneListeners.add(e),this},t.prototype.off=function(e){return this.listeners.delete(e),this.eventListeners.delete(e),this.sendListeners.delete(e),this.stopListeners.delete(e),this.doneListeners.delete(e),this.contextListeners.delete(e),this},t.prototype.start=function(e){var r=this;if(this.status===K.Running)return this;this.machine._init(),ut.register(this.sessionId,this),this.initialized=!0,this.status=K.Running;var n=e===void 0?this.initialState:Be(this,function(){return bi(e)?r.machine.resolveState(e):r.machine.resolveState(re.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,rt)}),this},t.prototype.stop=function(){var e,r,n,i,s,o,a,c,f,u,v=this;try{for(var d=x(this.listeners),l=d.next();!l.done;l=d.next()){var h=l.value;this.listeners.delete(h)}}catch(S){e={error:S}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}try{for(var p=x(this.stopListeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(),this.stopListeners.delete(h)}}catch(S){n={error:S}}finally{try{y&&!y.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}try{for(var E=x(this.contextListeners),g=E.next();!g.done;g=E.next()){var h=g.value;this.contextListeners.delete(h)}}catch(S){s={error:S}}finally{try{g&&!g.done&&(o=E.return)&&o.call(E)}finally{if(s)throw s.error}}try{for(var w=x(this.doneListeners),I=w.next();!I.done;I=w.next()){var h=I.value;this.doneListeners.delete(h)}}catch(S){a={error:S}}finally{try{I&&!I.done&&(c=w.return)&&c.call(w)}finally{if(a)throw a.error}}if(!this.initialized)return this;D([],A(this.state.configuration),!1).sort(function(S,b){return b.order-S.order}).forEach(function(S){var b,C;try{for(var q=x(S.definition.exit),W=q.next();!W.done;W=q.next()){var fe=W.value;v.exec(fe,v.state)}}catch(It){b={error:It}}finally{try{W&&!W.done&&(C=q.return)&&C.call(q)}finally{if(b)throw b.error}}}),this.children.forEach(function(S){P(S.stop)&&S.stop()}),this.children.clear();try{for(var _=x(Object.keys(this.delayedEventsMap)),$=_.next();!$.done;$=_.next()){var T=$.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(S){f={error:S}}finally{try{$&&!$.done&&(u=_.return)&&u.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.scheduler=new Mr({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=K.Stopped,this._initialState=void 0,ut.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(!(this.status===K.NotStarted&&this.options.deferEvents)){if(this.status!==K.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'))}this.scheduler.schedule(function(){var n,i,s=r.state,o=!1,a=[],c=function(d){var l=V(d);r.forward(l),s=Be(r,function(){return r.machine.transition(s,l)}),a.push.apply(a,D([],A(s.actions.map(function(h){return xi(h,s)})),!1)),o=o||!!s.changed};try{for(var f=x(e),u=f.next();!u.done;u=f.next()){var v=u.value;c(v)}}catch(d){n={error:d}}finally{try{u&&!u.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}s.changed=o,s.actions=a,r.update(s,V(e[e.length-1]))})},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype.nextState=function(e){var r=this,n=V(e);if(n.name.indexOf(wr)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(wr)===0}))throw n.data.data;var i=Be(this,function(){return r.machine.transition(r.state,n)});return i},t.prototype.forward=function(e){var r,n;try{for(var i=x(this.forwardTo),s=i.next();!s.done;s=i.next()){var o=s.value,a=this.children.get(o);if(!a)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(o,"'."));a.send(e)}}catch(c){r={error:c}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}},t.prototype.defer=function(e){var r=this;this.delayedEventsMap[e.id]=this.clock.setTimeout(function(){e.to?r.sendTo(e._event,e.to):r.send(e._event)},e.delay)},t.prototype.cancel=function(e){this.clock.clearTimeout(this.delayedEventsMap[e]),delete this.delayedEventsMap[e]},t.prototype.exec=function(e,r,n){n===void 0&&(n=this.machine.options.actions);var i=r.context,s=r._event,o=e.exec||Vt(e.type,n),a=P(o)?o:o?o.exec:e.exec;if(a)try{return a(i,s.data,{action:e,state:this.state,_event:s})}catch(I){throw this.parent&&this.parent.send({type:"xstate.error",data:I}),I}switch(e.type){case Ye:var c=e;if(typeof c.delay=="number"){this.defer(c);return}else c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case gr:this.cancel(e.sendId);break;case Dt:{if(this.status!==K.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===k.Invoke){var u=Cr(f.src),v=this.machine.options.services?this.machine.options.services[u.type]:void 0,d=f.id,l=f.data,h="autoForward"in f?f.autoForward:!!f.forward;if(!v)return;var p=l?et(l,i,s):void 0;if(typeof v=="string")return;var y=P(v)?v(i,s.data,{data:p,src:u,meta:f.meta}):v;if(!y)return;var E=void 0;de(y)&&(y=p?y.withContext(p):y,E={autoForward:h}),this.spawn(y,d,E)}else this.spawnActivity(f);break}case Ut:{this.stopChild(e.activity.id);break}case Er:var g=e.label,w=e.value;g?this.logger(g,w):this.logger(w);break}},t.prototype.removeChild=function(e){var r;this.children.delete(e),this.forwardTo.delete(e),(r=this.state)===null||r===void 0||delete r.children[e]},t.prototype.stopChild=function(e){var r=this.children.get(e);!r||(this.removeChild(e),P(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(Ar(e))return this.spawnPromise(Promise.resolve(e),r);if(P(e))return this.spawnCallback(e,r);if(gi(e))return this.spawnActor(e,r);if(ri(e))return this.spawnObservable(e,r);if(de(e))return this.spawnMachine(e,m(m({},n),{id:r}));if(ei(e))return this.spawnBehavior(e,r);throw new Error('Unable to spawn entity "'.concat(r,'" of type "').concat(typeof e,'".'))},t.prototype.spawnMachine=function(e,r){var n=this;r===void 0&&(r={});var i=new t(e,m(m({},this.options),{parent:this,id:r.id||e.id})),s=m(m({},Pi),r);s.sync&&i.onTransition(function(a){n.send(Sr,{state:a,id:i.id})});var o=i;return this.children.set(i.id,o),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(a){n.removeChild(i.id),n.send(V(a,{origin:i.id}))}).start(),o},t.prototype.spawnBehavior=function(e,r){var n=ki(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,o;e.then(function(c){s||(o=c,i.removeChild(r),i.send(V(st(r,c),{origin:r})))},function(c){if(!s){i.removeChild(r);var f=Me(r,c);try{i.send(V(f,{origin:r}))}catch{i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var a=(n={id:r,send:function(){},subscribe:function(c,f,u){var v=qt(c,f,u),d=!1;return e.then(function(l){d||(v.next(l),!d&&v.complete())},function(l){d||v.error(l)}),{unsubscribe:function(){return d=!0}}},stop:function(){s=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return o}},n[oe]=function(){return this},n);return this.children.set(r,a),a},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,o=new Set,a=new Set,c,f=function(d){c=d,a.forEach(function(l){return l(d)}),!s&&i.send(V(d,{origin:r}))},u;try{u=e(f,function(d){o.add(d)})}catch(d){this.send(Me(r,d))}if(Ar(u))return this.spawnPromise(u,r);var v=(n={id:r,send:function(d){return o.forEach(function(l){return l(d)})},subscribe:function(d){var l=qt(d);return a.add(l.next),{unsubscribe:function(){a.delete(l.next)}}},stop:function(){s=!0,P(u)&&u()},toJSON:function(){return{id:r}},getSnapshot:function(){return c}},n[oe]=function(){return this},n);return this.children.set(r,v),v},t.prototype.spawnObservable=function(e,r){var n,i=this,s,o=e.subscribe(function(c){s=c,i.send(V(c,{origin:r}))},function(c){i.removeChild(r),i.send(V(Me(r,c),{origin:r}))},function(){i.removeChild(r),i.send(V(st(r),{origin:r}))}),a=(n={id:r,send:function(){},subscribe:function(c,f,u){return e.subscribe(c,f,u)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[oe]=function(){return this},n);return this.children.set(r,a),a},t.prototype.spawnActor=function(e,r){return this.children.set(r,e),e},t.prototype.spawnActivity=function(e){var r=this.machine.options&&this.machine.options.activities?this.machine.options.activities[e.type]:void 0;if(!!r){var n=r(this.state.context,e);this.spawnEffect(e.id,n)}},t.prototype.spawnEffect=function(e,r){var n;this.children.set(e,(n={id:e,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:r||void 0,getSnapshot:function(){},toJSON:function(){return{id:e}}},n[oe]=function(){return this},n))},t.prototype.attachDev=function(){var e=Jt();if(this.options.devTools&&e){if(e.__REDUX_DEVTOOLS_EXTENSION__){var r=typeof this.options.devTools=="object"?this.options.devTools:void 0;this.devTools=e.__REDUX_DEVTOOLS_EXTENSION__.connect(m(m({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:m({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}Ri(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[oe]=function(){return this},t.prototype.getSnapshot=function(){return this.status===K.NotStarted?this.initialState:this._state},t.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(e,r){return setTimeout(e,r)},clearTimeout:function(e){return clearTimeout(e)}},logger:console.log.bind(console),devTools:!1},t.interpret=Se,t}();function Se(t,e){var r=new Ii(t,e);return r}function Ni(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function ct(t){return m(m({type:jt},t),{toJSON:function(){t.onDone,t.onError;var e=Ct(t,["onDone","onError"]);return m(m({},e),{type:jt,src:Ni(t.src)})}})}var Te="",Yt="#",qe="*",be={},xe=function(t){return t[0]===Yt},Ci=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Di=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(O(s.target)||de(s.target))}),i=e===Te?"the transient event":"event '".concat(e,"'");je(!n,"One or more transitions for ".concat(i," on state '").concat(t.id,"' are unreachable. ")+"Make sure that the default transition is the last one defined.")},Ui=function(){function t(e,r,n,i){var s=this;n===void 0&&(n="context"in e?e.context:void 0);var o;this.config=e,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign(Ci(),r),this.parent=i==null?void 0:i.parent,this.key=this.config.key||(i==null?void 0:i.key)||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:Tr),this.id=this.config.id||D([this.machine.key],A(this.path),!1).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:(o=this.config.schema)!==null&&o!==void 0?o:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?$e(this.config.states,function(f,u){var v,d=new t(f,{},void 0,{parent:s,key:u});return Object.assign(s.idMap,m((v={},v[d.id]=d,v),d.idMap)),d}):be;var a=0;function c(f){var u,v;f.order=a++;try{for(var d=x(Ee(f)),l=d.next();!l.done;l=d.next()){var h=l.value;c(h)}}catch(p){u={error:p}}finally{try{l&&!l.done&&(v=d.return)&&v.call(d)}finally{if(u)throw u.error}}}c(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(f){var u=f.event;return u===Te}):Te in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=Q(this.config.entry||this.config.onEntry).map(function(f){return Le(f)}),this.onExit=Q(this.config.exit||this.config.onExit).map(function(f){return Le(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=Q(this.config.invoke).map(function(f,u){var v,d;if(de(f)){var l=tt(s.id,u);return s.machine.options.services=m((v={},v[l]=f,v),s.machine.options.services),ct({src:l,id:l})}else if(O(f.src)){var l=f.id||tt(s.id,u);return ct(m(m({},f),{id:l,src:f.src}))}else if(de(f.src)||P(f.src)){var l=f.id||tt(s.id,u);return s.machine.options.services=m((d={},d[l]=f.src,d),s.machine.options.services),ct(m(m({id:l},f),{src:l}))}else{var h=f.src;return ct(m(m({id:tt(s.id,u)},f),{src:h}))}}),this.activities=Q(this.config.activities).concat(this.invoke).map(function(f){return Kt(f)}),this.transition=this.transition.bind(this),this.tags=Q(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||Ur(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,o=n.guards,a=n.services,c=n.delays;return new t(this.config,{actions:m(m({},i),e.actions),activities:m(m({},s),e.activities),guards:m(m({},o),e.guards),services:m(m({},a),e.services),delays:m(m({},c),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return P(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:$e(this.states,function(e){return e.definition}),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),t.prototype.toJSON=function(){return this.definition},Object.defineProperty(t.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var e=this.transitions;return this.__cache.on=e.reduce(function(r,n){return r[n.eventType]=r[n.eventType]||[],r[n.eventType].push(n),r},{})},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),t.prototype.getCandidates=function(e){if(this.__cache.candidates[e])return this.__cache.candidates[e];var r=e===Te,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===qe});return this.__cache.candidates[e]=n,n},t.prototype.getDelayedTransitions=function(){var e=this,r=this.config.after;if(!r)return[];var n=function(s,o){var a=P(s)?"".concat(e.id,":delay[").concat(o,"]"):s,c=pi(a,e.id);return e.onEntry.push(Ht(c,{delay:s})),e.onExit.push(ci(c)),c},i=me(r)?r.map(function(s,o){var a=n(s.delay,o);return m(m({},s),{event:a})}):N(Object.keys(r).map(function(s,o){var a=r[s],c=O(a)?{target:a}:a,f=isNaN(+s)?s:+s,u=n(f,o);return Q(c).map(function(v){return m(m({},v),{event:u,delay:f})})}));return i.map(function(s){var o=s.delay;return m(m({},e.formatTransition(s)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof re?e.value:Ue(e,this.delimiter);if(O(i)){var s=this.getStateNode(i).initial;return s!==void 0?this.getStateNodes((r={},r[i]=s,r)):[this,this.states[i]]}var o=Object.keys(i),a=[this];return a.push.apply(a,D([],A(N(o.map(function(c){return n.getStateNode(c).getStateNodes(i[c])}))),!1)),a},t.prototype.handles=function(e){var r=xr(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof re?e:re.create(e),n=Array.from(we([],this.getStateNodes(r.value)));return new re(m(m({},r),{value:this.resolve(r.value),configuration:n,done:Fe(n,this),tags:jr(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var i=this.getStateNode(e),s=i.next(r,n);return!s||!s.transitions.length?this.next(r,n):s},t.prototype.transitionCompoundNode=function(e,r,n){var i=Object.keys(e),s=this.getStateNode(i[0]),o=s._transition(e[i[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},t.prototype.transitionParallelNode=function(e,r,n){var i,s,o={};try{for(var a=x(Object.keys(e)),c=a.next();!c.done;c=a.next()){var f=c.value,u=e[f];if(!!u){var v=this.getStateNode(f),d=v._transition(u,r,n);d&&(o[f]=d)}}}catch(g){i={error:g}}finally{try{c&&!c.done&&(s=a.return)&&s.call(a)}finally{if(i)throw i.error}}var l=Object.keys(o).map(function(g){return o[g]}),h=N(l.map(function(g){return g.transitions})),p=l.some(function(g){return g.transitions.length>0});if(!p)return this.next(r,n);var y=N(l.map(function(g){return g.entrySet})),E=N(Object.keys(o).map(function(g){return o[g].configuration}));return{transitions:h,entrySet:y,exitSet:N(l.map(function(g){return g.exitSet})),configuration:E,source:r,actions:N(Object.keys(o).map(function(g){return o[g].actions}))}},t.prototype._transition=function(e,r,n){return O(e)?this.transitionLeafNode(e,r,n):Object.keys(e).length===1?this.transitionCompoundNode(e,r,n):this.transitionParallelNode(e,r,n)},t.prototype.getTransitionData=function(e,r){return this._transition(e.value,e,V(r))},t.prototype.next=function(e,r){var n,i,s=this,o=r.name,a=[],c=[],f;try{for(var u=x(this.getCandidates(o)),v=u.next();!v.done;v=u.next()){var d=v.value,l=d.cond,h=d.in,p=e.context,y=h?O(h)&&xe(h)?e.matches(Ue(this.getStateNodeById(h).path,this.delimiter)):Mt(Ue(h,this.delimiter),Qn(this.path.slice(0,-2))(e.value)):!0,E=!1;try{E=!l||Nr(this.machine,l,p,r,e)}catch(_){throw new Error("Unable to evaluate guard '".concat(l.name||l.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,`':
16
+ `).concat(_.message))}if(E&&y){d.target!==void 0&&(c=d.target),a.push.apply(a,D([],A(d.actions),!1)),f=d;break}}}catch(_){n={error:_}}finally{try{v&&!v.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}if(!!f){if(!c.length)return{transitions:[f],entrySet:[],exitSet:[],configuration:e.value?[this]:[],source:e,actions:a};var g=N(c.map(function(_){return s.getRelativeStateNodes(_,e.historyValue)})),w=!!f.internal,I=w?[]:N(g.map(function(_){return s.nodesFromChild(_)}));return{transitions:[f],entrySet:I,exitSet:w?[]:[this],configuration:g,source:e,actions:a}}},t.prototype.nodesFromChild=function(e){if(e.escapes(this))return[];for(var r=[],n=e;n&&n!==this;)r.push(n),n=n.parent;return r.push(this),r},t.prototype.escapes=function(e){if(this===e)return!1;for(var r=this.parent;r;){if(r===e)return!1;r=r.parent}return!0},t.prototype.getActions=function(e,r,n,i){var s,o,a,c,f=we([],i?this.getStateNodes(i.value):[this]),u=e.configuration.length?we(f,e.configuration):f;try{for(var v=x(u),d=v.next();!d.done;d=v.next()){var l=d.value;at(f,l)||e.entrySet.push(l)}}catch(T){s={error:T}}finally{try{d&&!d.done&&(o=v.return)&&o.call(v)}finally{if(s)throw s.error}}try{for(var h=x(f),p=h.next();!p.done;p=h.next()){var l=p.value;(!at(u,l)||at(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(T){a={error:T}}finally{try{p&&!p.done&&(c=h.return)&&c.call(h)}finally{if(a)throw a.error}}var y=N(e.entrySet.map(function(T){var S=[];if(T.type!=="final")return S;var b=T.parent;if(!b.parent)return S;S.push(it(T.id,T.doneData),it(b.id,T.doneData?et(T.doneData,r,n):void 0));var C=b.parent;return C.type==="parallel"&&Ee(C).every(function(q){return Fe(e.configuration,q)})&&S.push(it(C.id)),S}));e.exitSet.sort(function(T,S){return S.order-T.order}),e.entrySet.sort(function(T,S){return T.order-S.order});var E=new Set(e.entrySet),g=new Set(e.exitSet),w=A([N(Array.from(E).map(function(T){return D(D([],A(T.activities.map(function(S){return li(S)})),!1),A(T.onEntry),!1)})).concat(y.map(si)),N(Array.from(g).map(function(T){return D(D([],A(T.onExit),!1),A(T.activities.map(function(S){return fi(S)})),!1)}))],2),I=w[0],_=w[1],$=nt(_.concat(e.actions).concat(I),this.machine.options.actions);return $},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=V(r),s;if(e instanceof re)s=n===void 0?e:this.resolveState(re.from(e,n));else{var o=O(e)?this.resolve(Xe(this.getResolvedPath(e))):this.resolve(e),a=n!=null?n:this.machine.context;s=this.resolveState(re.from(o,a))}if(!De&&i.name===qe)throw new Error("An event cannot have the wildcard type ('".concat(qe,"')"));if(this.strict&&!this.events.includes(i.name)&&!Zn(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var c=this._transition(s.value,s,i)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},f=we([],this.getStateNodes(s.value)),u=c.configuration.length?we(f,c.configuration):f;return c.configuration=D([],A(u),!1),this.resolveTransition(c,s,s.context,i)},t.prototype.resolveRaisedTransition=function(e,r,n){var i,s=e.actions;return e=this.transition(e,r),e._event=n,e.event=n.data,(i=e.actions).unshift.apply(i,D([],A(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,o,a=this;i===void 0&&(i=rt);var c=e.configuration,f=!r||e.transitions.length>0,u=f?wi(this.machine,c):void 0,v=r?r.historyValue?r.historyValue:e.source?this.machine.historyValue(r.value):void 0:void 0,d=this.getActions(e,n,i,r),l=r?m({},r.activities):{};try{for(var h=x(d),p=h.next();!p.done;p=h.next()){var y=p.value;y.type===Dt?l[y.activity.id||y.activity.type]=y:y.type===Ut&&(l[y.activity.id||y.activity.type]=!1)}}catch(G){s={error:G}}finally{try{p&&!p.done&&(o=h.return)&&o.call(h)}finally{if(s)throw s.error}}var E=A(zt(this,r,n,i,d,this.machine.config.preserveActionOrder),2),g=E[0],w=E[1],I=A(Rr(g,function(G){return G.type===Je||G.type===Ye&&G.to===Ce.Internal}),2),_=I[0],$=I[1],T=g.filter(function(G){var Ne;return G.type===Dt&&((Ne=G.activity)===null||Ne===void 0?void 0:Ne.type)===jt}),S=T.reduce(function(G,Ne){return G[Ne.activity.id]=vi(Ne.activity,a.machine,w,i),G},r?m({},r.children):{}),b=f?e.configuration:r?r.configuration:[],C=Fe(b,this),q=new re({value:u||r.value,context:w,_event:i,_sessionid:r?r._sessionid:null,historyValue:u?v?ti(v,u):void 0:r?r.historyValue:void 0,history:!u||e.source?r:void 0,actions:u?$:[],activities:u?l:r?r.activities:{},events:[],configuration:b,transitions:e.transitions,children:S,done:C,tags:jr(b),machine:this}),W=n!==w;q.changed=i.name===Sr||W;var fe=q.history;fe&&delete fe.history;var It=!C&&(this._transient||c.some(function(G){return G._transient}));if(!f&&(!It||i.name===Te))return q;var ee=q;if(!C)for(It&&(ee=this.resolveRaisedTransition(ee,{type:Kn},i));_.length;){var fa=_.shift();ee=this.resolveRaisedTransition(ee,fa._event,i)}var da=ee.changed||(fe?!!ee.actions.length||W||typeof fe.value!=typeof ee.value||!Lr(ee.value,fe.value):void 0);return ee.changed=da,ee.history=fe,ee},t.prototype.getStateNode=function(e){if(xe(e))return this.machine.getStateNodeById(e);if(!this.states)throw new Error("Unable to retrieve child state '".concat(e,"' from '").concat(this.id,"'; no child states exist."));var r=this.states[e];if(!r)throw new Error("Child state '".concat(e,"' does not exist on '").concat(this.id,"'"));return r},t.prototype.getStateNodeById=function(e){var r=xe(e)?e.slice(Yt.length):e;if(r===this.id)return this;var n=this.machine.idMap[r];if(!n)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return n},t.prototype.getStateNodeByPath=function(e){if(typeof e=="string"&&xe(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=Bt(e,this.delimiter).slice(),n=this;r.length;){var i=r.shift();if(!i.length)break;n=n.getStateNode(i)}return n},t.prototype.resolve=function(e){var r,n=this;if(!e)return this.initialStateValue||be;switch(this.type){case"parallel":return $e(this.initialStateValue,function(s,o){return s?n.getStateNode(o).resolve(e[o]||s):be});case"compound":if(O(e)){var i=this.getStateNode(e);return i.type==="parallel"||i.type==="compound"?(r={},r[e]=i.initialStateValue,r):e}return Object.keys(e).length?$e(e,function(s,o){return s?n.getStateNode(o).resolve(s):be}):this.initialStateValue||{};default:return e||be}},t.prototype.getResolvedPath=function(e){if(xe(e)){var r=this.machine.idMap[e.slice(Yt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return Bt(e,this.delimiter)},Object.defineProperty(t.prototype,"initialStateValue",{get:function(){var e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;var r;if(this.type==="parallel")r=_r(this.states,function(n){return n.initialStateValue||be},function(n){return n.type!=="history"});else if(this.initial!==void 0){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));r=ot(this.states[this.initial])?this.initial:(e={},e[this.initial]=this.states[this.initial].initialStateValue,e)}else r={};return this.__cache.initialStateValue=r,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),t.prototype.getInitialState=function(e,r){this._init();var n=this.getStateNodes(e);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,r!=null?r:this.machine.context,void 0)},Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this.initialStateValue;if(!e)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"target",{get:function(){var e;if(this.type==="history"){var r=this.config;O(r.target)?e=xe(r.target)?Xe(this.machine.getStateNodeById(r.target).path.slice(this.path.length-1)):r.target:e=r.target}return e},enumerable:!1,configurable:!0}),t.prototype.getRelativeStateNodes=function(e,r,n){return n===void 0&&(n=!0),n?e.type==="history"?e.resolveHistory(r):e.initialStateNodes:[e]},Object.defineProperty(t.prototype,"initialStateNodes",{get:function(){var e=this;if(ot(this))return[this];if(this.type==="compound"&&!this.initial)return De||je(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Ze(this.initialStateValue);return N(r.map(function(n){return e.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(e){if(!e.length)return[this];var r=A(e),n=r[0],i=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var s=this.getStateNode(n);if(s.type==="history")return s.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(i)},t.prototype.historyValue=function(e){if(!!Object.keys(this.states).length)return{current:e||this.initialStateValue,states:_r(this.states,function(r,n){if(!e)return r.historyValue();var i=O(e)?void 0:e[n];return r.historyValue(i||r.initialStateValue)},function(r){return!r.history})}},t.prototype.resolveHistory=function(e){var r=this;if(this.type!=="history")return[this];var n=this.parent;if(!e){var i=this.target;return i?N(Ze(i).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var s=Xn(n.path,"states")(e).current;return O(s)?[n.getStateNode(s)]:N(Ze(s).map(function(o){return r.history==="deep"?n.getFromRelativePath(o):[n.states[o[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=N(Object.keys(this.states).map(function(n){return e.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var e,r,n,i;if(this.__cache.events)return this.__cache.events;var s=this.states,o=new Set(this.ownEvents);if(s)try{for(var a=x(Object.keys(s)),c=a.next();!c.done;c=a.next()){var f=c.value,u=s[f];if(u.states)try{for(var v=(n=void 0,x(u.events)),d=v.next();!d.done;d=v.next()){var l=d.value;o.add("".concat(l))}}catch(h){n={error:h}}finally{try{d&&!d.done&&(i=v.return)&&i.call(v)}finally{if(n)throw n.error}}}}catch(h){e={error:h}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!O(n))return n;var i=n[0]===r.delimiter;if(i&&!r.parent)return r.getStateNodeByPath(n.slice(1));var s=i?r.key+n:n;if(r.parent)try{var o=r.parent.getStateNodeByPath(s);return o}catch(a){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
17
+ `).concat(a.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=ii(e.target),i="internal"in e?e.internal:n?n.some(function(c){return O(c)&&c[0]===r.delimiter}):!0,s=this.machine.options.guards,o=this.resolveTarget(n),a=m(m({},e),{actions:nt(Q(e.actions)),cond:Ir(e.cond,s),target:o,source:this,internal:i,eventType:e.event,toJSON:function(){return m(m({},a),{target:a.target?a.target.map(function(c){return"#".concat(c.id)}):void 0,source:"#".concat(r.id)})}});return a},t.prototype.formatTransitions=function(){var e,r,n=this,i;if(!this.config.on)i=[];else if(Array.isArray(this.config.on))i=this.config.on;else{var s=this.config.on,o=qe,a=s[o],c=a===void 0?[]:a,f=Ct(s,[typeof o=="symbol"?o:o+""]);i=N(Object.keys(f).map(function(g){!De&&g===Te&&je(!1,"Empty string transition configs (e.g., `{ on: { '': ... }}`) for transient transitions are deprecated. Specify the transition in the `{ always: ... }` property instead. "+'Please check the `on` configuration for "#'.concat(n.id,'".'));var w=ge(g,f[g]);return De||Di(n,g,w),w}).concat(ge(qe,c)))}var u=this.config.always?ge("",this.config.always):[],v=this.config.onDone?ge(String(it(this.id)),this.config.onDone):[];De||je(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var d=N(this.invoke.map(function(g){var w=[];return g.onDone&&w.push.apply(w,D([],A(ge(String(st(g.id)),g.onDone)),!1)),g.onError&&w.push.apply(w,D([],A(ge(String(Me(g.id)),g.onError)),!1)),w})),l=this.after,h=N(D(D(D(D([],A(v),!1),A(d),!1),A(i),!1),A(u),!1).map(function(g){return Q(g).map(function(w){return n.formatTransition(w)})}));try{for(var p=x(l),y=p.next();!y.done;y=p.next()){var E=y.value;h.push(E)}}catch(g){e={error:g}}finally{try{y&&!y.done&&(r=p.return)&&r.call(p)}finally{if(e)throw e.error}}return h},t}();function Ve(t,e){return new Ui(t,e)}var L=hi,X=Ht,Qt={exports:{}},Br=function(e,r){return function(){for(var i=new Array(arguments.length),s=0;s<i.length;s++)i[s]=arguments[s];return e.apply(r,i)}},$i=Br,Xt=Object.prototype.toString,Zt=function(t){return function(e){var r=Xt.call(e);return t[r]||(t[r]=r.slice(8,-1).toLowerCase())}}(Object.create(null));function he(t){return t=t.toLowerCase(),function(r){return Zt(r)===t}}function er(t){return Array.isArray(t)}function lt(t){return typeof t=="undefined"}function ji(t){return t!==null&&!lt(t)&&t.constructor!==null&&!lt(t.constructor)&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}var Fr=he("ArrayBuffer");function Li(t){var e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&Fr(t.buffer),e}function Mi(t){return typeof t=="string"}function Bi(t){return typeof t=="number"}function qr(t){return t!==null&&typeof t=="object"}function ft(t){if(Zt(t)!=="object")return!1;var e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}var Fi=he("Date"),qi=he("File"),Vi=he("Blob"),Ki=he("FileList");function tr(t){return Xt.call(t)==="[object Function]"}function Hi(t){return qr(t)&&tr(t.pipe)}function zi(t){var e="[object FormData]";return t&&(typeof FormData=="function"&&t instanceof FormData||Xt.call(t)===e||tr(t.toString)&&t.toString()===e)}var Wi=he("URLSearchParams");function Gi(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function Ji(){return typeof navigator!="undefined"&&(navigator.product==="ReactNative"||navigator.product==="NativeScript"||navigator.product==="NS")?!1:typeof window!="undefined"&&typeof document!="undefined"}function rr(t,e){if(!(t===null||typeof t=="undefined"))if(typeof t!="object"&&(t=[t]),er(t))for(var r=0,n=t.length;r<n;r++)e.call(null,t[r],r,t);else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.call(null,t[i],i,t)}function nr(){var t={};function e(i,s){ft(t[s])&&ft(i)?t[s]=nr(t[s],i):ft(i)?t[s]=nr({},i):er(i)?t[s]=i.slice():t[s]=i}for(var r=0,n=arguments.length;r<n;r++)rr(arguments[r],e);return t}function Yi(t,e,r){return rr(e,function(i,s){r&&typeof i=="function"?t[s]=$i(i,r):t[s]=i}),t}function Qi(t){return t.charCodeAt(0)===65279&&(t=t.slice(1)),t}function Xi(t,e,r,n){t.prototype=Object.create(e.prototype,n),t.prototype.constructor=t,r&&Object.assign(t.prototype,r)}function Zi(t,e,r){var n,i,s,o={};e=e||{};do{for(n=Object.getOwnPropertyNames(t),i=n.length;i-- >0;)s=n[i],o[s]||(e[s]=t[s],o[s]=!0);t=Object.getPrototypeOf(t)}while(t&&(!r||r(t,e))&&t!==Object.prototype);return e}function es(t,e,r){t=String(t),(r===void 0||r>t.length)&&(r=t.length),r-=e.length;var n=t.indexOf(e,r);return n!==-1&&n===r}function ts(t){if(!t)return null;var e=t.length;if(lt(e))return null;for(var r=new Array(e);e-- >0;)r[e]=t[e];return r}var rs=function(t){return function(e){return t&&e instanceof t}}(typeof Uint8Array!="undefined"&&Object.getPrototypeOf(Uint8Array)),B={isArray:er,isArrayBuffer:Fr,isBuffer:ji,isFormData:zi,isArrayBufferView:Li,isString:Mi,isNumber:Bi,isObject:qr,isPlainObject:ft,isUndefined:lt,isDate:Fi,isFile:qi,isBlob:Vi,isFunction:tr,isStream:Hi,isURLSearchParams:Wi,isStandardBrowserEnv:Ji,forEach:rr,merge:nr,extend:Yi,trim:Gi,stripBOM:Qi,inherits:Xi,toFlatObject:Zi,kindOf:Zt,kindOfTest:he,endsWith:es,toArray:ts,isTypedArray:rs,isFileList:Ki},_e=B;function Vr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var Kr=function(e,r,n){if(!r)return e;var i;if(n)i=n(r);else if(_e.isURLSearchParams(r))i=r.toString();else{var s=[];_e.forEach(r,function(c,f){c===null||typeof c=="undefined"||(_e.isArray(c)?f=f+"[]":c=[c],_e.forEach(c,function(v){_e.isDate(v)?v=v.toISOString():_e.isObject(v)&&(v=JSON.stringify(v)),s.push(Vr(f)+"="+Vr(v))}))}),i=s.join("&")}if(i){var o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+i}return e},ns=B;function dt(){this.handlers=[]}dt.prototype.use=function(e,r,n){return this.handlers.push({fulfilled:e,rejected:r,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1},dt.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},dt.prototype.forEach=function(e){ns.forEach(this.handlers,function(n){n!==null&&e(n)})};var is=dt,ss=B,os=function(e,r){ss.forEach(e,function(i,s){s!==r&&s.toUpperCase()===r.toUpperCase()&&(e[r]=i,delete e[s])})},Hr=B;function Oe(t,e,r,n,i){Error.call(this),this.message=t,this.name="AxiosError",e&&(this.code=e),r&&(this.config=r),n&&(this.request=n),i&&(this.response=i)}Hr.inherits(Oe,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}}});var zr=Oe.prototype,Wr={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED"].forEach(function(t){Wr[t]={value:t}}),Object.defineProperties(Oe,Wr),Object.defineProperty(zr,"isAxiosError",{value:!0}),Oe.from=function(t,e,r,n,i,s){var o=Object.create(zr);return Hr.toFlatObject(t,o,function(c){return c!==Error.prototype}),Oe.call(o,t.message,e,r,n,i),o.name=t.name,s&&Object.assign(o,s),o};var Ae=Oe,Gr={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Z=B;function as(t,e){e=e||new FormData;var r=[];function n(s){return s===null?"":Z.isDate(s)?s.toISOString():Z.isArrayBuffer(s)||Z.isTypedArray(s)?typeof Blob=="function"?new Blob([s]):Buffer.from(s):s}function i(s,o){if(Z.isPlainObject(s)||Z.isArray(s)){if(r.indexOf(s)!==-1)throw Error("Circular reference detected in "+o);r.push(s),Z.forEach(s,function(c,f){if(!Z.isUndefined(c)){var u=o?o+"."+f:f,v;if(c&&!o&&typeof c=="object"){if(Z.endsWith(f,"{}"))c=JSON.stringify(c);else if(Z.endsWith(f,"[]")&&(v=Z.toArray(c))){v.forEach(function(d){!Z.isUndefined(d)&&e.append(u,n(d))});return}}i(c,u)}}),r.pop()}else e.append(o,n(s))}return i(t),e}var Jr=as,ir=Ae,us=function(e,r,n){var i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):r(new ir("Request failed with status code "+n.status,[ir.ERR_BAD_REQUEST,ir.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))},ht=B,cs=ht.isStandardBrowserEnv()?function(){return{write:function(r,n,i,s,o,a){var c=[];c.push(r+"="+encodeURIComponent(n)),ht.isNumber(i)&&c.push("expires="+new Date(i).toGMTString()),ht.isString(s)&&c.push("path="+s),ht.isString(o)&&c.push("domain="+o),a===!0&&c.push("secure"),document.cookie=c.join("; ")},read:function(r){var n=document.cookie.match(new RegExp("(^|;\\s*)("+r+")=([^;]*)"));return n?decodeURIComponent(n[3]):null},remove:function(r){this.write(r,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}(),ls=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},fs=function(e,r){return r?e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""):e},ds=ls,hs=fs,Yr=function(e,r){return e&&!ds(r)?hs(e,r):r},sr=B,ps=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"],vs=function(e){var r={},n,i,s;return e&&sr.forEach(e.split(`
18
+ `),function(a){if(s=a.indexOf(":"),n=sr.trim(a.substr(0,s)).toLowerCase(),i=sr.trim(a.substr(s+1)),n){if(r[n]&&ps.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([i]):r[n]=r[n]?r[n]+", "+i:i}}),r},Qr=B,ys=Qr.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function i(s){var o=s;return e&&(r.setAttribute("href",o),o=r.href),r.setAttribute("href",o),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:r.pathname.charAt(0)==="/"?r.pathname:"/"+r.pathname}}return n=i(window.location.href),function(o){var a=Qr.isString(o)?i(o):o;return a.protocol===n.protocol&&a.host===n.host}}():function(){return function(){return!0}}(),or=Ae,ms=B;function Xr(t){or.call(this,t==null?"canceled":t,or.ERR_CANCELED),this.name="CanceledError"}ms.inherits(Xr,or,{__CANCEL__:!0});var pt=Xr,gs=function(e){var r=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return r&&r[1]||""},Ke=B,Es=us,ws=cs,Ss=Kr,Ts=Yr,bs=vs,xs=ys,_s=Gr,ne=Ae,Os=pt,As=gs,Zr=function(e){return new Promise(function(n,i){var s=e.data,o=e.headers,a=e.responseType,c;function f(){e.cancelToken&&e.cancelToken.unsubscribe(c),e.signal&&e.signal.removeEventListener("abort",c)}Ke.isFormData(s)&&Ke.isStandardBrowserEnv()&&delete o["Content-Type"];var u=new XMLHttpRequest;if(e.auth){var v=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(v+":"+d)}var l=Ts(e.baseURL,e.url);u.open(e.method.toUpperCase(),Ss(l,e.params,e.paramsSerializer),!0),u.timeout=e.timeout;function h(){if(!!u){var E="getAllResponseHeaders"in u?bs(u.getAllResponseHeaders()):null,g=!a||a==="text"||a==="json"?u.responseText:u.response,w={data:g,status:u.status,statusText:u.statusText,headers:E,config:e,request:u};Es(function(_){n(_),f()},function(_){i(_),f()},w),u=null}}if("onloadend"in u?u.onloadend=h:u.onreadystatechange=function(){!u||u.readyState!==4||u.status===0&&!(u.responseURL&&u.responseURL.indexOf("file:")===0)||setTimeout(h)},u.onabort=function(){!u||(i(new ne("Request aborted",ne.ECONNABORTED,e,u)),u=null)},u.onerror=function(){i(new ne("Network Error",ne.ERR_NETWORK,e,u,u)),u=null},u.ontimeout=function(){var g=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded",w=e.transitional||_s;e.timeoutErrorMessage&&(g=e.timeoutErrorMessage),i(new ne(g,w.clarifyTimeoutError?ne.ETIMEDOUT:ne.ECONNABORTED,e,u)),u=null},Ke.isStandardBrowserEnv()){var p=(e.withCredentials||xs(l))&&e.xsrfCookieName?ws.read(e.xsrfCookieName):void 0;p&&(o[e.xsrfHeaderName]=p)}"setRequestHeader"in u&&Ke.forEach(o,function(g,w){typeof s=="undefined"&&w.toLowerCase()==="content-type"?delete o[w]:u.setRequestHeader(w,g)}),Ke.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),a&&a!=="json"&&(u.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&u.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&u.upload&&u.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(c=function(E){!u||(i(!E||E&&E.type?new Os:E),u.abort(),u=null)},e.cancelToken&&e.cancelToken.subscribe(c),e.signal&&(e.signal.aborted?c():e.signal.addEventListener("abort",c))),s||(s=null);var y=As(l);if(y&&["http","https","file"].indexOf(y)===-1){i(new ne("Unsupported protocol "+y+":",ne.ERR_BAD_REQUEST,e));return}u.send(s)})},Rs=null,M=B,en=os,tn=Ae,ks=Gr,Ps=Jr,Is={"Content-Type":"application/x-www-form-urlencoded"};function rn(t,e){!M.isUndefined(t)&&M.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function Ns(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Zr),t}function Cs(t,e,r){if(M.isString(t))try{return(e||JSON.parse)(t),M.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var vt={transitional:ks,adapter:Ns(),transformRequest:[function(e,r){if(en(r,"Accept"),en(r,"Content-Type"),M.isFormData(e)||M.isArrayBuffer(e)||M.isBuffer(e)||M.isStream(e)||M.isFile(e)||M.isBlob(e))return e;if(M.isArrayBufferView(e))return e.buffer;if(M.isURLSearchParams(e))return rn(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n=M.isObject(e),i=r&&r["Content-Type"],s;if((s=M.isFileList(e))||n&&i==="multipart/form-data"){var o=this.env&&this.env.FormData;return Ps(s?{"files[]":e}:e,o&&new o)}else if(n||i==="application/json")return rn(r,"application/json"),Cs(e);return e}],transformResponse:[function(e){var r=this.transitional||vt.transitional,n=r&&r.silentJSONParsing,i=r&&r.forcedJSONParsing,s=!n&&this.responseType==="json";if(s||i&&M.isString(e)&&e.length)try{return JSON.parse(e)}catch(o){if(s)throw o.name==="SyntaxError"?tn.from(o,tn.ERR_BAD_RESPONSE,this,null,this.response):o}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Rs},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};M.forEach(["delete","get","head"],function(e){vt.headers[e]={}}),M.forEach(["post","put","patch"],function(e){vt.headers[e]=M.merge(Is)});var ar=vt,Ds=B,Us=ar,$s=function(e,r,n){var i=this||Us;return Ds.forEach(n,function(o){e=o.call(i,e,r)}),e},nn=function(e){return!!(e&&e.__CANCEL__)},sn=B,ur=$s,js=nn,Ls=ar,Ms=pt;function cr(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new Ms}var Bs=function(e){cr(e),e.headers=e.headers||{},e.data=ur.call(e,e.data,e.headers,e.transformRequest),e.headers=sn.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),sn.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||Ls.adapter;return r(e).then(function(i){return cr(e),i.data=ur.call(e,i.data,i.headers,e.transformResponse),i},function(i){return js(i)||(cr(e),i&&i.response&&(i.response.data=ur.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},z=B,on=function(e,r){r=r||{};var n={};function i(u,v){return z.isPlainObject(u)&&z.isPlainObject(v)?z.merge(u,v):z.isPlainObject(v)?z.merge({},v):z.isArray(v)?v.slice():v}function s(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(e[u],r[u])}function o(u){if(!z.isUndefined(r[u]))return i(void 0,r[u])}function a(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(void 0,r[u])}function c(u){if(u in r)return i(e[u],r[u]);if(u in e)return i(void 0,e[u])}var f={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:c};return z.forEach(Object.keys(e).concat(Object.keys(r)),function(v){var d=f[v]||s,l=d(v);z.isUndefined(l)&&d!==c||(n[v]=l)}),n},an={version:"0.27.2"},Fs=an.version,ae=Ae,lr={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){lr[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var un={};lr.transitional=function(e,r,n){function i(s,o){return"[Axios v"+Fs+"] Transitional option '"+s+"'"+o+(n?". "+n:"")}return function(s,o,a){if(e===!1)throw new ae(i(o," has been removed"+(r?" in "+r:"")),ae.ERR_DEPRECATED);return r&&!un[o]&&(un[o]=!0,console.warn(i(o," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,o,a):!0}};function qs(t,e,r){if(typeof t!="object")throw new ae("options must be an object",ae.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],o=e[s];if(o){var a=t[s],c=a===void 0||o(a,s,t);if(c!==!0)throw new ae("option "+s+" must be "+c,ae.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new ae("Unknown option "+s,ae.ERR_BAD_OPTION)}}var Vs={assertOptions:qs,validators:lr},cn=B,Ks=Kr,ln=is,fn=Bs,yt=on,Hs=Yr,dn=Vs,Re=dn.validators;function ke(t){this.defaults=t,this.interceptors={request:new ln,response:new ln}}ke.prototype.request=function(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=yt(this.defaults,r),r.method?r.method=r.method.toLowerCase():this.defaults.method?r.method=this.defaults.method.toLowerCase():r.method="get";var n=r.transitional;n!==void 0&&dn.assertOptions(n,{silentJSONParsing:Re.transitional(Re.boolean),forcedJSONParsing:Re.transitional(Re.boolean),clarifyTimeoutError:Re.transitional(Re.boolean)},!1);var i=[],s=!0;this.interceptors.request.forEach(function(l){typeof l.runWhen=="function"&&l.runWhen(r)===!1||(s=s&&l.synchronous,i.unshift(l.fulfilled,l.rejected))});var o=[];this.interceptors.response.forEach(function(l){o.push(l.fulfilled,l.rejected)});var a;if(!s){var c=[fn,void 0];for(Array.prototype.unshift.apply(c,i),c=c.concat(o),a=Promise.resolve(r);c.length;)a=a.then(c.shift(),c.shift());return a}for(var f=r;i.length;){var u=i.shift(),v=i.shift();try{f=u(f)}catch(d){v(d);break}}try{a=fn(f)}catch(d){return Promise.reject(d)}for(;o.length;)a=a.then(o.shift(),o.shift());return a},ke.prototype.getUri=function(e){e=yt(this.defaults,e);var r=Hs(e.baseURL,e.url);return Ks(r,e.params,e.paramsSerializer)},cn.forEach(["delete","get","head","options"],function(e){ke.prototype[e]=function(r,n){return this.request(yt(n||{},{method:e,url:r,data:(n||{}).data}))}}),cn.forEach(["post","put","patch"],function(e){function r(n){return function(s,o,a){return this.request(yt(a||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}ke.prototype[e]=r(),ke.prototype[e+"Form"]=r(!0)});var zs=ke,Ws=pt;function Pe(t){if(typeof t!="function")throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(i){e=i});var r=this;this.promise.then(function(n){if(!!r._listeners){var i,s=r._listeners.length;for(i=0;i<s;i++)r._listeners[i](n);r._listeners=null}}),this.promise.then=function(n){var i,s=new Promise(function(o){r.subscribe(o),i=o}).then(n);return s.cancel=function(){r.unsubscribe(i)},s},t(function(i){r.reason||(r.reason=new Ws(i),e(r.reason))})}Pe.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},Pe.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},Pe.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},Pe.source=function(){var e,r=new Pe(function(i){e=i});return{token:r,cancel:e}};var Gs=Pe,Js=function(e){return function(n){return e.apply(null,n)}},Ys=B,Qs=function(e){return Ys.isObject(e)&&e.isAxiosError===!0},hn=B,Xs=Br,mt=zs,Zs=on,eo=ar;function pn(t){var e=new mt(t),r=Xs(mt.prototype.request,e);return hn.extend(r,mt.prototype,e),hn.extend(r,e),r.create=function(i){return pn(Zs(t,i))},r}var H=pn(eo);H.Axios=mt,H.CanceledError=pt,H.CancelToken=Gs,H.isCancel=nn,H.VERSION=an.version,H.toFormData=Jr,H.AxiosError=Ae,H.Cancel=H.CanceledError,H.all=function(e){return Promise.all(e)},H.spread=Js,H.isAxiosError=Qs,Qt.exports=H,Qt.exports.default=H;var gt=Qt.exports;/*! js-cookie v3.0.1 | MIT */function Et(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)t[n]=r[n]}return t}var to={read:function(t){return t[0]==='"'&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function fr(t,e){function r(i,s,o){if(typeof document!="undefined"){o=Et({},e,o),typeof o.expires=="number"&&(o.expires=new Date(Date.now()+o.expires*864e5)),o.expires&&(o.expires=o.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in o)!o[c]||(a+="; "+c,o[c]!==!0&&(a+="="+o[c].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+a}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],o={},a=0;a<s.length;a++){var c=s[a].split("="),f=c.slice(1).join("=");try{var u=decodeURIComponent(c[0]);if(o[u]=t.read(f,u),i===u)break}catch{}}return i?o[i]:o}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",Et({},s,{expires:-1}))},withAttributes:function(i){return fr(this.converter,Et({},this.attributes,i))},withConverter:function(i){return fr(Et({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var dr=fr(to,{path:"/"}),ro=Object.defineProperty,no=Object.defineProperties,io=Object.getOwnPropertyDescriptors,wt=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,mn=(t,e,r)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Y=(t,e)=>{for(var r in e||(e={}))vn.call(e,r)&&mn(t,r,e[r]);if(wt)for(var r of wt(e))yn.call(e,r)&&mn(t,r,e[r]);return t},ie=(t,e)=>no(t,io(e)),gn=(t,e)=>{var r={};for(var n in t)vn.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&wt)for(var n of wt(t))e.indexOf(n)<0&&yn.call(t,n)&&(r[n]=t[n]);return r};function so(t){return new TextEncoder().encode(t)}function pe(t){const e=new Uint8Array(t);let r="";for(const i of e)r+=String.fromCharCode(i);return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function hr(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),r=(4-e.length%4)%4,n=e.padEnd(e.length+r,"="),i=atob(n),s=new ArrayBuffer(i.length),o=new Uint8Array(s);for(let a=0;a<i.length;a++)o[a]=i.charCodeAt(a);return s}function En(){return(window==null?void 0:window.PublicKeyCredential)!==void 0&&typeof window.PublicKeyCredential=="function"}function wn(t){const{id:e}=t;return ie(Y({},t),{id:hr(e),transports:t.transports})}function Sn(t){return t==="localhost"||/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(t)}class F extends Error{constructor(e,r="WebAuthnError"){super(e),this.name=r}}function oo({error:t,options:e}){var r,n;const{publicKey:i}=e;if(!i)throw Error("options was missing required publicKey property");if(t.name==="AbortError"){if(e.signal===new AbortController().signal)return new F("Registration ceremony was sent an abort signal","AbortError")}else if(t.name==="ConstraintError"){if(((r=i.authenticatorSelection)===null||r===void 0?void 0:r.requireResidentKey)===!0)return new F("Discoverable credentials were required but no available authenticator supported it","ConstraintError");if(((n=i.authenticatorSelection)===null||n===void 0?void 0:n.userVerification)==="required")return new F("User verification was required but no available authenticator supported it","ConstraintError")}else{if(t.name==="InvalidStateError")return new F("The authenticator was previously registered","InvalidStateError");if(t.name==="NotAllowedError")return new F("User clicked cancel, or the registration ceremony timed out","NotAllowedError");if(t.name==="NotSupportedError")return i.pubKeyCredParams.filter(o=>o.type==="public-key").length===0?new F('No entry in pubKeyCredParams was of type "public-key"',"NotSupportedError"):new F("No available authenticator supported any of the specified pubKeyCredParams algorithms","NotSupportedError");if(t.name==="SecurityError"){const s=window.location.hostname;if(Sn(s)){if(i.rp.id!==s)return new F(`The RP ID "${i.rp.id}" is invalid for this domain`,"SecurityError")}else return new F(`${window.location.hostname} is an invalid domain`,"SecurityError")}else if(t.name==="TypeError"){if(i.user.id.byteLength<1||i.user.id.byteLength>64)return new F("User ID was not between 1 and 64 characters","TypeError")}else if(t.name==="UnknownError")return new F("The authenticator was unable to process the specified options, or could not create a new credential","UnknownError")}return t}class ao{createNewAbortSignal(){return this.controller&&this.controller.abort(),this.controller=new AbortController,this.controller.signal}reset(){this.controller=void 0}}const St=new ao;async function Tn(t){if(!En())throw new Error("WebAuthn is not supported in this browser");const r={publicKey:ie(Y({},t),{challenge:hr(t.challenge),user:ie(Y({},t.user),{id:so(t.user.id)}),excludeCredentials:t.excludeCredentials.map(wn)})};r.signal=St.createNewAbortSignal();let n;try{n=await navigator.credentials.create(r)}catch(f){throw oo({error:f,options:r})}finally{St.reset()}if(!n)throw new Error("Registration was not completed");const{id:i,rawId:s,response:o,type:a}=n,c={id:i,rawId:pe(s),response:{attestationObject:pe(o.attestationObject),clientDataJSON:pe(o.clientDataJSON)},type:a,clientExtensionResults:n.getClientExtensionResults(),authenticatorAttachment:n.authenticatorAttachment};return typeof o.getTransports=="function"&&(c.transports=o.getTransports()),c}function uo(t){return new TextDecoder("utf-8").decode(t)}async function co(){if(navigator.credentials.conditionalMediationSupported)return!0;const t=window.PublicKeyCredential;return t.isConditionalMediationAvailable!==void 0&&t.isConditionalMediationAvailable()}function lo({error:t,options:e}){var r;const{publicKey:n}=e;if(!n)throw Error("options was missing required publicKey property");if(t.name==="AbortError"){if(e.signal===new AbortController().signal)return new F("Authentication ceremony was sent an abort signal","AbortError")}else{if(t.name==="NotAllowedError")return!((r=n.allowCredentials)===null||r===void 0)&&r.length?new F("No available authenticator recognized any of the allowed credentials","NotAllowedError"):new F("User clicked cancel, or the authentication ceremony timed out","NotAllowedError");if(t.name==="SecurityError"){const i=window.location.hostname;if(Sn(i)){if(n.rpId!==i)return new F(`The RP ID "${n.rpId}" is invalid for this domain`,"SecurityError")}else return new F(`${window.location.hostname} is an invalid domain`,"SecurityError")}else if(t.name==="UnknownError")return new F("The authenticator was unable to process the specified options, or could not create a new assertion signature","UnknownError")}return t}async function fo(t,e=!1){var r,n;if(!En())throw new Error("WebAuthn is not supported in this browser");let i;((r=t.allowCredentials)===null||r===void 0?void 0:r.length)!==0&&(i=(n=t.allowCredentials)===null||n===void 0?void 0:n.map(wn));const s=ie(Y({},t),{challenge:hr(t.challenge),allowCredentials:i}),o={};if(e){if(!await co())throw Error("Browser does not support WebAuthn autofill");if(document.querySelectorAll("input[autocomplete*='webauthn']").length<1)throw Error('No <input> with `"webauthn"` in its `autocomplete` attribute was detected');o.mediation="conditional",s.allowCredentials=[]}o.publicKey=s,o.signal=St.createNewAbortSignal();let a;try{a=await navigator.credentials.get(o)}catch(l){throw lo({error:l,options:o})}finally{St.reset()}if(!a)throw new Error("Authentication was not completed");const{id:c,rawId:f,response:u,type:v}=a;let d;return u.userHandle&&(d=uo(u.userHandle)),{id:c,rawId:pe(f),response:{authenticatorData:pe(u.authenticatorData),clientDataJSON:pe(u.clientDataJSON),signature:pe(u.signature),userHandle:d},type:v,clientExtensionResults:a.getClientExtensionResults(),authenticatorAttachment:a.authenticatorAttachment}}const Tt="nhostRefreshToken",bt="nhostRefreshTokenExpiresAt",ho=3,po=300,vo=5,yo=0,mo=1,ue=10,xt=20;class _t extends Error{constructor(e){super(e.message),Error.captureStackTrace(this,this.constructor),e instanceof Error?(this.name=e.name,this.error={error:e.name,status:mo,message:e.message}):(this.name=e.error,this.error=e)}}const ce={status:ue,error:"invalid-email",message:"Email is incorrectly formatted"},pr={status:ue,error:"invalid-password",message:"Password is incorrectly formatted"},bn={status:ue,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},go={status:ue,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},Eo={status:ue,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},wo={status:ue,error:"no-refresh-token",message:"No refresh token has been provided"},So={status:xt,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},se={status:xt,error:"already-signed-in",message:"User is already signed in"},To={status:xt,error:"unauthenticated-user",message:"User is not authenticated"},bo={status:xt,error:"unverified-user",message:"Email needs verification"},xo={status:ue,error:"invalid-refresh-token",message:"Invalid or expired refresh token"},Ie=t=>{const e=gt.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,o,a,c,f,u,v,d;return Promise.reject({error:{message:(a=(o=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?o:r.request.responseText)!=null?a:JSON.stringify(r),status:(v=(u=(c=r.response)==null?void 0:c.status)!=null?u:(f=r.response)==null?void 0:f.data.statusCode)!=null?v:yo,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},Ot=typeof window!="undefined",At=new Map,_o=t=>{var e;return Ot&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=At.get(t))!=null?e:null},Oo=(t,e)=>{Ot&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?At.set(t,e):At.has(t)&&At.delete(t)},Ao=(t,e)=>{if(t==="localStorage"||t==="web")return _o;if(t==="cookie")return r=>{var n;return Ot&&(n=dr.get(r))!=null?n:null};if(!e)throw Error(`clientStorageType is set to '${t}' but no clientStorage has been given`);if(t==="react-native")return r=>{var n;return(n=e.getItem)==null?void 0:n.call(e,r)};if(t==="capacitor")return r=>{var n;return(n=e.get)==null?void 0:n.call(e,{key:r})};if(t==="expo-secure-storage")return r=>{var n;return(n=e.getItemAsync)==null?void 0:n.call(e,r)};if(t==="custom"){if(e.getItem&&e.removeItem)return e.getItem;if(e.getItemAsync)return e.getItemAsync;throw Error(`clientStorageType is set to 'custom' but clientStorage is missing either "getItem" and "removeItem" properties or "getItemAsync" property`)}throw Error(`Unknown storage type: ${t}`)},Ro=(t,e)=>{if(t==="localStorage"||t==="web")return Oo;if(t==="cookie")return(r,n)=>{Ot&&(n?dr.set(r,n,{expires:30}):dr.remove(r))};if(!e)throw Error(`clientStorageType is set to '${t}' but no clienStorage has been given`);if(t==="react-native")return(r,n)=>{var i,s;return n?(i=e.setItem)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};if(t==="capacitor")return(r,n)=>{var i,s;return n?(i=e.set)==null?void 0:i.call(e,{key:r,value:n}):(s=e.remove)==null?void 0:s.call(e,{key:r})};if(t==="expo-secure-storage")return async(r,n)=>{var i,s;return n?(i=e.setItemAsync)==null?void 0:i.call(e,r,n):(s=e.deleteItemAsync)==null?void 0:s.call(e,r)};if(t==="custom"){if(!e.removeItem)throw Error("clientStorageType is set to 'custom' but clientStorage is missing a removeItem property");if(e.setItem)return(r,n)=>{var i,s;return n?(i=e.setItem)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};if(e.setItemAsync)return async(r,n)=>{var i,s;return n?(i=e.setItemAsync)==null?void 0:i.call(e,r,n):(s=e.removeItem)==null?void 0:s.call(e,r)};throw Error("clientStorageType is set to 'custom' but clientStorage is missing setItem or setItemAsync property")}throw Error(`Unknown storage type: ${t}`)},xn=(t,e)=>{const r=e&&Object.entries(e).map(([n,i])=>{const s=Array.isArray(i)?i.join(","):typeof i=="object"?JSON.stringify(i):i;return`${n}=${encodeURIComponent(s)}`}).join("&");return r?`${t}?${r}`:t},te=(t,e)=>{if(!(e!=null&&e.redirectTo))return e;const r=e,{redirectTo:n}=r,i=gn(r,["redirectTo"]);if(!t)return n.startsWith("/")?i:e;const s=new URL(t),o=Object.fromEntries(new URLSearchParams(s.search)),a=new URL(n.startsWith("/")?s.origin+n:n),c=new URLSearchParams(a.search);let f=Object.fromEntries(c);n.startsWith("/")&&(f=Y(Y({},o),f));let u=s.pathname;return a.pathname.length>1&&(u+=a.pathname.slice(1)),ie(Y({},i),{redirectTo:xn(a.origin+u,f)})};function Rt(t,e){var r;if(!e){if(typeof window=="undefined")return;e=((r=window.location)==null?void 0:r.href)||""}t=t.replace(/[\[\]]/g,"\\$&");const n=new RegExp("[?&#]"+t+"(=([^&#]*)|&|#|$)"),i=n.exec(e);return i?i[2]?decodeURIComponent(i[2].replace(/\+/g," ")):"":null}function _n(t){var e;if(typeof window=="undefined")return;const r=window==null?void 0:window.location;if(!!r&&r){const n=new URLSearchParams(r.search),i=new URLSearchParams((e=r.hash)==null?void 0:e.slice(1));n.delete(t),i.delete(t);let s=window.location.pathname;Array.from(n).length&&(s+=`?${n.toString()}`),Array.from(i).length&&(s+=`#${i.toString()}`),window.history.pushState({},"",s)}}const le=t=>!!t&&typeof t=="string"&&!!String(t).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),vr=t=>!!t&&typeof t=="string"&&t.length>=ho,On=t=>!!t&&typeof t=="string",ko=t=>t&&typeof t=="string"&&t.match(/^mfaTotp:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),yr={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},Po=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Ie(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"changeEmail",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:L({error:i=>ce}),saveRequestError:L({error:(i,{data:{error:s}})=>s}),reportError:X(i=>({type:"ERROR",error:i.error})),reportSuccess:X("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!le(s)},services:{requestChange:async(i,{email:s,options:o})=>(await n.post("/user/email/change",{newEmail:s,options:te(e,o)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},Io=({backendUrl:t,interpreter:e})=>{const r=Ie(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidPassword",actions:"saveInvalidPasswordError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidPasswordError:L({error:n=>pr}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:X(n=>({type:"ERROR",error:n.error})),reportSuccess:X("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!vr(i)},services:{requestChange:(n,{password:i,ticket:s})=>r.post("/user/password",{newPassword:i,ticket:s},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},No=({backendUrl:t,clientUrl:e})=>{const r=Ie(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"changePassword",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"requestChange",id:"requestChange",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:L({error:n=>ce}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:X(n=>({type:"ERROR",error:n.error})),reportSuccess:X("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!le(i)},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:te(e,s)})}})},Co=({backendUrl:t,clientUrl:e})=>{const r=Ie(t);return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},preserveActionOrder:!0,id:"sendVerificationEmail",initial:"idle",context:{error:null},states:{idle:{on:{REQUEST:[{cond:"invalidEmail",actions:"saveInvalidEmailError",target:".error"},{target:"requesting"}]},initial:"initial",states:{initial:{},success:{},error:{}}},requesting:{invoke:{src:"request",id:"request",onDone:{target:"idle.success",actions:"reportSuccess"},onError:{actions:["saveRequestError","reportError"],target:"idle.error"}}}}},{actions:{saveInvalidEmailError:L({error:n=>ce}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:X(n=>({type:"ERROR",error:n.error})),reportSuccess:X("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!le(i)},services:{request:async(n,{email:i,options:s})=>(await r.post("/user/email/send-verification-email",{email:i,options:te(e,s)})).data}})},Do=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:o,autoRefreshToken:a=!0,autoSignIn:c=!0})=>{const f=r||Ao(i,s),u=n||Ro(i,s),v=Ie(t),d=async(l,h,p)=>(await v.post(l,h,p)).data;return Ve({schema:{context:{},events:{},services:{}},tsTypes:{},context:yr,preserveActionOrder:!0,id:"nhost",type:"parallel",states:{authentication:{initial:"starting",on:{SESSION_UPDATE:[{cond:"hasSession",actions:["saveSession","resetTimer","reportTokenChanged"],target:".signedIn"}]},states:{starting:{entry:"resetErrors",tags:["loading"],always:{cond:"isSignedIn",target:"signedIn"},invoke:{id:"importRefreshToken",src:"importRefreshToken",onDone:{actions:["saveSession","reportTokenChanged"],target:"signedIn"},onError:{actions:["saveAuthenticationError"],target:"signedOut"}}},signedOut:{initial:"noErrors",entry:"reportSignedOut",states:{noErrors:{},success:{},needsSmsOtp:{},needsMfa:{},failed:{},signingOut:{entry:["clearContextExceptRefreshToken"],exit:["destroyRefreshToken","reportTokenChanged"],invoke:{src:"signout",id:"signingOut",onDone:{target:"success"},onError:{target:"failed",actions:["saveAuthenticationError"]}}}},on:{SIGNIN_PASSWORD:"authenticating.password",SIGNIN_ANONYMOUS:"authenticating.anonymous",SIGNIN_SECURITY_KEY_EMAIL:"authenticating.securityKeyEmail",SIGNIN_MFA_TOTP:"authenticating.mfa.totp"}},authenticating:{entry:"resetErrors",states:{password:{invoke:{src:"signInPassword",id:"authenticateUserWithPassword",onDone:[{cond:"hasMfaTicket",actions:["saveMfaTicket"],target:"#nhost.authentication.signedOut.needsMfa"},{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"}],onError:[{cond:"unverified",target:["#nhost.authentication.signedOut","#nhost.registration.incomplete.needsEmailVerification"]},{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}]}},anonymous:{invoke:{src:"signInAnonymous",id:"authenticateAnonymously",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}}},mfa:{states:{totp:{invoke:{src:"signInMfaTotp",id:"signInMfaTotp",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:["saveAuthenticationError"],target:"#nhost.authentication.signedOut.failed"}}}}},securityKeyEmail:{invoke:{src:"signInSecurityKeyEmail",id:"authenticateUserWithSecurityKey",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:[{cond:"unverified",target:["#nhost.authentication.signedOut","#nhost.registration.incomplete.needsEmailVerification"]},{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}]}}}},signedIn:{type:"parallel",entry:["reportSignedIn","cleanUrl","broadcastToken","resetErrors"],on:{SIGNOUT:"signedOut.signingOut"},states:{refreshTimer:{id:"timer",initial:"idle",states:{disabled:{type:"final"},stopped:{always:{cond:"noToken",target:"idle"}},idle:{always:[{cond:"isAutoRefreshDisabled",target:"disabled"},{cond:"hasRefreshToken",target:"running"}]},running:{initial:"pending",entry:"resetTimer",states:{pending:{after:{"1000":{internal:!1,target:"pending"}},always:{cond:"refreshTimerShouldRefresh",target:"refreshing"}},refreshing:{invoke:{src:"refreshToken",id:"refreshToken",onDone:{actions:["saveSession","resetTimer","reportTokenChanged"],target:"pending"},onError:[{actions:"saveRefreshAttempt",target:"pending"}]}}}}}}}}}},token:{initial:"idle",states:{idle:{on:{TRY_TOKEN:"running"},initial:"noErrors",states:{noErrors:{},error:{}}},running:{invoke:{src:"refreshToken",id:"authenticateWithToken",onDone:{actions:["saveSession","reportTokenChanged"],target:["#nhost.authentication.signedIn","idle.noErrors"]},onError:[{cond:"isSignedIn",target:"idle.error"},{actions:"saveAuthenticationError",target:["#nhost.authentication.signedOut.failed","idle.error"]}]}}}},registration:{initial:"incomplete",on:{SIGNED_IN:[{cond:"isAnonymous",target:".incomplete"},".complete"]},states:{incomplete:{on:{SIGNUP_EMAIL_PASSWORD:"emailPassword",SIGNUP_SECURITY_KEY:"securityKey",PASSWORDLESS_EMAIL:"passwordlessEmail",PASSWORDLESS_SMS:"passwordlessSms",PASSWORDLESS_SMS_OTP:"passwordlessSmsOtp"},initial:"noErrors",states:{noErrors:{},needsEmailVerification:{},needsOtp:{},failed:{}}},emailPassword:{entry:["resetErrors"],invoke:{src:"signUpEmailPassword",id:"signUpEmailPassword",onDone:[{cond:"hasSession",actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},{actions:"clearContext",target:["#nhost.authentication.signedOut","incomplete.needsEmailVerification"]}],onError:[{cond:"unverified",target:"incomplete.needsEmailVerification"},{actions:"saveRegistrationError",target:"incomplete.failed"}]}},securityKey:{entry:["resetErrors"],invoke:{src:"signUpSecurityKey",id:"signUpSecurityKey",onDone:[{cond:"hasSession",actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},{actions:"clearContext",target:["#nhost.authentication.signedOut","incomplete.needsEmailVerification"]}],onError:[{cond:"unverified",target:"incomplete.needsEmailVerification"},{actions:"saveRegistrationError",target:"incomplete.failed"}]}},passwordlessEmail:{entry:["resetErrors"],invoke:{src:"passwordlessEmail",id:"passwordlessEmail",onDone:{actions:"clearContext",target:["#nhost.authentication.signedOut","incomplete.needsEmailVerification"]},onError:{actions:"saveRegistrationError",target:"incomplete.failed"}}},passwordlessSms:{entry:["resetErrors"],invoke:{src:"passwordlessSms",id:"passwordlessSms",onDone:{actions:"clearContext",target:["#nhost.authentication.signedOut","incomplete.needsOtp"]},onError:{actions:"saveRegistrationError",target:"incomplete.failed"}}},passwordlessSmsOtp:{entry:["resetErrors"],invoke:{src:"passwordlessSmsOtp",id:"passwordlessSmsOtp",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveRegistrationError",target:"incomplete.failed"}}},complete:{on:{SIGNED_OUT:"incomplete"}}}}}},{actions:{reportSignedIn:X("SIGNED_IN"),reportSignedOut:X("SIGNED_OUT"),reportTokenChanged:X("TOKEN_CHANGED"),clearContext:L(()=>(u(bt,null),u(Tt,null),Y({},yr))),clearContextExceptRefreshToken:L(({refreshToken:{value:l}})=>(u(bt,null),ie(Y({},yr),{refreshToken:{value:l}}))),saveSession:L({user:(l,{data:h})=>{var p;return((p=h==null?void 0:h.session)==null?void 0:p.user)||null},accessToken:(l,{data:h})=>{if(h.session){const{accessTokenExpiresIn:p,accessToken:y}=h.session,E=new Date(Date.now()+p*1e3);return u(bt,E.toISOString()),{value:y,expiresAt:E}}return u(bt,null),{value:null,expiresAt:null}},refreshToken:(l,{data:h})=>{var p;const y=((p=h.session)==null?void 0:p.refreshToken)||null;return y&&u(Tt,y),{value:y}}}),saveMfaTicket:L({mfa:(l,h)=>{var p;return(p=h.data)==null?void 0:p.mfa}}),resetTimer:L({refreshTimer:l=>({startedAt:new Date,attempts:0,lastAttempt:null})}),saveRefreshAttempt:L({refreshTimer:(l,h)=>({startedAt:l.refreshTimer.startedAt,attempts:l.refreshTimer.attempts+1,lastAttempt:new Date})}),saveAuthenticationError:L({errors:({errors:l},{data:{error:h}})=>ie(Y({},l),{authentication:h})}),resetErrors:L({errors:l=>({})}),saveRegistrationError:L({errors:({errors:l},{data:{error:h}})=>ie(Y({},l),{registration:h})}),destroyRefreshToken:L({refreshToken:l=>(u(Tt,null),{value:null})}),cleanUrl:()=>{c&&Rt("refreshToken")&&(_n("refreshToken"),_n("type"))},broadcastToken:l=>{if(c)try{new BroadcastChannel("nhost").postMessage(l.refreshToken.value)}catch{}}},guards:{isAnonymous:(l,h)=>{var p;return!!((p=l.user)!=null&&p.isAnonymous)},isSignedIn:l=>!!l.user&&!!l.refreshToken.value&&!!l.accessToken.value,noToken:l=>!l.refreshToken.value,hasRefreshToken:l=>!!l.refreshToken.value,isAutoRefreshDisabled:()=>!a,refreshTimerShouldRefresh:l=>{const{expiresAt:h}=l.accessToken;return h?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>vo*1e3:o&&Date.now()-l.refreshTimer.startedAt.getTime()>o*1e3?!0:h.getTime()-Date.now()-1e3*po<=0:!1},unverified:(l,{data:{error:h}})=>h.status===401&&(h.message==="Email is not verified"||h.error==="unverified-user"),hasSession:(l,h)=>{var p;return!!((p=h.data)!=null&&p.session)},hasMfaTicket:(l,h)=>{var p;return!!((p=h.data)!=null&&p.mfa)}},services:{signInPassword:(l,{email:h,password:p})=>le(h)?vr(p)?d("/signin/email-password",{email:h,password:p}):Promise.reject({error:pr}):Promise.reject({error:ce}),passwordlessSms:(l,{phoneNumber:h,options:p})=>{var y;return On(h)?(y=l.user)!=null&&y.isAnonymous?(console.warn("Deanonymisation from a phone number is not yet implemented in hasura-auth"),d("/user/deanonymize",{signInMethod:"passwordless",connection:"sms",phoneNumber:h,options:te(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}})):d("/signin/passwordless/sms",{phoneNumber:h,options:te(e,p)}):Promise.reject({error:bn})},passwordlessSmsOtp:(l,{phoneNumber:h,otp:p})=>On(h)?d("/signin/passwordless/sms/otp",{phoneNumber:h,otp:p}):Promise.reject({error:bn}),passwordlessEmail:(l,{email:h,options:p})=>{var y;return le(h)?(y=l.user)!=null&&y.isAnonymous?d("/user/deanonymize",{signInMethod:"passwordless",connection:"email",email:h,options:te(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signin/passwordless/email",{email:h,options:te(e,p)}):Promise.reject({error:ce})},signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,h)=>{var p;const y=h.ticket||((p=l.mfa)==null?void 0:p.ticket);return y?ko(y)?d("/signin/mfa/totp",{ticket:y,otp:h.otp}):Promise.reject({error:go}):Promise.reject({error:Eo})},signInSecurityKeyEmail:async(l,{email:h})=>{if(!le(h))throw new _t(ce);const p=await d("/signin/webauthn",{email:h});let y;try{y=await fo(p)}catch(E){throw new _t(E)}return d("/signin/webauthn/verify",{email:h,credential:y})},refreshToken:async(l,h)=>{const p=h.type==="TRY_TOKEN"?h.token:l.refreshToken.value;return{session:await d("/token",{refreshToken:p}),error:null}},signout:(l,h)=>d("/signout",{refreshToken:l.refreshToken.value,all:!!h.all}),signUpEmailPassword:async(l,{email:h,password:p,options:y})=>{var E;return le(h)?vr(p)?(E=l.user)!=null&&E.isAnonymous?d("/user/deanonymize",{signInMethod:"email-password",email:h,password:p,options:te(e,y)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signup/email-password",{email:h,password:p,options:te(e,y)}):Promise.reject({error:pr}):Promise.reject({error:ce})},signUpSecurityKey:async(l,{email:h,options:p})=>{if(!le(h))return Promise.reject({error:ce});const y=p==null?void 0:p.nickname;y&&delete p.nickname;const E=await d("/signup/webauthn",{email:h,options:p});let g;try{g=await Tn(E)}catch(w){throw new _t(w)}return d("/signup/webauthn/verify",{credential:g,options:{redirectTo:p==null?void 0:p.redirectTo,nickname:y}})},importRefreshToken:async()=>{let l=null;if(c){const p=Rt("refreshToken")||null;if(p)try{return{session:await d("/token",{refreshToken:p}),error:null}}catch(y){l=y.error}else{const y=Rt("error");if(y)return Promise.reject({session:null,error:{status:ue,error:y,message:Rt("errorDescription")||y}})}}const h=await f(Tt);if(h)try{return{session:await d("/token",{refreshToken:h}),error:null}}catch(p){l=p.error}return Promise.reject({error:l})}}})};class Uo{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:o=!0,backendUrl:a,clientUrl:c,devTools:f}=r,u=gn(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl","devTools"]);if(this._subscriptions=new Set,this.backendUrl=a,this.clientUrl=c,this.machine=Do(ie(Y({},u),{backendUrl:a,clientUrl:c,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),o&&(this.interpreter=Se(this.machine,{devTools:f}),this.interpreter.start()),typeof window!="undefined"&&i)try{this._channel=new BroadcastChannel("nhost"),this._channel.addEventListener("message",v=>{var d;const l=(d=this.interpreter)==null?void 0:d.state.context.refreshToken.value;this.interpreter&&v.data!==l&&this.interpreter.send("TRY_TOKEN",{token:v.data})})}catch{}}get interpreter(){return this._interpreter}set interpreter(e){this._interpreter=e,e&&this._subscriptions.forEach(r=>r(this))}onStart(e){this.interpreter?e(this):this._subscriptions.add(e)}}const $o=async({backendUrl:t,interpreter:e},r)=>{const n=Ie(t);try{const{data:i}=await n.post("/user/webauthn/add",{},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}});let s;try{s=await Tn(i)}catch(a){throw new _t(a)}const{data:o}=await n.post("/user/webauthn/verify",{credential:s,nickname:r},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}});return{key:o,isError:!1,error:null,isSuccess:!0}}catch(i){const{error:s}=i;return{isError:!0,error:s,isSuccess:!1}}},jo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,needsEmailVerification:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,needsEmailVerification:!0})})}),Lo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{password:e,ticket:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSuccess:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSuccess:!0})})}),Mo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSent:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSent:!0})})}),Bo=(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSent:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSent:!0})})}),Fo=t=>new Promise(e=>{const{changed:r}=t.send("SIGNIN_ANONYMOUS");r||e({isSuccess:!1,isError:!0,error:se,user:null,accessToken:null}),t.onTransition(n=>{n.matches({authentication:"signedIn"})&&e({isSuccess:!0,isError:!1,error:null,user:n.context.user,accessToken:n.context.accessToken.value}),n.matches({authentication:{signedOut:"failed"}})&&e({isSuccess:!1,isError:!0,error:n.context.errors.authentication||null,user:null,accessToken:null})})}),qo=(t,e,r)=>new Promise(n=>{const{changed:i,context:s}=t.send("SIGNIN_PASSWORD",{email:e,password:r});if(!i)return n({accessToken:s.accessToken.value,error:se,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:{signedOut:"needsMfa"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!0,mfa:o.context.mfa,user:null}):o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:o.context.user})})}),An=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_EMAIL",{email:e,options:r});if(!i)return n({error:se,isError:!0,isSuccess:!1});t.onTransition(s=>{s.matches("registration.incomplete.failed")?n({error:s.context.errors.registration||null,isError:!0,isSuccess:!1}):s.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})&&n({error:null,isError:!1,isSuccess:!0})})}),Vo=(t,e)=>new Promise(r=>{const{changed:n,context:i}=t.send({type:"SIGNIN_SECURITY_KEY_EMAIL",email:e});if(!n)return r({accessToken:i.accessToken.value,error:se,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:i.user});t.onTransition(s=>{s.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?r({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):s.matches({authentication:{signedOut:"failed"}})?r({accessToken:null,error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):s.matches({authentication:"signedIn"})&&r({accessToken:s.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:s.context.user})})}),Ko=(t,e,r)=>new Promise(n=>{const{changed:i,context:s}=t.send("SIGNIN_MFA_TOTP",{otp:e,ticket:r});if(!i)return n({accessToken:s.accessToken.value,error:se,isError:!0,isSuccess:!1,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,user:o.context.user})})}),Rn=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_SMS",{phoneNumber:e,options:r});if(!i)return n({error:se,isError:!0,isSuccess:!1,needsOtp:!1});t.onTransition(s=>{s.matches("registration.incomplete.needsOtp")?n({error:null,isError:!1,isSuccess:!1,needsOtp:!0}):s.matches("registration.incomplete.failed")&&n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,needsOtp:!1})})}),Ho=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send({type:"PASSWORDLESS_SMS_OTP",phoneNumber:e,otp:r});if(!i)return n({error:se,isError:!0,isSuccess:!1,user:null,accessToken:null});t.onTransition(s=>{s.matches({authentication:"signedIn"})?n({error:null,isError:!1,isSuccess:!0,user:s.context.user,accessToken:s.context.accessToken.value}):s.matches({registration:{incomplete:"failed"}})&&n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null,accessToken:null})})}),zo=async(t,e)=>new Promise(r=>{const{event:n}=t.send("SIGNOUT",{all:e});if(n.type!=="SIGNED_OUT")return r({isSuccess:!1,isError:!0,error:To});t.onTransition(i=>{i.matches({authentication:{signedOut:"success"}})?r({isSuccess:!0,isError:!1,error:null}):i.matches("authentication.signedOut.failed")&&r({isSuccess:!1,isError:!0,error:i.context.errors.signout||null})})}),kn=(t,e,r,n)=>new Promise(i=>{const{changed:s,context:o}=t.send("SIGNUP_EMAIL_PASSWORD",{email:e,password:r,options:n});if(!s)return i({error:se,accessToken:o.accessToken.value,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:o.user});t.onTransition(a=>{a.matches("registration.incomplete.failed")?i({accessToken:null,error:a.context.errors.registration||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):a.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?i({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):a.matches({authentication:"signedIn",registration:"complete"})&&i({accessToken:a.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:a.context.user})})}),Wo=(t,e,r)=>new Promise(n=>{const{changed:i,context:s}=t.send("SIGNUP_SECURITY_KEY",{email:e,options:r});if(!i)return n({error:se,accessToken:s.accessToken.value,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:s.user});t.onTransition(o=>{o.matches("registration.incomplete.failed")?n({accessToken:null,error:o.context.errors.registration||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):o.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):o.matches({authentication:"signedIn",registration:"complete"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:o.context.user})})});var Go=Object.defineProperty,Jo=Object.defineProperties,Yo=Object.getOwnPropertyDescriptors,Pn=Object.getOwnPropertySymbols,Qo=Object.prototype.hasOwnProperty,Xo=Object.prototype.propertyIsEnumerable,In=(t,e,r)=>e in t?Go(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,He=(t,e)=>{for(var r in e||(e={}))Qo.call(e,r)&&In(t,r,e[r]);if(Pn)for(var r of Pn(e))Xo.call(e,r)&&In(t,r,e[r]);return t},ze=(t,e)=>Jo(t,Yo(e));const Zo=()=>typeof window!="undefined",kt=t=>!t||!t.accessToken.value||!t.refreshToken.value||!t.accessToken.expiresAt||!t.user?null:{accessToken:t.accessToken.value,accessTokenExpiresIn:(t.accessToken.expiresAt.getTime()-Date.now())/1e3,refreshToken:t.refreshToken.value,user:t.user},ve=({accessToken:t,isError:e,user:r,error:n})=>e?{session:null,error:n}:r&&t?{session:{accessToken:t,accessTokenExpiresIn:0,refreshToken:"",user:r},error:null}:{session:null,error:null};class ea{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f,start:u=!0}){var v;this.url=e,this._client=new Uo({backendUrl:e,clientUrl:typeof window!="undefined"&&((v=window.location)==null?void 0:v.origin)||"",autoRefreshToken:r,autoSignIn:typeof i=="boolean"?i:n,start:u,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f})}async signUp(e){const r=await this.waitUntilReady(),{email:n,options:i}=e;return"securityKey"in e?ve(await Wo(r,n,i)):ve(await kn(r,n,e.password,i))}async signIn(e){const r=await this.waitUntilReady();if("provider"in e){const{provider:i,options:s}=e,o=xn(`${this._client.backendUrl}/signin/provider/${i}`,te(this._client.clientUrl,s));return Zo()&&(window.location.href=o),{providerUrl:o,provider:i,session:null,mfa:null,error:null}}if("email"in e&&"password"in e){const i=await qo(r,e.email,e.password);return i.needsEmailVerification?{session:null,mfa:null,error:bo}:i.needsMfaOtp?{session:null,mfa:i.mfa,error:null}:ze(He({},ve(i)),{mfa:null})}if("email"in e&&"securityKey"in e){if(e.securityKey!==!0)throw Error("securityKey must be true");const i=await Vo(r,e.email);return ze(He({},ve(i)),{mfa:null})}if("email"in e){const{email:i,options:s}=e,{error:o}=await An(r,i,s);return{session:null,mfa:null,error:o}}if("phoneNumber"in e&&"otp"in e){const i=await Ho(r,e.phoneNumber,e.otp);return ze(He({},ve(i)),{mfa:null})}if("phoneNumber"in e){const{error:i}=await Rn(r,e.phoneNumber,e.options);return{error:i,mfa:null,session:null}}if("otp"in e){const i=await Ko(r,e.otp,e.ticket);return ze(He({},ve(i)),{mfa:null})}const n=await Fo(r);return ze(He({},ve(n)),{mfa:null})}async signOut(e){const r=await this.waitUntilReady(),{error:n}=await zo(r,e==null?void 0:e.all);return{error:n}}async resetPassword({email:e,options:r}){const n=Se(No(this._client)).start(),{error:i}=await Mo(n,e,r);return{error:i}}async changePassword({newPassword:e,ticket:r}){const n=Se(Io(this._client)).start(),{error:i}=await Lo(n,e,r);return{error:i}}async sendVerificationEmail({email:e,options:r}){const n=Se(Co(this._client)).start(),{error:i}=await Bo(n,e,r);return{error:i}}async changeEmail({newEmail:e,options:r}){const n=Se(Po(this._client)).start(),{error:i}=await jo(n,e,r);return{error:i}}async deanonymize(e){const r=await this.waitUntilReady();if(e.signInMethod==="passwordless"){if(e.connection==="email"){const{error:n}=await An(r,e.email,e.options);return{error:n}}if(e.connection==="sms"){const{error:n}=await Rn(r,e.phoneNumber,e.options);return{error:n}}}if(e.signInMethod==="email-password"){const{error:n}=await kn(r,e.email,e.password,e.options);return{error:n}}throw Error("Unknown deanonymization method")}async addSecurityKey(e){const{error:r,key:n}=await $o(this._client,e);return{error:r,key:n}}onTokenChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{i.type==="TOKEN_CHANGED"&&e(kt(s))});if(this._client.interpreter){const n=r(this._client.interpreter);return()=>n.stop()}else return this._client.onStart(n=>{r(n.interpreter)}),()=>{console.log("onTokenChanged was added before the interpreter started. Cannot unsubscribe listener.")}}onAuthStateChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{(i.type==="SIGNED_IN"||i.type==="SIGNED_OUT")&&e(i.type,kt(s))});if(this._client.interpreter){const n=r(this._client.interpreter);return()=>n.stop()}else return this._client.onStart(n=>{r(n.interpreter)}),()=>{console.log("onAuthStateChanged was added before the interpreter started. Cannot unsubscribe listener.")}}isAuthenticated(){var e;return!!((e=this._client.interpreter)!=null&&e.state.matches({authentication:"signedIn"}))}async isAuthenticatedAsync(){return(await this.waitUntilReady()).state.matches({authentication:"signedIn"})}getAuthenticationStatus(){return this.isReady()?{isAuthenticated:this.isAuthenticated(),isLoading:!1}:{isAuthenticated:!1,isLoading:!0}}getJWTToken(){return this.getAccessToken()}getAccessToken(){var e,r;return(r=(e=this._client.interpreter)==null?void 0:e.state.context.accessToken.value)!=null?r:void 0}getDecodedAccessToken(){const e=this.getAccessToken();return e?Vn(e):null}getHasuraClaims(){var e;return((e=this.getDecodedAccessToken())==null?void 0:e["https://hasura.io/jwt/claims"])||null}getHasuraClaim(e){var r;return((r=this.getHasuraClaims())==null?void 0:r[e.startsWith("x-hasura-")?e:`x-hasura-${e}`])||null}async refreshSession(e){try{const r=await this.waitUntilReady();return new Promise(n=>{const i=e||r.state.context.refreshToken.value;if(!i)return n({session:null,error:wo});const{changed:s}=r.send("TRY_TOKEN",{token:i});if(!s)return n({session:null,error:So});r.onTransition(o=>{o.matches({token:{idle:"error"}})?n({session:null,error:xo}):o.event.type==="TOKEN_CHANGED"&&n({session:kt(o.context),error:null})})})}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return kt((r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)}getUser(){var e,r,n;return((n=(r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)==null?void 0:n.user)||null}waitUntilReady(){const r=this._client.interpreter;if(!r)throw Error("Auth interpreter not set");return r.state.hasTag("loading")?new Promise((n,i)=>{let s=setTimeout(()=>i(`The state machine is not yet ready after ${15} seconds.`),15e3);r.onTransition(o=>{if(!o.hasTag("loading"))return clearTimeout(s),n(r)})}):Promise.resolve(r)}isReady(){var e,r;return!((r=(e=this._client.interpreter)==null?void 0:e.state)!=null&&r.hasTag("loading"))}get client(){return this._client}}var ta=typeof self=="object"?self.FormData:window.FormData,ra=Object.defineProperty,na=Object.defineProperties,ia=Object.getOwnPropertyDescriptors,Nn=Object.getOwnPropertySymbols,sa=Object.prototype.hasOwnProperty,oa=Object.prototype.propertyIsEnumerable,Cn=(t,e,r)=>e in t?ra(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,We=(t,e)=>{for(var r in e||(e={}))sa.call(e,r)&&Cn(t,r,e[r]);if(Nn)for(var r of Nn(e))oa.call(e,r)&&Cn(t,r,e[r]);return t},Dn=(t,e)=>na(t,ia(e));class aa{constructor({url:e}){this.url=e,this.httpClient=gt.create({baseURL:this.url})}async upload(e){const{formData:r}=e;try{return{fileMetadata:(await this.httpClient.post("/files",r,{headers:Dn(We(We({},this.generateUploadHeaders(e)),this.generateAuthHeaders()),{"Content-Type":"multipart/form-data"})})).data,error:null}}catch(n){return{fileMetadata:null,error:n}}}async getPresignedUrl(e){try{const{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:We({},this.generateAuthHeaders())})).data,error:null}}catch(r){return{presignedUrl:null,error:r}}}async delete(e){try{const{fileId:r}=e;return await this.httpClient.delete(`/files/${r}`,{headers:We({},this.generateAuthHeaders())}),{error:null}}catch(r){return{error:r}}}setAccessToken(e){return this.accessToken=e,this}setAdminSecret(e){return this.adminSecret=e,this}generateUploadHeaders(e){const{bucketId:r,name:n,id:i}=e,s={};return r&&(s["x-nhost-bucket-id"]=r),i&&(s["x-nhost-file-id"]=i),n&&(s["x-nhost-file-name"]=n),s}generateAuthHeaders(){return!this.adminSecret&&!this.accessToken?null:this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:{Authorization:`Bearer ${this.accessToken}`}}}class ua{constructor({url:e,adminSecret:r}){this.url=e,this.api=new aa({url:e}),this.setAdminSecret(r)}async upload(e){let r;"file"in e?(r=new ta,r.append("file",e.file)):r=e.formData;const{fileMetadata:n,error:i}=await this.api.upload(Dn(We({},e),{formData:r}));return i?{fileMetadata:null,error:i}:n?{fileMetadata:n,error:null}:{fileMetadata:null,error:new Error("Invalid file returned")}}getUrl(e){return this.getPublicUrl(e)}getPublicUrl(e){const{fileId:r}=e;return`${this.url}/files/${r}`}async getPresignedUrl(e){const{presignedUrl:r,error:n}=await this.api.getPresignedUrl(e);return n?{presignedUrl:null,error:n}:r?{presignedUrl:r,error:null}:{presignedUrl:null,error:new Error("Invalid file id")}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}class Un{constructor(e){const{url:r,adminSecret:n}=e;this.accessToken=null,this.adminSecret=n,this.instance=gt.create({baseURL:r})}async call(e,r,n){const i=ye(ye({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,mr(ye({},n),{headers:i}))}catch(o){if(o instanceof Error)return{res:null,error:o}}return s?{res:s,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}class $n{constructor(e){const{url:r,adminSecret:n}=e;this.url=r,this.accessToken=null,this.adminSecret=n,this.instance=gt.create({baseURL:r})}async request(e,r,n){const i=ye(ye({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);try{const s="",a=(await this.instance.post("",{operationName:s||void 0,query:typeof e=="string"?e:U.print(e),variables:r},mr(ye({},n),{headers:i}))).data,{data:c}=a;return a.errors?{data:null,error:a.errors}:typeof c!="object"||Array.isArray(c)||c===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:c,error:null}}catch(s){return s instanceof Error?{data:null,error:s}:(console.error(s),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}const ca=/^localhost(:\d+)*$/g;function Pt(t,e){const{backendUrl:r,subdomain:n,region:i}=t;if(!r&&!n)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(r)return`${r}/v1/${e}`;if(!n)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const s=n.match(ca);if(s&&s.length>0){const o=s[0];return o==="localhost"?`http://localhost:1337/v1/${e}`:`http://${o}/v1/${e}`}if(!i)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${n}.${e}.${i}.nhost.run/v1`}class jn{constructor(d){var l=d,{refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,adminSecret:c,devTools:f,start:u=!0}=l,v=Fn(l,["refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","adminSecret","devTools","start"]);var h;this.auth=new ea({url:Pt(v,"auth"),refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,start:u}),this.storage=new ua({url:Pt(v,"storage"),adminSecret:c}),this.functions=new Un({url:Pt(v,"functions"),adminSecret:c}),this.graphql=new $n({url:Pt(v,"graphql"),adminSecret:c}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(h=this.auth.client)==null||h.onStart(()=>{this.auth.onAuthStateChanged((p,y)=>{p==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(p=>{this.storage.setAccessToken(p==null?void 0:p.accessToken),this.functions.setAccessToken(p==null?void 0:p.accessToken),this.graphql.setAccessToken(p==null?void 0:p.accessToken)})}),this._adminSecret=c,this.devTools=f}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const la=t=>new jn(t);R.NhostClient=jn,R.NhostFunctionsClient=Un,R.NhostGraphqlClient=$n,R.createClient=la,Object.defineProperties(R,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
19
19
  //# sourceMappingURL=nhost-js.umd.js.map