@nhost/nhost-js 1.4.9 → 1.4.10
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 +7 -7
- package/umd/nhost-js.umd.js +3 -3
- package/umd/nhost-js.umd.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nhost/nhost-js",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.10",
|
|
4
4
|
"description": "Nhost JavaScript SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@nhost/hasura-auth-js": "1.4.1",
|
|
47
|
-
"@nhost/hasura-storage-js": "0.
|
|
47
|
+
"@nhost/hasura-storage-js": "0.6.0",
|
|
48
48
|
"axios": "^0.27.2",
|
|
49
49
|
"jwt-decode": "^3.1.2",
|
|
50
50
|
"query-string": "^7.0.1"
|
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
"scripts": {
|
|
61
61
|
"dev": "vite build --config ../../config/vite.lib.dev.config.js",
|
|
62
62
|
"build": "run-p build:lib build:umd",
|
|
63
|
-
"build:lib": "vite build
|
|
63
|
+
"build:lib": "vite build",
|
|
64
64
|
"build:umd": "vite build --config ../../config/vite.lib.umd.config.js",
|
|
65
|
-
"e2e": "start-test e2e:backend :
|
|
66
|
-
"ci:test": "vitest run
|
|
65
|
+
"e2e": "start-test e2e:backend http-get://localhost:9695 ci:test",
|
|
66
|
+
"ci:test": "vitest run",
|
|
67
67
|
"e2e:backend": "nhost dev --no-browser",
|
|
68
|
-
"test:watch": "vitest
|
|
69
|
-
"test:coverage": "vitest run --coverage
|
|
68
|
+
"test:watch": "vitest",
|
|
69
|
+
"test:coverage": "vitest run --coverage",
|
|
70
70
|
"prettier": "prettier --check src/",
|
|
71
71
|
"prettier:fix": "prettier --write src/",
|
|
72
72
|
"lint": "eslint . --ext .ts,.tsx",
|
package/umd/nhost-js.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(A,U){typeof exports=="object"&&typeof module!="undefined"?U(exports,require("graphql")):typeof define=="function"&&define.amd?define(["exports","graphql"],U):(A=typeof globalThis!="undefined"?globalThis:A||self,U(A["@nhost/nhost-js"]={},A.graphql))})(this,function(A,U){"use strict";var
|
|
1
|
+
(function(A,U){typeof exports=="object"&&typeof module!="undefined"?U(exports,require("graphql")):typeof define=="function"&&define.amd?define(["exports","graphql"],U):(A=typeof globalThis!="undefined"?globalThis:A||self,U(A["@nhost/nhost-js"]={},A.graphql))})(this,function(A,U){"use strict";var Wo=Object.defineProperty,Jo=Object.defineProperties;var Ko=Object.getOwnPropertyDescriptors;var At=Object.getOwnPropertySymbols;var kn=Object.prototype.hasOwnProperty,In=Object.prototype.propertyIsEnumerable;var Pn=(A,U,j)=>U in A?Wo(A,U,{enumerable:!0,configurable:!0,writable:!0,value:j}):A[U]=j,le=(A,U)=>{for(var j in U||(U={}))kn.call(U,j)&&Pn(A,j,U[j]);if(At)for(var j of At(U))In.call(U,j)&&Pn(A,j,U[j]);return A},dr=(A,U)=>Jo(A,Ko(U));var Nn=(A,U)=>{var j={};for(var J in A)kn.call(A,J)&&U.indexOf(J)<0&&(j[J]=A[J]);if(A!=null&&At)for(var J of At(A))U.indexOf(J)<0&&In.call(A,J)&&(j[J]=A[J]);return j};function j(t){this.message=t}j.prototype=new Error,j.prototype.name="InvalidCharacterError";var J=typeof window!="undefined"&&window.atob&&window.atob.bind(window)||function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new j("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,n,i=0,s=0,o="";n=e.charAt(s++);~n&&(r=i%4?64*r+n:n,i++%4)?o+=String.fromCharCode(255&r>>(-2*i&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return o};function Cn(t){var e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw"Illegal base64url string!"}try{return function(r){return decodeURIComponent(J(r).replace(/(.)/g,function(n,i){var s=i.charCodeAt(0).toString(16).toUpperCase();return s.length<2&&(s="0"+s),"%"+s}))}(e)}catch{return J(e)}}function Ve(t){this.message=t}function Dn(t,e){if(typeof t!="string")throw new Ve("Invalid token specified");var r=(e=e||{}).header===!0?0:1;try{return JSON.parse(Cn(t.split(".")[r]))}catch(n){throw new Ve("Invalid token specified: "+n.message)}}Ve.prototype=new Error,Ve.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
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
PERFORMANCE OF THIS SOFTWARE.
|
|
14
14
|
***************************************************************************** */var y=function(){return y=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},y.apply(this,arguments)};function Pt(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=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}function D(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return t.concat(s||Array.prototype.slice.call(e))}var P;(function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"})(P||(P={}));var Ae;(function(t){t.Parent="#_parent",t.Internal="#_internal"})(Ae||(Ae={}));var kt=P.Start,It=P.Stop,ze=P.Raise,Ge=P.Send,hr=P.Cancel,Un=P.NullEvent,Nt=P.Assign;P.After,P.DoneState;var vr=P.Log,$n=P.Init,Ct=P.Invoke;P.ErrorExecution;var pr=P.ErrorPlatform,jn=P.ErrorCustom,mr=P.Update,Ln=P.Choose,Mn=P.Pure,yr=".",gr={},Dt="xstate.guard",Bn="",Pe=!0,We;function Ut(t,e,r){r===void 0&&(r=yr);var n=ke(t,r),i=ke(e,r);return _(i)?_(n)?i===n:!1:_(n)?n in i:Object.keys(n).every(function(s){return s in i?Ut(n[s],i[s]):!1})}function Er(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 $t(t,e){try{return fe(t)?t:t.toString().split(e)}catch{throw new Error("'".concat(t,"' is not a valid state path."))}}function Fn(t){return typeof t=="object"&&"value"in t&&"context"in t&&"event"in t&&"_event"in t}function ke(t,e){if(Fn(t))return t.value;if(fe(t))return Je(t);if(typeof t!="string")return t;var r=$t(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 wr(t,e,r){var n,i,s={};try{for(var o=O(Object.keys(t)),a=o.next();!a.done;a=o.next()){var c=a.value,f=t[c];!r(f)||(s[c]=e(f,c,t))}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}var qn=function(t){return function(e){var r,n,i=e;try{for(var s=O(t),o=s.next();!o.done;o=s.next()){var a=o.value;i=i[a]}}catch(c){r={error:c}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(r)throw r.error}}return i}};function Hn(t,e){return function(r){var n,i,s=r;try{for(var o=O(t),a=o.next();!a.done;a=o.next()){var c=a.value;s=s[e][c]}}catch(f){n={error:f}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}}function Ke(t){if(!t)return[[]];if(_(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]]:Ke(t[r]).map(function(i){return[r].concat(i)})}));return e}function N(t){var e;return(e=[]).concat.apply(e,D([],R(t),!1))}function Sr(t){return fe(t)?t:[t]}function K(t){return t===void 0?[]:Sr(t)}function Ye(t,e,r){var n,i;if(k(t))return t(e,r.data);var s={};try{for(var o=O(Object.keys(t)),a=o.next();!a.done;a=o.next()){var c=a.value,f=t[c];k(f)?s[c]=f(e,r.data):s[c]=f}}catch(u){n={error:u}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}return s}function Vn(t){return/^(done|error)\./.test(t)}function Tr(t){return!!(t instanceof Promise||t!==null&&(k(t)||typeof t=="object")&&k(t.then))}function zn(t){return t!==null&&typeof t=="object"&&"transition"in t&&typeof t.transition=="function"}function br(t,e){var r,n,i=R([[],[]],2),s=i[0],o=i[1];try{for(var a=O(t),c=a.next();!c.done;c=a.next()){var f=c.value;e(f)?s.push(f):o.push(f)}}catch(u){r={error:u}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}return[s,o]}function Or(t,e){return Ie(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:Or(r,i)}}})}function Gn(t,e){return{current:e,states:Or(t,e)}}function xr(t,e,r,n){var i=t&&r.reduce(function(s,o){var a,c,f=o.assignment,u={state:n,action:o,_event:e},v={};if(k(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]=k(p)?p(s,e.data,u):p}}catch(m){a={error:m}}finally{try{l&&!l.done&&(c=d.return)&&c.call(d)}finally{if(a)throw a.error}}return Object.assign({},s,v)},t);return i}var Ne=function(){};function fe(t){return Array.isArray(t)}function k(t){return typeof t=="function"}function _(t){return typeof t=="string"}function _r(t,e){if(!!t)return _(t)?{type:Dt,name:t,predicate:e?e[t]:void 0}:k(t)?{type:Dt,name:t.name,predicate:t}:t}function Wn(t){try{return"subscribe"in t&&k(t.subscribe)}catch{return!1}}var re=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();We={},We[re]=function(){return this},We[Symbol.observable]=function(){return this};function ae(t){return!!t&&"__xstatenode"in t}function Jn(t){return!!t&&typeof t.send=="function"}function jt(t,e){return _(t)||typeof t=="number"?y({type:t},e):t}function q(t,e){if(!_(t)&&"$$type"in t&&t.$$type==="scxml")return t;var r=jt(t);return y({name:r.type,data:r,$$type:"scxml",type:"external"},e)}function de(t,e){var r=Sr(e).map(function(n){return typeof n=="undefined"||typeof n=="string"||ae(n)?{target:n,event:t}:y(y({},n),{event:t})});return r}function Kn(t){if(!(t===void 0||t===Bn))return K(t)}function Rr(t,e,r,n,i){var s=t.options.guards,o={state:i,cond:e,_event:n};if(e.type===Dt)return((s==null?void 0:s[e.name])||e.predicate)(r,n.data,o);var a=s==null?void 0:s[e.type];if(!a)throw new Error("Guard '".concat(e.type,"' is not implemented on machine '").concat(t.id,"'."));return a(r,n.data,o)}function Ar(t){return typeof t=="string"?{type:t}:t}function Lt(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=q({type:$n});function Mt(t,e){return e&&e[t]||void 0}function Ce(t,e){var r;if(_(t)||typeof t=="number"){var n=Mt(t,e);k(n)?r={type:t,exec:n}:n?r=n:r={type:t,exec:void 0}}else if(k(t))r={type:t.name||t.toString(),exec:t};else{var n=Mt(t.type,e);if(k(n))r=y(y({},t),{exec:n});else if(n){var i=n.type||t.type;r=y(y(y({},n),t),{type:i})}else r=t}return r}var Ze=function(t,e){if(!t)return[];var r=fe(t)?t:[t];return r.map(function(n){return Ce(n,e)})};function Bt(t){var e=Ce(t);return y(y({id:_(t)?t:e.id},e),{type:e.type})}function Yn(t){return _(t)?{type:ze,event:t}:Ft(t,{to:Ae.Internal})}function Qn(t){return{type:ze,_event:q(t.event)}}function Ft(t,e){return{to:e?e.to:void 0,type:Ge,event:k(t)?t:jt(t),delay:e?e.delay:void 0,id:e&&e.id!==void 0?e.id:k(t)?t.name:Er(t)}}function Xn(t,e,r,n){var i={_event:r},s=q(k(t.event)?t.event(e,r.data,i):t.event),o;if(_(t.delay)){var a=n&&n[t.delay];o=k(a)?a(e,r.data,i):a}else o=k(t.delay)?t.delay(e,r.data,i):t.delay;var c=k(t.to)?t.to(e,r.data,i):t.to;return y(y({},t),{to:c,_event:s,event:s.data,delay:o})}var Zn=function(t,e,r){return y(y({},t),{value:_(t.expr)?t.expr:t.expr(e,r.data,{_event:r})})},ei=function(t){return{type:hr,sendId:t}};function ti(t){var e=Bt(t);return{type:P.Start,activity:e,exec:void 0}}function ri(t){var e=k(t)?t:Bt(t);return{type:P.Stop,activity:e,exec:void 0}}function ni(t,e,r){var n=k(t.activity)?t.activity(e,r.data):t.activity,i=typeof n=="string"?{id:n}:n,s={type:P.Stop,activity:i};return s}var ii=function(t){return{type:Nt,assignment:t}};function si(t,e){var r=e?"#".concat(e):"";return"".concat(P.After,"(").concat(t,")").concat(r)}function et(t,e){var r="".concat(P.DoneState,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function tt(t,e){var r="".concat(P.DoneInvoke,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function De(t,e){var r="".concat(P.ErrorPlatform,".").concat(t),n={type:r,data:e};return n.toString=function(){return r},n}function qt(t,e,r,n,i,s){s===void 0&&(s=!1);var o=R(s?[[],i]:br(i,function(d){return d.type===Nt}),2),a=o[0],c=o[1],f=a.length?xr(r,n,a,e):r,u=s?[r]:void 0,v=N(c.map(function(d){var l;switch(d.type){case ze:return Qn(d);case Ge:var h=Xn(d,f,n,t.options.delays);return h;case vr:return Zn(d,f,n);case Ln:{var p=d,m=(l=p.conds.find(function(C){var F=_r(C.cond,t.options.guards);return!F||Rr(t,F,f,n,e)}))===null||l===void 0?void 0:l.actions;if(!m)return[];var E=R(qt(t,e,f,n,Ze(K(m),t.options.actions),s),2),g=E[0],S=E[1];return f=S,u==null||u.push(f),g}case Mn:{var m=d.get(f,n.data);if(!m)return[];var I=R(qt(t,e,f,n,Ze(K(m),t.options.actions),s),2),x=I[0],$=I[1];return f=$,u==null||u.push(f),x}case It:return ni(d,f,n);case Nt:{f=xr(f,n,[d],e),u==null||u.push(f);break}default:var T=Ce(d,t.options.actions),w=T.exec;if(w&&u){var b=u.length-1;T=y(y({},T),{exec:function(C){for(var F=[],G=1;G<arguments.length;G++)F[G-1]=arguments[G];w.apply(void 0,D([u[b]],R(F),!1))}})}return T}}).filter(function(d){return!!d}));return[v,f]}var Ue=function(t,e){var r=e(t);return r};function Pr(t){var e;return e={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:t}}},e[re]=function(){return this},e}function oi(t,e,r,n){var i,s=Ar(t.src),o=(i=e==null?void 0:e.options.services)===null||i===void 0?void 0:i[s.type],a=t.data?Ye(t.data,r,n):void 0,c=o?ai(o,t.id,a):Pr(t.id);return c.meta=t,c}function ai(t,e,r){var n=Pr(e);if(n.deferred=!0,ae(t)){var i=n.state=Ue(void 0,function(){return(r?t.withContext(r):t).initialState});n.getSnapshot=function(){return i}}return n}function ui(t){try{return typeof t.send=="function"}catch{return!1}}function ci(t){return ui(t)&&"id"in t}function li(t){var e;return y((e={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},e[re]=function(){return this},e),t)}var rt=function(t){return t.type==="atomic"||t.type==="final"};function he(t){return Object.keys(t.states).map(function(e){return t.states[e]}).filter(function(e){return e.type!=="history"})}function kr(t){var e=[t];return rt(t)?e:e.concat(N(he(t).map(kr)))}function ve(t,e){var r,n,i,s,o,a,c,f,u=new Set(t),v=Ht(u),d=new Set(e);try{for(var l=O(d),h=l.next();!h.done;h=l.next())for(var p=h.value,m=p.parent;m&&!d.has(m);)d.add(m),m=m.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=Ht(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(C){return d.add(C)}):p.initialStateNodes.forEach(function(C){return d.add(C)});else if(p.type==="parallel")try{for(var I=(o=void 0,O(he(p))),x=I.next();!x.done;x=I.next()){var $=x.value;d.has($)||(d.add($),v.get($)?v.get($).forEach(function(C){return d.add(C)}):$.initialStateNodes.forEach(function(C){return d.add(C)}))}}catch(C){o={error:C}}finally{try{x&&!x.done&&(a=I.return)&&a.call(I)}finally{if(o)throw o.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,m=p.parent;m&&!d.has(m);)d.add(m),m=m.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 Ir(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]=Ir(s,e)}),i}function Ht(t){var e,r,n=new Map;try{for(var i=O(t),s=i.next();!s.done;s=i.next()){var o=s.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(a){e={error:a}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return n}function fi(t,e){var r=ve([t],e);return Ir(t,Ht(r))}function nt(t,e){return Array.isArray(t)?t.some(function(r){return r===e}):t instanceof Set?t.has(e):!1}function di(t){return D([],R(new Set(N(D([],R(t.map(function(e){return e.ownEvents})),!1)))),!1)}function $e(t,e){return e.type==="compound"?he(e).some(function(r){return r.type==="final"&&nt(t,r)}):e.type==="parallel"?he(e).every(function(r){return $e(t,r)}):!1}function hi(t){return t===void 0&&(t=[]),t.reduce(function(e,r){return r.meta!==void 0&&(e[r.id]=r.meta),e},{})}function Nr(t){return new Set(N(t.map(function(e){return e.tags})))}function Cr(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 Cr(t[i],e[i])})}function vi(t){return typeof t!="object"||t===null?!1:"value"in t&&"_event"in t}function pi(t,e){var r=t.exec,n=y(y({},t),{exec:r!==void 0?function(){return r(e.context,e.event,{action:t,state:e,_event:e._event})}:void 0});return n}var ee=function(){function t(e){var r=this,n;this.actions=[],this.activities=gr,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||gr,this.meta=hi(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 di(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="."),_(e))return[e];var i=Object.keys(e);return i.concat.apply(i,D([],R(i.map(function(s){return n.toStrings(e[s],r).map(function(o){return s+r+o})})),!1))},t.prototype.toJSON=function(){var e=this;e.configuration,e.transitions;var r=e.tags;e.machine;var n=Pt(e,["configuration","transitions","tags","machine"]);return y(y({},n),{tags:Array.from(r)})},t.prototype.matches=function(e){return Ut(e,this.value)},t.prototype.hasTag=function(e){return this.tags.has(e)},t.prototype.can=function(e){var r;Ne(!!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}(),mi={deferEvents:!1},Dr=function(){function t(e){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=y(y({},mi),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}(),Vt=new Map,yi=0,it={bookId:function(){return"x:".concat(yi++)},register:function(t,e){return Vt.set(t,e),t},get:function(t){return Vt.get(t)},free:function(t){Vt.delete(t)}};function zt(){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 gi(){var t=zt();if(t&&"__xstate__"in t)return t.__xstate__}function Ei(t){if(!!zt()){var e=gi();e&&e.register(t)}}function wi(t,e){e===void 0&&(e={});var r=t.initialState,n=new Set,i=[],s=!1,o=function(){if(!s){for(s=!0;i.length>0;){var f=i.shift();r=t.transition(r,f,c),n.forEach(function(u){return u.next(r)})}s=!1}},a=li({id:e.id,send:function(f){i.push(f),o()},getSnapshot:function(){return r},subscribe:function(f,u,v){var d=Lt(f,u,v);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),c={parent:e.parent,self:a,id:e.id||"anonymous",observers:n};return r=t.start?t.start(c):r,a}var Si={sync:!1,autoForward:!1},H;(function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"})(H||(H={}));var Ti=function(){function t(e,r){var n=this;r===void 0&&(r=t.defaultOptions),this.machine=e,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=H.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(u,v){if(fe(u))return n.batch(u),n.state;var d=q(jt(u,v));if(n.status===H.Stopped)return n.state;if(n.status!==H.Running&&!n.options.deferEvents)throw new Error('Event "'.concat(d.name,'" was sent to uninitialized service "').concat(n.machine.id,`". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
|
|
15
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===Ae.Parent||n.parent.id===v),l=d?n.parent:_(v)?n.children.get(v)||it.get(v):Jn(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(y(y({},u),{name:u.name===jn?"".concat(De(n.id)):u.name,origin:n.sessionId})):l.send(u.data)};var i=y(y({},t.defaultOptions),r),s=i.clock,o=i.logger,a=i.parent,c=i.id,f=c!==void 0?c:e.id;this.id=f,this.logger=o,this.clock=s,this.parent=a,this.options=i,this.scheduler=new Dr({deferEvents:this.options.deferEvents}),this.sessionId=it.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var e=this;return this._initialState?this._initialState:Ue(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),o=s.next();!o.done;o=s.next()){var a=o.value;this.exec(a,e,r)}}catch(c){n={error:c}}finally{try{o&&!o.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}},t.prototype.update=function(e,r){var n,i,s,o,a,c,f,u,v=this;if(e._sessionid=this.sessionId,this._state=e,this.options.execute&&this.execute(this.state),this.children.forEach(function(b){v.state.children[b.id]=b}),this.devTools&&this.devTools.send(r.data,e),e.event)try{for(var d=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),m=p.next();!m.done;m=p.next()){var h=m.value;h(e,e.event)}}catch(b){s={error:b}}finally{try{m&&!m.done&&(o=p.return)&&o.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){a={error:b}}finally{try{g&&!g.done&&(c=E.return)&&c.call(E)}finally{if(a)throw a.error}}var I=$e(e.configuration||[],this.machine);if(this.state.configuration&&I){var x=e.configuration.find(function(b){return b.type==="final"&&b.parent===v.machine}),$=x&&x.doneData?Ye(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(tt(this.id,$))}}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===H.Running&&e(this.state,this.state.event),this},t.prototype.subscribe=function(e,r,n){var i=this;if(!e)return{unsubscribe:function(){}};var s,o=n;return typeof e=="function"?s=e:(s=e.next.bind(e),o=e.complete.bind(e)),this.listeners.add(s),this.status!==H.NotStarted&&s(this.state),o&&(this.status===H.Stopped?o():this.onDone(o)),{unsubscribe:function(){s&&i.listeners.delete(s),o&&i.doneListeners.delete(o)}}},t.prototype.onEvent=function(e){return this.eventListeners.add(e),this},t.prototype.onSend=function(e){return this.sendListeners.add(e),this},t.prototype.onChange=function(e){return this.contextListeners.add(e),this},t.prototype.onStop=function(e){return this.stopListeners.add(e),this},t.prototype.onDone=function(e){return this.doneListeners.add(e),this},t.prototype.off=function(e){return this.listeners.delete(e),this.eventListeners.delete(e),this.sendListeners.delete(e),this.stopListeners.delete(e),this.doneListeners.delete(e),this.contextListeners.delete(e),this},t.prototype.start=function(e){var r=this;if(this.status===H.Running)return this;this.machine._init(),it.register(this.sessionId,this),this.initialized=!0,this.status=H.Running;var n=e===void 0?this.initialState:Ue(this,function(){return vi(e)?r.machine.resolveState(e):r.machine.resolveState(ee.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,o,a,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),m=p.next();!m.done;m=p.next()){var h=m.value;h(),this.stopListeners.delete(h)}}catch(w){n={error:w}}finally{try{m&&!m.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&&(o=E.return)&&o.call(E)}finally{if(s)throw s.error}}try{for(var S=O(this.doneListeners),I=S.next();!I.done;I=S.next()){var h=I.value;this.doneListeners.delete(h)}}catch(w){a={error:w}}finally{try{I&&!I.done&&(c=S.return)&&c.call(S)}finally{if(a)throw a.error}}if(!this.initialized)return this;D([],R(this.state.configuration),!1).sort(function(w,b){return b.order-w.order}).forEach(function(w){var b,C;try{for(var F=O(w.definition.exit),G=F.next();!G.done;G=F.next()){var oe=G.value;v.exec(oe,v.state)}}catch(Rt){b={error:Rt}}finally{try{G&&!G.done&&(C=F.return)&&C.call(F)}finally{if(b)throw b.error}}}),this.children.forEach(function(w){k(w.stop)&&w.stop()}),this.children.clear();try{for(var x=O(Object.keys(this.delayedEventsMap)),$=x.next();!$.done;$=x.next()){var T=$.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(w){f={error:w}}finally{try{$&&!$.done&&(u=x.return)&&u.call(x)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.scheduler=new Dr({deferEvents:this.options.deferEvents}),this.initialized=!1,this.status=H.Stopped,this._initialState=void 0,it.free(this.sessionId),this},t.prototype.batch=function(e){var r=this;if(!(this.status===H.NotStarted&&this.options.deferEvents)){if(this.status!==H.Running)throw new Error("".concat(e.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'))}this.scheduler.schedule(function(){var n,i,s=r.state,o=!1,a=[],c=function(d){var l=q(d);r.forward(l),s=Ue(r,function(){return r.machine.transition(s,l)}),a.push.apply(a,D([],R(s.actions.map(function(h){return pi(h,s)})),!1)),o=o||!!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=o,s.actions=a,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(pr)===0&&!this.state.nextEvents.some(function(s){return s.indexOf(pr)===0}))throw n.data.data;var i=Ue(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 o=s.value,a=this.children.get(o);if(!a)throw new Error("Unable to forward event '".concat(e,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(o,"'."));a.send(e)}}catch(c){r={error:c}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}},t.prototype.defer=function(e){var r=this;this.delayedEventsMap[e.id]=this.clock.setTimeout(function(){e.to?r.sendTo(e._event,e.to):r.send(e._event)},e.delay)},t.prototype.cancel=function(e){this.clock.clearTimeout(this.delayedEventsMap[e]),delete this.delayedEventsMap[e]},t.prototype.exec=function(e,r,n){n===void 0&&(n=this.machine.options.actions);var i=r.context,s=r._event,o=e.exec||Mt(e.type,n),a=k(o)?o:o?o.exec:e.exec;if(a)try{return a(i,s.data,{action:e,state:this.state,_event:s})}catch(I){throw this.parent&&this.parent.send({type:"xstate.error",data:I}),I}switch(e.type){case Ge: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 hr:this.cancel(e.sendId);break;case kt:{if(this.status!==H.Running)return;var f=e.activity;if(!this.state.activities[f.id||f.type])break;if(f.type===P.Invoke){var u=Ar(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?Ye(l,i,s):void 0;if(typeof v=="string")return;var m=k(v)?v(i,s.data,{data:p,src:u,meta:f.meta}):v;if(!m)return;var E=void 0;ae(m)&&(m=p?m.withContext(p):m,E={autoForward:h}),this.spawn(m,d,E)}else this.spawnActivity(f);break}case It:{this.stopChild(e.activity.id);break}case vr:var g=e.label,S=e.value;g?this.logger(g,S):this.logger(S);break}},t.prototype.removeChild=function(e){var r;this.children.delete(e),this.forwardTo.delete(e),(r=this.state)===null||r===void 0||delete r.children[e]},t.prototype.stopChild=function(e){var r=this.children.get(e);!r||(this.removeChild(e),k(r.stop)&&r.stop())},t.prototype.spawn=function(e,r,n){if(Tr(e))return this.spawnPromise(Promise.resolve(e),r);if(k(e))return this.spawnCallback(e,r);if(ci(e))return this.spawnActor(e,r);if(Wn(e))return this.spawnObservable(e,r);if(ae(e))return this.spawnMachine(e,y(y({},n),{id:r}));if(zn(e))return this.spawnBehavior(e,r);throw new Error('Unable to spawn entity "'.concat(r,'" of type "').concat(typeof e,'".'))},t.prototype.spawnMachine=function(e,r){var n=this;r===void 0&&(r={});var i=new t(e,y(y({},this.options),{parent:this,id:r.id||e.id})),s=y(y({},Si),r);s.sync&&i.onTransition(function(a){n.send(mr,{state:a,id:i.id})});var o=i;return this.children.set(i.id,o),s.autoForward&&this.forwardTo.add(i.id),i.onDone(function(a){n.removeChild(i.id),n.send(q(a,{origin:i.id}))}).start(),o},t.prototype.spawnBehavior=function(e,r){var n=wi(e,{id:r,parent:this});return this.children.set(r,n),n},t.prototype.spawnPromise=function(e,r){var n,i=this,s=!1,o;e.then(function(c){s||(o=c,i.removeChild(r),i.send(q(tt(r,c),{origin:r})))},function(c){if(!s){i.removeChild(r);var f=De(r,c);try{i.send(q(f,{origin:r}))}catch{i.devTools&&i.devTools.send(f,i.state),i.machine.strict&&i.stop()}}});var a=(n={id:r,send:function(){},subscribe:function(c,f,u){var v=Lt(c,f,u),d=!1;return e.then(function(l){d||(v.next(l),!d&&v.complete())},function(l){d||v.error(l)}),{unsubscribe:function(){return d=!0}}},stop:function(){s=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return o}},n[re]=function(){return this},n);return this.children.set(r,a),a},t.prototype.spawnCallback=function(e,r){var n,i=this,s=!1,o=new Set,a=new Set,c,f=function(d){c=d,a.forEach(function(l){return l(d)}),!s&&i.send(q(d,{origin:r}))},u;try{u=e(f,function(d){o.add(d)})}catch(d){this.send(De(r,d))}if(Tr(u))return this.spawnPromise(u,r);var v=(n={id:r,send:function(d){return o.forEach(function(l){return l(d)})},subscribe:function(d){var l=Lt(d);return a.add(l.next),{unsubscribe:function(){a.delete(l.next)}}},stop:function(){s=!0,k(u)&&u()},toJSON:function(){return{id:r}},getSnapshot:function(){return c}},n[re]=function(){return this},n);return this.children.set(r,v),v},t.prototype.spawnObservable=function(e,r){var n,i=this,s,o=e.subscribe(function(c){s=c,i.send(q(c,{origin:r}))},function(c){i.removeChild(r),i.send(q(De(r,c),{origin:r}))},function(){i.removeChild(r),i.send(q(tt(r),{origin:r}))}),a=(n={id:r,send:function(){},subscribe:function(c,f,u){return e.subscribe(c,f,u)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return s},toJSON:function(){return{id:r}}},n[re]=function(){return this},n);return this.children.set(r,a),a},t.prototype.spawnActor=function(e,r){return this.children.set(r,e),e},t.prototype.spawnActivity=function(e){var r=this.machine.options&&this.machine.options.activities?this.machine.options.activities[e.type]:void 0;if(!!r){var n=r(this.state.context,e);this.spawnEffect(e.id,n)}},t.prototype.spawnEffect=function(e,r){var n;this.children.set(e,(n={id:e,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:r||void 0,getSnapshot:function(){},toJSON:function(){return{id:e}}},n[re]=function(){return this},n))},t.prototype.attachDev=function(){var e=zt();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(y(y({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:y({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}Ei(this)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[re]=function(){return this},t.prototype.getSnapshot=function(){return this.status===H.NotStarted?this.initialState:this._state},t.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(e,r){return setTimeout(e,r)},clearTimeout:function(e){return clearTimeout(e)}},logger:console.log.bind(console),devTools:!1},t.interpret=pe,t}();function pe(t,e){var r=new Ti(t,e);return r}function bi(t){if(typeof t=="string"){var e={type:t};return e.toString=function(){return t},e}return t}function st(t){return y(y({type:Ct},t),{toJSON:function(){t.onDone,t.onError;var e=Pt(t,["onDone","onError"]);return y(y({},e),{type:Ct,src:bi(t.src)})}})}var me="",Gt="#",je="*",ye={},ge=function(t){return t[0]===Gt},Oi=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},xi=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===me?"the transient event":"event '".concat(e,"'");Ne(!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.")},_i=function(){function t(e,r,n,i){var s=this;n===void 0&&(n="context"in e?e.context:void 0);var o;this.config=e,this._context=n,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign(Oi(),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:yr),this.id=this.config.id||D([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:(o=this.config.schema)!==null&&o!==void 0?o:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?Ie(this.config.states,function(f,u){var v,d=new t(f,{},void 0,{parent:s,key:u});return Object.assign(s.idMap,y((v={},v[d.id]=d,v),d.idMap)),d}):ye;var a=0;function c(f){var u,v;f.order=a++;try{for(var d=O(he(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===me}):me in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=K(this.config.entry||this.config.onEntry).map(function(f){return Ce(f)}),this.onExit=K(this.config.exit||this.config.onExit).map(function(f){return Ce(f)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=K(this.config.invoke).map(function(f,u){var v,d;if(ae(f)){var l=Qe(s.id,u);return s.machine.options.services=y((v={},v[l]=f,v),s.machine.options.services),st({src:l,id:l})}else if(_(f.src)){var l=f.id||Qe(s.id,u);return st(y(y({},f),{id:l,src:f.src}))}else if(ae(f.src)||k(f.src)){var l=f.id||Qe(s.id,u);return s.machine.options.services=y((d={},d[l]=f.src,d),s.machine.options.services),st(y(y({id:l},f),{src:l}))}else{var h=f.src;return st(y(y({id:Qe(s.id,u)},f),{src:h}))}}),this.activities=K(this.config.activities).concat(this.invoke).map(function(f){return Bt(f)}),this.transition=this.transition.bind(this),this.tags=K(this.config.tags)}return t.prototype._init=function(){this.__cache.transitions||kr(this).forEach(function(e){return e.on})},t.prototype.withConfig=function(e,r){var n=this.options,i=n.actions,s=n.activities,o=n.guards,a=n.services,c=n.delays;return new t(this.config,{actions:y(y({},i),e.actions),activities:y(y({},s),e.activities),guards:y(y({},o),e.guards),services:y(y({},a),e.services),delays:y(y({},c),e.delays)},r!=null?r:this.context)},t.prototype.withContext=function(e){return new t(this.config,this.options,e)},Object.defineProperty(t.prototype,"context",{get:function(){return k(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states: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===me,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,o){var a=k(s)?"".concat(e.id,":delay[").concat(o,"]"):s,c=si(a,e.id);return e.onEntry.push(Ft(c,{delay:s})),e.onExit.push(ei(c)),c},i=fe(r)?r.map(function(s,o){var a=n(s.delay,o);return y(y({},s),{event:a})}):N(Object.keys(r).map(function(s,o){var a=r[s],c=_(a)?{target:a}:a,f=isNaN(+s)?s:+s,u=n(f,o);return K(c).map(function(v){return y(y({},v),{event:u,delay:f})})}));return i.map(function(s){var o=s.delay;return y(y({},e.formatTransition(s)),{delay:o})})},t.prototype.getStateNodes=function(e){var r,n=this;if(!e)return[];var i=e instanceof ee?e.value:ke(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 o=Object.keys(i),a=[this];return a.push.apply(a,D([],R(N(o.map(function(c){return n.getStateNode(c).getStateNodes(i[c])}))),!1)),a},t.prototype.handles=function(e){var r=Er(e);return this.events.includes(r)},t.prototype.resolveState=function(e){var r=e instanceof ee?e:ee.create(e),n=Array.from(ve([],this.getStateNodes(r.value)));return new ee(y(y({},r),{value:this.resolve(r.value),configuration:n,done:$e(n,this),tags:Nr(n),machine:this.machine}))},t.prototype.transitionLeafNode=function(e,r,n){var i=this.getStateNode(e),s=i.next(r,n);return!s||!s.transitions.length?this.next(r,n):s},t.prototype.transitionCompoundNode=function(e,r,n){var i=Object.keys(e),s=this.getStateNode(i[0]),o=s._transition(e[i[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},t.prototype.transitionParallelNode=function(e,r,n){var i,s,o={};try{for(var a=O(Object.keys(e)),c=a.next();!c.done;c=a.next()){var f=c.value,u=e[f];if(!!u){var v=this.getStateNode(f),d=v._transition(u,r,n);d&&(o[f]=d)}}}catch(g){i={error:g}}finally{try{c&&!c.done&&(s=a.return)&&s.call(a)}finally{if(i)throw i.error}}var l=Object.keys(o).map(function(g){return o[g]}),h=N(l.map(function(g){return g.transitions})),p=l.some(function(g){return g.transitions.length>0});if(!p)return this.next(r,n);var m=N(l.map(function(g){return g.entrySet})),E=N(Object.keys(o).map(function(g){return o[g].configuration}));return{transitions:h,entrySet:m,exitSet:N(l.map(function(g){return g.exitSet})),configuration:E,source:r,actions:N(Object.keys(o).map(function(g){return o[g].actions}))}},t.prototype._transition=function(e,r,n){return _(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,o=r.name,a=[],c=[],f;try{for(var u=O(this.getCandidates(o)),v=u.next();!v.done;v=u.next()){var d=v.value,l=d.cond,h=d.in,p=e.context,m=h?_(h)&&ge(h)?e.matches(ke(this.getStateNodeById(h).path,this.delimiter)):Ut(ke(h,this.delimiter),qn(this.path.slice(0,-2))(e.value)):!0,E=!1;try{E=!l||Rr(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(o,"' in state node '").concat(this.id,`':
|
|
16
|
-
`).concat(x.message))}if(E&&m){d.target!==void 0&&(c=d.target),a.push.apply(a,D([],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:a};var g=N(c.map(function(x){return s.getRelativeStateNodes(x,e.historyValue)})),S=!!f.internal,I=S?[]:N(g.map(function(x){return s.nodesFromChild(x)}));return{transitions:[f],entrySet:I,exitSet:S?[]:[this],configuration:g,source:e,actions:a}}},t.prototype.nodesFromChild=function(e){if(e.escapes(this))return[];for(var r=[],n=e;n&&n!==this;)r.push(n),n=n.parent;return r.push(this),r},t.prototype.escapes=function(e){if(this===e)return!1;for(var r=this.parent;r;){if(r===e)return!1;r=r.parent}return!0},t.prototype.getActions=function(e,r,n,i){var s,o,a,c,f=ve([],i?this.getStateNodes(i.value):[this]),u=e.configuration.length?ve(f,e.configuration):f;try{for(var v=O(u),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&&(o=v.return)&&o.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;(!nt(u,l)||nt(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(T){a={error:T}}finally{try{p&&!p.done&&(c=h.return)&&c.call(h)}finally{if(a)throw a.error}}var m=N(e.entrySet.map(function(T){var w=[];if(T.type!=="final")return w;var b=T.parent;if(!b.parent)return w;w.push(et(T.id,T.doneData),et(b.id,T.doneData?Ye(T.doneData,r,n):void 0));var C=b.parent;return C.type==="parallel"&&he(C).every(function(F){return $e(e.configuration,F)})&&w.push(et(C.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([N(Array.from(E).map(function(T){return D(D([],R(T.activities.map(function(w){return ti(w)})),!1),R(T.onEntry),!1)})).concat(m.map(Yn)),N(Array.from(g).map(function(T){return D(D([],R(T.onExit),!1),R(T.activities.map(function(w){return ri(w)})),!1)}))],2),I=S[0],x=S[1],$=Ze(x.concat(e.actions).concat(I),this.machine.options.actions);return $},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=q(r),s;if(e instanceof ee)s=n===void 0?e:this.resolveState(ee.from(e,n));else{var o=_(e)?this.resolve(Je(this.getResolvedPath(e))):this.resolve(e),a=n!=null?n:this.machine.context;s=this.resolveState(ee.from(o,a))}if(!Pe&&i.name===je)throw new Error("An event cannot have the wildcard type ('".concat(je,"')"));if(this.strict&&!this.events.includes(i.name)&&!Vn(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=ve([],this.getStateNodes(s.value)),u=c.configuration.length?ve(f,c.configuration):f;return c.configuration=D([],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,D([],R(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,o,a=this;i===void 0&&(i=Xe);var c=e.configuration,f=!r||e.transitions.length>0,u=f?fi(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?y({},r.activities):{};try{for(var h=O(d),p=h.next();!p.done;p=h.next()){var m=p.value;m.type===kt?l[m.activity.id||m.activity.type]=m:m.type===It&&(l[m.activity.id||m.activity.type]=!1)}}catch(W){s={error:W}}finally{try{p&&!p.done&&(o=h.return)&&o.call(h)}finally{if(s)throw s.error}}var E=R(qt(this,r,n,i,d,this.machine.config.preserveActionOrder),2),g=E[0],S=E[1],I=R(br(g,function(W){return W.type===ze||W.type===Ge&&W.to===Ae.Internal}),2),x=I[0],$=I[1],T=g.filter(function(W){var Re;return W.type===kt&&((Re=W.activity)===null||Re===void 0?void 0:Re.type)===Ct}),w=T.reduce(function(W,Re){return W[Re.activity.id]=oi(Re.activity,a.machine,S,i),W},r?y({},r.children):{}),b=f?e.configuration:r?r.configuration:[],C=$e(b,this),F=new ee({value:u||r.value,context:S,_event:i,_sessionid:r?r._sessionid:null,historyValue:u?v?Gn(v,u):void 0:r?r.historyValue:void 0,history:!u||e.source?r:void 0,actions:u?$:[],activities:u?l:r?r.activities:{},events:[],configuration:b,transitions:e.transitions,children:w,done:C,tags:Nr(b),machine:this}),G=n!==S;F.changed=i.name===mr||G;var oe=F.history;oe&&delete oe.history;var Rt=!C&&(this._transient||c.some(function(W){return W._transient}));if(!f&&(!Rt||i.name===me))return F;var X=F;if(!C)for(Rt&&(X=this.resolveRaisedTransition(X,{type:Un},i));x.length;){var Vo=x.shift();X=this.resolveRaisedTransition(X,Vo._event,i)}var zo=X.changed||(oe?!!X.actions.length||G||typeof oe.value!=typeof X.value||!Cr(X.value,oe.value):void 0);return X.changed=zo,X.history=oe,X},t.prototype.getStateNode=function(e){if(ge(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=ge(e)?e.slice(Gt.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"&&ge(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=$t(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||ye;switch(this.type){case"parallel":return Ie(this.initialStateValue,function(s,o){return s?n.getStateNode(o).resolve(e[o]||s):ye});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?Ie(e,function(s,o){return s?n.getStateNode(o).resolve(s):ye}):this.initialStateValue||{};default:return e||ye}},t.prototype.getResolvedPath=function(e){if(ge(e)){var r=this.machine.idMap[e.slice(Gt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return $t(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=wr(this.states,function(n){return n.initialStateValue||ye},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;_(r.target)?e=ge(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 Pe||Ne(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Ke(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=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:wr(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?N(Ke(i).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var s=Hn(n.path,"states")(e).current;return _(s)?[n.getStateNode(s)]:N(Ke(s).map(function(o){return r.history==="deep"?n.getFromRelativePath(o):[n.states[o[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=N(Object.keys(this.states).map(function(n){return e.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var e,r,n,i;if(this.__cache.events)return this.__cache.events;var s=this.states,o=new Set(this.ownEvents);if(s)try{for(var a=O(Object.keys(s)),c=a.next();!c.done;c=a.next()){var f=c.value,u=s[f];if(u.states)try{for(var v=(n=void 0,O(u.events)),d=v.next();!d.done;d=v.next()){var l=d.value;o.add("".concat(l))}}catch(h){n={error:h}}finally{try{d&&!d.done&&(i=v.return)&&i.call(v)}finally{if(n)throw n.error}}}}catch(h){e={error:h}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!_(n))return n;var i=n[0]===r.delimiter;if(i&&!r.parent)return r.getStateNodeByPath(n.slice(1));var s=i?r.key+n:n;if(r.parent)try{var o=r.parent.getStateNodeByPath(s);return o}catch(a){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
|
|
16
|
+
`).concat(x.message))}if(E&&m){d.target!==void 0&&(c=d.target),a.push.apply(a,D([],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:a};var g=N(c.map(function(x){return s.getRelativeStateNodes(x,e.historyValue)})),S=!!f.internal,I=S?[]:N(g.map(function(x){return s.nodesFromChild(x)}));return{transitions:[f],entrySet:I,exitSet:S?[]:[this],configuration:g,source:e,actions:a}}},t.prototype.nodesFromChild=function(e){if(e.escapes(this))return[];for(var r=[],n=e;n&&n!==this;)r.push(n),n=n.parent;return r.push(this),r},t.prototype.escapes=function(e){if(this===e)return!1;for(var r=this.parent;r;){if(r===e)return!1;r=r.parent}return!0},t.prototype.getActions=function(e,r,n,i){var s,o,a,c,f=ve([],i?this.getStateNodes(i.value):[this]),u=e.configuration.length?ve(f,e.configuration):f;try{for(var v=O(u),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&&(o=v.return)&&o.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;(!nt(u,l)||nt(e.exitSet,l.parent))&&e.exitSet.push(l)}}catch(T){a={error:T}}finally{try{p&&!p.done&&(c=h.return)&&c.call(h)}finally{if(a)throw a.error}}var m=N(e.entrySet.map(function(T){var w=[];if(T.type!=="final")return w;var b=T.parent;if(!b.parent)return w;w.push(et(T.id,T.doneData),et(b.id,T.doneData?Ye(T.doneData,r,n):void 0));var C=b.parent;return C.type==="parallel"&&he(C).every(function(F){return $e(e.configuration,F)})&&w.push(et(C.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([N(Array.from(E).map(function(T){return D(D([],R(T.activities.map(function(w){return ti(w)})),!1),R(T.onEntry),!1)})).concat(m.map(Yn)),N(Array.from(g).map(function(T){return D(D([],R(T.onExit),!1),R(T.activities.map(function(w){return ri(w)})),!1)}))],2),I=S[0],x=S[1],$=Ze(x.concat(e.actions).concat(I),this.machine.options.actions);return $},t.prototype.transition=function(e,r,n){e===void 0&&(e=this.initialState);var i=q(r),s;if(e instanceof ee)s=n===void 0?e:this.resolveState(ee.from(e,n));else{var o=_(e)?this.resolve(Je(this.getResolvedPath(e))):this.resolve(e),a=n!=null?n:this.machine.context;s=this.resolveState(ee.from(o,a))}if(!Pe&&i.name===je)throw new Error("An event cannot have the wildcard type ('".concat(je,"')"));if(this.strict&&!this.events.includes(i.name)&&!Vn(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=ve([],this.getStateNodes(s.value)),u=c.configuration.length?ve(f,c.configuration):f;return c.configuration=D([],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,D([],R(s),!1)),e},t.prototype.resolveTransition=function(e,r,n,i){var s,o,a=this;i===void 0&&(i=Xe);var c=e.configuration,f=!r||e.transitions.length>0,u=f?fi(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?y({},r.activities):{};try{for(var h=O(d),p=h.next();!p.done;p=h.next()){var m=p.value;m.type===kt?l[m.activity.id||m.activity.type]=m:m.type===It&&(l[m.activity.id||m.activity.type]=!1)}}catch(W){s={error:W}}finally{try{p&&!p.done&&(o=h.return)&&o.call(h)}finally{if(s)throw s.error}}var E=R(qt(this,r,n,i,d,this.machine.config.preserveActionOrder),2),g=E[0],S=E[1],I=R(br(g,function(W){return W.type===ze||W.type===Ge&&W.to===Ae.Internal}),2),x=I[0],$=I[1],T=g.filter(function(W){var Re;return W.type===kt&&((Re=W.activity)===null||Re===void 0?void 0:Re.type)===Ct}),w=T.reduce(function(W,Re){return W[Re.activity.id]=oi(Re.activity,a.machine,S,i),W},r?y({},r.children):{}),b=f?e.configuration:r?r.configuration:[],C=$e(b,this),F=new ee({value:u||r.value,context:S,_event:i,_sessionid:r?r._sessionid:null,historyValue:u?v?Gn(v,u):void 0:r?r.historyValue:void 0,history:!u||e.source?r:void 0,actions:u?$:[],activities:u?l:r?r.activities:{},events:[],configuration:b,transitions:e.transitions,children:w,done:C,tags:Nr(b),machine:this}),G=n!==S;F.changed=i.name===mr||G;var oe=F.history;oe&&delete oe.history;var Rt=!C&&(this._transient||c.some(function(W){return W._transient}));if(!f&&(!Rt||i.name===me))return F;var X=F;if(!C)for(Rt&&(X=this.resolveRaisedTransition(X,{type:Un},i));x.length;){var zo=x.shift();X=this.resolveRaisedTransition(X,zo._event,i)}var Go=X.changed||(oe?!!X.actions.length||G||typeof oe.value!=typeof X.value||!Cr(X.value,oe.value):void 0);return X.changed=Go,X.history=oe,X},t.prototype.getStateNode=function(e){if(ge(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=ge(e)?e.slice(Gt.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"&&ge(e))try{return this.getStateNodeById(e.slice(1))}catch{}for(var r=$t(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||ye;switch(this.type){case"parallel":return Ie(this.initialStateValue,function(s,o){return s?n.getStateNode(o).resolve(e[o]||s):ye});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?Ie(e,function(s,o){return s?n.getStateNode(o).resolve(s):ye}):this.initialStateValue||{};default:return e||ye}},t.prototype.getResolvedPath=function(e){if(ge(e)){var r=this.machine.idMap[e.slice(Gt.length)];if(!r)throw new Error("Unable to find state node '".concat(e,"'"));return r.path}return $t(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=wr(this.states,function(n){return n.initialStateValue||ye},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;_(r.target)?e=ge(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 Pe||Ne(!1,"Compound state node '".concat(this.id,"' has no initial state.")),[this];var r=Ke(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=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:wr(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?N(Ke(i).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var s=Hn(n.path,"states")(e).current;return _(s)?[n.getStateNode(s)]:N(Ke(s).map(function(o){return r.history==="deep"?n.getFromRelativePath(o):[n.states[o[0]]]}))},Object.defineProperty(t.prototype,"stateIds",{get:function(){var e=this,r=N(Object.keys(this.states).map(function(n){return e.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"events",{get:function(){var e,r,n,i;if(this.__cache.events)return this.__cache.events;var s=this.states,o=new Set(this.ownEvents);if(s)try{for(var a=O(Object.keys(s)),c=a.next();!c.done;c=a.next()){var f=c.value,u=s[f];if(u.states)try{for(var v=(n=void 0,O(u.events)),d=v.next();!d.done;d=v.next()){var l=d.value;o.add("".concat(l))}}catch(h){n={error:h}}finally{try{d&&!d.done&&(i=v.return)&&i.call(v)}finally{if(n)throw n.error}}}}catch(h){e={error:h}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(e)throw e.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ownEvents",{get:function(){var e=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(e)},enumerable:!1,configurable:!0}),t.prototype.resolveTarget=function(e){var r=this;if(e!==void 0)return e.map(function(n){if(!_(n))return n;var i=n[0]===r.delimiter;if(i&&!r.parent)return r.getStateNodeByPath(n.slice(1));var s=i?r.key+n:n;if(r.parent)try{var o=r.parent.getStateNodeByPath(s);return o}catch(a){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
|
|
17
17
|
`).concat(a.message))}else return r.getStateNodeByPath(s)})},t.prototype.formatTransition=function(e){var r=this,n=Kn(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,o=this.resolveTarget(n),a=y(y({},e),{actions:Ze(K(e.actions)),cond:_r(e.cond,s),target:o,source:this,internal:i,eventType:e.event,toJSON:function(){return y(y({},a),{target:a.target?a.target.map(function(c){return"#".concat(c.id)}):void 0,source:"#".concat(r.id)})}});return a},t.prototype.formatTransitions=function(){var e,r,n=this,i;if(!this.config.on)i=[];else if(Array.isArray(this.config.on))i=this.config.on;else{var s=this.config.on,o=je,a=s[o],c=a===void 0?[]:a,f=Pt(s,[typeof o=="symbol"?o:o+""]);i=N(Object.keys(f).map(function(g){!Pe&&g===me&&Ne(!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=de(g,f[g]);return Pe||xi(n,g,S),S}).concat(de(je,c)))}var u=this.config.always?de("",this.config.always):[],v=this.config.onDone?de(String(et(this.id)),this.config.onDone):[];Pe||Ne(!(this.config.onDone&&!this.parent),'Root nodes cannot have an ".onDone" transition. Please check the config of "'.concat(this.id,'".'));var d=N(this.invoke.map(function(g){var S=[];return g.onDone&&S.push.apply(S,D([],R(de(String(tt(g.id)),g.onDone)),!1)),g.onError&&S.push.apply(S,D([],R(de(String(De(g.id)),g.onError)),!1)),S})),l=this.after,h=N(D(D(D(D([],R(v),!1),R(d),!1),R(i),!1),R(u),!1).map(function(g){return K(g).map(function(S){return n.formatTransition(S)})}));try{for(var p=O(l),m=p.next();!m.done;m=p.next()){var E=m.value;h.push(E)}}catch(g){e={error:g}}finally{try{m&&!m.done&&(r=p.return)&&r.call(p)}finally{if(e)throw e.error}}return h},t}();function Le(t,e){return new _i(t,e)}var L=ii,Y=Ft,Wt={exports:{}},Ur=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)}},Ri=Ur,Jt=Object.prototype.toString,Kt=function(t){return function(e){var r=Jt.call(e);return t[r]||(t[r]=r.slice(8,-1).toLowerCase())}}(Object.create(null));function ue(t){return t=t.toLowerCase(),function(r){return Kt(r)===t}}function Yt(t){return Array.isArray(t)}function ot(t){return typeof t=="undefined"}function Ai(t){return t!==null&&!ot(t)&&t.constructor!==null&&!ot(t.constructor)&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}var $r=ue("ArrayBuffer");function Pi(t){var e;return typeof ArrayBuffer!="undefined"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&$r(t.buffer),e}function ki(t){return typeof t=="string"}function Ii(t){return typeof t=="number"}function jr(t){return t!==null&&typeof t=="object"}function at(t){if(Kt(t)!=="object")return!1;var e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}var Ni=ue("Date"),Ci=ue("File"),Di=ue("Blob"),Ui=ue("FileList");function Qt(t){return Jt.call(t)==="[object Function]"}function $i(t){return jr(t)&&Qt(t.pipe)}function ji(t){var e="[object FormData]";return t&&(typeof FormData=="function"&&t instanceof FormData||Jt.call(t)===e||Qt(t.toString)&&t.toString()===e)}var Li=ue("URLSearchParams");function Mi(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function Bi(){return typeof navigator!="undefined"&&(navigator.product==="ReactNative"||navigator.product==="NativeScript"||navigator.product==="NS")?!1:typeof window!="undefined"&&typeof document!="undefined"}function Xt(t,e){if(!(t===null||typeof t=="undefined"))if(typeof t!="object"&&(t=[t]),Yt(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 Zt(){var t={};function e(i,s){at(t[s])&&at(i)?t[s]=Zt(t[s],i):at(i)?t[s]=Zt({},i):Yt(i)?t[s]=i.slice():t[s]=i}for(var r=0,n=arguments.length;r<n;r++)Xt(arguments[r],e);return t}function Fi(t,e,r){return Xt(e,function(i,s){r&&typeof i=="function"?t[s]=Ri(i,r):t[s]=i}),t}function qi(t){return t.charCodeAt(0)===65279&&(t=t.slice(1)),t}function Hi(t,e,r,n){t.prototype=Object.create(e.prototype,n),t.prototype.constructor=t,r&&Object.assign(t.prototype,r)}function Vi(t,e,r){var n,i,s,o={};e=e||{};do{for(n=Object.getOwnPropertyNames(t),i=n.length;i-- >0;)s=n[i],o[s]||(e[s]=t[s],o[s]=!0);t=Object.getPrototypeOf(t)}while(t&&(!r||r(t,e))&&t!==Object.prototype);return e}function zi(t,e,r){t=String(t),(r===void 0||r>t.length)&&(r=t.length),r-=e.length;var n=t.indexOf(e,r);return n!==-1&&n===r}function Gi(t){if(!t)return null;var e=t.length;if(ot(e))return null;for(var r=new Array(e);e-- >0;)r[e]=t[e];return r}var Wi=function(t){return function(e){return t&&e instanceof t}}(typeof Uint8Array!="undefined"&&Object.getPrototypeOf(Uint8Array)),B={isArray:Yt,isArrayBuffer:$r,isBuffer:Ai,isFormData:ji,isArrayBufferView:Pi,isString:ki,isNumber:Ii,isObject:jr,isPlainObject:at,isUndefined:ot,isDate:Ni,isFile:Ci,isBlob:Di,isFunction:Qt,isStream:$i,isURLSearchParams:Li,isStandardBrowserEnv:Bi,forEach:Xt,merge:Zt,extend:Fi,trim:Mi,stripBOM:qi,inherits:Hi,toFlatObject:Vi,kindOf:Kt,kindOfTest:ue,endsWith:zi,toArray:Gi,isTypedArray:Wi,isFileList:Ui},Ee=B;function Lr(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var Mr=function(e,r,n){if(!r)return e;var i;if(n)i=n(r);else if(Ee.isURLSearchParams(r))i=r.toString();else{var s=[];Ee.forEach(r,function(c,f){c===null||typeof c=="undefined"||(Ee.isArray(c)?f=f+"[]":c=[c],Ee.forEach(c,function(v){Ee.isDate(v)?v=v.toISOString():Ee.isObject(v)&&(v=JSON.stringify(v)),s.push(Lr(f)+"="+Lr(v))}))}),i=s.join("&")}if(i){var o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+i}return e},Ji=B;function ut(){this.handlers=[]}ut.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},ut.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},ut.prototype.forEach=function(e){Ji.forEach(this.handlers,function(n){n!==null&&e(n)})};var Ki=ut,Yi=B,Qi=function(e,r){Yi.forEach(e,function(i,s){s!==r&&s.toUpperCase()===r.toUpperCase()&&(e[r]=i,delete e[s])})},Br=B;function we(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)}Br.inherits(we,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 Fr=we.prototype,qr={};["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){qr[t]={value:t}}),Object.defineProperties(we,qr),Object.defineProperty(Fr,"isAxiosError",{value:!0}),we.from=function(t,e,r,n,i,s){var o=Object.create(Fr);return Br.toFlatObject(t,o,function(c){return c!==Error.prototype}),we.call(o,t.message,e,r,n,i),o.name=t.name,s&&Object.assign(o,s),o};var Se=we,Hr={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Q=B;function Xi(t,e){e=e||new FormData;var r=[];function n(s){return s===null?"":Q.isDate(s)?s.toISOString():Q.isArrayBuffer(s)||Q.isTypedArray(s)?typeof Blob=="function"?new Blob([s]):Buffer.from(s):s}function i(s,o){if(Q.isPlainObject(s)||Q.isArray(s)){if(r.indexOf(s)!==-1)throw Error("Circular reference detected in "+o);r.push(s),Q.forEach(s,function(c,f){if(!Q.isUndefined(c)){var u=o?o+"."+f:f,v;if(c&&!o&&typeof c=="object"){if(Q.endsWith(f,"{}"))c=JSON.stringify(c);else if(Q.endsWith(f,"[]")&&(v=Q.toArray(c))){v.forEach(function(d){!Q.isUndefined(d)&&e.append(u,n(d))});return}}i(c,u)}}),r.pop()}else e.append(o,n(s))}return i(t),e}var Vr=Xi,er=Se,Zi=function(e,r,n){var i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):r(new er("Request failed with status code "+n.status,[er.ERR_BAD_REQUEST,er.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))},ct=B,es=ct.isStandardBrowserEnv()?function(){return{write:function(r,n,i,s,o,a){var c=[];c.push(r+"="+encodeURIComponent(n)),ct.isNumber(i)&&c.push("expires="+new Date(i).toGMTString()),ct.isString(s)&&c.push("path="+s),ct.isString(o)&&c.push("domain="+o),a===!0&&c.push("secure"),document.cookie=c.join("; ")},read:function(r){var n=document.cookie.match(new RegExp("(^|;\\s*)("+r+")=([^;]*)"));return n?decodeURIComponent(n[3]):null},remove:function(r){this.write(r,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}(),ts=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},rs=function(e,r){return r?e.replace(/\/+$/,"")+"/"+r.replace(/^\/+/,""):e},ns=ts,is=rs,zr=function(e,r){return e&&!ns(r)?is(e,r):r},tr=B,ss=["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"],os=function(e){var r={},n,i,s;return e&&tr.forEach(e.split(`
|
|
18
|
-
`),function(a){if(s=a.indexOf(":"),n=tr.trim(a.substr(0,s)).toLowerCase(),i=tr.trim(a.substr(s+1)),n){if(r[n]&&ss.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([i]):r[n]=r[n]?r[n]+", "+i:i}}),r},Gr=B,as=Gr.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function i(s){var o=s;return e&&(r.setAttribute("href",o),o=r.href),r.setAttribute("href",o),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:r.pathname.charAt(0)==="/"?r.pathname:"/"+r.pathname}}return n=i(window.location.href),function(o){var a=Gr.isString(o)?i(o):o;return a.protocol===n.protocol&&a.host===n.host}}():function(){return function(){return!0}}(),rr=Se,us=B;function Wr(t){rr.call(this,t==null?"canceled":t,rr.ERR_CANCELED),this.name="CanceledError"}us.inherits(Wr,rr,{__CANCEL__:!0});var lt=Wr,cs=function(e){var r=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return r&&r[1]||""},Me=B,ls=Zi,fs=es,ds=Mr,hs=zr,vs=os,ps=as,ms=Hr,te=Se,ys=lt,gs=cs,Jr=function(e){return new Promise(function(n,i){var s=e.data,o=e.headers,a=e.responseType,c;function f(){e.cancelToken&&e.cancelToken.unsubscribe(c),e.signal&&e.signal.removeEventListener("abort",c)}Me.isFormData(s)&&Me.isStandardBrowserEnv()&&delete o["Content-Type"];var u=new XMLHttpRequest;if(e.auth){var v=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(v+":"+d)}var l=hs(e.baseURL,e.url);u.open(e.method.toUpperCase(),ds(l,e.params,e.paramsSerializer),!0),u.timeout=e.timeout;function h(){if(!!u){var E="getAllResponseHeaders"in u?vs(u.getAllResponseHeaders()):null,g=!a||a==="text"||a==="json"?u.responseText:u.response,S={data:g,status:u.status,statusText:u.statusText,headers:E,config:e,request:u};ls(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 te("Request aborted",te.ECONNABORTED,e,u)),u=null)},u.onerror=function(){i(new te("Network Error",te.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||ms;e.timeoutErrorMessage&&(g=e.timeoutErrorMessage),i(new te(g,S.clarifyTimeoutError?te.ETIMEDOUT:te.ECONNABORTED,e,u)),u=null},Me.isStandardBrowserEnv()){var p=(e.withCredentials||ps(l))&&e.xsrfCookieName?fs.read(e.xsrfCookieName):void 0;p&&(o[e.xsrfHeaderName]=p)}"setRequestHeader"in u&&Me.forEach(o,function(g,S){typeof s=="undefined"&&S.toLowerCase()==="content-type"?delete o[S]:u.setRequestHeader(S,g)}),Me.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),a&&a!=="json"&&(u.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&u.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&u.upload&&u.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(c=function(E){!u||(i(!E||E&&E.type?new ys: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 m=gs(l);if(m&&["http","https","file"].indexOf(m)===-1){i(new te("Unsupported protocol "+m+":",te.ERR_BAD_REQUEST,e));return}u.send(s)})},Es=null,M=B,Kr=Qi,Yr=Se,ws=Hr,Ss=Vr,Ts={"Content-Type":"application/x-www-form-urlencoded"};function Qr(t,e){!M.isUndefined(t)&&M.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function bs(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Jr),t}function Os(t,e,r){if(M.isString(t))try{return(e||JSON.parse)(t),M.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var ft={transitional:ws,adapter:bs(),transformRequest:[function(e,r){if(Kr(r,"Accept"),Kr(r,"Content-Type"),M.isFormData(e)||M.isArrayBuffer(e)||M.isBuffer(e)||M.isStream(e)||M.isFile(e)||M.isBlob(e))return e;if(M.isArrayBufferView(e))return e.buffer;if(M.isURLSearchParams(e))return Qr(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n=M.isObject(e),i=r&&r["Content-Type"],s;if((s=M.isFileList(e))||n&&i==="multipart/form-data"){var o=this.env&&this.env.FormData;return Ss(s?{"files[]":e}:e,o&&new o)}else if(n||i==="application/json")return Qr(r,"application/json"),Os(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&&M.isString(e)&&e.length)try{return JSON.parse(e)}catch(o){if(s)throw o.name==="SyntaxError"?Yr.from(o,Yr.ERR_BAD_RESPONSE,this,null,this.response):o}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Es},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};M.forEach(["delete","get","head"],function(e){ft.headers[e]={}}),M.forEach(["post","put","patch"],function(e){ft.headers[e]=M.merge(Ts)});var nr=ft,xs=B,_s=nr,Rs=function(e,r,n){var i=this||_s;return xs.forEach(n,function(o){e=o.call(i,e,r)}),e},Xr=function(e){return!!(e&&e.__CANCEL__)},Zr=B,ir=Rs,As=Xr,Ps=nr,ks=lt;function sr(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new ks}var Is=function(e){sr(e),e.headers=e.headers||{},e.data=ir.call(e,e.data,e.headers,e.transformRequest),e.headers=Zr.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),Zr.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||Ps.adapter;return r(e).then(function(i){return sr(e),i.data=ir.call(e,i.data,i.headers,e.transformResponse),i},function(i){return As(i)||(sr(e),i&&i.response&&(i.response.data=ir.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},z=B,en=function(e,r){r=r||{};var n={};function i(u,v){return z.isPlainObject(u)&&z.isPlainObject(v)?z.merge(u,v):z.isPlainObject(v)?z.merge({},v):z.isArray(v)?v.slice():v}function s(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(e[u],r[u])}function o(u){if(!z.isUndefined(r[u]))return i(void 0,r[u])}function a(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(void 0,r[u])}function c(u){if(u in r)return i(e[u],r[u]);if(u in e)return i(void 0,e[u])}var f={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:c};return z.forEach(Object.keys(e).concat(Object.keys(r)),function(v){var d=f[v]||s,l=d(v);z.isUndefined(l)&&d!==c||(n[v]=l)}),n},tn={version:"0.27.2"},Ns=tn.version,ne=Se,or={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){or[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var rn={};or.transitional=function(e,r,n){function i(s,o){return"[Axios v"+Ns+"] Transitional option '"+s+"'"+o+(n?". "+n:"")}return function(s,o,a){if(e===!1)throw new ne(i(o," has been removed"+(r?" in "+r:"")),ne.ERR_DEPRECATED);return r&&!rn[o]&&(rn[o]=!0,console.warn(i(o," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,o,a):!0}};function Cs(t,e,r){if(typeof t!="object")throw new ne("options must be an object",ne.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],o=e[s];if(o){var a=t[s],c=a===void 0||o(a,s,t);if(c!==!0)throw new ne("option "+s+" must be "+c,ne.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new ne("Unknown option "+s,ne.ERR_BAD_OPTION)}}var Ds={assertOptions:Cs,validators:or},nn=B,Us=Mr,sn=Ki,on=Is,dt=en,$s=zr,an=Ds,Te=an.validators;function be(t){this.defaults=t,this.interceptors={request:new sn,response:new sn}}be.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&&an.assertOptions(n,{silentJSONParsing:Te.transitional(Te.boolean),forcedJSONParsing:Te.transitional(Te.boolean),clarifyTimeoutError:Te.transitional(Te.boolean)},!1);var i=[],s=!0;this.interceptors.request.forEach(function(l){typeof l.runWhen=="function"&&l.runWhen(r)===!1||(s=s&&l.synchronous,i.unshift(l.fulfilled,l.rejected))});var o=[];this.interceptors.response.forEach(function(l){o.push(l.fulfilled,l.rejected)});var a;if(!s){var c=[on,void 0];for(Array.prototype.unshift.apply(c,i),c=c.concat(o),a=Promise.resolve(r);c.length;)a=a.then(c.shift(),c.shift());return a}for(var f=r;i.length;){var u=i.shift(),v=i.shift();try{f=u(f)}catch(d){v(d);break}}try{a=on(f)}catch(d){return Promise.reject(d)}for(;o.length;)a=a.then(o.shift(),o.shift());return a},be.prototype.getUri=function(e){e=dt(this.defaults,e);var r=$s(e.baseURL,e.url);return Us(r,e.params,e.paramsSerializer)},nn.forEach(["delete","get","head","options"],function(e){be.prototype[e]=function(r,n){return this.request(dt(n||{},{method:e,url:r,data:(n||{}).data}))}}),nn.forEach(["post","put","patch"],function(e){function r(n){return function(s,o,a){return this.request(dt(a||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}be.prototype[e]=r(),be.prototype[e+"Form"]=r(!0)});var js=be,Ls=lt;function Oe(t){if(typeof t!="function")throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(i){e=i});var r=this;this.promise.then(function(n){if(!!r._listeners){var i,s=r._listeners.length;for(i=0;i<s;i++)r._listeners[i](n);r._listeners=null}}),this.promise.then=function(n){var i,s=new Promise(function(o){r.subscribe(o),i=o}).then(n);return s.cancel=function(){r.unsubscribe(i)},s},t(function(i){r.reason||(r.reason=new Ls(i),e(r.reason))})}Oe.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},Oe.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},Oe.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},Oe.source=function(){var e,r=new Oe(function(i){e=i});return{token:r,cancel:e}};var Ms=Oe,Bs=function(e){return function(n){return e.apply(null,n)}},Fs=B,qs=function(e){return Fs.isObject(e)&&e.isAxiosError===!0},un=B,Hs=Ur,ht=js,Vs=en,zs=nr;function cn(t){var e=new ht(t),r=Hs(ht.prototype.request,e);return un.extend(r,ht.prototype,e),un.extend(r,e),r.create=function(i){return cn(Vs(t,i))},r}var V=cn(zs);V.Axios=ht,V.CanceledError=lt,V.CancelToken=Ms,V.isCancel=Xr,V.VERSION=tn.version,V.toFormData=Vr,V.AxiosError=Se,V.Cancel=V.CanceledError,V.all=function(e){return Promise.all(e)},V.spread=Bs,V.isAxiosError=qs,Wt.exports=V,Wt.exports.default=V;var vt=Wt.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 Gs={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 ar(t,e){function r(i,s,o){if(typeof document!="undefined"){o=pt({},e,o),typeof o.expires=="number"&&(o.expires=new Date(Date.now()+o.expires*864e5)),o.expires&&(o.expires=o.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in o)!o[c]||(a+="; "+c,o[c]!==!0&&(a+="="+o[c].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+a}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],o={},a=0;a<s.length;a++){var c=s[a].split("="),f=c.slice(1).join("=");try{var u=decodeURIComponent(c[0]);if(o[u]=t.read(f,u),i===u)break}catch{}}return i?o[i]:o}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",pt({},s,{expires:-1}))},withAttributes:function(i){return ar(this.converter,pt({},this.attributes,i))},withConverter:function(i){return ar(pt({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var ur=ar(Gs,{path:"/"}),Ws=Object.defineProperty,Js=Object.defineProperties,Ks=Object.getOwnPropertyDescriptors,mt=Object.getOwnPropertySymbols,ln=Object.prototype.hasOwnProperty,fn=Object.prototype.propertyIsEnumerable,dn=(t,e,r)=>e in t?Ws(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ie=(t,e)=>{for(var r in e||(e={}))ln.call(e,r)&&dn(t,r,e[r]);if(mt)for(var r of mt(e))fn.call(e,r)&&dn(t,r,e[r]);return t},Be=(t,e)=>Js(t,Ks(e)),hn=(t,e)=>{var r={};for(var n in t)ln.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&mt)for(var n of mt(t))e.indexOf(n)<0&&fn.call(t,n)&&(r[n]=t[n]);return r};const yt="nhostRefreshToken",gt="nhostRefreshTokenExpiresAt",Ys=3,Qs=300,Xs=5,Zs=0,se=10,Et=20,xe={status:se,error:"invalid-email",message:"Email is incorrectly formatted"},cr={status:se,error:"invalid-password",message:"Password is incorrectly formatted"},vn={status:se,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},eo={status:se,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},to={status:se,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},ro={status:se,error:"no-refresh-token",message:"No refresh token has been provided"},no={status:Et,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},ce={status:Et,error:"already-signed-in",message:"User is already signed in"},io={status:Et,error:"unauthenticated-user",message:"User is not authenticated"},so={status:Et,error:"unverified-user",message:"Email needs verification"},oo={status:se,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,o,a,c,f,u,v,d;return Promise.reject({error:{message:(a=(o=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?o:r.request.responseText)!=null?a:JSON.stringify(r),status:(v=(u=(c=r.response)==null?void 0:c.status)!=null?u:(f=r.response)==null?void 0:f.data.statusCode)!=null?v:Zs,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},wt=typeof window!="undefined",St=new Map,ao=t=>{var e;return wt&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=St.get(t))!=null?e:null},uo=(t,e)=>{wt&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?St.set(t,e):St.has(t)&&St.delete(t)},co=(t,e)=>{if(t==="localStorage"||t==="web")return ao;if(t==="cookie")return r=>{var n;return wt&&(n=ur.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}`)},lo=(t,e)=>{if(t==="localStorage"||t==="web")return uo;if(t==="cookie")return(r,n)=>{wt&&(n?ur.set(r,n,{expires:30}):ur.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}`)},pn=(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},Z=(t,e)=>{if(!(e!=null&&e.redirectTo))return e;const r=e,{redirectTo:n}=r,i=hn(r,["redirectTo"]);if(!t)return n.startsWith("/")?i:e;const s=new URL(t),o=Object.fromEntries(new URLSearchParams(s.search)),a=new URL(n.startsWith("/")?s.origin+n:n),c=new URLSearchParams(a.search);let f=Object.fromEntries(c);n.startsWith("/")&&(f=ie(ie({},o),f));let u=s.pathname;return a.pathname.length>1&&(u+=a.pathname.slice(1)),Be(ie({},i),{redirectTo:pn(a.origin+u,f)})};function Tt(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 mn(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 _e=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,}))$/),lr=t=>!!t&&typeof t=="string"&&t.length>=Ys,yn=t=>!!t&&typeof t=="string",fo=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),fr={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},ho=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Fe(t);return Le({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=>xe}),saveRequestError:L({error:(i,{data:{error:s}})=>s}),reportError:Y(i=>({type:"ERROR",error:i.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!_e(s)},services:{requestChange:async(i,{email:s,options:o})=>(await n.post("/user/email/change",{newEmail:s,options:Z(e,o)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},vo=({backendUrl:t,interpreter:e})=>{const r=Fe(t);return Le({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=>cr}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!lr(i)},services:{requestChange:(n,{password:i,ticket:s})=>r.post("/user/password",{newPassword:i,ticket:s},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},po=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return Le({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=>xe}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!_e(i)},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:Z(e,s)})}})},mo=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return Le({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=>xe}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!_e(i)},services:{request:async(n,{email:i,options:s})=>(await r.post("/user/email/send-verification-email",{email:i,options:Z(e,s)})).data}})},yo=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:o,autoRefreshToken:a=!0,autoSignIn:c=!0})=>{const f=r||co(i,s),u=n||lo(i,s),v=Fe(t),d=async(l,h,p)=>(await v.post(l,h,p)).data;return Le({schema:{context:{},events:{}},tsTypes:{},context:fr,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:Y("SIGNED_IN"),reportSignedOut:Y("SIGNED_OUT"),reportTokenChanged:Y("TOKEN_CHANGED"),clearContext:L(()=>(u(gt,null),u(yt,null),ie({},fr))),clearContextExceptRefreshToken:L(({refreshToken:{value:l}})=>(u(gt,null),Be(ie({},fr),{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,m;if(h.session.accessTokenExpiresIn){const E=new Date(Date.now()+h.session.accessTokenExpiresIn*1e3).toISOString();u(gt,E)}else u(gt,null);return{value:(p=h==null?void 0:h.session)==null?void 0:p.accessToken,expiresAt:new Date(Date.now()+((m=h==null?void 0:h.session)==null?void 0:m.accessTokenExpiresIn)*1e3)}},refreshToken:(l,{data:h})=>{var p;return u(yt,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}})=>Be(ie({},l),{authentication:h})}),resetErrors:L({errors:l=>({})}),saveRegistrationError:L({errors:({errors:l},{data:{error:h}})=>Be(ie({},l),{registration:h})}),destroyRefreshToken:L({refreshToken:l=>(u(yt,null),{value:null})}),cleanUrl:()=>{c&&Tt("refreshToken")&&(mn("refreshToken"),mn("type"))},broadcastToken:l=>{if(c)try{new BroadcastChannel("nhost").postMessage(l.refreshToken.value)}catch{}}},guards:{isAnonymous:(l,h)=>{var p;return!!((p=l.user)!=null&&p.isAnonymous)},isSignedIn:l=>!!l.user&&!!l.refreshToken.value&&!!l.accessToken.value,noToken:l=>!l.refreshToken.value,hasRefreshToken:l=>!!l.refreshToken.value,isAutoRefreshDisabled:()=>!a,refreshTimerShouldRefresh:l=>{const{expiresAt:h}=l.accessToken;return h?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>Xs*1e3:o&&Date.now()-l.refreshTimer.startedAt.getTime()>o*1e3?!0:h.getTime()-Date.now()-1e3*Qs<=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})=>_e(h)?lr(p)?d("/signin/email-password",{email:h,password:p}):Promise.reject({error:cr}):Promise.reject({error:xe}),passwordlessSms:(l,{phoneNumber:h,options:p})=>{var m;return yn(h)?(m=l.user)!=null&&m.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:Z(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}})):d("/signin/passwordless/sms",{phoneNumber:h,options:Z(e,p)}):Promise.reject({error:vn})},passwordlessSmsOtp:(l,{phoneNumber:h,otp:p})=>yn(h)?d("/signin/passwordless/sms/otp",{phoneNumber:h,otp:p}):Promise.reject({error:vn}),passwordlessEmail:(l,{email:h,options:p})=>{var m;return _e(h)?(m=l.user)!=null&&m.isAnonymous?d("/user/deanonymize",{signInMethod:"passwordless",connection:"email",email:h,options:Z(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signin/passwordless/email",{email:h,options:Z(e,p)}):Promise.reject({error:xe})},signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,h)=>{var p;const m=h.ticket||((p=l.mfa)==null?void 0:p.ticket);return m?fo(m)?d("/signin/mfa/totp",{ticket:m,otp:h.otp}):Promise.reject({error:eo}):Promise.reject({error:to})},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:m})=>{var E;return _e(h)?lr(p)?(E=l.user)!=null&&E.isAnonymous?d("/user/deanonymize",{signInMethod:"email-password",email:h,password:p,options:Z(e,m)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signup/email-password",{email:h,password:p,options:Z(e,m)}):Promise.reject({error:cr}):Promise.reject({error:xe})},importRefreshToken:async()=>{let l=null;if(c){const p=Tt("refreshToken")||null;if(p)try{return{session:await d("/token",{refreshToken:p})}}catch(m){l=m.error}else{const m=Tt("error");if(m)return Promise.reject({error:{status:se,error:m,message:Tt("errorDescription")||m}})}}const h=await f(yt);if(h)try{return{session:await d("/token",{refreshToken:h})}}catch(p){l=p.error}return Promise.reject({error:l})}}})};class go{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:o=!0,backendUrl:a,clientUrl:c,devTools:f}=r,u=hn(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl","devTools"]);if(this._subscriptions=new Set,this.backendUrl=a,this.clientUrl=c,this.machine=yo(Be(ie({},u),{backendUrl:a,clientUrl:c,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),o&&(this.interpreter=pe(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 Eo=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})})}),wo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{password:e,ticket:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSuccess:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSuccess:!0})})}),So=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})})}),To=(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSent:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSent:!0})})}),bo=t=>new Promise(e=>{const{changed:r}=t.send("SIGNIN_ANONYMOUS");r||e({isSuccess:!1,isError:!0,error:ce,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})})}),Oo=(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:ce,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:{signedOut:"needsMfa"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!0,mfa:o.context.mfa,user:null}):o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:o.context.user})})}),gn=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_EMAIL",{email:e,options:r});if(!i)return n({error:ce,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})})}),xo=(t,e,r)=>new Promise(n=>{const{changed:i,context:s}=t.send("SIGNIN_MFA_TOTP",{otp:e,ticket:r});if(!i)return n({accessToken:s.accessToken.value,error:ce,isError:!0,isSuccess:!1,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,user:o.context.user})})}),En=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_SMS",{phoneNumber:e,options:r});if(!i)return n({error:ce,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})})}),_o=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send({type:"PASSWORDLESS_SMS_OTP",phoneNumber:e,otp:r});if(!i)return n({error:ce,isError:!0,isSuccess:!1,user:null,accessToken:null});t.onTransition(s=>{s.matches({authentication:"signedIn"})?n({error:null,isError:!1,isSuccess:!0,user:s.context.user,accessToken:s.context.accessToken.value}):s.matches({registration:{incomplete:"failed"}})&&n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null,accessToken:null})})}),Ro=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:io});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})})}),wn=(t,e,r,n)=>new Promise(i=>{const{changed:s,context:o}=t.send("SIGNUP_EMAIL_PASSWORD",{email:e,password:r,options:n});if(!s)return i({error:ce,accessToken:o.accessToken.value,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:o.user});t.onTransition(a=>{a.matches("registration.incomplete.failed")?i({accessToken:null,error:a.context.errors.registration||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):a.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?i({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):a.matches({authentication:"signedIn",registration:"complete"})&&i({accessToken:a.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:a.context.user})})});var Ao=Object.defineProperty,Po=Object.defineProperties,ko=Object.getOwnPropertyDescriptors,Sn=Object.getOwnPropertySymbols,Io=Object.prototype.hasOwnProperty,No=Object.prototype.propertyIsEnumerable,Tn=(t,e,r)=>e in t?Ao(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bt=(t,e)=>{for(var r in e||(e={}))Io.call(e,r)&&Tn(t,r,e[r]);if(Sn)for(var r of Sn(e))No.call(e,r)&&Tn(t,r,e[r]);return t},Ot=(t,e)=>Po(t,ko(e));const Co=()=>typeof window!="undefined",xt=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},qe=({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 Do{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f,start:u=!0}){var v;this.url=e,this._client=new go({backendUrl:e,clientUrl:typeof window!="undefined"&&((v=window.location)==null?void 0:v.origin)||"",autoRefreshToken:r,autoSignIn:typeof i=="boolean"?i:n,start:u,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f})}async signUp({email:e,password:r,options:n}){const i=await this.waitUntilReady();return qe(await wn(i,e,r,n))}async signIn(e){const r=await this.waitUntilReady();if("provider"in e){const{provider:i,options:s}=e,o=pn(`${this._client.backendUrl}/signin/provider/${i}`,Z(this._client.clientUrl,s));return Co()&&(window.location.href=o),{providerUrl:o,provider:i,session:null,mfa:null,error:null}}if("email"in e&&"password"in e){const i=await Oo(r,e.email,e.password);return i.needsEmailVerification?{session:null,mfa:null,error:so}:i.needsMfaOtp?{session:null,mfa:i.mfa,error:null}:Ot(bt({},qe(i)),{mfa:null})}if("email"in e){const{error:i}=await gn(r,e.email);return{session:null,mfa:null,error:i}}if("phoneNumber"in e&&"otp"in e){const i=await _o(r,e.phoneNumber,e.otp);return Ot(bt({},qe(i)),{mfa:null})}if("phoneNumber"in e){const{error:i}=await En(r,e.phoneNumber,e.options);return{error:i,mfa:null,session:null}}if("otp"in e){const i=await xo(r,e.otp,e.ticket);return Ot(bt({},qe(i)),{mfa:null})}const n=await bo(r);return Ot(bt({},qe(n)),{mfa:null})}async signOut(e){const r=await this.waitUntilReady(),{error:n}=await Ro(r,e==null?void 0:e.all);return{error:n}}async resetPassword({email:e,options:r}){const n=pe(po(this._client)).start(),{error:i}=await So(n,e,r);return{error:i}}async changePassword({newPassword:e,ticket:r}){const n=pe(vo(this._client)).start(),{error:i}=await wo(n,e,r);return{error:i}}async sendVerificationEmail({email:e,options:r}){const n=pe(mo(this._client)).start(),{error:i}=await To(n,e,r);return{error:i}}async changeEmail({newEmail:e,options:r}){const n=pe(ho(this._client)).start(),{error:i}=await Eo(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 gn(r,e.email,e.options);return{error:n}}if(e.connection==="sms"){const{error:n}=await En(r,e.phoneNumber,e.options);return{error:n}}}if(e.signInMethod==="email-password"){const{error:n}=await wn(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(xt(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,xt(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?Dn(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:ro});const{changed:s}=r.send("TRY_TOKEN",{token:i});if(!s)return n({session:null,error:no});r.onTransition(o=>{o.matches({token:{idle:"error"}})?n({session:null,error:oo}):o.event.type==="TOKEN_CHANGED"&&n({session:xt(o.context),error:null})})})}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return xt((r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)}getUser(){var e,r,n;return((n=(r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)==null?void 0:n.user)||null}waitUntilReady(){const r=this._client.interpreter;if(!r)throw Error("Auth interpreter not set");return r.state.hasTag("loading")?new Promise((n,i)=>{let s=setTimeout(()=>i(`The state machine is not yet ready after ${15} seconds.`),15e3);r.onTransition(o=>{if(!o.hasTag("loading"))return clearTimeout(s),n(r)})}):Promise.resolve(r)}isReady(){var e,r;return!((r=(e=this._client.interpreter)==null?void 0:e.state)!=null&&r.hasTag("loading"))}get client(){return this._client}}var Uo=Object.defineProperty,$o=Object.defineProperties,jo=Object.getOwnPropertyDescriptors,bn=Object.getOwnPropertySymbols,Lo=Object.prototype.hasOwnProperty,Mo=Object.prototype.propertyIsEnumerable,On=(t,e,r)=>e in t?Uo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,He=(t,e)=>{for(var r in e||(e={}))Lo.call(e,r)&&On(t,r,e[r]);if(bn)for(var r of bn(e))Mo.call(e,r)&&On(t,r,e[r]);return t},xn=(t,e)=>$o(t,jo(e));class Bo{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:xn(He(He({},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:He({},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:He({},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 Fo{constructor({url:e,adminSecret:r}){this.url=e,this.api=new Bo({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(xn(He({},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 _n{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=le(le({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,dr(le({},n),{headers:i}))}catch(o){if(o instanceof Error)return{res:null,error:o}}return s?{res:s,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}class Rn{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=le(le({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);try{const s="",a=(await this.instance.post("",{operationName:s||void 0,query:typeof e=="string"?e:U.print(e),variables:r},dr(le({},n),{headers:i}))).data,{data:c}=a;return a.errors?{data:null,error:a.errors}:typeof c!="object"||Array.isArray(c)||c===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:c,error:null}}catch(s){return s instanceof Error?{data:null,error:s}:(console.error(s),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}const qo=/^localhost(:\d+)*$/g;function _t(t,e){const{backendUrl:r,subdomain:n,region:i}=t;if(!r&&!n)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(r)return`${r}/v1/${e}`;if(!n)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const s=n.match(qo);if(s&&s.length>0){const o=s[0];return o==="localhost"?`http://localhost:1337/v1/${e}`:`http://${o}/v1/${e}`}if(!i)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${n}.${e}.${i}.nhost.run/v1`}class An{constructor(d){var l=d,{refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,adminSecret:c,devTools:f,start:u=!0}=l,v=Nn(l,["refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","adminSecret","devTools","start"]);var h;this.auth=new Do({url:_t(v,"auth"),refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,start:u}),this.storage=new Fo({url:_t(v,"storage"),adminSecret:c}),this.functions=new _n({url:_t(v,"functions"),adminSecret:c}),this.graphql=new Rn({url:_t(v,"graphql"),adminSecret:c}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(h=this.auth.client)==null||h.onStart(()=>{this.auth.onAuthStateChanged((p,m)=>{p==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(p=>{this.storage.setAccessToken(p==null?void 0:p.accessToken),this.functions.setAccessToken(p==null?void 0:p.accessToken),this.graphql.setAccessToken(p==null?void 0:p.accessToken)})}),this._adminSecret=c,this.devTools=f}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const Ho=t=>new An(t);A.NhostClient=An,A.NhostFunctionsClient=_n,A.NhostGraphqlClient=Rn,A.createClient=Ho,Object.defineProperties(A,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
18
|
+
`),function(a){if(s=a.indexOf(":"),n=tr.trim(a.substr(0,s)).toLowerCase(),i=tr.trim(a.substr(s+1)),n){if(r[n]&&ss.indexOf(n)>=0)return;n==="set-cookie"?r[n]=(r[n]?r[n]:[]).concat([i]):r[n]=r[n]?r[n]+", "+i:i}}),r},Gr=B,as=Gr.isStandardBrowserEnv()?function(){var e=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a"),n;function i(s){var o=s;return e&&(r.setAttribute("href",o),o=r.href),r.setAttribute("href",o),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:r.pathname.charAt(0)==="/"?r.pathname:"/"+r.pathname}}return n=i(window.location.href),function(o){var a=Gr.isString(o)?i(o):o;return a.protocol===n.protocol&&a.host===n.host}}():function(){return function(){return!0}}(),rr=Se,us=B;function Wr(t){rr.call(this,t==null?"canceled":t,rr.ERR_CANCELED),this.name="CanceledError"}us.inherits(Wr,rr,{__CANCEL__:!0});var lt=Wr,cs=function(e){var r=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return r&&r[1]||""},Me=B,ls=Zi,fs=es,ds=Mr,hs=zr,vs=os,ps=as,ms=Hr,te=Se,ys=lt,gs=cs,Jr=function(e){return new Promise(function(n,i){var s=e.data,o=e.headers,a=e.responseType,c;function f(){e.cancelToken&&e.cancelToken.unsubscribe(c),e.signal&&e.signal.removeEventListener("abort",c)}Me.isFormData(s)&&Me.isStandardBrowserEnv()&&delete o["Content-Type"];var u=new XMLHttpRequest;if(e.auth){var v=e.auth.username||"",d=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(v+":"+d)}var l=hs(e.baseURL,e.url);u.open(e.method.toUpperCase(),ds(l,e.params,e.paramsSerializer),!0),u.timeout=e.timeout;function h(){if(!!u){var E="getAllResponseHeaders"in u?vs(u.getAllResponseHeaders()):null,g=!a||a==="text"||a==="json"?u.responseText:u.response,S={data:g,status:u.status,statusText:u.statusText,headers:E,config:e,request:u};ls(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 te("Request aborted",te.ECONNABORTED,e,u)),u=null)},u.onerror=function(){i(new te("Network Error",te.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||ms;e.timeoutErrorMessage&&(g=e.timeoutErrorMessage),i(new te(g,S.clarifyTimeoutError?te.ETIMEDOUT:te.ECONNABORTED,e,u)),u=null},Me.isStandardBrowserEnv()){var p=(e.withCredentials||ps(l))&&e.xsrfCookieName?fs.read(e.xsrfCookieName):void 0;p&&(o[e.xsrfHeaderName]=p)}"setRequestHeader"in u&&Me.forEach(o,function(g,S){typeof s=="undefined"&&S.toLowerCase()==="content-type"?delete o[S]:u.setRequestHeader(S,g)}),Me.isUndefined(e.withCredentials)||(u.withCredentials=!!e.withCredentials),a&&a!=="json"&&(u.responseType=e.responseType),typeof e.onDownloadProgress=="function"&&u.addEventListener("progress",e.onDownloadProgress),typeof e.onUploadProgress=="function"&&u.upload&&u.upload.addEventListener("progress",e.onUploadProgress),(e.cancelToken||e.signal)&&(c=function(E){!u||(i(!E||E&&E.type?new ys: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 m=gs(l);if(m&&["http","https","file"].indexOf(m)===-1){i(new te("Unsupported protocol "+m+":",te.ERR_BAD_REQUEST,e));return}u.send(s)})},Es=null,M=B,Kr=Qi,Yr=Se,ws=Hr,Ss=Vr,Ts={"Content-Type":"application/x-www-form-urlencoded"};function Qr(t,e){!M.isUndefined(t)&&M.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}function bs(){var t;return(typeof XMLHttpRequest!="undefined"||typeof process!="undefined"&&Object.prototype.toString.call(process)==="[object process]")&&(t=Jr),t}function Os(t,e,r){if(M.isString(t))try{return(e||JSON.parse)(t),M.trim(t)}catch(n){if(n.name!=="SyntaxError")throw n}return(r||JSON.stringify)(t)}var ft={transitional:ws,adapter:bs(),transformRequest:[function(e,r){if(Kr(r,"Accept"),Kr(r,"Content-Type"),M.isFormData(e)||M.isArrayBuffer(e)||M.isBuffer(e)||M.isStream(e)||M.isFile(e)||M.isBlob(e))return e;if(M.isArrayBufferView(e))return e.buffer;if(M.isURLSearchParams(e))return Qr(r,"application/x-www-form-urlencoded;charset=utf-8"),e.toString();var n=M.isObject(e),i=r&&r["Content-Type"],s;if((s=M.isFileList(e))||n&&i==="multipart/form-data"){var o=this.env&&this.env.FormData;return Ss(s?{"files[]":e}:e,o&&new o)}else if(n||i==="application/json")return Qr(r,"application/json"),Os(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&&M.isString(e)&&e.length)try{return JSON.parse(e)}catch(o){if(s)throw o.name==="SyntaxError"?Yr.from(o,Yr.ERR_BAD_RESPONSE,this,null,this.response):o}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Es},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};M.forEach(["delete","get","head"],function(e){ft.headers[e]={}}),M.forEach(["post","put","patch"],function(e){ft.headers[e]=M.merge(Ts)});var nr=ft,xs=B,_s=nr,Rs=function(e,r,n){var i=this||_s;return xs.forEach(n,function(o){e=o.call(i,e,r)}),e},Xr=function(e){return!!(e&&e.__CANCEL__)},Zr=B,ir=Rs,As=Xr,Ps=nr,ks=lt;function sr(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new ks}var Is=function(e){sr(e),e.headers=e.headers||{},e.data=ir.call(e,e.data,e.headers,e.transformRequest),e.headers=Zr.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),Zr.forEach(["delete","get","head","post","put","patch","common"],function(i){delete e.headers[i]});var r=e.adapter||Ps.adapter;return r(e).then(function(i){return sr(e),i.data=ir.call(e,i.data,i.headers,e.transformResponse),i},function(i){return As(i)||(sr(e),i&&i.response&&(i.response.data=ir.call(e,i.response.data,i.response.headers,e.transformResponse))),Promise.reject(i)})},z=B,en=function(e,r){r=r||{};var n={};function i(u,v){return z.isPlainObject(u)&&z.isPlainObject(v)?z.merge(u,v):z.isPlainObject(v)?z.merge({},v):z.isArray(v)?v.slice():v}function s(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(e[u],r[u])}function o(u){if(!z.isUndefined(r[u]))return i(void 0,r[u])}function a(u){if(z.isUndefined(r[u])){if(!z.isUndefined(e[u]))return i(void 0,e[u])}else return i(void 0,r[u])}function c(u){if(u in r)return i(e[u],r[u]);if(u in e)return i(void 0,e[u])}var f={url:o,method:o,data:o,baseURL:a,transformRequest:a,transformResponse:a,paramsSerializer:a,timeout:a,timeoutMessage:a,withCredentials:a,adapter:a,responseType:a,xsrfCookieName:a,xsrfHeaderName:a,onUploadProgress:a,onDownloadProgress:a,decompress:a,maxContentLength:a,maxBodyLength:a,beforeRedirect:a,transport:a,httpAgent:a,httpsAgent:a,cancelToken:a,socketPath:a,responseEncoding:a,validateStatus:c};return z.forEach(Object.keys(e).concat(Object.keys(r)),function(v){var d=f[v]||s,l=d(v);z.isUndefined(l)&&d!==c||(n[v]=l)}),n},tn={version:"0.27.2"},Ns=tn.version,ne=Se,or={};["object","boolean","number","function","string","symbol"].forEach(function(t,e){or[t]=function(n){return typeof n===t||"a"+(e<1?"n ":" ")+t}});var rn={};or.transitional=function(e,r,n){function i(s,o){return"[Axios v"+Ns+"] Transitional option '"+s+"'"+o+(n?". "+n:"")}return function(s,o,a){if(e===!1)throw new ne(i(o," has been removed"+(r?" in "+r:"")),ne.ERR_DEPRECATED);return r&&!rn[o]&&(rn[o]=!0,console.warn(i(o," has been deprecated since v"+r+" and will be removed in the near future"))),e?e(s,o,a):!0}};function Cs(t,e,r){if(typeof t!="object")throw new ne("options must be an object",ne.ERR_BAD_OPTION_VALUE);for(var n=Object.keys(t),i=n.length;i-- >0;){var s=n[i],o=e[s];if(o){var a=t[s],c=a===void 0||o(a,s,t);if(c!==!0)throw new ne("option "+s+" must be "+c,ne.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new ne("Unknown option "+s,ne.ERR_BAD_OPTION)}}var Ds={assertOptions:Cs,validators:or},nn=B,Us=Mr,sn=Ki,on=Is,dt=en,$s=zr,an=Ds,Te=an.validators;function be(t){this.defaults=t,this.interceptors={request:new sn,response:new sn}}be.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&&an.assertOptions(n,{silentJSONParsing:Te.transitional(Te.boolean),forcedJSONParsing:Te.transitional(Te.boolean),clarifyTimeoutError:Te.transitional(Te.boolean)},!1);var i=[],s=!0;this.interceptors.request.forEach(function(l){typeof l.runWhen=="function"&&l.runWhen(r)===!1||(s=s&&l.synchronous,i.unshift(l.fulfilled,l.rejected))});var o=[];this.interceptors.response.forEach(function(l){o.push(l.fulfilled,l.rejected)});var a;if(!s){var c=[on,void 0];for(Array.prototype.unshift.apply(c,i),c=c.concat(o),a=Promise.resolve(r);c.length;)a=a.then(c.shift(),c.shift());return a}for(var f=r;i.length;){var u=i.shift(),v=i.shift();try{f=u(f)}catch(d){v(d);break}}try{a=on(f)}catch(d){return Promise.reject(d)}for(;o.length;)a=a.then(o.shift(),o.shift());return a},be.prototype.getUri=function(e){e=dt(this.defaults,e);var r=$s(e.baseURL,e.url);return Us(r,e.params,e.paramsSerializer)},nn.forEach(["delete","get","head","options"],function(e){be.prototype[e]=function(r,n){return this.request(dt(n||{},{method:e,url:r,data:(n||{}).data}))}}),nn.forEach(["post","put","patch"],function(e){function r(n){return function(s,o,a){return this.request(dt(a||{},{method:e,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}be.prototype[e]=r(),be.prototype[e+"Form"]=r(!0)});var js=be,Ls=lt;function Oe(t){if(typeof t!="function")throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(i){e=i});var r=this;this.promise.then(function(n){if(!!r._listeners){var i,s=r._listeners.length;for(i=0;i<s;i++)r._listeners[i](n);r._listeners=null}}),this.promise.then=function(n){var i,s=new Promise(function(o){r.subscribe(o),i=o}).then(n);return s.cancel=function(){r.unsubscribe(i)},s},t(function(i){r.reason||(r.reason=new Ls(i),e(r.reason))})}Oe.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},Oe.prototype.subscribe=function(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]},Oe.prototype.unsubscribe=function(e){if(!!this._listeners){var r=this._listeners.indexOf(e);r!==-1&&this._listeners.splice(r,1)}},Oe.source=function(){var e,r=new Oe(function(i){e=i});return{token:r,cancel:e}};var Ms=Oe,Bs=function(e){return function(n){return e.apply(null,n)}},Fs=B,qs=function(e){return Fs.isObject(e)&&e.isAxiosError===!0},un=B,Hs=Ur,ht=js,Vs=en,zs=nr;function cn(t){var e=new ht(t),r=Hs(ht.prototype.request,e);return un.extend(r,ht.prototype,e),un.extend(r,e),r.create=function(i){return cn(Vs(t,i))},r}var V=cn(zs);V.Axios=ht,V.CanceledError=lt,V.CancelToken=Ms,V.isCancel=Xr,V.VERSION=tn.version,V.toFormData=Vr,V.AxiosError=Se,V.Cancel=V.CanceledError,V.all=function(e){return Promise.all(e)},V.spread=Bs,V.isAxiosError=qs,Wt.exports=V,Wt.exports.default=V;var vt=Wt.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 Gs={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 ar(t,e){function r(i,s,o){if(typeof document!="undefined"){o=pt({},e,o),typeof o.expires=="number"&&(o.expires=new Date(Date.now()+o.expires*864e5)),o.expires&&(o.expires=o.expires.toUTCString()),i=encodeURIComponent(i).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in o)!o[c]||(a+="; "+c,o[c]!==!0&&(a+="="+o[c].split(";")[0]));return document.cookie=i+"="+t.write(s,i)+a}}function n(i){if(!(typeof document=="undefined"||arguments.length&&!i)){for(var s=document.cookie?document.cookie.split("; "):[],o={},a=0;a<s.length;a++){var c=s[a].split("="),f=c.slice(1).join("=");try{var u=decodeURIComponent(c[0]);if(o[u]=t.read(f,u),i===u)break}catch{}}return i?o[i]:o}}return Object.create({set:r,get:n,remove:function(i,s){r(i,"",pt({},s,{expires:-1}))},withAttributes:function(i){return ar(this.converter,pt({},this.attributes,i))},withConverter:function(i){return ar(pt({},this.converter,i),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(t)}})}var ur=ar(Gs,{path:"/"}),Ws=Object.defineProperty,Js=Object.defineProperties,Ks=Object.getOwnPropertyDescriptors,mt=Object.getOwnPropertySymbols,ln=Object.prototype.hasOwnProperty,fn=Object.prototype.propertyIsEnumerable,dn=(t,e,r)=>e in t?Ws(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ie=(t,e)=>{for(var r in e||(e={}))ln.call(e,r)&&dn(t,r,e[r]);if(mt)for(var r of mt(e))fn.call(e,r)&&dn(t,r,e[r]);return t},Be=(t,e)=>Js(t,Ks(e)),hn=(t,e)=>{var r={};for(var n in t)ln.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&mt)for(var n of mt(t))e.indexOf(n)<0&&fn.call(t,n)&&(r[n]=t[n]);return r};const yt="nhostRefreshToken",gt="nhostRefreshTokenExpiresAt",Ys=3,Qs=300,Xs=5,Zs=0,se=10,Et=20,xe={status:se,error:"invalid-email",message:"Email is incorrectly formatted"},cr={status:se,error:"invalid-password",message:"Password is incorrectly formatted"},vn={status:se,error:"invalid-phone-number",message:"Phone number is incorrectly formatted"},eo={status:se,error:"invalid-mfa-ticket",message:"MFA ticket is invalid"},to={status:se,error:"no-mfa-ticket",message:"No MFA ticket has been provided"},ro={status:se,error:"no-refresh-token",message:"No refresh token has been provided"},no={status:Et,error:"refresher-already-running",message:"The token refresher is already running. You must wait until is has finished before submitting a new token."},ce={status:Et,error:"already-signed-in",message:"User is already signed in"},io={status:Et,error:"unauthenticated-user",message:"User is not authenticated"},so={status:Et,error:"unverified-user",message:"Email needs verification"},oo={status:se,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,o,a,c,f,u,v,d;return Promise.reject({error:{message:(a=(o=(s=(i=(n=r.response)==null?void 0:n.data)==null?void 0:i.message)!=null?s:r.message)!=null?o:r.request.responseText)!=null?a:JSON.stringify(r),status:(v=(u=(c=r.response)==null?void 0:c.status)!=null?u:(f=r.response)==null?void 0:f.data.statusCode)!=null?v:Zs,error:((d=r.response)==null?void 0:d.data.error)||r.request.statusText||"network"}})}),e},wt=typeof window!="undefined",St=new Map,ao=t=>{var e;return wt&&typeof localStorage!="undefined"?localStorage.getItem(t):(e=St.get(t))!=null?e:null},uo=(t,e)=>{wt&&typeof localStorage!="undefined"?e?localStorage.setItem(t,e):localStorage.removeItem(t):e?St.set(t,e):St.has(t)&&St.delete(t)},co=(t,e)=>{if(t==="localStorage"||t==="web")return ao;if(t==="cookie")return r=>{var n;return wt&&(n=ur.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}`)},lo=(t,e)=>{if(t==="localStorage"||t==="web")return uo;if(t==="cookie")return(r,n)=>{wt&&(n?ur.set(r,n,{expires:30}):ur.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}`)},pn=(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},Z=(t,e)=>{if(!(e!=null&&e.redirectTo))return e;const r=e,{redirectTo:n}=r,i=hn(r,["redirectTo"]);if(!t)return n.startsWith("/")?i:e;const s=new URL(t),o=Object.fromEntries(new URLSearchParams(s.search)),a=new URL(n.startsWith("/")?s.origin+n:n),c=new URLSearchParams(a.search);let f=Object.fromEntries(c);n.startsWith("/")&&(f=ie(ie({},o),f));let u=s.pathname;return a.pathname.length>1&&(u+=a.pathname.slice(1)),Be(ie({},i),{redirectTo:pn(a.origin+u,f)})};function Tt(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 mn(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 _e=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,}))$/),lr=t=>!!t&&typeof t=="string"&&t.length>=Ys,yn=t=>!!t&&typeof t=="string",fo=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),fr={user:null,mfa:null,accessToken:{value:null,expiresAt:null},refreshTimer:{startedAt:null,attempts:0,lastAttempt:null},refreshToken:{value:null},errors:{}},ho=({backendUrl:t,clientUrl:e,interpreter:r})=>{const n=Fe(t);return Le({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=>xe}),saveRequestError:L({error:(i,{data:{error:s}})=>s}),reportError:Y(i=>({type:"ERROR",error:i.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(i,{email:s})=>!_e(s)},services:{requestChange:async(i,{email:s,options:o})=>(await n.post("/user/email/change",{newEmail:s,options:Z(e,o)},{headers:{authorization:`Bearer ${r==null?void 0:r.state.context.accessToken.value}`}})).data}})},vo=({backendUrl:t,interpreter:e})=>{const r=Fe(t);return Le({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=>cr}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidPassword:(n,{password:i})=>!lr(i)},services:{requestChange:(n,{password:i,ticket:s})=>r.post("/user/password",{newPassword:i,ticket:s},{headers:{authorization:`Bearer ${e==null?void 0:e.state.context.accessToken.value}`}})}})},po=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return Le({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=>xe}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!_e(i)},services:{requestChange:(n,{email:i,options:s})=>r.post("/user/password/reset",{email:i,options:Z(e,s)})}})},mo=({backendUrl:t,clientUrl:e})=>{const r=Fe(t);return Le({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=>xe}),saveRequestError:L({error:(n,{data:{error:i}})=>i}),reportError:Y(n=>({type:"ERROR",error:n.error})),reportSuccess:Y("SUCCESS")},guards:{invalidEmail:(n,{email:i})=>!_e(i)},services:{request:async(n,{email:i,options:s})=>(await r.post("/user/email/send-verification-email",{email:i,options:Z(e,s)})).data}})},yo=({backendUrl:t,clientUrl:e,clientStorageGetter:r,clientStorageSetter:n,clientStorageType:i="web",clientStorage:s,refreshIntervalTime:o,autoRefreshToken:a=!0,autoSignIn:c=!0})=>{const f=r||co(i,s),u=n||lo(i,s),v=Fe(t),d=async(l,h,p)=>(await v.post(l,h,p)).data;return Le({schema:{context:{},events:{}},tsTypes:{},context:fr,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:Y("SIGNED_IN"),reportSignedOut:Y("SIGNED_OUT"),reportTokenChanged:Y("TOKEN_CHANGED"),clearContext:L(()=>(u(gt,null),u(yt,null),ie({},fr))),clearContextExceptRefreshToken:L(({refreshToken:{value:l}})=>(u(gt,null),Be(ie({},fr),{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,m;if(h.session.accessTokenExpiresIn){const E=new Date(Date.now()+h.session.accessTokenExpiresIn*1e3).toISOString();u(gt,E)}else u(gt,null);return{value:(p=h==null?void 0:h.session)==null?void 0:p.accessToken,expiresAt:new Date(Date.now()+((m=h==null?void 0:h.session)==null?void 0:m.accessTokenExpiresIn)*1e3)}},refreshToken:(l,{data:h})=>{var p;return u(yt,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}})=>Be(ie({},l),{authentication:h})}),resetErrors:L({errors:l=>({})}),saveRegistrationError:L({errors:({errors:l},{data:{error:h}})=>Be(ie({},l),{registration:h})}),destroyRefreshToken:L({refreshToken:l=>(u(yt,null),{value:null})}),cleanUrl:()=>{c&&Tt("refreshToken")&&(mn("refreshToken"),mn("type"))},broadcastToken:l=>{if(c)try{new BroadcastChannel("nhost").postMessage(l.refreshToken.value)}catch{}}},guards:{isAnonymous:(l,h)=>{var p;return!!((p=l.user)!=null&&p.isAnonymous)},isSignedIn:l=>!!l.user&&!!l.refreshToken.value&&!!l.accessToken.value,noToken:l=>!l.refreshToken.value,hasRefreshToken:l=>!!l.refreshToken.value,isAutoRefreshDisabled:()=>!a,refreshTimerShouldRefresh:l=>{const{expiresAt:h}=l.accessToken;return h?l.refreshTimer.lastAttempt?Date.now()-l.refreshTimer.lastAttempt.getTime()>Xs*1e3:o&&Date.now()-l.refreshTimer.startedAt.getTime()>o*1e3?!0:h.getTime()-Date.now()-1e3*Qs<=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})=>_e(h)?lr(p)?d("/signin/email-password",{email:h,password:p}):Promise.reject({error:cr}):Promise.reject({error:xe}),passwordlessSms:(l,{phoneNumber:h,options:p})=>{var m;return yn(h)?(m=l.user)!=null&&m.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:Z(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}})):d("/signin/passwordless/sms",{phoneNumber:h,options:Z(e,p)}):Promise.reject({error:vn})},passwordlessSmsOtp:(l,{phoneNumber:h,otp:p})=>yn(h)?d("/signin/passwordless/sms/otp",{phoneNumber:h,otp:p}):Promise.reject({error:vn}),passwordlessEmail:(l,{email:h,options:p})=>{var m;return _e(h)?(m=l.user)!=null&&m.isAnonymous?d("/user/deanonymize",{signInMethod:"passwordless",connection:"email",email:h,options:Z(e,p)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signin/passwordless/email",{email:h,options:Z(e,p)}):Promise.reject({error:xe})},signInAnonymous:l=>d("/signin/anonymous"),signInMfaTotp:(l,h)=>{var p;const m=h.ticket||((p=l.mfa)==null?void 0:p.ticket);return m?fo(m)?d("/signin/mfa/totp",{ticket:m,otp:h.otp}):Promise.reject({error:eo}):Promise.reject({error:to})},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:m})=>{var E;return _e(h)?lr(p)?(E=l.user)!=null&&E.isAnonymous?d("/user/deanonymize",{signInMethod:"email-password",email:h,password:p,options:Z(e,m)},{headers:{authorization:`Bearer ${l.accessToken.value}`}}):d("/signup/email-password",{email:h,password:p,options:Z(e,m)}):Promise.reject({error:cr}):Promise.reject({error:xe})},importRefreshToken:async()=>{let l=null;if(c){const p=Tt("refreshToken")||null;if(p)try{return{session:await d("/token",{refreshToken:p})}}catch(m){l=m.error}else{const m=Tt("error");if(m)return Promise.reject({error:{status:se,error:m,message:Tt("errorDescription")||m}})}}const h=await f(yt);if(h)try{return{session:await d("/token",{refreshToken:h})}}catch(p){l=p.error}return Promise.reject({error:l})}}})};class go{constructor(e){var r=e,{clientStorageType:n="web",autoSignIn:i=!0,autoRefreshToken:s=!0,start:o=!0,backendUrl:a,clientUrl:c,devTools:f}=r,u=hn(r,["clientStorageType","autoSignIn","autoRefreshToken","start","backendUrl","clientUrl","devTools"]);if(this._subscriptions=new Set,this.backendUrl=a,this.clientUrl=c,this.machine=yo(Be(ie({},u),{backendUrl:a,clientUrl:c,clientStorageType:n,autoSignIn:i,autoRefreshToken:s})),o&&(this.interpreter=pe(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 Eo=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})})}),wo=async(t,e,r)=>new Promise(n=>{t.send("REQUEST",{password:e,ticket:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSuccess:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSuccess:!0})})}),So=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})})}),To=(t,e,r)=>new Promise(n=>{t.send("REQUEST",{email:e,options:r}),t.onTransition(i=>{i.matches({idle:"error"})?n({error:i.context.error,isError:!0,isSent:!1}):i.matches({idle:"success"})&&n({error:null,isError:!1,isSent:!0})})}),bo=t=>new Promise(e=>{const{changed:r}=t.send("SIGNIN_ANONYMOUS");r||e({isSuccess:!1,isError:!0,error:ce,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})})}),Oo=(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:ce,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:{signedOut:"needsMfa"}})?n({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!0,mfa:o.context.mfa,user:null}):o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,needsMfaOtp:!1,mfa:null,user:o.context.user})})}),gn=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_EMAIL",{email:e,options:r});if(!i)return n({error:ce,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})})}),xo=(t,e,r)=>new Promise(n=>{const{changed:i,context:s}=t.send("SIGNIN_MFA_TOTP",{otp:e,ticket:r});if(!i)return n({accessToken:s.accessToken.value,error:ce,isError:!0,isSuccess:!1,user:s.user});t.onTransition(o=>{o.matches({authentication:{signedOut:"failed"}})?n({accessToken:null,error:o.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null}):o.matches({authentication:"signedIn"})&&n({accessToken:o.context.accessToken.value,error:null,isError:!1,isSuccess:!0,user:o.context.user})})}),En=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send("PASSWORDLESS_SMS",{phoneNumber:e,options:r});if(!i)return n({error:ce,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})})}),_o=(t,e,r)=>new Promise(n=>{const{changed:i}=t.send({type:"PASSWORDLESS_SMS_OTP",phoneNumber:e,otp:r});if(!i)return n({error:ce,isError:!0,isSuccess:!1,user:null,accessToken:null});t.onTransition(s=>{s.matches({authentication:"signedIn"})?n({error:null,isError:!1,isSuccess:!0,user:s.context.user,accessToken:s.context.accessToken.value}):s.matches({registration:{incomplete:"failed"}})&&n({error:s.context.errors.authentication||null,isError:!0,isSuccess:!1,user:null,accessToken:null})})}),Ro=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:io});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})})}),wn=(t,e,r,n)=>new Promise(i=>{const{changed:s,context:o}=t.send("SIGNUP_EMAIL_PASSWORD",{email:e,password:r,options:n});if(!s)return i({error:ce,accessToken:o.accessToken.value,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:o.user});t.onTransition(a=>{a.matches("registration.incomplete.failed")?i({accessToken:null,error:a.context.errors.registration||null,isError:!0,isSuccess:!1,needsEmailVerification:!1,user:null}):a.matches({authentication:{signedOut:"noErrors"},registration:{incomplete:"needsEmailVerification"}})?i({accessToken:null,error:null,isError:!1,isSuccess:!1,needsEmailVerification:!0,user:null}):a.matches({authentication:"signedIn",registration:"complete"})&&i({accessToken:a.context.accessToken.value,error:null,isError:!1,isSuccess:!0,needsEmailVerification:!1,user:a.context.user})})});var Ao=Object.defineProperty,Po=Object.defineProperties,ko=Object.getOwnPropertyDescriptors,Sn=Object.getOwnPropertySymbols,Io=Object.prototype.hasOwnProperty,No=Object.prototype.propertyIsEnumerable,Tn=(t,e,r)=>e in t?Ao(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bt=(t,e)=>{for(var r in e||(e={}))Io.call(e,r)&&Tn(t,r,e[r]);if(Sn)for(var r of Sn(e))No.call(e,r)&&Tn(t,r,e[r]);return t},Ot=(t,e)=>Po(t,ko(e));const Co=()=>typeof window!="undefined",xt=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},qe=({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 Do{constructor({url:e,autoRefreshToken:r=!0,autoSignIn:n=!0,autoLogin:i,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f,start:u=!0}){var v;this.url=e,this._client=new go({backendUrl:e,clientUrl:typeof window!="undefined"&&((v=window.location)==null?void 0:v.origin)||"",autoRefreshToken:r,autoSignIn:typeof i=="boolean"?i:n,start:u,clientStorage:s,clientStorageType:o,clientStorageGetter:a,clientStorageSetter:c,refreshIntervalTime:f})}async signUp({email:e,password:r,options:n}){const i=await this.waitUntilReady();return qe(await wn(i,e,r,n))}async signIn(e){const r=await this.waitUntilReady();if("provider"in e){const{provider:i,options:s}=e,o=pn(`${this._client.backendUrl}/signin/provider/${i}`,Z(this._client.clientUrl,s));return Co()&&(window.location.href=o),{providerUrl:o,provider:i,session:null,mfa:null,error:null}}if("email"in e&&"password"in e){const i=await Oo(r,e.email,e.password);return i.needsEmailVerification?{session:null,mfa:null,error:so}:i.needsMfaOtp?{session:null,mfa:i.mfa,error:null}:Ot(bt({},qe(i)),{mfa:null})}if("email"in e){const{error:i}=await gn(r,e.email);return{session:null,mfa:null,error:i}}if("phoneNumber"in e&&"otp"in e){const i=await _o(r,e.phoneNumber,e.otp);return Ot(bt({},qe(i)),{mfa:null})}if("phoneNumber"in e){const{error:i}=await En(r,e.phoneNumber,e.options);return{error:i,mfa:null,session:null}}if("otp"in e){const i=await xo(r,e.otp,e.ticket);return Ot(bt({},qe(i)),{mfa:null})}const n=await bo(r);return Ot(bt({},qe(n)),{mfa:null})}async signOut(e){const r=await this.waitUntilReady(),{error:n}=await Ro(r,e==null?void 0:e.all);return{error:n}}async resetPassword({email:e,options:r}){const n=pe(po(this._client)).start(),{error:i}=await So(n,e,r);return{error:i}}async changePassword({newPassword:e,ticket:r}){const n=pe(vo(this._client)).start(),{error:i}=await wo(n,e,r);return{error:i}}async sendVerificationEmail({email:e,options:r}){const n=pe(mo(this._client)).start(),{error:i}=await To(n,e,r);return{error:i}}async changeEmail({newEmail:e,options:r}){const n=pe(ho(this._client)).start(),{error:i}=await Eo(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 gn(r,e.email,e.options);return{error:n}}if(e.connection==="sms"){const{error:n}=await En(r,e.phoneNumber,e.options);return{error:n}}}if(e.signInMethod==="email-password"){const{error:n}=await wn(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(xt(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,xt(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?Dn(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:ro});const{changed:s}=r.send("TRY_TOKEN",{token:i});if(!s)return n({session:null,error:no});r.onTransition(o=>{o.matches({token:{idle:"error"}})?n({session:null,error:oo}):o.event.type==="TOKEN_CHANGED"&&n({session:xt(o.context),error:null})})})}catch(r){return{session:null,error:r.message}}}getSession(){var e,r;return xt((r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)}getUser(){var e,r,n;return((n=(r=(e=this._client.interpreter)==null?void 0:e.state)==null?void 0:r.context)==null?void 0:n.user)||null}waitUntilReady(){const r=this._client.interpreter;if(!r)throw Error("Auth interpreter not set");return r.state.hasTag("loading")?new Promise((n,i)=>{let s=setTimeout(()=>i(`The state machine is not yet ready after ${15} seconds.`),15e3);r.onTransition(o=>{if(!o.hasTag("loading"))return clearTimeout(s),n(r)})}):Promise.resolve(r)}isReady(){var e,r;return!((r=(e=this._client.interpreter)==null?void 0:e.state)!=null&&r.hasTag("loading"))}get client(){return this._client}}var Uo=typeof self=="object"?self.FormData:window.FormData,$o=Object.defineProperty,jo=Object.defineProperties,Lo=Object.getOwnPropertyDescriptors,bn=Object.getOwnPropertySymbols,Mo=Object.prototype.hasOwnProperty,Bo=Object.prototype.propertyIsEnumerable,On=(t,e,r)=>e in t?$o(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,He=(t,e)=>{for(var r in e||(e={}))Mo.call(e,r)&&On(t,r,e[r]);if(bn)for(var r of bn(e))Bo.call(e,r)&&On(t,r,e[r]);return t},xn=(t,e)=>jo(t,Lo(e));class Fo{constructor({url:e}){this.url=e,this.httpClient=vt.create({baseURL:this.url})}async upload(e){const{formData:r}=e;try{return{fileMetadata:(await this.httpClient.post("/files",r,{headers:xn(He(He({},this.generateUploadHeaders(e)),this.generateAuthHeaders()),{"Content-Type":"multipart/form-data"})})).data,error:null}}catch(n){return{fileMetadata:null,error:n}}}async getPresignedUrl(e){try{const{fileId:r}=e;return{presignedUrl:(await this.httpClient.get(`/files/${r}/presignedurl`,{headers:He({},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:He({},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 qo{constructor({url:e,adminSecret:r}){this.url=e,this.api=new Fo({url:e}),this.setAdminSecret(r)}async upload(e){let r;"file"in e?(r=new Uo,r.append("file",e.file)):r=e.formData;const{fileMetadata:n,error:i}=await this.api.upload(xn(He({},e),{formData:r}));return i?{fileMetadata:null,error:i}:n?{fileMetadata:n,error:null}:{fileMetadata:null,error:new Error("Invalid file returned")}}getUrl(e){return this.getPublicUrl(e)}getPublicUrl(e){const{fileId:r}=e;return`${this.url}/files/${r}`}async getPresignedUrl(e){const{presignedUrl:r,error:n}=await this.api.getPresignedUrl(e);return n?{presignedUrl:null,error:n}:r?{presignedUrl:r,error:null}:{presignedUrl:null,error:new Error("Invalid file id")}}async delete(e){const{error:r}=await this.api.delete(e);return r?{error:r}:{error:null}}setAccessToken(e){return this.api.setAccessToken(e),this}setAdminSecret(e){return this.api.setAdminSecret(e),this}}class _n{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=le(le({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);let s;try{s=await this.instance.post(e,r,dr(le({},n),{headers:i}))}catch(o){if(o instanceof Error)return{res:null,error:o}}return s?{res:s,error:null}:{res:null,error:new Error("Unable to make post request to funtion")}}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}class Rn{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=le(le({},this.generateAccessTokenHeaders()),n==null?void 0:n.headers);try{const s="",a=(await this.instance.post("",{operationName:s||void 0,query:typeof e=="string"?e:U.print(e),variables:r},dr(le({},n),{headers:i}))).data,{data:c}=a;return a.errors?{data:null,error:a.errors}:typeof c!="object"||Array.isArray(c)||c===null?{data:null,error:new Error("incorrect response data from GraphQL server")}:{data:c,error:null}}catch(s){return s instanceof Error?{data:null,error:s}:(console.error(s),{data:null,error:new Error("Unable to get do GraphQL request")})}}getUrl(){return this.url}setAccessToken(e){if(!e){this.accessToken=null;return}this.accessToken=e}generateAccessTokenHeaders(){return this.adminSecret?{"x-hasura-admin-secret":this.adminSecret}:this.accessToken?{Authorization:`Bearer ${this.accessToken}`}:{}}}const Ho=/^localhost(:\d+)*$/g;function _t(t,e){const{backendUrl:r,subdomain:n,region:i}=t;if(!r&&!n)throw new Error("Either `backendUrl` or `subdomain` must be set.");if(r)return`${r}/v1/${e}`;if(!n)throw new Error("`subdomain` must be set if `backendUrl` is not set.");const s=n.match(Ho);if(s&&s.length>0){const o=s[0];return o==="localhost"?`http://localhost:1337/v1/${e}`:`http://${o}/v1/${e}`}if(!i)throw new Error('`region` must be set when using a `subdomain` other than "localhost".');return`https://${n}.${e}.${i}.nhost.run/v1`}class An{constructor(d){var l=d,{refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,adminSecret:c,devTools:f,start:u=!0}=l,v=Nn(l,["refreshIntervalTime","clientStorageGetter","clientStorageSetter","clientStorage","clientStorageType","autoRefreshToken","autoSignIn","adminSecret","devTools","start"]);var h;this.auth=new Do({url:_t(v,"auth"),refreshIntervalTime:e,clientStorageGetter:r,clientStorageSetter:n,clientStorage:i,clientStorageType:s,autoRefreshToken:o,autoSignIn:a,start:u}),this.storage=new qo({url:_t(v,"storage"),adminSecret:c}),this.functions=new _n({url:_t(v,"functions"),adminSecret:c}),this.graphql=new Rn({url:_t(v,"graphql"),adminSecret:c}),this.storage.setAccessToken(this.auth.getAccessToken()),this.functions.setAccessToken(this.auth.getAccessToken()),this.graphql.setAccessToken(this.auth.getAccessToken()),(h=this.auth.client)==null||h.onStart(()=>{this.auth.onAuthStateChanged((p,m)=>{p==="SIGNED_OUT"&&(this.storage.setAccessToken(void 0),this.functions.setAccessToken(void 0),this.graphql.setAccessToken(void 0))}),this.auth.onTokenChanged(p=>{this.storage.setAccessToken(p==null?void 0:p.accessToken),this.functions.setAccessToken(p==null?void 0:p.accessToken),this.graphql.setAccessToken(p==null?void 0:p.accessToken)})}),this._adminSecret=c,this.devTools=f}get adminSecret(){return this._adminSecret}set adminSecret(e){this._adminSecret=e,this.storage.setAdminSecret(e)}}const Vo=t=>new An(t);A.NhostClient=An,A.NhostFunctionsClient=_n,A.NhostGraphqlClient=Rn,A.createClient=Vo,Object.defineProperties(A,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
19
19
|
//# sourceMappingURL=nhost-js.umd.js.map
|