@nhost/nhost-js 1.2.2 → 1.3.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.
- package/package.json +12 -12
- package/umd/nhost-js.umd.js +6 -6
- package/umd/nhost-js.umd.js.map +1 -1
- package/dist/index.esm.mjs +0 -203
- package/dist/index.esm.mjs.map +0 -1
package/umd/nhost-js.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(D,j){typeof exports=="object"&&typeof module!="undefined"?j(exports,require("graphql")):typeof define=="function"&&define.amd?define(["exports","graphql"],j):(D=typeof globalThis!="undefined"?globalThis:D||self,j(D["@nhost/nhost-js"]={},D.graphql))})(this,function(D,j){"use strict";var
|
|
1
|
+
(function(D,j){typeof exports=="object"&&typeof module!="undefined"?j(exports,require("graphql")):typeof define=="function"&&define.amd?define(["exports","graphql"],j):(D=typeof globalThis!="undefined"?globalThis:D||self,j(D["@nhost/nhost-js"]={},D.graphql))})(this,function(D,j){"use strict";var Ma=Object.defineProperty,Ba=Object.defineProperties;var qa=Object.getOwnPropertyDescriptors;var Rn=Object.getOwnPropertySymbols;var Fa=Object.prototype.hasOwnProperty,Va=Object.prototype.propertyIsEnumerable;var An=(D,j,V)=>j in D?Ma(D,j,{enumerable:!0,configurable:!0,writable:!0,value:V}):D[j]=V,ue=(D,j)=>{for(var V in j||(j={}))Fa.call(j,V)&&An(D,V,j[V]);if(Rn)for(var V of Rn(j))Va.call(j,V)&&An(D,V,j[V]);return D},cr=(D,j)=>Ba(D,qa(j));function V(t){this.message=t}V.prototype=new Error,V.prototype.name="InvalidCharacterError";var lr=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new V("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,i=0,s=0,a="";n=e.charAt(s++);~n&&(r=i%4?64*r+n:n,i++%4)?a+=String.fromCharCode(255&r>>(-2*i&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return a};function Pn(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(lr(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 lr(e)}}function Fe(t){this.message=t}function kn(t,e){if(typeof t!="string")throw new Fe("Invalid token specified");var r=(e=e||{}).header===!0?0:1;try{return JSON.parse(Pn(t.split(".")[r]))}catch(n){throw new Fe("Invalid token specified: "+n.message)}}Fe.prototype=new Error,Fe.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 Tt(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 b(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=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return s}function C(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 R;(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"})(R||(R={}));var xe;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(xe||(xe={}));var Ot=R.Start,bt=R.Stop,Ge=R.Raise,ze=R.Send,cr=R.Cancel,In=R.NullEvent,_t=R.Assign;R.After,R.DoneState;var lr=R.Log,Pn=R.Init,xt=R.Invoke;R.ErrorExecution;var fr=R.ErrorPlatform,Nn=R.ErrorCustom,dr=R.Update,kn=R.Choose,Cn=R.Pure,hr=".",vr={},At="xstate.guard",Dn="",Ae=!0,We;function Rt(t,e,r){r===void 0&&(r=hr);var n=Re(t,r),i=Re(e,r);return x(i)?x(n)?i===n:!1:x(n)?n in i:Object.keys(n).every(function(s){return s in i?Rt(n[s],i[s]):!1})}function pr(t){try{return x(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 It(t,e){try{return ce(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function Un(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function Re(t,e){if(Un(t))return t.value;if(ce(t))return Je(t);if(typeof t!="string")return t;var r=It(t,e);return Je(r)}function Je(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 Ie(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 yr(t,e,r){var n,i,s={};try{for(var a=b(Object.keys(t)),o=a.next();!o.done;o=a.next()){var u=o.value,f=t[u];!r(f)||(s[u]=e(f,u,t))}}catch(c){n={error:c}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}var jn=function(t){return function(e){var r,n,i=e;try{for(var s=b(t),a=s.next();!a.done;a=s.next()){var o=a.value;i=i[o]}}catch(u){r={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function $n(t,e){return function(r){var n,i,s=r;try{for(var a=b(t),o=a.next();!o.done;o=a.next()){var u=o.value;s=s[e][u]}}catch(f){n={error:f}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}}function Ye(t){if(!t)return[[]];if(x(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]]:Ye(t[r]).map(function(i){return[r].concat(i)})}));return e}function N(t){var e;return(e=[]).concat.apply(e,C([],A(t),!1))}function mr(t){return ce(t)?t:[t]}function Y(t){return t===void 0?[]:mr(t)}function Ke(t,e,r){var n,i;if(I(t))return t(e,r.data);var s={};try{for(var a=b(Object.keys(t)),o=a.next();!o.done;o=a.next()){var u=o.value,f=t[u];I(f)?s[u]=f(e,r.data):s[u]=f}}catch(c){n={error:c}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}function Ln(t){return/^(done|error)\./.test(t)}function gr(t){return!!(t instanceof Promise||t!==null&&(I(t)||typeof t=="object")&&I(t.then))}function Mn(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function Er(t,e){var r,n,i=A([[],[]],2),s=i[0],a=i[1];try{for(var o=b(t),u=o.next();!u.done;u=o.next()){var f=u.value;e(f)?s.push(f):a.push(f)}}catch(c){r={error:c}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return[s,a]}function wr(t,e){return Ie(t.states,function(r,n){if(!!r){var i=(x(e)?void 0:e[n])||(r?r.current:void 0);if(!!i)return{current:i,states:wr(r,i)}}})}function Bn(t,e){return{current:e,states:wr(t,e)}}function Sr(t,e,r,n){var i=t&&r.reduce(function(s,a){var o,u,f=a.assignment,c={state:n,action:a,_event:e},v={};if(I(f))v=f(s,e.data,c);else try{for(var d=b(Object.keys(f)),l=d.next();!l.done;l=d.next()){var h=l.value,p=f[h];v[h]=I(p)?p(s,e.data,c):p}}catch(y){o={error:y}}finally{try{l&&!l.done&&(u=d.return)&&u.call(d)}finally{if(o)throw o.error}}return Object.assign({},s,v)},t);return i}var Pe=function(){};function ce(t){return Array.isArray(t)}function I(t){return typeof t=="function"}function x(t){return typeof t=="string"}function Tr(t,e){if(!!t)return x(t)?{type:At,name:t,predicate:e?e[t]:void 0}:I(t)?{type:At,name:t.name,predicate:t}:t}function Fn(t){try{return"subscribe"in t&&I(t.subscribe)}catch{return!1}}var te=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();We={},We[te]=function(){return this},We[Symbol.observable]=function(){return this};function ie(t){return!!t&&"__xstatenode"in t}function qn(t){return!!t&&typeof t.send=="function"}function Pt(t,e){return x(t)||typeof t=="number"?m({type:t},e):t}function F(t,e){if(!x(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=Pt(t);return m({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function le(t,e){var r=mr(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||ie(n)?{target:n,event:t}:m(m({},n),{event:t})});return r}function Vn(t){if(!(t===void 0||t===Dn))return Y(t)}function Or(t,e,r,n,i){var s=t.options.guards,a={state:i,cond:e,_event:n};if(e.type===At)return((s==null?void 0:s[e.name])||e.predicate)(r,n.data,a);var o=s==null?void 0:s[e.type];if(!o)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return o(r,n.data,a)}function br(t){return typeof t=="string"?{type:t}:t}function Nt(t,e,r){if(typeof t=="object")return t;var n=function(){};return{next:t,error:e||n,complete:r||n}}function Qe(t,e){return"".concat(t,":invocation[").concat(e,"]")}var Xe=F({type:Pn});function kt(t,e){return e&&e[t]||void 0}function Ne(t,e){var r;if(x(t)||typeof t=="number"){var n=kt(t,e);I(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(I(t))r={type:t.name||t.toString(),exec:t};else{var n=kt(t.type,e);if(I(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 Ze=function(t,e){if(!t)return[];var r=ce(t)?t:[t];return r.map(function(n){return Ne(n,e)})};function Ct(t){var e=Ne(t);return m(m({id:x(t)?t:e.id},e),{type:e.type})}function Hn(t){return x(t)?{type:Ge,event:t}:Dt(t,{to:xe.Internal})}function Gn(t){return{type:Ge,_event:F(t.event)}}function Dt(t,e){return{to:e?e.to:void 0,type:ze,event:I(t)?t:Pt(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:I(t)?t.name:pr(t)}}function zn(t,e,r,n){var i={_event:r},s=F(I(t.event)?t.event(e,r.data,i):t.event),a;if(x(t.delay)){var o=n&&n[t.delay];a=I(o)?o(e,r.data,i):o}else a=I(t.delay)?t.delay(e,r.data,i):t.delay;var u=I(t.to)?t.to(e,r.data,i):t.to;return m(m({},t),{to:u,_event:s,event:s.data,delay:a})}var Wn=function(t,e,r){return m(m({},t),{value:x(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},Jn=function(t){return{type:cr,sendId:t}};function Yn(t){var e=Ct(t);return{type:R.Start,activity:e,exec:void 0}}function Kn(t){var e=I(t)?t:Ct(t);return{type:R.Stop,activity:e,exec:void 0}}function Qn(t,e,r){var n=I(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:R.Stop,activity:i};return s}var Xn=function(t){return{type:_t,assignment:t}};function Zn(t,e){var r=e?"#".concat(e):"";return"".concat(R.After,"(").concat(t,")").concat(r)}function et(t,e){var r="".concat(R.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function tt(t,e){var r="".concat(R.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function ke(t,e){var r="".concat(R.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ut(t,e,r,n,i,s){s===void 0&&(s=!1);var a=A(s?[[],i]:Er(i,function(d){return d.type===_t}),2),o=a[0],u=a[1],f=o.length?Sr(r,n,o,e):r,c=s?[r]:void 0,v=N(u.map(function(d){var l;switch(d.type){case Ge:return Gn(d);case ze:var h=zn(d,f,n,t.options.delays);return h;case lr:return Wn(d,f,n);case kn:{var p=d,y=(l=p.conds.find(function(k){var B=Tr(k.cond,t.options.guards);return!B||Or(t,B,f,n,e)}))===null||l===void 0?void 0:l.actions;if(!y)return[];var w=A(Ut(t,e,f,n,Ze(Y(y),t.options.actions),s),2),g=w[0],S=w[1];return f=S,c==null||c.push(f),g}case Cn:{var y=d.get(f,n.data);if(!y)return[];var P=A(Ut(t,e,f,n,Ze(Y(y),t.options.actions),s),2),_=P[0],U=P[1];return f=U,c==null||c.push(f),_}case bt:return Qn(d,f,n);case _t:{f=Sr(f,n,[d],e),c==null||c.push(f);break}default:var T=Ne(d,t.options.actions),E=T.exec;if(E&&c){var O=c.length-1;T=m(m({},T),{exec:function(k){for(var B=[],z=1;z<arguments.length;z++)B[z-1]=arguments[z];E.apply(void 0,C([c[O]],A(B),!1))}})}return T}}).filter(function(d){return!!d}));return[v,f]}var Ce=function(t,e){var r=e(t);return r};function _r(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[te]=function(){return this},e}function ei(t,e,r,n){var i,s=br(t.src),a=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],o=t.data?Ke(t.data,r,n):void 0,u=a?ti(a,t.id,o):_r(t.id);return u.meta=t,u}function ti(t,e,r){var n=_r(e);if(n.deferred=!0,ie(t)){var i=n.state=Ce(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function ri(t){try{return typeof t.send=="function"}catch{return!1}}function ni(t){return ri(t)&&"id"in t}function ii(t){var e;return m((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[te]=function(){return this},e),t)}var rt=function(t){return t.type==="atomic"||t.type==="final"};function fe(t){return Object.keys(t.states).map(function(e){return t.states[e]}).filter(function(e){return e.type!=="history"})}function xr(t){var e=[t];return rt(t)?e:e.concat(N(fe(t).map(xr)))}function de(t,e){var r,n,i,s,a,o,u,f,c=new Set(t),v=jt(c),d=new Set(e);try{for(var l=b(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(O){r={error:O}}finally{try{h&&!h.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}var w=jt(d);try{for(var g=b(d),S=g.next();!S.done;S=g.next()){var p=S.value;if(p.type==="compound"&&(!w.get(p)||!w.get(p).length))v.get(p)?v.get(p).forEach(function(k){return d.add(k)}):p.initialStateNodes.forEach(function(k){return d.add(k)});else if(p.type==="parallel")try{for(var P=(a=void 0,b(fe(p))),_=P.next();!_.done;_=P.next()){var U=_.value;d.has(U)||(d.add(U),v.get(U)?v.get(U).forEach(function(k){return d.add(k)}):U.initialStateNodes.forEach(function(k){return d.add(k)}))}}catch(k){a={error:k}}finally{try{_&&!_.done&&(o=P.return)&&o.call(P)}finally{if(a)throw a.error}}}}catch(O){i={error:O}}finally{try{S&&!S.done&&(s=g.return)&&s.call(g)}finally{if(i)throw i.error}}try{for(var T=b(d),E=T.next();!E.done;E=T.next())for(var p=E.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(O){u={error:O}}finally{try{E&&!E.done&&(f=T.return)&&f.call(T)}finally{if(u)throw u.error}}return d}function Ar(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(rt(n))return n.key}else return{}}var i={};return r.forEach(function(s){i[s.key]=Ar(s,e)}),i}function jt(t){var e,r,n=new Map;try{for(var i=b(t),s=i.next();!s.done;s=i.next()){var a=s.value;n.has(a)||n.set(a,[]),a.parent&&(n.has(a.parent)||n.set(a.parent,[]),n.get(a.parent).push(a))}}catch(o){e={error:o}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n}function si(t,e){var r=de([t],e);return Ar(t,jt(r))}function nt(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function ai(t){return C([],A(new Set(N(C([],A(t.map(function(e){return e.ownEvents})),!1)))),!1)}function De(t,e){return e.type==="compound"?fe(e).some(function(r){return r.type==="final"&&nt(t,r)}):e.type==="parallel"?fe(e).every(function(r){return De(t,r)}):!1}function oi(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function Rr(t){return new Set(N(t.map(function(e){return e.tags})))}function Ir(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(x(t)||x(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(i){return Ir(t[i],e[i])})}function ui(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function ci(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 X=function(){function t(e){var r=this,n;this.actions=[],this.activities=vr,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||vr,this.meta=oi(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 ai(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=Xe;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=Xe;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="."),x(e))return[e];var i=Object.keys(e);return i.concat.apply(i,C([],A(i.map(function(s){return n.toStrings(e[s],r).map(function(a){return s+r+a})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=Tt(e,["configuration","transitions","tags","machine"]);return m(m({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Rt(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;Pe(!!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}(),li={deferEvents:!1},Pr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=m(m({},li),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}(),$t=new Map,fi=0,it={bookId:function(){return"x:".concat(fi++)},register:function(t,e){return $t.set(t,e),t},get:function(t){return $t.get(t)},free:function(t){$t.delete(t)}};function Lt(){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 di(){var t=Lt();if(t&&"__xstate__"in t)return t.__xstate__}function hi(t){if(!!Lt()){var e=di();e&&e.register(t)}}function vi(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,a=function(){if(!s){for(s=!0;i.length>0;){var f=i.shift();r=t.transition(r,f,u),n.forEach(function(c){return c.next(r)})}s=!1}},o=ii({id:e.id,send:function(f){i.push(f),a()},getSnapshot:function(){return r},subscribe:function(f,c,v){var d=Nt(f,c,v);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),u={parent:e.parent,self:o,id:e.id||"anonymous",observers:n};return r=t.start?t.start(u):r,o}var pi={sync:!1,autoForward:!1},q;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(q||(q={}));var yi=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=q.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(c,v){if(ce(c))return n.batch(c),n.state;var d=F(Pt(c,v));if(n.status===q.Stopped)return n.state;if(n.status!==q.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(c,v){var d=n.parent&&(v===xe.Parent||n.parent.id===v),l=d?n.parent:x(v)?n.children.get(v)||it.get(v):qn(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({},c),{name:c.name===Nn?"".concat(ke(n.id)):c.name,origin:n.sessionId})):l.send(c.data)};var i=m(m({},t.defaultOptions),r),s=i.clock,a=i.logger,o=i.parent,u=i.id,f=u!==void 0?u:e.id;this.id=f,this.logger=a,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Pr({deferEvents:this.options.deferEvents}),this.sessionId=it.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Ce(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=b(e.actions),a=s.next();!a.done;a=s.next()){var o=a.value;this.exec(o,e,r)}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,a,o,u,f,c,v=this;if(e._sessionid=this.sessionId,this._state=e,this.options.execute&&this.execute(this.state),this.children.forEach(function(O){v.state.children[O.id]=O}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var d=b(this.eventListeners),l=d.next();!l.done;l=d.next()){var h=l.value;h(e.event)}}catch(O){n={error:O}}finally{try{l&&!l.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var p=b(this.listeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(e,e.event)}}catch(O){s={error:O}}finally{try{y&&!y.done&&(a=p.return)&&a.call(p)}finally{if(s)throw s.error}}try{for(var w=b(this.contextListeners),g=w.next();!g.done;g=w.next()){var S=g.value;S(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(O){o={error:O}}finally{try{g&&!g.done&&(u=w.return)&&u.call(w)}finally{if(o)throw o.error}}var P=De(e.configuration||[],this.machine);if(this.state.configuration&&P){var _=e.configuration.find(function(O){return O.type==="final"&&O.parent===v.machine}),U=_&&_.doneData?Ke(_.doneData,e.context,r):void 0;try{for(var T=b(this.doneListeners),E=T.next();!E.done;E=T.next()){var h=E.value;h(tt(this.id,U))}}catch(O){f={error:O}}finally{try{E&&!E.done&&(c=T.return)&&c.call(T)}finally{if(f)throw f.error}}this.stop()}},t.prototype.onTransition=function(e){return this.listeners.add(e),this.status===q.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,a=n;return typeof e=="function"?s=e:(s=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(s),this.status!==q.NotStarted&&s(this.state),a&&(this.status===q.Stopped?a():this.onDone(a)),{unsubscribe:function(){s&&i.listeners.delete(s),a&&i.doneListeners.delete(a)}}},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===q.Running)return this;this.machine._init(),it.register(this.sessionId,this),this.initialized=!0,this.status=q.Running;var n=e===void 0?this.initialState:Ce(this,function(){return ui(e)?r.machine.resolveState(e):r.machine.resolveState(X.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,Xe)}),this},t.prototype.stop=function(){var e,r,n,i,s,a,o,u,f,c,v=this;try{for(var d=b(this.listeners),l=d.next();!l.done;l=d.next()){var h=l.value;this.listeners.delete(h)}}catch(E){e={error:E}}finally{try{l&&!l.done&&(r=d.return)&&r.call(d)}finally{if(e)throw e.error}}try{for(var p=b(this.stopListeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(),this.stopListeners.delete(h)}}catch(E){n={error:E}}finally{try{y&&!y.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}try{for(var w=b(this.contextListeners),g=w.next();!g.done;g=w.next()){var h=g.value;this.contextListeners.delete(h)}}catch(E){s={error:E}}finally{try{g&&!g.done&&(a=w.return)&&a.call(w)}finally{if(s)throw s.error}}try{for(var S=b(this.doneListeners),P=S.next();!P.done;P=S.next()){var h=P.value;this.doneListeners.delete(h)}}catch(E){o={error:E}}finally{try{P&&!P.done&&(u=S.return)&&u.call(S)}finally{if(o)throw o.error}}if(!this.initialized)return this;C([],A(this.state.configuration),!1).sort(function(E,O){return O.order-E.order}).forEach(function(E){var O,k;try{for(var B=b(E.definition.exit),z=B.next();!z.done;z=B.next()){var ne=z.value;v.exec(ne,v.state)}}catch(St){O={error:St}}finally{try{z&&!z.done&&(k=B.return)&&k.call(B)}finally{if(O)throw O.error}}}),this.children.forEach(function(E){I(E.stop)&&E.stop()}),this.children.clear();try{for(var _=b(Object.keys(this.delayedEventsMap)),U=_.next();!U.done;U=_.next()){var T=U.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(E){f={error:E}}finally{try{U&&!U.done&&(c=_.return)&&c.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.scheduler=new Pr({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=q.Stopped,this._initialState=void 0,it.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(!(this.status===q.NotStarted&&this.options.deferEvents)){if(this.status!==q.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,a=!1,o=[],u=function(d){var l=F(d);r.forward(l),s=Ce(r,function(){return r.machine.transition(s,l)}),o.push.apply(o,C([],A(s.actions.map(function(h){return ci(h,s)})),!1)),a=a||!!s.changed};try{for(var f=b(e),c=f.next();!c.done;c=f.next()){var v=c.value;u(v)}}catch(d){n={error:d}}finally{try{c&&!c.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}s.changed=a,s.actions=o,r.update(s,F(e[e.length-1]))})},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype.nextState=function(e){var r=this,n=F(e);if(n.name.indexOf(fr)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(fr)===0}))throw n.data.data;var i=Ce(this,function(){return r.machine.transition(r.state,n)});return i},t.prototype.forward=function(e){var r,n;try{for(var i=b(this.forwardTo),s=i.next();!s.done;s=i.next()){var a=s.value,o=this.children.get(a);if(!o)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));o.send(e)}}catch(u){r={error:u}}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,a=e.exec||kt(e.type,n),o=I(a)?a:a?a.exec:e.exec;if(o)try{return o(i,s.data,{action:e,state:this.state,_event:s})}catch(P){throw this.parent&&this.parent.send({type:"xstate.error",data:P}),P}switch(e.type){case ze:var u=e;if(typeof u.delay=="number"){this.defer(u);return}else u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case cr:this.cancel(e.sendId);break;case Ot:{if(this.status!==q.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===R.Invoke){var c=br(f.src),v=this.machine.options.services?this.machine.options.services[c.type]:void 0,d=f.id,l=f.data,h="autoForward"in f?f.autoForward:!!f.forward;if(!v)return;var p=l?Ke(l,i,s):void 0;if(typeof v=="string")return;var y=I(v)?v(i,s.data,{data:p,src:c,meta:f.meta}):v;if(!y)return;var w=void 0;ie(y)&&(y=p?y.withContext(p):y,w={autoForward:h}),this.spawn(y,d,w)}else this.spawnActivity(f);break}case bt:{this.stopChild(e.activity.id);break}case lr: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),I(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(gr(e))return this.spawnPromise(Promise.resolve(e),r);if(I(e))return this.spawnCallback(e,r);if(ni(e))return this.spawnActor(e,r);if(Fn(e))return this.spawnObservable(e,r);if(ie(e))return this.spawnMachine(e,m(m({},n),{id:r}));if(Mn(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(o){n.send(dr,{state:o,id:i.id})});var a=i;return this.children.set(i.id,a),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(o){n.removeChild(i.id),n.send(F(o,{origin:i.id}))}).start(),a},t.prototype.spawnBehavior=function(e,r){var n=vi(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,a;e.then(function(u){s||(a=u,i.removeChild(r),i.send(F(tt(r,u),{origin:r})))},function(u){if(!s){i.removeChild(r);var f=ke(r,u);try{i.send(F(f,{origin:r}))}catch{i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var o=(n={id:r,send:function(){},subscribe:function(u,f,c){var v=Nt(u,f,c),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 a}},n[te]=function(){return this},n);return this.children.set(r,o),o},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,a=new Set,o=new Set,u,f=function(d){u=d,o.forEach(function(l){return l(d)}),!s&&i.send(F(d,{origin:r}))},c;try{c=e(f,function(d){a.add(d)})}catch(d){this.send(ke(r,d))}if(gr(c))return this.spawnPromise(c,r);var v=(n={id:r,send:function(d){return a.forEach(function(l){return l(d)})},subscribe:function(d){var l=Nt(d);return o.add(l.next),{unsubscribe:function(){o.delete(l.next)}}},stop:function(){s=!0,I(c)&&c()},toJSON:function(){return{id:r}},getSnapshot:function(){return u}},n[te]=function(){return this},n);return this.children.set(r,v),v},t.prototype.spawnObservable=function(e,r){var n,i=this,s,a=e.subscribe(function(u){s=u,i.send(F(u,{origin:r}))},function(u){i.removeChild(r),i.send(F(ke(r,u),{origin:r}))},function(){i.removeChild(r),i.send(F(tt(r),{origin:r}))}),o=(n={id:r,send:function(){},subscribe:function(u,f,c){return e.subscribe(u,f,c)},stop:function(){return a.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[te]=function(){return this},n);return this.children.set(r,o),o},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[te]=function(){return this},n))},t.prototype.attachDev=function(){var e=Lt();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)}hi(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[te]=function(){return this},t.prototype.getSnapshot=function(){return this.status===q.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=he,t}();function he(t,e){var r=new yi(t,e);return r}function mi(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function st(t){return m(m({type:xt},t),{toJSON:function(){t.onDone,t.onError;var e=Tt(t,["onDone","onError"]);return m(m({},e),{type:xt,src:mi(t.src)})}})}var ve="",Mt="#",Ue="*",pe={},ye=function(t){return t[0]===Mt},gi=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Ei=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(x(s.target)||ie(s.target))}),i=e===ve?"the transient event":"event '".concat(e,"'");Pe(!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.")},wi=function(){function t(e,r,n,i){var s=this;n===void 0&&(n="context"in e?e.context:void 0);var a;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(gi(),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:hr),this.id=this.config.id||C([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:(a=this.config.schema)!==null&&a!==void 0?a:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?Ie(this.config.states,function(f,c){var v,d=new t(f,{},void 0,{parent:s,key:c});return Object.assign(s.idMap,m((v={},v[d.id]=d,v),d.idMap)),d}):pe;var o=0;function u(f){var c,v;f.order=o++;try{for(var d=b(fe(f)),l=d.next();!l.done;l=d.next()){var h=l.value;u(h)}}catch(p){c={error:p}}finally{try{l&&!l.done&&(v=d.return)&&v.call(d)}finally{if(c)throw c.error}}}u(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 c=f.event;return c===ve}):ve in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=Y(this.config.entry||this.config.onEntry).map(function(f){return Ne(f)}),this.onExit=Y(this.config.exit||this.config.onExit).map(function(f){return Ne(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=Y(this.config.invoke).map(function(f,c){var v,d;if(ie(f)){var l=Qe(s.id,c);return s.machine.options.services=m((v={},v[l]=f,v),s.machine.options.services),st({src:l,id:l})}else if(x(f.src)){var l=f.id||Qe(s.id,c);return st(m(m({},f),{id:l,src:f.src}))}else if(ie(f.src)||I(f.src)){var l=f.id||Qe(s.id,c);return s.machine.options.services=m((d={},d[l]=f.src,d),s.machine.options.services),st(m(m({id:l},f),{src:l}))}else{var h=f.src;return st(m(m({id:Qe(s.id,c)},f),{src:h}))}}),this.activities=Y(this.config.activities).concat(this.invoke).map(function(f){return Ct(f)}),this.transition=this.transition.bind(this),this.tags=Y(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||xr(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,a=n.guards,o=n.services,u=n.delays;return new t(this.config,{actions:m(m({},i),e.actions),activities:m(m({},s),e.activities),guards:m(m({},a),e.guards),services:m(m({},o),e.services),delays:m(m({},u),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 I(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:Ie(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===ve,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===Ue});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,a){var o=I(s)?"".concat(e.id,":delay[").concat(a,"]"):s,u=Zn(o,e.id);return e.onEntry.push(Dt(u,{delay:s})),e.onExit.push(Jn(u)),u},i=ce(r)?r.map(function(s,a){var o=n(s.delay,a);return m(m({},s),{event:o})}):N(Object.keys(r).map(function(s,a){var o=r[s],u=x(o)?{target:o}:o,f=isNaN(+s)?s:+s,c=n(f,a);return Y(u).map(function(v){return m(m({},v),{event:c,delay:f})})}));return i.map(function(s){var a=s.delay;return m(m({},e.formatTransition(s)),{delay:a})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof X?e.value:Re(e,this.delimiter);if(x(i)){var s=this.getStateNode(i).initial;return s!==void 0?this.getStateNodes((r={},r[i]=s,r)):[this,this.states[i]]}var a=Object.keys(i),o=[this];return o.push.apply(o,C([],A(N(a.map(function(u){return n.getStateNode(u).getStateNodes(i[u])}))),!1)),o},t.prototype.handles=function(e){var r=pr(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof X?e:X.create(e),n=Array.from(de([],this.getStateNodes(r.value)));return new X(m(m({},r),{value:this.resolve(r.value),configuration:n,done:De(n,this),tags:Rr(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]),a=s._transition(e[i[0]],r,n);return!a||!a.transitions.length?this.next(r,n):a},t.prototype.transitionParallelNode=function(e,r,n){var i,s,a={};try{for(var o=b(Object.keys(e)),u=o.next();!u.done;u=o.next()){var f=u.value,c=e[f];if(!!c){var v=this.getStateNode(f),d=v._transition(c,r,n);d&&(a[f]=d)}}}catch(g){i={error:g}}finally{try{u&&!u.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}var l=Object.keys(a).map(function(g){return a[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})),w=N(Object.keys(a).map(function(g){return a[g].configuration}));return{transitions:h,entrySet:y,exitSet:N(l.map(function(g){return g.exitSet})),configuration:w,source:r,actions:N(Object.keys(a).map(function(g){return a[g].actions}))}},t.prototype._transition=function(e,r,n){return x(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,F(r))},t.prototype.next=function(e,r){var n,i,s=this,a=r.name,o=[],u=[],f;try{for(var c=b(this.getCandidates(a)),v=c.next();!v.done;v=c.next()){var d=v.value,l=d.cond,h=d.in,p=e.context,y=h?x(h)&&ye(h)?e.matches(Re(this.getStateNodeById(h).path,this.delimiter)):Rt(Re(h,this.delimiter),jn(this.path.slice(0,-2))(e.value)):!0,w=!1;try{w=!l||Or(this.machine,l,p,r,e)}catch(_){throw new Error("Unable to evaluate guard '".concat(l.name||l.type,"' in transition for event '").concat(a,"' in state node '").concat(this.id,`':
|
|
16
|
-
`).concat(_.message))}if(w&&y){d.target!==void 0&&(u=d.target),o.push.apply(o,C([],A(d.actions),!1)),f=d;break}}}catch(_){n={error:_}}finally{try{v&&!v.done&&(i=c.return)&&i.call(c)}finally{if(n)throw n.error}}if(!!f){if(!u.length)return{transitions:[f],entrySet:[],exitSet:[],configuration:e.value?[this]:[],source:e,actions:o};var g=N(u.map(function(_){return s.getRelativeStateNodes(_,e.historyValue)})),S=!!f.internal,P=S?[]:N(g.map(function(_){return s.nodesFromChild(_)}));return{transitions:[f],entrySet:P,exitSet:S?[]:[this],configuration:g,source:e,actions:o}}},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,a,o,u,f=de([],i?this.getStateNodes(i.value):[this]),c=e.configuration.length?de(f,e.configuration):f;try{for(var v=b(c),d=v.next();!d.done;d=v.next()){var l=d.value;nt(f,l)||e.entrySet.push(l)}}catch(T){s={error:T}}finally{try{d&&!d.done&&(a=v.return)&&a.call(v)}finally{if(s)throw s.error}}try{for(var h=b(f),p=h.next();!p.done;p=h.next()){var l=p.value;(!nt(c,l)||nt(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(T){o={error:T}}finally{try{p&&!p.done&&(u=h.return)&&u.call(h)}finally{if(o)throw o.error}}var y=N(e.entrySet.map(function(T){var E=[];if(T.type!=="final")return E;var O=T.parent;if(!O.parent)return E;E.push(et(T.id,T.doneData),et(O.id,T.doneData?Ke(T.doneData,r,n):void 0));var k=O.parent;return k.type==="parallel"&&fe(k).every(function(B){return De(e.configuration,B)})&&E.push(et(k.id)),E}));e.exitSet.sort(function(T,E){return E.order-T.order}),e.entrySet.sort(function(T,E){return T.order-E.order});var w=new Set(e.entrySet),g=new Set(e.exitSet),S=A([N(Array.from(w).map(function(T){return C(C([],A(T.activities.map(function(E){return Yn(E)})),!1),A(T.onEntry),!1)})).concat(y.map(Hn)),N(Array.from(g).map(function(T){return C(C([],A(T.onExit),!1),A(T.activities.map(function(E){return Kn(E)})),!1)}))],2),P=S[0],_=S[1],U=Ze(_.concat(e.actions).concat(P),this.machine.options.actions);return U},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=F(r),s;if(e instanceof X)s=n===void 0?e:this.resolveState(X.from(e,n));else{var a=x(e)?this.resolve(Je(this.getResolvedPath(e))):this.resolve(e),o=n!=null?n:this.machine.context;s=this.resolveState(X.from(a,o))}if(!Ae&&i.name===Ue)throw new Error("An event cannot have the wildcard type ('".concat(Ue,"')"));if(this.strict&&!this.events.includes(i.name)&&!Ln(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var u=this._transition(s.value,s,i)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},f=de([],this.getStateNodes(s.value)),c=u.configuration.length?de(f,u.configuration):f;return u.configuration=C([],A(c),!1),this.resolveTransition(u,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,C([],A(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,a,o=this;i===void 0&&(i=Xe);var u=e.configuration,f=!r||e.transitions.length>0,c=f?si(this.machine,u):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=b(d),p=h.next();!p.done;p=h.next()){var y=p.value;y.type===Ot?l[y.activity.id||y.activity.type]=y:y.type===bt&&(l[y.activity.id||y.activity.type]=!1)}}catch(W){s={error:W}}finally{try{p&&!p.done&&(a=h.return)&&a.call(h)}finally{if(s)throw s.error}}var w=A(Ut(this,r,n,i,d,this.machine.config.preserveActionOrder),2),g=w[0],S=w[1],P=A(Er(g,function(W){return W.type===Ge||W.type===ze&&W.to===xe.Internal}),2),_=P[0],U=P[1],T=g.filter(function(W){var _e;return W.type===Ot&&((_e=W.activity)===null||_e===void 0?void 0:_e.type)===xt}),E=T.reduce(function(W,_e){return W[_e.activity.id]=ei(_e.activity,o.machine,S,i),W},r?m({},r.children):{}),O=f?e.configuration:r?r.configuration:[],k=De(O,this),B=new X({value:c||r.value,context:S,_event:i,_sessionid:r?r._sessionid:null,historyValue:c?v?Bn(v,c):void 0:r?r.historyValue:void 0,history:!c||e.source?r:void 0,actions:c?U:[],activities:c?l:r?r.activities:{},events:[],configuration:O,transitions:e.transitions,children:E,done:k,tags:Rr(O),machine:this}),z=n!==S;B.changed=i.name===dr||z;var ne=B.history;ne&&delete ne.history;var St=!k&&(this._transient||u.some(function(W){return W._transient}));if(!f&&(!St||i.name===ve))return B;var Q=B;if(!k)for(St&&(Q=this.resolveRaisedTransition(Q,{type:In},i));_.length;){var La=_.shift();Q=this.resolveRaisedTransition(Q,La._event,i)}var Ma=Q.changed||(ne?!!Q.actions.length||z||typeof ne.value!=typeof Q.value||!Ir(Q.value,ne.value):void 0);return Q.changed=Ma,Q.history=ne,Q},t.prototype.getStateNode=function(e){if(ye(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=ye(e)?e.slice(Mt.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"&&ye(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=It(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||pe;switch(this.type){case"parallel":return Ie(this.initialStateValue,function(s,a){return s?n.getStateNode(a).resolve(e[a]||s):pe});case"compound":if(x(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?Ie(e,function(s,a){return s?n.getStateNode(a).resolve(s):pe}):this.initialStateValue||{};default:return e||pe}},t.prototype.getResolvedPath=function(e){if(ye(e)){var r=this.machine.idMap[e.slice(Mt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return It(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=yr(this.states,function(n){return n.initialStateValue||pe},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=rt(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;x(r.target)?e=ye(r.target)?Je(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(rt(this))return[this];if(this.type==="compound"&&!this.initial)return Ae||Pe(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Ye(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:yr(this.states,function(r,n){if(!e)return r.historyValue();var i=x(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(Ye(i).map(function(a){return n.getFromRelativePath(a)})):n.initialStateNodes}var s=$n(n.path,"states")(e).current;return x(s)?[n.getStateNode(s)]:N(Ye(s).map(function(a){return r.history==="deep"?n.getFromRelativePath(a):[n.states[a[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,a=new Set(this.ownEvents);if(s)try{for(var o=b(Object.keys(s)),u=o.next();!u.done;u=o.next()){var f=u.value,c=s[f];if(c.states)try{for(var v=(n=void 0,b(c.events)),d=v.next();!d.done;d=v.next()){var l=d.value;a.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{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(a)},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(!x(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 a=r.parent.getStateNodeByPath(s);return a}catch(o){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
|
|
17
|
-
`).concat(o.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=
|
|
18
|
-
`),function(o){if(s=o.indexOf(":"),n=Jt.trim(o.substr(0,s)).toLowerCase(),i=Jt.trim(o.substr(s+1)),n){if(r[n]&&Zi.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=M,ts=qr.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function i(s){var a=s;return e&&(r.setAttribute("href",a),a=r.href),r.setAttribute("href",a),{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(a){var o=qr.isString(a)?i(a):a;return o.protocol===n.protocol&&o.host===n.host}}():function(){return function(){return!0}}(),Yt=Ee,rs=M;function Vr(t){Yt.call(this,t==null?"canceled":t,Yt.ERR_CANCELED),this.name="CanceledError"}rs.inherits(Vr,Yt,{__CANCEL__:!0});var lt=Vr,ns=function(e){var r=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return r&&r[1]||""},$e=M,is=Wi,ss=Ji,as=Ur,os=Fr,us=es,cs=ts,ls=Mr,Z=Ee,fs=lt,ds=ns,Hr=function(e){return new Promise(function(n,i){var s=e.data,a=e.headers,o=e.responseType,u;function f(){e.cancelToken&&e.cancelToken.unsubscribe(u),e.signal&&e.signal.removeEventListener("abort",u)}$e.isFormData(s)&&$e.isStandardBrowserEnv()&&delete a["Content-Type"];var c=new XMLHttpRequest;if(e.auth){var v=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";a.Authorization="Basic "+btoa(v+":"+d)}var l=os(e.baseURL,e.url);c.open(e.method.toUpperCase(),as(l,e.params,e.paramsSerializer),!0),c.timeout=e.timeout;function h(){if(!!c){var w="getAllResponseHeaders"in c?us(c.getAllResponseHeaders()):null,g=!o||o==="text"||o==="json"?c.responseText:c.response,S={data:g,status:c.status,statusText:c.statusText,headers:w,config:e,request:c};is(function(_){n(_),f()},function(_){i(_),f()},S),c=null}}if("onloadend"in c?c.onloadend=h:c.onreadystatechange=function(){!c||c.readyState!==4||c.status===0&&!(c.responseURL&&c.responseURL.indexOf("file:")===0)||setTimeout(h)},c.onabort=function(){!c||(i(new Z("Request aborted",Z.ECONNABORTED,e,c)),c=null)},c.onerror=function(){i(new Z("Network Error",Z.ERR_NETWORK,e,c,c)),c=null},c.ontimeout=function(){var g=e.timeout?"timeout of "+e.timeout+"ms exceeded":"timeout exceeded",S=e.transitional||ls;e.timeoutErrorMessage&&(g=e.timeoutErrorMessage),i(new Z(g,S.clarifyTimeoutError?Z.ETIMEDOUT:Z.ECONNABORTED,e,c)),c=null},$e.isStandardBrowserEnv()){var p=(e.withCredentials||cs(l))&&e.xsrfCookieName?ss.read(e.xsrfCookieName):void 0;p&&(a[e.xsrfHeaderName]=p)}"setRequestHeader"in c&&$e.forEach(a,function(g,S){typeof s=="undefined"&&S.toLowerCase()==="content-type"?delete a[S]:c.setRequestHeader(S,g)}),$e.isUndefined(e.withCredentials)||(c.withCredentials=!!e.withCredentials),o&&o!=="json"&&(c.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&c.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&c.upload&&c.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(u=function(w){!c||(i(!w||w&&w.type?new fs:w),c.abort(),c=null)},e.cancelToken&&e.cancelToken.subscribe(u),e.signal&&(e.signal.aborted?u():e.signal.addEventListener("abort",u))),s||(s=null);var y=ds(l);if(y&&["http","https","file"].indexOf(y)===-1){i(new Z("Unsupported protocol "+y+":",Z.ERR_BAD_REQUEST,e));return}c.send(s)})},hs=null,$=M,Gr=Gi,zr=Ee,vs=Mr,ps=Br,ys={"Content-Type":"application/x-www-form-urlencoded"};function Wr(t,e){!$.isUndefined(t)&&$.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function ms(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Hr),t}function gs(t,e,r){if($.isString(t))try{return(e||JSON.parse)(t),$.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var ft={transitional:vs,adapter:ms(),transformRequest:[function(e,r){if(Gr(r,"Accept"),Gr(r,"Content-Type"),$.isFormData(e)||$.isArrayBuffer(e)||$.isBuffer(e)||$.isStream(e)||$.isFile(e)||$.isBlob(e))return e;if($.isArrayBufferView(e))return e.buffer;if($.isURLSearchParams(e))return Wr(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n=$.isObject(e),i=r&&r["Content-Type"],s;if((s=$.isFileList(e))||n&&i==="multipart/form-data"){var a=this.env&&this.env.FormData;return ps(s?{"files[]":e}:e,a&&new a)}else if(n||i==="application/json")return Wr(r,"application/json"),gs(e);return e}],transformResponse:[function(e){var r=this.transitional||ft.transitional,n=r&&r.silentJSONParsing,i=r&&r.forcedJSONParsing,s=!n&&this.responseType==="json";if(s||i&&$.isString(e)&&e.length)try{return JSON.parse(e)}catch(a){if(s)throw a.name==="SyntaxError"?zr.from(a,zr.ERR_BAD_RESPONSE,this,null,this.response):a}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:hs},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};$.forEach(["delete","get","head"],function(e){ft.headers[e]={}}),$.forEach(["post","put","patch"],function(e){ft.headers[e]=$.merge(ys)});var Kt=ft,Es=M,ws=Kt,Ss=function(e,r,n){var i=this||ws;return Es.forEach(n,function(a){e=a.call(i,e,r)}),e},Jr=function(e){return!!(e&&e.__CANCEL__)},Yr=M,Qt=Ss,Ts=Jr,Os=Kt,bs=lt;function Xt(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new bs}var _s=function(e){Xt(e),e.headers=e.headers||{},e.data=Qt.call(e,e.data,e.headers,e.transformRequest),e.headers=Yr.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),Yr.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||Os.adapter;return r(e).then(function(i){return Xt(e),i.data=Qt.call(e,i.data,i.headers,e.transformResponse),i},function(i){return Ts(i)||(Xt(e),i&&i.response&&(i.response.data=Qt.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},G=M,Kr=function(e,r){r=r||{};var n={};function i(c,v){return G.isPlainObject(c)&&G.isPlainObject(v)?G.merge(c,v):G.isPlainObject(v)?G.merge({},v):G.isArray(v)?v.slice():v}function s(c){if(G.isUndefined(r[c])){if(!G.isUndefined(e[c]))return i(void 0,e[c])}else return i(e[c],r[c])}function a(c){if(!G.isUndefined(r[c]))return i(void 0,r[c])}function o(c){if(G.isUndefined(r[c])){if(!G.isUndefined(e[c]))return i(void 0,e[c])}else return i(void 0,r[c])}function u(c){if(c in r)return i(e[c],r[c]);if(c in e)return i(void 0,e[c])}var f={url:a,method:a,data:a,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:u};return G.forEach(Object.keys(e).concat(Object.keys(r)),function(v){var d=f[v]||s,l=d(v);G.isUndefined(l)&&d!==u||(n[v]=l)}),n},Qr={version:"0.27.2"},xs=Qr.version,re=Ee,Zt={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){Zt[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var Xr={};Zt.transitional=function(e,r,n){function i(s,a){return"[Axios v"+xs+"] Transitional option '"+s+"'"+a+(n?". "+n:"")}return function(s,a,o){if(e===!1)throw new re(i(a," has been removed"+(r?" in "+r:"")),re.ERR_DEPRECATED);return r&&!Xr[a]&&(Xr[a]=!0,console.warn(i(a," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,a,o):!0}};function As(t,e,r){if(typeof t!="object")throw new re("options must be an object",re.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],a=e[s];if(a){var o=t[s],u=o===void 0||a(o,s,t);if(u!==!0)throw new re("option "+s+" must be "+u,re.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new re("Unknown option "+s,re.ERR_BAD_OPTION)}}var Rs={assertOptions:As,validators:Zt},Zr=M,Is=Ur,en=Vi,tn=_s,dt=Kr,Ps=Fr,rn=Rs,we=rn.validators;function Se(t){this.defaults=t,this.interceptors={request:new en,response:new en}}Se.prototype.request=function(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=dt(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&&rn.assertOptions(n,{silentJSONParsing:we.transitional(we.boolean),forcedJSONParsing:we.transitional(we.boolean),clarifyTimeoutError:we.transitional(we.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 a=[];this.interceptors.response.forEach(function(l){a.push(l.fulfilled,l.rejected)});var o;if(!s){var u=[tn,void 0];for(Array.prototype.unshift.apply(u,i),u=u.concat(a),o=Promise.resolve(r);u.length;)o=o.then(u.shift(),u.shift());return o}for(var f=r;i.length;){var c=i.shift(),v=i.shift();try{f=c(f)}catch(d){v(d);break}}try{o=tn(f)}catch(d){return Promise.reject(d)}for(;a.length;)o=o.then(a.shift(),a.shift());return o},Se.prototype.getUri=function(e){e=dt(this.defaults,e);var r=Ps(e.baseURL,e.url);return Is(r,e.params,e.paramsSerializer)},Zr.forEach(["delete","get","head","options"],function(e){Se.prototype[e]=function(r,n){return this.request(dt(n||{},{method:e,url:r,data:(n||{}).data}))}}),Zr.forEach(["post","put","patch"],function(e){function r(n){return function(s,a,o){return this.request(dt(o||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:a}))}}Se.prototype[e]=r(),Se.prototype[e+"Form"]=r(!0)});var Ns=Se,ks=lt;function Te(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(a){r.subscribe(a),i=a}).then(n);return s.cancel=function(){r.unsubscribe(i)},s},t(function(i){r.reason||(r.reason=new ks(i),e(r.reason))})}Te.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},Te.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},Te.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},Te.source=function(){var e,r=new Te(function(i){e=i});return{token:r,cancel:e}};var Cs=Te,Ds=function(e){return function(n){return e.apply(null,n)}},Us=M,js=function(e){return Us.isObject(e)&&e.isAxiosError===!0},nn=M,$s=Nr,ht=Ns,Ls=Kr,Ms=Kt;function sn(t){var e=new ht(t),r=$s(ht.prototype.request,e);return nn.extend(r,ht.prototype,e),nn.extend(r,e),r.create=function(i){return sn(Ls(t,i))},r}var H=sn(Ms);H.Axios=ht,H.CanceledError=lt,H.CancelToken=Cs,H.isCancel=Jr,H.VERSION=Qr.version,H.toFormData=Br,H.AxiosError=Ee,H.Cancel=H.CanceledError,H.all=function(e){return Promise.all(e)},H.spread=Ds,H.isAxiosError=js,Bt.exports=H,Bt.exports.default=H;var vt=Bt.exports;/*! js-cookie v3.0.1 | MIT */function pt(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 Bs={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 er(t,e){function r(i,s,a){if(typeof document!="undefined"){a=pt({},e,a),typeof a.expires=="number"&&(a.expires=new Date(Date.now()+a.expires*864e5)),a.expires&&(a.expires=a.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var u in a)!a[u]||(o+="; "+u,a[u]!==!0&&(o+="="+a[u].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+o}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],a={},o=0;o<s.length;o++){var u=s[o].split("="),f=u.slice(1).join("=");try{var c=decodeURIComponent(u[0]);if(a[c]=t.read(f,c),i===c)break}catch{}}return i?a[i]:a}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",pt({},s,{expires:-1}))},withAttributes:function(i){return er(this.converter,pt({},this.attributes,i))},withConverter:function(i){return er(pt({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var tr=er(Bs,{path:"/"}),Fs=Object.defineProperty,qs=Object.defineProperties,Vs=Object.getOwnPropertyDescriptors,yt=Object.getOwnPropertySymbols,an=Object.prototype.hasOwnProperty,on=Object.prototype.propertyIsEnumerable,un=(t,e,r)=>e in t?Fs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ae=(t,e)=>{for(var r in e||(e={}))an.call(e,r)&&un(t,r,e[r]);if(yt)for(var r of yt(e))on.call(e,r)&&un(t,r,e[r]);return t},Le=(t,e)=>qs(t,Vs(e)),Hs=(t,e)=>{var r={};for(var n in t)an.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&yt)for(var n of yt(t))e.indexOf(n)<0&&on.call(t,n)&&(r[n]=t[n]);return r};const rr="nhostRefreshToken",nr="nhostRefreshTokenExpiresAt",Gs=3,zs=300,Ws=5,Js=0,ee=10,Me=20,Oe={status:ee,error:"invalid-email",message:"Email is incorrectly formatted"},ir={status:ee,error:"invalid-password",message:"Password is incorrectly formatted"},cn={status:ee,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},Ys={status:ee,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},Ks={status:ee,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},Qs={status:ee,error:"no-refresh-token",message:"No refresh token has been provided"},Xs={status:Me,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},Be={status:Me,error:"already-signed-in",message:"User is already signed in"},Zs={status:Me,error:"unauthenticated-user",message:"User is not authenticated"},ea={status:Me,error:"user-not-anonymous",message:"User is not anonymous"},ta={status:Me,error:"unverified-user",message:"Email needs verification"},ra={status:ee,error:"invalid-authentication-method",message:"Incorrect parameters"},na={status:ee,error:"invalid-refresh-token",message:"Invalid or expired refresh token"},Fe=t=>{const e=vt.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,a,o,u,f,c,v,d;return Promise.reject({error:{message:(o=(a=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?a:r.request.responseText)!=null?o:JSON.stringify(r),status:(v=(c=(u=r.response)==null?void 0:u.status)!=null?c:(f=r.response)==null?void 0:f.data.statusCode)!=null?v:Js,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},mt=typeof window!="undefined",gt=new Map,ia=t=>{var e;return mt&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=gt.get(t))!=null?e:null},sa=(t,e)=>{mt&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?gt.set(t,e):gt.has(t)&>.delete(t)},aa=(t,e)=>{if(t==="localStorage"||t==="web")return ia;if(t==="cookie")return r=>{var n;return mt&&(n=tr.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}`)},oa=(t,e)=>{if(t==="localStorage"||t==="web")return sa;if(t==="cookie")return(r,n)=>{mt&&(n?tr.set(r,n):tr.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}`)},ln=(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},oe=(t,e)=>{if(!(e!=null&&e.redirectTo))return e;const r=new URL(t),n=Object.fromEntries(new URLSearchParams(r.search)),i=new URL(e.redirectTo.startsWith("/")?r.origin+e.redirectTo:e.redirectTo),s=new URLSearchParams(i.search);let a=Object.fromEntries(s);e.redirectTo.startsWith("/")&&(a=ae(ae({},n),a));let o=r.pathname;return i.pathname.length>1&&(o+=i.pathname.slice(1)),Le(ae({},e),{redirectTo:ln(i.origin+o,a)})};function Et(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 fn(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 be=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,}))$/),sr=t=>!!t&&typeof t=="string"&&t.length>=Gs,dn=t=>!!t&&typeof t=="string",ua=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),hn={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},ca=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Fe(t);return je({schema:{context:{},events:{}},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=>Oe}),saveRequestError:L({error:(i,{data:{error:s}})=>s}),reportError:J(i=>({type:"ERROR",error:i.error})),reportSuccess:J("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!be(s)},services:{requestChange:async(i,{email:s,options:a})=>(await n.post("/user/email/change",{newEmail:s,options:oe(e,a)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},la=({backendUrl:t,interpreter:e})=>{const r=Fe(t);return je({schema:{context:{},events:{}},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=>ir}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:J(n=>({type:"ERROR",error:n.error})),reportSuccess:J("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!sr(i)},services:{requestChange:(n,{password:i})=>r.post("/user/password",{newPassword:i},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},fa=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return je({schema:{context:{},events:{}},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=>Oe}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:J(n=>({type:"ERROR",error:n.error})),reportSuccess:J("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!be(i)},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:oe(e,s)})}})},da=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return je({schema:{context:{},events:{}},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=>Oe}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:J(n=>({type:"ERROR",error:n.error})),reportSuccess:J("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!be(i)},services:{request:async(n,{email:i,options:s})=>(await r.post("/user/email/send-verification-email",{email:i,options:oe(e,s)})).data}})},ha=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:a,autoRefreshToken:o=!0,autoSignIn:u=!0})=>{const f=r||aa(i,s),c=n||oa(i,s),v=Fe(t),d=async(l,h,p)=>(await v.post(l,h,p)).data;return je({schema:{context:{},events:{}},tsTypes:{},context:hn,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:"#nhost.authentication.authenticating.password",SIGNIN_PASSWORDLESS_EMAIL:"#nhost.authentication.authenticating.passwordlessEmail",SIGNIN_PASSWORDLESS_SMS:"#nhost.authentication.authenticating.passwordlessSms",SIGNIN_PASSWORDLESS_SMS_OTP:"#nhost.authentication.authenticating.passwordlessSmsOtp",SIGNUP_EMAIL_PASSWORD:"#nhost.authentication.registering",SIGNIN_ANONYMOUS:"#nhost.authentication.authenticating.anonymous",SIGNIN_MFA_TOTP:"#nhost.authentication.authenticating.mfa.totp"}},authenticating:{entry:"resetErrors",states:{passwordlessEmail:{invoke:{src:"signInPasswordlessEmail",id:"authenticatePasswordlessEmail",onDone:{target:"#nhost.authentication.signedOut",actions:"reportAwaitEmailVerification"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}}},passwordlessSms:{invoke:{src:"signInPasswordlessSms",id:"authenticatePasswordlessSms",onDone:"#nhost.authentication.signedOut.needsSmsOtp",onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}}},passwordlessSmsOtp:{invoke:{src:"signInPasswordlessSmsOtp",id:"authenticatePasswordlessSmsOtp",onDone:{actions:["saveSession","reportTokenChanged"],target:"#nhost.authentication.signedIn"},onError:{actions:"saveAuthenticationError",target:"#nhost.authentication.signedOut.failed"}}},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",actions:"reportAwaitEmailVerification",target:"#nhost.authentication.signedOut"},{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"}}}}}}},registering:{entry:["resetErrors"],invoke:{src:"signUp",id:"signUp",onDone:[{cond:"hasSession",target:"signedIn",actions:["saveSession","reportTokenChanged"]},{actions:"reportAwaitEmailVerification",target:"signedOut"}],onError:[{cond:"unverified",actions:"reportAwaitEmailVerification",target:"signedOut"},{actions:"saveRegistrationError",target:"signedOut.failed"}]}},signedIn:{type:"parallel",entry:["reportSignedIn","cleanUrl","broadcastToken","resetErrors"],on:{SIGNOUT:"signedOut.signingOut",DEANONYMIZE:{target:".deanonymizing"}},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"}]}}}}}},deanonymizing:{initial:"error",states:{error:{},success:{}}}}}}},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"]}]}}}},email:{initial:"unknown",on:{SIGNED_IN:[{cond:"needsVerification",target:".awaitingVerification"},".valid"],SIGNOUT:".unknown",AWAIT_EMAIL_VERIFICATION:".awaitingVerification"},states:{unknown:{},awaitingVerification:{},valid:{}}}}},{actions:{reportSignedIn:J("SIGNED_IN"),reportSignedOut:J("SIGNED_OUT"),reportAwaitEmailVerification:J("AWAIT_EMAIL_VERIFICATION"),reportTokenChanged:J("TOKEN_CHANGED"),clearContextExceptRefreshToken:L(({refreshToken:{value:l}})=>(c(nr,null),Le(ae({},hn),{refreshToken:{value:l}}))),saveSession:L({user:(l,{data:h})=>{var p;return(p=h==null?void 0:h.session)==null?void 0:p.user},accessToken:(l,{data:h})=>{var p,y;if(h.session.accessTokenExpiresIn){const w=new Date(Date.now()+h.session.accessTokenExpiresIn*1e3).toISOString();c(nr,w)}else c(nr,null);return{value:(p=h==null?void 0:h.session)==null?void 0:p.accessToken,expiresAt:new Date(Date.now()+((y=h==null?void 0:h.session)==null?void 0:y.accessTokenExpiresIn)*1e3)}},refreshToken:(l,{data:h})=>{var p;return c(rr,h.session.refreshToken),{value:(p=h==null?void 0:h.session)==null?void 0:p.refreshToken}}}),saveMfaTicket:L({mfa:(l,h)=>{var p;return(p=h.data)==null?void 0:p.mfa}}),resetTimer:L({refreshTimer:(l,h)=>({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}})=>Le(ae({},l),{authentication:h})}),resetErrors:L({errors:l=>({})}),saveRegistrationError:L({errors:({errors:l},{data:{error:h}})=>Le(ae({},l),{registration:h})}),destroyRefreshToken:L({refreshToken:l=>(c(rr,null),{value:null})}),cleanUrl:()=>{u&&Et("refreshToken")&&(fn("refreshToken"),fn("type"))},broadcastToken:l=>{if(u)try{new BroadcastChannel("nhost").postMessage(l.refreshToken.value)}catch{}}},guards:{needsVerification:(l,h)=>!l.user||l.user.isAnonymous,isSignedIn:l=>!!l.user&&!!l.refreshToken.value&&!!l.accessToken.value,noToken:l=>!l.refreshToken.value,hasRefreshToken:l=>!!l.refreshToken.value,isAutoRefreshDisabled:()=>!o,refreshTimerShouldRefresh:l=>{const{expiresAt:h}=l.accessToken;return h?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>Ws*1e3:a&&Date.now()-l.refreshTimer.startedAt.getTime()>a*1e3?!0:h.getTime()-Date.now()-1e3*zs<=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})=>be(h)?sr(p)?d("/signin/email-password",{email:h,password:p}):Promise.reject({error:ir}):Promise.reject({error:Oe}),signInPasswordlessSms:(l,{phoneNumber:h,options:p})=>dn(h)?d("/signin/passwordless/sms",{phoneNumber:h,options:oe(e,p)}):Promise.reject({error:cn}),signInPasswordlessSmsOtp:(l,{phoneNumber:h,otp:p})=>dn(h)?d("/signin/passwordless/sms/otp",{phoneNumber:h,otp:p}):Promise.reject({error:cn}),signInPasswordlessEmail:async(l,{email:h,options:p})=>be(h)?d("/signin/passwordless/email",{email:h,options:oe(e,p)}):Promise.reject({error:Oe}),signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,h)=>{var p;const y=h.ticket||((p=l.mfa)==null?void 0:p.ticket);return y?ua(y)?d("/signin/mfa/totp",{ticket:y,otp:h.otp}):Promise.reject({error:Ys}):Promise.reject({error:Ks})},refreshToken:async(l,h)=>{const p=h.type==="TRY_TOKEN"?h.token:l.refreshToken.value;return{session:await d("/token",{refreshToken:p})}},signout:(l,h)=>d("/signout",{refreshToken:l.refreshToken.value,all:!!h.all}),signUp:(l,{email:h,password:p,options:y})=>be(h)?sr(p)?d("/signup/email-password",{email:h,password:p,options:oe(e,y)}):Promise.reject({error:ir}):Promise.reject({error:Oe}),importRefreshToken:async()=>{let l=null;if(u){const p=Et("refreshToken")||null;if(p)try{return{session:await d("/token",{refreshToken:p})}}catch(y){l=y.error}else{const y=Et("error");if(y)return Promise.reject({error:{status:ee,error:y,message:Et("errorDescription")||y}})}}const h=await f(rr);if(h)try{return{session:await d("/token",{refreshToken:h})}}catch(p){l=p.error}return Promise.reject({error:l})}}})};class va{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:a=!0,backendUrl:o,clientUrl:u,devTools:f}=r,c=Hs(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl","devTools"]);if(this._subscriptions=new Set,this.backendUrl=o,this.clientUrl=u,this.machine=ha(Le(ae({},c),{backendUrl:o,clientUrl:u,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),a&&(this.interpreter=he(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 pa=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})})}),ya=async(t,e)=>new Promise(r=>{t.send("REQUEST",{password:e}),t.onTransition(n=>{n.matches({idle:"error"})?r({error:n.context.error,isError:!0,isSuccess:!1}):n.matches({idle:"success"})&&r({error:null,isError:!1,isSuccess:!0})})}),ma=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})})}),ga=(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})})}),Ea=t=>new Promise(e=>{const{changed:r}=t.send("SIGNIN_ANONYMOUS");r||e({isSuccess:!1,isError:!0,error:ra,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})})}),wa=(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:Be,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:s.user});t.onTransition(a=>{a.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,needsMfaOtp:!1,mfa:null,user:null}):a.matches({authentication:{signedOut:"needsMfa"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!0,mfa:a.context.mfa,user:null}):a.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:a.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:null}):a.matches({authentication:"signedIn"})&&n({accessToken:a.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:a.context.user})})}),Sa=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("SIGNIN_PASSWORDLESS_EMAIL",{email:e,options:r});if(!i)return n({error:Be,isError:!0,isSuccess:!1});t.onTransition(s=>{s.matches({authentication:{signedOut:"failed"}})?n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1}):s.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"})&&n({error:null,isError:!1,isSuccess:!0})})}),Ta=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:Zs});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})})}),Oa=(t,e,r,n)=>new Promise(i=>{const{changed:s,context:a}=t.send("SIGNUP_EMAIL_PASSWORD",{email:e,password:r,options:n});if(!s)return i({error:Be,accessToken:a.accessToken.value,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:a.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"failed"}})?i({accessToken:null,error:o.context.errors.registration||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):o.matches({authentication:{signedOut:"noErrors"},email:"awaitingVerification"})?i({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):o.matches({authentication:"signedIn"})&&i({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:o.context.user})})});var ba=Object.defineProperty,_a=Object.defineProperties,xa=Object.getOwnPropertyDescriptors,wt=Object.getOwnPropertySymbols,vn=Object.prototype.hasOwnProperty,pn=Object.prototype.propertyIsEnumerable,yn=(t,e,r)=>e in t?ba(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mn=(t,e)=>{for(var r in e||(e={}))vn.call(e,r)&&yn(t,r,e[r]);if(wt)for(var r of wt(e))pn.call(e,r)&&yn(t,r,e[r]);return t},gn=(t,e)=>_a(t,xa(e)),Aa=(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&&pn.call(t,n)&&(r[n]=t[n]);return r};const Ra=()=>typeof window!="undefined",qe=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},ar=({accessToken:t,isError:e,user:r,error:n})=>e?{session:null,error:n}:r&&t?{session:{accessToken:t,accessTokenExpiresIn:0,refreshToken:"TODO",user:r},error:null}:{session:null,error:null};class Ia{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:a,clientStorageGetter:o,clientStorageSetter:u,refreshIntervalTime:f,start:c=!0}){var v;this._client=new va({backendUrl:e,clientUrl:typeof window!="undefined"&&((v=window.location)==null?void 0:v.origin)||"",autoRefreshToken:r,autoSignIn:typeof i=="boolean"?i:n,start:c,clientStorage:s,clientStorageType:a,clientStorageGetter:o,clientStorageSetter:u,refreshIntervalTime:f})}async signUp({email:e,password:r,options:n}){const i=await this.waitUntilReady();return ar(await Oa(i,e,r,n))}async signIn(e){const r=await this.waitUntilReady();if("provider"in e){const{provider:i,options:s}=e,a=ln(`${this._client.backendUrl}/signin/provider/${i}`,oe(this._client.clientUrl,s));return Ra()&&(window.location.href=a),{providerUrl:a,provider:i,session:null,mfa:null,error:null}}if("email"in e&&"password"in e){const i=await wa(r,e.email,e.password);return i.needsEmailVerification?{session:null,mfa:null,error:ta}:i.needsMfaOtp?{session:null,mfa:i.mfa,error:null}:gn(mn({},ar(i)),{mfa:null})}if("email"in e&&!("otp"in e)){const{error:i}=await Sa(r,e.email);return{session:null,mfa:null,error:i}}if("phoneNumber"in e&&!("otp"in e))return new Promise(i=>{const{changed:s}=r.send("SIGNIN_PASSWORDLESS_SMS",e);if(!s)return i({session:null,mfa:null,error:Be});r.onTransition(a=>{a.matches({authentication:{signedOut:"needsSmsOtp"}})?i({session:null,mfa:null,error:null}):a.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:a.context.errors.authentication||null})})});if("otp"in e)return new Promise(i=>{const{changed:s}=r.send("SIGNIN_PASSWORDLESS_SMS_OTP",e);if(!s)return i({session:null,mfa:null,error:Be});r.onTransition(a=>{a.matches({authentication:"signedIn"})?i({session:qe(a.context),mfa:null,error:null}):a.matches({authentication:{signedOut:"failed"}})&&i({session:null,mfa:null,error:a.context.errors.authentication||null})})});const n=await Ea(r);return gn(mn({},ar(n)),{mfa:null})}async signOut(e){const r=await this.waitUntilReady(),{error:n}=await Ta(r,e==null?void 0:e.all);return{error:n}}async resetPassword({email:e,options:r}){const n=he(fa(this._client)).start(),{error:i}=await ma(n,e,r);return{error:i}}async changePassword({newPassword:e}){const r=he(la(this._client)).start(),{error:n}=await ya(r,e);return{error:n}}async sendVerificationEmail({email:e,options:r}){const n=he(da(this._client)).start(),{error:i}=await ga(n,e,r);return{error:i}}async changeEmail({newEmail:e,options:r}){const n=he(ca(this._client)).start(),{error:i}=await pa(n,e,r);return{error:i}}async deanonymize(e){const r=await this.waitUntilReady();return new Promise(n=>{var i;if(!this.isAuthenticated()||!((i=r.state.context.user)!=null&&i.isAnonymous))return{error:ea};const s=e,{signInMethod:a,connection:o}=s,u=Aa(s,["signInMethod","connection"]);r.send("DEANONYMIZE",{signInMethod:a,connection:o,options:u}),r.onTransition(f=>{f.matches({authentication:{signedIn:{deanonymizing:"success"}}})?n({error:null}):f.matches({authentication:{signedIn:{deanonymizing:"error"}}})&&n({error:f.context.errors.authentication||null})}),r.start()})}onTokenChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{i.type==="TOKEN_CHANGED"&&e(qe(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,qe(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?Rn(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:Qs});const{changed:s}=r.send("TRY_TOKEN",{token:i});if(!s)return n({session:null,error:Xs});r.onTransition(a=>{a.matches({token:{idle:"error"}})?n({session:null,error:na}):a.event.type==="TOKEN_CHANGED"&&n({session:qe(a.context),error:null})})})}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return qe((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(a=>{if(!a.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 Pa=Object.defineProperty,Na=Object.defineProperties,ka=Object.getOwnPropertyDescriptors,En=Object.getOwnPropertySymbols,Ca=Object.prototype.hasOwnProperty,Da=Object.prototype.propertyIsEnumerable,wn=(t,e,r)=>e in t?Pa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ve=(t,e)=>{for(var r in e||(e={}))Ca.call(e,r)&&wn(t,r,e[r]);if(En)for(var r of En(e))Da.call(e,r)&&wn(t,r,e[r]);return t},Sn=(t,e)=>Na(t,ka(e));class Ua{constructor({url:e}){this.url=e,this.httpClient=vt.create({baseURL:this.url})}async upload(e){try{return{fileMetadata:(await this.httpClient.post("/files",e.file,{headers:Sn(Ve(Ve({},this.generateUploadHeaders(e)),this.generateAuthHeaders()),{"Content-Type":"multipart/form-data"})})).data,error:null}}catch(r){return{fileMetadata:null,error:r}}}async getPresignedUrl(e){try{const{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:Ve({},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:Ve({},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 ja{constructor({url:e,adminSecret:r}){this.url=e,this.api=new Ua({url:e}),this.setAdminSecret(r)}async upload(e){const r=new FormData;r.append("file",e.file);const{fileMetadata:n,error:i}=await this.api.upload(Sn(Ve({},e),{file: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 Tn{constructor(e){const{url:r,adminSecret:n}=e;this.accessToken=null,this.adminSecret=n,this.instance=vt.create({baseURL:r})}async call(e,r,n){const i=ue(ue({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,or(ue({},n),{headers:i}))}catch(a){if(a instanceof Error)return{res:null,error:a}}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 On{constructor(e){const{url:r,adminSecret:n}=e;this.url=r,this.accessToken=null,this.adminSecret=n,this.instance=vt.create({baseURL:r})}async request(e,r,n){const i=ue(ue({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);try{const s="",o=(await this.instance.post("",{operationName:s||void 0,query:typeof e=="string"?e:j.print(e),variables:r},or(ue({},n),{headers:i}))).data,{data:u}=o;return o.errors?{data:null,error:o.errors}:typeof u!="object"||Array.isArray(u)||u===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:u,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}`}:{}}}class bn{constructor({backendUrl:e,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:u,adminSecret:f,devTools:c,start:v=!0}){var d;if(!e)throw new Error("Please specify a `backendUrl`. Docs: [todo]!");this.auth=new Ia({url:`${e}/v1/auth`,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:u,start:v}),this.storage=new ja({url:`${e}/v1/storage`,adminSecret:f}),this.functions=new Tn({url:`${e}/v1/functions`,adminSecret:f}),this.graphql=new On({url:`${e}/v1/graphql`,adminSecret:f}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(d=this.auth.client)==null||d.onStart(()=>{this.auth.onAuthStateChanged((l,h)=>{l==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(l=>{this.storage.setAccessToken(l==null?void 0:l.accessToken),this.functions.setAccessToken(l==null?void 0:l.accessToken),this.graphql.setAccessToken(l==null?void 0:l.accessToken)})}),this.devTools=c}}const $a=t=>new bn(t);D.NhostClient=bn,D.NhostFunctionsClient=Tn,D.NhostGraphqlClient=On,D.createClient=$a,Object.defineProperties(D,{__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 Ot(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 O(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 R(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(a)throw a.error}}return s}function C(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 A;(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"})(A||(A={}));var Re;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(Re||(Re={}));var xt=A.Start,_t=A.Stop,Ve=A.Raise,He=A.Send,fr=A.Cancel,In=A.NullEvent,Rt=A.Assign;A.After,A.DoneState;var dr=A.Log,Nn=A.Init,At=A.Invoke;A.ErrorExecution;var hr=A.ErrorPlatform,Cn=A.ErrorCustom,vr=A.Update,Dn=A.Choose,Un=A.Pure,pr=".",yr={},Pt="xstate.guard",jn="",Ae=!0,ze;function kt(t,e,r){r===void 0&&(r=pr);var n=Pe(t,r),i=Pe(e,r);return _(i)?_(n)?i===n:!1:_(n)?n in i:Object.keys(n).every(function(s){return s in i?kt(n[s],i[s]):!1})}function mr(t){try{return _(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 It(t,e){try{return ce(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function $n(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function Pe(t,e){if($n(t))return t.value;if(ce(t))return Ge(t);if(typeof t!="string")return t;var r=It(t,e);return Ge(r)}function Ge(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 ke(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 gr(t,e,r){var n,i,s={};try{for(var a=O(Object.keys(t)),o=a.next();!o.done;o=a.next()){var c=o.value,f=t[c];!r(f)||(s[c]=e(f,c,t))}}catch(u){n={error:u}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}var Ln=function(t){return function(e){var r,n,i=e;try{for(var s=O(t),a=s.next();!a.done;a=s.next()){var o=a.value;i=i[o]}}catch(c){r={error:c}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function Mn(t,e){return function(r){var n,i,s=r;try{for(var a=O(t),o=a.next();!o.done;o=a.next()){var c=o.value;s=s[e][c]}}catch(f){n={error:f}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}}function We(t){if(!t)return[[]];if(_(t))return[[t]];var e=I(Object.keys(t).map(function(r){var n=t[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:We(t[r]).map(function(i){return[r].concat(i)})}));return e}function I(t){var e;return(e=[]).concat.apply(e,C([],R(t),!1))}function Er(t){return ce(t)?t:[t]}function J(t){return t===void 0?[]:Er(t)}function Je(t,e,r){var n,i;if(P(t))return t(e,r.data);var s={};try{for(var a=O(Object.keys(t)),o=a.next();!o.done;o=a.next()){var c=o.value,f=t[c];P(f)?s[c]=f(e,r.data):s[c]=f}}catch(u){n={error:u}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return s}function Bn(t){return/^(done|error)\./.test(t)}function wr(t){return!!(t instanceof Promise||t!==null&&(P(t)||typeof t=="object")&&P(t.then))}function qn(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function Sr(t,e){var r,n,i=R([[],[]],2),s=i[0],a=i[1];try{for(var o=O(t),c=o.next();!c.done;c=o.next()){var f=c.value;e(f)?s.push(f):a.push(f)}}catch(u){r={error:u}}finally{try{c&&!c.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return[s,a]}function Tr(t,e){return ke(t.states,function(r,n){if(!!r){var i=(_(e)?void 0:e[n])||(r?r.current:void 0);if(!!i)return{current:i,states:Tr(r,i)}}})}function Fn(t,e){return{current:e,states:Tr(t,e)}}function br(t,e,r,n){var i=t&&r.reduce(function(s,a){var o,c,f=a.assignment,u={state:n,action:a,_event:e},v={};if(P(f))v=f(s,e.data,u);else try{for(var d=O(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){o={error:y}}finally{try{l&&!l.done&&(c=d.return)&&c.call(d)}finally{if(o)throw o.error}}return Object.assign({},s,v)},t);return i}var Ie=function(){};function ce(t){return Array.isArray(t)}function P(t){return typeof t=="function"}function _(t){return typeof t=="string"}function Or(t,e){if(!!t)return _(t)?{type:Pt,name:t,predicate:e?e[t]:void 0}:P(t)?{type:Pt,name:t.name,predicate:t}:t}function Vn(t){try{return"subscribe"in t&&P(t.subscribe)}catch{return!1}}var te=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();ze={},ze[te]=function(){return this},ze[Symbol.observable]=function(){return this};function ae(t){return!!t&&"__xstatenode"in t}function Hn(t){return!!t&&typeof t.send=="function"}function Nt(t,e){return _(t)||typeof t=="number"?m({type:t},e):t}function q(t,e){if(!_(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=Nt(t);return m({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function le(t,e){var r=Er(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||ae(n)?{target:n,event:t}:m(m({},n),{event:t})});return r}function zn(t){if(!(t===void 0||t===jn))return J(t)}function xr(t,e,r,n,i){var s=t.options.guards,a={state:i,cond:e,_event:n};if(e.type===Pt)return((s==null?void 0:s[e.name])||e.predicate)(r,n.data,a);var o=s==null?void 0:s[e.type];if(!o)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return o(r,n.data,a)}function _r(t){return typeof t=="string"?{type:t}:t}function Ct(t,e,r){if(typeof t=="object")return t;var n=function(){};return{next:t,error:e||n,complete:r||n}}function Ke(t,e){return"".concat(t,":invocation[").concat(e,"]")}var Ye=q({type:Nn});function Dt(t,e){return e&&e[t]||void 0}function Ne(t,e){var r;if(_(t)||typeof t=="number"){var n=Dt(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=Dt(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 Qe=function(t,e){if(!t)return[];var r=ce(t)?t:[t];return r.map(function(n){return Ne(n,e)})};function Ut(t){var e=Ne(t);return m(m({id:_(t)?t:e.id},e),{type:e.type})}function Gn(t){return _(t)?{type:Ve,event:t}:jt(t,{to:Re.Internal})}function Wn(t){return{type:Ve,_event:q(t.event)}}function jt(t,e){return{to:e?e.to:void 0,type:He,event:P(t)?t:Nt(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:P(t)?t.name:mr(t)}}function Jn(t,e,r,n){var i={_event:r},s=q(P(t.event)?t.event(e,r.data,i):t.event),a;if(_(t.delay)){var o=n&&n[t.delay];a=P(o)?o(e,r.data,i):o}else a=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:a})}var Kn=function(t,e,r){return m(m({},t),{value:_(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},Yn=function(t){return{type:fr,sendId:t}};function Qn(t){var e=Ut(t);return{type:A.Start,activity:e,exec:void 0}}function Xn(t){var e=P(t)?t:Ut(t);return{type:A.Stop,activity:e,exec:void 0}}function Zn(t,e,r){var n=P(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:A.Stop,activity:i};return s}var ei=function(t){return{type:Rt,assignment:t}};function ti(t,e){var r=e?"#".concat(e):"";return"".concat(A.After,"(").concat(t,")").concat(r)}function Xe(t,e){var r="".concat(A.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ze(t,e){var r="".concat(A.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function Ce(t,e){var r="".concat(A.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function $t(t,e,r,n,i,s){s===void 0&&(s=!1);var a=R(s?[[],i]:Sr(i,function(d){return d.type===Rt}),2),o=a[0],c=a[1],f=o.length?br(r,n,o,e):r,u=s?[r]:void 0,v=I(c.map(function(d){var l;switch(d.type){case Ve:return Wn(d);case He:var h=Jn(d,f,n,t.options.delays);return h;case dr:return Kn(d,f,n);case Dn:{var p=d,y=(l=p.conds.find(function(N){var B=Or(N.cond,t.options.guards);return!B||xr(t,B,f,n,e)}))===null||l===void 0?void 0:l.actions;if(!y)return[];var E=R($t(t,e,f,n,Qe(J(y),t.options.actions),s),2),g=E[0],S=E[1];return f=S,u==null||u.push(f),g}case Un:{var y=d.get(f,n.data);if(!y)return[];var k=R($t(t,e,f,n,Qe(J(y),t.options.actions),s),2),x=k[0],U=k[1];return f=U,u==null||u.push(f),x}case _t:return Zn(d,f,n);case Rt:{f=br(f,n,[d],e),u==null||u.push(f);break}default:var T=Ne(d,t.options.actions),w=T.exec;if(w&&u){var b=u.length-1;T=m(m({},T),{exec:function(N){for(var B=[],G=1;G<arguments.length;G++)B[G-1]=arguments[G];w.apply(void 0,C([u[b]],R(B),!1))}})}return T}}).filter(function(d){return!!d}));return[v,f]}var De=function(t,e){var r=e(t);return r};function Rr(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[te]=function(){return this},e}function ri(t,e,r,n){var i,s=_r(t.src),a=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],o=t.data?Je(t.data,r,n):void 0,c=a?ni(a,t.id,o):Rr(t.id);return c.meta=t,c}function ni(t,e,r){var n=Rr(e);if(n.deferred=!0,ae(t)){var i=n.state=De(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function ii(t){try{return typeof t.send=="function"}catch{return!1}}function si(t){return ii(t)&&"id"in t}function ai(t){var e;return m((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[te]=function(){return this},e),t)}var et=function(t){return t.type==="atomic"||t.type==="final"};function fe(t){return Object.keys(t.states).map(function(e){return t.states[e]}).filter(function(e){return e.type!=="history"})}function Ar(t){var e=[t];return et(t)?e:e.concat(I(fe(t).map(Ar)))}function de(t,e){var r,n,i,s,a,o,c,f,u=new Set(t),v=Lt(u),d=new Set(e);try{for(var l=O(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=Lt(d);try{for(var g=O(d),S=g.next();!S.done;S=g.next()){var p=S.value;if(p.type==="compound"&&(!E.get(p)||!E.get(p).length))v.get(p)?v.get(p).forEach(function(N){return d.add(N)}):p.initialStateNodes.forEach(function(N){return d.add(N)});else if(p.type==="parallel")try{for(var k=(a=void 0,O(fe(p))),x=k.next();!x.done;x=k.next()){var U=x.value;d.has(U)||(d.add(U),v.get(U)?v.get(U).forEach(function(N){return d.add(N)}):U.initialStateNodes.forEach(function(N){return d.add(N)}))}}catch(N){a={error:N}}finally{try{x&&!x.done&&(o=k.return)&&o.call(k)}finally{if(a)throw a.error}}}}catch(b){i={error:b}}finally{try{S&&!S.done&&(s=g.return)&&s.call(g)}finally{if(i)throw i.error}}try{for(var T=O(d),w=T.next();!w.done;w=T.next())for(var p=w.value,y=p.parent;y&&!d.has(y);)d.add(y),y=y.parent}catch(b){c={error:b}}finally{try{w&&!w.done&&(f=T.return)&&f.call(T)}finally{if(c)throw c.error}}return d}function Pr(t,e){var r=e.get(t);if(!r)return{};if(t.type==="compound"){var n=r[0];if(n){if(et(n))return n.key}else return{}}var i={};return r.forEach(function(s){i[s.key]=Pr(s,e)}),i}function Lt(t){var e,r,n=new Map;try{for(var i=O(t),s=i.next();!s.done;s=i.next()){var a=s.value;n.has(a)||n.set(a,[]),a.parent&&(n.has(a.parent)||n.set(a.parent,[]),n.get(a.parent).push(a))}}catch(o){e={error:o}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n}function oi(t,e){var r=de([t],e);return Pr(t,Lt(r))}function tt(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function ui(t){return C([],R(new Set(I(C([],R(t.map(function(e){return e.ownEvents})),!1)))),!1)}function Ue(t,e){return e.type==="compound"?fe(e).some(function(r){return r.type==="final"&&tt(t,r)}):e.type==="parallel"?fe(e).every(function(r){return Ue(t,r)}):!1}function ci(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function kr(t){return new Set(I(t.map(function(e){return e.tags})))}function Ir(t,e){if(t===e)return!0;if(t===void 0||e===void 0)return!1;if(_(t)||_(e))return t===e;var r=Object.keys(t),n=Object.keys(e);return r.length===n.length&&r.every(function(i){return Ir(t[i],e[i])})}function li(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function fi(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 Z=function(){function t(e){var r=this,n;this.actions=[],this.activities=yr,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||yr,this.meta=ci(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 ui(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=Ye;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=Ye;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="."),_(e))return[e];var i=Object.keys(e);return i.concat.apply(i,C([],R(i.map(function(s){return n.toStrings(e[s],r).map(function(a){return s+r+a})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=Ot(e,["configuration","transitions","tags","machine"]);return m(m({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return kt(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;Ie(!!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}(),di={deferEvents:!1},Nr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=m(m({},di),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}(),Mt=new Map,hi=0,rt={bookId:function(){return"x:".concat(hi++)},register:function(t,e){return Mt.set(t,e),t},get:function(t){return Mt.get(t)},free:function(t){Mt.delete(t)}};function Bt(){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 vi(){var t=Bt();if(t&&"__xstate__"in t)return t.__xstate__}function pi(t){if(!!Bt()){var e=vi();e&&e.register(t)}}function yi(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,a=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}},o=ai({id:e.id,send:function(f){i.push(f),a()},getSnapshot:function(){return r},subscribe:function(f,u,v){var d=Ct(f,u,v);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),c={parent:e.parent,self:o,id:e.id||"anonymous",observers:n};return r=t.start?t.start(c):r,o}var mi={sync:!1,autoForward:!1},F;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(F||(F={}));var gi=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=F.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(u,v){if(ce(u))return n.batch(u),n.state;var d=q(Nt(u,v));if(n.status===F.Stopped)return n.state;if(n.status!==F.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===Re.Parent||n.parent.id===v),l=d?n.parent:_(v)?n.children.get(v)||rt.get(v):Hn(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===Cn?"".concat(Ce(n.id)):u.name,origin:n.sessionId})):l.send(u.data)};var i=m(m({},t.defaultOptions),r),s=i.clock,a=i.logger,o=i.parent,c=i.id,f=c!==void 0?c:e.id;this.id=f,this.logger=a,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Nr({deferEvents:this.options.deferEvents}),this.sessionId=rt.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:De(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=O(e.actions),a=s.next();!a.done;a=s.next()){var o=a.value;this.exec(o,e,r)}}catch(c){n={error:c}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,a,o,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=O(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=O(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&&(a=p.return)&&a.call(p)}finally{if(s)throw s.error}}try{for(var E=O(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(b){o={error:b}}finally{try{g&&!g.done&&(c=E.return)&&c.call(E)}finally{if(o)throw o.error}}var k=Ue(e.configuration||[],this.machine);if(this.state.configuration&&k){var x=e.configuration.find(function(b){return b.type==="final"&&b.parent===v.machine}),U=x&&x.doneData?Je(x.doneData,e.context,r):void 0;try{for(var T=O(this.doneListeners),w=T.next();!w.done;w=T.next()){var h=w.value;h(Ze(this.id,U))}}catch(b){f={error:b}}finally{try{w&&!w.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===F.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,a=n;return typeof e=="function"?s=e:(s=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(s),this.status!==F.NotStarted&&s(this.state),a&&(this.status===F.Stopped?a():this.onDone(a)),{unsubscribe:function(){s&&i.listeners.delete(s),a&&i.doneListeners.delete(a)}}},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===F.Running)return this;this.machine._init(),rt.register(this.sessionId,this),this.initialized=!0,this.status=F.Running;var n=e===void 0?this.initialState:De(this,function(){return li(e)?r.machine.resolveState(e):r.machine.resolveState(Z.from(e,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,Ye)}),this},t.prototype.stop=function(){var e,r,n,i,s,a,o,c,f,u,v=this;try{for(var d=O(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 p=O(this.stopListeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(),this.stopListeners.delete(h)}}catch(w){n={error:w}}finally{try{y&&!y.done&&(i=p.return)&&i.call(p)}finally{if(n)throw n.error}}try{for(var E=O(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&&(a=E.return)&&a.call(E)}finally{if(s)throw s.error}}try{for(var S=O(this.doneListeners),k=S.next();!k.done;k=S.next()){var h=k.value;this.doneListeners.delete(h)}}catch(w){o={error:w}}finally{try{k&&!k.done&&(c=S.return)&&c.call(S)}finally{if(o)throw o.error}}if(!this.initialized)return this;C([],R(this.state.configuration),!1).sort(function(w,b){return b.order-w.order}).forEach(function(w){var b,N;try{for(var B=O(w.definition.exit),G=B.next();!G.done;G=B.next()){var se=G.value;v.exec(se,v.state)}}catch(bt){b={error:bt}}finally{try{G&&!G.done&&(N=B.return)&&N.call(B)}finally{if(b)throw b.error}}}),this.children.forEach(function(w){P(w.stop)&&w.stop()}),this.children.clear();try{for(var x=O(Object.keys(this.delayedEventsMap)),U=x.next();!U.done;U=x.next()){var T=U.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(w){f={error:w}}finally{try{U&&!U.done&&(u=x.return)&&u.call(x)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.scheduler=new Nr({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=F.Stopped,this._initialState=void 0,rt.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(!(this.status===F.NotStarted&&this.options.deferEvents)){if(this.status!==F.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,a=!1,o=[],c=function(d){var l=q(d);r.forward(l),s=De(r,function(){return r.machine.transition(s,l)}),o.push.apply(o,C([],R(s.actions.map(function(h){return fi(h,s)})),!1)),a=a||!!s.changed};try{for(var f=O(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=a,s.actions=o,r.update(s,q(e[e.length-1]))})},t.prototype.sender=function(e){return this.send.bind(this,e)},t.prototype.nextState=function(e){var r=this,n=q(e);if(n.name.indexOf(hr)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(hr)===0}))throw n.data.data;var i=De(this,function(){return r.machine.transition(r.state,n)});return i},t.prototype.forward=function(e){var r,n;try{for(var i=O(this.forwardTo),s=i.next();!s.done;s=i.next()){var a=s.value,o=this.children.get(a);if(!o)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(a,"'."));o.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,a=e.exec||Dt(e.type,n),o=P(a)?a:a?a.exec:e.exec;if(o)try{return o(i,s.data,{action:e,state:this.state,_event:s})}catch(k){throw this.parent&&this.parent.send({type:"xstate.error",data:k}),k}switch(e.type){case He: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 fr:this.cancel(e.sendId);break;case xt:{if(this.status!==F.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===A.Invoke){var u=_r(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?Je(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;ae(y)&&(y=p?y.withContext(p):y,E={autoForward:h}),this.spawn(y,d,E)}else this.spawnActivity(f);break}case _t:{this.stopChild(e.activity.id);break}case dr: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),P(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(wr(e))return this.spawnPromise(Promise.resolve(e),r);if(P(e))return this.spawnCallback(e,r);if(si(e))return this.spawnActor(e,r);if(Vn(e))return this.spawnObservable(e,r);if(ae(e))return this.spawnMachine(e,m(m({},n),{id:r}));if(qn(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({},mi),r);s.sync&&i.onTransition(function(o){n.send(vr,{state:o,id:i.id})});var a=i;return this.children.set(i.id,a),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(o){n.removeChild(i.id),n.send(q(o,{origin:i.id}))}).start(),a},t.prototype.spawnBehavior=function(e,r){var n=yi(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,a;e.then(function(c){s||(a=c,i.removeChild(r),i.send(q(Ze(r,c),{origin:r})))},function(c){if(!s){i.removeChild(r);var f=Ce(r,c);try{i.send(q(f,{origin:r}))}catch{i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var o=(n={id:r,send:function(){},subscribe:function(c,f,u){var v=Ct(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 a}},n[te]=function(){return this},n);return this.children.set(r,o),o},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,a=new Set,o=new Set,c,f=function(d){c=d,o.forEach(function(l){return l(d)}),!s&&i.send(q(d,{origin:r}))},u;try{u=e(f,function(d){a.add(d)})}catch(d){this.send(Ce(r,d))}if(wr(u))return this.spawnPromise(u,r);var v=(n={id:r,send:function(d){return a.forEach(function(l){return l(d)})},subscribe:function(d){var l=Ct(d);return o.add(l.next),{unsubscribe:function(){o.delete(l.next)}}},stop:function(){s=!0,P(u)&&u()},toJSON:function(){return{id:r}},getSnapshot:function(){return c}},n[te]=function(){return this},n);return this.children.set(r,v),v},t.prototype.spawnObservable=function(e,r){var n,i=this,s,a=e.subscribe(function(c){s=c,i.send(q(c,{origin:r}))},function(c){i.removeChild(r),i.send(q(Ce(r,c),{origin:r}))},function(){i.removeChild(r),i.send(q(Ze(r),{origin:r}))}),o=(n={id:r,send:function(){},subscribe:function(c,f,u){return e.subscribe(c,f,u)},stop:function(){return a.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[te]=function(){return this},n);return this.children.set(r,o),o},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[te]=function(){return this},n))},t.prototype.attachDev=function(){var e=Bt();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)}pi(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[te]=function(){return this},t.prototype.getSnapshot=function(){return this.status===F.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=he,t}();function he(t,e){var r=new gi(t,e);return r}function Ei(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function nt(t){return m(m({type:At},t),{toJSON:function(){t.onDone,t.onError;var e=Ot(t,["onDone","onError"]);return m(m({},e),{type:At,src:Ei(t.src)})}})}var ve="",qt="#",je="*",pe={},ye=function(t){return t[0]===qt},wi=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Si=function(t,e,r){var n=r.slice(0,-1).some(function(s){return!("cond"in s)&&!("in"in s)&&(_(s.target)||ae(s.target))}),i=e===ve?"the transient event":"event '".concat(e,"'");Ie(!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.")},Ti=function(){function t(e,r,n,i){var s=this;n===void 0&&(n="context"in e?e.context:void 0);var a;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(wi(),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:pr),this.id=this.config.id||C([this.machine.key],R(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:(a=this.config.schema)!==null&&a!==void 0?a:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?ke(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}):pe;var o=0;function c(f){var u,v;f.order=o++;try{for(var d=O(fe(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===ve}):ve in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=J(this.config.entry||this.config.onEntry).map(function(f){return Ne(f)}),this.onExit=J(this.config.exit||this.config.onExit).map(function(f){return Ne(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=J(this.config.invoke).map(function(f,u){var v,d;if(ae(f)){var l=Ke(s.id,u);return s.machine.options.services=m((v={},v[l]=f,v),s.machine.options.services),nt({src:l,id:l})}else if(_(f.src)){var l=f.id||Ke(s.id,u);return nt(m(m({},f),{id:l,src:f.src}))}else if(ae(f.src)||P(f.src)){var l=f.id||Ke(s.id,u);return s.machine.options.services=m((d={},d[l]=f.src,d),s.machine.options.services),nt(m(m({id:l},f),{src:l}))}else{var h=f.src;return nt(m(m({id:Ke(s.id,u)},f),{src:h}))}}),this.activities=J(this.config.activities).concat(this.invoke).map(function(f){return Ut(f)}),this.transition=this.transition.bind(this),this.tags=J(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||Ar(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,a=n.guards,o=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({},a),e.guards),services:m(m({},o),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:ke(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===ve,n=this.transitions.filter(function(i){var s=i.eventType===e;return r?s:s||i.eventType===je});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,a){var o=P(s)?"".concat(e.id,":delay[").concat(a,"]"):s,c=ti(o,e.id);return e.onEntry.push(jt(c,{delay:s})),e.onExit.push(Yn(c)),c},i=ce(r)?r.map(function(s,a){var o=n(s.delay,a);return m(m({},s),{event:o})}):I(Object.keys(r).map(function(s,a){var o=r[s],c=_(o)?{target:o}:o,f=isNaN(+s)?s:+s,u=n(f,a);return J(c).map(function(v){return m(m({},v),{event:u,delay:f})})}));return i.map(function(s){var a=s.delay;return m(m({},e.formatTransition(s)),{delay:a})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof Z?e.value:Pe(e,this.delimiter);if(_(i)){var s=this.getStateNode(i).initial;return s!==void 0?this.getStateNodes((r={},r[i]=s,r)):[this,this.states[i]]}var a=Object.keys(i),o=[this];return o.push.apply(o,C([],R(I(a.map(function(c){return n.getStateNode(c).getStateNodes(i[c])}))),!1)),o},t.prototype.handles=function(e){var r=mr(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof Z?e:Z.create(e),n=Array.from(de([],this.getStateNodes(r.value)));return new Z(m(m({},r),{value:this.resolve(r.value),configuration:n,done:Ue(n,this),tags:kr(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]),a=s._transition(e[i[0]],r,n);return!a||!a.transitions.length?this.next(r,n):a},t.prototype.transitionParallelNode=function(e,r,n){var i,s,a={};try{for(var o=O(Object.keys(e)),c=o.next();!c.done;c=o.next()){var f=c.value,u=e[f];if(!!u){var v=this.getStateNode(f),d=v._transition(u,r,n);d&&(a[f]=d)}}}catch(g){i={error:g}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}var l=Object.keys(a).map(function(g){return a[g]}),h=I(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=I(l.map(function(g){return g.entrySet})),E=I(Object.keys(a).map(function(g){return a[g].configuration}));return{transitions:h,entrySet:y,exitSet:I(l.map(function(g){return g.exitSet})),configuration:E,source:r,actions:I(Object.keys(a).map(function(g){return a[g].actions}))}},t.prototype._transition=function(e,r,n){return _(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,q(r))},t.prototype.next=function(e,r){var n,i,s=this,a=r.name,o=[],c=[],f;try{for(var u=O(this.getCandidates(a)),v=u.next();!v.done;v=u.next()){var d=v.value,l=d.cond,h=d.in,p=e.context,y=h?_(h)&&ye(h)?e.matches(Pe(this.getStateNodeById(h).path,this.delimiter)):kt(Pe(h,this.delimiter),Ln(this.path.slice(0,-2))(e.value)):!0,E=!1;try{E=!l||xr(this.machine,l,p,r,e)}catch(x){throw new Error("Unable to evaluate guard '".concat(l.name||l.type,"' in transition for event '").concat(a,"' in state node '").concat(this.id,`':
|
|
16
|
+
`).concat(x.message))}if(E&&y){d.target!==void 0&&(c=d.target),o.push.apply(o,C([],R(d.actions),!1)),f=d;break}}}catch(x){n={error:x}}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:o};var g=I(c.map(function(x){return s.getRelativeStateNodes(x,e.historyValue)})),S=!!f.internal,k=S?[]:I(g.map(function(x){return s.nodesFromChild(x)}));return{transitions:[f],entrySet:k,exitSet:S?[]:[this],configuration:g,source:e,actions:o}}},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,a,o,c,f=de([],i?this.getStateNodes(i.value):[this]),u=e.configuration.length?de(f,e.configuration):f;try{for(var v=O(u),d=v.next();!d.done;d=v.next()){var l=d.value;tt(f,l)||e.entrySet.push(l)}}catch(T){s={error:T}}finally{try{d&&!d.done&&(a=v.return)&&a.call(v)}finally{if(s)throw s.error}}try{for(var h=O(f),p=h.next();!p.done;p=h.next()){var l=p.value;(!tt(u,l)||tt(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(T){o={error:T}}finally{try{p&&!p.done&&(c=h.return)&&c.call(h)}finally{if(o)throw o.error}}var y=I(e.entrySet.map(function(T){var w=[];if(T.type!=="final")return w;var b=T.parent;if(!b.parent)return w;w.push(Xe(T.id,T.doneData),Xe(b.id,T.doneData?Je(T.doneData,r,n):void 0));var N=b.parent;return N.type==="parallel"&&fe(N).every(function(B){return Ue(e.configuration,B)})&&w.push(Xe(N.id)),w}));e.exitSet.sort(function(T,w){return w.order-T.order}),e.entrySet.sort(function(T,w){return T.order-w.order});var E=new Set(e.entrySet),g=new Set(e.exitSet),S=R([I(Array.from(E).map(function(T){return C(C([],R(T.activities.map(function(w){return Qn(w)})),!1),R(T.onEntry),!1)})).concat(y.map(Gn)),I(Array.from(g).map(function(T){return C(C([],R(T.onExit),!1),R(T.activities.map(function(w){return Xn(w)})),!1)}))],2),k=S[0],x=S[1],U=Qe(x.concat(e.actions).concat(k),this.machine.options.actions);return U},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=q(r),s;if(e instanceof Z)s=n===void 0?e:this.resolveState(Z.from(e,n));else{var a=_(e)?this.resolve(Ge(this.getResolvedPath(e))):this.resolve(e),o=n!=null?n:this.machine.context;s=this.resolveState(Z.from(a,o))}if(!Ae&&i.name===je)throw new Error("An event cannot have the wildcard type ('".concat(je,"')"));if(this.strict&&!this.events.includes(i.name)&&!Bn(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=de([],this.getStateNodes(s.value)),u=c.configuration.length?de(f,c.configuration):f;return c.configuration=C([],R(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,C([],R(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,a,o=this;i===void 0&&(i=Ye);var c=e.configuration,f=!r||e.transitions.length>0,u=f?oi(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=O(d),p=h.next();!p.done;p=h.next()){var y=p.value;y.type===xt?l[y.activity.id||y.activity.type]=y:y.type===_t&&(l[y.activity.id||y.activity.type]=!1)}}catch(W){s={error:W}}finally{try{p&&!p.done&&(a=h.return)&&a.call(h)}finally{if(s)throw s.error}}var E=R($t(this,r,n,i,d,this.machine.config.preserveActionOrder),2),g=E[0],S=E[1],k=R(Sr(g,function(W){return W.type===Ve||W.type===He&&W.to===Re.Internal}),2),x=k[0],U=k[1],T=g.filter(function(W){var _e;return W.type===xt&&((_e=W.activity)===null||_e===void 0?void 0:_e.type)===At}),w=T.reduce(function(W,_e){return W[_e.activity.id]=ri(_e.activity,o.machine,S,i),W},r?m({},r.children):{}),b=f?e.configuration:r?r.configuration:[],N=Ue(b,this),B=new Z({value:u||r.value,context:S,_event:i,_sessionid:r?r._sessionid:null,historyValue:u?v?Fn(v,u):void 0:r?r.historyValue:void 0,history:!u||e.source?r:void 0,actions:u?U:[],activities:u?l:r?r.activities:{},events:[],configuration:b,transitions:e.transitions,children:w,done:N,tags:kr(b),machine:this}),G=n!==S;B.changed=i.name===vr||G;var se=B.history;se&&delete se.history;var bt=!N&&(this._transient||c.some(function(W){return W._transient}));if(!f&&(!bt||i.name===ve))return B;var Q=B;if(!N)for(bt&&(Q=this.resolveRaisedTransition(Q,{type:In},i));x.length;){var $a=x.shift();Q=this.resolveRaisedTransition(Q,$a._event,i)}var La=Q.changed||(se?!!Q.actions.length||G||typeof se.value!=typeof Q.value||!Ir(Q.value,se.value):void 0);return Q.changed=La,Q.history=se,Q},t.prototype.getStateNode=function(e){if(ye(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=ye(e)?e.slice(qt.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"&&ye(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=It(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||pe;switch(this.type){case"parallel":return ke(this.initialStateValue,function(s,a){return s?n.getStateNode(a).resolve(e[a]||s):pe});case"compound":if(_(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?ke(e,function(s,a){return s?n.getStateNode(a).resolve(s):pe}):this.initialStateValue||{};default:return e||pe}},t.prototype.getResolvedPath=function(e){if(ye(e)){var r=this.machine.idMap[e.slice(qt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return It(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=gr(this.states,function(n){return n.initialStateValue||pe},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=et(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;_(r.target)?e=ye(r.target)?Ge(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(et(this))return[this];if(this.type==="compound"&&!this.initial)return Ae||Ie(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=We(this.initialStateValue);return I(r.map(function(n){return e.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),t.prototype.getFromRelativePath=function(e){if(!e.length)return[this];var r=R(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:gr(this.states,function(r,n){if(!e)return r.historyValue();var i=_(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?I(We(i).map(function(a){return n.getFromRelativePath(a)})):n.initialStateNodes}var s=Mn(n.path,"states")(e).current;return _(s)?[n.getStateNode(s)]:I(We(s).map(function(a){return r.history==="deep"?n.getFromRelativePath(a):[n.states[a[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=I(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,a=new Set(this.ownEvents);if(s)try{for(var o=O(Object.keys(s)),c=o.next();!c.done;c=o.next()){var f=c.value,u=s[f];if(u.states)try{for(var v=(n=void 0,O(u.events)),d=v.next();!d.done;d=v.next()){var l=d.value;a.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=o.return)&&r.call(o)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(a)},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(!_(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 a=r.parent.getStateNodeByPath(s);return a}catch(o){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
|
|
17
|
+
`).concat(o.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=zn(e.target),i="internal"in e?e.internal:n?n.some(function(c){return _(c)&&c[0]===r.delimiter}):!0,s=this.machine.options.guards,a=this.resolveTarget(n),o=m(m({},e),{actions:Qe(J(e.actions)),cond:Or(e.cond,s),target:a,source:this,internal:i,eventType:e.event,toJSON:function(){return m(m({},o),{target:o.target?o.target.map(function(c){return"#".concat(c.id)}):void 0,source:"#".concat(r.id)})}});return o},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,a=je,o=s[a],c=o===void 0?[]:o,f=Ot(s,[typeof a=="symbol"?a:a+""]);i=I(Object.keys(f).map(function(g){!Ae&&g===ve&&Ie(!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=le(g,f[g]);return Ae||Si(n,g,S),S}).concat(le(je,c)))}var u=this.config.always?le("",this.config.always):[],v=this.config.onDone?le(String(Xe(this.id)),this.config.onDone):[];Ae||Ie(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var d=I(this.invoke.map(function(g){var S=[];return g.onDone&&S.push.apply(S,C([],R(le(String(Ze(g.id)),g.onDone)),!1)),g.onError&&S.push.apply(S,C([],R(le(String(Ce(g.id)),g.onError)),!1)),S})),l=this.after,h=I(C(C(C(C([],R(v),!1),R(d),!1),R(i),!1),R(u),!1).map(function(g){return J(g).map(function(S){return n.formatTransition(S)})}));try{for(var p=O(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 $e(t,e){return new Ti(t,e)}var $=ei,K=jt,Ft={exports:{}},Cr=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)}},bi=Cr,Vt=Object.prototype.toString,Ht=function(t){return function(e){var r=Vt.call(e);return t[r]||(t[r]=r.slice(8,-1).toLowerCase())}}(Object.create(null));function oe(t){return t=t.toLowerCase(),function(r){return Ht(r)===t}}function zt(t){return Array.isArray(t)}function it(t){return typeof t=="undefined"}function Oi(t){return t!==null&&!it(t)&&t.constructor!==null&&!it(t.constructor)&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}var Dr=oe("ArrayBuffer");function xi(t){var e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&Dr(t.buffer),e}function _i(t){return typeof t=="string"}function Ri(t){return typeof t=="number"}function Ur(t){return t!==null&&typeof t=="object"}function st(t){if(Ht(t)!=="object")return!1;var e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}var Ai=oe("Date"),Pi=oe("File"),ki=oe("Blob"),Ii=oe("FileList");function Gt(t){return Vt.call(t)==="[object Function]"}function Ni(t){return Ur(t)&&Gt(t.pipe)}function Ci(t){var e="[object FormData]";return t&&(typeof FormData=="function"&&t instanceof FormData||Vt.call(t)===e||Gt(t.toString)&&t.toString()===e)}var Di=oe("URLSearchParams");function Ui(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 Wt(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 Jt(){var t={};function e(i,s){st(t[s])&&st(i)?t[s]=Jt(t[s],i):st(i)?t[s]=Jt({},i):zt(i)?t[s]=i.slice():t[s]=i}for(var r=0,n=arguments.length;r<n;r++)Wt(arguments[r],e);return t}function $i(t,e,r){return Wt(e,function(i,s){r&&typeof i=="function"?t[s]=bi(i,r):t[s]=i}),t}function Li(t){return t.charCodeAt(0)===65279&&(t=t.slice(1)),t}function Mi(t,e,r,n){t.prototype=Object.create(e.prototype,n),t.prototype.constructor=t,r&&Object.assign(t.prototype,r)}function Bi(t,e,r){var n,i,s,a={};e=e||{};do{for(n=Object.getOwnPropertyNames(t),i=n.length;i-- >0;)s=n[i],a[s]||(e[s]=t[s],a[s]=!0);t=Object.getPrototypeOf(t)}while(t&&(!r||r(t,e))&&t!==Object.prototype);return e}function qi(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 Fi(t){if(!t)return null;var e=t.length;if(it(e))return null;for(var r=new Array(e);e-- >0;)r[e]=t[e];return r}var Vi=function(t){return function(e){return t&&e instanceof t}}(typeof Uint8Array!="undefined"&&Object.getPrototypeOf(Uint8Array)),M={isArray:zt,isArrayBuffer:Dr,isBuffer:Oi,isFormData:Ci,isArrayBufferView:xi,isString:_i,isNumber:Ri,isObject:Ur,isPlainObject:st,isUndefined:it,isDate:Ai,isFile:Pi,isBlob:ki,isFunction:Gt,isStream:Ni,isURLSearchParams:Di,isStandardBrowserEnv:ji,forEach:Wt,merge:Jt,extend:$i,trim:Ui,stripBOM:Li,inherits:Mi,toFlatObject:Bi,kindOf:Ht,kindOfTest:oe,endsWith:qi,toArray:Fi,isTypedArray:Vi,isFileList:Ii},me=M;function jr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var $r=function(e,r,n){if(!r)return e;var i;if(n)i=n(r);else if(me.isURLSearchParams(r))i=r.toString();else{var s=[];me.forEach(r,function(c,f){c===null||typeof c=="undefined"||(me.isArray(c)?f=f+"[]":c=[c],me.forEach(c,function(v){me.isDate(v)?v=v.toISOString():me.isObject(v)&&(v=JSON.stringify(v)),s.push(jr(f)+"="+jr(v))}))}),i=s.join("&")}if(i){var a=e.indexOf("#");a!==-1&&(e=e.slice(0,a)),e+=(e.indexOf("?")===-1?"?":"&")+i}return e},Hi=M;function at(){this.handlers=[]}at.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},at.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},at.prototype.forEach=function(e){Hi.forEach(this.handlers,function(n){n!==null&&e(n)})};var zi=at,Gi=M,Wi=function(e,r){Gi.forEach(e,function(i,s){s!==r&&s.toUpperCase()===r.toUpperCase()&&(e[r]=i,delete e[s])})},Lr=M;function ge(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)}Lr.inherits(ge,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 Mr=ge.prototype,Br={};["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){Br[t]={value:t}}),Object.defineProperties(ge,Br),Object.defineProperty(Mr,"isAxiosError",{value:!0}),ge.from=function(t,e,r,n,i,s){var a=Object.create(Mr);return Lr.toFlatObject(t,a,function(c){return c!==Error.prototype}),ge.call(a,t.message,e,r,n,i),a.name=t.name,s&&Object.assign(a,s),a};var Ee=ge,qr={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Y=M;function Ji(t,e){e=e||new FormData;var r=[];function n(s){return s===null?"":Y.isDate(s)?s.toISOString():Y.isArrayBuffer(s)||Y.isTypedArray(s)?typeof Blob=="function"?new Blob([s]):Buffer.from(s):s}function i(s,a){if(Y.isPlainObject(s)||Y.isArray(s)){if(r.indexOf(s)!==-1)throw Error("Circular reference detected in "+a);r.push(s),Y.forEach(s,function(c,f){if(!Y.isUndefined(c)){var u=a?a+"."+f:f,v;if(c&&!a&&typeof c=="object"){if(Y.endsWith(f,"{}"))c=JSON.stringify(c);else if(Y.endsWith(f,"[]")&&(v=Y.toArray(c))){v.forEach(function(d){!Y.isUndefined(d)&&e.append(u,n(d))});return}}i(c,u)}}),r.pop()}else e.append(a,n(s))}return i(t),e}var Fr=Ji,Kt=Ee,Ki=function(e,r,n){var i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):r(new Kt("Request failed with status code "+n.status,[Kt.ERR_BAD_REQUEST,Kt.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))},ot=M,Yi=ot.isStandardBrowserEnv()?function(){return{write:function(r,n,i,s,a,o){var c=[];c.push(r+"="+encodeURIComponent(n)),ot.isNumber(i)&&c.push("expires="+new Date(i).toGMTString()),ot.isString(s)&&c.push("path="+s),ot.isString(a)&&c.push("domain="+a),o===!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(){}}}(),Qi=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},Xi=function(e,r){return r?e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""):e},Zi=Qi,es=Xi,Vr=function(e,r){return e&&!Zi(r)?es(e,r):r},Yt=M,ts=["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"],rs=function(e){var r={},n,i,s;return e&&Yt.forEach(e.split(`
|
|
18
|
+
`),function(o){if(s=o.indexOf(":"),n=Yt.trim(o.substr(0,s)).toLowerCase(),i=Yt.trim(o.substr(s+1)),n){if(r[n]&&ts.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([i]):r[n]=r[n]?r[n]+", "+i:i}}),r},Hr=M,ns=Hr.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function i(s){var a=s;return e&&(r.setAttribute("href",a),a=r.href),r.setAttribute("href",a),{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(a){var o=Hr.isString(a)?i(a):a;return o.protocol===n.protocol&&o.host===n.host}}():function(){return function(){return!0}}(),Qt=Ee,is=M;function zr(t){Qt.call(this,t==null?"canceled":t,Qt.ERR_CANCELED),this.name="CanceledError"}is.inherits(zr,Qt,{__CANCEL__:!0});var ut=zr,ss=function(e){var r=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return r&&r[1]||""},Le=M,as=Ki,os=Yi,us=$r,cs=Vr,ls=rs,fs=ns,ds=qr,ee=Ee,hs=ut,vs=ss,Gr=function(e){return new Promise(function(n,i){var s=e.data,a=e.headers,o=e.responseType,c;function f(){e.cancelToken&&e.cancelToken.unsubscribe(c),e.signal&&e.signal.removeEventListener("abort",c)}Le.isFormData(s)&&Le.isStandardBrowserEnv()&&delete a["Content-Type"];var u=new XMLHttpRequest;if(e.auth){var v=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";a.Authorization="Basic "+btoa(v+":"+d)}var l=cs(e.baseURL,e.url);u.open(e.method.toUpperCase(),us(l,e.params,e.paramsSerializer),!0),u.timeout=e.timeout;function h(){if(!!u){var E="getAllResponseHeaders"in u?ls(u.getAllResponseHeaders()):null,g=!o||o==="text"||o==="json"?u.responseText:u.response,S={data:g,status:u.status,statusText:u.statusText,headers:E,config:e,request:u};as(function(x){n(x),f()},function(x){i(x),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 ee("Request aborted",ee.ECONNABORTED,e,u)),u=null)},u.onerror=function(){i(new ee("Network Error",ee.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||ds;e.timeoutErrorMessage&&(g=e.timeoutErrorMessage),i(new ee(g,S.clarifyTimeoutError?ee.ETIMEDOUT:ee.ECONNABORTED,e,u)),u=null},Le.isStandardBrowserEnv()){var p=(e.withCredentials||fs(l))&&e.xsrfCookieName?os.read(e.xsrfCookieName):void 0;p&&(a[e.xsrfHeaderName]=p)}"setRequestHeader"in u&&Le.forEach(a,function(g,S){typeof s=="undefined"&&S.toLowerCase()==="content-type"?delete a[S]:u.setRequestHeader(S,g)}),Le.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),o&&o!=="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 hs: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=vs(l);if(y&&["http","https","file"].indexOf(y)===-1){i(new ee("Unsupported protocol "+y+":",ee.ERR_BAD_REQUEST,e));return}u.send(s)})},ps=null,L=M,Wr=Wi,Jr=Ee,ys=qr,ms=Fr,gs={"Content-Type":"application/x-www-form-urlencoded"};function Kr(t,e){!L.isUndefined(t)&&L.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function Es(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Gr),t}function ws(t,e,r){if(L.isString(t))try{return(e||JSON.parse)(t),L.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var ct={transitional:ys,adapter:Es(),transformRequest:[function(e,r){if(Wr(r,"Accept"),Wr(r,"Content-Type"),L.isFormData(e)||L.isArrayBuffer(e)||L.isBuffer(e)||L.isStream(e)||L.isFile(e)||L.isBlob(e))return e;if(L.isArrayBufferView(e))return e.buffer;if(L.isURLSearchParams(e))return Kr(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n=L.isObject(e),i=r&&r["Content-Type"],s;if((s=L.isFileList(e))||n&&i==="multipart/form-data"){var a=this.env&&this.env.FormData;return ms(s?{"files[]":e}:e,a&&new a)}else if(n||i==="application/json")return Kr(r,"application/json"),ws(e);return e}],transformResponse:[function(e){var r=this.transitional||ct.transitional,n=r&&r.silentJSONParsing,i=r&&r.forcedJSONParsing,s=!n&&this.responseType==="json";if(s||i&&L.isString(e)&&e.length)try{return JSON.parse(e)}catch(a){if(s)throw a.name==="SyntaxError"?Jr.from(a,Jr.ERR_BAD_RESPONSE,this,null,this.response):a}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:ps},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};L.forEach(["delete","get","head"],function(e){ct.headers[e]={}}),L.forEach(["post","put","patch"],function(e){ct.headers[e]=L.merge(gs)});var Xt=ct,Ss=M,Ts=Xt,bs=function(e,r,n){var i=this||Ts;return Ss.forEach(n,function(a){e=a.call(i,e,r)}),e},Yr=function(e){return!!(e&&e.__CANCEL__)},Qr=M,Zt=bs,Os=Yr,xs=Xt,_s=ut;function er(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new _s}var Rs=function(e){er(e),e.headers=e.headers||{},e.data=Zt.call(e,e.data,e.headers,e.transformRequest),e.headers=Qr.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),Qr.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||xs.adapter;return r(e).then(function(i){return er(e),i.data=Zt.call(e,i.data,i.headers,e.transformResponse),i},function(i){return Os(i)||(er(e),i&&i.response&&(i.response.data=Zt.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},z=M,Xr=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 a(u){if(!z.isUndefined(r[u]))return i(void 0,r[u])}function o(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:a,method:a,data:a,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,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},Zr={version:"0.27.2"},As=Zr.version,re=Ee,tr={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){tr[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var en={};tr.transitional=function(e,r,n){function i(s,a){return"[Axios v"+As+"] Transitional option '"+s+"'"+a+(n?". "+n:"")}return function(s,a,o){if(e===!1)throw new re(i(a," has been removed"+(r?" in "+r:"")),re.ERR_DEPRECATED);return r&&!en[a]&&(en[a]=!0,console.warn(i(a," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,a,o):!0}};function Ps(t,e,r){if(typeof t!="object")throw new re("options must be an object",re.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],a=e[s];if(a){var o=t[s],c=o===void 0||a(o,s,t);if(c!==!0)throw new re("option "+s+" must be "+c,re.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new re("Unknown option "+s,re.ERR_BAD_OPTION)}}var ks={assertOptions:Ps,validators:tr},tn=M,Is=$r,rn=zi,nn=Rs,lt=Xr,Ns=Vr,sn=ks,we=sn.validators;function Se(t){this.defaults=t,this.interceptors={request:new rn,response:new rn}}Se.prototype.request=function(e,r){typeof e=="string"?(r=r||{},r.url=e):r=e||{},r=lt(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&&sn.assertOptions(n,{silentJSONParsing:we.transitional(we.boolean),forcedJSONParsing:we.transitional(we.boolean),clarifyTimeoutError:we.transitional(we.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 a=[];this.interceptors.response.forEach(function(l){a.push(l.fulfilled,l.rejected)});var o;if(!s){var c=[nn,void 0];for(Array.prototype.unshift.apply(c,i),c=c.concat(a),o=Promise.resolve(r);c.length;)o=o.then(c.shift(),c.shift());return o}for(var f=r;i.length;){var u=i.shift(),v=i.shift();try{f=u(f)}catch(d){v(d);break}}try{o=nn(f)}catch(d){return Promise.reject(d)}for(;a.length;)o=o.then(a.shift(),a.shift());return o},Se.prototype.getUri=function(e){e=lt(this.defaults,e);var r=Ns(e.baseURL,e.url);return Is(r,e.params,e.paramsSerializer)},tn.forEach(["delete","get","head","options"],function(e){Se.prototype[e]=function(r,n){return this.request(lt(n||{},{method:e,url:r,data:(n||{}).data}))}}),tn.forEach(["post","put","patch"],function(e){function r(n){return function(s,a,o){return this.request(lt(o||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:a}))}}Se.prototype[e]=r(),Se.prototype[e+"Form"]=r(!0)});var Cs=Se,Ds=ut;function Te(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(a){r.subscribe(a),i=a}).then(n);return s.cancel=function(){r.unsubscribe(i)},s},t(function(i){r.reason||(r.reason=new Ds(i),e(r.reason))})}Te.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},Te.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},Te.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},Te.source=function(){var e,r=new Te(function(i){e=i});return{token:r,cancel:e}};var Us=Te,js=function(e){return function(n){return e.apply(null,n)}},$s=M,Ls=function(e){return $s.isObject(e)&&e.isAxiosError===!0},an=M,Ms=Cr,ft=Cs,Bs=Xr,qs=Xt;function on(t){var e=new ft(t),r=Ms(ft.prototype.request,e);return an.extend(r,ft.prototype,e),an.extend(r,e),r.create=function(i){return on(Bs(t,i))},r}var H=on(qs);H.Axios=ft,H.CanceledError=ut,H.CancelToken=Us,H.isCancel=Yr,H.VERSION=Zr.version,H.toFormData=Fr,H.AxiosError=Ee,H.Cancel=H.CanceledError,H.all=function(e){return Promise.all(e)},H.spread=js,H.isAxiosError=Ls,Ft.exports=H,Ft.exports.default=H;var dt=Ft.exports;/*! js-cookie v3.0.1 | MIT */function ht(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 Fs={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 rr(t,e){function r(i,s,a){if(typeof document!="undefined"){a=ht({},e,a),typeof a.expires=="number"&&(a.expires=new Date(Date.now()+a.expires*864e5)),a.expires&&(a.expires=a.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var c in a)!a[c]||(o+="; "+c,a[c]!==!0&&(o+="="+a[c].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+o}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],a={},o=0;o<s.length;o++){var c=s[o].split("="),f=c.slice(1).join("=");try{var u=decodeURIComponent(c[0]);if(a[u]=t.read(f,u),i===u)break}catch{}}return i?a[i]:a}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",ht({},s,{expires:-1}))},withAttributes:function(i){return rr(this.converter,ht({},this.attributes,i))},withConverter:function(i){return rr(ht({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var nr=rr(Fs,{path:"/"}),Vs=Object.defineProperty,Hs=Object.defineProperties,zs=Object.getOwnPropertyDescriptors,vt=Object.getOwnPropertySymbols,un=Object.prototype.hasOwnProperty,cn=Object.prototype.propertyIsEnumerable,ln=(t,e,r)=>e in t?Vs(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ne=(t,e)=>{for(var r in e||(e={}))un.call(e,r)&&ln(t,r,e[r]);if(vt)for(var r of vt(e))cn.call(e,r)&&ln(t,r,e[r]);return t},Me=(t,e)=>Hs(t,zs(e)),fn=(t,e)=>{var r={};for(var n in t)un.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&vt)for(var n of vt(t))e.indexOf(n)<0&&cn.call(t,n)&&(r[n]=t[n]);return r};const pt="nhostRefreshToken",yt="nhostRefreshTokenExpiresAt",Gs=3,Ws=300,Js=5,Ks=0,ie=10,mt=20,be={status:ie,error:"invalid-email",message:"Email is incorrectly formatted"},ir={status:ie,error:"invalid-password",message:"Password is incorrectly formatted"},dn={status:ie,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},Ys={status:ie,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},Qs={status:ie,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},Xs={status:ie,error:"no-refresh-token",message:"No refresh token has been provided"},Zs={status:mt,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},Oe={status:mt,error:"already-signed-in",message:"User is already signed in"},ea={status:mt,error:"unauthenticated-user",message:"User is not authenticated"},ta={status:mt,error:"unverified-user",message:"Email needs verification"},ra={status:ie,error:"invalid-refresh-token",message:"Invalid or expired refresh token"},Be=t=>{const e=dt.create({baseURL:t});return e.interceptors.response.use(r=>r,r=>{var n,i,s,a,o,c,f,u,v,d;return Promise.reject({error:{message:(o=(a=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?a:r.request.responseText)!=null?o: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:Ks,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},gt=typeof window!="undefined",Et=new Map,na=t=>{var e;return gt&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=Et.get(t))!=null?e:null},ia=(t,e)=>{gt&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?Et.set(t,e):Et.has(t)&&Et.delete(t)},sa=(t,e)=>{if(t==="localStorage"||t==="web")return na;if(t==="cookie")return r=>{var n;return gt&&(n=nr.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}`)},aa=(t,e)=>{if(t==="localStorage"||t==="web")return ia;if(t==="cookie")return(r,n)=>{gt&&(n?nr.set(r,n):nr.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}`)},hn=(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},X=(t,e)=>{if(!(e!=null&&e.redirectTo))return e;const r=e,{redirectTo:n}=r,i=fn(r,["redirectTo"]);if(!t)return n.startsWith("/")?i:e;const s=new URL(t),a=Object.fromEntries(new URLSearchParams(s.search)),o=new URL(n.startsWith("/")?s.origin+n:n),c=new URLSearchParams(o.search);let f=Object.fromEntries(c);n.startsWith("/")&&(f=ne(ne({},a),f));let u=s.pathname;return o.pathname.length>1&&(u+=o.pathname.slice(1)),Me(ne({},i),{redirectTo:hn(o.origin+u,f)})};function wt(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 vn(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 xe=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,}))$/),sr=t=>!!t&&typeof t=="string"&&t.length>=Gs,pn=t=>!!t&&typeof t=="string",oa=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),ar={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},ua=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Be(t);return $e({schema:{context:{},events:{}},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:$({error:i=>be}),saveRequestError:$({error:(i,{data:{error:s}})=>s}),reportError:K(i=>({type:"ERROR",error:i.error})),reportSuccess:K("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!xe(s)},services:{requestChange:async(i,{email:s,options:a})=>(await n.post("/user/email/change",{newEmail:s,options:X(e,a)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},ca=({backendUrl:t,interpreter:e})=>{const r=Be(t);return $e({schema:{context:{},events:{}},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:$({error:n=>ir}),saveRequestError:$({error:(n,{data:{error:i}})=>i}),reportError:K(n=>({type:"ERROR",error:n.error})),reportSuccess:K("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!sr(i)},services:{requestChange:(n,{password:i})=>r.post("/user/password",{newPassword:i},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},la=({backendUrl:t,clientUrl:e})=>{const r=Be(t);return $e({schema:{context:{},events:{}},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:$({error:n=>be}),saveRequestError:$({error:(n,{data:{error:i}})=>i}),reportError:K(n=>({type:"ERROR",error:n.error})),reportSuccess:K("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!xe(i)},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:X(e,s)})}})},fa=({backendUrl:t,clientUrl:e})=>{const r=Be(t);return $e({schema:{context:{},events:{}},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:$({error:n=>be}),saveRequestError:$({error:(n,{data:{error:i}})=>i}),reportError:K(n=>({type:"ERROR",error:n.error})),reportSuccess:K("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!xe(i)},services:{request:async(n,{email:i,options:s})=>(await r.post("/user/email/send-verification-email",{email:i,options:X(e,s)})).data}})},da=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:a,autoRefreshToken:o=!0,autoSignIn:c=!0})=>{const f=r||sa(i,s),u=n||aa(i,s),v=Be(t),d=async(l,h,p)=>(await v.post(l,h,p)).data;return $e({schema:{context:{},events:{}},tsTypes:{},context:ar,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_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"}}}}}}},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:K("SIGNED_IN"),reportSignedOut:K("SIGNED_OUT"),reportTokenChanged:K("TOKEN_CHANGED"),clearContext:$(()=>(u(yt,null),u(pt,null),ne({},ar))),clearContextExceptRefreshToken:$(({refreshToken:{value:l}})=>(u(yt,null),Me(ne({},ar),{refreshToken:{value:l}}))),saveSession:$({user:(l,{data:h})=>{var p;return(p=h==null?void 0:h.session)==null?void 0:p.user},accessToken:(l,{data:h})=>{var p,y;if(h.session.accessTokenExpiresIn){const E=new Date(Date.now()+h.session.accessTokenExpiresIn*1e3).toISOString();u(yt,E)}else u(yt,null);return{value:(p=h==null?void 0:h.session)==null?void 0:p.accessToken,expiresAt:new Date(Date.now()+((y=h==null?void 0:h.session)==null?void 0:y.accessTokenExpiresIn)*1e3)}},refreshToken:(l,{data:h})=>{var p;return u(pt,h.session.refreshToken),{value:(p=h==null?void 0:h.session)==null?void 0:p.refreshToken}}}),saveMfaTicket:$({mfa:(l,h)=>{var p;return(p=h.data)==null?void 0:p.mfa}}),resetTimer:$({refreshTimer:(l,h)=>({startedAt:new Date,attempts:0,lastAttempt:null})}),saveRefreshAttempt:$({refreshTimer:(l,h)=>({startedAt:l.refreshTimer.startedAt,attempts:l.refreshTimer.attempts+1,lastAttempt:new Date})}),saveAuthenticationError:$({errors:({errors:l},{data:{error:h}})=>Me(ne({},l),{authentication:h})}),resetErrors:$({errors:l=>({})}),saveRegistrationError:$({errors:({errors:l},{data:{error:h}})=>Me(ne({},l),{registration:h})}),destroyRefreshToken:$({refreshToken:l=>(u(pt,null),{value:null})}),cleanUrl:()=>{c&&wt("refreshToken")&&(vn("refreshToken"),vn("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:()=>!o,refreshTimerShouldRefresh:l=>{const{expiresAt:h}=l.accessToken;return h?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>Js*1e3:a&&Date.now()-l.refreshTimer.startedAt.getTime()>a*1e3?!0:h.getTime()-Date.now()-1e3*Ws<=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})=>xe(h)?sr(p)?d("/signin/email-password",{email:h,password:p}):Promise.reject({error:ir}):Promise.reject({error:be}),passwordlessSms:(l,{phoneNumber:h,options:p})=>{var y;return pn(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:X(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}})):d("/signin/passwordless/sms",{phoneNumber:h,options:X(e,p)}):Promise.reject({error:dn})},passwordlessSmsOtp:(l,{phoneNumber:h,otp:p})=>pn(h)?d("/signin/passwordless/sms/otp",{phoneNumber:h,otp:p}):Promise.reject({error:dn}),passwordlessEmail:(l,{email:h,options:p})=>{var y;return xe(h)?(y=l.user)!=null&&y.isAnonymous?d("/user/deanonymize",{signInMethod:"passwordless",connection:"email",email:h,options:X(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signin/passwordless/email",{email:h,options:X(e,p)}):Promise.reject({error:be})},signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,h)=>{var p;const y=h.ticket||((p=l.mfa)==null?void 0:p.ticket);return y?oa(y)?d("/signin/mfa/totp",{ticket:y,otp:h.otp}):Promise.reject({error:Ys}):Promise.reject({error:Qs})},refreshToken:async(l,h)=>{const p=h.type==="TRY_TOKEN"?h.token:l.refreshToken.value;return{session:await d("/token",{refreshToken:p})}},signout:(l,h)=>d("/signout",{refreshToken:l.refreshToken.value,all:!!h.all}),signUpEmailPassword:async(l,{email:h,password:p,options:y})=>{var E;return xe(h)?sr(p)?(E=l.user)!=null&&E.isAnonymous?d("/user/deanonymize",{signInMethod:"email-password",email:h,password:p,options:X(e,y)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signup/email-password",{email:h,password:p,options:X(e,y)}):Promise.reject({error:ir}):Promise.reject({error:be})},importRefreshToken:async()=>{let l=null;if(c){const p=wt("refreshToken")||null;if(p)try{return{session:await d("/token",{refreshToken:p})}}catch(y){l=y.error}else{const y=wt("error");if(y)return Promise.reject({error:{status:ie,error:y,message:wt("errorDescription")||y}})}}const h=await f(pt);if(h)try{return{session:await d("/token",{refreshToken:h})}}catch(p){l=p.error}return Promise.reject({error:l})}}})};class ha{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:a=!0,backendUrl:o,clientUrl:c,devTools:f}=r,u=fn(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl","devTools"]);if(this._subscriptions=new Set,this.backendUrl=o,this.clientUrl=c,this.machine=da(Me(ne({},u),{backendUrl:o,clientUrl:c,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),a&&(this.interpreter=he(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 va=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})})}),pa=async(t,e)=>new Promise(r=>{t.send("REQUEST",{password:e}),t.onTransition(n=>{n.matches({idle:"error"})?r({error:n.context.error,isError:!0,isSuccess:!1}):n.matches({idle:"success"})&&r({error:null,isError:!1,isSuccess:!0})})}),ya=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})})}),ma=(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})})}),ga=t=>new Promise(e=>{const{changed:r}=t.send("SIGNIN_ANONYMOUS");r||e({isSuccess:!1,isError:!0,error:Oe,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})})}),Ea=(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:Oe,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:s.user});t.onTransition(a=>{a.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,needsMfaOtp:!1,mfa:null,user:null}):a.matches({authentication:{signedOut:"needsMfa"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!0,mfa:a.context.mfa,user:null}):a.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:a.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:null}):a.matches({authentication:"signedIn"})&&n({accessToken:a.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:a.context.user})})}),yn=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_EMAIL",{email:e,options:r});if(!i)return n({error:Oe,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})})}),mn=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_SMS",{phoneNumber:e,options:r});if(!i)return n({error:Oe,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})})}),wa=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_SMS_OTP",{phoneNumber:e,otp:r});if(!i)return n({error:Oe,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({authentication:{signedOut:"failed"}})&&n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null,accessToken:null})})}),Sa=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:ea});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})})}),gn=(t,e,r,n)=>new Promise(i=>{const{changed:s,context:a}=t.send("SIGNUP_EMAIL_PASSWORD",{email:e,password:r,options:n});if(!s)return i({error:Oe,accessToken:a.accessToken.value,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:a.user});t.onTransition(o=>{o.matches("registration.incomplete.failed")?i({accessToken:null,error:o.context.errors.registration||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):o.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?i({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):o.matches({authentication:"signedIn",registration:"complete"})&&i({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:o.context.user})})});var Ta=Object.defineProperty,ba=Object.defineProperties,Oa=Object.getOwnPropertyDescriptors,En=Object.getOwnPropertySymbols,xa=Object.prototype.hasOwnProperty,_a=Object.prototype.propertyIsEnumerable,wn=(t,e,r)=>e in t?Ta(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,or=(t,e)=>{for(var r in e||(e={}))xa.call(e,r)&&wn(t,r,e[r]);if(En)for(var r of En(e))_a.call(e,r)&&wn(t,r,e[r]);return t},ur=(t,e)=>ba(t,Oa(e));const Ra=()=>typeof window!="undefined",St=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},Tt=({accessToken:t,isError:e,user:r,error:n})=>e?{session:null,error:n}:r&&t?{session:{accessToken:t,accessTokenExpiresIn:0,refreshToken:"TODO",user:r},error:null}:{session:null,error:null};class Aa{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:a,clientStorageGetter:o,clientStorageSetter:c,refreshIntervalTime:f,start:u=!0}){var v;this._client=new ha({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:a,clientStorageGetter:o,clientStorageSetter:c,refreshIntervalTime:f})}async signUp({email:e,password:r,options:n}){const i=await this.waitUntilReady();return Tt(await gn(i,e,r,n))}async signIn(e){const r=await this.waitUntilReady();if("provider"in e){const{provider:i,options:s}=e,a=hn(`${this._client.backendUrl}/signin/provider/${i}`,X(this._client.clientUrl,s));return Ra()&&(window.location.href=a),{providerUrl:a,provider:i,session:null,mfa:null,error:null}}if("email"in e&&"password"in e){const i=await Ea(r,e.email,e.password);return i.needsEmailVerification?{session:null,mfa:null,error:ta}:i.needsMfaOtp?{session:null,mfa:i.mfa,error:null}:ur(or({},Tt(i)),{mfa:null})}if("email"in e&&!("otp"in e)){const{error:i}=await yn(r,e.email);return{session:null,mfa:null,error:i}}if("phoneNumber"in e&&!("otp"in e)){const{error:i}=await mn(r,e.phoneNumber,e.options);return{error:i,mfa:null,session:null}}if("otp"in e){const i=await wa(r,e.phoneNumber,e.otp);return ur(or({},Tt(i)),{mfa:null})}const n=await ga(r);return ur(or({},Tt(n)),{mfa:null})}async signOut(e){const r=await this.waitUntilReady(),{error:n}=await Sa(r,e==null?void 0:e.all);return{error:n}}async resetPassword({email:e,options:r}){const n=he(la(this._client)).start(),{error:i}=await ya(n,e,r);return{error:i}}async changePassword({newPassword:e}){const r=he(ca(this._client)).start(),{error:n}=await pa(r,e);return{error:n}}async sendVerificationEmail({email:e,options:r}){const n=he(fa(this._client)).start(),{error:i}=await ma(n,e,r);return{error:i}}async changeEmail({newEmail:e,options:r}){const n=he(ua(this._client)).start(),{error:i}=await va(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 yn(r,e.email,e.options);return{error:n}}if(e.connection==="sms"){const{error:n}=await mn(r,e.phoneNumber,e.options);return{error:n}}}if(e.signInMethod==="email-password"){const{error:n}=await gn(r,e.email,e.password,e.options);return{error:n}}throw Error("Unknown deanonymization method")}onTokenChanged(e){const r=n=>n.onTransition(({event:i,context:s})=>{i.type==="TOKEN_CHANGED"&&e(St(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,St(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?kn(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:Xs});const{changed:s}=r.send("TRY_TOKEN",{token:i});if(!s)return n({session:null,error:Zs});r.onTransition(a=>{a.matches({token:{idle:"error"}})?n({session:null,error:ra}):a.event.type==="TOKEN_CHANGED"&&n({session:St(a.context),error:null})})})}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return St((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(a=>{if(!a.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 Pa=Object.defineProperty,ka=Object.defineProperties,Ia=Object.getOwnPropertyDescriptors,Sn=Object.getOwnPropertySymbols,Na=Object.prototype.hasOwnProperty,Ca=Object.prototype.propertyIsEnumerable,Tn=(t,e,r)=>e in t?Pa(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qe=(t,e)=>{for(var r in e||(e={}))Na.call(e,r)&&Tn(t,r,e[r]);if(Sn)for(var r of Sn(e))Ca.call(e,r)&&Tn(t,r,e[r]);return t},bn=(t,e)=>ka(t,Ia(e));class Da{constructor({url:e}){this.url=e,this.httpClient=dt.create({baseURL:this.url})}async upload(e){try{return{fileMetadata:(await this.httpClient.post("/files",e.file,{headers:bn(qe(qe({},this.generateUploadHeaders(e)),this.generateAuthHeaders()),{"Content-Type":"multipart/form-data"})})).data,error:null}}catch(r){return{fileMetadata:null,error:r}}}async getPresignedUrl(e){try{const{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:qe({},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:qe({},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 Da({url:e}),this.setAdminSecret(r)}async upload(e){const r=new FormData;r.append("file",e.file);const{fileMetadata:n,error:i}=await this.api.upload(bn(qe({},e),{file: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 On{constructor(e){const{url:r,adminSecret:n}=e;this.accessToken=null,this.adminSecret=n,this.instance=dt.create({baseURL:r})}async call(e,r,n){const i=ue(ue({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,cr(ue({},n),{headers:i}))}catch(a){if(a instanceof Error)return{res:null,error:a}}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 xn{constructor(e){const{url:r,adminSecret:n}=e;this.url=r,this.accessToken=null,this.adminSecret=n,this.instance=dt.create({baseURL:r})}async request(e,r,n){const i=ue(ue({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);try{const s="",o=(await this.instance.post("",{operationName:s||void 0,query:typeof e=="string"?e:j.print(e),variables:r},cr(ue({},n),{headers:i}))).data,{data:c}=o;return o.errors?{data:null,error:o.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}`}:{}}}class _n{constructor({backendUrl:e,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:c,adminSecret:f,devTools:u,start:v=!0}){var d;if(!e)throw new Error("Please specify a `backendUrl`. Docs: [todo]!");this.auth=new Aa({url:`${e}/v1/auth`,refreshIntervalTime:r,clientStorageGetter:n,clientStorageSetter:i,clientStorage:s,clientStorageType:a,autoRefreshToken:o,autoSignIn:c,start:v}),this.storage=new Ua({url:`${e}/v1/storage`,adminSecret:f}),this.functions=new On({url:`${e}/v1/functions`,adminSecret:f}),this.graphql=new xn({url:`${e}/v1/graphql`,adminSecret:f}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(d=this.auth.client)==null||d.onStart(()=>{this.auth.onAuthStateChanged((l,h)=>{l==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(l=>{this.storage.setAccessToken(l==null?void 0:l.accessToken),this.functions.setAccessToken(l==null?void 0:l.accessToken),this.graphql.setAccessToken(l==null?void 0:l.accessToken)})}),this.devTools=u}}const ja=t=>new _n(t);D.NhostClient=_n,D.NhostFunctionsClient=On,D.NhostGraphqlClient=xn,D.createClient=ja,Object.defineProperties(D,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
19
19
|
//# sourceMappingURL=nhost-js.umd.js.map
|